Minor code style changes

- Updated FakeEntity and FakeImage classes
- Updated Internals class
This commit is contained in:
José Miguel Moreno committed 2024-10-13 11:28:08 +02:00
1 parent 25d5a33d86
commit c6ff5bb877
3 files changed
+20 -22

No files matched your search

@@ -88,7 +88,11 @@ public abstract class FakeEntity {
if (NETWORK_MANAGER_INJECTOR == null) { // Use single-threaded packet sending if reflection failed
CONNECTION.sendServerPacket(player, packet);
} else { // Use non-blocking packet sending if available (faster, the expected case)
NETWORK_MANAGER_INJECTOR.getInjector(player).sendClientboundPacket(packet.getHandle(), null, false);
NETWORK_MANAGER_INJECTOR.getInjector(player).sendClientboundPacket(
packet.getHandle(),
null,
false
);
}
} catch (IllegalStateException e) {
// Server is shutting down and cannot send the packet, ignore
@@ -444,24 +444,19 @@ public class FakeImage extends FakeEntity {
* @param player Player instance
*/
private void spawnOnceLoaded(@NotNull Player player) {
try {
String playerName = player.getName();
observingPlayers.add(player);
String playerName = player.getName();
observingPlayers.add(player);
// Prepare packets to send
List<PacketContainer> packets = new ArrayList<>();
for (FakeItemFrame frame : frames) {
packets.add(frame.getSpawnPacket());
packets.addAll(frame.getRenderPackets(player, 0));
LOGGER.fine("Spawned FakeItemFrame#" + frame.getId() + " for Player#" + playerName);
}
// Prepare packets to send
List<PacketContainer> packets = new ArrayList<>();
for (FakeItemFrame frame : frames) {
packets.add(frame.getSpawnPacket());
packets.addAll(frame.getRenderPackets(player, 0));
LOGGER.fine("Spawned FakeItemFrame#" + frame.getId() + " for Player#" + playerName);
}
// Send packets
tryToSendPackets(player, packets);
} catch (Exception e) {
// We should log errors and don't just let the default thread exception handler silence them
e.printStackTrace();
}
// Send packets
tryToSendPackets(player, packets);
}
/**
@@ -2,14 +2,12 @@ package io.josemmo.bukkit.plugin.utils;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.command.CommandMap;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.comphenix.protocol.reflect.FuzzyReflection;
import com.comphenix.protocol.utility.MinecraftReflection;
import com.mojang.brigadier.CommandDispatcher;
@@ -36,9 +34,10 @@ public class Internals {
// Get "net.minecraft.server.CommandDispatcher" references
Class<?> nmsDispatcherClass = MinecraftReflection.getMinecraftClass(
/*spigot (1.16.x)*/"CommandDispatcher",
/*spigot*/"commands.CommandDispatcher",
/*mojang/paper*/"commands.Commands");
"CommandDispatcher", // Spigot <1.17
"commands.CommandDispatcher", // Spigot >=1.17
"commands.Commands" // PaperMC
);
Object nmsDispatcherInstance = FuzzyReflection.fromObject(nmsServerInstance, true)
.getMethodByReturnTypeAndParameters("getDispatcher", nmsDispatcherClass)
.invoke(nmsServerInstance);