diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index aeb2d6f..9629482 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ stages: variables: name: "EpicHoppers" path: "/builds/$CI_PROJECT_PATH" - version: "4-pre-release-5" + version: "4-pre-release-7" build: stage: build diff --git a/pom.xml b/pom.xml index 12ea26c..c713634 100644 --- a/pom.xml +++ b/pom.xml @@ -103,5 +103,10 @@ 2.2.1 provided + + net.brcdev + ShopGUIPlus + 1.19.5 + diff --git a/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoSell.java b/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoSell.java index 1540b41..0b5fbf0 100644 --- a/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoSell.java +++ b/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoSell.java @@ -5,8 +5,10 @@ import com.songoda.epichoppers.hopper.Hopper; import com.songoda.epichoppers.tasks.HopTask; import com.songoda.epichoppers.utils.Methods; import com.songoda.epichoppers.utils.ServerVersion; +import com.songoda.epichoppers.utils.settings.Setting; import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; @@ -46,23 +48,28 @@ public class ModuleAutoSell implements Module { List list = instance.getConfig().getStringList("Main.AutoSell Prices"); - for (String line : list) { - try { - String[] split = line.split(","); + OfflinePlayer player = Bukkit.getOfflinePlayer(hopper.getPlacedBy()); - Material material = Material.valueOf(split[0]); - double price = Double.valueOf(split[1]); + for (ItemStack itemStack : hopperInventory.getContents()) { + if (itemStack == null) continue; - for (ItemStack itemStack : hopperInventory.getContents()) { - if (itemStack == null || itemStack.getType() != material) continue; - - instance.getEconomy().deposit(Bukkit.getOfflinePlayer(hopper.getPlacedBy()), price * itemStack.getAmount()); - hopperInventory.removeItem(itemStack); - - updateComparators = true; + double value; + if (Setting.AUTOSELL_SHOPGUIPLUS.getBoolean() && player.isOnline()) { + try { + value = net.brcdev.shopgui.ShopGuiPlusApi.getItemStackPriceSell(player.getPlayer(), itemStack); + } catch (Exception e){ + value = 0; } - } catch (Exception ignored) { - } + } else + value = list.stream().filter(line -> Material.valueOf(line.split(",")[0]) + == itemStack.getType()).findFirst().map(s -> Double.valueOf(s.split(",")[1])).orElse(0.0); + + if (value == 0) continue; + + instance.getEconomy().deposit(player, value * itemStack.getAmount()); + hopperInventory.removeItem(itemStack); + + updateComparators = true; } hopper.setAutoSellTimer(timeOut); diff --git a/src/main/java/com/songoda/epichoppers/listeners/HopperListeners.java b/src/main/java/com/songoda/epichoppers/listeners/HopperListeners.java index c4d192b..8cbe836 100644 --- a/src/main/java/com/songoda/epichoppers/listeners/HopperListeners.java +++ b/src/main/java/com/songoda/epichoppers/listeners/HopperListeners.java @@ -3,14 +3,12 @@ package com.songoda.epichoppers.listeners; import com.songoda.epichoppers.EpicHoppers; import com.songoda.epichoppers.hopper.Hopper; import com.songoda.epichoppers.utils.HopperDirection; -import org.bukkit.Bukkit; +import com.songoda.epichoppers.utils.ServerVersion; import org.bukkit.Location; import org.bukkit.block.Chest; import org.bukkit.block.DoubleChest; -import org.bukkit.block.ShulkerBox; import org.bukkit.entity.Minecart; import org.bukkit.entity.minecart.HopperMinecart; -import org.bukkit.entity.minecart.StorageMinecart; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryMoveItemEvent; @@ -35,12 +33,19 @@ public class HopperListeners implements Listener { // Hopper minecarts should be able to take care of themselves // Let EpicHoppers take over if the hopper is pointing down though - if (destination.getHolder() instanceof HopperMinecart && (!(source.getHolder() instanceof org.bukkit.block.Hopper) - || HopperDirection.getDirection(((org.bukkit.block.Hopper)destination.getHolder()).getRawData()) != HopperDirection.DOWN)) + if (destination.getHolder() instanceof HopperMinecart + && source.getHolder() instanceof org.bukkit.block.Hopper + && HopperDirection.getDirection(((org.bukkit.block.Hopper)source.getHolder()).getRawData()) != HopperDirection.DOWN) return; // Shulker boxes have a mind of their own and relentlessly steal items from hoppers - if (destination.getHolder() instanceof ShulkerBox || !(source.getHolder() instanceof org.bukkit.block.Hopper)) { + if (this.instance.isServerVersionAtLeast(ServerVersion.V1_11) && destination.getHolder() instanceof org.bukkit.block.ShulkerBox || !(source.getHolder() instanceof org.bukkit.block.Hopper)) { + event.setCancelled(true); + return; + } + + // Hopper going into minecarts + if (destination.getHolder() instanceof Minecart && source.getHolder() instanceof org.bukkit.block.Hopper) { event.setCancelled(true); return; } diff --git a/src/main/java/com/songoda/epichoppers/utils/Serializers.java b/src/main/java/com/songoda/epichoppers/utils/Serializers.java index 7f3aca4..e0d5c70 100644 --- a/src/main/java/com/songoda/epichoppers/utils/Serializers.java +++ b/src/main/java/com/songoda/epichoppers/utils/Serializers.java @@ -53,7 +53,6 @@ public class Serializers { } for (String str : strings) { args = str.split(":", 2); - Bukkit.broadcastMessage(Arrays.toString(args)); if (isNumber(args[0])) item.setAmount(Integer.parseInt(args[0])); if (args.length == 1) continue; if (args[0].equalsIgnoreCase("name")) { diff --git a/src/main/java/com/songoda/epichoppers/utils/settings/Setting.java b/src/main/java/com/songoda/epichoppers/utils/settings/Setting.java index 62e4bba..efe79cc 100644 --- a/src/main/java/com/songoda/epichoppers/utils/settings/Setting.java +++ b/src/main/java/com/songoda/epichoppers/utils/settings/Setting.java @@ -58,6 +58,11 @@ public enum Setting { Arrays.asList("STONE,0.50", "COBBLESTONE,0.20", "IRON_ORE,0.35", "COAL_ORE,0.20"), "These are the prices used by the auto sell module."), + AUTOSELL_SHOPGUIPLUS("Main.Use ShopGuiPlus for Prices", false, + "Should prices be grabbed from ShopGuiPlus?", + "If ShopGuiPlus is not enabled or the player is offline the default price list will be used.", + "If this is something that you do not want then you should empty the default list."), + VAULT_ECONOMY("Economy.Use Vault Economy", true, "Should Vault be used?"),