Compare commits

...
Author SHA1 Message Date
main() d65cc8215c Testing... 2012-05-03 17:05:17 +02:00
main() c6feb127de Rewritten for SerializationConfig
Conflicts:
	src/main/java/com/onarandombox/MultiverseCore/MVWorld.java
	src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java
2012-05-03 16:47:11 +02:00
main() 77480915a1 Merge branch 'master' of github.com:Multiverse/Multiverse-Core into allow-flight 2012-04-30 14:31:06 +02:00
main() c233b74c98 Merge branch 'master' into allow-flight
Conflicts:
	src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java
2012-02-26 16:50:02 +01:00
main() ae95a4c4f9 Merge branch 'master' of github.com:Multiverse/Multiverse-Core into allow-flight 2012-02-04 20:00:21 +01:00
Eric Stokes 49fd9e81d1 Inital allow flight code, if we use it 2012-01-29 16:57:16 -07:00
5 changed files with 126 additions and 6 deletions

No files matched your search

@@ -275,10 +275,26 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
@Override
public GameMode validateChange(String property, GameMode newValue, GameMode oldValue,
MVWorld object) throws ChangeDeniedException {
for (Player p : plugin.getServer().getWorld(getName()).getPlayers()) {
for (Player p : object.getCBWorld().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().handleGameMode(p, object);
}
return super.validateChange(property, newValue, oldValue, object);
}
}
/**
* Used to apply the allowFlight-property.
*/
private final class AllowFlightPropertyValidator extends WorldPropertyValidator<Boolean> {
@Override
public Boolean validateChange(String property, Boolean newValue, Boolean oldValue,
MVWorld object) throws ChangeDeniedException {
for (Player p : object.getCBWorld().getPlayers()) {
plugin.log(Level.FINER, String.format("Setting %s's allowFlight to %s",
p.getName(), newValue));
plugin.getPlayerListener().handleAllowFlight(p, object);
}
return super.validateChange(property, newValue, oldValue, object);
}
@@ -440,6 +456,8 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
return world.get().getTime();
}
};
@Property(validator = AllowFlightPropertyValidator.class)
private boolean allowFlight;
@Property
private Environment environment;
@Property
@@ -636,6 +654,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
this.bedRespawn = true;
this.worldBlacklist = new ArrayList<String>();
this.generator = null;
this.allowFlight = true;
}
/**
@@ -1365,6 +1384,22 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
this.setPropertyValueUnchecked("portalForm", portalType);
}
/**
* {@inheritDoc}
*/
@Override
public boolean isFlightAllowed() {
return allowFlight;
}
/**
* {@inheritDoc}
*/
@Override
public void setFlightAllowed(boolean flightAllowed) {
this.setPropertyValueUnchecked("allowFlight", flightAllowed);
}
@Override
public String toString() {
StringBuilder toStringBuilder = new StringBuilder();
@@ -654,4 +654,25 @@ public interface MultiverseWorld {
* @return All property names, with alternating colors.
*/
String getAllPropertyNames();
/**
* Gets whether or not flight is allowed in this world.
* <p>
* It should be noted that this refers to clientside flying. Creative
* mode will always allow server based flying.
*
* @return True if flight is allowed.
*/
boolean isFlightAllowed();
/**
* Sets whether or not flight is allowed in this world.
* <p>
* It should be noted that this refers to clientside flying. Creative
* mode will always allow server based flying.
*
* @param flightAllowed Wheter or not flight is allowed in this world.
*/
void setFlightAllowed(boolean flightAllowed);
}
@@ -299,6 +299,7 @@ public class MVPlayerListener implements Listener {
// Remove the player 1 tick after the login. I'm sure there's GOT to be a better way to do this...
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
new Runnable() {
@Override
public void run() {
player.teleport(plugin.getMVWorldManager().getFirstSpawnWorld().getSpawnLocation());
}
@@ -324,16 +325,15 @@ public class MVPlayerListener implements Listener {
*/
public void handleGameMode(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.
// destination world, otherwise we'd be changing the player mode if they haven't moved anywhere.
if (!this.pt.playerCanIgnoreGameModeRestriction(world, player)) {
this.plugin.log(Level.FINE, "Handeling gamemode for player: " + player.getName());
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
new Runnable() {
@Override
public void run() {
// Check that the player is in the new world and they haven't been teleported elsewhere or the event cancelled.
if (player.getWorld() == world.getCBWorld()) {
MultiverseCore.staticLog(Level.FINE, String.format(
"Handling gamemode for player: %s, Changing to %s",
player.getName(), world.getGameMode().toString()));
MultiverseCore.staticLog(Level.FINEST, "From World: " + player.getWorld());
MultiverseCore.staticLog(Level.FINEST, "To World: " + world);
player.setGameMode(world.getGameMode());
@@ -348,4 +348,36 @@ public class MVPlayerListener implements Listener {
this.plugin.log(Level.FINE, String.format("Player: %s is IMMUNE to gamemode changes!", player.getName()));
}
}
/**
* Handles the allowflight attribute for the specified {@link Player}.
* @param player The {@link Player}.
* @param world The world the player is in.
*/
public void handleAllowFlight(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 haven't moved anywhere.
if (!this.pt.playerCanIgnoreAllowFlightRestriction(world, player)) {
this.plugin.log(Level.FINE, "Handeling flight for player: " + player.getName());
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
new Runnable() {
@Override
public void run() {
// Check that the player is in the new world and they haven't been teleported elsewhere or the event cancelled.
if (player.getWorld() == world.getCBWorld()) {
player.setAllowFlight(world.isFlightAllowed());
MultiverseCore.staticLog(Level.FINER,
String.format("%s's allowFlight was set to %b!",
player.getName(), world.isFlightAllowed()));
} else {
MultiverseCore.staticLog(Level.FINE,
String.format("allowFlight was NOT changed for player '%s' because he is now in world '%s' instead of world '%s'",
player.getName(), player.getWorld().getName(), world.getName()));
}
}
}, 1L);
} else {
this.plugin.log(Level.FINE, "Player: " + player.getName() + " is IMMUNE to flight changes!");
}
}
}
@@ -47,6 +47,21 @@ public class MVPermissions implements PermissionsInterface {
return p.hasPermission("mv.bypass.gamemode." + w.getName());
}
/**
* Check if a Player can ignore GameMode restrictions for world they travel to.
*
* @param p The {@link Player} to check.
* @param w The {@link MultiverseWorld} the player wants to teleport to.
* @return True if they should bypass restrictions.
*/
public boolean canIgnoreAllowFlightRestriction(Player p, MultiverseWorld w) {
if (p.hasPermission("mv.bypass.allowflight.*")) {
this.plugin.log(Level.FINER, "Player has mv.bypass.allowflight.* they can fly!");
return true;
}
return p.hasPermission("mv.bypass.allowflight." + w.getName());
}
/**
* Check if a Player can teleport to the Destination world from there current world.
*
@@ -246,4 +246,21 @@ public class PermissionTools {
return true;
}
}
/**
* Checks to see if a player should bypass allow-flight restrictions.
*
* @param toWorld world travelling to.
* @param teleportee player travelling.
* @return True if they should bypass restrictions
*/
public boolean playerCanIgnoreAllowFlightRestriction(MultiverseWorld toWorld, Player teleportee) {
if (toWorld != null) {
return this.plugin.getMVPerms().canIgnoreAllowFlightRestriction(teleportee, toWorld);
} else {
// TODO: Determine if this value is false because a world didn't exist
// or if it was because a world wasn't imported.
return true;
}
}
}