CoreProtect v20.0 release
This commit is contained in:
parent
415d7b323a
commit
48ef18e2c8
173 changed files with 25072 additions and 1 deletions
74
src/main/java/net/coreprotect/utility/Chat.java
Normal file
74
src/main/java/net/coreprotect/utility/Chat.java
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
package net.coreprotect.utility;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.coreprotect.spigot.SpigotAdapter;
|
||||
|
||||
public final class Chat {
|
||||
|
||||
public static final String COMPONENT_TAG_OPEN = "<COMPONENT>";
|
||||
public static final String COMPONENT_TAG_CLOSE = "</COMPONENT>";
|
||||
public static final String COMPONENT_COMMAND = "COMMAND";
|
||||
public static final String COMPONENT_POPUP = "POPUP";
|
||||
|
||||
private Chat() throws RuntimeException {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
public static void sendComponent(CommandSender sender, String string, String bypass) {
|
||||
SpigotAdapter.ADAPTER.sendComponent(sender, string, bypass);
|
||||
}
|
||||
|
||||
public static void sendComponent(CommandSender sender, String string) {
|
||||
sendComponent(sender, string, null);
|
||||
}
|
||||
|
||||
public static void sendMessage(CommandSender sender, String message) {
|
||||
if (sender instanceof ConsoleCommandSender) {
|
||||
message = message.replace(Color.DARK_AQUA, ChatColor.DARK_AQUA.toString());
|
||||
}
|
||||
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
|
||||
public static void sendConsoleMessage(String string) {
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(string);
|
||||
}
|
||||
|
||||
public static void console(String string) {
|
||||
if (string.startsWith("-") || string.startsWith("[")) {
|
||||
Bukkit.getLogger().log(Level.INFO, string);
|
||||
}
|
||||
else {
|
||||
Bukkit.getLogger().log(Level.INFO, "[CoreProtect] " + string);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendGlobalMessage(CommandSender user, String string) {
|
||||
if (user instanceof ConsoleCommandSender) {
|
||||
sendMessage(user, Color.DARK_AQUA + "[CoreProtect] " + Color.WHITE + string);
|
||||
return;
|
||||
}
|
||||
|
||||
Server server = Bukkit.getServer();
|
||||
server.getConsoleSender().sendMessage("[CoreProtect] " + string);
|
||||
for (Player player : server.getOnlinePlayers()) {
|
||||
if (player.isOp() && !player.getName().equals(user.getName())) {
|
||||
sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + string);
|
||||
}
|
||||
}
|
||||
if (user instanceof Player) {
|
||||
if (((Player) user).isOnline()) {
|
||||
sendMessage(user, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
140
src/main/java/net/coreprotect/utility/ChatMessage.java
Normal file
140
src/main/java/net/coreprotect/utility/ChatMessage.java
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
package net.coreprotect.utility;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class ChatMessage {
|
||||
|
||||
/**
|
||||
* Returns the plugin name with the DARK_AQUA chat color.
|
||||
*/
|
||||
final String COREPROTECT = Color.DARK_AQUA + "CoreProtect";
|
||||
|
||||
String message;
|
||||
String textColor = Color.WHITE;
|
||||
String textStyle = new String();
|
||||
String separator = "-";
|
||||
boolean useTag = true;
|
||||
boolean useSpaces = true;
|
||||
|
||||
public ChatMessage() {
|
||||
this.message = new String();
|
||||
}
|
||||
|
||||
public ChatMessage setSeparator(String separator) {
|
||||
this.separator = separator;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ChatMessage setColor(String color) {
|
||||
this.textColor = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ChatMessage setStyle(String style) {
|
||||
this.textStyle = style;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ChatMessage useTag(boolean tag) {
|
||||
this.useTag = tag;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ChatMessage useSpaces(boolean spaces) {
|
||||
this.useSpaces = spaces;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ChatMessage append(String color, String string) {
|
||||
this.message = this.message + color + string;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ChatMessage(String string) {
|
||||
this.message = parseQuotes(string, this.textColor);
|
||||
// this.message = Chat.COREPROTECT + this.textStyle + this.textColor + " - " + string;
|
||||
}
|
||||
|
||||
public String build(boolean tag) {
|
||||
useTag(tag);
|
||||
return build();
|
||||
}
|
||||
|
||||
public String build(String color) {
|
||||
setColor(color);
|
||||
return build();
|
||||
}
|
||||
|
||||
public String build(boolean tag, String color) {
|
||||
useTag(tag);
|
||||
setColor(color);
|
||||
return build();
|
||||
}
|
||||
|
||||
public String build(String color, String style) {
|
||||
setColor(color);
|
||||
setStyle(style);
|
||||
return build();
|
||||
}
|
||||
|
||||
public String build(boolean tag, String color, String style) {
|
||||
useTag(tag);
|
||||
setColor(color);
|
||||
setStyle(style);
|
||||
return build();
|
||||
}
|
||||
|
||||
public String build(String separator, String color, String style) {
|
||||
setSeparator(separator);
|
||||
setColor(color);
|
||||
setStyle(style);
|
||||
return build();
|
||||
}
|
||||
|
||||
public String build(boolean tag, String separator, String color, String style) {
|
||||
useTag(tag);
|
||||
setSeparator(separator);
|
||||
setColor(color);
|
||||
setStyle(style);
|
||||
return build();
|
||||
}
|
||||
|
||||
public static String parseQuotes(String string, String textColor) {
|
||||
int indexFirst = string.indexOf("\"");
|
||||
int indexLast = string.lastIndexOf("\"");
|
||||
if (indexFirst > -1 && indexLast > indexFirst) {
|
||||
String quoteText = string.substring(indexFirst + 1, indexLast);
|
||||
string = string.replace(quoteText, Color.DARK_AQUA + ChatColor.stripColor(quoteText) + textColor);
|
||||
}
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
private static String createSpaces(String string, boolean seperatorOffset, boolean createSpaces) {
|
||||
String result = "";
|
||||
if (!createSpaces) {
|
||||
return result;
|
||||
}
|
||||
|
||||
int count = (string.length() - string.replace(String.valueOf(ChatColor.COLOR_CHAR), "").length()) * 2;
|
||||
int length = (int) ((string.length() - count) * 1.4);
|
||||
if (seperatorOffset) {
|
||||
length += 2;
|
||||
}
|
||||
for (int i = 0; i < length; i++) {
|
||||
result += " ";
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public String build() {
|
||||
return (this.useTag ? COREPROTECT : createSpaces(COREPROTECT, true, this.useSpaces)) + this.textColor + " " + this.separator + " " + this.textStyle + this.message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
}
|
||||
95
src/main/java/net/coreprotect/utility/ChestTool.java
Normal file
95
src/main/java/net/coreprotect/utility/ChestTool.java
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
package net.coreprotect.utility;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Directional;
|
||||
import org.bukkit.block.data.type.Chest;
|
||||
import org.bukkit.inventory.DoubleChestInventory;
|
||||
|
||||
public class ChestTool {
|
||||
|
||||
public static void updateDoubleChest(Block block, BlockData blockData) {
|
||||
try {
|
||||
// modifying existing container, trigger physics update on both sides of double chest
|
||||
if (blockData != null && blockData instanceof Chest) {
|
||||
int chestType = 0;
|
||||
switch (((Chest) blockData).getType()) {
|
||||
case LEFT:
|
||||
chestType = 1;
|
||||
break;
|
||||
case RIGHT:
|
||||
chestType = 2;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (chestType > 0) {
|
||||
// check that not already a double chest
|
||||
BlockState blockState = block.getState();
|
||||
if (blockState instanceof org.bukkit.block.Chest) {
|
||||
org.bukkit.block.Chest chest = (org.bukkit.block.Chest) blockState;
|
||||
if (chest.getInventory() instanceof DoubleChestInventory) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Directional directional = (Directional) blockData;
|
||||
BlockFace blockFace = directional.getFacing();
|
||||
BlockFace newFace = null;
|
||||
if (chestType == 1) {
|
||||
switch (blockFace) {
|
||||
case NORTH:
|
||||
newFace = BlockFace.EAST;
|
||||
break;
|
||||
case WEST:
|
||||
newFace = BlockFace.NORTH;
|
||||
break;
|
||||
case EAST:
|
||||
newFace = BlockFace.SOUTH;
|
||||
break;
|
||||
case SOUTH:
|
||||
newFace = BlockFace.WEST;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (chestType == 2) {
|
||||
switch (blockFace) {
|
||||
case NORTH:
|
||||
newFace = BlockFace.WEST;
|
||||
break;
|
||||
case WEST:
|
||||
newFace = BlockFace.SOUTH;
|
||||
break;
|
||||
case EAST:
|
||||
newFace = BlockFace.NORTH;
|
||||
break;
|
||||
case SOUTH:
|
||||
newFace = BlockFace.EAST;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (newFace != null) {
|
||||
Block relativeBlock = block.getRelative(newFace);
|
||||
String relativeBlockData = relativeBlock.getBlockData().getAsString();
|
||||
String newChestType = (chestType == 1) ? "type=right" : "type=left";
|
||||
relativeBlockData = relativeBlockData.replace("type=single", newChestType);
|
||||
relativeBlock.setBlockData(Bukkit.createBlockData(relativeBlockData), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
121
src/main/java/net/coreprotect/utility/Color.java
Normal file
121
src/main/java/net/coreprotect/utility/Color.java
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
package net.coreprotect.utility;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public final class Color {
|
||||
|
||||
// we define our own constants here to eliminate string concatenation
|
||||
|
||||
// javadoc taken from org.bukkit.ChatColor
|
||||
|
||||
/**
|
||||
* Represents black.
|
||||
*/
|
||||
public static final String BLACK = ChatColor.BLACK.toString();
|
||||
|
||||
/**
|
||||
* Represents dark blue.
|
||||
*/
|
||||
public static final String DARK_BLUE = ChatColor.DARK_BLUE.toString();
|
||||
|
||||
/**
|
||||
* Represents dark green.
|
||||
*/
|
||||
public static final String DARK_GREEN = ChatColor.DARK_GREEN.toString();
|
||||
|
||||
/**
|
||||
* Represents dark blue (aqua).
|
||||
*/
|
||||
public static String DARK_AQUA = ChatColor.DARK_AQUA.toString();
|
||||
|
||||
/**
|
||||
* Represents dark red.
|
||||
*/
|
||||
public static final String DARK_RED = ChatColor.DARK_RED.toString();
|
||||
|
||||
/**
|
||||
* Represents dark purple.
|
||||
*/
|
||||
public static final String DARK_PURPLE = ChatColor.DARK_PURPLE.toString();
|
||||
|
||||
/**
|
||||
* Represents gold.
|
||||
*/
|
||||
public static final String GOLD = ChatColor.GOLD.toString();
|
||||
|
||||
/**
|
||||
* Represents grey.
|
||||
*/
|
||||
public static final String GREY = ChatColor.GRAY.toString();
|
||||
|
||||
/**
|
||||
* Represents dark grey.
|
||||
*/
|
||||
public static final String DARK_GREY = ChatColor.DARK_GRAY.toString();
|
||||
|
||||
/**
|
||||
* Represents blue.
|
||||
*/
|
||||
public static final String BLUE = ChatColor.BLUE.toString();
|
||||
|
||||
/**
|
||||
* Represents green.
|
||||
*/
|
||||
public static final String GREEN = ChatColor.GREEN.toString();
|
||||
|
||||
/**
|
||||
* Represents aqua.
|
||||
*/
|
||||
public static final String AQUA = ChatColor.AQUA.toString();
|
||||
|
||||
/**
|
||||
* Represents red.
|
||||
*/
|
||||
public static final String RED = ChatColor.RED.toString();
|
||||
|
||||
/**
|
||||
* Represents light purple.
|
||||
*/
|
||||
public static final String LIGHT_PURPLE = ChatColor.LIGHT_PURPLE.toString();
|
||||
|
||||
/**
|
||||
* Represents yellow.
|
||||
*/
|
||||
public static final String YELLOW = ChatColor.YELLOW.toString();
|
||||
|
||||
/**
|
||||
* Represents white.
|
||||
*/
|
||||
public static final String WHITE = ChatColor.WHITE.toString();
|
||||
|
||||
/**
|
||||
* Represents magical characters that change around randomly.
|
||||
*/
|
||||
public static final String MAGIC = ChatColor.COLOR_CHAR + "k";
|
||||
|
||||
/**
|
||||
* Makes the text bold.
|
||||
*/
|
||||
public static final String BOLD = ChatColor.COLOR_CHAR + "l";
|
||||
|
||||
/**
|
||||
* Makes a line appear through the text.
|
||||
*/
|
||||
public static final String STRIKETHROUGH = ChatColor.COLOR_CHAR + "m";
|
||||
|
||||
/**
|
||||
* Makes the text appear underlined.
|
||||
*/
|
||||
public static final String UNDERLINE = ChatColor.COLOR_CHAR + "n";
|
||||
|
||||
/**
|
||||
* Makes the text italic.
|
||||
*/
|
||||
public static final String ITALIC = ChatColor.COLOR_CHAR + "o";
|
||||
|
||||
/**
|
||||
* Resets all previous chat colors or formats.
|
||||
*/
|
||||
public static final String RESET = ChatColor.COLOR_CHAR + "r";
|
||||
|
||||
}
|
||||
2139
src/main/java/net/coreprotect/utility/Util.java
Executable file
2139
src/main/java/net/coreprotect/utility/Util.java
Executable file
File diff suppressed because it is too large
Load diff
20
src/main/java/net/coreprotect/utility/Validate.java
Normal file
20
src/main/java/net/coreprotect/utility/Validate.java
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
package net.coreprotect.utility;
|
||||
|
||||
import org.bukkit.block.DoubleChest;
|
||||
import org.bukkit.block.Hopper;
|
||||
import org.bukkit.entity.minecart.HopperMinecart;
|
||||
import org.bukkit.inventory.BlockInventoryHolder;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
public class Validate {
|
||||
|
||||
public static boolean isHopper(InventoryHolder inventoryHolder) {
|
||||
return (inventoryHolder instanceof Hopper || inventoryHolder instanceof HopperMinecart);
|
||||
}
|
||||
|
||||
/* check if valid hopper destination */
|
||||
public static boolean isContainer(InventoryHolder inventoryHolder) {
|
||||
return (inventoryHolder instanceof BlockInventoryHolder || inventoryHolder instanceof DoubleChest);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,282 @@
|
|||
package net.coreprotect.utility.serialize;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.FireworkEffect;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeModifier;
|
||||
import org.bukkit.block.banner.Pattern;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BannerMeta;
|
||||
import org.bukkit.inventory.meta.CrossbowMeta;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.bukkit.inventory.meta.FireworkEffectMeta;
|
||||
import org.bukkit.inventory.meta.FireworkMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
import org.bukkit.inventory.meta.MapMeta;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
import net.coreprotect.bukkit.BukkitAdapter;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class ItemMetaHandler {
|
||||
|
||||
public static String getEnchantmentName(Enchantment enchantment, int level) {
|
||||
String name = enchantment.getKey().getKey();
|
||||
|
||||
switch (name) {
|
||||
case "vanishing_curse":
|
||||
name = "Curse of Vanishing";
|
||||
break;
|
||||
case "binding_curse":
|
||||
name = "Curse of Binding";
|
||||
break;
|
||||
default:
|
||||
name = Util.capitalize(name.replace("_", " "), true);
|
||||
break;
|
||||
}
|
||||
|
||||
if (enchantment.getMaxLevel() > 1) {
|
||||
name = name + " " + getEnchantmentLevel(level);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
private static String getEnchantmentLevel(int level) {
|
||||
switch (level) {
|
||||
case 1:
|
||||
return "I";
|
||||
case 2:
|
||||
return "II";
|
||||
case 3:
|
||||
return "III";
|
||||
case 4:
|
||||
return "IV";
|
||||
case 5:
|
||||
return "V";
|
||||
case 6:
|
||||
return "VI";
|
||||
case 7:
|
||||
return "VII";
|
||||
case 8:
|
||||
return "VIII";
|
||||
case 9:
|
||||
return "IX";
|
||||
case 10:
|
||||
return "X";
|
||||
default:
|
||||
return Integer.toString(level);
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<Enchantment, Integer> getEnchantments(ItemMeta itemMeta) {
|
||||
if (itemMeta == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (itemMeta instanceof EnchantmentStorageMeta) {
|
||||
EnchantmentStorageMeta enchantmentStorageEngine = (EnchantmentStorageMeta) itemMeta;
|
||||
return enchantmentStorageEngine.getStoredEnchants();
|
||||
}
|
||||
|
||||
return itemMeta.getEnchants();
|
||||
}
|
||||
|
||||
public static String getEnchantments(ItemStack item) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
Map<Enchantment, Integer> enchantments = getEnchantments(item.getItemMeta());
|
||||
|
||||
for (Entry<Enchantment, Integer> entry : enchantments.entrySet()) {
|
||||
Enchantment enchantment = entry.getKey();
|
||||
Integer level = entry.getValue();
|
||||
|
||||
if (result.length() > 0) {
|
||||
result.append("\n");
|
||||
}
|
||||
result.append(getEnchantmentName(enchantment, level));
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static List<List<Map<String, Object>>> seralize(ItemStack item, Material type, int slot) {
|
||||
List<List<Map<String, Object>>> metadata = new ArrayList<>();
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
List<Object> modifiers = new ArrayList<>();
|
||||
|
||||
if (item.hasItemMeta() && item.getItemMeta() != null) {
|
||||
ItemMeta itemMeta = item.getItemMeta().clone();
|
||||
|
||||
if (itemMeta.hasAttributeModifiers()) {
|
||||
for (Map.Entry<Attribute, AttributeModifier> entry : itemMeta.getAttributeModifiers().entries()) {
|
||||
Map<Attribute, Map<String, Object>> attributeList = new HashMap<>();
|
||||
Attribute attribute = entry.getKey();
|
||||
AttributeModifier modifier = entry.getValue();
|
||||
|
||||
itemMeta.removeAttributeModifier(attribute, modifier);
|
||||
attributeList.put(attribute, modifier.serialize());
|
||||
modifiers.add(attributeList);
|
||||
}
|
||||
}
|
||||
|
||||
if (itemMeta instanceof LeatherArmorMeta) {
|
||||
LeatherArmorMeta meta = (LeatherArmorMeta) itemMeta;
|
||||
LeatherArmorMeta subMeta = meta.clone();
|
||||
|
||||
meta.setColor(null);
|
||||
list.add(meta.serialize());
|
||||
metadata.add(list);
|
||||
|
||||
list = new ArrayList<>();
|
||||
list.add(subMeta.getColor().serialize());
|
||||
metadata.add(list);
|
||||
}
|
||||
else if (itemMeta instanceof PotionMeta) {
|
||||
PotionMeta meta = (PotionMeta) itemMeta;
|
||||
PotionMeta subMeta = meta.clone();
|
||||
meta.setColor(null);
|
||||
meta.clearCustomEffects();
|
||||
list.add(meta.serialize());
|
||||
|
||||
if (subMeta.hasColor()) {
|
||||
list.add(subMeta.getColor().serialize());
|
||||
}
|
||||
metadata.add(list);
|
||||
|
||||
if (subMeta.hasCustomEffects()) {
|
||||
for (PotionEffect effect : subMeta.getCustomEffects()) {
|
||||
list = new ArrayList<>();
|
||||
list.add(effect.serialize());
|
||||
metadata.add(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (itemMeta instanceof FireworkMeta) {
|
||||
FireworkMeta meta = (FireworkMeta) itemMeta;
|
||||
FireworkMeta subMeta = meta.clone();
|
||||
meta.clearEffects();
|
||||
list.add(meta.serialize());
|
||||
metadata.add(list);
|
||||
|
||||
if (subMeta.hasEffects()) {
|
||||
for (FireworkEffect effect : subMeta.getEffects()) {
|
||||
deserializeFireworkEffect(effect, metadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (itemMeta instanceof FireworkEffectMeta) {
|
||||
FireworkEffectMeta meta = (FireworkEffectMeta) itemMeta;
|
||||
FireworkEffectMeta subMeta = meta.clone();
|
||||
meta.setEffect(null);
|
||||
list.add(meta.serialize());
|
||||
metadata.add(list);
|
||||
|
||||
if (subMeta.hasEffect()) {
|
||||
FireworkEffect effect = subMeta.getEffect();
|
||||
deserializeFireworkEffect(effect, metadata);
|
||||
}
|
||||
}
|
||||
else if (itemMeta instanceof BannerMeta) {
|
||||
BannerMeta meta = (BannerMeta) itemMeta;
|
||||
BannerMeta subMeta = (BannerMeta) meta.clone();
|
||||
meta.setPatterns(new ArrayList<>());
|
||||
list.add(meta.serialize());
|
||||
metadata.add(list);
|
||||
|
||||
for (Pattern pattern : subMeta.getPatterns()) {
|
||||
list = new ArrayList<>();
|
||||
list.add(pattern.serialize());
|
||||
metadata.add(list);
|
||||
}
|
||||
}
|
||||
else if (itemMeta instanceof CrossbowMeta) {
|
||||
CrossbowMeta meta = (CrossbowMeta) itemMeta;
|
||||
CrossbowMeta subMeta = (CrossbowMeta) meta.clone();
|
||||
meta.setChargedProjectiles(null);
|
||||
list.add(meta.serialize());
|
||||
metadata.add(list);
|
||||
|
||||
if (subMeta.hasChargedProjectiles()) {
|
||||
list = new ArrayList<>();
|
||||
|
||||
for (ItemStack chargedProjectile : subMeta.getChargedProjectiles()) {
|
||||
Map<String, Object> itemMap = Util.serializeItemStack(chargedProjectile, slot);
|
||||
if (itemMap.size() > 0) {
|
||||
list.add(itemMap);
|
||||
}
|
||||
}
|
||||
|
||||
metadata.add(list);
|
||||
}
|
||||
}
|
||||
else if (itemMeta instanceof MapMeta) {
|
||||
MapMeta meta = (MapMeta) itemMeta;
|
||||
MapMeta subMeta = meta.clone();
|
||||
meta.setColor(null);
|
||||
list.add(meta.serialize());
|
||||
metadata.add(list);
|
||||
|
||||
if (subMeta.hasColor()) {
|
||||
list = new ArrayList<>();
|
||||
list.add(subMeta.getColor().serialize());
|
||||
metadata.add(list);
|
||||
}
|
||||
}
|
||||
else if (!BukkitAdapter.ADAPTER.getItemMeta(itemMeta, list, metadata, slot)) {
|
||||
list.add(itemMeta.serialize());
|
||||
metadata.add(list);
|
||||
}
|
||||
}
|
||||
|
||||
if (type != null && type.equals(Material.ARMOR_STAND)) {
|
||||
Map<String, Object> meta = new HashMap<>();
|
||||
meta.put("slot", slot);
|
||||
list = new ArrayList<>();
|
||||
list.add(meta);
|
||||
metadata.add(list);
|
||||
}
|
||||
|
||||
if (modifiers.size() > 0) {
|
||||
Map<String, Object> meta = new HashMap<>();
|
||||
meta.put("modifiers", modifiers);
|
||||
list = new ArrayList<>();
|
||||
list.add(meta);
|
||||
metadata.add(list);
|
||||
}
|
||||
|
||||
return metadata;
|
||||
}
|
||||
|
||||
private static void deserializeFireworkEffect(FireworkEffect effect, List<List<Map<String, Object>>> metadata) {
|
||||
List<Map<String, Object>> colorList = new ArrayList<>();
|
||||
List<Map<String, Object>> fadeList = new ArrayList<>();
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
|
||||
for (Color color : effect.getColors()) {
|
||||
colorList.add(color.serialize());
|
||||
}
|
||||
|
||||
for (Color color : effect.getFadeColors()) {
|
||||
fadeList.add(color.serialize());
|
||||
}
|
||||
|
||||
Map<String, Object> hasCheck = new HashMap<>();
|
||||
hasCheck.put("flicker", effect.hasFlicker());
|
||||
hasCheck.put("trail", effect.hasTrail());
|
||||
list.add(hasCheck);
|
||||
metadata.add(list);
|
||||
metadata.add(colorList);
|
||||
metadata.add(fadeList);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue