Move guard itemstack method to Interface

Former-commit-id: 090c16292113475f477b22bb5ea1cb49370eb680 [formerly 446b6b29967396c40d79ce9586f270eaa98264b0]
Former-commit-id: fa2e0bd527ab9a88516387d06c88b2e33cd4d6cc
This commit is contained in:
Ghost_chu committed 2019-06-06 15:37:24 +08:00
1 parent 17e0f982b0
commit b0ef67a3ae
4 files changed
+70 -17

No files matched your search

@@ -1,13 +1,11 @@
package org.maxgamer.quickshop.Shop;
import java.util.ArrayList;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.maxgamer.quickshop.QuickShop;
import org.maxgamer.quickshop.Util.Util;
@@ -42,9 +40,8 @@ public class ArmorStandDisplayItem implements DisplayItem {
Util.debugLog("Cancelled the displayItem spawning cause a plugin setCancelled the spawning event, usually is QuickShop Addon");
return;
}
this.armorStand = (ArmorStand) this.shop.getLocation().getWorld().spawnEntity(this.shop
.getLocation(), EntityType.ARMOR_STAND);
this.armorStand = (ArmorStand) this.shop.getLocation().getWorld()
.spawnEntity(getDisplayLocation(), EntityType.ARMOR_STAND);
//Set basic armorstand datas.
this.armorStand.setArms(false);
this.armorStand.setBasePlate(false);
@@ -68,17 +65,7 @@ public class ArmorStandDisplayItem implements DisplayItem {
}
ArmorStand armorStand = (ArmorStand) entity;
//Set item protect in the armorstand's hand
ItemStack itemStack = armorStand.getItemInHand();
ItemMeta iMeta = itemStack.getItemMeta();
if (plugin.getConfig().getBoolean("shop.display-item-use-name")) {
iMeta.setDisplayName("QuickShop");
}
java.util.List<String> lore = new ArrayList<String>();
for (int i = 0; i < 21; i++) {
lore.add("QuickShop DisplayItem"); //Create 20 lines lore to make sure no stupid plugin accident remove mark.
}
iMeta.setLore(lore);
itemStack.setItemMeta(iMeta);
armorStand.setItemInHand(itemStack);
Util.debugLog("Successfully safeGuard ArmorStand: " + armorStand.getLocation().toString());
}
@@ -102,5 +89,12 @@ public class ArmorStandDisplayItem implements DisplayItem {
spawn();
}
public Entity getDisplay() {
return this.armorStand;
}
@Override
public Location getDisplayLocation() {
return this.shop.getLocation().clone().add(0.5, 1.2, 0.5);
}
}
@@ -1,8 +1,12 @@
package org.maxgamer.quickshop.Shop;
import java.util.ArrayList;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.maxgamer.quickshop.QuickShop;
//import org.maxgamer.quickshop.Util.NMS;
/**
@@ -188,4 +192,21 @@ public interface DisplayItem {
// public Item getItem() {
// return this.item;
// }
public static ItemStack createGuardItemStack(ItemStack itemStack) {
itemStack = itemStack.clone();
ItemMeta iMeta = itemStack.getItemMeta();
if (QuickShop.instance.getConfig().getBoolean("shop.display-item-use-name")) {
iMeta.setDisplayName("QuickShop");
}
java.util.List<String> lore = new ArrayList<String>();
for (int i = 0; i < 21; i++) {
lore.add("QuickShop DisplayItem"); //Create 20 lines lore to make sure no stupid plugin accident remove mark.
}
iMeta.setLore(lore);
itemStack.setItemMeta(iMeta);
return itemStack;
}
}
@@ -0,0 +1,35 @@
package org.maxgamer.quickshop.Shop;
public enum DisplayType {
UNKNOWN(-1), REALITEM(0), ARMORSTAND(1), VIRTUALITEM(2);
private int id;
private DisplayType(int id) {
this.id = id;
}
public static DisplayType fromID(int id) {
for (DisplayType type : DisplayType.values()) {
if (type.id == id) {
return type;
}
}
return null;
}
public static int toID(DisplayType displayType) {
return displayType.id;
}
public int toID() {
return id;
}
public static DisplayType typeIs(DisplayItem displayItem) {
if (displayItem instanceof RealDisplayItem)
return REALITEM;
if (displayItem instanceof ArmorStandDisplayItem)
return ARMORSTAND;
return UNKNOWN;
}
}
@@ -261,5 +261,8 @@ public abstract interface Shop {
*/
public abstract ArrayList<UUID> getStaffs();
public static ItemStack createGuardItemStack(ItemStack itemStack) {
}
}