diff --git a/Core.iml b/Core.iml index c49390e..8a9805d 100644 --- a/Core.iml +++ b/Core.iml @@ -11,6 +11,7 @@ + @@ -24,10 +25,7 @@ - - - @@ -38,6 +36,7 @@ + diff --git a/pom.xml b/pom.xml index 13beb7f..7830560 100644 --- a/pom.xml +++ b/pom.xml @@ -56,6 +56,12 @@ + + org.projectlombok + lombok + 1.14.8 + provided + org.spigotmc spigot-api @@ -75,7 +81,7 @@ eu.univento - CloudCommons + Commons 1.0-SNAPSHOT diff --git a/src/main/java/eu/univento/core/Core.java b/src/main/java/eu/univento/core/Core.java index 782af01..b26b23f 100644 --- a/src/main/java/eu/univento/core/Core.java +++ b/src/main/java/eu/univento/core/Core.java @@ -199,6 +199,7 @@ public class Core extends JavaPlugin implements NettyInjection.PacketHandler { " \n" + " \n" + "\n"), 0L); + /* Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> { for (Plugin plugin : pm.getPlugins()) { if (!plugin.getName().equalsIgnoreCase("WorldEdit") && !plugin.getName().equalsIgnoreCase("VoxelSniper") && !registeredPlugins.contains(plugin.getName())) { @@ -207,6 +208,7 @@ public class Core extends JavaPlugin implements NettyInjection.PacketHandler { } } }, 5L); + */ this.injection = new NettyInjection(this, this.getName()); this.injection.addHandler("TIMEOUT", new NettyInjection.PacketHandler() { public Object onPacketIn(Player sender, Channel channel, Object packet) { @@ -222,11 +224,13 @@ public class Core extends JavaPlugin implements NettyInjection.PacketHandler { return packet; } }); + /* commons.getSecurityHandler().isValidServer(getServer().getIp(), aBoolean -> { if(!aBoolean) { getServer().shutdown(); } }); + */ Bukkit.getScheduler().runTask(this, new TPS()); debugManager = new DebugManager(); } diff --git a/src/main/java/eu/univento/core/antihack/AntiHack.java b/src/main/java/eu/univento/core/antihack/AntiHack.java index a0fe67b..bad74f2 100644 --- a/src/main/java/eu/univento/core/antihack/AntiHack.java +++ b/src/main/java/eu/univento/core/antihack/AntiHack.java @@ -1,10 +1,10 @@ package eu.univento.core.antihack; +import eu.univento.commons.player.warn.WarnReason; import eu.univento.core.Core; import eu.univento.core.antihack.modules.*; import eu.univento.core.antihack.utils.PacketInjector; import eu.univento.core.api.player.CustomPlayer; -import eu.univento.core.api.player.WarnReason; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -28,11 +28,15 @@ public class AntiHack implements Listener{ pm.registerEvents(new Regen(), Core.getInstance()); pm.registerEvents(new AutoRespawn(), Core.getInstance()); pm.registerEvents(new FastPlace(), Core.getInstance()); + pm.registerEvents(new AutoSoup(), Core.getInstance()); + pm.registerEvents(new Nuker(), Core.getInstance()); + pm.registerEvents(new SelfHit(), Core.getInstance()); + pm.registerEvents(new BowAimbot(), Core.getInstance()); //pm.registerEvents(new KillAura(), Core.getInstance()); Bukkit.getScheduler().scheduleSyncRepeatingTask(Core.getInstance(), () -> { for(Map.Entry entry : AutoClicker.clicks.entrySet()) { - if(entry.getValue() > 16) { + if(entry.getValue() > 25) { //TODO: change to real warn reason entry.getKey().warn(WarnReason.SPAM, null, "https://players.univento.eu/" + entry.getKey().getUniqueId().toString() + "/hacks"); } diff --git a/src/main/java/eu/univento/core/antihack/modules/AutoRespawn.java b/src/main/java/eu/univento/core/antihack/modules/AutoRespawn.java index 48f5669..00c3a59 100644 --- a/src/main/java/eu/univento/core/antihack/modules/AutoRespawn.java +++ b/src/main/java/eu/univento/core/antihack/modules/AutoRespawn.java @@ -1,7 +1,7 @@ package eu.univento.core.antihack.modules; +import eu.univento.commons.player.warn.WarnReason; import eu.univento.core.api.player.CustomPlayer; -import eu.univento.core.api.player.WarnReason; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; diff --git a/src/main/java/eu/univento/core/antihack/modules/AutoSoup.java b/src/main/java/eu/univento/core/antihack/modules/AutoSoup.java index bb95d37..921c974 100644 --- a/src/main/java/eu/univento/core/antihack/modules/AutoSoup.java +++ b/src/main/java/eu/univento/core/antihack/modules/AutoSoup.java @@ -1,5 +1,6 @@ package eu.univento.core.antihack.modules; +import eu.univento.commons.player.warn.WarnReason; import eu.univento.core.api.player.CustomPlayer; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -16,8 +17,9 @@ public class AutoSoup implements Listener{ public void onEntityDamageByEntity(EntityDamageByEntityEvent e) { if(e.getEntity() instanceof Player && e.getDamager() instanceof Player) { CustomPlayer p = (CustomPlayer) e.getDamager(); - if(p.getInventory().getViewers().size() < 0) { + if(p.getInventory().getViewers().contains(p)) { p.closeInventory(); + p.warn(WarnReason.SPAM, null, ""); } } } diff --git a/src/main/java/eu/univento/core/antihack/modules/BowAimbot.java b/src/main/java/eu/univento/core/antihack/modules/BowAimbot.java new file mode 100644 index 0000000..07bc709 --- /dev/null +++ b/src/main/java/eu/univento/core/antihack/modules/BowAimbot.java @@ -0,0 +1,84 @@ +package eu.univento.core.antihack.modules; + +import eu.univento.core.api.player.CustomPlayer; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.ProjectileLaunchEvent; + +import java.util.HashMap; + +import static jdk.nashorn.internal.objects.NativeMath.log; + +/** + * @author joethei + * @version 0.1 + */ + +public class BowAimbot implements Listener { + + private HashMap totalShots = new HashMap<>(); + private HashMap totalHits = new HashMap<>(); + + + + private int getTotalShots(CustomPlayer p){ + if(!(totalShots.containsKey(p))){ + totalShots.put(p, 0); + } + + return totalShots.get(p); + } + + private int getTotalHits(CustomPlayer p){ + if(!(totalHits.containsKey(p))){ + totalHits.put(p, 0); + } + + return totalHits.get(p); + } + + private int getHitRatio(CustomPlayer p){ + int shots = getTotalShots(p); + int hits = getTotalHits(p); + + return (hits / shots) * 100; + } + + @EventHandler + public void onEntityDamageByEntity(EntityDamageByEntityEvent event){ + if(event.getDamager() instanceof Arrow){ + Arrow arrow = (Arrow) event.getDamager(); + + if(arrow.getShooter() instanceof Player){ + CustomPlayer p = CustomPlayer.getPlayer((Player) arrow.getShooter()); + int hits = getTotalHits(p) + 1; + + totalHits.put(p, hits); + + if(hits >= 10){ + int ratio = getHitRatio(p); + + if(ratio >= 80){ + log(p, ratio + "% hits"); + } + } + } + } + } + + @EventHandler + public void onProjectileLaunch(ProjectileLaunchEvent event){ + if(event.getEntity() instanceof Arrow){ + Arrow arrow = (Arrow) event.getEntity(); + + if(arrow.getShooter() instanceof Player){ + CustomPlayer p = CustomPlayer.getPlayer((Player) arrow.getShooter()); + + totalShots.put(p, getTotalShots(p) + 1); + } + } + } +} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/antihack/modules/Criticals.java b/src/main/java/eu/univento/core/antihack/modules/Criticals.java index 9932f6f..35139c3 100644 --- a/src/main/java/eu/univento/core/antihack/modules/Criticals.java +++ b/src/main/java/eu/univento/core/antihack/modules/Criticals.java @@ -1,8 +1,8 @@ package eu.univento.core.antihack.modules; +import eu.univento.commons.player.warn.WarnReason; import eu.univento.core.Core; import eu.univento.core.api.player.CustomPlayer; -import eu.univento.core.api.player.WarnReason; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; diff --git a/src/main/java/eu/univento/core/antihack/modules/FastPlace.java b/src/main/java/eu/univento/core/antihack/modules/FastPlace.java index e9d9547..d16e19f 100644 --- a/src/main/java/eu/univento/core/antihack/modules/FastPlace.java +++ b/src/main/java/eu/univento/core/antihack/modules/FastPlace.java @@ -1,7 +1,7 @@ package eu.univento.core.antihack.modules; +import eu.univento.commons.player.warn.WarnReason; import eu.univento.core.api.player.CustomPlayer; -import eu.univento.core.api.player.WarnReason; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockPlaceEvent; diff --git a/src/main/java/eu/univento/core/antihack/modules/Nuker.java b/src/main/java/eu/univento/core/antihack/modules/Nuker.java index e243648..304bc34 100644 --- a/src/main/java/eu/univento/core/antihack/modules/Nuker.java +++ b/src/main/java/eu/univento/core/antihack/modules/Nuker.java @@ -1,7 +1,7 @@ package eu.univento.core.antihack.modules; +import eu.univento.commons.player.warn.WarnReason; import eu.univento.core.api.player.CustomPlayer; -import eu.univento.core.api.player.WarnReason; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; @@ -12,7 +12,7 @@ import java.util.LinkedHashMap; * @author joethei * @version 0.1 */ -class Nuker implements Listener { +public class Nuker implements Listener { private final LinkedHashMap last = new LinkedHashMap<>(); private final LinkedHashMap blocks = new LinkedHashMap<>(); diff --git a/src/main/java/eu/univento/core/antihack/modules/Regen.java b/src/main/java/eu/univento/core/antihack/modules/Regen.java index 189d375..f3d56bb 100644 --- a/src/main/java/eu/univento/core/antihack/modules/Regen.java +++ b/src/main/java/eu/univento/core/antihack/modules/Regen.java @@ -1,8 +1,8 @@ package eu.univento.core.antihack.modules; +import eu.univento.commons.player.warn.WarnReason; import eu.univento.core.Core; import eu.univento.core.api.player.CustomPlayer; -import eu.univento.core.api.player.WarnReason; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; diff --git a/src/main/java/eu/univento/core/antihack/utils/PacketHandler.java b/src/main/java/eu/univento/core/antihack/utils/PacketHandler.java index 656c540..9c00927 100644 --- a/src/main/java/eu/univento/core/antihack/utils/PacketHandler.java +++ b/src/main/java/eu/univento/core/antihack/utils/PacketHandler.java @@ -1,11 +1,11 @@ package eu.univento.core.antihack.utils; import com.mojang.authlib.GameProfile; +import eu.univento.commons.player.warn.WarnReason; import eu.univento.core.Core; import eu.univento.core.antihack.modules.KillAura; import eu.univento.core.api.fakeplayer.FakePlayer; import eu.univento.core.api.player.CustomPlayer; -import eu.univento.core.api.player.WarnReason; import io.netty.channel.ChannelDuplexHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelPromise; diff --git a/src/main/java/eu/univento/core/api/gui/AnvilGUI.java b/src/main/java/eu/univento/core/api/gui/AnvilGUI.java index 60642a0..247a475 100644 --- a/src/main/java/eu/univento/core/api/gui/AnvilGUI.java +++ b/src/main/java/eu/univento/core/api/gui/AnvilGUI.java @@ -83,16 +83,16 @@ public class AnvilGUI { return close; } - public void setWillClose(){ - this.close = true; + public void setWillClose(boolean close){ + this.close = close; } public boolean getWillDestroy(){ return destroy; } - public void setWillDestroy(){ - this.destroy = true; + public void setWillDestroy(boolean destroy){ + this.destroy = destroy; } } @@ -178,8 +178,8 @@ public class AnvilGUI { return player; } - public void setSlot(ItemStack item){ - items.put(AnvilSlot.INPUT_LEFT, item); + public void setSlot(AnvilSlot slot, ItemStack item){ + items.put(slot, item); } public void open(){ diff --git a/src/main/java/eu/univento/core/api/npc/NPC.java b/src/main/java/eu/univento/core/api/npc/NPC.java new file mode 100644 index 0000000..c3d0d6c --- /dev/null +++ b/src/main/java/eu/univento/core/api/npc/NPC.java @@ -0,0 +1,153 @@ +package eu.univento.core.api.npc; + +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; +import eu.univento.commons.player.uuid.UUIDFetcher; +import eu.univento.core.Core; +import eu.univento.core.api.player.CustomPlayer; +import eu.univento.core.api.utils.GameProfileBuilder; +import lombok.Data; +import net.minecraft.server.v1_10_R1.DataWatcher; +import net.minecraft.server.v1_10_R1.PacketPlayOutEntityDestroy; +import net.minecraft.server.v1_10_R1.PacketPlayOutNamedEntitySpawn; +import org.bukkit.Bukkit; +import org.bukkit.Location; + +import java.io.IOException; +import java.lang.reflect.Field; +import java.util.UUID; + +/** + * @author joethei + * @version 0.1 + */ + +@Data +public class NPC{ + + private int entityID; + private Location location; + private static GameProfile gameProfile; + private DataWatcher dataWatcher; + + public NPC(String name, Location location) { + this.location = location; + dataWatcher = new DataWatcher(null); + gameProfile = new GameProfile(UUID.randomUUID(), name); + entityID = (int) (Math.ceil(Math.random() * 1000) + 2000); + Bukkit.getScheduler().scheduleAsyncDelayedTask(Core.getInstance(), () -> { + try { + gameProfile = GameProfileBuilder.fetch(UUIDFetcher.getRequest(name)); + } catch (IOException e) { + e.printStackTrace(); + } + }, 20L); + } + + public void spawn() { + PacketPlayOutNamedEntitySpawn packet = new PacketPlayOutNamedEntitySpawn(); + + setField(packet, "a", entityID); + setField(packet, "b", gameProfile.getId()); + setField(packet, "c", location.getX()); + setField(packet, "d", location.getY()); + setField(packet, "e", location.getZ()); + setField(packet, "f", location.getYaw()); + setField(packet, "g", location.getPitch()); + setField(packet, "h", dataWatcher); + + for(CustomPlayer player : Core.getOnlinePlayers()) player.sendPacket(packet); + } + + public void setSkin(String value, String signature) { + gameProfile.getProperties().put("textures", new Property("textures", value, signature)); + } + + public void remove() { + PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(entityID); + for(CustomPlayer player : Core.getOnlinePlayers()) player.sendPacket(packet); + } + + private void addToTablist() { + + } + + private void removeFromTablist() { + + } + + private void setField(Object instance, String field, Object value) { + try { + Field f = instance.getClass().getDeclaredField(field); + f.setAccessible(true); + f.set(instance, value); + } catch (NoSuchFieldException | IllegalAccessException e) { + e.printStackTrace(); + } + } + + + /* + int entityID; + Location location; + GameProfile gameprofile; + + + public NPC(String name,Location location){ + entityID = (int)Math.ceil(Math.random() * 1000) + 2000; + gameprofile = new GameProfile(UUID.randomUUID(), name); + this.location = location; + } + + public void spawn(){ + PacketPlayOutNamedEntitySpawn packet = new PacketPlayOutNamedEntitySpawn(); + + setValue(packet, "a", entityID); + setValue(packet, "b", gameprofile.getId()); + setValue(packet, "c", (int)MathHelper.floor(location.getX() * 32.0D)); + setValue(packet, "d", (int)MathHelper.floor(location.getY() * 32.0D)); + setValue(packet, "e", (int)MathHelper.floor(location.getZ() * 32.0D)); + setValue(packet, "f", (byte) ((int) (location.getYaw() * 256.0F / 360.0F))); + setValue(packet, "g", (byte) ((int) (location.getPitch() * 256.0F / 360.0F))); + setValue(packet, "h", 0); + DataWatcher w = new DataWatcher(null); + w.a(6,(float)20); + w.a(10,(byte)127); + setValue(packet, "i", w); + addToTablist(); + sendPacket(packet); + } + + public void destroy(){ + PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(new int[] {entityID}); + rmvFromTablist(); + sendPacket(packet); + } + + public void addToTablist(){ + PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo(); + PacketPlayOutPlayerInfo.PlayerInfoData data = packet.new PlayerInfoData(gameprofile, 1, EnumGamemode.NOT_SET, CraftChatMessage.fromString(gameprofile.getName())[0]); + @SuppressWarnings("unchecked") + List players = (List) getValue(packet, "b"); + players.add(data); + + setValue(packet, "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER); + setValue(packet, "b", players); + + sendPacket(packet); + } + + public void rmvFromTablist(){ + PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo(); + PacketPlayOutPlayerInfo.PlayerInfoData data = packet.new PlayerInfoData(gameprofile, 1, EnumGamemode.NOT_SET, CraftChatMessage.fromString(gameprofile.getName())[0]); + @SuppressWarnings("unchecked") + List players = (List) getValue(packet, "b"); + players.add(data); + + setValue(packet, "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER); + setValue(packet, "b", players); + + sendPacket(packet); + } + */ +} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/npc/datawatcher/EnumDataWatcher.java b/src/main/java/eu/univento/core/api/npc/datawatcher/EnumDataWatcher.java new file mode 100644 index 0000000..3a52cfc --- /dev/null +++ b/src/main/java/eu/univento/core/api/npc/datawatcher/EnumDataWatcher.java @@ -0,0 +1,33 @@ +package eu.univento.core.api.npc.datawatcher; + +/** + * @author ingrim4, joethei + * @version 1.0 + */ +public enum EnumDataWatcher { + + ENTITY_BITMASK_00("Entity", "ay"),// + ENTITY_AIR_01("Entity", "az"),//AIR + ENTITY_NAME_02("Entity", "aA"),//CUSTOM_NAME + ENTITY_NAME_VISIBLE_03("Entity", "aB"),//CUSTOM_NAME_VISIBLE + ENTITY_SILENT_04("Entity", "aC"),//SILENT + + LIVING_HAND_05("EntityLiving", "as"), + LIVING_HEALTH_06("EntityLiving", "HEALTH"), + LIVING_POTION_COLOR_07("EntityLiving", "f"), + LIVING_POTION_AMBIENT_08("EntityLiving", "g"), + LIVING_ARROWS_09("EntityLiving", "h"), + + HUMAN_ABSORTION_10("EntityHuman", ""), + HUMAN_SCORE_11("EntityHuman", ""), + HUMAN_SKIN_12("EntityHuman", ""), + HUMAN_HAND_13("EntityHuman", ""); + + EnumDataWatcher(String owner, String field) { + + } + + public Object getObject() { + return null; + } +} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/npc/datawatcher/NullDataWatcher.java b/src/main/java/eu/univento/core/api/npc/datawatcher/NullDataWatcher.java new file mode 100644 index 0000000..9b7210f --- /dev/null +++ b/src/main/java/eu/univento/core/api/npc/datawatcher/NullDataWatcher.java @@ -0,0 +1,49 @@ +package eu.univento.core.api.npc.datawatcher; + +import eu.univento.core.api.utils.reflection.IReflection; + +/** + * @author ingrim4, joethei + * @version 1.0 + */ +public class NullDataWatcher { + + private static final Class CLASS_DATAWATCHER = IReflection.getClass(IReflection.ServerPacket.MINECRAFT_PACKAGE, "DataWatcher"); + private static final IReflection.ConstructorAccessor CONSTRUCTOR_DATAWATCHER_ENTITY = IReflection.getConstructor(CLASS_DATAWATCHER, IReflection.getClass(IReflection.ServerPacket.MINECRAFT_PACKAGE, "Entity")); + + private static final Class CLASS_DATAWATCHER_OBJECT = IReflection.getClass(IReflection.ServerPacket.MINECRAFT_PACKAGE, "DataWatcherObject"); + + private static final Class CLASS_DATAWATCHER_ITEM = IReflection.getClass(IReflection.ServerPacket.MINECRAFT_PACKAGE, "DataWatcher$Item"); + private static final IReflection.MethodAccessor METHOD_DATAWATCHER_ITEM_SETDATA = IReflection.getMethod(CLASS_DATAWATCHER_ITEM, "a", Object.class); + + private static final IReflection.MethodAccessor METHOD_DATAWATCHER_REGISTER = IReflection.getMethod(CLASS_DATAWATCHER, "register", CLASS_DATAWATCHER_OBJECT, Object.class); + private static final IReflection.MethodAccessor METHOD_DATAWATCHER_GETITEM = IReflection.getMethod(CLASS_DATAWATCHER, "c", CLASS_DATAWATCHER_OBJECT, Object.class); + + private static final IReflection.MethodAccessor METHOD_DATAWATCHER_C = IReflection.getMethod(CLASS_DATAWATCHER, "c"); + + private final Object dataWatcher; + + public NullDataWatcher() { + this.dataWatcher = CONSTRUCTOR_DATAWATCHER_ENTITY.newInstance(new Object[]{null}); + + } + + public NullDataWatcher add(EnumDataWatcher dataWatcher, Object value) { + METHOD_DATAWATCHER_REGISTER.invoke(this.dataWatcher, dataWatcher.getObject(), value); + return this; + } + + public NullDataWatcher update(EnumDataWatcher dataWatcher, Object value) { + Object item = METHOD_DATAWATCHER_GETITEM.invoke(this.dataWatcher, dataWatcher.getObject()); + METHOD_DATAWATCHER_ITEM_SETDATA.invoke(item, value); + return this; + } + + public Object toPacket() { + return METHOD_DATAWATCHER_C.invoke(this.dataWatcher); + } + + public Object toNMS() { + return this.dataWatcher; + } +} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/player/CustomPlayer.java b/src/main/java/eu/univento/core/api/player/CustomPlayer.java index 0aeed3b..1237db0 100644 --- a/src/main/java/eu/univento/core/api/player/CustomPlayer.java +++ b/src/main/java/eu/univento/core/api/player/CustomPlayer.java @@ -1,10 +1,10 @@ package eu.univento.core.api.player; import com.mojang.authlib.GameProfile; -import com.mojang.authlib.properties.Property; import com.mongodb.BasicDBObject; import eu.univento.commons.player.DatabasePlayer; import eu.univento.commons.player.Rank; +import eu.univento.commons.player.warn.WarnReason; import eu.univento.core.Core; import eu.univento.core.api.Hologram; import eu.univento.core.api.Utils; @@ -14,12 +14,9 @@ import eu.univento.core.api.languages.Messages; import eu.univento.core.api.server.ServerSettings; import eu.univento.core.api.server.Servers; import eu.univento.core.api.shop.ShopItem; -import eu.univento.core.api.utils.GameProfileBuilder; -import eu.univento.core.api.utils.UUIDFetcher; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import net.minecraft.server.v1_10_R1.*; -import org.bson.Document; import org.bukkit.*; import org.bukkit.Material; import org.bukkit.World; @@ -33,8 +30,9 @@ import org.bukkit.boss.BossBar; import org.bukkit.craftbukkit.v1_10_R1.CraftServer; import org.bukkit.craftbukkit.v1_10_R1.CraftWorld; import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.inventory.ItemStack; import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Team; @@ -48,16 +46,20 @@ public class CustomPlayer extends CraftPlayer { private static final HashMap PLAYERS = new HashMap<>(); + private static final Map nickedPlayers = new HashMap<>(); private final Player PLAYER; private final DatabasePlayer DATABASE_PLAYER; private boolean openInventory; + private final GameProfile gameProfile; + private CustomPlayer(Player player) { super((CraftServer) Bukkit.getServer(), ((CraftPlayer) player).getHandle()); DATABASE_PLAYER = new DatabasePlayer(Core.getCommons(), player.getUniqueId()); PLAYERS.put(player.getUniqueId(), this); PLAYER = player; + gameProfile = ((CraftPlayer) player).getProfile(); } public void onLeave() { @@ -95,12 +97,11 @@ public class CustomPlayer extends CraftPlayer { } } - public static CustomPlayer getPlayer(Player player) { return getPlayer(player.getUniqueId()); } - public Player getPLAYER() { + public Player getPlayer() { return PLAYER; } @@ -142,13 +143,7 @@ public class CustomPlayer extends CraftPlayer { } public void warn(WarnReason reason, CustomPlayer warner, String proof) { - Document doc = new Document("uuid", getUniqueId().toString()); - doc.put("reason", reason.name()); - doc.put("warner", warner.getUniqueId().toString()); - doc.put("date", new Date()); - doc.put("proof", proof); - - DATABASE_PLAYER.getWarnCollection().insertOne(doc); + DATABASE_PLAYER.warn(reason, warner.getUniqueId(), proof); } public boolean hasEmptyInventory() { @@ -168,18 +163,11 @@ public class CustomPlayer extends CraftPlayer { this.openInventory = openInventory; } - /* - @Deprecated public void sendActionBar(String text) { IChatBaseComponent cbc = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + text + "\"}"); PacketPlayOutChat ppoc = new PacketPlayOutChat(cbc, (byte) 2); sendPacket(ppoc); } - */ - - public void sendActionBar(String text) { - //spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(text)); - } public void sendTitle(int fadeIn, int stay, int fadeOut, String title, String subtitle) { PacketPlayOutTitle packetPlayOutTimes = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut); @@ -206,8 +194,8 @@ public class CustomPlayer extends CraftPlayer { return bar; } - public Hologram sendHologram(Location location, String... text) { - Hologram hologram = new Hologram(text, location); + public Hologram sendHologram(ItemStack item, Location location, String... text) { + Hologram hologram = new Hologram(item, text, location); hologram.showPlayer(this); return hologram; } @@ -238,6 +226,56 @@ public class CustomPlayer extends CraftPlayer { } } + public void setNickName(String name) { + if(name.length() > 16) { + sendMessage("Disguised name can only be less the 16 characters."); + return; + } + if(nickedPlayers.containsKey(getUniqueId())) { + sendMessage("You are already disguised!"); + return; + } + if(Bukkit.getOnlinePlayers().stream().filter(p -> p.getName().equals(name)).count() != 0) { + sendMessage("The name you chose is online."); + return; + } + nickedPlayers.put(getUniqueId(), new NickedPlayer(this, name)); + setGameProfile(name, new GameProfile(getUniqueId(), name)); + } + + private void setGameProfile(String name, GameProfile profile) { + getHandle().playerConnection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, getHandle())); + setDisplayName(name); + setPlayerListName(name); + try { + Field gp2 = getHandle().getClass().getSuperclass().getDeclaredField("bT"); + gp2.setAccessible(true); + gp2.set(getHandle(), profile); + gp2.setAccessible(false); + } catch (Exception e) { + e.printStackTrace(); + removeNickName(); + return; + } + Core.getOnlinePlayers().stream().filter(p -> p.getUniqueId() != getUniqueId()).forEach(p -> { + p.sendPacket(new PacketPlayOutEntityDestroy(getEntityId())); + p.sendPacket(new PacketPlayOutNamedEntitySpawn(getHandle())); + Bukkit.getServer().getScheduler().runTask(Core.getInstance(), () -> p.hidePlayer(this)); + Bukkit.getServer().getScheduler().runTaskLater(Core.getInstance(), () -> p.showPlayer(this), 5); + }); + } + + public void removeNickName() { + if(isNicked()) { + nickedPlayers.remove(getUniqueId()); + setGameProfile(getName(), gameProfile); + } + } + + public boolean isNicked() { + return nickedPlayers.containsKey(getUniqueId()); + } + public void addExperience(int experience) { DATABASE_PLAYER.setExperience(DATABASE_PLAYER.getExperience() + experience); setExp(0F); @@ -283,71 +321,6 @@ public class CustomPlayer extends CraftPlayer { return new Messages(this); } - @Deprecated - private void loadSkin(String name) { - //Skin skin = new Skin(UUIDFetcher.getUUID(name).toString()); - GameProfile skin; - GameProfile gp = getProfile(); - try { - skin = GameProfileBuilder.fetch(UUIDFetcher.getUUID(name)); - Collection properties = skin.getProperties().get("textures"); - gp.getProperties().removeAll("textures"); - gp.getProperties().putAll("textures", properties); - PacketPlayOutEntityDestroy destroy = new PacketPlayOutEntityDestroy(getEntityId()); - sendPacket(destroy); - PacketPlayOutPlayerInfo remove = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, getHandle()); - sendPacket(remove); - setHealth(0.0D); - new BukkitRunnable() { - @Override - public void run() { - PacketPlayOutPlayerInfo add = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, getHandle()); - sendPacket(add); - PacketPlayOutNamedEntitySpawn spawn = new PacketPlayOutNamedEntitySpawn(getHandle()); - Core.getOnlinePlayers().stream().filter(player -> !player.getName().equals(getName())).forEach(player -> sendPacket(spawn)); - } - }.runTaskLater(Core.getInstance(), 4); - } catch (IOException e) { - e.printStackTrace(); - Core.getCommons().getLoggingHandler().getCore().error("Mojang Skin Server offline"); - sendMessage("§cSkin Server sind offline"); - } - } - - @Deprecated - public void removeNick() { - setNick(getName()); - } - - @Deprecated - public void setNick(String name) { - setDisplayName(name); - Field nameField = getField(GameProfile.class, "name"); - try { - assert nameField != null; - nameField.setAccessible(true); - nameField.set(getProfile(), name); - PacketPlayOutEntityDestroy destroy = new PacketPlayOutEntityDestroy(getEntityId()); - sendPacket(destroy); - PacketPlayOutPlayerInfo remove = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, getHandle()); - sendPacket(remove); - - new BukkitRunnable() { - @Override - public void run() { - PacketPlayOutPlayerInfo add = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, getHandle()); - sendPacket(add); - PacketPlayOutNamedEntitySpawn spawn = new PacketPlayOutNamedEntitySpawn(getHandle()); - Core.getOnlinePlayers().stream().filter(players -> !players.equals(this)).forEach(players -> players.sendPacket(spawn)); - } - }.runTaskLater(Core.getInstance(), 4); - - loadSkin(name); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } - public void strikeLightning(Location loc) { World nmsWorld = (World) ((CraftWorld) loc.getWorld()).getHandle(); EntityLightning lightning = new EntityLightning((net.minecraft.server.v1_10_R1.World) nmsWorld, loc.getX(), loc.getY(), loc.getZ(), true); @@ -478,7 +451,7 @@ public class CustomPlayer extends CraftPlayer { * @param time time in seconds */ public void setItemCooldown(ItemStack item, int time) { - sendPacket(new PacketPlayOutSetCooldown(item.getItem(), time)); + sendPacket(new PacketPlayOutSetCooldown(CraftItemStack.asNMSCopy(item).getItem(), time)); } } \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/player/FriendObject.java b/src/main/java/eu/univento/core/api/player/FriendObject.java deleted file mode 100644 index fef7832..0000000 --- a/src/main/java/eu/univento/core/api/player/FriendObject.java +++ /dev/null @@ -1,26 +0,0 @@ -package eu.univento.core.api.player; - -import eu.univento.core.api.utils.UUIDFetcher; - -import java.util.UUID; - -/** - * @author joethei - * @version 0.1 - */ -public class FriendObject { - - private UUID uuid; - - public FriendObject(UUID uuid) { - this.uuid = uuid; - } - - public UUID getUuid() { - return uuid; - } - - public String getName() { - return UUIDFetcher.getName(uuid); - } -} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/player/NickedPlayer.java b/src/main/java/eu/univento/core/api/player/NickedPlayer.java new file mode 100644 index 0000000..3b2d057 --- /dev/null +++ b/src/main/java/eu/univento/core/api/player/NickedPlayer.java @@ -0,0 +1,28 @@ +package eu.univento.core.api.player; + +import com.mojang.authlib.GameProfile; +import lombok.Data; + +import java.util.UUID; + +/** + * @author joethei + * @version 0.1 + */ + +@Data +public class NickedPlayer { + + private CustomPlayer player; + private String name; + private UUID uuid; + + private GameProfile gameProfile; + + public NickedPlayer(CustomPlayer player, String name) { + this.player = player; + this.name = name; + this.uuid = player.getUniqueId(); + } + +} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/player/WarnReason.java b/src/main/java/eu/univento/core/api/player/WarnReason.java deleted file mode 100644 index e66bea2..0000000 --- a/src/main/java/eu/univento/core/api/player/WarnReason.java +++ /dev/null @@ -1,26 +0,0 @@ -package eu.univento.core.api.player; - -/** - * @author joethei - * @version 0.1 - */ -public enum WarnReason { - ADVERTISEMENT("Advertisement", 10), - SPAM("Spamming", 10); - - private String name; - private int value; - - WarnReason(String name, int value) { - this.name = name; - this.value = value; - } - - public String getName() { - return name; - } - - public int getValue() { - return value; - } -} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/server/GameInfo.java b/src/main/java/eu/univento/core/api/server/GameInfo.java index 3ab2bcc..36bed1a 100644 --- a/src/main/java/eu/univento/core/api/server/GameInfo.java +++ b/src/main/java/eu/univento/core/api/server/GameInfo.java @@ -1,5 +1,7 @@ package eu.univento.core.api.server; +import eu.univento.commons.server.ServerType; + /** * @author joethei * @version 0.1 diff --git a/src/main/java/eu/univento/core/api/utils/reflection/IReflection.java b/src/main/java/eu/univento/core/api/utils/reflection/IReflection.java index 464f735..c205e0b 100644 --- a/src/main/java/eu/univento/core/api/utils/reflection/IReflection.java +++ b/src/main/java/eu/univento/core/api/utils/reflection/IReflection.java @@ -59,7 +59,7 @@ public class IReflection { return null; } - private static ConstructorAccessor getConstructor(Class clazz, Class... parameterTypes) { + public static ConstructorAccessor getConstructor(Class clazz, Class... parameterTypes) { Class[] p = DataType.convertToPrimitive(parameterTypes); for (Constructor c : clazz.getDeclaredConstructors()) if (DataType.equalsArray(DataType.convertToPrimitive(c.getParameterTypes()), p)) { @@ -143,14 +143,11 @@ public class IReflection { return new FieldAccessor() { @Override - @SuppressWarnings("unchecked") public T get(Object target) { try { return (T) field.get(target); } catch (IllegalAccessException e) { throw new IllegalStateException("Cannot use reflection.", e); - } catch (IllegalArgumentException e) { - throw e; } } @@ -160,8 +157,6 @@ public class IReflection { field.set(target, value); } catch (IllegalAccessException e) { throw new IllegalStateException("Cannot use reflection.", e); - } catch (IllegalArgumentException e) { - throw e; } } diff --git a/src/main/java/eu/univento/core/api/utils/reflection/Reflection.java b/src/main/java/eu/univento/core/api/utils/reflection/Reflection.java deleted file mode 100644 index 5668c60..0000000 --- a/src/main/java/eu/univento/core/api/utils/reflection/Reflection.java +++ /dev/null @@ -1,238 +0,0 @@ -package eu.univento.core.api.utils.reflection; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - -import org.bukkit.Bukkit; - - -/** - * A class containing static utility methods and caches which are intended as reflective conveniences. - * Unless otherwise noted, upon failure methods will return {@code null}. - */ -final class Reflection { - - private static String _versionString; - - private Reflection() { - - } - - /** - * Gets the version string from the package name of the CraftBukkit server implementation. - * This is needed to bypass the JAR package name changing on each update. - * - * @return The version string of the OBC and NMS packages, including the trailing dot. - */ - private synchronized static String getVersion() { - if (_versionString == null) { - if (Bukkit.getServer() == null) { - // The server hasn't started, static initializer call? - return null; - } - String name = Bukkit.getServer().getClass().getPackage().getName(); - _versionString = name.substring(name.lastIndexOf('.') + 1) + "."; - } - - return _versionString; - } - - /** - * Stores loaded classes from the {@code net.minecraft.server} package. - */ - private static final Map> _loadedNMSClasses = new HashMap<>(); - /** - * Stores loaded classes from the {@code org.bukkit.craftbukkit} package (and subpackages). - */ - private static final Map> _loadedOBCClasses = new HashMap<>(); - - /** - * Gets a {@link Class} object representing a type contained within the {@code net.minecraft.server} versioned package. - * The class instances returned by this method are cached, such that no lookup will be done twice (unless multiple threads are accessing this method simultaneously). - * - * @param className The name of the class, excluding the package, within NMS. - * @return The class instance representing the specified NMS class, or {@code null} if it could not be loaded. - */ - public synchronized static Class getNMSClass(String className) { - if (_loadedNMSClasses.containsKey(className)) { - return _loadedNMSClasses.get(className); - } - - String fullName = "net.minecraft.server." + getVersion() + className; - Class clazz; - try { - clazz = Class.forName(fullName); - } catch (Exception e) { - e.printStackTrace(); - _loadedNMSClasses.put(className, null); - return null; - } - _loadedNMSClasses.put(className, clazz); - return clazz; - } - - public synchronized static Class getCTBClass(String className) { - if (_loadedNMSClasses.containsKey(className)) { - return _loadedNMSClasses.get(className); - } - - String fullName = "org.bukkit.craftbukkit." + getVersion() + className; - Class clazz; - try { - clazz = Class.forName(fullName); - } catch (Exception e) { - e.printStackTrace(); - _loadedNMSClasses.put(className, null); - return null; - } - _loadedNMSClasses.put(className, clazz); - return clazz; - } - - /** - * Gets a {@link Class} object representing a type contained within the {@code org.bukkit.craftbukkit} versioned package. - * The class instances returned by this method are cached, such that no lookup will be done twice (unless multiple threads are accessing this method simultaneously). - * - * @param className The name of the class, excluding the package, within OBC. This name may contain a subpackage name, such as {@code inventory.CraftItemStack}. - * @return The class instance representing the specified OBC class, or {@code null} if it could not be loaded. - */ - public synchronized static Class getOBCClass(String className) { - if (_loadedOBCClasses.containsKey(className)) { - return _loadedOBCClasses.get(className); - } - - String fullName = "org.bukkit.craftbukkit." + getVersion() + className; - Class clazz; - try { - clazz = Class.forName(fullName); - } catch (Exception e) { - e.printStackTrace(); - _loadedOBCClasses.put(className, null); - return null; - } - _loadedOBCClasses.put(className, clazz); - return clazz; - } - - /** - * Attempts to get the NMS handle of a CraftBukkit object. - *

- * The only match currently attempted by this method is a retrieval by using a parameterless {@code getHandle()} method implemented by the runtime type of the specified object. - *

- * - * @param obj The object for which to retrieve an NMS handle. - * @return The NMS handle of the specified object, or {@code null} if it could not be retrieved using {@code getHandle()}. - */ - public synchronized static Object getHandle(Object obj) { - try { - return getMethod(obj.getClass(), "getHandle").invoke(obj); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - private static final Map, Map> _loadedFields = new HashMap<>(); - - /** - * Retrieves a {@link Field} instance declared by the specified class with the specified name. - * Java access modifiers are ignored during this retrieval. No guarantee is made as to whether the field - * returned will be an instance or static field. - *

- * A global caching mechanism within this class is used to store fields. Combined with synchronization, this guarantees that - * no field will be reflectively looked up twice. - *

- *

- * If a field is deemed suitable for return, {@link Field#setAccessible(boolean) setAccessible} will be invoked with an argument of {@code true} before it is returned. - * This ensures that callers do not have to check or worry about Java access modifiers when dealing with the returned instance. - *

- * - * @param clazz The class which contains the field to retrieve. - * @param name The declared name of the field in the class. - * @return A field object with the specified name declared by the specified class. - * @see Class#getDeclaredField(String) - */ - public synchronized static Field getField(Class clazz, String name) { - Map loaded; - if (!_loadedFields.containsKey(clazz)) { - loaded = new HashMap<>(); - _loadedFields.put(clazz, loaded); - } else { - loaded = _loadedFields.get(clazz); - } - if (loaded.containsKey(name)) { - // If the field is loaded (or cached as not existing), return the relevant value, which might be null - return loaded.get(name); - } - try { - Field field = clazz.getDeclaredField(name); - field.setAccessible(true); - loaded.put(name, field); - return field; - } catch (Exception e) { - // Error loading - e.printStackTrace(); - // Cache field as not existing - loaded.put(name, null); - return null; - } - } - - /** - * Contains loaded methods in a cache. - * The map maps [types to maps of [method names to maps of [parameter types to method instances]]]. - */ - private static final Map, Map>, Method>>> _loadedMethods = new HashMap<>(); - - /** - * Retrieves a {@link Method} instance declared by the specified class with the specified name and argument types. - * Java access modifiers are ignored during this retrieval. No guarantee is made as to whether the field - * returned will be an instance or static field. - *

- * A global caching mechanism within this class is used to store method. Combined with synchronization, this guarantees that - * no method will be reflectively looked up twice. - *

- *

- * If a method is deemed suitable for return, {@link Method#setAccessible(boolean) setAccessible} will be invoked with an argument of {@code true} before it is returned. - * This ensures that callers do not have to check or worry about Java access modifiers when dealing with the returned instance. - *

- *

- * This method does not search superclasses of the specified type for methods with the specified signature. - * Callers wishing this behavior should use {@link Class#getDeclaredMethod(String, Class...)}. - * - * @param clazz The class which contains the method to retrieve. - * @param name The declared name of the method in the class. - * @param args The formal argument types of the method. - * @return A method object with the specified name declared by the specified class. - */ - private synchronized static Method getMethod(Class clazz, String name, - Class... args) { - if (!_loadedMethods.containsKey(clazz)) { - _loadedMethods.put(clazz, new HashMap<>()); - } - - Map>, Method>> loadedMethodNames = _loadedMethods.get(clazz); - if (!loadedMethodNames.containsKey(name)) { - loadedMethodNames.put(name, new HashMap<>()); - } - - Map>, Method> loadedSignatures = loadedMethodNames.get(name); - ArrayWrapper> wrappedArg = new ArrayWrapper<>(args); - if (loadedSignatures.containsKey(wrappedArg)) { - return loadedSignatures.get(wrappedArg); - } - - for (Method m : clazz.getMethods()) - if (m.getName().equals(name) && Arrays.equals(args, m.getParameterTypes())) { - m.setAccessible(true); - loadedSignatures.put(wrappedArg, m); - return m; - } - loadedSignatures.put(wrappedArg, null); - return null; - } - -} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/commands/Nick.java b/src/main/java/eu/univento/core/commands/Nick.java index 9d77f73..a6a4fbe 100644 --- a/src/main/java/eu/univento/core/commands/Nick.java +++ b/src/main/java/eu/univento/core/commands/Nick.java @@ -40,14 +40,14 @@ public class Nick extends AutoCommand{ p.getDatabasePlayer().getSettings().setNickStatus(false); p.getScoreboard().getTeam(p.getDatabasePlayer().getRank().getTeam()).addEntry(p.getDisplayName()); p.sendMessage(msgs.PREFIX() + msgs.Core_NICK_OFF()); - p.removeNick(); + p.removeNickName(); }else { p.getScoreboard().getTeam(p.getDatabasePlayer().getRank().getTeam()).removeEntry(p.getDisplayName()); p.getDatabasePlayer().getSettings().setNickStatus(true); p.getScoreboard().getTeam(p.getDatabasePlayer().getRank().getTeam()).addEntry(p.getDisplayName()); p.sendMessage(msgs.PREFIX() + msgs.Core_NICK_ON()); String nick = NickName.getRandomNick(); - p.setNick(nick); + p.setNickName(nick); //Core.getDebugManager().sendOverlay("der Nick ist " + nick); } }else { diff --git a/src/main/java/eu/univento/core/commands/Timeout.java b/src/main/java/eu/univento/core/commands/Timeout.java index 53afc9e..fd88d1d 100644 --- a/src/main/java/eu/univento/core/commands/Timeout.java +++ b/src/main/java/eu/univento/core/commands/Timeout.java @@ -1,6 +1,7 @@ package eu.univento.core.commands; import eu.univento.commons.player.Rank; +import eu.univento.commons.player.language.MessageConstant; import eu.univento.core.Core; import eu.univento.core.api.AutoCommand; import eu.univento.core.api.languages.Messages; @@ -35,13 +36,13 @@ public class Timeout extends AutoCommand { Core.getTimeout().add(p); } } else { - p.sendMessage(p.getDatabasePlayer().getMessage("Command.not_online")); + p.sendMessage(p.getDatabasePlayer().getLanguage().getMessage(MessageConstant.COMMAND_NOT_ONLINE)); } } else { p.sendMessage("Nicht genug Argumente"); } } else { - p.sendMessage(p.getDatabasePlayer().getMessage("Command.no_perms")); + p.sendMessage(p.getDatabasePlayer().getLanguage().getMessage(MessageConstant.COMMAND_NO_PERMS)); } } else { sender.sendMessage(Messages.Console.NOT_A_PLAYER); diff --git a/src/main/java/eu/univento/core/listeners/Chat.java b/src/main/java/eu/univento/core/listeners/Chat.java index f67fc6b..836ca8e 100644 --- a/src/main/java/eu/univento/core/listeners/Chat.java +++ b/src/main/java/eu/univento/core/listeners/Chat.java @@ -1,12 +1,12 @@ package eu.univento.core.listeners; import eu.univento.commons.player.Rank; +import eu.univento.commons.player.warn.WarnReason; import eu.univento.core.Core; import eu.univento.core.api.blocks.MiniBlock; import eu.univento.core.api.customitems.swords.BestSwordEver; import eu.univento.core.api.languages.Messages; import eu.univento.core.api.player.CustomPlayer; -import eu.univento.core.api.player.WarnReason; import eu.univento.core.api.server.ServerSettings; import eu.univento.core.api.shop.ShopItem; import eu.univento.core.api.shop.ShopMenu; diff --git a/src/main/java/eu/univento/core/listeners/Commands.java b/src/main/java/eu/univento/core/listeners/Commands.java index 6fa84f8..11476f4 100644 --- a/src/main/java/eu/univento/core/listeners/Commands.java +++ b/src/main/java/eu/univento/core/listeners/Commands.java @@ -1,6 +1,7 @@ package eu.univento.core.listeners; import eu.univento.commons.player.Rank; +import eu.univento.commons.player.language.MessageConstant; import eu.univento.core.Core; import eu.univento.core.api.player.CustomPlayer; import org.bukkit.Bukkit; @@ -29,7 +30,7 @@ public class Commands implements Listener{ String cmd = e.getMessage().split(" ")[0]; HelpTopic topic = Bukkit.getServer().getHelpMap().getHelpTopic(cmd); if (topic == null) { - p.sendMessage(p.getDatabasePlayer().getMessage("Command.not_found")); + p.sendMessage(p.getDatabasePlayer().getLanguage().getMessage(MessageConstant.COMMAND_NOT_FOUND)); e.setCancelled(true); } } @@ -44,7 +45,7 @@ public class Commands implements Listener{ Bukkit.spigot().restart(); }, 100L); }else { - p.sendMessage(p.getDatabasePlayer().getMessage("Command.no_perms")); + p.sendMessage(p.getDatabasePlayer().getLanguage().getMessage(MessageConstant.COMMAND_NO_PERMS)); } } } diff --git a/src/main/java/eu/univento/core/listeners/Events.java b/src/main/java/eu/univento/core/listeners/Events.java index d1bbb26..602df17 100644 --- a/src/main/java/eu/univento/core/listeners/Events.java +++ b/src/main/java/eu/univento/core/listeners/Events.java @@ -1,25 +1,34 @@ package eu.univento.core.listeners; import eu.univento.core.api.player.CustomPlayer; +import eu.univento.core.api.player.SpectateManager; import eu.univento.core.api.server.ServerSettings; +import eu.univento.core.commands.Vanish; +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.entity.ExperienceOrb; import org.bukkit.entity.Player; +import org.bukkit.entity.Tameable; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityTargetEvent; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.server.ServerListPingEvent; import org.bukkit.util.Vector; /** * some basic events + * * @author joethei * @version 0.2 */ -public class Events implements Listener{ +public class Events implements Listener { @EventHandler public void onServerListPing(ServerListPingEvent e) { - if(ServerSettings.isGame()) e.setMotd(ServerSettings.getServerType().toString() + ";" + ServerSettings.getGameState()); + e.setMotd(ServerSettings.getServerType().name() + ";" + (ServerSettings.isGame() ? ServerSettings.getGameState() : "")); } @EventHandler @@ -31,10 +40,54 @@ public class Events implements Listener{ @EventHandler public void onMove(PlayerMoveEvent e) { CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer()); - if(p.getLocation().getY() <= 0) { + if (p.getLocation().getY() <= 0) { p.setVelocity(new Vector().setY(10.0D).multiply(1.0D)); p.setGliding(true); } } + @EventHandler + public void onEntityTarget(EntityTargetEvent e) { + if (e.isCancelled()) return; + final Entity entity = e.getEntity(); + final Entity target = e.getTarget(); + if (!(target instanceof Player)) return; + CustomPlayer p = CustomPlayer.getPlayer((Player) target); + if (Vanish.getPlayers().contains(p) || SpectateManager.contains(p)) { + if (entity instanceof Tameable) { + e.setTarget(null); + } + + if (entity instanceof ExperienceOrb) { + repellExpOrb((Player) target, (ExperienceOrb) entity); + e.setCancelled(true); + e.setTarget(null); + } + } + } + + private void repellExpOrb(Player player, ExperienceOrb orb) { + final Location pLoc = player.getLocation(); + final Location oLoc = orb.getLocation(); + final Vector dir = oLoc.toVector().subtract(pLoc.toVector()); + final double dx = Math.abs(dir.getX()); + final double dz = Math.abs(dir.getZ()); + if ((dx == 0.0) && (dz == 0.0)) { + // Special case probably never happens + dir.setX(0.001); + } + if ((dx < 3.0) && (dz < 3.0)) { + final Vector nDir = dir.normalize(); + final Vector newV = nDir.clone().multiply(0.3); + newV.setY(0); + orb.setVelocity(newV); + if ((dx < 1.0) && (dz < 1.0)) { + // maybe oLoc + orb.teleport(oLoc.clone().add(nDir.multiply(1.0)), PlayerTeleportEvent.TeleportCause.PLUGIN); + } + if ((dx < 0.5) && (dz < 0.5)) { + orb.remove(); + } + } + } } \ No newline at end of file diff --git a/src/main/java/eu/univento/core/listeners/JoinQuit.java b/src/main/java/eu/univento/core/listeners/JoinQuit.java index 1d5c536..ab48fb0 100644 --- a/src/main/java/eu/univento/core/listeners/JoinQuit.java +++ b/src/main/java/eu/univento/core/listeners/JoinQuit.java @@ -37,6 +37,9 @@ public class JoinQuit implements Listener { @EventHandler public void onJoin(PlayerJoinEvent e) { CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer()); + if(!p.hasPlayedBefore()) { + + } for (Player players : Bukkit.getOnlinePlayers()) { CustomPlayer player = CustomPlayer.getPlayer(players); @@ -77,7 +80,7 @@ public class JoinQuit implements Listener { p.initScoreboard(); p.sendTabHeaderAndFooter(p.getMessages().Core_TAB_TITLE() + Bukkit.getServerName(), p.getMessages().TAB_PREFIX()); if (p.getDatabasePlayer().getSettings().isNicked() && !ServerSettings.isLobby()) { - p.setNick(NickName.getRandomNick()); + p.setNickName(NickName.getRandomNick()); } for (CustomPlayer player : Core.getOnlinePlayers()) { p.getScoreboard().getTeam(player.getDatabasePlayer().getRank().getTeam()).addEntry(player.getDisplayName()); @@ -118,7 +121,7 @@ public class JoinQuit implements Listener { if (Build.getPlayers().containsKey(p)) Build.getPlayers().remove(p); if (p.getDatabasePlayer().getSettings().isNicked() && !ServerSettings.isLobby()) { - p.removeNick(); + p.removeNickName(); } for (Team team : p.getScoreboard().getTeams()) { team.removeEntry(p.getDisplayName()); diff --git a/src/main/java/eu/univento/core/listeners/PluginMessenger.java b/src/main/java/eu/univento/core/listeners/PluginMessenger.java index db1ab78..6597471 100644 --- a/src/main/java/eu/univento/core/listeners/PluginMessenger.java +++ b/src/main/java/eu/univento/core/listeners/PluginMessenger.java @@ -2,9 +2,9 @@ package eu.univento.core.listeners; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; +import eu.univento.commons.player.warn.WarnReason; import eu.univento.core.Core; import eu.univento.core.api.player.CustomPlayer; -import eu.univento.core.api.player.WarnReason; import org.bukkit.entity.Player; import org.bukkit.plugin.messaging.PluginMessageListener; @@ -24,7 +24,7 @@ public class PluginMessenger implements PluginMessageListener { e.printStackTrace(); } Core.getCommons().getLoggingHandler().getCore().info(p.getName() + " hat WDL installiert. Version : " + version); - p.sendMessage(p.getDatabasePlayer().getMessage("Prefix") + p.getDatabasePlayer().getMessage("Hack.WorldDownloader")); + p.sendMessage(p.getDatabasePlayer().getLanguage().getWord("Prefix") + p.getDatabasePlayer().getLanguage().getWord("Hack.WorldDownloader")); } if(channel.equals("WDL|CONTROL")) { p.sendPluginMessage(Core.getInstance(), "WDL|CONTROL", createWDLPacket(0, false, false, false, false)); @@ -32,7 +32,7 @@ public class PluginMessenger implements PluginMessageListener { if (channel.equals("PERMISSIONSREPL") && new String(data).contains("mod.worlddownloader")) { //TODO: change to real warn reason p.warn(WarnReason.SPAM, null, "https://players.univento.eu/" + p.getUniqueId().toString() + "/hacks"); - p.sendMessage(p.getDatabasePlayer().getMessage("Prefix") + p.getDatabasePlayer().getMessage("Hack.WorldDownloader")); + p.sendMessage(p.getDatabasePlayer().getLanguage().getWord("Prefix") + p.getDatabasePlayer().getLanguage().getWord("Hack.WorldDownloader")); } if(channel.equals("5zig_Set")) { try { diff --git a/src/main/java/eu/univento/core/listeners/SpectatorEvents.java b/src/main/java/eu/univento/core/listeners/SpectatorEvents.java index fde5561..ab7e2ab 100644 --- a/src/main/java/eu/univento/core/listeners/SpectatorEvents.java +++ b/src/main/java/eu/univento/core/listeners/SpectatorEvents.java @@ -1,5 +1,6 @@ package eu.univento.core.listeners; +import eu.univento.commons.player.language.MessageConstant; import eu.univento.core.api.player.CustomPlayer; import eu.univento.core.api.player.SpectateManager; import eu.univento.core.api.player.Spectator; @@ -59,7 +60,7 @@ public class SpectatorEvents implements Listener{ public void onInventoryClick(InventoryClickEvent e) { CustomPlayer p = CustomPlayer.getPlayer((Player) e.getWhoClicked()); if(SpectateManager.contains(p)) { - if (e.getInventory().getName().equals(p.getDatabasePlayer().getMessage("Game.Menu.SpectateMenu"))) { + if (e.getInventory().getName().equals(p.getDatabasePlayer().getLanguage().getWord("Game.Menu.SpectateMenu"))) { if(e.getCurrentItem().getType() == Material.SKULL_ITEM) { SkullMeta meta = (SkullMeta) e.getCurrentItem().getItemMeta(); CustomPlayer player = CustomPlayer.getPlayer(meta.getOwner()); @@ -70,7 +71,7 @@ public class SpectatorEvents implements Listener{ p.closeInventory(); spectator.spectate(player); }else{ - p.sendMessage(p.getDatabasePlayer().getMessage("Not_online")); + p.sendMessage(p.getDatabasePlayer().getLanguage().getMessage(MessageConstant.COMMAND_NOT_ONLINE)); } } }