From 9421eaf82055a815368adf54cdbf34d91b401f25 Mon Sep 17 00:00:00 2001 From: SvGaming Date: Thu, 16 Jan 2025 23:01:06 +0100 Subject: [PATCH] readd multiworld weather command --- .../beta/fundamentals/Fundamentals.java | 1 + .../fundamentals/commands/CommandWeather.java | 71 +++++++++++++++++++ .../settings/FundamentalsLanguage.java | 3 + .../src/main/resources/plugin.yml | 3 + 4 files changed, 78 insertions(+) create mode 100644 FundamentalsCore/src/main/java/com/johnymuffin/beta/fundamentals/commands/CommandWeather.java diff --git a/FundamentalsCore/src/main/java/com/johnymuffin/beta/fundamentals/Fundamentals.java b/FundamentalsCore/src/main/java/com/johnymuffin/beta/fundamentals/Fundamentals.java index 7673595..e78da98 100644 --- a/FundamentalsCore/src/main/java/com/johnymuffin/beta/fundamentals/Fundamentals.java +++ b/FundamentalsCore/src/main/java/com/johnymuffin/beta/fundamentals/Fundamentals.java @@ -160,6 +160,7 @@ public void onEnable() { // Bukkit.getPluginCommand("time").setExecutor(new CommandTime(plugin)); // Bukkit.getPluginCommand("ptime").setExecutor(new CommandPTime(plugin)); Bukkit.getPluginCommand("vanish").setExecutor(new CommandVanish(plugin)); + Bukkit.getPluginCommand("weather").setExecutor(new CommandWeather()); Bukkit.getPluginCommand("bank").setExecutor(new CommandBank(plugin)); Bukkit.getPluginCommand("balancetop").setExecutor(new CommandBalanceTop(plugin)); Bukkit.getPluginCommand("fakequit").setExecutor(new CommandFakeQuit(plugin)); diff --git a/FundamentalsCore/src/main/java/com/johnymuffin/beta/fundamentals/commands/CommandWeather.java b/FundamentalsCore/src/main/java/com/johnymuffin/beta/fundamentals/commands/CommandWeather.java new file mode 100644 index 0000000..9b0c35a --- /dev/null +++ b/FundamentalsCore/src/main/java/com/johnymuffin/beta/fundamentals/commands/CommandWeather.java @@ -0,0 +1,71 @@ +package com.johnymuffin.beta.fundamentals.commands; +import com.johnymuffin.beta.fundamentals.settings.FundamentalsLanguage; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.World; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import java.util.ArrayList; +import java.util.List; +public class CommandWeather implements CommandExecutor { + @Override + public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { + Player player; + List worlds = new ArrayList<>(); + String worldarg; + if (!(commandSender.hasPermission("fundamentals.weather") || commandSender.isOp())) { + commandSender.sendMessage(FundamentalsLanguage.getInstance().getMessage("no_permission")); + return true; + } + if (strings.length < 1) { + commandSender.sendMessage(FundamentalsLanguage.getInstance().getMessage("weather_invalid_usage")); + return true; + } + if (strings.length < 2) { + player = (Player) commandSender; + worlds.add(0, player.getWorld()); + } + else { + worldarg = strings[1]; + if (worldarg.equals("all")) { + worlds = Bukkit.getWorlds(); + } + else { + worlds.add(0, Bukkit.getWorld(worldarg)); + } + } + String arg = strings[0].toLowerCase(); + for (World world : worlds) { + switch (arg) { + case "clear": + case "sun": + if (world.hasStorm()) { + world.setThundering(false); + world.setWeatherDuration(5); + } + break; + case "storm": + if (!world.hasStorm()) { + world.setWeatherDuration(5); + } + world.setThundering(true); + break; + case "rain": + if (!world.hasStorm()) { + world.setWeatherDuration(5); + } + world.setThundering(false); + break; + default: + commandSender.sendMessage(FundamentalsLanguage.getInstance().getMessage("weather_invalid_usage")); + return true; + } + commandSender.sendMessage(FundamentalsLanguage.getInstance().getMessage("weather_set_weather") + .replace("%var1%", arg) + .replace("%var2%", world.getName()) + ); + } + return true; + } +} \ No newline at end of file diff --git a/FundamentalsCore/src/main/java/com/johnymuffin/beta/fundamentals/settings/FundamentalsLanguage.java b/FundamentalsCore/src/main/java/com/johnymuffin/beta/fundamentals/settings/FundamentalsLanguage.java index e0895eb..138a9f4 100644 --- a/FundamentalsCore/src/main/java/com/johnymuffin/beta/fundamentals/settings/FundamentalsLanguage.java +++ b/FundamentalsCore/src/main/java/com/johnymuffin/beta/fundamentals/settings/FundamentalsLanguage.java @@ -108,6 +108,9 @@ private void loadDefaults() { map.put("vanish_successful_other_disabled", "&4Disabled vanish for another player."); map.put("vanish_disable", "&4Vanish Disabled."); map.put("vanish_enable", "&7Vanish Enabled."); + //Weather + map.put("weather_invalid_usage", "&6Invalid usage: &a/weather [worldname|all]"); + map.put("weather_set_weather", "&7Weather has been set to %var1% in %var2%"); //Clear Inventory map.put("clearinventory_notice", "&9Your inventory has been cleared"); map.put("clearinventory_successfully", "&9Inventory cleared successfully"); diff --git a/FundamentalsCore/src/main/resources/plugin.yml b/FundamentalsCore/src/main/resources/plugin.yml index 0c45fbe..39801cf 100644 --- a/FundamentalsCore/src/main/resources/plugin.yml +++ b/FundamentalsCore/src/main/resources/plugin.yml @@ -67,6 +67,9 @@ commands: vanish: description: Command to vanish player. usage: / + weather: + description: Command to change the weather in a world. + usage: / [worldname|all] bank: description: Command to do bank stuff. usage: /