diff --git a/buildsystem-core/src/main/java/com/eintosti/buildsystem/config/WorldConfig.java b/buildsystem-core/src/main/java/com/eintosti/buildsystem/config/WorldConfig.java index ad69e8ec..97f06be8 100644 --- a/buildsystem-core/src/main/java/com/eintosti/buildsystem/config/WorldConfig.java +++ b/buildsystem-core/src/main/java/com/eintosti/buildsystem/config/WorldConfig.java @@ -44,7 +44,7 @@ public void loadWorlds(WorldManager worldManager) { worldManager.getBuildWorlds().forEach(world -> { String worldName = world.getName(); - worldManager.generateBukkitWorld(worldName, world.getType(), world.getChunkGenerator()); + worldManager.generateBukkitWorld(worldName, world.getType(), world.getDifficulty(), world.getChunkGenerator()); if (world.getMaterial() == XMaterial.PLAYER_HEAD) { plugin.getSkullCache().cacheSkull(worldName); diff --git a/buildsystem-core/src/main/java/com/eintosti/buildsystem/inventory/EditInventory.java b/buildsystem-core/src/main/java/com/eintosti/buildsystem/inventory/EditInventory.java index adb88029..7ba11947 100644 --- a/buildsystem-core/src/main/java/com/eintosti/buildsystem/inventory/EditInventory.java +++ b/buildsystem-core/src/main/java/com/eintosti/buildsystem/inventory/EditInventory.java @@ -71,7 +71,8 @@ public Inventory getInventory(Player player, BuildWorld buildWorld) { addVisibilityItem(inventory, buildWorld, player); addSettingsItem(inventory, 33, XMaterial.TRIPWIRE_HOOK, buildWorld.isBlockInteractions(), plugin.getString("worldeditor_blockinteractions_item"), plugin.getStringList("worldeditor_blockinteractions_lore")); inventoryManager.addItemStack(inventory, 38, XMaterial.FILLED_MAP, plugin.getString("worldeditor_gamerules_item"), plugin.getStringList("worldeditor_gamerules_lore")); - inventoryManager.addItemStack(inventory, 39, inventoryManager.getStatusItem(buildWorld.getStatus()), plugin.getString("worldeditor_status_item"), getStatusLore(buildWorld)); + addDifficultyItem(inventory, buildWorld); + inventoryManager.addItemStack(inventory, 40, inventoryManager.getStatusItem(buildWorld.getStatus()), plugin.getString("worldeditor_status_item"), getStatusLore(buildWorld)); inventoryManager.addItemStack(inventory, 41, XMaterial.ANVIL, plugin.getString("worldeditor_project_item"), getProjectLore(buildWorld)); inventoryManager.addItemStack(inventory, 42, XMaterial.PAPER, plugin.getString("worldeditor_permission_item"), getPermissionLore(buildWorld)); @@ -121,9 +122,8 @@ private void addTimeItem(Inventory inventory, BuildWorld buildWorld) { XMaterial xMaterial = XMaterial.WHITE_STAINED_GLASS; String value = plugin.getString("worldeditor_time_lore_unknown"); - BuildWorld.Time time = getWorldTime(bukkitWorld); - switch (time) { + switch (getWorldTime(bukkitWorld)) { case SUNRISE: xMaterial = XMaterial.ORANGE_STAINED_GLASS; value = plugin.getString("worldeditor_time_lore_sunrise"); @@ -191,6 +191,30 @@ private void addVisibilityItem(Inventory inventory, BuildWorld buildWorld, Playe inventoryManager.addItemStack(inventory, slot, xMaterial, displayName, lore); } + private void addDifficultyItem(Inventory inventory, BuildWorld buildWorld) { + XMaterial xMaterial; + + switch (buildWorld.getDifficulty()) { + case EASY: + xMaterial = XMaterial.GOLDEN_HELMET; + break; + case NORMAL: + xMaterial = XMaterial.IRON_HELMET; + break; + case HARD: + xMaterial = XMaterial.DIAMOND_HELMET; + break; + default: + xMaterial = XMaterial.LEATHER_HELMET; + break; + } + + ArrayList lore = new ArrayList<>(); + plugin.getStringList("worldeditor_difficulty_lore").forEach(line -> lore.add(line.replace("%difficulty%", buildWorld.getDifficultyName()))); + + inventoryManager.addItemStack(inventory, 39, xMaterial, plugin.getString("worldeditor_difficulty_item"), lore); + } + private List getStatusLore(BuildWorld buildWorld) { List lore = new ArrayList<>(); for (String line : plugin.getStringList("worldeditor_status_lore")) { @@ -286,6 +310,10 @@ public void onInventoryClick(InventoryClickEvent event) { plugin.getGameRuleInventory().openInventory(player, buildWorld); return; case 39: + buildWorld.cycleDifficulty(); + buildWorld.getWorld().setDifficulty(buildWorld.getDifficulty()); + break; + case 40: XSound.ENTITY_CHICKEN_EGG.play(player); plugin.getStatusInventory().openInventory(player); return; diff --git a/buildsystem-core/src/main/java/com/eintosti/buildsystem/manager/WorldManager.java b/buildsystem-core/src/main/java/com/eintosti/buildsystem/manager/WorldManager.java index 9aeb0078..cb02d3d8 100644 --- a/buildsystem-core/src/main/java/com/eintosti/buildsystem/manager/WorldManager.java +++ b/buildsystem-core/src/main/java/com/eintosti/buildsystem/manager/WorldManager.java @@ -26,6 +26,7 @@ import com.eintosti.buildsystem.util.external.PlayerChatInput; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.Difficulty; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; @@ -308,7 +309,7 @@ public boolean createCustomWorld(Player player, String worldName, boolean privat player.sendMessage(plugin.getString("worlds_world_creation_started") .replace("%world%", buildWorld.getName()) .replace("%type%", buildWorld.getTypeName())); - generateBukkitWorld(worldName, buildWorld.getType(), chunkGenerator); + generateBukkitWorld(worldName, buildWorld.getType(), buildWorld.getDifficulty(), chunkGenerator); player.sendMessage(plugin.getString("worlds_creation_finished")); }); return true; @@ -358,7 +359,7 @@ private boolean createTemplateWorld(Player player, String worldName, String temp */ private void finishPreparationsAndGenerate(BuildWorld buildWorld) { WorldType worldType = buildWorld.getType(); - World bukkitWorld = generateBukkitWorld(buildWorld.getName(), worldType); + World bukkitWorld = generateBukkitWorld(buildWorld.getName(), worldType, buildWorld.getDifficulty(), buildWorld.getChunkGenerator()); switch (worldType) { case VOID: @@ -381,10 +382,11 @@ private void finishPreparationsAndGenerate(BuildWorld buildWorld) { * * @param worldName The name of the world * @param worldType The world type + * @param difficulty The world's difficulty * @param chunkGenerators Custom chunk generator to be used, if any * @return The world object */ - public World generateBukkitWorld(String worldName, WorldType worldType, ChunkGenerator... chunkGenerators) { + public World generateBukkitWorld(String worldName, WorldType worldType, Difficulty difficulty, ChunkGenerator... chunkGenerators) { WorldCreator worldCreator = new WorldCreator(worldName); org.bukkit.WorldType bukkitWorldType; @@ -434,7 +436,7 @@ public World generateBukkitWorld(String worldName, WorldType worldType, ChunkGen World bukkitWorld = Bukkit.createWorld(worldCreator); if (bukkitWorld != null) { - bukkitWorld.setDifficulty(configValues.getWorldDifficulty()); + bukkitWorld.setDifficulty(difficulty); bukkitWorld.setTime(configValues.getNoonTime()); bukkitWorld.getWorldBorder().setSize(configValues.getWorldBorderSize()); bukkitWorld.setKeepSpawnInMemory(configValues.isTeleportAfterCreation()); @@ -516,7 +518,7 @@ public void importWorld(Player player, String worldName, Generator generator, St false ); buildWorlds.add(buildWorld); - generateBukkitWorld(worldName, generator.getWorldType(), chunkGenerator); + generateBukkitWorld(worldName, generator.getWorldType(), buildWorld.getDifficulty(), chunkGenerator); player.sendMessage(plugin.getString("worlds_import_finished")); if (configValues.isTeleportAfterCreation()) { @@ -552,8 +554,9 @@ public void run() { } long creation = FileUtils.getDirectoryCreation(new File(Bukkit.getWorldContainer(), worldName)); - buildWorlds.add(new BuildWorld(plugin, worldName, "-", null, WorldType.IMPORTED, creation, false)); - generateBukkitWorld(worldName, WorldType.VOID); + BuildWorld buildWorld = new BuildWorld(plugin, worldName, "-", null, WorldType.IMPORTED, creation, false); + buildWorlds.add(buildWorld); + generateBukkitWorld(worldName, WorldType.VOID, buildWorld.getDifficulty()); player.sendMessage(plugin.getString("worlds_importall_world_imported").replace("%world%", worldName)); if (!(worldsImported.get() < worlds)) { @@ -709,7 +712,7 @@ public void renameWorld(Player player, BuildWorld buildWorld, String newName) { FileUtils.deleteDirectory(oldWorldFile); buildWorld.setName(newName); - World newWorld = generateBukkitWorld(buildWorld.getName(), buildWorld.getType(), buildWorld.getChunkGenerator()); + World newWorld = generateBukkitWorld(buildWorld.getName(), buildWorld.getType(), buildWorld.getDifficulty(), buildWorld.getChunkGenerator()); Location spawnLocation = oldWorld.getSpawnLocation(); spawnLocation.setWorld(newWorld); @@ -850,15 +853,11 @@ public BuildWorld loadWorld(String worldName) { boolean blockPlacement = !configuration.isBoolean("worlds." + worldName + ".block-placement") || configuration.getBoolean("worlds." + worldName + ".block-placement"); boolean blockInteractions = !configuration.isBoolean("worlds." + worldName + ".block-interactions") || configuration.getBoolean("worlds." + worldName + ".block-interactions"); boolean buildersEnabled = configuration.isBoolean("worlds." + worldName + ".builders-enabled") && configuration.getBoolean("worlds." + worldName + ".builders-enabled"); + Difficulty difficulty = Difficulty.valueOf(configuration.getString("worlds." + worldName + ".difficulty", "PEACEFUL").toUpperCase()); List builders = parseBuilders(configuration, worldName); String chunkGeneratorString = configuration.getString("worlds." + worldName + ".chunk-generator"); ChunkGenerator chunkGenerator = parseChunkGenerator(configuration, worldName); - if (worldType == WorldType.PRIVATE) { - privateWorld = true; - worldType = WorldType.FLAT; - } - BuildWorld buildWorld = new BuildWorld( plugin, worldName, @@ -879,6 +878,7 @@ public BuildWorld loadWorld(String worldName) { blockPlacement, blockInteractions, buildersEnabled, + difficulty, builders, chunkGenerator, chunkGeneratorString diff --git a/buildsystem-core/src/main/java/com/eintosti/buildsystem/object/world/BuildWorld.java b/buildsystem-core/src/main/java/com/eintosti/buildsystem/object/world/BuildWorld.java index bd88130f..7095a6e5 100644 --- a/buildsystem-core/src/main/java/com/eintosti/buildsystem/object/world/BuildWorld.java +++ b/buildsystem-core/src/main/java/com/eintosti/buildsystem/object/world/BuildWorld.java @@ -20,6 +20,7 @@ import com.eintosti.buildsystem.util.exception.UnexpectedEnumValueException; import org.bukkit.Bukkit; import org.bukkit.Chunk; +import org.bukkit.Difficulty; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.configuration.serialization.ConfigurationSerializable; @@ -70,6 +71,7 @@ public class BuildWorld implements ConfigurationSerializable { private boolean blockPlacement; private boolean blockInteractions; private boolean buildersEnabled; + private Difficulty difficulty; private long seconds; private boolean loaded; @@ -107,6 +109,7 @@ public BuildWorld( this.blockPlacement = configValues.isWorldBlockPlacement(); this.blockInteractions = configValues.isWorldBlockInteractions(); this.buildersEnabled = isPrivate(); + this.difficulty = configValues.getWorldDifficulty(); this.chunkGeneratorName = (chunkGeneratorName != null && chunkGeneratorName.length > 0) ? chunkGeneratorName[0] : null; InventoryManager inventoryManager = plugin.getInventoryManager(); @@ -169,6 +172,7 @@ public BuildWorld( boolean blockPlacement, boolean blockInteractions, boolean buildersEnabled, + Difficulty difficulty, List builders, ChunkGenerator chunkGenerator, String chunkGeneratorName @@ -194,6 +198,7 @@ public BuildWorld( this.blockPlacement = blockPlacement; this.blockInteractions = blockInteractions; this.buildersEnabled = buildersEnabled; + this.difficulty = difficulty; this.builders = builders; this.chunkGenerator = chunkGenerator; this.chunkGeneratorName = chunkGeneratorName; @@ -201,6 +206,15 @@ public BuildWorld( manageUnload(); } + /** + * Get the world linked to this object. + * + * @return The bukkit world + */ + public World getWorld() { + return Bukkit.getWorld(name); + } + /** * Get the name of the world. * @@ -378,7 +392,7 @@ public void setStatus(WorldStatus worldStatus) { * Get the display name of a {@link WorldStatus}. * * @return the status's display name - * @see BuildWorld#getStatus() () + * @see BuildWorld#getStatus() */ public String getStatusName() { switch (worldStatus) { @@ -608,6 +622,56 @@ public void setBlockInteractions(boolean blockInteractions) { this.blockInteractions = blockInteractions; } + /** + * Gets the world's difficulty + * + * @return the difficulty + */ + public Difficulty getDifficulty() { + return difficulty; + } + + /** + * Get the display name of a {@link Difficulty}. + * + * @return the difficulty's display name + * @see BuildWorld#getDifficulty() + */ + public String getDifficultyName() { + switch (difficulty) { + case PEACEFUL: + return plugin.getString("difficulty_peaceful"); + case EASY: + return plugin.getString("difficulty_easy"); + case NORMAL: + return plugin.getString("difficulty_normal"); + case HARD: + return plugin.getString("difficulty_hard"); + default: + return "-"; + } + } + + /** + * Cycles to the next {@link Difficulty}. + */ + public void cycleDifficulty() { + switch (difficulty) { + case PEACEFUL: + this.difficulty = Difficulty.EASY; + break; + case EASY: + this.difficulty = Difficulty.NORMAL; + break; + case NORMAL: + this.difficulty = Difficulty.HARD; + break; + case HARD: + this.difficulty = Difficulty.PEACEFUL; + break; + } + } + /** * If enabled, only {@link Builder}s can break and place blocks in the world. * @@ -868,7 +932,7 @@ public void load() { } plugin.getLogger().info("*** Loading world \"" + name + "\" ***"); - plugin.getWorldManager().generateBukkitWorld(name, worldType, chunkGenerator); + plugin.getWorldManager().generateBukkitWorld(name, worldType, difficulty, chunkGenerator); this.loaded = true; resetUnloadTask(); @@ -893,6 +957,7 @@ public void load() { world.put("block-breaking", isBlockBreaking()); world.put("block-placement", isBlockPlacement()); world.put("block-interactions", isBlockInteractions()); + world.put("difficulty", getDifficulty().toString()); world.put("builders-enabled", isBuilders()); world.put("builders", saveBuilders()); if (customSpawn != null) { diff --git a/buildsystem-core/src/main/java/com/eintosti/buildsystem/util/Messages.java b/buildsystem-core/src/main/java/com/eintosti/buildsystem/util/Messages.java index e73d3f26..8b768eb2 100644 --- a/buildsystem-core/src/main/java/com/eintosti/buildsystem/util/Messages.java +++ b/buildsystem-core/src/main/java/com/eintosti/buildsystem/util/Messages.java @@ -476,7 +476,7 @@ public void createMessageFile() { setMessage(sb, config, "type_template", "Template"); setMessage(sb, config, "type_private", "Private"); addLine(sb, ""); - addLine(sb, "# Worlds Status"); + addLine(sb, "# World Status"); setMessage(sb, config, "status_title", "&8Status &7» &3%world%"); setMessage(sb, config, "status_not_started", "&cNot Started"); setMessage(sb, config, "status_in_progress", "&6In Progress"); @@ -485,6 +485,12 @@ public void createMessageFile() { setMessage(sb, config, "status_archive", "&9Archive"); setMessage(sb, config, "status_hidden", "&fHidden"); addLine(sb, ""); + addLine(sb, "# World Difficulty"); + setMessage(sb, config, "difficulty_peaceful", "&fPeaceful"); + setMessage(sb, config, "difficulty_easy", "&aEasy"); + setMessage(sb, config, "difficulty_normal", "&6Normal"); + setMessage(sb, config, "difficulty_hard", "&cHard"); + addLine(sb, ""); addLine(sb, "# Delete World"); setMessage(sb, config, "delete_title", "&3» &8Delete World"); setMessage(sb, config, "delete_world_name", "&e%world%"); @@ -549,19 +555,22 @@ public void createMessageFile() { setList(sb, config, "worldeditor_visibility_lore_private", Arrays.asList("&7&oChange the world's visibility", "", "&7&nCurrently&7: &bPrivate")); addLine(sb, ""); setMessage(sb, config, "worldeditor_mobai_item", "&bMob AI"); - setList(sb, config, "worldeditor_mobai_lore", Arrays.asList("&7&oToggle where or not mobs", "&7&ohave an AI.")); + setList(sb, config, "worldeditor_mobai_lore", Arrays.asList("&7&oToggle whether mobs have an AI.")); addLine(sb, ""); setMessage(sb, config, "worldeditor_blockinteractions_item", "&bBlock Interactions"); - setList(sb, config, "worldeditor_blockinteractions_lore", Arrays.asList("&7&oToggle whether or not interactions", "&7&owith blocks are cancelled.")); + setList(sb, config, "worldeditor_blockinteractions_lore", Arrays.asList("&7&oToggle whether interactions", "&7&owith blocks are cancelled.")); + addLine(sb, ""); + setMessage(sb, config, "worldeditor_difficulty_item", "&bDifficulty"); + setList(sb, config, "worldeditor_difficulty_lore", Arrays.asList("&7&oChange the world's difficulty.", "", "&7&nCurrently&7: %difficulty%")); addLine(sb, ""); setMessage(sb, config, "worldeditor_status_item", "&bStatus"); - setList(sb, config, "worldeditor_status_lore", Arrays.asList("&7&oChange the world's current", "&7&ostatus.", "", "&7&nCurrently&7: %status%")); + setList(sb, config, "worldeditor_status_lore", Arrays.asList("&7&oChange the world's status.", "", "&7&nCurrently&7: %status%")); addLine(sb, ""); setMessage(sb, config, "worldeditor_project_item", "&bProject"); - setList(sb, config, "worldeditor_project_lore", Arrays.asList("&7&oChange the world's current", "&7&oproject.", "", "&7&nCurrently&7: &b%project%")); + setList(sb, config, "worldeditor_project_lore", Arrays.asList("&7&oChange the world's project.", "", "&7&nCurrently&7: &b%project%")); addLine(sb, ""); setMessage(sb, config, "worldeditor_permission_item", "&bPermission"); - setList(sb, config, "worldeditor_permission_lore", Arrays.asList("&7&oChange the world's current", "&7&opermission.", "", "&7&nCurrently&7: &b%permission%")); + setList(sb, config, "worldeditor_permission_lore", Arrays.asList("&7&oChange the world's permission.", "", "&7&nCurrently&7: &b%permission%")); addLine(sb, ""); addLine(sb, "# Settings"); setMessage(sb, config, "settings_title", "&3» &8Settings"); diff --git a/gradle.properties b/gradle.properties index 37681e4b..5aa7025a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ group=com.eintosti -version=2.18.6-dev +version=2.18.6 org.gradle.daemon=true org.gradle.caching=true org.gradle.parallel=true