Update NMS + Use PaperLib for teleportAsync

This commit is contained in:
Telesphoreo 2020-08-30 19:13:46 -05:00
parent c61f7e78fd
commit 43b266f17d
17 changed files with 57 additions and 41 deletions

17
pom.xml
View File

@ -46,7 +46,12 @@
<repository> <repository>
<id>CodeMC</id> <id>CodeMC</id>
<url>https://repo.codemc.org/repository/maven-public</url> <url>https://repo.codemc.org/repository/maven-public/</url>
</repository>
<repository>
<id>nms-repo</id>
<url>https://repo.codemc.org/repository/nms/</url>
</repository> </repository>
<repository> <repository>
@ -142,7 +147,7 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot</artifactId>
<version>1.16.2-R0.1-SNAPSHOT</version> <version>1.16.2-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
@ -197,10 +202,10 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.destroystokyo.paper</groupId> <groupId>io.papermc</groupId>
<artifactId>paper-api</artifactId> <artifactId>paperlib</artifactId>
<version>1.16.2-R0.1-SNAPSHOT</version> <version>1.0.5</version>
<scope>provided</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -1,5 +1,6 @@
package me.totalfreedom.totalfreedommod; package me.totalfreedom.totalfreedommod;
import io.papermc.lib.PaperLib;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -197,7 +198,7 @@ public class LoginProcess extends FreedomService
int z = FUtil.randomInteger(-10000, 10000); int z = FUtil.randomInteger(-10000, 10000);
int y = player.getWorld().getHighestBlockYAt(x, z); int y = player.getWorld().getHighestBlockYAt(x, z);
Location location = new Location(player.getLocation().getWorld(), x, y, 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."); player.sendMessage(ChatColor.AQUA + "You have been teleported to a random location automatically.");
return; return;
} }

View File

@ -3,14 +3,15 @@ package me.totalfreedom.totalfreedommod;
import ca.momothereal.mojangson.ex.MojangsonParseException; import ca.momothereal.mojangson.ex.MojangsonParseException;
import ca.momothereal.mojangson.value.MojangsonCompound; import ca.momothereal.mojangson.value.MojangsonCompound;
import ca.momothereal.mojangson.value.MojangsonValue; import ca.momothereal.mojangson.value.MojangsonValue;
import io.papermc.lib.PaperLib;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import net.minecraft.server.v1_16_R1.NBTTagCompound; import net.minecraft.server.v1_16_R2.NBTTagCompound;
import net.minecraft.server.v1_16_R1.NBTTagList; import net.minecraft.server.v1_16_R2.NBTTagList;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; 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.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; 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) 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); event.setCancelled(true);
player.teleport(player.getWorld().getSpawnLocation()); PaperLib.teleportAsync(player, player.getWorld().getSpawnLocation());
} }
if (exploitItem(event.getPlayer().getInventory().getHelmet())) if (exploitItem(event.getPlayer().getInventory().getHelmet()))
@ -110,7 +111,7 @@ public class MovementValidator extends FreedomService
// Validate position // 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) 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) 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); NBTTagList modifiers = getAttributeList(nmsStack);
MojangsonCompound compound = new MojangsonCompound(); MojangsonCompound compound = new MojangsonCompound();
boolean foundNegative = false; 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) if (stack.getTag() == null)
{ {

View File

@ -4,14 +4,14 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import net.minecraft.server.v1_16_R1.EntityPlayer; import net.minecraft.server.v1_16_R2.EntityPlayer;
import net.minecraft.server.v1_16_R1.MinecraftServer; import net.minecraft.server.v1_16_R2.MinecraftServer;
import org.bukkit.Bukkit; 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 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 @Override
public void onStart() public void onStart()

View File

@ -1,10 +1,10 @@
package me.totalfreedom.totalfreedommod.blocking; package me.totalfreedom.totalfreedommod.blocking;
import me.totalfreedom.totalfreedommod.FreedomService; 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.ChatColor;
import org.bukkit.Tag; 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.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
@ -35,7 +35,7 @@ public class SignBlocker extends FreedomService
if (Tag.SIGNS.getValues().contains(event.getBlock().getType())) if (Tag.SIGNS.getValues().contains(event.getBlock().getType()))
{ {
ItemStack sign = event.getItemInHand(); 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 compound = (nmsSign.hasTag()) ? nmsSign.getTag() : new NBTTagCompound();
NBTTagCompound bet = compound.getCompound("BlockEntityTag"); NBTTagCompound bet = compound.getCompound("BlockEntityTag");
String line1 = bet.getString("Text1"); String line1 = bet.getString("Text1");

View File

@ -1,5 +1,6 @@
package me.totalfreedom.totalfreedommod.caging; package me.totalfreedom.totalfreedommod.caging;
import io.papermc.lib.PaperLib;
import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
@ -71,7 +72,7 @@ public class Cager extends FreedomService
if (outOfCage) 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); FUtil.playerMsg(player.getPlayer(), "You may not leave your cage.", ChatColor.RED);
cage.regenerate(); cage.regenerate();
} }

View File

@ -1,5 +1,6 @@
package me.totalfreedom.totalfreedommod.command; package me.totalfreedom.totalfreedommod.command;
import io.papermc.lib.PaperLib;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -72,7 +73,7 @@ public class Command_hubworld extends FreedomCommand
if (hubWorld == null || playerSender.getWorld() == hubWorld) if (hubWorld == null || playerSender.getWorld() == hubWorld)
{ {
msg("Going to the main world."); msg("Going to the main world.");
playerSender.teleport(server.getWorlds().get(0).getSpawnLocation()); PaperLib.teleportAsync(playerSender, server.getWorlds().get(0).getSpawnLocation());
} }
else else
{ {

View File

@ -1,5 +1,6 @@
package me.totalfreedom.totalfreedommod.command; package me.totalfreedom.totalfreedommod.command;
import io.papermc.lib.PaperLib;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -12,7 +13,7 @@ public class Command_localspawn extends FreedomCommand
@Override @Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) 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() + "\"."); msg("Teleported to spawnpoint for world \"" + playerSender.getWorld().getName() + "\".");
return true; return true;
} }

View File

@ -1,5 +1,6 @@
package me.totalfreedom.totalfreedommod.command; package me.totalfreedom.totalfreedommod.command;
import io.papermc.lib.PaperLib;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -72,7 +73,7 @@ public class Command_masterbuilderworld extends FreedomCommand
if (masterBuilderWorld == null || playerSender.getWorld() == masterBuilderWorld) if (masterBuilderWorld == null || playerSender.getWorld() == masterBuilderWorld)
{ {
msg("Going to the main world."); msg("Going to the main world.");
playerSender.teleport(server.getWorlds().get(0).getSpawnLocation()); PaperLib.teleportAsync(playerSender, server.getWorlds().get(0).getSpawnLocation());
} }
else else
{ {

View File

@ -5,13 +5,13 @@ import java.util.List;
import java.util.Random; import java.util.Random;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import net.minecraft.server.v1_16_R1.NBTTagCompound; import net.minecraft.server.v1_16_R2.NBTTagCompound;
import net.minecraft.server.v1_16_R1.NBTTagList; import net.minecraft.server.v1_16_R2.NBTTagList;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; 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.enchantments.Enchantment;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -149,7 +149,7 @@ public class Command_modifyitem extends FreedomCommand
{ {
return false; 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(); NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
NBTTagList modifiers = getAttributeList(nmsStack); NBTTagList modifiers = getAttributeList(nmsStack);
NBTTagCompound cmpnd = new NBTTagCompound(); NBTTagCompound cmpnd = new NBTTagCompound();
@ -199,7 +199,7 @@ public class Command_modifyitem extends FreedomCommand
return true; 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) if (stack.getTag() == null)
{ {

View File

@ -1,5 +1,6 @@
package me.totalfreedom.totalfreedommod.command; package me.totalfreedom.totalfreedommod.command;
import io.papermc.lib.PaperLib;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -10,14 +11,13 @@ import org.bukkit.entity.Player;
@CommandParameters(description = "Go to the PlotWorld.", usage = "/<command>", aliases = "pw") @CommandParameters(description = "Go to the PlotWorld.", usage = "/<command>", aliases = "pw")
public class Command_plotworld extends FreedomCommand public class Command_plotworld extends FreedomCommand
{ {
@Override @Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
World plotworld = server.getWorld("plotworld"); World plotworld = server.getWorld("plotworld");
if (plotworld != null) if (plotworld != null)
{ {
playerSender.teleport(plotworld.getSpawnLocation()); PaperLib.teleportAsync(playerSender, plotworld.getSpawnLocation());
} }
else else
{ {

View File

@ -1,5 +1,6 @@
package me.totalfreedom.totalfreedommod.command; package me.totalfreedom.totalfreedommod.command;
import io.papermc.lib.PaperLib;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.TimerTask; import java.util.TimerTask;
@ -55,7 +56,7 @@ public class Command_ride extends FreedomCommand
if (requester.getWorld() != playerSender.getWorld()) if (requester.getWorld() != playerSender.getWorld())
{ {
requester.teleport(playerSender); PaperLib.teleportAsync(requester, playerSender.getLocation());
} }
playerSender.addPassenger(requester); playerSender.addPassenger(requester);
@ -145,7 +146,7 @@ public class Command_ride extends FreedomCommand
if (player.getWorld() != playerSender.getWorld()) if (player.getWorld() != playerSender.getWorld())
{ {
playerSender.teleport(player); PaperLib.teleportAsync(playerSender, player.getLocation());
} }
player.addPassenger(playerSender); player.addPassenger(playerSender);

View File

@ -1,5 +1,6 @@
package me.totalfreedom.totalfreedommod.command; package me.totalfreedom.totalfreedommod.command;
import io.papermc.lib.PaperLib;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.GameMode; import org.bukkit.GameMode;
@ -40,7 +41,7 @@ public class Command_spectate extends FreedomCommand
if (playerSender.getWorld() != player.getWorld()) if (playerSender.getWorld() != player.getWorld())
{ {
playerSender.teleport(player); PaperLib.teleportAsync(playerSender, player.getLocation());
} }
playerSender.setSpectatorTarget(player); playerSender.setSpectatorTarget(player);

View File

@ -1,5 +1,6 @@
package me.totalfreedom.totalfreedommod.command; package me.totalfreedom.totalfreedommod.command;
import io.papermc.lib.PaperLib;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -72,7 +73,7 @@ public class Command_staffworld extends FreedomCommand
if (staffWorld == null || playerSender.getWorld() == staffWorld) if (staffWorld == null || playerSender.getWorld() == staffWorld)
{ {
msg("Going to the main world."); msg("Going to the main world.");
playerSender.teleport(server.getWorlds().get(0).getSpawnLocation()); PaperLib.teleportAsync(playerSender, server.getWorlds().get(0).getSpawnLocation());
} }
else else
{ {

View File

@ -1,5 +1,6 @@
package me.totalfreedom.totalfreedommod.command; package me.totalfreedom.totalfreedommod.command;
import io.papermc.lib.PaperLib;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -19,7 +20,7 @@ public class Command_tprandom extends FreedomCommand
int z = FUtil.randomInteger(-50000, 50000); int z = FUtil.randomInteger(-50000, 50000);
int y = playerSender.getWorld().getHighestBlockYAt(x, z); int y = playerSender.getWorld().getHighestBlockYAt(x, z);
Location location = new Location(playerSender.getLocation().getWorld(), x, y, z); Location location = new Location(playerSender.getLocation().getWorld(), x, y, z);
playerSender.teleport(location); PaperLib.teleportAsync(playerSender, location);
msg("Poof!", ChatColor.GREEN); msg("Poof!", ChatColor.GREEN);
return true; return true;
} }

View File

@ -1,5 +1,6 @@
package me.totalfreedom.totalfreedommod.world; package me.totalfreedom.totalfreedommod.world;
import io.papermc.lib.PaperLib;
import lombok.Getter; import lombok.Getter;
import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FLog;
@ -49,7 +50,7 @@ public abstract class CustomWorld extends FreedomService
{ {
try try
{ {
player.teleport(getWorld().getSpawnLocation()); PaperLib.teleportAsync(player, getWorld().getSpawnLocation());
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -1,5 +1,6 @@
package me.totalfreedom.totalfreedommod.world; package me.totalfreedom.totalfreedommod.world;
import io.papermc.lib.PaperLib;
import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
@ -127,7 +128,7 @@ public class WorldManager extends FreedomService
if (player.getWorld().getName().equalsIgnoreCase(targetWorld)) if (player.getWorld().getName().equalsIgnoreCase(targetWorld))
{ {
playerMsg(player, "Going to main world.", ChatColor.GRAY); playerMsg(player, "Going to main world.", ChatColor.GRAY);
player.teleport(Bukkit.getWorlds().get(0).getSpawnLocation()); PaperLib.teleportAsync(player, Bukkit.getWorlds().get(0).getSpawnLocation());
return; return;
} }
@ -136,12 +137,11 @@ public class WorldManager extends FreedomService
if (world.getName().equalsIgnoreCase(targetWorld)) if (world.getName().equalsIgnoreCase(targetWorld))
{ {
playerMsg(player, "Going to world: " + targetWorld, ChatColor.GRAY); playerMsg(player, "Going to world: " + targetWorld, ChatColor.GRAY);
player.teleport(world.getSpawnLocation()); PaperLib.teleportAsync(player, world.getSpawnLocation());
return; return;
} }
} }
playerMsg(player, "World " + targetWorld + " not found.", ChatColor.GRAY); playerMsg(player, "World " + targetWorld + " not found.", ChatColor.GRAY);
} }
} }