Remove non-working parts of ChestGUI

This commit is contained in:
Magnus Ulf 2019-05-13 12:56:55 +02:00
parent 69b2a8f0c9
commit cfb4f6ae93
3 changed files with 2 additions and 119 deletions

View File

@ -4,8 +4,6 @@ import com.massivecraft.massivecore.util.IdUtil;
import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.MUtil;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
public class ChestActionAbstract implements ChestAction public class ChestActionAbstract implements ChestAction
{ {
@ -19,27 +17,6 @@ public class ChestActionAbstract implements ChestAction
Player player = IdUtil.getAsPlayer(event.getWhoClicked()); Player player = IdUtil.getAsPlayer(event.getWhoClicked());
if (MUtil.isntPlayer(player)) return false; if (MUtil.isntPlayer(player)) return false;
// Variables
Inventory inventory = event.getInventory();
ChestGui gui = ChestGui.get(inventory);
int slot = event.getSlot();
// Transform item
ItemStack itemBefore = event.getCurrentItem();
ItemStack itemAfter = transformItem(itemBefore);
if (itemAfter != null)
{
inventory.setItem(slot, itemAfter);
}
// Transform action
ChestAction actionAfter = transformAction();
if (actionAfter != null)
{
gui.setAction(slot, actionAfter);
}
return onClick(event, player); return onClick(event, player);
} }
@ -48,14 +25,4 @@ public class ChestActionAbstract implements ChestAction
return false; return false;
} }
public ItemStack transformItem(ItemStack clickedItem)
{
return null;
}
public ChestAction transformAction()
{
return null;
}
} }

View File

@ -1,84 +0,0 @@
package com.massivecraft.massivecore.chestgui;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
public class ChestActionToggle extends ChestActionAbstract implements ChestButton
{
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private final ItemStack enabledItem;
public ItemStack getEnabledItem() { return this.enabledItem; }
private final ItemStack disabledItem;
public ItemStack getDisabledItem() { return this.disabledItem; }
private final ChestAction enableAction;
public ChestAction getEnableAction() { return this.enableAction; }
private final ChestAction disableAction;
public ChestAction getDisableAction() { return this.disableAction; }
private boolean enabled;
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public ChestActionToggle(ItemStack enabledItem, ItemStack disabledItem, ChestAction enableAction, ChestAction disableAction, boolean enabled)
{
this.enabledItem = enabledItem;
this.disabledItem = disabledItem;
this.enableAction = enableAction;
this.disableAction = disableAction;
this.enabled = enabled;
}
// -------------------------------------------- //
// OVERRIDE: CHEST ACTION
// -------------------------------------------- //
@Override
public boolean onClick(InventoryClickEvent event, Player player)
{
// If it is enabled then use the disable action
// If it is disabled use the enable action
boolean ret;
ChestAction inner = this.enabled ? this.getDisableAction() : this.getEnableAction();
ret = inner.onClick(event);
this.enabled = !this.enabled;
return ret;
}
// This method is run /before/ onClick
// so this.enabled has not yet changed value
@Override
public ItemStack transformItem(ItemStack clickedItem)
{
// Currently enabled means it will be disabled, so show the disable item and vice versa
return this.enabled ? this.getDisabledItem() : this.getEnabledItem();
}
// -------------------------------------------- //
// OVERRIDE: CHEST BUTTON
// -------------------------------------------- //
@Override
public ChestAction getAction()
{
return this;
}
@Override
public ItemStack getItem()
{
return this.enabled ? this.getEnabledItem() : this.getDisabledItem();
}
}

View File

@ -177,7 +177,7 @@ public class ChestGui
} }
public ChestGui constructFromButtons(List<ChestButton> buttons) public static ChestGui constructFromButtons(List<? extends ChestButton> buttons, String title)
{ {
int size = buttons.size(); int size = buttons.size();
int modulo = size % 9; int modulo = size % 9;
@ -186,7 +186,7 @@ public class ChestGui
size = size + 9 - modulo; size = size + 9 - modulo;
} }
Inventory inventory = Bukkit.createInventory(null, size); Inventory inventory = Bukkit.createInventory(null, size, title);
ChestGui gui = getCreative(inventory); ChestGui gui = getCreative(inventory);
for (int i = 0; i < buttons.size(); i++) for (int i = 0; i < buttons.size(); i++)