More work on clans..

Finished ClansDataAccessLayer
Finished ClansAdmin
Finished ClansDisplay
This commit is contained in:
Jonathan Williams 2014-11-19 22:24:36 -08:00
parent 828b866fc1
commit 1a6b80b08e
10 changed files with 1323 additions and 71 deletions

View File

@ -0,0 +1,121 @@
package mineplex.core.common.util;
import java.util.HashSet;
public class UtilInput
{
//Valid Chars
protected static HashSet<Character> validSet = new HashSet<Character>();
protected static HashSet<String> filterSet = new HashSet<String>();
public static boolean valid(String input)
{
if (validSet.isEmpty())
addChars();
for (char cur : input.toCharArray())
if (!validSet.contains(cur))
return false;
return true;
}
public static String filter(String input)
{
if (filterSet.isEmpty())
addDictionary();
for (String cur : filterSet)
{
if (input.equalsIgnoreCase(cur))
{
String out = "" + input.charAt(0);
while (out.length() < input.length())
out += '*';
return out;
}
}
return input;
}
public static void addDictionary()
{
filterSet.add("fuck");
filterSet.add("shit");
filterSet.add("cunt");
filterSet.add("ass");
filterSet.add("asshole");
filterSet.add("faggot");
filterSet.add("fag");
filterSet.add("gay");
}
public static void addChars()
{
validSet.add('1');
validSet.add('2');
validSet.add('3');
validSet.add('4');
validSet.add('5');
validSet.add('6');
validSet.add('7');
validSet.add('8');
validSet.add('9');
validSet.add('0');
validSet.add('a');
validSet.add('b');
validSet.add('c');
validSet.add('d');
validSet.add('e');
validSet.add('f');
validSet.add('g');
validSet.add('h');
validSet.add('i');
validSet.add('j');
validSet.add('k');
validSet.add('l');
validSet.add('m');
validSet.add('n');
validSet.add('o');
validSet.add('p');
validSet.add('q');
validSet.add('r');
validSet.add('s');
validSet.add('t');
validSet.add('u');
validSet.add('v');
validSet.add('w');
validSet.add('x');
validSet.add('y');
validSet.add('z');
validSet.add('A');
validSet.add('B');
validSet.add('C');
validSet.add('D');
validSet.add('E');
validSet.add('F');
validSet.add('G');
validSet.add('H');
validSet.add('I');
validSet.add('J');
validSet.add('K');
validSet.add('L');
validSet.add('M');
validSet.add('N');
validSet.add('O');
validSet.add('P');
validSet.add('Q');
validSet.add('R');
validSet.add('S');
validSet.add('T');
validSet.add('U');
validSet.add('V');
validSet.add('W');
validSet.add('X');
validSet.add('Y');
validSet.add('Z');
}
}

View File

@ -37,6 +37,7 @@ public class ClanInfo
}
}
private int _id = -1;
private String _name = "";
private String _desc = "";
private Location _home = null;
@ -64,6 +65,7 @@ public class ClanInfo
{
Clans = clans;
_id = token.Id;
_name = token.Name;
_desc = token.Description;
@ -370,4 +372,9 @@ public class ClanInfo
{
return _admin;
}
public int getId()
{
return _id;
}
}

View File

@ -0,0 +1,695 @@
package mineplex.game.clans.clans;
import java.util.ArrayList;
import mineplex.core.account.CoreClient;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
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.entity.Player;
public class ClansAdmin
{
private ClansManager Clans;
public ClansAdmin(ClansManager clans)
{
Clans = clans;
}
public void command(Player caller, String[] args)
{
if (args.length == 1)
help(caller);
else if (args[1].equalsIgnoreCase("help") || args[1].equalsIgnoreCase("h"))
help(caller);
else if (args[1].equalsIgnoreCase("set") || args[1].equalsIgnoreCase("mimic"))
setMimic(caller, args);
else if (args[1].equalsIgnoreCase("create"))
create(caller, args);
else if (args[1].equalsIgnoreCase("disband") || args[1].equalsIgnoreCase("delete") || args[1].equalsIgnoreCase("d"))
delete(caller, args);
else if (args[1].equalsIgnoreCase("invite") || args[1].equalsIgnoreCase("i"))
invite(caller, args);
else if (args[1].equalsIgnoreCase("promote"))
promote(caller, args);
else if (args[1].equalsIgnoreCase("demote"))
demote(caller, args);
else if (args[1].equalsIgnoreCase("kick") || args[1].equalsIgnoreCase("k"))
kick(caller, args);
else if (args[1].equalsIgnoreCase("ally") || args[1].equalsIgnoreCase("a"))
ally(caller, args);
else if (args[1].equalsIgnoreCase("trust"))
trust(caller, args);
else if (args[0].equalsIgnoreCase("neutral") || args[0].equalsIgnoreCase("neut") || args[0].equalsIgnoreCase("n"))
neutral(caller, args);
else if (args[1].equalsIgnoreCase("claim") || args[1].equalsIgnoreCase("c"))
claim(caller);
else if (args[1].equalsIgnoreCase("unclaim") || args[1].equalsIgnoreCase("uc"))
unclaim(caller, args);
else if (args[1].equalsIgnoreCase("home") || args[1].equalsIgnoreCase("h"))
home(caller, args);
else if (args[1].equalsIgnoreCase("safe"))
safe(caller);
else if (args[1].equalsIgnoreCase("autoclaim"))
autoclaim(caller);
else
help(caller);
}
private void help(Player caller)
{
UtilPlayer.message(caller, F.main("Clans Admin", "Admin Commands List;"));
UtilPlayer.message(caller, F.help("/c x create <clan>", "Create Admin Clan", Rank.ADMIN));
UtilPlayer.message(caller, F.help("/c x set <clan>", "Set Mimic Clan", Rank.ALL));
UtilPlayer.message(caller, F.help("/c x home (set)", "Teleport to Mimic Home", Rank.ADMIN));
UtilPlayer.message(caller, F.help("/c x invite <player>", "Invite Player to Mimic", Rank.ADMIN));
UtilPlayer.message(caller, F.help("/c x promote <player>", "Promote Player in Mimic", Rank.ADMIN));
UtilPlayer.message(caller, F.help("/c x demote <player>", "Demote Player in Mimic", Rank.ADMIN));
UtilPlayer.message(caller, F.help("/c x kick <player>", "Kick Player from Mimic", Rank.ADMIN));
UtilPlayer.message(caller, F.help("/c x ally <clan>", "Send Alliance to Mimic", Rank.ADMIN));
UtilPlayer.message(caller, F.help("/c x trust <clan>", "Give Trust to Clan", Rank.ADMIN));
UtilPlayer.message(caller, F.help("/c x neutral <clan>", "Set Neutrality", Rank.ADMIN));
UtilPlayer.message(caller, F.help("/c x enemy <clan>", "Start Invasion", Rank.ADMIN));
UtilPlayer.message(caller, F.help("/c x claim", "Claim Territory for Mimic", Rank.ADMIN));
UtilPlayer.message(caller, F.help("/c x unclaim (all)", "Unclaim Territory for Mimic", Rank.ADMIN));
UtilPlayer.message(caller, F.help("/c x delete", "Delete Mimic Clan", Rank.ADMIN));
UtilPlayer.message(caller, F.help("/c x autoclaim", "AutoClaim for Mimic Clan", Rank.ADMIN));
UtilPlayer.message(caller, F.main("Mimic Clan", Clans.Get(caller).getMimic()));
}
private void autoclaim(Player caller)
{
Clans.Get(caller).setAutoClaim(!Clans.Get(caller).isAutoClaim());
UtilPlayer.message(caller, F.main("Clans Admin", F.oo("Auto Claim", Clans.Get(caller).isAutoClaim())));
}
public void setMimic(Player caller, String[] args)
{
if (args.length < 3)
{
if (Clans.Get(caller).getMimic().length() > 0)
{
UtilPlayer.message(caller, F.main("Clans Admin", "You are no longer mimicing " + F.elem("Clan " + Clans.Get(caller).getMimic()) + "."));
Clans.Get(caller).setMimic("");
}
else
UtilPlayer.message(caller, F.main("Clans Admin", "You did not input a Clan/Player."));
return;
}
ClanInfo clan = Clans.getClanUtility().searchClanPlayer(caller, args[2], true);
if (clan == null)
{
UtilPlayer.message(caller, F.main("Clans Admin", "Invalid Clan/Player."));
return;
}
//Set Mimic
Clans.Get(caller).setMimic(clan.getName());
//Inform
UtilPlayer.message(caller, F.main("Clans Admin", "You are mimicing " + F.elem("Clan " + clan.getName()) + "."));
}
public ClanInfo getMimic(Player caller, boolean inform)
{
String mimic = Clans.Get(caller).getMimic();
if (mimic.length() == 0)
return null;
ClanInfo clan = Clans.getClanUtility().searchClanPlayer(caller, mimic, true);
if (clan == null)
{
if (inform)
UtilPlayer.message(caller, F.main("Clans Admin", "You are not mimicing a Clan."));
return null;
}
return clan;
}
public void create(Player caller, String[] args)
{
if (args.length < 3)
{
UtilPlayer.message(caller, F.main("Clans Admin", "You did not input a Clan name."));
return;
}
if (!UtilInput.valid(args[2]))
{
UtilPlayer.message(caller, F.main("Clans Admin", "Invalid characters in Clan name."));
return;
}
if (args[2].length() < Clans.getNameMin())
{
UtilPlayer.message(caller, F.main("Clans Admin", "Clan name too short. Minimum length is " + (Clans.getNameMin()) + "."));
return;
}
if (args[2].length() > Clans.getNameMax())
{
UtilPlayer.message(caller, F.main("Clans Admin", "Clan name too long. Maximum length is + " + (Clans.getNameMax()) + "."));
return;
}
for (String cur : Clans.CCommand().denyClan)
{
if (cur.equalsIgnoreCase(args[2]))
{
UtilPlayer.message(caller, F.main("Clans Admin", "Clan name cannot be a Clan command."));
return;
}
}
for (String cur : Clans.getAll())
{
if (cur.equalsIgnoreCase(args[2]))
{
UtilPlayer.message(caller, F.main("Clans Admin", "Clan name cannot be a Player name."));
return;
}
}
if (Clans.getClan(args[2]) != null)
{
UtilPlayer.message(caller, F.main("Clans Admin", F.elem("Clan " + args[2]) + " already exists."));
return;
}
//Inform
UtilServer.broadcast(F.main("Clans Admin", caller.getName() + " formed " + F.elem("Admin Clan " + args[2]) + "."));
// Create and Join
Clans.getClanDataAccess().create(caller.getName(), args[2], true);
// Set Mimic
Clans.Get(caller).setMimic(args[2]);
// Inform
UtilPlayer.message(caller, F.main("Clans Admin", "You are mimicing Clan " + args[2] + "."));
}
public void delete(Player caller, String[] args)
{
ClanInfo clan = getMimic(caller, true);
if (clan == null)
return;
//Task
Clans.getClanDataAccess().delete(clan);
//Inform
UtilServer.broadcast(F.main("Clans Admin", caller.getName() + " disbanded " + F.elem("Clan " + clan.getName()) + "."));
}
public void invite(Player caller, String[] args)
{
ClanInfo clan = getMimic(caller, true);
if (clan == null)
return;
if (args.length < 3)
{
UtilPlayer.message(caller, F.main("Clans Admin", "You did not input an invitee."));
return;
}
Player target = UtilPlayer.searchOnline(caller, args[2], true);
if (target == null)
return;
if (target.getName().equals(caller.getName()))
{
UtilPlayer.message(caller, F.main("Clans Admin", "You cannot invite yourself."));
return;
}
//Inform
clan.inform(caller.getName() + " invited " + target.getName() + " to join Clan " + clan.getName() + ".", caller.getName());
UtilPlayer.message(caller, F.main("Clans Admin", "You invited " + target.getName() + " to join " + F.elem("Clan " + clan.getName()) + "."));
UtilPlayer.message(target, F.main("Clans Admin", caller.getName() + " invited you to join " + F.elem("Clan " + clan.getName()) + "."));
//Task
Clans.getClanDataAccess().invite(clan, target.getName(), caller.getName());
}
public void promote(Player caller, String[] args)
{
ClanInfo clan = getMimic(caller, true);
if (clan == null)
return;
if (args.length < 3)
{
UtilPlayer.message(caller, F.main("Clans Admin", "You did not input player to promote."));
return;
}
String target = UtilPlayer.searchCollection(caller, args[2], clan.getMembers().keySet(), "Clan Member", true);
if (target == null)
return;
if (clan.getMembers().get(target) == Role.LEADER)
{
UtilPlayer.message(caller, F.main("Clans Admin", "You cannot promote " + F.name(target) + " any further."));
return;
}
//Task
String newRank = "?";
if (clan.getMembers().get(target) == Role.RECRUIT)
{
Clans.getClanDataAccess().role(clan, target, Role.MEMBER);
newRank = "Member";
}
else if (clan.getMembers().get(target) == Role.MEMBER)
{
Clans.getClanDataAccess().role(clan, target, Role.ADMIN);
newRank = "Admin";
}
else if (clan.getMembers().get(target) == Role.ADMIN)
{
Clans.getClanDataAccess().role(clan, target, Role.LEADER);
newRank = "Leader";
}
//Inform
UtilPlayer.message(caller, F.main("Clans Admin", "You promoted " + target + " to " + newRank + " in Mimic Clan."));
clan.inform(caller.getName() + " promoted " + target + " to " + newRank + ".", null);
}
public void demote(Player caller, String[] args)
{
ClanInfo clan = getMimic(caller, true);
if (clan == null)
return;
if (args.length < 3)
{
UtilPlayer.message(caller, F.main("Clans Admin", "You did not input player to demote."));
return;
}
String target = UtilPlayer.searchCollection(caller, args[2], clan.getMembers().keySet(), "Clan Member", true);
if (target == null)
return;
if (clan.getMembers().get(target) == Role.RECRUIT)
{
UtilPlayer.message(caller, F.main("Clans Admin", "You cannot demote " + F.name(target) + " any further."));
return;
}
//Task
String newRank = "?";
if (clan.getMembers().get(target) == Role.MEMBER)
{
Clans.getClanDataAccess().role(clan, target, Role.RECRUIT);
newRank = "Recruit";
}
else if (clan.getMembers().get(target) == Role.ADMIN)
{
Clans.getClanDataAccess().role(clan, target, Role.MEMBER);
newRank = "Member";
}
else if (clan.getMembers().get(target) == Role.LEADER)
{
Clans.getClanDataAccess().role(clan, target, Role.ADMIN);
newRank = "Admin";
}
//Inform
UtilPlayer.message(caller, F.main("Clans Admin", "You demoted " + target + " to " + newRank + " in Mimic Clan."));
clan.inform(F.main("Clans Admin", caller.getName() + " demoted " + target + " to " + newRank + "."), null);
}
public void kick(Player caller, String[] args)
{
ClanInfo clan = getMimic(caller, true);
if (clan == null)
return;
if (args.length < 3)
{
UtilPlayer.message(caller, F.main("Clans Admin", "You did not input a Player to kick."));
return;
}
String targetName = UtilPlayer.searchCollection(caller, args[2], clan.getMembers().keySet(), "Clan Member", true);
if (targetName == null)
return;
//Task
Clans.getClanDataAccess().leave(clan, targetName);
//Inform
UtilPlayer.message(UtilPlayer.searchOnline(null, targetName, false), F.main("Clans Admin", caller.getName() + " kicked you from " + F.elem("Clan " + clan.getName()) + "."));
UtilPlayer.message(caller, F.main("Clans Admin", "You kicked " + targetName + " from your Clan."));
clan.inform(F.main("Clans Admin", caller.getName() + " kicked " + targetName + " from your Clan."), caller.getName());
}
public void ally(Player caller, String[] args)
{
ClanInfo cA = getMimic(caller, true);
if (cA == null)
return;
if (args.length < 3)
{
UtilPlayer.message(caller, F.main("Clans Admin", "You did not input a Clan to ally."));
return;
}
ClanInfo cB = Clans.getClanUtility().searchClanPlayer(caller, args[2], true);
if (cB == null)
return;
if (cA.isSelf(cB.getName()))
{
UtilPlayer.message(caller, F.main("Clans Admin", "You cannot ally with yourself."));
return;
}
if (cA.isAlly(cB.getName()))
{
UtilPlayer.message(caller, F.main("Clans Admin", "You are already allies with " + F.elem("Clan " + cB.getName()) + "."));
return;
}
if (cB.isRequested(cA.getName()))
{
//Task
Clans.getClanDataAccess().ally(cA, cB, caller.getName());
//Inform
UtilPlayer.message(caller, F.main("Clans Admin", "You accepted alliance with Clan " + cB.getName() + "."));
cA.inform(caller.getName() + " accepted alliance with Clan " + cB.getName() + ".", caller.getName());
cB.inform("Clan " + cA.getName() + " has accepted alliance with you.", null);
}
else
{
//Task
Clans.getClanDataAccess().requestAlly(cA, cB, caller.getName());
//Inform
UtilPlayer.message(caller, F.main("Clans Admin", "You requested alliance with Clan " + cB.getName() + "."));
cA.inform(caller.getName() + " has requested alliance with Clan " + cB.getName() + ".", caller.getName());
cB.inform("Clan " + cA.getName() + " has requested alliance with you.", null);
}
}
public void trust(Player caller, String[] args)
{
ClanInfo cA = getMimic(caller, true);
if (cA == null)
return;
if (args.length < 3)
{
UtilPlayer.message(caller, F.main("Clans Admin", "You did not input a Clan to enemy."));
return;
}
ClanInfo cB = Clans.getClanUtility().searchClanPlayer(caller, args[2], true);
if (cB == null)
return;
if (!cA.isAlly(cB.getName()))
{
UtilPlayer.message(caller, F.main("Clans Admin", "You cannot give trust to enemies."));
return;
}
//Task
if (Clans.getClanDataAccess().trust(cA, cB, caller.getName()))
{
//Inform
UtilPlayer.message(caller, F.main("Clans Admin", "You gave trust to Clan " + cB.getName() + "."));
cA.inform(caller.getName() + " has given trust to Clan " + cB.getName() + ".", caller.getName());
cB.inform("Clan " + cA.getName() + " has given trust to you.", null);
}
else
{
//Inform
UtilPlayer.message(caller, F.main("Clans Admin", "You revoked trust to Clan " + cB.getName() + "."));
cA.inform(caller.getName() + " has revoked trust to Clan " + cB.getName() + ".", caller.getName());
cB.inform("Clan " + cA.getName() + " has revoked trust to you.", null);
}
}
public void neutral(Player caller, String[] args)
{
ClanInfo cA = getMimic(caller, true);
if (cA == null)
return;
if (args.length < 2)
{
UtilPlayer.message(caller, F.main("Clans", "You did not input a Clan to set neutrality with."));
return;
}
ClanInfo cB = Clans.getClanUtility().searchClanPlayer(caller, args[1], true);
if (cB == null)
return;
if (cB.isSelf(cA.getName()))
{
UtilPlayer.message(caller, F.main("Clans", "You prefer to think of yourself positively..."));
return;
}
if (cB.isNeutral(cA.getName()))
{
UtilPlayer.message(caller, F.main("Clans", "You are already neutral with " + F.elem("Clan " + cB.getName()) + "."));
return;
}
if (cB.isAlly(cA.getName()))
{
//Task
Clans.getClanDataAccess().neutral(cA, cB, caller.getName(), true);
//Inform
UtilPlayer.message(caller, F.main("Clans", "You revoked alliance with " + F.elem("Clan " + cB.getName()) + "."));
cA.inform(F.name(caller.getName()) + " revoked alliance with " + F.elem("Clan " + cB.getName()) + ".", caller.getName());
cB.inform(F.elem("Clan " + cA.getName()) + " has revoked alliance with you.", null);
return;
}
}
public void claim(Player caller)
{
ClanInfo clientClan = getMimic(caller, true);
if (clientClan == null)
return;
if (clientClan.getClaims() >= clientClan.getClaimsMax())
{
UtilPlayer.message(caller, F.main("Clans Admin", "Your Clan cannot claim more Territory."));
return;
}
String chunk = UtilWorld.chunkToStr(caller.getLocation().getChunk());
ClanInfo ownerClan = Clans.getClanUtility().getOwner(caller.getLocation());
//Already Claimed
if (ownerClan != null)
{
UtilPlayer.message(caller, F.main("Clans Admin", "This Territory is claimed by " +
Clans.getClanUtility().mRel(Clans.getClanUtility().relPC(caller.getName(), ownerClan), ownerClan.getName(), true) + "."));
return;
}
//Task
Clans.getClanDataAccess().claim(clientClan.getName(), chunk, caller.getName(), false);
//Inform
UtilPlayer.message(caller, F.main("Clans Admin", "You claimed Territory " + F.elem(UtilWorld.chunkToStrClean(caller.getLocation().getChunk())) + "."));
clientClan.inform(caller.getName() + " claimed Territory " + F.elem(UtilWorld.chunkToStrClean(caller.getLocation().getChunk())) + ".", caller.getName());
}
public void unclaim(Player caller, String args[])
{
if (args.length > 2)
{
if (args[2].equalsIgnoreCase("all") || args[2].equalsIgnoreCase("a"))
{
unclaimall(caller);
return;
}
}
ClanInfo clientClan = getMimic(caller, true);
if (clientClan == null)
return;
String chunk = UtilWorld.chunkToStr(caller.getLocation().getChunk());
ClanInfo ownerClan = Clans.getClanUtility().getOwner(caller.getLocation());
//Not Claimed
if (ownerClan == null)
{
UtilPlayer.message(caller, F.main("Clans Admin", "Territory is not claimed."));
return;
}
//Task
Clans.getClanDataAccess().unclaim(chunk, caller.getName(), true);
//Inform
UtilPlayer.message(caller, F.main("Clans Admin", "You unclaimed Territory " + F.elem(UtilWorld.chunkToStrClean(caller.getLocation().getChunk())) + "."));
ownerClan.inform(caller.getName() + " unclaimed Territory " + F.elem(UtilWorld.chunkToStrClean(caller.getLocation().getChunk())) + ".", caller.getName());
}
public void unclaimall(Player caller)
{
ClanInfo clientClan = getMimic(caller, true);
if (clientClan == null)
return;
//Unclaim
ArrayList<String> toUnclaim = new ArrayList<String>();
for (String chunk : clientClan.getClaimSet())
toUnclaim.add(chunk);
for (String chunk : toUnclaim)
Clans.getClanDataAccess().unclaim(chunk, caller.getName(), true);
//Inform
UtilPlayer.message(caller, F.main("Clans Admin", "You unclaimed all your Clans Territory."));
clientClan.inform(caller.getName() + " unclaimed all your Clans Territory.", caller.getName());
}
public void home(Player caller, String[] args)
{
if (args.length > 2)
{
if (args[2].equalsIgnoreCase("set") || args[2].equalsIgnoreCase("s"))
{
homeSet(caller);
return;
}
}
ClanInfo clan = getMimic(caller, true);
if (clan == null)
return;
if (clan.getHome() == null)
{
UtilPlayer.message(caller, F.main("Clans Admin", "Your Clan has not set a Home."));
return;
}
if (!clan.getClaimSet().contains(UtilWorld.chunkToStr(clan.getHome().getChunk())))
{
UtilPlayer.message(caller, F.main("Clans Admin", "Your Clan has lost its Home Territory."));
return;
}
//Do
Clans.getTeleport().TP(caller, clan.getHome());
//Inform
UtilPlayer.message(caller, F.main("Clans Admin", "You teleported to your Clan Home " + UtilWorld.locToStrClean(caller.getLocation()) + "."));
}
public void homeSet(Player caller)
{
ClanInfo clan = getMimic(caller, true);
if (clan == null)
return;
if (Clans.getClanUtility().getOwner(caller.getLocation()) == null)
{
UtilPlayer.message(caller, F.main("Clans Admin", "You must set your Clan Home in your own Territory."));
return;
}
if (!Clans.getClanUtility().getOwner(caller.getLocation()).isSelf(clan.getName()))
{
UtilPlayer.message(caller, F.main("Clans Admin", "You must set your Clan Home in your own Territory."));
return;
}
//Task
Clans.getClanDataAccess().home(clan, caller.getLocation(), caller.getName());
//Inform
UtilPlayer.message(caller, F.main("Clans Admin", "You set Clan Home to " + UtilWorld.locToStrClean(caller.getLocation()) + "."));
clan.inform(caller.getName() + " set Clan Home to " + UtilWorld.locToStrClean(caller.getLocation()) + ".", caller.getName());
}
public void safe(Player caller)
{
ClanTerritory claim = Clans.getClanUtility().getClaim(caller.getLocation());
if (claim == null)
{
UtilPlayer.message(caller, F.main("Clans Admin", "You can only Safe Zone on Claimed Territory."));
return;
}
//Set
Clans.getClanDataAccess().safe(claim, caller.getName());
//Inform
UtilPlayer.message(caller, F.main("Clans Admin", "Territory Safe Zone: " + F.tf(claim.Safe)));
}
}

View File

@ -7,7 +7,6 @@ import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import mineplex.core.account.CoreClient;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilWorld;
import mineplex.game.clans.clans.ClanInfo.Role;
@ -92,7 +91,7 @@ public class ClansDataAccessLayer
clan.getInviterMap().remove(player);
//Save
_repository.addMember(clan.getName(), player);
_repository.addMember(clan.getId(), player, role.toString());
//Log
_manager.log("Added [" + player + "] to [" + clan.getName() + "].");
@ -108,7 +107,7 @@ public class ClansDataAccessLayer
_manager.getClanMemberMap().remove(player);
//Save
_repository.removeMember(clan.getName(), player);
_repository.removeMember(clan.getId(), player);
//Log
_manager.log("Removed [" + player + "] from [" + clan.getName() + "].");
@ -120,7 +119,7 @@ public class ClansDataAccessLayer
clan.getMembers().put(player, role);
//Save
_repository.updateMember(clan.getName(), player, role);
_repository.updateMember(clan.getId(), player, role.toString());
//Log
_manager.log("Removed [" + player + "] from [" + clan.getName() + "].");
@ -154,8 +153,8 @@ public class ClansDataAccessLayer
cB.getAllyMap().put(cA.getName(), false);
//Save
_manager.CRepo().EditClan(cA.GetToken());
_manager.CRepo().EditClan(cB.GetToken());
_repository.addClanRelationship(cA.getId(), cB.getId(), true);
_repository.addClanRelationship(cB.getId(), cA.getId(), true);
//Log
_manager.log("Added Ally for [" + cB.getName() + "] and [" + cA.getName() + "] by [" + player + "].");
@ -172,16 +171,8 @@ public class ClansDataAccessLayer
cA.getAllyMap().put(cB.getName(), trust);
//Save
_manager.CRepo().EditClan(cA.GetToken());
_manager.CRepo().EditClan(cB.GetToken());
//Update Relations
for (String cur : cA.getMembers().keySet())
_manager.getClanUtility().updateRelations(cur);
//Update Relations
for (String cur : cB.getMembers().keySet())
_manager.getClanUtility().updateRelations(cur);
_repository.updateClanRelationship(cA.getId(), cB.getId(), true);
_repository.updateClanRelationship(cB.getId(), cA.getId(), true);
//Log
_manager.log("Gave Trust [" + trust + "] to [" + cB.getName() + "] for [" + cA.getName() + "] by [" + player + "].");
@ -196,21 +187,14 @@ public class ClansDataAccessLayer
cB.getAllyMap().remove(cA.getName());
//Save
_manager.CRepo().EditClan(cA.GetToken());
_manager.CRepo().EditClan(cB.GetToken());
//Update Relations
for (String cur : cA.getMembers().keySet())
_manager.getClanUtility().updateRelations(cur);
//Update Relations
for (String cur : cB.getMembers().keySet())
_manager.getClanUtility().updateRelations(cur);
_repository.removeClanRelationship(cA.getId(), cB.getId());
_repository.removeClanRelationship(cB.getId(), cA.getId());
//Log
_manager.log("Added Neutral between [" + cA.getName() + "] and [" + cB.getName() + "] by [" + player + "].");
}
@SuppressWarnings("deprecation")
public boolean claim(String name, String chunk, String player, boolean safe)
{
if (!_manager.getClanMap().containsKey(name))
@ -223,16 +207,18 @@ public class ClansDataAccessLayer
unclaim(chunk, player, false);
//Memory
ClanTerritory claim = new ClanTerritory(_manager, name, chunk, safe);
ClanTerritory claim = new ClanTerritory();
claim.Owner = name;
claim.Safe = safe;
clan.getClaimSet().add(chunk);
_manager.getClaimMap().put(chunk, claim);
//Save
_manager.CRepo().EditClan(clan.GetToken());
_repository.addTerritoryClaim(clan.getId(), chunk, safe);
//Visual
Chunk c = UtilWorld.strToChunk(chunk);
if (!clan.IsAdmin())
if (!clan.isAdmin())
for (int i = 0 ; i < 3 ; i++)
for (int x=0 ; x < 16 ; x++)
for (int z=0 ; z < 16 ; z++)
@ -241,7 +227,7 @@ public class ClansDataAccessLayer
Block down = UtilBlock.getHighest(c.getWorld(), c.getBlock(x, 0, z).getX(), c.getBlock(x, 0, z).getZ()).getRelative(BlockFace.DOWN);
if (down.getTypeId() == 1 || down.getTypeId() == 2 || down.getTypeId() == 3 || down.getTypeId() == 12 || down.getTypeId() == 8)
_manager.BlockRestore().Add(down, 89, (byte)0, 180000);
_manager.getBlockRestore().Add(down, 89, (byte)0, 180000);
}
//Log
@ -272,10 +258,10 @@ public class ClansDataAccessLayer
clan.getClaimSet().remove(chunk);
//Save
_manager.CRepo().EditClan(clan.GetToken());
_repository.removeTerritoryClaim(clan.getId(), chunk);
//Register
_manager.getUnclaimMap().put(chunk, System.currentTimeMillis());
// _manager.getUnclaimMap().put(chunk, System.currentTimeMillis());
//Log
_manager.log("Removed Claim for [" + clan.getName() + "] at [" + chunk + "] by [" + player + "].");
@ -286,10 +272,10 @@ public class ClansDataAccessLayer
public void home(ClanInfo clan, Location loc, String player)
{
//Memory
clan.SetHome(loc);
clan.setHome(loc);
//Save
_manager.CRepo().EditClan(clan.GetToken());
_repository.updateClan(clan.getId(), clan.getName(), clan.getDesc(), UtilWorld.locToStr(clan.getHome()), clan.isAdmin(), clan.getLastOnline());
//Log
_manager.log("Set Home for [" + clan.getName() + "] to " + UtilWorld.locToStrClean(loc) + " by [" + player + "].");
@ -301,9 +287,9 @@ public class ClansDataAccessLayer
claim.Safe = !claim.Safe;
//Save
_manager.CRepo().EditClan(_manager.getClan(claim.Owner).GetToken());
_repository.updateTerritoryClaim(claim.Chunk, claim.Safe);
//Log
_manager.log("Safe Zone at [" + claim.chunk + "] set to [" + claim.Safe + "] by [" + player + "].");
_manager.log("Safe Zone at [" + claim.Chunk + "] set to [" + claim.Safe + "] by [" + player + "].");
}
}

View File

@ -0,0 +1,251 @@
package mineplex.game.clans.clans;
import java.util.LinkedList;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.recharge.Recharge;
import mineplex.game.clans.clans.ClansUtility.ClanRelation;
import mineplex.game.clans.clans.repository.ClanTerritory;
import org.bukkit.Chunk;
import org.bukkit.Material;
import org.bukkit.World.Environment;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerInteractEvent;
public class ClansDisplay
{
private ClansManager Clans;
public ClansDisplay(ClansManager clans)
{
Clans = clans;
}
public void Update(Player player)
{
if (player.getWorld().getEnvironment() != Environment.NORMAL)
return;
ClientClan client = Clans.Get(player);
if (client == null) return;
//Same Chunk
if (client.getTerritory().equals(UtilWorld.chunkToStr(player.getLocation().getChunk())))
return;
//Update Territory
client.setTerritory(UtilWorld.chunkToStr(player.getLocation().getChunk()));
//AutoClaim
if (client.isAutoClaim())
Clans.getClanAdmin().claim(player);
//Map
String owner = "?";
ClanInfo ownerClan = Clans.getClanUtility().getOwner(player.getLocation());
if (ownerClan != null)
owner = ownerClan.getName();
boolean safe = Clans.getClanUtility().isSafe(player);
if (!client.isMapOn())
{
boolean showChange = false;
//Owner Change
if (!client.getOwner().equals(owner))
{
client.setOwner(owner);
showChange = true;
}
//Safe Change
if (safe != client.isSafe())
{
client.setSafe(safe);
showChange = true;
}
if (showChange)
displayOwner(player);
}
else
{
displayOwner(player);
displayMap(player);
}
}
public void displayOwner(Player player)
{
//Name
String ownerString = C.xWilderness + "Wilderness";
ClanTerritory claim = Clans.getClanUtility().getClaim(player.getLocation());
String append = "";
if (claim != null)
{
//Relation
ClanRelation relation = Clans.getClanUtility().relPT(player.getName(), claim.Chunk);
//Name
ownerString = Clans.getClanUtility().mRel(relation, claim.Owner, false);
//Trust
if (relation == ClanRelation.ALLY_TRUST)
append = C.mBody + "(" + C.mElem + "Trusted" + C.mBody + ")";
}
UtilPlayer.message(player, F.main("Clans", ownerString + " " + append));
}
public int width = 8;
public int height = 4;
public void displayMap(Player player)
{
if (player.getWorld().getEnvironment().equals(Environment.NETHER))
return;
//Get Local
LinkedList<String> local = mLocalMap(player, player.getLocation().getChunk(), true);
//Get Home
LinkedList<String> home = null;
if (player.getItemInHand().getType() == Material.MAP)
{
ClanInfo clan = Clans.getClanUtility().getClanByPlayer(player);
if (clan != null)
if (clan.getHome() != null)
home = mLocalMap(player, clan.getHome().getChunk(), false);
}
//Display
if (home == null || local.size() != home.size())
UtilPlayer.message(player, local);
else
for (int i = 0 ; i < local.size() ; i++)
UtilPlayer.message(player, local.get(i) + " " + home.get(i));
}
public LinkedList<String> mLocalMap(Player player, Chunk chunk, boolean local)
{
if (chunk == null)
return null;
LinkedList<String> localMap = new LinkedList<String>();
for (int i=(chunk.getX()-height) ; i <= (chunk.getX()+height) ; i++)
{
String output = C.xNone + "<";
for (int j=(chunk.getZ()+width) ; j >= (chunk.getZ()-width) ; j--)
{
Chunk curChunk = player.getWorld().getChunkAt(i, j);
//Count Players
int pCount = 0;
if (player.getItemInHand().getType() == Material.MAP)
{
for (Player cur : UtilServer.getPlayers())
if (cur.getLocation().getChunk().toString().equals(curChunk.toString()))
pCount++;
}
//Get Data
ClanInfo curOwner = Clans.getClanUtility().getOwner(UtilWorld.chunkToStr(curChunk));
ClanTerritory curClaim = Clans.getClanUtility().getClaim(UtilWorld.chunkToStr(curChunk));
//Add Icon
if (i == chunk.getX() && j == chunk.getZ())
output += getMapIcon(Clans.getClanUtility().relPC(player.getName(), curOwner), curClaim, curOwner, curChunk, pCount, true, local);
else
output += getMapIcon(Clans.getClanUtility().relPC(player.getName(), curOwner), curClaim, curOwner, curChunk, pCount, false, local);
}
output += ">";
//Send
localMap.add(output);
}
return localMap;
}
public String getMapIcon(ClanRelation relation, ClanTerritory claim, ClanInfo owner, Chunk chunk, int players, boolean mid, boolean local)
{
if (players > 9)
players = 9;
if (mid && local)
{
if (players > 0) return "" + C.cWhite + players;
else return "" + C.cWhite + "X";
}
if (owner == null || claim == null)
{
if (players > 0) return "" + C.xNone + players;
else return "" + C.xNone + "-";
}
if (claim.Safe)
{
if (players > 0) return "" + C.xSafe + players;
else return "" + C.xSafe + "S";
}
if (owner.isAdmin())
{
if (players > 0) return "" + C.xAdmin + players;
else return "" + C.xAdmin + "+";
}
if (relation == ClanRelation.SELF)
{
if (players > 0) return "" + C.xSelf + players;
else if (Clans.getClanUtility().isChunkHome(owner, chunk)) return "" + C.xSelf + "H";
else return "" + C.xSelf + "#";
}
if (relation == ClanRelation.ALLY)
{
if (players > 0) return "" + C.xAlly + players;
else if (Clans.getClanUtility().isChunkHome(owner, chunk)) return "" + C.xAlly + "H";
else return "" + C.xAlly + "#";
}
if (relation == ClanRelation.ALLY_TRUST)
{
if (players > 0) return "" + C.xdAlly + players;
else if (Clans.getClanUtility().isChunkHome(owner, chunk)) return "" + C.xdAlly + "H";
else return "" + C.xdAlly + "#";
}
if (players > 0) return "" + C.xEnemy + players;
else if (Clans.getClanUtility().isChunkHome(owner, chunk)) return "" + C.xEnemy + "H";
else return "" + C.xEnemy + "#";
}
public void handleInteract(PlayerInteractEvent event)
{
if (event.getPlayer().getItemInHand().getType() != Material.MAP)
return;
if (!Recharge.Instance.use(event.getPlayer(), "Clan Map", 500, false, false))
return;
displayOwner(event.getPlayer());
displayMap(event.getPlayer());
}
}

View File

@ -24,6 +24,7 @@ import mineplex.core.MiniClientPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClient;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap;
@ -33,6 +34,7 @@ import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilEvent.ActionType;
import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.creature.event.CreatureSpawnCustomEvent;
import mineplex.core.teleport.Teleport;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.repository.ClanTerritory;
@ -43,6 +45,11 @@ public class ClansManager extends MiniClientPlugin<ClientClan>
{
private CombatManager _combatManager;
private ClansUtility _clanUtility;
private ClansDataAccessLayer _clanDataAccess;
private ClansDisplay _clanDisplay;
private ClansAdmin _clanAdmin;
private BlockRestore _blockRestore;
private Teleport _teleport;
private int _dominanceLimit = 16;
private int _inviteExpire = 2;
@ -57,12 +64,17 @@ public class ClansManager extends MiniClientPlugin<ClientClan>
private NautHashMap<String, ClanTerritory> _claimMap = new NautHashMap<String, ClanTerritory>();
private NautHashMap<String, Long> _unclaimMap = new NautHashMap<String, Long>();
public ClansManager(JavaPlugin plugin, CombatManager combatManager)
public ClansManager(JavaPlugin plugin, CombatManager combatManager, BlockRestore blockRestore, Teleport teleport)
{
super("Clans Manager", plugin);
_combatManager = combatManager;
_clanUtility = new ClansUtility(this);
_blockRestore = blockRestore;
_teleport = teleport;
_clanDataAccess = new ClansDataAccessLayer(this);
_clanDisplay = new ClansDisplay(this);
_clanAdmin = new ClansAdmin(this);
}
public int getInviteExpire()
@ -111,11 +123,6 @@ public class ClansManager extends MiniClientPlugin<ClientClan>
CCommand().command(caller, args);
}
public ClansClan getClan(String name)
{
return GetClanMap().get(name);
}
@EventHandler
public void Update(UpdateEvent event)
{
@ -402,4 +409,34 @@ public class ClansManager extends MiniClientPlugin<ClientClan>
protected void loadClientInformation(RetrieveClientInformationEvent event)
{
}
public BlockRestore getBlockRestore()
{
return _blockRestore;
}
public ClansDataAccessLayer getClanDataAccess()
{
return _clanDataAccess;
}
public Teleport getTeleport()
{
return _teleport;
}
public ClansDisplay getClanDisplay()
{
return _clanDisplay;
}
public NautHashMap<String, Long> getUnclaimMap()
{
return _unclaimMap;
}
public ClansAdmin getClanAdmin()
{
return _clanAdmin;
}
}

View File

@ -9,6 +9,12 @@ public class ClientClan
private boolean _canJoin;
private long _joinDelay;
private String _territory;
private boolean _autoClaim;
private String _owner;
private boolean _safe;
private String _mimic;
public boolean isAllyChat()
{
return _allyChat;
@ -48,4 +54,54 @@ public class ClientClan
{
return _joinDelay;
}
public String getTerritory()
{
return _territory;
}
public void setTerritory(String territory)
{
_territory = territory;
}
public boolean isAutoClaim()
{
return _autoClaim;
}
public String getOwner()
{
return _owner;
}
public void setOwner(String owner)
{
_owner = owner;
}
public boolean isSafe()
{
return _safe;
}
public void setSafe(boolean safe)
{
_safe = safe;
}
public void setAutoClaim(boolean autoclaim)
{
_autoClaim = autoclaim;
}
public void setMimic(String mimic)
{
_mimic = mimic;
}
public String getMimic()
{
return _mimic;
}
}

View File

@ -5,11 +5,11 @@ import java.util.ArrayList;
import org.bukkit.Chunk;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClient;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilInput;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
@ -50,7 +50,7 @@ public class ClansCommand extends CommandBase<ClansManager>
help(caller);
else if (args[0].equalsIgnoreCase("admin") || args[0].equalsIgnoreCase("x"))
Plugin.CAdmin().command(caller, args);
Plugin.getClanAdmin().command(caller, args);
else if (args[0].equalsIgnoreCase("create"))
create(caller, args);
@ -204,7 +204,7 @@ public class ClansCommand extends CommandBase<ClansManager>
return;
}
if (!Plugin.Util().Input().valid(args[1]))
if (!UtilInput.valid(args[1]))
{
UtilPlayer.message(caller, F.main("Clans", "Invalid characters in Clan name."));
return;
@ -243,8 +243,10 @@ public class ClansCommand extends CommandBase<ClansManager>
//Inform
UtilServer.broadcast(F.main("Clans", F.name(caller.getName()) + " formed " + F.elem("Clan " + args[1]) + "."));
//Create and Join
Plugin.CTask().join(Plugin.CTask().create(caller.getName(), args[1], false), caller.getName(), Role.LEADER);
ClanInfo clan = Plugin.getClanDataAccess().create(caller.getName(), args[1], false);
Plugin.getClanDataAccess().join(clan, caller.getName(), Role.LEADER);
}
public void delete(Player caller, String[] args)
@ -264,7 +266,7 @@ public class ClansCommand extends CommandBase<ClansManager>
}
//Task
Plugin.CTask().delete(clan);
Plugin.getClanDataAccess().delete(clan);
//Inform
UtilServer.broadcast(F.main("Clans", F.name(caller.getName()) + " disbanded " + F.elem("Clan " + clan.getName()) + "."));
@ -310,7 +312,7 @@ public class ClansCommand extends CommandBase<ClansManager>
UtilPlayer.message(target, F.main("Clans", "Type " + F.elem("/c join " + clan.getName()) + " to accept!"));
//Task
Plugin.CTask().invite(clan, target.getName(), caller.getName());
Plugin.getClanDataAccess().invite(clan, target.getName(), caller.getName());
}
public void join(Player caller, String[] args)
@ -337,7 +339,7 @@ public class ClansCommand extends CommandBase<ClansManager>
return;
}
if (!Plugin.Util().Input().valid(args[1]))
if (!UtilInput.valid(args[1]))
{
UtilPlayer.message(caller, F.main("Clans", "Invalid characters in Clan name."));
return;
@ -354,7 +356,7 @@ public class ClansCommand extends CommandBase<ClansManager>
}
//Task
Plugin.CTask().join(clan, caller.getName(), Role.RECRUIT);
Plugin.getClanDataAccess().join(clan, caller.getName(), Role.RECRUIT);
//Inform
UtilPlayer.message(caller, F.main("Clans", "You joined " + F.elem("Clan " + clan.getName()) + "."));
@ -384,7 +386,7 @@ public class ClansCommand extends CommandBase<ClansManager>
UtilPlayer.message(caller, F.main("Clans", "You left " + F.elem("Clan " + clan.getName()) + "."));
//Task
Plugin.CTask().leave(clan, caller.getName());
Plugin.getClanDataAccess().leave(clan, caller.getName());
//Inform
clan.inform(F.name(caller.getName()) + " has left your Clan.", null);
@ -432,7 +434,7 @@ public class ClansCommand extends CommandBase<ClansManager>
//Task
Plugin.CTask().leave(clan, target);
Plugin.getClanDataAccess().leave(clan, target);
//Inform
UtilPlayer.message(UtilPlayer.searchOnline(null, target, false), F.main("Clans", F.name(caller.getName()) + " kicked you from " + F.elem("Clan " + clan.getName()) + "."));
@ -477,21 +479,21 @@ public class ClansCommand extends CommandBase<ClansManager>
String newRank = "?";
if (clan.getMembers().get(target) == Role.RECRUIT)
{
Plugin.CTask().role(clan, target, Role.MEMBER);
Plugin.getClanDataAccess().role(clan, target, Role.MEMBER);
newRank = "Member";
}
else if (clan.getMembers().get(target) == Role.MEMBER)
{
Plugin.CTask().role(clan, target, Role.ADMIN);
Plugin.getClanDataAccess().role(clan, target, Role.ADMIN);
newRank = "Admin";
}
else if (clan.getMembers().get(target) == Role.ADMIN)
{
Plugin.CTask().role(clan, target, Role.LEADER);
Plugin.getClanDataAccess().role(clan, target, Role.LEADER);
newRank = "Leader";
//Give Leader
Plugin.CTask().role(clan, caller.getName(), Role.ADMIN);
Plugin.getClanDataAccess().role(clan, caller.getName(), Role.ADMIN);
}
//Inform
@ -541,12 +543,12 @@ public class ClansCommand extends CommandBase<ClansManager>
String newRank = "?";
if (clan.getMembers().get(target) == Role.MEMBER)
{
Plugin.CTask().role(clan, target, Role.RECRUIT);
Plugin.getClanDataAccess().role(clan, target, Role.RECRUIT);
newRank = "Recruit";
}
else if (clan.getMembers().get(target) == Role.ADMIN)
{
Plugin.CTask().role(clan, target, Role.MEMBER);
Plugin.getClanDataAccess().role(clan, target, Role.MEMBER);
newRank = "Member";
}
@ -608,7 +610,7 @@ public class ClansCommand extends CommandBase<ClansManager>
if (cB.isRequested(cA.getName()))
{
//Task
Plugin.CTask().ally(cA, cB, caller.getName());
Plugin.getClanDataAccess().ally(cA, cB, caller.getName());
//Inform
UtilPlayer.message(caller, F.main("Clans", "You accepted alliance with " + F.elem("Clan " + cB.getName()) + "."));
@ -618,7 +620,7 @@ public class ClansCommand extends CommandBase<ClansManager>
else
{
//Task
Plugin.CTask().requestAlly(cA, cB, caller.getName());
Plugin.getClanDataAccess().requestAlly(cA, cB, caller.getName());
//Inform
UtilPlayer.message(caller, F.main("Clans", "You requested alliance with " + F.elem("Clan " + cB.getName()) + "."));
@ -661,7 +663,7 @@ public class ClansCommand extends CommandBase<ClansManager>
}
//Task
if (Plugin.CTask().trust(cA, cB, caller.getName()))
if (Plugin.getClanDataAccess().trust(cA, cB, caller.getName()))
{
//Inform
UtilPlayer.message(caller, F.main("Clans", "You gave trust to " + F.elem("Clan " + cB.getName()) + "."));
@ -719,7 +721,7 @@ public class ClansCommand extends CommandBase<ClansManager>
if (cB.isAlly(cA.getName()))
{
//Task
Plugin.CTask().neutral(cA, cB, caller.getName(), true);
Plugin.getClanDataAccess().neutral(cA, cB, caller.getName(), true);
//Inform
UtilPlayer.message(caller, F.main("Clans", "You revoked alliance with " + F.elem("Clan " + cB.getName()) + "."));
@ -864,7 +866,7 @@ public class ClansCommand extends CommandBase<ClansManager>
return;
//Task
Plugin.CTask().claim(clan.getName(), chunk, caller.getName(), false);
Plugin.getClanDataAccess().claim(clan.getName(), chunk, caller.getName(), false);
//Inform
UtilPlayer.message(caller, F.main("Clans", "You claimed Territory " + F.elem(UtilWorld.chunkToStrClean(caller.getLocation().getChunk())) + "."));
@ -936,7 +938,7 @@ public class ClansCommand extends CommandBase<ClansManager>
}
//Task
Plugin.CTask().unclaim(chunk, caller.getName(), true);
Plugin.getClanDataAccess().unclaim(chunk, caller.getName(), true);
//Inform
UtilPlayer.message(caller, F.main("Clans", "You unclaimed Territory " + F.elem(UtilWorld.chunkToStrClean(caller.getLocation().getChunk())) + "."));
@ -964,7 +966,7 @@ public class ClansCommand extends CommandBase<ClansManager>
F.elem(ownerClan.getName()) + " at " + F.elem(UtilWorld.locToStrClean(caller.getLocation())) + "."));
//Unclaim
Plugin.CTask().unclaim(UtilWorld.chunkToStr(caller.getLocation().getChunk()), caller.getName(), true);
Plugin.getClanDataAccess().unclaim(UtilWorld.chunkToStr(caller.getLocation().getChunk()), caller.getName(), true);
return true;
}
@ -992,7 +994,7 @@ public class ClansCommand extends CommandBase<ClansManager>
toUnclaim.add(chunk);
for (String chunk : toUnclaim)
Plugin.CTask().unclaim(chunk, caller.getName(), true);
Plugin.getClanDataAccess().unclaim(chunk, caller.getName(), true);
//Inform
UtilPlayer.message(caller, F.main("Clans", "You unclaimed all your Clans Territory."));
@ -1013,8 +1015,8 @@ public class ClansCommand extends CommandBase<ClansManager>
}
//Display
Plugin.CDisplay().displayOwner(caller);
Plugin.CDisplay().displayMap(caller);
Plugin.getClanDisplay().displayOwner(caller);
Plugin.getClanDisplay().displayMap(caller);
}
public void home(Player caller, String[] args)
@ -1075,7 +1077,7 @@ public class ClansCommand extends CommandBase<ClansManager>
return;
//Do
Plugin.Teleport().TP(caller, clan.GetHome());
Plugin.getTeleport().TP(caller, clan.getHome());
//Inform
UtilPlayer.message(caller, F.main("Clans", "You teleported to your Clan Home " + UtilWorld.locToStrClean(caller.getLocation()) + "."));
@ -1110,7 +1112,7 @@ public class ClansCommand extends CommandBase<ClansManager>
}
//Task
Plugin.CTask().home(clan, caller.getLocation(), caller.getName());
Plugin.getClanDataAccess().home(clan, caller.getLocation(), caller.getName());
//Inform
UtilPlayer.message(caller, F.main("Clans", "You set Clan Home to " + UtilWorld.locToStrClean(caller.getLocation()) + "."));

View File

@ -9,6 +9,9 @@ import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnBoolean;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnLong;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.game.clans.clans.repository.tokens.ClanAllianceToken;
import mineplex.game.clans.clans.repository.tokens.ClanMemberToken;
@ -26,6 +29,24 @@ public class ClanRepository extends RepositoryBase
private static String RETRIEVE_CLAN_MEMBER_INFO = "SELECT c.name, a.name, role FROM accountClan AS ac INNER JOIN accounts AS a ON a.id = ac.accountId INNER JOIN clans AS c on c.id = ac.clanId;";
private static String RETRIEVE_CLAN_ALLIANCE_INFO = "SELECT c.name, cOther.name, ca.trusted FROM clanAlliances AS ca INNER JOIN clans AS c ON c.id = ca.clanId INNER JOIN clans as cOther ON cOther.id = ca.otherClanId;";
private static String DELETE_CLAN_MEMBER = "DELETE FROM accountClan INNER JOIN accounts ON accounts.id = accountClan.accountId WHERE clans.id = ? AND accounts.name = ?;";
private static String DELETE_CLAN_MEMBERS = "DELETE FROM accountClan INNER JOIN clans ON clans.id = accountClan.clanId WHERE clans.name = ?;";
private static String DELETE_CLAN_TERRITORY = "DELETE FROM clanTerritory WHERE clanId = ? AND serverName = ? AND chunk = ?;";
private static String DELETE_CLAN_TERRITORIES = "DELETE FROM clanTerritory INNER JOIN clans ON clans.id = clanTerritory.clanId WHERE clans.name = ?;";
private static String DELETE_CLAN_ALLIANCE = "DELETE FROM clanAlliances WHERE clanId = ? AND otherClanId = ?;";
private static String DELETE_CLAN_ALLIANCES = "DELETE FROM clanAlliances INNER JOIN clans ON clans.id = clanAlliances.clanId WHERE clans.name = ?;";
private static String DELETE_CLAN = "DELETE FROM clans WHERE name = ?;";
private static String ADD_CLAN = "INSERT INTO clans (name, description, home, admin, dateCreated, lastOnline) VALUES (?, ?, ?, ?, now(), now());";
private static String ADD_CLAN_MEMBER = "INSERT INTO accountClan (accountId, clanId, clanRole) SELECT accounts.id, ?, ? FROM accounts WHERE accounts.name = ?;";
private static String ADD_CLAN_ALLIANCE = "INSERT INTO clanAlliances (clandId, otherClanId, trusted) VALUES (?, ?, ?);";
private static String ADD_CLAN_TERRITORY = "INSERT INTO clanTerritory (clanId, serverName, chunk, safe) VALUES (?, ?, ?, ?);";
private static String UPDATE_CLAN = "UPDATE clans SET name = ?, desc = ?, home = ?, admin = ?, lastOnline = ? WHERE id = ?;";
private static String UPDATE_CLAN_MEMBER = "UPDATE AC SET clanRole = ? FROM accountClan AS AC INNER JOIN accounts ON accounts.id = accountClan.accountId WHERE clans.id = ? AND accounts.name = ?;";
private static String UPDATE_CLAN_ALLIANCE = "UPDATE clanAlliances SET trusted = ? WHERE clanId = ? AND otherClanId = ?;";
private static String UPDATE_CLAN_TERRITORY = "UPDATE clanTerritory SET safe = ? WHERE serverName = ? AND chunk = ?;";
private String _serverName;
public ClanRepository(JavaPlugin plugin, String serverName)
@ -130,4 +151,79 @@ public class ClanRepository extends RepositoryBase
protected void update()
{
}
public void deleteClan(String name)
{
executeUpdate(DELETE_CLAN_MEMBERS, new ColumnVarChar("name", 100, name));
executeUpdate(DELETE_CLAN_TERRITORIES, new ColumnVarChar("name", 100, name));
executeUpdate(DELETE_CLAN_ALLIANCES, new ColumnVarChar("name", 100, name));
executeUpdate(DELETE_CLAN, new ColumnVarChar("name", 100, name));
}
public void addClan(final ClanToken token)
{
executeUpdate(ADD_CLAN, new ResultSetCallable()
{
@Override
public void processResultSet(ResultSet resultSet) throws SQLException
{
while (resultSet.next())
{
executeUpdate(ADD_CLAN_MEMBER, new ColumnInt("clanid", resultSet.getInt(0)), new ColumnVarChar("clanRole", 100, token.Members.get(0).ClanRole), new ColumnVarChar("name", 100, token.Members.get(0).Name));
}
}
}, new ColumnVarChar("name", 100, token.Name), new ColumnVarChar("description", 100, token.Description), new ColumnVarChar("home", 100, token.Home), new ColumnBoolean("admin", token.Admin));
}
public void addMember(int clanId, String playerName, String role)
{
executeUpdate(ADD_CLAN_MEMBER, new ColumnInt("clanid", clanId), new ColumnVarChar("clanRole", 100, role), new ColumnVarChar("name", 100, playerName));
}
public void removeMember(int clanId, String playerName)
{
executeUpdate(DELETE_CLAN_MEMBER, new ColumnInt("clanid", clanId), new ColumnVarChar("name", 100, playerName));
}
public void updateMember(int clanId, String playerName, String role)
{
executeUpdate(UPDATE_CLAN_MEMBER, new ColumnInt("clanid", clanId), new ColumnVarChar("clanRole", 100, role), new ColumnVarChar("name", 100, playerName));
}
public void addClanRelationship(int clanId, int otherClanId, boolean trusted)
{
executeUpdate(ADD_CLAN_ALLIANCE, new ColumnInt("clanid", clanId), new ColumnInt("otherClanId", otherClanId), new ColumnBoolean("trusted", trusted));
}
public void updateClanRelationship(int clanId, int otherClanId, boolean trusted)
{
executeUpdate(UPDATE_CLAN_ALLIANCE, new ColumnInt("clanid", clanId), new ColumnInt("otherClanId", otherClanId), new ColumnBoolean("trusted", trusted));
}
public void removeClanRelationship(int clanId, int otherClanId)
{
executeUpdate(DELETE_CLAN_ALLIANCE, new ColumnInt("clanid", clanId), new ColumnInt("otherClanId", otherClanId));
}
public void addTerritoryClaim(int clanId, String chunk, boolean safe)
{
executeUpdate(ADD_CLAN_TERRITORY, new ColumnInt("clanId", clanId), new ColumnVarChar("serverName", 100, _serverName), new ColumnVarChar("chunk", 100, chunk), new ColumnBoolean("safe", safe));
}
public void removeTerritoryClaim(int clanId, String chunk)
{
executeUpdate(DELETE_CLAN_TERRITORY, new ColumnInt("clanId", clanId), new ColumnVarChar("serverName", 100, _serverName), new ColumnVarChar("chunk", 100, chunk));
}
public void updateClan(int clanId, String name, String desc, String home, boolean admin, long lastOnline)
{
executeUpdate(UPDATE_CLAN, new ColumnVarChar("name", 100, name), new ColumnVarChar("desc", 100, desc), new ColumnVarChar("home", 100, home), new ColumnBoolean("admin", admin), new ColumnLong("lastOnline", lastOnline), new ColumnInt("clanId", clanId));
}
public void updateTerritoryClaim(String chunk, boolean safe)
{
executeUpdate(UPDATE_CLAN_TERRITORY, new ColumnBoolean("safe", safe), new ColumnVarChar("serverName", 100, _serverName), new ColumnVarChar("chunk", 100, chunk));
}
}

View File

@ -4,4 +4,5 @@ public class ClanTerritory
{
public boolean Safe;
public String Owner;
public String Chunk;
}