IDEA Auto Inspect

This commit is contained in:
Izzel_Aliz 2018-03-24 23:18:11 +08:00
parent 848b91f2e7
commit d4910db108
139 changed files with 1714 additions and 1814 deletions

9
.idea/compiler.xml Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel>
<module name="TabooLib_main" target="1.8" />
<module name="TabooLib_test" target="1.8" />
</bytecodeTargetLevel>
</component>
</project>

19
.idea/gradle.xml Normal file
View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="C:/gradle-4.3.1" />
<option name="gradleJvm" value="1.8" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
<option name="useAutoImport" value="true" />
</GradleProjectSettings>
</option>
</component>
</project>

View File

@ -0,0 +1,36 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="JavaDoc" enabled="true" level="WARNING" enabled_by_default="true">
<option name="TOP_LEVEL_CLASS_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="INNER_CLASS_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="METHOD_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="@return@param@throws or @exception" />
</value>
</option>
<option name="FIELD_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="IGNORE_DEPRECATED" value="false" />
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
<option name="IGNORE_POINT_TO_ITSELF" value="false" />
<option name="myAdditionalJavadocTags" value="author,author" />
</inspection_tool>
</profile>
</component>

View File

@ -0,0 +1,148 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="TabooLib:main" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="" external.system.module.type="sourceSet" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>SPIGOT</platformType>
</autoDetectTypes>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/../../out/production/classes" />
<exclude-output />
<content url="file://$MODULE_DIR$/../../src/main">
<sourceFolder url="file://$MODULE_DIR$/../../src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/../../src/main/resources" type="java-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../libs/1_10_R1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../libs/1_11_R1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../libs/1_12_R1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../libs/1_8_R3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../libs/1_9_R3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../libs/com.sun.tools.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../libs/lombok.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../libs/PlaceholderAPI.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../libs/ProtocolLib.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../libs/Skript.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../libs/TabooCode5.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../libs/Vault.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../libs/WorldGuard.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../libs/Yum.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>

View File

@ -0,0 +1,150 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="TabooLib:test" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="" external.system.module.type="sourceSet" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>SPIGOT</platformType>
</autoDetectTypes>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output-test url="file://$MODULE_DIR$/../../out/test/classes" />
<exclude-output />
<content url="file://$MODULE_DIR$/../../src/test">
<sourceFolder url="file://$MODULE_DIR$/../../src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/../../src/test/resources" type="java-test-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="TabooLib_main" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../libs/1_10_R1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../libs/1_11_R1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../libs/1_12_R1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../libs/1_8_R3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../libs/1_9_R3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../libs/com.sun.tools.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../libs/lombok.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../libs/PlaceholderAPI.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../libs/ProtocolLib.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../libs/Skript.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../libs/TabooCode5.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../libs/Vault.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../libs/WorldGuard.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../libs/Yum.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
<component name="TestModuleProperties" production-module="TabooLib_main" />
</module>

7
.idea/vcs.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -1,5 +1,6 @@
#Sat Mar 24 22:41:19 CST 2018
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.5-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-4.5-all.zip

View File

@ -1,15 +1,5 @@
package me.skymc.taboolib; package me.skymc.taboolib;
import java.io.File;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import me.skymc.taboolib.anvil.AnvilContainerAPI; import me.skymc.taboolib.anvil.AnvilContainerAPI;
@ -19,22 +9,22 @@ import me.skymc.taboolib.commands.MainCommands;
import me.skymc.taboolib.commands.language.Language2Command; import me.skymc.taboolib.commands.language.Language2Command;
import me.skymc.taboolib.commands.sub.itemlist.listener.ItemLibraryPatch; import me.skymc.taboolib.commands.sub.itemlist.listener.ItemLibraryPatch;
import me.skymc.taboolib.commands.sub.sounds.listener.SoundsLibraryPatch; import me.skymc.taboolib.commands.sub.sounds.listener.SoundsLibraryPatch;
import me.skymc.taboolib.database.PlayerDataManager;
import me.skymc.taboolib.database.GlobalDataManager; import me.skymc.taboolib.database.GlobalDataManager;
import me.skymc.taboolib.database.PlayerDataManager;
import me.skymc.taboolib.economy.EcoUtils; import me.skymc.taboolib.economy.EcoUtils;
import me.skymc.taboolib.entity.EntityUtils; import me.skymc.taboolib.entity.EntityUtils;
import me.skymc.taboolib.fileutils.ConfigUtils; import me.skymc.taboolib.fileutils.ConfigUtils;
import me.skymc.taboolib.inventory.ItemUtils; import me.skymc.taboolib.inventory.ItemUtils;
import me.skymc.taboolib.inventory.speciaitem.SpecialItem; import me.skymc.taboolib.inventory.speciaitem.SpecialItem;
import me.skymc.taboolib.javashell.JavaShell; import me.skymc.taboolib.javashell.JavaShell;
import me.skymc.taboolib.listener.ListenerNetWork; import me.skymc.taboolib.listener.*;
import me.skymc.taboolib.listener.ListenerPlayerCommand;
import me.skymc.taboolib.listener.ListenerPlayerQuit;
import me.skymc.taboolib.listener.ListenerPlayerJump;
import me.skymc.taboolib.listener.ListenerPluginDisable;
import me.skymc.taboolib.message.ChatCatcher; import me.skymc.taboolib.message.ChatCatcher;
import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.mysql.protect.MySQLConnection; import me.skymc.taboolib.mysql.protect.MySQLConnection;
import me.skymc.taboolib.nms.item.DabItemUtils;
import me.skymc.taboolib.other.NumberUtils;
import me.skymc.taboolib.permission.PermissionUtils;
import me.skymc.taboolib.playerdata.DataUtils;
import me.skymc.taboolib.sign.SignUtils; import me.skymc.taboolib.sign.SignUtils;
import me.skymc.taboolib.skript.SkriptHandler; import me.skymc.taboolib.skript.SkriptHandler;
import me.skymc.taboolib.string.StringUtils; import me.skymc.taboolib.string.StringUtils;
@ -46,11 +36,16 @@ import me.skymc.taboolib.update.UpdateTask;
import me.skymc.tlm.TLM; import me.skymc.tlm.TLM;
import me.skymc.tlm.command.TLMCommands; import me.skymc.tlm.command.TLMCommands;
import me.skymc.tlm.module.TabooLibraryModule; import me.skymc.tlm.module.TabooLibraryModule;
import me.skymc.taboolib.nms.item.DabItemUtils;
import me.skymc.taboolib.other.NumberUtils;
import me.skymc.taboolib.permission.PermissionUtils;
import me.skymc.taboolib.playerdata.DataUtils;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import java.io.File;
import java.util.Random;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class Main extends JavaPlugin implements Listener { public class Main extends JavaPlugin implements Listener {
@ -199,7 +194,7 @@ public class Main extends JavaPlugin implements Listener {
MsgUtils.send("§7游戏版本: §f" + TabooLib.getVerint()); MsgUtils.send("§7游戏版本: §f" + TabooLib.getVerint());
// 文件保存 // 文件保存
Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> DataUtils.saveAllCaches(), 20, 20 * 120); Bukkit.getScheduler().runTaskTimerAsynchronously(this, DataUtils::saveAllCaches, 20, 20 * 120);
Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> PlayerDataManager.saveAllCaches(true, false), 20, 20 * 60); Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> PlayerDataManager.saveAllCaches(true, false), 20, 20 * 60);
// 插件联动 // 插件联动
@ -322,7 +317,7 @@ public class Main extends JavaPlugin implements Listener {
} }
} }
public static enum StorageType { public enum StorageType {
LOCAL, SQL; LOCAL, SQL
} }
} }

View File

@ -1,13 +1,11 @@
package me.skymc.taboolib; package me.skymc.taboolib;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import me.skymc.taboolib.playerdata.DataUtils; import me.skymc.taboolib.playerdata.DataUtils;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import java.util.UUID;
public class TabooLib { public class TabooLib {

View File

@ -1,9 +1,6 @@
package me.skymc.taboolib.anvil; package me.skymc.taboolib.anvil;
import java.util.ArrayList; import me.skymc.taboolib.anvil.versions.AnvilContainer_V1_9_4;
import java.util.HashMap;
import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
@ -18,8 +15,9 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import me.skymc.taboolib.anvil.versions.AnvilContainer_V1_9_4; import java.util.ArrayList;
import me.skymc.taboolib.methods.MethodsUtils; import java.util.HashMap;
import java.util.List;
public class AnvilContainerAPI implements Listener{ public class AnvilContainerAPI implements Listener{

View File

@ -1,16 +1,9 @@
package me.skymc.taboolib.anvil.versions; package me.skymc.taboolib.anvil.versions;
import net.minecraft.server.v1_11_R1.*;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import me.skymc.taboolib.methods.MethodsUtils;
import net.minecraft.server.v1_11_R1.BlockPosition;
import net.minecraft.server.v1_11_R1.ChatMessage;
import net.minecraft.server.v1_11_R1.ContainerAnvil;
import net.minecraft.server.v1_11_R1.EntityHuman;
import net.minecraft.server.v1_11_R1.EntityPlayer;
import net.minecraft.server.v1_11_R1.PacketPlayOutOpenWindow;
public class AnvilContainer_V1_11_R1 extends ContainerAnvil { public class AnvilContainer_V1_11_R1 extends ContainerAnvil {
public AnvilContainer_V1_11_R1(EntityHuman player) public AnvilContainer_V1_11_R1(EntityHuman player)
@ -31,7 +24,7 @@ public class AnvilContainer_V1_11_R1 extends ContainerAnvil {
EntityPlayer player = ((CraftPlayer)p).getHandle(); EntityPlayer player = ((CraftPlayer)p).getHandle();
AnvilContainer_V1_11_R1 container = new AnvilContainer_V1_11_R1(player); AnvilContainer_V1_11_R1 container = new AnvilContainer_V1_11_R1(player);
int c = player.nextContainerCounter(); int c = player.nextContainerCounter();
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(c, "minecraft:anvil", new ChatMessage("Repairing", new Object[0]), 0)); player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(c, "minecraft:anvil", new ChatMessage("Repairing"), 0));
player.activeContainer = container; player.activeContainer = container;
player.activeContainer.windowId = c; player.activeContainer.windowId = c;
player.activeContainer.addSlotListener(player); player.activeContainer.addSlotListener(player);

View File

@ -1,16 +1,9 @@
package me.skymc.taboolib.anvil.versions; package me.skymc.taboolib.anvil.versions;
import net.minecraft.server.v1_8_R3.*;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import me.skymc.taboolib.methods.MethodsUtils;
import net.minecraft.server.v1_8_R3.BlockPosition;
import net.minecraft.server.v1_8_R3.ChatMessage;
import net.minecraft.server.v1_8_R3.ContainerAnvil;
import net.minecraft.server.v1_8_R3.EntityHuman;
import net.minecraft.server.v1_8_R3.EntityPlayer;
import net.minecraft.server.v1_8_R3.PacketPlayOutOpenWindow;
public class AnvilContainer_V1_8_R3 extends ContainerAnvil { public class AnvilContainer_V1_8_R3 extends ContainerAnvil {
public AnvilContainer_V1_8_R3(EntityHuman player) public AnvilContainer_V1_8_R3(EntityHuman player)
@ -31,7 +24,7 @@ public class AnvilContainer_V1_8_R3 extends ContainerAnvil {
EntityPlayer player = ((CraftPlayer)p).getHandle(); EntityPlayer player = ((CraftPlayer)p).getHandle();
AnvilContainer_V1_8_R3 container = new AnvilContainer_V1_8_R3(player); AnvilContainer_V1_8_R3 container = new AnvilContainer_V1_8_R3(player);
int c = player.nextContainerCounter(); int c = player.nextContainerCounter();
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(c, "minecraft:anvil", new ChatMessage("Repairing", new Object[0]), 0)); player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(c, "minecraft:anvil", new ChatMessage("Repairing"), 0));
player.activeContainer = container; player.activeContainer = container;
player.activeContainer.windowId = c; player.activeContainer.windowId = c;
player.activeContainer.addSlotListener(player); player.activeContainer.addSlotListener(player);

View File

@ -1,16 +1,9 @@
package me.skymc.taboolib.anvil.versions; package me.skymc.taboolib.anvil.versions;
import net.minecraft.server.v1_9_R2.*;
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import me.skymc.taboolib.methods.MethodsUtils;
import net.minecraft.server.v1_9_R2.BlockPosition;
import net.minecraft.server.v1_9_R2.ChatMessage;
import net.minecraft.server.v1_9_R2.ContainerAnvil;
import net.minecraft.server.v1_9_R2.EntityHuman;
import net.minecraft.server.v1_9_R2.EntityPlayer;
import net.minecraft.server.v1_9_R2.PacketPlayOutOpenWindow;
public class AnvilContainer_V1_9_4 extends ContainerAnvil { public class AnvilContainer_V1_9_4 extends ContainerAnvil {
public AnvilContainer_V1_9_4(EntityHuman player) public AnvilContainer_V1_9_4(EntityHuman player)
@ -31,7 +24,7 @@ public class AnvilContainer_V1_9_4 extends ContainerAnvil {
EntityPlayer player = ((CraftPlayer)p).getHandle(); EntityPlayer player = ((CraftPlayer)p).getHandle();
AnvilContainer_V1_9_4 container = new AnvilContainer_V1_9_4(player); AnvilContainer_V1_9_4 container = new AnvilContainer_V1_9_4(player);
int c = player.nextContainerCounter(); int c = player.nextContainerCounter();
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(c, "minecraft:anvil", new ChatMessage("Repairing", new Object[0]), 0)); player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(c, "minecraft:anvil", new ChatMessage("Repairing"), 0));
player.activeContainer = container; player.activeContainer = container;
player.activeContainer.windowId = c; player.activeContainer.windowId = c;
player.activeContainer.addSlotListener(player); player.activeContainer.addSlotListener(player);

View File

@ -17,13 +17,7 @@ import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.*;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
@ -153,12 +147,7 @@ public class Metrics {
} }
// Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler // Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler
// Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;) // Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
Bukkit.getScheduler().runTask(plugin, new Runnable() { Bukkit.getScheduler().runTask(plugin, () -> submitData());
@Override
public void run() {
submitData();
}
});
} }
}, 1000*60*5, 1000*60*30); }, 1000*60*5, 1000*60*30);
// Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start // Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
@ -263,9 +252,7 @@ public class Metrics {
data.put("plugins", pluginData); data.put("plugins", pluginData);
// Create a new thread for the connection to the bStats server // Create a new thread for the connection to the bStats server
new Thread(new Runnable() { new Thread(() -> {
@Override
public void run() {
try { try {
// Send the data // Send the data
sendData(data); sendData(data);
@ -275,7 +262,6 @@ public class Metrics {
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e); plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
} }
} }
}
}).start(); }).start();
} }

View File

@ -1,38 +1,15 @@
package me.skymc.taboolib.commands; package me.skymc.taboolib.commands;
import java.util.HashMap; import me.skymc.taboolib.commands.sub.*;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.commands.sub.AttributesCommand;
import me.skymc.taboolib.commands.sub.EnchantCommand;
import me.skymc.taboolib.commands.sub.FlagCommand;
import me.skymc.taboolib.commands.sub.HelpCommand;
import me.skymc.taboolib.commands.sub.ImportCommand;
import me.skymc.taboolib.commands.sub.InfoCommand;
import me.skymc.taboolib.commands.sub.ItemCommand;
import me.skymc.taboolib.commands.sub.PotionCommand;
import me.skymc.taboolib.commands.sub.SaveCommand;
import me.skymc.taboolib.commands.sub.SlotCommand;
import me.skymc.taboolib.commands.sub.TagDeleteCommand;
import me.skymc.taboolib.commands.sub.TagPrefixCommand;
import me.skymc.taboolib.commands.sub.TagSuffixCommand;
import me.skymc.taboolib.commands.sub.VariableGetCommand;
import me.skymc.taboolib.commands.sub.VariableSetCommand;
import me.skymc.taboolib.commands.sub.cycle.CycleCommand; import me.skymc.taboolib.commands.sub.cycle.CycleCommand;
import me.skymc.taboolib.commands.sub.itemlist.ItemListCommand; import me.skymc.taboolib.commands.sub.itemlist.ItemListCommand;
import me.skymc.taboolib.commands.sub.shell.ShellCommand; import me.skymc.taboolib.commands.sub.shell.ShellCommand;
import me.skymc.taboolib.commands.sub.sounds.SoundsCommand; import me.skymc.taboolib.commands.sub.sounds.SoundsCommand;
import me.skymc.taboolib.inventory.ItemUtils; import me.skymc.taboolib.inventory.ItemUtils;
import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.message.MsgUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class MainCommands implements CommandExecutor{ public class MainCommands implements CommandExecutor{

View File

@ -28,7 +28,7 @@ public abstract class SubCommand {
} }
public String getArgs(int size) { public String getArgs(int size) {
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
for (int i = size ; i < args.length ; i++) { for (int i = size ; i < args.length ; i++) {
sb.append(args[i]); sb.append(args[i]);
sb.append(" "); sb.append(" ");

View File

@ -3,8 +3,8 @@ package me.skymc.taboolib.commands;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@Deprecated @Deprecated
public abstract interface SubCommandExecutor { public interface SubCommandExecutor {
public abstract boolean command(CommandSender sender, String[] args); boolean command(CommandSender sender, String[] args);
} }

View File

@ -1,13 +1,11 @@
package me.skymc.taboolib.commands.sub; package me.skymc.taboolib.commands.sub;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.commands.SubCommand;
import me.skymc.taboolib.jsonformatter.JSONFormatter; import me.skymc.taboolib.jsonformatter.JSONFormatter;
import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent; import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent;
import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent; import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class AttributesCommand extends SubCommand { public class AttributesCommand extends SubCommand {

View File

@ -1,19 +1,17 @@
package me.skymc.taboolib.commands.sub; package me.skymc.taboolib.commands.sub;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import me.skymc.taboolib.TabooLib; import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.commands.SubCommand;
import me.skymc.taboolib.jsonformatter.JSONFormatter; import me.skymc.taboolib.jsonformatter.JSONFormatter;
import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent; import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent;
import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent; import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
public class HelpCommand extends SubCommand { public class HelpCommand extends SubCommand {

View File

@ -1,11 +1,5 @@
package me.skymc.taboolib.commands.sub; package me.skymc.taboolib.commands.sub;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.commands.SubCommand;
import me.skymc.taboolib.inventory.ItemUtils; import me.skymc.taboolib.inventory.ItemUtils;
import me.skymc.taboolib.itemnbtapi.NBTItem; import me.skymc.taboolib.itemnbtapi.NBTItem;
@ -14,6 +8,9 @@ import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent;
import me.skymc.taboolib.jsonformatter.hover.ShowItemEvent; import me.skymc.taboolib.jsonformatter.hover.ShowItemEvent;
import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent; import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent;
import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.message.MsgUtils;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class InfoCommand extends SubCommand { public class InfoCommand extends SubCommand {

View File

@ -1,13 +1,11 @@
package me.skymc.taboolib.commands.sub; package me.skymc.taboolib.commands.sub;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.commands.SubCommand;
import me.skymc.taboolib.jsonformatter.JSONFormatter; import me.skymc.taboolib.jsonformatter.JSONFormatter;
import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent; import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent;
import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent; import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class SlotCommand extends SubCommand { public class SlotCommand extends SubCommand {

View File

@ -1,13 +1,11 @@
package me.skymc.taboolib.commands.sub; package me.skymc.taboolib.commands.sub;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import me.clip.placeholderapi.PlaceholderAPI;
import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.commands.SubCommand;
import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.team.TagManager; import me.skymc.taboolib.team.TagManager;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/** /**
* @author sky * @author sky

View File

@ -1,12 +1,8 @@
package me.skymc.taboolib.commands.sub.cycle; package me.skymc.taboolib.commands.sub.cycle;
import java.io.File;
import org.bukkit.command.CommandSender;
import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.commands.SubCommand;
import me.skymc.taboolib.javashell.JavaShell;
import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.message.MsgUtils;
import org.bukkit.command.CommandSender;
public class CycleCommand extends SubCommand { public class CycleCommand extends SubCommand {

View File

@ -1,20 +1,13 @@
package me.skymc.taboolib.commands.sub.cycle; package me.skymc.taboolib.commands.sub.cycle;
import java.util.concurrent.TimeUnit;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitRunnable;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.commands.SubCommand;
import me.skymc.taboolib.database.GlobalDataManager;
import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.other.DateUtils; import me.skymc.taboolib.other.DateUtils;
import me.skymc.taboolib.timecycle.TimeCycle; import me.skymc.taboolib.timecycle.TimeCycle;
import me.skymc.taboolib.timecycle.TimeCycleEvent;
import me.skymc.taboolib.timecycle.TimeCycleInitializeEvent;
import me.skymc.taboolib.timecycle.TimeCycleManager; import me.skymc.taboolib.timecycle.TimeCycleManager;
import org.bukkit.command.CommandSender;
import java.util.concurrent.TimeUnit;
public class CycleInfoCommand extends SubCommand { public class CycleInfoCommand extends SubCommand {

View File

@ -1,19 +1,13 @@
package me.skymc.taboolib.commands.sub.cycle; package me.skymc.taboolib.commands.sub.cycle;
import java.io.File;
import java.util.concurrent.TimeUnit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.commands.SubCommand;
import me.skymc.taboolib.javashell.JavaShell;
import me.skymc.taboolib.jsonformatter.JSONFormatter; import me.skymc.taboolib.jsonformatter.JSONFormatter;
import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent; import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent;
import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent; import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent;
import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.timecycle.TimeCycle; import me.skymc.taboolib.timecycle.TimeCycle;
import me.skymc.taboolib.timecycle.TimeCycleManager; import me.skymc.taboolib.timecycle.TimeCycleManager;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class CycleListCommand extends SubCommand { public class CycleListCommand extends SubCommand {

View File

@ -1,17 +1,15 @@
package me.skymc.taboolib.commands.sub.cycle; package me.skymc.taboolib.commands.sub.cycle;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitRunnable;
import me.skymc.taboolib.Main; import me.skymc.taboolib.Main;
import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.commands.SubCommand;
import me.skymc.taboolib.database.GlobalDataManager; import me.skymc.taboolib.database.GlobalDataManager;
import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.timecycle.TimeCycle; import me.skymc.taboolib.timecycle.TimeCycle;
import me.skymc.taboolib.timecycle.TimeCycleEvent; import me.skymc.taboolib.timecycle.TimeCycleEvent;
import me.skymc.taboolib.timecycle.TimeCycleInitializeEvent;
import me.skymc.taboolib.timecycle.TimeCycleManager; import me.skymc.taboolib.timecycle.TimeCycleManager;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitRunnable;
public class CycleUpdateCommand extends SubCommand { public class CycleUpdateCommand extends SubCommand {

View File

@ -1,11 +1,7 @@
package me.skymc.taboolib.commands.sub.itemlist.listener; package me.skymc.taboolib.commands.sub.itemlist.listener;
import java.util.ArrayList; import me.skymc.taboolib.inventory.InventoryUtil;
import java.util.HashMap; import me.skymc.taboolib.inventory.ItemUtils;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -17,8 +13,10 @@ import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import me.skymc.taboolib.inventory.InventoryUtil; import java.util.ArrayList;
import me.skymc.taboolib.inventory.ItemUtils; import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
/** /**
* @author sky * @author sky
@ -26,27 +24,6 @@ import me.skymc.taboolib.inventory.ItemUtils;
*/ */
public class ItemLibraryPatch implements Listener { public class ItemLibraryPatch implements Listener {
@EventHandler
public void inventoryClick(InventoryClickEvent e) {
if (e.getInventory().getHolder() instanceof ItemLibraryHolder) {
e.setCancelled(true);
if (e.getCurrentItem() == null || e.getCurrentItem().getType().equals(Material.AIR) || e.getRawSlot() >= e.getInventory().getSize()) {
return;
}
if (e.getRawSlot() == 47) {
openInventory((Player) e.getWhoClicked(), ((ItemLibraryHolder) e.getInventory().getHolder()).PAGE - 1);
}
else if (e.getRawSlot() == 51) {
openInventory((Player) e.getWhoClicked(), ((ItemLibraryHolder) e.getInventory().getHolder()).PAGE + 1);
}
else {
e.getWhoClicked().getInventory().addItem(ItemUtils.getCacheItem(((ItemLibraryHolder) e.getInventory().getHolder()).ITEMS_DATA.get(e.getRawSlot())));
}
}
}
/** /**
* 打开物品库界面 * 打开物品库界面
* *
@ -62,13 +39,12 @@ public class ItemLibraryPatch implements Listener {
map.putAll(ItemUtils.getItemCaches()); map.putAll(ItemUtils.getItemCaches());
int loop = 0; int loop = 0;
Iterator<String> iterator = map.keySet().iterator(); for (String name : map.keySet()) {
while (iterator.hasNext()) {
String name = iterator.next();
if (loop >= (page - 1) * 28) { if (loop >= (page - 1) * 28) {
if (loop < page * 28) { if (loop < page * 28) {
int slot = InventoryUtil.SLOT_OF_CENTENTS.get(loop - ((page - 1) * 28)); int slot = InventoryUtil.SLOT_OF_CENTENTS.get(loop - ((page - 1) * 28));
ItemStack item = map.get(name).clone(); { ItemStack item = map.get(name).clone();
{
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<>(); List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<>();
lore.add("§f"); lore.add("§f");
@ -79,8 +55,7 @@ public class ItemLibraryPatch implements Listener {
inventory.setItem(slot, item); inventory.setItem(slot, item);
} }
holder.ITEMS_DATA.put(slot, name); holder.ITEMS_DATA.put(slot, name);
} } else {
else {
break; break;
} }
} }
@ -96,6 +71,29 @@ public class ItemLibraryPatch implements Listener {
player.openInventory(inventory); player.openInventory(inventory);
} }
@EventHandler
public void inventoryClick(InventoryClickEvent e) {
if (e.getInventory().getHolder() instanceof ItemLibraryHolder) {
e.setCancelled(true);
if (e.getCurrentItem() == null || e.getCurrentItem().getType().equals(Material.AIR) || e.getRawSlot() >= e.getInventory().getSize()) {
return;
}
switch (e.getRawSlot()) {
case 47:
openInventory((Player) e.getWhoClicked(), ((ItemLibraryHolder) e.getInventory().getHolder()).PAGE - 1);
break;
case 51:
openInventory((Player) e.getWhoClicked(), ((ItemLibraryHolder) e.getInventory().getHolder()).PAGE + 1);
break;
default:
e.getWhoClicked().getInventory().addItem(ItemUtils.getCacheItem(((ItemLibraryHolder) e.getInventory().getHolder()).ITEMS_DATA.get(e.getRawSlot())));
break;
}
}
}
public static class ItemLibraryHolder implements InventoryHolder { public static class ItemLibraryHolder implements InventoryHolder {
public final int PAGE; public final int PAGE;

View File

@ -1,12 +1,8 @@
package me.skymc.taboolib.commands.sub.shell; package me.skymc.taboolib.commands.sub.shell;
import java.io.File;
import org.bukkit.command.CommandSender;
import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.commands.SubCommand;
import me.skymc.taboolib.javashell.JavaShell;
import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.message.MsgUtils;
import org.bukkit.command.CommandSender;
public class ShellCommand extends SubCommand { public class ShellCommand extends SubCommand {

View File

@ -1,12 +1,7 @@
package me.skymc.taboolib.commands.sub.sounds.listener; package me.skymc.taboolib.commands.sub.sounds.listener;
import java.util.ArrayList; import me.skymc.taboolib.inventory.InventoryUtil;
import java.util.Arrays; import me.skymc.taboolib.inventory.ItemUtils;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
@ -19,8 +14,8 @@ import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import me.skymc.taboolib.inventory.InventoryUtil; import java.util.Arrays;
import me.skymc.taboolib.inventory.ItemUtils; import java.util.HashMap;
/** /**
* @author sky * @author sky
@ -28,33 +23,6 @@ import me.skymc.taboolib.inventory.ItemUtils;
*/ */
public class SoundsLibraryPatch implements Listener { public class SoundsLibraryPatch implements Listener {
@EventHandler
public void inventoryClick(InventoryClickEvent e) {
if (e.getInventory().getHolder() instanceof SoundLibraryHolder) {
e.setCancelled(true);
if (e.getCurrentItem() == null || e.getCurrentItem().getType().equals(Material.AIR) || e.getRawSlot() >= e.getInventory().getSize()) {
return;
}
if (e.getRawSlot() == 47) {
openInventory((Player) e.getWhoClicked(), ((SoundLibraryHolder) e.getInventory().getHolder()).PAGE - 1);
}
else if (e.getRawSlot() == 51) {
openInventory((Player) e.getWhoClicked(), ((SoundLibraryHolder) e.getInventory().getHolder()).PAGE + 1);
}
else {
Sound sound = ((SoundLibraryHolder) e.getInventory().getHolder()).SOUNDS_DATA.get(e.getRawSlot());
if (e.getClick().isLeftClick()) {
((Player) e.getWhoClicked()).playSound(e.getWhoClicked().getLocation(), sound, 1f, 1f);
}
else {
((Player) e.getWhoClicked()).playSound(e.getWhoClicked().getLocation(), sound, 1f, 2f);
}
}
}
}
/** /**
* 打开物品库界面 * 打开物品库界面
* *
@ -66,13 +34,12 @@ public class SoundsLibraryPatch implements Listener {
Inventory inventory = Bukkit.createInventory(holder, 54, "音效库 " + page); Inventory inventory = Bukkit.createInventory(holder, 54, "音效库 " + page);
int loop = 0; int loop = 0;
Iterator<Sound> iterator = Arrays.asList(Sound.values()).iterator(); for (Sound sound : Arrays.asList(Sound.values())) {
while (iterator.hasNext()) {
Sound sound = iterator.next();
if (loop >= (page - 1) * 28) { if (loop >= (page - 1) * 28) {
if (loop < page * 28) { if (loop < page * 28) {
int slot = InventoryUtil.SLOT_OF_CENTENTS.get(loop - ((page - 1) * 28)); int slot = InventoryUtil.SLOT_OF_CENTENTS.get(loop - ((page - 1) * 28));
ItemStack item = new ItemStack(Material.MAP); { ItemStack item = new ItemStack(Material.MAP);
{
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§f" + sound.name()); meta.setDisplayName("§f" + sound.name());
meta.setLore(Arrays.asList("", "§f左键: §71 音调", "§f左键: §72 音调")); meta.setLore(Arrays.asList("", "§f左键: §71 音调", "§f左键: §72 音调"));
@ -80,8 +47,7 @@ public class SoundsLibraryPatch implements Listener {
inventory.setItem(slot, item); inventory.setItem(slot, item);
} }
holder.SOUNDS_DATA.put(slot, sound); holder.SOUNDS_DATA.put(slot, sound);
} } else {
else {
break; break;
} }
} }
@ -97,6 +63,34 @@ public class SoundsLibraryPatch implements Listener {
player.openInventory(inventory); player.openInventory(inventory);
} }
@EventHandler
public void inventoryClick(InventoryClickEvent e) {
if (e.getInventory().getHolder() instanceof SoundLibraryHolder) {
e.setCancelled(true);
if (e.getCurrentItem() == null || e.getCurrentItem().getType().equals(Material.AIR) || e.getRawSlot() >= e.getInventory().getSize()) {
return;
}
switch (e.getRawSlot()) {
case 47:
openInventory((Player) e.getWhoClicked(), ((SoundLibraryHolder) e.getInventory().getHolder()).PAGE - 1);
break;
case 51:
openInventory((Player) e.getWhoClicked(), ((SoundLibraryHolder) e.getInventory().getHolder()).PAGE + 1);
break;
default:
Sound sound = ((SoundLibraryHolder) e.getInventory().getHolder()).SOUNDS_DATA.get(e.getRawSlot());
if (e.getClick().isLeftClick()) {
((Player) e.getWhoClicked()).playSound(e.getWhoClicked().getLocation(), sound, 1f, 1f);
} else {
((Player) e.getWhoClicked()).playSound(e.getWhoClicked().getLocation(), sound, 1f, 2f);
}
break;
}
}
}
public static class SoundLibraryHolder implements InventoryHolder { public static class SoundLibraryHolder implements InventoryHolder {
public final int PAGE; public final int PAGE;

View File

@ -2,8 +2,6 @@ package me.skymc.taboolib.cooldown;
import java.util.HashMap; import java.util.HashMap;
import org.bukkit.plugin.Plugin;
@Deprecated @Deprecated
public class CooldownPack { public class CooldownPack {

View File

@ -1,19 +1,13 @@
package me.skymc.taboolib.cooldown; package me.skymc.taboolib.cooldown;
import java.util.ArrayList; import me.skymc.taboolib.message.MsgUtils;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import me.skymc.taboolib.message.MsgUtils; import java.util.concurrent.ConcurrentHashMap;
@Deprecated @Deprecated
public class CooldownUtils implements Listener { public class CooldownUtils implements Listener {

View File

@ -2,9 +2,6 @@ package me.skymc.taboolib.cooldown.seconds;
import java.util.HashMap; import java.util.HashMap;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
public class CooldownPack2 { public class CooldownPack2 {
private String plugin; private String plugin;

View File

@ -1,19 +1,12 @@
package me.skymc.taboolib.cooldown.seconds; package me.skymc.taboolib.cooldown.seconds;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import me.skymc.taboolib.message.MsgUtils; import java.util.concurrent.ConcurrentHashMap;
public class CooldownUtils2 implements Listener { public class CooldownUtils2 implements Listener {

View File

@ -1,9 +1,9 @@
package me.skymc.taboolib.csvutils; package me.skymc.taboolib.csvutils;
import java.nio.charset.*;
import java.text.*;
import java.io.*; import java.io.*;
import java.util.*; import java.nio.charset.Charset;
import java.text.NumberFormat;
import java.util.HashMap;
public class CsvReader public class CsvReader
{ {
@ -503,7 +503,6 @@ public class CsvReader
this.close(); this.close();
throw new IOException("Maximum column length of 100,000 exceeded in column " + NumberFormat.getIntegerInstance().format(this.columnsCount) + " in record " + NumberFormat.getIntegerInstance().format(this.currentRecord) + ". Set the SafetySwitch property to false" + " if you're expecting column lengths greater than 100,000 characters to" + " avoid this error."); throw new IOException("Maximum column length of 100,000 exceeded in column " + NumberFormat.getIntegerInstance().format(this.columnsCount) + " in record " + NumberFormat.getIntegerInstance().format(this.currentRecord) + ". Set the SafetySwitch property to false" + " if you're expecting column lengths greater than 100,000 characters to" + " avoid this error.");
} }
continue;
} }
} while (this.hasMoreData && this.startedColumn); } while (this.hasMoreData && this.startedColumn);
} }
@ -714,7 +713,6 @@ public class CsvReader
this.close(); this.close();
throw new IOException("Maximum column length of 100,000 exceeded in column " + NumberFormat.getIntegerInstance().format(this.columnsCount) + " in record " + NumberFormat.getIntegerInstance().format(this.currentRecord) + ". Set the SafetySwitch property to false" + " if you're expecting column lengths greater than 100,000 characters to" + " avoid this error."); throw new IOException("Maximum column length of 100,000 exceeded in column " + NumberFormat.getIntegerInstance().format(this.columnsCount) + " in record " + NumberFormat.getIntegerInstance().format(this.currentRecord) + ". Set the SafetySwitch property to false" + " if you're expecting column lengths greater than 100,000 characters to" + " avoid this error.");
} }
continue;
} }
} while (this.hasMoreData && this.startedColumn); } while (this.hasMoreData && this.startedColumn);
} }
@ -881,7 +879,7 @@ public class CsvReader
this.dataBuffer.ColumnStart = this.dataBuffer.Position + 1; this.dataBuffer.ColumnStart = this.dataBuffer.Position + 1;
} }
public void endRecord() throws IOException { public void endRecord() {
this.hasReadNextLine = true; this.hasReadNextLine = true;
++this.currentRecord; ++this.currentRecord;
} }
@ -960,8 +958,8 @@ public class CsvReader
if (this.initialized) { if (this.initialized) {
this.inputStream.close(); this.inputStream.close();
} }
} catch (Exception ignored) {
} }
catch (Exception ex) {}
this.inputStream = null; this.inputStream = null;
this.closed = true; this.closed = true;
} }

View File

@ -1,7 +1,7 @@
package me.skymc.taboolib.csvutils; package me.skymc.taboolib.csvutils;
import java.nio.charset.*;
import java.io.*; import java.io.*;
import java.nio.charset.Charset;
public class CsvWriter public class CsvWriter
{ {
@ -203,13 +203,21 @@ public class CsvWriter
this.firstColumn = true; this.firstColumn = true;
} }
public void writeRecord(final String[] array, final boolean b) throws IOException { public static String replace(final String s, final String s2, final String s3) {
if (array != null && array.length > 0) { final int length = s2.length();
for (int i = 0; i < array.length; ++i) { int i = s.indexOf(s2);
this.write(array[i], b); if (i > -1) {
final StringBuilder sb = new StringBuilder();
int n;
for (n = 0; i != -1; i = s.indexOf(s2, n)) {
sb.append(s.substring(n, i));
sb.append(s3);
n = i + length;
} }
this.endRecord(); sb.append(s.substring(n));
return sb.toString();
} }
return s;
} }
public void writeRecord(final String[] array) throws IOException { public void writeRecord(final String[] array) throws IOException {
@ -248,19 +256,12 @@ public class CsvWriter
} }
} }
private void close(final boolean b) { public void writeRecord(final String[] array, final boolean b) throws IOException {
if (!this.closed) { if (array != null && array.length > 0) {
if (b) { for (String anArray : array) {
this.charset = null; this.write(anArray, b);
} }
try { this.endRecord();
if (this.initialized) {
this.outputStream.close();
}
}
catch (Exception ex) {}
this.outputStream = null;
this.closed = true;
} }
} }
@ -274,21 +275,20 @@ public class CsvWriter
this.close(false); this.close(false);
} }
public static String replace(final String s, final String s2, final String s3) { private void close(final boolean b) {
final int length = s2.length(); if (!this.closed) {
int i = s.indexOf(s2); if (b) {
if (i > -1) { this.charset = null;
final StringBuffer sb = new StringBuffer();
int n;
for (n = 0; i != -1; i = s.indexOf(s2, n)) {
sb.append(s.substring(n, i));
sb.append(s3);
n = i + length;
} }
sb.append(s.substring(n)); try {
return sb.toString(); if (this.initialized) {
this.outputStream.close();
}
} catch (Exception ignored) {
}
this.outputStream = null;
this.closed = true;
} }
return s;
} }
private class UserSettings private class UserSettings

View File

@ -1,12 +1,11 @@
package me.skymc.taboolib.damage; package me.skymc.taboolib.damage;
import java.lang.reflect.InvocationTargetException; import me.skymc.taboolib.TabooLib;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import me.skymc.taboolib.TabooLib; import java.lang.reflect.InvocationTargetException;
public class DamageUtils { public class DamageUtils {
@ -31,7 +30,7 @@ public class DamageUtils {
Object localObject1 = null; Object localObject1 = null;
try try
{ {
localObject1 = paramLivingEntity1.getClass().getDeclaredMethod("getHandle", new Class[0]).invoke(paramLivingEntity1, new Object[0]); localObject1 = paramLivingEntity1.getClass().getDeclaredMethod("getHandle", new Class[0]).invoke(paramLivingEntity1);
} }
catch (IllegalAccessException|IllegalArgumentException|InvocationTargetException|NoSuchMethodException|SecurityException localIllegalAccessException1) catch (IllegalAccessException|IllegalArgumentException|InvocationTargetException|NoSuchMethodException|SecurityException localIllegalAccessException1)
{ {
@ -41,7 +40,7 @@ public class DamageUtils {
Object localObject2 = null; Object localObject2 = null;
try try
{ {
localObject2 = paramLivingEntity2.getClass().getDeclaredMethod("getHandle", new Class[0]).invoke(paramLivingEntity2, new Object[0]); localObject2 = paramLivingEntity2.getClass().getDeclaredMethod("getHandle", new Class[0]).invoke(paramLivingEntity2);
} }
catch (IllegalAccessException|IllegalArgumentException|InvocationTargetException|NoSuchMethodException|SecurityException localIllegalAccessException2) catch (IllegalAccessException|IllegalArgumentException|InvocationTargetException|NoSuchMethodException|SecurityException localIllegalAccessException2)
{ {
@ -51,13 +50,11 @@ public class DamageUtils {
try try
{ {
Class<?> DamageSource = nmsClass("DamageSource"); Class<?> DamageSource = nmsClass("DamageSource");
Object localObject3 = DamageSource.getDeclaredMethod("playerAttack", new Class[] { nmsClass("EntityHuman") }).invoke(DamageSource, new Object[] { localObject1 }); Object localObject3 = DamageSource.getDeclaredMethod("playerAttack", new Class[]{nmsClass("EntityHuman")}).invoke(DamageSource, localObject1);
localObject2.getClass().getDeclaredMethod("damageEntity", new Class[] { DamageSource, Float.TYPE }).invoke(localObject2, new Object[] { localObject3, Float.valueOf((float) paramDouble) }); localObject2.getClass().getDeclaredMethod("damageEntity", new Class[]{DamageSource, Float.TYPE}).invoke(localObject2, localObject3, (float) paramDouble);
} } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException ignored)
catch (IllegalAccessException|IllegalArgumentException|InvocationTargetException|NoSuchMethodException|SecurityException localIllegalAccessException3)
{ {
return;
} }
} }

View File

@ -1,12 +1,9 @@
package me.skymc.taboolib.damage; package me.skymc.taboolib.damage;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile; import org.bukkit.entity.Projectile;
import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityDeathEvent;
import me.skymc.taboolib.methods.MethodsUtils;
public class GetKiller { public class GetKiller {
public static Player get(EntityDeathEvent e) { public static Player get(EntityDeathEvent e) {

View File

@ -1,20 +1,18 @@
package me.skymc.taboolib.database; package me.skymc.taboolib.database;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.Main.StorageType;
import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.playerdata.DataUtils;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.scheduler.BukkitRunnable;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.Main.StorageType;
import me.skymc.taboolib.playerdata.DataUtils;
public class GlobalDataManager { public class GlobalDataManager {
public static FileConfiguration data = DataUtils.addPluginData("TabooLibrary-Variable.yml", null); public static FileConfiguration data = DataUtils.addPluginData("TabooLibrary-Variable.yml", null);
@ -92,7 +90,7 @@ public class GlobalDataManager {
*/ */
public static boolean contains(String name) { public static boolean contains(String name) {
if (Main.getStorageType() == StorageType.SQL) { if (Main.getStorageType() == StorageType.SQL) {
return getVariable(name, null) == null ? false : true; return getVariable(name, null) != null;
} }
else { else {
return data.contains(name.replace(":", "-")); return data.contains(name.replace(":", "-"));
@ -107,7 +105,7 @@ public class GlobalDataManager {
*/ */
public static boolean containsAsynchronous(String name) { public static boolean containsAsynchronous(String name) {
if (Main.getStorageType() == StorageType.SQL) { if (Main.getStorageType() == StorageType.SQL) {
return getVariableAsynchronous(name, null) == null ? false : true; return getVariableAsynchronous(name, null) != null;
} }
else { else {
return contains(name); return contains(name);
@ -316,10 +314,6 @@ public class GlobalDataManager {
@Override @Override
public void run() { public void run() {
/**
* 根据正序排列获取所有变量
* 新的变量会覆盖旧的变量
*/
LinkedList<HashMap<String, Object>> list = Main.getConnection().getValues(Main.getTablePrefix() + "_plugindata", "id", -1, false, "name", "variable", "upgrade"); LinkedList<HashMap<String, Object>> list = Main.getConnection().getValues(Main.getTablePrefix() + "_plugindata", "id", -1, false, "name", "variable", "upgrade");
// 循环变量 // 循环变量
for (HashMap<String, Object> value : list) { for (HashMap<String, Object> value : list) {

View File

@ -1,9 +1,12 @@
package me.skymc.taboolib.database; package me.skymc.taboolib.database;
import java.io.File; import me.skymc.taboolib.Main;
import java.util.UUID; import me.skymc.taboolib.Main.StorageType;
import java.util.concurrent.ConcurrentHashMap; import me.skymc.taboolib.events.PlayerLoadedEvent;
import me.skymc.taboolib.exception.PlayerOfflineException;
import me.skymc.taboolib.fileutils.ConfigUtils;
import me.skymc.taboolib.fileutils.FileUtils;
import me.skymc.taboolib.message.MsgUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
@ -15,20 +18,16 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import me.skymc.taboolib.Main; import java.io.File;
import me.skymc.taboolib.Main.StorageType; import java.util.UUID;
import me.skymc.taboolib.events.PlayerLoadedEvent; import java.util.concurrent.ConcurrentHashMap;
import me.skymc.taboolib.exception.PlayerOfflineException;
import me.skymc.taboolib.fileutils.ConfigUtils;
import me.skymc.taboolib.fileutils.FileUtils;
import me.skymc.taboolib.message.MsgUtils;
public class PlayerDataManager implements Listener { public class PlayerDataManager implements Listener {
private static final ConcurrentHashMap<String, FileConfiguration> PLAYER_DATA = new ConcurrentHashMap<>(); private static final ConcurrentHashMap<String, FileConfiguration> PLAYER_DATA = new ConcurrentHashMap<>();
public static enum UsernameType { public enum UsernameType {
UUID, USERNAME; UUID, USERNAME
} }
/** /**

View File

@ -1,10 +1,10 @@
package me.skymc.taboolib.display; package me.skymc.taboolib.display;
import java.lang.reflect.Constructor; import me.skymc.taboolib.TabooLib;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import me.skymc.taboolib.TabooLib; import java.lang.reflect.Constructor;
public class ActionUtils { public class ActionUtils {
@ -12,9 +12,9 @@ public class ActionUtils {
{ {
try try
{ {
Object handle = player.getClass().getMethod("getHandle", new Class[0]).invoke(player, new Object[0]); Object handle = player.getClass().getMethod("getHandle", new Class[0]).invoke(player);
Object playerConnection = handle.getClass().getField("playerConnection").get(handle); Object playerConnection = handle.getClass().getField("playerConnection").get(handle);
playerConnection.getClass().getMethod("sendPacket", new Class[] { getNMSClass("Packet") }).invoke(playerConnection, new Object[] { packet }); playerConnection.getClass().getMethod("sendPacket", new Class[]{getNMSClass("Packet")}).invoke(playerConnection, packet);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -43,7 +43,7 @@ public class ActionUtils {
} }
try try
{ {
Object ab = getNMSClass("ChatComponentText").getConstructor(new Class[] { String.class }).newInstance(new Object[] { msg }); Object ab = getNMSClass("ChatComponentText").getConstructor(new Class[]{String.class}).newInstance(msg);
Constructor<?> ac = null; Constructor<?> ac = null;
Object abPacket = null; Object abPacket = null;
// 如果版本大于 1.11.0 // 如果版本大于 1.11.0
@ -53,7 +53,7 @@ public class ActionUtils {
abPacket = ac.newInstance(ab, chatMessageType.getMethod("a", Byte.TYPE).invoke(null, (byte) 2)); abPacket = ac.newInstance(ab, chatMessageType.getMethod("a", Byte.TYPE).invoke(null, (byte) 2));
} else { } else {
ac = getNMSClass("PacketPlayOutChat").getConstructor(getNMSClass("IChatBaseComponent"), Byte.TYPE); ac = getNMSClass("PacketPlayOutChat").getConstructor(getNMSClass("IChatBaseComponent"), Byte.TYPE);
abPacket = ac.newInstance(ab, Byte.valueOf((byte) 2)); abPacket = ac.newInstance(ab, (byte) 2);
} }
sendPacket(p, abPacket); sendPacket(p, abPacket);
} }

View File

@ -1,10 +1,8 @@
package me.skymc.taboolib.display; package me.skymc.taboolib.display;
import java.lang.reflect.Constructor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import me.skymc.taboolib.methods.MethodsUtils; import java.lang.reflect.Constructor;
public class TitleUtils { public class TitleUtils {
@ -12,9 +10,9 @@ public class TitleUtils {
{ {
try try
{ {
Object handle = player.getClass().getMethod("getHandle", new Class[0]).invoke(player, new Object[0]); Object handle = player.getClass().getMethod("getHandle", new Class[0]).invoke(player);
Object playerConnection = handle.getClass().getField("playerConnection").get(handle); Object playerConnection = handle.getClass().getField("playerConnection").get(handle);
playerConnection.getClass().getMethod("sendPacket", new Class[] { getNMSClass("Packet") }).invoke(playerConnection, new Object[] { packet }); playerConnection.getClass().getMethod("sendPacket", new Class[]{getNMSClass("Packet")}).invoke(playerConnection, packet);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -53,29 +51,29 @@ public class TitleUtils {
if (title != null) if (title != null)
{ {
Object e = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TIMES").get(null); Object e = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TIMES").get(null);
Object chatTitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[] { String.class }).invoke(null, new Object[] { "{\"text\":\"" + title + "\"}" }); Object chatTitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[]{String.class}).invoke(null, "{\"text\":\"" + title + "\"}");
Constructor<?> subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[] { getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE }); Constructor<?> subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE);
Object titlePacket = subtitleConstructor.newInstance(new Object[] { e, chatTitle, Integer.valueOf(fadeint), Integer.valueOf(stayt), Integer.valueOf(fadeoutt) }); Object titlePacket = subtitleConstructor.newInstance(e, chatTitle, fadeint, stayt, fadeoutt);
sendPacket(p, titlePacket); sendPacket(p, titlePacket);
e = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TITLE").get(null); e = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TITLE").get(null);
chatTitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[] { String.class }).invoke(null, new Object[] { "{\"text\":\"" + title + "\"}" }); chatTitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[]{String.class}).invoke(null, "{\"text\":\"" + title + "\"}");
subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[] { getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent") }); subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"));
titlePacket = subtitleConstructor.newInstance(new Object[] { e, chatTitle }); titlePacket = subtitleConstructor.newInstance(e, chatTitle);
sendPacket(p, titlePacket); sendPacket(p, titlePacket);
} }
if (subtitle != null) if (subtitle != null)
{ {
Object e = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TIMES").get(null); Object e = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TIMES").get(null);
Object chatSubtitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[] { String.class }).invoke(null, new Object[] { "{\"text\":\"" + title + "\"}" }); Object chatSubtitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[]{String.class}).invoke(null, "{\"text\":\"" + title + "\"}");
Constructor<?> subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[] { getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE }); Constructor<?> subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE);
Object subtitlePacket = subtitleConstructor.newInstance(new Object[] { e, chatSubtitle, Integer.valueOf(fadeinst), Integer.valueOf(stayst), Integer.valueOf(fadeoutst) }); Object subtitlePacket = subtitleConstructor.newInstance(e, chatSubtitle, fadeinst, stayst, fadeoutst);
sendPacket(p, subtitlePacket); sendPacket(p, subtitlePacket);
e = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("SUBTITLE").get(null); e = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("SUBTITLE").get(null);
chatSubtitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[] { String.class }).invoke(null, new Object[] { "{\"text\":\"" + subtitle + "\"}" }); chatSubtitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[]{String.class}).invoke(null, "{\"text\":\"" + subtitle + "\"}");
subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[] { getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE }); subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE);
subtitlePacket = subtitleConstructor.newInstance(new Object[] { e, chatSubtitle, Integer.valueOf(fadeinst), Integer.valueOf(stayst), Integer.valueOf(fadeoutst) }); subtitlePacket = subtitleConstructor.newInstance(e, chatSubtitle, fadeinst, stayst, fadeoutst);
sendPacket(p, subtitlePacket); sendPacket(p, subtitlePacket);
} }
} }

View File

@ -1,14 +1,13 @@
package me.skymc.taboolib.entity; package me.skymc.taboolib.entity;
import me.skymc.taboolib.Main;
import org.bukkit.entity.Entity;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.entity.Entity;
import org.bukkit.scheduler.BukkitRunnable;
import me.skymc.taboolib.Main;
/** /**
* - MetaData * - MetaData
* *
@ -67,7 +66,6 @@ public class EntityTag {
* *
* @param key * @param key
* @param value * @param value
* @param entity 实体
*/ */
public void set(String key, Object value, Entity... entities) { public void set(String key, Object value, Entity... entities) {
for (Entity entity : entities) set(key, value, entity); for (Entity entity : entities) set(key, value, entity);
@ -78,7 +76,6 @@ public class EntityTag {
* *
* @param key * @param key
* @param value * @param value
* @param entity 实体
*/ */
public void set(String key, Object value, List<Entity> entities) { public void set(String key, Object value, List<Entity> entities) {
for (Entity entity : entities) set(key, value, entity); for (Entity entity : entities) set(key, value, entity);
@ -138,10 +135,7 @@ public class EntityTag {
* @return boolean * @return boolean
*/ */
public boolean hasKey(String key, Entity entity) { public boolean hasKey(String key, Entity entity) {
if (contains(entity)) { return contains(entity) && entityData.get(entity.getUniqueId()).containsKey(key);
return entityData.get(entity.getUniqueId()).containsKey(key);
}
return false;
} }
/** /**
@ -212,10 +206,7 @@ public class EntityTag {
*/ */
public boolean getBoolean(String key, Entity entity) { public boolean getBoolean(String key, Entity entity) {
Object object = get(key, entity); Object object = get(key, entity);
if (object != null) { return object != null && (boolean) object;
return (boolean) object;
}
return false;
} }
/** /**

View File

@ -1,7 +1,6 @@
package me.skymc.taboolib.events; package me.skymc.taboolib.events;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;

View File

@ -1,7 +1,6 @@
package me.skymc.taboolib.events; package me.skymc.taboolib.events;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;

View File

@ -1,21 +1,13 @@
package me.skymc.taboolib.fileutils; package me.skymc.taboolib.fileutils;
import java.io.File; import com.google.common.base.Charsets;
import java.io.FileInputStream; import me.skymc.taboolib.message.MsgUtils;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.util.HashMap;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder; import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
import com.google.common.base.Charsets; import java.io.*;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.message.MsgUtils;
public class ConfigUtils { public class ConfigUtils {
@ -47,8 +39,6 @@ public class ConfigUtils {
/** /**
* UTF-8 的格式载入配置文件 * UTF-8 的格式载入配置文件
* *
* @param main
* @param filename
* @return * @return
*/ */
public static FileConfiguration load(Plugin plugin, File file) { public static FileConfiguration load(Plugin plugin, File file) {

View File

@ -7,8 +7,6 @@ import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import me.skymc.taboolib.methods.MethodsUtils;
@Deprecated @Deprecated
public class CopyUtils { public class CopyUtils {

View File

@ -1,13 +1,6 @@
package me.skymc.taboolib.fileutils; package me.skymc.taboolib.fileutils;
import java.io.File; import java.io.*;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException; import java.nio.charset.UnsupportedCharsetException;
@ -40,7 +33,6 @@ public class EncodeUtils {
/** /**
* 把指定文件或目录转换成指定的编码 * 把指定文件或目录转换成指定的编码
* *
* @param file 要转换的文件或目录
* @param fromCharsetName 源文件的编码 * @param fromCharsetName 源文件的编码
* @param toCharsetName 转换的编码 * @param toCharsetName 转换的编码
* @param filter 文件名过滤器 * @param filter 文件名过滤器

View File

@ -1,13 +1,12 @@
package me.skymc.taboolib.fileutils; package me.skymc.taboolib.fileutils;
import me.skymc.taboolib.message.MsgUtils;
import java.io.*; import java.io.*;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.util.List;
import me.skymc.taboolib.message.MsgUtils;
public class FileUtils { public class FileUtils {
@ -19,7 +18,7 @@ public class FileUtils {
ins = con.getInputStream(); ins = con.getInputStream();
InputStreamReader isReader = new InputStreamReader(ins, "GB2312"); InputStreamReader isReader = new InputStreamReader(ins, "GB2312");
BufferedReader bReader = new BufferedReader(isReader); BufferedReader bReader = new BufferedReader(isReader);
StringBuffer webContent = new StringBuffer(); StringBuilder webContent = new StringBuilder();
String str = null; String str = null;
while ((str = bReader.readLine()) != null) { while ((str = bReader.readLine()) != null) {
webContent.append(str); webContent.append(str);
@ -86,8 +85,8 @@ public class FileUtils {
return; return;
} }
File[] files = file.listFiles(); File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) { for (File file1 : files) {
deleteAllFile(files[i]); deleteAllFile(file1);
} }
file.delete(); file.delete();
} }

View File

@ -1,15 +1,13 @@
package me.skymc.taboolib.fileutils; package me.skymc.taboolib.fileutils;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.other.DateUtils;
import org.bukkit.plugin.Plugin;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import org.bukkit.plugin.Plugin;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.methods.MethodsUtils;
import me.skymc.taboolib.other.DateUtils;
@Deprecated @Deprecated
public class LogUtils { public class LogUtils {

View File

@ -1,16 +1,12 @@
package me.skymc.taboolib.inventory; package me.skymc.taboolib.inventory;
import java.util.Random; import me.skymc.taboolib.other.NumberUtils;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import me.skymc.taboolib.other.NumberUtils;
public class DropUtils { public class DropUtils {
public static Item drop(Player player, ItemStack itemStack, double bulletSpread, double radius) { public static Item drop(Player player, ItemStack itemStack, double bulletSpread, double radius) {

View File

@ -1,15 +1,11 @@
package me.skymc.taboolib.inventory; package me.skymc.taboolib.inventory;
import java.util.Arrays;
import java.util.LinkedList;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import me.skymc.taboolib.methods.MethodsUtils; import java.util.Arrays;
import java.util.LinkedList;
public class InventoryUtil { public class InventoryUtil {
@ -62,27 +58,13 @@ public class InventoryUtil {
for (int i = 0; i < player.getInventory().getSize() && remove; i++) { for (int i = 0; i < player.getInventory().getSize() && remove; i++) {
ItemStack _item = player.getInventory().getItem(i); ItemStack _item = player.getInventory().getItem(i);
if (_item != null && _item.isSimilar(item)) { if (_item != null && _item.isSimilar(item)) {
/**
* 如果循环到的物品数量 小于 需要的数量
* 删除物品减少需要的数量
*/
if (_item.getAmount() < requireAmount) { if (_item.getAmount() < requireAmount) {
player.getInventory().setItem(i, null); player.getInventory().setItem(i, null);
requireAmount -= _item.getAmount(); requireAmount -= _item.getAmount();
} } else if (_item.getAmount() == requireAmount) {
/**
* 如果循环到的物品数量 等于 需要的数量
* 删除物品直接结束
*/
else if (_item.getAmount() == requireAmount) {
player.getInventory().setItem(i, null); player.getInventory().setItem(i, null);
return true; return true;
} } else {
/**
* 如果循环到的物品数量 大于 需要的数量
* 则扣除 需要的数量
*/
else {
_item.setAmount(_item.getAmount() - requireAmount); _item.setAmount(_item.getAmount() - requireAmount);
return true; return true;
} }
@ -101,10 +83,7 @@ public class InventoryUtil {
} }
} }
} }
if (inventoryAmount >= amount) { return inventoryAmount >= amount;
return true;
}
return false;
} }
@Deprecated @Deprecated

View File

@ -1,14 +1,17 @@
package me.skymc.taboolib.inventory; package me.skymc.taboolib.inventory;
import java.io.File; import lombok.Getter;
import java.io.FileInputStream; import me.clip.placeholderapi.PlaceholderAPI;
import java.io.InputStreamReader; import me.skymc.taboolib.Main;
import java.util.ArrayList; import me.skymc.taboolib.TabooLib;
import java.util.HashMap; import me.skymc.taboolib.fileutils.ConfigUtils;
import java.util.LinkedHashMap; import me.skymc.taboolib.itemnbtapi.NBTItem;
import java.util.List; import me.skymc.taboolib.itemnbtapi.NBTList;
import me.skymc.taboolib.itemnbtapi.NBTListCompound;
import org.bukkit.Bukkit; import me.skymc.taboolib.itemnbtapi.NBTType;
import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.other.NumberUtils;
import me.skymc.taboolib.string.Language;
import org.bukkit.Color; import org.bukkit.Color;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
@ -25,18 +28,10 @@ import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import lombok.Getter; import java.io.File;
import me.clip.placeholderapi.PlaceholderAPI; import java.util.ArrayList;
import me.skymc.taboolib.Main; import java.util.LinkedHashMap;
import me.skymc.taboolib.TabooLib; import java.util.List;
import me.skymc.taboolib.fileutils.ConfigUtils;
import me.skymc.taboolib.itemnbtapi.NBTItem;
import me.skymc.taboolib.itemnbtapi.NBTList;
import me.skymc.taboolib.itemnbtapi.NBTListCompound;
import me.skymc.taboolib.itemnbtapi.NBTType;
import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.other.NumberUtils;
import me.skymc.taboolib.string.Language;
public class ItemUtils { public class ItemUtils {
@ -150,8 +145,7 @@ public class ItemUtils {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static ItemStack item(int n, int a, int d) { public static ItemStack item(int n, int a, int d) {
ItemStack item = new ItemStack(n, a, (short)d); return new ItemStack(n, a, (short) d);
return item;
} }
public static ItemStack setName(ItemStack i, String n) { public static ItemStack setName(ItemStack i, String n) {
@ -180,17 +174,11 @@ public class ItemUtils {
} }
public static boolean isName(ItemStack i, String a) { public static boolean isName(ItemStack i, String a) {
if (!isNamed(i) || i.getItemMeta() == null || i.getItemMeta().getDisplayName() == null || !i.getItemMeta().getDisplayName().equals(a)) { return isNamed(i) && i.getItemMeta() != null && i.getItemMeta().getDisplayName() != null && i.getItemMeta().getDisplayName().equals(a);
return false;
}
return true;
} }
public static boolean isNameAs(ItemStack i, String a) { public static boolean isNameAs(ItemStack i, String a) {
if (!isNamed(i) || !i.getItemMeta().getDisplayName().contains(a)) { return isNamed(i) && i.getItemMeta().getDisplayName().contains(a);
return false;
}
return true;
} }
public static String asString(String args, Player placeholderPlayer) { public static String asString(String args, Player placeholderPlayer) {
@ -259,25 +247,20 @@ public class ItemUtils {
} }
public static String asAttribute(String name) { public static String asAttribute(String name) {
if (name.toLowerCase().equals("damage")) { switch (name.toLowerCase()) {
case "damage":
return "generic.attackDamage"; return "generic.attackDamage";
} case "attackspeed":
else if (name.toLowerCase().equals("attackspeed")) {
return "generic.attackSpeed"; return "generic.attackSpeed";
} case "health":
else if (name.toLowerCase().equals("health")) {
return "generic.maxHealth"; return "generic.maxHealth";
} case "speed":
else if (name.toLowerCase().equals("speed")) {
return "generic.movementSpeed"; return "generic.movementSpeed";
} case "knockback":
else if (name.toLowerCase().equals("knockback")) {
return "generic.knockbackResistance"; return "generic.knockbackResistance";
} case "armor":
else if (name.toLowerCase().equals("armor")) {
return "generic.armor"; return "generic.armor";
} case "luck":
else if (name.toLowerCase().equals("luck")) {
return "generic.luck"; return "generic.luck";
} }
return null; return null;
@ -290,10 +273,7 @@ public class ItemUtils {
* @param a 关键字 * @param a 关键字
*/ */
public static boolean hasLore(ItemStack i, String a) { public static boolean hasLore(ItemStack i, String a) {
if (!isLored(i) || !i.getItemMeta().getLore().toString().contains(a)) { return isLored(i) && i.getItemMeta().getLore().toString().contains(a);
return false;
}
return true;
} }
/** /**
@ -303,10 +283,7 @@ public class ItemUtils {
* @return * @return
*/ */
public static boolean isLored(ItemStack i) { public static boolean isLored(ItemStack i) {
if (i == null || i.getItemMeta() == null || i.getItemMeta().getLore() == null) { return i != null && i.getItemMeta() != null && i.getItemMeta().getLore() != null;
return false;
}
return true;
} }
/** /**
@ -316,10 +293,7 @@ public class ItemUtils {
* @return * @return
*/ */
public static boolean isNamed(ItemStack i) { public static boolean isNamed(ItemStack i) {
if (i == null || i.getItemMeta() == null || i.getItemMeta().getDisplayName() == null) { return i != null && i.getItemMeta() != null && i.getItemMeta().getDisplayName() != null;
return false;
}
return true;
} }
/** /**

View File

@ -8,7 +8,7 @@ import org.bukkit.plugin.Plugin;
* @author sky * @author sky
* @since 2018年2月17日 下午8:35:42 * @since 2018年2月17日 下午8:35:42
*/ */
public abstract interface AbstractSpecialItem { public interface AbstractSpecialItem {
/** /**
* 当接口被载入 * 当接口被载入
@ -25,14 +25,14 @@ public abstract interface AbstractSpecialItem {
* *
* @return String * @return String
*/ */
abstract String getName(); String getName();
/** /**
* 获取载入插件 * 获取载入插件
* *
* @return {@link Plugin} * @return {@link Plugin}
*/ */
abstract Plugin getPlugin(); Plugin getPlugin();
/** /**
* 是否进行点击事件 * 是否进行点击事件
@ -42,5 +42,5 @@ public abstract interface AbstractSpecialItem {
* @param cursorItem 持有物品 * @param cursorItem 持有物品
* @return {@link SpecialItemResult[]} * @return {@link SpecialItemResult[]}
*/ */
abstract SpecialItemResult[] isCorrectClick(Player player, ItemStack currentItem, ItemStack cursorItem); SpecialItemResult[] isCorrectClick(Player player, ItemStack currentItem, ItemStack cursorItem);
} }

View File

@ -1,8 +1,9 @@
package me.skymc.taboolib.inventory.speciaitem; package me.skymc.taboolib.inventory.speciaitem;
import java.util.List; import lombok.Getter;
import java.util.concurrent.CopyOnWriteArrayList; import me.skymc.taboolib.Main;
import me.skymc.taboolib.inventory.ItemUtils;
import me.skymc.taboolib.message.MsgUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -12,10 +13,8 @@ import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import lombok.Getter; import java.util.List;
import me.skymc.taboolib.Main; import java.util.concurrent.CopyOnWriteArrayList;
import me.skymc.taboolib.inventory.ItemUtils;
import me.skymc.taboolib.message.MsgUtils;
/** /**
* @author sky * @author sky
@ -119,7 +118,7 @@ public class SpecialItem implements Listener {
* 载入所有已注册接口 * 载入所有已注册接口
*/ */
public void loadItems() { public void loadItems() {
ITEM_DATA.forEach(x -> x.onEnable()); ITEM_DATA.forEach(AbstractSpecialItem::onEnable);
isLoaded = true; isLoaded = true;
} }
@ -127,7 +126,7 @@ public class SpecialItem implements Listener {
* 注销所有已注册接口 * 注销所有已注册接口
*/ */
public void unloadItems() { public void unloadItems() {
ITEM_DATA.forEach(x -> x.onDisable()); ITEM_DATA.forEach(AbstractSpecialItem::onDisable);
ITEM_DATA.clear(); ITEM_DATA.clear();
} }
@ -147,33 +146,32 @@ public class SpecialItem implements Listener {
Player player = (Player) e.getWhoClicked(); Player player = (Player) e.getWhoClicked();
for (AbstractSpecialItem specialitem : ITEM_DATA) { for (AbstractSpecialItem specialitem : ITEM_DATA) {
for (SpecialItemResult result : specialitem.isCorrectClick(player, e.getCurrentItem(), e.getCursor())) { for (SpecialItemResult result : specialitem.isCorrectClick(player, e.getCurrentItem(), e.getCursor())) {
if (result == SpecialItemResult.CANCEL) { switch (result) {
case CANCEL:
e.setCancelled(true); e.setCancelled(true);
} break;
else if (result == SpecialItemResult.BREAK) { case BREAK:
return; return;
} case REMOVE_ITEM_CURRENT:
else if (result == SpecialItemResult.REMOVE_ITEM_CURRENT) {
e.setCurrentItem(null); e.setCurrentItem(null);
} break;
else if (result == SpecialItemResult.REMOVE_ITEM_CURSOR) { case REMOVE_ITEM_CURSOR:
e.getWhoClicked().setItemOnCursor(null); e.getWhoClicked().setItemOnCursor(null);
} break;
else if (result == SpecialItemResult.REMOVE_ITEM_CURRENT_AMOUNT_1) { case REMOVE_ITEM_CURRENT_AMOUNT_1:
if (e.getCurrentItem().getAmount() > 1) { if (e.getCurrentItem().getAmount() > 1) {
e.getCurrentItem().setAmount(e.getCurrentItem().getAmount() - 1); e.getCurrentItem().setAmount(e.getCurrentItem().getAmount() - 1);
} } else {
else {
e.setCurrentItem(null); e.setCurrentItem(null);
} }
} break;
else if (result == SpecialItemResult.REMOVE_ITEM_CURSOR_AMOUNT_1) { case REMOVE_ITEM_CURSOR_AMOUNT_1:
if (e.getCursor().getAmount() > 1) { if (e.getCursor().getAmount() > 1) {
e.getCursor().setAmount(e.getCursor().getAmount() - 1); e.getCursor().setAmount(e.getCursor().getAmount() - 1);
} } else {
else {
e.getWhoClicked().setItemOnCursor(null); e.getWhoClicked().setItemOnCursor(null);
} }
break;
} }
} }
} }

View File

@ -34,6 +34,6 @@ public enum SpecialItemResult {
/** /**
* 移除一个鼠标物品 * 移除一个鼠标物品
*/ */
REMOVE_ITEM_CURSOR_AMOUNT_1; REMOVE_ITEM_CURSOR_AMOUNT_1
} }

View File

@ -1,5 +1,14 @@
package me.skymc.taboolib.itemnbtapi; package me.skymc.taboolib.itemnbtapi;
import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.itemnbtapi.utils.GsonWrapper;
import me.skymc.taboolib.itemnbtapi.utils.MethodNames;
import me.skymc.taboolib.message.MsgUtils;
import org.bukkit.Bukkit;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStream; import java.io.InputStream;
@ -8,16 +17,6 @@ import java.lang.reflect.Method;
import java.util.Set; import java.util.Set;
import java.util.Stack; import java.util.Stack;
import org.bukkit.Bukkit;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.itemnbtapi.utils.GsonWrapper;
import me.skymc.taboolib.itemnbtapi.utils.MethodNames;
import me.skymc.taboolib.message.MsgUtils;
// TODO: finish codestyle cleanup -sgdc3 // TODO: finish codestyle cleanup -sgdc3
public class NBTReflectionUtil { public class NBTReflectionUtil {
@ -27,8 +26,7 @@ public class NBTReflectionUtil {
private static Class getCraftItemStack() { private static Class getCraftItemStack() {
try { try {
Class clazz = Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack"); return Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack");
return clazz;
} catch (Exception ex) { } catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
return null; return null;
@ -38,8 +36,7 @@ public class NBTReflectionUtil {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private static Class getCraftEntity() { private static Class getCraftEntity() {
try { try {
Class clazz = Class.forName("org.bukkit.craftbukkit." + version + ".entity.CraftEntity"); return Class.forName("org.bukkit.craftbukkit." + version + ".entity.CraftEntity");
return clazz;
} catch (Exception ex) { } catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
return null; return null;
@ -49,8 +46,7 @@ public class NBTReflectionUtil {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
protected static Class getNBTBase() { protected static Class getNBTBase() {
try { try {
Class clazz = Class.forName("net.minecraft.server." + version + ".NBTBase"); return Class.forName("net.minecraft.server." + version + ".NBTBase");
return clazz;
} catch (Exception ex) { } catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
return null; return null;
@ -60,8 +56,7 @@ public class NBTReflectionUtil {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
protected static Class getNBTTagString() { protected static Class getNBTTagString() {
try { try {
Class clazz = Class.forName("net.minecraft.server." + version + ".NBTTagString"); return Class.forName("net.minecraft.server." + version + ".NBTTagString");
return clazz;
} catch (Exception ex) { } catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
@ -72,8 +67,7 @@ public class NBTReflectionUtil {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
protected static Class getNMSItemStack() { protected static Class getNMSItemStack() {
try { try {
Class clazz = Class.forName("net.minecraft.server." + version + ".ItemStack"); return Class.forName("net.minecraft.server." + version + ".ItemStack");
return clazz;
} catch (Exception ex) { } catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
@ -84,8 +78,7 @@ public class NBTReflectionUtil {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
protected static Class getNBTTagCompound() { protected static Class getNBTTagCompound() {
try { try {
Class clazz = Class.forName("net.minecraft.server." + version + ".NBTTagCompound"); return Class.forName("net.minecraft.server." + version + ".NBTTagCompound");
return clazz;
} catch (Exception ex) { } catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
@ -96,8 +89,7 @@ public class NBTReflectionUtil {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
protected static Class getNBTCompressedStreamTools() { protected static Class getNBTCompressedStreamTools() {
try { try {
Class clazz = Class.forName("net.minecraft.server." + version + ".NBTCompressedStreamTools"); return Class.forName("net.minecraft.server." + version + ".NBTCompressedStreamTools");
return clazz;
} catch (Exception ex) { } catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
@ -108,8 +100,7 @@ public class NBTReflectionUtil {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
protected static Class getMojangsonParser() { protected static Class getMojangsonParser() {
try { try {
Class c = Class.forName("net.minecraft.server." + version + ".MojangsonParser"); return Class.forName("net.minecraft.server." + version + ".MojangsonParser");
return c;
} catch (Exception ex) { } catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
@ -120,8 +111,7 @@ public class NBTReflectionUtil {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
protected static Class getTileEntity() { protected static Class getTileEntity() {
try { try {
Class clazz = Class.forName("net.minecraft.server." + version + ".TileEntity"); return Class.forName("net.minecraft.server." + version + ".TileEntity");
return clazz;
} catch (Exception ex) { } catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
@ -132,8 +122,7 @@ public class NBTReflectionUtil {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
protected static Class getCraftWorld() { protected static Class getCraftWorld() {
try { try {
Class clazz = Class.forName("org.bukkit.craftbukkit." + version + ".CraftWorld"); return Class.forName("org.bukkit.craftbukkit." + version + ".CraftWorld");
return clazz;
} catch (Exception ex) { } catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
@ -186,8 +175,7 @@ public class NBTReflectionUtil {
Method method; Method method;
try { try {
method = clazz.getMethod("asNMSCopy", ItemStack.class); method = clazz.getMethod("asNMSCopy", ItemStack.class);
Object answer = method.invoke(clazz, item); return method.invoke(clazz, item);
return answer;
} catch (Exception e) { } catch (Exception e) {
MsgUtils.warn("NBT 操作出现异常: §7" + e.getMessage()); MsgUtils.warn("NBT 操作出现异常: §7" + e.getMessage());
} }
@ -272,8 +260,7 @@ public class NBTReflectionUtil {
Method method; Method method;
try { try {
method = clazz.getMethod("getTag"); method = clazz.getMethod("getTag");
Object answer = method.invoke(nmsitem); return method.invoke(nmsitem);
return answer;
} catch (Exception e) { } catch (Exception e) {
MsgUtils.warn("NBT 操作出现异常: §7" + e.getMessage()); MsgUtils.warn("NBT 操作出现异常: §7" + e.getMessage());
} }
@ -285,8 +272,7 @@ public class NBTReflectionUtil {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
Class clazz = getNMSItemStack(); Class clazz = getNMSItemStack();
try { try {
Object nmsstack = clazz.getConstructor(getNBTTagCompound()).newInstance(nbtcompound.getCompound()); return clazz.getConstructor(getNBTTagCompound()).newInstance(nbtcompound.getCompound());
return nmsstack;
} catch (Exception e) { } catch (Exception e) {
MsgUtils.warn("NBT 操作出现异常: §7" + e.getMessage()); MsgUtils.warn("NBT 操作出现异常: §7" + e.getMessage());
} }
@ -379,8 +365,7 @@ public class NBTReflectionUtil {
Method method; Method method;
try { try {
method = c.getMethod("getCompound", String.class); method = c.getMethod("getCompound", String.class);
Object answer = method.invoke(compound, name); return method.invoke(compound, name);
return answer;
} catch (Exception e) { } catch (Exception e) {
MsgUtils.warn("NBT 操作出现异常: §7" + e.getMessage()); MsgUtils.warn("NBT 操作出现异常: §7" + e.getMessage());
} }
@ -403,11 +388,9 @@ public class NBTReflectionUtil {
method = workingtag.getClass().getMethod("set", String.class, getNBTBase()); method = workingtag.getClass().getMethod("set", String.class, getNBTBase());
method.invoke(workingtag, name, getNBTTagCompound().newInstance()); method.invoke(workingtag, name, getNBTTagCompound().newInstance());
comp.setCompound(nbttag); comp.setCompound(nbttag);
return;
} catch (Exception ex) { } catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
} }
return;
} }
public static Boolean valideCompound(NBTCompound comp) { public static Boolean valideCompound(NBTCompound comp) {
@ -562,7 +545,6 @@ public class NBTReflectionUtil {
} catch (Exception ex) { } catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
} }
return;
} }
public static byte[] getByteArray(NBTCompound comp, String key) { public static byte[] getByteArray(NBTCompound comp, String key) {
@ -634,7 +616,7 @@ public class NBTReflectionUtil {
Method method; Method method;
try { try {
method = workingtag.getClass().getMethod("setFloat", String.class, float.class); method = workingtag.getClass().getMethod("setFloat", String.class, float.class);
method.invoke(workingtag, key, (float) f); method.invoke(workingtag, key, f);
comp.setCompound(rootnbttag); comp.setCompound(rootnbttag);
} catch (Exception ex) { } catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
@ -672,7 +654,7 @@ public class NBTReflectionUtil {
Method method; Method method;
try { try {
method = workingtag.getClass().getMethod("setLong", String.class, long.class); method = workingtag.getClass().getMethod("setLong", String.class, long.class);
method.invoke(workingtag, key, (long) f); method.invoke(workingtag, key, f);
comp.setCompound(rootnbttag); comp.setCompound(rootnbttag);
} catch (Exception ex) { } catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
@ -710,7 +692,7 @@ public class NBTReflectionUtil {
Method method; Method method;
try { try {
method = workingtag.getClass().getMethod("setShort", String.class, short.class); method = workingtag.getClass().getMethod("setShort", String.class, short.class);
method.invoke(workingtag, key, (short) f); method.invoke(workingtag, key, f);
comp.setCompound(rootnbttag); comp.setCompound(rootnbttag);
} catch (Exception ex) { } catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
@ -748,7 +730,7 @@ public class NBTReflectionUtil {
Method method; Method method;
try { try {
method = workingtag.getClass().getMethod("setByte", String.class, byte.class); method = workingtag.getClass().getMethod("setByte", String.class, byte.class);
method.invoke(workingtag, key, (byte) f); method.invoke(workingtag, key, f);
comp.setCompound(rootnbttag); comp.setCompound(rootnbttag);
} catch (Exception ex) { } catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage()); MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());

View File

@ -1,16 +1,14 @@
package me.skymc.taboolib.javascript; package me.skymc.taboolib.javascript;
import java.io.File; import me.skymc.taboolib.Main;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import javax.script.Invocable; import javax.script.Invocable;
import javax.script.ScriptEngine; import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager; import javax.script.ScriptEngineManager;
import javax.script.ScriptException; import javax.script.ScriptException;
import java.io.File;
import me.skymc.taboolib.Main; import java.io.FileReader;
import java.io.IOException;
public class JavaScriptUtils { public class JavaScriptUtils {
@ -51,13 +49,7 @@ public class JavaScriptUtils {
} }
reader.close(); reader.close();
} catch (FileNotFoundException e) { } catch (NoSuchMethodException | IOException | ScriptException e) {
e.printStackTrace();
} catch (ScriptException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;
@ -76,13 +68,7 @@ public class JavaScriptUtils {
} }
reader.close(); reader.close();
} catch (FileNotFoundException e) { } catch (NoSuchMethodException | IOException | ScriptException e) {
e.printStackTrace();
} catch (ScriptException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }

View File

@ -1,12 +1,10 @@
package me.skymc.taboolib.javashell; package me.skymc.taboolib.javashell;
import java.io.File; import lombok.Getter;
import java.io.FilenameFilter; import lombok.Setter;
import java.lang.reflect.Method; import me.skymc.taboolib.Main;
import java.net.URL; import me.skymc.taboolib.javashell.utils.JarUtils;
import java.net.URLClassLoader; import me.skymc.taboolib.message.MsgUtils;
import java.util.HashMap;
import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.ArrayUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@ -14,11 +12,11 @@ import org.bukkit.event.Listener;
import org.bukkit.plugin.RegisteredListener; import org.bukkit.plugin.RegisteredListener;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import me.skymc.taboolib.Main; import java.io.File;
import me.skymc.taboolib.javashell.utils.JarUtils; import java.lang.reflect.Method;
import me.skymc.taboolib.message.MsgUtils; import java.net.URL;
import lombok.Getter; import java.net.URLClassLoader;
import lombok.Setter; import java.util.HashMap;
public class JavaShell { public class JavaShell {
@ -51,17 +49,9 @@ public class JavaShell {
File pluginsFolder = dataFolder.getParentFile(); File pluginsFolder = dataFolder.getParentFile();
File serverRoot = Bukkit.getWorldContainer(); File serverRoot = Bukkit.getWorldContainer();
File[] rootJars = serverRoot.listFiles(new FilenameFilter() { File[] rootJars = serverRoot.listFiles((dir, name) -> name.toLowerCase().endsWith("jar"));
public boolean accept(File dir, String name) {
return name.toLowerCase().endsWith("jar");
}
});
File[] pluginJars = pluginsFolder.listFiles(new FilenameFilter() { File[] pluginJars = pluginsFolder.listFiles((dir, name) -> name.toLowerCase().endsWith("jar"));
public boolean accept(File dir, String name) {
return name.toLowerCase().endsWith("jar");
}
});
for (File file : (File[]) ArrayUtils.addAll(rootJars, pluginJars)) { for (File file : (File[]) ArrayUtils.addAll(rootJars, pluginJars)) {
String path = file.getAbsolutePath(); String path = file.getAbsolutePath();
@ -123,7 +113,7 @@ public class JavaShell {
if (shells.containsKey(name)) { if (shells.containsKey(name)) {
Class<?> clazz = shells.get(name); Class<?> clazz = shells.get(name);
try { try {
Method disableMethod = clazz.getMethod(method, new Class[0]); Method disableMethod = clazz.getMethod(method);
if (disableMethod != null) { if (disableMethod != null) {
disableMethod.invoke(clazz.newInstance()); disableMethod.invoke(clazz.newInstance());
} }

View File

@ -1,12 +1,9 @@
package me.skymc.taboolib.javashell.utils; package me.skymc.taboolib.javashell.utils;
import java.io.BufferedInputStream; import me.skymc.taboolib.message.MsgUtils;
import java.io.BufferedOutputStream; import org.bukkit.Bukkit;
import java.io.File;
import java.io.FileOutputStream; import java.io.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
@ -15,10 +12,6 @@ import java.util.Enumeration;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import org.bukkit.Bukkit;
import me.skymc.taboolib.message.MsgUtils;
public class JarUtils { public class JarUtils {
public static boolean extractFromJar(final String fileName, final String dest) throws IOException { public static boolean extractFromJar(final String fileName, final String dest) throws IOException {
@ -51,7 +44,7 @@ public class JarUtils {
return false; return false;
} }
private final static void copyInputStream(final InputStream in, final OutputStream out) throws IOException { private static void copyInputStream(final InputStream in, final OutputStream out) throws IOException {
try { try {
final byte[] buff = new byte[4096]; final byte[] buff = new byte[4096];
int n; int n;
@ -88,13 +81,13 @@ public class JarUtils {
} }
} }
public static void addClassPath(final URL url) throws IOException { public static void addClassPath(final URL url) {
final URLClassLoader sysloader = (URLClassLoader) Bukkit.class.getClassLoader(); final URLClassLoader sysloader = (URLClassLoader) Bukkit.class.getClassLoader();
final Class<URLClassLoader> sysclass = URLClassLoader.class; final Class<URLClassLoader> sysclass = URLClassLoader.class;
try { try {
final Method method = sysclass.getDeclaredMethod("addURL", new Class[] { URL.class }); final Method method = sysclass.getDeclaredMethod("addURL", URL.class);
method.setAccessible(true); method.setAccessible(true);
method.invoke(sysloader, new Object[] { url }); method.invoke(sysloader, url);
} catch (Throwable t) { } catch (Throwable t) {
MsgUtils.warn("无法添加添加 &4" + url + "&c 到运行库"); MsgUtils.warn("无法添加添加 &4" + url + "&c 到运行库");
MsgUtils.warn(t.getMessage()); MsgUtils.warn(t.getMessage());

View File

@ -69,7 +69,7 @@ public class CDL {
} }
public static String rowToString(JSONArray ja) { public static String rowToString(JSONArray ja) {
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
for (int i = 0; i < ja.length(); i += 1) { for (int i = 0; i < ja.length(); i += 1) {
if (i > 0) { if (i > 0) {
sb.append(','); sb.append(',');
@ -146,7 +146,7 @@ public class CDL {
if (names == null || names.length() == 0) { if (names == null || names.length() == 0) {
return null; return null;
} }
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
for (int i = 0; i < ja.length(); i += 1) { for (int i = 0; i < ja.length(); i += 1) {
JSONObject jo = ja.optJSONObject(i); JSONObject jo = ja.optJSONObject(i);
if (jo != null) { if (jo != null) {

View File

@ -5,7 +5,7 @@ public class Cookie {
public static String escape(String string) { public static String escape(String string) {
char c; char c;
String s = string.trim(); String s = string.trim();
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
int length = s.length(); int length = s.length();
for (int i = 0; i < length; i += 1) { for (int i = 0; i < length; i += 1) {
c = s.charAt(i); c = s.charAt(i);
@ -47,7 +47,7 @@ public class Cookie {
} }
public static String toString(JSONObject jo) throws JSONException { public static String toString(JSONObject jo) throws JSONException {
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
sb.append(escape(jo.getString("name"))); sb.append(escape(jo.getString("name")));
sb.append("="); sb.append("=");
@ -72,7 +72,7 @@ public class Cookie {
public static String unescape(String string) { public static String unescape(String string) {
int length = string.length(); int length = string.length();
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
for (int i = 0; i < length; ++i) { for (int i = 0; i < length; ++i) {
char c = string.charAt(i); char c = string.charAt(i);
if (c == '+') { if (c == '+') {

View File

@ -21,7 +21,7 @@ public class CookieList {
boolean b = false; boolean b = false;
Iterator keys = jo.keys(); Iterator keys = jo.keys();
String string; String string;
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
while (keys.hasNext()) { while (keys.hasNext()) {
string = keys.next().toString(); string = keys.next().toString();
if (!jo.isNull(string)) { if (!jo.isNull(string)) {

View File

@ -35,7 +35,7 @@ public class HTTP {
public static String toString(JSONObject jo) throws JSONException { public static String toString(JSONObject jo) throws JSONException {
Iterator keys = jo.keys(); Iterator keys = jo.keys();
String string; String string;
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
if (jo.has("Status-Code") && jo.has("Reason-Phrase")) { if (jo.has("Status-Code") && jo.has("Reason-Phrase")) {
sb.append(jo.getString("HTTP-Version")); sb.append(jo.getString("HTTP-Version"));
sb.append(' '); sb.append(' ');

View File

@ -9,7 +9,7 @@ public class HTTPTokener extends JSONTokener {
public String nextToken() throws JSONException { public String nextToken() throws JSONException {
char c; char c;
char q; char q;
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
do { do {
c = next(); c = next();
} while (Character.isWhitespace(c)); } while (Character.isWhitespace(c));

View File

@ -6,7 +6,6 @@ import java.io.Writer;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator;
import java.util.Map; import java.util.Map;
@SuppressWarnings({"rawtypes", "unchecked"}) @SuppressWarnings({"rawtypes", "unchecked"})
@ -57,9 +56,8 @@ public class JSONArray {
public JSONArray(Collection collection) { public JSONArray(Collection collection) {
this.myArrayList = new ArrayList(); this.myArrayList = new ArrayList();
if (collection != null) { if (collection != null) {
Iterator iter = collection.iterator(); for (Object aCollection : collection) {
while (iter.hasNext()) { this.myArrayList.add(JSONObject.wrap(aCollection));
this.myArrayList.add(JSONObject.wrap(iter.next()));
} }
} }
} }
@ -166,7 +164,7 @@ public class JSONArray {
public String join(String separator) throws JSONException { public String join(String separator) throws JSONException {
int len = this.length(); int len = this.length();
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
for (int i = 0; i < len; i += 1) { for (int i = 0; i < len; i += 1) {
if (i > 0) { if (i > 0) {
@ -267,7 +265,7 @@ public class JSONArray {
} }
public JSONArray put(double value) throws JSONException { public JSONArray put(double value) throws JSONException {
Double d = new Double(value); Double d = value;
JSONObject.testValidity(d); JSONObject.testValidity(d);
this.put(d); this.put(d);
return this; return this;

View File

@ -40,13 +40,15 @@ public class JSONML {
return token; return token;
} else if (token == XML.BANG) { } else if (token == XML.BANG) {
c = x.next(); c = x.next();
if (c == '-') { switch (c) {
case '-':
if (x.next() == '-') { if (x.next() == '-') {
x.skipPast("-->"); x.skipPast("-->");
} else { } else {
x.back(); x.back();
} }
} else if (c == '[') { break;
case '[':
token = x.nextToken(); token = x.nextToken();
if (token.equals("CDATA") && x.next() == '[') { if (token.equals("CDATA") && x.next() == '[') {
if (ja != null) { if (ja != null) {
@ -55,7 +57,8 @@ public class JSONML {
} else { } else {
throw x.syntaxError("Expected 'CDATA['"); throw x.syntaxError("Expected 'CDATA['");
} }
} else { break;
default:
i = 1; i = 1;
do { do {
token = x.nextMeta(); token = x.nextMeta();
@ -67,6 +70,7 @@ public class JSONML {
i -= 1; i -= 1;
} }
} while (i > 0); } while (i > 0);
break;
} }
} else if (token == XML.QUEST) { } else if (token == XML.QUEST) {
x.skipPast("?>"); x.skipPast("?>");
@ -189,7 +193,7 @@ public class JSONML {
Iterator keys; Iterator keys;
int length; int length;
Object object; Object object;
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
String tagName; String tagName;
String value; String value;
tagName = ja.getString(0); tagName = ja.getString(0);
@ -247,7 +251,7 @@ public class JSONML {
} }
public static String toString(JSONObject jo) throws JSONException { public static String toString(JSONObject jo) throws JSONException {
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
int i; int i;
JSONArray ja; JSONArray ja;
String key; String key;

View File

@ -6,13 +6,7 @@ import java.io.Writer;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.Collection; import java.util.*;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
@SuppressWarnings({"rawtypes", "unchecked"}) @SuppressWarnings({"rawtypes", "unchecked"})
public class JSONObject { public class JSONObject {
@ -42,9 +36,9 @@ public class JSONObject {
public JSONObject(JSONObject jo, String[] names) { public JSONObject(JSONObject jo, String[] names) {
this(); this();
for (int i = 0; i < names.length; i += 1) { for (String name : names) {
try { try {
this.putOnce(names[i], jo.opt(names[i])); this.putOnce(name, jo.opt(name));
} catch (Exception ignore) { } catch (Exception ignore) {
} }
} }
@ -97,9 +91,8 @@ public class JSONObject {
public JSONObject(Map map) { public JSONObject(Map map) {
this.map = new HashMap(); this.map = new HashMap();
if (map != null) { if (map != null) {
Iterator i = map.entrySet().iterator(); for (Object o : map.entrySet()) {
while (i.hasNext()) { Map.Entry e = (Map.Entry) o;
Map.Entry e = (Map.Entry)i.next();
Object value = e.getValue(); Object value = e.getValue();
if (value != null) { if (value != null) {
this.map.put(e.getKey(), wrap(value)); this.map.put(e.getKey(), wrap(value));
@ -116,8 +109,7 @@ public class JSONObject {
public JSONObject(Object object, String names[]) { public JSONObject(Object object, String names[]) {
this(); this();
Class c = object.getClass(); Class c = object.getClass();
for (int i = 0; i < names.length; i += 1) { for (String name : names) {
String name = names[i];
try { try {
this.putOpt(name, c.getField(name).get(object)); this.putOpt(name, c.getField(name).get(object));
} catch (Exception ignore) { } catch (Exception ignore) {
@ -329,22 +321,41 @@ public class JSONObject {
return this.map.containsKey(key); return this.map.containsKey(key);
} }
public JSONObject increment(String key) throws JSONException { public static Object stringToValue(String string) {
Object value = this.opt(key); Double d;
if (value == null) { if (string.equals("")) {
this.put(key, 1); return string;
} else if (value instanceof Integer) {
this.put(key, ((Integer)value).intValue() + 1);
} else if (value instanceof Long) {
this.put(key, ((Long)value).longValue() + 1);
} else if (value instanceof Double) {
this.put(key, ((Double)value).doubleValue() + 1);
} else if (value instanceof Float) {
this.put(key, ((Float)value).floatValue() + 1);
} else {
throw new JSONException("Unable to increment [" + quote(key) + "].");
} }
return this; if (string.equalsIgnoreCase("true")) {
return Boolean.TRUE;
}
if (string.equalsIgnoreCase("false")) {
return Boolean.FALSE;
}
if (string.equalsIgnoreCase("null")) {
return JSONObject.NULL;
}
char b = string.charAt(0);
if ((b >= '0' && b <= '9') || b == '.' || b == '-' || b == '+') {
try {
if (string.indexOf('.') > -1 ||
string.indexOf('e') > -1 || string.indexOf('E') > -1) {
d = Double.valueOf(string);
if (!d.isInfinite() && !d.isNaN()) {
return d;
}
} else {
Long myLong = new Long(string);
if (myLong == myLong.intValue()) {
return myLong.intValue();
} else {
return myLong;
}
}
} catch (Exception ignore) {
}
}
return string;
} }
public boolean isNull(String key) { public boolean isNull(String key) {
@ -458,49 +469,39 @@ public class JSONObject {
return NULL.equals(object) ? defaultValue : object.toString(); return NULL.equals(object) ? defaultValue : object.toString();
} }
public static String valueToString(Object value) throws JSONException {
private void populateMap(Object bean) { if (value == null || value == null) {
Class klass = bean.getClass(); return "null";
boolean includeSuperClass = klass.getClassLoader() != null; }
if (value instanceof JSONString) {
Method[] methods = includeSuperClass Object object;
? klass.getMethods()
: klass.getDeclaredMethods();
for (int i = 0; i < methods.length; i += 1) {
try { try {
Method method = methods[i]; object = ((JSONString) value).toJSONString();
if (Modifier.isPublic(method.getModifiers())) { } catch (Exception e) {
String name = method.getName(); throw new JSONException(e);
String key = "";
if (name.startsWith("get")) {
if ("getClass".equals(name) ||
"getDeclaringClass".equals(name)) {
key = "";
} else {
key = name.substring(3);
} }
} else if (name.startsWith("is")) { if (object instanceof String) {
key = name.substring(2); return (String) object;
} }
if (key.length() > 0 && throw new JSONException("Bad value from toJSONString: " + object);
Character.isUpperCase(key.charAt(0)) &&
method.getParameterTypes().length == 0) {
if (key.length() == 1) {
key = key.toLowerCase();
} else if (!Character.isUpperCase(key.charAt(1))) {
key = key.substring(0, 1).toLowerCase() +
key.substring(1);
} }
if (value instanceof Number) {
Object result = method.invoke(bean, (Object[])null); return numberToString((Number) value);
if (result != null) {
this.map.put(key, wrap(result));
} }
if (value instanceof Boolean || value instanceof JSONObject ||
value instanceof JSONArray) {
return value.toString();
} }
if (value instanceof Map) {
return new JSONObject((Map) value).toString();
} }
} catch (Exception ignore) { if (value instanceof Collection) {
return new JSONArray((Collection) value).toString();
} }
if (value.getClass().isArray()) {
return new JSONArray(value).toString();
} }
return quote(value.toString());
} }
public JSONObject put(String key, boolean value) throws JSONException { public JSONObject put(String key, boolean value) throws JSONException {
@ -635,41 +636,37 @@ public class JSONObject {
return this.map.remove(key); return this.map.remove(key);
} }
public static Object stringToValue(String string) { static Writer writeValue(Writer writer, Object value,
Double d; int indentFactor, int indent) throws JSONException, IOException {
if (string.equals("")) { if (value == null || value == null) {
return string; writer.write("null");
} } else if (value instanceof JSONObject) {
if (string.equalsIgnoreCase("true")) { ((JSONObject) value).write(writer, indentFactor, indent);
return Boolean.TRUE; } else if (value instanceof JSONArray) {
} ((JSONArray) value).write(writer, indentFactor, indent);
if (string.equalsIgnoreCase("false")) { } else if (value instanceof Map) {
return Boolean.FALSE; new JSONObject((Map) value).write(writer, indentFactor, indent);
} } else if (value instanceof Collection) {
if (string.equalsIgnoreCase("null")) { new JSONArray((Collection) value).write(writer, indentFactor,
return JSONObject.NULL; indent);
} } else if (value.getClass().isArray()) {
char b = string.charAt(0); new JSONArray(value).write(writer, indentFactor, indent);
if ((b >= '0' && b <= '9') || b == '.' || b == '-' || b == '+') { } else if (value instanceof Number) {
writer.write(numberToString((Number) value));
} else if (value instanceof Boolean) {
writer.write(value.toString());
} else if (value instanceof JSONString) {
Object o;
try { try {
if (string.indexOf('.') > -1 || o = ((JSONString) value).toJSONString();
string.indexOf('e') > -1 || string.indexOf('E') > -1) { } catch (Exception e) {
d = Double.valueOf(string); throw new JSONException(e);
if (!d.isInfinite() && !d.isNaN()) {
return d;
} }
writer.write(o != null ? o.toString() : quote(value.toString()));
} else { } else {
Long myLong = new Long(string); quote(value.toString(), writer);
if (myLong.longValue() == myLong.intValue()) {
return new Integer(myLong.intValue());
} else {
return myLong;
} }
} return writer;
} catch (Exception ignore) {
}
}
return string;
} }
public static void testValidity(Object o) throws JSONException { public static void testValidity(Object o) throws JSONException {
@ -714,39 +711,10 @@ public class JSONObject {
} }
} }
public static String valueToString(Object value) throws JSONException { static void indent(Writer writer, int indent) throws IOException {
if (value == null || value.equals(null)) { for (int i = 0; i < indent; i += 1) {
return "null"; writer.write(' ');
} }
if (value instanceof JSONString) {
Object object;
try {
object = ((JSONString)value).toJSONString();
} catch (Exception e) {
throw new JSONException(e);
}
if (object instanceof String) {
return (String)object;
}
throw new JSONException("Bad value from toJSONString: " + object);
}
if (value instanceof Number) {
return numberToString((Number) value);
}
if (value instanceof Boolean || value instanceof JSONObject ||
value instanceof JSONArray) {
return value.toString();
}
if (value instanceof Map) {
return new JSONObject((Map)value).toString();
}
if (value instanceof Collection) {
return new JSONArray((Collection)value).toString();
}
if (value.getClass().isArray()) {
return new JSONArray(value).toString();
}
return quote(value.toString());
} }
public static Object wrap(Object object) { public static Object wrap(Object object) {
@ -794,43 +762,65 @@ public class JSONObject {
return this.write(writer, 0, 0); return this.write(writer, 0, 0);
} }
public JSONObject increment(String key) throws JSONException {
static final Writer writeValue(Writer writer, Object value, Object value = this.opt(key);
int indentFactor, int indent) throws JSONException, IOException { if (value == null) {
if (value == null || value.equals(null)) { this.put(key, 1);
writer.write("null"); } else if (value instanceof Integer) {
} else if (value instanceof JSONObject) { this.put(key, (Integer) value + 1);
((JSONObject) value).write(writer, indentFactor, indent); } else if (value instanceof Long) {
} else if (value instanceof JSONArray) { this.put(key, (Long) value + 1);
((JSONArray) value).write(writer, indentFactor, indent); } else if (value instanceof Double) {
} else if (value instanceof Map) { this.put(key, (Double) value + 1);
new JSONObject((Map) value).write(writer, indentFactor, indent); } else if (value instanceof Float) {
} else if (value instanceof Collection) { this.put(key, (Float) value + 1);
new JSONArray((Collection) value).write(writer, indentFactor,
indent);
} else if (value.getClass().isArray()) {
new JSONArray(value).write(writer, indentFactor, indent);
} else if (value instanceof Number) {
writer.write(numberToString((Number) value));
} else if (value instanceof Boolean) {
writer.write(value.toString());
} else if (value instanceof JSONString) {
Object o;
try {
o = ((JSONString) value).toJSONString();
} catch (Exception e) {
throw new JSONException(e);
}
writer.write(o != null ? o.toString() : quote(value.toString()));
} else { } else {
quote(value.toString(), writer); throw new JSONException("Unable to increment [" + quote(key) + "].");
} }
return writer; return this;
} }
static final void indent(Writer writer, int indent) throws IOException { private void populateMap(Object bean) {
for (int i = 0; i < indent; i += 1) { Class klass = bean.getClass();
writer.write(' '); boolean includeSuperClass = klass.getClassLoader() != null;
Method[] methods = includeSuperClass
? klass.getMethods()
: klass.getDeclaredMethods();
for (Method method1 : methods) {
try {
Method method = method1;
if (Modifier.isPublic(method.getModifiers())) {
String name = method.getName();
String key = "";
if (name.startsWith("get")) {
if ("getClass".equals(name) ||
"getDeclaringClass".equals(name)) {
key = "";
} else {
key = name.substring(3);
}
} else if (name.startsWith("is")) {
key = name.substring(2);
}
if (key.length() > 0 &&
Character.isUpperCase(key.charAt(0)) &&
method.getParameterTypes().length == 0) {
if (key.length() == 1) {
key = key.toLowerCase();
} else if (!Character.isUpperCase(key.charAt(1))) {
key = key.substring(0, 1).toLowerCase() +
key.substring(1);
}
Object result = method.invoke(bean, (Object[]) null);
if (result != null) {
this.map.put(key, wrap(result));
}
}
}
} catch (Exception ignore) {
}
} }
} }

View File

@ -2,5 +2,5 @@ package me.skymc.taboolib.json;
public interface JSONString { public interface JSONString {
public String toJSONString(); String toJSONString();
} }

View File

@ -1,12 +1,7 @@
package me.skymc.taboolib.json; package me.skymc.taboolib.json;
import java.io.BufferedReader; import java.io.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
public class JSONTokener { public class JSONTokener {
@ -30,7 +25,7 @@ public class JSONTokener {
this.line = 1; this.line = 1;
} }
public JSONTokener(InputStream inputStream) throws JSONException { public JSONTokener(InputStream inputStream) {
this(new InputStreamReader(inputStream)); this(new InputStreamReader(inputStream));
} }
@ -143,7 +138,7 @@ public class JSONTokener {
public String nextString(char quote) throws JSONException { public String nextString(char quote) throws JSONException {
char c; char c;
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
for (;;) { for (;;) {
c = this.next(); c = this.next();
switch (c) { switch (c) {
@ -192,7 +187,7 @@ public class JSONTokener {
} }
public String nextTo(char delimiter) throws JSONException { public String nextTo(char delimiter) throws JSONException {
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
for (;;) { for (;;) {
char c = this.next(); char c = this.next();
if (c == delimiter || c == 0 || c == '\n' || c == '\r') { if (c == delimiter || c == 0 || c == '\n' || c == '\r') {
@ -207,7 +202,7 @@ public class JSONTokener {
public String nextTo(String delimiters) throws JSONException { public String nextTo(String delimiters) throws JSONException {
char c; char c;
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
for (;;) { for (;;) {
c = this.next(); c = this.next();
if (delimiters.indexOf(c) >= 0 || c == 0 || if (delimiters.indexOf(c) >= 0 || c == 0 ||
@ -237,7 +232,7 @@ public class JSONTokener {
return new JSONArray(this); return new JSONArray(this);
} }
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) { while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) {
sb.append(c); sb.append(c);
c = this.next(); c = this.next();

View File

@ -6,26 +6,26 @@ import java.util.Iterator;
@SuppressWarnings({"rawtypes"}) @SuppressWarnings({"rawtypes"})
public class XML { public class XML {
public static final Character AMP = new Character('&'); public static final Character AMP = '&';
public static final Character APOS = new Character('\''); public static final Character APOS = '\'';
public static final Character BANG = new Character('!'); public static final Character BANG = '!';
public static final Character EQ = new Character('='); public static final Character EQ = '=';
public static final Character GT = new Character('>'); public static final Character GT = '>';
public static final Character LT = new Character('<'); public static final Character LT = '<';
public static final Character QUEST = new Character('?'); public static final Character QUEST = '?';
public static final Character QUOT = new Character('"'); public static final Character QUOT = '"';
public static final Character SLASH = new Character('/'); public static final Character SLASH = '/';
public static String escape(String string) { public static String escape(String string) {
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
for (int i = 0, length = string.length(); i < length; i++) { for (int i = 0, length = string.length(); i < length; i++) {
char c = string.charAt(i); char c = string.charAt(i);
switch (c) { switch (c) {
@ -206,7 +206,7 @@ public class XML {
return JSONObject.NULL; return JSONObject.NULL;
} }
if ("0".equals(string)) { if ("0".equals(string)) {
return new Integer(0); return 0;
} }
try { try {
char initial = string.charAt(0); char initial = string.charAt(0);
@ -223,8 +223,8 @@ public class XML {
return Double.valueOf(string); return Double.valueOf(string);
} else if (string.indexOf('e') < 0 && string.indexOf('E') < 0) { } else if (string.indexOf('e') < 0 && string.indexOf('E') < 0) {
Long myLong = new Long(string); Long myLong = new Long(string);
if (myLong.longValue() == myLong.intValue()) { if (myLong == myLong.intValue()) {
return new Integer(myLong.intValue()); return myLong.intValue();
} else { } else {
return myLong; return myLong;
} }
@ -250,7 +250,7 @@ public class XML {
public static String toString(Object object, String tagName) public static String toString(Object object, String tagName)
throws JSONException { throws JSONException {
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
int i; int i;
JSONArray ja; JSONArray ja;
JSONObject jo; JSONObject jo;

View File

@ -21,7 +21,7 @@ public class XMLTokener extends JSONTokener {
public String nextCDATA() throws JSONException { public String nextCDATA() throws JSONException {
char c; char c;
int i; int i;
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
for (;;) { for (;;) {
c = next(); c = next();
if (end()) { if (end()) {
@ -65,7 +65,7 @@ public class XMLTokener extends JSONTokener {
} }
public Object nextEntity(char ampersand) throws JSONException { public Object nextEntity(char ampersand) throws JSONException {
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
for (;;) { for (;;) {
char c = next(); char c = next();
if (Character.isLetterOrDigit(c) || c == '#') { if (Character.isLetterOrDigit(c) || c == '#') {

View File

@ -1,27 +1,26 @@
package me.skymc.taboolib.jsonformatter; package me.skymc.taboolib.jsonformatter;
import me.skymc.taboolib.json.JSONArray;
import me.skymc.taboolib.json.JSONObject;
import me.skymc.taboolib.jsonformatter.click.ClickEvent;
import me.skymc.taboolib.jsonformatter.hover.HoverEvent;
import me.skymc.taboolib.nms.NMSUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import me.skymc.taboolib.json.JSONArray;
import me.skymc.taboolib.json.JSONObject;
import me.skymc.taboolib.jsonformatter.click.ClickEvent;
import me.skymc.taboolib.jsonformatter.hover.HoverEvent;
import me.skymc.taboolib.nms.NMSUtils;
public class JSONFormatter { public class JSONFormatter {
private JSONArray ja = new JSONArray(); private JSONArray ja = new JSONArray();
private Builder builder = new Builder(); private Builder builder = new Builder();
private String color = ""; private String color = "";
private List<JSONArray> all = new ArrayList<JSONArray>(); private List<JSONArray> all = new ArrayList<>();
private boolean newline = true; private boolean newline = true;
public JSONFormatter(){ public JSONFormatter(){
@ -102,7 +101,7 @@ public class JSONFormatter {
} }
public List<String> toJSONList(){ public List<String> toJSONList(){
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<>();
try{ try{
for(JSONArray ja : all){ for(JSONArray ja : all){
JSONObject jo = new JSONObject(); JSONObject jo = new JSONObject();
@ -133,7 +132,7 @@ public class JSONFormatter {
} }
public List<Object> toSerializedList(){ public List<Object> toSerializedList(){
List<Object> list = new ArrayList<Object>(); List<Object> list = new ArrayList<>();
try{ try{
for(String s : toJSONList()){ for(String s : toJSONList()){
list.add(a.invoke(null, s)); list.add(a.invoke(null, s));
@ -255,19 +254,19 @@ public class JSONFormatter {
public Object getPacket(){ public Object getPacket(){
try{ try{
return ppocc.newInstance(toSerialized()); return ppocc.newInstance(toSerialized());
}catch(Exception e){ } catch (Exception ignored) {
} }
return null; return null;
} }
public List<Object> getPacketList(){ public List<Object> getPacketList(){
List<Object> list = new ArrayList<Object>(); List<Object> list = new ArrayList<>();
try{ try{
for(Object o : toSerializedList()){ for(Object o : toSerializedList()){
list.add(ppocc.newInstance(o)); list.add(ppocc.newInstance(o));
} }
return list; return list;
}catch(Exception e){ } catch (Exception ignored) {
} }
return null; return null;
} }
@ -382,7 +381,7 @@ public class JSONFormatter {
public JSONObject toString(String color){ public JSONObject toString(String color){
return toString(color, new BuilderHelper(){ return toString(color, new BuilderHelper(){
@Override @Override
public void add(JSONObject jo) throws Exception{ public void add(JSONObject jo) {
} }
}); });
} }

View File

@ -1,20 +1,17 @@
package me.skymc.taboolib.jsonformatter.hover; package me.skymc.taboolib.jsonformatter.hover;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import me.skymc.taboolib.TabooLib; import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.inventory.ItemUtils; import me.skymc.taboolib.inventory.ItemUtils;
import me.skymc.taboolib.json.JSONObject; import me.skymc.taboolib.json.JSONObject;
import me.skymc.taboolib.nms.item.DabItemUtils; import me.skymc.taboolib.nms.item.DabItemUtils;
import me.skymc.taboolib.nms.item.IDabItemUtils; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
public class ShowItemEvent extends HoverEvent{ public class ShowItemEvent extends HoverEvent{
@ -35,17 +32,17 @@ public class ShowItemEvent extends HoverEvent{
StringBuilder tag = new StringBuilder(); StringBuilder tag = new StringBuilder();
Object itemTag = getItemTag(is); Object itemTag = getItemTag(is);
if (itemTag != null) { if (itemTag != null) {
tag.append(",tag:" + itemTag); tag.append(",tag:").append(itemTag);
} }
else { else {
ItemMeta im = is.getItemMeta(); ItemMeta im = is.getItemMeta();
List<String> lore = im.hasLore() ? im.getLore() : new ArrayList<>(); List<String> lore = im.hasLore() ? im.getLore() : new ArrayList<>();
Map<Enchantment, Integer> enchants = is.getItemMeta().getEnchants(); Map<Enchantment, Integer> enchants = is.getItemMeta().getEnchants();
tag.append(",tag:{display:{Name:" + (enchants.size() > 0 ? "§b§o" : "§f") + ItemUtils.getCustomName(is)); tag.append(",tag:{display:{Name:").append(enchants.size() > 0 ? "§b§o" : "§f").append(ItemUtils.getCustomName(is));
if (lore.size() > 0) { if (lore.size() > 0) {
tag.append(",Lore:["); tag.append(",Lore:[");
for (String s : lore){ for (String s : lore){
tag.append("\"" + s + "\","); tag.append("\"").append(s).append("\",");
} }
tag.delete(tag.length() - 1, tag.length()); tag.delete(tag.length() - 1, tag.length());
tag.append("]"); tag.append("]");
@ -57,7 +54,7 @@ public class ShowItemEvent extends HoverEvent{
} }
tag.append("ench:["); tag.append("ench:[");
for (Entry<Enchantment, Integer> e : enchants.entrySet()) { for (Entry<Enchantment, Integer> e : enchants.entrySet()) {
tag.append("{id:" + e.getKey().getId() + ",lvl:" + e.getValue() + "},"); tag.append("{id:").append(e.getKey().getId()).append(",lvl:").append(e.getValue()).append("},");
} }
tag.delete(tag.length() - 1, tag.length()); tag.delete(tag.length() - 1, tag.length());
tag.append("]"); tag.append("]");

View File

@ -1,26 +1,17 @@
package me.skymc.taboolib.listener; package me.skymc.taboolib.listener;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.server.ServerCommandEvent;
import me.skymc.taboolib.Main; import me.skymc.taboolib.Main;
import me.skymc.taboolib.TabooLib; import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.database.PlayerDataManager; import me.skymc.taboolib.database.PlayerDataManager;
import me.skymc.taboolib.inventory.ItemUtils;
import me.skymc.taboolib.itemnbtapi.NBTCompound;
import me.skymc.taboolib.itemnbtapi.NBTItem; import me.skymc.taboolib.itemnbtapi.NBTItem;
import me.skymc.taboolib.jsonformatter.JSONFormatter;
import me.skymc.taboolib.jsonformatter.click.RunCommandEvent;
import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent;
import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent;
import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.permission.PermissionUtils; import me.skymc.taboolib.permission.PermissionUtils;
import me.skymc.taboolib.playerdata.DataUtils; import me.skymc.taboolib.playerdata.DataUtils;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.server.ServerCommandEvent;
public class ListenerPlayerCommand implements Listener { public class ListenerPlayerCommand implements Listener {
@ -30,7 +21,7 @@ public class ListenerPlayerCommand implements Listener {
if (TabooLib.getVerint() > 10700) { if (TabooLib.getVerint() > 10700) {
e.setCancelled(true); e.setCancelled(true);
} }
Bukkit.getScheduler().runTask(Main.getInst(), () -> DataUtils.saveAllCaches()); Bukkit.getScheduler().runTask(Main.getInst(), DataUtils::saveAllCaches);
Bukkit.getScheduler().runTask(Main.getInst(), () -> PlayerDataManager.saveAllCaches(true, false)); Bukkit.getScheduler().runTask(Main.getInst(), () -> PlayerDataManager.saveAllCaches(true, false));
} }
} }

View File

@ -1,12 +1,10 @@
package me.skymc.taboolib.listener; package me.skymc.taboolib.listener;
import java.util.HashMap; import me.skymc.taboolib.events.PlayerJumpEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
@ -14,7 +12,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import me.skymc.taboolib.events.PlayerJumpEvent; import java.util.HashMap;
public class ListenerPlayerJump public class ListenerPlayerJump
implements Listener implements Listener
@ -31,17 +29,16 @@ public class ListenerPlayerJump
{ {
if (!this.cooldown.containsKey(event.getPlayer())) if (!this.cooldown.containsKey(event.getPlayer()))
{ {
this.cooldown.put(event.getPlayer(), Long.valueOf(System.currentTimeMillis() + 350L)); this.cooldown.put(event.getPlayer(), System.currentTimeMillis() + 350L);
PlayerJumpEvent evt = new PlayerJumpEvent(event.isCancelled(), event.getPlayer()); PlayerJumpEvent evt = new PlayerJumpEvent(event.isCancelled(), event.getPlayer());
Bukkit.getPluginManager().callEvent(evt); Bukkit.getPluginManager().callEvent(evt);
if (evt.isCancelled()) if (evt.isCancelled())
{ {
event.setCancelled(true); event.setCancelled(true);
} }
} } else if (this.cooldown.get(event.getPlayer()) <= System.currentTimeMillis())
else if (((Long)this.cooldown.get(event.getPlayer())).longValue() <= System.currentTimeMillis())
{ {
this.cooldown.put(event.getPlayer(), Long.valueOf(System.currentTimeMillis() + 350L)); this.cooldown.put(event.getPlayer(), System.currentTimeMillis() + 350L);
PlayerJumpEvent evt = new PlayerJumpEvent(event.isCancelled(), event.getPlayer()); PlayerJumpEvent evt = new PlayerJumpEvent(event.isCancelled(), event.getPlayer());
Bukkit.getPluginManager().callEvent(evt); Bukkit.getPluginManager().callEvent(evt);

View File

@ -1,15 +1,10 @@
package me.skymc.taboolib.listener; package me.skymc.taboolib.listener;
import me.skymc.taboolib.playerdata.DataUtils;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.scheduler.BukkitRunnable;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.database.PlayerDataManager;
import me.skymc.taboolib.playerdata.DataUtils;
public class ListenerPlayerQuit implements Listener{ public class ListenerPlayerQuit implements Listener{

View File

@ -1,19 +1,17 @@
package me.skymc.taboolib.listener; package me.skymc.taboolib.listener;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.scheduler.BukkitRunnable;
import me.skymc.taboolib.Main; import me.skymc.taboolib.Main;
import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.mysql.MysqlUtils; import me.skymc.taboolib.mysql.MysqlUtils;
import me.skymc.taboolib.mysql.protect.MySQLConnection; import me.skymc.taboolib.mysql.protect.MySQLConnection;
import me.skymc.taboolib.timecycle.TimeCycleManager; import me.skymc.taboolib.timecycle.TimeCycleManager;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.ArrayList;
import java.util.List;
public class ListenerPluginDisable implements Listener { public class ListenerPluginDisable implements Listener {

View File

@ -5,8 +5,6 @@ import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import me.skymc.taboolib.methods.MethodsUtils;
public class LocationUtils { public class LocationUtils {
/** /**

View File

@ -1,17 +1,14 @@
package me.skymc.taboolib.message; package me.skymc.taboolib.message;
import java.util.HashMap; import lombok.Getter;
import java.util.LinkedList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import lombok.Getter; import java.util.HashMap;
import java.util.LinkedList;
public class ChatCatcher implements Listener { public class ChatCatcher implements Listener {
@ -67,12 +64,12 @@ public class ChatCatcher implements Listener {
} }
} }
public abstract interface Catcher { public interface Catcher {
public abstract Catcher before(); Catcher before();
public abstract boolean after(String message); boolean after(String message);
public abstract void cancel(); void cancel();
} }
} }

View File

@ -9,11 +9,7 @@ public class MethodsUtils {
public static boolean checkUser(String packagename, String current) public static boolean checkUser(String packagename, String current)
{ {
if (current.substring(0, 8).equals(packagename)) return current.substring(0, 8).equals(packagename);
{
return true;
}
return false;
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@ -24,21 +20,13 @@ public class MethodsUtils {
throw new Error("未经允许的方法调用"); throw new Error("未经允许的方法调用");
} }
Class<? extends Object> clazz = classname.getClass(); Class<?> clazz = classname.getClass();
Method method = null; Method method = null;
try { try {
method = clazz.getDeclaredMethod(methodname, classes); method = clazz.getDeclaredMethod(methodname, classes);
method.setAccessible(true); method.setAccessible(true);
return new Object[] { method.invoke(classname, objects) }; return new Object[] { method.invoke(classname, objects) };
} catch (SecurityException e) { } catch (SecurityException | InvocationTargetException | IllegalAccessException | NoSuchMethodException | IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;
@ -51,20 +39,14 @@ public class MethodsUtils {
throw new Error("未经允许的方法调用"); throw new Error("未经允许的方法调用");
} }
Class<? extends Object> clazz = classname.getClass(); Class<?> clazz = classname.getClass();
Field field = null; Field field = null;
Object object = null; Object object = null;
try { try {
field = clazz.getDeclaredField(fieldname); field = clazz.getDeclaredField(fieldname);
field.setAccessible(true); field.setAccessible(true);
object = field.get(classname); object = field.get(classname);
} catch (NoSuchFieldException e) { } catch (NoSuchFieldException | IllegalAccessException | IllegalArgumentException | SecurityException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();
} }
return object; return object;

View File

@ -1,5 +1,7 @@
package me.skymc.taboolib.methods; package me.skymc.taboolib.methods;
import org.bukkit.Bukkit;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -7,8 +9,6 @@ import java.lang.reflect.Method;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.bukkit.Bukkit;
/** /**
* <b>ReflectionUtils</b> * <b>ReflectionUtils</b>
* <p> * <p>
@ -60,7 +60,6 @@ public final class ReflectionUtils {
* @return The constructor of the desired target class with the specified parameter types * @return The constructor of the desired target class with the specified parameter types
* @throws NoSuchMethodException If the desired constructor with the specified parameter types cannot be found * @throws NoSuchMethodException If the desired constructor with the specified parameter types cannot be found
* @throws ClassNotFoundException ClassNotFoundException If the desired target class with the specified name and package cannot be found * @throws ClassNotFoundException ClassNotFoundException If the desired target class with the specified name and package cannot be found
* @see #getClass(String, PackageType)
* @see #getConstructor(Class, Class...) * @see #getConstructor(Class, Class...)
*/ */
public static Constructor<?> getConstructor(String className, PackageType packageType, Class<?>... parameterTypes) throws NoSuchMethodException, ClassNotFoundException { public static Constructor<?> getConstructor(String className, PackageType packageType, Class<?>... parameterTypes) throws NoSuchMethodException, ClassNotFoundException {
@ -96,7 +95,6 @@ public final class ReflectionUtils {
* @throws InvocationTargetException If the desired constructor cannot be invoked * @throws InvocationTargetException If the desired constructor cannot be invoked
* @throws NoSuchMethodException If the desired constructor with the specified arguments cannot be found * @throws NoSuchMethodException If the desired constructor with the specified arguments cannot be found
* @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found * @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found
* @see #getClass(String, PackageType)
* @see #instantiateObject(Class, Object...) * @see #instantiateObject(Class, Object...)
*/ */
public static Object instantiateObject(String className, PackageType packageType, Object... arguments) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException { public static Object instantiateObject(String className, PackageType packageType, Object... arguments) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
@ -135,7 +133,6 @@ public final class ReflectionUtils {
* @return The method of the desired target class with the specified name and parameter types * @return The method of the desired target class with the specified name and parameter types
* @throws NoSuchMethodException If the desired method of the desired target class with the specified name and parameter types cannot be found * @throws NoSuchMethodException If the desired method of the desired target class with the specified name and parameter types cannot be found
* @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found * @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found
* @see #getClass(String, PackageType)
* @see #getMethod(Class, String, Class...) * @see #getMethod(Class, String, Class...)
*/ */
public static Method getMethod(String className, PackageType packageType, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException, ClassNotFoundException { public static Method getMethod(String className, PackageType packageType, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException, ClassNotFoundException {
@ -193,7 +190,6 @@ public final class ReflectionUtils {
* @throws InvocationTargetException If the desired method cannot be invoked on the target object * @throws InvocationTargetException If the desired method cannot be invoked on the target object
* @throws NoSuchMethodException If the desired method of the desired target class with the specified name and arguments cannot be found * @throws NoSuchMethodException If the desired method of the desired target class with the specified name and arguments cannot be found
* @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found * @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found
* @see #getClass(String, PackageType)
* @see #invokeMethod(Object, Class, String, Object...) * @see #invokeMethod(Object, Class, String, Object...)
*/ */
public static Object invokeMethod(Object instance, String className, PackageType packageType, String methodName, Object... arguments) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException { public static Object invokeMethod(Object instance, String className, PackageType packageType, String methodName, Object... arguments) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
@ -380,7 +376,7 @@ public final class ReflectionUtils {
* *
* @param path Path of the package * @param path Path of the package
*/ */
private PackageType(String path) { PackageType(String path) {
this.path = path; this.path = path;
} }
@ -390,7 +386,7 @@ public final class ReflectionUtils {
* @param parent Parent package of the package * @param parent Parent package of the package
* @param path Path of the package * @param path Path of the package
*/ */
private PackageType(PackageType parent, String path) { PackageType(PackageType parent, String path) {
this(parent + "." + path); this(parent + "." + path);
} }
@ -448,7 +444,7 @@ public final class ReflectionUtils {
DOUBLE(double.class, Double.class), DOUBLE(double.class, Double.class),
BOOLEAN(boolean.class, Boolean.class); BOOLEAN(boolean.class, Boolean.class);
private static final Map<Class<?>, DataType> CLASS_MAP = new HashMap<Class<?>, DataType>(); private static final Map<Class<?>, DataType> CLASS_MAP = new HashMap<>();
private final Class<?> primitive; private final Class<?> primitive;
private final Class<?> reference; private final Class<?> reference;
@ -466,7 +462,7 @@ public final class ReflectionUtils {
* @param primitive Primitive class of this data type * @param primitive Primitive class of this data type
* @param reference Reference class of this data type * @param reference Reference class of this data type
*/ */
private DataType(Class<?> primitive, Class<?> reference) { DataType(Class<?> primitive, Class<?> reference) {
this.primitive = primitive; this.primitive = primitive;
this.reference = reference; this.reference = reference;
} }
@ -554,7 +550,6 @@ public final class ReflectionUtils {
/** /**
* Returns the primitive class array of the given object array * Returns the primitive class array of the given object array
* *
* @param object Given object array
* @return The primitive class array * @return The primitive class array
*/ */
public static Class<?>[] getPrimitive(Object[] objects) { public static Class<?>[] getPrimitive(Object[] objects) {
@ -569,7 +564,6 @@ public final class ReflectionUtils {
/** /**
* Returns the reference class array of the given object array * Returns the reference class array of the given object array
* *
* @param object Given object array
* @return The reference class array * @return The reference class array
*/ */
public static Class<?>[] getReference(Object[] objects) { public static Class<?>[] getReference(Object[] objects) {

View File

@ -1,17 +1,9 @@
package me.skymc.taboolib.mysql; package me.skymc.taboolib.mysql;
import java.sql.Connection; import java.sql.*;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.bukkit.configuration.file.FileConfiguration;
import com.mysql.jdbc.PreparedStatement;
@Deprecated @Deprecated
public class MysqlConnection { public class MysqlConnection {
@ -56,8 +48,6 @@ public class MysqlConnection {
} }
Thread.sleep(30000); Thread.sleep(30000);
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -120,10 +110,10 @@ public class MysqlConnection {
for (int i = 0 ; i < list.length ; i++) { for (int i = 0 ; i < list.length ; i++) {
if (i + 1 < list.length) { if (i + 1 < list.length) {
stringBuilder.append("`" + checkString(list[i]) + "` varchar(255), "); stringBuilder.append("`").append(checkString(list[i])).append("` varchar(255), ");
} }
else { else {
stringBuilder.append("`" + checkString(list[i]) + "` varchar(255)"); stringBuilder.append("`").append(checkString(list[i])).append("` varchar(255)");
} }
} }
String url = "CREATE TABLE IF NOT EXISTS `" + table + "` ( " + stringBuilder + " )"; String url = "CREATE TABLE IF NOT EXISTS `" + table + "` ( " + stringBuilder + " )";
@ -150,12 +140,12 @@ public class MysqlConnection {
for (int i = 0 ; i < list.length ; i++) { for (int i = 0 ; i < list.length ; i++) {
if (i + 1 < list.length) { if (i + 1 < list.length) {
listbuilder.append("`" + checkString(list[i]) + "`, "); listbuilder.append("`").append(checkString(list[i])).append("`, ");
valuebuilder.append("'" + checkString(values[i]) + "', "); valuebuilder.append("'").append(checkString(values[i])).append("', ");
} }
else { else {
listbuilder.append("`" + checkString(list[i]) + "`"); listbuilder.append("`").append(checkString(list[i])).append("`");
valuebuilder.append("'" + checkString(values[i]) + "'"); valuebuilder.append("'").append(checkString(values[i])).append("'");
} }
} }

View File

@ -1,15 +1,12 @@
package me.skymc.taboolib.mysql; package me.skymc.taboolib.mysql;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.Plugin;
import me.skymc.taboolib.Main; import me.skymc.taboolib.Main;
import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.mysql.protect.MySQLConnection; import me.skymc.taboolib.mysql.protect.MySQLConnection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.Plugin;
import java.util.concurrent.CopyOnWriteArrayList;
public class MysqlUtils { public class MysqlUtils {

View File

@ -1,20 +1,15 @@
package me.skymc.taboolib.mysql.protect; package me.skymc.taboolib.mysql.protect;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import org.bukkit.plugin.Plugin;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import me.skymc.taboolib.Main; import me.skymc.taboolib.Main;
import org.bukkit.plugin.Plugin;
import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
public class MySQLConnection { public class MySQLConnection {
@ -69,19 +64,14 @@ public class MySQLConnection {
connect(); connect();
// 断线检测 // 断线检测
recheckThread = new Thread(new Runnable() { recheckThread = new Thread(() -> {
@Override
public void run() {
while (!Main.isDisable()) { while (!Main.isDisable()) {
try { try {
Thread.sleep(getReCheckSeconds() * 1000); Thread.sleep(getReCheckSeconds() * 1000);
if (connection == null) { if (connection == null) {
print("警告! 数据库尚未连接, 请检查配置文件后重启服务器! (" + (plugin.getName()) + ")"); print("警告! 数据库尚未连接, 请检查配置文件后重启服务器! (" + (plugin.getName()) + ")");
continue; } else {
}
else {
isExists("taboolib"); isExists("taboolib");
} }
} catch (Exception e) { } catch (Exception e) {
@ -89,7 +79,6 @@ public class MySQLConnection {
print("错误原因: " + e.getMessage()); print("错误原因: " + e.getMessage());
} }
} }
}
}); });
// 启动检测 // 启动检测
@ -266,7 +255,7 @@ public class MySQLConnection {
*/ */
public boolean intoValue(String name, Object... values) { public boolean intoValue(String name, Object... values) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (int i = 0 ; i < values.length ; i++) { for (Object value : values) {
sb.append("?, "); sb.append("?, ");
} }
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
@ -300,7 +289,7 @@ public class MySQLConnection {
public boolean createTable(String name, Column... columns) { public boolean createTable(String name, Column... columns) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (Column column : columns) { for (Column column : columns) {
sb.append(column.toString() + ", "); sb.append(column.toString()).append(", ");
} }
return execute("create table if not exists " + name + " (id int(1) not null primary key auto_increment, " + sb.substring(0, sb.length() - 2) + ")"); return execute("create table if not exists " + name + " (id int(1) not null primary key auto_increment, " + sb.substring(0, sb.length() - 2) + ")");
} }
@ -316,9 +305,9 @@ public class MySQLConnection {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (String column : columns) { for (String column : columns) {
if (!column.contains("/")) { if (!column.contains("/")) {
sb.append("`" + column + "` text, "); sb.append("`").append(column).append("` text, ");
} else { } else {
sb.append("`" + column.split("/")[0] + "` " + column.split("/")[1] + ", "); sb.append("`").append(column.split("/")[0]).append("` ").append(column.split("/")[1]).append(", ");
} }
} }
return execute("create table if not exists " + name + " (id int(1) not null primary key auto_increment, " + sb.substring(0, sb.length() - 2) + ")"); return execute("create table if not exists " + name + " (id int(1) not null primary key auto_increment, " + sb.substring(0, sb.length() - 2) + ")");
@ -750,24 +739,24 @@ public class MySQLConnection {
} }
} }
public static enum ColumnInteger { public enum ColumnInteger {
TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT; TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT
} }
public static enum ColumnFloat { public enum ColumnFloat {
FLOAT, DOUBLE; FLOAT, DOUBLE
} }
public static enum ColumnChar { public enum ColumnChar {
CHAR, VARCHAR; CHAR, VARCHAR
} }
public static enum ColumnString { public enum ColumnString {
TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT; TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT
} }
public static class Column { public static class Column {

View File

@ -1,10 +1,6 @@
package me.skymc.taboolib.nms; package me.skymc.taboolib.nms;
import org.bukkit.Bukkit; import org.bukkit.*;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
@ -915,7 +911,7 @@ public class NMSUtil18 {
// Testing Glow API based on ItemMetadata storage // Testing Glow API based on ItemMetadata storage
Object bukkitData = createNode(stack, "bukkit"); Object bukkitData = createNode(stack, "bukkit");
class_NBTTagCompound_setBooleanMethod.invoke(bukkitData, "glow", true); class_NBTTagCompound_setBooleanMethod.invoke(bukkitData, "glow", true);
} catch (Throwable ex) { } catch (Throwable ignored) {
} }
} }
@ -939,7 +935,7 @@ public class NMSUtil18 {
if (bukkitData != null) { if (bukkitData != null) {
class_NBTTagCompound_setBooleanMethod.invoke(bukkitData, "glow", false); class_NBTTagCompound_setBooleanMethod.invoke(bukkitData, "glow", false);
} }
} catch (Throwable ex) { } catch (Throwable ignored) {
} }
} }
@ -960,7 +956,7 @@ public class NMSUtil18 {
unbreakableFlag = class_NBTTagByte_legacy_constructor.newInstance("", (byte) 1); unbreakableFlag = class_NBTTagByte_legacy_constructor.newInstance("", (byte) 1);
} }
class_NBTTagCompound_setMethod.invoke(tagObject, "Unbreakable", unbreakableFlag); class_NBTTagCompound_setMethod.invoke(tagObject, "Unbreakable", unbreakableFlag);
} catch (Throwable ex) { } catch (Throwable ignored) {
} }
} }
@ -985,7 +981,7 @@ public class NMSUtil18 {
hideFlag = class_NBTTagByte_legacy_constructor.newInstance("", flags); hideFlag = class_NBTTagByte_legacy_constructor.newInstance("", flags);
} }
class_NBTTagCompound_setMethod.invoke(tagObject, "HideFlags", hideFlag); class_NBTTagCompound_setMethod.invoke(tagObject, "HideFlags", hideFlag);
} catch (Throwable ex) { } catch (Throwable ignored) {
} }
} }

View File

@ -1,12 +1,7 @@
package me.skymc.taboolib.nms; package me.skymc.taboolib.nms;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.*;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.MemorySection; import org.bukkit.configuration.MemorySection;
@ -24,12 +19,7 @@ import java.io.InputStream;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Collection; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
@SuppressWarnings({ "rawtypes", "unchecked" }) @SuppressWarnings({ "rawtypes", "unchecked" })
@ -1139,8 +1129,7 @@ public class NMSUtil19 {
} }
public static boolean hasMeta(ItemStack stack, String tag) { public static boolean hasMeta(ItemStack stack, String tag) {
if (NMSUtil19.isEmpty(stack)) return false; return !NMSUtil19.isEmpty(stack) && getNode(stack, tag) != null;
return getNode(stack, tag) != null;
} }
public static Object getTag(ItemStack itemStack) { public static Object getTag(ItemStack itemStack) {
@ -1474,7 +1463,7 @@ public class NMSUtil19 {
Object tagObject = getTag(craft); Object tagObject = getTag(craft);
if (tagObject == null) return false; if (tagObject == null) return false;
unbreakableFlag = getMetaBoolean(tagObject, "Unbreakable"); unbreakableFlag = getMetaBoolean(tagObject, "Unbreakable");
} catch (Throwable ex) { } catch (Throwable ignored) {
} }
@ -1493,7 +1482,7 @@ public class NMSUtil19 {
Object unbreakableFlag = null; Object unbreakableFlag = null;
unbreakableFlag = class_NBTTagByte_constructor.newInstance((byte) 1); unbreakableFlag = class_NBTTagByte_constructor.newInstance((byte) 1);
class_NBTTagCompound_setMethod.invoke(tagObject, "Unbreakable", unbreakableFlag); class_NBTTagCompound_setMethod.invoke(tagObject, "Unbreakable", unbreakableFlag);
} catch (Throwable ex) { } catch (Throwable ignored) {
} }
} }
@ -1514,7 +1503,7 @@ public class NMSUtil19 {
Object hideFlag = null; Object hideFlag = null;
hideFlag = class_NBTTagByte_constructor.newInstance(flags); hideFlag = class_NBTTagByte_constructor.newInstance(flags);
class_NBTTagCompound_setMethod.invoke(tagObject, "HideFlags", hideFlag); class_NBTTagCompound_setMethod.invoke(tagObject, "HideFlags", hideFlag);
} catch (Throwable ex) { } catch (Throwable ignored) {
} }
} }

View File

@ -1,14 +1,11 @@
package me.skymc.taboolib.nms; package me.skymc.taboolib.nms;
import org.bukkit.Bukkit;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Entity;
public class NMSUtils { public class NMSUtils {
@ -34,7 +31,7 @@ public class NMSUtils {
for(String s : strings){ for(String s : strings){
try{ try{
return getClassWithException(s); return getClassWithException(s);
}catch(Exception e){ } catch (Exception ignored) {
} }
} }
return null; return null;
@ -43,7 +40,7 @@ public class NMSUtils {
public static Class<?> getClassSilent(String name){ public static Class<?> getClassSilent(String name){
try{ try{
return getClassWithException(name); return getClassWithException(name);
}catch(Exception e){ } catch (Exception ignored) {
} }
return null; return null;
} }
@ -64,7 +61,7 @@ public class NMSUtils {
public static Class<?> getNMSClassSilent(String className){ public static Class<?> getNMSClassSilent(String className){
try{ try{
return getNMSClassWithException(className); return getNMSClassWithException(className);
}catch(Exception e){ } catch (Exception ignored) {
} }
return null; return null;
} }
@ -101,7 +98,7 @@ public class NMSUtils {
public static Class<?> getOBCClassSilent(String className){ public static Class<?> getOBCClassSilent(String className){
try{ try{
return getOBCClassWithException(className); return getOBCClassWithException(className);
}catch(Exception e){ } catch (Exception ignored) {
} }
return null; return null;
} }
@ -175,7 +172,7 @@ public class NMSUtils {
for(String name : names){ for(String name : names){
try{ try{
return getFieldWithException(clazz, name); return getFieldWithException(clazz, name);
}catch(Exception e){ } catch (Exception ignored) {
} }
} }
return null; return null;
@ -184,7 +181,7 @@ public class NMSUtils {
public static Field getFieldSilent(Class<?> clazz, String name){ public static Field getFieldSilent(Class<?> clazz, String name){
try{ try{
return getFieldWithException(clazz, name); return getFieldWithException(clazz, name);
}catch(Exception e){ } catch (Exception ignored) {
} }
return null; return null;
} }
@ -193,7 +190,7 @@ public class NMSUtils {
for(String name : names){ for(String name : names){
try{ try{
return getFieldWithException(clazz, name); return getFieldWithException(clazz, name);
}catch(Exception e){ } catch (Exception ignored) {
} }
} }
return null; return null;
@ -298,7 +295,7 @@ public class NMSUtils {
public static Method getMethodSilent(Class<?> clazz, String name, Class<?>... args){ public static Method getMethodSilent(Class<?> clazz, String name, Class<?>... args){
try{ try{
return getMethodWithException(clazz, name, args); return getMethodWithException(clazz, name, args);
}catch(Exception e){ } catch (Exception ignored) {
} }
return null; return null;
} }
@ -331,7 +328,7 @@ public class NMSUtils {
public static Class<?> getInnerClassSilent(Class<?> c, String className){ public static Class<?> getInnerClassSilent(Class<?> c, String className){
try{ try{
return getInnerClassWithException(c, className); return getInnerClassWithException(c, className);
}catch(Exception e){ } catch (Exception ignored) {
} }
return null; return null;
} }
@ -353,7 +350,7 @@ public class NMSUtils {
public static Constructor<?> getConstructorSilent(Class<?> clazz, Class<?>... args){ public static Constructor<?> getConstructorSilent(Class<?> clazz, Class<?>... args){
try{ try{
return getConstructor(clazz, args); return getConstructor(clazz, args);
}catch(Exception e){ } catch (Exception ignored) {
} }
return null; return null;
} }

View File

@ -1,22 +1,21 @@
package me.skymc.taboolib.nms.item; package me.skymc.taboolib.nms.item;
import java.lang.reflect.Method; import me.skymc.taboolib.Main;
import java.util.List; import me.skymc.taboolib.json.JSONArray;
import java.util.Map; import me.skymc.taboolib.json.JSONObject;
import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.nms.item.impl._164ItemUtils;
import me.skymc.taboolib.nms.item.impl._1710ItemUtils;
import me.skymc.taboolib.nms.item.impl._194ItemUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import me.skymc.taboolib.Main; import java.lang.reflect.Method;
import me.skymc.taboolib.json.JSONArray; import java.util.List;
import me.skymc.taboolib.json.JSONObject; import java.util.Map;
import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.nms.item.impl._194ItemUtils;
import me.skymc.taboolib.nms.item.impl._164ItemUtils;
import me.skymc.taboolib.nms.item.impl._1710ItemUtils;
public class DabItemUtils { public class DabItemUtils {
@ -32,21 +31,21 @@ public class DabItemUtils {
inst.convertItemStackToJSON(is); inst.convertItemStackToJSON(is);
MsgUtils.send("载入 1.9.4 Spigot 物品工具成功!"); MsgUtils.send("载入 1.9.4 Spigot 物品工具成功!");
return inst; return inst;
}catch(Exception e){ } catch (Exception ignored) {
} }
try{ try{
_1710ItemUtils inst = new _1710ItemUtils(); _1710ItemUtils inst = new _1710ItemUtils();
inst.convertItemStackToJSON(is); inst.convertItemStackToJSON(is);
MsgUtils.send("载入 1.7.10 Cauldron 物品工具成功!"); MsgUtils.send("载入 1.7.10 Cauldron 物品工具成功!");
return inst; return inst;
}catch(Exception e){ } catch (Exception ignored) {
} }
try{ try{
IDabItemUtils inst = new _164ItemUtils(); IDabItemUtils inst = new _164ItemUtils();
inst.convertItemStackToJSON(is); inst.convertItemStackToJSON(is);
MsgUtils.send("载入 1.6.4 Cauldron 物品工具成功!"); MsgUtils.send("载入 1.6.4 Cauldron 物品工具成功!");
return inst; return inst;
}catch(Exception e){ } catch (Exception ignored) {
} }
MsgUtils.send("&4物品工具载入失败, 插件已关闭!"); MsgUtils.send("&4物品工具载入失败, 插件已关闭!");
Bukkit.getPluginManager().disablePlugin(Main.getInst()); Bukkit.getPluginManager().disablePlugin(Main.getInst());

View File

@ -1,102 +1,171 @@
package me.skymc.taboolib.nms.item; package me.skymc.taboolib.nms.item;
import me.skymc.taboolib.json.JSONArray;
import me.skymc.taboolib.json.JSONObject;
import org.bukkit.inventory.ItemStack;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.bukkit.inventory.ItemStack;
import me.skymc.taboolib.json.JSONArray;
import me.skymc.taboolib.json.JSONObject;
public interface IDabItemUtils{ public interface IDabItemUtils{
//@formatter:off //@formatter:off
public boolean hasBanner(); boolean hasBanner();
public Object getNMSCopy(ItemStack is) throws Exception;
public boolean hasTag(Object is) throws Exception; Object getNMSCopy(ItemStack is) throws Exception;
public ItemStack asCraftMirror(Object nis) throws Exception;
public ItemStack asBukkitCopy(Object nmis) throws Exception; boolean hasTag(Object is) throws Exception;
public String getName(ItemStack is);
public Object getItem(Object nis) throws Exception; ItemStack asCraftMirror(Object nis) throws Exception;
public Method getA();
public String getRawName(ItemStack is); ItemStack asBukkitCopy(Object nmis) throws Exception;
public String getItemName(ItemStack is);
public Object getRegistry(); String getName(ItemStack is);
public String getMinecraftName(ItemStack is);
public Object getTag(Object is) throws Exception; Object getItem(Object nis) throws Exception;
public void setTag(Object is, Object tag1) throws Exception;
public boolean isEmpty(Object tag) throws Exception; Method getA();
public Object getMap(Object tag) throws Exception;
public void set(Object tag, String key, Object value) throws Exception; String getRawName(ItemStack is);
public void setString(Object tag, String key, String value) throws Exception;
public void setShort(Object tag, String key, short value) throws Exception; String getItemName(ItemStack is);
public void setInt(Object tag, String key, int i) throws Exception;
public void setDouble(Object tag, String key, double d) throws Exception; Object getRegistry();
public void setLong(Object tag, String key, long l) throws Exception;
public boolean hasKey(Object tag, String key) throws Exception; String getMinecraftName(ItemStack is);
public Object get(Object tag, String key) throws Exception;
public String getString(Object tag, String key) throws Exception; Object getTag(Object is) throws Exception;
public int getInt(Object tag, String key) throws Exception;
public double getDouble(Object tag, String key) throws Exception; void setTag(Object is, Object tag1) throws Exception;
public long getLong(Object tag, String key) throws Exception;
public short getShort(Object tag, String key) throws Exception; boolean isEmpty(Object tag) throws Exception;
public Object getNewNBTTagCompound() throws Exception;
public boolean hasAttributeModifiersKey(Object tag) throws Exception; Object getMap(Object tag) throws Exception;
public Object getList(Object tag) throws Exception;
public Object getList(Object tag, String name, int id) throws Exception; void set(Object tag, String key, Object value) throws Exception;
public boolean getUnbreakable(Object tag) throws Exception;
public void setUnbreakable(Object tag, boolean value) throws Exception; void setString(Object tag, String key, String value) throws Exception;
public Object getNewNBTTagList() throws Exception;
public void addToList(Object taglist, Object nbt) throws Exception; void setShort(Object tag, String key, short value) throws Exception;
public int getSize(Object list) throws Exception;
public Object get(Object tlist, int i) throws Exception; void setInt(Object tag, String key, int i) throws Exception;
public Object getNewNBTTagByte(byte value) throws Exception;
public Object getNewNBTTagByteArray(byte[] value) throws Exception; void setDouble(Object tag, String key, double d) throws Exception;
public Object getData(Object nbt) throws Exception;
public Object createData(Object value) throws Exception; void setLong(Object tag, String key, long l) throws Exception;
public Map<String, Object> convertCompoundTagToValueMap(Object nbt) throws Exception;
public List<Object> convertListTagToValueList(Object nbttl) throws Exception; boolean hasKey(Object tag, String key) throws Exception;
public Object convertValueMapToCompoundTag(Map<String, Object> map) throws Exception;
public Object convertValueListToListTag(List<Object> list) throws Exception; Object get(Object tag, String key) throws Exception;
String getString(Object tag, String key) throws Exception;
int getInt(Object tag, String key) throws Exception;
double getDouble(Object tag, String key) throws Exception;
long getLong(Object tag, String key) throws Exception;
short getShort(Object tag, String key) throws Exception;
Object getNewNBTTagCompound() throws Exception;
boolean hasAttributeModifiersKey(Object tag) throws Exception;
Object getList(Object tag) throws Exception;
Object getList(Object tag, String name, int id) throws Exception;
boolean getUnbreakable(Object tag) throws Exception;
void setUnbreakable(Object tag, boolean value) throws Exception;
Object getNewNBTTagList() throws Exception;
void addToList(Object taglist, Object nbt) throws Exception;
int getSize(Object list) throws Exception;
Object get(Object tlist, int i) throws Exception;
Object getNewNBTTagByte(byte value) throws Exception;
Object getNewNBTTagByteArray(byte[] value) throws Exception;
Object getData(Object nbt) throws Exception;
Object createData(Object value) throws Exception;
Map<String, Object> convertCompoundTagToValueMap(Object nbt) throws Exception;
List<Object> convertListTagToValueList(Object nbttl) throws Exception;
Object convertValueMapToCompoundTag(Map<String, Object> map) throws Exception;
Object convertValueListToListTag(List<Object> list) throws Exception;
@Deprecated @Deprecated
public void convertListTagToJSON(Object nbttl, JSONArray ja, JSONArray helper) throws Exception; void convertListTagToJSON(Object nbttl, JSONArray ja, JSONArray helper) throws Exception;
public void convertListTagToJSON(Object nbttl, JSONArray ja) throws Exception;
void convertListTagToJSON(Object nbttl, JSONArray ja) throws Exception;
@Deprecated @Deprecated
public void convertCompoundTagToJSON(Object nbt, JSONObject jo, JSONObject helper) throws Exception; void convertCompoundTagToJSON(Object nbt, JSONObject jo, JSONObject helper) throws Exception;
public void convertCompoundTagToJSON(Object nbt, JSONObject jo) throws Exception;
void convertCompoundTagToJSON(Object nbt, JSONObject jo) throws Exception;
@Deprecated @Deprecated
public Object convertJSONToCompoundTag(JSONObject jo, JSONObject helper) throws Exception; Object convertJSONToCompoundTag(JSONObject jo, JSONObject helper) throws Exception;
public Object convertJSONToCompoundTag(JSONObject jo) throws Exception;
Object convertJSONToCompoundTag(JSONObject jo) throws Exception;
@Deprecated @Deprecated
public Object convertJSONToListTag(JSONArray ja, JSONArray helper) throws Exception; Object convertJSONToListTag(JSONArray ja, JSONArray helper) throws Exception;
public Object convertJSONToListTag(JSONArray ja) throws Exception;
Object convertJSONToListTag(JSONArray ja) throws Exception;
@Deprecated @Deprecated
public Object getDataJSON(String key, Object nbt, JSONObject jo, JSONObject helper) throws Exception; Object getDataJSON(String key, Object nbt, JSONObject jo, JSONObject helper) throws Exception;
public JSONArray getDataJSON(Object nbt) throws Exception;
JSONArray getDataJSON(Object nbt) throws Exception;
@Deprecated @Deprecated
public Object getDataJSON(Object nbt, JSONArray ja, JSONArray helper) throws Exception; Object getDataJSON(Object nbt, JSONArray ja, JSONArray helper) throws Exception;
@Deprecated @Deprecated
public Object createDataJSON(String key, JSONObject jo, JSONObject helper) throws Exception; Object createDataJSON(String key, JSONObject jo, JSONObject helper) throws Exception;
public Object createDataJSON(String key, JSONObject jo) throws Exception;
public byte getByte(Object o); Object createDataJSON(String key, JSONObject jo) throws Exception;
public short getShort(Object o);
public int getInt(Object o); byte getByte(Object o);
public double getDouble(Object o);
public float getFloat(Object o); short getShort(Object o);
public long getLong(Object o);
int getInt(Object o);
double getDouble(Object o);
float getFloat(Object o);
long getLong(Object o);
@Deprecated @Deprecated
public Object createDataJSON(int key, JSONArray jo, JSONArray helper) throws Exception; Object createDataJSON(int key, JSONArray jo, JSONArray helper) throws Exception;
public Object createDataJSON(int key, JSONArray jo) throws Exception;
public boolean compareBaseTag(Object tag, Object tag1) throws Exception; Object createDataJSON(int key, JSONArray jo) throws Exception;
public boolean compareCompoundTag(Object tag, Object tag1) throws Exception;
public boolean compareListTag(Object tag, Object tag1) throws Exception; boolean compareBaseTag(Object tag, Object tag1) throws Exception;
public boolean compare(ItemStack is1, ItemStack is2);
public boolean canMerge(ItemStack add, ItemStack to); boolean compareCompoundTag(Object tag, Object tag1) throws Exception;
public boolean isModified(ItemStack is);
public void sortByMaterial(List<ItemStack> items); boolean compareListTag(Object tag, Object tag1) throws Exception;
public void sortByName(List<ItemStack> items);
public void sortByAmount(List<ItemStack> items); boolean compare(ItemStack is1, ItemStack is2);
public ItemStack convertJSONToItemStack(JSONObject jo) throws Exception;
public JSONObject convertItemStackToJSON(ItemStack is) throws Exception; boolean canMerge(ItemStack add, ItemStack to);
boolean isModified(ItemStack is);
void sortByMaterial(List<ItemStack> items);
void sortByName(List<ItemStack> items);
void sortByAmount(List<ItemStack> items);
ItemStack convertJSONToItemStack(JSONObject jo) throws Exception;
JSONObject convertItemStackToJSON(ItemStack is) throws Exception;
} }

View File

@ -1,26 +1,19 @@
package me.skymc.taboolib.nms.item.impl; package me.skymc.taboolib.nms.item.impl;
import java.lang.reflect.Constructor; import me.skymc.taboolib.json.JSONArray;
import java.lang.reflect.Field; import me.skymc.taboolib.json.JSONObject;
import java.lang.reflect.Method; import me.skymc.taboolib.nms.NMSUtils;
import java.util.ArrayList; import me.skymc.taboolib.nms.item.IDabItemUtils;
import java.util.Collections; import me.skymc.taboolib.nms.nbt.NBTConstants;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import me.skymc.taboolib.json.*; import java.lang.reflect.Constructor;
import me.skymc.taboolib.nms.NMSUtils; import java.lang.reflect.Field;
import me.skymc.taboolib.nms.item.IDabItemUtils; import java.lang.reflect.Method;
import me.skymc.taboolib.nms.nbt.NBTConstants; import java.util.*;
import java.util.Map.Entry;
public class _164ItemUtils implements IDabItemUtils{ public class _164ItemUtils implements IDabItemUtils{
@ -30,7 +23,7 @@ public class _164ItemUtils implements IDabItemUtils{
try{ try{
Material m = Material.valueOf("BANNER"); Material m = Material.valueOf("BANNER");
if(m != null){ return true; } if(m != null){ return true; }
}catch(Exception e){ } catch (Exception ignored) {
} }
return false; return false;
} }
@ -110,7 +103,7 @@ public class _164ItemUtils implements IDabItemUtils{
public Object getRegistry(){ public Object getRegistry(){
try{ try{
return NMSUtils.getFieldSilent(ni, "REGISTRY", "field_150901_e").get(null); return NMSUtils.getFieldSilent(ni, "REGISTRY", "field_150901_e").get(null);
}catch(Exception e){ } catch (Exception ignored) {
} }
return null; return null;
} }
@ -376,7 +369,7 @@ public class _164ItemUtils implements IDabItemUtils{
@SuppressWarnings({ "unchecked" }) @SuppressWarnings({ "unchecked" })
public Map<String, Object> convertCompoundTagToValueMap(Object nbt) throws Exception{ public Map<String, Object> convertCompoundTagToValueMap(Object nbt) throws Exception{
Map<String, Object> ret = new HashMap<String, Object>(); Map<String, Object> ret = new HashMap<>();
Map<String, Object> map = (Map<String, Object>)getMap(nbt); Map<String, Object> map = (Map<String, Object>)getMap(nbt);
for(Entry<String, Object> e : map.entrySet()){ for(Entry<String, Object> e : map.entrySet()){
Object nbti = e.getValue(); Object nbti = e.getValue();
@ -390,7 +383,7 @@ public class _164ItemUtils implements IDabItemUtils{
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public List<Object> convertListTagToValueList(Object nbttl) throws Exception{ public List<Object> convertListTagToValueList(Object nbttl) throws Exception{
List<Object> ret = new ArrayList<Object>(); List<Object> ret = new ArrayList<>();
List<Object> list = (List<Object>)nbtld.get(nbttl); List<Object> list = (List<Object>)nbtld.get(nbttl);
for(Object e : list){ for(Object e : list){
Object data = getData(e); Object data = getData(e);
@ -402,7 +395,7 @@ public class _164ItemUtils implements IDabItemUtils{
} }
public Object convertValueMapToCompoundTag(Map<String, Object> map) throws Exception{ public Object convertValueMapToCompoundTag(Map<String, Object> map) throws Exception{
Map<String, Object> value = new HashMap<String, Object>(); Map<String, Object> value = new HashMap<>();
for(Entry<String, Object> e : map.entrySet()){ for(Entry<String, Object> e : map.entrySet()){
value.put(e.getKey(), createData(e.getValue())); value.put(e.getKey(), createData(e.getValue()));
} }
@ -412,14 +405,14 @@ public class _164ItemUtils implements IDabItemUtils{
} }
public Object convertValueListToListTag(List<Object> list) throws Exception{ public Object convertValueListToListTag(List<Object> list) throws Exception{
List<Object> value = new ArrayList<Object>(); List<Object> value = new ArrayList<>();
for(Object e : list){ for(Object e : list){
value.add(createData(e)); value.add(createData(e));
} }
Object ret = getNewNBTTagList(); Object ret = getNewNBTTagList();
nbttcm.set(ret, value); nbttcm.set(ret, value);
if(value.size() > 0){ if(value.size() > 0){
nbtlt.set(ret, (byte)gti.invoke(value.get(0))); nbtlt.set(ret, gti.invoke(value.get(0)));
} }
return ret; return ret;
} }
@ -475,7 +468,7 @@ public class _164ItemUtils implements IDabItemUtils{
@Deprecated @Deprecated
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Object convertJSONToCompoundTag(JSONObject jo, JSONObject helper) throws Exception{ public Object convertJSONToCompoundTag(JSONObject jo, JSONObject helper) throws Exception{
Map<String, Object> value = new HashMap<String, Object>(); Map<String, Object> value = new HashMap<>();
Iterator<String> it = jo.keys(); Iterator<String> it = jo.keys();
while(it.hasNext()){ while(it.hasNext()){
String e = it.next(); String e = it.next();
@ -488,7 +481,7 @@ public class _164ItemUtils implements IDabItemUtils{
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Object convertJSONToCompoundTag(JSONObject jo) throws Exception{ public Object convertJSONToCompoundTag(JSONObject jo) throws Exception{
Map<String, Object> value = new HashMap<String, Object>(); Map<String, Object> value = new HashMap<>();
Iterator<String> it = jo.keys(); Iterator<String> it = jo.keys();
while(it.hasNext()){ while(it.hasNext()){
String e = it.next(); String e = it.next();
@ -509,7 +502,7 @@ public class _164ItemUtils implements IDabItemUtils{
Object ret = getNewNBTTagList(); Object ret = getNewNBTTagList();
nbtld.set(ret, value); nbtld.set(ret, value);
if(value.size() > 0){ if(value.size() > 0){
nbtlt.set(ret, (byte)gti.invoke(value.get(0))); nbtlt.set(ret, gti.invoke(value.get(0)));
} }
return ret; return ret;
} }
@ -523,7 +516,7 @@ public class _164ItemUtils implements IDabItemUtils{
Object ret = getNewNBTTagList(); Object ret = getNewNBTTagList();
nbtld.set(ret, value); nbtld.set(ret, value);
if(value.size() > 0){ if(value.size() > 0){
nbtlt.set(ret, (byte)gti.invoke(value.get(0))); nbtlt.set(ret, gti.invoke(value.get(0)));
} }
return ret; return ret;
} }
@ -742,7 +735,7 @@ public class _164ItemUtils implements IDabItemUtils{
public Object createDataJSON(String key, JSONObject jo) throws Exception{ public Object createDataJSON(String key, JSONObject jo) throws Exception{
JSONArray j = jo.getJSONArray(key); JSONArray j = jo.getJSONArray(key);
Object ret = null; Object ret = null;
int i = (int)j.getInt(0); int i = j.getInt(0);
switch(i){ switch(i){
case NBTConstants.TYPE_COMPOUND: case NBTConstants.TYPE_COMPOUND:
ret = convertJSONToCompoundTag(j.getJSONObject(1)); ret = convertJSONToCompoundTag(j.getJSONObject(1));
@ -889,7 +882,7 @@ public class _164ItemUtils implements IDabItemUtils{
public Object createDataJSON(int key, JSONArray jo) throws Exception{ public Object createDataJSON(int key, JSONArray jo) throws Exception{
JSONArray j = jo.getJSONArray(key); JSONArray j = jo.getJSONArray(key);
Object ret = null; Object ret = null;
int i = (int)j.getInt(0); int i = j.getInt(0);
switch(i){ switch(i){
case NBTConstants.TYPE_COMPOUND: case NBTConstants.TYPE_COMPOUND:
ret = convertJSONToCompoundTag(j.getJSONObject(1)); ret = convertJSONToCompoundTag(j.getJSONObject(1));
@ -970,7 +963,7 @@ public class _164ItemUtils implements IDabItemUtils{
case NBTConstants.TYPE_BYTE_ARRAY: case NBTConstants.TYPE_BYTE_ARRAY:
byte[] ba = (byte[])nbtbad.get(tag); byte[] ba = (byte[])nbtbad.get(tag);
byte[] ba1 = (byte[])nbtbad.get(tag1); byte[] ba1 = (byte[])nbtbad.get(tag1);
return ba.equals(ba1); return Arrays.equals(ba, ba1);
case NBTConstants.TYPE_STRING: case NBTConstants.TYPE_STRING:
String st = (String)nbtstd.get(tag); String st = (String)nbtstd.get(tag);
String st1 = (String)nbtstd.get(tag1); String st1 = (String)nbtstd.get(tag1);
@ -983,7 +976,7 @@ public class _164ItemUtils implements IDabItemUtils{
case NBTConstants.TYPE_INT_ARRAY: case NBTConstants.TYPE_INT_ARRAY:
int[] ia = (int[])nbtiad.get(tag); int[] ia = (int[])nbtiad.get(tag);
int[] ia1 = (int[])nbtiad.get(tag); int[] ia1 = (int[])nbtiad.get(tag);
return ia.equals(ia1); return Arrays.equals(ia, ia1);
} }
return false; return false;
} }
@ -1028,7 +1021,6 @@ public class _164ItemUtils implements IDabItemUtils{
cont = true; cont = true;
break; break;
} }
;
} }
if(!cont) if(!cont)
return false; return false;
@ -1041,7 +1033,7 @@ public class _164ItemUtils implements IDabItemUtils{
} }
public Map<Integer, Object> getAttributes(Object attribs) throws Exception{ public Map<Integer, Object> getAttributes(Object attribs) throws Exception{
Map<Integer, Object> r = new HashMap<Integer, Object>(); Map<Integer, Object> r = new HashMap<>();
for(int i = 0; i < getSize(attribs); i++){ for(int i = 0; i < getSize(attribs); i++){
Object compound = g.invoke(attribs, i); Object compound = g.invoke(attribs, i);
Object attrib = a.invoke(null, compound); Object attrib = a.invoke(null, compound);
@ -1058,23 +1050,18 @@ public class _164ItemUtils implements IDabItemUtils{
public boolean compare(ItemStack is1, ItemStack is2){ public boolean compare(ItemStack is1, ItemStack is2){
if(is1.getType().equals(is2.getType())){ if(is1.getType().equals(is2.getType())){
if(is1.getDurability() == is2.getDurability()){ if(is1.getDurability() == is2.getDurability()){
try{ try {
Object nis1 = getNMSCopy(is1); Object nis1 = getNMSCopy(is1);
Object nis2 = getNMSCopy(is2); Object nis2 = getNMSCopy(is2);
Object tis1 = getTag(nis1); Object tis1 = getTag(nis1);
Object tis2 = getTag(nis2); Object tis2 = getTag(nis2);
if(tis1 != null && tis2 == null){ if (tis1 != null && tis2 == null) {
if(isEmpty(tis1)) return isEmpty(tis1);
return true;
return false;
} }
if(tis1 == null && tis2 != null){ if (tis1 == null && tis2 != null) {
if(isEmpty(tis2)) return isEmpty(tis2);
return true;
return false;
} }
if(tis1 == null && tis2 == null){ return true; } return tis1 == null && tis2 == null || compareCompoundTag(tis1, tis2);
return compareCompoundTag(tis1, tis2);
}catch(Exception e){ }catch(Exception e){
e.printStackTrace(); e.printStackTrace();
} }
@ -1095,7 +1082,7 @@ public class _164ItemUtils implements IDabItemUtils{
} }
public void sortByMaterial(List<ItemStack> items){ public void sortByMaterial(List<ItemStack> items){
Collections.sort(items, new MaterialComparator()); items.sort(new MaterialComparator());
} }
public class MaterialComparator implements Comparator<ItemStack>{ public class MaterialComparator implements Comparator<ItemStack>{
@ -1106,7 +1093,7 @@ public class _164ItemUtils implements IDabItemUtils{
} }
public void sortByName(List<ItemStack> items){ public void sortByName(List<ItemStack> items){
Collections.sort(items, new NameComparator()); items.sort(new NameComparator());
} }
public class NameComparator implements Comparator<ItemStack>{ public class NameComparator implements Comparator<ItemStack>{
@ -1123,7 +1110,7 @@ public class _164ItemUtils implements IDabItemUtils{
} }
public void sortByAmount(List<ItemStack> items){ public void sortByAmount(List<ItemStack> items){
Collections.sort(items, new AmountComparator()); items.sort(new AmountComparator());
} }
public class AmountComparator implements Comparator<ItemStack>{ public class AmountComparator implements Comparator<ItemStack>{

View File

@ -1,25 +1,19 @@
package me.skymc.taboolib.nms.item.impl; package me.skymc.taboolib.nms.item.impl;
import java.lang.reflect.Constructor; import me.skymc.taboolib.json.JSONArray;
import java.lang.reflect.Field; import me.skymc.taboolib.json.JSONObject;
import java.lang.reflect.Method; import me.skymc.taboolib.nms.NMSUtils;
import java.util.ArrayList; import me.skymc.taboolib.nms.item.IDabItemUtils;
import java.util.Collections; import me.skymc.taboolib.nms.nbt.NBTConstants;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import me.skymc.taboolib.json.*; import java.lang.reflect.Constructor;
import me.skymc.taboolib.nms.NMSUtils; import java.lang.reflect.Field;
import me.skymc.taboolib.nms.item.IDabItemUtils; import java.lang.reflect.Method;
import me.skymc.taboolib.nms.nbt.NBTConstants; import java.util.*;
import java.util.Map.Entry;
public class _1710ItemUtils implements IDabItemUtils{ public class _1710ItemUtils implements IDabItemUtils{
@ -29,7 +23,7 @@ public class _1710ItemUtils implements IDabItemUtils{
try{ try{
Material m = Material.valueOf("BANNER"); Material m = Material.valueOf("BANNER");
if(m != null){ return true; } if(m != null){ return true; }
}catch(Exception e){ } catch (Exception ignored) {
} }
return false; return false;
} }
@ -109,7 +103,7 @@ public class _1710ItemUtils implements IDabItemUtils{
public Object getRegistry(){ public Object getRegistry(){
try{ try{
return NMSUtils.getFieldSilent(ni, "REGISTRY", "field_150901_e").get(null); return NMSUtils.getFieldSilent(ni, "REGISTRY", "field_150901_e").get(null);
}catch(Exception e){ } catch (Exception ignored) {
} }
return null; return null;
} }
@ -374,7 +368,7 @@ public class _1710ItemUtils implements IDabItemUtils{
@SuppressWarnings({ "unchecked" }) @SuppressWarnings({ "unchecked" })
public Map<String, Object> convertCompoundTagToValueMap(Object nbt) throws Exception{ public Map<String, Object> convertCompoundTagToValueMap(Object nbt) throws Exception{
Map<String, Object> ret = new HashMap<String, Object>(); Map<String, Object> ret = new HashMap<>();
Map<String, Object> map = (Map<String, Object>)getMap(nbt); Map<String, Object> map = (Map<String, Object>)getMap(nbt);
for(Entry<String, Object> e : map.entrySet()){ for(Entry<String, Object> e : map.entrySet()){
Object nbti = e.getValue(); Object nbti = e.getValue();
@ -388,7 +382,7 @@ public class _1710ItemUtils implements IDabItemUtils{
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public List<Object> convertListTagToValueList(Object nbttl) throws Exception{ public List<Object> convertListTagToValueList(Object nbttl) throws Exception{
List<Object> ret = new ArrayList<Object>(); List<Object> ret = new ArrayList<>();
List<Object> list = (List<Object>)nbtld.get(nbttl); List<Object> list = (List<Object>)nbtld.get(nbttl);
for(Object e : list){ for(Object e : list){
Object data = getData(e); Object data = getData(e);
@ -400,7 +394,7 @@ public class _1710ItemUtils implements IDabItemUtils{
} }
public Object convertValueMapToCompoundTag(Map<String, Object> map) throws Exception{ public Object convertValueMapToCompoundTag(Map<String, Object> map) throws Exception{
Map<String, Object> value = new HashMap<String, Object>(); Map<String, Object> value = new HashMap<>();
for(Entry<String, Object> e : map.entrySet()){ for(Entry<String, Object> e : map.entrySet()){
value.put(e.getKey(), createData(e.getValue())); value.put(e.getKey(), createData(e.getValue()));
} }
@ -410,14 +404,14 @@ public class _1710ItemUtils implements IDabItemUtils{
} }
public Object convertValueListToListTag(List<Object> list) throws Exception{ public Object convertValueListToListTag(List<Object> list) throws Exception{
List<Object> value = new ArrayList<Object>(); List<Object> value = new ArrayList<>();
for(Object e : list){ for(Object e : list){
value.add(createData(e)); value.add(createData(e));
} }
Object ret = getNewNBTTagList(); Object ret = getNewNBTTagList();
nbttcm.set(ret, value); nbttcm.set(ret, value);
if(value.size() > 0){ if(value.size() > 0){
nbtlt.set(ret, (byte)gti.invoke(value.get(0))); nbtlt.set(ret, gti.invoke(value.get(0)));
} }
return ret; return ret;
} }
@ -473,7 +467,7 @@ public class _1710ItemUtils implements IDabItemUtils{
@Deprecated @Deprecated
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Object convertJSONToCompoundTag(JSONObject jo, JSONObject helper) throws Exception{ public Object convertJSONToCompoundTag(JSONObject jo, JSONObject helper) throws Exception{
Map<String, Object> value = new HashMap<String, Object>(); Map<String, Object> value = new HashMap<>();
Iterator<String> it = jo.keys(); Iterator<String> it = jo.keys();
while(it.hasNext()){ while(it.hasNext()){
String e = it.next(); String e = it.next();
@ -486,7 +480,7 @@ public class _1710ItemUtils implements IDabItemUtils{
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Object convertJSONToCompoundTag(JSONObject jo) throws Exception{ public Object convertJSONToCompoundTag(JSONObject jo) throws Exception{
Map<String, Object> value = new HashMap<String, Object>(); Map<String, Object> value = new HashMap<>();
Iterator<String> it = jo.keys(); Iterator<String> it = jo.keys();
while(it.hasNext()){ while(it.hasNext()){
String e = it.next(); String e = it.next();
@ -507,7 +501,7 @@ public class _1710ItemUtils implements IDabItemUtils{
Object ret = getNewNBTTagList(); Object ret = getNewNBTTagList();
nbtld.set(ret, value); nbtld.set(ret, value);
if(value.size() > 0){ if(value.size() > 0){
nbtlt.set(ret, (byte)gti.invoke(value.get(0))); nbtlt.set(ret, gti.invoke(value.get(0)));
} }
return ret; return ret;
} }
@ -521,7 +515,7 @@ public class _1710ItemUtils implements IDabItemUtils{
Object ret = getNewNBTTagList(); Object ret = getNewNBTTagList();
nbtld.set(ret, value); nbtld.set(ret, value);
if(value.size() > 0){ if(value.size() > 0){
nbtlt.set(ret, (byte)gti.invoke(value.get(0))); nbtlt.set(ret, gti.invoke(value.get(0)));
} }
return ret; return ret;
} }
@ -740,7 +734,7 @@ public class _1710ItemUtils implements IDabItemUtils{
public Object createDataJSON(String key, JSONObject jo) throws Exception{ public Object createDataJSON(String key, JSONObject jo) throws Exception{
JSONArray j = jo.getJSONArray(key); JSONArray j = jo.getJSONArray(key);
Object ret = null; Object ret = null;
int i = (int)j.getInt(0); int i = j.getInt(0);
switch(i){ switch(i){
case NBTConstants.TYPE_COMPOUND: case NBTConstants.TYPE_COMPOUND:
ret = convertJSONToCompoundTag(j.getJSONObject(1)); ret = convertJSONToCompoundTag(j.getJSONObject(1));
@ -887,7 +881,7 @@ public class _1710ItemUtils implements IDabItemUtils{
public Object createDataJSON(int key, JSONArray jo) throws Exception{ public Object createDataJSON(int key, JSONArray jo) throws Exception{
JSONArray j = jo.getJSONArray(key); JSONArray j = jo.getJSONArray(key);
Object ret = null; Object ret = null;
int i = (int)j.getInt(0); int i = j.getInt(0);
switch(i){ switch(i){
case NBTConstants.TYPE_COMPOUND: case NBTConstants.TYPE_COMPOUND:
ret = convertJSONToCompoundTag(j.getJSONObject(1)); ret = convertJSONToCompoundTag(j.getJSONObject(1));
@ -968,7 +962,7 @@ public class _1710ItemUtils implements IDabItemUtils{
case NBTConstants.TYPE_BYTE_ARRAY: case NBTConstants.TYPE_BYTE_ARRAY:
byte[] ba = (byte[])nbtbad.get(tag); byte[] ba = (byte[])nbtbad.get(tag);
byte[] ba1 = (byte[])nbtbad.get(tag1); byte[] ba1 = (byte[])nbtbad.get(tag1);
return ba.equals(ba1); return Arrays.equals(ba, ba1);
case NBTConstants.TYPE_STRING: case NBTConstants.TYPE_STRING:
String st = (String)nbtstd.get(tag); String st = (String)nbtstd.get(tag);
String st1 = (String)nbtstd.get(tag1); String st1 = (String)nbtstd.get(tag1);
@ -981,7 +975,7 @@ public class _1710ItemUtils implements IDabItemUtils{
case NBTConstants.TYPE_INT_ARRAY: case NBTConstants.TYPE_INT_ARRAY:
int[] ia = (int[])nbtiad.get(tag); int[] ia = (int[])nbtiad.get(tag);
int[] ia1 = (int[])nbtiad.get(tag); int[] ia1 = (int[])nbtiad.get(tag);
return ia.equals(ia1); return Arrays.equals(ia, ia1);
} }
return false; return false;
} }
@ -1027,23 +1021,18 @@ public class _1710ItemUtils implements IDabItemUtils{
public boolean compare(ItemStack is1, ItemStack is2){ public boolean compare(ItemStack is1, ItemStack is2){
if(is1.getType().equals(is2.getType())){ if(is1.getType().equals(is2.getType())){
if(is1.getDurability() == is2.getDurability()){ if(is1.getDurability() == is2.getDurability()){
try{ try {
Object nis1 = getNMSCopy(is1); Object nis1 = getNMSCopy(is1);
Object nis2 = getNMSCopy(is2); Object nis2 = getNMSCopy(is2);
Object tis1 = getTag(nis1); Object tis1 = getTag(nis1);
Object tis2 = getTag(nis2); Object tis2 = getTag(nis2);
if(tis1 != null && tis2 == null){ if (tis1 != null && tis2 == null) {
if(isEmpty(tis1)) return isEmpty(tis1);
return true;
return false;
} }
if(tis1 == null && tis2 != null){ if (tis1 == null && tis2 != null) {
if(isEmpty(tis2)) return isEmpty(tis2);
return true;
return false;
} }
if(tis1 == null && tis2 == null){ return true; } return tis1 == null && tis2 == null || compareCompoundTag(tis1, tis2);
return compareCompoundTag(tis1, tis2);
}catch(Exception e){ }catch(Exception e){
e.printStackTrace(); e.printStackTrace();
} }
@ -1064,7 +1053,7 @@ public class _1710ItemUtils implements IDabItemUtils{
} }
public void sortByMaterial(List<ItemStack> items){ public void sortByMaterial(List<ItemStack> items){
Collections.sort(items, new MaterialComparator()); items.sort(new MaterialComparator());
} }
public class MaterialComparator implements Comparator<ItemStack>{ public class MaterialComparator implements Comparator<ItemStack>{
@ -1075,7 +1064,7 @@ public class _1710ItemUtils implements IDabItemUtils{
} }
public void sortByName(List<ItemStack> items){ public void sortByName(List<ItemStack> items){
Collections.sort(items, new NameComparator()); items.sort(new NameComparator());
} }
public class NameComparator implements Comparator<ItemStack>{ public class NameComparator implements Comparator<ItemStack>{
@ -1092,7 +1081,7 @@ public class _1710ItemUtils implements IDabItemUtils{
} }
public void sortByAmount(List<ItemStack> items){ public void sortByAmount(List<ItemStack> items){
Collections.sort(items, new AmountComparator()); items.sort(new AmountComparator());
} }
public class AmountComparator implements Comparator<ItemStack>{ public class AmountComparator implements Comparator<ItemStack>{

View File

@ -1,25 +1,19 @@
package me.skymc.taboolib.nms.item.impl; package me.skymc.taboolib.nms.item.impl;
import java.lang.reflect.Constructor; import me.skymc.taboolib.json.JSONArray;
import java.lang.reflect.Field; import me.skymc.taboolib.json.JSONObject;
import java.lang.reflect.Method; import me.skymc.taboolib.nms.NMSUtils;
import java.util.ArrayList; import me.skymc.taboolib.nms.item.IDabItemUtils;
import java.util.Collections; import me.skymc.taboolib.nms.nbt.NBTConstants;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import me.skymc.taboolib.json.*; import java.lang.reflect.Constructor;
import me.skymc.taboolib.nms.NMSUtils; import java.lang.reflect.Field;
import me.skymc.taboolib.nms.item.IDabItemUtils; import java.lang.reflect.Method;
import me.skymc.taboolib.nms.nbt.NBTConstants; import java.util.*;
import java.util.Map.Entry;
public class _194ItemUtils implements IDabItemUtils{ public class _194ItemUtils implements IDabItemUtils{
@ -29,7 +23,7 @@ public class _194ItemUtils implements IDabItemUtils{
try{ try{
Material m = Material.valueOf("BANNER"); Material m = Material.valueOf("BANNER");
if(m != null){ return true; } if(m != null){ return true; }
}catch(Exception e){ } catch (Exception ignored) {
} }
return false; return false;
} }
@ -113,7 +107,7 @@ public class _194ItemUtils implements IDabItemUtils{
public Object getRegistry(){ public Object getRegistry(){
try{ try{
return NMSUtils.getFieldSilent(ni, "REGISTRY").get(null); return NMSUtils.getFieldSilent(ni, "REGISTRY").get(null);
}catch(Exception e){ } catch (Exception ignored) {
} }
return null; return null;
} }
@ -375,7 +369,7 @@ public class _194ItemUtils implements IDabItemUtils{
@SuppressWarnings({ "unchecked" }) @SuppressWarnings({ "unchecked" })
public Map<String, Object> convertCompoundTagToValueMap(Object nbt) throws Exception{ public Map<String, Object> convertCompoundTagToValueMap(Object nbt) throws Exception{
Map<String, Object> ret = new HashMap<String, Object>(); Map<String, Object> ret = new HashMap<>();
Map<String, Object> map = (Map<String, Object>)getMap(nbt); Map<String, Object> map = (Map<String, Object>)getMap(nbt);
for(Entry<String, Object> e : map.entrySet()){ for(Entry<String, Object> e : map.entrySet()){
Object nbti = e.getValue(); Object nbti = e.getValue();
@ -389,7 +383,7 @@ public class _194ItemUtils implements IDabItemUtils{
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public List<Object> convertListTagToValueList(Object nbttl) throws Exception{ public List<Object> convertListTagToValueList(Object nbttl) throws Exception{
List<Object> ret = new ArrayList<Object>(); List<Object> ret = new ArrayList<>();
List<Object> list = (List<Object>)nbtld.get(nbttl); List<Object> list = (List<Object>)nbtld.get(nbttl);
for(Object e : list){ for(Object e : list){
Object data = getData(e); Object data = getData(e);
@ -401,7 +395,7 @@ public class _194ItemUtils implements IDabItemUtils{
} }
public Object convertValueMapToCompoundTag(Map<String, Object> map) throws Exception{ public Object convertValueMapToCompoundTag(Map<String, Object> map) throws Exception{
Map<String, Object> value = new HashMap<String, Object>(); Map<String, Object> value = new HashMap<>();
for(Entry<String, Object> e : map.entrySet()){ for(Entry<String, Object> e : map.entrySet()){
value.put(e.getKey(), createData(e.getValue())); value.put(e.getKey(), createData(e.getValue()));
} }
@ -411,14 +405,14 @@ public class _194ItemUtils implements IDabItemUtils{
} }
public Object convertValueListToListTag(List<Object> list) throws Exception{ public Object convertValueListToListTag(List<Object> list) throws Exception{
List<Object> value = new ArrayList<Object>(); List<Object> value = new ArrayList<>();
for(Object e : list){ for(Object e : list){
value.add(createData(e)); value.add(createData(e));
} }
Object ret = getNewNBTTagList(); Object ret = getNewNBTTagList();
nbttcm.set(ret, value); nbttcm.set(ret, value);
if(value.size() > 0){ if(value.size() > 0){
nbtlt.set(ret, (byte)gti.invoke(value.get(0))); nbtlt.set(ret, gti.invoke(value.get(0)));
} }
return ret; return ret;
} }
@ -474,7 +468,7 @@ public class _194ItemUtils implements IDabItemUtils{
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Deprecated @Deprecated
public Object convertJSONToCompoundTag(JSONObject jo, JSONObject helper) throws Exception{ public Object convertJSONToCompoundTag(JSONObject jo, JSONObject helper) throws Exception{
Map<String, Object> value = new HashMap<String, Object>(); Map<String, Object> value = new HashMap<>();
Iterator<String> it = jo.keys(); Iterator<String> it = jo.keys();
while(it.hasNext()){ while(it.hasNext()){
String e = it.next(); String e = it.next();
@ -487,7 +481,7 @@ public class _194ItemUtils implements IDabItemUtils{
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Object convertJSONToCompoundTag(JSONObject jo) throws Exception{ public Object convertJSONToCompoundTag(JSONObject jo) throws Exception{
Map<String, Object> value = new HashMap<String, Object>(); Map<String, Object> value = new HashMap<>();
Iterator<String> it = jo.keys(); Iterator<String> it = jo.keys();
while(it.hasNext()){ while(it.hasNext()){
String e = it.next(); String e = it.next();
@ -508,7 +502,7 @@ public class _194ItemUtils implements IDabItemUtils{
Object ret = getNewNBTTagList(); Object ret = getNewNBTTagList();
nbtld.set(ret, value); nbtld.set(ret, value);
if(value.size() > 0){ if(value.size() > 0){
nbtlt.set(ret, (byte)gti.invoke(value.get(0))); nbtlt.set(ret, gti.invoke(value.get(0)));
} }
return ret; return ret;
} }
@ -522,7 +516,7 @@ public class _194ItemUtils implements IDabItemUtils{
Object ret = getNewNBTTagList(); Object ret = getNewNBTTagList();
nbtld.set(ret, value); nbtld.set(ret, value);
if(value.size() > 0){ if(value.size() > 0){
nbtlt.set(ret, (byte)gti.invoke(value.get(0))); nbtlt.set(ret, gti.invoke(value.get(0)));
} }
return ret; return ret;
} }
@ -743,7 +737,7 @@ public class _194ItemUtils implements IDabItemUtils{
public Object createDataJSON(String key, JSONObject jo) throws Exception{ public Object createDataJSON(String key, JSONObject jo) throws Exception{
JSONArray j = jo.getJSONArray(key); JSONArray j = jo.getJSONArray(key);
Object ret = null; Object ret = null;
int i = (int)j.getInt(0); int i = j.getInt(0);
switch(i){ switch(i){
case NBTConstants.TYPE_COMPOUND: case NBTConstants.TYPE_COMPOUND:
ret = convertJSONToCompoundTag(j.getJSONObject(1)); ret = convertJSONToCompoundTag(j.getJSONObject(1));
@ -891,7 +885,7 @@ public class _194ItemUtils implements IDabItemUtils{
public Object createDataJSON(int key, JSONArray jo) throws Exception{ public Object createDataJSON(int key, JSONArray jo) throws Exception{
JSONArray j = jo.getJSONArray(key); JSONArray j = jo.getJSONArray(key);
Object ret = null; Object ret = null;
int i = (int)j.getInt(0); int i = j.getInt(0);
switch(i){ switch(i){
case NBTConstants.TYPE_COMPOUND: case NBTConstants.TYPE_COMPOUND:
ret = convertJSONToCompoundTag(j.getJSONObject(1)); ret = convertJSONToCompoundTag(j.getJSONObject(1));
@ -972,7 +966,7 @@ public class _194ItemUtils implements IDabItemUtils{
case NBTConstants.TYPE_BYTE_ARRAY: case NBTConstants.TYPE_BYTE_ARRAY:
byte[] ba = (byte[])nbtbad.get(tag); byte[] ba = (byte[])nbtbad.get(tag);
byte[] ba1 = (byte[])nbtbad.get(tag1); byte[] ba1 = (byte[])nbtbad.get(tag1);
return ba.equals(ba1); return Arrays.equals(ba, ba1);
case NBTConstants.TYPE_STRING: case NBTConstants.TYPE_STRING:
String st = (String)nbtstd.get(tag); String st = (String)nbtstd.get(tag);
String st1 = (String)nbtstd.get(tag1); String st1 = (String)nbtstd.get(tag1);
@ -985,7 +979,7 @@ public class _194ItemUtils implements IDabItemUtils{
case NBTConstants.TYPE_INT_ARRAY: case NBTConstants.TYPE_INT_ARRAY:
int[] ia = (int[])nbtiad.get(tag); int[] ia = (int[])nbtiad.get(tag);
int[] ia1 = (int[])nbtiad.get(tag); int[] ia1 = (int[])nbtiad.get(tag);
return ia.equals(ia1); return Arrays.equals(ia, ia1);
} }
return false; return false;
} }
@ -1030,7 +1024,6 @@ public class _194ItemUtils implements IDabItemUtils{
cont = true; cont = true;
break; break;
} }
;
} }
if(!cont) if(!cont)
return false; return false;
@ -1041,23 +1034,18 @@ public class _194ItemUtils implements IDabItemUtils{
public boolean compare(ItemStack is1, ItemStack is2){ public boolean compare(ItemStack is1, ItemStack is2){
if(is1.getType().equals(is2.getType())){ if(is1.getType().equals(is2.getType())){
if(is1.getDurability() == is2.getDurability()){ if(is1.getDurability() == is2.getDurability()){
try{ try {
Object nis1 = getNMSCopy(is1); Object nis1 = getNMSCopy(is1);
Object nis2 = getNMSCopy(is2); Object nis2 = getNMSCopy(is2);
Object tis1 = getTag(nis1); Object tis1 = getTag(nis1);
Object tis2 = getTag(nis2); Object tis2 = getTag(nis2);
if(tis1 != null && tis2 == null){ if (tis1 != null && tis2 == null) {
if(isEmpty(tis1)) return isEmpty(tis1);
return true;
return false;
} }
if(tis1 == null && tis2 != null){ if (tis1 == null && tis2 != null) {
if(isEmpty(tis2)) return isEmpty(tis2);
return true;
return false;
} }
if(tis1 == null && tis2 == null){ return true; } return tis1 == null && tis2 == null || compareCompoundTag(tis1, tis2);
return compareCompoundTag(tis1, tis2);
}catch(Exception e){ }catch(Exception e){
e.printStackTrace(); e.printStackTrace();
} }
@ -1078,7 +1066,7 @@ public class _194ItemUtils implements IDabItemUtils{
} }
public void sortByMaterial(List<ItemStack> items){ public void sortByMaterial(List<ItemStack> items){
Collections.sort(items, new MaterialComparator()); items.sort(new MaterialComparator());
} }
public class MaterialComparator implements Comparator<ItemStack>{ public class MaterialComparator implements Comparator<ItemStack>{
@ -1089,7 +1077,7 @@ public class _194ItemUtils implements IDabItemUtils{
} }
public void sortByName(List<ItemStack> items){ public void sortByName(List<ItemStack> items){
Collections.sort(items, new NameComparator()); items.sort(new NameComparator());
} }
public class NameComparator implements Comparator<ItemStack>{ public class NameComparator implements Comparator<ItemStack>{
@ -1106,7 +1094,7 @@ public class _194ItemUtils implements IDabItemUtils{
} }
public void sortByAmount(List<ItemStack> items){ public void sortByAmount(List<ItemStack> items){
Collections.sort(items, new AmountComparator()); items.sort(new AmountComparator());
} }
public class AmountComparator implements Comparator<ItemStack>{ public class AmountComparator implements Comparator<ItemStack>{

View File

@ -4,9 +4,6 @@ import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class DateUtils { public class DateUtils {
/** /**

View File

@ -3,8 +3,6 @@ package me.skymc.taboolib.other;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.Random; import java.util.Random;
import me.skymc.taboolib.methods.MethodsUtils;
public class NumberUtils { public class NumberUtils {
private static Random rand = new Random(); private static Random rand = new Random();
@ -25,7 +23,7 @@ public class NumberUtils {
@Deprecated @Deprecated
public static boolean getChance(int a) { public static boolean getChance(int a) {
return getRandom() <= a ? true : false; return getRandom() <= a;
} }
public static int getRandomInteger(Number l, Number u) { public static int getRandomInteger(Number l, Number u) {

View File

@ -1,11 +1,9 @@
package me.skymc.taboolib.other; package me.skymc.taboolib.other;
import java.util.List;
import java.util.Random;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.object.WeightCategory; import me.skymc.taboolib.object.WeightCategory;
import java.util.List;
public class WeightUtils { public class WeightUtils {
public static String getStringByWeight(List<WeightCategory> categorys) { public static String getStringByWeight(List<WeightCategory> categorys) {

View File

@ -1,12 +1,11 @@
package me.skymc.taboolib.packet; package me.skymc.taboolib.packet;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.WrappedDataWatcher; import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
public class PacketUtils { public class PacketUtils {
@ -20,32 +19,34 @@ public class PacketUtils {
packet.getIntegers().write(0, entity.getEntityId()); packet.getIntegers().write(0, entity.getEntityId());
WrappedDataWatcher watcher = new WrappedDataWatcher(); WrappedDataWatcher watcher = new WrappedDataWatcher();
WrappedDataWatcher.Serializer serializer = WrappedDataWatcher.Registry.get(Byte.class); WrappedDataWatcher.Serializer serializer = WrappedDataWatcher.Registry.get(Byte.class);
if (status == EntityStatus.FIRE) { switch (status) {
case FIRE:
watcher.setObject(0, serializer, (byte) 0x01); watcher.setObject(0, serializer, (byte) 0x01);
} break;
else if (status == EntityStatus.CROUCHED) { case CROUCHED:
watcher.setObject(0, serializer, (byte) 0x02); watcher.setObject(0, serializer, (byte) 0x02);
} break;
else if (status == EntityStatus.UNUSED1) { case UNUSED1:
watcher.setObject(0, serializer, (byte) 0x04); watcher.setObject(0, serializer, (byte) 0x04);
} break;
else if (status == EntityStatus.SPRINTING) { case SPRINTING:
watcher.setObject(0, serializer, (byte) 0x08); watcher.setObject(0, serializer, (byte) 0x08);
} break;
else if (status == EntityStatus.UNUSED2) { case UNUSED2:
watcher.setObject(0, serializer, (byte) 0x10); watcher.setObject(0, serializer, (byte) 0x10);
} break;
else if (status == EntityStatus.INVISIBLE) { case INVISIBLE:
watcher.setObject(0, serializer, (byte) 0x20); watcher.setObject(0, serializer, (byte) 0x20);
} break;
else if (status == EntityStatus.GLOWING) { case GLOWING:
watcher.setObject(0, serializer, (byte) 0x40); watcher.setObject(0, serializer, (byte) 0x40);
} break;
else if (status == EntityStatus.ELYTRA) { case ELYTRA:
watcher.setObject(0, serializer, (byte) 0x80); watcher.setObject(0, serializer, (byte) 0x80);
} break;
else { default:
watcher.setObject(0, serializer, (byte) 0x00); watcher.setObject(0, serializer, (byte) 0x00);
break;
} }
packet.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects()); packet.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects());
try { try {

View File

@ -1,5 +1,7 @@
package me.skymc.taboolib.particle; package me.skymc.taboolib.particle;
import me.skymc.taboolib.methods.ReflectionUtils;
import me.skymc.taboolib.methods.ReflectionUtils.PackageType;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Color; import org.bukkit.Color;
import org.bukkit.Location; import org.bukkit.Location;
@ -7,9 +9,6 @@ import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import me.skymc.taboolib.methods.ReflectionUtils;
import me.skymc.taboolib.methods.ReflectionUtils.PackageType;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -406,8 +405,8 @@ public enum EffLib {
*/ */
SWEEP_ATTACK("sweepAttack", 45, 9); SWEEP_ATTACK("sweepAttack", 45, 9);
private static final Map<String, EffLib> NAME_MAP = new HashMap<String, EffLib>(); private static final Map<String, EffLib> NAME_MAP = new HashMap<>();
private static final Map<Integer, EffLib> ID_MAP = new HashMap<Integer, EffLib>(); private static final Map<Integer, EffLib> ID_MAP = new HashMap<>();
private final String name; private final String name;
private final int id; private final int id;
private final int requiredVersion; private final int requiredVersion;
@ -429,7 +428,7 @@ public enum EffLib {
* @param requiredVersion Version which is required (1.x) * @param requiredVersion Version which is required (1.x)
* @param properties Properties of this particle effect * @param properties Properties of this particle effect
*/ */
private EffLib(String name, int id, int requiredVersion, ParticleProperty... properties) { EffLib(String name, int id, int requiredVersion, ParticleProperty... properties) {
this.name = name; this.name = name;
this.id = id; this.id = id;
this.requiredVersion = requiredVersion; this.requiredVersion = requiredVersion;
@ -478,10 +477,7 @@ public enum EffLib {
* @return Whether the particle effect is supported or not * @return Whether the particle effect is supported or not
*/ */
public boolean isSupported() { public boolean isSupported() {
if (requiredVersion == -1) { return requiredVersion == -1 || ParticlePacket.getVersion() >= requiredVersion;
return true;
}
return ParticlePacket.getVersion() >= requiredVersion;
} }
/** /**
@ -933,7 +929,7 @@ public enum EffLib {
* @author DarkBlade12 * @author DarkBlade12
* @since 1.7 * @since 1.7
*/ */
public static enum ParticleProperty { public enum ParticleProperty {
/** /**
* The particle effect requires water to be displayed * The particle effect requires water to be displayed
*/ */
@ -949,7 +945,7 @@ public enum EffLib {
/** /**
* The particle effect uses the offsets as color values * The particle effect uses the offsets as color values
*/ */
COLORABLE; COLORABLE
} }
/** /**
@ -1393,7 +1389,6 @@ public enum EffLib {
* @param longDistance Indicates whether the maximum distance is increased from 256 to 65536 * @param longDistance Indicates whether the maximum distance is increased from 256 to 65536
* @param data Data of the effect * @param data Data of the effect
* @throws IllegalArgumentException If the speed is lower than 0 * @throws IllegalArgumentException If the speed is lower than 0
* @see #ParticleEffect(ParticleEffect, float, float, float, float, int, boolean, ParticleData)
*/ */
public ParticlePacket(EffLib effect, Vector direction, float speed, boolean longDistance, ParticleData data) throws IllegalArgumentException { public ParticlePacket(EffLib effect, Vector direction, float speed, boolean longDistance, ParticleData data) throws IllegalArgumentException {
this(effect, (float) direction.getX(), (float) direction.getY(), (float) direction.getZ(), speed, 0, longDistance, data); this(effect, (float) direction.getX(), (float) direction.getY(), (float) direction.getZ(), speed, 0, longDistance, data);
@ -1405,7 +1400,6 @@ public enum EffLib {
* @param effect Particle effect * @param effect Particle effect
* @param color Color of the particle * @param color Color of the particle
* @param longDistance Indicates whether the maximum distance is increased from 256 to 65536 * @param longDistance Indicates whether the maximum distance is increased from 256 to 65536
* @see #ParticleEffect(ParticleEffect, float, float, float, float, int, boolean, ParticleData)
*/ */
public ParticlePacket(EffLib effect, ParticleColor color, boolean longDistance) { public ParticlePacket(EffLib effect, ParticleColor color, boolean longDistance) {
this(effect, color.getValueX(), color.getValueY(), color.getValueZ(), 1, 0, longDistance, null); this(effect, color.getValueX(), color.getValueY(), color.getValueZ(), 1, 0, longDistance, null);

Some files were not shown because too many files have changed in this diff Show More