|
59 | 59 | import org.bukkit.potion.PotionEffect; |
60 | 60 | import org.bukkit.potion.PotionEffectType; |
61 | 61 |
|
62 | | -import java.lang.reflect.InvocationTargetException; |
63 | 62 | import java.net.InetSocketAddress; |
64 | 63 | import java.util.ArrayList; |
65 | 64 | import java.util.List; |
@@ -408,8 +407,14 @@ public MCEntity getSpectatorTarget() { |
408 | 407 | return BukkitConvertor.BukkitGetCorrectEntity(p.getSpectatorTarget()); |
409 | 408 | } |
410 | 409 |
|
411 | | - @Override |
412 | | - public void setTempOp(Boolean value) throws ClassNotFoundException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { |
| 410 | + private static Class gameProfileClass = null; |
| 411 | + private static Class opListEntryClass = null; |
| 412 | + private static Map<String, Object> opMap = null; |
| 413 | + |
| 414 | + private static void SetupTempOp() throws ClassNotFoundException { |
| 415 | + if(gameProfileClass != null) { |
| 416 | + return; |
| 417 | + } |
413 | 418 | boolean isPaper = ((BukkitMCServer) Static.getServer()).isPaper(); |
414 | 419 | // Get some version specific mappings |
415 | 420 | String nms = "net.minecraft.server"; |
@@ -446,18 +451,25 @@ public void setTempOp(Boolean value) throws ClassNotFoundException, NoSuchFieldE |
446 | 451 |
|
447 | 452 | Class nmsMinecraftServerClass = Class.forName(nms + ".MinecraftServer"); |
448 | 453 | /*n.m.s.MinecraftServer*/ Object nmsServer = ReflectionUtils.invokeMethod(nmsMinecraftServerClass, null, "getServer"); |
449 | | - /*n.m.s.PlayerList*/ Object nmsPlayerList = ReflectionUtils.invokeMethod(nmsServer, getPlayerList); |
450 | | - /*n.m.s.OpList*/ Object opSet = ReflectionUtils.get(Class.forName(playersPackage + ".PlayerList"), nmsPlayerList, ops); |
451 | | - //opSet.getClass().getSuperclass() == n.m.s.JsonList |
452 | | - Map/*<String, n.m.s.OpListEntry>*/ d = (Map) ReflectionUtils.get(opSet.getClass().getSuperclass(), opSet, "d"); |
| 454 | + /*n.m.s.players.PlayerList*/ Object nmsPlayerList = ReflectionUtils.invokeMethod(nmsServer, getPlayerList); |
| 455 | + /*n.m.s.players.OpList*/ Object opSet = ReflectionUtils.get(Class.forName(playersPackage + ".PlayerList"), nmsPlayerList, ops); |
| 456 | + //opSet.getClass().getSuperclass() == n.m.s.players.JsonList |
| 457 | + /*Map<String, n.m.s.players.OpListEntry>*/ opMap = (Map) ReflectionUtils.get(opSet.getClass().getSuperclass(), opSet, "d"); |
| 458 | + /*n.m.s.players.OpListEntry*/ opListEntryClass = Class.forName(playersPackage + ".OpListEntry"); |
| 459 | + /*com.mojang.authlib.GameProfile*/ gameProfileClass = Class.forName("com.mojang.authlib.GameProfile"); |
| 460 | + } |
| 461 | + |
| 462 | + @Override |
| 463 | + public void setTempOp(Boolean value) throws ClassNotFoundException { |
| 464 | + SetupTempOp(); |
453 | 465 | if(value) { |
454 | | - /*n.m.s.OpListEntry*/ Class nmsOpListEntry = Class.forName(playersPackage + ".OpListEntry"); |
455 | | - /*com.mojang.authlib.GameProfile*/ Class nmsGameProfile = Class.forName("com.mojang.authlib.GameProfile"); |
456 | 466 | Object gameProfile = ReflectionUtils.invokeMethod(p, "getProfile"); |
457 | | - Object opListEntry = ReflectionUtils.newInstance(nmsOpListEntry, new Class[]{nmsGameProfile, int.class, boolean.class}, new Object[]{gameProfile, 4, false}); |
458 | | - d.put(p.getUniqueId().toString(), opListEntry); |
| 467 | + Object opListEntry = ReflectionUtils.newInstance(opListEntryClass, |
| 468 | + new Class[]{gameProfileClass, int.class, boolean.class}, |
| 469 | + new Object[]{gameProfile, 4, false}); |
| 470 | + opMap.put(p.getUniqueId().toString(), opListEntry); |
459 | 471 | } else { |
460 | | - d.remove(p.getUniqueId().toString()); |
| 472 | + opMap.remove(p.getUniqueId().toString()); |
461 | 473 | } |
462 | 474 | p.recalculatePermissions(); |
463 | 475 | } |
|
0 commit comments