From 78f105fd2b300d3be4f6ac5d7e71d108ff7741a1 Mon Sep 17 00:00:00 2001 From: mathiascode Date: Wed, 26 Feb 2020 22:20:13 +0200 Subject: [PATCH] Handle tridents --- src/main/java/pw/kaboom/extras/Main.java | 1 + .../commands/CommandBroadcastVanilla.java | 18 ++++++++ .../modules/entity/EntityKnockback.java | 16 ++++++++ .../modules/player/PlayerConnection.java | 41 +++++++++++++++---- .../extras/modules/player/PlayerInteract.java | 14 +++++++ .../extras/modules/server/ServerCommand.java | 36 ---------------- src/main/resources/plugin.yml | 4 ++ 7 files changed, 86 insertions(+), 44 deletions(-) create mode 100644 src/main/java/pw/kaboom/extras/commands/CommandBroadcastVanilla.java diff --git a/src/main/java/pw/kaboom/extras/Main.java b/src/main/java/pw/kaboom/extras/Main.java index ae2fb0b..eef91e3 100644 --- a/src/main/java/pw/kaboom/extras/Main.java +++ b/src/main/java/pw/kaboom/extras/Main.java @@ -417,6 +417,7 @@ public final class Main extends JavaPlugin { @Override public void onEnable() { /* Commands */ + this.getCommand("broadcastvanilla").setExecutor(new CommandBroadcastVanilla()); this.getCommand("clearchat").setExecutor(new CommandClearChat()); this.getCommand("console").setExecutor(new CommandConsole()); this.getCommand("destroyentities").setExecutor(new CommandDestroyEntities()); diff --git a/src/main/java/pw/kaboom/extras/commands/CommandBroadcastVanilla.java b/src/main/java/pw/kaboom/extras/commands/CommandBroadcastVanilla.java new file mode 100644 index 0000000..5e5b8aa --- /dev/null +++ b/src/main/java/pw/kaboom/extras/commands/CommandBroadcastVanilla.java @@ -0,0 +1,18 @@ +package pw.kaboom.extras.commands; + +import org.bukkit.ChatColor; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; + +public final class CommandBroadcastVanilla implements CommandExecutor { + public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { + if (args.length == 0) { + sender.sendMessage(ChatColor.RED + "Usage: /" + label + " "); + } else { + Command.broadcastCommandMessage(sender, ChatColor.translateAlternateColorCodes('&', String.join(" ", args))); + } + return true; + } +} diff --git a/src/main/java/pw/kaboom/extras/modules/entity/EntityKnockback.java b/src/main/java/pw/kaboom/extras/modules/entity/EntityKnockback.java index b562fbe..dde77b3 100644 --- a/src/main/java/pw/kaboom/extras/modules/entity/EntityKnockback.java +++ b/src/main/java/pw/kaboom/extras/modules/entity/EntityKnockback.java @@ -1,7 +1,10 @@ package pw.kaboom.extras.modules.entity; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.entity.ProjectileHitEvent; import com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent; @@ -16,4 +19,17 @@ public final class EntityKnockback implements Listener { ); } } + + @EventHandler + void onProjectileHit(final ProjectileHitEvent event) { + if (event.getHitEntity() != null && + EntityType.ARROW.equals(event.getEntityType())) { + final Arrow arrow = (Arrow) event.getEntity(); + final int knockbackLimit = 60; + + if (arrow.getKnockbackStrength() > knockbackLimit) { + arrow.setKnockbackStrength(knockbackLimit); + } + } + } } diff --git a/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java b/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java index d5c6400..027142b 100644 --- a/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java +++ b/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java @@ -1,26 +1,34 @@ package pw.kaboom.extras.modules.player; -import com.destroystokyo.paper.event.profile.PreLookupProfileEvent; -import com.destroystokyo.paper.profile.PlayerProfile; -import com.google.common.base.Charsets; +import java.io.File; +import java.io.IOException; +import java.util.UUID; + import org.bukkit.Bukkit; +import org.bukkit.GameRule; +import org.bukkit.World; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.player.*; +import org.bukkit.event.player.AsyncPlayerPreLoginEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerKickEvent; +import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerLoginEvent.Result; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerStatisticIncrementEvent; import org.bukkit.plugin.java.JavaPlugin; +import com.destroystokyo.paper.event.profile.PreLookupProfileEvent; +import com.destroystokyo.paper.profile.PlayerProfile; +import com.google.common.base.Charsets; + import pw.kaboom.extras.Main; import pw.kaboom.extras.helpers.SkinDownloader; -import java.io.File; -import java.io.IOException; -import java.util.UUID; - public final class PlayerConnection implements Listener { private long connectionMillis; @@ -52,6 +60,12 @@ public final class PlayerConnection implements Listener { event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, "A player with that username is already logged in"); } } + + final Integer spawnRadius = Bukkit.getWorld("world").getGameRuleValue(GameRule.SPAWN_RADIUS); + + if (spawnRadius > 100) { + Bukkit.getWorld("world").setGameRule(GameRule.SPAWN_RADIUS, 100); + } try { final PlayerProfile profile = event.getPlayerProfile(); @@ -85,6 +99,17 @@ public final class PlayerConnection implements Listener { @EventHandler void onPlayerCommandSend2(final PlayerStatisticIncrementEvent event) { + final World world = event.getPlayer().getWorld(); + final Integer randomTickSpeed = world.getGameRuleValue(GameRule.RANDOM_TICK_SPEED); + + if (randomTickSpeed > 6) { + world.setGameRule(GameRule.RANDOM_TICK_SPEED, 6); + } + + if (!world.isAutoSave()) { + world.setAutoSave(true); + } + //if (event.getPlayer().isOnline()) { event.setCancelled(true); //} diff --git a/src/main/java/pw/kaboom/extras/modules/player/PlayerInteract.java b/src/main/java/pw/kaboom/extras/modules/player/PlayerInteract.java index 6eb560b..9b3dc37 100644 --- a/src/main/java/pw/kaboom/extras/modules/player/PlayerInteract.java +++ b/src/main/java/pw/kaboom/extras/modules/player/PlayerInteract.java @@ -3,10 +3,13 @@ package pw.kaboom.extras.modules.player; import java.util.HashMap; import java.util.UUID; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; public final class PlayerInteract implements Listener { static HashMap interactMillisList = new HashMap(); @@ -33,5 +36,16 @@ public final class PlayerInteract implements Listener { } interactMillisList.put(playerUuid, System.currentTimeMillis()); + + final ItemStack item = event.getItem(); + + if (item != null && + Material.TRIDENT.equals(item.getType())) { + final int riptideLimit = 20; + + if (item.getEnchantmentLevel(Enchantment.RIPTIDE) > riptideLimit) { + item.addUnsafeEnchantment(Enchantment.RIPTIDE, riptideLimit); + } + } } } diff --git a/src/main/java/pw/kaboom/extras/modules/server/ServerCommand.java b/src/main/java/pw/kaboom/extras/modules/server/ServerCommand.java index e1a8a84..ddea1ff 100644 --- a/src/main/java/pw/kaboom/extras/modules/server/ServerCommand.java +++ b/src/main/java/pw/kaboom/extras/modules/server/ServerCommand.java @@ -35,7 +35,6 @@ public final class ServerCommand implements Listener { || "clone".equalsIgnoreCase(arr[i + 1]) || "fill".equalsIgnoreCase(arr[i + 1]) || "particle".equalsIgnoreCase(arr[i + 1]) - || "save-off".equalsIgnoreCase(arr[i + 1]) || "say".equalsIgnoreCase(arr[i + 1]) || "spreadplayers".equalsIgnoreCase(arr[i + 1]) || "stop".equalsIgnoreCase(arr[i + 1]) @@ -79,9 +78,6 @@ public final class ServerCommand implements Listener { if ("randomTickSpeed".equalsIgnoreCase(arr[1]) && Double.parseDouble(arr[2]) > 6) { return command.replaceFirst(arr[2], "6"); - } else if ("spawnRadius".equalsIgnoreCase(arr[1]) - && Double.parseDouble(arr[2]) > 100) { - return command.replaceFirst(arr[2], "100"); } } break; @@ -100,32 +96,6 @@ public final class ServerCommand implements Listener { return String.join(" ", arr); } break; - case "/bukkit:reload": - case "/bukkit:rl": - case "/reload": - case "/rl": - if (sender.hasPermission("bukkit.command.reload") - && arr.length >= 2 - && "confirm".equalsIgnoreCase(arr[1])) { - Command.broadcastCommandMessage(sender, ChatColor.RED + "Please note that this command is not supported and may cause issues when using some plugins."); - Command.broadcastCommandMessage(sender, ChatColor.RED + "If you encounter any issues please use the /stop command to restart your server."); - Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Reload complete."); - return "cancel"; - } - break; - case "/spigot:restart": - case "/restart": - if (sender.hasPermission("bukkit.command.restart")) { - return "cancel"; - } - break; - case "/minecraft:save-off": - case "/save-off": - if (sender.hasPermission("minecraft.command.save.disable")) { - Command.broadcastCommandMessage(sender, "Automatic saving is now disabled"); - return "cancel"; - } - break; case "/minecraft:spreadplayers": case "/spreadplayers": if (arr.length >= 5) { @@ -142,12 +112,6 @@ public final class ServerCommand implements Listener { return String.join(" ", arr); } break; - case "/minecraft:stop": - case "/stop": - if (sender.hasPermission("minecraft.command.stop")) { - Command.broadcastCommandMessage(sender, "Stopping the server"); - return "cancel"; - } default: break; } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 02128f7..cb07132 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -10,6 +10,10 @@ commands: aliases: [bcraw, tellraw] description: Broadcasts raw text to the server permission: extras.broadcastraw + broadcastvanilla: + aliases: [bcv] + description: Broadcasts text in vanilla style + permission: extras.broadcastvanilla clearchat: aliases: cc description: Clears messages from the chat