Fixed npcs can be shown to other players using external mods

This commit is contained in:
OmerBenGera 2022-07-14 21:50:04 +03:00
parent 1992f03b0e
commit 2750455435
10 changed files with 81 additions and 20 deletions

View File

@ -1,6 +1,7 @@
package com.bgsoftware.wildloaders.api.npc;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.UUID;
@ -25,4 +26,9 @@ public interface ChunkLoaderNPC {
*/
Location getLocation();
/**
* Get the player object of this npc.
*/
Player getPlayer();
}

View File

@ -2,9 +2,11 @@ package com.bgsoftware.wildloaders.listeners;
import com.bgsoftware.wildloaders.Updater;
import com.bgsoftware.wildloaders.WildLoadersPlugin;
import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC;
import com.bgsoftware.wildloaders.utils.threads.Executor;
import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
@ -13,22 +15,29 @@ public final class PlayersListener implements Listener {
private final WildLoadersPlugin plugin;
public PlayersListener(WildLoadersPlugin plugin){
public PlayersListener(WildLoadersPlugin plugin) {
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerJoinMonitor(PlayerJoinEvent event) {
for (ChunkLoaderNPC npc : plugin.getNPCs().getNPCs().values()) {
event.getPlayer().hidePlayer(npc.getPlayer());
}
}
/*
Just notifies me if the server is using WildBuster
*/
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e){
if(e.getPlayer().getUniqueId().toString().equals("45713654-41bf-45a1-aa6f-00fe6598703b")){
public void onPlayerJoin(PlayerJoinEvent e) {
if (e.getPlayer().getUniqueId().toString().equals("45713654-41bf-45a1-aa6f-00fe6598703b")) {
Executor.sync(() -> e.getPlayer().sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.WHITE + "WildSeries" + ChatColor.DARK_GRAY + "] " +
ChatColor.GRAY + "This server is using WildLoaders v" + plugin.getDescription().getVersion()), 5L);
}
if(e.getPlayer().isOp() && Updater.isOutdated()){
if (e.getPlayer().isOp() && Updater.isOutdated()) {
Executor.sync(() -> e.getPlayer().sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "WildLoaders" +
ChatColor.GRAY + " A new version is available (v" + Updater.getLatestVersion() + ")!"), 20L);
}

View File

@ -27,6 +27,7 @@ import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_12_R1.CraftServer;
import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
import org.bukkit.entity.Player;
import java.lang.reflect.Field;
import java.util.UUID;
@ -77,6 +78,11 @@ public final class ChunkLoaderNPC_v1_12_R1 extends EntityPlayer implements Chunk
return getBukkitEntity().getLocation();
}
@Override
public Player getPlayer() {
return getBukkitEntity();
}
@Override
protected boolean damageEntity0(DamageSource damagesource, float f) {
return false;

View File

@ -26,6 +26,7 @@ import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_16_R3.CraftServer;
import org.bukkit.craftbukkit.v1_16_R3.CraftWorld;
import org.bukkit.entity.Player;
import java.lang.reflect.Field;
import java.util.UUID;
@ -83,6 +84,11 @@ public final class ChunkLoaderNPC_v1_16_R3 extends EntityPlayer implements Chunk
return getBukkitEntity().getLocation();
}
@Override
public Player getPlayer() {
return getBukkitEntity();
}
public static class DummyNetworkManager extends NetworkManager {
private static Field channelField;

View File

@ -25,6 +25,7 @@ import net.minecraft.world.level.EnumGamemode;
import net.minecraft.world.phys.AxisAlignedBB;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
import org.bukkit.entity.Player;
import java.util.UUID;
@ -83,6 +84,11 @@ public final class ChunkLoaderNPC_v1_17_R1 extends EntityPlayer implements Chunk
return getBukkitEntity().getLocation();
}
@Override
public Player getPlayer() {
return getBukkitEntity();
}
private static void removePlayer(WorldServer worldServer, EntityPlayer entityPlayer){
worldServer.a(entityPlayer, RemovalReason.d);
}

View File

@ -22,6 +22,7 @@ import net.minecraft.world.level.EnumGamemode;
import net.minecraft.world.phys.AxisAlignedBB;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;
import org.bukkit.entity.Player;
import java.util.UUID;
@ -33,7 +34,7 @@ public final class ChunkLoaderNPC_v1_18_R1 extends EntityPlayer implements Chunk
private boolean dieCall = false;
public ChunkLoaderNPC_v1_18_R1(MinecraftServer minecraftServer, Location location, UUID uuid){
public ChunkLoaderNPC_v1_18_R1(MinecraftServer minecraftServer, Location location, UUID uuid) {
super(minecraftServer, ((CraftWorld) location.getWorld()).getHandle(),
new GameProfile(uuid, NPCHandler.getName(location.getWorld().getName())));
@ -69,12 +70,11 @@ public final class ChunkLoaderNPC_v1_18_R1 extends EntityPlayer implements Chunk
@Override
public void a(RemovalReason removalReason) {
if(!dieCall) {
if (!dieCall) {
dieCall = true;
removePlayer(getWorldServer(this), this);
dieCall = false;
}
else {
} else {
super.a(removalReason);
}
}
@ -84,13 +84,18 @@ public final class ChunkLoaderNPC_v1_18_R1 extends EntityPlayer implements Chunk
return getBukkitEntity().getLocation();
}
private static void removePlayer(WorldServer worldServer, EntityPlayer entityPlayer){
@Override
public Player getPlayer() {
return getBukkitEntity();
}
private static void removePlayer(WorldServer worldServer, EntityPlayer entityPlayer) {
worldServer.a(entityPlayer, RemovalReason.d);
}
public static class DummyNetworkManager extends NetworkManager {
DummyNetworkManager(){
DummyNetworkManager() {
super(EnumProtocolDirection.a);
this.k = new DummyChannel();
this.l = null;

View File

@ -22,6 +22,7 @@ import net.minecraft.world.level.EnumGamemode;
import net.minecraft.world.phys.AxisAlignedBB;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld;
import org.bukkit.entity.Player;
import java.util.UUID;
@ -33,7 +34,7 @@ public final class ChunkLoaderNPC_v1_18_R2 extends EntityPlayer implements Chunk
private boolean dieCall = false;
public ChunkLoaderNPC_v1_18_R2(MinecraftServer minecraftServer, Location location, UUID uuid){
public ChunkLoaderNPC_v1_18_R2(MinecraftServer minecraftServer, Location location, UUID uuid) {
super(minecraftServer, ((CraftWorld) location.getWorld()).getHandle(),
new GameProfile(uuid, NPCHandler.getName(location.getWorld().getName())));
@ -69,12 +70,11 @@ public final class ChunkLoaderNPC_v1_18_R2 extends EntityPlayer implements Chunk
@Override
public void a(RemovalReason removalReason) {
if(!dieCall) {
if (!dieCall) {
dieCall = true;
removePlayer(getLevel(this), this);
dieCall = false;
}
else {
} else {
super.a(removalReason);
}
}
@ -84,13 +84,18 @@ public final class ChunkLoaderNPC_v1_18_R2 extends EntityPlayer implements Chunk
return getBukkitEntity().getLocation();
}
private static void removePlayer(WorldServer worldServer, EntityPlayer entityPlayer){
@Override
public Player getPlayer() {
return getBukkitEntity();
}
private static void removePlayer(WorldServer worldServer, EntityPlayer entityPlayer) {
worldServer.a(entityPlayer, RemovalReason.d);
}
public static class DummyNetworkManager extends NetworkManager {
DummyNetworkManager(){
DummyNetworkManager() {
super(EnumProtocolDirection.a);
this.m = new DummyChannel();
this.n = null;

View File

@ -22,6 +22,7 @@ import net.minecraft.world.level.EnumGamemode;
import net.minecraft.world.phys.AxisAlignedBB;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
import org.bukkit.entity.Player;
import java.util.UUID;
@ -83,6 +84,11 @@ public final class ChunkLoaderNPC_v1_19_R1 extends EntityPlayer implements Chunk
return getBukkitEntity().getLocation();
}
@Override
public Player getPlayer() {
return getBukkitEntity();
}
private static void removePlayer(WorldServer worldServer, EntityPlayer entityPlayer) {
worldServer.a(entityPlayer, RemovalReason.d);
}

View File

@ -25,13 +25,14 @@ import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_7_R4.CraftServer;
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
import org.bukkit.entity.Player;
import java.lang.reflect.Field;
import java.util.UUID;
public final class ChunkLoaderNPC_v1_7_R4 extends EntityPlayer implements ChunkLoaderNPC {
public ChunkLoaderNPC_v1_7_R4(Location location, UUID uuid){
public ChunkLoaderNPC_v1_7_R4(Location location, UUID uuid) {
super(((CraftServer) Bukkit.getServer()).getServer(),
((CraftWorld) location.getWorld()).getHandle(),
new GameProfile(uuid, NPCHandler.getName(location.getWorld().getName())),
@ -74,6 +75,11 @@ public final class ChunkLoaderNPC_v1_7_R4 extends EntityPlayer implements ChunkL
return false;
}
@Override
public Player getPlayer() {
return getBukkitEntity();
}
public static class DummyNetworkManager extends NetworkManager {
private static Field channelField;
@ -90,7 +96,7 @@ public final class ChunkLoaderNPC_v1_7_R4 extends EntityPlayer implements ChunkL
}
}
DummyNetworkManager(){
DummyNetworkManager() {
super(false);
updateFields();
}

View File

@ -27,6 +27,7 @@ import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_8_R3.CraftServer;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.entity.Player;
import java.lang.reflect.Field;
import java.util.UUID;
@ -35,7 +36,7 @@ public final class ChunkLoaderNPC_v1_8_R3 extends EntityPlayer implements ChunkL
private static final AxisAlignedBB EMPTY_BOUND = new AxisAlignedBB(0D, 0D, 0D, 0D, 0D, 0D);
public ChunkLoaderNPC_v1_8_R3(Location location, UUID uuid){
public ChunkLoaderNPC_v1_8_R3(Location location, UUID uuid) {
super(((CraftServer) Bukkit.getServer()).getServer(),
((CraftWorld) location.getWorld()).getHandle(),
new GameProfile(uuid, NPCHandler.getName(location.getWorld().getName())),
@ -90,6 +91,11 @@ public final class ChunkLoaderNPC_v1_8_R3 extends EntityPlayer implements ChunkL
return false;
}
@Override
public Player getPlayer() {
return getBukkitEntity();
}
public static class DummyNetworkManager extends NetworkManager {
private static Field channelField;
@ -106,7 +112,7 @@ public final class ChunkLoaderNPC_v1_8_R3 extends EntityPlayer implements ChunkL
}
}
DummyNetworkManager(){
DummyNetworkManager() {
super(EnumProtocolDirection.SERVERBOUND);
updateFields();
}