From 045aec1adb1c4b3810d7e31802c57088771b1c6e Mon Sep 17 00:00:00 2001 From: Brianna Date: Sun, 13 Oct 2019 18:50:33 -0400 Subject: [PATCH] Added the ability to toggle suction on and modify the range.. --- .../songoda/epichoppers/gui/GUIOverview.java | 2 + .../hopper/levels/modules/ModuleSuction.java | 62 ++++++++++++++++--- .../storage/types/StorageYaml.java | 1 - src/main/resources/en_US.lang | 3 +- 4 files changed, 58 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/songoda/epichoppers/gui/GUIOverview.java b/src/main/java/com/songoda/epichoppers/gui/GUIOverview.java index 9096941..4f025ee 100644 --- a/src/main/java/com/songoda/epichoppers/gui/GUIOverview.java +++ b/src/main/java/com/songoda/epichoppers/gui/GUIOverview.java @@ -142,6 +142,8 @@ public class GUIOverview extends Gui { layouts.put(6, new Integer[]{23, 3, 4, 5, 21, 22}); layouts.put(7, new Integer[]{23, 3, 4, 5, 21, 22, 12}); layouts.put(8, new Integer[]{23, 3, 4, 5, 21, 22, 12, 14}); + layouts.put(9, new Integer[]{23, 3, 4, 5, 21, 22, 12, 14, 20}); + layouts.put(10, new Integer[]{23, 3, 4, 5, 21, 22, 12, 14, 20, 24}); int amount = 1; diff --git a/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleSuction.java b/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleSuction.java index 11655b7..9743f33 100644 --- a/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleSuction.java +++ b/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleSuction.java @@ -1,7 +1,9 @@ package com.songoda.epichoppers.hopper.levels.modules; import com.bgsoftware.wildstacker.api.WildStackerAPI; +import com.songoda.core.compatibility.CompatibleMaterial; import com.songoda.core.compatibility.ServerVersion; +import com.songoda.core.locale.Locale; import com.songoda.epichoppers.EpicHoppers; import com.songoda.epichoppers.hopper.Hopper; import com.songoda.epichoppers.utils.Methods; @@ -15,6 +17,7 @@ import org.bukkit.entity.Item; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; import java.lang.reflect.Method; import java.util.ArrayList; @@ -25,9 +28,9 @@ import java.util.stream.Collectors; public class ModuleSuction extends Module { - private final int searchRadius; + private final int maxSearchRadius; - public static List blacklist = new ArrayList<>(); + private static List blacklist = new ArrayList<>(); private final static boolean wildStacker = Bukkit.getPluginManager().isPluginEnabled("WildStacker"); private final static boolean ultimateStacker = Bukkit.getPluginManager().isPluginEnabled("UltimateStacker"); @@ -48,7 +51,7 @@ public class ModuleSuction extends Module { public ModuleSuction(EpicHoppers plugin, int amount) { super(plugin); - this.searchRadius = amount; + this.maxSearchRadius = amount; } @Override @@ -58,7 +61,9 @@ public class ModuleSuction extends Module { @Override public void run(Hopper hopper, StorageContainerCache.Cache hopperCache) { - double radius = searchRadius + .5; + double radius = getRadius(hopper) + .5; + + if (!isEnabled(hopper)) return; Set itemsToSuck = hopper.getLocation().getWorld().getNearbyEntities(hopper.getLocation().add(0.5, 0.5, 0.5), radius, radius, radius) .stream() @@ -162,8 +167,7 @@ public class ModuleSuction extends Module { } else if (wildStacker) WildStackerAPI.getStackedItem(item).setStackAmount(amount, true); else - item.getItemStack().setAmount(amount > item.getItemStack().getMaxStackSize() - ? item.getItemStack().getMaxStackSize() : amount); + item.getItemStack().setAmount(Math.min(amount, item.getItemStack().getMaxStackSize())); } public static boolean isBlacklisted(UUID uuid) { @@ -172,11 +176,53 @@ public class ModuleSuction extends Module { @Override public ItemStack getGUIButton(Hopper hopper) { - return null; + Locale locale = EpicHoppers.getInstance().getLocale(); + ItemStack item = CompatibleMaterial.CAULDRON.getItem(); + ItemMeta meta = item.getItemMeta(); + meta.setDisplayName(locale.getMessage("interface.hopper.suctiontitle").getMessage()); + List lore = new ArrayList<>(); + String[] parts = locale.getMessage("interface.hopper.suctionlore") + .processPlaceholder("status", isEnabled(hopper) ? locale.getMessage("general.word.enabled").getMessage() : locale.getMessage("general.word.disabled")) + .processPlaceholder("radius", getRadius(hopper)).getMessage().split("\\|"); + for (String line : parts) { + lore.add(Methods.formatText(line)); + } + meta.setLore(lore); + item.setItemMeta(meta); + return item; } @Override public void runButtonPress(Player player, Hopper hopper, ClickType type) { + if (type == ClickType.LEFT) { + toggleEnabled(hopper); + } else if (type == ClickType.RIGHT) { + int setRadius = getRadius(hopper); + if (setRadius >= maxSearchRadius) { + setRadius(hopper, 1); + } else { + setRadius(hopper, ++setRadius); + } + } + } + + + private boolean isEnabled(Hopper hopper) { + Object obj = getData(hopper, "enabled"); + return obj == null || (boolean) obj; + } + + private void toggleEnabled(Hopper hopper) { + saveData(hopper, "enabled", !isEnabled(hopper)); + } + + private int getRadius(Hopper hopper) { + Object foundRadius = getData(hopper, "radius"); + return foundRadius == null ? maxSearchRadius : (int) foundRadius; + } + + private void setRadius(Hopper hopper, int radius) { + saveData(hopper, "radius", radius); } @Override @@ -187,6 +233,6 @@ public class ModuleSuction extends Module { @Override public String getDescription() { return EpicHoppers.getInstance().getLocale().getMessage("interface.hopper.suction") - .processPlaceholder("suction", searchRadius).getMessage(); + .processPlaceholder("suction", maxSearchRadius).getMessage(); } } diff --git a/src/main/java/com/songoda/epichoppers/storage/types/StorageYaml.java b/src/main/java/com/songoda/epichoppers/storage/types/StorageYaml.java index 0edbbfa..e0bd839 100644 --- a/src/main/java/com/songoda/epichoppers/storage/types/StorageYaml.java +++ b/src/main/java/com/songoda/epichoppers/storage/types/StorageYaml.java @@ -94,7 +94,6 @@ public class StorageYaml extends Storage { } for (Map.Entry entry : toSave.entrySet()) { - System.out.println(entry.getKey()); dataFile.set(entry.getKey(), entry.getValue()); } diff --git a/src/main/resources/en_US.lang b/src/main/resources/en_US.lang index 93d6247..4e6aaba 100644 --- a/src/main/resources/en_US.lang +++ b/src/main/resources/en_US.lang @@ -38,6 +38,8 @@ interface.hopper.selltitle = "&6Left-Click to Toggle AutoSelling" interface.hopper.selllore = "&6Right-Click to Toggle Notifications||&7Selling in &6%timeleft%s&7.|&7Notifications: &6%state%&7." interface.hopper.blocktitle = "&6Click to Toggle BlockBreak" interface.hopper.blocklore = "|&7BlockBreak is set to &6%enabled%&7." +interface.hopper.suctiontitle = "&6Suction" +interface.hopper.suctionlore = "|&7Left-Click to toggle suction |&7(&6%status%&7).||&7Right-Click to set radius |&7(&6%radius%&7)." interface.hopper.synchopper = "&6Click to Link This hopper" interface.hopper.rejectsync = "&6Click to Link Rejected Items" interface.filter.infotitle = "&aFilter Guide" @@ -75,5 +77,4 @@ event.hopper.walkteledisabled = "Walk on teleporting has been disabled for this event.hopper.onlyone = "&cYou may only place a single item at a time." event.hopper.syncchest = "&7You have linked your &9%name% &7with this chest." event.hopper.desyncchest = "&7You have unlinked your &9%name% &7with this chest." - event.hopper.autosell = "&7Your hopper sold &6%items% &7item(s) worth &6$%amount%&7." \ No newline at end of file