Skip to content

Commit

Permalink
Changed ServerVersion as 1.20.6+ removed package nms
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigerpanzer02 committed Jul 12, 2024
1 parent 6a7eaf3 commit adf33f3
Show file tree
Hide file tree
Showing 21 changed files with 143 additions and 152 deletions.
2 changes: 1 addition & 1 deletion MiniGamesBox API/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ plugins {
}

dependencies {
implementation("me.tigerhix.lib:scoreboard:1.4.4") { isTransitive = false }
implementation("me.tigerhix.lib:scoreboard:1.4.5") { isTransitive = false }
compileOnly(project(":MiniGamesBox-Database", "shadow"))
compileOnly("com.github.cryptomorin:XSeries:11.2.0") { isTransitive = false }
}
Expand Down
2 changes: 1 addition & 1 deletion MiniGamesBox Classic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ plugins {
}

dependencies {
implementation("me.tigerhix.lib:scoreboard:1.4.4") { isTransitive = false }
implementation("me.tigerhix.lib:scoreboard:1.4.5") { isTransitive = false }
implementation("com.github.cryptomorin:XSeries:11.2.0") { isTransitive = false }
implementation(project(":MiniGamesBox-API", "shadow"))
implementation(project(":MiniGamesBox-Inventory", "shadow"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ private boolean validateIfPluginShouldStart() {
getServer().getPluginManager().disablePlugin(this);
return false;
}
if(ServerVersion.Version.isCurrentLower(ServerVersion.Version.v1_8_R3)) {
if(ServerVersion.Version.isCurrentLower(ServerVersion.Version.v1_8_8)) {
MiscUtils.sendLineBreaker(getName());
messageUtils.thisVersionIsNotSupported();
MiscUtils.sendVersionInformation(this, getName(), getDescription());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void bossBarUpdate() {

@Override
public void doBarAction(IPluginArena.IBarAction action, Player player) {
if (ServerVersion.Version.isCurrentLower(ServerVersion.Version.v1_9_R1) || !plugin.getConfigPreferences().getOption("BOSSBAR")) {
if (ServerVersion.Version.isCurrentLower(ServerVersion.Version.v1_9) || !plugin.getConfigPreferences().getOption("BOSSBAR")) {
return;
}
switch (action) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private void sendAdminHelpCommand(CommandSender sender) {
data.addAll(mappedArguments.get(plugin.getPluginNamePrefixLong()).stream().filter(arg -> arg instanceof LabeledCommandArgument)
.map(arg -> ((LabeledCommandArgument) arg).getLabelData()).collect(Collectors.toList()));

if(ServerVersion.Version.isCurrentEqualOrLower(ServerVersion.Version.v1_11_R1)) {
if(ServerVersion.Version.isCurrentEqualOrLower(ServerVersion.Version.v1_11)) {
for(LabelData labelData : data) {
sender.sendMessage(labelData.getText() + " - " + labelData.getDescription().split("\n", 2)[0]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ private void changeWorldCycles() {
}

private void setWeatherGameRule(World world) {
if(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_13_R1)) {
if(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_13)) {
world.setGameRule(GameRule.DO_WEATHER_CYCLE, false);
} else {
world.setGameRuleValue("doWeatherCycle", "false");
}
}

private void setDayLightGameRule(World world) {
if(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_13_R1)) {
if(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_13)) {
world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false);
} else {
world.setGameRuleValue("doDaylightCycle", "false");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void onItemSwap(PlugilyPlayerSwapHandItemsEvent event) {
@EventHandler
public void onSpawn(CreatureSpawnEvent event) {
if(event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.CUSTOM
|| (ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_17_R1) && event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.COMMAND)) {
|| (ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_17) && event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.COMMAND)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private void formatSpecialChars() {
}

private void colorRawMessage() {
if(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_16_R1) && message.indexOf('#') != -1) {
if(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_16) && message.indexOf('#') != -1) {
message = MiscUtils.matchColorRegex(message);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public ArenaSign(Sign sign, IPluginArena arena) {
private void setBehindBlock() {
behind = null;
if(MaterialUtils.isWallSign(sign.getBlock().getType())) {
behind = ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_14_R1) ? getBlockBehind() : getBlockBehindLegacy();
behind = ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_14) ? getBlockBehind() : getBlockBehindLegacy();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ public void loadSigns() {
org.bukkit.block.BlockState state = loc.getBlock().getState();
if(state instanceof Sign) {
arenaSigns.add(new ArenaSign((Sign) state, arena));
if(ServerVersion.Version.isCurrentHigher(ServerVersion.Version.v1_12_R1)) {
if(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_20_R1)) {
if(ServerVersion.Version.isCurrentHigher(ServerVersion.Version.v1_12)) {
if(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_20)) {
((Sign) state).setWaxed(true);
} else {
((Sign) state).setEditable(false);
Expand Down Expand Up @@ -213,31 +213,31 @@ public void updateSigns() {
switch(arenaSign.getArena().getArenaState()) {
case WAITING_FOR_PLAYERS:
behind.setType(XMaterial.WHITE_STAINED_GLASS.parseMaterial());
if(ServerVersion.Version.isCurrentLower(ServerVersion.Version.v1_13_R1)) {
if(ServerVersion.Version.isCurrentLower(ServerVersion.Version.v1_13)) {
Block.class.getMethod("setData", byte.class).invoke(behind, XMaterial.WHITE_STAINED_GLASS.getData());
}
break;
case STARTING:
behind.setType(XMaterial.YELLOW_STAINED_GLASS.parseMaterial());
if(ServerVersion.Version.isCurrentLower(ServerVersion.Version.v1_13_R1)) {
if(ServerVersion.Version.isCurrentLower(ServerVersion.Version.v1_13)) {
Block.class.getMethod("setData", byte.class).invoke(behind, XMaterial.YELLOW_STAINED_GLASS.getData());
}
break;
case IN_GAME:
behind.setType(XMaterial.ORANGE_STAINED_GLASS.parseMaterial());
if(ServerVersion.Version.isCurrentLower(ServerVersion.Version.v1_13_R1)) {
if(ServerVersion.Version.isCurrentLower(ServerVersion.Version.v1_13)) {
Block.class.getMethod("setData", byte.class).invoke(behind, XMaterial.ORANGE_STAINED_GLASS.getData());
}
break;
case ENDING:
behind.setType(XMaterial.GRAY_STAINED_GLASS.parseMaterial());
if(ServerVersion.Version.isCurrentLower(ServerVersion.Version.v1_13_R1)) {
if(ServerVersion.Version.isCurrentLower(ServerVersion.Version.v1_13)) {
Block.class.getMethod("setData", byte.class).invoke(behind, XMaterial.GRAY_STAINED_GLASS.getData());
}
break;
case RESTARTING:
behind.setType(XMaterial.BLACK_STAINED_GLASS.parseMaterial());
if(ServerVersion.Version.isCurrentLower(ServerVersion.Version.v1_13_R1)) {
if(ServerVersion.Version.isCurrentLower(ServerVersion.Version.v1_13)) {
Block.class.getMethod("setData", byte.class).invoke(behind, XMaterial.BLACK_STAINED_GLASS.getData());
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ public static ItemStack getSkull(String url) {
SkullMeta headMeta = (SkullMeta) head.getItemMeta();

GameProfile profile;
if(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_20_R1)) {
if(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_20)) {
profile = new GameProfile(UUID.randomUUID(), "Plugily");
} else {
profile = new GameProfile(UUID.randomUUID(), null);
}
profile.getProperties().put("textures", new Property("textures", url));
if(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_15_R1)) {
if(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_15)) {
try {
Method mtd = headMeta.getClass().getDeclaredMethod("setProfile", GameProfile.class);
mtd.setAccessible(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,11 @@ private void append() {
}
entityItem.setCustomNameVisible(false);

if(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_10_R1)) {
if(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_10)) {
entityItem.setGravity(true);
}

if(ServerVersion.Version.isCurrentHigher(ServerVersion.Version.v1_8_R3)) {
if(ServerVersion.Version.isCurrentHigher(ServerVersion.Version.v1_8_8)) {
entityItem.setInvulnerable(true);
}
VersionUtils.teleport(entityItem, location);
Expand All @@ -214,7 +214,7 @@ private ArmorStand getEntityArmorStand(double y) {
loc.setY(y);

World world = loc.getWorld();
if(ServerVersion.Version.isCurrentHigher(ServerVersion.Version.v1_8_R1)) {
if(ServerVersion.Version.isCurrentHigher(ServerVersion.Version.v1_8_8)) {
world.getNearbyEntities(location, 0.2, 0.2, 0.2).forEach(entity -> {
if(entity instanceof ArmorStand && !armorStands.contains(entity) && !plugin.getHologramManager().getArmorStands().contains(entity)) {
entity.remove();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void monitorPerformance(String task) {

@Override
public void sendConsoleMsg(String msg) {
if (ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_16_R1) && msg.indexOf('#') >= 0) {
if (ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_16) && msg.indexOf('#') >= 0) {
msg = MiscUtils.matchColorRegex(msg);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private MiscUtils() {
}

public static String matchColorRegex(String s) {
if(Version.isCurrentLower(Version.v1_16_R1)) {
if(Version.isCurrentLower(Version.v1_16)) {
return s;
}

Expand Down Expand Up @@ -198,21 +198,21 @@ public static void sendStartUpMessage(Plugin plugin, String pluginname, PluginDe
Bukkit.getConsoleSender().sendMessage("[" + pluginname + "][SNAPSHOT] §eSNAPSHOT builds are just for test purposes and we do not provide any support to them!");
}
if(disclaimer) {
if(ServerVersion.Version.isCurrentEqual(Version.v0_0_R0) || ServerVersion.Version.isCurrentLower(Version.v1_12_R1)) {
if(ServerVersion.Version.isCurrentEqual(Version.v0_0_0) || ServerVersion.Version.isCurrentLower(Version.v1_12)) {
Bukkit.getConsoleSender().sendMessage("[" + pluginname + "] ");
if(ServerVersion.Version.isCurrentEqual(Version.v0_0_R0)) {
if(ServerVersion.Version.isCurrentEqual(Version.v0_0_0)) {
Bukkit.getConsoleSender().sendMessage("[" + pluginname + "][DISCLAIMER] §cIt seems like our system does not know your Server version, you should contact our support!");
}
if(ServerVersion.Version.isCurrentLower(Version.v1_17_R1)) {
if(ServerVersion.Version.isCurrentLower(Version.v1_17)) {
Bukkit.getConsoleSender().sendMessage("[" + pluginname + "][DISCLAIMER] §cWe noticed that you are using an older version of Minecraft.");
Bukkit.getConsoleSender().sendMessage("[" + pluginname + "][DISCLAIMER] §cPlease keep in mind that newer versions will help improving the security and performance of your server.");
if(ServerVersion.Version.isCurrentLower(Version.v1_12_R1)) {
if(ServerVersion.Version.isCurrentLower(Version.v1_12)) {
Bukkit.getConsoleSender().sendMessage("[" + pluginname + "][DISCLAIMER] §cWe do not give official support for old Minecraft versions as they are to outdated, have security risks and slow down dev progress!");
}
}
}
}
if(support && ServerVersion.Version.isCurrentEqualOrHigher(Version.v1_12_R1)) {
if(support && ServerVersion.Version.isCurrentEqualOrHigher(Version.v1_12)) {
Bukkit.getConsoleSender().sendMessage("[" + pluginname + "] ");
Bukkit.getConsoleSender().sendMessage("[" + pluginname + "][SUPPORT] If you have any problems, you can always contact us on our Discord server! ( https://discord.plugily.xyz )");
Bukkit.getConsoleSender().sendMessage("[" + pluginname + "][SUPPORT] You can also check out our wiki at https://wiki.plugily.xyz");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class ComplementAccessor {
} catch(NoSuchMethodException | ClassNotFoundException e) {
}

complement = (ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_16_R3) && kyoriSupported)
complement = (ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_16) && kyoriSupported)
? new Complement2()
: new Complement1();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static boolean saveInventoryToFile(JavaPlugin plugin, Player player) {
for(int i = 0; i < invContents.length; i++) {
ItemStack itemInInv = invContents[i];
if(itemInInv != null && itemInInv.getType() != Material.AIR) {
if(ServerVersion.Version.isCurrentEqualOrLower(ServerVersion.Version.v1_8_R3) && itemInInv.getItemMeta() instanceof SkullMeta) {
if(ServerVersion.Version.isCurrentEqualOrLower(ServerVersion.Version.v1_8_8) && itemInInv.getItemMeta() instanceof SkullMeta) {
SkullMeta skullMeta = ((SkullMeta) itemInInv.getItemMeta());
if(skullMeta.getOwner() != null) {
try {
Expand All @@ -133,7 +133,7 @@ public static boolean saveInventoryToFile(JavaPlugin plugin, Player player) {
}
}

if(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_9_R1)) {
if(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_9)) {
invConfig.set("Offhand", inventory.getItemInOffHand());
}

Expand Down Expand Up @@ -221,7 +221,7 @@ public static void loadInventory(JavaPlugin plugin, Player player) {
}
}
playerInventory.setArmorContents(armor);
if(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_9_R1)) {
if(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_9)) {
playerInventory.setItemInOffHand(invConfig.getItemStack("Offhand", new ItemStack(Material.AIR)));
}
VersionUtils.setMaxHealth(player, invConfig.getDouble("Max health"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

/**
Expand All @@ -42,12 +43,12 @@ public static void sendPacket(Player player, Object packet) {

if (playerConnectionField == null)
playerConnectionField = handle.getClass().getField(
(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_17_R1) ? "b" : "playerConnection"));
(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_17) ? "b" : "playerConnection"));

Object playerConnection = playerConnectionField.get(handle);

if (sendPacketMethod == null)
sendPacketMethod = playerConnection.getClass().getMethod((ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_18_R1) ? "a" : "sendPacket"),
sendPacketMethod = playerConnection.getClass().getMethod((ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_18) ? "a" : "sendPacket"),
classByName("net.minecraft.network.protocol", "Packet"));

sendPacketMethod.invoke(playerConnection, packet);
Expand All @@ -57,8 +58,8 @@ public static void sendPacket(Player player, Object packet) {
}

public static Class<?> classByName(String newPackageName, String className) {
if(ServerVersion.Version.isCurrentLower(ServerVersion.Version.v1_17_R1) || newPackageName == null) {
newPackageName = "net.minecraft.server." + ServerVersion.Version.getPackageVersion()[3];
if(ServerVersion.Version.isCurrentLower(ServerVersion.Version.v1_17) || newPackageName == null) {
newPackageName = "net.minecraft.server." + Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
}

try {
Expand Down
Loading

0 comments on commit adf33f3

Please sign in to comment.