Added untested support for Vault permission handling.
This commit is contained in:
		| @@ -10,12 +10,15 @@ import java.util.Map; | |||||||
| import java.util.logging.Level; | import java.util.logging.Level; | ||||||
| import java.util.logging.Logger; | import java.util.logging.Logger; | ||||||
|  |  | ||||||
|  | import net.milkbowl.vault.permission.Permission; | ||||||
|  |  | ||||||
| import org.bukkit.command.Command; | import org.bukkit.command.Command; | ||||||
| import org.bukkit.command.CommandSender; | import org.bukkit.command.CommandSender; | ||||||
| import org.bukkit.configuration.file.FileConfiguration; | import org.bukkit.configuration.file.FileConfiguration; | ||||||
| import org.bukkit.configuration.file.YamlConfiguration; | import org.bukkit.configuration.file.YamlConfiguration; | ||||||
| import org.bukkit.configuration.serialization.ConfigurationSerialization; | import org.bukkit.configuration.serialization.ConfigurationSerialization; | ||||||
| import org.bukkit.plugin.PluginManager; | import org.bukkit.plugin.PluginManager; | ||||||
|  | import org.bukkit.plugin.RegisteredServiceProvider; | ||||||
| import org.bukkit.plugin.java.JavaPlugin; | import org.bukkit.plugin.java.JavaPlugin; | ||||||
|  |  | ||||||
| import de.craftinc.gates.commands.*; | import de.craftinc.gates.commands.*; | ||||||
| @@ -30,9 +33,11 @@ public class Plugin extends JavaPlugin | |||||||
| 	 | 	 | ||||||
| 	public static final String permissionInfo = "craftincgates.info"; | 	public static final String permissionInfo = "craftincgates.info"; | ||||||
| 	public static final String permissionManage = "craftincgates.manage"; | 	public static final String permissionManage = "craftincgates.manage"; | ||||||
| 	public static final String permissionAll = "craftincgates.*"; | //	public static final String permissionAll = "craftincgates.*"; | ||||||
| 	public static final String permissionUse = "craftincgates.use"; | 	public static final String permissionUse = "craftincgates.use"; | ||||||
| 	 | 	 | ||||||
|  | 	public static Permission permission = null; | ||||||
|  | 	 | ||||||
| 	public PluginPlayerListener playerListener = new PluginPlayerListener(); | 	public PluginPlayerListener playerListener = new PluginPlayerListener(); | ||||||
| 	public PluginBlockListener blockListener = new PluginBlockListener(); | 	public PluginBlockListener blockListener = new PluginBlockListener(); | ||||||
| 	public PluginPortalListener portalListener = new PluginPortalListener(); | 	public PluginPortalListener portalListener = new PluginPortalListener(); | ||||||
| @@ -55,9 +60,25 @@ public class Plugin extends JavaPlugin | |||||||
| 	@Override | 	@Override | ||||||
| 	public void onLoad()  | 	public void onLoad()  | ||||||
| 	{ | 	{ | ||||||
|  | 		setupPermissions(); | ||||||
| 		ConfigurationSerialization.registerClass(Gate.class); | 		ConfigurationSerialization.registerClass(Gate.class); | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
|  | 	 | ||||||
|  | 	private void setupPermissions() | ||||||
|  | 	{ | ||||||
|  | 		if (getServer().getPluginManager().getPlugin("Vault") == null) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 		 | ||||||
|  | 		RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class); | ||||||
|  | 		 | ||||||
|  | 		if (rsp != null) | ||||||
|  | 		{ | ||||||
|  | 			permission = rsp.getProvider(); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  |  | ||||||
| 	@Override | 	@Override | ||||||
| 	public void onDisable()  | 	public void onDisable()  | ||||||
|   | |||||||
| @@ -12,24 +12,26 @@ import de.craftinc.gates.util.TextUtil; | |||||||
|  |  | ||||||
| public abstract class BaseCommand  | public abstract class BaseCommand  | ||||||
| { | { | ||||||
| 	public List<String> aliases; | 	protected List<String> aliases; | ||||||
| 	public List<String> requiredParameters; | 	protected List<String> requiredParameters; | ||||||
| 	public List<String> optionalParameters; | 	protected List<String> optionalParameters; | ||||||
| 	 | 	 | ||||||
| 	public String helpDescription; | 	protected String helpDescription; | ||||||
| 	 | 	 | ||||||
| 	public CommandSender sender; | 	protected List<String> parameters; | ||||||
| 	public boolean senderMustBePlayer; | 	protected CommandSender sender; | ||||||
| 	public boolean hasGateParam; | 	protected Player player; | ||||||
| 	public Player player; | 	protected Gate gate; | ||||||
| 	public Gate gate; |  | ||||||
| 	 | 	 | ||||||
| 	public List<String> parameters; | 	protected boolean senderMustBePlayer; | ||||||
|  | 	protected boolean hasGateParam; | ||||||
| 	 | 	 | ||||||
| 	public String requiredPermission; | 	protected String requiredPermission; | ||||||
|  | 	protected boolean needsPermissionAtCurrentLocation; | ||||||
| 	 | 	 | ||||||
| 	 | 	 | ||||||
| 	public BaseCommand() { | 	public BaseCommand()  | ||||||
|  | 	{ | ||||||
| 		aliases = new ArrayList<String>(); | 		aliases = new ArrayList<String>(); | ||||||
| 		requiredParameters = new ArrayList<String>(); | 		requiredParameters = new ArrayList<String>(); | ||||||
| 		optionalParameters = new ArrayList<String>(); | 		optionalParameters = new ArrayList<String>(); | ||||||
| @@ -43,12 +45,13 @@ public abstract class BaseCommand | |||||||
| 	public List<String> getAliases() { | 	public List<String> getAliases() { | ||||||
| 		return aliases; | 		return aliases; | ||||||
| 	} | 	} | ||||||
| 		 | 	 | ||||||
|  | 	 | ||||||
| 	public void execute(CommandSender sender, List<String> parameters) { | 	public void execute(CommandSender sender, List<String> parameters) { | ||||||
| 		this.sender = sender; | 		this.sender = sender; | ||||||
| 		this.parameters = parameters; | 		this.parameters = parameters; | ||||||
| 		 | 		 | ||||||
| 		if ( ! validateCall()) { | 		if (!this.validateCall()) { | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
| @@ -56,79 +59,146 @@ public abstract class BaseCommand | |||||||
| 			this.player = (Player)sender; | 			this.player = (Player)sender; | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
| 		perform(); | 		this.perform(); | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public void perform() { |  | ||||||
| 		 |  | ||||||
| 	} |  | ||||||
| 	 | 	 | ||||||
| 	public void sendMessage(String message) { | 	abstract protected void perform(); | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	protected void sendMessage(String message) { | ||||||
| 		sender.sendMessage(message); | 		sender.sendMessage(message); | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public void sendMessage(List<String> messages) { | 	 | ||||||
|  | 	protected void sendMessage(List<String> messages) { | ||||||
| 		for(String message : messages) { | 		for(String message : messages) { | ||||||
| 			this.sendMessage(message); | 			this.sendMessage(message); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public boolean validateCall()  | 	 | ||||||
|  | 	protected boolean validateCall()  | ||||||
| 	{ | 	{ | ||||||
| 		// validate player		 | 		boolean allParamtertersThere = parameters.size() < requiredParameters.size(); | ||||||
| 		if ( this.senderMustBePlayer && ! (sender instanceof Player))  | 		boolean senderIsPlayer = this.sender instanceof Player; | ||||||
|  | 		boolean parameterIsGate = this.getGateForParamater(this.parameters.get(0)); | ||||||
|  | 		boolean senderHasPermission; | ||||||
|  | 		 | ||||||
|  | 		try { | ||||||
|  | 			senderHasPermission = this.hasPermission(); | ||||||
|  | 		}  | ||||||
|  | 		catch (Exception e) { // the gate paramter is missing or incorrect! | ||||||
|  | 			senderHasPermission = parameterIsGate ? false : true; // only display the lack of permission message if there is a gate | ||||||
|  | 																  // this should prevent giving permission to the user if there is | ||||||
|  | 																  // a bug inside the permission validation code. | ||||||
|  | 		} | ||||||
|  | 		 | ||||||
|  |  | ||||||
|  | 		if(!senderHasPermission)  | ||||||
|  | 		{ | ||||||
|  | 			sendMessage("You lack the permissions to " + this.helpDescription.toLowerCase() + "."); | ||||||
|  | 			return false; | ||||||
|  | 		} | ||||||
|  | 		 | ||||||
|  | 			 | ||||||
|  | 		if (this.senderMustBePlayer && !senderIsPlayer)  | ||||||
| 		{ | 		{ | ||||||
| 			sendMessage("This command can only be used by ingame players."); | 			sendMessage("This command can only be used by ingame players."); | ||||||
| 			return false; | 			return false; | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
| 		// validate permission | 		if (this.hasGateParam && !parameterIsGate)  | ||||||
| 		if( !hasPermission(sender))  |  | ||||||
| 		{ | 		{ | ||||||
| 			sendMessage("You lack the permissions to "+this.helpDescription.toLowerCase()+"."); | 			sendMessage("There exists no gate with id " + this.parameters.get(0)); | ||||||
| 			return false; | 			return false; | ||||||
| 		} | 		} | ||||||
| 		 | 	 | ||||||
| 		// valide parameter count | 		if (allParamtertersThere)  | ||||||
| 		if (parameters.size() < requiredParameters.size())  |  | ||||||
| 		{ | 		{ | ||||||
| 			sendMessage("Usage: "+this.getUseageTemplate(true)); | 			sendMessage("Usage: " + this.getUseageTemplate(true)); | ||||||
| 			return false; | 			return false; | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
| 		// validate gate parameter |  | ||||||
| 		if (this.hasGateParam)  |  | ||||||
| 		{ |  | ||||||
| 			String id = parameters.get(0); |  | ||||||
| 			 |  | ||||||
| 			if ( ! Gate.exists(id))  |  | ||||||
| 			{ |  | ||||||
| 				sendMessage("There exists no gate with id "+id); |  | ||||||
| 				return false; |  | ||||||
| 			} |  | ||||||
| 			gate = Gate.get(id); |  | ||||||
| 		} |  | ||||||
| 		 |  | ||||||
| 		return true; | 		return true; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public boolean hasPermission(CommandSender sender)  | 	 | ||||||
|  | 	protected boolean getGateForParamater(String param) | ||||||
| 	{ | 	{ | ||||||
| 		if (sender.hasPermission(Plugin.permissionAll)) { | 		if (!Gate.exists(param)) | ||||||
|  | 		{ | ||||||
|  | 			return false; | ||||||
|  | 		} | ||||||
|  | 		else | ||||||
|  | 		{ | ||||||
|  | 			gate = Gate.get(param); | ||||||
| 			return true; | 			return true; | ||||||
| 		} | 		} | ||||||
| 		 |  | ||||||
| 		if (sender.hasPermission(requiredPermission)) { |  | ||||||
| 			return true; |  | ||||||
| 		} |  | ||||||
| 		 |  | ||||||
| 		return false;  |  | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	protected boolean hasPermission() throws Exception | ||||||
|  | 	{		 | ||||||
|  | 		if (Plugin.permission == null) // fallback <20> use the standard bukkit permission system | ||||||
|  | 		{ | ||||||
|  | 			return this.sender.hasPermission(this.requiredPermission); | ||||||
|  | 		} | ||||||
|  | 		 | ||||||
|  | 		 | ||||||
|  | 		if (this.requiredPermission.equals(Plugin.permissionInfo)) | ||||||
|  | 		{ | ||||||
|  | 			return Plugin.permission.has(this.player.getWorld(), this.player.getName(), this.requiredPermission); | ||||||
|  | 		} | ||||||
|  | 		 | ||||||
|  | 		 | ||||||
|  | 		if (this.requiredPermission.equals(Plugin.permissionUse) ) | ||||||
|  | 		{ | ||||||
|  | 			return this.hasPermissionAtGateLocationAndExit(); | ||||||
|  | 		} | ||||||
|  | 			 | ||||||
|  | 		 | ||||||
|  | 		if (this.requiredPermission.equals(Plugin.permissionManage)) | ||||||
|  | 		{ | ||||||
|  | 			if (this.needsPermissionAtCurrentLocation && this.hasGateParam) | ||||||
|  | 			{ | ||||||
|  | 				boolean hasPersmissionAtCurrentLocation = Plugin.permission.has(this.player.getWorld(), this.player.getName(), this.requiredPermission); | ||||||
|  | 				return hasPersmissionAtCurrentLocation && this.hasPermissionAtGateLocationAndExit(); | ||||||
|  | 			} | ||||||
|  | 			else if (this.needsPermissionAtCurrentLocation) | ||||||
|  | 			{ | ||||||
|  | 				return Plugin.permission.has(this.player.getWorld(), this.player.getName(), this.requiredPermission); | ||||||
|  | 			} | ||||||
|  | 			else | ||||||
|  | 			{ | ||||||
|  | 				return this.hasPermissionAtGateLocationAndExit(); | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 			 | ||||||
|  | 		 | ||||||
|  | 		return false; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	protected boolean hasPermissionAtGateLocationAndExit() throws Exception | ||||||
|  | 	{ | ||||||
|  | 		if (this.gate == null) // make sure we don't run into a nullpointer exception | ||||||
|  | 		{ | ||||||
|  | 			throw new Exception("Cannot check permissons with no gate provided!"); | ||||||
|  | 		} | ||||||
|  | 		 | ||||||
|  | 		boolean permAtLocation = Plugin.permission.has(this.gate.getLocation().getWorld(), player.getName(), this.requiredPermission); | ||||||
|  | 		boolean permAtExit = Plugin.permission.has(this.gate.getExit().getWorld(), player.getName(), this.requiredPermission); | ||||||
|  | 		 | ||||||
|  | 		return permAtLocation && permAtExit; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
| 	// -------------------------------------------- // | 	// -------------------------------------------- // | ||||||
| 	// Help and usage description | 	// Help and usage description | ||||||
| 	// -------------------------------------------- // | 	// -------------------------------------------- // | ||||||
| 	public String getUsageTemplate(boolean withColor, boolean withDescription) { | 	protected String getUsageTemplate(boolean withColor, boolean withDescription) { | ||||||
| 		String ret = ""; | 		String ret = ""; | ||||||
| 		 | 		 | ||||||
| //		if (withColor) { | //		if (withColor) { | ||||||
| @@ -159,11 +229,11 @@ public abstract class BaseCommand | |||||||
| 		return ret; | 		return ret; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public String getUseageTemplate(boolean withColor) { | 	protected String getUseageTemplate(boolean withColor) { | ||||||
| 		return getUsageTemplate(withColor, false); | 		return getUsageTemplate(withColor, false); | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public String getUseageTemplate() { | 	protected String getUseageTemplate() { | ||||||
| 		return getUseageTemplate(true); | 		return getUseageTemplate(true); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -14,6 +14,8 @@ public class CommandClose extends BaseCommand | |||||||
| 		helpDescription = "Closes a gate to prevent players from using it."; | 		helpDescription = "Closes a gate to prevent players from using it."; | ||||||
| 		 | 		 | ||||||
| 		requiredPermission = Plugin.permissionManage; | 		requiredPermission = Plugin.permissionManage; | ||||||
|  | 		 | ||||||
|  | 		needsPermissionAtCurrentLocation = false; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	 | 	 | ||||||
|   | |||||||
| @@ -21,6 +21,8 @@ public class CommandCreate extends BaseLocationCommand | |||||||
| 		helpDescription = "Create a gate at your current location."; | 		helpDescription = "Create a gate at your current location."; | ||||||
| 		 | 		 | ||||||
| 		requiredPermission = Plugin.permissionManage; | 		requiredPermission = Plugin.permissionManage; | ||||||
|  | 		 | ||||||
|  | 		needsPermissionAtCurrentLocation = true; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	 | 	 | ||||||
|   | |||||||
| @@ -19,6 +19,8 @@ public class CommandDelete extends BaseCommand | |||||||
| 		helpDescription = "Removes the gate from the game."; | 		helpDescription = "Removes the gate from the game."; | ||||||
| 		 | 		 | ||||||
| 		requiredPermission = Plugin.permissionManage; | 		requiredPermission = Plugin.permissionManage; | ||||||
|  | 		 | ||||||
|  | 		needsPermissionAtCurrentLocation = false; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	 | 	 | ||||||
|   | |||||||
| @@ -4,6 +4,7 @@ import java.util.ArrayList; | |||||||
|  |  | ||||||
| import org.bukkit.command.CommandSender; | import org.bukkit.command.CommandSender; | ||||||
|  |  | ||||||
|  | import de.craftinc.gates.Gate; | ||||||
| import de.craftinc.gates.util.TextUtil; | import de.craftinc.gates.util.TextUtil; | ||||||
|  |  | ||||||
| public class CommandHelp extends BaseCommand  | public class CommandHelp extends BaseCommand  | ||||||
| @@ -19,10 +20,12 @@ public class CommandHelp extends BaseCommand | |||||||
| 		hasGateParam = false; | 		hasGateParam = false; | ||||||
| 		 | 		 | ||||||
| 		helpDescription = "Prints a list of all availible commands."; | 		helpDescription = "Prints a list of all availible commands."; | ||||||
|  | 		 | ||||||
|  | 		needsPermissionAtCurrentLocation = false; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	@Override |  | ||||||
| 	public boolean hasPermission(CommandSender sender)  | 	public boolean hasPermission(CommandSender sender, Gate gate)  | ||||||
| 	{ | 	{ | ||||||
| 		return true; | 		return true; | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -17,6 +17,8 @@ public class CommandInfo extends BaseCommand | |||||||
| 		helpDescription = "Prints detailed informations about a certain gate."; | 		helpDescription = "Prints detailed informations about a certain gate."; | ||||||
| 		 | 		 | ||||||
| 		requiredPermission = Plugin.permissionInfo; | 		requiredPermission = Plugin.permissionInfo; | ||||||
|  | 		 | ||||||
|  | 		needsPermissionAtCurrentLocation = false; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	 | 	 | ||||||
|   | |||||||
| @@ -25,6 +25,8 @@ public class CommandList extends BaseCommand | |||||||
| 		helpDescription = "Prints a list of all availible gates."; | 		helpDescription = "Prints a list of all availible gates."; | ||||||
| 		 | 		 | ||||||
| 		requiredPermission = Plugin.permissionInfo; | 		requiredPermission = Plugin.permissionInfo; | ||||||
|  | 		 | ||||||
|  | 		needsPermissionAtCurrentLocation = false; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	 | 	 | ||||||
|   | |||||||
| @@ -15,6 +15,8 @@ public class CommandOpen extends BaseCommand | |||||||
| 		helpDescription = "Open a gate so players can use it."; | 		helpDescription = "Open a gate so players can use it."; | ||||||
| 		 | 		 | ||||||
| 		requiredPermission = Plugin.permissionManage; | 		requiredPermission = Plugin.permissionManage; | ||||||
|  | 		 | ||||||
|  | 		needsPermissionAtCurrentLocation = false; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	 | 	 | ||||||
|   | |||||||
| @@ -21,6 +21,8 @@ public class CommandRename extends BaseCommand | |||||||
| 		helpDescription = "Changes the id of a gate."; | 		helpDescription = "Changes the id of a gate."; | ||||||
| 		 | 		 | ||||||
| 		requiredPermission = Plugin.permissionManage; | 		requiredPermission = Plugin.permissionManage; | ||||||
|  | 		 | ||||||
|  | 		needsPermissionAtCurrentLocation = false; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	 | 	 | ||||||
|   | |||||||
| @@ -16,6 +16,8 @@ public class CommandSetExit extends BaseCommand | |||||||
| 		helpDescription = "Changes the location where the gate will teleport players to your current location."; | 		helpDescription = "Changes the location where the gate will teleport players to your current location."; | ||||||
| 		 | 		 | ||||||
| 		requiredPermission = Plugin.permissionManage; | 		requiredPermission = Plugin.permissionManage; | ||||||
|  | 		 | ||||||
|  | 		needsPermissionAtCurrentLocation = true; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	 | 	 | ||||||
|   | |||||||
| @@ -15,6 +15,8 @@ public class CommandSetHidden extends BaseCommand | |||||||
| 		helpDescription = "Makes a gate NOT consist of gate blocks while open."; | 		helpDescription = "Makes a gate NOT consist of gate blocks while open."; | ||||||
| 		 | 		 | ||||||
| 		requiredPermission = Plugin.permissionManage; | 		requiredPermission = Plugin.permissionManage; | ||||||
|  | 		 | ||||||
|  | 		needsPermissionAtCurrentLocation = false; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	 | 	 | ||||||
|   | |||||||
| @@ -19,6 +19,8 @@ public class CommandSetLocation extends BaseLocationCommand | |||||||
| 		helpDescription = "Set the entrance of the gate to your current location."; | 		helpDescription = "Set the entrance of the gate to your current location."; | ||||||
| 		 | 		 | ||||||
| 		requiredPermission = Plugin.permissionManage; | 		requiredPermission = Plugin.permissionManage; | ||||||
|  | 		 | ||||||
|  | 		needsPermissionAtCurrentLocation = true; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	 | 	 | ||||||
|   | |||||||
| @@ -16,6 +16,8 @@ public class CommandSetVisible extends BaseCommand | |||||||
| 		helpDescription = "Make that gate visible"; | 		helpDescription = "Make that gate visible"; | ||||||
| 		 | 		 | ||||||
| 		requiredPermission = Plugin.permissionManage; | 		requiredPermission = Plugin.permissionManage; | ||||||
|  | 		 | ||||||
|  | 		needsPermissionAtCurrentLocation = false; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	 | 	 | ||||||
|   | |||||||
| @@ -25,10 +25,6 @@ public class PluginPlayerListener extends BaseLocationListener implements Listen | |||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
| 		// Check for permission |  | ||||||
| 		if (!hasPermission(event.getPlayer())) { |  | ||||||
| 			return; |  | ||||||
| 		} |  | ||||||
| 		 | 		 | ||||||
| 		// Find the gate at the current location. | 		// Find the gate at the current location. | ||||||
| 		Gate gateAtLocation = getValidGateAtPlayerLocation(event); | 		Gate gateAtLocation = getValidGateAtPlayerLocation(event); | ||||||
| @@ -38,6 +34,11 @@ public class PluginPlayerListener extends BaseLocationListener implements Listen | |||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
|  | 		// Check for permission | ||||||
|  | 		if (!hasPermission(event.getPlayer(), gateAtLocation)) { | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  | 		 | ||||||
| 		// Teleport the player | 		// Teleport the player | ||||||
| 		checkChunkLoad(gateAtLocation.getLocation().getBlock()); | 		checkChunkLoad(gateAtLocation.getLocation().getBlock()); | ||||||
| 		 | 		 | ||||||
| @@ -72,7 +73,17 @@ public class PluginPlayerListener extends BaseLocationListener implements Listen | |||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	 | 	 | ||||||
| 	protected boolean hasPermission(Player player) { | 	protected boolean hasPermission(Player player, Gate gate)  | ||||||
|         return player.hasPermission(Plugin.permissionUse) || player.hasPermission(Plugin.permissionAll); | 	{ | ||||||
|  | 		if (Plugin.permission == null) // fallback <20> use the standard bukkit permission system | ||||||
|  | 		{ | ||||||
|  | 			return player.hasPermission(Plugin.permissionUse); | ||||||
|  | 		} | ||||||
|  | 		else { | ||||||
|  | 			boolean permAtLocation = Plugin.permission.has(gate.getLocation().getWorld(), player.getName(), Plugin.permissionUse); | ||||||
|  | 			boolean permAtExit = Plugin.permission.has(gate.getExit().getWorld(), player.getName(), Plugin.permissionUse); | ||||||
|  | 			 | ||||||
|  | 			return permAtLocation && permAtExit; | ||||||
|  | 		} | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Tobias Ottenweller
					Tobias Ottenweller