From 43b266f17dcd79303241d9194f2f6ad0c3ba64e6 Mon Sep 17 00:00:00 2001 From: Telesphoreo Date: Sun, 30 Aug 2020 19:13:46 -0500 Subject: [PATCH] Update NMS + Use PaperLib for teleportAsync --- pom.xml | 17 +++++++++++------ .../totalfreedommod/LoginProcess.java | 3 ++- .../totalfreedommod/MovementValidator.java | 15 ++++++++------- .../totalfreedommod/ServerInterface.java | 8 ++++---- .../totalfreedommod/blocking/SignBlocker.java | 6 +++--- .../totalfreedommod/caging/Cager.java | 3 ++- .../command/Command_hubworld.java | 3 ++- .../command/Command_localspawn.java | 3 ++- .../command/Command_masterbuilderworld.java | 3 ++- .../command/Command_modifyitem.java | 10 +++++----- .../command/Command_plotworld.java | 4 ++-- .../totalfreedommod/command/Command_ride.java | 5 +++-- .../command/Command_spectate.java | 3 ++- .../command/Command_staffworld.java | 3 ++- .../command/Command_tprandom.java | 3 ++- .../totalfreedommod/world/CustomWorld.java | 3 ++- .../totalfreedommod/world/WorldManager.java | 6 +++--- 17 files changed, 57 insertions(+), 41 deletions(-) diff --git a/pom.xml b/pom.xml index 1908ca4c..8355eb2f 100644 --- a/pom.xml +++ b/pom.xml @@ -46,7 +46,12 @@ CodeMC - https://repo.codemc.org/repository/maven-public + https://repo.codemc.org/repository/maven-public/ + + + + nms-repo + https://repo.codemc.org/repository/nms/ @@ -142,7 +147,7 @@ org.spigotmc - spigot-api + spigot 1.16.2-R0.1-SNAPSHOT provided @@ -197,10 +202,10 @@ - com.destroystokyo.paper - paper-api - 1.16.2-R0.1-SNAPSHOT - provided + io.papermc + paperlib + 1.0.5 + compile diff --git a/src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java b/src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java index 77907ee2..9faeecca 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod; +import io.papermc.lib.PaperLib; import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; @@ -197,7 +198,7 @@ public class LoginProcess extends FreedomService int z = FUtil.randomInteger(-10000, 10000); int y = player.getWorld().getHighestBlockYAt(x, z); Location location = new Location(player.getLocation().getWorld(), x, y, z); - player.teleport(location); + PaperLib.teleportAsync(player, location); player.sendMessage(ChatColor.AQUA + "You have been teleported to a random location automatically."); return; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java b/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java index 0666c0cb..d513a6f2 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java @@ -3,14 +3,15 @@ package me.totalfreedom.totalfreedommod; import ca.momothereal.mojangson.ex.MojangsonParseException; import ca.momothereal.mojangson.value.MojangsonCompound; import ca.momothereal.mojangson.value.MojangsonValue; +import io.papermc.lib.PaperLib; import java.util.List; import java.util.Objects; -import net.minecraft.server.v1_16_R1.NBTTagCompound; -import net.minecraft.server.v1_16_R1.NBTTagList; +import net.minecraft.server.v1_16_R2.NBTTagCompound; +import net.minecraft.server.v1_16_R2.NBTTagList; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -61,7 +62,7 @@ public class MovementValidator extends FreedomService if (Math.abs(event.getTo().getX()) >= MAX_XYZ_COORD || Math.abs(event.getTo().getZ()) >= MAX_XYZ_COORD || Math.abs(event.getTo().getY()) >= MAX_XYZ_COORD) { event.setCancelled(true); - player.teleport(player.getWorld().getSpawnLocation()); + PaperLib.teleportAsync(player, player.getWorld().getSpawnLocation()); } if (exploitItem(event.getPlayer().getInventory().getHelmet())) @@ -110,7 +111,7 @@ public class MovementValidator extends FreedomService // Validate position if (Math.abs(player.getLocation().getX()) >= MAX_XYZ_COORD || Math.abs(player.getLocation().getZ()) >= MAX_XYZ_COORD || Math.abs(player.getLocation().getY()) >= MAX_XYZ_COORD) { - player.teleport(player.getWorld().getSpawnLocation()); // Illegal position, teleport to spawn + PaperLib.teleportAsync(player, player.getWorld().getSpawnLocation()); // Illegal position, teleport to spawn } } @@ -131,7 +132,7 @@ public class MovementValidator extends FreedomService private Boolean exploitItem(ItemStack item) { - net.minecraft.server.v1_16_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(item); + net.minecraft.server.v1_16_R2.ItemStack nmsStack = CraftItemStack.asNMSCopy(item); NBTTagList modifiers = getAttributeList(nmsStack); MojangsonCompound compound = new MojangsonCompound(); boolean foundNegative = false; @@ -168,7 +169,7 @@ public class MovementValidator extends FreedomService } - private NBTTagList getAttributeList(net.minecraft.server.v1_16_R1.ItemStack stack) + private NBTTagList getAttributeList(net.minecraft.server.v1_16_R2.ItemStack stack) { if (stack.getTag() == null) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/ServerInterface.java b/src/main/java/me/totalfreedom/totalfreedommod/ServerInterface.java index 033281ad..b64adac3 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/ServerInterface.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/ServerInterface.java @@ -4,14 +4,14 @@ import java.util.Arrays; import java.util.List; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.minecraft.server.v1_16_R1.EntityPlayer; -import net.minecraft.server.v1_16_R1.MinecraftServer; +import net.minecraft.server.v1_16_R2.EntityPlayer; +import net.minecraft.server.v1_16_R2.MinecraftServer; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_16_R1.CraftServer; +import org.bukkit.craftbukkit.v1_16_R2.CraftServer; public class ServerInterface extends FreedomService { - public static final String COMPILE_NMS_VERSION = "v1_16_R1"; + public static final String COMPILE_NMS_VERSION = "v1_16_R2"; @Override public void onStart() diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/SignBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/SignBlocker.java index bfbaaa3e..6a220b18 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/blocking/SignBlocker.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/SignBlocker.java @@ -1,10 +1,10 @@ package me.totalfreedom.totalfreedommod.blocking; import me.totalfreedom.totalfreedommod.FreedomService; -import net.minecraft.server.v1_16_R1.NBTTagCompound; +import net.minecraft.server.v1_16_R2.NBTTagCompound; import org.bukkit.ChatColor; import org.bukkit.Tag; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -35,7 +35,7 @@ public class SignBlocker extends FreedomService if (Tag.SIGNS.getValues().contains(event.getBlock().getType())) { ItemStack sign = event.getItemInHand(); - net.minecraft.server.v1_16_R1.ItemStack nmsSign = CraftItemStack.asNMSCopy(sign); + net.minecraft.server.v1_16_R2.ItemStack nmsSign = CraftItemStack.asNMSCopy(sign); NBTTagCompound compound = (nmsSign.hasTag()) ? nmsSign.getTag() : new NBTTagCompound(); NBTTagCompound bet = compound.getCompound("BlockEntityTag"); String line1 = bet.getString("Text1"); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/caging/Cager.java b/src/main/java/me/totalfreedom/totalfreedommod/caging/Cager.java index 504d9f72..5307d562 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/caging/Cager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/caging/Cager.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.caging; +import io.papermc.lib.PaperLib; import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.util.FUtil; @@ -71,7 +72,7 @@ public class Cager extends FreedomService if (outOfCage) { - player.getPlayer().teleport(cageLoc.subtract(0, 0.1, 0)); + PaperLib.teleportAsync(player.getPlayer(), cageLoc.subtract(0, 0.1, 0)); FUtil.playerMsg(player.getPlayer(), "You may not leave your cage.", ChatColor.RED); cage.regenerate(); } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_hubworld.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_hubworld.java index 97ab3f3f..e29764a7 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_hubworld.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_hubworld.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import io.papermc.lib.PaperLib; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -72,7 +73,7 @@ public class Command_hubworld extends FreedomCommand if (hubWorld == null || playerSender.getWorld() == hubWorld) { msg("Going to the main world."); - playerSender.teleport(server.getWorlds().get(0).getSpawnLocation()); + PaperLib.teleportAsync(playerSender, server.getWorlds().get(0).getSpawnLocation()); } else { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_localspawn.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_localspawn.java index 4246c932..3bea6064 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_localspawn.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_localspawn.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import io.papermc.lib.PaperLib; import me.totalfreedom.totalfreedommod.rank.Rank; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -12,7 +13,7 @@ public class Command_localspawn extends FreedomCommand @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - playerSender.teleport(playerSender.getWorld().getSpawnLocation()); + PaperLib.teleportAsync(playerSender, playerSender.getWorld().getSpawnLocation()); msg("Teleported to spawnpoint for world \"" + playerSender.getWorld().getName() + "\"."); return true; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_masterbuilderworld.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_masterbuilderworld.java index 1ee29f31..b18e0379 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_masterbuilderworld.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_masterbuilderworld.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import io.papermc.lib.PaperLib; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -72,7 +73,7 @@ public class Command_masterbuilderworld extends FreedomCommand if (masterBuilderWorld == null || playerSender.getWorld() == masterBuilderWorld) { msg("Going to the main world."); - playerSender.teleport(server.getWorlds().get(0).getSpawnLocation()); + PaperLib.teleportAsync(playerSender, server.getWorlds().get(0).getSpawnLocation()); } else { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_modifyitem.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_modifyitem.java index 96b9ebc6..c3e54346 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_modifyitem.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_modifyitem.java @@ -5,13 +5,13 @@ import java.util.List; import java.util.Random; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.minecraft.server.v1_16_R1.NBTTagCompound; -import net.minecraft.server.v1_16_R1.NBTTagList; +import net.minecraft.server.v1_16_R2.NBTTagCompound; +import net.minecraft.server.v1_16_R2.NBTTagList; import org.apache.commons.lang.StringUtils; import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -149,7 +149,7 @@ public class Command_modifyitem extends FreedomCommand { return false; } - net.minecraft.server.v1_16_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(item); + net.minecraft.server.v1_16_R2.ItemStack nmsStack = CraftItemStack.asNMSCopy(item); NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound(); NBTTagList modifiers = getAttributeList(nmsStack); NBTTagCompound cmpnd = new NBTTagCompound(); @@ -199,7 +199,7 @@ public class Command_modifyitem extends FreedomCommand return true; } - private NBTTagList getAttributeList(net.minecraft.server.v1_16_R1.ItemStack stack) + private NBTTagList getAttributeList(net.minecraft.server.v1_16_R2.ItemStack stack) { if (stack.getTag() == null) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_plotworld.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_plotworld.java index 2fd10037..e764e94f 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_plotworld.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_plotworld.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import io.papermc.lib.PaperLib; import me.totalfreedom.totalfreedommod.rank.Rank; import org.bukkit.World; import org.bukkit.command.Command; @@ -10,14 +11,13 @@ import org.bukkit.entity.Player; @CommandParameters(description = "Go to the PlotWorld.", usage = "/", aliases = "pw") public class Command_plotworld extends FreedomCommand { - @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { World plotworld = server.getWorld("plotworld"); if (plotworld != null) { - playerSender.teleport(plotworld.getSpawnLocation()); + PaperLib.teleportAsync(playerSender, plotworld.getSpawnLocation()); } else { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java index 02b9f7dd..69247c8e 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import io.papermc.lib.PaperLib; import java.util.HashMap; import java.util.Map; import java.util.TimerTask; @@ -55,7 +56,7 @@ public class Command_ride extends FreedomCommand if (requester.getWorld() != playerSender.getWorld()) { - requester.teleport(playerSender); + PaperLib.teleportAsync(requester, playerSender.getLocation()); } playerSender.addPassenger(requester); @@ -145,7 +146,7 @@ public class Command_ride extends FreedomCommand if (player.getWorld() != playerSender.getWorld()) { - playerSender.teleport(player); + PaperLib.teleportAsync(playerSender, player.getLocation()); } player.addPassenger(playerSender); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_spectate.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_spectate.java index b54d846a..1dff9c2c 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_spectate.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_spectate.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import io.papermc.lib.PaperLib; import me.totalfreedom.totalfreedommod.rank.Rank; import org.bukkit.ChatColor; import org.bukkit.GameMode; @@ -40,7 +41,7 @@ public class Command_spectate extends FreedomCommand if (playerSender.getWorld() != player.getWorld()) { - playerSender.teleport(player); + PaperLib.teleportAsync(playerSender, player.getLocation()); } playerSender.setSpectatorTarget(player); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_staffworld.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_staffworld.java index 20cc96b2..203429cd 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_staffworld.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_staffworld.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import io.papermc.lib.PaperLib; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -72,7 +73,7 @@ public class Command_staffworld extends FreedomCommand if (staffWorld == null || playerSender.getWorld() == staffWorld) { msg("Going to the main world."); - playerSender.teleport(server.getWorlds().get(0).getSpawnLocation()); + PaperLib.teleportAsync(playerSender, server.getWorlds().get(0).getSpawnLocation()); } else { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tprandom.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tprandom.java index fa57e979..ab4ef62e 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tprandom.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tprandom.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import io.papermc.lib.PaperLib; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.ChatColor; @@ -19,7 +20,7 @@ public class Command_tprandom extends FreedomCommand int z = FUtil.randomInteger(-50000, 50000); int y = playerSender.getWorld().getHighestBlockYAt(x, z); Location location = new Location(playerSender.getLocation().getWorld(), x, y, z); - playerSender.teleport(location); + PaperLib.teleportAsync(playerSender, location); msg("Poof!", ChatColor.GREEN); return true; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/world/CustomWorld.java b/src/main/java/me/totalfreedom/totalfreedommod/world/CustomWorld.java index ec2ff8f2..e70c619c 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/world/CustomWorld.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/world/CustomWorld.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.world; +import io.papermc.lib.PaperLib; import lombok.Getter; import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.util.FLog; @@ -49,7 +50,7 @@ public abstract class CustomWorld extends FreedomService { try { - player.teleport(getWorld().getSpawnLocation()); + PaperLib.teleportAsync(player, getWorld().getSpawnLocation()); } catch (Exception ex) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/world/WorldManager.java b/src/main/java/me/totalfreedom/totalfreedommod/world/WorldManager.java index a6371069..5f7b3856 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/world/WorldManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/world/WorldManager.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.world; +import io.papermc.lib.PaperLib; import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.util.FUtil; @@ -127,7 +128,7 @@ public class WorldManager extends FreedomService if (player.getWorld().getName().equalsIgnoreCase(targetWorld)) { playerMsg(player, "Going to main world.", ChatColor.GRAY); - player.teleport(Bukkit.getWorlds().get(0).getSpawnLocation()); + PaperLib.teleportAsync(player, Bukkit.getWorlds().get(0).getSpawnLocation()); return; } @@ -136,12 +137,11 @@ public class WorldManager extends FreedomService if (world.getName().equalsIgnoreCase(targetWorld)) { playerMsg(player, "Going to world: " + targetWorld, ChatColor.GRAY); - player.teleport(world.getSpawnLocation()); + PaperLib.teleportAsync(player, world.getSpawnLocation()); return; } } playerMsg(player, "World " + targetWorld + " not found.", ChatColor.GRAY); } - }