mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
[CI skip] Reduced technical debt
This commit is contained in:
parent
f50d1d2faa
commit
c168497e79
@ -50,6 +50,7 @@
|
||||
* Fixed #2183
|
||||
* Fixed #2181
|
||||
* Fixed #2180
|
||||
* Fixed #2122
|
||||
|
||||
## Release Candidate 15 (01 Aug 2020)
|
||||
|
||||
|
@ -2,19 +2,33 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.cargo;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
|
||||
import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
|
||||
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.ChatUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.HeadTexture;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
||||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
|
||||
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
|
||||
|
||||
/**
|
||||
* This abstract class is the super class of all cargo nodes.
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
*/
|
||||
abstract class AbstractCargoNode extends SlimefunItem {
|
||||
|
||||
protected static final String FREQUENCY = "frequency";
|
||||
@ -22,6 +36,21 @@ abstract class AbstractCargoNode extends SlimefunItem {
|
||||
public AbstractCargoNode(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
|
||||
super(category, item, recipeType, recipe, recipeOutput);
|
||||
|
||||
addItemHandler(new BlockPlaceHandler(false) {
|
||||
|
||||
@Override
|
||||
public void onPlayerPlace(BlockPlaceEvent e) {
|
||||
Block b = e.getBlock();
|
||||
|
||||
// The owner and frequency are required by every node
|
||||
BlockStorage.addBlockInfo(b, "owner", e.getPlayer().getUniqueId().toString());
|
||||
BlockStorage.addBlockInfo(b, FREQUENCY, "0");
|
||||
|
||||
onPlace(e);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
new BlockMenuPreset(getID(), ChatUtils.removeColorCodes(item.getItemMeta().getDisplayName())) {
|
||||
|
||||
@Override
|
||||
@ -46,6 +75,59 @@ abstract class AbstractCargoNode extends SlimefunItem {
|
||||
};
|
||||
}
|
||||
|
||||
protected void addChannelSelector(Block b, BlockMenu menu, int slotPrev, int slotCurrent, int slotNext) {
|
||||
boolean isChestTerminalInstalled = SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled();
|
||||
|
||||
menu.replaceExistingItem(slotPrev, new CustomItem(SlimefunUtils.getCustomHead(HeadTexture.CARGO_ARROW_LEFT.getTexture()), "&bPrevious Channel", "", "&e> Click to decrease the Channel ID by 1"));
|
||||
menu.addMenuClickHandler(slotPrev, (p, slot, item, action) -> {
|
||||
int channel = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), FREQUENCY)) - 1;
|
||||
|
||||
if (channel < 0) {
|
||||
if (isChestTerminalInstalled) {
|
||||
channel = 16;
|
||||
}
|
||||
else {
|
||||
channel = 15;
|
||||
}
|
||||
}
|
||||
|
||||
BlockStorage.addBlockInfo(b, FREQUENCY, String.valueOf(channel));
|
||||
updateBlockMenu(menu, b);
|
||||
return false;
|
||||
});
|
||||
|
||||
int channel = ((!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), FREQUENCY) == null) ? 0 : (Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), FREQUENCY))));
|
||||
|
||||
if (channel == 16) {
|
||||
menu.replaceExistingItem(slotCurrent, new CustomItem(SlimefunUtils.getCustomHead(HeadTexture.CHEST_TERMINAL.getTexture()), "&bChannel ID: &3" + (channel + 1)));
|
||||
menu.addMenuClickHandler(slotCurrent, ChestMenuUtils.getEmptyClickHandler());
|
||||
}
|
||||
else {
|
||||
menu.replaceExistingItem(slotCurrent, new CustomItem(MaterialCollections.getAllWoolColors().get(channel), "&bChannel ID: &3" + (channel + 1)));
|
||||
menu.addMenuClickHandler(slotCurrent, ChestMenuUtils.getEmptyClickHandler());
|
||||
}
|
||||
|
||||
menu.replaceExistingItem(slotNext, new CustomItem(SlimefunUtils.getCustomHead(HeadTexture.CARGO_ARROW_RIGHT.getTexture()), "&bNext Channel", "", "&e> Click to increase the Channel ID by 1"));
|
||||
menu.addMenuClickHandler(slotNext, (p, slot, item, action) -> {
|
||||
int channeln = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), FREQUENCY)) + 1;
|
||||
|
||||
if (isChestTerminalInstalled) {
|
||||
if (channeln > 16) {
|
||||
channeln = 0;
|
||||
}
|
||||
}
|
||||
else if (channeln > 15) {
|
||||
channeln = 0;
|
||||
}
|
||||
|
||||
BlockStorage.addBlockInfo(b, FREQUENCY, String.valueOf(channeln));
|
||||
updateBlockMenu(menu, b);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
protected abstract void onPlace(BlockPlaceEvent e);
|
||||
|
||||
protected abstract void createBorder(BlockMenuPreset preset);
|
||||
|
||||
protected abstract void updateBlockMenu(BlockMenu menu, Block b);
|
||||
|
@ -0,0 +1,140 @@
|
||||
package io.github.thebusybiscuit.slimefun4.implementation.items.cargo;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
||||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
|
||||
|
||||
/**
|
||||
* This abstract super class represents all filtered Cargo nodes.
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
* @see CargoInputNode
|
||||
* @see AdvancedCargoOutputNode
|
||||
*
|
||||
*/
|
||||
abstract class AbstractFilterNode extends AbstractCargoNode {
|
||||
|
||||
protected static final int[] SLOTS = { 19, 20, 21, 28, 29, 30, 37, 38, 39 };
|
||||
|
||||
public AbstractFilterNode(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
|
||||
super(category, item, recipeType, recipe, recipeOutput);
|
||||
|
||||
registerBlockHandler(getID(), (p, b, stack, reason) -> {
|
||||
BlockMenu inv = BlockStorage.getInventory(b);
|
||||
|
||||
if (inv != null) {
|
||||
inv.dropItems(b.getLocation(), SLOTS);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
protected abstract int[] getBorder();
|
||||
|
||||
@Override
|
||||
protected void onPlace(BlockPlaceEvent e) {
|
||||
Block b = e.getBlock();
|
||||
BlockStorage.addBlockInfo(b, "index", "0");
|
||||
BlockStorage.addBlockInfo(b, "filter-type", "whitelist");
|
||||
BlockStorage.addBlockInfo(b, "filter-lore", String.valueOf(true));
|
||||
BlockStorage.addBlockInfo(b, "filter-durability", String.valueOf(false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createBorder(BlockMenuPreset preset) {
|
||||
for (int i : getBorder()) {
|
||||
preset.addItem(i, new CustomItem(Material.CYAN_STAINED_GLASS_PANE, " "), ChestMenuUtils.getEmptyClickHandler());
|
||||
}
|
||||
|
||||
preset.addItem(2, new CustomItem(Material.PAPER, "&3Items", "", "&bPut in all Items you want to", "&bblacklist/whitelist"), ChestMenuUtils.getEmptyClickHandler());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateBlockMenu(BlockMenu menu, Block b) {
|
||||
String filterType = BlockStorage.getLocationInfo(b.getLocation(), "filter-type");
|
||||
|
||||
if (!BlockStorage.hasBlockInfo(b) || filterType == null || filterType.equals("whitelist")) {
|
||||
menu.replaceExistingItem(15, new CustomItem(Material.WHITE_WOOL, "&7Type: &rWhitelist", "", "&e> Click to change it to Blacklist"));
|
||||
menu.addMenuClickHandler(15, (p, slot, item, action) -> {
|
||||
BlockStorage.addBlockInfo(b, "filter-type", "blacklist");
|
||||
updateBlockMenu(menu, b);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
else {
|
||||
menu.replaceExistingItem(15, new CustomItem(Material.BLACK_WOOL, "&7Type: &8Blacklist", "", "&e> Click to change it to Whitelist"));
|
||||
menu.addMenuClickHandler(15, (p, slot, item, action) -> {
|
||||
BlockStorage.addBlockInfo(b, "filter-type", "whitelist");
|
||||
updateBlockMenu(menu, b);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
String durability = BlockStorage.getLocationInfo(b.getLocation(), "filter-durability");
|
||||
|
||||
if (!BlockStorage.hasBlockInfo(b) || durability == null || durability.equals(String.valueOf(false))) {
|
||||
ItemStack is = new ItemStack(Material.STONE_SWORD);
|
||||
ItemMeta meta = is.getItemMeta();
|
||||
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||
is.setItemMeta(meta);
|
||||
|
||||
menu.replaceExistingItem(16, new CustomItem(is, "&7Include Sub-IDs/Durability: &4\u2718", "", "&e> Click to toggle whether the Durability has to match"));
|
||||
menu.addMenuClickHandler(16, (p, slot, item, action) -> {
|
||||
BlockStorage.addBlockInfo(b, "filter-durability", String.valueOf(true));
|
||||
updateBlockMenu(menu, b);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
else {
|
||||
ItemStack is = new ItemStack(Material.GOLDEN_SWORD);
|
||||
ItemMeta meta = is.getItemMeta();
|
||||
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||
((Damageable) meta).setDamage(20);
|
||||
is.setItemMeta(meta);
|
||||
|
||||
menu.replaceExistingItem(16, new CustomItem(is, "&7Include Sub-IDs/Durability: &2\u2714", "", "&e> Click to toggle whether the Durability has to match"));
|
||||
menu.addMenuClickHandler(16, (p, slot, item, action) -> {
|
||||
BlockStorage.addBlockInfo(b, "filter-durability", String.valueOf(false));
|
||||
updateBlockMenu(menu, b);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
String lore = BlockStorage.getLocationInfo(b.getLocation(), "filter-lore");
|
||||
|
||||
if (!BlockStorage.hasBlockInfo(b) || lore == null || lore.equals(String.valueOf(true))) {
|
||||
menu.replaceExistingItem(25, new CustomItem(Material.MAP, "&7Include Lore: &2\u2714", "", "&e> Click to toggle whether the Lore has to match"));
|
||||
menu.addMenuClickHandler(25, (p, slot, item, action) -> {
|
||||
BlockStorage.addBlockInfo(b, "filter-lore", String.valueOf(false));
|
||||
updateBlockMenu(menu, b);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
else {
|
||||
menu.replaceExistingItem(25, new CustomItem(Material.MAP, "&7Include Lore: &4\u2718", "", "&e> Click to toggle whether the Lore has to match"));
|
||||
menu.addMenuClickHandler(25, (p, slot, item, action) -> {
|
||||
BlockStorage.addBlockInfo(b, "filter-lore", String.valueOf(true));
|
||||
updateBlockMenu(menu, b);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
addChannelSelector(b, menu, 41, 42, 43);
|
||||
}
|
||||
|
||||
}
|
@ -1,165 +1,22 @@
|
||||
package io.github.thebusybiscuit.slimefun4.implementation.items.cargo;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
|
||||
import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
||||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
|
||||
|
||||
public class AdvancedCargoOutputNode extends AbstractCargoNode {
|
||||
public class AdvancedCargoOutputNode extends AbstractFilterNode {
|
||||
|
||||
private static final int[] BORDER = { 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 17, 18, 22, 23, 24, 26, 27, 31, 32, 33, 34, 35, 36, 40, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 };
|
||||
private static final int[] SLOTS = { 19, 20, 21, 28, 29, 30, 37, 38, 39 };
|
||||
|
||||
public AdvancedCargoOutputNode(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
|
||||
super(category, item, recipeType, recipe, recipeOutput);
|
||||
|
||||
addItemHandler(onPlace());
|
||||
registerBlockHandler(getID(), (p, b, stack, reason) -> {
|
||||
BlockMenu inv = BlockStorage.getInventory(b);
|
||||
|
||||
if (inv != null) {
|
||||
inv.dropItems(b.getLocation(), SLOTS);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
private BlockPlaceHandler onPlace() {
|
||||
return new BlockPlaceHandler(false) {
|
||||
|
||||
@Override
|
||||
public void onPlayerPlace(BlockPlaceEvent e) {
|
||||
Block b = e.getBlock();
|
||||
BlockStorage.addBlockInfo(b, "owner", e.getPlayer().getUniqueId().toString());
|
||||
BlockStorage.addBlockInfo(b, "index", "0");
|
||||
BlockStorage.addBlockInfo(b, FREQUENCY, "0");
|
||||
BlockStorage.addBlockInfo(b, "filter-type", "whitelist");
|
||||
BlockStorage.addBlockInfo(b, "filter-lore", String.valueOf(true));
|
||||
BlockStorage.addBlockInfo(b, "filter-durability", String.valueOf(false));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createBorder(BlockMenuPreset preset) {
|
||||
for (int i : BORDER) {
|
||||
preset.addItem(i, new CustomItem(Material.CYAN_STAINED_GLASS_PANE, " "), ChestMenuUtils.getEmptyClickHandler());
|
||||
}
|
||||
|
||||
preset.addItem(2, new CustomItem(Material.PAPER, "&3Items", "", "&bPut in all Items you want to", "&bblacklist/whitelist"), ChestMenuUtils.getEmptyClickHandler());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateBlockMenu(BlockMenu menu, Block b) {
|
||||
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-type") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-type").equals("whitelist")) {
|
||||
menu.replaceExistingItem(15, new CustomItem(Material.WHITE_WOOL, "&7Type: &rWhitelist", "", "&e> Click to change it to Blacklist"));
|
||||
menu.addMenuClickHandler(15, (p, slot, item, action) -> {
|
||||
BlockStorage.addBlockInfo(b, "filter-type", "blacklist");
|
||||
updateBlockMenu(menu, b);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
else {
|
||||
menu.replaceExistingItem(15, new CustomItem(Material.BLACK_WOOL, "&7Type: &8Blacklist", "", "&e> Click to change it to Whitelist"));
|
||||
menu.addMenuClickHandler(15, (p, slot, item, action) -> {
|
||||
BlockStorage.addBlockInfo(b, "filter-type", "whitelist");
|
||||
updateBlockMenu(menu, b);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability").equals(String.valueOf(false))) {
|
||||
menu.replaceExistingItem(16, new CustomItem(Material.STONE_SWORD, "&7Include Sub-IDs/Durability: &4\u2718", "", "&e> Click to toggle whether the Durability has to match"));
|
||||
menu.addMenuClickHandler(16, (p, slot, item, action) -> {
|
||||
BlockStorage.addBlockInfo(b, "filter-durability", String.valueOf(true));
|
||||
updateBlockMenu(menu, b);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
else {
|
||||
ItemStack is = new ItemStack(Material.GOLDEN_SWORD);
|
||||
Damageable dmg = (Damageable) is.getItemMeta();
|
||||
dmg.setDamage(20);
|
||||
is.setItemMeta((ItemMeta) dmg);
|
||||
|
||||
menu.replaceExistingItem(16, new CustomItem(is, "&7Include Sub-IDs/Durability: &2\u2714", "", "&e> Click to toggle whether the Durability has to match"));
|
||||
menu.addMenuClickHandler(16, (p, slot, item, action) -> {
|
||||
BlockStorage.addBlockInfo(b, "filter-durability", String.valueOf(false));
|
||||
updateBlockMenu(menu, b);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore").equals(String.valueOf(true))) {
|
||||
menu.replaceExistingItem(25, new CustomItem(Material.MAP, "&7Include Lore: &2\u2714", "", "&e> Click to toggle whether the Lore has to match"));
|
||||
menu.addMenuClickHandler(25, (p, slot, item, action) -> {
|
||||
BlockStorage.addBlockInfo(b, "filter-lore", String.valueOf(false));
|
||||
updateBlockMenu(menu, b);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
else {
|
||||
menu.replaceExistingItem(25, new CustomItem(Material.MAP, "&7Include Lore: &4\u2718", "", "&e> Click to toggle whether the Lore has to match"));
|
||||
menu.addMenuClickHandler(25, (p, slot, item, action) -> {
|
||||
BlockStorage.addBlockInfo(b, "filter-lore", String.valueOf(true));
|
||||
updateBlockMenu(menu, b);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
menu.replaceExistingItem(41, new CustomItem(SlimefunUtils.getCustomHead("f2599bd986659b8ce2c4988525c94e19ddd39fad08a38284a197f1b70675acc"), "&bChannel", "", "&e> Click to decrease the Channel ID by 1"));
|
||||
menu.addMenuClickHandler(41, (p, slot, item, action) -> {
|
||||
int channel = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), FREQUENCY)) - 1;
|
||||
if (channel < 0) {
|
||||
if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) channel = 16;
|
||||
else channel = 15;
|
||||
}
|
||||
BlockStorage.addBlockInfo(b, FREQUENCY, String.valueOf(channel));
|
||||
updateBlockMenu(menu, b);
|
||||
return false;
|
||||
});
|
||||
|
||||
int channel = ((!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), FREQUENCY) == null) ? 0 : (Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), FREQUENCY))));
|
||||
|
||||
if (channel == 16) {
|
||||
menu.replaceExistingItem(42, new CustomItem(SlimefunUtils.getCustomHead("7a44ff3a5f49c69cab676bad8d98a063fa78cfa61916fdef3e267557fec18283"), "&bChannel ID: &3" + (channel + 1)));
|
||||
menu.addMenuClickHandler(42, ChestMenuUtils.getEmptyClickHandler());
|
||||
}
|
||||
else {
|
||||
menu.replaceExistingItem(42, new CustomItem(MaterialCollections.getAllWoolColors().get(channel), "&bChannel ID: &3" + (channel + 1)));
|
||||
menu.addMenuClickHandler(42, ChestMenuUtils.getEmptyClickHandler());
|
||||
}
|
||||
|
||||
menu.replaceExistingItem(43, new CustomItem(SlimefunUtils.getCustomHead("c2f910c47da042e4aa28af6cc81cf48ac6caf37dab35f88db993accb9dfe516"), "&bChannel", "", "&e> Click to increase the Channel ID by 1"));
|
||||
menu.addMenuClickHandler(43, (p, slot, item, action) -> {
|
||||
int channeln = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), FREQUENCY)) + 1;
|
||||
|
||||
if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) {
|
||||
if (channeln > 16) channeln = 0;
|
||||
}
|
||||
else {
|
||||
if (channeln > 15) channeln = 0;
|
||||
}
|
||||
|
||||
BlockStorage.addBlockInfo(b, FREQUENCY, String.valueOf(channeln));
|
||||
updateBlockMenu(menu, b);
|
||||
return false;
|
||||
});
|
||||
protected int[] getBorder() {
|
||||
return BORDER;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,114 +1,44 @@
|
||||
package io.github.thebusybiscuit.slimefun4.implementation.items.cargo;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
|
||||
import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.HeadTexture;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
||||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
|
||||
|
||||
public class CargoInputNode extends AbstractCargoNode {
|
||||
public class CargoInputNode extends AbstractFilterNode {
|
||||
|
||||
private static final int[] BORDER = { 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 17, 18, 22, 23, 26, 27, 31, 32, 33, 34, 35, 36, 40, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 };
|
||||
private static final int[] SLOTS = { 19, 20, 21, 28, 29, 30, 37, 38, 39 };
|
||||
|
||||
public CargoInputNode(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
|
||||
super(category, item, recipeType, recipe, recipeOutput);
|
||||
|
||||
addItemHandler(onPlace());
|
||||
registerBlockHandler(getID(), (p, b, stack, reason) -> {
|
||||
BlockMenu inv = BlockStorage.getInventory(b);
|
||||
|
||||
if (inv != null) {
|
||||
inv.dropItems(b.getLocation(), SLOTS);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
private BlockPlaceHandler onPlace() {
|
||||
return new BlockPlaceHandler(false) {
|
||||
|
||||
@Override
|
||||
public void onPlayerPlace(BlockPlaceEvent e) {
|
||||
Block b = e.getBlock();
|
||||
BlockStorage.addBlockInfo(b, "owner", e.getPlayer().getUniqueId().toString());
|
||||
BlockStorage.addBlockInfo(b, "index", "0");
|
||||
BlockStorage.addBlockInfo(b, FREQUENCY, "0");
|
||||
BlockStorage.addBlockInfo(b, "filter-type", "whitelist");
|
||||
BlockStorage.addBlockInfo(b, "filter-lore", String.valueOf(true));
|
||||
BlockStorage.addBlockInfo(b, "filter-durability", String.valueOf(false));
|
||||
BlockStorage.addBlockInfo(b, "round-robin", String.valueOf(false));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createBorder(BlockMenuPreset preset) {
|
||||
for (int i : BORDER) {
|
||||
preset.addItem(i, new CustomItem(Material.CYAN_STAINED_GLASS_PANE, " "), ChestMenuUtils.getEmptyClickHandler());
|
||||
}
|
||||
protected int[] getBorder() {
|
||||
return BORDER;
|
||||
}
|
||||
|
||||
preset.addItem(2, new CustomItem(Material.PAPER, "&3Items", "", "&bPut in all Items you want to", "&bblacklist/whitelist"), ChestMenuUtils.getEmptyClickHandler());
|
||||
@Override
|
||||
protected void onPlace(BlockPlaceEvent e) {
|
||||
super.onPlace(e);
|
||||
BlockStorage.addBlockInfo(e.getBlock(), "round-robin", String.valueOf(false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateBlockMenu(BlockMenu menu, Block b) {
|
||||
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-type") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-type").equals("whitelist")) {
|
||||
menu.replaceExistingItem(15, new CustomItem(Material.WHITE_WOOL, "&7Type: &rWhitelist", "", "&e> Click to change it to Blacklist"));
|
||||
menu.addMenuClickHandler(15, (p, slot, item, action) -> {
|
||||
BlockStorage.addBlockInfo(b, "filter-type", "blacklist");
|
||||
updateBlockMenu(menu, b);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
else {
|
||||
menu.replaceExistingItem(15, new CustomItem(Material.BLACK_WOOL, "&7Type: &8Blacklist", "", "&e> Click to change it to Whitelist"));
|
||||
menu.addMenuClickHandler(15, (p, slot, item, action) -> {
|
||||
BlockStorage.addBlockInfo(b, "filter-type", "whitelist");
|
||||
updateBlockMenu(menu, b);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
super.updateBlockMenu(menu, b);
|
||||
|
||||
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability").equals(String.valueOf(false))) {
|
||||
menu.replaceExistingItem(16, new CustomItem(Material.STONE_SWORD, "&7Include Sub-IDs/Durability: &4\u2718", "", "&e> Click to toggle whether the Durability has to match"));
|
||||
menu.addMenuClickHandler(16, (p, slot, item, action) -> {
|
||||
BlockStorage.addBlockInfo(b, "filter-durability", String.valueOf(true));
|
||||
updateBlockMenu(menu, b);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
else {
|
||||
ItemStack is = new ItemStack(Material.GOLDEN_SWORD);
|
||||
Damageable dmg = (Damageable) is.getItemMeta();
|
||||
dmg.setDamage(20);
|
||||
is.setItemMeta((ItemMeta) dmg);
|
||||
|
||||
menu.replaceExistingItem(16, new CustomItem(is, "&7Include Sub-IDs/Durability: &2\u2714", "", "&e> Click to toggle whether the Durability has to match"));
|
||||
menu.addMenuClickHandler(16, (p, slot, item, action) -> {
|
||||
BlockStorage.addBlockInfo(b, "filter-durability", String.valueOf(false));
|
||||
updateBlockMenu(menu, b);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "round-robin") == null || BlockStorage.getLocationInfo(b.getLocation(), "round-robin").equals(String.valueOf(false))) {
|
||||
menu.replaceExistingItem(24, new CustomItem(SlimefunUtils.getCustomHead("d78f2b7e5e75639ea7fb796c35d364c4df28b4243e66b76277aadcd6261337"), "&7Round-Robin Mode: &4\u2718", "", "&e> Click to enable Round Robin Mode", "&e(Items will be equally distributed on the Channel)"));
|
||||
String roundRobinMode = BlockStorage.getLocationInfo(b.getLocation(), "round-robin");
|
||||
if (!BlockStorage.hasBlockInfo(b) || roundRobinMode == null || roundRobinMode.equals(String.valueOf(false))) {
|
||||
menu.replaceExistingItem(24, new CustomItem(SlimefunUtils.getCustomHead(HeadTexture.ENERGY_REGULATOR.getTexture()), "&7Round-Robin Mode: &4\u2718", "", "&e> Click to enable Round Robin Mode", "&e(Items will be equally distributed on the Channel)"));
|
||||
menu.addMenuClickHandler(24, (p, slot, item, action) -> {
|
||||
BlockStorage.addBlockInfo(b, "round-robin", String.valueOf(true));
|
||||
updateBlockMenu(menu, b);
|
||||
@ -116,69 +46,13 @@ public class CargoInputNode extends AbstractCargoNode {
|
||||
});
|
||||
}
|
||||
else {
|
||||
menu.replaceExistingItem(24, new CustomItem(SlimefunUtils.getCustomHead("d78f2b7e5e75639ea7fb796c35d364c4df28b4243e66b76277aadcd6261337"), "&7Round-Robin Mode: &2\u2714", "", "&e> Click to disable Round Robin Mode", "&e(Items will be equally distributed on the Channel)"));
|
||||
menu.replaceExistingItem(24, new CustomItem(SlimefunUtils.getCustomHead(HeadTexture.ENERGY_REGULATOR.getTexture()), "&7Round-Robin Mode: &2\u2714", "", "&e> Click to disable Round Robin Mode", "&e(Items will be equally distributed on the Channel)"));
|
||||
menu.addMenuClickHandler(24, (p, slot, item, action) -> {
|
||||
BlockStorage.addBlockInfo(b, "round-robin", String.valueOf(false));
|
||||
updateBlockMenu(menu, b);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore").equals(String.valueOf(true))) {
|
||||
menu.replaceExistingItem(25, new CustomItem(Material.MAP, "&7Include Lore: &2\u2714", "", "&e> Click to toggle whether the Lore has to match"));
|
||||
menu.addMenuClickHandler(25, (p, slot, item, action) -> {
|
||||
BlockStorage.addBlockInfo(b, "filter-lore", String.valueOf(false));
|
||||
updateBlockMenu(menu, b);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
else {
|
||||
menu.replaceExistingItem(25, new CustomItem(Material.MAP, "&7Include Lore: &4\u2718", "", "&e> Click to toggle whether the Lore has to match"));
|
||||
menu.addMenuClickHandler(25, (p, slot, item, action) -> {
|
||||
BlockStorage.addBlockInfo(b, "filter-lore", String.valueOf(true));
|
||||
updateBlockMenu(menu, b);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
menu.replaceExistingItem(41, new CustomItem(SlimefunUtils.getCustomHead("f2599bd986659b8ce2c4988525c94e19ddd39fad08a38284a197f1b70675acc"), "&bChannel", "", "&e> Click to decrease the Channel ID by 1"));
|
||||
menu.addMenuClickHandler(41, (p, slot, item, action) -> {
|
||||
int channel = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), FREQUENCY)) - 1;
|
||||
if (channel < 0) {
|
||||
if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) channel = 16;
|
||||
else channel = 15;
|
||||
}
|
||||
BlockStorage.addBlockInfo(b, FREQUENCY, String.valueOf(channel));
|
||||
updateBlockMenu(menu, b);
|
||||
return false;
|
||||
});
|
||||
|
||||
int channel = ((!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), FREQUENCY) == null) ? 0 : (Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), FREQUENCY))));
|
||||
|
||||
if (channel == 16) {
|
||||
menu.replaceExistingItem(42, new CustomItem(SlimefunUtils.getCustomHead("7a44ff3a5f49c69cab676bad8d98a063fa78cfa61916fdef3e267557fec18283"), "&bChannel ID: &3" + (channel + 1)));
|
||||
menu.addMenuClickHandler(42, ChestMenuUtils.getEmptyClickHandler());
|
||||
}
|
||||
else {
|
||||
menu.replaceExistingItem(42, new CustomItem(new ItemStack(MaterialCollections.getAllWoolColors().get(channel)), "&bChannel ID: &3" + (channel + 1)));
|
||||
menu.addMenuClickHandler(42, ChestMenuUtils.getEmptyClickHandler());
|
||||
}
|
||||
|
||||
menu.replaceExistingItem(43, new CustomItem(SlimefunUtils.getCustomHead("c2f910c47da042e4aa28af6cc81cf48ac6caf37dab35f88db993accb9dfe516"), "&bChannel", "", "&e> Click to increase the Channel ID by 1"));
|
||||
menu.addMenuClickHandler(43, (p, slot, item, action) -> {
|
||||
int channeln = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), FREQUENCY)) + 1;
|
||||
|
||||
if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) {
|
||||
if (channeln > 16) channeln = 0;
|
||||
}
|
||||
else {
|
||||
if (channeln > 15) channeln = 0;
|
||||
}
|
||||
|
||||
BlockStorage.addBlockInfo(b, FREQUENCY, String.valueOf(channeln));
|
||||
updateBlockMenu(menu, b);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,14 +6,9 @@ import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
|
||||
import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
||||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
|
||||
@ -24,20 +19,11 @@ public class CargoOutputNode extends AbstractCargoNode {
|
||||
|
||||
public CargoOutputNode(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
|
||||
super(category, item, recipeType, recipe, recipeOutput);
|
||||
|
||||
addItemHandler(onPlace());
|
||||
}
|
||||
|
||||
private BlockPlaceHandler onPlace() {
|
||||
return new BlockPlaceHandler(false) {
|
||||
|
||||
@Override
|
||||
public void onPlayerPlace(BlockPlaceEvent e) {
|
||||
Block b = e.getBlock();
|
||||
BlockStorage.addBlockInfo(b, "owner", e.getPlayer().getUniqueId().toString());
|
||||
BlockStorage.addBlockInfo(b, FREQUENCY, "0");
|
||||
}
|
||||
};
|
||||
@Override
|
||||
protected void onPlace(BlockPlaceEvent e) {
|
||||
// We only require the default values
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -49,46 +35,7 @@ public class CargoOutputNode extends AbstractCargoNode {
|
||||
|
||||
@Override
|
||||
protected void updateBlockMenu(BlockMenu menu, Block b) {
|
||||
menu.replaceExistingItem(12, new CustomItem(SlimefunUtils.getCustomHead("f2599bd986659b8ce2c4988525c94e19ddd39fad08a38284a197f1b70675acc"), "&bChannel", "", "&e> Click to decrease the Channel ID by 1"));
|
||||
menu.addMenuClickHandler(12, (p, slot, item, action) -> {
|
||||
int channel = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), FREQUENCY)) - 1;
|
||||
|
||||
if (channel < 0) {
|
||||
if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) channel = 16;
|
||||
else channel = 15;
|
||||
}
|
||||
|
||||
BlockStorage.addBlockInfo(b, FREQUENCY, String.valueOf(channel));
|
||||
updateBlockMenu(menu, b);
|
||||
return false;
|
||||
});
|
||||
|
||||
int channel = ((!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), FREQUENCY) == null) ? 0 : (Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), FREQUENCY))));
|
||||
|
||||
if (channel == 16) {
|
||||
menu.replaceExistingItem(13, new CustomItem(SlimefunUtils.getCustomHead("7a44ff3a5f49c69cab676bad8d98a063fa78cfa61916fdef3e267557fec18283"), "&bChannel ID: &3" + (channel + 1)));
|
||||
menu.addMenuClickHandler(13, ChestMenuUtils.getEmptyClickHandler());
|
||||
}
|
||||
else {
|
||||
menu.replaceExistingItem(13, new CustomItem(MaterialCollections.getAllWoolColors().get(channel), "&bChannel ID: &3" + (channel + 1)));
|
||||
menu.addMenuClickHandler(13, ChestMenuUtils.getEmptyClickHandler());
|
||||
}
|
||||
|
||||
menu.replaceExistingItem(14, new CustomItem(SlimefunUtils.getCustomHead("c2f910c47da042e4aa28af6cc81cf48ac6caf37dab35f88db993accb9dfe516"), "&bChannel", "", "&e> Click to increase the Channel ID by 1"));
|
||||
menu.addMenuClickHandler(14, (p, slot, item, action) -> {
|
||||
int channeln = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), FREQUENCY)) + 1;
|
||||
|
||||
if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) {
|
||||
if (channeln > 16) channeln = 0;
|
||||
}
|
||||
else {
|
||||
if (channeln > 15) channeln = 0;
|
||||
}
|
||||
|
||||
BlockStorage.addBlockInfo(b, FREQUENCY, String.valueOf(channeln));
|
||||
updateBlockMenu(menu, b);
|
||||
return false;
|
||||
});
|
||||
addChannelSelector(b, menu, 12, 13, 14);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -96,7 +96,10 @@ public enum HeadTexture {
|
||||
NETHER_STAR_REACTOR("a11ed1d1b25b624665ecdddc3d3a5dff0b9f35e3de77a12f516e60fe8501cc8d"),
|
||||
UNKNOWN("46ba63344f49dd1c4f5488e926bf3d9e2b29916a6c50d610bb40a5273dc8c82"),
|
||||
MISSING_TEXTURE("e9eb9da26cf2d3341397a7f4913ba3d37d1ad10eae30ab25fa39ceb84bc"),
|
||||
MINECRAFT_CHUNK("8449b9318e33158e64a46ab0de121c3d40000e3332c1574932b3c849d8fa0dc2");
|
||||
MINECRAFT_CHUNK("8449b9318e33158e64a46ab0de121c3d40000e3332c1574932b3c849d8fa0dc2"),
|
||||
CHEST_TERMINAL("7a44ff3a5f49c69cab676bad8d98a063fa78cfa61916fdef3e267557fec18283"),
|
||||
CARGO_ARROW_LEFT("f2599bd986659b8ce2c4988525c94e19ddd39fad08a38284a197f1b70675acc"),
|
||||
CARGO_ARROW_RIGHT("c2f910c47da042e4aa28af6cc81cf48ac6caf37dab35f88db993accb9dfe516");
|
||||
|
||||
private final String texture;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user