diff --git a/build.gradle.kts b/build.gradle.kts index 8fb1f22e7..9123fd547 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { } group = "com.iridium" -version = "4.0.3" +version = "4.0.5" description = "IridiumSkyblock" repositories { @@ -23,7 +23,7 @@ dependencies { implementation("org.jetbrains:annotations:24.0.1") implementation("com.j256.ormlite:ormlite-core:6.1") implementation("com.j256.ormlite:ormlite-jdbc:6.1") - implementation("com.iridium:IridiumTeams:2.0.7") + implementation("com.iridium:IridiumTeams:2.2.0") // Other dependencies that are not required or already available at runtime compileOnly("org.projectlombok:lombok:1.18.26") @@ -45,7 +45,7 @@ tasks { shadowJar { fun relocate(origin: String) = - relocate(origin, "com.iridium.iridiumskyblock.dependencies${origin.substring(origin.lastIndexOf('.'))}") + relocate(origin, "com.iridium.iridiumskyblock.dependencies${origin.substring(origin.lastIndexOf('.'))}") // Remove the archive classifier suffix archiveClassifier.set("") @@ -97,4 +97,4 @@ publishing { publications.create("maven") { from(components["java"]) } -} +} \ No newline at end of file diff --git a/src/main/java/com/iridium/iridiumskyblock/api/IslandCreateEvent.java b/src/main/java/com/iridium/iridiumskyblock/api/IslandCreateEvent.java new file mode 100644 index 000000000..c1d0a0fd9 --- /dev/null +++ b/src/main/java/com/iridium/iridiumskyblock/api/IslandCreateEvent.java @@ -0,0 +1,78 @@ +package com.iridium.iridiumskyblock.api; + +import com.iridium.iridiumskyblock.configs.Schematics; +import com.iridium.iridiumskyblock.database.User; +import lombok.Getter; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +@Getter + +public class IslandCreateEvent extends Event implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + private boolean cancelled; + @Nullable + private String islandName; + @NotNull + private final User user; + @NotNull + private Schematics.SchematicConfig schematicConfig; + + public IslandCreateEvent(@NotNull User user, @Nullable String islandName, Schematics.@NotNull SchematicConfig schematicConfig) { + this.islandName = islandName; + this.user = user; + this.schematicConfig = schematicConfig; + } + + @NotNull + public HandlerList getHandlers() { + return handlers; + } + + @NotNull + public static HandlerList getHandlerList() { + return handlers; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + + /** + * The name of the Island.
+ * null indicates that the name of the Player is used as the Island name + * because it hasn't been set. + * + * @return the name of the Island or null + */ + @Nullable + public String getIslandName() { + return islandName; + } + + /** + * + * Sets the name of the Island.
+ * set it to null to default to the player's name + * + * @param islandName The name of the island + */ + public void setIslandName(@Nullable String islandName) { + this.islandName = islandName; + } + + /** + * Sets the schematic of the new island + * + * @param schematicConfig The schematic configuration of the island + */ + + public void setSchematicConfig(Schematics.@NotNull SchematicConfig schematicConfig) { + this.schematicConfig = schematicConfig; + } +} diff --git a/src/main/java/com/iridium/iridiumskyblock/api/IslandDeleteEvent.java b/src/main/java/com/iridium/iridiumskyblock/api/IslandDeleteEvent.java new file mode 100644 index 000000000..ed3029e65 --- /dev/null +++ b/src/main/java/com/iridium/iridiumskyblock/api/IslandDeleteEvent.java @@ -0,0 +1,39 @@ +package com.iridium.iridiumskyblock.api; + +import com.iridium.iridiumskyblock.database.Island; +import com.iridium.iridiumskyblock.database.User; +import lombok.Getter; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +@Getter +public class IslandDeleteEvent extends Event implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + private boolean cancelled; + @NotNull private final Island island; + @NotNull private final User user; + + public IslandDeleteEvent(@NotNull Island island, @NotNull User user) { + this.island = island; + this.user = user; + } + + @NotNull + public HandlerList getHandlers() { + return handlers; + } + + @NotNull + public static HandlerList getHandlerList() { + return handlers; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + +} \ No newline at end of file diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/BiomeCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/BiomeCommand.java index 753e40724..54fb81bd3 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/BiomeCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/BiomeCommand.java @@ -19,14 +19,15 @@ public class BiomeCommand extends Command { public BiomeCommand() { - super(Collections.singletonList("biomes"), "Refresh your Island Biome", "%prefix% &7/is biomes ", ""); + super(Collections.singletonList("biomes"), "Refresh your Island Biome", "%prefix% &7/is biomes ", "", 10); } @Override - public void execute(User user, String[] args, IridiumTeams iridiumTeams) { + public boolean execute(User user, Island island, String[] args, IridiumTeams iridiumTeams) { Player player = user.getPlayer(); if (args.length == 0) { player.openInventory(new BiomeOverviewGUI(player.getOpenInventory().getTopInventory()).getInventory()); + return false; } else { Optional categoryName = getCategoryName(String.join(" ", args)); @@ -34,10 +35,11 @@ public void execute(User user, String[] args, IridiumTeams iridium player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noBiomeCategory .replace("%prefix%", iridiumTeams.getConfiguration().prefix) )); - return; + return false; } player.openInventory(new BiomeCategoryGUI(categoryName.get(), player.getOpenInventory().getTopInventory()).getInventory()); + return false; } } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/BorderCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/BorderCommand.java index d69a48be8..68b3f07cf 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/BorderCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/BorderCommand.java @@ -27,31 +27,31 @@ public class BorderCommand extends Command { * The default constructor. */ public BorderCommand() { - super(Collections.singletonList("border"), "Change the Island Border", "%prefix% &7/is border ", ""); + super(Collections.singletonList("border"), "Change the Island Border", "%prefix% &7/is border ", "", 0); } @Override - public void execute(User user, Island island, String[] args, IridiumTeams iridiumTeams) { + public boolean execute(User user, Island island, String[] args, IridiumTeams iridiumTeams) { Player player = user.getPlayer(); if (!IridiumSkyblock.getInstance().getIslandManager().getTeamPermission(island, IridiumSkyblock.getInstance().getUserManager().getUser(player), "border")) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotManageBorder.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); - return; + return false; } if (args.length == 0) { player.openInventory(new BorderGUI(player.getOpenInventory().getTopInventory()).getInventory()); - return; + return false; } Color color = Color.getColor(args[0]); if (color == null) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notAColor.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); - return; + return false; } if (!IridiumSkyblock.getInstance().getConfiguration().enabledBorders.getOrDefault(color, true)) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().borderColorDisabled.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); - return; + return false; } island.setColor(color); @@ -65,6 +65,8 @@ public void execute(User user, Island island, String[] args, IridiumTeams { public RegenCommand() { - super(Collections.singletonList("regen"), "Regenerate your Island", "%prefix% &7/is regen ", ""); + super(Collections.singletonList("regen"), "Regenerate your Island", "%prefix% &7/is regen ", "", 300); } @Override - public void execute(User user, Island island, String[] args, IridiumTeams iridiumTeams) { + public boolean execute(User user, Island island, String[] args, IridiumTeams iridiumTeams) { Player player = user.getPlayer(); if (args.length == 0) { if (!IridiumSkyblock.getInstance().getIslandManager().getTeamPermission(island, IridiumSkyblock.getInstance().getUserManager().getUser(player), "regen")) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotRegenIsland .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix) )); - return; + return false; } player.openInventory(new RegenGUI(player.getOpenInventory().getTopInventory(), player).getInventory()); - return; + return false; } - Optional schematicConfig = IridiumSkyblock.getInstance().getSchematics().schematics.keySet().stream() + Optional schematic = IridiumSkyblock.getInstance().getSchematics().schematics.keySet().stream() .filter(config -> config.equalsIgnoreCase(args[0])) .findFirst(); - if (!schematicConfig.isPresent()) { + if (!schematic.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().unknownSchematic .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix) )); - return; + return false; } + Schematics.SchematicConfig schematicConfig = IridiumSkyblock.getInstance().getSchematics().schematics.get(schematic.get()); + IridiumSkyblock.getInstance().getIslandManager().getTeamMembers(island).stream() .map(User::getPlayer) .filter(Objects::nonNull) @@ -51,13 +54,18 @@ public void execute(User user, Island island, String[] args, IridiumTeams Bukkit.getScheduler().runTask(IridiumSkyblock.getInstance(), () -> { + IridiumSkyblock.getInstance().getIslandManager().clearTeamInventory(island); + + IridiumSkyblock.getInstance().getIslandManager().generateIsland(island, schematicConfig).thenRun(() -> Bukkit.getScheduler().runTask(IridiumSkyblock.getInstance(), () -> { + if (IridiumSkyblock.getInstance().getTeamManager().teleport(player, island.getHome(), island)) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().teleportingHome .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix) )); } })); + + return true; } @Override diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/VisitCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/VisitCommand.java index a95d37d44..0d0a3a2be 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/VisitCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/VisitCommand.java @@ -18,30 +18,31 @@ public class VisitCommand extends Command { public VisitCommand() { - super(Collections.singletonList("visit"), "Visit other islands", "%prefix% &7/is visit", ""); + super(Collections.singletonList("visit"), "Visit other islands", "%prefix% &7/is visit", "", 0); } @Override - public void execute(User user, String[] args, IridiumTeams iridiumTeams) { + public boolean execute(User user, String[] args, IridiumTeams iridiumTeams) { Player player = user.getPlayer(); if (args.length == 0) { player.openInventory(new VisitGUI(player.getOpenInventory().getTopInventory(), iridiumTeams).getInventory()); - return; + return false; } Optional island = IridiumSkyblock.getInstance().getTeamManager().getTeamViaNameOrPlayer(args[0]); if (!island.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().teamDoesntExistByName .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix) )); - return; + return false; } if (!IridiumSkyblock.getInstance().getIslandManager().canVisit(player, island.get())) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotVisit .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix) )); - return; + return false; } player.teleport(island.get().getHome()); + return true; } @Override diff --git a/src/main/java/com/iridium/iridiumskyblock/configs/Biomes.java b/src/main/java/com/iridium/iridiumskyblock/configs/Biomes.java index cf4742e0a..c6e12f140 100644 --- a/src/main/java/com/iridium/iridiumskyblock/configs/Biomes.java +++ b/src/main/java/com/iridium/iridiumskyblock/configs/Biomes.java @@ -14,9 +14,9 @@ public class Biomes { public Map categories = ImmutableMap.builder() - .put("Overworld", new BiomeCategory(new Item(XMaterial.GRASS_BLOCK, 20, 1, "&9&lOverworld", Collections.emptyList()), 54)) - .put("Nether", new BiomeCategory(new Item(XMaterial.CRIMSON_NYLIUM, 22, 1, "&9&lNether", Collections.emptyList()), 36)) - .put("End", new BiomeCategory(new Item(XMaterial.END_STONE, 24, 1, "&9&lEnd", Collections.emptyList()), 36)) + .put("Overworld", new BiomeCategory(new Item(XMaterial.GRASS_BLOCK, 11, 1, "&9&lOverworld", Collections.emptyList()), 54)) + .put("Nether", new BiomeCategory(new Item(XMaterial.CRIMSON_NYLIUM, 13, 1, "&9&lNether", Collections.emptyList()), 36)) + .put("End", new BiomeCategory(new Item(XMaterial.END_STONE, 15, 1, "&9&lEnd", Collections.emptyList()), 36)) .build(); public Map> items = ImmutableMap.>builder() .put("Overworld", Arrays.asList( diff --git a/src/main/java/com/iridium/iridiumskyblock/configs/Configuration.java b/src/main/java/com/iridium/iridiumskyblock/configs/Configuration.java index fcddccf3a..8a692bddf 100644 --- a/src/main/java/com/iridium/iridiumskyblock/configs/Configuration.java +++ b/src/main/java/com/iridium/iridiumskyblock/configs/Configuration.java @@ -19,39 +19,44 @@ public Configuration() { this.levelRewards = ImmutableMap.builder() - .put(1, new Reward(new Item(XMaterial.EXPERIENCE_BOTTLE, 1, "&b&lLevel %island_level% Reward", Arrays.asList( + .put(1, new Reward(new Item(XMaterial.EXPERIENCE_BOTTLE, 1, "&9&lLevel %island_level% Reward", Arrays.asList( "&7Island Level %island_level% Rewards:", - "&b&l* &b1000 Money", - "&b&l* &b5 Island Crystals", + "&9&l* &91000 Money", + "&9&l* &95 Island Crystals", "", - "&b&l[!] &bLeft click to redeem" + "&9&l[!] &9Left click to redeem" )), Collections.emptyList(), 0, new ImmutableMap.Builder().put("Crystals", 5.00).build(), 200, 0, XSound.ENTITY_PLAYER_LEVELUP)) - .put(5, new Reward(new Item(XMaterial.EXPERIENCE_BOTTLE, 1, "&b&lLevel %island_level% Reward", Arrays.asList( + .put(5, new Reward(new Item(XMaterial.EXPERIENCE_BOTTLE, 1, "&9&lLevel %island_level% Reward", Arrays.asList( "&7Island Level %island_level% Rewards:", - "&b&l* &b10000 Money", - "&b&l* &b10 Island Crystals", + "&9&l* &910000 Money", + "&9&l* &910 Island Crystals", "", - "&b&l[!] &bLeft click to redeem" + "&9&l[!] &9Left click to redeem" )), Collections.emptyList(), 0, new ImmutableMap.Builder().put("Crystals", 10.00).build(), 2000, 0, XSound.ENTITY_PLAYER_LEVELUP)) .build(); } - public String islandCreateTitle = "&b&lIsland Created"; + public String islandCreateTitle = "&9&lIsland Created"; public String islandCreateSubTitle = "&7IridiumSkyblock by Peaches_MLG"; public String defaultDescription = "Default island description :c"; public String worldName = "IridiumSkyblock"; public String spawnWorldName = "world"; public String islandTitleTop = "&9%island_name%"; - public String islandTitleBottom = "&7%island_description%"; + public String islandTitleBottom = "&7%island_description%"; public String paster = "worldedit"; public boolean obsidianBucket = true; + public boolean endPortalPick = true; + public boolean removeIslandBlocksOnDelete = false; + public boolean clearInventoryOnRegen = false; + public boolean clearEnderChestOnRegen = false; + public boolean allowPvPOnIslands = false; public int distance = 151; public int netherUnlockLevel = 10; public int pasterDelayInTick = 1; - public int pasterLimitPerTick = 100; + public int pasterLimitPerTick = 10; public Item islandCrystal = new Item(XMaterial.NETHER_STAR, 1, "&9*** &9&lIsland Crystal &9***", Arrays.asList( "", diff --git a/src/main/java/com/iridium/iridiumskyblock/configs/Inventories.java b/src/main/java/com/iridium/iridiumskyblock/configs/Inventories.java index bcb84c6cb..677444074 100644 --- a/src/main/java/com/iridium/iridiumskyblock/configs/Inventories.java +++ b/src/main/java/com/iridium/iridiumskyblock/configs/Inventories.java @@ -59,7 +59,7 @@ public class Inventories extends com.iridium.iridiumteams.configs.Inventories { ))); public NoItemGUI islandSchematicGUI = new NoItemGUI(27, "&7Select a Schematic", background2); - public NoItemGUI biomeOverviewGUI = new NoItemGUI(54, "Biomes", background2); + public NoItemGUI biomeOverviewGUI = new NoItemGUI(27, "Biomes", background2); public NoItemGUI biomeCategoryGUI = new NoItemGUI(54, "Biomes - %biome_category_name%", background1); public Inventories() { diff --git a/src/main/java/com/iridium/iridiumskyblock/configs/Messages.java b/src/main/java/com/iridium/iridiumskyblock/configs/Messages.java index 779b4c6b4..b50c8a708 100644 --- a/src/main/java/com/iridium/iridiumskyblock/configs/Messages.java +++ b/src/main/java/com/iridium/iridiumskyblock/configs/Messages.java @@ -4,6 +4,8 @@ public class Messages extends com.iridium.iridiumteams.configs.Messages { public Messages() { super("Island", "is", "IridiumSkyblock", "&9"); + + teamCreated = "%prefix% &7Island Creation Completed!"; } public String voidTeleport = "%prefix% &7You have fallen off your island. Teleporting home..."; @@ -18,6 +20,7 @@ public Messages() { public String unknownSchematic = "%prefix% &7No schematic with that name exists."; public String noSafeLocation = "%prefix% &7Could not find a safe location to teleport to."; public String cannotHurtPlayers = "%prefix% &7You cannot hurt players on your Island."; + public String creatingIsland = "%prefix% &7Creating Island, please wait..."; public String noBiomeCategory = "%prefix% &7No biome category with that name."; public String noBiome = "%prefix% &7No biome with that name."; public String changedBiome = "%prefix% &7%player% successfully changed your Island biome to %biome%."; diff --git a/src/main/java/com/iridium/iridiumskyblock/configs/Missions.java b/src/main/java/com/iridium/iridiumskyblock/configs/Missions.java index ad9b28fcd..a06fdfa17 100644 --- a/src/main/java/com/iridium/iridiumskyblock/configs/Missions.java +++ b/src/main/java/com/iridium/iridiumskyblock/configs/Missions.java @@ -227,7 +227,7 @@ public Missions() { "&7Which can be used to purchase Island Upgrades", "", "&9&lObjectives:", - "&9&l* &7Mine 10 logs: %progress_1%/3", + "&9&l* &7Mine 10 logs: %progress_1%/10", "", "&9&lRewards", "&9&l* &75 Island Crystals", @@ -251,7 +251,7 @@ public Missions() { "&7Which can be used to purchase Island Upgrades", "", "&9&lObjectives:", - "&9&l* &7Mine 100 logs: %progress_1%/3", + "&9&l* &7Mine 100 logs: %progress_1%/100", "", "&9&lRewards", "&9&l* &75 Island Crystals", @@ -275,7 +275,7 @@ public Missions() { "&7Which can be used to purchase Island Upgrades", "", "&9&lObjectives:", - "&9&l* &7Mine 1000 logs: %progress_1%/3", + "&9&l* &7Mine 1000 logs: %progress_1%/1000", "", "&9&lRewards", "&9&l* &75 Island Crystals", diff --git a/src/main/java/com/iridium/iridiumskyblock/configs/Permissions.java b/src/main/java/com/iridium/iridiumskyblock/configs/Permissions.java index 4a3804e87..ad28f8ec8 100644 --- a/src/main/java/com/iridium/iridiumskyblock/configs/Permissions.java +++ b/src/main/java/com/iridium/iridiumskyblock/configs/Permissions.java @@ -7,8 +7,8 @@ import java.util.Arrays; public class Permissions extends com.iridium.iridiumteams.configs.Permissions { - public Permission border = new Permission(new Item(XMaterial.BEACON, 33, 1, "&bIsland Border", Arrays.asList("&7Grant the ability to Change the Island border.", "", "&b&lPermission", "%permission%")), 1, 1); - public Permission regen = new Permission(new Item(XMaterial.TNT, 34, 1, "&bRegenerate Island", Arrays.asList("&7Grant the ability to regenerate your Island.", "", "&b&lPermission", "%permission%")), 1, 3); + public Permission border = new Permission(new Item(XMaterial.BEACON, 33, 1, "&9Island Border", Arrays.asList("&7Grant the ability to Change the Island border.", "", "&9&lPermission", "%permission%")), 1, 1); + public Permission regen = new Permission(new Item(XMaterial.TNT, 34, 1, "&9Regenerate Island", Arrays.asList("&7Grant the ability to regenerate your Island.", "", "&9&lPermission", "%permission%")), 1, 3); public Permissions() { super("Island", "&9"); diff --git a/src/main/java/com/iridium/iridiumskyblock/configs/Schematics.java b/src/main/java/com/iridium/iridiumskyblock/configs/Schematics.java index 5ae0685f5..0e5606f36 100644 --- a/src/main/java/com/iridium/iridiumskyblock/configs/Schematics.java +++ b/src/main/java/com/iridium/iridiumskyblock/configs/Schematics.java @@ -15,7 +15,7 @@ public class Schematics { public Map schematics = ImmutableMap.builder() - .put("desert", new SchematicConfig(new Item(XMaterial.PLAYER_HEAD, 11, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNGY0OTNkZDgwNjUzM2Q5ZDIwZTg0OTUzOTU0MzY1ZjRkMzY5NzA5Y2ViYzlkZGVmMDIyZDFmZDQwZDg2YTY4ZiJ9fX0=", 1, "&b&lDesert Island", Collections.singletonList("&7A starter desert island.")), + .put("desert", new SchematicConfig(new Item(XMaterial.PLAYER_HEAD, 11, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNGY0OTNkZDgwNjUzM2Q5ZDIwZTg0OTUzOTU0MzY1ZjRkMzY5NzA5Y2ViYzlkZGVmMDIyZDFmZDQwZDg2YTY4ZiJ9fX0=", 1, "&9&lDesert Island", Collections.singletonList("&7A starter desert island.")), -0.5, 89, -0.5, 90, new SchematicWorld(Biome.DESERT, "desert.schem", 90.0, true ), new SchematicWorld(Biome.NETHER_WASTES, @@ -23,7 +23,7 @@ public class Schematics { ), new SchematicWorld(Biome.THE_END, "desert_end.schem", 90.0, true ))) - .put("jungle", new SchematicConfig(new Item(XMaterial.PLAYER_HEAD, 13, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNjgzYWRmNDU2MGRlNDc0MTQwNDA5M2FjNjFjMzNmYjU1NmIzZDllZTUxNDBmNjIwMzYyNTg5ZmRkZWRlZmEyZCJ9fX0=", 1, "&b&lJungle Island", Collections.singletonList("&7A starter jungle island.")), + .put("jungle", new SchematicConfig(new Item(XMaterial.PLAYER_HEAD, 13, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNjgzYWRmNDU2MGRlNDc0MTQwNDA5M2FjNjFjMzNmYjU1NmIzZDllZTUxNDBmNjIwMzYyNTg5ZmRkZWRlZmEyZCJ9fX0=", 1, "&9&lJungle Island", Collections.singletonList("&7A starter jungle island.")), 1.5, 83, 1.5, 90, new SchematicWorld(Biome.JUNGLE, "jungle.schem", 90.0, true ), new SchematicWorld(Biome.NETHER_WASTES, @@ -31,7 +31,7 @@ public class Schematics { ), new SchematicWorld(Biome.THE_END, "jungle_end.schem", 90.0, true ))) - .put("mushroom", new SchematicConfig(new Item(XMaterial.PLAYER_HEAD, 15, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZWE0NWQxYjQxN2NiZGRjMjE3NjdiMDYwNDRlODk5YjI2NmJmNzhhNjZlMjE4NzZiZTNjMDUxNWFiNTVkNzEifX19", 1, "&b&lMushroom Island", Collections.singletonList("&7A starter mushroom island.")), + .put("mushroom", new SchematicConfig(new Item(XMaterial.PLAYER_HEAD, 15, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZWE0NWQxYjQxN2NiZGRjMjE3NjdiMDYwNDRlODk5YjI2NmJmNzhhNjZlMjE4NzZiZTNjMDUxNWFiNTVkNzEifX19", 1, "&9&lMushroom Island", Collections.singletonList("&7A starter mushroom island.")), 0.5, 89, -0.5, 90, new SchematicWorld(Biome.MUSHROOM_FIELDS, "mushroom.schem", 90.0, true ), new SchematicWorld(Biome.NETHER_WASTES, diff --git a/src/main/java/com/iridium/iridiumskyblock/database/User.java b/src/main/java/com/iridium/iridiumskyblock/database/User.java index 07471b58c..cd25e2443 100644 --- a/src/main/java/com/iridium/iridiumskyblock/database/User.java +++ b/src/main/java/com/iridium/iridiumskyblock/database/User.java @@ -17,19 +17,21 @@ public class User extends IridiumUser { private Optional currentIsland = Optional.empty(); + public User(UUID uuid, String name) { setUuid(uuid); setName(name); setJoinTime(LocalDateTime.now()); } - public Optional getIsland(){ + public Optional getIsland() { return IridiumSkyblock.getInstance().getTeamManager().getTeamViaID(getTeamID()); } public Optional getCurrentIsland() { Player player = getPlayer(); - if(currentIsland.isPresent() && currentIsland.get().isInIsland(player.getLocation())){ + if (player == null) return Optional.empty(); + if (currentIsland.isPresent() && currentIsland.get().isInIsland(player.getLocation())) { return currentIsland; } setCurrentIsland(IridiumSkyblock.getInstance().getTeamManager().getTeamViaLocation(player.getLocation())); diff --git a/src/main/java/com/iridium/iridiumskyblock/gui/BiomeCategoryGUI.java b/src/main/java/com/iridium/iridiumskyblock/gui/BiomeCategoryGUI.java index 042572c2f..eabd13579 100644 --- a/src/main/java/com/iridium/iridiumskyblock/gui/BiomeCategoryGUI.java +++ b/src/main/java/com/iridium/iridiumskyblock/gui/BiomeCategoryGUI.java @@ -99,6 +99,7 @@ public void onInventoryClick(InventoryClickEvent event) { Player player = (Player) event.getWhoClicked(); if (event.isLeftClick() && biomeItem.get().buyCost.canPurchase()) { IridiumSkyblock.getInstance().getBiomeManager().buy(player, biomeItem.get()); + player.closeInventory(); } else { IridiumSkyblock.getInstance().getBiomes().failSound.play(player); } diff --git a/src/main/java/com/iridium/iridiumskyblock/gui/BorderGUI.java b/src/main/java/com/iridium/iridiumskyblock/gui/BorderGUI.java index 22887c56c..376668c5c 100644 --- a/src/main/java/com/iridium/iridiumskyblock/gui/BorderGUI.java +++ b/src/main/java/com/iridium/iridiumskyblock/gui/BorderGUI.java @@ -52,19 +52,19 @@ public void onInventoryClick(InventoryClickEvent event) { super.onInventoryClick(event); if (IridiumSkyblock.getInstance().getConfiguration().enabledBorders.getOrDefault(Color.BLUE, true) && event.getSlot() == IridiumSkyblock.getInstance().getInventories().islandBorderGUI.blue.slot) { - IridiumSkyblock.getInstance().getCommands().borderCommand.execute(event.getWhoClicked(), new String[]{"blue"}, IridiumSkyblock.getInstance()); + IridiumSkyblock.getInstance().getCommandManager().executeCommand(event.getWhoClicked(), IridiumSkyblock.getInstance().getCommands().borderCommand, new String[]{"blue"}); } if (IridiumSkyblock.getInstance().getConfiguration().enabledBorders.getOrDefault(Color.RED, true) && event.getSlot() == IridiumSkyblock.getInstance().getInventories().islandBorderGUI.red.slot) { - IridiumSkyblock.getInstance().getCommands().borderCommand.execute(event.getWhoClicked(), new String[]{"red"}, IridiumSkyblock.getInstance()); + IridiumSkyblock.getInstance().getCommandManager().executeCommand(event.getWhoClicked(), IridiumSkyblock.getInstance().getCommands().borderCommand, new String[]{"red"}); } if (IridiumSkyblock.getInstance().getConfiguration().enabledBorders.getOrDefault(Color.GREEN, true) && event.getSlot() == IridiumSkyblock.getInstance().getInventories().islandBorderGUI.green.slot) { - IridiumSkyblock.getInstance().getCommands().borderCommand.execute(event.getWhoClicked(), new String[]{"green"}, IridiumSkyblock.getInstance()); + IridiumSkyblock.getInstance().getCommandManager().executeCommand(event.getWhoClicked(), IridiumSkyblock.getInstance().getCommands().borderCommand, new String[]{"green"}); } if (IridiumSkyblock.getInstance().getConfiguration().enabledBorders.getOrDefault(Color.OFF, true) && event.getSlot() == IridiumSkyblock.getInstance().getInventories().islandBorderGUI.off.slot) { - IridiumSkyblock.getInstance().getCommands().borderCommand.execute(event.getWhoClicked(), new String[]{"off"}, IridiumSkyblock.getInstance()); + IridiumSkyblock.getInstance().getCommandManager().executeCommand(event.getWhoClicked(), IridiumSkyblock.getInstance().getCommands().borderCommand, new String[]{"off"}); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/gui/RegenGUI.java b/src/main/java/com/iridium/iridiumskyblock/gui/RegenGUI.java index 23e610d70..13b0b23bc 100644 --- a/src/main/java/com/iridium/iridiumskyblock/gui/RegenGUI.java +++ b/src/main/java/com/iridium/iridiumskyblock/gui/RegenGUI.java @@ -5,8 +5,6 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import java.util.concurrent.CompletableFuture; - @Getter public class RegenGUI extends SchematicGUI { private final Player player; @@ -18,7 +16,7 @@ public RegenGUI(Inventory previousInventory, Player player) { @Override public void selectSchematic(String schematic) { - IridiumSkyblock.getInstance().getCommands().regenCommand.execute(player, new String[]{schematic}, IridiumSkyblock.getInstance()); + IridiumSkyblock.getInstance().getCommandManager().executeCommand(player, IridiumSkyblock.getInstance().getCommands().regenCommand, new String[]{schematic}); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/gui/VisitGUI.java b/src/main/java/com/iridium/iridiumskyblock/gui/VisitGUI.java index 47bd6c481..e4216575e 100644 --- a/src/main/java/com/iridium/iridiumskyblock/gui/VisitGUI.java +++ b/src/main/java/com/iridium/iridiumskyblock/gui/VisitGUI.java @@ -63,6 +63,6 @@ public void onInventoryClick(InventoryClickEvent event) { Island island = getItem(event.getSlot()); if (island == null) return; - IridiumSkyblock.getInstance().getCommands().visitCommand.execute(event.getWhoClicked(), new String[]{island.getName()}, iridiumTeams); + IridiumSkyblock.getInstance().getCommandManager().executeCommand(event.getWhoClicked(), IridiumSkyblock.getInstance().getCommands().visitCommand, new String[]{island.getName()}); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/listeners/EntityDamageListener.java b/src/main/java/com/iridium/iridiumskyblock/listeners/EntityDamageListener.java index 10d3e0a68..c7970f8a5 100755 --- a/src/main/java/com/iridium/iridiumskyblock/listeners/EntityDamageListener.java +++ b/src/main/java/com/iridium/iridiumskyblock/listeners/EntityDamageListener.java @@ -19,6 +19,7 @@ public class EntityDamageListener implements Listener { @EventHandler(ignoreCancelled = true) public void onEntityDamage(EntityDamageEvent event) { + if (!IridiumSkyblock.getInstance().getConfiguration().allowPvPOnIslands) return; Optional island = IridiumSkyblock.getInstance().getIslandManager().getTeamViaLocation(event.getEntity().getLocation()); if (!island.isPresent()) return; @@ -33,6 +34,7 @@ public void onEntityDamage(EntityDamageEvent event) { @EventHandler(ignoreCancelled = true) public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { + if (!IridiumSkyblock.getInstance().getConfiguration().allowPvPOnIslands) return; if (event.getEntity().equals(event.getDamager())) return; Optional island = IridiumSkyblock.getInstance().getIslandManager().getTeamViaLocation(event.getEntity().getLocation()); diff --git a/src/main/java/com/iridium/iridiumskyblock/listeners/PlayerInteractListener.java b/src/main/java/com/iridium/iridiumskyblock/listeners/PlayerInteractListener.java index 38814e4dc..eb1143f1b 100644 --- a/src/main/java/com/iridium/iridiumskyblock/listeners/PlayerInteractListener.java +++ b/src/main/java/com/iridium/iridiumskyblock/listeners/PlayerInteractListener.java @@ -1,11 +1,14 @@ package com.iridium.iridiumskyblock.listeners; +import com.iridium.iridiumcore.dependencies.xseries.XMaterial; import com.iridium.iridiumcore.utils.StringUtils; import com.iridium.iridiumskyblock.IridiumSkyblock; import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.User; import com.iridium.iridiumteams.PermissionType; +import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -14,6 +17,7 @@ import org.bukkit.inventory.ItemStack; import java.util.Optional; +import java.util.concurrent.atomic.AtomicInteger; public class PlayerInteractListener implements Listener { @@ -23,13 +27,6 @@ public void onClick(PlayerInteractEvent event) { User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); ItemStack itemInHand = player.getInventory().getItemInMainHand(); - if (!(IridiumSkyblock.getInstance().getConfiguration().obsidianBucket - && event.getAction().equals(Action.RIGHT_CLICK_BLOCK) - && event.getClickedBlock().getType().equals(Material.OBSIDIAN) - && itemInHand.getType().equals(Material.BUCKET))) { - return; - } - Optional island = IridiumSkyblock.getInstance().getTeamManager().getTeamViaLocation(event.getClickedBlock().getLocation()); if (!island.isPresent()) return; if (!IridiumSkyblock.getInstance().getTeamManager().getTeamPermission(island.get(), user, PermissionType.BLOCK_BREAK)) { @@ -39,14 +36,52 @@ public void onClick(PlayerInteractEvent event) { return; } - event.getClickedBlock().setType(Material.AIR); - if (itemInHand.getAmount() > 1) { - itemInHand.setAmount(itemInHand.getAmount() - 1); - player.getInventory().addItem(new ItemStack(Material.LAVA_BUCKET)).values().forEach(itemStack -> - player.getWorld().dropItem(player.getLocation(), itemStack) - ); - } else { - itemInHand.setType(Material.LAVA_BUCKET); + if (IridiumSkyblock.getInstance().getConfiguration().obsidianBucket + && event.getAction().equals(Action.RIGHT_CLICK_BLOCK) + && event.getClickedBlock().getType().equals(Material.OBSIDIAN) + && itemInHand.getType().equals(Material.BUCKET)) { + + event.getClickedBlock().setType(Material.AIR); + + if (itemInHand.getAmount() > 1) { + itemInHand.setAmount(itemInHand.getAmount() - 1); + player.getInventory().addItem(new ItemStack(Material.LAVA_BUCKET)).values().forEach(itemStack -> + player.getWorld().dropItem(player.getLocation(), itemStack) + ); + } else { + itemInHand.setType(Material.LAVA_BUCKET); + } + } + + if (IridiumSkyblock.getInstance().getConfiguration().endPortalPick + && (event.getAction().equals(Action.LEFT_CLICK_BLOCK) && player.isSneaking()) + && event.getClickedBlock().getType().equals(Material.END_PORTAL_FRAME) + && (itemInHand.getType().name().contains("PICKAXE"))) { + + event.getClickedBlock().breakNaturally(); + + player.getWorld().dropItem(event.getClickedBlock().getLocation(), new ItemStack(Material.END_PORTAL_FRAME)); + removeAdjacentBlocks(event.getClickedBlock().getLocation(), XMaterial.END_PORTAL.parseMaterial(), new AtomicInteger(9)); + } + } + + public void removeAdjacentBlocks(Location location, Material targetMaterial, AtomicInteger iterationsLeft) { + if (iterationsLeft.get() <= 0) { + return; + } + + for (int xOffset = -1; xOffset <= 1; xOffset++) { + for (int yOffset = -1; yOffset <= 1; yOffset++) { + for (int zOffset = -1; zOffset <= 1; zOffset++) { + Location adjacentLocation = location.clone().add(xOffset, yOffset, zOffset); + Block block = adjacentLocation.getBlock(); + if (block.getType() == targetMaterial) { + block.breakNaturally(); + iterationsLeft.getAndDecrement(); + removeAdjacentBlocks(adjacentLocation, targetMaterial, iterationsLeft); + } + } + } } } diff --git a/src/main/java/com/iridium/iridiumskyblock/listeners/PlayerTeleportListener.java b/src/main/java/com/iridium/iridiumskyblock/listeners/PlayerTeleportListener.java index 9c59054cb..f3974b504 100644 --- a/src/main/java/com/iridium/iridiumskyblock/listeners/PlayerTeleportListener.java +++ b/src/main/java/com/iridium/iridiumskyblock/listeners/PlayerTeleportListener.java @@ -2,6 +2,7 @@ import com.iridium.iridiumskyblock.IridiumSkyblock; import org.bukkit.Bukkit; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerTeleportEvent; @@ -10,7 +11,12 @@ public class PlayerTeleportListener implements Listener { @EventHandler public void onPlayerTeleport(PlayerTeleportEvent event) { - Bukkit.getScheduler().runTask(IridiumSkyblock.getInstance(), () -> IridiumSkyblock.getInstance().getTeamManager().sendIslandBorder(event.getPlayer())); + Bukkit.getScheduler().runTask(IridiumSkyblock.getInstance(), () -> { + Player player = event.getPlayer(); + if(player == null) return; + + IridiumSkyblock.getInstance().getTeamManager().sendIslandBorder(player); + }); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/managers/BiomeManager.java b/src/main/java/com/iridium/iridiumskyblock/managers/BiomeManager.java index 0ec380b96..05c6e6771 100644 --- a/src/main/java/com/iridium/iridiumskyblock/managers/BiomeManager.java +++ b/src/main/java/com/iridium/iridiumskyblock/managers/BiomeManager.java @@ -31,21 +31,23 @@ public void buy(Player player, Biomes.BiomeItem biomeItem) { } if (!biomeOptional.isPresent()) { - player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noBiome) + player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noBiome .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix) - ); + )); return; } if (!island.isPresent()) { - player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().dontHaveTeam) + player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().dontHaveTeam .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix) - ); + )); return; } purchase(player, biomeItem); + IridiumSkyblock.getInstance().getCommands().biomeCommand.getCooldownProvider().applyCooldown(player); + IridiumSkyblock.getInstance().getIslandManager().setIslandBiome(island.get(), biomeOptional.get()); IridiumSkyblock.getInstance().getTeamManager().getTeamMembers(island.get()).stream().map(IridiumUser::getPlayer).forEach((teamMember) -> { if (teamMember != null) { diff --git a/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java b/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java index 10afc3463..381d16b3f 100644 --- a/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java +++ b/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java @@ -9,6 +9,8 @@ import com.iridium.iridiumcore.utils.Placeholder; import com.iridium.iridiumcore.utils.StringUtils; import com.iridium.iridiumskyblock.IridiumSkyblock; +import com.iridium.iridiumskyblock.api.IslandCreateEvent; +import com.iridium.iridiumskyblock.api.IslandDeleteEvent; import com.iridium.iridiumskyblock.configs.Schematics; import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.User; @@ -20,6 +22,7 @@ import com.iridium.iridiumteams.database.*; import com.iridium.iridiumteams.managers.TeamManager; import com.iridium.iridiumteams.missions.Mission; +import com.iridium.iridiumteams.missions.MissionData; import com.iridium.iridiumteams.missions.MissionType; import org.bukkit.*; import org.bukkit.block.Block; @@ -140,15 +143,23 @@ public CompletableFuture createTeam(@NotNull Player owner, String name) if (schematic == null) return null; User user = IridiumSkyblock.getInstance().getUserManager().getUser(owner); - Island island = new Island(name); + Schematics.SchematicConfig schematicConfig = IridiumSkyblock.getInstance().getSchematics().schematics.get(schematic); + + IslandCreateEvent islandCreateEvent = getIslandCreateEvent(user, name, schematicConfig).join(); + if (islandCreateEvent.isCancelled()) return null; + + owner.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().creatingIsland + .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix) + )); + Island island = new Island(islandCreateEvent.getIslandName()); IridiumSkyblock.getInstance().getDatabaseManager().registerIsland(island).join(); user.setTeam(island); user.setUserRank(Rank.OWNER.getId()); - generateIsland(island, schematic).join(); + generateIsland(island, islandCreateEvent.getSchematicConfig()).join(); Bukkit.getScheduler().runTask(IridiumSkyblock.getInstance(), () -> { teleport(owner, island.getHome(), island); IridiumSkyblock.getInstance().getNms().sendTitle(owner, IridiumSkyblock.getInstance().getConfiguration().islandCreateTitle, IridiumSkyblock.getInstance().getConfiguration().islandCreateSubTitle, 20, 40, 20); @@ -161,9 +172,19 @@ public CompletableFuture createTeam(@NotNull Player owner, String name) }); } - public CompletableFuture generateIsland(Island island, String schematic) { + private CompletableFuture getIslandCreateEvent(@NotNull User user, @Nullable String islandName, Schematics.@NotNull SchematicConfig schematicConfig) { + CompletableFuture completableFuture = new CompletableFuture<>(); + Bukkit.getScheduler().runTask(IridiumSkyblock.getInstance(), () -> { + IslandCreateEvent islandCreateEvent = new IslandCreateEvent(user, islandName, schematicConfig); + Bukkit.getPluginManager().callEvent(islandCreateEvent); + completableFuture.complete(islandCreateEvent); + + }); + return completableFuture; + } + + public CompletableFuture generateIsland(Island island, Schematics.SchematicConfig schematicConfig) { return CompletableFuture.runAsync(() -> { - Schematics.SchematicConfig schematicConfig = IridiumSkyblock.getInstance().getSchematics().schematics.get(schematic); setHome(island, schematicConfig); deleteIslandBlocks(island).join(); IridiumSkyblock.getInstance().getSchematicManager().pasteSchematic(island, schematicConfig).join(); @@ -229,14 +250,25 @@ private void deleteIslandBlocks(Island island, World world, int y, CompletableFu } @Override - public void deleteTeam(Island island, User user) { + public boolean deleteTeam(Island island, User user) { + IslandDeleteEvent islandDeleteEvent = new IslandDeleteEvent(island, user); + Bukkit.getPluginManager().callEvent(islandDeleteEvent); + if (islandDeleteEvent.isCancelled()) return false; + + if (IridiumSkyblock.getInstance().getConfiguration().removeIslandBlocksOnDelete) { + deleteIslandBlocks(island); + } + IridiumSkyblock.getInstance().getDatabaseManager().getIslandTableManager().delete(island); + IridiumSkyblock.getInstance().getIslandManager().clearTeamInventory(island); getMembersOnIsland(island).forEach(member -> PlayerUtils.teleportSpawn(member.getPlayer())); + + return true; } @Override - public boolean getTeamPermission(Island island, int rank, String permission) { + public synchronized boolean getTeamPermission(Island island, int rank, String permission) { if (rank == Rank.OWNER.getId()) return true; return IridiumSkyblock.getInstance().getDatabaseManager().getPermissionsTableManager().getEntry(new TeamPermission(island, permission, rank, true)) .map(TeamPermission::isAllowed) @@ -345,7 +377,7 @@ public synchronized TeamSetting getTeamSetting(Island island, String settingKey) } @Override - public TeamEnhancement getTeamEnhancement(Island island, String enhancementName) { + public synchronized TeamEnhancement getTeamEnhancement(Island island, String enhancementName) { Optional teamEnhancement = IridiumSkyblock.getInstance().getDatabaseManager().getEnhancementTableManager().getEntry(new TeamEnhancement(island, enhancementName, 0)); if (teamEnhancement.isPresent()) { return teamEnhancement.get(); @@ -460,7 +492,7 @@ public List getTeamMissions(Island island) { } @Override - public TeamMission getTeamMission(Island island, String missionName) { + public synchronized TeamMission getTeamMission(Island island, String missionName) { Mission mission = IridiumSkyblock.getInstance().getMissions().missions.get(missionName); LocalDateTime localDateTime = IridiumSkyblock.getInstance().getMissionManager().getExpirationTime(mission == null ? MissionType.ONCE : mission.getMissionType(), LocalDateTime.now()); @@ -469,13 +501,15 @@ public TeamMission getTeamMission(Island island, String missionName) { if (teamMission.isPresent()) { return teamMission.get(); } else { + //TODO need to consider reworking this, it could generate some lag + IridiumSkyblock.getInstance().getDatabaseManager().getTeamMissionTableManager().save(newTeamMission); IridiumSkyblock.getInstance().getDatabaseManager().getTeamMissionTableManager().addEntry(newTeamMission); return newTeamMission; } } @Override - public TeamMissionData getTeamMissionData(TeamMission teamMission, int missionIndex) { + public synchronized TeamMissionData getTeamMissionData(TeamMission teamMission, int missionIndex) { Optional teamMissionData = IridiumSkyblock.getInstance().getDatabaseManager().getTeamMissionDataTableManager().getEntry(new TeamMissionData(teamMission, missionIndex)); if (teamMissionData.isPresent()) { return teamMissionData.get(); @@ -487,16 +521,19 @@ public TeamMissionData getTeamMissionData(TeamMission teamMission, int missionIn } @Override - public void deleteTeamMission(TeamMission teamMission) { - IridiumSkyblock.getInstance().getDatabaseManager().getTeamMissionTableManager().delete(teamMission); + public List getTeamMissionData(TeamMission teamMission) { + MissionData missionData = IridiumSkyblock.getInstance().getMissions().missions.get(teamMission.getMissionName()).getMissionData().get(teamMission.getMissionLevel()); + + List list = new ArrayList<>(); + for (int i = 0; i < missionData.getMissions().size(); i++) { + list.add(getTeamMissionData(teamMission, i)); + } + return list; } @Override - public void deleteTeamMissionData(TeamMission teamMission) { - List teamMissionDataList = IridiumSkyblock.getInstance().getDatabaseManager().getTeamMissionDataTableManager().getEntries().stream() - .filter(teamMissionData -> teamMissionData.getMissionID() == teamMission.getId()) - .collect(Collectors.toList()); - IridiumSkyblock.getInstance().getDatabaseManager().getTeamMissionDataTableManager().delete(teamMissionDataList); + public void deleteTeamMission(TeamMission teamMission) { + IridiumSkyblock.getInstance().getDatabaseManager().getTeamMissionTableManager().delete(teamMission); } @Override @@ -582,7 +619,7 @@ public boolean teleport(Player player, Location location, Island team) { @Override public void handleBlockBreakOutsideTerritory(BlockBreakEvent blockEvent) { - if(isInSkyblockWorld(blockEvent.getBlock().getWorld())){ + if (isInSkyblockWorld(blockEvent.getBlock().getWorld())) { blockEvent.getPlayer().sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotBreakBlocks .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix) )); @@ -592,7 +629,7 @@ public void handleBlockBreakOutsideTerritory(BlockBreakEvent blockEvent) { @Override public void handleBlockPlaceOutsideTerritory(BlockPlaceEvent blockEvent) { - if(isInSkyblockWorld(blockEvent.getBlock().getWorld())){ + if (isInSkyblockWorld(blockEvent.getBlock().getWorld())) { blockEvent.getPlayer().sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotPlaceBlocks .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix) )); @@ -600,4 +637,17 @@ public void handleBlockPlaceOutsideTerritory(BlockPlaceEvent blockEvent) { } } + public void clearTeamInventory(Island island) { + + if (IridiumSkyblock.getInstance().getConfiguration().clearInventoryOnRegen) { + IridiumSkyblock.getInstance().getIslandManager().getMembersOnIsland(island).forEach(member -> + member.getPlayer().getInventory().clear()); + } + + if (IridiumSkyblock.getInstance().getConfiguration().clearEnderChestOnRegen) { + IridiumSkyblock.getInstance().getIslandManager().getMembersOnIsland(island).forEach(member -> + member.getPlayer().getEnderChest().clear()); + } + } + } diff --git a/src/main/java/com/iridium/iridiumskyblock/managers/tablemanagers/TableManager.java b/src/main/java/com/iridium/iridiumskyblock/managers/tablemanagers/TableManager.java index e4ef83b47..2eed5d557 100644 --- a/src/main/java/com/iridium/iridiumskyblock/managers/tablemanagers/TableManager.java +++ b/src/main/java/com/iridium/iridiumskyblock/managers/tablemanagers/TableManager.java @@ -1,6 +1,5 @@ package com.iridium.iridiumskyblock.managers.tablemanagers; -import com.iridium.iridiumskyblock.IridiumSkyblock; import com.iridium.iridiumskyblock.SortedList; import com.iridium.iridiumteams.database.DatabaseObject; import com.j256.ormlite.dao.Dao; @@ -36,12 +35,8 @@ public void save() { List entryList = new ArrayList<>(entries); for (T t : entryList) { if (!t.isChanged()) continue; - try { - dao.createOrUpdate(t); - t.setChanged(false); - } catch (Exception exception) { - IridiumSkyblock.getInstance().getLogger().warning("Failed to save " + t.getClass().getSimpleName() + " to database: " + exception.getMessage()); - } + dao.createOrUpdate(t); + t.setChanged(false); } dao.commit(getDatabaseConnection()); } catch (SQLException throwables) { @@ -49,6 +44,17 @@ public void save() { } } + public void save(T t) { + try { + if (!t.isChanged()) return; + dao.createOrUpdate(t); + dao.commit(getDatabaseConnection()); + t.setChanged(false); + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + } + public void addEntry(T t) { entries.add(t); }