diff --git a/src/main/java/pw/kaboom/extras/Commands.java b/src/main/java/pw/kaboom/extras/Commands.java index ab6d4ff..5c45dc9 100644 --- a/src/main/java/pw/kaboom/extras/Commands.java +++ b/src/main/java/pw/kaboom/extras/Commands.java @@ -45,7 +45,8 @@ class CommandClearChat implements CommandExecutor { class CommandConsole implements CommandExecutor { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - Player player = (Player)sender; + Player player = (Player) sender; + if (args.length == 0) { player.sendMessage(ChatColor.RED + "Usage: /" + label + " "); } else { @@ -57,13 +58,12 @@ class CommandConsole implements CommandExecutor { class CommandDestroyEntities implements CommandExecutor { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - Player player = (Player)sender; + Player player = (Player) sender; + for (World world : Bukkit.getServer().getWorlds()) { - for (Chunk chunk : world.getLoadedChunks()) { - for (Entity entity : chunk.getEntities()) { - if (entity.getType() != EntityType.PLAYER) { - entity.remove(); - } + for (Entity entity : world.getEntities()) { + if (entity.getType() != EntityType.PLAYER) { + entity.remove(); } } } @@ -72,19 +72,11 @@ class CommandDestroyEntities implements CommandExecutor { } } -class CommandDiscord implements CommandExecutor { - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - Player player = (Player)sender; - player.sendMessage("Join the Kaboom.pw Discord server to chat with other users"); - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "minecraft:tellraw " + player.getName() + " [\"\",{\"text\":\"https://discord.gg/UMGbMsU\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://discord.gg/UMGbMsU\"}}]"); - return true; - } -} - class CommandEnchantAll implements CommandExecutor { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - Player player = (Player)sender; + Player player = (Player) sender; ItemStack item = player.getItemInHand(); + if (item.getType() == Material.AIR) { player.sendMessage("Please hold an item in your hand to enchant it"); } else { @@ -101,7 +93,7 @@ class CommandEnchantAll implements CommandExecutor { item.addUnsafeEnchantment(Enchantment.DURABILITY, 32767); item.addUnsafeEnchantment(Enchantment.FIRE_ASPECT, 32767); item.addUnsafeEnchantment(Enchantment.FROST_WALKER, 32767); - /*item.addUnsafeEnchantment(Enchantment.KNOCKBACK, 32767);*/ + item.addUnsafeEnchantment(Enchantment.KNOCKBACK, 32767); item.addUnsafeEnchantment(Enchantment.LOOT_BONUS_BLOCKS, 32767); item.addUnsafeEnchantment(Enchantment.LOOT_BONUS_MOBS, 32767); item.addUnsafeEnchantment(Enchantment.LUCK, 32767); @@ -133,12 +125,13 @@ class CommandJumpscare implements CommandExecutor { } public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - Player player = (Player)sender; + Player player = (Player) sender; + if (args.length == 0) { player.sendMessage(ChatColor.RED + "Usage: /" + label + " "); } else { if (args[0].equals("*") || args[0].equals("**")) { - for (Player p: Bukkit.getOnlinePlayers()) { + for (Player p : Bukkit.getOnlinePlayers()) { createJumpscare(p); } player.sendMessage("Successfully created jumpscare for every player"); @@ -163,7 +156,8 @@ class CommandPrefix implements CommandExecutor { } public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - Player player = (Player)sender; + Player player = (Player) sender; + if (args.length == 0) { player.sendMessage(ChatColor.RED + "Usage: /" + label + " "); } else if (args[0].equalsIgnoreCase("off")) { @@ -180,43 +174,57 @@ class CommandPrefix implements CommandExecutor { } class CommandSkin implements CommandExecutor { + Main main; + CommandSkin(Main main) { + this.main = main; + } + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - Player player = (Player)sender; + Player player = (Player) sender; + if (args.length == 0) { player.sendMessage(ChatColor.RED + "Usage: /" + label + " "); } else { - try { - String name = args[0]; - URL nameurl = new URL("https://api.mojang.com/users/profiles/minecraft/" + name); - HttpURLConnection nameconnection = (HttpURLConnection) nameurl.openConnection(); + Bukkit.getScheduler().runTaskAsynchronously(main, () -> { + try { + String name = args[0]; + URL nameurl = new URL("https://api.mojang.com/users/profiles/minecraft/" + name); + HttpURLConnection nameconnection = (HttpURLConnection) nameurl.openConnection(); - if (nameconnection.getResponseCode() == 200) { - InputStreamReader namestream = new InputStreamReader(nameconnection.getInputStream()); - String uuid = new JsonParser().parse(namestream).getAsJsonObject().get("id").getAsString(); - URL uuidurl = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false"); - HttpURLConnection uuidconnection = (HttpURLConnection) uuidurl.openConnection(); + if (nameconnection.getResponseCode() == 200) { + InputStreamReader namestream = new InputStreamReader(nameconnection.getInputStream()); + String uuid = new JsonParser().parse(namestream).getAsJsonObject().get("id").getAsString(); + URL uuidurl = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false"); + HttpURLConnection uuidconnection = (HttpURLConnection) uuidurl.openConnection(); - if (uuidconnection.getResponseCode() == 200) { - InputStreamReader uuidstream = new InputStreamReader(uuidconnection.getInputStream()); - JsonObject response = new JsonParser().parse(uuidstream).getAsJsonObject().get("properties").getAsJsonArray().get(0).getAsJsonObject(); - String texture = response.get("value").getAsString(); - String signature = response.get("signature").getAsString(); + if (uuidconnection.getResponseCode() == 200) { + InputStreamReader uuidstream = new InputStreamReader(uuidconnection.getInputStream()); + JsonObject response = new JsonParser().parse(uuidstream).getAsJsonObject().get("properties").getAsJsonArray().get(0).getAsJsonObject(); + String texture = response.get("value").getAsString(); + String signature = response.get("signature").getAsString(); - PlayerProfile textureprofile = player.getPlayerProfile(); - textureprofile.setProperty(new ProfileProperty("textures", texture, signature)); - player.setPlayerProfile(textureprofile); - player.sendMessage("Successfully set your skin to " + name + "'s"); + Bukkit.getScheduler().scheduleSyncDelayedTask(main, () -> { + PlayerProfile textureprofile = player.getPlayerProfile(); + textureprofile.setProperty(new ProfileProperty("textures", texture, signature)); + player.setPlayerProfile(textureprofile); + player.sendMessage("Successfully set your skin to " + name + "'s"); + }); + } else { + Bukkit.getScheduler().scheduleSyncDelayedTask(main, () -> { + player.sendMessage("Failed to change skin. Try again later"); + }); + } + uuidconnection.disconnect(); } else { - player.sendMessage("Failed to change skin. Try again later"); + Bukkit.getScheduler().scheduleSyncDelayedTask(main, () -> { + player.sendMessage("A player with that username doesn't exist"); + }); } - uuidconnection.disconnect(); - } else { - player.sendMessage("A player with that username doesn't exist"); + nameconnection.disconnect(); + } catch (Exception exception) { + exception.printStackTrace(); } - nameconnection.disconnect(); - } catch (Exception exception) { - exception.printStackTrace(); - } + }); } return true; } @@ -224,7 +232,8 @@ class CommandSkin implements CommandExecutor { class CommandSpawn implements CommandExecutor { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - Player player = (Player)sender; + Player player = (Player) sender; + World world = Bukkit.getWorld("world"); player.teleport(new Location(world, 0.5, 100, 0.5)); player.sendMessage("Successfully moved to the spawn"); @@ -234,7 +243,8 @@ class CommandSpawn implements CommandExecutor { class CommandTellraw implements CommandExecutor { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - Player player = (Player)sender; + Player player = (Player) sender; + if (args.length == 0) { player.sendMessage(ChatColor.RED + "Usage: /" + label + " "); } else { @@ -246,7 +256,8 @@ class CommandTellraw implements CommandExecutor { class CommandUnloadChunks implements CommandExecutor { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - Player player = (Player)sender; + Player player = (Player) sender; + for (World world : Bukkit.getServer().getWorlds()) { for (Chunk chunk : world.getLoadedChunks()) { chunk.unload(true); @@ -264,7 +275,8 @@ class CommandUsername implements CommandExecutor { } public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - Player player = (Player)sender; + Player player = (Player) sender; + if (args.length == 0) { player.sendMessage(ChatColor.RED + "Usage: /" + label + " "); } else { diff --git a/src/main/java/pw/kaboom/extras/Events.java b/src/main/java/pw/kaboom/extras/Events.java index 493d106..9cca9e9 100644 --- a/src/main/java/pw/kaboom/extras/Events.java +++ b/src/main/java/pw/kaboom/extras/Events.java @@ -7,11 +7,13 @@ import java.util.Iterator; import com.boydti.fawe.FaweAPI; import com.destroystokyo.paper.event.entity.EntityAddToWorldEvent; +import com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent; import com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent; 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.World; @@ -21,11 +23,14 @@ import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.block.Container; import org.bukkit.block.CreatureSpawner; import org.bukkit.entity.Player; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; +import org.bukkit.entity.Item; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.MagmaCube; import org.bukkit.entity.Slime; @@ -33,28 +38,25 @@ import org.bukkit.entity.Slime; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockDispenseEvent; import org.bukkit.event.block.BlockExplodeEvent; -import org.bukkit.event.block.BlockFromToEvent; import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockRedstoneEvent; +import org.bukkit.event.block.BlockSpreadEvent; -import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; -import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.entity.ExplosionPrimeEvent; +import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.entity.LingeringPotionSplashEvent; import org.bukkit.event.entity.PotionSplashEvent; import org.bukkit.event.entity.SpawnerSpawnEvent; -import org.bukkit.event.hanging.HangingPlaceEvent; - import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.AsyncPlayerPreLoginEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerKickEvent; import org.bukkit.event.player.PlayerLoginEvent; @@ -62,9 +64,12 @@ import org.bukkit.event.player.PlayerLoginEvent.Result; import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.server.ServerCommandEvent; -import org.bukkit.event.server.ServerListPingEvent; +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.scheduler.BukkitRunnable; @@ -82,19 +87,23 @@ class PasteSpawn extends BukkitRunnable { } public void run() { - boolean allowUndo = false; - boolean noAir = false; - Vector position = new Vector(0, 100, 0); - try { + boolean allowUndo = false; + boolean noAir = false; + Vector position = new Vector(0, 100, 0); EditSession editSession = ClipboardFormat.findByFile(main.spawnSchematic).load(main.spawnSchematic).paste(FaweAPI.getWorld("world"), position, allowUndo, !noAir, (Transform) null); - } catch(Exception exception) { + } catch (Exception exception) { exception.printStackTrace(); } } } -class Tick extends BukkitRunnable { +class TickAsync extends BukkitRunnable { + Main main; + TickAsync(Main main) { + this.main = main; + } + public void run() { for (World world : Bukkit.getServer().getWorlds()) { WorldBorder worldborder = world.getWorldBorder(); @@ -104,16 +113,49 @@ class Tick extends BukkitRunnable { worldborder.setCenter(0, 0); } + if (world.isAutoSave() == false) { + world.setAutoSave(true); + } + for (Entity entity : world.getEntities()) { if (entity instanceof LivingEntity) { LivingEntity mob = (LivingEntity) entity; AttributeInstance followAttribute = mob.getAttribute(Attribute.GENERIC_FOLLOW_RANGE); - if (followAttribute != null && followAttribute.getBaseValue() > 32) { + if (followAttribute != null && followAttribute.getBaseValue() > 40) { followAttribute.setBaseValue(32); } } } + + for (Chunk chunk : world.getLoadedChunks()) { + int sizeCount = 0; + for (BlockState block : chunk.getTileEntities()) { + if (block instanceof Container) { + Container container = (Container) block; + + for (ItemStack item : container.getInventory().getContents()) { + if (item != null) { + try { + sizeCount = sizeCount + item.toString().length(); + + if (sizeCount > 200000) { + for (BlockState chunkBlock : chunk.getTileEntities()) { + if (chunkBlock instanceof Container) { + Bukkit.getScheduler().scheduleSyncDelayedTask(main, () -> { + chunkBlock.getBlock().getDrops().clear(); + chunkBlock.getBlock().setType(Material.AIR); + }); + } + } + } + } catch (Exception e) { + } + } + } + } + } + } } } } @@ -127,81 +169,34 @@ class Events implements Listener { @EventHandler void onAsyncPlayerChat(AsyncPlayerChatEvent event) { Player player = event.getPlayer(); - String message = event.getMessage().substring(0, Math.min(256, event.getMessage().length())); if (main.getConfig().getString(player.getUniqueId().toString()) != null) { String prefix = ChatColor.translateAlternateColorCodes('&', main.getConfig().getString(player.getUniqueId().toString())); - event.setFormat(prefix + ChatColor.RESET + " " + player.getDisplayName().toString() + ChatColor.RESET + ": " + ChatColor.RESET + ChatColor.translateAlternateColorCodes('&', message)); + 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]"); - event.setFormat(prefix + ChatColor.RED + " " + player.getDisplayName().toString() + ChatColor.RESET + ": " + ChatColor.RESET + ChatColor.translateAlternateColorCodes('&', message)); + 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]"); - event.setFormat(prefix + ChatColor.GRAY + " " + player.getDisplayName().toString() + ChatColor.RESET + ": " + ChatColor.RESET + ChatColor.translateAlternateColorCodes('&', message)); + event.setFormat(prefix + ChatColor.GRAY + " " + player.getDisplayName().toString() + ChatColor.RESET + ": " + ChatColor.RESET + "%2$s"); } - } - - @EventHandler - void onBlockBreak(BlockBreakEvent event) { - for (ItemStack item : event.getBlock().getDrops()) { - main.editMeta(item); - } - } - - @EventHandler - void onBlockDispense(BlockDispenseEvent event) { - ItemStack item = event.getItem(); - main.editMeta(item); + event.setMessage(ChatColor.translateAlternateColorCodes('&', event.getMessage())); } @EventHandler void onBlockExplode(BlockExplodeEvent event) { - Block block = event.getBlock(); - double x = block.getLocation().getX(); - double z = block.getLocation().getZ(); double tps = Bukkit.getServer().getTPS()[0]; - if (block.getWorld().getName().equals("world")) { - if ((x > -20 && x < 20) && (z > -20 && z < 20)) { - event.blockList().clear(); - } - } - if (tps < 14) { event.setCancelled(true); } - - event.setYield(0); - } - - @EventHandler - void onBlockFromTo(BlockFromToEvent event) { - Block block = event.getBlock(); - double x = block.getLocation().getX(); - double z = block.getLocation().getZ(); - - if (block.getWorld().getName().equals("world")) { - if ((x > -20 && x < 20) && (z > -20 && z < 20)) { - event.setCancelled(true); - } - } } @EventHandler void onBlockPhysics(BlockPhysicsEvent event) { Block block = event.getBlock(); - double x = block.getLocation().getX(); - double z = block.getLocation().getZ(); - if (block.getWorld().getName().equals("world")) { - if ((x > -20 && x < 20) && (z > -20 && z < 20)) { - event.setCancelled(true); - } - } - - if (block.getType() == Material.SOIL || - block.getType() == Material.LAVA || - block.getType() == Material.WATER) { + if (block.getType() == Material.SOIL) { event.setCancelled(true); } } @@ -222,46 +217,39 @@ class Events implements Listener { } } + @EventHandler + void onBlockSpread(BlockSpreadEvent event) { + double tps = Bukkit.getServer().getTPS()[0]; + + if (tps < 14) { + event.setCancelled(true); + } + } + @EventHandler void onEntityAddToWorld(EntityAddToWorldEvent event) { Entity entity = event.getEntity(); Entity[] chunkEntities = entity.getLocation().getChunk().getEntities(); + double tps = Bukkit.getServer().getTPS()[0]; int onChunk = 0; for (Entity chunkEntity : chunkEntities) { - if (onChunk < 50 && !(chunkEntity instanceof Player)) { + if (onChunk < 50 && chunkEntity.getType() != EntityType.PLAYER) { onChunk++; } } - if (onChunk == 50 && !(entity instanceof LivingEntity)) { + if (onChunk == 50 && !(entity instanceof LivingEntity) || + tps < 14 && entity.getType() == EntityType.PRIMED_TNT) { entity.remove(); } - if (entity instanceof MagmaCube) { - MagmaCube magmacube = (MagmaCube) entity; - if (magmacube.getSize() > 100) { - magmacube.setSize(100); - } - } + if (entity instanceof LivingEntity) { + LivingEntity mob = (LivingEntity) entity; + AttributeInstance followAttribute = mob.getAttribute(Attribute.GENERIC_FOLLOW_RANGE); - if (entity instanceof Slime) { - Slime slime = (Slime) entity; - if (slime.getSize() > 100) { - slime.setSize(100); - } - } - } - - @EventHandler - void onEntityChangeBlockEvent(EntityChangeBlockEvent event) { - Block block = event.getBlock(); - double x = block.getLocation().getX(); - double z = block.getLocation().getZ(); - - if (block.getWorld().getName().equals("world")) { - if ((x > -20 && x < 20) && (z > -20 && z < 20)) { - event.setCancelled(true); + if (followAttribute != null && followAttribute.getBaseValue() > 40) { + followAttribute.setBaseValue(40); } } } @@ -279,27 +267,12 @@ class Events implements Listener { } @EventHandler - void onEntityExplode(EntityExplodeEvent event) { - double tps = Bukkit.getServer().getTPS()[0]; + void onEntityKnockbackByEntity(EntityKnockbackByEntityEvent event) { + Entity entity = event.getEntity(); - Iterator iter = event.blockList().iterator(); - while (iter.hasNext()) { - Block block = iter.next(); - double x = block.getX(); - double z = block.getZ(); - - if (block.getWorld().getName().equals("world")) { - if ((x > -20 && x < 20) && (z > -20 && z < 20)) { - iter.remove(); - } - } - } - - if (tps < 14) { + if (event.getKnockbackStrength() > 100) { event.setCancelled(true); } - - event.setYield(0); } @EventHandler @@ -309,12 +282,12 @@ class Events implements Listener { int onChunk = 0; for (Entity chunkEntity : chunkEntities) { - if (onChunk < 50 && !(chunkEntity instanceof Player)) { + if (onChunk < 50 && chunkEntity.getType() != EntityType.PLAYER) { onChunk++; } } - if (onChunk == 50 && !(entity instanceof Player)) { + if (onChunk == 50 && entity.getType() != EntityType.PLAYER) { event.setCancelled(true); } @@ -322,15 +295,53 @@ class Events implements Listener { LivingEntity mob = (LivingEntity) entity; AttributeInstance followAttribute = mob.getAttribute(Attribute.GENERIC_FOLLOW_RANGE); - if (followAttribute != null && followAttribute.getBaseValue() > 32) { - followAttribute.setBaseValue(32); + 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.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); } } } @EventHandler void onExplosionPrime(ExplosionPrimeEvent event) { - Entity entity = event.getEntity(); double tps = Bukkit.getServer().getTPS()[0]; if (tps < 14) { @@ -342,6 +353,17 @@ class Events implements Listener { } } + @EventHandler + void onItemSpawn(ItemSpawnEvent event) { + ItemStack item = event.getEntity().getItemStack(); + + try { + item.getItemMeta(); + } catch (Exception e) { + event.setCancelled(true); + } + } + @EventHandler void onLingeringPotionSplash(LingeringPotionSplashEvent event) { Entity entity = event.getEntity(); @@ -368,45 +390,23 @@ class Events implements Listener { } } - @EventHandler - void onHangingPlace(HangingPlaceEvent event) { - Entity entity = event.getEntity(); - double x = entity.getLocation().getX(); - double z = entity.getLocation().getZ(); - - if (entity.getWorld().getName().equals("world")) { - if ((x > -20 && x < 20) && (z > -20 && z < 20)) { - event.setCancelled(true); - } - } - } - @EventHandler void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { String arr[] = event.getMessage().split(" "); - if (arr[0].toLowerCase().equals("//schem") || - arr[0].toLowerCase().equals("//schematic") || - arr[0].toLowerCase().equals("/schem") || - arr[0].toLowerCase().equals("/schematic") || - arr[0].toLowerCase().equals("/worldedit:/schem") || - arr[0].toLowerCase().equals("/worldedit:/schematic") || - arr[0].toLowerCase().equals("/worldedit:schem") || - arr[0].toLowerCase().equals("/worldedit:schematic")) { - if (arr[1].toLowerCase().equals("delete")) { - event.setCancelled(true); - } - } else if (arr[0].toLowerCase().equals("/minecraft:gamerule") || + if (arr[0].toLowerCase().equals("/minecraft:gamerule") || arr[0].toLowerCase().equals("/gamerule")) { if (arr[1] != null && arr[1].toLowerCase().equals("randomtickspeed")) { if (arr[2] != null && Integer.parseInt(arr[2]) > 6) { - event.setMessage(String.join(" ", arr[0], arr[1]) + " 6"); + String gameruleArr[] = event.getMessage().split(" ", 2); + event.setMessage(gameruleArr[0] + " 6"); } } } else if (arr[0].toLowerCase().equals("/minecraft:particle") || arr[0].toLowerCase().equals("/particle")) { if (arr[9] != null && Integer.parseInt(arr[9]) > 10) { - event.setMessage(String.join(" ", arr[0], arr[1], arr[2], arr[3], arr[4], arr[5], arr[6], arr[7], arr[8]) + " 10"); + String particleArr[] = event.getMessage().split(" ", 11); + event.setMessage(particleArr[0].replaceAll(" [^ ]+$", "") + " 10 " + particleArr[1]); } } } @@ -415,14 +415,20 @@ class Events implements Listener { void onPlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); - /*if (player.getInventory().getContents() != null) { - for (ItemStack item : player.getInventory().getContents()) { - main.editMeta(item); - } - }*/ - player.getInventory().clear(); + Bukkit.getScheduler().runTaskAsynchronously(main, () -> { + main.getSkin(player.getName(), player); + }); + + for (ItemStack item : player.getInventory().getContents()) { + if (item != null) { + try { + item.getItemMeta(); + } catch (Exception e) { + player.getInventory().remove(item); + } + } + } - main.getSkin(player.getName(), player); player.setOp(true); player.sendTitle(ChatColor.GRAY + "Kaboom.pw", "Free OP • Anarchy • Creative", 10, 160, 5); } @@ -445,7 +451,6 @@ class Events implements Listener { } else { event.allow(); } - /*event.allow();*/ } @EventHandler @@ -488,42 +493,26 @@ class Events implements Listener { if (main.consoleCommandBlacklist.contains(arr[0].toLowerCase())) { event.setCancelled(true); - } else if (arr[0].toLowerCase().equals("/schem") || - arr[0].toLowerCase().equals("/schematic") || - arr[0].toLowerCase().equals("schem") || - arr[0].toLowerCase().equals("schematic") || - arr[0].toLowerCase().equals("worldedit:/schem") || - arr[0].toLowerCase().equals("worldedit:/schematic") || - arr[0].toLowerCase().equals("worldedit:schem") || - arr[0].toLowerCase().equals("worldedit:schematic")) { - if (arr[1].toLowerCase().equals("delete")) { - event.setCancelled(true); - } - } else if (arr[0].toLowerCase().equals("/minecraft:gamerule") || - arr[0].toLowerCase().equals("/gamerule")) { + } else if (arr[0].toLowerCase().equals("minecraft:gamerule") || + arr[0].toLowerCase().equals("gamerule")) { if (arr[1] != null && arr[1].toLowerCase().equals("randomtickspeed")) { if (arr[2] != null && Integer.parseInt(arr[2]) > 6) { - event.setCommand(String.join(" ", arr[0], arr[1]) + " 6"); + String gameruleArr[] = event.getCommand().split(" ", 3); + event.setCommand(gameruleArr[0] + " 6"); } } } else if (arr[0].toLowerCase().equals("minecraft:particle") || arr[0].toLowerCase().equals("particle")) { if (arr[9] != null && Integer.parseInt(arr[9]) > 10) { - event.setCommand(String.join(" ", arr[0], arr[1], arr[2], arr[3], arr[4], arr[5], arr[6], arr[7], arr[8]) + " 10"); + String particleArr[] = event.getCommand().split(" ", 11); + event.setCommand(particleArr[0].replaceAll(" [^ ]+$", "") + " 10 " + particleArr[1]); } } } - @EventHandler - void onServerListPing(ServerListPingEvent event) { - event.setMaxPlayers(event.getNumPlayers() + 1); - } - @EventHandler void onSpawnerSpawn(SpawnerSpawnEvent event) { CreatureSpawner spawner = event.getSpawner(); - Entity entity = event.getEntity(); - LivingEntity mob = (LivingEntity) entity; if (spawner.getSpawnCount() > 200) { spawner.setSpawnCount(200); diff --git a/src/main/java/pw/kaboom/extras/Main.java b/src/main/java/pw/kaboom/extras/Main.java index 7aed69e..304ff52 100644 --- a/src/main/java/pw/kaboom/extras/Main.java +++ b/src/main/java/pw/kaboom/extras/Main.java @@ -13,15 +13,12 @@ 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.inventory.ItemStack; -import org.bukkit.inventory.meta.LeatherArmorMeta; -import org.bukkit.inventory.meta.PotionMeta; - import org.bukkit.plugin.java.JavaPlugin; public class Main extends JavaPlugin { @@ -358,18 +355,17 @@ public class Main extends JavaPlugin { this.getCommand("clearchat").setExecutor(new CommandClearChat()); this.getCommand("console").setExecutor(new CommandConsole()); this.getCommand("destroyentities").setExecutor(new CommandDestroyEntities()); - this.getCommand("discord").setExecutor(new CommandDiscord()); this.getCommand("enchantall").setExecutor(new CommandEnchantAll()); this.getCommand("jumpscare").setExecutor(new CommandJumpscare()); this.getCommand("prefix").setExecutor(new CommandPrefix(this)); - this.getCommand("skin").setExecutor(new CommandSkin()); + this.getCommand("skin").setExecutor(new CommandSkin(this)); this.getCommand("spawn").setExecutor(new CommandSpawn()); this.getCommand("tellraw").setExecutor(new CommandTellraw()); this.getCommand("unloadchunks").setExecutor(new CommandUnloadChunks()); this.getCommand("username").setExecutor(new CommandUsername(this)); - new PasteSpawn(this).runTaskTimer(this, 0, 200); - new Tick().runTaskTimer(this, 0, 1); + new PasteSpawn(this).runTaskTimerAsynchronously(this, 0, 10); + new TickAsync(this).runTaskTimerAsynchronously(this, 0, 1); this.getServer().getPluginManager().registerEvents(new Events(this), this); } @@ -390,9 +386,11 @@ public class Main extends JavaPlugin { String texture = response.get("value").getAsString(); String signature = response.get("signature").getAsString(); - PlayerProfile textureprofile = player.getPlayerProfile(); - textureprofile.setProperty(new ProfileProperty("textures", texture, signature)); - player.setPlayerProfile(textureprofile); + Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> { + PlayerProfile textureprofile = player.getPlayerProfile(); + textureprofile.setProperty(new ProfileProperty("textures", texture, signature)); + player.setPlayerProfile(textureprofile); + }); } uuidconnection.disconnect(); } @@ -401,19 +399,4 @@ public class Main extends JavaPlugin { exception.printStackTrace(); } } - - public void editMeta(ItemStack item) { - if (item.getType() == Material.LINGERING_POTION || - item.getType() == Material.POTION || - item.getType() == Material.SPLASH_POTION) { - PotionMeta potion = (PotionMeta) item.getItemMeta(); - potion.setColor(Color.WHITE); - } else if (item.getType() == Material.LEATHER_BOOTS || - item.getType() == Material.LEATHER_CHESTPLATE || - item.getType() == Material.LEATHER_HELMET || - item.getType() == Material.LEATHER_LEGGINGS) { - LeatherArmorMeta armor = (LeatherArmorMeta) item.getItemMeta(); - armor.setColor(Color.fromRGB(160,101,64)); - } - } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index f9f7637..dd80a9d 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: Extras main: pw.kaboom.extras.Main description: Plugin that adds extra functionality to the Kaboom.pw server. -depend: [WorldEdit] +depend: [FastAsyncWorldEdit] version: master commands: @@ -15,9 +15,6 @@ commands: destroyentities: description: Destroys all entities in every world permission: extras.destroyentities - discord: - description: Join the Kaboom.pw Discord server - permission: extras.discord enchantall: description: Adds every enchantment to a held item permission: extras.enchantall