mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-01-23 08:41:21 +01:00
Added world property 'allowFlight' to disable flying per world. Does not have an override permission yet. Adds #440.
This commit is contained in:
parent
9e029ad6ae
commit
ebc2a516bb
@ -286,7 +286,7 @@ public class MVWorld implements MultiverseWorld {
|
||||
for (Player p : plugin.getServer().getWorld(getName()).getPlayers()) {
|
||||
plugin.log(Level.FINER, String.format("Setting %s's GameMode to %s",
|
||||
p.getName(), newValue.toString()));
|
||||
plugin.getPlayerListener().handleGameMode(p, MVWorld.this);
|
||||
plugin.getPlayerListener().handleGameModeAndFlight(p, MVWorld.this);
|
||||
}
|
||||
return super.validateChange(property, newValue, oldValue, object);
|
||||
}
|
||||
@ -1188,6 +1188,22 @@ public class MVWorld implements MultiverseWorld {
|
||||
return this.props.setStyle(style);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean getAllowFlight() {
|
||||
return this.props.getAllowFlight();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setAllowFlight(final boolean allowFlight) {
|
||||
this.props.setAllowFlight(allowFlight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final JSONObject jsonData = new JSONObject();
|
||||
|
@ -52,6 +52,9 @@ public class WorldProperties extends SerializationConfig {
|
||||
PROPERTY_ALIASES.put("monsters", "spawning.monsters.spawn");
|
||||
PROPERTY_ALIASES.put("animalsrate", "spawning.animals.spawnrate");
|
||||
PROPERTY_ALIASES.put("monstersrate", "spawning.monsters.spawnrate");
|
||||
PROPERTY_ALIASES.put("flight", "allowFlight");
|
||||
PROPERTY_ALIASES.put("fly", "allowFlight");
|
||||
PROPERTY_ALIASES.put("allowfly", "allowFlight");
|
||||
}
|
||||
|
||||
public WorldProperties(Map<String, Object> values) {
|
||||
@ -280,6 +283,8 @@ public class WorldProperties extends SerializationConfig {
|
||||
private volatile String generator;
|
||||
@Property
|
||||
private volatile int playerLimit;
|
||||
@Property
|
||||
private volatile boolean allowFlight;
|
||||
// End of properties
|
||||
// --------------------------------------------------------------
|
||||
|
||||
@ -331,6 +336,7 @@ public class WorldProperties extends SerializationConfig {
|
||||
this.worldBlacklist = new ArrayList<String>();
|
||||
this.generator = null;
|
||||
this.playerLimit = -1;
|
||||
this.allowFlight = true;
|
||||
}
|
||||
|
||||
private static double getDefaultScale(Environment environment) {
|
||||
@ -616,4 +622,12 @@ public class WorldProperties extends SerializationConfig {
|
||||
public boolean setStyle(String style) {
|
||||
return this.setPropertyUnchecked("style", style);
|
||||
}
|
||||
|
||||
public boolean getAllowFlight() {
|
||||
return this.allowFlight;
|
||||
}
|
||||
|
||||
public void setAllowFlight(final boolean allowFlight) {
|
||||
this.setPropertyValueUnchecked("allowFlight", allowFlight);
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import com.onarandombox.MultiverseCore.enums.AllowedPortalType;
|
||||
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Difficulty;
|
||||
import org.bukkit.GameMode;
|
||||
@ -685,4 +684,18 @@ public interface MultiverseWorld {
|
||||
* @return All property names, with alternating colors.
|
||||
*/
|
||||
String getAllPropertyNames();
|
||||
|
||||
/**
|
||||
* Whether or not players are allowed to fly in this world.
|
||||
*
|
||||
* @return True if players allowed to fly in this world.
|
||||
*/
|
||||
boolean getAllowFlight();
|
||||
|
||||
/**
|
||||
* Sets whether or not players are allowed to fly in this world.
|
||||
*
|
||||
* @param allowFlight True to allow flight in this world.
|
||||
*/
|
||||
void setAllowFlight(final boolean allowFlight);
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.event.MVRespawnEvent;
|
||||
import com.onarandombox.MultiverseCore.utils.PermissionTools;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
@ -125,7 +126,7 @@ public class MVPlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
// Handle the Players GameMode setting for the new world.
|
||||
this.handleGameMode(event.getPlayer(), event.getPlayer().getWorld());
|
||||
this.handleGameModeAndFlight(event.getPlayer(), event.getPlayer().getWorld());
|
||||
playerWorld.put(p.getName(), p.getWorld().getName());
|
||||
}
|
||||
|
||||
@ -136,7 +137,7 @@ public class MVPlayerListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void playerChangedWorld(PlayerChangedWorldEvent event) {
|
||||
// Permissions now determine whether or not to handle a gamemode.
|
||||
this.handleGameMode(event.getPlayer(), event.getPlayer().getWorld());
|
||||
this.handleGameModeAndFlight(event.getPlayer(), event.getPlayer().getWorld());
|
||||
playerWorld.put(event.getPlayer().getName(), event.getPlayer().getWorld().getName());
|
||||
}
|
||||
|
||||
@ -316,13 +317,13 @@ public class MVPlayerListener implements Listener {
|
||||
}
|
||||
|
||||
// FOLLOWING 2 Methods and Private class handle Per Player GameModes.
|
||||
private void handleGameMode(Player player, World world) {
|
||||
private void handleGameModeAndFlight(Player player, World world) {
|
||||
|
||||
MultiverseWorld mvWorld = this.worldManager.getMVWorld(world.getName());
|
||||
if (mvWorld != null) {
|
||||
this.handleGameMode(player, mvWorld);
|
||||
this.handleGameModeAndFlight(player, mvWorld);
|
||||
} else {
|
||||
this.plugin.log(Level.FINER, "Not handling gamemode for world '" + world.getName()
|
||||
this.plugin.log(Level.FINER, "Not handling gamemode and flight for world '" + world.getName()
|
||||
+ "' not managed by Multiverse.");
|
||||
}
|
||||
}
|
||||
@ -332,7 +333,7 @@ public class MVPlayerListener implements Listener {
|
||||
* @param player The {@link Player}.
|
||||
* @param world The world the player is in.
|
||||
*/
|
||||
public void handleGameMode(final Player player, final MultiverseWorld world) {
|
||||
public void handleGameModeAndFlight(final Player player, final MultiverseWorld world) {
|
||||
// We perform this task one tick later to MAKE SURE that the player actually reaches the
|
||||
// destination world, otherwise we'd be changing the player mode if they havent moved anywhere.
|
||||
if (!this.pt.playerCanIgnoreGameModeRestriction(world, player)) {
|
||||
@ -355,5 +356,16 @@ public class MVPlayerListener implements Listener {
|
||||
} else {
|
||||
this.plugin.log(Level.FINE, "Player: " + player.getName() + " is IMMUNE to gamemode changes!");
|
||||
}
|
||||
// TODO need a override permission for this
|
||||
if (player.getAllowFlight() && !world.getAllowFlight() && player.getGameMode() != GameMode.CREATIVE) {
|
||||
player.setAllowFlight(false);
|
||||
if (player.isFlying()) {
|
||||
player.setFlying(false);
|
||||
}
|
||||
} else if (world.getAllowFlight()) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE) {
|
||||
player.setAllowFlight(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user