Clans Gui

This commit is contained in:
Shaun Bennett 2015-11-02 20:41:08 -05:00
parent 27c6ef4e9d
commit 4794cc6924
34 changed files with 1144 additions and 16 deletions

View File

@ -1,6 +1,13 @@
package mineplex.core.common.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.entity.*;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
public class UtilSkull
{
@ -25,6 +32,17 @@ public class UtilSkull
return 3;
}
public static ItemStack getPlayerHead(String playerName, String itemName, List<String> itemLore)
{
ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) 0, (byte) 3);
SkullMeta meta = ((SkullMeta) skull.getItemMeta());
meta.setOwner(playerName);
meta.setDisplayName(itemName);
meta.setLore(itemLore);
skull.setItemMeta(meta);
return skull;
}
public static boolean isPlayerHead(byte data)
{
return data == 3;

View File

@ -58,8 +58,8 @@ public class TablistFix extends MiniPlugin
{
if (player.canSee(other))
{
PacketPlayOutPlayerInfo packet = PacketPlayOutPlayerInfo.updateDisplayName(((CraftPlayer) player).getHandle(), ((CraftPlayer) other).getHandle());
UtilPlayer.sendPacket(player, packet);
// PacketPlayOutPlayerInfo packet = PacketPlayOutPlayerInfo.updateDisplayName(((CraftPlayer) player).getHandle(), ((CraftPlayer) other).getHandle());
// UtilPlayer.sendPacket(player, packet);
}
}
}

View File

@ -577,6 +577,16 @@ public class ClanInfo
}
}
public List<ClanWar> getInitiatedWars()
{
return new ArrayList<ClanWar>(_initiatedWars.values());
}
public List<ClanWar> getInitiatedOnWars()
{
return new ArrayList<ClanWar>(_initiatedOnWars.values());
}
public ClanWar getWar(String againstClan)
{
ClanWar initiated = getInitiatedWar(againstClan);

View File

@ -2,6 +2,23 @@ package mineplex.game.clans.clans;
public enum ClanRole
{
NONE, RECRUIT, MEMBER, ADMIN, LEADER;
NONE(0), RECRUIT(100), MEMBER(500), ADMIN(1000), LEADER(Integer.MAX_VALUE);
private int _powerValue;
ClanRole(int powerValue)
{
_powerValue = powerValue;
}
public boolean has(ClanRole role)
{
return getPowerValue() >= role.getPowerValue();
}
public int getPowerValue()
{
return _powerValue;
}
}

View File

@ -656,7 +656,7 @@ public class ClansDataAccessLayer
@Override
public void run()
{
final boolean ran = _repository.updateWar(clanA.getId(), clanB.getId(), war.getScore(), war.isCompleted(), war.getLastUpdated(), war.getEnded());
final boolean ran = _repository.updateWar(clanA.getId(), clanB.getId(), war.getClanAScore(), war.isCompleted(), war.getLastUpdated(), war.getEnded());
runSync(new Runnable()
{
@Override
@ -678,7 +678,7 @@ public class ClansDataAccessLayer
* EnemyData iData = initiator.getEnemyData(); ClanInfo other = clan ==
* initiator ? otherClan : clan; EnemyData oData = other.getEnemyData();
* _repository.updateEnemy(initiator.getId(), other.getId(),
* iData.getScore(), oData.getScore(), iData.getKills(), oData.getKills());
* iData.getClanAScore(), oData.getClanAScore(), iData.getKills(), oData.getKills());
* //Log _manager.log("Updated Enemy Data for [" + clan.getName() + ", " +
* otherClan.getName() + "]"); }
*/

View File

@ -19,6 +19,7 @@ import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemBreakEvent;
import org.bukkit.event.player.PlayerJoinEvent;
@ -63,6 +64,7 @@ import mineplex.game.clans.clans.commands.MapCommand;
import mineplex.game.clans.clans.commands.RegionsCommand;
import mineplex.game.clans.clans.data.PlayerClan;
import mineplex.game.clans.clans.event.ClansPlayerDeathEvent;
import mineplex.game.clans.clans.gui.ClansCommandShop;
import mineplex.game.clans.clans.loot.LootManager;
import mineplex.game.clans.clans.map.ItemMapManager;
import mineplex.game.clans.clans.murder.MurderManager;
@ -158,6 +160,9 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
private long _reclaimTime = 1800000;
private long _onlineTime = 1200000;
// Command Shop
private ClansCommandShop _commandShop;
//Clans
private NautHashMap<String, ClanInfo> _clanMap = new NautHashMap<String, ClanInfo>();
// private NautHashMap<String, ClanInfo> _clanMemberNameMap = new NautHashMap<String, ClanInfo>();
@ -215,7 +220,9 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
_explosion = new Explosion(plugin, blockRestore);
new ClansLoginManager(getPlugin(), clientManager, _serverName);
// new ClansLoginManager(getPlugin(), clientManager, _serverName);
_commandShop = new ClansCommandShop(this, clientManager, donationManager);
Energy energy = new Energy(plugin);
// TODO: Re-enable customtagfix with NCP update?
@ -839,6 +846,16 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
}
}
@EventHandler
public void openShop(PlayerCommandPreprocessEvent event)
{
if (event.getMessage().equals("/cgui"))
{
_commandShop.attemptShopOpen(event.getPlayer());
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGH)
public void handleClansDeath(PlayerDeathEvent event)
{

View File

@ -15,11 +15,17 @@ import org.bukkit.World;
import org.bukkit.entity.Player;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
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.UtilTime;
import mineplex.core.common.util.UtilWorld;
import mineplex.game.clans.clans.event.ClanDisbandedEvent;
import mineplex.game.clans.core.repository.ClanTerritory;
import mineplex.game.clans.tutorials.TutorialManager;
import mineplex.game.clans.tutorials.types.TutorialGettingStarted;
public class ClansUtility
{
@ -588,4 +594,143 @@ public class ClansUtility
{
return Math.abs(loc.getBlockX()) > ClansManager.CLAIMABLE_RADIUS || Math.abs(loc.getBlockZ()) > ClansManager.CLAIMABLE_RADIUS;
}
/**
* Used for commands
*/
public void join(final Player caller, final ClanInfo clanInfo)
{
if (Clans.getClanMemberUuidMap().containsKey(caller.getUniqueId()))
{
UtilPlayer.message(caller, F.main("Clans", "You are already in a Clan."));
return;
}
if (!Clans.Get(caller).canJoin())
{
UtilPlayer.message(caller, F.main("Clans", "You cannot join a Clan for " + C.mTime + UtilTime.convertString(System.currentTimeMillis() - Clans.Get(caller).getDelay(), 1, UtilTime.TimeUnit.FIT) + C.mBody + "."));
return;
}
if (clanInfo == null)
{
UtilPlayer.message(caller, F.main("Clans", "Error: Clan does not exist"));
return;
}
if (!clanInfo.isInvited(caller.getName()))
{
UtilPlayer.message(caller, F.main("Clans", "You are not invited to " + F.elem("Clan " + clanInfo.getName()) + "."));
return;
}
if (clanInfo.getSize() >= clanInfo.getMaxSize())
{
UtilPlayer.message(caller, F.main("Clans", "The clan " + F.elem("Clan " + clanInfo.getName()) + " is full and cannot be joined!"));
return;
}
// Task
Clans.getClanDataAccess().join(clanInfo, caller, ClanRole.RECRUIT, new Callback<Boolean>()
{
@Override
public void run(Boolean data)
{
if (data)
{
// Inform
UtilPlayer.message(caller, F.main("Clans", "You joined " + F.elem("Clan " + clanInfo.getName()) + "."));
clanInfo.inform(F.name(caller.getName()) + " has joined your Clan.", caller.getName());
}
else
{
UtilPlayer.message(caller, F.main("Clans", "There was an error processing your request"));
}
}
});
}
public void leave(final Player caller)
{
final ClanInfo clan = getClanByPlayer(caller);
if (clan == null)
{
UtilPlayer.message(caller, F.main("Clans", "You are not in a Clan."));
return;
}
if (clan.getMembers().get(caller.getUniqueId()).getRole() == ClanRole.LEADER && clan.getMembers().size() > 1)
{
UtilPlayer.message(caller, F.main("Clans", "You must pass on " + F.elem("Leadership") + " before leaving."));
return;
}
// Leave or Delete
if (clan.getMembers().size() > 1)
{
// Task
Clans.getClanDataAccess().leave(clan, caller, new Callback<Boolean>()
{
@Override
public void run(Boolean data)
{
// Inform
UtilPlayer.message(caller, F.main("Clans", "You left " + F.elem("Clan " + clan.getName()) + "."));
clan.inform(F.name(caller.getName()) + " has left your Clan.", null);
}
});
}
else
{
delete(caller);
}
}
public void delete(final Player caller)
{
final ClanInfo clan = getClanByPlayer(caller);
if (clan == null)
{
UtilPlayer.message(caller, F.main("Clans", "You are not in a Clan."));
return;
}
if (getRole(caller) != ClanRole.LEADER)
{
UtilPlayer.message(caller, F.main("Clans", "Only the Clan Leader can disband the Clan."));
return;
}
// Event
ClanDisbandedEvent event = new ClanDisbandedEvent(clan, caller);
UtilServer.getServer().getPluginManager().callEvent(event);
if (event.isCancelled())
{
return;
}
// Task
Clans.getClanDataAccess().delete(clan, new Callback<Boolean>()
{
@Override
public void run(Boolean data)
{
if (data)
{
// Inform
UtilServer.broadcast(F.main("Clans", F.name(caller.getName()) + " disbanded " + F.elem("Clan " + clan.getName()) + "."));
}
else
{
UtilPlayer.message(caller, F.main("Clans", "There was an error processing your request. Try again later"));
}
}
});
}
}

View File

@ -0,0 +1,25 @@
package mineplex.game.clans.clans.gui;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.CurrencyType;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.ShopBase;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.gui.page.ClansMainPage;
public class ClansCommandShop extends ShopBase<ClansManager>
{
public ClansCommandShop(ClansManager plugin, CoreClientManager clientManager, DonationManager donationManager)
{
super(plugin, clientManager, donationManager, "Clans Commands");
}
@Override
protected ShopPageBase<ClansManager, ? extends ShopBase<ClansManager>> buildPagesFor(Player player)
{
return new ClansMainPage(getPlugin(), this, getClientManager(), getDonationManager(), player);
}
}

View File

@ -0,0 +1,21 @@
package mineplex.game.clans.clans.gui.button;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import mineplex.core.common.jsonchat.ClickEvent;
import mineplex.core.common.jsonchat.JsonMessage;
import mineplex.core.common.util.C;
import mineplex.core.shop.item.IButton;
public class ClanAddAllyButton implements IButton
{
@Override
public void onClick(Player player, ClickType clickType)
{
player.closeInventory();
JsonMessage message = new JsonMessage(C.cRed + C.Bold + "Click here to add an Ally").click(ClickEvent.SUGGEST_COMMAND, "/c ally ");
message.sendToPlayer(player);
}
}

View File

@ -0,0 +1,21 @@
package mineplex.game.clans.clans.gui.button;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import mineplex.core.common.jsonchat.ClickEvent;
import mineplex.core.common.jsonchat.JsonMessage;
import mineplex.core.common.util.C;
import mineplex.core.shop.item.IButton;
public class ClanAddTrustedButton implements IButton
{
@Override
public void onClick(Player player, ClickType clickType)
{
player.closeInventory();
JsonMessage message = new JsonMessage(C.cRed + C.Bold + "Click here to trust a clan").click(ClickEvent.SUGGEST_COMMAND, "/c trust ");
message.sendToPlayer(player);
}
}

View File

@ -0,0 +1,21 @@
package mineplex.game.clans.clans.gui.button;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import mineplex.core.common.jsonchat.ClickEvent;
import mineplex.core.common.jsonchat.JsonMessage;
import mineplex.core.common.util.C;
import mineplex.core.shop.item.IButton;
public class ClanAddWarButton implements IButton
{
@Override
public void onClick(Player player, ClickType clickType)
{
player.closeInventory();
JsonMessage message = new JsonMessage(C.cRed + C.Bold + "Click here to war a clan").click(ClickEvent.SUGGEST_COMMAND, "/war ");
message.sendToPlayer(player);
}
}

View File

@ -0,0 +1,44 @@
package mineplex.game.clans.clans.gui.button;
import org.bukkit.entity.Player;
import mineplex.core.shop.item.IButton;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClanRole;
import mineplex.game.clans.clans.ClansManager;
public abstract class ClanButton implements IButton
{
private ClansManager _clansManager;
private Player _player;
private ClanInfo _clanInfo;
private ClanRole _clanRole;
public ClanButton(ClansManager clansManager, Player player, ClanInfo clanInfo, ClanRole clanRole)
{
_clansManager = clansManager;
_player = player;
_clanInfo = clanInfo;
_clanRole = clanRole;
}
public ClansManager getClansManager()
{
return _clansManager;
}
public Player getPlayer()
{
return _player;
}
public ClanInfo getClanInfo()
{
return _clanInfo;
}
public ClanRole getClanRole()
{
return _clanRole;
}
}

View File

@ -0,0 +1,26 @@
package mineplex.game.clans.clans.gui.button;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import mineplex.core.common.jsonchat.ClickEvent;
import mineplex.core.common.jsonchat.JsonMessage;
import mineplex.core.common.util.C;
import mineplex.core.shop.item.IButton;
public class ClanCreateButton implements IButton
{
public ClanCreateButton()
{
}
@Override
public void onClick(Player player, ClickType clickType)
{
player.closeInventory();
JsonMessage message = new JsonMessage(C.cRed + C.Bold + "Click here to create a clan").click(ClickEvent.SUGGEST_COMMAND, "/c create ");
message.sendToPlayer(player);
}
}

View File

@ -0,0 +1,23 @@
package mineplex.game.clans.clans.gui.button;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClanRole;
import mineplex.game.clans.clans.ClansManager;
public class ClanDisbandButton extends ClanButton
{
public ClanDisbandButton(ClansManager clansManager, Player player, ClanInfo clanInfo, ClanRole clanRole)
{
super(clansManager, player, clanInfo, clanRole);
}
@Override
public void onClick(Player player, ClickType clickType)
{
getPlayer().closeInventory();
getClansManager().getClanUtility().delete(getPlayer());
}
}

View File

@ -0,0 +1,28 @@
package mineplex.game.clans.clans.gui.button;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import mineplex.core.common.jsonchat.ClickEvent;
import mineplex.core.common.jsonchat.JsonMessage;
import mineplex.core.common.util.C;
import mineplex.core.shop.item.IButton;
public class ClanInviteButton implements IButton
{
private Player _player;
public ClanInviteButton(Player player)
{
_player = player;
}
@Override
public void onClick(Player player, ClickType clickType)
{
_player.closeInventory();
JsonMessage message = new JsonMessage(C.cRed + C.Bold + "Click Here to invite a player to your Clan").click(ClickEvent.SUGGEST_COMMAND, "/c invite ");
message.sendToPlayer(_player);
}
}

View File

@ -0,0 +1,27 @@
package mineplex.game.clans.clans.gui.button;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import mineplex.core.shop.item.IButton;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansManager;
public class ClanJoinButton implements IButton
{
private ClansManager _clansManager;
private ClanInfo _clanInfo;
public ClanJoinButton(ClansManager clansManager, ClanInfo clanInfo)
{
_clansManager = clansManager;
_clanInfo = clanInfo;
}
@Override
public void onClick(Player player, ClickType clickType)
{
player.closeInventory();
_clansManager.getClanUtility().join(player, _clanInfo);
}
}

View File

@ -0,0 +1,24 @@
package mineplex.game.clans.clans.gui.button;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import mineplex.core.shop.item.IButton;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClanRole;
import mineplex.game.clans.clans.ClansManager;
public class ClanLeaveButton extends ClanButton
{
public ClanLeaveButton(ClansManager clansManager, Player player, ClanInfo clanInfo, ClanRole clanRole)
{
super(clansManager, player, clanInfo, clanRole);
}
@Override
public void onClick(Player player, ClickType clickType)
{
getPlayer().closeInventory();
getClansManager().getClanUtility().leave(getPlayer());
}
}

View File

@ -0,0 +1,8 @@
package mineplex.game.clans.clans.gui.button;
/**
* Created by phina on 10/31/2015.
*/
public class ClanRelationsButton
{
}

View File

@ -0,0 +1,8 @@
package mineplex.game.clans.clans.gui.button;
/**
* Created by phina on 10/31/2015.
*/
public class ClanTerritoryButton
{
}

View File

@ -0,0 +1,21 @@
package mineplex.game.clans.clans.gui.button;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import mineplex.core.common.jsonchat.ClickEvent;
import mineplex.core.common.jsonchat.JsonMessage;
import mineplex.core.common.util.C;
import mineplex.core.shop.item.IButton;
public class ClanWhoButton implements IButton
{
@Override
public void onClick(Player player, ClickType clickType)
{
player.closeInventory();
JsonMessage message = new JsonMessage(C.cRed + C.Bold + "Click here to lookup a clan").click(ClickEvent.SUGGEST_COMMAND, "/c who ");
message.sendToPlayer(player);
}
}

View File

@ -0,0 +1,16 @@
package mineplex.game.clans.clans.gui.button;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import mineplex.core.shop.item.IButton;
public class MemberButton implements IButton
{
@Override
public void onClick(Player player, ClickType clickType)
{
Bukkit.broadcastMessage("Member button click");
}
}

View File

@ -0,0 +1,8 @@
package mineplex.game.clans.clans.gui.button;
/**
* Created by phina on 10/31/2015.
*/
public class MemberManagementButton
{
}

View File

@ -0,0 +1,61 @@
package mineplex.game.clans.clans.gui.page;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.item.IButton;
import mineplex.core.shop.item.ShopItem;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClanRole;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.gui.ClansCommandShop;
public abstract class ClansCommandPageBase extends ShopPageBase<ClansManager, ClansCommandShop>
{
public ClansCommandPageBase(ClansManager plugin, ClansCommandShop shop, CoreClientManager clientManager, DonationManager donationManager, String name, Player player, int size)
{
super(plugin, shop, clientManager, donationManager, name, player, size);
buildPage();
}
@Override
protected final void buildPage()
{
ClanInfo clanInfo = getPlugin().getClan(getPlayer());
if (clanInfo == null)
{
buildNoClan();
}
else
{
ClanRole role = getPlugin().getClanUtility().getRole(getPlayer());
buildClan(clanInfo, role);
}
}
public abstract void buildNoClan();
public abstract void buildClan(ClanInfo clanInfo, ClanRole clanRole);
protected void addBackButton()
{
addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), new IButton()
{
public void onClick(Player player, ClickType clickType)
{
ShopPageBase<ClansManager, ClansCommandShop> mainPage = new ClansMainPage(getPlugin(), getShop(), getClientManager(), getDonationManager(), getPlayer());
getShop().openPageForPlayer(getPlayer(), mainPage);
player.playSound(player.getLocation(), Sound.CLICK, 1, 1);
}
});
}
}

View File

@ -0,0 +1,57 @@
package mineplex.game.clans.clans.gui.page;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.item.ShopItem;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClanRole;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.gui.ClansCommandShop;
import mineplex.game.clans.clans.gui.button.ClanJoinButton;
public class ClansJoinPage extends ClansCommandPageBase
{
public ClansJoinPage(ClansManager plugin, ClansCommandShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player)
{
super(plugin, shop, clientManager, donationManager, "Join Clan", player, 54);
}
@Override
public void buildNoClan()
{
int currentIndex = 9;
for (ClanInfo clanInfo : getPlugin().getClanMap().values())
{
if (clanInfo.isInvited(getPlayer().getName()))
{
addInvitation(currentIndex, clanInfo);
currentIndex++;
}
}
if (currentIndex == 9)
{
// No invitations :(
ShopItem shopItem = new ShopItem(Material.BOOK, "You have no Clan Invitations!", new String[] {}, 1, true, false);
setItem(22, shopItem);
}
addBackButton();
}
private void addInvitation(int index, ClanInfo clanInfo)
{
ShopItem shopItem = new ShopItem(Material.BOOK_AND_QUILL, clanInfo.getName(), new String[] {}, 1, false, false);
addButton(index, shopItem, new ClanJoinButton(getPlugin(), clanInfo));
}
@Override
public void buildClan(ClanInfo clanInfo, ClanRole clanRole)
{
// Nothing
}
}

View File

@ -0,0 +1,68 @@
package mineplex.game.clans.clans.gui.page;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.item.ShopItem;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClanRole;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.gui.ClansCommandShop;
import mineplex.game.clans.clans.war.ClanWar;
public class ClansListWarPage extends ClansCommandPageBase
{
public ClansListWarPage(ClansManager plugin, ClansCommandShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player)
{
super(plugin, shop, clientManager, donationManager, "Active Wars", player, 54);
}
@Override
public void buildNoClan()
{
// Nothing to do here
}
@Override
public void buildClan(ClanInfo clanInfo, ClanRole clanRole)
{
List<ClanWar> initiatedWars = clanInfo.getInitiatedWars();
List<ClanWar> initiatedOnWars = clanInfo.getInitiatedOnWars();
int currentIndex = 9;
for (ClanWar war : initiatedWars)
{
addWar(currentIndex, war, true);
currentIndex++;
}
for (ClanWar war : initiatedOnWars)
{
addWar(currentIndex, war, false);
currentIndex++;
}
if (currentIndex == 9)
{
ShopItem shopItem = new ShopItem(Material.BOOK, "You are not at war with any clan!", new String[] {}, 1, true, false);
setItem(22, shopItem);
}
addBackButton();
}
private void addWar(int index, ClanWar war, boolean initiated)
{
String enemyName = initiated ? war.getClanB() : war.getClanA();
int score = initiated ? war.getClanAScore() : war.getClanBScore();
ShopItem shopItem = new ShopItem(initiated ? Material.BOW : Material.GOLD_SWORD, enemyName,
new String[] {ChatColor.RESET + C.cGray + "Score: " + C.cYellow + score }, 1, false, false);
setItem(index, shopItem);
}
}

View File

@ -0,0 +1,142 @@
package mineplex.game.clans.clans.gui.page;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import mineplex.core.account.CoreClientManager;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.item.IButton;
import mineplex.core.shop.item.ShopItem;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClanRole;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.gui.ClansCommandShop;
import mineplex.game.clans.clans.gui.button.ClanCreateButton;
import mineplex.game.clans.clans.gui.button.ClanWhoButton;
public class ClansMainPage extends ShopPageBase<ClansManager, ClansCommandShop>
{
public ClansMainPage(ClansManager plugin, ClansCommandShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player)
{
super(plugin, shop, clientManager, donationManager, "Clans", player, 9);
buildPage();
}
@Override
protected void buildPage()
{
ClanInfo clanInfo = getPlugin().getClan(getPlayer());
if (clanInfo == null)
{
// Clan does not exist state
// Clan Create
ShopItem clanCreate = new ShopItem(Material.BOOK_AND_QUILL, "Create Clan", new String[] {}, 1, false, false);
addButton(2, clanCreate, new ClanCreateButton());
// Clan Join
ShopItem clanJoin = new ShopItem(Material.BOOK, "Join Clan", new String[] {}, 1, false, false);
addButton(4, clanJoin, new IButton()
{
@Override
public void onClick(Player player, ClickType clickType)
{
getShop().openPageForPlayer(getPlayer(), new ClansJoinPage(getPlugin(), getShop(), getClientManager(), getDonationManager(), getPlayer()));
}
});
// Clan Who
ShopItem clanWho = new ShopItem(Material.MAP, "Lookup Clan", new String[] {}, 1, false, false);
addButton(6, clanWho, new ClanWhoButton());
}
else
{
// Clan does exist state
ClanRole role = getPlugin().getClanUtility().getRole(getPlayer());
boolean canOpenClanManagement = role.has(ClanRole.MEMBER);
boolean canOpenClanRelations = role.has(ClanRole.MEMBER);
boolean canOpenMemberManagement = role.has(ClanRole.MEMBER);
boolean canOpenClanTerritory = role.has(ClanRole.MEMBER);
ShopItem clanManagement = new ShopItem(Material.BOOK_AND_QUILL, "Clan Management", new String[]{}, 1, !canOpenClanManagement, false);
ShopItem clanRelations = new ShopItem(Material.DIAMOND_SWORD, "Clan Relations", new String[]{}, 1, !canOpenClanRelations, false);
ShopItem memberManagement = new ShopItem(Material.SKULL_ITEM, (byte) 3, "Member Management", new String[]{}, 1, !canOpenMemberManagement, false);
ShopItem clanTerritory = new ShopItem(Material.MAP, "Clan Territory", new String[]{}, 1, !canOpenClanTerritory, false);
// Clan Manage
if (canOpenClanManagement)
{
addButton(1, clanManagement, new IButton()
{
@Override
public void onClick(Player player, ClickType clickType)
{
getShop().openPageForPlayer(getPlayer(), new ClansManagePage(getPlugin(), getShop(), getClientManager(), getDonationManager(), getPlayer()));
}
});
}
else
{
setItem(1, clanManagement);
}
// Clan Relations
if (canOpenClanRelations)
{
addButton(3, clanRelations, new IButton()
{
@Override
public void onClick(Player player, ClickType clickType)
{
getShop().openPageForPlayer(getPlayer(), new ClansRelationsPage(getPlugin(), getShop(), getClientManager(), getDonationManager(), getPlayer()));
}
});
}
else
{
setItem(3, clanRelations);
}
// Member Management
if (canOpenMemberManagement)
{
addButton(5, memberManagement, new IButton()
{
@Override
public void onClick(Player player, ClickType clickType)
{
getShop().openPageForPlayer(getPlayer(), new MemberManagementPage(getPlugin(), getShop(), getClientManager(), getDonationManager(), getPlayer()));
}
});
}
else
{
setItem(5, memberManagement);
}
// Clan Territory
if (canOpenClanTerritory)
{
addButton(7, clanTerritory, new IButton()
{
@Override
public void onClick(Player player, ClickType clickType)
{
getShop().openPageForPlayer(getPlayer(), new ClansTerritoryPage(getPlugin(), getShop(), getClientManager(), getDonationManager(), getPlayer()));
}
});
}
else
{
setItem(7, clanTerritory);
}
}
}
}

View File

@ -0,0 +1,56 @@
package mineplex.game.clans.clans.gui.page;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.item.ShopItem;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClanRole;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.gui.ClansCommandShop;
import mineplex.game.clans.clans.gui.button.ClanDisbandButton;
import mineplex.game.clans.clans.gui.button.ClanInviteButton;
import mineplex.game.clans.clans.gui.button.ClanLeaveButton;
public class ClansManagePage extends ClansCommandPageBase
{
public ClansManagePage(ClansManager plugin, ClansCommandShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player)
{
super(plugin, shop, clientManager, donationManager, "Clan Management", player, 18);
}
@Override
public void buildNoClan()
{
// Nothing to do here
}
@Override
public void buildClan(ClanInfo clanInfo, ClanRole clanRole)
{
// Invite
boolean canInvite = clanRole.has(clanRole.ADMIN);
ShopItem invite = new ShopItem(Material.PAPER, "Invite Player", new String[] {}, 1, !canInvite, false);
if (canInvite)
addButton(11, invite, new ClanInviteButton(getPlayer()));
else
setItem(11, invite);
// Leave
ShopItem leave = new ShopItem(Material.POTATO, "Leave Clan", new String[] {}, 1, false, false);
addButton(13, leave, new ClanLeaveButton(getPlugin(), getPlayer(), clanInfo, clanRole));
// Disband
boolean canDisband = clanRole == ClanRole.LEADER;
ShopItem disband = new ShopItem(Material.TNT, "Disband Clan", new String[] {}, 1, !canDisband, false);
if (canDisband)
addButton(15, disband, new ClanDisbandButton(getPlugin(), getPlayer(), clanInfo, clanRole));
else
setItem(15, disband);
addBackButton();
}
}

View File

@ -0,0 +1,93 @@
package mineplex.game.clans.clans.gui.page;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import mineplex.core.account.CoreClientManager;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.item.IButton;
import mineplex.core.shop.item.ShopItem;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClanRole;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.commands.ClansCommand;
import mineplex.game.clans.clans.gui.ClansCommandShop;
import mineplex.game.clans.clans.gui.button.ClanAddAllyButton;
import mineplex.game.clans.clans.gui.button.ClanAddTrustedButton;
import mineplex.game.clans.clans.gui.button.ClanAddWarButton;
public class ClansRelationsPage extends ClansCommandPageBase
{
public ClansRelationsPage(ClansManager plugin, ClansCommandShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player)
{
super(plugin, shop, clientManager, donationManager, "Clan Relations", player, 27);
}
@Override
public void buildNoClan()
{
// Nothing!
}
@Override
public void buildClan(ClanInfo clanInfo, ClanRole clanRole)
{
// Add Ally
boolean canAddAlly = clanRole.has(ClanRole.ADMIN);
ShopItem addAlly = new ShopItem(Material.DIAMOND_SWORD, "Add Ally", new String[] {}, 1, !canAddAlly, false);
if (canAddAlly)
addButton(11, addAlly, new ClanAddAllyButton());
else
setItem(11, addAlly);
// List Allys
ShopItem listAlly = new ShopItem(Material.POTATO, "List Allies", new String[] {}, 1, false, false);
addButton(20, listAlly, new IButton()
{
@Override
public void onClick(Player player, ClickType clickType)
{
// TODO
}
});
// Add Trust
boolean canAddTrusted = clanRole.has(ClanRole.ADMIN);
ShopItem addTrusted = new ShopItem(Material.RED_ROSE, "Add Trusted", new String[] {}, 1, !canAddTrusted, false);
if (canAddTrusted)
addButton(13, addTrusted, new ClanAddTrustedButton());
else
setItem(13, addTrusted);
// List Trusted
ShopItem listTrusted = new ShopItem(Material.POTATO, "List Trusted", new String[] {}, 1, false, false);
addButton(22, listTrusted, new IButton()
{
@Override
public void onClick(Player player, ClickType clickType)
{
// TODO
}
});
// Add War
boolean canAddWar = clanRole.has(ClanRole.ADMIN);
ShopItem addWar = new ShopItem(Material.BOW, "Add War", new String[] {}, 1, !canAddWar, false);
if (canAddWar)
addButton(15, addWar, new ClanAddWarButton());
// List War
ShopItem listWar = new ShopItem(Material.POTATO, "List Wars", new String[] {}, 1, false, false);
addButton(24, listWar, new IButton()
{
@Override
public void onClick(Player player, ClickType clickType)
{
getShop().openPageForPlayer(getPlayer(), new ClansListWarPage(getPlugin(), getShop(), getClientManager(), getDonationManager(), getPlayer()));
}
});
addBackButton();
}
}

View File

@ -0,0 +1,31 @@
package mineplex.game.clans.clans.gui.page;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClanRole;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.gui.ClansCommandShop;
public class ClansTerritoryPage extends ClansCommandPageBase
{
public ClansTerritoryPage(ClansManager plugin, ClansCommandShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player)
{
super(plugin, shop, clientManager, donationManager, "Clan Territory", player, 18);
}
@Override
public void buildNoClan()
{
// Nothing!
}
@Override
public void buildClan(ClanInfo clanInfo, ClanRole clanRole)
{
addBackButton();
}
}

View File

@ -0,0 +1,88 @@
package mineplex.game.clans.clans.gui.page;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilSkull;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.item.IButton;
import mineplex.core.shop.page.ShopPageInventory;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClanRole;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.ClansPlayer;
import mineplex.game.clans.clans.ClansPlayerComparator;
import mineplex.game.clans.clans.gui.ClansCommandShop;
import mineplex.game.clans.clans.gui.button.MemberButton;
public class MemberManagementPage extends ShopPageInventory<ClansManager, ClansCommandShop>
{
private IButton[] _buttons;
private ItemStack[] _items;
public MemberManagementPage(ClansManager plugin, ClansCommandShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player)
{
super(plugin, shop, clientManager, donationManager, "Member Manager", player);
buildPage();
}
@Override
protected IButton[] getButtons()
{
return _buttons;
}
@Override
protected ItemStack[] getItems()
{
return _items;
}
@Override
protected void buildItems()
{
ClanInfo clanInfo = getPlugin().getClan(getPlayer());
if (clanInfo == null)
{
// do nothing
_buttons = new IButton[0];
_items = new ItemStack[0];
}
else
{
ClanRole role = getPlugin().getClanUtility().getRole(getPlayer());
List<ClansPlayer> playerList = new ArrayList<ClansPlayer>(clanInfo.getMembers().values());
Collections.sort(playerList, new ClansPlayerComparator());
_buttons = new IButton[playerList.size()];
_items = new ItemStack[_buttons.length];
int currentIndex = 0;
for (ClansPlayer clansPlayer : playerList)
{
addPlayerButton(clansPlayer, currentIndex);
currentIndex++;
}
}
}
private void addPlayerButton(ClansPlayer player, int index)
{
ItemStack playerHead = UtilSkull.getPlayerHead(player.getPlayerName(), C.cGreen + player.getPlayerName(), Arrays.asList(new String[] {ChatColor.RESET + "Role: " + player.getRole().ordinal()}));
_items[index] = playerHead;
_buttons[index] = new MemberButton();
}
}

View File

@ -61,11 +61,16 @@ public class ClanWar
* Get the score of the war. Score is represented as an int value with the initiator clan's score. The score
* works as a tug of war, score starts at 20 and either the initiator will get to 40 or 0 to trigger the end of war
*/
public int getScore()
public int getClanAScore()
{
return _score;
}
public int getClanBScore()
{
return WarManager.WAR_MAX_SCORE - getClanAScore();
}
/**
* Is the war finished (has a clan won already)
*/
@ -132,7 +137,7 @@ public class ClanWar
if (obj instanceof ClanWar)
{
ClanWar war = ((ClanWar) obj);
return _clanA.equals(war.getClanA()) && _clanB.equals(war.getClanB()) && _completed == war.isCompleted() && _score == war.getScore()
return _clanA.equals(war.getClanA()) && _clanB.equals(war.getClanB()) && _completed == war.isCompleted() && _score == war.getClanAScore()
&& _created.equals(war.getCreated());
}

View File

@ -1,7 +1,5 @@
package mineplex.game.clans.clans.war;
import mineplex.game.clans.clans.ClanInfo;
public class WarInvasion
{
private static final long INVADE_LENGTH = 60000L * 30; // 30 Minutes
@ -13,7 +11,7 @@ public class WarInvasion
public WarInvasion(ClanWar clanWar)
{
if (clanWar.getScore() > WarManager.WAR_START_SCORE)
if (clanWar.getClanAScore() > WarManager.WAR_START_SCORE)
{
// Initiator Won
_invaderClan = clanWar.getClanA();

View File

@ -32,6 +32,7 @@ import mineplex.game.clans.clans.war.event.WarInvasionStartEvent;
public class WarManager extends MiniPlugin
{
public static final int WAR_START_SCORE = 20;
public static final int WAR_MAX_SCORE = 40;
private final ClansManager _clansManager;
@ -113,12 +114,12 @@ public class WarManager extends MiniPlugin
{
boolean completed = false;
if (clanWar.getScore() >= WAR_START_SCORE * 2)
if (clanWar.getClanAScore() >= WAR_START_SCORE * 2)
{
// Initiator Won
completed = true;
}
else if (clanWar.getScore() <= 0)
else if (clanWar.getClanAScore() <= 0)
{
// Initiated On Won
completed = true;

View File

@ -48,10 +48,10 @@ public class DominanceCommand extends CommandBase<WarManager>
{
System.out.println("Initiator: " + war.getClanA());
System.out.println("Other Clan: " + war.getClanB());
System.out.println("Score: " + war.getScore());
System.out.println("Score: " + war.getClanAScore());
UtilPlayer.message(caller, F.main("War", "War Status with " + searchName));
UtilPlayer.message(caller, F.main("War", "Initiated by: " + (war.getClanA().equals(clan.getName()) ? selfName : searchName)));
UtilPlayer.message(caller, F.main("War", "Initiator Dominance: " + F.elem("" + war.getScore())));
UtilPlayer.message(caller, F.main("War", "Initiator Dominance: " + F.elem("" + war.getClanAScore())));
UtilPlayer.message(caller, F.main("War", "Age: " + F.elem(UtilTime.convertString(System.currentTimeMillis() - war.getCreated().getTime(), 1, UtilTime.TimeUnit.FIT))));
}