48 lines
1.4 KiB
Java
48 lines
1.4 KiB
Java
package de.leafbla.meinkraft.roleplay;
|
|
|
|
import de.leafbla.meinkraft.Main;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.bukkit.entity.Player;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.logging.Logger;
|
|
|
|
public class RoleManager {
|
|
|
|
private final Map<Player, PlayerRole> classes = new HashMap<>();
|
|
private final Main plugin;
|
|
|
|
public RoleManager(Main plugin) {
|
|
this.plugin = plugin;
|
|
}
|
|
|
|
public void setClass(Player player, Role theclass) {
|
|
this.unsetClass(player);
|
|
PlayerRole thePlayerRole = theclass.createInstance(plugin, player);
|
|
if (thePlayerRole == null) {
|
|
Logger.getLogger("MeinKraft").warning("setClass(Player, Class) returned null");
|
|
return;
|
|
}
|
|
this.classes.put(player, thePlayerRole);
|
|
player.sendMessage(
|
|
String.format("§eYou are now a §6%s§e!", StringUtils.capitalize(theclass.name()))
|
|
);
|
|
}
|
|
|
|
public void unsetClass(Player player) {
|
|
if (this.classes.containsKey(player)) {
|
|
Role oldclass = this.classes.get(player).getRole();
|
|
player.sendMessage(
|
|
String.format("§eYou are no longer a §6%s§e!", StringUtils.capitalize(oldclass.name()))
|
|
);
|
|
this.classes.remove(player);
|
|
}
|
|
}
|
|
|
|
public PlayerRole getPlayerRole(Player player) {
|
|
return this.classes.getOrDefault(player, null);
|
|
}
|
|
|
|
}
|