diff --git a/src/main/java/de/studiocode/invui/resourcepack/ForceResourcePack.java b/src/main/java/de/studiocode/invui/resourcepack/ForceResourcePack.java index feccc2e..efc3cc3 100644 --- a/src/main/java/de/studiocode/invui/resourcepack/ForceResourcePack.java +++ b/src/main/java/de/studiocode/invui/resourcepack/ForceResourcePack.java @@ -1,6 +1,7 @@ package de.studiocode.invui.resourcepack; import de.studiocode.invui.InvUI; +import de.studiocode.invui.resourcepack.Icon.MaterialIcon; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -8,19 +9,34 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerResourcePackStatusEvent; import org.bukkit.scheduler.BukkitTask; +import org.jetbrains.annotations.Nullable; import java.util.HashMap; import static org.bukkit.event.player.PlayerResourcePackStatusEvent.Status.DECLINED; +/** + * Forces {@link Player}s to use a custom ResourcePack and kicks them if they don't accept it. + */ public class ForceResourcePack implements Listener { + /** + * A resource pack with all the {@link Icon}s + */ + public static final String LIGHT_RESOURCE_PACK_URL = + "https://github.com/NichtStudioCode/InvUIRP/releases/download/v0.6-light/InvUIRP.zip"; + + /** + * A resource pack that also provides all {@link MaterialIcon}s + */ + public static final String FULL_RESOURCE_PACK_URL = + "https://github.com/NichtStudioCode/InvUIRP/releases/download/v0.6/InvUIRP.zip"; + private static final ForceResourcePack INSTANCE = new ForceResourcePack(); private final HashMap tasks = new HashMap<>(); - private String resourcePackUrl = "https://github.com/NichtStudioCode/InvUIRP/releases/download/v0.6/InvUIRP.zip"; - private boolean activated; + private String resourcePackUrl; private ForceResourcePack() { Bukkit.getPluginManager().registerEvents(this, InvUI.getInstance().getPlugin()); @@ -31,14 +47,34 @@ public class ForceResourcePack implements Listener { return INSTANCE; } + /** + * Sets the URL String for the custom ResourcePack every {@link Player} is required to download. + * Can be set to null to stop the forcing of a ResourcePack + * + * @param resourcePackUrl The ResourcePack URL String + */ + public void setResourcePackUrl(@Nullable String resourcePackUrl) { + this.resourcePackUrl = resourcePackUrl; + } + + public String getResourcePackUrl() { + return resourcePackUrl; + } + @EventHandler public void handleJoin(PlayerJoinEvent event) { - if (activated) sendResourcePack(event.getPlayer()); + if (resourcePackUrl != null) sendResourcePack(event.getPlayer()); + } + + private void sendResourcePack(Player player) { + player.setResourcePack(resourcePackUrl); + tasks.put(player, Bukkit.getScheduler().runTaskLater(InvUI.getInstance().getPlugin(), + () -> kickPlayer(player), 20 * 5)); } @EventHandler public void handleResourcePackStatus(PlayerResourcePackStatusEvent event) { - if (activated) { + if (resourcePackUrl != null) { Player player = event.getPlayer(); if (tasks.containsKey(player)) { if (event.getStatus() == DECLINED) kickPlayer(player); @@ -48,30 +84,8 @@ public class ForceResourcePack implements Listener { } } - private void sendResourcePack(Player player) { - player.setResourcePack(resourcePackUrl); - tasks.put(player, Bukkit.getScheduler().runTaskLater(InvUI.getInstance().getPlugin(), - () -> kickPlayer(player), 20 * 5)); - } - private void kickPlayer(Player player) { player.kickPlayer("§cPlease accept the custom resource pack"); } - public String getResourcePackUrl() { - return resourcePackUrl; - } - - public void setResourcePackUrl(String resourcePackUrl) { - this.resourcePackUrl = resourcePackUrl; - } - - public boolean isActivated() { - return activated; - } - - public void setActivated(boolean activated) { - this.activated = activated; - } - }