public static boolean canSetClass(AncientRPGClass newClass, final Player p) { PlayerData pd = PlayerData.getPlayerData(p.getName()); if (AncientRPGExperience.isEnabled() && AncientRPGExperience.isWorldEnabled(p)) { if (pd.getXpSystem().level < newClass.minlevel) { p.sendMessage( AncientRPG.brand2 + "You need to be level " + newClass.minlevel + " to join this class"); return false; } } if (!newClass.isWorldEnabled(p)) { return false; } if (newClass.preclass != null && !newClass.preclass.equals("") && !newClass.preclass.toLowerCase().equals(pd.getClassName().toLowerCase())) { return false; } AncientRPGRace race = AncientRPGRace.getRaceByName(PlayerData.getPlayerData(p.getName()).getRacename()); if (newClass.requiredraces.size() >= 0 && (race != null && !newClass.requiredraces.contains(race.name.toLowerCase()))) { return false; } if (!(newClass.permissionNode == null || newClass.permissionNode.equalsIgnoreCase("")) && !AncientRPG.hasPermissions(p, newClass.permissionNode)) { return false; } return AncientRPG.hasPermissions(p, AncientRPGClass.cNodeClass); }
public static void setClass( AncientRPGClass newClass, AncientRPGClass oldClass, final Player p, CommandSender sender) { if (p == null) { return; } PlayerData pd = PlayerData.getPlayerData(p.getName()); if (newClass != null) { if (sender == p && AncientRPGExperience.isEnabled() && AncientRPGExperience.isWorldEnabled(p)) { if (pd.getXpSystem().level < newClass.minlevel) { p.sendMessage( AncientRPG.brand2 + "You need to be level " + newClass.minlevel + " to join this class"); return; } } if (!senderHasPermissions(sender, AncientRPGClass.cNodeClass)) { sender.sendMessage( AncientRPG.brand2 + "You don't have the required permissions to become this class"); return; } if (!newClass.isWorldEnabled(p)) { sender.sendMessage(AncientRPG.brand2 + "This class cannot be used in this world"); return; } AncientRPGRace race = AncientRPGRace.getRaceByName(PlayerData.getPlayerData(p.getName()).getRacename()); if (newClass.requiredraces.size() > 0 && (race == null || !newClass.requiredraces.contains(race.name.toLowerCase()))) { p.sendMessage(AncientRPG.brand2 + "Your race can't use this class"); return; } if (sender == null || !(newClass.permissionNode == null || newClass.permissionNode.equalsIgnoreCase("")) && !senderHasPermissions(sender, newClass.permissionNode)) { p.sendMessage(AncientRPG.brand2 + "You don't have permissions to use this class"); return; } AncientRPGClassChangeEvent classevent = new AncientRPGClassChangeEvent(p, oldClass, newClass); Bukkit.getPluginManager().callEvent(classevent); if (classevent.isCancelled()) { return; } try { if (oldClass != null && oldClass.permGroup != null && !oldClass.permGroup.equals("")) { if (AncientRPG.permissionHandler != null) { AncientRPG.permissionHandler.playerRemoveGroup(p, oldClass.permGroup); } } if (AncientRPGExperience.isEnabled()) { if (oldClass != null) { pd.getClassLevels().put(oldClass.name.toLowerCase(), pd.getXpSystem().xp); } } } catch (Exception ignored) { } pd.setClassName(newClass.name); if (AncientRPGExperience.isEnabled()) { int xp = 0; if (pd.getClassLevels().get(newClass.name.toLowerCase()) != null && !AncientRPGClass.resetlevelonchange) { xp = pd.getClassLevels().get(newClass.name.toLowerCase()); } pd.getXpSystem().xp = xp; pd.getXpSystem().addXP(0, false); pd.getXpSystem().recalculateLevel(); } pd.getHpsystem().setHpRegen(); pd.getHpsystem().setMinecraftHP(); pd.getHpsystem().setMaxHp(); // pd.hpsystem.maxhp = ct.getMaxHp(); pd.setBindings(new HashMap<BindingData, String>()); p.sendMessage(AncientRPG.brand2 + "Your class is now " + newClass.name); pd.setStance(""); try { if (newClass.permGroup != null && !newClass.permGroup.equals("") && AncientRPG.permissionHandler != null) { AncientRPG.permissionHandler.playerAddGroup(p, newClass.permGroup); } } catch (Exception ignored) { } for (Map.Entry<BindingData, String> bind : newClass.bindings.entrySet()) { pd.getBindings().put(bind.getKey(), bind.getValue()); } AncientRPGClass.playersOnCd.put(p.getName(), System.currentTimeMillis()); File f = new File( AncientRPG.plugin.getDataFolder() + File.separator + "Class" + File.separator + "changecds.dat"); FileOutputStream fos; try { fos = new FileOutputStream(f); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(AncientRPGClass.playersOnCd); oos.close(); } catch (Exception e) { e.printStackTrace(); } } pd.getManasystem().setMaxMana(); }