-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to 2.1.0: - Fixed 1.12/11 invisible mobs - Fixed an NBTInjector exception that could happen in 1.13.2 - If reflections where unable to get their hook, a NPE was thrown because the logger wasn't yet initialized - The NBTInjector won't enable by default, enable it during onLoad if you want to use it - Prevent /reload when the NBTInjector is enabled to prevent currupt serverstates
- Loading branch information
Showing
11 changed files
with
761 additions
and
698 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
366 changes: 183 additions & 183 deletions
366
item-nbt-api/src/main/java/de/tr7zw/changeme/nbtapi/utils/nmsmappings/ReflectionMethod.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
301 changes: 153 additions & 148 deletions
301
item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/NBTAPI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,148 +1,153 @@ | ||
package de.tr7zw.nbtapi.plugin; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.logging.Level; | ||
|
||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion; | ||
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ClassWrapper; | ||
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod; | ||
import de.tr7zw.nbtapi.plugin.tests.NBTFileTest; | ||
import de.tr7zw.nbtapi.plugin.tests.compounds.GetterSetterTest; | ||
import de.tr7zw.nbtapi.plugin.tests.compounds.ListTest; | ||
import de.tr7zw.nbtapi.plugin.tests.compounds.MergeTest; | ||
import de.tr7zw.nbtapi.plugin.tests.compounds.RemovingKeys; | ||
import de.tr7zw.nbtapi.plugin.tests.compounds.SubCompoundsTest; | ||
import de.tr7zw.nbtapi.plugin.tests.compounds.TypeTest; | ||
import de.tr7zw.nbtapi.plugin.tests.entities.EntityCustomNbtTest; | ||
import de.tr7zw.nbtapi.plugin.tests.entities.EntityTest; | ||
import de.tr7zw.nbtapi.plugin.tests.items.EmptyItemTest; | ||
import de.tr7zw.nbtapi.plugin.tests.items.ItemConvertionTest; | ||
import de.tr7zw.nbtapi.plugin.tests.tiles.TilesCustomNBTTest; | ||
import de.tr7zw.nbtinjector.NBTInjector; | ||
|
||
public class NBTAPI extends JavaPlugin { | ||
|
||
private boolean compatible = true; | ||
private ArrayList<de.tr7zw.nbtapi.plugin.tests.Test> apiTests = new ArrayList<>(); | ||
|
||
private static NBTAPI instance; | ||
|
||
public static NBTAPI getInstance() { | ||
return instance; | ||
} | ||
|
||
@Override | ||
public void onLoad() { | ||
getLogger().info("Injecting custom NBT"); | ||
try { | ||
NBTInjector.inject(); | ||
getLogger().info("Injected!"); | ||
} catch (Throwable ex) { // NOSONAR | ||
getLogger().log(Level.SEVERE, "Error while Injecting custom Tile/Entity classes!", ex); | ||
compatible = false; | ||
} | ||
|
||
// NBTCompounds | ||
apiTests.add(new GetterSetterTest()); | ||
apiTests.add(new TypeTest()); | ||
apiTests.add(new RemovingKeys()); | ||
apiTests.add(new ListTest()); | ||
apiTests.add(new SubCompoundsTest()); | ||
apiTests.add(new MergeTest()); | ||
|
||
// Items | ||
apiTests.add(new ItemConvertionTest()); | ||
apiTests.add(new EmptyItemTest()); | ||
|
||
// Entity | ||
apiTests.add(new EntityTest()); | ||
apiTests.add(new EntityCustomNbtTest()); | ||
|
||
// Tiles | ||
apiTests.add(new TilesCustomNBTTest()); | ||
|
||
// Files | ||
apiTests.add(new NBTFileTest()); | ||
|
||
} | ||
|
||
@Override | ||
public void onEnable() { | ||
instance = this; // NOSONAR | ||
// new MetricsLite(this); The metrics moved into the API | ||
|
||
getLogger().info("Checking bindings..."); | ||
MinecraftVersion.getVersion(); | ||
getLogger().info("Gson:"); | ||
MinecraftVersion.hasGsonSupport(); | ||
getLogger().info("Classes:"); | ||
boolean classUnlinked = false; | ||
for (ClassWrapper c : ClassWrapper.values()) { | ||
if (c.isEnabled() && c.getClazz() == null) { | ||
getLogger().warning(c.name() + " did not find it's class!"); | ||
compatible = false; | ||
classUnlinked = true; | ||
} | ||
} | ||
if (!classUnlinked) | ||
getLogger().info("All Classes where able to link!"); | ||
|
||
getLogger().info("Methods:"); | ||
boolean methodUnlinked = false; | ||
for (ReflectionMethod method : ReflectionMethod.values()) { | ||
if (method.isCompatible() && !method.isLoaded()) { | ||
getLogger().warning(method.name() + " did not find the method!"); | ||
compatible = false; | ||
methodUnlinked = true; | ||
} | ||
} | ||
if (!methodUnlinked) | ||
getLogger().info("All Methods where able to link!"); | ||
getLogger().info("Running NBT reflection test..."); | ||
|
||
Map<de.tr7zw.nbtapi.plugin.tests.Test, Exception> results = new HashMap<>(); | ||
for (de.tr7zw.nbtapi.plugin.tests.Test test : apiTests) { | ||
try { | ||
test.test(); | ||
results.put(test, null); | ||
} catch (Exception ex) { | ||
results.put(test, ex); | ||
getLogger().log(Level.WARNING, "Error during '" + test.getClass().getSimpleName() + "' test!", ex); | ||
} catch (Throwable th) { // NOSONAR | ||
getLogger().log(Level.SEVERE, "Servere error during '" + test.getClass().getSimpleName() + "' test!"); | ||
getLogger().warning( | ||
"WARNING! This version of Item-NBT-API seems to be broken with your Spigot version! Canceled the other tests!"); | ||
throw th; | ||
} | ||
} | ||
|
||
for (Entry<de.tr7zw.nbtapi.plugin.tests.Test, Exception> entry : results.entrySet()) { | ||
if (entry.getValue() != null) | ||
compatible = false; | ||
getLogger().info(entry.getKey().getClass().getSimpleName() + ": " | ||
+ (entry.getValue() == null ? "Ok" : entry.getValue().getMessage())); | ||
} | ||
|
||
String checkMessage = "Plugins that don't check properly may throw Exeptions, crash or have unexpected behaviors!"; | ||
if (compatible) { | ||
getLogger().info("Success! This version of NBT-API is compatible with your server."); | ||
} else { | ||
getLogger().warning( | ||
"WARNING! This version of NBT-API seems to be broken with your Spigot version! " + checkMessage); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* @return True if all selfchecks succeeded | ||
*/ | ||
public boolean isCompatible() { | ||
return compatible; | ||
} | ||
|
||
} | ||
package de.tr7zw.nbtapi.plugin; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.logging.Level; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion; | ||
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ClassWrapper; | ||
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod; | ||
import de.tr7zw.nbtapi.plugin.tests.NBTFileTest; | ||
import de.tr7zw.nbtapi.plugin.tests.compounds.GetterSetterTest; | ||
import de.tr7zw.nbtapi.plugin.tests.compounds.ListTest; | ||
import de.tr7zw.nbtapi.plugin.tests.compounds.MergeTest; | ||
import de.tr7zw.nbtapi.plugin.tests.compounds.RemovingKeys; | ||
import de.tr7zw.nbtapi.plugin.tests.compounds.SubCompoundsTest; | ||
import de.tr7zw.nbtapi.plugin.tests.compounds.TypeTest; | ||
import de.tr7zw.nbtapi.plugin.tests.entities.EntityCustomNbtTest; | ||
import de.tr7zw.nbtapi.plugin.tests.entities.EntityTest; | ||
import de.tr7zw.nbtapi.plugin.tests.items.EmptyItemTest; | ||
import de.tr7zw.nbtapi.plugin.tests.items.ItemConvertionTest; | ||
import de.tr7zw.nbtapi.plugin.tests.tiles.TilesCustomNBTTest; | ||
import de.tr7zw.nbtinjector.NBTInjector; | ||
|
||
public class NBTAPI extends JavaPlugin { | ||
|
||
private boolean compatible = true; | ||
private ArrayList<de.tr7zw.nbtapi.plugin.tests.Test> apiTests = new ArrayList<>(); | ||
|
||
private static NBTAPI instance; | ||
|
||
public static NBTAPI getInstance() { | ||
return instance; | ||
} | ||
|
||
@Override | ||
public void onLoad() { | ||
|
||
//Disabled by default since 2.1. Enable it yourself by calling NBTInjector.inject(); during onLoad. | ||
/*getLogger().info("Injecting custom NBT"); | ||
try { | ||
NBTInjector.inject(); | ||
getLogger().info("Injected!"); | ||
} catch (Throwable ex) { // NOSONAR | ||
getLogger().log(Level.SEVERE, "Error while Injecting custom Tile/Entity classes!", ex); | ||
compatible = false; | ||
}*/ | ||
|
||
// NBTCompounds | ||
apiTests.add(new GetterSetterTest()); | ||
apiTests.add(new TypeTest()); | ||
apiTests.add(new RemovingKeys()); | ||
apiTests.add(new ListTest()); | ||
apiTests.add(new SubCompoundsTest()); | ||
apiTests.add(new MergeTest()); | ||
|
||
// Items | ||
apiTests.add(new ItemConvertionTest()); | ||
apiTests.add(new EmptyItemTest()); | ||
|
||
// Entity | ||
apiTests.add(new EntityTest()); | ||
apiTests.add(new EntityCustomNbtTest()); | ||
|
||
// Tiles | ||
apiTests.add(new TilesCustomNBTTest()); | ||
|
||
// Files | ||
apiTests.add(new NBTFileTest()); | ||
|
||
} | ||
|
||
@Override | ||
public void onEnable() { | ||
instance = this; // NOSONAR | ||
// new MetricsLite(this); The metrics moved into the API | ||
|
||
getLogger().info("Adding listeners..."); | ||
Bukkit.getPluginManager().registerEvents(new ReloadListener(), this); | ||
getLogger().info("Checking bindings..."); | ||
MinecraftVersion.getVersion(); | ||
getLogger().info("Gson:"); | ||
MinecraftVersion.hasGsonSupport(); | ||
getLogger().info("Classes:"); | ||
boolean classUnlinked = false; | ||
for (ClassWrapper c : ClassWrapper.values()) { | ||
if (c.isEnabled() && c.getClazz() == null) { | ||
getLogger().warning(c.name() + " did not find it's class!"); | ||
compatible = false; | ||
classUnlinked = true; | ||
} | ||
} | ||
if (!classUnlinked) | ||
getLogger().info("All Classes where able to link!"); | ||
|
||
getLogger().info("Methods:"); | ||
boolean methodUnlinked = false; | ||
for (ReflectionMethod method : ReflectionMethod.values()) { | ||
if (method.isCompatible() && !method.isLoaded()) { | ||
getLogger().warning(method.name() + " did not find the method!"); | ||
compatible = false; | ||
methodUnlinked = true; | ||
} | ||
} | ||
if (!methodUnlinked) | ||
getLogger().info("All Methods where able to link!"); | ||
getLogger().info("Running NBT reflection test..."); | ||
|
||
Map<de.tr7zw.nbtapi.plugin.tests.Test, Exception> results = new HashMap<>(); | ||
for (de.tr7zw.nbtapi.plugin.tests.Test test : apiTests) { | ||
try { | ||
test.test(); | ||
results.put(test, null); | ||
} catch (Exception ex) { | ||
results.put(test, ex); | ||
getLogger().log(Level.WARNING, "Error during '" + test.getClass().getSimpleName() + "' test!", ex); | ||
} catch (Throwable th) { // NOSONAR | ||
getLogger().log(Level.SEVERE, "Servere error during '" + test.getClass().getSimpleName() + "' test!"); | ||
getLogger().warning( | ||
"WARNING! This version of Item-NBT-API seems to be broken with your Spigot version! Canceled the other tests!"); | ||
throw th; | ||
} | ||
} | ||
|
||
for (Entry<de.tr7zw.nbtapi.plugin.tests.Test, Exception> entry : results.entrySet()) { | ||
if (entry.getValue() != null) | ||
compatible = false; | ||
getLogger().info(entry.getKey().getClass().getSimpleName() + ": " | ||
+ (entry.getValue() == null ? "Ok" : entry.getValue().getMessage())); | ||
} | ||
|
||
String checkMessage = "Plugins that don't check properly may throw Exeptions, crash or have unexpected behaviors!"; | ||
if (compatible) { | ||
getLogger().info("Success! This version of NBT-API is compatible with your server."); | ||
} else { | ||
getLogger().warning( | ||
"WARNING! This version of NBT-API seems to be broken with your Spigot version! " + checkMessage); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* @return True if all selfchecks succeeded | ||
*/ | ||
public boolean isCompatible() { | ||
return compatible; | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/ReloadListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package de.tr7zw.nbtapi.plugin; | ||
|
||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
|
||
import de.tr7zw.nbtinjector.NBTInjector; | ||
|
||
/** | ||
* This listener class tries to prevent people from reloading while the NBTInjector is enabled. | ||
* | ||
* @author tr7zw | ||
* | ||
*/ | ||
public class ReloadListener implements Listener{ | ||
|
||
/** | ||
* Console handler | ||
* | ||
* @param event | ||
*/ | ||
@EventHandler | ||
public void onCommand(org.bukkit.event.server.ServerCommandEvent event) { | ||
if(event.getCommand().toLowerCase().startsWith("reload") && NBTInjector.isInjected()) { | ||
event.setCancelled(true); | ||
event.getSender().sendMessage("[NBTAPI] The NBTInjector is currently enabled. Reloading will turn the server into an unstable state and data-loss may accure. Please do a clean restart. Canceled reload!"); | ||
} | ||
} | ||
|
||
/** | ||
* Player handler | ||
* | ||
* @param event | ||
*/ | ||
@EventHandler | ||
public void onCommand(org.bukkit.event.player.PlayerCommandPreprocessEvent event) { | ||
if(event.getMessage().toLowerCase().startsWith("/reload") && NBTInjector.isInjected()) { | ||
event.setCancelled(true); | ||
event.getPlayer().sendMessage("[NBTAPI] The NBTInjector is currently enabled. Reloading will turn the server into an unstable state and data-loss may accure. Please do a clean restart. Canceled reload!"); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.