Allow expanding the island WorldBorderLevel

This commit is contained in:
Len 2024-02-17 21:55:17 +01:00
parent 05926df76e
commit 333e8e9b8d
6 changed files with 95 additions and 12 deletions

View File

@ -26,6 +26,7 @@ public class CometSkyBlockPlugin extends JavaPlugin implements CometSkyBlockAPI
@Getter private ConfigurationContainer<MessageConfiguration> messagesConfiguration;
@Getter private ConfigurationContainer<ChallengesConfiguration> challengesConfiguration;
@Getter private ConfigurationContainer<CobblestoneGeneratorConfiguration> cobblestoneGeneratorConfiguration;
@Getter private ConfigurationContainer<WorldBorderConfiguration> worldBorderConfiguration;
@Getter private IslandManager islandManager;
@Getter private MasterWorldGenerator worldGenerator;
@ -75,6 +76,7 @@ public class CometSkyBlockPlugin extends JavaPlugin implements CometSkyBlockAPI
messagesConfiguration = ConfigurationContainer.load(logger, path, MessageConfiguration.class, "messages");
challengesConfiguration = ConfigurationContainer.load(logger, path, ChallengesConfiguration.class, "challenges");
cobblestoneGeneratorConfiguration = ConfigurationContainer.load(logger, path, CobblestoneGeneratorConfiguration.class, "coblestonegenerator");
worldBorderConfiguration = ConfigurationContainer.load(logger, path, WorldBorderConfiguration.class, "worldborder");
}
public void loadCommands() {

View File

@ -30,6 +30,13 @@ public class MessageConfiguration implements Configuration {
String upgraded = "Your cobblestone generation is now level <level>.";
}
WorldBorder worldBorder = new WorldBorder();
@ConfigSerializable @Getter
public static class WorldBorder {
String requiredLevel = "You must reach islandlevel <islandlevel> before you can expand the worldborder.";
String upgraded = "You have expanded your worldborder by <range> blocks.";
}
Level level = new Level();
@ConfigSerializable @Getter
public static class Level {

View File

@ -0,0 +1,16 @@
package com.alttd.cometskyblock.configuration;
import com.alttd.cometskyblock.island.WorldBorderLevel;
import lombok.Getter;
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
import java.util.ArrayList;
import java.util.List;
@Getter
@ConfigSerializable
@SuppressWarnings({"CanBeFinal", "FieldMayBeFinal"})
public class WorldBorderConfiguration implements Configuration {
private List<WorldBorderLevel> levels = new ArrayList<>();
}

View File

@ -172,6 +172,15 @@ public class Island extends YamlConfiguration {
save();
}
public int worldBorderLevel() {
return getInt("island.worldborder.level", 0);
}
public void worldBorderLevel(int level) {
set("island.worldborder.level", level);
save();
}
public void teleport(Player player) {
World islandWorld = CometSkyBlockPlugin.instance().worldGenerator().loadIslandWorld(worldName());
if (islandWorld == null) {

View File

@ -0,0 +1,15 @@
package com.alttd.cometskyblock.island;
import lombok.Getter;
import org.bukkit.Material;
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
@Getter
@ConfigSerializable
public class WorldBorderLevel {
private int level;
private int islandLevel;
private int range;
}

View File

@ -5,6 +5,7 @@ import com.alttd.cometskyblock.configuration.MessageConfiguration;
import com.alttd.cometskyblock.gui.GUIInventory;
import com.alttd.cometskyblock.island.CobblestoneGeneratorLevel;
import com.alttd.cometskyblock.island.Island;
import com.alttd.cometskyblock.island.WorldBorderLevel;
import com.alttd.cometskyblock.util.Experience;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
@ -35,22 +36,34 @@ public class UpgradesGUI extends GUIInventory {
MessageConfiguration.Island islandMessages = CometSkyBlockPlugin.instance().messagesConfiguration().get().island();
// Todo - move to handlers, add costs, validation ...
// WorldBorder
addButton(10, createMenuButton(Material.GRASS_BLOCK, "Expand The world border", new ArrayList<>(), event -> {
player.sendRichMessage("<red>This feature is not implemented yet - please wait for a future update.");
// World islandWorld = CometSkyBlockPlugin.instance().worldGenerator().loadIslandWorld(island.worldName());
// if (islandWorld == null) {
// player.sendRichMessage("<red>Could not load islandWorld. Contact an administrator");
// return;
// }
// WorldBorder worldBorder = islandWorld.getWorldBorder();
// worldBorder.setSize(worldBorder.getSize() + 250);
addButton(10, createMenuButton(Material.GRASS_BLOCK, "Expand the world border", new ArrayList<>(), event -> {
int requiredIslandLevel = getRequiredIslandWorldBorderLevel(island.worldBorderLevel() + 1);
if (island.level() < requiredIslandLevel) {
player.sendRichMessage(islandMessages.worldBorder().requiredLevel(), Placeholder.parsed("islandlevel", "<gold>" + requiredIslandLevel + "</gold>"));
return;
}
World islandWorld = CometSkyBlockPlugin.instance().worldGenerator().loadIslandWorld(island.worldName());
if (islandWorld == null) {
player.sendRichMessage("<red>Could not load islandWorld. Contact an administrator");
return;
}
WorldBorder worldBorder = islandWorld.getWorldBorder();
island.worldBorderLevel(island.worldBorderLevel() + 1);
WorldBorderLevel worldBorderLevel = getWorldBorderLevel(island.worldBorderLevel());
if (worldBorderLevel == null) {
player.sendRichMessage("<red>You can not expand your world border.");
return;
}
worldBorder.setSize(worldBorder.getSize() + worldBorderLevel.range());
player.sendRichMessage(islandMessages.worldBorder().upgraded(), Placeholder.parsed("range", "<gold>" + worldBorderLevel.range() + "</gold>"));
decorate(player);
}));
// Cobble Gen
addButton(11, createMenuButton(Material.COBBLESTONE, "Upgrade your cobble stone generator", List.of(
"<white>Level: <gold>" + island.cobblegenLevel() + "</gold>",
"<white>Ore tier: <gold>" + getOreTier(island.cobblegenLevel()) + "</gold>"
), event -> {
int requiredIslandLevel = getRequiredIslandLevel(island.cobblegenLevel() + 1);
int requiredIslandLevel = getRequiredIslandCobbleLevel(island.cobblegenLevel() + 1);
if (island.level() < requiredIslandLevel) {
player.sendRichMessage(islandMessages.cobbeGen().requiredLevel(), Placeholder.parsed("islandlevel", "<gold>" + requiredIslandLevel + "</gold>"));
return;
@ -82,7 +95,7 @@ public class UpgradesGUI extends GUIInventory {
super.decorate(player);
}
Integer getRequiredIslandLevel(int generatorLevel) {
Integer getRequiredIslandCobbleLevel(int generatorLevel) {
CobblestoneGeneratorLevel level = getLevel(generatorLevel);
return level != null ? level.islandLevel() : 0;
}
@ -93,7 +106,7 @@ public class UpgradesGUI extends GUIInventory {
}
CometSkyBlockPlugin plugin = CometSkyBlockPlugin.instance();
if (plugin.cobblestoneGeneratorConfiguration().get().levels().size() < generatorLevel) {
return getLevel(generatorLevel - 1);
return null;
}
for (CobblestoneGeneratorLevel level : plugin.cobblestoneGeneratorConfiguration().get().levels()) {
if (level.level() == generatorLevel) {
@ -107,4 +120,25 @@ public class UpgradesGUI extends GUIInventory {
CobblestoneGeneratorLevel level = getLevel(generatorLevel);
return level != null ? level.type() : Material.COBBLESTONE;
}
Integer getRequiredIslandWorldBorderLevel(int generatorLevel) {
WorldBorderLevel level = getWorldBorderLevel(generatorLevel);
return level != null ? level.islandLevel() : 0;
}
WorldBorderLevel getWorldBorderLevel(int generatorLevel) {
if (generatorLevel == 0) {
return null;
}
CometSkyBlockPlugin plugin = CometSkyBlockPlugin.instance();
if (plugin.worldBorderConfiguration().get().levels().size() < generatorLevel) {
return null;
}
for (WorldBorderLevel level : plugin.worldBorderConfiguration().get().levels()) {
if (level.level() == generatorLevel) {
return level;
}
}
return null;
}
}