feat: Drop Items of FakePlayer and Ban real Player on Death
This commit is contained in:
parent
44ef00d397
commit
d2b4772242
7 changed files with 124 additions and 18 deletions
|
@ -24,6 +24,7 @@ import de.cliffbreak.varo.listeners.PlayerDeathListener;
|
||||||
import de.cliffbreak.varo.listeners.PlayerJoinQuitListener;
|
import de.cliffbreak.varo.listeners.PlayerJoinQuitListener;
|
||||||
import de.cliffbreak.varo.listeners.PlayerPreLoginListener;
|
import de.cliffbreak.varo.listeners.PlayerPreLoginListener;
|
||||||
import de.cliffbreak.varo.managers.NPCManager;
|
import de.cliffbreak.varo.managers.NPCManager;
|
||||||
|
import de.cliffbreak.varo.uitls.BanUtils;
|
||||||
|
|
||||||
public class Varo extends JavaPlugin {
|
public class Varo extends JavaPlugin {
|
||||||
|
|
||||||
|
@ -31,6 +32,7 @@ public class Varo extends JavaPlugin {
|
||||||
public FileConfiguration config = YamlConfiguration.loadConfiguration(this.configurationFile);
|
public FileConfiguration config = YamlConfiguration.loadConfiguration(this.configurationFile);
|
||||||
public NPCManager npcManager;
|
public NPCManager npcManager;
|
||||||
public PlayerCache playerCache;
|
public PlayerCache playerCache;
|
||||||
|
public BanUtils banUtils;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
@ -39,6 +41,7 @@ public class Varo extends JavaPlugin {
|
||||||
|
|
||||||
this.npcManager = new NPCManager(this);
|
this.npcManager = new NPCManager(this);
|
||||||
this.playerCache = new PlayerCache(this);
|
this.playerCache = new PlayerCache(this);
|
||||||
|
this.banUtils = new BanUtils(this);
|
||||||
|
|
||||||
// this.config.addDefault("Varo.Start", "TODO: StartDate");
|
// this.config.addDefault("Varo.Start", "TODO: StartDate");
|
||||||
this.config.addDefault("Varo.Debug", false);
|
this.config.addDefault("Varo.Debug", false);
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package de.cliffbreak.varo.commands;
|
package de.cliffbreak.varo.commands;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import com.destroystokyo.paper.Title;
|
import com.destroystokyo.paper.Title;
|
||||||
|
|
||||||
|
@ -36,8 +35,7 @@ public class VaroCommand implements CommandExecutor {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (args.length == 2 && args[0].equals("unban")) {
|
if (args.length == 2 && args[0].equals("unban")) {
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
final ArrayList<String> bans = (ArrayList<String>) this.plugin.config.get("Varo.Bans");
|
|
||||||
try {
|
try {
|
||||||
String result = WebUtils.GET("https://api.mojang.com/users/profiles/minecraft/" + args[1]);
|
String result = WebUtils.GET("https://api.mojang.com/users/profiles/minecraft/" + args[1]);
|
||||||
if (result.isEmpty()) {
|
if (result.isEmpty()) {
|
||||||
|
@ -45,13 +43,11 @@ public class VaroCommand implements CommandExecutor {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
JSONObject uuidObject = (JSONObject) JSONValue.parseWithException(result);
|
JSONObject uuidObject = (JSONObject) JSONValue.parseWithException(result);
|
||||||
if (!bans.contains(uuidObject.get("id").toString())) {
|
if (!plugin.banUtils.isBanned(uuidObject.get("id").toString())) {
|
||||||
sender.sendMessage("§c§lFehler: §r§cDer Spieler ist nicht gebannt.");
|
sender.sendMessage("§c§lFehler: §r§cDer Spieler ist nicht gebannt.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bans.remove(uuidObject.get("id").toString());
|
plugin.banUtils.removeBan(uuidObject.get("id").toString());
|
||||||
this.plugin.config.set("Varo.Bans", bans);
|
|
||||||
this.plugin.saveConfiguration();
|
|
||||||
sender.sendMessage("§a§lErfolg: §r§aDer Spieler ist nun nicht mehr gebannt.");
|
sender.sendMessage("§a§lErfolg: §r§aDer Spieler ist nun nicht mehr gebannt.");
|
||||||
} catch (IOException | ParseException e) {
|
} catch (IOException | ParseException e) {
|
||||||
sender.sendMessage(
|
sender.sendMessage(
|
||||||
|
|
|
@ -29,11 +29,7 @@ public class PlayerDeathListener implements Listener {
|
||||||
|
|
||||||
e.getEntity().setHealth(20d); // Reset health to prevent death dialog after rejoin (if unbanned)
|
e.getEntity().setHealth(20d); // Reset health to prevent death dialog after rejoin (if unbanned)
|
||||||
e.getEntity().setGameMode(GameMode.SPECTATOR);
|
e.getEntity().setGameMode(GameMode.SPECTATOR);
|
||||||
@SuppressWarnings("unchecked")
|
this.plugin.banUtils.addBann(e.getEntity().getUniqueId());
|
||||||
final ArrayList<String> bans = (ArrayList<String>) this.plugin.config.get("Varo.Bans");
|
|
||||||
bans.add(e.getEntity().getUniqueId().toString().replace("-", ""));
|
|
||||||
this.plugin.config.set("Varo.Bans", bans);
|
|
||||||
this.plugin.saveConfiguration();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -52,6 +52,7 @@ public class PlayerJoinQuitListener implements Listener {
|
||||||
|
|
||||||
final Stack<String> changes = new Stack<String>();
|
final Stack<String> changes = new Stack<String>();
|
||||||
|
|
||||||
|
changes.push(" §7• §r§lADD: §rFakePlayer now drops his items and gets real player banned on death");
|
||||||
changes.push(" §7• §r§lADD: §rFakePlayer is no attackable (can also be killed)");
|
changes.push(" §7• §r§lADD: §rFakePlayer is no attackable (can also be killed)");
|
||||||
changes.push(" §7• §r§lADD: §rAdd a FakePlayer if Player is logged out");
|
changes.push(" §7• §r§lADD: §rAdd a FakePlayer if Player is logged out");
|
||||||
changes.push(" §7• §r§lADD: §rAdd /varo test && /varo testremove");
|
changes.push(" §7• §r§lADD: §rAdd /varo test && /varo testremove");
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package de.cliffbreak.varo.listeners;
|
package de.cliffbreak.varo.listeners;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||||
|
@ -19,10 +17,7 @@ public class PlayerPreLoginListener implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerPreLogin(final AsyncPlayerPreLoginEvent e) {
|
public void onPlayerPreLogin(final AsyncPlayerPreLoginEvent e) {
|
||||||
@SuppressWarnings("unchecked")
|
if (plugin.banUtils.isBanned(e.getPlayerProfile().getId()))
|
||||||
final ArrayList<String> bans = (ArrayList<String>) this.plugin.config.get("Varo.Bans");
|
|
||||||
if (bans.contains(e.getPlayerProfile().getId().toString().replace("-", ""))) {
|
|
||||||
e.disallow(Result.KICK_BANNED, "§4Du bist gestorben.\n \n§cDamit bist du aus §eVaro§c ausgeschieden.");
|
e.disallow(Result.KICK_BANNED, "§4Du bist gestorben.\n \n§cDamit bist du aus §eVaro§c ausgeschieden.");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,6 +2,8 @@ package de.cliffbreak.varo.managers;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.properties.Property;
|
import com.mojang.authlib.properties.Property;
|
||||||
|
@ -14,7 +16,10 @@ import org.bukkit.World;
|
||||||
import org.bukkit.craftbukkit.v1_15_R1.CraftServer;
|
import org.bukkit.craftbukkit.v1_15_R1.CraftServer;
|
||||||
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
|
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
|
||||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
||||||
|
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import org.bukkit.scoreboard.Scoreboard;
|
import org.bukkit.scoreboard.Scoreboard;
|
||||||
import org.bukkit.scoreboard.Team;
|
import org.bukkit.scoreboard.Team;
|
||||||
|
@ -28,8 +33,10 @@ import de.cliffbreak.varo.uitls.WebUtils;
|
||||||
import net.minecraft.server.v1_15_R1.DataWatcherObject;
|
import net.minecraft.server.v1_15_R1.DataWatcherObject;
|
||||||
import net.minecraft.server.v1_15_R1.DataWatcherRegistry;
|
import net.minecraft.server.v1_15_R1.DataWatcherRegistry;
|
||||||
import net.minecraft.server.v1_15_R1.EntityPlayer;
|
import net.minecraft.server.v1_15_R1.EntityPlayer;
|
||||||
|
import net.minecraft.server.v1_15_R1.EnumItemSlot;
|
||||||
import net.minecraft.server.v1_15_R1.MinecraftServer;
|
import net.minecraft.server.v1_15_R1.MinecraftServer;
|
||||||
import net.minecraft.server.v1_15_R1.PacketPlayOutEntityDestroy;
|
import net.minecraft.server.v1_15_R1.PacketPlayOutEntityDestroy;
|
||||||
|
import net.minecraft.server.v1_15_R1.PacketPlayOutEntityEquipment;
|
||||||
import net.minecraft.server.v1_15_R1.PacketPlayOutEntityHeadRotation;
|
import net.minecraft.server.v1_15_R1.PacketPlayOutEntityHeadRotation;
|
||||||
import net.minecraft.server.v1_15_R1.PacketPlayOutEntityMetadata;
|
import net.minecraft.server.v1_15_R1.PacketPlayOutEntityMetadata;
|
||||||
import net.minecraft.server.v1_15_R1.PacketPlayOutEntityStatus;
|
import net.minecraft.server.v1_15_R1.PacketPlayOutEntityStatus;
|
||||||
|
@ -44,6 +51,7 @@ public class NPCManager {
|
||||||
|
|
||||||
private final Varo plugin;
|
private final Varo plugin;
|
||||||
private final ArrayList<EntityPlayer> npcs = new ArrayList<EntityPlayer>();
|
private final ArrayList<EntityPlayer> npcs = new ArrayList<EntityPlayer>();
|
||||||
|
private final HashMap<UUID, PlayerInventory> inventories = new HashMap<UUID, PlayerInventory>();
|
||||||
private Scoreboard scoreboard;
|
private Scoreboard scoreboard;
|
||||||
private Team afkTeam;
|
private Team afkTeam;
|
||||||
|
|
||||||
|
@ -65,6 +73,7 @@ public class NPCManager {
|
||||||
final MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
|
final MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
|
||||||
final WorldServer nmsWorld = ((CraftWorld) player.getWorld()).getHandle();
|
final WorldServer nmsWorld = ((CraftWorld) player.getWorld()).getHandle();
|
||||||
final GameProfile gameProfile = new GameProfile(player.getUniqueId(), player.getName());
|
final GameProfile gameProfile = new GameProfile(player.getUniqueId(), player.getName());
|
||||||
|
inventories.put(player.getUniqueId(), player.getInventory());
|
||||||
try {
|
try {
|
||||||
final String result = WebUtils.GET("https://sessionserver.mojang.com/session/minecraft/profile/"
|
final String result = WebUtils.GET("https://sessionserver.mojang.com/session/minecraft/profile/"
|
||||||
+ player.getUniqueId().toString().replace("-", "") + "?unsigned=false");
|
+ player.getUniqueId().toString().replace("-", "") + "?unsigned=false");
|
||||||
|
@ -105,9 +114,25 @@ public class NPCManager {
|
||||||
npc.getDataWatcher().set(new DataWatcherObject<>(17, DataWatcherRegistry.a),
|
npc.getDataWatcher().set(new DataWatcherObject<>(17, DataWatcherRegistry.a),
|
||||||
plugin.playerCache.getMainHandAsByte(player.getUniqueId().toString().replace("-", "")));
|
plugin.playerCache.getMainHandAsByte(player.getUniqueId().toString().replace("-", "")));
|
||||||
connection.sendPacket(new PacketPlayOutEntityMetadata(npc.getId(), npc.getDataWatcher(), true));
|
connection.sendPacket(new PacketPlayOutEntityMetadata(npc.getId(), npc.getDataWatcher(), true));
|
||||||
|
sendEquipmentPackets(connection, npc.getId(), player.getInventory());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendEquipmentPackets(PlayerConnection connection, int id, PlayerInventory inventory) {
|
||||||
|
connection.sendPacket(new PacketPlayOutEntityEquipment(id, EnumItemSlot.MAINHAND,
|
||||||
|
CraftItemStack.asNMSCopy(inventory.getItemInMainHand())));
|
||||||
|
connection.sendPacket(new PacketPlayOutEntityEquipment(id, EnumItemSlot.OFFHAND,
|
||||||
|
CraftItemStack.asNMSCopy(inventory.getItemInOffHand())));
|
||||||
|
connection.sendPacket(new PacketPlayOutEntityEquipment(id, EnumItemSlot.FEET,
|
||||||
|
CraftItemStack.asNMSCopy(inventory.getBoots())));
|
||||||
|
connection.sendPacket(new PacketPlayOutEntityEquipment(id, EnumItemSlot.LEGS,
|
||||||
|
CraftItemStack.asNMSCopy(inventory.getLeggings())));
|
||||||
|
connection.sendPacket(new PacketPlayOutEntityEquipment(id, EnumItemSlot.CHEST,
|
||||||
|
CraftItemStack.asNMSCopy(inventory.getChestplate())));
|
||||||
|
connection.sendPacket(new PacketPlayOutEntityEquipment(id, EnumItemSlot.HEAD,
|
||||||
|
CraftItemStack.asNMSCopy(inventory.getHelmet())));
|
||||||
|
}
|
||||||
|
|
||||||
public void syncClones(Player player) {
|
public void syncClones(Player player) {
|
||||||
for (EntityPlayer npc : this.npcs) {
|
for (EntityPlayer npc : this.npcs) {
|
||||||
final PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
|
final PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
|
@ -119,6 +144,7 @@ public class NPCManager {
|
||||||
npc.getDataWatcher().set(new DataWatcherObject<>(17, DataWatcherRegistry.a),
|
npc.getDataWatcher().set(new DataWatcherObject<>(17, DataWatcherRegistry.a),
|
||||||
plugin.playerCache.getMainHandAsByte(player.getUniqueId().toString().replace("-", "")));
|
plugin.playerCache.getMainHandAsByte(player.getUniqueId().toString().replace("-", "")));
|
||||||
connection.sendPacket(new PacketPlayOutEntityMetadata(npc.getId(), npc.getDataWatcher(), true));
|
connection.sendPacket(new PacketPlayOutEntityMetadata(npc.getId(), npc.getDataWatcher(), true));
|
||||||
|
sendEquipmentPackets(connection, npc.getId(), this.inventories.get(npc.getUniqueID()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,6 +174,7 @@ public class NPCManager {
|
||||||
if (isCritical)
|
if (isCritical)
|
||||||
world.playSound(loc, Sound.ENTITY_PLAYER_ATTACK_CRIT, 1.0F, 1.0F);
|
world.playSound(loc, Sound.ENTITY_PLAYER_ATTACK_CRIT, 1.0F, 1.0F);
|
||||||
} else {
|
} else {
|
||||||
|
// Send Death Animation Packet
|
||||||
for (Player connectionPlayer : Bukkit.getOnlinePlayers()) {
|
for (Player connectionPlayer : Bukkit.getOnlinePlayers()) {
|
||||||
final PlayerConnection connection = ((CraftPlayer) connectionPlayer)
|
final PlayerConnection connection = ((CraftPlayer) connectionPlayer)
|
||||||
.getHandle().playerConnection;
|
.getHandle().playerConnection;
|
||||||
|
@ -156,12 +183,34 @@ public class NPCManager {
|
||||||
if (isCritical)
|
if (isCritical)
|
||||||
world.playSound(loc, Sound.ENTITY_PLAYER_ATTACK_CRIT, 1.0F, 1.0F);
|
world.playSound(loc, Sound.ENTITY_PLAYER_ATTACK_CRIT, 1.0F, 1.0F);
|
||||||
world.playSound(loc, Sound.ENTITY_PLAYER_DEATH, 1.0F, 1.0F);
|
world.playSound(loc, Sound.ENTITY_PLAYER_DEATH, 1.0F, 1.0F);
|
||||||
|
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (ItemStack item : inventories.get(npc.getUniqueID())) {
|
||||||
|
if (item != null)
|
||||||
|
world.dropItem(loc, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}.runTask(plugin); // Run Task in sync to be thread safe
|
||||||
|
|
||||||
|
this.plugin.banUtils.addBann(npc.getUniqueID());
|
||||||
|
Bukkit.broadcastMessage("TODO: Player(" + "??" + ") killed AFK Player (" + npc.getName() + ")");
|
||||||
|
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
removeClone(npc.getUniqueID());
|
||||||
|
}
|
||||||
|
}.runTaskLater(plugin, 20);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: Only for debug reasons -- Remove
|
||||||
public void removeClone(Player player) {
|
public void removeClone(Player player) {
|
||||||
this.afkTeam.removeEntry(player.getName());
|
this.afkTeam.removeEntry(player.getName());
|
||||||
for (int i = 0; i < this.npcs.size(); i++) {
|
for (int i = 0; i < this.npcs.size(); i++) {
|
||||||
|
@ -178,4 +227,28 @@ public class NPCManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeClone(UUID uuid) {
|
||||||
|
for (int i = 0; i < this.npcs.size(); i++) {
|
||||||
|
EntityPlayer npc = this.npcs.get(i);
|
||||||
|
if (npc.getUniqueID().equals(uuid)) {
|
||||||
|
final WorldServer nmsWorld = npc.getWorldServer();
|
||||||
|
|
||||||
|
for (Player connectionPlayer : Bukkit.getOnlinePlayers()) {
|
||||||
|
final PlayerConnection connection = ((CraftPlayer) connectionPlayer).getHandle().playerConnection;
|
||||||
|
connection.sendPacket(new PacketPlayOutEntityDestroy(npc.getId()));
|
||||||
|
connection.sendPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, npc));
|
||||||
|
}
|
||||||
|
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
nmsWorld.removeEntity(npc);
|
||||||
|
afkTeam.removeEntry(npc.getName());
|
||||||
|
npcs.remove(npc);
|
||||||
|
}
|
||||||
|
}.runTask(this.plugin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
42
varo/src/main/java/de/cliffbreak/varo/uitls/BanUtils.java
Normal file
42
varo/src/main/java/de/cliffbreak/varo/uitls/BanUtils.java
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
package de.cliffbreak.varo.uitls;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import de.cliffbreak.varo.Varo;
|
||||||
|
|
||||||
|
public class BanUtils {
|
||||||
|
|
||||||
|
private final Varo plugin;
|
||||||
|
|
||||||
|
public BanUtils(Varo plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBanned(UUID uuid) {
|
||||||
|
return isBanned(uuid.toString().replace("-", ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBanned(String compressedUuid) {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
final ArrayList<String> bans = (ArrayList<String>) this.plugin.config.get("Varo.Bans");
|
||||||
|
return bans.contains(compressedUuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addBann(UUID uuid) {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
final ArrayList<String> bans = (ArrayList<String>) this.plugin.config.get("Varo.Bans");
|
||||||
|
bans.add(uuid.toString().replace("-", ""));
|
||||||
|
this.plugin.config.set("Varo.Bans", bans);
|
||||||
|
this.plugin.saveConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeBan(String compressedUuid) {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
final ArrayList<String> bans = (ArrayList<String>) this.plugin.config.get("Varo.Bans");
|
||||||
|
bans.remove(compressedUuid);
|
||||||
|
this.plugin.config.set("Varo.Bans", bans);
|
||||||
|
this.plugin.saveConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue