Work on amplifiers and deleting banners when the clan is deleted

This commit is contained in:
AlexTheCoder 2016-07-21 13:20:45 -04:00
parent e5cd38c11b
commit 1f2b1557d5
8 changed files with 222 additions and 5 deletions

View File

@ -137,7 +137,7 @@ public class Clans extends JavaPlugin
new MemoryFix(this);
new FoodDupeFix(this);
new Explosion(this, blockRestore);
new InventoryManager(this, _clientManager);
InventoryManager inventory = new InventoryManager(this, _clientManager);
ResourcePackManager resourcePackManager = new ResourcePackManager(this, portal);
resourcePackManager.setResourcePack(new Pair[]
{
@ -154,7 +154,7 @@ public class Clans extends JavaPlugin
GearManager customGear = new GearManager(this, packetHandler, _clientManager, _donationManager);
HologramManager hologram = new HologramManager(this, packetHandler);
_clansManager = new ClansManager(this, clansBans, serverStatusManager.getCurrentServerName(), incognito, packetHandler, punish, _clientManager, _donationManager, preferenceManager, blockRestore, statsManager, teleport, chat, customGear, hologram, webServerAddress);
_clansManager = new ClansManager(this, clansBans, serverStatusManager.getCurrentServerName(), incognito, packetHandler, punish, _clientManager, _donationManager, preferenceManager, blockRestore, statsManager, teleport, chat, customGear, hologram, inventory, webServerAddress);
new Recipes(this);
new Farming(this);
new BuildingShop(_clansManager, _clientManager, _donationManager);

View File

@ -35,6 +35,7 @@ import mineplex.core.hologram.Hologram;
import mineplex.core.hologram.HologramManager;
import mineplex.core.incognito.IncognitoManager;
import mineplex.core.incognito.events.IncognitoStatusChangeEvent;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.movement.Movement;
import mineplex.core.npc.NpcManager;
import mineplex.core.packethandler.PacketHandler;
@ -179,6 +180,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
private GearManager _gearManager;
private LootManager _lootManager;
private DonationManager _donationManager;
private InventoryManager _inventoryManager;
private NetherManager _netherManager;
private DamageManager _damageManager;
private SiegeManager _siegeManager;
@ -241,7 +243,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
// Spawn area
public ClansManager(JavaPlugin plugin, ClansBanManager clansBans, String serverName, IncognitoManager incognitoManager, PacketHandler packetHandler, Punish punish, CoreClientManager clientManager, DonationManager donationManager, PreferencesManager preferencesManager, BlockRestore blockRestore, StatsManager statsManager, Teleport teleport, Chat chat, GearManager gearManager, HologramManager hologramManager, String webServerAddress)
public ClansManager(JavaPlugin plugin, ClansBanManager clansBans, String serverName, IncognitoManager incognitoManager, PacketHandler packetHandler, Punish punish, CoreClientManager clientManager, DonationManager donationManager, PreferencesManager preferencesManager, BlockRestore blockRestore, StatsManager statsManager, Teleport teleport, Chat chat, GearManager gearManager, HologramManager hologramManager, InventoryManager inventoryManager, String webServerAddress)
{
super("Clans Manager", plugin);
@ -264,6 +266,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
_warManager = new WarManager(plugin, this);
_donationManager = donationManager;
_inventoryManager = inventoryManager;
_blacklist = new ClansBlacklist(plugin);
@ -516,6 +519,11 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
return _donationManager;
}
public InventoryManager getInventoryManager()
{
return _inventoryManager;
}
public ItemMapManager getItemMapManager()
{
return _itemMapManager;

View File

@ -0,0 +1,13 @@
package mineplex.game.clans.clans.amplifiers;
import mineplex.game.clans.clans.amplifiers.AmplifierManager.AmplifierType;
import org.bukkit.entity.Player;
public class Amplifier
{
public Amplifier(Player owner, AmplifierType type)
{
}
}

View File

@ -0,0 +1,125 @@
package mineplex.game.clans.clans.amplifiers;
import java.util.HashMap;
import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.amplifiers.AmplifierManager.AmplifierType;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
public abstract class AmplifierGUI implements Listener
{
private Player _viewer;
private AmplifierManager _manager;
private Inventory _inventory;
private final HashMap<Integer, ItemStack> _items = new HashMap<>();
private final HashMap<Integer, AmplifierType> _boundSlots = new HashMap<>();
private AmplifierType _selected;
public AmplifierGUI(Player viewer, AmplifierManager manager)
{
_viewer = viewer;
_inventory = Bukkit.createInventory(viewer, 9 * Math.max(1, AmplifierType.values().length % 9), C.cClansNether + "Rune Amplifiers");
Bukkit.getPluginManager().registerEvents(this, ClansManager.getInstance().getPlugin());
}
public Player getViewer()
{
return _viewer;
}
public HashMap<Integer, ItemStack> getItems()
{
return _items;
}
public void propagate()
{
getItems().clear();
Integer slot = 0;
for (AmplifierType type : AmplifierType.values())
{
getItems().put(slot, new ItemBuilder(Material.NETHER_STAR).setAmount(_manager.getAmountOwned(getViewer(), type)).setTitle(type.getDisplayName()).build());
_boundSlots.put(slot, type);
}
}
public void propagateConfirmation()
{
getItems().clear();
_boundSlots.clear();
getItems().put(3, new ItemBuilder(Material.STAINED_GLASS_PANE).setData((short) 5).setTitle(C.cGreen + "Confirm").build());
getItems().put(5, new ItemBuilder(Material.STAINED_GLASS_PANE).setData((short) 14).setTitle(C.cRed + "Cancel").build());
}
public void onClick(Integer slot, ClickType type)
{
if (_boundSlots.containsKey(slot))
{
}
}
public void open()
{
_viewer.openInventory(_inventory);
}
public void refresh()
{
_inventory.clear();
for (Integer slot : _items.keySet())
{
_inventory.setItem(slot, _items.get(slot));
}
for (Integer slot = 0; slot < _inventory.getSize(); slot++)
{
if (!_items.containsKey(slot))
{
_inventory.setItem(slot, new ItemBuilder(Material.STAINED_GLASS_PANE).setTitle(C.cGray).setData((short)7).build());
}
}
_viewer.updateInventory();
}
@EventHandler
public void handleClick(InventoryClickEvent event)
{
if (event.getClickedInventory() == null || !event.getClickedInventory().equals(_inventory))
{
return;
}
if (!_viewer.getName().equals(event.getWhoClicked().getName()))
{
return;
}
event.setCancelled(true);
Integer slot = event.getSlot();
if (!_items.containsKey(slot))
{
return;
}
onClick(slot, event.getClick());
}
@EventHandler
public void onClose(InventoryCloseEvent event)
{
if (event.getPlayer().getUniqueId().equals(_viewer.getUniqueId()))
{
HandlerList.unregisterAll(this);
}
}
}

View File

@ -1,6 +1,56 @@
package mineplex.game.clans.clans.amplifiers;
public class AmplifierManager
{
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.game.clans.clans.ClansManager;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class AmplifierManager extends MiniPlugin
{
private static final String AMPLIFIER_NAME = "Rune Amplifier";
public AmplifierManager(JavaPlugin plugin)
{
super("Rune Amplifiers", plugin);
}
public int getAmountOwned(Player player, AmplifierType type)
{
return ClansManager.getInstance().getInventoryManager().Get(player).getItemCount(type.getFullItemName());
}
public static enum AmplifierType
{
TWENTY("20", "Twenty Minute Amplifier", UtilTime.convert(20, TimeUnit.MINUTES, TimeUnit.MILLISECONDS)),
SIXTY("60", "One Hour Amplifier", UtilTime.convert(60, TimeUnit.MINUTES, TimeUnit.MILLISECONDS));
private String _extension, _display;
private long _duration;
private AmplifierType(String extension, String displayName, long duration)
{
_extension = extension;
_display = C.cClansNether + displayName;
_duration = duration;
}
public String getFullItemName()
{
return AMPLIFIER_NAME + " " + _extension;
}
public String getDisplayName()
{
return _display;
}
public long getDuration()
{
return _duration;
}
}
}

View File

@ -69,6 +69,17 @@ public class BannerManager extends MiniPlugin
_repo.saveBanner(banner);
}
public void deleteBanner(ClanInfo clan)
{
_repo.deleteBanner(clan);
LoadedBanners.remove(clan.getName());
}
public void deleteBanner(ClanBanner banner)
{
deleteBanner(banner.getClan());
}
public void placeBanner(Player placing, ClanBanner banner)
{
Block block = placing.getLocation().getBlock();

View File

@ -24,6 +24,7 @@ public class BannerRepository extends MinecraftRepository
private static final String GET_BANNER_BY_CLAN = "SELECT * FROM clanBanners WHERE clanId=? LIMIT 1;";
private static final String INSERT_BANNER = "INSERT INTO clanBanners (clanId, baseColor, patterns) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE baseColor=VALUES(baseColor), patterns=VALUES(patterns);";
private static final String DELETE_BANNER = "DELETE FROM clanBanners WHERE clanId=?;";
private BannerManager _bannerManager;
@ -89,6 +90,14 @@ public class BannerRepository extends MinecraftRepository
executeUpdate(INSERT_BANNER, new ColumnInt("clanId", banner.getClan().getId()), new ColumnVarChar("baseColor", 15, banner.getBaseColor().toString()), new ColumnVarChar("patterns", 300, patternStr));
});
}
public void deleteBanner(ClanInfo clan)
{
_bannerManager.runAsync(() ->
{
executeUpdate(DELETE_BANNER, new ColumnInt("clanId", clan.getId()));
});
}
@Override
protected void initialize()

View File

@ -52,6 +52,7 @@ public abstract class BannerGUI implements Listener
public void refresh()
{
_inventory.clear();
for (Integer slot : _items.keySet())
{
_inventory.setItem(slot, _items.get(slot));