diff --git a/checkstyle.xml b/checkstyle.xml new file mode 100644 index 0000000..e350ceb --- /dev/null +++ b/checkstyle.xml @@ -0,0 +1,521 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index 1f29d3c..3c89020 100644 --- a/pom.xml +++ b/pom.xml @@ -4,8 +4,8 @@ Extras master - 1.8 - 1.8 + 1.7 + 1.7 @@ -13,7 +13,7 @@ com.destroystokyo.paper paper-api - 1.12.2-R0.1-SNAPSHOT + 1.13.2-R0.1-SNAPSHOT @@ -26,18 +26,28 @@ ${project.artifactId} - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.0 - - - -Xlint:all - - - - + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.1.0 + + ${basedir}/checkstyle.xml + true + false + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + + -Xlint:all + + + + diff --git a/src/main/java/pw/kaboom/extras/Commands.java b/src/main/java/pw/kaboom/extras/Commands.java index 9ad3bce..93c1416 100644 --- a/src/main/java/pw/kaboom/extras/Commands.java +++ b/src/main/java/pw/kaboom/extras/Commands.java @@ -2,14 +2,9 @@ package pw.kaboom.extras; import java.io.InputStreamReader; import java.net.URL; + import javax.net.ssl.HttpsURLConnection; -import com.destroystokyo.paper.profile.PlayerProfile; -import com.destroystokyo.paper.profile.ProfileProperty; - -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; - import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Chunk; @@ -30,16 +25,19 @@ import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; -import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import org.bukkit.scheduler.BukkitRunnable; - import org.bukkit.util.BlockIterator; import org.bukkit.util.Vector; +import com.destroystokyo.paper.profile.PlayerProfile; +import com.destroystokyo.paper.profile.ProfileProperty; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; + class CommandClearChat implements CommandExecutor { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { @@ -54,7 +52,7 @@ class CommandClearChat implements CommandExecutor { class CommandConsole implements CommandExecutor { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - Player player = (Player) sender; + final Player player = (Player) sender; if (args.length == 0) { player.sendMessage(ChatColor.RED + "Usage: /" + label + " "); @@ -67,7 +65,7 @@ class CommandConsole implements CommandExecutor { class CommandDestroyEntities implements CommandExecutor { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - Player player = (Player) sender; + final Player player = (Player) sender; for (World world : Bukkit.getServer().getWorlds()) { for (Entity entity : world.getEntities()) { @@ -83,8 +81,8 @@ class CommandDestroyEntities implements CommandExecutor { class CommandEnchantAll implements CommandExecutor { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - Player player = (Player) sender; - ItemStack item = player.getInventory().getItemInMainHand(); + final Player player = (Player) sender; + final ItemStack item = player.getInventory().getItemInMainHand(); if (item.getType() == Material.AIR) { player.sendMessage("Please hold an item in your hand to enchant it"); @@ -132,25 +130,23 @@ class CommandHerobrine implements CommandExecutor { } private void spawnHerobrine(Player player) { - Location location = player.getLocation(); + final Location location = player.getLocation(); - Player herobrine = (Player) location.getWorld().spawnEntity( + final Player herobrine = (Player) location.getWorld().spawnEntity( location.add(location.getDirection().multiply(6)), EntityType.PLAYER ); - main.getSkin("Herobrine", herobrine); } public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - Player player = (Player) sender; - Location location = player.getLocation(); + final Player player = (Player) sender; + final Location location = player.getLocation(); if (args.length == 0) { - Player herobrine = (Player) location.getWorld().spawnEntity( + final Player herobrine = (Player) location.getWorld().spawnEntity( location, EntityType.PLAYER ); - main.getSkin("Herobrine", herobrine); } else { if (args[0].equals("*") || args[0].equals("**")) { for (Player p : Bukkit.getOnlinePlayers()) { @@ -158,7 +154,8 @@ class CommandHerobrine implements CommandExecutor { } player.sendMessage("Successfully spawned Herobrine behind every player"); } else { - Player target = Bukkit.getPlayer(args[0]); + final Player target = Bukkit.getPlayer(args[0]); + if (target != null) { spawnHerobrine(target); player.sendMessage("Successfully spawned Herobrine behind player \"" + target.getName() + "\""); @@ -175,12 +172,12 @@ class CommandJumpscare implements CommandExecutor { private void createJumpscare(Player player) { player.spawnParticle(Particle.MOB_APPEARANCE, player.getLocation(), 4); for (int i = 0; i < 10; ++i) { - player.playSound(player.getLocation(), Sound.ENTITY_ENDERMEN_SCREAM, 1, 0); + player.playSound(player.getLocation(), Sound.ENTITY_ENDERMAN_SCREAM, 1, 0); } } public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - Player player = (Player) sender; + final Player player = (Player) sender; if (args.length == 0) { player.sendMessage(ChatColor.RED + "Usage: /" + label + " "); @@ -191,7 +188,7 @@ class CommandJumpscare implements CommandExecutor { } player.sendMessage("Successfully created jumpscare for every player"); } else { - Player target = Bukkit.getPlayer(args[0]); + final Player target = Bukkit.getPlayer(args[0]); if (target != null) { createJumpscare(target); player.sendMessage("Successfully created jumpscare for player \"" + target.getName() + "\""); @@ -211,7 +208,7 @@ class CommandPrefix implements CommandExecutor { } public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - Player player = (Player) sender; + final Player player = (Player) sender; if (args.length == 0) { player.sendMessage(ChatColor.RED + "Usage: /" + label + " "); @@ -230,11 +227,11 @@ class CommandPrefix implements CommandExecutor { class CommandPumpkin implements CommandExecutor { private void placePumpkin(Player player) { - player.getInventory().setHelmet(new ItemStack(Material.PUMPKIN)); + player.getInventory().setHelmet(new ItemStack(Material.CARVED_PUMPKIN)); } public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - Player player = (Player) sender; + final Player player = (Player) sender; if (args.length == 0) { player.sendMessage(ChatColor.RED + "Usage: /" + label + " "); @@ -245,7 +242,7 @@ class CommandPumpkin implements CommandExecutor { } player.sendMessage("Everyone is now a pumpkin"); } else { - Player target = Bukkit.getPlayer(args[0]); + final Player target = Bukkit.getPlayer(args[0]); if (target != null) { placePumpkin(target); player.sendMessage("Player \"" + target.getName() + "\" is now a pumpkin"); @@ -271,24 +268,24 @@ class CommandSkin implements CommandExecutor { player.sendMessage(ChatColor.RED + "Usage: /" + label + " "); } else { Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() { - public void run() { + public void run() { try { final String name = args[0]; - URL nameUrl = new URL("https://api.mojang.com/users/profiles/minecraft/" + name); - HttpsURLConnection nameConnection = (HttpsURLConnection) nameUrl.openConnection(); + final URL nameUrl = new URL("https://api.mojang.com/users/profiles/minecraft/" + name); + final HttpsURLConnection nameConnection = (HttpsURLConnection) nameUrl.openConnection(); if (nameConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) { - InputStreamReader nameStream = new InputStreamReader(nameConnection.getInputStream()); - String uuid = new JsonParser().parse(nameStream).getAsJsonObject().get("id").getAsString(); + final InputStreamReader nameStream = new InputStreamReader(nameConnection.getInputStream()); + final String uuid = new JsonParser().parse(nameStream).getAsJsonObject().get("id").getAsString(); nameStream.close(); nameConnection.disconnect(); - URL uuidUrl = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false"); - HttpsURLConnection uuidConnection = (HttpsURLConnection) uuidUrl.openConnection(); + final URL uuidUrl = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false"); + final HttpsURLConnection uuidConnection = (HttpsURLConnection) uuidUrl.openConnection(); if (uuidConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) { - InputStreamReader uuidStream = new InputStreamReader(uuidConnection.getInputStream()); - JsonObject response = new JsonParser().parse(uuidStream).getAsJsonObject().get("properties").getAsJsonArray().get(0).getAsJsonObject(); + final InputStreamReader uuidStream = new InputStreamReader(uuidConnection.getInputStream()); + final JsonObject response = new JsonParser().parse(uuidStream).getAsJsonObject().get("properties").getAsJsonArray().get(0).getAsJsonObject(); final String texture = response.get("value").getAsString(); final String signature = response.get("signature").getAsString(); uuidStream.close(); @@ -300,7 +297,7 @@ class CommandSkin implements CommandExecutor { Bukkit.getScheduler().runTask(main, new Runnable() { @Override - public void run() { + public void run() { player.setPlayerProfile(textureProfile); player.sendMessage("Successfully set your skin to " + name + "'s"); } @@ -309,7 +306,7 @@ class CommandSkin implements CommandExecutor { uuidConnection.disconnect(); Bukkit.getScheduler().runTask(main, new Runnable() { @Override - public void run() { + public void run() { player.sendMessage("Failed to change skin. Try again later"); } }); @@ -318,7 +315,7 @@ class CommandSkin implements CommandExecutor { nameConnection.disconnect(); Bukkit.getScheduler().runTask(main, new Runnable() { @Override - public void run() { + public void run() { player.sendMessage("A player with that username doesn't exist"); } }); @@ -334,17 +331,17 @@ class CommandSkin implements CommandExecutor { class CommandSpawn implements CommandExecutor { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - Player player = (Player) sender; - World world = Bukkit.getWorld("world"); - Location spawnLoc = world.getSpawnLocation(); + final Player player = (Player) sender; + final World world = Bukkit.getWorld("world"); + final Location spawnLocation = world.getSpawnLocation(); - for (double y = spawnLoc.getY(); y <= 256; y++) { - Location yLoc = new Location(world, spawnLoc.getX(), y, spawnLoc.getZ()); - Block coordBlock = world.getBlockAt(yLoc); + for (double y = spawnLocation.getY(); y <= 256; y++) { + final Location yLocation = new Location(world, spawnLocation.getX(), y, spawnLocation.getZ()); + final Block coordBlock = world.getBlockAt(yLocation); - if (coordBlock.getType().isTransparent() && - coordBlock.getRelative(BlockFace.UP).getType().isTransparent()) { - player.teleport(yLoc); + if (!coordBlock.getType().isSolid() && + !coordBlock.getRelative(BlockFace.UP).getType().isSolid()) { + player.teleport(yLocation); break; } } @@ -356,20 +353,20 @@ class CommandSpawn implements CommandExecutor { class CommandSpidey implements CommandExecutor { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - Player player = (Player) sender; - Location eyePos = player.getEyeLocation(); - Vector playerPos = new Vector(player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ()); - Vector direction = eyePos.getDirection(); - int distance = 50; + final Player player = (Player) sender; + final Location eyePos = player.getEyeLocation(); + final Vector playerPos = new Vector(eyePos.getX(), eyePos.getY(), eyePos.getZ()); + final Vector direction = eyePos.getDirection(); + final int distance = 50; - BlockIterator blockIterator = new BlockIterator(player.getWorld(), playerPos, direction, 0, distance); + final BlockIterator blockIterator = new BlockIterator(player.getWorld(), playerPos, direction, 0, distance); while (blockIterator.hasNext()) { if (blockIterator.next().getType() != Material.AIR) { break; } - blockIterator.next().setType(Material.WEB); + blockIterator.next().setType(Material.COBWEB); } return true; } @@ -377,7 +374,7 @@ class CommandSpidey implements CommandExecutor { class CommandTellraw implements CommandExecutor { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - Player player = (Player) sender; + final Player player = (Player) sender; if (args.length == 0) { player.sendMessage(ChatColor.RED + "Usage: /" + label + " "); @@ -392,13 +389,14 @@ class CommandTellraw implements CommandExecutor { class CommandUnloadChunks implements CommandExecutor { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - Player player = (Player) sender; + final Player player = (Player) sender; for (World world : Bukkit.getServer().getWorlds()) { for (Chunk chunk : world.getLoadedChunks()) { chunk.unload(true); } } + player.sendMessage("Successfully unloaded unused chunks"); return true; } @@ -410,21 +408,66 @@ class CommandUsername implements CommandExecutor { this.main = main; } - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - Player player = (Player) sender; + public boolean onCommand(CommandSender sender, Command command, String label, final String[] args) { + final Player player = (Player) sender; if (args.length == 0) { player.sendMessage(ChatColor.RED + "Usage: /" + label + " "); } else { - String namelong = ChatColor.translateAlternateColorCodes('&', String.join(" ", args)); - String name = namelong.substring(0, Math.min(16, namelong.length())); + Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() { + public void run() { + try { + String texture = ""; + String signature = ""; - PlayerProfile profile = player.getPlayerProfile(); - profile.setName(name); - player.setPlayerProfile(profile); - player.sendMessage("Successfully set your username to \"" + name + "\""); + final String namelong = ChatColor.translateAlternateColorCodes('&', String.join(" ", args)); + final String name = namelong.substring(0, Math.min(16, namelong.length())); - main.getSkin(name, player); + final URL nameUrl = new URL("https://api.mojang.com/users/profiles/minecraft/" + name); + final HttpsURLConnection nameConnection = (HttpsURLConnection) nameUrl.openConnection(); + + if (nameConnection != null && + nameConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) { + final InputStreamReader nameStream = new InputStreamReader(nameConnection.getInputStream()); + final String uuid = new JsonParser().parse(nameStream).getAsJsonObject().get("id").getAsString(); + nameStream.close(); + nameConnection.disconnect(); + + final URL uuidUrl = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false"); + final HttpsURLConnection uuidConnection = (HttpsURLConnection) uuidUrl.openConnection(); + + if (uuidConnection != null && + uuidConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) { + final InputStreamReader uuidStream = new InputStreamReader(uuidConnection.getInputStream()); + final JsonObject response = new JsonParser().parse(uuidStream).getAsJsonObject().get("properties").getAsJsonArray().get(0).getAsJsonObject(); + texture = response.get("value").getAsString(); + signature = response.get("signature").getAsString(); + + uuidStream.close(); + uuidConnection.disconnect(); + } + } + + final PlayerProfile profile = player.getPlayerProfile(); + profile.clearProperties(); + profile.setName(name); + + if (!("".equals(texture)) && + !("".equals(signature))) { + profile.setProperty(new ProfileProperty("textures", texture, signature)); + } + + Bukkit.getScheduler().runTask(main, new Runnable() { + @Override + public void run() { + player.setPlayerProfile(profile); + player.sendMessage("Successfully set your username to \"" + name + "\""); + } + }); + } catch (Exception exception) { + } + } + }); } return true; } diff --git a/src/main/java/pw/kaboom/extras/Events.java b/src/main/java/pw/kaboom/extras/Events.java index e6aea5c..c166119 100644 --- a/src/main/java/pw/kaboom/extras/Events.java +++ b/src/main/java/pw/kaboom/extras/Events.java @@ -2,55 +2,31 @@ package pw.kaboom.extras; import java.io.InputStreamReader; import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Set; import java.util.UUID; + import javax.net.ssl.HttpsURLConnection; -import java.util.concurrent.TimeUnit; - -import com.destroystokyo.paper.event.entity.EntityAddToWorldEvent; -import com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent; -import com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent; -import com.destroystokyo.paper.event.server.PaperServerListPingEvent; -import com.destroystokyo.paper.profile.PlayerProfile; -import com.destroystokyo.paper.profile.ProfileProperty; - import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import org.bukkit.Chunk; -import org.bukkit.Color; -import org.bukkit.Material; import org.bukkit.Location; -import org.bukkit.Server; +import org.bukkit.Material; import org.bukkit.World; -import org.bukkit.WorldBorder; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import org.bukkit.block.BlockState; -import org.bukkit.block.Container; import org.bukkit.block.CreatureSpawner; -import org.bukkit.block.Sign; +import org.bukkit.block.data.Levelled; -import org.bukkit.command.CommandSender; -import org.bukkit.command.CommandSender.Spigot; - -import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; -import org.bukkit.entity.Player; +import org.bukkit.entity.EnderDragon; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.FallingBlock; -import org.bukkit.entity.Item; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.MagmaCube; -import org.bukkit.entity.Minecart; +import org.bukkit.entity.Player; import org.bukkit.entity.Slime; import org.bukkit.event.EventHandler; @@ -63,20 +39,19 @@ import org.bukkit.event.block.BlockRedstoneEvent; import org.bukkit.event.block.BlockSpreadEvent; import org.bukkit.event.block.SignChangeEvent; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.entity.ExplosionPrimeEvent; import org.bukkit.event.entity.ItemSpawnEvent; +import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.SpawnerSpawnEvent; -import org.bukkit.event.inventory.InventoryClickEvent; - import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerPreLoginEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerKickEvent; @@ -86,74 +61,33 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.server.ServerCommandEvent; -import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.LeatherArmorMeta; -import org.bukkit.inventory.meta.PotionMeta; - -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionAttachment; -import org.bukkit.permissions.PermissionAttachmentInfo; - -import org.bukkit.plugin.Plugin; import org.bukkit.scheduler.BukkitRunnable; +import com.destroystokyo.paper.event.block.TNTPrimeEvent; +import com.destroystokyo.paper.event.entity.EntityAddToWorldEvent; +import com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent; +import com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent; +import com.destroystokyo.paper.event.entity.PreSpawnerSpawnEvent; +import com.destroystokyo.paper.event.server.PaperServerListPingEvent; +import com.destroystokyo.paper.profile.PlayerProfile; +import com.destroystokyo.paper.profile.ProfileProperty; + import com.google.gson.JsonObject; import com.google.gson.JsonParser; -class Tick extends BukkitRunnable { - Main main; - Tick(Main main) { - this.main = main; - } - - public void run() { - } -} - -class TickAsync extends BukkitRunnable { - Main main; - TickAsync(Main main) { - this.main = main; - } - +class AutosaveCheck extends BukkitRunnable { public void run() { for (final World world : Bukkit.getServer().getWorlds()) { - WorldBorder worldborder = world.getWorldBorder(); - - if (worldborder.getSize() != 60000000) { - worldborder.setSize(60000000); - } - - if (worldborder.getCenter().getX() != 0 || worldborder.getCenter().getZ() != 0) { - worldborder.setCenter(0, 0); - } - if (world.isAutoSave() == false) { world.setAutoSave(true); } - - try { - for (LivingEntity mob : world.getLivingEntities()) { - final AttributeInstance followAttribute = mob.getAttribute(Attribute.GENERIC_FOLLOW_RANGE); - - if (followAttribute != null && followAttribute.getBaseValue() > 40) { - Bukkit.getScheduler().runTask(main, new Runnable() { - public void run() { - followAttribute.setBaseValue(40); - } - }); - } - } - } catch (Exception e) { - } } } } -class TileEntityCheckAsync extends BukkitRunnable { +/*class TileEntityCheckAsync extends BukkitRunnable { Main main; TileEntityCheckAsync(Main main) { this.main = main; @@ -174,99 +108,6 @@ class TileEntityCheckAsync extends BukkitRunnable { } } } -} - -/*class CommandSenderOutput implements CommandSender { - String lastOutput; - @Override - public void sendMessage(String output) { - lastOutput = output; - } - - @Override - public void sendMessage(String[] strings) { - String string = ""; - for(String s : strings) { - string += s; - string += " "; - } - lastOutput = string; - } - - @Override - public Server getServer() { - return Bukkit.getServer(); - } - - - @Override - public String getName() { - return "CommandSender"; - } - - @Override - public boolean isPermissionSet(Permission permission) { - return true; - } - - @Override - public boolean isPermissionSet(String s) { - return true; - } - - @Override - public boolean hasPermission(Permission permission) { - return true; - } - - @Override - public boolean hasPermission(String s) { - return true; - } - - @Override - public PermissionAttachment addAttachment(Plugin plugin) { - return addAttachment(plugin); - } - - @Override - public PermissionAttachment addAttachment(Plugin plugin, int i) { - return addAttachment(plugin, i); - } - - @Override - public PermissionAttachment addAttachment(Plugin plugin, String s, boolean b, int i) { - return addAttachment(plugin, s, b, i); - } - - @Override - public PermissionAttachment addAttachment(Plugin plugin, String s, boolean b) { - return addAttachment(plugin, s, b); - } - - @Override - public void removeAttachment(PermissionAttachment permissionAttachment) {} - - @Override - public void recalculatePermissions() {} - - @Override - public Set getEffectivePermissions() { - return getEffectivePermissions(); - } - - @Override - public boolean isOp() { - return true; - } - - @Override - public void setOp(boolean b) {} - - @Override - public Spigot spigot() { - return null; - } }*/ class Events implements Listener { @@ -277,16 +118,28 @@ class Events implements Listener { @EventHandler void onAsyncPlayerChat(AsyncPlayerChatEvent event) { - Player player = event.getPlayer(); + final Player player = event.getPlayer(); if (main.getConfig().getString(player.getUniqueId().toString()) != null) { - String prefix = ChatColor.translateAlternateColorCodes('&', main.getConfig().getString(player.getUniqueId().toString())); + final String prefix = ChatColor.translateAlternateColorCodes( + '&', + main.getConfig().getString(player.getUniqueId().toString()) + ); + event.setFormat(prefix + ChatColor.RESET + " " + player.getDisplayName().toString() + ChatColor.RESET + ": " + ChatColor.RESET + "%2$s"); } else if (event.getPlayer().isOp()) { - String prefix = ChatColor.translateAlternateColorCodes('&', "&4&l[&c&lOP&4&l]"); + final String prefix = ChatColor.translateAlternateColorCodes( + '&', + "&4&l[&c&lOP&4&l]" + ); + event.setFormat(prefix + ChatColor.RED + " " + player.getDisplayName().toString() + ChatColor.RESET + ": " + ChatColor.RESET + "%2$s"); } else { - String prefix = ChatColor.translateAlternateColorCodes('&', "&8&l[&7&lDeOP&8&l]"); + final String prefix = ChatColor.translateAlternateColorCodes( + '&', + "&8&l[&7&lDeOP&8&l]" + ); + event.setFormat(prefix + ChatColor.GRAY + " " + player.getDisplayName().toString() + ChatColor.RESET + ": " + ChatColor.RESET + "%2$s"); } @@ -296,16 +149,34 @@ class Events implements Listener { @EventHandler void onAsyncPlayerPreLogin(AsyncPlayerPreLoginEvent event) { try { - URL nameUrl = new URL("https://api.mojang.com/users/profiles/minecraft/" + event.getName()); - HttpsURLConnection nameConnection = (HttpsURLConnection) nameUrl.openConnection(); + final URL nameUrl = new URL("https://api.mojang.com/users/profiles/minecraft/" + event.getName()); + final HttpsURLConnection nameConnection = (HttpsURLConnection) nameUrl.openConnection(); if (nameConnection != null && - nameConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) { - InputStreamReader nameStream = new InputStreamReader(nameConnection.getInputStream()); - String uuid = new JsonParser().parse(nameStream).getAsJsonObject().get("id").getAsString(); - main.playerPremiumUUID.put(event.getName(), uuid); + nameConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) { + final InputStreamReader nameStream = new InputStreamReader(nameConnection.getInputStream()); + final String uuid = new JsonParser().parse(nameStream).getAsJsonObject().get("id").getAsString(); nameStream.close(); nameConnection.disconnect(); + + final URL uuidUrl = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false"); + final HttpsURLConnection uuidConnection = (HttpsURLConnection) uuidUrl.openConnection(); + + if (uuidConnection != null && + uuidConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) { + final InputStreamReader uuidStream = new InputStreamReader(uuidConnection.getInputStream()); + final JsonObject response = new JsonParser().parse(uuidStream).getAsJsonObject().get("properties").getAsJsonArray().get(0).getAsJsonObject(); + final String texture = response.get("value").getAsString(); + final String signature = response.get("signature").getAsString(); + uuidStream.close(); + uuidConnection.disconnect(); + + final PlayerProfile textureProfile = event.getPlayerProfile(); + textureProfile.clearProperties(); + textureProfile.setProperty(new ProfileProperty("textures", texture, signature)); + + main.playerProfile.put(event.getName(), textureProfile); + } } } catch (Exception exception) { } @@ -316,14 +187,14 @@ class Events implements Listener { try { event.getBlock().getState(); event.getToBlock().getState(); - } catch (Exception e) { + } catch (Exception exception) { event.setCancelled(true); } - } + } @EventHandler void onBlockPhysics(BlockPhysicsEvent event) { - Block block = event.getBlock(); + final Block block = event.getBlock(); if (main.fallingBlockList.contains(block.getType())) { main.fallingBlockCount++; @@ -332,33 +203,36 @@ class Events implements Listener { event.setCancelled(true); main.fallingBlockCount = 0; } - } else if (block.getType() == Material.SOIL) { + } else if (block.getType() == Material.FARMLAND) { event.setCancelled(true); - } else if (block.getType() == Material.STATIONARY_WATER || - block.getType() == Material.STATIONARY_LAVA) { - if (block.getRelative(BlockFace.UP).getType() == block.getType()) { + } else if (block.getType() == Material.WATER || + block.getType() == Material.LAVA) { + final Levelled levelledBlock = (Levelled) block.getBlockData(); + + if (levelledBlock.getLevel() <= 7 && + block.getRelative(BlockFace.UP).getType() == block.getType()) { if (block.getRelative(BlockFace.DOWN).getType() != Material.AIR && - block.getRelative(BlockFace.NORTH).getType() != Material.AIR && - block.getRelative(BlockFace.SOUTH).getType() != Material.AIR && - block.getRelative(BlockFace.WEST).getType() != Material.AIR && - block.getRelative(BlockFace.EAST).getType() != Material.AIR) { + block.getRelative(BlockFace.NORTH).getType() != Material.AIR && + block.getRelative(BlockFace.SOUTH).getType() != Material.AIR && + block.getRelative(BlockFace.WEST).getType() != Material.AIR && + block.getRelative(BlockFace.EAST).getType() != Material.AIR) { event.setCancelled(true); } } } else if (main.nonSolidWallMountedBlockList.contains(block.getType())) { - World world = event.getBlock().getWorld(); - int radius = 5; + final World world = event.getBlock().getWorld(); + final int radius = 5; int blockCount = 0; for (int x = -radius; x <= radius; x++) { for (int y = -radius; y <= radius; y++) { for (int z = -radius; z <= radius; z++) { if (blockCount < 42) { - Location blockLocation = new Location(world, block.getX() + x, block.getY() + y, block.getZ() + z); - Block coordBlock = world.getBlockAt(blockLocation); + final Location blockLocation = new Location(world, block.getX() + x, block.getY() + y, block.getZ() + z); + final Block coordBlock = world.getBlockAt(blockLocation); if (coordBlock.getType() == block.getType() || - main.nonSolidWallMountedBlockList.contains(coordBlock.getType())) { + main.nonSolidWallMountedBlockList.contains(coordBlock.getType())) { blockCount++; } @@ -376,11 +250,11 @@ class Events implements Listener { if (main.nonSolidDoubleBlockList.contains(block.getRelative(BlockFace.DOWN).getType())) { event.setCancelled(true); } else if (block.getRelative(BlockFace.DOWN).getType() == Material.AIR || - (main.nonSolidBlockList.contains(block.getRelative(BlockFace.DOWN).getType()) && - !main.nonSolidDoubleBlockList.contains(block.getRelative(BlockFace.DOWN).getType()))) { + (main.nonSolidBlockList.contains(block.getRelative(BlockFace.DOWN).getType()) && + !main.nonSolidDoubleBlockList.contains(block.getRelative(BlockFace.DOWN).getType()))) { for (int y = block.getRelative(BlockFace.UP).getY(); y <= 256; y++) { - World world = event.getBlock().getWorld(); - Block coordBlock = world.getBlockAt(new Location(world, block.getX(), y, block.getZ())); + final World world = event.getBlock().getWorld(); + final Block coordBlock = world.getBlockAt(new Location(world, block.getX(), y, block.getZ())); if (main.nonSolidDoubleBlockList.contains(coordBlock.getType())) { coordBlock.setType(Material.AIR, false); @@ -394,11 +268,11 @@ class Events implements Listener { } } else if (main.nonSolidSingularBlockList.contains(block.getType())) { if (block.getRelative(BlockFace.DOWN).getType() == Material.AIR || - main.nonSolidBlockList.contains(block.getRelative(BlockFace.DOWN).getType())) { + main.nonSolidBlockList.contains(block.getRelative(BlockFace.DOWN).getType())) { block.setType(Material.AIR, false); } } - } + } @EventHandler void onBlockPlace(BlockPlaceEvent event) { @@ -408,58 +282,110 @@ class Events implements Listener { try { event.getBlockPlaced().getState(); - } catch (Exception e) { + } catch (Exception exception) { event.setCancelled(true); } - } + } @EventHandler void onBlockRedstone(BlockRedstoneEvent event) { - double tps = Bukkit.getServer().getTPS()[0]; + final double tps = Bukkit.getServer().getTPS()[0]; if (tps < 14) { event.setNewCurrent(0); } - } + } @EventHandler void onBlockSpread(BlockSpreadEvent event) { - double tps = Bukkit.getServer().getTPS()[0]; + final double tps = Bukkit.getServer().getTPS()[0]; if (tps < 14) { event.setCancelled(true); } - } + } + + @EventHandler + void onCreatureSpawn(CreatureSpawnEvent event) { + if (event.getSpawnReason() == SpawnReason.CUSTOM || + event.getSpawnReason() == SpawnReason.DEFAULT || + event.getSpawnReason() == SpawnReason.DISPENSE_EGG || + event.getSpawnReason() == SpawnReason.SPAWNER || + event.getSpawnReason() == SpawnReason.SPAWNER_EGG) { + final LivingEntity mob = event.getEntity(); + final AttributeInstance followAttribute = mob.getAttribute(Attribute.GENERIC_FOLLOW_RANGE); + + if (followAttribute != null && + followAttribute.getBaseValue() > 40) { + followAttribute.setBaseValue(40); + } + } + + if (event.getEntityType() == EntityType.DROWNED || + event.getEntityType() == EntityType.GIANT || + event.getEntityType() == EntityType.HUSK || + event.getEntityType() == EntityType.PIG_ZOMBIE || + event.getEntityType() == EntityType.PLAYER || + event.getEntityType() == EntityType.SKELETON || + event.getEntityType() == EntityType.STRAY || + event.getEntityType() == EntityType.WITHER_SKELETON || + event.getEntityType() == EntityType.ZOMBIE || + event.getEntityType() == EntityType.ZOMBIE_VILLAGER) { + final LivingEntity mob = event.getEntity(); + + try { + mob.getEquipment().getArmorContents(); + } catch (Exception exception) { + mob.getEquipment().setArmorContents( + new ItemStack[] { + new ItemStack(Material.AIR), + new ItemStack(Material.AIR), + new ItemStack(Material.AIR), + new ItemStack(Material.AIR), + } + ); + } + + try { + mob.getEquipment().getItemInMainHand(); + } catch (Exception exception) { + mob.getEquipment().setItemInMainHand(new ItemStack(Material.AIR)); + } + + try { + mob.getEquipment().getItemInOffHand(); + } catch (Exception exception) { + mob.getEquipment().setItemInOffHand(new ItemStack(Material.AIR)); + } + } else if (event.getEntityType() == EntityType.ENDER_DRAGON) { + final int dragonCount = event.getLocation().getWorld().getEntitiesByClass(EnderDragon.class).size(); + + if (dragonCount > 25) { + event.setCancelled(true); + return; + } + } else if (event.getEntityType() == EntityType.MAGMA_CUBE) { + final MagmaCube magmacube = (MagmaCube) event.getEntity(); + + if (magmacube.getSize() > 100) { + magmacube.setSize(100); + } + } else if (event.getEntityType() == EntityType.SLIME) { + final Slime slime = (Slime) event.getEntity(); + + if (slime.getSize() > 100) { + slime.setSize(100); + } + } + } @EventHandler void onEntityAddToWorld(EntityAddToWorldEvent event) { - Entity entity = event.getEntity(); + if (event.getEntityType() != EntityType.PLAYER) { + final Entity entity = event.getEntity(); + final int count = entity.getLocation().getChunk().getEntities().length; - if (entity instanceof LivingEntity) { - LivingEntity mob = (LivingEntity) entity; - AttributeInstance followAttribute = mob.getAttribute(Attribute.GENERIC_FOLLOW_RANGE); - - if (followAttribute != null && followAttribute.getBaseValue() > 40) { - followAttribute.setBaseValue(40); - } - } else { - Entity[] chunkEntities = entity.getLocation().getChunk().getEntities(); - int count = 0; - - for (Entity chunkEntity : chunkEntities) { - if (chunkEntity.getType() != EntityType.PLAYER) { - if (count < 50) { - count++; - } else { - entity.remove(); - return; - } - } - } - - double tps = Bukkit.getServer().getTPS()[0]; - - if (tps < 14 && entity.getType() == EntityType.PRIMED_TNT) { + if (count > 50) { entity.remove(); } } @@ -467,14 +393,12 @@ class Events implements Listener { @EventHandler void onEntityDamage(EntityDamageEvent event) { - Entity entity = event.getEntity(); - - if (entity.getType() == EntityType.PLAYER) { + if (event.getEntityType() == EntityType.PLAYER) { if (((event.getCause() == DamageCause.CUSTOM || - event.getCause() == DamageCause.SUICIDE) && - event.getDamage() == Short.MAX_VALUE) || - (event.getCause() == DamageCause.VOID && - event.getDamage() == Float.MAX_VALUE)) { + event.getCause() == DamageCause.SUICIDE) && + event.getDamage() == Short.MAX_VALUE) || + (event.getCause() == DamageCause.VOID && + event.getDamage() == Float.MAX_VALUE)) { event.setDamage(Float.MAX_VALUE); event.setCancelled(true); } @@ -490,97 +414,22 @@ class Events implements Listener { @EventHandler void onEntitySpawn(EntitySpawnEvent event) { - Entity entity = event.getEntity(); + if (event.getEntityType() != EntityType.PLAYER) { + final int entityCount = event.getLocation().getChunk().getEntities().length; - if (entity instanceof LivingEntity) { - LivingEntity mob = (LivingEntity) entity; - AttributeInstance followAttribute = mob.getAttribute(Attribute.GENERIC_FOLLOW_RANGE); - - if (followAttribute != null && followAttribute.getBaseValue() > 40) { - followAttribute.setBaseValue(40); - } - - try { - mob.getEquipment().getArmorContents(); - } catch (Exception e) { - mob.getEquipment().setArmorContents( - new ItemStack[] { - new ItemStack(Material.AIR), - new ItemStack(Material.AIR), - new ItemStack(Material.AIR), - new ItemStack(Material.AIR) - } - ); - } - - try { - mob.getEquipment().getItemInMainHand(); - } catch (Exception e) { - mob.getEquipment().setItemInMainHand(new ItemStack(Material.AIR)); - } - - try { - mob.getEquipment().getItemInOffHand(); - } catch (Exception e) { - mob.getEquipment().setItemInOffHand(new ItemStack(Material.AIR)); - } - } - - if (entity.getType() != EntityType.PLAYER) { - int count = 0; - Entity[] chunkEntities = event.getLocation().getChunk().getEntities(); - - for (Entity chunkEntity : chunkEntities) { - if (chunkEntity.getType() != EntityType.PLAYER) { - if (count < 50) { - count++; - } else { - event.setCancelled(true); - return; - } - } - } - - if (entity.getType() == EntityType.ENDER_DRAGON) { - List worldEntities = event.getLocation().getWorld().getLivingEntities(); - - for (LivingEntity worldEntity : worldEntities) { - if (worldEntity.getType() == EntityType.ENDER_DRAGON) { - if (count < 25) { - count++; - } else { - event.setCancelled(true); - return; - } - } - } - } - - if (entity.getType() == EntityType.MAGMA_CUBE) { - MagmaCube magmacube = (MagmaCube) entity; - if (magmacube.getSize() > 100) { - magmacube.setSize(100); - } - } - - if (entity.getType() == EntityType.SLIME) { - Slime slime = (Slime) entity; - if (slime.getSize() > 100) { - slime.setSize(100); - } + if (entityCount > 50) { + event.setCancelled(true); } } } @EventHandler void onExplosionPrime(ExplosionPrimeEvent event) { - double tps = Bukkit.getServer().getTPS()[0]; + final double tps = Bukkit.getServer().getTPS()[0]; if (tps < 14) { event.setCancelled(true); - } - - if (event.getRadius() > 20) { + } else if (event.getRadius() > 20) { event.setRadius(20); } } @@ -589,38 +438,37 @@ class Events implements Listener { void onItemSpawn(ItemSpawnEvent event) { try { event.getEntity().getItemStack().getItemMeta(); - } catch (Exception | StackOverflowError e) { + } catch (Exception | StackOverflowError exception) { event.setCancelled(true); } } @EventHandler void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { - String arr[] = event.getMessage().split(" "); - String command = event.getMessage(); - UUID playerUUID = event.getPlayer().getUniqueId(); + final String[] arr = event.getMessage().split(" "); + final String command = event.getMessage(); + final UUID playerUuid = event.getPlayer().getUniqueId(); + final long millisDifference = System.currentTimeMillis() - main.commandMillisList.get(playerUuid); - if (main.commandMillisList.containsKey(playerUUID)) { - long millisDifference = System.currentTimeMillis() - main.commandMillisList.get(playerUUID); + main.commandMillisList.put(playerUuid, System.currentTimeMillis()); - if (millisDifference < 400) { - event.setCancelled(true); - } + if (millisDifference < 400) { + event.setCancelled(true); + return; } - main.commandMillisList.put(playerUUID, System.currentTimeMillis()); - - if ((arr[0].toLowerCase().equals("/minecraft:gamerule") || - arr[0].toLowerCase().equals("/gamerule")) && - arr.length >= 3) { - if (arr[1].toLowerCase().equals("randomtickspeed") && Double.parseDouble(arr[2]) > 6) { + if (("/minecraft:gamerule".equals(arr[0].toLowerCase()) || + "/gamerule".equals(arr[0].toLowerCase())) && + arr.length >= 3) { + if ("randomtickspeed".equals(arr[1].toLowerCase()) && + Double.parseDouble(arr[2]) > 6) { event.setMessage(command.replaceFirst(arr[2], "6")); } - } else if ((arr[0].toLowerCase().equals("/minecraft:particle") || - arr[0].toLowerCase().equals("/particle")) && - arr.length >= 10) { + } else if (("/minecraft:particle".equals(arr[0].toLowerCase()) || + "/particle".equals(arr[0].toLowerCase())) && + arr.length >= 10) { if (Double.parseDouble(arr[9]) > 10) { - StringBuilder stringBuilder = new StringBuilder(); + final StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < 9; i++) { stringBuilder.append(arr[i] + " "); @@ -629,7 +477,7 @@ class Events implements Listener { for (int i = 10; i < arr.length; i++) { stringBuilder.append(arr[i] + " "); } - + event.setMessage(stringBuilder.toString()); } } @@ -637,15 +485,14 @@ class Events implements Listener { @EventHandler void onPlayerDeath(PlayerDeathEvent event) { - System.out.println("dead"); - Player player = event.getEntity(); + final Player player = event.getEntity(); final AttributeInstance maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH); boolean maxHealthLow = false; maxHealth.setBaseValue(20); try { player.setHealth(20); - } catch (Exception e) { + } catch (Exception exception) { maxHealth.setBaseValue(Double.POSITIVE_INFINITY); player.setHealth(20); maxHealth.setBaseValue(20); @@ -662,49 +509,42 @@ class Events implements Listener { } if ((player.getLastDamageCause() != null && - player.getLastDamageCause().getCause() == DamageCause.SUICIDE && - player.getLastDamageCause().getDamage() == Float.MAX_VALUE) || - maxHealthLow == true) { + player.getLastDamageCause().getCause() == DamageCause.SUICIDE && + player.getLastDamageCause().getDamage() == Float.MAX_VALUE) || + maxHealthLow == true) { return; } - Bukkit.getScheduler().runTask(main, new Runnable() { - public void run() { - if (player.getBedSpawnLocation() != null) { - player.teleport(player.getBedSpawnLocation()); - } else { - World world = Bukkit.getWorld("world"); - Location spawnLoc = world.getSpawnLocation(); + if (player.getBedSpawnLocation() != null) { + player.teleport(player.getBedSpawnLocation()); + } else { + final World world = Bukkit.getWorld("world"); + final Location spawnLoc = world.getSpawnLocation(); - for (double y = spawnLoc.getY(); y <= 256; y++) { - Location yLoc = new Location(world, spawnLoc.getX(), y, spawnLoc.getZ()); - Block coordBlock = world.getBlockAt(yLoc); + for (double y = spawnLoc.getY(); y <= 256; y++) { + final Location yLocation = new Location(world, spawnLoc.getX(), y, spawnLoc.getZ()); + final Block coordBlock = world.getBlockAt(yLocation); - if (coordBlock.getType().isTransparent() && - coordBlock.getRelative(BlockFace.UP).getType().isTransparent()) { - player.teleport(yLoc); - return; - } - } + if (!coordBlock.getType().isSolid() && + !coordBlock.getRelative(BlockFace.UP).getType().isSolid()) { + player.teleport(yLocation); + return; } } - }); + } } @EventHandler void onPlayerInteract(PlayerInteractEvent event) { - Player player = event.getPlayer(); - UUID playerUUID = event.getPlayer().getUniqueId(); + final Player player = event.getPlayer(); + final UUID playerUuid = event.getPlayer().getUniqueId(); + final long millisDifference = System.currentTimeMillis() - main.interactMillisList.get(playerUuid); - if (main.interactMillisList.containsKey(playerUUID)) { - long millisDifference = System.currentTimeMillis() - main.interactMillisList.get(playerUUID); + main.interactMillisList.put(playerUuid, System.currentTimeMillis()); - if (millisDifference < 200) { - event.setCancelled(true); - } + if (millisDifference < 200) { + event.setCancelled(true); } - - main.interactMillisList.put(playerUUID, System.currentTimeMillis()); } @EventHandler @@ -725,54 +565,27 @@ class Events implements Listener { @EventHandler void onPlayerLogin(PlayerLoginEvent event) { - /*if (!(event.getHostname().startsWith("play.kaboom.pw") && - event.getHostname().endsWith(":53950"))) { + if (!(event.getHostname().startsWith("play.kaboom.pw") && + event.getHostname().endsWith(":53950"))) { event.disallow(Result.KICK_OTHER, "You connected to the server using an outdated server address/IP.\nPlease use the following address/IP:\n\nkaboom.pw"); - } else {*/ + } else { final Player player = event.getPlayer(); event.allow(); player.setOp(true); - - if (main.playerPremiumUUID.containsKey(player.getName())) { - Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() { - public void run() { - try { - URL uuidUrl = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + main.playerPremiumUUID.get(player.getName()) + "?unsigned=false"); - HttpsURLConnection uuidConnection = (HttpsURLConnection) uuidUrl.openConnection(); - - if (uuidConnection != null && - uuidConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) { - InputStreamReader uuidStream = new InputStreamReader(uuidConnection.getInputStream()); - JsonObject response = new JsonParser().parse(uuidStream).getAsJsonObject().get("properties").getAsJsonArray().get(0).getAsJsonObject(); - final String texture = response.get("value").getAsString(); - final String signature = response.get("signature").getAsString(); - uuidStream.close(); - uuidConnection.disconnect(); - - final PlayerProfile textureProfile = player.getPlayerProfile(); - textureProfile.clearProperties(); - textureProfile.setProperty(new ProfileProperty("textures", texture, signature)); - - Bukkit.getScheduler().runTask(main, new Runnable() { - @Override - public void run() { - player.setPlayerProfile(textureProfile); - } - }); - } - main.playerPremiumUUID.remove(player.getName()); - } catch (Exception exception) { - } - } - }); + main.commandMillisList.put(player.getUniqueId(), System.currentTimeMillis()); + main.interactMillisList.put(player.getUniqueId(), System.currentTimeMillis()); + try { + player.setPlayerProfile(main.playerProfile.get(player.getName())); + } catch (Exception exception) { } - /*}*/ + main.playerProfile.remove(player.getName()); + } } @EventHandler void onPlayerQuit(PlayerQuitEvent event) { - Player player = event.getPlayer(); + final Player player = event.getPlayer(); main.commandMillisList.remove(player.getUniqueId()); main.interactMillisList.remove(player.getUniqueId()); @@ -780,109 +593,32 @@ class Events implements Listener { @EventHandler void onPreCreatureSpawn(PreCreatureSpawnEvent event) { - int count = 0; - if (event.getType() != EntityType.PLAYER) { - Entity[] chunkEntities = event.getSpawnLocation().getChunk().getEntities(); + final int entityCount = event.getSpawnLocation().getChunk().getEntities().length; - for (Entity chunkEntity : chunkEntities) { - if (chunkEntity.getType() != EntityType.PLAYER) { - if (count < 50) { - count++; - } else { - event.setCancelled(true); - return; - } - } - } - - if (event.getType() == EntityType.ENDER_DRAGON) { - List worldEntities = event.getSpawnLocation().getWorld().getLivingEntities(); - - for (LivingEntity worldEntity : worldEntities) { - if (worldEntity.getType() == EntityType.ENDER_DRAGON) { - if (count < 25) { - count++; - } else { - event.setCancelled(true); - return; - } - } - } - } - - if (event.getType() == EntityType.MINECART_MOB_SPAWNER && - event.getReason() == SpawnReason.SPAWNER) { + if (entityCount > 50) { event.setCancelled(true); return; - } - } - } + } else if (event.getType() == EntityType.ENDER_DRAGON) { + final int dragonCount = event.getSpawnLocation().getWorld().getEntitiesByClass(EnderDragon.class).size(); - @EventHandler - void onServerCommand(ServerCommandEvent event) { - String arr[] = event.getCommand().split(" "); - String command = event.getCommand(); - - if (main.consoleCommandBlacklist.contains(arr[0].toLowerCase())) { - event.setCancelled(true); - } else if ((arr[0].toLowerCase().equals("minecraft:gamerule") || - arr[0].toLowerCase().equals("gamerule")) && - arr.length >= 3) { - if (arr[1].toLowerCase().equals("randomtickspeed") && Double.parseDouble(arr[2]) > 6) { - event.setCommand(command.replaceFirst(arr[2], "6")); - } - } else if ((arr[0].toLowerCase().equals("minecraft:particle") || - arr[0].toLowerCase().equals("particle")) && - arr.length >= 10) { - if (Double.parseDouble(arr[9]) > 10) { - StringBuilder stringBuilder = new StringBuilder(); - - for (int i = 0; i < 9; i++) { - stringBuilder.append(arr[i] + " "); - } - stringBuilder.append("10 "); - for (int i = 10; i < arr.length; i++) { - stringBuilder.append(arr[i] + " "); - } - - event.setCommand(stringBuilder.toString()); - } - } - } - - @EventHandler - void onServerListPing(PaperServerListPingEvent event) { - if (event.getClient().getProtocolVersion() != -1) { - event.setProtocolVersion(event.getClient().getProtocolVersion()); - } else { - event.setProtocolVersion(490); - } - event.setVersion("1.14.3"); - } - - @EventHandler - void onSignChange(SignChangeEvent event) { - try { - event.getLines(); - } catch (Exception e) { - event.setCancelled(true); - } - } - - @EventHandler - void onSpawnerSpawn(SpawnerSpawnEvent event) { - CreatureSpawner spawner = event.getSpawner(); - - try { - if (spawner.getSpawnedType() == EntityType.FALLING_BLOCK) { - FallingBlock block = (FallingBlock) event.getEntity(); - - if (block.getMaterial() == Material.MOB_SPAWNER) { + if (dragonCount > 25) { event.setCancelled(true); return; } + } + } + } + @EventHandler + void onPreSpawnerSpawn(PreSpawnerSpawnEvent event) { + try { + final CreatureSpawner spawner = (CreatureSpawner) event.getSpawnerLocation().getBlock().getState(); + + if (event.getType() == EntityType.MINECART_MOB_SPAWNER) { + event.setCancelled(true); + return; + } else if (event.getType() == EntityType.FALLING_BLOCK) { if (spawner.getDelay() > 100) { spawner.setMaxSpawnDelay(100); spawner.setDelay(100); @@ -904,4 +640,77 @@ class Events implements Listener { return; } } + + @EventHandler + void onServerCommand(ServerCommandEvent event) { + final String[] arr = event.getCommand().split(" "); + final String command = event.getCommand(); + + if (main.consoleCommandBlacklist.contains(arr[0].toLowerCase())) { + event.setCancelled(true); + } else if (("minecraft:gamerule".equals(arr[0].toLowerCase()) || + "gamerule".equals(arr[0].toLowerCase())) && + arr.length >= 3) { + if ("randomtickspeed".equals(arr[1].toLowerCase()) && + Double.parseDouble(arr[2]) > 6) { + event.setCommand(command.replaceFirst(arr[2], "6")); + } + } else if (("minecraft:particle".equals(arr[0].toLowerCase()) || + "particle".equals(arr[0].toLowerCase())) && + arr.length >= 10) { + if (Double.parseDouble(arr[9]) > 10) { + final StringBuilder stringBuilder = new StringBuilder(); + + for (int i = 0; i < 9; i++) { + stringBuilder.append(arr[i] + " "); + } + stringBuilder.append("10 "); + for (int i = 10; i < arr.length; i++) { + stringBuilder.append(arr[i] + " "); + } + + event.setCommand(stringBuilder.toString()); + } + } + } + + @EventHandler + void onServerListPing(PaperServerListPingEvent event) { + if (event.getClient().getProtocolVersion() != -1) { + event.setProtocolVersion(event.getClient().getProtocolVersion()); + } else { + event.setProtocolVersion(498); + } + event.setVersion("1.14.4"); + } + + @EventHandler + void onSignChange(SignChangeEvent event) { + try { + event.getLines(); + } catch (Exception exception) { + event.setCancelled(true); + } + } + + @EventHandler + void onSpawnerSpawn(SpawnerSpawnEvent event) { + if (event.getEntity().getType() == EntityType.FALLING_BLOCK) { + final FallingBlock block = (FallingBlock) event.getEntity(); + + if (block.getBlockData().getMaterial() == Material.SPAWNER) { + event.setCancelled(true); + return; + } + } + } + + @EventHandler + void onTNTPrime(TNTPrimeEvent event) { + final double tps = Bukkit.getServer().getTPS()[0]; + + if (tps < 14) { + event.setCancelled(true); + } + } } diff --git a/src/main/java/pw/kaboom/extras/Main.java b/src/main/java/pw/kaboom/extras/Main.java index f3face1..0efa0db 100644 --- a/src/main/java/pw/kaboom/extras/Main.java +++ b/src/main/java/pw/kaboom/extras/Main.java @@ -1,34 +1,20 @@ package pw.kaboom.extras; -import java.io.File; -import java.io.InputStreamReader; -import java.net.URL; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.UUID; -import javax.net.ssl.HttpsURLConnection; -import com.destroystokyo.paper.profile.PlayerProfile; -import com.destroystokyo.paper.profile.ProfileProperty; - -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; - -import org.bukkit.Bukkit; -import org.bukkit.Color; import org.bukkit.Material; - -import org.bukkit.entity.Player; - import org.bukkit.plugin.java.JavaPlugin; +import com.destroystokyo.paper.profile.PlayerProfile; + public class Main extends JavaPlugin { - int onlineCount = 0; - int fallingBlockCount = 0; + int fallingBlockCount; HashMap commandMillisList = new HashMap(); HashMap interactMillisList = new HashMap(); - HashMap playerPremiumUUID = new HashMap(); + HashMap playerProfile = new HashMap(); HashSet consoleCommandBlacklist = new HashSet(Arrays.asList(new String[] { "essentials:action", "essentials:adventure", @@ -361,75 +347,202 @@ public class Main extends JavaPlugin { Material.SAND, })); HashSet nonSolidDoubleBlockList = new HashSet(Arrays.asList(new Material[] { - Material.LONG_GRASS, - Material.SIGN_POST, - Material.WOODEN_DOOR, - Material.IRON_DOOR_BLOCK, + Material.GRASS, + Material.SIGN, + Material.OAK_DOOR, + Material.IRON_DOOR, Material.CACTUS, - Material.SUGAR_CANE_BLOCK, - Material.CAKE_BLOCK, + Material.SUGAR_CANE, + Material.CAKE, Material.DAYLIGHT_DETECTOR, - Material.CARPET, - Material.DOUBLE_PLANT, - Material.STANDING_BANNER, - Material.DAYLIGHT_DETECTOR_INVERTED, + Material.BLACK_CARPET, + Material.BLUE_CARPET, + Material.BROWN_CARPET, + Material.CYAN_CARPET, + Material.GRAY_CARPET, + Material.GREEN_CARPET, + Material.LIGHT_BLUE_CARPET, + Material.LIGHT_GRAY_CARPET, + Material.LIME_CARPET, + Material.MAGENTA_CARPET, + Material.ORANGE_CARPET, + Material.PINK_CARPET, + Material.PURPLE_CARPET, + Material.RED_CARPET, + Material.WHITE_CARPET, + Material.YELLOW_CARPET, + Material.BLACK_BANNER, + Material.BLUE_BANNER, + Material.BROWN_BANNER, + Material.CYAN_BANNER, + Material.GRAY_BANNER, + Material.GREEN_BANNER, + Material.LIGHT_BLUE_BANNER, + Material.LIGHT_GRAY_BANNER, + Material.LIME_BANNER, + Material.MAGENTA_BANNER, + Material.ORANGE_BANNER, + Material.PINK_BANNER, + Material.PURPLE_BANNER, + Material.RED_BANNER, + Material.WHITE_BANNER, + Material.YELLOW_BANNER, Material.SPRUCE_DOOR, Material.BIRCH_DOOR, Material.JUNGLE_DOOR, Material.ACACIA_DOOR, Material.DARK_OAK_DOOR, + Material.KELP, + Material.TALL_SEAGRASS, + Material.TALL_GRASS, + Material.SUNFLOWER, + Material.LARGE_FERN, + Material.LILAC, + Material.ROSE_BUSH, + Material.PEONY, })); HashSet nonSolidSingularBlockList = new HashSet(Arrays.asList(new Material[] { - Material.SAPLING, - Material.BED_BLOCK, + Material.ACACIA_SAPLING, + Material.BIRCH_SAPLING, + Material.DARK_OAK_SAPLING, + Material.JUNGLE_SAPLING, + Material.OAK_SAPLING, + Material.SPRUCE_SAPLING, + Material.BLACK_BED, + Material.BLUE_BED, + Material.BROWN_BED, + Material.CYAN_BED, + Material.GRAY_BED, + Material.GREEN_BED, + Material.LIGHT_BLUE_BED, + Material.LIGHT_GRAY_BED, + Material.LIME_BED, + Material.MAGENTA_BED, + Material.ORANGE_BED, + Material.PINK_BED, + Material.PURPLE_BED, + Material.RED_BED, + Material.WHITE_BED, + Material.YELLOW_BED, Material.POWERED_RAIL, Material.DETECTOR_RAIL, Material.DEAD_BUSH, - Material.YELLOW_FLOWER, - Material.RED_ROSE, + Material.AZURE_BLUET, + Material.ALLIUM, + Material.BLUE_ORCHID, + Material.DANDELION, + Material.FERN, + Material.ORANGE_TULIP, + Material.PINK_TULIP, + Material.POPPY, + Material.RED_TULIP, + Material.WHITE_TULIP, + Material.OXEYE_DAISY, Material.BROWN_MUSHROOM, Material.RED_MUSHROOM, Material.FIRE, - Material.CROPS, - Material.RAILS, - Material.STONE_PLATE, - Material.WOOD_PLATE, + Material.WHEAT, + Material.RAIL, + Material.STONE_PRESSURE_PLATE, + Material.ACACIA_PRESSURE_PLATE, + Material.BIRCH_PRESSURE_PLATE, + Material.DARK_OAK_PRESSURE_PLATE, + Material.JUNGLE_PRESSURE_PLATE, + Material.OAK_PRESSURE_PLATE, + Material.SPRUCE_PRESSURE_PLATE, Material.SNOW, - Material.DIODE_BLOCK_OFF, - Material.DIODE_BLOCK_ON, + Material.REPEATER, Material.PUMPKIN_STEM, Material.MELON_STEM, - Material.WATER_LILY, + Material.LILY_PAD, Material.FLOWER_POT, Material.CARROT, Material.POTATO, - Material.GOLD_PLATE, - Material.IRON_PLATE, - Material.REDSTONE_COMPARATOR_OFF, - Material.REDSTONE_COMPARATOR_ON, + Material.HEAVY_WEIGHTED_PRESSURE_PLATE, + Material.LIGHT_WEIGHTED_PRESSURE_PLATE, + Material.COMPARATOR, Material.ACTIVATOR_RAIL, - Material.BEETROOT_BLOCK, + Material.BEETROOTS, Material.NETHER_WART_BLOCK, + Material.SEAGRASS, + Material.BRAIN_CORAL, + Material.BUBBLE_CORAL, + Material.DEAD_BRAIN_CORAL, + Material.DEAD_BUBBLE_CORAL, + Material.DEAD_FIRE_CORAL, + Material.DEAD_HORN_CORAL, + Material.DEAD_TUBE_CORAL, + Material.FIRE_CORAL, + Material.HORN_CORAL, + Material.TUBE_CORAL, + Material.SEA_PICKLE, })); HashSet nonSolidWallMountedBlockList = new HashSet(Arrays.asList(new Material[] { Material.TORCH, + Material.WALL_TORCH, Material.LADDER, Material.WALL_SIGN, Material.LEVER, Material.REDSTONE_WIRE, - Material.REDSTONE_TORCH_OFF, - Material.REDSTONE_TORCH_ON, + Material.REDSTONE_TORCH, + Material.REDSTONE_WALL_TORCH, Material.STONE_BUTTON, - Material.TRAP_DOOR, + Material.ACACIA_TRAPDOOR, + Material.BIRCH_TRAPDOOR, + Material.DARK_OAK_TRAPDOOR, + Material.JUNGLE_TRAPDOOR, + Material.OAK_TRAPDOOR, + Material.SPRUCE_TRAPDOOR, Material.VINE, Material.COCOA, Material.TRIPWIRE_HOOK, - Material.WOOD_BUTTON, + Material.ACACIA_BUTTON, + Material.BIRCH_BUTTON, + Material.DARK_OAK_BUTTON, + Material.JUNGLE_BUTTON, + Material.OAK_BUTTON, + Material.SPRUCE_BUTTON, Material.IRON_TRAPDOOR, - Material.WALL_BANNER, - Material.PORTAL, - Material.ENDER_PORTAL, + Material.BLACK_WALL_BANNER, + Material.BLUE_WALL_BANNER, + Material.BROWN_WALL_BANNER, + Material.CYAN_WALL_BANNER, + Material.GRAY_WALL_BANNER, + Material.GREEN_WALL_BANNER, + Material.LIGHT_BLUE_WALL_BANNER, + Material.LIGHT_GRAY_WALL_BANNER, + Material.LIME_WALL_BANNER, + Material.MAGENTA_WALL_BANNER, + Material.ORANGE_WALL_BANNER, + Material.PINK_WALL_BANNER, + Material.PURPLE_WALL_BANNER, + Material.RED_WALL_BANNER, + Material.WHITE_WALL_BANNER, + Material.YELLOW_WALL_BANNER, + Material.NETHER_PORTAL, + Material.END_PORTAL, + Material.BRAIN_CORAL_FAN, + Material.BRAIN_CORAL_WALL_FAN, + Material.BUBBLE_CORAL_FAN, + Material.BUBBLE_CORAL_WALL_FAN, + Material.DEAD_BRAIN_CORAL_FAN, + Material.DEAD_BRAIN_CORAL_WALL_FAN, + Material.DEAD_BUBBLE_CORAL_FAN, + Material.DEAD_BUBBLE_CORAL_WALL_FAN, + Material.DEAD_FIRE_CORAL_FAN, + Material.DEAD_FIRE_CORAL_WALL_FAN, + Material.DEAD_HORN_CORAL_FAN, + Material.DEAD_HORN_CORAL_WALL_FAN, + Material.DEAD_TUBE_CORAL_FAN, + Material.DEAD_TUBE_CORAL_WALL_FAN, + Material.FIRE_CORAL_FAN, + Material.FIRE_CORAL_WALL_FAN, + Material.HORN_CORAL_FAN, + Material.HORN_CORAL_WALL_FAN, + Material.TUBE_CORAL_FAN, + Material.TUBE_CORAL_WALL_FAN, })); + HashSet nonSolidBlockList = new HashSet(); public void onEnable() { @@ -452,49 +565,8 @@ public class Main extends JavaPlugin { this.getCommand("unloadchunks").setExecutor(new CommandUnloadChunks()); this.getCommand("username").setExecutor(new CommandUsername(this)); - new Tick(this).runTaskTimer(this, 0, 1); - new TickAsync(this).runTaskTimerAsynchronously(this, 0, 1); - new TileEntityCheckAsync(this).runTaskTimerAsynchronously(this, 0, 400); + new AutosaveCheck().runTaskTimerAsynchronously(this, 0, 20); + /*new TileEntityCheckAsync(this).runTaskTimerAsynchronously(this, 0, 400);*/ this.getServer().getPluginManager().registerEvents(new Events(this), this); } - - public void getSkin(String name, final Player player) { - try { - URL nameUrl = new URL("https://api.mojang.com/users/profiles/minecraft/" + name); - HttpsURLConnection nameConnection = (HttpsURLConnection) nameUrl.openConnection(); - - if (nameConnection != null && - nameConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) { - InputStreamReader nameStream = new InputStreamReader(nameConnection.getInputStream()); - String uuid = new JsonParser().parse(nameStream).getAsJsonObject().get("id").getAsString(); - nameStream.close(); - nameConnection.disconnect(); - - URL uuidUrl = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false"); - HttpsURLConnection uuidConnection = (HttpsURLConnection) uuidUrl.openConnection(); - - if (uuidConnection != null && - uuidConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) { - InputStreamReader uuidStream = new InputStreamReader(uuidConnection.getInputStream()); - JsonObject response = new JsonParser().parse(uuidStream).getAsJsonObject().get("properties").getAsJsonArray().get(0).getAsJsonObject(); - final String texture = response.get("value").getAsString(); - final String signature = response.get("signature").getAsString(); - uuidStream.close(); - uuidConnection.disconnect(); - - final PlayerProfile textureProfile = player.getPlayerProfile(); - textureProfile.clearProperties(); - textureProfile.setProperty(new ProfileProperty("textures", texture, signature)); - - Bukkit.getScheduler().runTask(this, new Runnable() { - @Override - public void run() { - player.setPlayerProfile(textureProfile); - } - }); - } - } - } catch (Exception exception) { - } - } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 2349a65..c6693d9 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,7 @@ name: Extras main: pw.kaboom.extras.Main description: Plugin that adds extra functionality to the Kaboom.pw server. +api-version: 1.13 version: master commands: