Skip to content

Commit

Permalink
Fix 1.18.2 spigot bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cavallium committed Aug 16, 2022
1 parent 37e056e commit 5aaf7a9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.warp</groupId>
<artifactId>CoordinatesObfuscator</artifactId>
<version>1.4.6</version>
<version>1.4.7</version>
<name>CoordinatesObfuscator</name>
<build>
<resources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
import com.comphenix.protocol.events.*;
import com.comphenix.protocol.injector.GamePhase;
import com.comphenix.protocol.wrappers.nbt.NbtBase;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;

import java.lang.invoke.MethodType;

import org.bukkit.Bukkit;
import org.bukkit.WorldBorder;
import org.bukkit.entity.Player;
Expand All @@ -28,6 +34,20 @@ public class CoordinatesObfuscator extends JavaPlugin implements Listener {

public static final boolean DEBUG_ENABLED = "debug".equals(System.getProperty("coordinates_obfuscator.env"));
public static final boolean DISALLOW_REMOVING_NONEXISTENT_COORDINATES = false;

private static final MethodHandle CREATE_WORLD_BORDER_METHOD;

static {
var lookup = MethodHandles.publicLookup();
MethodHandle createWorldBorderMethod = null;
try {
Class<?> worldBorderClass = lookup.findClass("org.bukkit.WorldBorder");
createWorldBorderMethod = lookup.findStatic(Bukkit.class, "createWorldBorder", MethodType.methodType(worldBorderClass));
} catch (ClassNotFoundException | IllegalAccessException | NoSuchMethodException e) {
// ignore
}
CREATE_WORLD_BORDER_METHOD = createWorldBorderMethod;
}
private Logger logger;

@Override
Expand All @@ -46,7 +66,7 @@ public void onEnable() {

final ProtocolManager pm = ProtocolLibrary.getProtocolManager();

final HashSet<PacketType> packets = new HashSet<PacketType>();
final HashSet<PacketType> packets = new HashSet<>();

// /Server side packets
{
Expand Down Expand Up @@ -204,7 +224,15 @@ public void onPlayerTeleport(final PlayerRespawnEvent event){
private void setMaxWorldBorder(final Player player){
Bukkit.getScheduler().runTaskLater(this, () -> {
if (!player.isOnline()) return;
WorldBorder border = Bukkit.createWorldBorder();
// Some bukkit versions don't have this method
if (CREATE_WORLD_BORDER_METHOD == null) return;
WorldBorder border;
try {
border = (WorldBorder) CREATE_WORLD_BORDER_METHOD.invokeExact();
} catch (Throwable e) {
// This shouldn't happen
throw new RuntimeException(e);
}
border.setCenter(player.getWorld().getWorldBorder().getCenter());
border.setSize(59999968E7);
player.setWorldBorder(border);
Expand Down

0 comments on commit 5aaf7a9

Please sign in to comment.