Revert "Creating command fixes & Armorstand display fixes GH-162 & Configurable per item display & Close GH-312"

This reverts commit 47eb1f63


Former-commit-id: b4062ad676f5aef2849208496bf61bbf2a7fb2af
This commit is contained in:
Ghost_chu committed 2020-01-30 09:57:45 +08:00
1 parent a2c0e499f2
commit 25fcb96e70
8 files changed
+17 -169

No files matched your search

@@ -21,8 +21,6 @@ package org.maxgamer.quickshop.Command.SubCommands;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.BitField;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
@@ -60,7 +60,7 @@ public class ShopDisplayItemSpawnEvent extends QSEvent implements Cancellable {
*/
@Deprecated
public ShopDisplayItemSpawnEvent(@NotNull Shop shop, @NotNull ItemStack itemStack) {
this(shop, itemStack, DisplayItem.getNowUsing(itemStack));
this(shop, itemStack, DisplayItem.getNowUsing());
}
@Override
@@ -40,7 +40,7 @@ public class DisplayBugFixListener implements Listener {
@EventHandler(ignoreCancelled = true)
public void canBuild(BlockCanBuildEvent e) {
if (!plugin.isDisplay()
|| DisplayItem.getNowUsing(null) != DisplayType.ARMORSTAND
|| DisplayItem.getNowUsing() != DisplayType.ARMORSTAND
|| e.isBuildable()) {
return;
}
@@ -109,7 +109,7 @@ public class ContainerShop implements Shop {
this.unlimited = unlimited;
if (plugin.isDisplay()) {
switch (DisplayItem.getNowUsing(this.item)) {
switch (DisplayItem.getNowUsing()) {
case UNKNOWN:
Util.debugLog(
"Failed to create a ContainerShop displayItem, the type is unknown, fallback to RealDisplayItem");
@@ -427,15 +427,6 @@ public class ContainerShop implements Shop {
@Override
public void checkDisplay() {
try {
// Workaround for error tracing when this is executed by tasks
checkDisplay0();
} catch (Throwable t) {
t.printStackTrace();
}
}
public void checkDisplay0() {
if (!plugin.isDisplay() || !this.isLoaded) { // FIXME: Reinit scheduler on reloading config
return;
}
@@ -19,19 +19,10 @@
package org.maxgamer.quickshop.Shop;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@@ -183,138 +174,7 @@ public interface DisplayItem {
*
* @return Using displayType.
*/
static DisplayType getNowUsing(@Nullable ItemStack item) {
if (item != null) {
/*
* The below codes are massy like a shit (but not bad at function), need to cleanup
*
* Nest structure as:
* - 0:
* - small_:
* type: DEBUG_STICK
* lore:
* - mysterious item
* - gift
* strict: true
* - small2:
* type:
* - GLASS
* - GRASS
* - GRASS_BLOCK
* - 3:
* - small:
* type: BOW
* lore: common mark
*/
// type id such as 0, 1, 2, 3.
List<?> typeSections =
QuickShop.instance.getConfig().getList("shop.display-type-specifics");
for (Object typeSection : typeSections) {
// id as key
Util.debugLog(typeSection.toString() + " @ LEVEL 1, " + typeSection.getClass().getName());
if (typeSection instanceof Map) {
Map<?, ?> itemSections = Map.class.cast(typeSection);
for (Entry<?, ?> itemSection : itemSections.entrySet()) {
// list
Util.debugLog(itemSection.toString() + " @ LEVEL 2, " + itemSection.getClass().getName());
if (itemSection.getValue() instanceof List) {
List<?> infoSections = List.class.cast(itemSection.getValue());
for (Object $infoSection : infoSections) {
// custom name as key
Util.debugLog($infoSection.toString() + " @ LEVEL 3, " + $infoSection.getClass().getName());
if ($infoSection instanceof Map) {
for (Object infoSectiont : Map.class.cast($infoSection).values()) {
Map<?, Object> infoSection = Map.class.cast(infoSectiont);
Util.debugLog(infoSection.toString() + " @ LEVEL 4, " + infoSection.getClass().getName());
List<Material> type = Lists.newArrayList();
boolean strictMeta = (boolean) infoSection.getOrDefault("strict-meta", false);
String name = "";
List<String> lore = Lists.newArrayList();
int customModelData = -1;
Object strOrListType = infoSection.getOrDefault("type", Lists.newArrayList());
if (strOrListType instanceof List) {
for (Object s : (List<?>) strOrListType) {
if (s instanceof String) {
type.add(Material.valueOf((String) s));
}
}
} else {
type = Collections.singletonList(Material.valueOf((String) strOrListType));
}
name = (String) infoSection.getOrDefault("name", "");
Object strOrListLore = infoSection.getOrDefault("lore", Lists.newArrayList());
if (strOrListLore instanceof List) {
for (Object s : (List<?>) strOrListLore) {
if (s instanceof String) {
lore.add((String) s);
}
}
} else {
lore = Collections.singletonList((String) strOrListLore);
}
customModelData = (int) infoSection.getOrDefault("custom-model-data", -1);
boolean meta = !name.isEmpty() || !lore.isEmpty() || customModelData != -1;
if (type.isEmpty() || type.contains(item.getType())) {
if (meta) {
if (item.hasItemMeta()) {
ItemMeta itemMeta = item.getItemMeta();
if (!name.isEmpty()) {
if (!(itemMeta.hasDisplayName() && name.equals(itemMeta.getDisplayName()))) {
Util.debugLog("getNowUsing failed in name");
return
DisplayType.fromID(QuickShop.instance.getConfig().getInt("shop.display-type"));
}
}
if (!lore.isEmpty()) {
boolean loreCheck = strictMeta ? lore.equals(itemMeta.getLore()) :
lore.containsAll(itemMeta.getLore());
if (!(itemMeta.hasLore() && loreCheck)) {
Util.debugLog("getNowUsing failed in lore");
return
DisplayType.fromID(QuickShop.instance.getConfig().getInt("shop.display-type"));
}
}
try {
if (customModelData != -1) {
if (!(itemMeta.hasCustomModelData() &&
customModelData == itemMeta.getCustomModelData())) {
Util.debugLog("getNowUsing failed in CMD");
return
DisplayType.fromID(QuickShop.instance.getConfig().getInt("shop.display-type"));
}
}
} catch (Exception e) {
;
}
Util.debugLog("getNowUsing passed thorough meta");
return DisplayType.fromID((Integer) itemSection.getKey());
} else {
;
}
} else {
Util.debugLog("getNowUsing passed without meta");
return DisplayType.fromID((Integer) itemSection.getKey());
}
}
}
}
}
}
}
}
}
}
static DisplayType getNowUsing() {
return DisplayType.fromID(QuickShop.instance.getConfig().getInt("shop.display-type"));
}
@@ -29,12 +29,10 @@ public enum DisplayType {
* ARMORSTAND = USE ARMORSTAND DISPLAY
* VIRTUALITEM = USE VIRTUAL DROPPED ITEM (CLIENT SIDE)
* */
UNKNOWN(-1), // same as 0
UNKNOWN(-1),
REALITEM(0),
ARMORSTAND(1),
VIRTUALITEM(2); // not implement yet
VIRTUALITEM(2);
private int id;
@@ -1111,7 +1111,7 @@ public class ShopManager {
final String message = ChatColor.stripColor(msg);
// Use from the main thread, because Bukkit hates life
Bukkit.getScheduler()
.runTask(
.scheduleSyncDelayedTask(
plugin,
() -> {
HashMap<UUID, Info> actions = getActions();
@@ -161,7 +161,7 @@ public class Util {
return plugin.getOpenInvPlugin() != null;
}
return bs instanceof InventoryHolder;
return bs instanceof BlockInventoryHolder;
}
/**
@@ -243,19 +243,20 @@ public class Util {
for (String log : logs) {
String text =
"["
//+ ChatColor.DARK_GREEN
//+ ChatColor.BOLD
//+ "DEBUG"
//+ ChatColor.RESET
//+ "] ["
+ ChatColor.DARK_GREEN
+ ChatColor.BOLD
+ "DEBUG"
+ ChatColor.RESET
+ "] ["
+ ChatColor.DARK_GREEN
+ className
+ ChatColor.RESET
+ "] ("
/*+ " ["
+ "]"
+ " ["
+ ChatColor.DARK_GREEN
+ methodName
+ ChatColor.RESET*/
+ ChatColor.RESET
+ "] ("
+ ChatColor.DARK_GREEN
+ codeLine
+ ChatColor.RESET