mirror of
https://github.com/BentoBoxWorld/CaveBlock.git
synced 2025-02-13 00:21:56 +01:00
Create custom listener that process player movement.
Add ability to deny players from walking over world roof. (#3) Add ability to teleport players to other worlds by falling into void. (#4)
This commit is contained in:
parent
3d49f60885
commit
beccadd7d4
@ -13,6 +13,7 @@ import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
import world.bentobox.caveblock.commands.AdminCommand;
|
||||
import world.bentobox.caveblock.commands.IslandCommand;
|
||||
import world.bentobox.caveblock.generators.ChunkGeneratorWorld;
|
||||
import world.bentobox.caveblock.listeners.CustomHeightLimitations;
|
||||
|
||||
|
||||
public class CaveBlock extends GameModeAddon
|
||||
@ -161,6 +162,8 @@ public class CaveBlock extends GameModeAddon
|
||||
createWorld();
|
||||
}
|
||||
}
|
||||
|
||||
this.getServer().getPluginManager().registerEvents(new CustomHeightLimitations(this), this.getPlugin());
|
||||
}
|
||||
|
||||
|
||||
|
@ -797,6 +797,27 @@ public class Settings implements DataObject, WorldSettings
|
||||
return numberOfBlockGenerationTries;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Setters
|
||||
// ---------------------------------------------------------------------
|
||||
@ -1550,6 +1571,28 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the debug
|
||||
*/
|
||||
@ -1653,6 +1696,20 @@ 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("")
|
||||
@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("")
|
||||
@ConfigComment("Make over world roof of bedrock, if false, it will be made from stone")
|
||||
@ConfigEntry(path = "world.normal.roof", needsReset = true)
|
||||
|
@ -0,0 +1,147 @@
|
||||
package world.bentobox.caveblock.listeners;
|
||||
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
import world.bentobox.bentobox.util.teleport.SafeSpotTeleport;
|
||||
import world.bentobox.caveblock.CaveBlock;
|
||||
|
||||
|
||||
/**
|
||||
* This listener checks player movement. If enabled, players will be deny to get over world depth limit and
|
||||
* if alternative teleports is enabled, then falling in void also will be processed.
|
||||
*/
|
||||
public class CustomHeightLimitations implements Listener
|
||||
{
|
||||
/**
|
||||
* Simple constructor
|
||||
* @param addon
|
||||
*/
|
||||
public CustomHeightLimitations(CaveBlock addon)
|
||||
{
|
||||
this.addon = addon;
|
||||
this.worldHeight = addon.getSettings().getWorldDepth() - 1;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerMove(PlayerMoveEvent 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;
|
||||
}
|
||||
|
||||
// Use custom teleport to different world
|
||||
if (this.addon.getSettings().isAlternativeTeleports() && nextY <= 0)
|
||||
{
|
||||
switch (player.getWorld().getEnvironment())
|
||||
{
|
||||
case NORMAL:
|
||||
{
|
||||
// From normal world users will get to nether.
|
||||
|
||||
Location to = this.addon.getIslands().getIslandAt(event.getFrom()).
|
||||
map(i -> i.getSpawnPoint(World.Environment.NETHER)).
|
||||
orElse(event.getFrom().toVector().toLocation(this.addon.getNetherWorld()));
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
new SafeSpotTeleport.Builder(this.addon.getPlugin()).
|
||||
entity(event.getPlayer()).
|
||||
location(to).
|
||||
portal().
|
||||
build();
|
||||
|
||||
break;
|
||||
}
|
||||
case NETHER:
|
||||
{
|
||||
// From nether world users will get to the end.
|
||||
|
||||
Location to = this.addon.getIslands().getIslandAt(event.getFrom()).
|
||||
map(i -> i.getSpawnPoint(World.Environment.THE_END)).
|
||||
orElse(event.getFrom().toVector().toLocation(this.addon.getEndWorld()));
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
new SafeSpotTeleport.Builder(this.addon.getPlugin()).
|
||||
entity(event.getPlayer()).
|
||||
location(to).
|
||||
portal().
|
||||
build();
|
||||
|
||||
break;
|
||||
}
|
||||
case THE_END:
|
||||
{
|
||||
// From the end users will get to over world.
|
||||
|
||||
Location to = this.addon.getIslands().getIslandAt(event.getFrom()).
|
||||
map(i -> i.getSpawnPoint(World.Environment.NORMAL)).
|
||||
orElse(event.getFrom().toVector().toLocation(this.addon.getOverWorld()));
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
new SafeSpotTeleport.Builder(this.addon.getPlugin()).
|
||||
entity(event.getPlayer()).
|
||||
location(to).
|
||||
portal().
|
||||
build();
|
||||
break;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Variables
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* CaveBlock addon
|
||||
*/
|
||||
private CaveBlock addon;
|
||||
|
||||
/**
|
||||
* This variable store world height.
|
||||
*/
|
||||
private int worldHeight;
|
||||
}
|
@ -6,25 +6,25 @@ authors: BONNe
|
||||
|
||||
permissions:
|
||||
caveblock.island:
|
||||
description: Allow island command usage
|
||||
description: Allow cave command usage
|
||||
default: true
|
||||
caveblock.island.create:
|
||||
description: Allow island creation
|
||||
description: Allow cave creation
|
||||
default: true
|
||||
caveblock.island.home:
|
||||
description: Allow teleporting to player island
|
||||
description: Allow teleporting to player cave
|
||||
default: true
|
||||
caveblock.island.sethome:
|
||||
description: Let the player use the sethome command
|
||||
default: true
|
||||
caveblock.island.info:
|
||||
description: Let the player check their island level
|
||||
description: Let the player check their cave level
|
||||
default: true
|
||||
caveblock.island.sethome:
|
||||
description: Let the player set their island teleport point
|
||||
description: Let the player set their cave teleport point
|
||||
default: true
|
||||
caveblock.island.lock:
|
||||
description: Allows island locking
|
||||
description: Allows cave locking
|
||||
default: false
|
||||
caveblock.island.expel:
|
||||
description: Allows expelling of visitors
|
||||
@ -39,13 +39,13 @@ permissions:
|
||||
description: Player can select a language
|
||||
default: true
|
||||
caveblock.island.name:
|
||||
description: Player can set the name of their island
|
||||
description: Player can set the name of their cave
|
||||
default: true
|
||||
caveblock.island.spawn:
|
||||
description: Player can use the island spawn command if spawn exists
|
||||
description: Player can use the cave spawn command if spawn exists
|
||||
default: true
|
||||
caveblock.island.reset:
|
||||
description: Player can use the island reset or restart command
|
||||
description: Player can use the cave reset or restart command
|
||||
default: true
|
||||
caveblock.island.team:
|
||||
description: Let a player use team commands
|
||||
@ -57,7 +57,7 @@ permissions:
|
||||
description: Let a player use team coop commands
|
||||
default: true
|
||||
caveblock.settings.*:
|
||||
description: Allow use of settings on island
|
||||
description: Allow use of settings on cave
|
||||
default: true
|
||||
caveblock.mod.info:
|
||||
description: Let a moderator see info on a player
|
||||
@ -66,71 +66,74 @@ permissions:
|
||||
description: Allows setting or reseting of a player's home position
|
||||
default: op
|
||||
caveblock.mod.clearreset:
|
||||
description: Allow clearing of island reset limit
|
||||
description: Allow clearing of cave reset limit
|
||||
default: false
|
||||
caveblock.mod.tp:
|
||||
description: Allows teleport to an island
|
||||
description: Allows teleport to an cave
|
||||
default: op
|
||||
caveblock.mod.bypasscooldowns:
|
||||
description: Allow moderator to bypass cooldowns
|
||||
default: op
|
||||
caveblock.mod.bypassprotect:
|
||||
description: Allow moderator to bypass island protection
|
||||
description: Allow moderator to bypass cave protection
|
||||
default: op
|
||||
caveblock.mod.bypassexpel:
|
||||
description: Allow moderator to bypass island expulsion
|
||||
description: Allow moderator to bypass cave expulsion
|
||||
default: op
|
||||
caveblock.mod.lock:
|
||||
description: Locks or unlocks an island
|
||||
description: Locks or unlocks an cave
|
||||
default: op
|
||||
caveblock.mod.bypasslock:
|
||||
description: Bypasses an island lock
|
||||
description: Bypasses an cave lock
|
||||
default: op
|
||||
caveblock.mod.team:
|
||||
description: Enables modification of teams via kick and add commands
|
||||
default: false
|
||||
caveblock.mod.name:
|
||||
description: Enables naming of player's islands
|
||||
description: Enables naming of player's caves
|
||||
default: false
|
||||
caveblock.mod.resetname:
|
||||
description: Enables reset of player's island names
|
||||
description: Enables reset of player's cave names
|
||||
default: false
|
||||
caveblock.admin.clearresetall:
|
||||
description: Allow clearing of island reset limit of all players
|
||||
description: Allow clearing of cave reset limit of all players
|
||||
default: op
|
||||
caveblock.admin.reload:
|
||||
description: Reload the config.yml
|
||||
default: op
|
||||
caveblock.admin.delete:
|
||||
description: Let a player completely remove a player (including island)
|
||||
description: Let a player completely remove a player (including cave)
|
||||
default: op
|
||||
caveblock.admin.deleteisland:
|
||||
description: Let a player completely remove the island the player is on
|
||||
description: Let a player completely remove the cave the player is on
|
||||
default: op
|
||||
caveblock.admin.register:
|
||||
description: Let a player register the nearest island to another player.
|
||||
description: Let a player register the nearest cave to another player.
|
||||
default: op
|
||||
caveblock.admin.unregister:
|
||||
description: Removes a player from an island without deleting the island blocks.
|
||||
description: Removes a player from an cave without deleting the cave blocks.
|
||||
default: op
|
||||
caveblock.admin.purge:
|
||||
description: Let a player purge old islands.
|
||||
description: Let a player purge old caves.
|
||||
default: op
|
||||
caveblock.admin.setspawn:
|
||||
description: Allows use of spawn tools
|
||||
default: op
|
||||
caveblock.admin.setrange:
|
||||
description: Allows setting of island protection range
|
||||
description: Allows setting of cave protection range
|
||||
default: op
|
||||
caveblock.admin.reserve:
|
||||
description: Reserves an empty spot for a player's next island
|
||||
description: Reserves an empty spot for a player's next cave
|
||||
default: op
|
||||
caveblock.admin.settingsreset:
|
||||
description: Resets all the islands to default protection settings
|
||||
description: Resets all the caves to default protection settings
|
||||
default: op
|
||||
caveblock.admin.noban:
|
||||
description: Player cannot be banned from an island
|
||||
description: Player cannot be banned from an cave
|
||||
default: op
|
||||
caveblock.admin.setlanguage:
|
||||
description: Resets all player languages and sets the default language
|
||||
default: op
|
||||
caveblock.skywalker:
|
||||
description: Allows player to walk over the heigh limit.
|
||||
default: op
|
@ -1,7 +1,7 @@
|
||||
# CaveBlock Configuration ${version}
|
||||
# This config file is dynamic and saved when the server is shutdown.
|
||||
# You cannot edit it while the server is running because changes will
|
||||
# be lost! Use in-game settings GUI or edit when server is offline.
|
||||
# If you edit it while the server is running use /cbadmin reload
|
||||
# otherwise your settings will be lost.
|
||||
world:
|
||||
# Friendly name for this world. Used in admin commands. Must be a single word
|
||||
friendly-name: CaveBlock
|
||||
@ -45,17 +45,30 @@ world:
|
||||
# The default biome for the overworld
|
||||
default-biome: MOUNTAINS
|
||||
# The maximum number of players a player can ban at any one time in this game mode.
|
||||
# The permission acidisland.ban.maxlimit.X where X is a number can also be used per player
|
||||
# The permission caveblock.ban.maxlimit.X where X is a number can also be used per player
|
||||
# -1 = unlimited
|
||||
ban-limit: -1
|
||||
#
|
||||
#
|
||||
# This is cave... no height... only depth. Max 256.
|
||||
# Should not be less then island height.
|
||||
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
|
||||
#
|
||||
# This disabled default portals from obsidian or end portal.
|
||||
disable-default-portal: true
|
||||
normal:
|
||||
#
|
||||
#
|
||||
# Make over world roof of bedrock, if false, it will be made from stone
|
||||
roof: true
|
||||
# Make over world floor of bedrock, if false, it will be made from stone
|
||||
|
@ -9,6 +9,11 @@ caveblock:
|
||||
line1: "Welcome!"
|
||||
line2: "[name]"
|
||||
line3: "Start digging! &c<3"
|
||||
|
||||
informational:
|
||||
to-nether: "So unlucky to fall into nether."
|
||||
to-the-end: "You have reached the end."
|
||||
to-normal: "Back to your cave."
|
||||
# Override BentoBox default command strings
|
||||
# General strings
|
||||
general:
|
||||
@ -19,6 +24,7 @@ caveblock:
|
||||
already-have-island: "&cYou already have a cave!"
|
||||
no-safe-location: "&cNo safe location found!"
|
||||
not-owner: "&cYou are not the owner of your team!"
|
||||
cave-limit-reached: "&cYou have reached the top of your cave. You cannot get higher!"
|
||||
commands:
|
||||
# Override BentoBox default island command strings
|
||||
island:
|
||||
|
Loading…
Reference in New Issue
Block a user