diff --git a/CHANGELOG.md b/CHANGELOG.md index f1d91e4e2..462ee5fa2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,9 @@ #### Changes * Tree Growth Accelerators can now actually cause the Tree to fully grow (1.17+ only) * Slimefun now requires Java 16 +* "Connected / Not connected" messages for cargo nodes are now sent via the actionbar +* "/sf stats" can no longer be used if researching is disabled +* "/sf research" can no longer be used if researching is disabled #### Fixes * Fixed #3597 diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/GPSNetwork.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/GPSNetwork.java index f2b65f821..5bbabcefb 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/GPSNetwork.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/GPSNetwork.java @@ -8,6 +8,7 @@ import java.util.Set; import java.util.UUID; import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; @@ -28,6 +29,7 @@ import io.github.thebusybiscuit.slimefun4.api.geo.GEOResource; import io.github.thebusybiscuit.slimefun4.api.geo.ResourceManager; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; +import io.github.thebusybiscuit.slimefun4.core.services.localization.SlimefunLocalization; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.items.gps.GPSTransmitter; @@ -57,7 +59,9 @@ public class GPSNetwork { private final Map> transmitters = new HashMap<>(); private final TeleportationManager teleportation = new TeleportationManager(); + private final ResourceManager resourceManager; + private final SlimefunLocalization locale; /** * This constructs a new {@link GPSNetwork}. @@ -68,6 +72,7 @@ public class GPSNetwork { */ public GPSNetwork(@Nonnull Slimefun plugin) { resourceManager = new ResourceManager(plugin); + locale = Slimefun.getLocalization(); } /** @@ -141,24 +146,24 @@ public class GPSNetwork { * The {@link Player} */ public void openTransmitterControlPanel(@Nonnull Player p) { - ChestMenu menu = new ChestMenu(ChatColor.BLUE + Slimefun.getLocalization().getMessage(p, "machines.GPS_CONTROL_PANEL.title")); + ChestMenu menu = new ChestMenu(ChatColor.BLUE + locale.getMessage(p, "machines.GPS_CONTROL_PANEL.title")); for (int slot : border) { menu.addItem(slot, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler()); } menu.addItem(2, new CustomItemStack(SlimefunItems.GPS_TRANSMITTER, im -> { - im.setDisplayName(ChatColor.GRAY + Slimefun.getLocalization().getMessage(p, "machines.GPS_CONTROL_PANEL.transmitters")); + im.setDisplayName(ChatColor.GRAY + locale.getMessage(p, "machines.GPS_CONTROL_PANEL.transmitters")); im.setLore(null); })); menu.addMenuClickHandler(2, ChestMenuUtils.getEmptyClickHandler()); int complexity = getNetworkComplexity(p.getUniqueId()); - menu.addItem(4, new CustomItemStack(SlimefunItems.GPS_CONTROL_PANEL, "&7Network Info", "", "&8\u21E8 &7Status: " + (complexity > 0 ? "&2&lONLINE" : "&4&lOFFLINE"), "&8\u21E8 &7Complexity: &f" + complexity)); + menu.addItem(4, new CustomItemStack(SlimefunItems.GPS_CONTROL_PANEL, "&7Network Info", "", "&8\u21E8 &7Status: " + getStatusText(p, complexity), "&8\u21E8 &7Complexity: &f" + complexity)); menu.addMenuClickHandler(4, ChestMenuUtils.getEmptyClickHandler()); - menu.addItem(6, new CustomItemStack(HeadTexture.GLOBE_OVERWORLD.getAsItemStack(), "&7" + Slimefun.getLocalization().getMessage(p, "machines.GPS_CONTROL_PANEL.waypoints"), "", ChatColor.GRAY + "\u21E8 " + Slimefun.getLocalization().getMessage(p, "guide.tooltips.open-itemgroup"))); + menu.addItem(6, new CustomItemStack(HeadTexture.GLOBE_OVERWORLD.getAsItemStack(), "&7" + locale.getMessage(p, "machines.GPS_CONTROL_PANEL.waypoints"), "", ChatColor.GRAY + "\u21E8 " + locale.getMessage(p, "guide.tooltips.open-itemgroup"))); menu.addMenuClickHandler(6, (pl, slot, item, action) -> { openWaypointControlPanel(pl); return false; @@ -200,8 +205,8 @@ public class GPSNetwork { * * @return An icon for this waypoint */ - @Nonnull - public ItemStack getIcon(@Nonnull String name, @Nonnull Environment environment) { + @ParametersAreNonnullByDefault + public @Nonnull ItemStack getIcon(String name, Environment environment) { if (name.startsWith("player:death ")) { return HeadTexture.DEATHPOINT.getAsItemStack(); } else if (environment == Environment.NETHER) { @@ -213,15 +218,24 @@ public class GPSNetwork { } } + @ParametersAreNonnullByDefault + private @Nonnull String getStatusText(Player player, int complexity) { + if (complexity > 0) { + return "&2&l" + locale.getMessage(player, "gps.status-online"); + } else { + return "&4&l" + locale.getMessage(player, "gps.status-offline"); + } + } + public void openWaypointControlPanel(@Nonnull Player p) { PlayerProfile.get(p, profile -> { - ChestMenu menu = new ChestMenu(ChatColor.BLUE + Slimefun.getLocalization().getMessage(p, "machines.GPS_CONTROL_PANEL.title")); + ChestMenu menu = new ChestMenu(ChatColor.BLUE + locale.getMessage(p, "machines.GPS_CONTROL_PANEL.title")); for (int slot : border) { menu.addItem(slot, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler()); } - menu.addItem(2, new CustomItemStack(SlimefunItems.GPS_TRANSMITTER, "&7" + Slimefun.getLocalization().getMessage(p, "machines.GPS_CONTROL_PANEL.transmitters"), "", ChatColor.GRAY + "\u21E8 " + Slimefun.getLocalization().getMessage(p, "guide.tooltips.open-itemgroup"))); + menu.addItem(2, new CustomItemStack(SlimefunItems.GPS_TRANSMITTER, "&7" + locale.getMessage(p, "machines.GPS_CONTROL_PANEL.transmitters"), "", ChatColor.GRAY + "\u21E8 " + locale.getMessage(p, "guide.tooltips.open-itemgroup"))); menu.addMenuClickHandler(2, (pl, slot, item, action) -> { openTransmitterControlPanel(pl); return false; @@ -231,7 +245,7 @@ public class GPSNetwork { menu.addItem(4, new CustomItemStack(SlimefunItems.GPS_CONTROL_PANEL, "&7Network Info", "", "&8\u21E8 &7Status: " + (complexity > 0 ? "&2&lONLINE" : "&4&lOFFLINE"), "&8\u21E8 &7Complexity: &f" + complexity)); menu.addMenuClickHandler(4, ChestMenuUtils.getEmptyClickHandler()); - menu.addItem(6, new CustomItemStack(HeadTexture.GLOBE_OVERWORLD.getAsItemStack(), "&7" + Slimefun.getLocalization().getMessage(p, "machines.GPS_CONTROL_PANEL.waypoints"))); + menu.addItem(6, new CustomItemStack(HeadTexture.GLOBE_OVERWORLD.getAsItemStack(), "&7" + locale.getMessage(p, "machines.GPS_CONTROL_PANEL.waypoints"))); menu.addMenuClickHandler(6, ChestMenuUtils.getEmptyClickHandler()); int index = 0; @@ -274,11 +288,11 @@ public class GPSNetwork { PlayerProfile.get(p, profile -> { if ((profile.getWaypoints().size() + 2) > inventory.length) { - Slimefun.getLocalization().sendMessage(p, "gps.waypoint.max", true); + locale.sendMessage(p, "gps.waypoint.max", true); return; } - Slimefun.getLocalization().sendMessage(p, "gps.waypoint.new", true); + locale.sendMessage(p, "gps.waypoint.new", true); p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 0.5F, 1F); ChatInput.waitForPlayer(Slimefun.instance(), p, message -> addWaypoint(p, message, l)); @@ -302,7 +316,7 @@ public class GPSNetwork { PlayerProfile.get(p, profile -> { if ((profile.getWaypoints().size() + 2) > inventory.length) { - Slimefun.getLocalization().sendMessage(p, "gps.waypoint.max", true); + locale.sendMessage(p, "gps.waypoint.max", true); return; } @@ -315,7 +329,7 @@ public class GPSNetwork { for (Waypoint wp : profile.getWaypoints()) { if (wp.getId().equals(id)) { - Slimefun.getLocalization().sendMessage(p, "gps.waypoint.duplicate", true, msg -> msg.replace("%waypoint%", event.getName())); + locale.sendMessage(p, "gps.waypoint.duplicate", true, msg -> msg.replace("%waypoint%", event.getName())); return; } } @@ -323,7 +337,7 @@ public class GPSNetwork { profile.addWaypoint(new Waypoint(profile, id, event.getLocation(), event.getName())); p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 1F, 1F); - Slimefun.getLocalization().sendMessage(p, "gps.waypoint.added", true); + locale.sendMessage(p, "gps.waypoint.added", true); } }); }); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ResearchCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ResearchCommand.java index caf6f6d25..8b81c87b5 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ResearchCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ResearchCommand.java @@ -33,6 +33,12 @@ class ResearchCommand extends SubCommand { @Override public void onExecute(CommandSender sender, String[] args) { + // Check if researching is even enabled + if (!Slimefun.getRegistry().isResearchingEnabled()) { + Slimefun.getLocalization().sendMessage(sender, "messages.researching-is-disabled"); + return; + } + if (args.length == 3) { if (!(sender instanceof Player) || sender.hasPermission("slimefun.cheat.researches")) { Optional player = PlayerList.findByName(args[1]); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/StatsCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/StatsCommand.java index 1ea7a60f6..cb9069eb6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/StatsCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/StatsCommand.java @@ -23,6 +23,12 @@ class StatsCommand extends SubCommand { @Override public void onExecute(CommandSender sender, String[] args) { + // Check if researching is even enabled + if (!Slimefun.getRegistry().isResearchingEnabled()) { + Slimefun.getLocalization().sendMessage(sender, "messages.researching-is-disabled"); + return; + } + if (args.length > 1) { if (sender.hasPermission("slimefun.stats.others") || sender instanceof ConsoleCommandSender) { Optional player = PlayerList.findByName(args[1]); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/FireworksOption.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/FireworksOption.java index 85fa76612..07b757018 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/FireworksOption.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/FireworksOption.java @@ -10,6 +10,7 @@ import org.bukkit.inventory.ItemStack; import io.github.bakedlibs.dough.data.persistent.PersistentDataAPI; import io.github.bakedlibs.dough.items.CustomItemStack; import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon; +import io.github.thebusybiscuit.slimefun4.core.SlimefunRegistry; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; class FireworksOption implements SlimefunGuideOption { @@ -26,7 +27,9 @@ class FireworksOption implements SlimefunGuideOption { @Override public Optional getDisplayItem(Player p, ItemStack guide) { - if (Slimefun.getRegistry().isResearchFireworkEnabled()) { + SlimefunRegistry registry = Slimefun.getRegistry(); + + if (registry.isResearchingEnabled() && registry.isResearchFireworkEnabled()) { boolean enabled = getSelectedOption(p, guide).orElse(true); ItemStack item = new CustomItemStack(Material.FIREWORK_ROCKET, "&bFireworks: &" + (enabled ? "aYes" : "4No"), "", "&7You can now toggle whether you", "&7will be presented with a big firework", "&7upon researching an item.", "", "&7\u21E8 &eClick to " + (enabled ? "disable" : "enable") + " your fireworks"); return Optional.of(item); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/LearningAnimationOption.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/LearningAnimationOption.java index 11040f2c3..5d694c896 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/LearningAnimationOption.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/LearningAnimationOption.java @@ -13,6 +13,7 @@ import org.bukkit.inventory.ItemStack; import io.github.bakedlibs.dough.data.persistent.PersistentDataAPI; import io.github.bakedlibs.dough.items.CustomItemStack; import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon; +import io.github.thebusybiscuit.slimefun4.core.SlimefunRegistry; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; /** @@ -39,7 +40,9 @@ class LearningAnimationOption implements SlimefunGuideOption { @Nonnull @Override public Optional getDisplayItem(@Nonnull Player p, @Nonnull ItemStack guide) { - if (Slimefun.getRegistry().isLearningAnimationDisabled()) { + SlimefunRegistry registry = Slimefun.getRegistry(); + + if (!registry.isResearchingEnabled() || registry.isLearningAnimationDisabled()) { return Optional.empty(); } else { boolean enabled = getSelectedOption(p, guide).orElse(true); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/CargoConnectorNode.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/CargoConnectorNode.java index 52db1b424..45c795bb7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/CargoConnectorNode.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/CargoConnectorNode.java @@ -7,12 +7,12 @@ import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import io.github.bakedlibs.dough.common.ChatColors; import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler; import io.github.thebusybiscuit.slimefun4.core.networks.cargo.CargoNet; +import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; /** @@ -32,9 +32,8 @@ public class CargoConnectorNode extends SimpleSlimefunItem { super(itemGroup, item, recipeType, recipe, recipeOutput); } - @Nonnull @Override - public BlockUseHandler getItemHandler() { + public @Nonnull BlockUseHandler getItemHandler() { return e -> { if (!e.getClickedBlock().isPresent()) { return; @@ -44,9 +43,9 @@ public class CargoConnectorNode extends SimpleSlimefunItem { Block b = e.getClickedBlock().get(); if (CargoNet.getNetworkFromLocation(b.getLocation()) != null) { - p.sendMessage(ChatColors.color("&7Connected: " + "&2\u2714")); + Slimefun.getLocalization().sendActionbarMessage(p, "machines.CARGO_NODES.connected", false); } else { - p.sendMessage(ChatColors.color("&7Connected: " + "&4\u2718")); + Slimefun.getLocalization().sendActionbarMessage(p, "machines.CARGO_NODES.not-connected", false); } }; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/elevator/ElevatorFloor.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/elevator/ElevatorFloor.java index 24e6f2b9c..be9245e51 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/elevator/ElevatorFloor.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/elevator/ElevatorFloor.java @@ -54,8 +54,7 @@ class ElevatorFloor { * * @return The name of this floor */ - @Nonnull - public String getName() { + public @Nonnull String getName() { return name; } @@ -64,8 +63,7 @@ class ElevatorFloor { * * @return The {@link Location} of this floor */ - @Nonnull - public Location getLocation() { + public @Nonnull Location getLocation() { return location; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/elevator/ElevatorPlate.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/elevator/ElevatorPlate.java index a3d41456c..70e33e049 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/elevator/ElevatorPlate.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/elevator/ElevatorPlate.java @@ -68,8 +68,7 @@ public class ElevatorPlate extends SimpleSlimefunItem { addItemHandler(onPlace()); } - @Nonnull - private BlockPlaceHandler onPlace() { + private @Nonnull BlockPlaceHandler onPlace() { return new BlockPlaceHandler(false) { @Override @@ -81,9 +80,8 @@ public class ElevatorPlate extends SimpleSlimefunItem { }; } - @Nonnull @Override - public BlockUseHandler getItemHandler() { + public @Nonnull BlockUseHandler getItemHandler() { return e -> { Block b = e.getClickedBlock().get(); @@ -93,8 +91,7 @@ public class ElevatorPlate extends SimpleSlimefunItem { }; } - @Nonnull - public List getFloors(@Nonnull Block b) { + public @Nonnull List getFloors(@Nonnull Block b) { LinkedList floors = new LinkedList<>(); int index = 0; @@ -209,7 +206,7 @@ public class ElevatorPlate extends SimpleSlimefunItem { @ParametersAreNonnullByDefault public void openEditor(Player p, Block b) { - ChestMenu menu = new ChestMenu("Elevator Settings"); + ChestMenu menu = new ChestMenu(Slimefun.getLocalization().getMessage(p, "machines.ELEVATOR.editor-title")); menu.addItem(4, new CustomItemStack(Material.NAME_TAG, "&7Floor Name &e(Click to edit)", "", ChatColor.WHITE + ChatColors.color(BlockStorage.getLocationInfo(b.getLocation(), DATA_KEY)))); menu.addMenuClickHandler(4, (pl, slot, item, action) -> { diff --git a/src/main/resources/languages/en/messages.yml b/src/main/resources/languages/en/messages.yml index 0f4f4ffb6..c678a28c2 100644 --- a/src/main/resources/languages/en/messages.yml +++ b/src/main/resources/languages/en/messages.yml @@ -168,6 +168,7 @@ messages: piglin-barter: '&4You cannot barter with piglins using Slimefun items' bee-suit-slow-fall: '&eYour Bee Wings will help you to get back to the ground safe and slow' deprecated-item: '&4This item has been deprecated and will be removed from Slimefun soon.' + researching-is-disabled: '&cResearching has been disabled on this server. Everything is unlocked by default!' multi-tool: mode-change: '&b%device% mode changed to: &9%mode%' @@ -296,8 +297,9 @@ machines: pick-a-floor: '&3- Pick a floor -' current-floor: '&eThis is the floor you are currently on:' click-to-teleport: '&eClick &7to teleport to this floor:' - enter-name: '&7Please enter your desired floor name into your Chat. &r(Color Codes are supported!)' - named: '&2Successfully named this floor: &r%floor%' + enter-name: '&7Please enter your desired floor name into your Chat. &f(Color Codes are supported!)' + named: '&2Successfully named this floor: &f%floor%' + editor-title: 'Configure this elevator' TELEPORTER: teleporting: '&3Teleporting...' @@ -317,6 +319,8 @@ machines: CARGO_NODES: must-be-placed: '&4Must be placed onto a chest or machine!' + connected: '&2Connected!' + not-connected: '&4Not connected!' INDUSTRIAL_MINER: no-fuel: '&cYour Industrial Miner ran out of fuel! Put your fuel into the chest above.' @@ -356,6 +360,8 @@ cauldron: gps: deathpoint: '&4Deathpoint &7%date%' + status-online: 'ONLINE' + status-offline: 'OFFLINE' waypoint: new: '&ePlease type in a name for your new waypoint in the chat. &7(Color Codes supported!)' added: '&aSuccessfully added a new waypoint'