Bring back NMS

This commit is contained in:
Florian CUNY 2017-12-10 09:19:20 +01:00
parent 09ac5c439e
commit 2dff568cb9
7 changed files with 130 additions and 0 deletions

BIN
lib/library-1.12.jar Normal file

Binary file not shown.

View File

@ -12,6 +12,7 @@
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<server.jars>${project.basedir}/lib</server.jars>
</properties>
<build>
<defaultGoal>clean package install</defaultGoal>
@ -75,6 +76,13 @@
<version>1.12.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>spigotmc.org</groupId>
<artifactId>library-1.12</artifactId>
<scope>system</scope>
<systemPath>${server.jars}/library-1.12.jar</systemPath>
<version>1.12</version>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>

View File

@ -27,7 +27,9 @@ import us.tastybento.bskyblock.listeners.protection.IslandGuard;
import us.tastybento.bskyblock.listeners.protection.IslandGuard1_8;
import us.tastybento.bskyblock.listeners.protection.IslandGuard1_9;
import us.tastybento.bskyblock.listeners.protection.NetherEvents;
import us.tastybento.bskyblock.util.Util;
import us.tastybento.bskyblock.util.VaultHelper;
import us.tastybento.bskyblock.util.nms.NMSAbstraction;
/**
* Main BSkyBlock class - provides an island minigame in the sky
@ -247,6 +249,16 @@ public class BSkyBlock extends JavaPlugin {
return localeManager.getLocale(uuid);
}
public NMSAbstraction getNMSHandler() {
NMSAbstraction nmsHandler = null;
try {
nmsHandler = Util.getNMSHandler();
} catch(Exception e) {
e.printStackTrace();
}
return nmsHandler;
}
/**
* Add a new sub command to BSkyBlock
* @param argHandler - must specify either the island or admin command

View File

@ -1,6 +1,7 @@
package us.tastybento.bskyblock.util;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
@ -30,6 +31,7 @@ import org.bukkit.plugin.Plugin;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.generators.IslandWorld;
import us.tastybento.bskyblock.util.nms.NMSAbstraction;
import us.tastybento.bskyblock.util.placeholders.PlaceholderHandler;
/**
@ -41,6 +43,8 @@ import us.tastybento.bskyblock.util.placeholders.PlaceholderHandler;
public class Util {
private static BSkyBlock plugin = BSkyBlock.getPlugin();
private static NMSAbstraction nmsHandler;
public static void sendMessage(CommandSender receiver, String message){
message = PlaceholderHandler.replacePlaceholders(receiver, message);
@ -51,6 +55,39 @@ public class Util {
}
}
/**
* Checks what version the server is running and picks the appropriate NMS handler, or fallback
* @return NMSAbstraction class
* @throws ClassNotFoundException
* @throws IllegalArgumentException
* @throws SecurityException
* @throws InstantiationException
* @throws IllegalAccessException
* @throws InvocationTargetException
* @throws NoSuchMethodException
*/
public static NMSAbstraction getNMSHandler() throws ClassNotFoundException, IllegalArgumentException,
SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException,
NoSuchMethodException {
String serverPackageName = plugin.getServer().getClass().getPackage().getName();
String pluginPackageName = plugin.getClass().getPackage().getName();
String version = serverPackageName.substring(serverPackageName.lastIndexOf('.') + 1);
Class<?> clazz;
try {
clazz = Class.forName(pluginPackageName + ".util.nms." + version + ".NMSHandler");
} catch (Exception e) {
plugin.getLogger().info("No NMS Handler found for " + version + ", falling back to Bukkit API.");
clazz = Class.forName(pluginPackageName + ".util.nms.fallback.NMSHandler");
}
// Check if we have a NMSAbstraction implementing class at that location.
if (NMSAbstraction.class.isAssignableFrom(clazz)) {
nmsHandler = (NMSAbstraction) clazz.getConstructor().newInstance();
return nmsHandler;
} else {
throw new IllegalStateException("Class " + clazz.getName() + " does not implement NMSAbstraction");
}
}
/**
* Converts a serialized location to a Location. Returns null if string is
* empty

View File

@ -0,0 +1,29 @@
package us.tastybento.bskyblock.util.nms;
import org.bukkit.entity.Player;
public interface NMSAbstraction {
/**
* Send an action bar message to player
* @param player
* @param message
*/
void sendActionBar(Player player, String message);
/**
* Send a title to a player
* @param player
* @param message
*/
void sendTitle(Player player, String message);
/**
* Send a subtitle to a player
* @param player
* @param message
*/
void sendSubtitle(Player player, String message);
}

View File

@ -0,0 +1,22 @@
package us.tastybento.bskyblock.util.nms.fallback;
import org.bukkit.entity.Player;
import us.tastybento.bskyblock.util.nms.NMSAbstraction;
public class NMSHandler implements NMSAbstraction {
@Override
public void sendActionBar(Player player, String message) {
}
@Override
public void sendTitle(Player player, String message) {
}
@Override
public void sendSubtitle(Player player, String message) {
}
}

View File

@ -0,0 +1,22 @@
package us.tastybento.bskyblock.util.nms.v1_12_R1;
import org.bukkit.entity.Player;
import us.tastybento.bskyblock.util.nms.NMSAbstraction;
public class NMSHandler implements NMSAbstraction {
@Override
public void sendActionBar(Player player, String message) {
}
@Override
public void sendTitle(Player player, String message) {
}
@Override
public void sendSubtitle(Player player, String message) {
}
}