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
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
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;
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.Setter;
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.sub.itemlist.listener.ItemLibraryPatch;
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.PlayerDataManager;
import me.skymc.taboolib.economy.EcoUtils;
import me.skymc.taboolib.entity.EntityUtils;
import me.skymc.taboolib.fileutils.ConfigUtils;
import me.skymc.taboolib.inventory.ItemUtils;
import me.skymc.taboolib.inventory.speciaitem.SpecialItem;
import me.skymc.taboolib.javashell.JavaShell;
import me.skymc.taboolib.listener.ListenerNetWork;
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.listener.*;
import me.skymc.taboolib.message.ChatCatcher;
import me.skymc.taboolib.message.MsgUtils;
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.skript.SkriptHandler;
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.command.TLMCommands;
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 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")
public class Main extends JavaPlugin implements Listener {
@ -199,7 +194,7 @@ public class Main extends JavaPlugin implements Listener {
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);
// 插件联动
@ -322,7 +317,7 @@ public class Main extends JavaPlugin implements Listener {
}
}
public static enum StorageType {
LOCAL, SQL;
public enum StorageType {
LOCAL, SQL
}
}

View File

@ -1,13 +1,11 @@
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 net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import java.util.UUID;
public class TabooLib {

View File

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

View File

@ -1,16 +1,9 @@
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.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 AnvilContainer_V1_11_R1(EntityHuman player)
@ -31,7 +24,7 @@ public class AnvilContainer_V1_11_R1 extends ContainerAnvil {
EntityPlayer player = ((CraftPlayer)p).getHandle();
AnvilContainer_V1_11_R1 container = new AnvilContainer_V1_11_R1(player);
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.windowId = c;
player.activeContainer.addSlotListener(player);

View File

@ -1,16 +1,9 @@
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.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 AnvilContainer_V1_8_R3(EntityHuman player)
@ -31,7 +24,7 @@ public class AnvilContainer_V1_8_R3 extends ContainerAnvil {
EntityPlayer player = ((CraftPlayer)p).getHandle();
AnvilContainer_V1_8_R3 container = new AnvilContainer_V1_8_R3(player);
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.windowId = c;
player.activeContainer.addSlotListener(player);

View File

@ -1,16 +1,9 @@
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.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 AnvilContainer_V1_9_4(EntityHuman player)
@ -31,7 +24,7 @@ public class AnvilContainer_V1_9_4 extends ContainerAnvil {
EntityPlayer player = ((CraftPlayer)p).getHandle();
AnvilContainer_V1_9_4 container = new AnvilContainer_V1_9_4(player);
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.windowId = c;
player.activeContainer.addSlotListener(player);

View File

@ -17,13 +17,7 @@ import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
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.*;
import java.util.concurrent.Callable;
import java.util.logging.Level;
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
// 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() {
@Override
public void run() {
submitData();
}
});
Bukkit.getScheduler().runTask(plugin, () -> submitData());
}
}, 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
@ -263,9 +252,7 @@ public class Metrics {
data.put("plugins", pluginData);
// Create a new thread for the connection to the bStats server
new Thread(new Runnable() {
@Override
public void run() {
new Thread(() -> {
try {
// Send the data
sendData(data);
@ -275,7 +262,6 @@ public class Metrics {
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
}
}
}
}).start();
}

View File

@ -1,38 +1,15 @@
package me.skymc.taboolib.commands;
import java.util.HashMap;
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.*;
import me.skymc.taboolib.commands.sub.cycle.CycleCommand;
import me.skymc.taboolib.commands.sub.itemlist.ItemListCommand;
import me.skymc.taboolib.commands.sub.shell.ShellCommand;
import me.skymc.taboolib.commands.sub.sounds.SoundsCommand;
import me.skymc.taboolib.inventory.ItemUtils;
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{

View File

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

View File

@ -3,8 +3,8 @@ package me.skymc.taboolib.commands;
import org.bukkit.command.CommandSender;
@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;
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.jsonformatter.JSONFormatter;
import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent;
import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class AttributesCommand extends SubCommand {

View File

@ -1,19 +1,17 @@
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.commands.SubCommand;
import me.skymc.taboolib.jsonformatter.JSONFormatter;
import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent;
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 {

View File

@ -1,11 +1,5 @@
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.inventory.ItemUtils;
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.ShowTextEvent;
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 {

View File

@ -1,13 +1,11 @@
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.jsonformatter.JSONFormatter;
import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent;
import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class SlotCommand extends SubCommand {

View File

@ -1,13 +1,11 @@
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.message.MsgUtils;
import me.skymc.taboolib.team.TagManager;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
* @author sky

View File

@ -1,12 +1,8 @@
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.javashell.JavaShell;
import me.skymc.taboolib.message.MsgUtils;
import org.bukkit.command.CommandSender;
public class CycleCommand extends SubCommand {

View File

@ -1,20 +1,13 @@
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.database.GlobalDataManager;
import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.other.DateUtils;
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 org.bukkit.command.CommandSender;
import java.util.concurrent.TimeUnit;
public class CycleInfoCommand extends SubCommand {

View File

@ -1,19 +1,13 @@
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.javashell.JavaShell;
import me.skymc.taboolib.jsonformatter.JSONFormatter;
import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent;
import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent;
import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.timecycle.TimeCycle;
import me.skymc.taboolib.timecycle.TimeCycleManager;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class CycleListCommand extends SubCommand {

View File

@ -1,17 +1,15 @@
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.commands.SubCommand;
import me.skymc.taboolib.database.GlobalDataManager;
import me.skymc.taboolib.message.MsgUtils;
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 org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitRunnable;
public class CycleUpdateCommand extends SubCommand {

View File

@ -1,11 +1,7 @@
package me.skymc.taboolib.commands.sub.itemlist.listener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import me.skymc.taboolib.inventory.InventoryUtil;
import me.skymc.taboolib.inventory.ItemUtils;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@ -17,8 +13,10 @@ import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import me.skymc.taboolib.inventory.InventoryUtil;
import me.skymc.taboolib.inventory.ItemUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
/**
* @author sky
@ -26,27 +24,6 @@ import me.skymc.taboolib.inventory.ItemUtils;
*/
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());
int loop = 0;
Iterator<String> iterator = map.keySet().iterator();
while (iterator.hasNext()) {
String name = iterator.next();
for (String name : map.keySet()) {
if (loop >= (page - 1) * 28) {
if (loop < page * 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();
List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<>();
lore.add("§f");
@ -79,8 +55,7 @@ public class ItemLibraryPatch implements Listener {
inventory.setItem(slot, item);
}
holder.ITEMS_DATA.put(slot, name);
}
else {
} else {
break;
}
}
@ -96,6 +71,29 @@ public class ItemLibraryPatch implements Listener {
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 final int PAGE;

View File

@ -1,12 +1,8 @@
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.javashell.JavaShell;
import me.skymc.taboolib.message.MsgUtils;
import org.bukkit.command.CommandSender;
public class ShellCommand extends SubCommand {

View File

@ -1,12 +1,7 @@
package me.skymc.taboolib.commands.sub.sounds.listener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import me.skymc.taboolib.inventory.InventoryUtil;
import me.skymc.taboolib.inventory.ItemUtils;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Sound;
@ -19,8 +14,8 @@ import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import me.skymc.taboolib.inventory.InventoryUtil;
import me.skymc.taboolib.inventory.ItemUtils;
import java.util.Arrays;
import java.util.HashMap;
/**
* @author sky
@ -28,33 +23,6 @@ import me.skymc.taboolib.inventory.ItemUtils;
*/
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);
int loop = 0;
Iterator<Sound> iterator = Arrays.asList(Sound.values()).iterator();
while (iterator.hasNext()) {
Sound sound = iterator.next();
for (Sound sound : Arrays.asList(Sound.values())) {
if (loop >= (page - 1) * 28) {
if (loop < page * 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();
meta.setDisplayName("§f" + sound.name());
meta.setLore(Arrays.asList("", "§f左键: §71 音调", "§f左键: §72 音调"));
@ -80,8 +47,7 @@ public class SoundsLibraryPatch implements Listener {
inventory.setItem(slot, item);
}
holder.SOUNDS_DATA.put(slot, sound);
}
else {
} else {
break;
}
}
@ -97,6 +63,34 @@ public class SoundsLibraryPatch implements Listener {
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 final int PAGE;

View File

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

View File

@ -1,19 +1,13 @@
package me.skymc.taboolib.cooldown;
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 me.skymc.taboolib.message.MsgUtils;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.plugin.Plugin;
import me.skymc.taboolib.message.MsgUtils;
import java.util.concurrent.ConcurrentHashMap;
@Deprecated
public class CooldownUtils implements Listener {

View File

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

View File

@ -1,19 +1,12 @@
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.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.plugin.Plugin;
import me.skymc.taboolib.message.MsgUtils;
import java.util.concurrent.ConcurrentHashMap;
public class CooldownUtils2 implements Listener {

View File

@ -1,9 +1,9 @@
package me.skymc.taboolib.csvutils;
import java.nio.charset.*;
import java.text.*;
import java.io.*;
import java.util.*;
import java.nio.charset.Charset;
import java.text.NumberFormat;
import java.util.HashMap;
public class CsvReader
{
@ -503,7 +503,6 @@ public class CsvReader
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.");
}
continue;
}
} while (this.hasMoreData && this.startedColumn);
}
@ -714,7 +713,6 @@ public class CsvReader
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.");
}
continue;
}
} while (this.hasMoreData && this.startedColumn);
}
@ -881,7 +879,7 @@ public class CsvReader
this.dataBuffer.ColumnStart = this.dataBuffer.Position + 1;
}
public void endRecord() throws IOException {
public void endRecord() {
this.hasReadNextLine = true;
++this.currentRecord;
}
@ -960,8 +958,8 @@ public class CsvReader
if (this.initialized) {
this.inputStream.close();
}
} catch (Exception ignored) {
}
catch (Exception ex) {}
this.inputStream = null;
this.closed = true;
}

View File

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

View File

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

View File

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

View File

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

View File

@ -1,9 +1,12 @@
package me.skymc.taboolib.database;
import java.io.File;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.Main.StorageType;
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.OfflinePlayer;
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.scheduler.BukkitRunnable;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.Main.StorageType;
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 java.io.File;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public class PlayerDataManager implements Listener {
private static final ConcurrentHashMap<String, FileConfiguration> PLAYER_DATA = new ConcurrentHashMap<>();
public static enum UsernameType {
UUID, USERNAME;
public enum UsernameType {
UUID, USERNAME
}
/**

View File

@ -1,10 +1,10 @@
package me.skymc.taboolib.display;
import java.lang.reflect.Constructor;
import me.skymc.taboolib.TabooLib;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import me.skymc.taboolib.TabooLib;
import java.lang.reflect.Constructor;
public class ActionUtils {
@ -12,9 +12,9 @@ public class ActionUtils {
{
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);
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)
{
@ -43,7 +43,7 @@ public class ActionUtils {
}
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;
Object abPacket = null;
// 如果版本大于 1.11.0
@ -53,7 +53,7 @@ public class ActionUtils {
abPacket = ac.newInstance(ab, chatMessageType.getMethod("a", Byte.TYPE).invoke(null, (byte) 2));
} else {
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);
}

View File

@ -1,10 +1,8 @@
package me.skymc.taboolib.display;
import java.lang.reflect.Constructor;
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 {
@ -12,9 +10,9 @@ public class TitleUtils {
{
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);
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)
{
@ -53,29 +51,29 @@ public class TitleUtils {
if (title != 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 + "\"}" });
Constructor<?> subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[] { 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 chatTitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[]{String.class}).invoke(null, "{\"text\":\"" + title + "\"}");
Constructor<?> subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE);
Object titlePacket = subtitleConstructor.newInstance(e, chatTitle, fadeint, stayt, fadeoutt);
sendPacket(p, titlePacket);
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 + "\"}" });
subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[] { getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent") });
titlePacket = subtitleConstructor.newInstance(new Object[] { e, chatTitle });
chatTitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[]{String.class}).invoke(null, "{\"text\":\"" + title + "\"}");
subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"));
titlePacket = subtitleConstructor.newInstance(e, chatTitle);
sendPacket(p, titlePacket);
}
if (subtitle != 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 + "\"}" });
Constructor<?> subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[] { 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 chatSubtitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[]{String.class}).invoke(null, "{\"text\":\"" + title + "\"}");
Constructor<?> subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE);
Object subtitlePacket = subtitleConstructor.newInstance(e, chatSubtitle, fadeinst, stayst, fadeoutst);
sendPacket(p, subtitlePacket);
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 + "\"}" });
subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[] { 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) });
chatSubtitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[]{String.class}).invoke(null, "{\"text\":\"" + subtitle + "\"}");
subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE);
subtitlePacket = subtitleConstructor.newInstance(e, chatSubtitle, fadeinst, stayst, fadeoutst);
sendPacket(p, subtitlePacket);
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,15 +1,13 @@
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.File;
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
public class LogUtils {

View File

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

View File

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

View File

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

View File

@ -8,7 +8,7 @@ import org.bukkit.plugin.Plugin;
* @author sky
* @since 2018年2月17日 下午8:35:42
*/
public abstract interface AbstractSpecialItem {
public interface AbstractSpecialItem {
/**
* 当接口被载入
@ -25,14 +25,14 @@ public abstract interface AbstractSpecialItem {
*
* @return String
*/
abstract String getName();
String getName();
/**
* 获取载入插件
*
* @return {@link Plugin}
*/
abstract Plugin getPlugin();
Plugin getPlugin();
/**
* 是否进行点击事件
@ -42,5 +42,5 @@ public abstract interface AbstractSpecialItem {
* @param cursorItem 持有物品
* @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;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import lombok.Getter;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.inventory.ItemUtils;
import me.skymc.taboolib.message.MsgUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -12,10 +13,8 @@ import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.plugin.Plugin;
import lombok.Getter;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.inventory.ItemUtils;
import me.skymc.taboolib.message.MsgUtils;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
/**
* @author sky
@ -119,7 +118,7 @@ public class SpecialItem implements Listener {
* 载入所有已注册接口
*/
public void loadItems() {
ITEM_DATA.forEach(x -> x.onEnable());
ITEM_DATA.forEach(AbstractSpecialItem::onEnable);
isLoaded = true;
}
@ -127,7 +126,7 @@ public class SpecialItem implements Listener {
* 注销所有已注册接口
*/
public void unloadItems() {
ITEM_DATA.forEach(x -> x.onDisable());
ITEM_DATA.forEach(AbstractSpecialItem::onDisable);
ITEM_DATA.clear();
}
@ -147,33 +146,32 @@ public class SpecialItem implements Listener {
Player player = (Player) e.getWhoClicked();
for (AbstractSpecialItem specialitem : ITEM_DATA) {
for (SpecialItemResult result : specialitem.isCorrectClick(player, e.getCurrentItem(), e.getCursor())) {
if (result == SpecialItemResult.CANCEL) {
switch (result) {
case CANCEL:
e.setCancelled(true);
}
else if (result == SpecialItemResult.BREAK) {
break;
case BREAK:
return;
}
else if (result == SpecialItemResult.REMOVE_ITEM_CURRENT) {
case REMOVE_ITEM_CURRENT:
e.setCurrentItem(null);
}
else if (result == SpecialItemResult.REMOVE_ITEM_CURSOR) {
break;
case REMOVE_ITEM_CURSOR:
e.getWhoClicked().setItemOnCursor(null);
}
else if (result == SpecialItemResult.REMOVE_ITEM_CURRENT_AMOUNT_1) {
break;
case REMOVE_ITEM_CURRENT_AMOUNT_1:
if (e.getCurrentItem().getAmount() > 1) {
e.getCurrentItem().setAmount(e.getCurrentItem().getAmount() - 1);
}
else {
} else {
e.setCurrentItem(null);
}
}
else if (result == SpecialItemResult.REMOVE_ITEM_CURSOR_AMOUNT_1) {
break;
case REMOVE_ITEM_CURSOR_AMOUNT_1:
if (e.getCursor().getAmount() > 1) {
e.getCursor().setAmount(e.getCursor().getAmount() - 1);
}
else {
} else {
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;
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.FileOutputStream;
import java.io.InputStream;
@ -8,16 +17,6 @@ import java.lang.reflect.Method;
import java.util.Set;
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
public class NBTReflectionUtil {
@ -27,8 +26,7 @@ public class NBTReflectionUtil {
private static Class getCraftItemStack() {
try {
Class clazz = Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack");
return clazz;
return Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack");
} catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
return null;
@ -38,8 +36,7 @@ public class NBTReflectionUtil {
@SuppressWarnings("rawtypes")
private static Class getCraftEntity() {
try {
Class clazz = Class.forName("org.bukkit.craftbukkit." + version + ".entity.CraftEntity");
return clazz;
return Class.forName("org.bukkit.craftbukkit." + version + ".entity.CraftEntity");
} catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
return null;
@ -49,8 +46,7 @@ public class NBTReflectionUtil {
@SuppressWarnings("rawtypes")
protected static Class getNBTBase() {
try {
Class clazz = Class.forName("net.minecraft.server." + version + ".NBTBase");
return clazz;
return Class.forName("net.minecraft.server." + version + ".NBTBase");
} catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
return null;
@ -60,8 +56,7 @@ public class NBTReflectionUtil {
@SuppressWarnings("rawtypes")
protected static Class getNBTTagString() {
try {
Class clazz = Class.forName("net.minecraft.server." + version + ".NBTTagString");
return clazz;
return Class.forName("net.minecraft.server." + version + ".NBTTagString");
} catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
@ -72,8 +67,7 @@ public class NBTReflectionUtil {
@SuppressWarnings("rawtypes")
protected static Class getNMSItemStack() {
try {
Class clazz = Class.forName("net.minecraft.server." + version + ".ItemStack");
return clazz;
return Class.forName("net.minecraft.server." + version + ".ItemStack");
} catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
@ -84,8 +78,7 @@ public class NBTReflectionUtil {
@SuppressWarnings("rawtypes")
protected static Class getNBTTagCompound() {
try {
Class clazz = Class.forName("net.minecraft.server." + version + ".NBTTagCompound");
return clazz;
return Class.forName("net.minecraft.server." + version + ".NBTTagCompound");
} catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
@ -96,8 +89,7 @@ public class NBTReflectionUtil {
@SuppressWarnings("rawtypes")
protected static Class getNBTCompressedStreamTools() {
try {
Class clazz = Class.forName("net.minecraft.server." + version + ".NBTCompressedStreamTools");
return clazz;
return Class.forName("net.minecraft.server." + version + ".NBTCompressedStreamTools");
} catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
@ -108,8 +100,7 @@ public class NBTReflectionUtil {
@SuppressWarnings("rawtypes")
protected static Class getMojangsonParser() {
try {
Class c = Class.forName("net.minecraft.server." + version + ".MojangsonParser");
return c;
return Class.forName("net.minecraft.server." + version + ".MojangsonParser");
} catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
@ -120,8 +111,7 @@ public class NBTReflectionUtil {
@SuppressWarnings("rawtypes")
protected static Class getTileEntity() {
try {
Class clazz = Class.forName("net.minecraft.server." + version + ".TileEntity");
return clazz;
return Class.forName("net.minecraft.server." + version + ".TileEntity");
} catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
@ -132,8 +122,7 @@ public class NBTReflectionUtil {
@SuppressWarnings("rawtypes")
protected static Class getCraftWorld() {
try {
Class clazz = Class.forName("org.bukkit.craftbukkit." + version + ".CraftWorld");
return clazz;
return Class.forName("org.bukkit.craftbukkit." + version + ".CraftWorld");
} catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
@ -186,8 +175,7 @@ public class NBTReflectionUtil {
Method method;
try {
method = clazz.getMethod("asNMSCopy", ItemStack.class);
Object answer = method.invoke(clazz, item);
return answer;
return method.invoke(clazz, item);
} catch (Exception e) {
MsgUtils.warn("NBT 操作出现异常: §7" + e.getMessage());
}
@ -272,8 +260,7 @@ public class NBTReflectionUtil {
Method method;
try {
method = clazz.getMethod("getTag");
Object answer = method.invoke(nmsitem);
return answer;
return method.invoke(nmsitem);
} catch (Exception e) {
MsgUtils.warn("NBT 操作出现异常: §7" + e.getMessage());
}
@ -285,8 +272,7 @@ public class NBTReflectionUtil {
@SuppressWarnings("rawtypes")
Class clazz = getNMSItemStack();
try {
Object nmsstack = clazz.getConstructor(getNBTTagCompound()).newInstance(nbtcompound.getCompound());
return nmsstack;
return clazz.getConstructor(getNBTTagCompound()).newInstance(nbtcompound.getCompound());
} catch (Exception e) {
MsgUtils.warn("NBT 操作出现异常: §7" + e.getMessage());
}
@ -379,8 +365,7 @@ public class NBTReflectionUtil {
Method method;
try {
method = c.getMethod("getCompound", String.class);
Object answer = method.invoke(compound, name);
return answer;
return method.invoke(compound, name);
} catch (Exception e) {
MsgUtils.warn("NBT 操作出现异常: §7" + e.getMessage());
}
@ -403,11 +388,9 @@ public class NBTReflectionUtil {
method = workingtag.getClass().getMethod("set", String.class, getNBTBase());
method.invoke(workingtag, name, getNBTTagCompound().newInstance());
comp.setCompound(nbttag);
return;
} catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
}
return;
}
public static Boolean valideCompound(NBTCompound comp) {
@ -562,7 +545,6 @@ public class NBTReflectionUtil {
} catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
}
return;
}
public static byte[] getByteArray(NBTCompound comp, String key) {
@ -634,7 +616,7 @@ public class NBTReflectionUtil {
Method method;
try {
method = workingtag.getClass().getMethod("setFloat", String.class, float.class);
method.invoke(workingtag, key, (float) f);
method.invoke(workingtag, key, f);
comp.setCompound(rootnbttag);
} catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
@ -672,7 +654,7 @@ public class NBTReflectionUtil {
Method method;
try {
method = workingtag.getClass().getMethod("setLong", String.class, long.class);
method.invoke(workingtag, key, (long) f);
method.invoke(workingtag, key, f);
comp.setCompound(rootnbttag);
} catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
@ -710,7 +692,7 @@ public class NBTReflectionUtil {
Method method;
try {
method = workingtag.getClass().getMethod("setShort", String.class, short.class);
method.invoke(workingtag, key, (short) f);
method.invoke(workingtag, key, f);
comp.setCompound(rootnbttag);
} catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
@ -748,7 +730,7 @@ public class NBTReflectionUtil {
Method method;
try {
method = workingtag.getClass().getMethod("setByte", String.class, byte.class);
method.invoke(workingtag, key, (byte) f);
method.invoke(workingtag, key, f);
comp.setCompound(rootnbttag);
} catch (Exception ex) {
MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -6,26 +6,26 @@ import java.util.Iterator;
@SuppressWarnings({"rawtypes"})
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) {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
for (int i = 0, length = string.length(); i < length; i++) {
char c = string.charAt(i);
switch (c) {
@ -206,7 +206,7 @@ public class XML {
return JSONObject.NULL;
}
if ("0".equals(string)) {
return new Integer(0);
return 0;
}
try {
char initial = string.charAt(0);
@ -223,8 +223,8 @@ public class XML {
return Double.valueOf(string);
} else if (string.indexOf('e') < 0 && string.indexOf('E') < 0) {
Long myLong = new Long(string);
if (myLong.longValue() == myLong.intValue()) {
return new Integer(myLong.intValue());
if (myLong == myLong.intValue()) {
return myLong.intValue();
} else {
return myLong;
}
@ -250,7 +250,7 @@ public class XML {
public static String toString(Object object, String tagName)
throws JSONException {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
int i;
JSONArray ja;
JSONObject jo;

View File

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

View File

@ -1,27 +1,26 @@
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.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
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 {
private JSONArray ja = new JSONArray();
private Builder builder = new Builder();
private String color = "";
private List<JSONArray> all = new ArrayList<JSONArray>();
private List<JSONArray> all = new ArrayList<>();
private boolean newline = true;
public JSONFormatter(){
@ -102,7 +101,7 @@ public class JSONFormatter {
}
public List<String> toJSONList(){
List<String> list = new ArrayList<String>();
List<String> list = new ArrayList<>();
try{
for(JSONArray ja : all){
JSONObject jo = new JSONObject();
@ -133,7 +132,7 @@ public class JSONFormatter {
}
public List<Object> toSerializedList(){
List<Object> list = new ArrayList<Object>();
List<Object> list = new ArrayList<>();
try{
for(String s : toJSONList()){
list.add(a.invoke(null, s));
@ -255,19 +254,19 @@ public class JSONFormatter {
public Object getPacket(){
try{
return ppocc.newInstance(toSerialized());
}catch(Exception e){
} catch (Exception ignored) {
}
return null;
}
public List<Object> getPacketList(){
List<Object> list = new ArrayList<Object>();
List<Object> list = new ArrayList<>();
try{
for(Object o : toSerializedList()){
list.add(ppocc.newInstance(o));
}
return list;
}catch(Exception e){
} catch (Exception ignored) {
}
return null;
}
@ -382,7 +381,7 @@ public class JSONFormatter {
public JSONObject toString(String color){
return toString(color, new BuilderHelper(){
@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;
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.inventory.ItemUtils;
import me.skymc.taboolib.json.JSONObject;
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{
@ -35,17 +32,17 @@ public class ShowItemEvent extends HoverEvent{
StringBuilder tag = new StringBuilder();
Object itemTag = getItemTag(is);
if (itemTag != null) {
tag.append(",tag:" + itemTag);
tag.append(",tag:").append(itemTag);
}
else {
ItemMeta im = is.getItemMeta();
List<String> lore = im.hasLore() ? im.getLore() : new ArrayList<>();
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) {
tag.append(",Lore:[");
for (String s : lore){
tag.append("\"" + s + "\",");
tag.append("\"").append(s).append("\",");
}
tag.delete(tag.length() - 1, tag.length());
tag.append("]");
@ -57,7 +54,7 @@ public class ShowItemEvent extends HoverEvent{
}
tag.append("ench:[");
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.append("]");

View File

@ -1,26 +1,17 @@
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.TabooLib;
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.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.permission.PermissionUtils;
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 {
@ -30,7 +21,7 @@ public class ListenerPlayerCommand implements Listener {
if (TabooLib.getVerint() > 10700) {
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));
}
}

View File

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

View File

@ -1,15 +1,10 @@
package me.skymc.taboolib.listener;
import me.skymc.taboolib.playerdata.DataUtils;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
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{

View File

@ -1,19 +1,17 @@
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.message.MsgUtils;
import me.skymc.taboolib.mysql.MysqlUtils;
import me.skymc.taboolib.mysql.protect.MySQLConnection;
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 {

View File

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

View File

@ -1,17 +1,14 @@
package me.skymc.taboolib.message;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import org.bukkit.Bukkit;
import lombok.Getter;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import lombok.Getter;
import java.util.HashMap;
import java.util.LinkedList;
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)
{
if (current.substring(0, 8).equals(packagename))
{
return true;
}
return false;
return current.substring(0, 8).equals(packagename);
}
@SuppressWarnings("rawtypes")
@ -24,21 +20,13 @@ public class MethodsUtils {
throw new Error("未经允许的方法调用");
}
Class<? extends Object> clazz = classname.getClass();
Class<?> clazz = classname.getClass();
Method method = null;
try {
method = clazz.getDeclaredMethod(methodname, classes);
method.setAccessible(true);
return new Object[] { method.invoke(classname, objects) };
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
} catch (SecurityException | InvocationTargetException | IllegalAccessException | NoSuchMethodException | IllegalArgumentException e) {
e.printStackTrace();
}
return null;
@ -51,20 +39,14 @@ public class MethodsUtils {
throw new Error("未经允许的方法调用");
}
Class<? extends Object> clazz = classname.getClass();
Class<?> clazz = classname.getClass();
Field field = null;
Object object = null;
try {
field = clazz.getDeclaredField(fieldname);
field.setAccessible(true);
object = field.get(classname);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
} catch (NoSuchFieldException | IllegalAccessException | IllegalArgumentException | SecurityException e) {
e.printStackTrace();
}
return object;

View File

@ -1,5 +1,7 @@
package me.skymc.taboolib.methods;
import org.bukkit.Bukkit;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
@ -7,8 +9,6 @@ import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Bukkit;
/**
* <b>ReflectionUtils</b>
* <p>
@ -60,7 +60,6 @@ public final class ReflectionUtils {
* @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 ClassNotFoundException ClassNotFoundException If the desired target class with the specified name and package cannot be found
* @see #getClass(String, PackageType)
* @see #getConstructor(Class, Class...)
*/
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 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
* @see #getClass(String, PackageType)
* @see #instantiateObject(Class, Object...)
*/
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
* @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
* @see #getClass(String, PackageType)
* @see #getMethod(Class, String, Class...)
*/
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 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
* @see #getClass(String, PackageType)
* @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 {
@ -380,7 +376,7 @@ public final class ReflectionUtils {
*
* @param path Path of the package
*/
private PackageType(String path) {
PackageType(String path) {
this.path = path;
}
@ -390,7 +386,7 @@ public final class ReflectionUtils {
* @param parent Parent package of the package
* @param path Path of the package
*/
private PackageType(PackageType parent, String path) {
PackageType(PackageType parent, String path) {
this(parent + "." + path);
}
@ -448,7 +444,7 @@ public final class ReflectionUtils {
DOUBLE(double.class, Double.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<?> reference;
@ -466,7 +462,7 @@ public final class ReflectionUtils {
* @param primitive Primitive 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.reference = reference;
}
@ -554,7 +550,6 @@ public final class ReflectionUtils {
/**
* Returns the primitive class array of the given object array
*
* @param object Given object array
* @return The primitive class array
*/
public static Class<?>[] getPrimitive(Object[] objects) {
@ -569,7 +564,6 @@ public final class ReflectionUtils {
/**
* Returns the reference class array of the given object array
*
* @param object Given object array
* @return The reference class array
*/
public static Class<?>[] getReference(Object[] objects) {

View File

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

View File

@ -1,15 +1,12 @@
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.message.MsgUtils;
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 {

View File

@ -1,20 +1,15 @@
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.Setter;
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 {
@ -69,19 +64,14 @@ public class MySQLConnection {
connect();
// 断线检测
recheckThread = new Thread(new Runnable() {
@Override
public void run() {
recheckThread = new Thread(() -> {
while (!Main.isDisable()) {
try {
Thread.sleep(getReCheckSeconds() * 1000);
if (connection == null) {
print("警告! 数据库尚未连接, 请检查配置文件后重启服务器! (" + (plugin.getName()) + ")");
continue;
}
else {
} else {
isExists("taboolib");
}
} catch (Exception e) {
@ -89,7 +79,6 @@ public class MySQLConnection {
print("错误原因: " + e.getMessage());
}
}
}
});
// 启动检测
@ -266,7 +255,7 @@ public class MySQLConnection {
*/
public boolean intoValue(String name, Object... values) {
StringBuilder sb = new StringBuilder();
for (int i = 0 ; i < values.length ; i++) {
for (Object value : values) {
sb.append("?, ");
}
PreparedStatement pstmt = null;
@ -300,7 +289,7 @@ public class MySQLConnection {
public boolean createTable(String name, Column... columns) {
StringBuilder sb = new StringBuilder();
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) + ")");
}
@ -316,9 +305,9 @@ public class MySQLConnection {
StringBuilder sb = new StringBuilder();
for (String column : columns) {
if (!column.contains("/")) {
sb.append("`" + column + "` text, ");
sb.append("`").append(column).append("` text, ");
} 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) + ")");
@ -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 {

View File

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

View File

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

View File

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

View File

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

View File

@ -1,102 +1,171 @@
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.util.List;
import java.util.Map;
import org.bukkit.inventory.ItemStack;
import me.skymc.taboolib.json.JSONArray;
import me.skymc.taboolib.json.JSONObject;
public interface IDabItemUtils{
//@formatter:off
public boolean hasBanner();
public Object getNMSCopy(ItemStack is) throws Exception;
public boolean hasTag(Object is) throws Exception;
public ItemStack asCraftMirror(Object nis) throws Exception;
public ItemStack asBukkitCopy(Object nmis) throws Exception;
public String getName(ItemStack is);
public Object getItem(Object nis) throws Exception;
public Method getA();
public String getRawName(ItemStack is);
public String getItemName(ItemStack is);
public Object getRegistry();
public String getMinecraftName(ItemStack is);
public Object getTag(Object is) throws Exception;
public void setTag(Object is, Object tag1) throws Exception;
public boolean isEmpty(Object tag) throws Exception;
public Object getMap(Object tag) throws Exception;
public void set(Object tag, String key, Object value) throws Exception;
public void setString(Object tag, String key, String value) throws Exception;
public void setShort(Object tag, String key, short value) throws Exception;
public void setInt(Object tag, String key, int i) throws Exception;
public void setDouble(Object tag, String key, double d) throws Exception;
public void setLong(Object tag, String key, long l) throws Exception;
public boolean hasKey(Object tag, String key) throws Exception;
public Object get(Object tag, String key) throws Exception;
public String getString(Object tag, String key) throws Exception;
public int getInt(Object tag, String key) throws Exception;
public double getDouble(Object tag, String key) throws Exception;
public long getLong(Object tag, String key) throws Exception;
public short getShort(Object tag, String key) throws Exception;
public Object getNewNBTTagCompound() throws Exception;
public boolean hasAttributeModifiersKey(Object tag) throws Exception;
public Object getList(Object tag) throws Exception;
public Object getList(Object tag, String name, int id) throws Exception;
public boolean getUnbreakable(Object tag) throws Exception;
public void setUnbreakable(Object tag, boolean value) throws Exception;
public Object getNewNBTTagList() throws Exception;
public void addToList(Object taglist, Object nbt) throws Exception;
public int getSize(Object list) throws Exception;
public Object get(Object tlist, int i) throws Exception;
public Object getNewNBTTagByte(byte value) throws Exception;
public Object getNewNBTTagByteArray(byte[] value) throws Exception;
public Object getData(Object nbt) throws Exception;
public Object createData(Object value) throws Exception;
public Map<String, Object> convertCompoundTagToValueMap(Object nbt) throws Exception;
public List<Object> convertListTagToValueList(Object nbttl) throws Exception;
public Object convertValueMapToCompoundTag(Map<String, Object> map) throws Exception;
public Object convertValueListToListTag(List<Object> list) throws Exception;
boolean hasBanner();
Object getNMSCopy(ItemStack is) throws Exception;
boolean hasTag(Object is) throws Exception;
ItemStack asCraftMirror(Object nis) throws Exception;
ItemStack asBukkitCopy(Object nmis) throws Exception;
String getName(ItemStack is);
Object getItem(Object nis) throws Exception;
Method getA();
String getRawName(ItemStack is);
String getItemName(ItemStack is);
Object getRegistry();
String getMinecraftName(ItemStack is);
Object getTag(Object is) throws Exception;
void setTag(Object is, Object tag1) throws Exception;
boolean isEmpty(Object tag) throws Exception;
Object getMap(Object tag) throws Exception;
void set(Object tag, String key, Object value) throws Exception;
void setString(Object tag, String key, String value) throws Exception;
void setShort(Object tag, String key, short value) throws Exception;
void setInt(Object tag, String key, int i) throws Exception;
void setDouble(Object tag, String key, double d) throws Exception;
void setLong(Object tag, String key, long l) throws Exception;
boolean hasKey(Object tag, String key) 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
public 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, JSONArray helper) throws Exception;
void convertListTagToJSON(Object nbttl, JSONArray ja) throws Exception;
@Deprecated
public 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, JSONObject helper) throws Exception;
void convertCompoundTagToJSON(Object nbt, JSONObject jo) throws Exception;
@Deprecated
public Object convertJSONToCompoundTag(JSONObject jo, JSONObject helper) throws Exception;
public Object convertJSONToCompoundTag(JSONObject jo) throws Exception;
Object convertJSONToCompoundTag(JSONObject jo, JSONObject helper) throws Exception;
Object convertJSONToCompoundTag(JSONObject jo) throws Exception;
@Deprecated
public Object convertJSONToListTag(JSONArray ja, JSONArray helper) throws Exception;
public Object convertJSONToListTag(JSONArray ja) throws Exception;
Object convertJSONToListTag(JSONArray ja, JSONArray helper) throws Exception;
Object convertJSONToListTag(JSONArray ja) throws Exception;
@Deprecated
public Object getDataJSON(String key, Object nbt, JSONObject jo, JSONObject helper) throws Exception;
public JSONArray getDataJSON(Object nbt) throws Exception;
Object getDataJSON(String key, Object nbt, JSONObject jo, JSONObject helper) throws Exception;
JSONArray getDataJSON(Object nbt) throws Exception;
@Deprecated
public Object getDataJSON(Object nbt, JSONArray ja, JSONArray helper) throws Exception;
Object getDataJSON(Object nbt, JSONArray ja, JSONArray helper) throws Exception;
@Deprecated
public Object createDataJSON(String key, JSONObject jo, JSONObject helper) throws Exception;
public Object createDataJSON(String key, JSONObject jo) throws Exception;
public byte getByte(Object o);
public short getShort(Object o);
public int getInt(Object o);
public double getDouble(Object o);
public float getFloat(Object o);
public long getLong(Object o);
Object createDataJSON(String key, JSONObject jo, JSONObject helper) throws Exception;
Object createDataJSON(String key, JSONObject jo) throws Exception;
byte getByte(Object o);
short getShort(Object o);
int getInt(Object o);
double getDouble(Object o);
float getFloat(Object o);
long getLong(Object o);
@Deprecated
public 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;
public boolean compareCompoundTag(Object tag, Object tag1) throws Exception;
public boolean compareListTag(Object tag, Object tag1) throws Exception;
public boolean compare(ItemStack is1, ItemStack is2);
public boolean canMerge(ItemStack add, ItemStack to);
public boolean isModified(ItemStack is);
public void sortByMaterial(List<ItemStack> items);
public void sortByName(List<ItemStack> items);
public void sortByAmount(List<ItemStack> items);
public ItemStack convertJSONToItemStack(JSONObject jo) throws Exception;
public JSONObject convertItemStackToJSON(ItemStack is) throws Exception;
Object createDataJSON(int key, JSONArray jo, JSONArray helper) throws Exception;
Object createDataJSON(int key, JSONArray jo) throws Exception;
boolean compareBaseTag(Object tag, Object tag1) throws Exception;
boolean compareCompoundTag(Object tag, Object tag1) throws Exception;
boolean compareListTag(Object tag, Object tag1) throws Exception;
boolean compare(ItemStack is1, ItemStack is2);
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;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
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 me.skymc.taboolib.json.JSONArray;
import me.skymc.taboolib.json.JSONObject;
import me.skymc.taboolib.nms.NMSUtils;
import me.skymc.taboolib.nms.item.IDabItemUtils;
import me.skymc.taboolib.nms.nbt.NBTConstants;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import me.skymc.taboolib.json.*;
import me.skymc.taboolib.nms.NMSUtils;
import me.skymc.taboolib.nms.item.IDabItemUtils;
import me.skymc.taboolib.nms.nbt.NBTConstants;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;
import java.util.Map.Entry;
public class _164ItemUtils implements IDabItemUtils{
@ -30,7 +23,7 @@ public class _164ItemUtils implements IDabItemUtils{
try{
Material m = Material.valueOf("BANNER");
if(m != null){ return true; }
}catch(Exception e){
} catch (Exception ignored) {
}
return false;
}
@ -110,7 +103,7 @@ public class _164ItemUtils implements IDabItemUtils{
public Object getRegistry(){
try{
return NMSUtils.getFieldSilent(ni, "REGISTRY", "field_150901_e").get(null);
}catch(Exception e){
} catch (Exception ignored) {
}
return null;
}
@ -376,7 +369,7 @@ public class _164ItemUtils implements IDabItemUtils{
@SuppressWarnings({ "unchecked" })
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);
for(Entry<String, Object> e : map.entrySet()){
Object nbti = e.getValue();
@ -390,7 +383,7 @@ public class _164ItemUtils implements IDabItemUtils{
@SuppressWarnings("unchecked")
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);
for(Object e : list){
Object data = getData(e);
@ -402,7 +395,7 @@ public class _164ItemUtils implements IDabItemUtils{
}
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()){
value.put(e.getKey(), createData(e.getValue()));
}
@ -412,14 +405,14 @@ public class _164ItemUtils implements IDabItemUtils{
}
public Object convertValueListToListTag(List<Object> list) throws Exception{
List<Object> value = new ArrayList<Object>();
List<Object> value = new ArrayList<>();
for(Object e : list){
value.add(createData(e));
}
Object ret = getNewNBTTagList();
nbttcm.set(ret, value);
if(value.size() > 0){
nbtlt.set(ret, (byte)gti.invoke(value.get(0)));
nbtlt.set(ret, gti.invoke(value.get(0)));
}
return ret;
}
@ -475,7 +468,7 @@ public class _164ItemUtils implements IDabItemUtils{
@Deprecated
@SuppressWarnings("unchecked")
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();
while(it.hasNext()){
String e = it.next();
@ -488,7 +481,7 @@ public class _164ItemUtils implements IDabItemUtils{
@SuppressWarnings("unchecked")
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();
while(it.hasNext()){
String e = it.next();
@ -509,7 +502,7 @@ public class _164ItemUtils implements IDabItemUtils{
Object ret = getNewNBTTagList();
nbtld.set(ret, value);
if(value.size() > 0){
nbtlt.set(ret, (byte)gti.invoke(value.get(0)));
nbtlt.set(ret, gti.invoke(value.get(0)));
}
return ret;
}
@ -523,7 +516,7 @@ public class _164ItemUtils implements IDabItemUtils{
Object ret = getNewNBTTagList();
nbtld.set(ret, value);
if(value.size() > 0){
nbtlt.set(ret, (byte)gti.invoke(value.get(0)));
nbtlt.set(ret, gti.invoke(value.get(0)));
}
return ret;
}
@ -742,7 +735,7 @@ public class _164ItemUtils implements IDabItemUtils{
public Object createDataJSON(String key, JSONObject jo) throws Exception{
JSONArray j = jo.getJSONArray(key);
Object ret = null;
int i = (int)j.getInt(0);
int i = j.getInt(0);
switch(i){
case NBTConstants.TYPE_COMPOUND:
ret = convertJSONToCompoundTag(j.getJSONObject(1));
@ -889,7 +882,7 @@ public class _164ItemUtils implements IDabItemUtils{
public Object createDataJSON(int key, JSONArray jo) throws Exception{
JSONArray j = jo.getJSONArray(key);
Object ret = null;
int i = (int)j.getInt(0);
int i = j.getInt(0);
switch(i){
case NBTConstants.TYPE_COMPOUND:
ret = convertJSONToCompoundTag(j.getJSONObject(1));
@ -970,7 +963,7 @@ public class _164ItemUtils implements IDabItemUtils{
case NBTConstants.TYPE_BYTE_ARRAY:
byte[] ba = (byte[])nbtbad.get(tag);
byte[] ba1 = (byte[])nbtbad.get(tag1);
return ba.equals(ba1);
return Arrays.equals(ba, ba1);
case NBTConstants.TYPE_STRING:
String st = (String)nbtstd.get(tag);
String st1 = (String)nbtstd.get(tag1);
@ -983,7 +976,7 @@ public class _164ItemUtils implements IDabItemUtils{
case NBTConstants.TYPE_INT_ARRAY:
int[] ia = (int[])nbtiad.get(tag);
int[] ia1 = (int[])nbtiad.get(tag);
return ia.equals(ia1);
return Arrays.equals(ia, ia1);
}
return false;
}
@ -1028,7 +1021,6 @@ public class _164ItemUtils implements IDabItemUtils{
cont = true;
break;
}
;
}
if(!cont)
return false;
@ -1041,7 +1033,7 @@ public class _164ItemUtils implements IDabItemUtils{
}
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++){
Object compound = g.invoke(attribs, i);
Object attrib = a.invoke(null, compound);
@ -1058,23 +1050,18 @@ public class _164ItemUtils implements IDabItemUtils{
public boolean compare(ItemStack is1, ItemStack is2){
if(is1.getType().equals(is2.getType())){
if(is1.getDurability() == is2.getDurability()){
try{
try {
Object nis1 = getNMSCopy(is1);
Object nis2 = getNMSCopy(is2);
Object tis1 = getTag(nis1);
Object tis2 = getTag(nis2);
if(tis1 != null && tis2 == null){
if(isEmpty(tis1))
return true;
return false;
if (tis1 != null && tis2 == null) {
return isEmpty(tis1);
}
if(tis1 == null && tis2 != null){
if(isEmpty(tis2))
return true;
return false;
if (tis1 == null && tis2 != null) {
return isEmpty(tis2);
}
if(tis1 == null && tis2 == null){ return true; }
return compareCompoundTag(tis1, tis2);
return tis1 == null && tis2 == null || compareCompoundTag(tis1, tis2);
}catch(Exception e){
e.printStackTrace();
}
@ -1095,7 +1082,7 @@ public class _164ItemUtils implements IDabItemUtils{
}
public void sortByMaterial(List<ItemStack> items){
Collections.sort(items, new MaterialComparator());
items.sort(new MaterialComparator());
}
public class MaterialComparator implements Comparator<ItemStack>{
@ -1106,7 +1093,7 @@ public class _164ItemUtils implements IDabItemUtils{
}
public void sortByName(List<ItemStack> items){
Collections.sort(items, new NameComparator());
items.sort(new NameComparator());
}
public class NameComparator implements Comparator<ItemStack>{
@ -1123,7 +1110,7 @@ public class _164ItemUtils implements IDabItemUtils{
}
public void sortByAmount(List<ItemStack> items){
Collections.sort(items, new AmountComparator());
items.sort(new AmountComparator());
}
public class AmountComparator implements Comparator<ItemStack>{

View File

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

View File

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

View File

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

View File

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

View File

@ -1,11 +1,9 @@
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 java.util.List;
public class WeightUtils {
public static String getStringByWeight(List<WeightCategory> categorys) {

View File

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

View File

@ -1,5 +1,7 @@
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.Color;
import org.bukkit.Location;
@ -7,9 +9,6 @@ import org.bukkit.Material;
import org.bukkit.entity.Player;
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.Field;
import java.lang.reflect.Method;
@ -406,8 +405,8 @@ public enum EffLib {
*/
SWEEP_ATTACK("sweepAttack", 45, 9);
private static final Map<String, EffLib> NAME_MAP = new HashMap<String, EffLib>();
private static final Map<Integer, EffLib> ID_MAP = new HashMap<Integer, EffLib>();
private static final Map<String, EffLib> NAME_MAP = new HashMap<>();
private static final Map<Integer, EffLib> ID_MAP = new HashMap<>();
private final String name;
private final int id;
private final int requiredVersion;
@ -429,7 +428,7 @@ public enum EffLib {
* @param requiredVersion Version which is required (1.x)
* @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.id = id;
this.requiredVersion = requiredVersion;
@ -478,10 +477,7 @@ public enum EffLib {
* @return Whether the particle effect is supported or not
*/
public boolean isSupported() {
if (requiredVersion == -1) {
return true;
}
return ParticlePacket.getVersion() >= requiredVersion;
return requiredVersion == -1 || ParticlePacket.getVersion() >= requiredVersion;
}
/**
@ -933,7 +929,7 @@ public enum EffLib {
* @author DarkBlade12
* @since 1.7
*/
public static enum ParticleProperty {
public enum ParticleProperty {
/**
* The particle effect requires water to be displayed
*/
@ -949,7 +945,7 @@ public enum EffLib {
/**
* 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 data Data of the effect
* @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 {
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 color Color of the particle
* @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) {
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