mirror of
https://github.com/songoda/EpicHoppers.git
synced 2024-11-29 21:54:16 +01:00
Added AutoSell filter
This commit is contained in:
parent
23ccce1bc4
commit
cd601a8b7f
@ -19,6 +19,7 @@ import com.songoda.epichoppers.hopper.HopperManager;
|
||||
import com.songoda.epichoppers.hopper.levels.Level;
|
||||
import com.songoda.epichoppers.hopper.levels.LevelManager;
|
||||
import com.songoda.epichoppers.hopper.levels.modules.*;
|
||||
import com.songoda.epichoppers.hopper.levels.modules.Module;
|
||||
import com.songoda.epichoppers.listeners.*;
|
||||
import com.songoda.epichoppers.player.PlayerDataManager;
|
||||
import com.songoda.epichoppers.settings.Settings;
|
||||
@ -199,12 +200,19 @@ public class EpicHoppers extends SongodaPlugin {
|
||||
List<ItemStack> blackList = row.get("blacklist").asItemStackList();
|
||||
List<ItemStack> voidList = row.get("void").asItemStackList();
|
||||
|
||||
List<ItemStack> autoSellWhiteList = row.get("autosell-whitelist").asItemStackList();
|
||||
List<ItemStack> autoSellBlackList = row.get("autosell-blacklist").asItemStackList();
|
||||
|
||||
String blackLoc = row.get("black").asString();
|
||||
Location black = blackLoc == null ? null : Methods.unserializeLocation(blackLoc);
|
||||
|
||||
filter.setWhiteList(whiteList);
|
||||
filter.setBlackList(blackList);
|
||||
filter.setVoidList(voidList);
|
||||
|
||||
filter.setAutoSellWhiteList(autoSellWhiteList);
|
||||
filter.setAutoSellBlackList(autoSellBlackList);
|
||||
|
||||
filter.setEndPoint(black);
|
||||
|
||||
TeleportTrigger teleportTrigger = TeleportTrigger.valueOf(row.get("teleporttrigger").asString() == null ? "DISABLED" : row.get("teleporttrigger").asString());
|
||||
|
153
src/main/java/com/songoda/epichoppers/gui/GUIAutoSellFilter.java
Normal file
153
src/main/java/com/songoda/epichoppers/gui/GUIAutoSellFilter.java
Normal file
@ -0,0 +1,153 @@
|
||||
package com.songoda.epichoppers.gui;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.gui.Gui;
|
||||
import com.songoda.core.gui.GuiUtils;
|
||||
import com.songoda.epichoppers.EpicHoppers;
|
||||
import com.songoda.epichoppers.hopper.Filter;
|
||||
import com.songoda.epichoppers.hopper.Hopper;
|
||||
import com.songoda.epichoppers.settings.Settings;
|
||||
import com.songoda.epichoppers.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GUIAutoSellFilter extends Gui {
|
||||
|
||||
public final Hopper hopper;
|
||||
|
||||
private final int[] whiteListSlots = {9, 10, 11, 18, 19, 20, 27, 28, 29, 36, 37, 38};
|
||||
private final int[] blackListSlots = {12, 13, 14, 21, 22, 23, 30, 31, 32, 39, 40, 41};
|
||||
|
||||
public GUIAutoSellFilter(EpicHoppers plugin, Hopper hopper) {
|
||||
this.hopper = hopper;
|
||||
|
||||
setRows(6);
|
||||
setTitle(Methods.formatText(Methods.formatName(hopper.getLevel().getLevel(), false) + " &8-&f AutoSell Filter"));
|
||||
setDefaultItem(null);
|
||||
setAcceptsItems(true);
|
||||
|
||||
setOnClose((event) -> compile());
|
||||
|
||||
Filter filter = hopper.getFilter();
|
||||
|
||||
// Fill
|
||||
ItemStack glass1 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_1.getMaterial());
|
||||
ItemStack glass2 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_2.getMaterial());
|
||||
|
||||
GuiUtils.mirrorFill(this, 0, 6, true, false, glass2);
|
||||
GuiUtils.mirrorFill(this, 0, 7, true, false, glass2);
|
||||
GuiUtils.mirrorFill(this, 0, 8, true, false, glass2);
|
||||
GuiUtils.mirrorFill(this, 1, 6, true, false, glass2);
|
||||
GuiUtils.mirrorFill(this, 1, 8, true, false, glass2);
|
||||
GuiUtils.mirrorFill(this, 2, 6, true, false, glass2);
|
||||
GuiUtils.mirrorFill(this, 2, 7, true, false, glass1);
|
||||
GuiUtils.mirrorFill(this, 2, 8, true, false, glass2);
|
||||
GuiUtils.mirrorFill(this, 4, 7, false, false, glass1);
|
||||
|
||||
// Whitelist
|
||||
ItemStack indicatorItem = CompatibleMaterial.WHITE_STAINED_GLASS_PANE.getItem();
|
||||
ItemMeta indicatorMeta = indicatorItem.getItemMeta();
|
||||
indicatorMeta.setDisplayName(plugin.getLocale().getMessage("interface.autosell-filter.whitelist").getMessage());
|
||||
indicatorItem.setItemMeta(indicatorMeta);
|
||||
|
||||
int[] whiteSlots = {0, 1, 2, 45, 46, 47};
|
||||
for (int nu : whiteSlots) {
|
||||
setItem(nu, indicatorItem);
|
||||
}
|
||||
|
||||
int num = 0;
|
||||
for (ItemStack m : filter.getAutoSellWhiteList()) {
|
||||
if (num >= filter.getAutoSellWhiteList().size()) break;
|
||||
setItem(whiteListSlots[num], new ItemStack(m));
|
||||
num++;
|
||||
}
|
||||
|
||||
// Blacklist
|
||||
indicatorItem = CompatibleMaterial.BLACK_STAINED_GLASS_PANE.getItem();
|
||||
indicatorMeta = indicatorItem.getItemMeta();
|
||||
indicatorMeta.setDisplayName(plugin.getLocale().getMessage("interface.autosell-filter.blacklist").getMessage());
|
||||
indicatorItem.setItemMeta(indicatorMeta);
|
||||
|
||||
int[] blackSlots = {3, 4, 5, 48, 49, 50};
|
||||
for (int nu : blackSlots) {
|
||||
setItem(nu, indicatorItem);
|
||||
}
|
||||
|
||||
num = 0;
|
||||
for (ItemStack m : filter.getAutoSellBlackList()) {
|
||||
if (num >= filter.getAutoSellBlackList().size()) break;
|
||||
setItem(blackListSlots[num], new ItemStack(m));
|
||||
num++;
|
||||
}
|
||||
|
||||
// Info item
|
||||
indicatorItem = new ItemStack(Material.PAPER, 1);
|
||||
indicatorMeta = indicatorItem.getItemMeta();
|
||||
|
||||
indicatorMeta.setDisplayName(plugin.getLocale().getMessage("interface.autosell-filter.infotitle").getMessage());
|
||||
ArrayList<String> loreInfo = new ArrayList<>();
|
||||
String[] parts = plugin.getLocale().getMessage("interface.autosell-filter.infolore").getMessage().split("\\|");
|
||||
|
||||
for (String line : parts) {
|
||||
loreInfo.add(Methods.formatText(line));
|
||||
}
|
||||
|
||||
indicatorMeta.setLore(loreInfo);
|
||||
indicatorItem.setItemMeta(indicatorMeta);
|
||||
|
||||
setItem(16, indicatorItem);
|
||||
|
||||
setUnlockedRange(9, 14);
|
||||
setUnlockedRange(18, 23);
|
||||
setUnlockedRange(27, 32);
|
||||
setUnlockedRange(36, 41);
|
||||
}
|
||||
|
||||
private void compile() {
|
||||
ItemStack[] items = inventory.getContents();
|
||||
|
||||
Filter filter = hopper.getFilter();
|
||||
|
||||
List<ItemStack> whiteListItems = new ArrayList<>();
|
||||
List<ItemStack> blackListItems = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
for (int slot : whiteListSlots) {
|
||||
if (slot != i) continue;
|
||||
|
||||
if (items[i] != null && items[i].getType() != Material.AIR) {
|
||||
ItemStack item = items[i];
|
||||
if (item.getAmount() != 1) {
|
||||
item.setAmount(item.getAmount() - 1);
|
||||
Bukkit.getPlayer(hopper.getLastPlayerOpened()).getInventory().addItem(item);
|
||||
item.setAmount(1);
|
||||
}
|
||||
|
||||
whiteListItems.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
for (int slot : blackListSlots) {
|
||||
if (slot != i) continue;
|
||||
|
||||
if (items[i] != null && items[i].getType() != Material.AIR) {
|
||||
ItemStack item = items[i];
|
||||
if (item.getAmount() != 1) {
|
||||
item.setAmount(item.getAmount() - 1);
|
||||
Bukkit.getPlayer(hopper.getLastPlayerOpened()).getInventory().addItem(item);
|
||||
item.setAmount(1);
|
||||
}
|
||||
blackListItems.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
filter.setAutoSellWhiteList(whiteListItems);
|
||||
filter.setAutoSellBlackList(blackListItems);
|
||||
}
|
||||
}
|
@ -12,6 +12,10 @@ public class Filter {
|
||||
private List<ItemStack> blackList;
|
||||
private List<ItemStack> voidList;
|
||||
|
||||
private List<ItemStack> autoSellWhiteList;
|
||||
private List<ItemStack> autoSellBlackList;
|
||||
|
||||
|
||||
private Location endPoint;
|
||||
|
||||
|
||||
@ -45,6 +49,26 @@ public class Filter {
|
||||
}
|
||||
|
||||
|
||||
public List<ItemStack> getAutoSellWhiteList() {
|
||||
return autoSellWhiteList != null ? autoSellWhiteList : Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
|
||||
public void setAutoSellWhiteList(List<ItemStack> autoSellWhiteList) {
|
||||
this.autoSellWhiteList = autoSellWhiteList;
|
||||
}
|
||||
|
||||
|
||||
public List<ItemStack> getAutoSellBlackList() {
|
||||
return autoSellBlackList != null ? autoSellBlackList : Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
|
||||
public void setAutoSellBlackList(List<ItemStack> autoSellBlackList) {
|
||||
this.autoSellBlackList = autoSellBlackList;
|
||||
}
|
||||
|
||||
|
||||
public Location getEndPoint() {
|
||||
return endPoint;
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ package com.songoda.epichoppers.hopper.levels.modules;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.hooks.EconomyManager;
|
||||
import com.songoda.epichoppers.EpicHoppers;
|
||||
import com.songoda.epichoppers.gui.GUIAutoSellFilter;
|
||||
import com.songoda.epichoppers.hopper.Filter;
|
||||
import com.songoda.epichoppers.hopper.Hopper;
|
||||
import com.songoda.epichoppers.settings.Settings;
|
||||
import com.songoda.epichoppers.utils.Methods;
|
||||
@ -24,6 +26,7 @@ public class ModuleAutoSell extends Module {
|
||||
|
||||
private final int timeOut;
|
||||
private final int hopperTickRate;
|
||||
// TODO: Cached Sell prices are not updated on plugin reload, same with any other module
|
||||
private static List<String> cachedSellPrices = null;
|
||||
private static final Map<Hopper, Boolean> cachedNotifications = new ConcurrentHashMap<>();
|
||||
|
||||
@ -60,8 +63,22 @@ public class ModuleAutoSell extends Module {
|
||||
// -1
|
||||
for (int i = 0; i < hopperCache.cachedInventory.length; i++) {
|
||||
final ItemStack itemStack = hopperCache.cachedInventory[i];
|
||||
|
||||
if (itemStack == null) continue;
|
||||
|
||||
Filter filter = hopper.getFilter();
|
||||
|
||||
if (filter.getAutoSellWhiteList().isEmpty()) {
|
||||
// Check blacklist
|
||||
if (filter.getAutoSellBlackList().stream().anyMatch(item -> Methods.isSimilarMaterial(itemStack, item)))
|
||||
continue;
|
||||
} else {
|
||||
// Check whitelist
|
||||
if (filter.getAutoSellWhiteList().stream().noneMatch(item -> Methods.isSimilarMaterial(itemStack, item)))
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get the value from config or ShopGuiPlus
|
||||
double value;
|
||||
if (Settings.AUTOSELL_SHOPGUIPLUS.getBoolean() && player.isOnline()) {
|
||||
try {
|
||||
@ -72,8 +89,8 @@ public class ModuleAutoSell extends Module {
|
||||
value = 0;
|
||||
}
|
||||
} else
|
||||
value = cachedSellPrices.stream().filter(line -> Material.valueOf(line.split(",")[0])
|
||||
== itemStack.getType()).findFirst().map(s -> Double.valueOf(s.split(",")[1])).orElse(0.0);
|
||||
value = cachedSellPrices.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;
|
||||
|
||||
@ -101,19 +118,23 @@ public class ModuleAutoSell extends Module {
|
||||
|
||||
@Override
|
||||
public ItemStack getGUIButton(Hopper hopper) {
|
||||
ItemStack sell = CompatibleMaterial.SUNFLOWER.getItem();
|
||||
ItemMeta sellmeta = sell.getItemMeta();
|
||||
sellmeta.setDisplayName(EpicHoppers.getInstance().getLocale().getMessage("interface.hopper.selltitle").getMessage());
|
||||
ItemStack sellItem = CompatibleMaterial.SUNFLOWER.getItem();
|
||||
ItemMeta sellMeta = sellItem.getItemMeta();
|
||||
|
||||
sellMeta.setDisplayName(EpicHoppers.getInstance().getLocale().getMessage("interface.hopper.selltitle").getMessage());
|
||||
ArrayList<String> loreSell = new ArrayList<>();
|
||||
|
||||
String[] parts = EpicHoppers.getInstance().getLocale().getMessage("interface.hopper.selllore")
|
||||
.processPlaceholder("timeleft", getTime(hopper) == -9999 ? "\u221E" : (int) Math.floor(getTime(hopper) / 20))
|
||||
.processPlaceholder("state", isNotifying(hopper)).getMessage().split("\\|");
|
||||
|
||||
for (String line : parts) {
|
||||
loreSell.add(Methods.formatText(line));
|
||||
}
|
||||
sellmeta.setLore(loreSell);
|
||||
sell.setItemMeta(sellmeta);
|
||||
return sell;
|
||||
|
||||
sellMeta.setLore(loreSell);
|
||||
sellItem.setItemMeta(sellMeta);
|
||||
return sellItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -126,6 +147,9 @@ public class ModuleAutoSell extends Module {
|
||||
}
|
||||
} else if (type == ClickType.RIGHT) {
|
||||
setNotifying(hopper, !isNotifying(hopper));
|
||||
} else if (type == ClickType.SHIFT_LEFT || type == ClickType.SHIFT_RIGHT) {
|
||||
// Any shift click opens AutoSell filter configuration GUI
|
||||
EpicHoppers.getInstance().getGuiManager().showGUI(player, new GUIAutoSellFilter(EpicHoppers.getInstance(), hopper));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,6 +50,8 @@ public abstract class Storage {
|
||||
|
||||
new StorageItem("whitelist", hopper.getFilter().getWhiteList()),
|
||||
new StorageItem("blacklist", hopper.getFilter().getBlackList()),
|
||||
new StorageItem("autosell-whitelist", hopper.getFilter().getAutoSellWhiteList()),
|
||||
new StorageItem("autosell-blacklist", hopper.getFilter().getAutoSellBlackList()),
|
||||
new StorageItem("void", hopper.getFilter().getVoidList()),
|
||||
new StorageItem("black", hopper.getFilter().getEndPoint() == null ? null : Methods.serializeLocation(hopper.getFilter().getEndPoint())));
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ interface:
|
||||
craftingtitle: '&cClick to Setup AutoCrafting'
|
||||
craftinglore: '|&7This allows you to choose|&7which item this hopper|&7will automatically craft.'
|
||||
selltitle: '&6Left-Click to Toggle AutoSelling'
|
||||
selllore: '&6Right-Click to Toggle Notifications||&7Selling in &6%timeleft%s&7.|&7Notifications: &6%state%&7.'
|
||||
selllore: '&6Right-Click to Toggle Notifications|&6Shift-Click to Open AutoSell filter||&7Selling in &6%timeleft%s&7.|&7Notifications: &6%state%&7.'
|
||||
blocktitle: '&6Click to Toggle BlockBreak'
|
||||
blocklore: '|&7BlockBreak is set to &6%enabled%&7.'
|
||||
suctiontitle: '&6Suction'
|
||||
@ -53,6 +53,11 @@ interface:
|
||||
whitelist: '&f&lWhite List'
|
||||
blacklist: '&8&lBlack List'
|
||||
void: '&c&lVoid'
|
||||
autosell-filter:
|
||||
infotitle: '&aFilter Guide'
|
||||
infolore: '&7Items placed in the left column|&7space will be whitelisted for Auto Sell.||&7Items placed in the right column|&7will be blacklisted from Auto Sell.'
|
||||
whitelist: '&f&lWhite List'
|
||||
blacklist: '&8&lBlack List'
|
||||
|
||||
# Command Messages
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user