From 4b74e73fc3dfe5f4889ca2f102f68a7b1aa1e89d Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Sat, 22 Sep 2018 22:18:13 +0800 Subject: [PATCH] add float filter,idea by @WHiZ#7935 in discord channel Former-commit-id: 6e15b75659f6722b033b91208aefbf77b5aeb08d --- .../maxgamer/quickshop/Shop/DisplayItem.java | 124 +++++++++++++++++- src/main/resources/config.yml | 31 ++++- 2 files changed, 153 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java b/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java index 420065bcd..50dd334aa 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java @@ -1,10 +1,14 @@ package org.maxgamer.quickshop.Shop; +import java.awt.List; import java.util.ArrayList; import java.util.logging.Level; import org.bukkit.Chunk; import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Entity; import org.bukkit.entity.Item; import org.bukkit.inventory.ItemStack; @@ -13,6 +17,8 @@ import org.bukkit.util.Vector; import org.maxgamer.quickshop.QuickShop; //import org.maxgamer.quickshop.Util.NMS; +import com.google.common.util.concurrent.ForwardingListenableFuture; + /** * @author Netherfoam A display item, that spawns a block above the chest and * cannot be interacted with. @@ -22,9 +28,12 @@ public class DisplayItem { private ItemStack iStack; private Item item; private QuickShop plugin; + private java.util.List itemlist; + private java.util.List lorelist; + private java.util.List displaynamelist; // private Location displayLoc; - /** + /**ZZ * Creates a new display item. * * @param shop @@ -35,6 +44,7 @@ public class DisplayItem { public DisplayItem(Shop shop, ItemStack iStack) { this.shop = shop; this.iStack = iStack.clone(); + // this.displayLoc = shop.getLocation().clone().add(0.5, 1.2, 0.5); } @@ -45,6 +55,118 @@ public class DisplayItem { if (shop.getLocation().getWorld() == null) return; Location dispLoc = this.getDisplayLocation(); + //Check is or not in blacklist/whitelist + boolean showFloatItem = true; + FileConfiguration config = plugin.getConfig(); + if(config.getBoolean("float.enable")){ + //Enabled! Check start! + //Item + boolean found_item = false; + boolean found_lore = false; + boolean found_displayname = false; + if(config.getBoolean("float.item.enable")) { + boolean blacklist = config.getBoolean("float.item.blacklist"); + itemlist.clear(); + itemlist = config.getList("float.item.list"); + for (Object material : itemlist) { + String materialname = String.valueOf(material); + Material item = Material.matchMaterial(materialname); + if(item!=null) { + found_item=true; + break; + }else { + plugin.getLogger().info(materialname+" not a bukkit item."); + } + } + if(found_item) { + if(blacklist) { + showFloatItem=false; + } + }else { + if(!blacklist) { + showFloatItem=false; + } + } + } + if(!showFloatItem) { + return; + } + //End Item check + + //DisplayName + if(config.getBoolean("float.displayname.enable")) { + boolean blacklist = config.getBoolean("float.displayname.blacklist"); + displaynamelist.clear(); + displaynamelist = config.getList("float.displayname.list"); + if(!iStack.hasItemMeta()) { + found_displayname=false; + }else { + String itemname = iStack.getItemMeta().getDisplayName(); + for (Object name : displaynamelist) { + String listname = String.valueOf(name); + if(listname.contains(listname)) { + found_displayname = true; + break; + } + } + + } + if(blacklist) { + if(found_displayname) { + showFloatItem = false; + } + }else { + if(!found_displayname) { + showFloatItem = false; + } + } + if(!showFloatItem) { + return; + } + //End DisplayName check + } + + if(config.getBoolean("float.lore.enable")) { + boolean blacklist = config.getBoolean("float.lore.blacklist"); + lorelist.clear(); + lorelist=config.getList("float.lore.list"); + if(!iStack.hasItemMeta()) { + found_lore = false; + }else { + java.util.List itemlores = iStack.getItemMeta().getLore(); + for (String loreinItem : itemlores) { + String loreinItem_String = loreinItem; + for (Object loreinList : lorelist) { + String loreinList_String = String.valueOf(loreinList); + if(loreinItem_String.contains(loreinList_String)) { + found_lore = true; + break; + } + } + if(found_lore) { + break; + } + } + if(blacklist) { + if(found_lore) { + showFloatItem=false; + } + }else { + if(!found_lore) { + showFloatItem=false; + } + } + if(!showFloatItem) { + return; + } + + } + } + } + //Check end + if(!showFloatItem) { + return; + } this.item = shop.getLocation().getWorld().dropItem(dispLoc, this.iStack); this.item.setVelocity(new Vector(0, 0.1, 0)); if (QuickShop.debug) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 1f41b261d..69bdc125f 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -151,4 +151,33 @@ itemi18n: lockette: private: "[Private]" more_users: "[More Users]" - #Make Quickshop not cancel break lock sign event(Inpossible break locked chest) \ No newline at end of file + #Make Quickshop not cancel break lock sign event(Inpossible break locked chest) +float: + enable: false + #If this is disabled, all options after this will not working. + item: + #Item filter + enable: false + blacklist: true + #true = use blacklist mode, in blacklist item will disallow spawn float item + #false = use whitelist mode, in whitelist item will allow spawn float item + list: + - STONE + - GRASS + #add item's BUKKIT NAME in there + lore: + enable: false + blacklist: true + #true = use blacklist mode, in blacklist item will disallow spawn float item + #false = use whitelist mode, in whitelist item will allow spawn float item + list: + - NOT FLOAT LORE + #add keywords in there, plugin will check it contain or not on items. + displayname: + enable: false + blacklist: true + #true = use blacklist mode, in blacklist item will disallow spawn float item + #false = use whitelist mode, in whitelist item will allow spawn float item + list: + - Super Sword(Can't float) + #add keywords in there, plugin will check it contain or not on items. \ No newline at end of file