From 2bc1b46beb4fa29cefc49ca8d19950ca64446437 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Wed, 24 Apr 2019 16:15:18 +0300 Subject: [PATCH 1/2] Init 1.4.1 CaveBlock version. --- pom.xml | 7 ++++--- src/main/resources/addon.yml | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 8831cb1..78c6b86 100644 --- a/pom.xml +++ b/pom.xml @@ -50,8 +50,8 @@ ${build.version}-SNAPSHOT - 1.4.0 - 0 + 1.4.1 + -LOCAL @@ -66,7 +66,7 @@ - ${env.BUILD_NUMBER} + -#${env.BUILD_NUMBER} @@ -84,6 +84,7 @@ ${build.version} + diff --git a/src/main/resources/addon.yml b/src/main/resources/addon.yml index aebe7ff..c1658e6 100644 --- a/src/main/resources/addon.yml +++ b/src/main/resources/addon.yml @@ -1,6 +1,6 @@ name: CaveBlock main: world.bentobox.caveblock.CaveBlock -version: ${version}-#${build.number} +version: ${version}${build.number} authors: BONNe From 418eb7bef2c5c692d42b99a462f92a1840f9f574 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Wed, 24 Apr 2019 17:39:10 +0300 Subject: [PATCH 2/2] Fix issue when alternative teleports did not work. (#4). There was a mistake with checking if position is changed in Y coordinate. It took from position and compare it to from position, so always fails. This issue has been fixed now. Also to improve ability to change these settings on the fly, I add them as world protection flags, so admins can enable and disable them via config. --- .../world/bentobox/caveblock/CaveBlock.java | 48 ++++++- .../world/bentobox/caveblock/Settings.java | 83 ----------- .../listeners/CustomHeightLimitations.java | 135 +++++++++++------- src/main/resources/config.yml | 14 -- src/main/resources/locales/en-US.yml | 12 +- 5 files changed, 135 insertions(+), 157 deletions(-) diff --git a/src/main/java/world/bentobox/caveblock/CaveBlock.java b/src/main/java/world/bentobox/caveblock/CaveBlock.java index 52d352e..811932d 100644 --- a/src/main/java/world/bentobox/caveblock/CaveBlock.java +++ b/src/main/java/world/bentobox/caveblock/CaveBlock.java @@ -1,6 +1,7 @@ package world.bentobox.caveblock; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.WorldCreator; import org.bukkit.WorldType; @@ -10,6 +11,7 @@ import org.eclipse.jdt.annotation.NonNull; import world.bentobox.bentobox.api.addons.GameModeAddon; import world.bentobox.bentobox.api.configuration.Config; import world.bentobox.bentobox.api.configuration.WorldSettings; +import world.bentobox.bentobox.api.flags.Flag; import world.bentobox.caveblock.commands.AdminCommand; import world.bentobox.caveblock.commands.IslandCommand; import world.bentobox.caveblock.generators.ChunkGeneratorWorld; @@ -41,6 +43,16 @@ public class CaveBlock extends GameModeAddon { this.playerCommand = new IslandCommand(this); this.adminCommand = new AdminCommand(this); + + // Register flags + CaveBlock.ALTERNATIVE_TELEPORT_FLAG.addGameModeAddon(this); + CaveBlock.SKY_WALKER_FLAG.addGameModeAddon(this); + + this.getPlugin().getFlagsManager().registerFlag(CaveBlock.ALTERNATIVE_TELEPORT_FLAG); + this.getPlugin().getFlagsManager().registerFlag(CaveBlock.SKY_WALKER_FLAG); + + // Register listener + this.registerListener(new CustomHeightLimitations(this)); } @@ -160,8 +172,6 @@ public class CaveBlock extends GameModeAddon createWorld(); } } - - this.getServer().getPluginManager().registerEvents(new CustomHeightLimitations(this), this.getPlugin()); } @@ -202,14 +212,17 @@ public class CaveBlock extends GameModeAddon return this.settings; } - @Override - public void saveWorldSettings() { - if (settings != null) { - new Config<>(this, Settings.class).saveConfigObject(settings); - } + @Override + public void saveWorldSettings() + { + if (this.settings != null) + { + new Config<>(this, Settings.class).saveConfigObject(this.settings); + } } + // --------------------------------------------------------------------- // Section: Variables // --------------------------------------------------------------------- @@ -231,6 +244,27 @@ public class CaveBlock extends GameModeAddon // --------------------------------------------------------------------- + /** + * This flag allows enables and disables alternative teleport paths. If player falls + * into void and this flag is enabled, then he will be teleported to different world. + */ + public final static Flag ALTERNATIVE_TELEPORT_FLAG = + new Flag.Builder("ALTERNATIVE_TELEPORT_FLAG", Material.ENDER_PEARL). + type(Flag.Type.WORLD_SETTING). + defaultSetting(false). + build(); + + /** + * This flag allows enables and disables to walk on top of the world without a + * permission. When enabled, players will be able to reach other player islands through + * top of the world. + */ + public final static Flag SKY_WALKER_FLAG = + new Flag.Builder("SKY_WALKER_FLAG", Material.FEATHER). + type(Flag.Type.WORLD_SETTING). + defaultSetting(false). + build(); + /** * String for nether world. */ diff --git a/src/main/java/world/bentobox/caveblock/Settings.java b/src/main/java/world/bentobox/caveblock/Settings.java index 8123e5a..3a2e6ba 100644 --- a/src/main/java/world/bentobox/caveblock/Settings.java +++ b/src/main/java/world/bentobox/caveblock/Settings.java @@ -768,36 +768,6 @@ public class Settings implements DataObject, WorldSettings } - /** - * This method returns the skyWalking object. - * @return the skyWalking object. - */ - public boolean isSkyWalking() - { - return skyWalking; - } - - - /** - * This method returns the alternativeTeleports object. - * @return the alternativeTeleports object. - */ - public boolean isAlternativeTeleports() - { - return alternativeTeleports; - } - - - /** - * This method returns the beaconAllowed object. - * @return the beaconAllowed object. - */ - public boolean isBeaconAllowed() - { - return beaconAllowed; - } - - /** * This method returns the islandCommand value. * @return the value of islandCommand. @@ -1537,39 +1507,6 @@ public class Settings implements DataObject, WorldSettings } - /** - * This method sets the skyWalking object value. - * @param skyWalking the skyWalking object new value. - * - */ - public void setSkyWalking(boolean skyWalking) - { - this.skyWalking = skyWalking; - } - - - /** - * This method sets the alternativeTeleports object value. - * @param alternativeTeleports the alternativeTeleports object new value. - * - */ - public void setAlternativeTeleports(boolean alternativeTeleports) - { - this.alternativeTeleports = alternativeTeleports; - } - - - /** - * This method sets the beaconAllowed object value. - * @param beaconAllowed the beaconAllowed object new value. - * - */ - public void setBeaconAllowed(boolean beaconAllowed) - { - this.beaconAllowed = beaconAllowed; - } - - /** * @return the debug */ @@ -1708,26 +1645,6 @@ public class Settings implements DataObject, WorldSettings @ConfigEntry(path = "world.generation-tries", needsReset = true) private int numberOfBlockGenerationTries = 1; - @ConfigComment("") - @ConfigComment("Allows to walk over the world roof.") - @ConfigEntry(path = "world.sky-walking") - private boolean skyWalking; - - @ConfigComment("Enables different ways how to get to other worlds.") - @ConfigComment("If players fall into void, then they will be teleported:") - @ConfigComment(" - to nether if falls into void from over world") - @ConfigComment(" - to the end if falls into void from nether") - @ConfigComment(" - to over world if falls into void from the end") - @ConfigEntry(path = "world.alternative-teleports") - private boolean alternativeTeleports; - - @ConfigComment("Enables ability to use beacon, if world roof is made of Bedrock. It will replace") - @ConfigComment("bedrock with black stained glass and on beacon placing, and replace it with bedrock if") - @ConfigComment("beacon is destroyed.") - @ConfigComment("This will not do anything, if roof is not made of bedrock.") - @ConfigEntry(path = "world.allow-beacon") - private boolean beaconAllowed; - @ConfigComment("") @ConfigComment("Make over world roof of bedrock, if false, it will be made from stone") @ConfigEntry(path = "world.normal.roof", needsReset = true) diff --git a/src/main/java/world/bentobox/caveblock/listeners/CustomHeightLimitations.java b/src/main/java/world/bentobox/caveblock/listeners/CustomHeightLimitations.java index f64a376..844172e 100644 --- a/src/main/java/world/bentobox/caveblock/listeners/CustomHeightLimitations.java +++ b/src/main/java/world/bentobox/caveblock/listeners/CustomHeightLimitations.java @@ -43,9 +43,9 @@ public class CustomHeightLimitations implements Listener public void onPlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); - final double nextY = event.getTo().getY(); + final double nextY = event.getTo() == null ? 1 : event.getTo().getY(); - if (this.addon.getSettings().isSkyWalking() || + if (CaveBlock.SKY_WALKER_FLAG.isSetForWorld(player.getWorld()) || player.isOp() || player.isDead() || player.getGameMode().equals(GameMode.CREATIVE) || @@ -53,9 +53,87 @@ public class CustomHeightLimitations implements Listener this.addon.getPlayers().isInTeleport(player.getUniqueId()) || player.hasPermission("caveblock.skywalker") || !Util.sameWorld(this.addon.getOverWorld(), player.getWorld()) || - nextY > 0 && nextY < this.worldHeight || + nextY < this.worldHeight || // Next check will allow to go down, but never up. - event.getFrom().getBlockY() <= event.getFrom().getBlockY() && + event.getFrom().getY() >= nextY && + event.getFrom().getBlockX() == event.getTo().getBlockX() && + event.getFrom().getBlockZ() == event.getTo().getBlockZ()) + { + // interested only in movements that is above height limit. + return; + } + + + // Prevent to get over world height + if (nextY >= this.worldHeight) + { + User.getInstance(player).sendMessage("caveblock.general.errors.cave-limit-reached"); + event.setCancelled(true); + } + } + + + /** + * Method onPlayerTeleport disables all teleports that involves moving on top of the world. + * + * @param event of type PlayerTeleportEvent + */ + @EventHandler(priority = EventPriority.LOWEST) + public void onPlayerTeleport(PlayerTeleportEvent event) + { + Player player = event.getPlayer(); + final double nextY = event.getTo() == null ? 1 : event.getTo().getY(); + + if (CaveBlock.SKY_WALKER_FLAG.isSetForWorld(player.getWorld()) || + player.isOp() || + player.isDead() || + player.getGameMode().equals(GameMode.CREATIVE) || + player.getGameMode().equals(GameMode.SPECTATOR) || + this.addon.getPlayers().isInTeleport(player.getUniqueId()) || + player.hasPermission("caveblock.skywalker") || + !Util.sameWorld(this.addon.getOverWorld(), player.getWorld()) || + nextY < this.worldHeight || + // Next check will allow to go down, but never up. + event.getFrom().getY() >= nextY && + event.getFrom().getBlockX() == event.getTo().getBlockX() && + event.getFrom().getBlockZ() == event.getTo().getBlockZ()) + { + // interested only in movements that is below 0 or above height limit. + return; + } + + // Prevent to get over world height + if (nextY >= this.worldHeight) + { + User.getInstance(player).sendMessage("caveblock.general.errors.cave-limit-reached"); + event.setCancelled(true); + } + } + + + + /** + * Method onPlayerMove disables movement if player is falling in void and alternative + * teleport flag is enabled. + * It will work only when player reach negative Y coordinates. + * + * @param event of type PlayerMoveEvent + */ + @EventHandler(priority = EventPriority.LOWEST) + public void onPlayerLeftWorld(PlayerMoveEvent event) + { + Player player = event.getPlayer(); + final double nextY = event.getTo() == null ? 1 : event.getTo().getY(); + + if (event.isCancelled() || + !CaveBlock.ALTERNATIVE_TELEPORT_FLAG.isSetForWorld(player.getWorld()) || + player.isDead() || + player.getGameMode().equals(GameMode.SPECTATOR) || + this.addon.getPlayers().isInTeleport(player.getUniqueId()) || + !Util.sameWorld(this.addon.getOverWorld(), player.getWorld()) || + nextY > 0 || + // Next check will allow to go down, but never up. + event.getFrom().getY() <= nextY && event.getFrom().getBlockX() == event.getTo().getBlockX() && event.getFrom().getBlockZ() == event.getTo().getBlockZ()) { @@ -64,7 +142,7 @@ public class CustomHeightLimitations implements Listener } // Use custom teleport to different world - if (this.addon.getSettings().isAlternativeTeleports() && nextY <= 0) + if (CaveBlock.ALTERNATIVE_TELEPORT_FLAG.isSetForWorld(player.getWorld()) && nextY <= 0) { switch (player.getWorld().getEnvironment()) { @@ -124,53 +202,6 @@ public class CustomHeightLimitations implements Listener default: break; } - - return; - } - - // Prevent to get over world height - if (nextY >= this.worldHeight) - { - User.getInstance(player).sendMessage("caveblock.general.errors.cave-limit-reached"); - event.setCancelled(true); - } - } - - - /** - * Method onPlayerTeleport disables all teleports that involves moving on top of the world. - * - * @param event of type PlayerTeleportEvent - */ - @EventHandler(priority = EventPriority.LOWEST) - public void onPlayerTeleport(PlayerTeleportEvent event) - { - Player player = event.getPlayer(); - final double nextY = event.getTo().getY(); - - if (this.addon.getSettings().isSkyWalking() || - player.isOp() || - player.isDead() || - player.getGameMode().equals(GameMode.CREATIVE) || - player.getGameMode().equals(GameMode.SPECTATOR) || - this.addon.getPlayers().isInTeleport(player.getUniqueId()) || - player.hasPermission("caveblock.skywalker") || - !Util.sameWorld(this.addon.getOverWorld(), player.getWorld()) || - nextY > 0 && nextY < this.worldHeight || - // Next check will allow to go down, but never up. - event.getFrom().getBlockY() <= event.getFrom().getBlockY() && - event.getFrom().getBlockX() == event.getTo().getBlockX() && - event.getFrom().getBlockZ() == event.getTo().getBlockZ()) - { - // interested only in movements that is below 0 or above height limit. - return; - } - - // Prevent to get over world height - if (nextY >= this.worldHeight) - { - User.getInstance(player).sendMessage("caveblock.general.errors.cave-limit-reached"); - event.setCancelled(true); } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index dfb39d4..597e3ab 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -62,20 +62,6 @@ world: world-depth: 256 # This indicate how many times block should be tried to generate. generation-tries: 2 - # - # Allows to walk over the world roof. - sky-walking: false - # Enables different ways how to get to other worlds. - # If players fall into void, then they will be teleported: - # - to nether if falls into void from over world - # - to the end if falls into void from nether - # - to over world if falls into void from the end - alternative-teleports: true - # Enables ability to use beacon, if world roof is made of Bedrock. It will replace - # bedrock with black stained glass and on beacon placing, and replace it with bedrock if - # beacon is destroyed. - # This will not do anything, if roof is not made of bedrock. - allow-beacon: false normal: # # Make over world roof of bedrock, if false, it will be made from stone diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index e286622..6115257 100644 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -239,4 +239,14 @@ caveblock: description: |- &aGeneral settings &afor this cave - \ No newline at end of file + +protection: + flags: + ALTERNATIVE_TELEPORT_FLAG: + description: "&5&oThis allows to enable/disable\n&5&oability to teleport to\n&5&odiferent dimension if\n&5&oplayer falls in void." + name: "Alternative teleports" + hint: "Falling in void will not end in death." + SKY_WALKER_FLAG: + description: "&5&oThis allows to enable/disable\n&5&oability to walk on the\n&5&otop of the cave world\n&5&owithout extra permissions." + name: "Sky Walker" + hint: "Allows to walk on cave ceiling." \ No newline at end of file