From 38265afa4949c7dce63b19acb193b29bf38d5663 Mon Sep 17 00:00:00 2001 From: mathias Date: Tue, 16 Jul 2019 15:56:19 +0300 Subject: [PATCH] Fixes --- src/main/java/pw/kaboom/extras/Commands.java | 54 +++++++++++++++++ src/main/java/pw/kaboom/extras/Events.java | 62 +++++++++++--------- src/main/java/pw/kaboom/extras/Main.java | 3 + src/main/resources/plugin.yml | 6 ++ 4 files changed, 98 insertions(+), 27 deletions(-) diff --git a/src/main/java/pw/kaboom/extras/Commands.java b/src/main/java/pw/kaboom/extras/Commands.java index 36745cb..c382e56 100644 --- a/src/main/java/pw/kaboom/extras/Commands.java +++ b/src/main/java/pw/kaboom/extras/Commands.java @@ -36,6 +36,9 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.util.BlockIterator; +import org.bukkit.util.Vector; + class CommandClearChat implements CommandExecutor { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { @@ -178,6 +181,36 @@ class CommandPrefix implements CommandExecutor { } } +class CommandPumpkin implements CommandExecutor { + private void placePumpkin(Player player) { + player.getInventory().setHelmet(new ItemStack(Material.PUMPKIN)); + } + + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + 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()) { + placePumpkin(p); + } + player.sendMessage("Everyone is now a pumpkin"); + } else { + Player target = Bukkit.getPlayer(args[0]); + if (target != null) { + placePumpkin(target); + player.sendMessage("Player \"" + target.getName() + "\" is now a pumpkin"); + } else { + player.sendMessage("Player \"" + target.getName() + "\" not found"); + } + } + } + return true; + } +} + class CommandSkin implements CommandExecutor { Main main; CommandSkin(Main main) { @@ -274,6 +307,27 @@ 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; + + 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); + } + return true; + } +} + class CommandTellraw implements CommandExecutor { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { Player player = (Player) sender; diff --git a/src/main/java/pw/kaboom/extras/Events.java b/src/main/java/pw/kaboom/extras/Events.java index 8250d4c..83ae5de 100644 --- a/src/main/java/pw/kaboom/extras/Events.java +++ b/src/main/java/pw/kaboom/extras/Events.java @@ -150,6 +150,29 @@ class TickAsync extends BukkitRunnable { } } +class TileEntityCheckAsync extends BukkitRunnable { + Main main; + TileEntityCheckAsync(Main main) { + this.main = main; + } + + public void run() { + for (final World world : Bukkit.getServer().getWorlds()) { + for (final Chunk chunk : world.getLoadedChunks()) { + try { + chunk.getTileEntities(); + } catch (Exception e) { + Bukkit.getScheduler().runTask(main, new Runnable() { + public void run() { + world.regenerateChunk(chunk.getX(), chunk.getZ()); + } + }); + } + } + } + } +} + /*class CommandSenderOutput implements CommandSender { String lastOutput; @Override @@ -601,25 +624,14 @@ class Events implements Listener { event.setMessage(stringBuilder.toString()); } - } else if (arr[0].toLowerCase().equals("/minecraft:blockdata") || - arr[0].toLowerCase().equals("/minecraft:clone") || - arr[0].toLowerCase().equals("/minecraft:fill") || - arr[0].toLowerCase().equals("/minecraft:setblock") || - arr[0].toLowerCase().equals("/blockdata") || - arr[0].toLowerCase().equals("/clone") || - arr[0].toLowerCase().equals("/fill") || - arr[0].toLowerCase().equals("/setblock")) { - if (event.getMessage().contains("translation.test.invalid")) { - event.setCancelled(true); - } } } @EventHandler void onPlayerDeath(PlayerDeathEvent event) { Player player = event.getEntity(); - final AttributeInstance maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH); + boolean maxHealthLow = false; maxHealth.setBaseValue(20); try { @@ -628,15 +640,22 @@ class Events implements Listener { maxHealth.setBaseValue(Double.POSITIVE_INFINITY); player.setHealth(20); maxHealth.setBaseValue(20); + maxHealthLow = true; } player.setFoodLevel(20); player.setFireTicks(0); player.setRemainingAir(player.getMaximumAir()); player.getActivePotionEffects().clear(); + event.setCancelled(true); - if (player.getLastDamageCause() != null && + for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { + onlinePlayer.sendMessage(event.getDeathMessage()); + } + + if ((player.getLastDamageCause() != null && player.getLastDamageCause().getCause() == DamageCause.SUICIDE && - player.getLastDamageCause().getDamage() == Float.MAX_VALUE) { + player.getLastDamageCause().getDamage() == Float.MAX_VALUE) || + maxHealthLow == true) { return; } @@ -810,17 +829,6 @@ class Events implements Listener { event.setCommand(stringBuilder.toString()); } - } else if (arr[0].toLowerCase().equals("minecraft:blockdata") || - arr[0].toLowerCase().equals("minecraft:clone") || - arr[0].toLowerCase().equals("minecraft:fill") || - arr[0].toLowerCase().equals("minecraft:setblock") || - arr[0].toLowerCase().equals("blockdata") || - arr[0].toLowerCase().equals("clone") || - arr[0].toLowerCase().equals("fill") || - arr[0].toLowerCase().equals("setblock")) { - if (event.getCommand().contains("translation.test.invalid")) { - event.setCancelled(true); - } } } @@ -829,9 +837,9 @@ class Events implements Listener { if (event.getClient().getProtocolVersion() != -1) { event.setProtocolVersion(event.getClient().getProtocolVersion()); } else { - event.setProtocolVersion(485); + event.setProtocolVersion(490); } - event.setVersion("1.14.2"); + event.setVersion("1.14.3"); } @EventHandler diff --git a/src/main/java/pw/kaboom/extras/Main.java b/src/main/java/pw/kaboom/extras/Main.java index 30691de..52b217a 100644 --- a/src/main/java/pw/kaboom/extras/Main.java +++ b/src/main/java/pw/kaboom/extras/Main.java @@ -443,14 +443,17 @@ public class Main extends JavaPlugin { this.getCommand("enchantall").setExecutor(new CommandEnchantAll()); this.getCommand("jumpscare").setExecutor(new CommandJumpscare()); this.getCommand("prefix").setExecutor(new CommandPrefix(this)); + this.getCommand("pumpkin").setExecutor(new CommandPumpkin()); this.getCommand("skin").setExecutor(new CommandSkin(this)); this.getCommand("spawn").setExecutor(new CommandSpawn()); + this.getCommand("spidey").setExecutor(new CommandSpidey()); this.getCommand("tellraw").setExecutor(new CommandTellraw()); 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); this.getServer().getPluginManager().registerEvents(new Events(this), this); } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 678e973..de981b3 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -25,12 +25,18 @@ commands: aliases: [rank, tag] description: Changes your tag permission: extras.prefix + pumpkin: + description: Places a pumpkin on a player's head + permission: extras.pumpkin skin: description: Changes your skin permission: extras.skin spawn: description: Teleports you to spawn permission: extras.spawn + spidey: + description: Annoying little spider... + permission: extras.spidey tellraw: description: Broadcasts raw text to the server permission: extras.tellraw