Merge pull request #8 from feature/clans-energy to master
* commit '882eb464798f07fcd6cd929342ecdc85d2244378': Unclaiming land when you run out of energy Fix ugly /gold command Clan Energy
This commit is contained in:
commit
0e59d9b21e
@ -0,0 +1,26 @@
|
|||||||
|
package mineplex.core.common.util;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class PlayerInfo
|
||||||
|
{
|
||||||
|
private String _name;
|
||||||
|
private UUID _uuid;
|
||||||
|
|
||||||
|
public PlayerInfo(String name, UUID uuid)
|
||||||
|
{
|
||||||
|
_name = name;
|
||||||
|
_uuid = uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return _name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getUUID()
|
||||||
|
{
|
||||||
|
return _uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -6,7 +6,6 @@ import java.util.LinkedList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
@ -42,6 +42,7 @@ public class DonationManager extends MiniDbClientPlugin<Donor>
|
|||||||
{
|
{
|
||||||
addCommand(new GemCommand(this));
|
addCommand(new GemCommand(this));
|
||||||
addCommand(new CoinCommand(this));
|
addCommand(new CoinCommand(this));
|
||||||
|
addCommand(new GoldCommand(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -0,0 +1,84 @@
|
|||||||
|
package mineplex.core.donation;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import mineplex.core.command.CommandBase;
|
||||||
|
import mineplex.core.common.Rank;
|
||||||
|
import mineplex.core.common.util.Callback;
|
||||||
|
import mineplex.core.common.util.F;
|
||||||
|
import mineplex.core.common.util.UUIDFetcher;
|
||||||
|
import mineplex.core.common.util.UtilPlayer;
|
||||||
|
|
||||||
|
public class GoldCommand extends CommandBase<DonationManager>
|
||||||
|
{
|
||||||
|
public GoldCommand(DonationManager plugin)
|
||||||
|
{
|
||||||
|
super(plugin, Rank.ADMIN, "givegold");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void Execute(final Player caller, String[] args)
|
||||||
|
{
|
||||||
|
if (args == null || args.length == 0)
|
||||||
|
{
|
||||||
|
UtilPlayer.message(caller, F.main("Gold", "Your Gold: " + F.elem("" + Plugin.Get(caller).getGold())));
|
||||||
|
}
|
||||||
|
else if (args.length < 2)
|
||||||
|
{
|
||||||
|
UtilPlayer.message(caller, F.main("Gold", "Missing Args: " + F.elem("/gold <player> <amount>")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String targetName = args[0];
|
||||||
|
String goldString = args[1];
|
||||||
|
Player target = UtilPlayer.searchExact(targetName);
|
||||||
|
|
||||||
|
if (target == null)
|
||||||
|
{
|
||||||
|
UUID uuid = UUIDFetcher.getUUIDOf(targetName);
|
||||||
|
if (uuid != null)
|
||||||
|
{
|
||||||
|
rewardGold(caller, null, targetName, uuid, goldString);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UtilPlayer.message(caller, F.main("Gold", "Could not find player " + F.name(targetName)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rewardGold(caller, target, target.getName(), target.getUniqueId(), goldString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void rewardGold(final Player caller, final Player target, final String targetName, final UUID uuid, String goldString)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int gold = Integer.parseInt(goldString);
|
||||||
|
rewardGold(caller, target, targetName, uuid, gold);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
UtilPlayer.message(caller, F.main("Gold", "Invalid Gold Amount"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void rewardGold(final Player caller, final Player target, final String targetName, final UUID uuid, final int gold)
|
||||||
|
{
|
||||||
|
Plugin.RewardGold(new Callback<Boolean>()
|
||||||
|
{
|
||||||
|
public void run(Boolean completed)
|
||||||
|
{
|
||||||
|
UtilPlayer.message(caller, F.main("Gold", "You gave " + F.elem(gold + " Gold") + " to " + F.name(targetName) + "."));
|
||||||
|
|
||||||
|
if (target != null)
|
||||||
|
{
|
||||||
|
UtilPlayer.message(target, F.main("Gold", F.name(caller.getName()) + " gave you " + F.elem(gold + " Gold") + "."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, caller.getName(), targetName, uuid, gold);
|
||||||
|
}
|
||||||
|
}
|
@ -18,7 +18,6 @@ import mineplex.core.common.util.UtilInv;
|
|||||||
import mineplex.core.donation.DonationManager;
|
import mineplex.core.donation.DonationManager;
|
||||||
import mineplex.core.shop.ShopBase;
|
import mineplex.core.shop.ShopBase;
|
||||||
import mineplex.core.shop.item.IButton;
|
import mineplex.core.shop.item.IButton;
|
||||||
import mineplex.core.shop.item.ShopItem;
|
|
||||||
|
|
||||||
public abstract class ShopPageBase<PluginType extends MiniPlugin, ShopType extends ShopBase<PluginType>> extends CraftInventoryCustom implements Listener
|
public abstract class ShopPageBase<PluginType extends MiniPlugin, ShopType extends ShopBase<PluginType>> extends CraftInventoryCustom implements Listener
|
||||||
{
|
{
|
||||||
@ -187,10 +186,16 @@ public abstract class ShopPageBase<PluginType extends MiniPlugin, ShopType exten
|
|||||||
|
|
||||||
public void Refresh()
|
public void Refresh()
|
||||||
{
|
{
|
||||||
clear();
|
clearPage();
|
||||||
BuildPage();
|
BuildPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clearPage()
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
ButtonMap.clear();
|
||||||
|
}
|
||||||
|
|
||||||
public void setItem(int column, int row, ItemStack itemStack)
|
public void setItem(int column, int row, ItemStack itemStack)
|
||||||
{
|
{
|
||||||
setItem(column + (row * 9), itemStack);
|
setItem(column + (row * 9), itemStack);
|
||||||
|
@ -0,0 +1,83 @@
|
|||||||
|
package mineplex.game.clans.clans;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import mineplex.core.MiniPlugin;
|
||||||
|
import mineplex.core.account.CoreClientManager;
|
||||||
|
import mineplex.core.common.util.F;
|
||||||
|
import mineplex.core.donation.DonationManager;
|
||||||
|
import mineplex.game.clans.shop.energy.EnergyShop;
|
||||||
|
|
||||||
|
public class ClanEnergyManager extends MiniPlugin implements Runnable
|
||||||
|
{
|
||||||
|
private ClansManager _clansManager;
|
||||||
|
private EnergyShop _shop;
|
||||||
|
private int tickCount;
|
||||||
|
|
||||||
|
public ClanEnergyManager(JavaPlugin plugin, ClansManager clansManager, CoreClientManager clientManager, DonationManager donationManager)
|
||||||
|
{
|
||||||
|
super("Clan Energy", plugin);
|
||||||
|
_clansManager = clansManager;
|
||||||
|
_shop = new EnergyShop(clansManager, clientManager, donationManager);
|
||||||
|
|
||||||
|
// Wait 5 seconds and then tick every 60 seconds
|
||||||
|
_plugin.getServer().getScheduler().runTaskTimer(_plugin, this, 20 * 5, 20 * 60);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
tickCount++;
|
||||||
|
|
||||||
|
for (final ClanInfo clanInfo : _clansManager.getClanMap().values())
|
||||||
|
{
|
||||||
|
if (clanInfo.isAdmin())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
int energyPerMinute = clanInfo.getEnergyCostPerMinute();
|
||||||
|
int currentEnergy = clanInfo.getEnergy();
|
||||||
|
|
||||||
|
if (currentEnergy < energyPerMinute)
|
||||||
|
{
|
||||||
|
for (String chunk : clanInfo.getClaimSet())
|
||||||
|
{
|
||||||
|
_clansManager.getClanDataAccess().unclaimSilent(chunk, true);
|
||||||
|
}
|
||||||
|
_clansManager.messageClan(clanInfo, F.main("Clans", "Your clan has ran out of energy. Land claims have been removed"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
clanInfo.adjustEnergy(-energyPerMinute);
|
||||||
|
if (tickCount % 5 == 0 && energyPerMinute > 0)
|
||||||
|
{
|
||||||
|
runAsync(new Runnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_clansManager.getClanDataAccess().updateEnergy(clanInfo);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void openShop(Player player)
|
||||||
|
{
|
||||||
|
_shop.attemptShopOpen(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO DEBUG
|
||||||
|
@EventHandler
|
||||||
|
public void command(PlayerCommandPreprocessEvent event)
|
||||||
|
{
|
||||||
|
if (event.getMessage().startsWith("/energyshop"))
|
||||||
|
{
|
||||||
|
openShop(event.getPlayer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,14 @@
|
|||||||
package mineplex.game.clans.clans;
|
package mineplex.game.clans.clans;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import mineplex.core.common.util.C;
|
import mineplex.core.common.util.C;
|
||||||
import mineplex.core.common.util.F;
|
import mineplex.core.common.util.F;
|
||||||
@ -9,18 +16,14 @@ import mineplex.core.common.util.NautHashMap;
|
|||||||
import mineplex.core.common.util.UtilAlg;
|
import mineplex.core.common.util.UtilAlg;
|
||||||
import mineplex.core.common.util.UtilPlayer;
|
import mineplex.core.common.util.UtilPlayer;
|
||||||
import mineplex.core.common.util.UtilTime;
|
import mineplex.core.common.util.UtilTime;
|
||||||
import mineplex.core.common.util.UtilWorld;
|
|
||||||
import mineplex.core.common.util.UtilTime.TimeUnit;
|
import mineplex.core.common.util.UtilTime.TimeUnit;
|
||||||
|
import mineplex.core.common.util.UtilWorld;
|
||||||
import mineplex.game.clans.clans.ClansUtility.ClanRelation;
|
import mineplex.game.clans.clans.ClansUtility.ClanRelation;
|
||||||
import mineplex.game.clans.clans.repository.tokens.ClanAllianceToken;
|
import mineplex.game.clans.clans.repository.tokens.ClanAllianceToken;
|
||||||
import mineplex.game.clans.clans.repository.tokens.ClanMemberToken;
|
import mineplex.game.clans.clans.repository.tokens.ClanMemberToken;
|
||||||
import mineplex.game.clans.clans.repository.tokens.ClanTerritoryToken;
|
import mineplex.game.clans.clans.repository.tokens.ClanTerritoryToken;
|
||||||
import mineplex.game.clans.clans.repository.tokens.ClanToken;
|
import mineplex.game.clans.clans.repository.tokens.ClanToken;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Sound;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class ClanInfo
|
public class ClanInfo
|
||||||
{
|
{
|
||||||
public enum Role
|
public enum Role
|
||||||
@ -60,6 +63,7 @@ public class ClanInfo
|
|||||||
// Temporary
|
// Temporary
|
||||||
private NautHashMap<String, Long> _inviteeMap = new NautHashMap<String, Long>();
|
private NautHashMap<String, Long> _inviteeMap = new NautHashMap<String, Long>();
|
||||||
private NautHashMap<String, String> _inviterMap = new NautHashMap<String, String>();
|
private NautHashMap<String, String> _inviterMap = new NautHashMap<String, String>();
|
||||||
|
private List<UUID> _onlinePlayers = new ArrayList<UUID>();
|
||||||
|
|
||||||
private NautHashMap<String, Long> _requestMap = new NautHashMap<String, Long>();
|
private NautHashMap<String, Long> _requestMap = new NautHashMap<String, Long>();
|
||||||
|
|
||||||
@ -152,9 +156,9 @@ public class ClanInfo
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMember(String clan)
|
public boolean isMember(String other)
|
||||||
{
|
{
|
||||||
return getMembers().containsKey(clan);
|
return getMembers().containsKey(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAlly(String other)
|
public boolean isAlly(String other)
|
||||||
@ -204,6 +208,16 @@ public class ClanInfo
|
|||||||
// Land
|
// Land
|
||||||
stringList.add(F.value("Territory", getClaims() + "/" + getClaimsMax()));
|
stringList.add(F.value("Territory", getClaims() + "/" + getClaimsMax()));
|
||||||
|
|
||||||
|
// Energy
|
||||||
|
int energy = getEnergy();
|
||||||
|
int costPerHour = getEnergyCostPerMinute() * 60;
|
||||||
|
stringList.add(" ");
|
||||||
|
stringList.add(F.value("Clan Energy", "" + energy));
|
||||||
|
// stringList.add(F.value("Max Energy", "" + getEnergyMax()));
|
||||||
|
stringList.add(F.value("Energy Drain/Hour", "" + costPerHour));
|
||||||
|
stringList.add(F.value("Hours Left", "" + energy / costPerHour));
|
||||||
|
stringList.add(" ");
|
||||||
|
|
||||||
// Ally String
|
// Ally String
|
||||||
String allySorted = "";
|
String allySorted = "";
|
||||||
HashSet<String> allyUnsorted = new HashSet<String>();
|
HashSet<String> allyUnsorted = new HashSet<String>();
|
||||||
@ -413,4 +427,52 @@ public class ClanInfo
|
|||||||
{
|
{
|
||||||
_energy += energy;
|
_energy += energy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getClaimCount()
|
||||||
|
{
|
||||||
|
return _claimSet.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSize()
|
||||||
|
{
|
||||||
|
return _memberMap.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEnergyMax()
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
// 10080 = 7 days of minutes
|
||||||
|
return 1440 + (getEnergyCostPerMinute() * 10080);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEnergyCostPerMinute()
|
||||||
|
{
|
||||||
|
return (getSize() * getClaimCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEnergyPurchasable()
|
||||||
|
{
|
||||||
|
int diff = getEnergyMax() - getEnergy();
|
||||||
|
return diff > 0 ? diff : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Player> getOnlinePlayers()
|
||||||
|
{
|
||||||
|
ArrayList<Player> players = new ArrayList<Player>(_onlinePlayers.size());
|
||||||
|
for (UUID uuid : _onlinePlayers)
|
||||||
|
{
|
||||||
|
players.add(UtilPlayer.searchExact(uuid));
|
||||||
|
}
|
||||||
|
return players;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void playerOnline(Player player)
|
||||||
|
{
|
||||||
|
_onlinePlayers.add(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void playerOffline(Player player)
|
||||||
|
{
|
||||||
|
_onlinePlayers.remove(player.getUniqueId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -255,11 +255,17 @@ public class ClansDataAccessLayer
|
|||||||
// _manager.getUnclaimMap().put(chunk, System.currentTimeMillis());
|
// _manager.getUnclaimMap().put(chunk, System.currentTimeMillis());
|
||||||
|
|
||||||
//Log
|
//Log
|
||||||
_manager.log("Removed Claim for [" + clan.getName() + "] at [" + chunk + "] by [" + player + "].");
|
if (player != null)
|
||||||
|
_manager.log("Removed Claim for [" + clan.getName() + "] at [" + chunk + "] by [" + player + "].");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean unclaimSilent(String chunk, boolean sql)
|
||||||
|
{
|
||||||
|
return unclaim(chunk, null, sql);
|
||||||
|
}
|
||||||
|
|
||||||
public void home(ClanInfo clan, Location loc, String player)
|
public void home(ClanInfo clan, Location loc, String player)
|
||||||
{
|
{
|
||||||
//Memory
|
//Memory
|
||||||
|
@ -2,12 +2,12 @@ package mineplex.game.clans.clans;
|
|||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
@ -135,6 +135,8 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
|
|||||||
ClassShopManager shopManager = new ClassShopManager(plugin, _classManager, skillManager, itemFactory, achievementManager, _clientManager);
|
ClassShopManager shopManager = new ClassShopManager(plugin, _classManager, skillManager, itemFactory, achievementManager, _clientManager);
|
||||||
_classShop = new ClassCombatShop(shopManager, _clientManager, donationManager, true, "Class Shop");
|
_classShop = new ClassCombatShop(shopManager, _clientManager, donationManager, true, "Class Shop");
|
||||||
|
|
||||||
|
ClanEnergyManager clanEnergyManager = new ClanEnergyManager(plugin, this, clientManager, donationManager);
|
||||||
|
|
||||||
for (ClanToken token : _clanDataAccess.getRepository().retrieveClans())
|
for (ClanToken token : _clanDataAccess.getRepository().retrieveClans())
|
||||||
{
|
{
|
||||||
ClanInfo clan = new ClanInfo(this, token);
|
ClanInfo clan = new ClanInfo(this, token);
|
||||||
@ -171,6 +173,16 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
|
|||||||
return _clanMemberMap;
|
return _clanMemberMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ClanInfo getClan(Player player)
|
||||||
|
{
|
||||||
|
return _clanMemberMap.get(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInClan(Player player)
|
||||||
|
{
|
||||||
|
return _clanMemberMap.containsKey(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
public ClanInfo getClan(String clan)
|
public ClanInfo getClan(String clan)
|
||||||
{
|
{
|
||||||
return _clanMap.get(clan);
|
return _clanMap.get(clan);
|
||||||
@ -219,6 +231,28 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
|
|||||||
getClanDisplay().handleInteract(event);
|
getClanDisplay().handleInteract(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void join(PlayerJoinEvent event)
|
||||||
|
{
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
ClanInfo clanInfo = getClanMemberMap().get(player.getName());
|
||||||
|
if (clanInfo != null)
|
||||||
|
{
|
||||||
|
clanInfo.playerOnline(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void quit(PlayerQuitEvent event)
|
||||||
|
{
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
ClanInfo clanInfo = getClanMemberMap().get(player.getName());
|
||||||
|
if (clanInfo != null)
|
||||||
|
{
|
||||||
|
clanInfo.playerOffline(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void handlePlayerChat(AsyncPlayerChatEvent event)
|
public void handlePlayerChat(AsyncPlayerChatEvent event)
|
||||||
{
|
{
|
||||||
@ -302,46 +336,29 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void messageClan(ClanInfo clan, String message)
|
||||||
|
{
|
||||||
|
for (Player player : clan.getOnlinePlayers())
|
||||||
|
UtilPlayer.message(player, message);
|
||||||
|
}
|
||||||
|
|
||||||
public void chatClan(ClanInfo clan, Player caller, String message)
|
public void chatClan(ClanInfo clan, Player caller, String message)
|
||||||
{
|
{
|
||||||
for (String cur : clan.getMembers().keySet())
|
messageClan(clan, C.cAqua + caller.getName() + " " + C.cDAqua + message);
|
||||||
{
|
|
||||||
Player player = UtilPlayer.searchOnline(null, cur, false);
|
|
||||||
|
|
||||||
if (player == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
UtilPlayer.message(player, C.cAqua + caller.getName() + " " + C.cDAqua + message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void chatAlly(ClanInfo clan, Player caller, String message)
|
public void chatAlly(ClanInfo clan, Player caller, String message)
|
||||||
{
|
{
|
||||||
for (String cur : clan.getMembers().keySet())
|
String sendMessage = C.cDGreen + clan.getName() + " " + C.cDGreen + caller.getName() + " " + C.cGreen + message;
|
||||||
{
|
|
||||||
Player player = UtilPlayer.searchOnline(null, cur, false);
|
|
||||||
|
|
||||||
if (player == null)
|
messageClan(clan, sendMessage);
|
||||||
continue;
|
|
||||||
|
|
||||||
UtilPlayer.message(player, C.cDGreen + clan.getName() + " " + C.cDGreen + caller.getName() + " " + C.cGreen + message);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String allyName : clan.getAllyMap().keySet())
|
for (String allyName : clan.getAllyMap().keySet())
|
||||||
{
|
{
|
||||||
ClanInfo ally = _clanUtility.getClanByClanName(allyName);
|
ClanInfo ally = _clanUtility.getClanByClanName(allyName);
|
||||||
if (ally == null) continue;
|
if (ally == null) continue;
|
||||||
|
|
||||||
for (String playerName : ally.getMembers().keySet())
|
messageClan(ally, sendMessage);
|
||||||
{
|
|
||||||
Player player = UtilPlayer.searchOnline(null, playerName, false);
|
|
||||||
|
|
||||||
if (player == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
UtilPlayer.message(player, C.cDGreen + clan.getName() + " " + C.cDGreen + caller.getName() + " " + C.cGreen + message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -466,4 +483,14 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
|
|||||||
{
|
{
|
||||||
return _classShop;
|
return _classShop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int convertGoldToEnergy(int gold)
|
||||||
|
{
|
||||||
|
return gold * 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int convertEnergyToGold(int energy)
|
||||||
|
{
|
||||||
|
return (energy / 4) + (energy % 4 == 0 ? 0 : 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package mineplex.game.clans.clans.repository;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
@ -27,7 +28,7 @@ public class ClanRepository extends RepositoryBase
|
|||||||
private static String CREATE_CLAN_ALLIANCE_TABLE = "CREATE TABLE IF NOT EXISTS clanAlliances (id INT NOT NULL AUTO_INCREMENT, clanId INT, otherClanId INT, trusted BOOL, PRIMARY KEY (id), FOREIGN KEY (otherClanId) REFERENCES clans(id), FOREIGN KEY (clanId) REFERENCES clans(id), INDEX clanIdIndex (clanId));";
|
private static String CREATE_CLAN_ALLIANCE_TABLE = "CREATE TABLE IF NOT EXISTS clanAlliances (id INT NOT NULL AUTO_INCREMENT, clanId INT, otherClanId INT, trusted BOOL, PRIMARY KEY (id), FOREIGN KEY (otherClanId) REFERENCES clans(id), FOREIGN KEY (clanId) REFERENCES clans(id), INDEX clanIdIndex (clanId));";
|
||||||
|
|
||||||
private static String RETRIEVE_START_CLAN_INFO = "SELECT c.id, c.name, c.description, c.home, c.admin, c.energy, c.dateCreated, c.lastOnline, ct.chunk, ct.safe FROM clans AS c LEFT JOIN clanTerritory AS ct ON ct.clanId = c.id WHERE c.serverName = ?;";
|
private static String RETRIEVE_START_CLAN_INFO = "SELECT c.id, c.name, c.description, c.home, c.admin, c.energy, c.dateCreated, c.lastOnline, ct.chunk, ct.safe FROM clans AS c LEFT JOIN clanTerritory AS ct ON ct.clanId = c.id WHERE c.serverName = ?;";
|
||||||
private static String RETRIEVE_CLAN_MEMBER_INFO = "SELECT c.name, a.name, clanRole FROM accountClan AS ac INNER JOIN accounts AS a ON a.id = ac.accountId INNER JOIN clans AS c on c.id = ac.clanId WHERE c.serverName = ?;";
|
private static String RETRIEVE_CLAN_MEMBER_INFO = "SELECT c.name, a.name, a.uuid, clanRole FROM accountClan AS ac INNER JOIN accounts AS a ON a.id = ac.accountId INNER JOIN clans AS c on c.id = ac.clanId WHERE c.serverName = ?;";
|
||||||
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 WHERE c.serverName = ?;";
|
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 WHERE c.serverName = ?;";
|
||||||
|
|
||||||
private static String DELETE_CLAN_MEMBER = "DELETE aC FROM accountClan AS aC INNER JOIN accounts ON accounts.id = aC.accountId WHERE aC.clanId = ? AND accounts.name = ?;";
|
private static String DELETE_CLAN_MEMBER = "DELETE aC FROM accountClan AS aC INNER JOIN accounts ON accounts.id = aC.accountId WHERE aC.clanId = ? AND accounts.name = ?;";
|
||||||
@ -117,7 +118,8 @@ public class ClanRepository extends RepositoryBase
|
|||||||
{
|
{
|
||||||
ClanMemberToken memberToken = new ClanMemberToken();
|
ClanMemberToken memberToken = new ClanMemberToken();
|
||||||
memberToken.Name = resultSet.getString(2);
|
memberToken.Name = resultSet.getString(2);
|
||||||
memberToken.ClanRole = resultSet.getString(3);
|
memberToken.PlayerUUID = UUID.fromString(resultSet.getString(3));
|
||||||
|
memberToken.ClanRole = resultSet.getString(4);
|
||||||
|
|
||||||
clans.get(clanName).Members.add(memberToken);
|
clans.get(clanName).Members.add(memberToken);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package mineplex.game.clans.clans.repository.tokens;
|
package mineplex.game.clans.clans.repository.tokens;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class ClanMemberToken
|
public class ClanMemberToken
|
||||||
{
|
{
|
||||||
public String Name;
|
public String Name;
|
||||||
|
public UUID PlayerUUID;
|
||||||
public String ClanRole;
|
public String ClanRole;
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
|
||||||
import mineplex.core.account.CoreClientManager;
|
import mineplex.core.account.CoreClientManager;
|
||||||
|
import mineplex.core.common.util.C;
|
||||||
|
import mineplex.core.common.util.F;
|
||||||
import mineplex.core.common.util.UtilPlayer;
|
import mineplex.core.common.util.UtilPlayer;
|
||||||
import mineplex.core.shop.ShopBase;
|
import mineplex.core.shop.ShopBase;
|
||||||
import mineplex.core.shop.page.ShopPageBase;
|
import mineplex.core.shop.page.ShopPageBase;
|
||||||
@ -28,7 +30,7 @@ public class BuildingShop extends ShopBase<ClansManager>
|
|||||||
{
|
{
|
||||||
if (event.getMessage().startsWith("/gold"))
|
if (event.getMessage().startsWith("/gold"))
|
||||||
{
|
{
|
||||||
UtilPlayer.message(event.getPlayer(), "PVP SHOP > Gold balance : " + DonationManager.Get(event.getPlayer().getName()).getGold());
|
UtilPlayer.message(event.getPlayer(), F.main("Gold", "Your Balance is " + C.cYellow + DonationManager.Get(event.getPlayer().getName()).getGold() + "g"));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,129 @@
|
|||||||
|
package mineplex.game.clans.shop.energy;
|
||||||
|
|
||||||
|
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.F;
|
||||||
|
import mineplex.core.donation.DonationManager;
|
||||||
|
import mineplex.core.itemstack.ItemStackFactory;
|
||||||
|
import mineplex.core.shop.item.ShopItem;
|
||||||
|
import mineplex.core.shop.page.ShopPageBase;
|
||||||
|
import mineplex.game.clans.clans.ClanInfo;
|
||||||
|
import mineplex.game.clans.clans.ClansManager;
|
||||||
|
|
||||||
|
public class EnergyPage extends ShopPageBase<ClansManager, EnergyShop>
|
||||||
|
{
|
||||||
|
private ClanInfo _clanInfo;
|
||||||
|
|
||||||
|
public EnergyPage(ClansManager plugin, EnergyShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player)
|
||||||
|
{
|
||||||
|
super(plugin, shop, clientManager, donationManager, "Energy Shop", player, 9);
|
||||||
|
_clanInfo = Plugin.getClan(Player);
|
||||||
|
|
||||||
|
BuildPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void BuildPage()
|
||||||
|
{
|
||||||
|
if (_clanInfo == null)
|
||||||
|
{
|
||||||
|
buildNoClan();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (_clanInfo.getEnergyPurchasable() > 0)
|
||||||
|
{
|
||||||
|
if (hasEnoughGold())
|
||||||
|
{
|
||||||
|
buildPurchasable(_clanInfo);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buildNotEnoughGold(_clanInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buildMaxEnergy(_clanInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buildPurchasable(ClanInfo _clanInfo)
|
||||||
|
{
|
||||||
|
int playerGold = getPlayerGold();
|
||||||
|
int energyCost = getEnergyPerHour();
|
||||||
|
int goldCost = getGoldPerHour();
|
||||||
|
|
||||||
|
EnergyShopButton button = new EnergyShopButton(Player, Plugin, this, _clanInfo, true, getDonationManager());
|
||||||
|
String title = "Purchase Energy";
|
||||||
|
String currentEnergy = ChatColor.RESET + F.value("Clan Energy", "" + _clanInfo.getEnergy());
|
||||||
|
String energyString = ChatColor.RESET + F.value("Energy drain/hour", "" + energyCost);
|
||||||
|
String playerGoldString = ChatColor.RESET + F.value("Your Gold", playerGold + "g");
|
||||||
|
String purchaseString = ChatColor.RESET + C.cWhite + "Click to buy 1 hour of energy for " + C.cYellow + goldCost + "g";
|
||||||
|
ShopItem shopItem = new ShopItem(Material.LAVA_BUCKET, title, new String[] {" ", currentEnergy, energyString, " ", playerGoldString, purchaseString}, 0, false, false);
|
||||||
|
AddButton(4, shopItem, button);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buildNotEnoughGold(ClanInfo _clanInfo)
|
||||||
|
{
|
||||||
|
int playerGold = getPlayerGold();
|
||||||
|
int energyCost = getEnergyPerHour();
|
||||||
|
int goldCost = getGoldPerHour();
|
||||||
|
|
||||||
|
EnergyShopButton button = new EnergyShopButton(Player, Plugin, this, _clanInfo, true, getDonationManager());
|
||||||
|
String title = ChatColor.RED + C.Bold + "Missing Gold!";
|
||||||
|
String currentEnergy = ChatColor.RESET + F.value("Clan Energy", "" + _clanInfo.getEnergy());
|
||||||
|
String energyString = ChatColor.RESET + F.value("Energy drain/hour", "" + energyCost);
|
||||||
|
String playerGoldString = ChatColor.RESET + F.value("Your Gold", playerGold + "g");
|
||||||
|
String purchaseString = ChatColor.RESET + C.cWhite + "You don't have enough gold";
|
||||||
|
String goldString = ChatColor.RESET + C.cWhite + "You need " + C.cYellow + goldCost + C.cWhite + " gold to purchase energy";
|
||||||
|
ShopItem shopItem = new ShopItem(Material.GOLD_INGOT, title, new String[] {" ", currentEnergy, energyString, " ", playerGoldString, purchaseString, goldString}, 0, false, false);
|
||||||
|
AddButton(4, shopItem, button);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buildNoClan()
|
||||||
|
{
|
||||||
|
ShopItem shopItem = new ShopItem(Material.GLASS, "No Clan!", new String[] {" ", "You need to be in a", "clan to purchase energy!"}, 1, false, false);
|
||||||
|
setItem(4, shopItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buildMaxEnergy(ClanInfo _clanInfo)
|
||||||
|
{
|
||||||
|
int energy = _clanInfo.getEnergy();
|
||||||
|
String title = C.cRed + C.Bold + "Cannot Purchase Energy!";
|
||||||
|
String currentEnergy = ChatColor.RESET + F.value("Clan Energy", "" + energy);
|
||||||
|
String[] lore = new String[] {" ", currentEnergy, ChatColor.RESET + "Your clan is at the energy cap"};
|
||||||
|
ShopItem shopItem = new ShopItem(Material.BUCKET, title, lore, 0, false, false);
|
||||||
|
AddItem(4, shopItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean hasEnoughGold()
|
||||||
|
{
|
||||||
|
return getPlayerGold() >= getGoldPerHour();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int getGoldPerHour()
|
||||||
|
{
|
||||||
|
return Plugin.convertEnergyToGold(getEnergyPerHour());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int getEnergyPerHour()
|
||||||
|
{
|
||||||
|
return _clanInfo.getEnergyCostPerMinute() * 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int getPlayerGold()
|
||||||
|
{
|
||||||
|
return getDonationManager().Get(Player).getGold();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showLoading()
|
||||||
|
{
|
||||||
|
ItemStack is = ItemStackFactory.Instance.CreateStack(Material.WOOL, (byte) 11, 1, C.cAqua + C.Bold + "Please Wait..");
|
||||||
|
setItem(4, is);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package mineplex.game.clans.shop.energy;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import mineplex.core.account.CoreClientManager;
|
||||||
|
import mineplex.core.donation.DonationManager;
|
||||||
|
import mineplex.core.shop.ShopBase;
|
||||||
|
import mineplex.core.shop.page.ShopPageBase;
|
||||||
|
import mineplex.game.clans.clans.ClansManager;
|
||||||
|
|
||||||
|
public class EnergyShop extends ShopBase<ClansManager>
|
||||||
|
{
|
||||||
|
|
||||||
|
public EnergyShop(ClansManager plugin, CoreClientManager clientManager, DonationManager donationManager)
|
||||||
|
{
|
||||||
|
super(plugin, clientManager, donationManager, "Energy Shop");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ShopPageBase<ClansManager, ? extends ShopBase<ClansManager>> BuildPagesFor(Player player)
|
||||||
|
{
|
||||||
|
return new EnergyPage(Plugin, this, ClientManager, DonationManager, player);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
package mineplex.game.clans.shop.energy;
|
||||||
|
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
|
||||||
|
import mineplex.core.common.util.Callback;
|
||||||
|
import mineplex.core.donation.DonationManager;
|
||||||
|
import mineplex.core.shop.item.IButton;
|
||||||
|
import mineplex.game.clans.clans.ClanInfo;
|
||||||
|
import mineplex.game.clans.clans.ClansManager;
|
||||||
|
|
||||||
|
public class EnergyShopButton implements IButton
|
||||||
|
{
|
||||||
|
private Player _player;
|
||||||
|
private ClansManager _clansManager;
|
||||||
|
private EnergyPage _page;
|
||||||
|
private ClanInfo _clanInfo;
|
||||||
|
private boolean _canPurchaseEnergy;
|
||||||
|
private DonationManager _donationManager;
|
||||||
|
|
||||||
|
public EnergyShopButton(Player player, ClansManager clansManager, EnergyPage page, ClanInfo clanInfo, boolean canPurchaseEnergy, DonationManager donationManager)
|
||||||
|
{
|
||||||
|
_player = player;
|
||||||
|
_clansManager = clansManager;
|
||||||
|
_clanInfo = clanInfo;
|
||||||
|
_canPurchaseEnergy = canPurchaseEnergy;
|
||||||
|
_donationManager = donationManager;
|
||||||
|
_page = page;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(final Player player, ClickType clickType)
|
||||||
|
{
|
||||||
|
if (_page.hasEnoughGold())
|
||||||
|
{
|
||||||
|
int playerGold = _page.getPlayerGold();
|
||||||
|
final int energy = _page.getEnergyPerHour();
|
||||||
|
int goldCost = _page.getGoldPerHour();
|
||||||
|
|
||||||
|
_page.clearPage();
|
||||||
|
_page.showLoading();
|
||||||
|
_donationManager.RewardGold(new Callback<Boolean>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run(Boolean data)
|
||||||
|
{
|
||||||
|
player.playSound(player.getEyeLocation(), Sound.ANVIL_USE, 1, 1);
|
||||||
|
_clanInfo.adjustEnergy(energy);
|
||||||
|
_page.Refresh();
|
||||||
|
}
|
||||||
|
}, "Energy Purchase", player.getName(), player.getUniqueId(), -goldCost, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user