Update Config.yml, implement enforceaccess

Cache enforceaccess and enforcegamemodes, as both of these get accessed
a lot.
This commit is contained in:
fernferret 2011-10-10 11:49:53 -06:00
parent 1aad872333
commit 50a89b7b1a
6 changed files with 39 additions and 21 deletions

View File

@ -661,7 +661,7 @@ public class MVWorld implements MultiverseWorld {
config.setProperty("worlds." + this.name + ".gamemode", this.gameMode.toString());
saveConfig();
if (this.plugin.getConfig().getBoolean("enforcegamemodes", true)) {
if (MultiverseCore.EnforceGameModes) {
for (Player p : this.plugin.getServer().getWorld(this.getName()).getPlayers()) {
this.plugin.log(Level.FINER, "Setting " + p.getName() + "'s GameMode to " + this.gameMode.toString());
this.plugin.getPlayerListener().handleGameMode(p, this);

View File

@ -35,6 +35,7 @@ import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.config.Configuration;
import javax.persistence.EntityNotFoundException;
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
@ -44,6 +45,11 @@ import java.util.logging.Logger;
public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
private final static int Protocol = 5;
// Global Multiverse config variable, states whether or not
// Multiverse should stop other plugins from teleporting players
// to worlds.
public static boolean EnforceAccess;
public static boolean EnforceGameModes;
@Override
public String dumpVersionInfo(String buffer) {
@ -271,8 +277,14 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
// Setup the Debug option, we'll default to false because this option will not be in the default config.
GlobalDebug = this.configMV.getInt("debug", 0);
// Lets cache this value due to the fact that it will be accessed many times.
EnforceAccess = this.configMV.getBoolean("enforceaccess", false);
EnforceGameModes = this.configMV.getBoolean("enforcegamemodes", true);
this.configMV.setProperty("enforceaccess", EnforceAccess);
this.configMV.setProperty("enforcegamemodes", EnforceAccess);
this.messaging = new MVMessaging(this);
this.messaging.setCooldown(this.configMV.getInt("messagecooldown", 5000));
this.configMV.save();
}
public MVMessaging getMessaging() {

View File

@ -34,7 +34,7 @@ public class ConfigCommand extends MultiverseCommand {
@Override
public void runCommand(CommandSender sender, List<String> args) {
if (args.get(0).equalsIgnoreCase("messagecooldown") || args.get(0).equalsIgnoreCase("teleportcooldown")) {
if (args.get(0).equalsIgnoreCase("messagecooldown") || args.get(0).equalsIgnoreCase("teleportcooldown") || args.get(0).equalsIgnoreCase("debug")) {
try {
this.plugin.getConfig().setProperty(args.get(0).toLowerCase(), Integer.parseInt(args.get(1)));
this.plugin.loadConfigs();

View File

@ -10,5 +10,5 @@ package com.onarandombox.MultiverseCore.enums;
/** Multiverse 2 */
public enum ConfigProperty {
messagecooldown, teleportcooldown, worldnameprefix, useworldaccess,
disableautoheal, fakepvp, bedrespawn, finalsayaccess
disableautoheal, fakepvp, bedrespawn, finalsayaccess, debug
}

View File

@ -105,7 +105,7 @@ public class MVPlayerListener extends PlayerListener {
event.getPlayer().sendMessage("If you just wanna see all of the Multiverse Help, type: " + ChatColor.GREEN + "/mv");
}
// Handle the Players GameMode setting for the new world.
if (this.plugin.getConfig().getBoolean("enforcegamemodes", true)) {
if (MultiverseCore.EnforceGameModes) {
this.handleGameMode(event.getPlayer(), event.getPlayer().getWorld());
}
}
@ -113,7 +113,7 @@ public class MVPlayerListener extends PlayerListener {
@Override
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
// Handle the Players GameMode setting for the new world.
if (this.plugin.getConfig().getBoolean("enforcegamemodes", true)) {
if (MultiverseCore.EnforceGameModes) {
this.handleGameMode(event.getPlayer(), event.getPlayer().getWorld());
}
}
@ -130,7 +130,9 @@ public class MVPlayerListener extends PlayerListener {
}
MultiverseWorld fromWorld = this.worldManager.getMVWorld(event.getFrom().getWorld().getName());
MultiverseWorld toWorld = this.worldManager.getMVWorld(event.getTo().getWorld().getName());
event.setCancelled(checkWorldPermissions(fromWorld, toWorld, event.getPlayer()));
if (MultiverseCore.EnforceAccess) {
event.setCancelled(!playerCanGoFromTo(fromWorld, toWorld, event.getPlayer()));
}
}
@Override
@ -141,7 +143,9 @@ public class MVPlayerListener extends PlayerListener {
}
MultiverseWorld fromWorld = this.worldManager.getMVWorld(event.getFrom().getWorld().getName());
MultiverseWorld toWorld = this.worldManager.getMVWorld(event.getTo().getWorld().getName());
event.setCancelled(checkWorldPermissions(fromWorld, toWorld, event.getPlayer()));
if (MultiverseCore.EnforceAccess) {
event.setCancelled(!playerCanGoFromTo(fromWorld, toWorld, event.getPlayer()));
}
}
/**
@ -155,21 +159,22 @@ public class MVPlayerListener extends PlayerListener {
*
* @return True if they can't go to the world, False if they can.
*/
private boolean checkWorldPermissions(MultiverseWorld fromWorld, MultiverseWorld toWorld, Player player) {
private boolean playerCanGoFromTo(MultiverseWorld fromWorld, MultiverseWorld toWorld, Player player) {
if (toWorld != null) {
if (!this.plugin.getMVPerms().canEnterWorld(player, toWorld)) {
player.sendMessage("You don't have access to go here...");
return true;
return false;
}
} else {
// The toworld is not handled by MV, we don't care about payments
return false;
//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;
}
if (fromWorld != null) {
if (fromWorld.getWorldBlacklist().contains(toWorld.getName())) {
player.sendMessage("You don't have access to go to " + toWorld.getColoredWorldString() + " from " + fromWorld.getColoredWorldString());
return true;
return false;
}
}
@ -177,16 +182,16 @@ public class MVPlayerListener extends PlayerListener {
if (!toWorld.equals(fromWorld)) {
// If the player does not have to pay, return now.
if (this.plugin.getMVPerms().hasPermission(player, toWorld.getExemptPermission().getName(), true)) {
return false;
return true;
}
GenericBank bank = plugin.getBank();
if (!bank.hasEnough(player, toWorld.getPrice(), toWorld.getCurrency(), "You need " + bank.getFormattedAmount(player, toWorld.getPrice(), toWorld.getCurrency()) + " to enter " + toWorld.getColoredWorldString())) {
return true;
return false;
} else {
bank.pay(player, toWorld.getPrice(), toWorld.getCurrency());
}
}
return false;
return true;
}
// FOLLOWING 2 Methods and Private class handle Per Player GameModes.

View File

@ -15,12 +15,13 @@ teleportcooldown: 5000
# won't touch your chat
worldnameprefix: true
# If value is set to false, Multiverse will NOT enforce permissions
useworldaccess: false
# If value is set to false, Multiverse will NOT enforce
# world access permissions
enforceaccess: false
# Should multiverse have the final say in world access? If set to false, Multiverse will only check access
# for itself and any MVPlugin.
finalsayaccess: true
# If value is set to false, Multiverse will NOT enforce
# world access permissions
enforcegamemodes: true
# If you have a world(s) that has monsters = false, and you want to disable the built
# in autohealing, set this to true. This will have NO EFFECT if monsters = true for a given world.
@ -36,4 +37,4 @@ bedrespawn: true
# This just signifies the version number so we can see what version of config you have.
# NEVER TOUCH THIS VALUE
version: 2.2
version: 2.3