[FEAT] Paper Support
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package com.hypherionmc.craterlib.common;
|
||||
|
||||
import com.hypherionmc.craterlib.core.platform.CommonPlatform;
|
||||
import com.hypherionmc.craterlib.nojang.server.BridgedMinecraftServer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
*/
|
||||
public class PaperCommonHelper implements CommonPlatform {
|
||||
|
||||
public PaperCommonHelper() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BridgedMinecraftServer getMCServer() {
|
||||
return BridgedMinecraftServer.of(MinecraftServer.getServer());
|
||||
}
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
package com.hypherionmc.craterlib.common;
|
||||
|
||||
import com.hypherionmc.craterlib.core.platform.CompatUtils;
|
||||
import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class PaperCompatHelper implements CompatUtils {
|
||||
|
||||
@Override
|
||||
public boolean isPlayerActive(BridgedPlayer player) {
|
||||
// Essentials Vanish
|
||||
if (ModloaderEnvironment.INSTANCE.isModLoaded("Essentials")) {
|
||||
return !isEssentialsVanished(player);
|
||||
}
|
||||
|
||||
// PhantomAdmin Vanish
|
||||
if (ModloaderEnvironment.INSTANCE.isModLoaded("PhantomAdmin"))
|
||||
return !isPhantomVanished(player);
|
||||
|
||||
// Other vanish mods
|
||||
try {
|
||||
Player p = (Player) player.toMojangServerPlayer();
|
||||
for (MetadataValue meta : p.getMetadata("vanished")) {
|
||||
if (meta.asBoolean()) return true;
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSkinUUID(BridgedPlayer player) {
|
||||
return player.getStringUUID();
|
||||
}
|
||||
|
||||
private boolean isEssentialsVanished(BridgedPlayer player) {
|
||||
try {
|
||||
Plugin p = Bukkit.getPluginManager().getPlugin("Essentials");
|
||||
if (p == null)
|
||||
return false;
|
||||
|
||||
Method getUser = p.getClass().getMethod("getUser", String.class);
|
||||
Object essentialsPlayer = getUser.invoke(p, ChatUtils.resolve(player.getName(), false));
|
||||
|
||||
if (essentialsPlayer != null) {
|
||||
Method isVanished = essentialsPlayer.getClass().getMethod("isVanished");
|
||||
return (boolean) isVanished.invoke(essentialsPlayer);
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isPhantomVanished(BridgedPlayer player) {
|
||||
try {
|
||||
Plugin p = Bukkit.getPluginManager().getPlugin("PhantomAdmin");
|
||||
if (p == null)
|
||||
return false;
|
||||
|
||||
Method isInvisible = p.getClass().getDeclaredMethod("isInvisible", Player.class);
|
||||
isInvisible.setAccessible(true);
|
||||
|
||||
return (boolean) isInvisible.invoke(p, (Player) player.toMojangServerPlayer());
|
||||
} catch (Exception ignored) {
|
||||
ignored.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,70 @@
|
||||
package com.hypherionmc.craterlib.common;
|
||||
|
||||
import com.hypherionmc.craterlib.core.platform.Environment;
|
||||
import com.hypherionmc.craterlib.core.platform.LoaderType;
|
||||
import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment;
|
||||
import net.minecraft.SharedConstants;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
*/
|
||||
public class PaperLoaderHelper implements ModloaderEnvironment {
|
||||
|
||||
public PaperLoaderHelper() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFabric() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoaderType getLoaderType() {
|
||||
return LoaderType.PAPER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGameVersion() {
|
||||
return SharedConstants.getCurrentVersion().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getGameFolder() {
|
||||
return new File(".");
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getConfigFolder() {
|
||||
return new File("config");
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getModsFolder() {
|
||||
return Bukkit.getPluginsFolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Environment getEnvironment() {
|
||||
return Environment.SERVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModLoaded(String modid) {
|
||||
return Bukkit.getPluginManager().isPluginEnabled(modid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDevEnv() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getModCount() {
|
||||
return (int) Arrays.stream(Bukkit.getPluginManager().getPlugins()).filter(Plugin::isEnabled).count();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user