diff --git a/addon/togglepersist/src/main/java/com/github/jikoo/openinv/togglepersist/TogglePersist.java b/addon/togglepersist/src/main/java/com/github/jikoo/openinv/togglepersist/TogglePersist.java index 71f0d883..070ff081 100644 --- a/addon/togglepersist/src/main/java/com/github/jikoo/openinv/togglepersist/TogglePersist.java +++ b/addon/togglepersist/src/main/java/com/github/jikoo/openinv/togglepersist/TogglePersist.java @@ -3,7 +3,7 @@ import com.google.errorprone.annotations.Keep; import com.lishid.openinv.event.PlayerToggledEvent; import com.lishid.openinv.util.setting.PlayerToggle; -import com.lishid.openinv.util.setting.Toggles; +import com.lishid.openinv.util.setting.PlayerToggles; import org.bukkit.configuration.Configuration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.event.EventHandler; @@ -42,7 +42,7 @@ public void onEnable() { // For each toggle, enable loaded players. for (String toggleName : loaded.getKeys(false)) { - PlayerToggle toggle = Toggles.get(toggleName); + PlayerToggle toggle = PlayerToggles.get(toggleName); // Ensure toggle exists. if (toggle == null) { continue; @@ -120,7 +120,7 @@ private void onPlayerJoin(@NotNull PlayerJoinEvent event) { } for (String toggleName : toggleNames) { - PlayerToggle toggle = Toggles.get(toggleName); + PlayerToggle toggle = PlayerToggles.get(toggleName); if (toggle != null) { toggle.set(playerId, true); } diff --git a/api/src/main/java/com/lishid/openinv/util/setting/Toggles.java b/api/src/main/java/com/lishid/openinv/util/setting/PlayerToggles.java similarity index 83% rename from api/src/main/java/com/lishid/openinv/util/setting/Toggles.java rename to api/src/main/java/com/lishid/openinv/util/setting/PlayerToggles.java index cd6b53df..c3edbbf2 100644 --- a/api/src/main/java/com/lishid/openinv/util/setting/Toggles.java +++ b/api/src/main/java/com/lishid/openinv/util/setting/PlayerToggles.java @@ -2,14 +2,17 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.UnmodifiableView; +import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.UUID; -public final class Toggles { +public final class PlayerToggles { private static final Map TOGGLES = new HashMap<>(); private static final PlayerToggle ANY = add(new MemoryToggle("anycontainer")); @@ -27,12 +30,16 @@ public final class Toggles { return TOGGLES.get(toggleName); } + public static @UnmodifiableView @NotNull Collection get() { + return Collections.unmodifiableCollection(TOGGLES.values()); + } + private static @NotNull PlayerToggle add(@NotNull PlayerToggle toggle) { TOGGLES.put(toggle.getName(), toggle); return toggle; } - private Toggles() { + private PlayerToggles() { throw new IllegalStateException("Cannot create instance of utility class."); } diff --git a/plugin/src/main/java/com/lishid/openinv/OpenInv.java b/plugin/src/main/java/com/lishid/openinv/OpenInv.java index 7d9c9db9..d583e450 100644 --- a/plugin/src/main/java/com/lishid/openinv/OpenInv.java +++ b/plugin/src/main/java/com/lishid/openinv/OpenInv.java @@ -36,7 +36,8 @@ import com.lishid.openinv.util.InventoryManager; import com.lishid.openinv.util.lang.LangMigrator; import com.lishid.openinv.util.PlayerLoader; -import com.lishid.openinv.util.setting.Toggles; +import com.lishid.openinv.util.setting.PlayerToggle; +import com.lishid.openinv.util.setting.PlayerToggles; import com.lishid.openinv.util.lang.LanguageManager; import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; @@ -204,22 +205,22 @@ public boolean noArgsOpensSelf() { @Override public boolean getAnyContainerStatus(@NotNull final OfflinePlayer offline) { - return Toggles.any().is(offline.getUniqueId()); + return PlayerToggles.any().is(offline.getUniqueId()); } @Override public void setAnyContainerStatus(@NotNull final OfflinePlayer offline, final boolean status) { - Toggles.any().set(offline.getUniqueId(), status); + PlayerToggles.any().set(offline.getUniqueId(), status); } @Override public boolean getSilentContainerStatus(@NotNull final OfflinePlayer offline) { - return Toggles.silent().is(offline.getUniqueId()); + return PlayerToggles.silent().is(offline.getUniqueId()); } @Override public void setSilentContainerStatus(@NotNull final OfflinePlayer offline, final boolean status) { - Toggles.silent().set(offline.getUniqueId(), status); + PlayerToggles.silent().set(offline.getUniqueId(), status); } @Override diff --git a/plugin/src/main/java/com/lishid/openinv/command/ContainerSettingCommand.java b/plugin/src/main/java/com/lishid/openinv/command/ContainerSettingCommand.java index 62324597..af00131b 100644 --- a/plugin/src/main/java/com/lishid/openinv/command/ContainerSettingCommand.java +++ b/plugin/src/main/java/com/lishid/openinv/command/ContainerSettingCommand.java @@ -19,7 +19,7 @@ import com.lishid.openinv.event.OpenEvents; import com.lishid.openinv.util.setting.PlayerToggle; import com.lishid.openinv.util.TabCompleter; -import com.lishid.openinv.util.setting.Toggles; +import com.lishid.openinv.util.setting.PlayerToggles; import com.lishid.openinv.util.lang.LanguageManager; import com.lishid.openinv.util.lang.Replacement; import org.bukkit.command.Command; @@ -49,7 +49,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command return true; } - PlayerToggle toggle = Toggles.get(command.getName()); + PlayerToggle toggle = PlayerToggles.get(command.getName()); // Shouldn't be possible. if (toggle == null) { diff --git a/plugin/src/main/java/com/lishid/openinv/listener/ContainerListener.java b/plugin/src/main/java/com/lishid/openinv/listener/ContainerListener.java index 0195ae11..d93e7f54 100644 --- a/plugin/src/main/java/com/lishid/openinv/listener/ContainerListener.java +++ b/plugin/src/main/java/com/lishid/openinv/listener/ContainerListener.java @@ -20,7 +20,7 @@ import com.lishid.openinv.internal.ViewOnly; import com.lishid.openinv.util.InternalAccessor; import com.lishid.openinv.util.Permissions; -import com.lishid.openinv.util.setting.Toggles; +import com.lishid.openinv.util.setting.PlayerToggles; import com.lishid.openinv.util.lang.LanguageManager; import org.bukkit.GameMode; import org.bukkit.entity.HumanEntity; @@ -72,14 +72,14 @@ private void onPlayerInteract(@NotNull PlayerInteractEvent event) { Player player = event.getPlayer(); UUID playerId = player.getUniqueId(); - boolean any = Permissions.CONTAINER_ANY.hasPermission(player) && Toggles.any().is(playerId); + boolean any = Permissions.CONTAINER_ANY.hasPermission(player) && PlayerToggles.any().is(playerId); boolean needsAny = accessor.getAnySilentContainer().isAnyContainerNeeded(event.getClickedBlock()); if (!any && needsAny) { return; } - boolean silent = Permissions.CONTAINER_SILENT.hasPermission(player) && Toggles.silent().is(playerId); + boolean silent = Permissions.CONTAINER_SILENT.hasPermission(player) && PlayerToggles.silent().is(playerId); // If anycontainer or silentcontainer is active if (any || silent) { @@ -104,7 +104,7 @@ private void onInventoryClose(@NotNull final InventoryCloseEvent event) { } InventoryHolder holder = event.getInventory().getHolder(); - if (Toggles.silent().is(player.getUniqueId()) + if (PlayerToggles.silent().is(player.getUniqueId()) && holder != null && this.accessor.getAnySilentContainer().isAnySilentContainer(holder)) { this.accessor.getAnySilentContainer().deactivateContainer(player); diff --git a/plugin/src/main/java/com/lishid/openinv/listener/ToggleListener.java b/plugin/src/main/java/com/lishid/openinv/listener/ToggleListener.java index 0d811694..2714acdc 100644 --- a/plugin/src/main/java/com/lishid/openinv/listener/ToggleListener.java +++ b/plugin/src/main/java/com/lishid/openinv/listener/ToggleListener.java @@ -1,6 +1,6 @@ package com.lishid.openinv.listener; -import com.lishid.openinv.util.setting.Toggles; +import com.lishid.openinv.util.setting.PlayerToggles; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; @@ -13,8 +13,8 @@ public class ToggleListener implements Listener { @EventHandler private void onPlayerQuit(@NotNull PlayerQuitEvent event) { UUID playerId = event.getPlayer().getUniqueId(); - Toggles.any().set(playerId, false); - Toggles.silent().set(playerId, false); + PlayerToggles.any().set(playerId, false); + PlayerToggles.silent().set(playerId, false); } }