Refactored ClanRole enum

This commit is contained in:
CoderTim 2015-02-18 19:56:29 -05:00
parent 44f453c56e
commit aebe390c3c
7 changed files with 65 additions and 80 deletions

View File

@ -27,23 +27,6 @@ import mineplex.game.clans.clans.repository.tokens.ClanToken;
public class ClanInfo
{
public enum Role
{
LEADER(4), ADMIN(3), MEMBER(2), RECRUIT(1), NONE(0);
private int i;
private Role(int value)
{
this.i = value;
}
public int toInt()
{
return i;
}
}
private int _id = -1;
private String _name = "";
private String _desc = "";
@ -56,7 +39,7 @@ public class ClanInfo
private long _lastOnline = 0;
// Loaded from Client
private NautHashMap<String, Role> _memberMap = new NautHashMap<String, Role>();
private NautHashMap<String, ClanRole> _memberMap = new NautHashMap<String, ClanRole>();
private NautHashMap<String, Boolean> _allyMap = new NautHashMap<String, Boolean>();
private HashSet<String> _claimSet = new HashSet<String>();
private EnemyData _enemyData;
@ -95,7 +78,7 @@ public class ClanInfo
for (ClanMemberToken memberToken : token.Members)
{
_memberMap.put(memberToken.Name, Role.valueOf(memberToken.ClanRole));
_memberMap.put(memberToken.Name, ClanRole.valueOf(memberToken.ClanRole));
}
for (ClanTerritoryToken territoryToken : token.Territories)
@ -251,16 +234,16 @@ public class ClanInfo
if (UtilPlayer.isOnline(cur))
name = C.listValueOn + cur;
if (getMembers().get(cur) == Role.LEADER)
if (getMembers().get(cur) == ClanRole.LEADER)
members += C.listValue + "L." + name + C.mBody + ", ";
if (getMembers().get(cur) == Role.ADMIN)
if (getMembers().get(cur) == ClanRole.ADMIN)
members += C.listValue + "A." + name + C.mBody + ", ";
if (getMembers().get(cur) == Role.MEMBER)
if (getMembers().get(cur) == ClanRole.MEMBER)
members += C.listValue + "M." + name + C.mBody + ", ";
if (getMembers().get(cur) == Role.RECRUIT)
if (getMembers().get(cur) == ClanRole.RECRUIT)
members += C.listValue + "R." + name + C.mBody + ", ";
}
stringList.add(F.value("Members", members));
@ -338,7 +321,7 @@ public class ClanInfo
_desc = desc;
}
public NautHashMap<String, Role> getMembers()
public NautHashMap<String, ClanRole> getMembers()
{
return _memberMap;
}

View File

@ -0,0 +1,6 @@
package mineplex.game.clans.clans;
public enum ClanRole
{
NONE, RECRUIT, MEMBER, ADMIN, LEADER
}

View File

@ -9,7 +9,6 @@ import mineplex.core.common.util.UtilInput;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilWorld;
import mineplex.game.clans.clans.ClanInfo.Role;
import mineplex.game.clans.clans.repository.ClanTerritory;
import org.bukkit.Bukkit;
@ -297,7 +296,7 @@ public class ClansAdmin
if (target == null)
return;
if (clan.getMembers().get(target) == Role.LEADER)
if (clan.getMembers().get(target) == ClanRole.LEADER)
{
UtilPlayer.message(caller, F.main("Clans Admin", "You cannot promote " + F.name(target) + " any further."));
return;
@ -305,19 +304,19 @@ public class ClansAdmin
//Task
String newRank = "?";
if (clan.getMembers().get(target) == Role.RECRUIT)
if (clan.getMembers().get(target) == ClanRole.RECRUIT)
{
Clans.getClanDataAccess().role(clan, target, Role.MEMBER);
Clans.getClanDataAccess().role(clan, target, ClanRole.MEMBER);
newRank = "Member";
}
else if (clan.getMembers().get(target) == Role.MEMBER)
else if (clan.getMembers().get(target) == ClanRole.MEMBER)
{
Clans.getClanDataAccess().role(clan, target, Role.ADMIN);
Clans.getClanDataAccess().role(clan, target, ClanRole.ADMIN);
newRank = "Admin";
}
else if (clan.getMembers().get(target) == Role.ADMIN)
else if (clan.getMembers().get(target) == ClanRole.ADMIN)
{
Clans.getClanDataAccess().role(clan, target, Role.LEADER);
Clans.getClanDataAccess().role(clan, target, ClanRole.LEADER);
newRank = "Leader";
}
@ -343,7 +342,7 @@ public class ClansAdmin
if (target == null)
return;
if (clan.getMembers().get(target) == Role.RECRUIT)
if (clan.getMembers().get(target) == ClanRole.RECRUIT)
{
UtilPlayer.message(caller, F.main("Clans Admin", "You cannot demote " + F.name(target) + " any further."));
return;
@ -351,19 +350,19 @@ public class ClansAdmin
//Task
String newRank = "?";
if (clan.getMembers().get(target) == Role.MEMBER)
if (clan.getMembers().get(target) == ClanRole.MEMBER)
{
Clans.getClanDataAccess().role(clan, target, Role.RECRUIT);
Clans.getClanDataAccess().role(clan, target, ClanRole.RECRUIT);
newRank = "Recruit";
}
else if (clan.getMembers().get(target) == Role.ADMIN)
else if (clan.getMembers().get(target) == ClanRole.ADMIN)
{
Clans.getClanDataAccess().role(clan, target, Role.MEMBER);
Clans.getClanDataAccess().role(clan, target, ClanRole.MEMBER);
newRank = "Member";
}
else if (clan.getMembers().get(target) == Role.LEADER)
else if (clan.getMembers().get(target) == ClanRole.LEADER)
{
Clans.getClanDataAccess().role(clan, target, Role.ADMIN);
Clans.getClanDataAccess().role(clan, target, ClanRole.ADMIN);
newRank = "Admin";
}

View File

@ -9,7 +9,6 @@ import org.bukkit.block.BlockFace;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilWorld;
import mineplex.game.clans.clans.ClanInfo.Role;
import mineplex.game.clans.clans.repository.ClanRepository;
import mineplex.game.clans.clans.repository.ClanTerritory;
import mineplex.game.clans.clans.repository.tokens.ClanEnemyToken;
@ -74,7 +73,7 @@ public class ClansDataAccessLayer
return clan;
}
public void join(ClanInfo clan, String player, Role role)
public void join(ClanInfo clan, String player, ClanRole role)
{
if (_manager.getClanMemberMap().containsKey(player))
leave(_manager.getClanUtility().getClanByPlayer(player), player);
@ -108,7 +107,7 @@ public class ClansDataAccessLayer
_manager.log("Removed [" + player + "] from [" + clan.getName() + "].");
}
public void role(ClanInfo clan, String player, Role role)
public void role(ClanInfo clan, String player, ClanRole role)
{
//Update Clan
clan.getMembers().put(player, role);

View File

@ -38,7 +38,6 @@ import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClanInfo.Role;
import mineplex.game.clans.clans.ClansUtility.ClanRelation;
import mineplex.minecraft.game.classcombat.Skill.event.SkillTriggerEvent;
import mineplex.minecraft.game.core.condition.Condition.ConditionType;
@ -223,7 +222,7 @@ public class ClansGame extends MiniPlugin
if (Clans.getClanUtility().isClaimed(event.getBlock().getLocation()))
if (event.getBlock().getTypeId() == 54)
{
if (Clans.getClanUtility().getRole(event.getPlayer()) == Role.RECRUIT)
if (Clans.getClanUtility().getRole(event.getPlayer()) == ClanRole.RECRUIT)
{
//Disallow
event.setCancelled(true);
@ -332,7 +331,7 @@ public class ClansGame extends MiniPlugin
//Recruits cannot open Chests // IN OWN CLAIMED LAND
if (event.getClickedBlock().getTypeId() == 54 && Clans.getClanUtility().getOwner(loc) != null)
{
if (Clans.getClanUtility().getRole(player) == Role.RECRUIT)
if (Clans.getClanUtility().getRole(player) == ClanRole.RECRUIT)
{
//Disallow
event.setCancelled(true);

View File

@ -13,7 +13,6 @@ import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilWorld;
import mineplex.game.clans.clans.ClanInfo.Role;
import mineplex.game.clans.clans.repository.ClanTerritory;
public class ClansUtility
@ -160,7 +159,7 @@ public class ClansUtility
return Clans.getClanMemberMap().get(name);
}
public Role getRole(Player player)
public ClanRole getRole(Player player)
{
try
{
@ -168,7 +167,7 @@ public class ClansUtility
}
catch (Exception e)
{
return Role.NONE;
return ClanRole.NONE;
}
}

View File

@ -18,7 +18,7 @@ import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.recharge.Recharge;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClanInfo.Role;
import mineplex.game.clans.clans.ClanRole;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.ClansUtility.ClanRelation;
import mineplex.game.clans.clans.ClientClan;
@ -284,7 +284,7 @@ public class ClansCommand extends CommandBase<ClansManager>
ClanInfo clan = Plugin.getClanDataAccess().create(caller.getName(), args[1], false);
Plugin.getClanDataAccess().join(clan, caller.getName(), Role.LEADER);
Plugin.getClanDataAccess().join(clan, caller.getName(), ClanRole.LEADER);
}
public void delete(Player caller, String[] args)
@ -297,7 +297,7 @@ public class ClansCommand extends CommandBase<ClansManager>
return;
}
if (Plugin.getClanUtility().getRole(caller) != Role.LEADER)
if (Plugin.getClanUtility().getRole(caller) != ClanRole.LEADER)
{
UtilPlayer.message(caller, F.main("Clans", "Only the Clan Leader can disband the Clan."));
return;
@ -320,8 +320,8 @@ public class ClansCommand extends CommandBase<ClansManager>
return;
}
if (clan.getMembers().get(caller.getName()) != Role.LEADER &&
clan.getMembers().get(caller.getName()) != Role.ADMIN)
if (clan.getMembers().get(caller.getName()) != ClanRole.LEADER &&
clan.getMembers().get(caller.getName()) != ClanRole.ADMIN)
{
UtilPlayer.message(caller, F.main("Clans", "Only the Clan Leader and Admins can send invites."));
return;
@ -392,7 +392,7 @@ public class ClansCommand extends CommandBase<ClansManager>
}
//Task
Plugin.getClanDataAccess().join(clan, caller.getName(), Role.RECRUIT);
Plugin.getClanDataAccess().join(clan, caller.getName(), ClanRole.RECRUIT);
//Inform
UtilPlayer.message(caller, F.main("Clans", "You joined " + F.elem("Clan " + clan.getName()) + "."));
@ -409,7 +409,7 @@ public class ClansCommand extends CommandBase<ClansManager>
return;
}
if (clan.getMembers().get(caller.getName()) == Role.LEADER && clan.getMembers().size() > 1)
if (clan.getMembers().get(caller.getName()) == ClanRole.LEADER && clan.getMembers().size() > 1)
{
UtilPlayer.message(caller, F.main("Clans", "You must pass on " + F.elem("Leadership") + " before leaving."));
return;
@ -454,15 +454,15 @@ public class ClansCommand extends CommandBase<ClansManager>
if (target == null)
return;
if (clan.getMembers().get(caller.getName()) != Role.LEADER &&
clan.getMembers().get(caller.getName()) != Role.ADMIN)
if (clan.getMembers().get(caller.getName()) != ClanRole.LEADER &&
clan.getMembers().get(caller.getName()) != ClanRole.ADMIN)
{
UtilPlayer.message(caller, F.main("Clans", "Only the Clan Leader and Admins can kick members."));
return;
}
if ((clan.getMembers().get(target) == Role.LEADER && clan.getMembers().get(caller.getName()) == Role.ADMIN) ||
(clan.getMembers().get(target) == Role.ADMIN && clan.getMembers().get(caller.getName()) == Role.ADMIN))
if ((clan.getMembers().get(target) == ClanRole.LEADER && clan.getMembers().get(caller.getName()) == ClanRole.ADMIN) ||
(clan.getMembers().get(target) == ClanRole.ADMIN && clan.getMembers().get(caller.getName()) == ClanRole.ADMIN))
{
UtilPlayer.message(caller, F.main("Clans", "You do not outrank " + F.name(target) + "."));
return;
@ -505,7 +505,7 @@ public class ClansCommand extends CommandBase<ClansManager>
return;
}
if (clan.getMembers().get(caller.getName()).toInt() <= clan.getMembers().get(target).toInt())
if (clan.getMembers().get(caller.getName()).ordinal() <= clan.getMembers().get(target).ordinal())
{
UtilPlayer.message(caller, F.main("Clans", "You do not outrank " + F.name(target) + "."));
return;
@ -513,23 +513,23 @@ public class ClansCommand extends CommandBase<ClansManager>
//Task
String newRank = "?";
if (clan.getMembers().get(target) == Role.RECRUIT)
if (clan.getMembers().get(target) == ClanRole.RECRUIT)
{
Plugin.getClanDataAccess().role(clan, target, Role.MEMBER);
Plugin.getClanDataAccess().role(clan, target, ClanRole.MEMBER);
newRank = "Member";
}
else if (clan.getMembers().get(target) == Role.MEMBER)
else if (clan.getMembers().get(target) == ClanRole.MEMBER)
{
Plugin.getClanDataAccess().role(clan, target, Role.ADMIN);
Plugin.getClanDataAccess().role(clan, target, ClanRole.ADMIN);
newRank = "Admin";
}
else if (clan.getMembers().get(target) == Role.ADMIN)
else if (clan.getMembers().get(target) == ClanRole.ADMIN)
{
Plugin.getClanDataAccess().role(clan, target, Role.LEADER);
Plugin.getClanDataAccess().role(clan, target, ClanRole.LEADER);
newRank = "Leader";
//Give Leader
Plugin.getClanDataAccess().role(clan, caller.getName(), Role.ADMIN);
Plugin.getClanDataAccess().role(clan, caller.getName(), ClanRole.ADMIN);
}
//Inform
@ -563,13 +563,13 @@ public class ClansCommand extends CommandBase<ClansManager>
return;
}
if (clan.getMembers().get(caller.getName()).toInt() <= clan.getMembers().get(target).toInt())
if (clan.getMembers().get(caller.getName()).ordinal() <= clan.getMembers().get(target).ordinal())
{
UtilPlayer.message(caller, F.main("Clans", "You do not outrank " + F.name(target) + "."));
return;
}
if (clan.getMembers().get(target) == Role.RECRUIT)
if (clan.getMembers().get(target) == ClanRole.RECRUIT)
{
UtilPlayer.message(caller, F.main("Clans", "You cannot demote " + F.name(target) + " any further."));
return;
@ -577,14 +577,14 @@ public class ClansCommand extends CommandBase<ClansManager>
//Task
String newRank = "?";
if (clan.getMembers().get(target) == Role.MEMBER)
if (clan.getMembers().get(target) == ClanRole.MEMBER)
{
Plugin.getClanDataAccess().role(clan, target, Role.RECRUIT);
Plugin.getClanDataAccess().role(clan, target, ClanRole.RECRUIT);
newRank = "Recruit";
}
else if (clan.getMembers().get(target) == Role.ADMIN)
else if (clan.getMembers().get(target) == ClanRole.ADMIN)
{
Plugin.getClanDataAccess().role(clan, target, Role.MEMBER);
Plugin.getClanDataAccess().role(clan, target, ClanRole.MEMBER);
newRank = "Member";
}
@ -602,7 +602,7 @@ public class ClansCommand extends CommandBase<ClansManager>
return;
}
if (cA.getMembers().get(caller.getName()) != Role.LEADER && cA.getMembers().get(caller.getName()) != Role.ADMIN)
if (cA.getMembers().get(caller.getName()) != ClanRole.LEADER && cA.getMembers().get(caller.getName()) != ClanRole.ADMIN)
{
UtilPlayer.message(caller, F.main("Clans", "Only the Clan Leader and Admins can manage Alliances."));
return;
@ -675,7 +675,7 @@ public class ClansCommand extends CommandBase<ClansManager>
return;
}
if (cA.getMembers().get(caller.getName()) != Role.LEADER && cA.getMembers().get(caller.getName()) != Role.ADMIN)
if (cA.getMembers().get(caller.getName()) != ClanRole.LEADER && cA.getMembers().get(caller.getName()) != ClanRole.ADMIN)
{
UtilPlayer.message(caller, F.main("Clans", "Only the Clan Leader and Admins can manage Trust."));
return;
@ -725,7 +725,7 @@ public class ClansCommand extends CommandBase<ClansManager>
return;
}
if (cA.getMembers().get(caller.getName()) != Role.LEADER && cA.getMembers().get(caller.getName()) != Role.ADMIN)
if (cA.getMembers().get(caller.getName()) != ClanRole.LEADER && cA.getMembers().get(caller.getName()) != ClanRole.ADMIN)
{
UtilPlayer.message(caller, F.main("Clans", "Only the Clan Leader and Admins can manage relationships."));
return;
@ -778,7 +778,7 @@ public class ClansCommand extends CommandBase<ClansManager>
return;
}
if (clan.getMembers().get(caller.getName()) != Role.LEADER && clan.getMembers().get(caller.getName()) != Role.ADMIN)
if (clan.getMembers().get(caller.getName()) != ClanRole.LEADER && clan.getMembers().get(caller.getName()) != ClanRole.ADMIN)
{
UtilPlayer.message(caller, F.main("Clans", "Only the Clan Leader and Admins can claim Territory."));
return;
@ -960,7 +960,7 @@ public class ClansCommand extends CommandBase<ClansManager>
return;
//Role
if (clan.getMembers().get(caller.getName()) != Role.LEADER && clan.getMembers().get(caller.getName()) != Role.ADMIN)
if (clan.getMembers().get(caller.getName()) != ClanRole.LEADER && clan.getMembers().get(caller.getName()) != ClanRole.ADMIN)
{
UtilPlayer.message(caller, F.main("Clans", "Only the Clan Leader and Admins can unclaim Territory."));
return;
@ -1017,7 +1017,7 @@ public class ClansCommand extends CommandBase<ClansManager>
return;
}
if (clan.getMembers().get(caller.getName()) != Role.LEADER)
if (clan.getMembers().get(caller.getName()) != ClanRole.LEADER)
{
UtilPlayer.message(caller, F.main("Clans", "Only the Clan Leader can unclaim all Territory."));
return;
@ -1129,7 +1129,7 @@ public class ClansCommand extends CommandBase<ClansManager>
return;
}
if (clan.getMembers().get(caller.getName()) != Role.LEADER && clan.getMembers().get(caller.getName()) != Role.ADMIN)
if (clan.getMembers().get(caller.getName()) != ClanRole.LEADER && clan.getMembers().get(caller.getName()) != ClanRole.ADMIN)
{
UtilPlayer.message(caller, F.main("Clans", "Only the Clan Leader and Admins can manage Clan Home."));
return;