1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

[CI skip] Introduced proper Maven structure

This commit is contained in:
TheBusyBiscuit 2019-10-17 00:37:46 +02:00
parent 20e3f2b9ce
commit 18b5bda4a8
296 changed files with 5551 additions and 5552 deletions

View File

@ -43,7 +43,7 @@
</repositories>
<build>
<sourceDirectory>${project.basedir}/src</sourceDirectory>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<finalName>${project.name} v${project.version}</finalName>
<plugins>
<plugin>
@ -90,11 +90,10 @@
<resources>
<resource>
<directory>${basedir}/src</directory>
<directory>${basedir}/src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>plugin.yml</include>
<include>config.yml</include>
<include>*</include>
</includes>
</resource>
</resources>

View File

@ -1,443 +1,443 @@
package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import io.github.thebusybiscuit.cscorelib2.math.DoubleHandler;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.InvUtils;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem;
import me.mrCookieSlime.CSCoreLibPlugin.general.World.CustomSkull;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.RecipeDisplayItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.machines.ReactorAccessPort;
import me.mrCookieSlime.Slimefun.Setup.SlimefunManager;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
import me.mrCookieSlime.Slimefun.api.energy.EnergyTicker;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
import me.mrCookieSlime.Slimefun.holograms.ReactorHologram;
import me.mrCookieSlime.Slimefun.utils.MachineHelper;
public abstract class AReactor extends SlimefunItem implements RecipeDisplayItem {
public static Map<Location, MachineFuel> processing = new HashMap<>();
public static Map<Location, Integer> progress = new HashMap<>();
private static final BlockFace[] cooling =
{
BlockFace.NORTH,
BlockFace.NORTH_EAST,
BlockFace.EAST,
BlockFace.SOUTH_EAST,
BlockFace.SOUTH,
BlockFace.SOUTH_WEST,
BlockFace.WEST,
BlockFace.NORTH_WEST
};
private final Set<MachineFuel> recipes = new HashSet<>();
private static final int[] border = {0, 1, 2, 3, 5, 6, 7, 8, 12, 13, 14, 21, 23};
private static final int[] border_1 = {9, 10, 11, 18, 20, 27, 29, 36, 38, 45, 46, 47};
private static final int[] border_2 = {15, 16, 17, 24, 26, 33, 35, 42, 44, 51, 52, 53};
private static final int[] border_3 = {30, 31, 32, 39, 41, 48, 50};
// No coolant border
private static final int[] border_4 = {25, 34, 43};
private static final int INFO_SLOT = 49;
public AReactor(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, id, recipeType, recipe);
new BlockMenuPreset(id, getInventoryTitle()) {
@Override
public void init() {
constructMenu(this);
}
@Override
public void newInstance(final BlockMenu menu, final Block b) {
try {
if (BlockStorage.getLocationInfo(b.getLocation(), "reactor-mode") == null){
BlockStorage.addBlockInfo(b, "reactor-mode", "generator");
}
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "reactor-mode").equals("generator")) {
menu.replaceExistingItem(4, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOTM0M2NlNThkYTU0Yzc5OTI0YTJjOTMzMWNmYzQxN2ZlOGNjYmJlYTliZTQ1YTdhYzg1ODYwYTZjNzMwIn19fQ=="), "&7Focus: &eElectricity", "", "&6Your Reactor will focus on Power Generation", "&6If your Energy Network doesn't need Power", "&6it will not produce any either", "", "&7> Click to change the Focus to &eProduction"));
menu.addMenuClickHandler(4, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "reactor-mode", "production");
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(4, new CustomItem(SlimefunItems.PLUTONIUM, "&7Focus: &eProduction", "", "&6Your Reactor will focus on producing goods", "&6If your Energy Network doesn't need Power", "&6it will continue to run and simply will", "&6not generate any Power in the mean time", "", "&7> Click to change the Focus to &ePower Generation"));
menu.addMenuClickHandler(4, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "reactor-mode", "generator");
newInstance(menu, b);
return false;
});
}
BlockMenu port = getAccessPort(b.getLocation());
if (port != null) {
menu.replaceExistingItem(INFO_SLOT, new CustomItem(new ItemStack(Material.GREEN_WOOL), "&7Access Port", "", "&6Detected", "", "&7> Click to view Access Port"));
menu.addMenuClickHandler(INFO_SLOT, (p, slot, item, action) -> {
port.open(p);
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(INFO_SLOT, new CustomItem(new ItemStack(Material.RED_WOOL), "&7Access Port", "", "&cNot detected", "", "&7Access Port must be", "&7placed 3 blocks above", "&7a reactor!"));
menu.addMenuClickHandler(INFO_SLOT, (p, slot, item, action) -> {
newInstance(menu, b);
menu.open(p);
return false;
});
}
} catch(Exception x) {
Slimefun.getLogger().log(Level.SEVERE, "An Error occured when creating a Reactor Menu for Slimefun " + Slimefun.getVersion(), x);
}
}
@Override
public boolean canOpen(Block b, Player p) {
return p.hasPermission("slimefun.inventory.bypass") || SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.ACCESS_INVENTORIES);
}
@Override
public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) {
return new int[0];
}
};
registerBlockHandler(id, (p, b, tool, reason) -> {
BlockMenu inv = BlockStorage.getInventory(b);
if (inv != null) {
for (int slot : getFuelSlots()) {
if (inv.getItemInSlot(slot) != null) {
b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot));
inv.replaceExistingItem(slot, null);
}
}
for (int slot : getCoolantSlots()) {
if (inv.getItemInSlot(slot) != null) {
b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot));
inv.replaceExistingItem(slot, null);
}
}
for (int slot : getOutputSlots()) {
if (inv.getItemInSlot(slot) != null) {
b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot));
inv.replaceExistingItem(slot, null);
}
}
}
progress.remove(b.getLocation());
processing.remove(b.getLocation());
ReactorHologram.remove(b.getLocation());
return true;
});
this.registerDefaultRecipes();
}
private void constructMenu(BlockMenuPreset preset) {
for (int i : border) {
preset.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
}
for (int i : border_1) {
preset.addItem(i, new CustomItem(new ItemStack(Material.LIME_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
}
for (int i : border_3) {
preset.addItem(i, new CustomItem(new ItemStack(Material.GREEN_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
}
preset.addItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
preset.addItem(1, new CustomItem(SlimefunItems.URANIUM, "&7Fuel Slot", "", "&rThis Slot accepts radioactive Fuel such as:", "&2Uranium &ror &aNeptunium"), (p, slot, item, action) -> false);
for (int i : border_2) {
preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
}
if (needsCooling()) {
preset.addItem(7, new CustomItem(this.getCoolant(), "&bCoolant Slot", "", "&rThis Slot accepts Coolant Cells", "&4Without any Coolant Cells, your Reactor", "&4will explode"));
}
else {
preset.addItem(7, new CustomItem(new ItemStack(Material.BARRIER), "&bCoolant Slot", "", "&rThis Slot accepts Coolant Cells"));
for (int i : border_4) {
preset.addItem(i, new CustomItem(new ItemStack(Material.BARRIER), "&cNo Coolant Required"), (p, slot, item, action) -> false);
}
}
}
public abstract String getInventoryTitle();
public abstract void registerDefaultRecipes();
public abstract int getEnergyProduction();
public abstract void extraTick(Location l);
public abstract ItemStack getCoolant();
public boolean needsCooling() {
return getCoolant() != null;
}
public int[] getInputSlots() {
return new int[] {19, 28, 37, 25, 34, 43};
}
public int[] getFuelSlots() {
return new int[] {19, 28, 37};
}
public int[] getCoolantSlots() {
return needsCooling() ? new int[] {25, 34, 43} : new int[]{};
}
public int[] getOutputSlots() {
return new int[] {40};
}
public MachineFuel getProcessing(Location l) {
return processing.get(l);
}
public boolean isProcessing(Location l) {
return progress.containsKey(l);
}
public void registerFuel(MachineFuel fuel) {
this.recipes.add(fuel);
}
@Override
public void preRegister() {
addItemHandler(new EnergyTicker() {
private Set<Location> explode = new HashSet<>();
@Override
public double generateEnergy(final Location l, SlimefunItem sf, Config data) {
BlockMenu menu = BlockStorage.getInventory(l);
BlockMenu port = getAccessPort(l);
if (isProcessing(l)) {
extraTick(l);
int timeleft = progress.get(l);
if (timeleft > 0) {
int produced = getEnergyProduction();
int space = ChargableBlock.getMaxCharge(l) - ChargableBlock.getCharge(l);
if (space >= produced) {
ChargableBlock.addCharge(l, getEnergyProduction());
space -= produced;
}
if (space >= produced || !"generator".equals(BlockStorage.getLocationInfo(l, "reactor-mode"))) {
progress.put(l, timeleft - 1);
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, () -> {
if (!l.getBlock().getRelative(cooling[new Random().nextInt(cooling.length)]).isLiquid()) explode.add(l);
});
MachineHelper.updateProgressbar(menu, 22, timeleft, processing.get(l).getTicks(), getProgressBar());
if (needsCooling()) {
boolean coolant = (processing.get(l).getTicks() - timeleft) % 25 == 0;
if (coolant) {
if (port != null) {
for (int slot: getCoolantSlots()) {
if (SlimefunManager.isItemSimiliar(port.getItemInSlot(slot), getCoolant(), true)) {
port.replaceExistingItem(slot, menu.pushItem(port.getItemInSlot(slot), getCoolantSlots()));
}
}
}
boolean explosion = true;
for (int slot: getCoolantSlots()) {
if (SlimefunManager.isItemSimiliar(menu.getItemInSlot(slot), getCoolant(), true)) {
menu.replaceExistingItem(slot, InvUtils.decreaseItem(menu.getItemInSlot(slot), 1));
ReactorHologram.update(l, "&b\u2744 &7100%");
explosion = false;
break;
}
}
if (explosion) {
explode.add(l);
return 0;
}
}
else {
ReactorHologram.update(l, "&b\u2744 &7" + MachineHelper.getPercentage(timeleft, processing.get(l).getTicks()) + "%");
}
}
return ChargableBlock.getCharge(l);
}
return 0;
}
else {
menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "));
if (processing.get(l).getOutput() != null) {
menu.pushItem(processing.get(l).getOutput(), getOutputSlots());
}
if (port != null) {
for (int slot: getOutputSlots()) {
if (menu.getItemInSlot(slot) != null) {
menu.replaceExistingItem(slot, port.pushItem(menu.getItemInSlot(slot), ReactorAccessPort.getOutputSlots()));
}
}
}
progress.remove(l);
processing.remove(l);
return 0;
}
}
else {
Map<Integer, Integer> found = new HashMap<>();
MachineFuel fuel = findRecipe(menu, found);
if (port != null) {
restockCoolant(menu, port);
}
if (fuel != null) {
for (Map.Entry<Integer, Integer> entry: found.entrySet()) {
menu.replaceExistingItem(entry.getKey(), InvUtils.decreaseItem(menu.getItemInSlot(entry.getKey()), entry.getValue()));
}
processing.put(l, fuel);
progress.put(l, fuel.getTicks());
}
return 0;
}
}
@Override
public boolean explode(final Location l) {
final boolean explosion = explode.contains(l);
if (explosion) {
BlockStorage.getInventory(l).close();
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, () -> ReactorHologram.remove(l), 0);
explode.remove(l);
processing.remove(l);
progress.remove(l);
}
return explosion;
}
});
}
private void restockCoolant(BlockMenu menu, BlockMenu port) {
for (int slot: getFuelSlots()) {
for (MachineFuel recipe: recipes) {
if (SlimefunManager.isItemSimiliar(port.getItemInSlot(slot), recipe.getInput(), true) && menu.fits(new CustomItem(port.getItemInSlot(slot), 1), getFuelSlots())) {
port.replaceExistingItem(slot, InvUtils.decreaseItem(port.getItemInSlot(slot), 1));
return;
}
}
}
}
private MachineFuel findRecipe(BlockMenu menu, Map<Integer, Integer> found) {
for (MachineFuel recipe: recipes) {
for (int slot: getInputSlots()) {
if (SlimefunManager.isItemSimiliar(menu.getItemInSlot(slot), recipe.getInput(), true)) {
found.put(slot, recipe.getInput().getAmount());
return recipe;
}
}
}
return null;
}
public abstract ItemStack getProgressBar();
public Set<MachineFuel> getFuelTypes() {
return this.recipes;
}
public BlockMenu getAccessPort(Location l) {
Location portL = new Location(l.getWorld(), l.getX(), l.getY() + 3, l.getZ());
if (BlockStorage.check(portL, "REACTOR_ACCESS_PORT")) return BlockStorage.getInventory(portL);
return null;
}
@Override
public String getRecipeSectionLabel() {
return "&7\u21E9 Available Types of Fuel \u21E9";
}
@Override
public List<ItemStack> getDisplayRecipes() {
List<ItemStack> list = new ArrayList<>();
for (MachineFuel fuel: recipes) {
ItemStack item = fuel.getInput().clone();
ItemMeta im = item.getItemMeta();
List<String> lore = new ArrayList<>();
lore.add(ChatColor.translateAlternateColorCodes('&', "&8\u21E8 &7Lasts " + getTimeLeft(fuel.getTicks() / 2)));
lore.add(ChatColor.translateAlternateColorCodes('&', "&8\u21E8 &e\u26A1 &7" + getEnergyProduction() * 2) + " J/s");
lore.add(ChatColor.translateAlternateColorCodes('&', "&8\u21E8 &e\u26A1 &7" + DoubleHandler.getFancyDouble((double) fuel.getTicks() * getEnergyProduction()) + " J in total"));
im.setLore(lore);
item.setItemMeta(im);
list.add(item);
}
if (list.size() % 2 != 0) list.add(null);
return list;
}
private static String getTimeLeft(int seconds) {
String timeleft = "";
final int minutes = (int) (seconds / 60L);
if (minutes > 0) {
timeleft += minutes + "m ";
}
seconds -= minutes * 60;
return "&7" + timeleft + seconds + "s";
}
}
package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import io.github.thebusybiscuit.cscorelib2.math.DoubleHandler;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.InvUtils;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem;
import me.mrCookieSlime.CSCoreLibPlugin.general.World.CustomSkull;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.RecipeDisplayItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.machines.ReactorAccessPort;
import me.mrCookieSlime.Slimefun.Setup.SlimefunManager;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
import me.mrCookieSlime.Slimefun.api.energy.EnergyTicker;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
import me.mrCookieSlime.Slimefun.holograms.ReactorHologram;
import me.mrCookieSlime.Slimefun.utils.MachineHelper;
public abstract class AReactor extends SlimefunItem implements RecipeDisplayItem {
public static Map<Location, MachineFuel> processing = new HashMap<>();
public static Map<Location, Integer> progress = new HashMap<>();
private static final BlockFace[] cooling =
{
BlockFace.NORTH,
BlockFace.NORTH_EAST,
BlockFace.EAST,
BlockFace.SOUTH_EAST,
BlockFace.SOUTH,
BlockFace.SOUTH_WEST,
BlockFace.WEST,
BlockFace.NORTH_WEST
};
private final Set<MachineFuel> recipes = new HashSet<>();
private static final int[] border = {0, 1, 2, 3, 5, 6, 7, 8, 12, 13, 14, 21, 23};
private static final int[] border_1 = {9, 10, 11, 18, 20, 27, 29, 36, 38, 45, 46, 47};
private static final int[] border_2 = {15, 16, 17, 24, 26, 33, 35, 42, 44, 51, 52, 53};
private static final int[] border_3 = {30, 31, 32, 39, 41, 48, 50};
// No coolant border
private static final int[] border_4 = {25, 34, 43};
private static final int INFO_SLOT = 49;
public AReactor(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, id, recipeType, recipe);
new BlockMenuPreset(id, getInventoryTitle()) {
@Override
public void init() {
constructMenu(this);
}
@Override
public void newInstance(final BlockMenu menu, final Block b) {
try {
if (BlockStorage.getLocationInfo(b.getLocation(), "reactor-mode") == null){
BlockStorage.addBlockInfo(b, "reactor-mode", "generator");
}
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "reactor-mode").equals("generator")) {
menu.replaceExistingItem(4, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOTM0M2NlNThkYTU0Yzc5OTI0YTJjOTMzMWNmYzQxN2ZlOGNjYmJlYTliZTQ1YTdhYzg1ODYwYTZjNzMwIn19fQ=="), "&7Focus: &eElectricity", "", "&6Your Reactor will focus on Power Generation", "&6If your Energy Network doesn't need Power", "&6it will not produce any either", "", "&7> Click to change the Focus to &eProduction"));
menu.addMenuClickHandler(4, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "reactor-mode", "production");
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(4, new CustomItem(SlimefunItems.PLUTONIUM, "&7Focus: &eProduction", "", "&6Your Reactor will focus on producing goods", "&6If your Energy Network doesn't need Power", "&6it will continue to run and simply will", "&6not generate any Power in the mean time", "", "&7> Click to change the Focus to &ePower Generation"));
menu.addMenuClickHandler(4, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "reactor-mode", "generator");
newInstance(menu, b);
return false;
});
}
BlockMenu port = getAccessPort(b.getLocation());
if (port != null) {
menu.replaceExistingItem(INFO_SLOT, new CustomItem(new ItemStack(Material.GREEN_WOOL), "&7Access Port", "", "&6Detected", "", "&7> Click to view Access Port"));
menu.addMenuClickHandler(INFO_SLOT, (p, slot, item, action) -> {
port.open(p);
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(INFO_SLOT, new CustomItem(new ItemStack(Material.RED_WOOL), "&7Access Port", "", "&cNot detected", "", "&7Access Port must be", "&7placed 3 blocks above", "&7a reactor!"));
menu.addMenuClickHandler(INFO_SLOT, (p, slot, item, action) -> {
newInstance(menu, b);
menu.open(p);
return false;
});
}
} catch(Exception x) {
Slimefun.getLogger().log(Level.SEVERE, "An Error occured when creating a Reactor Menu for Slimefun " + Slimefun.getVersion(), x);
}
}
@Override
public boolean canOpen(Block b, Player p) {
return p.hasPermission("slimefun.inventory.bypass") || SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.ACCESS_INVENTORIES);
}
@Override
public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) {
return new int[0];
}
};
registerBlockHandler(id, (p, b, tool, reason) -> {
BlockMenu inv = BlockStorage.getInventory(b);
if (inv != null) {
for (int slot : getFuelSlots()) {
if (inv.getItemInSlot(slot) != null) {
b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot));
inv.replaceExistingItem(slot, null);
}
}
for (int slot : getCoolantSlots()) {
if (inv.getItemInSlot(slot) != null) {
b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot));
inv.replaceExistingItem(slot, null);
}
}
for (int slot : getOutputSlots()) {
if (inv.getItemInSlot(slot) != null) {
b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot));
inv.replaceExistingItem(slot, null);
}
}
}
progress.remove(b.getLocation());
processing.remove(b.getLocation());
ReactorHologram.remove(b.getLocation());
return true;
});
this.registerDefaultRecipes();
}
private void constructMenu(BlockMenuPreset preset) {
for (int i : border) {
preset.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
}
for (int i : border_1) {
preset.addItem(i, new CustomItem(new ItemStack(Material.LIME_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
}
for (int i : border_3) {
preset.addItem(i, new CustomItem(new ItemStack(Material.GREEN_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
}
preset.addItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
preset.addItem(1, new CustomItem(SlimefunItems.URANIUM, "&7Fuel Slot", "", "&rThis Slot accepts radioactive Fuel such as:", "&2Uranium &ror &aNeptunium"), (p, slot, item, action) -> false);
for (int i : border_2) {
preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
}
if (needsCooling()) {
preset.addItem(7, new CustomItem(this.getCoolant(), "&bCoolant Slot", "", "&rThis Slot accepts Coolant Cells", "&4Without any Coolant Cells, your Reactor", "&4will explode"));
}
else {
preset.addItem(7, new CustomItem(new ItemStack(Material.BARRIER), "&bCoolant Slot", "", "&rThis Slot accepts Coolant Cells"));
for (int i : border_4) {
preset.addItem(i, new CustomItem(new ItemStack(Material.BARRIER), "&cNo Coolant Required"), (p, slot, item, action) -> false);
}
}
}
public abstract String getInventoryTitle();
public abstract void registerDefaultRecipes();
public abstract int getEnergyProduction();
public abstract void extraTick(Location l);
public abstract ItemStack getCoolant();
public boolean needsCooling() {
return getCoolant() != null;
}
public int[] getInputSlots() {
return new int[] {19, 28, 37, 25, 34, 43};
}
public int[] getFuelSlots() {
return new int[] {19, 28, 37};
}
public int[] getCoolantSlots() {
return needsCooling() ? new int[] {25, 34, 43} : new int[]{};
}
public int[] getOutputSlots() {
return new int[] {40};
}
public MachineFuel getProcessing(Location l) {
return processing.get(l);
}
public boolean isProcessing(Location l) {
return progress.containsKey(l);
}
public void registerFuel(MachineFuel fuel) {
this.recipes.add(fuel);
}
@Override
public void preRegister() {
addItemHandler(new EnergyTicker() {
private Set<Location> explode = new HashSet<>();
@Override
public double generateEnergy(final Location l, SlimefunItem sf, Config data) {
BlockMenu menu = BlockStorage.getInventory(l);
BlockMenu port = getAccessPort(l);
if (isProcessing(l)) {
extraTick(l);
int timeleft = progress.get(l);
if (timeleft > 0) {
int produced = getEnergyProduction();
int space = ChargableBlock.getMaxCharge(l) - ChargableBlock.getCharge(l);
if (space >= produced) {
ChargableBlock.addCharge(l, getEnergyProduction());
space -= produced;
}
if (space >= produced || !"generator".equals(BlockStorage.getLocationInfo(l, "reactor-mode"))) {
progress.put(l, timeleft - 1);
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, () -> {
if (!l.getBlock().getRelative(cooling[new Random().nextInt(cooling.length)]).isLiquid()) explode.add(l);
});
MachineHelper.updateProgressbar(menu, 22, timeleft, processing.get(l).getTicks(), getProgressBar());
if (needsCooling()) {
boolean coolant = (processing.get(l).getTicks() - timeleft) % 25 == 0;
if (coolant) {
if (port != null) {
for (int slot: getCoolantSlots()) {
if (SlimefunManager.isItemSimiliar(port.getItemInSlot(slot), getCoolant(), true)) {
port.replaceExistingItem(slot, menu.pushItem(port.getItemInSlot(slot), getCoolantSlots()));
}
}
}
boolean explosion = true;
for (int slot: getCoolantSlots()) {
if (SlimefunManager.isItemSimiliar(menu.getItemInSlot(slot), getCoolant(), true)) {
menu.replaceExistingItem(slot, InvUtils.decreaseItem(menu.getItemInSlot(slot), 1));
ReactorHologram.update(l, "&b\u2744 &7100%");
explosion = false;
break;
}
}
if (explosion) {
explode.add(l);
return 0;
}
}
else {
ReactorHologram.update(l, "&b\u2744 &7" + MachineHelper.getPercentage(timeleft, processing.get(l).getTicks()) + "%");
}
}
return ChargableBlock.getCharge(l);
}
return 0;
}
else {
menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "));
if (processing.get(l).getOutput() != null) {
menu.pushItem(processing.get(l).getOutput(), getOutputSlots());
}
if (port != null) {
for (int slot: getOutputSlots()) {
if (menu.getItemInSlot(slot) != null) {
menu.replaceExistingItem(slot, port.pushItem(menu.getItemInSlot(slot), ReactorAccessPort.getOutputSlots()));
}
}
}
progress.remove(l);
processing.remove(l);
return 0;
}
}
else {
Map<Integer, Integer> found = new HashMap<>();
MachineFuel fuel = findRecipe(menu, found);
if (port != null) {
restockCoolant(menu, port);
}
if (fuel != null) {
for (Map.Entry<Integer, Integer> entry: found.entrySet()) {
menu.replaceExistingItem(entry.getKey(), InvUtils.decreaseItem(menu.getItemInSlot(entry.getKey()), entry.getValue()));
}
processing.put(l, fuel);
progress.put(l, fuel.getTicks());
}
return 0;
}
}
@Override
public boolean explode(final Location l) {
final boolean explosion = explode.contains(l);
if (explosion) {
BlockStorage.getInventory(l).close();
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, () -> ReactorHologram.remove(l), 0);
explode.remove(l);
processing.remove(l);
progress.remove(l);
}
return explosion;
}
});
}
private void restockCoolant(BlockMenu menu, BlockMenu port) {
for (int slot: getFuelSlots()) {
for (MachineFuel recipe: recipes) {
if (SlimefunManager.isItemSimiliar(port.getItemInSlot(slot), recipe.getInput(), true) && menu.fits(new CustomItem(port.getItemInSlot(slot), 1), getFuelSlots())) {
port.replaceExistingItem(slot, InvUtils.decreaseItem(port.getItemInSlot(slot), 1));
return;
}
}
}
}
private MachineFuel findRecipe(BlockMenu menu, Map<Integer, Integer> found) {
for (MachineFuel recipe: recipes) {
for (int slot: getInputSlots()) {
if (SlimefunManager.isItemSimiliar(menu.getItemInSlot(slot), recipe.getInput(), true)) {
found.put(slot, recipe.getInput().getAmount());
return recipe;
}
}
}
return null;
}
public abstract ItemStack getProgressBar();
public Set<MachineFuel> getFuelTypes() {
return this.recipes;
}
public BlockMenu getAccessPort(Location l) {
Location portL = new Location(l.getWorld(), l.getX(), l.getY() + 3, l.getZ());
if (BlockStorage.check(portL, "REACTOR_ACCESS_PORT")) return BlockStorage.getInventory(portL);
return null;
}
@Override
public String getRecipeSectionLabel() {
return "&7\u21E9 Available Types of Fuel \u21E9";
}
@Override
public List<ItemStack> getDisplayRecipes() {
List<ItemStack> list = new ArrayList<>();
for (MachineFuel fuel: recipes) {
ItemStack item = fuel.getInput().clone();
ItemMeta im = item.getItemMeta();
List<String> lore = new ArrayList<>();
lore.add(ChatColor.translateAlternateColorCodes('&', "&8\u21E8 &7Lasts " + getTimeLeft(fuel.getTicks() / 2)));
lore.add(ChatColor.translateAlternateColorCodes('&', "&8\u21E8 &e\u26A1 &7" + getEnergyProduction() * 2) + " J/s");
lore.add(ChatColor.translateAlternateColorCodes('&', "&8\u21E8 &e\u26A1 &7" + DoubleHandler.getFancyDouble((double) fuel.getTicks() * getEnergyProduction()) + " J in total"));
im.setLore(lore);
item.setItemMeta(im);
list.add(item);
}
if (list.size() % 2 != 0) list.add(null);
return list;
}
private static String getTimeLeft(int seconds) {
String timeleft = "";
final int minutes = (int) (seconds / 60L);
if (minutes > 0) {
timeleft += minutes + "m ";
}
seconds -= minutes * 60;
return "&7" + timeleft + seconds + "s";
}
}

View File

@ -1,210 +1,210 @@
package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.cargo;
import java.util.logging.Level;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem;
import me.mrCookieSlime.CSCoreLibPlugin.general.World.CustomSkull;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.item_transport.CargoNet;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
public class AdvancedCargoOutputNode extends SlimefunItem {
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};
public AdvancedCargoOutputNode(Category category, ItemStack item, String name, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
super(category, item, name, recipeType, recipe, recipeOutput);
new BlockMenuPreset(name, "&cOutput Node") {
@Override
public void init() {
constructMenu(this);
}
@Override
public void newInstance(final BlockMenu menu, final Block b) {
try {
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-type") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-type").equals("whitelist")) {
menu.replaceExistingItem(15, new CustomItem(new ItemStack(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");
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(15, new CustomItem(new ItemStack(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");
newInstance(menu, b);
return false;
});
}
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability").equals("false")) {
ItemStack is = new ItemStack(Material.STONE_SWORD);
Damageable dmg = (Damageable) is.getItemMeta();
dmg.setDamage(20);
is.setItemMeta((ItemMeta) dmg);
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", "true");
newInstance(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", "false");
newInstance(menu, b);
return false;
});
}
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore").equals("true")) {
menu.replaceExistingItem(25, new CustomItem(new ItemStack(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", "false");
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(25, new CustomItem(new ItemStack(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", "true");
newInstance(menu, b);
return false;
});
}
menu.replaceExistingItem(41, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjI1OTliZDk4NjY1OWI4Y2UyYzQ5ODg1MjVjOTRlMTlkZGQzOWZhZDA4YTM4Mjg0YTE5N2YxYjcwNjc1YWNjIn19fQ=="), "&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 (CargoNet.extraChannels) channel = 16;
else channel = 15;
}
BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channel));
newInstance(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(SlimefunItems.CHEST_TERMINAL, "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(42,
(p, slot, item, action) -> false
);
}
else {
menu.replaceExistingItem(42, new CustomItem(new ItemStack(MaterialCollections.getAllWoolColors().get(channel)), "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(42,
(p, slot, item, action) -> false
);
}
menu.replaceExistingItem(43, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzJmOTEwYzQ3ZGEwNDJlNGFhMjhhZjZjYzgxY2Y0OGFjNmNhZjM3ZGFiMzVmODhkYjk5M2FjY2I5ZGZlNTE2In19fQ=="), "&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 (CargoNet.extraChannels) {
if (channeln > 16) channeln = 0;
}
else {
if (channeln > 15) channeln = 0;
}
BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channeln));
newInstance(menu, b);
return false;
});
} catch (Exception x) {
Slimefun.getLogger().log(Level.SEVERE, "An Error occured while creating the Inventory of an Advanced Cargo Output Node for Slimefun " + Slimefun.getVersion(), x);
}
}
@Override
public boolean canOpen(Block b, Player p) {
return p.hasPermission("slimefun.cargo.bypass") || SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.ACCESS_INVENTORIES);
}
@Override
public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) {
return new int[0];
}
};
registerBlockHandler(name, new SlimefunBlockHandler() {
@Override
public void onPlace(Player p, Block b, SlimefunItem item) {
BlockStorage.addBlockInfo(b, "owner", p.getUniqueId().toString());
BlockStorage.addBlockInfo(b, "index", "0");
BlockStorage.addBlockInfo(b, "frequency", "0");
BlockStorage.addBlockInfo(b, "filter-type", "whitelist");
BlockStorage.addBlockInfo(b, "filter-lore", "true");
BlockStorage.addBlockInfo(b, "filter-durability", "false");
}
@Override
public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) {
BlockMenu inv = BlockStorage.getInventory(b);
if (inv != null) {
for (int slot: getInputSlots()) {
if (inv.getItemInSlot(slot) != null) {
b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot));
inv.replaceExistingItem(slot, null);
}
}
}
return true;
}
});
}
protected void constructMenu(BlockMenuPreset preset) {
for (int i : border) {
preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "),
(p, slot, item, action) -> false
);
}
preset.addItem(2, new CustomItem(new ItemStack(Material.PAPER), "&3Items", "", "&bPut in all Items you want to", "&bblacklist/whitelist"),
(p, slot, item, action) -> false
);
}
public int[] getInputSlots() {
return new int[] {19, 20, 21, 28, 29, 30, 37, 38, 39};
}
}
package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.cargo;
import java.util.logging.Level;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem;
import me.mrCookieSlime.CSCoreLibPlugin.general.World.CustomSkull;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.item_transport.CargoNet;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
public class AdvancedCargoOutputNode extends SlimefunItem {
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};
public AdvancedCargoOutputNode(Category category, ItemStack item, String name, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
super(category, item, name, recipeType, recipe, recipeOutput);
new BlockMenuPreset(name, "&cOutput Node") {
@Override
public void init() {
constructMenu(this);
}
@Override
public void newInstance(final BlockMenu menu, final Block b) {
try {
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-type") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-type").equals("whitelist")) {
menu.replaceExistingItem(15, new CustomItem(new ItemStack(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");
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(15, new CustomItem(new ItemStack(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");
newInstance(menu, b);
return false;
});
}
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability").equals("false")) {
ItemStack is = new ItemStack(Material.STONE_SWORD);
Damageable dmg = (Damageable) is.getItemMeta();
dmg.setDamage(20);
is.setItemMeta((ItemMeta) dmg);
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", "true");
newInstance(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", "false");
newInstance(menu, b);
return false;
});
}
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore").equals("true")) {
menu.replaceExistingItem(25, new CustomItem(new ItemStack(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", "false");
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(25, new CustomItem(new ItemStack(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", "true");
newInstance(menu, b);
return false;
});
}
menu.replaceExistingItem(41, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjI1OTliZDk4NjY1OWI4Y2UyYzQ5ODg1MjVjOTRlMTlkZGQzOWZhZDA4YTM4Mjg0YTE5N2YxYjcwNjc1YWNjIn19fQ=="), "&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 (CargoNet.extraChannels) channel = 16;
else channel = 15;
}
BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channel));
newInstance(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(SlimefunItems.CHEST_TERMINAL, "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(42,
(p, slot, item, action) -> false
);
}
else {
menu.replaceExistingItem(42, new CustomItem(new ItemStack(MaterialCollections.getAllWoolColors().get(channel)), "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(42,
(p, slot, item, action) -> false
);
}
menu.replaceExistingItem(43, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzJmOTEwYzQ3ZGEwNDJlNGFhMjhhZjZjYzgxY2Y0OGFjNmNhZjM3ZGFiMzVmODhkYjk5M2FjY2I5ZGZlNTE2In19fQ=="), "&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 (CargoNet.extraChannels) {
if (channeln > 16) channeln = 0;
}
else {
if (channeln > 15) channeln = 0;
}
BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channeln));
newInstance(menu, b);
return false;
});
} catch (Exception x) {
Slimefun.getLogger().log(Level.SEVERE, "An Error occured while creating the Inventory of an Advanced Cargo Output Node for Slimefun " + Slimefun.getVersion(), x);
}
}
@Override
public boolean canOpen(Block b, Player p) {
return p.hasPermission("slimefun.cargo.bypass") || SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.ACCESS_INVENTORIES);
}
@Override
public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) {
return new int[0];
}
};
registerBlockHandler(name, new SlimefunBlockHandler() {
@Override
public void onPlace(Player p, Block b, SlimefunItem item) {
BlockStorage.addBlockInfo(b, "owner", p.getUniqueId().toString());
BlockStorage.addBlockInfo(b, "index", "0");
BlockStorage.addBlockInfo(b, "frequency", "0");
BlockStorage.addBlockInfo(b, "filter-type", "whitelist");
BlockStorage.addBlockInfo(b, "filter-lore", "true");
BlockStorage.addBlockInfo(b, "filter-durability", "false");
}
@Override
public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) {
BlockMenu inv = BlockStorage.getInventory(b);
if (inv != null) {
for (int slot: getInputSlots()) {
if (inv.getItemInSlot(slot) != null) {
b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot));
inv.replaceExistingItem(slot, null);
}
}
}
return true;
}
});
}
protected void constructMenu(BlockMenuPreset preset) {
for (int i : border) {
preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "),
(p, slot, item, action) -> false
);
}
preset.addItem(2, new CustomItem(new ItemStack(Material.PAPER), "&3Items", "", "&bPut in all Items you want to", "&bblacklist/whitelist"),
(p, slot, item, action) -> false
);
}
public int[] getInputSlots() {
return new int[] {19, 20, 21, 28, 29, 30, 37, 38, 39};
}
}

View File

@ -1,226 +1,226 @@
package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.cargo;
import java.util.logging.Level;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem;
import me.mrCookieSlime.CSCoreLibPlugin.general.World.CustomSkull;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.item_transport.CargoNet;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
public class CargoInputNode extends SlimefunItem {
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};
public CargoInputNode(Category category, ItemStack item, String name, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
super(category, item, name, recipeType, recipe, recipeOutput);
new BlockMenuPreset(name, "&3Input Node") {
@Override
public void init() {
constructMenu(this);
}
@Override
public void newInstance(final BlockMenu menu, final Block b) {
try {
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-type") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-type").equals("whitelist")) {
menu.replaceExistingItem(15, new CustomItem(new ItemStack(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");
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(15, new CustomItem(new ItemStack(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");
newInstance(menu, b);
return false;
});
}
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability").equals("false")) {
ItemStack is = new ItemStack(Material.STONE_SWORD);
Damageable dmg = (Damageable) is.getItemMeta();
dmg.setDamage(20);
is.setItemMeta((ItemMeta) dmg);
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", "true");
newInstance(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", "false");
newInstance(menu, b);
return false;
});
}
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "round-robin") == null || BlockStorage.getLocationInfo(b.getLocation(), "round-robin").equals("false")) {
menu.replaceExistingItem(24, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDc4ZjJiN2U1ZTc1NjM5ZWE3ZmI3OTZjMzVkMzY0YzRkZjI4YjQyNDNlNjZiNzYyNzdhYWRjZDYyNjEzMzcifX19"), "&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", "true");
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(24, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDc4ZjJiN2U1ZTc1NjM5ZWE3ZmI3OTZjMzVkMzY0YzRkZjI4YjQyNDNlNjZiNzYyNzdhYWRjZDYyNjEzMzcifX19"), "&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", "false");
newInstance(menu, b);
return false;
});
}
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore").equals("true")) {
menu.replaceExistingItem(25, new CustomItem(new ItemStack(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", "false");
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(25, new CustomItem(new ItemStack(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", "true");
newInstance(menu, b);
return false;
});
}
menu.replaceExistingItem(41, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjI1OTliZDk4NjY1OWI4Y2UyYzQ5ODg1MjVjOTRlMTlkZGQzOWZhZDA4YTM4Mjg0YTE5N2YxYjcwNjc1YWNjIn19fQ=="), "&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 (CargoNet.extraChannels) channel = 16;
else channel = 15;
}
BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channel));
newInstance(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(SlimefunItems.CHEST_TERMINAL, "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(42,
(p, slot, item, action) -> false
);
}
else {
menu.replaceExistingItem(42, new CustomItem(new ItemStack(MaterialCollections.getAllWoolColors().get(channel)), "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(42,
(p, slot, item, action) -> false
);
}
menu.replaceExistingItem(43, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzJmOTEwYzQ3ZGEwNDJlNGFhMjhhZjZjYzgxY2Y0OGFjNmNhZjM3ZGFiMzVmODhkYjk5M2FjY2I5ZGZlNTE2In19fQ=="), "&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 (CargoNet.extraChannels) {
if (channeln > 16) channeln = 0;
}
else {
if (channeln > 15) channeln = 0;
}
BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channeln));
newInstance(menu, b);
return false;
});
} catch (Exception x) {
Slimefun.getLogger().log(Level.SEVERE, "An Error occured while creating a Cargo Input Node for Slimefun " + Slimefun.getVersion(), x);
}
}
@Override
public boolean canOpen(Block b, Player p) {
return p.hasPermission("slimefun.cargo.bypass") || SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.ACCESS_INVENTORIES);
}
@Override
public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) {
return new int[0];
}
};
registerBlockHandler(name, new SlimefunBlockHandler() {
@Override
public void onPlace(Player p, Block b, SlimefunItem item) {
BlockStorage.addBlockInfo(b, "owner", p.getUniqueId().toString());
BlockStorage.addBlockInfo(b, "index", "0");
BlockStorage.addBlockInfo(b, "frequency", "0");
BlockStorage.addBlockInfo(b, "filter-type", "whitelist");
BlockStorage.addBlockInfo(b, "filter-lore", "true");
BlockStorage.addBlockInfo(b, "filter-durability", "false");
BlockStorage.addBlockInfo(b, "round-robin", "false");
}
@Override
public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) {
BlockMenu inv = BlockStorage.getInventory(b);
if (inv != null) {
for (int slot : getInputSlots()) {
if (inv.getItemInSlot(slot) != null) {
b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot));
inv.replaceExistingItem(slot, null);
}
}
}
return true;
}
});
}
protected void constructMenu(BlockMenuPreset preset) {
for (int i : border) {
preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
}
preset.addItem(2, new CustomItem(new ItemStack(Material.PAPER), "&3Items", "", "&bPut in all Items you want to", "&bblacklist/whitelist"), (p, slot, item, action) -> false);
}
public int[] getInputSlots() {
return new int[] {19, 20, 21, 28, 29, 30, 37, 38, 39};
}
}
package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.cargo;
import java.util.logging.Level;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem;
import me.mrCookieSlime.CSCoreLibPlugin.general.World.CustomSkull;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.item_transport.CargoNet;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
public class CargoInputNode extends SlimefunItem {
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};
public CargoInputNode(Category category, ItemStack item, String name, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
super(category, item, name, recipeType, recipe, recipeOutput);
new BlockMenuPreset(name, "&3Input Node") {
@Override
public void init() {
constructMenu(this);
}
@Override
public void newInstance(final BlockMenu menu, final Block b) {
try {
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-type") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-type").equals("whitelist")) {
menu.replaceExistingItem(15, new CustomItem(new ItemStack(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");
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(15, new CustomItem(new ItemStack(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");
newInstance(menu, b);
return false;
});
}
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability").equals("false")) {
ItemStack is = new ItemStack(Material.STONE_SWORD);
Damageable dmg = (Damageable) is.getItemMeta();
dmg.setDamage(20);
is.setItemMeta((ItemMeta) dmg);
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", "true");
newInstance(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", "false");
newInstance(menu, b);
return false;
});
}
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "round-robin") == null || BlockStorage.getLocationInfo(b.getLocation(), "round-robin").equals("false")) {
menu.replaceExistingItem(24, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDc4ZjJiN2U1ZTc1NjM5ZWE3ZmI3OTZjMzVkMzY0YzRkZjI4YjQyNDNlNjZiNzYyNzdhYWRjZDYyNjEzMzcifX19"), "&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", "true");
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(24, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDc4ZjJiN2U1ZTc1NjM5ZWE3ZmI3OTZjMzVkMzY0YzRkZjI4YjQyNDNlNjZiNzYyNzdhYWRjZDYyNjEzMzcifX19"), "&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", "false");
newInstance(menu, b);
return false;
});
}
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore").equals("true")) {
menu.replaceExistingItem(25, new CustomItem(new ItemStack(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", "false");
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(25, new CustomItem(new ItemStack(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", "true");
newInstance(menu, b);
return false;
});
}
menu.replaceExistingItem(41, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjI1OTliZDk4NjY1OWI4Y2UyYzQ5ODg1MjVjOTRlMTlkZGQzOWZhZDA4YTM4Mjg0YTE5N2YxYjcwNjc1YWNjIn19fQ=="), "&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 (CargoNet.extraChannels) channel = 16;
else channel = 15;
}
BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channel));
newInstance(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(SlimefunItems.CHEST_TERMINAL, "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(42,
(p, slot, item, action) -> false
);
}
else {
menu.replaceExistingItem(42, new CustomItem(new ItemStack(MaterialCollections.getAllWoolColors().get(channel)), "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(42,
(p, slot, item, action) -> false
);
}
menu.replaceExistingItem(43, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzJmOTEwYzQ3ZGEwNDJlNGFhMjhhZjZjYzgxY2Y0OGFjNmNhZjM3ZGFiMzVmODhkYjk5M2FjY2I5ZGZlNTE2In19fQ=="), "&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 (CargoNet.extraChannels) {
if (channeln > 16) channeln = 0;
}
else {
if (channeln > 15) channeln = 0;
}
BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channeln));
newInstance(menu, b);
return false;
});
} catch (Exception x) {
Slimefun.getLogger().log(Level.SEVERE, "An Error occured while creating a Cargo Input Node for Slimefun " + Slimefun.getVersion(), x);
}
}
@Override
public boolean canOpen(Block b, Player p) {
return p.hasPermission("slimefun.cargo.bypass") || SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.ACCESS_INVENTORIES);
}
@Override
public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) {
return new int[0];
}
};
registerBlockHandler(name, new SlimefunBlockHandler() {
@Override
public void onPlace(Player p, Block b, SlimefunItem item) {
BlockStorage.addBlockInfo(b, "owner", p.getUniqueId().toString());
BlockStorage.addBlockInfo(b, "index", "0");
BlockStorage.addBlockInfo(b, "frequency", "0");
BlockStorage.addBlockInfo(b, "filter-type", "whitelist");
BlockStorage.addBlockInfo(b, "filter-lore", "true");
BlockStorage.addBlockInfo(b, "filter-durability", "false");
BlockStorage.addBlockInfo(b, "round-robin", "false");
}
@Override
public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) {
BlockMenu inv = BlockStorage.getInventory(b);
if (inv != null) {
for (int slot : getInputSlots()) {
if (inv.getItemInSlot(slot) != null) {
b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot));
inv.replaceExistingItem(slot, null);
}
}
}
return true;
}
});
}
protected void constructMenu(BlockMenuPreset preset) {
for (int i : border) {
preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
}
preset.addItem(2, new CustomItem(new ItemStack(Material.PAPER), "&3Items", "", "&bPut in all Items you want to", "&bblacklist/whitelist"), (p, slot, item, action) -> false);
}
public int[] getInputSlots() {
return new int[] {19, 20, 21, 28, 29, 30, 37, 38, 39};
}
}

View File

@ -1,5 +1,5 @@
package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces;
public interface NotPlaceable {
}
package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces;
public interface NotPlaceable {
}

Some files were not shown because too many files have changed in this diff Show More