[Version 0.7.4.3]

- Implement StargateAccessEvent, used for bypassing permission
checks/denying access to gates.
This commit is contained in:
Steven Scott 2012-01-27 22:01:52 -08:00
parent 82894b2e52
commit 64053cdc63
5 changed files with 136 additions and 22 deletions

2
README
View File

@ -198,6 +198,8 @@ createConflict=Gate conflicts with existing gate
=============
Changes
=============
[Version 0.7.4.3]
- Implement StargateAccessEvent, used for bypassing permission checks/denying access to gates.
[Version 0.7.4.2]
- stargate.create.personal permission now also allows user to use personal gates
[Version 0.7.4.1]

View File

@ -6,6 +6,8 @@ import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.TheDgtl.Stargate.event.StargateAccessEvent;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
@ -386,6 +388,15 @@ public class Stargate extends JavaPlugin {
return false;
}
/*
* Call the StargateAccessPortal event, used for other plugins to bypass Permissions checks
*/
public static StargateAccessEvent canAccessPortal(Player player, Portal portal) {
StargateAccessEvent event = new StargateAccessEvent(player, portal);
Stargate.server.getPluginManager().callEvent(event);
return event;
}
/*
* Return true if the portal is free for the player
*/
@ -600,18 +611,27 @@ public class Stargate extends JavaPlugin {
Portal dest = portal.getDestination();
if (dest == null) return;
// Check if player has access to this network
if (!canAccessNetwork(player, portal.getNetwork())) {
// Check if we're bypassing the permission check
StargateAccessEvent access = canAccessPortal(player, portal);
if (access.getDeny()) {
Stargate.sendMessage(player, Stargate.getString("denyMsg"));
portal.close(false);
return;
}
if (!access.getBypassPerms()) {
// Check if player has access to this network
if (!canAccessNetwork(player, portal.getNetwork())) {
Stargate.sendMessage(player, Stargate.getString("denyMsg"));
portal.close(false);
return;
}
// Check if player has access to destination world
if (!canAccessWorld(player, dest.getWorld().getName())) {
Stargate.sendMessage(player, Stargate.getString("denyMsg"));
portal.close(false);
return;
// Check if player has access to destination world
if (!canAccessWorld(player, dest.getWorld().getName())) {
Stargate.sendMessage(player, Stargate.getString("denyMsg"));
portal.close(false);
return;
}
}
int cost = Stargate.getUseCost(player, portal, dest);
@ -694,20 +714,30 @@ public class Stargate extends JavaPlugin {
Portal destination = portal.getDestination();
if (destination == null) return;
// Check if player has access to this network
if (!canAccessNetwork(player, portal.getNetwork())) {
// Check if we're bypassing the perm check
StargateAccessEvent access = canAccessPortal(player, portal);
if (access.getDeny()) {
Stargate.sendMessage(player, Stargate.getString("denyMsg"));
portal.teleport(player, portal, event);
portal.close(false);
return;
}
if (!access.getBypassPerms()) {
// Check if player has access to this network
if (!canAccessNetwork(player, portal.getNetwork())) {
Stargate.sendMessage(player, Stargate.getString("denyMsg"));
portal.teleport(player, portal, event);
portal.close(false);
return;
}
// Check if player has access to destination world
if (!canAccessWorld(player, destination.getWorld().getName())) {
Stargate.sendMessage(player, Stargate.getString("denyMsg"));
portal.teleport(player, portal, event);
portal.close(false);
return;
// Check if player has access to destination world
if (!canAccessWorld(player, destination.getWorld().getName())) {
Stargate.sendMessage(player, Stargate.getString("denyMsg"));
portal.teleport(player, portal, event);
portal.close(false);
return;
}
}
int cost = Stargate.getUseCost(player, portal, destination);
@ -751,10 +781,18 @@ public class Stargate extends JavaPlugin {
event.setUseItemInHand(Result.DENY);
event.setUseInteractedBlock(Result.DENY);
if (!Stargate.canAccessNetwork(player, portal.getNetwork())) {
// Check if we're bypassing the perm check
StargateAccessEvent access = canAccessPortal(player, portal);
if (access.getDeny()) {
Stargate.sendMessage(player, Stargate.getString("denyMsg"));
return;
}
if (!access.getBypassPerms()) {
if (!Stargate.canAccessNetwork(player, portal.getNetwork())) {
Stargate.sendMessage(player, Stargate.getString("denyMsg"));
return;
}
}
if ((!portal.isOpen()) && (!portal.isFixed())) {
portal.cycleDestination(player);
@ -771,10 +809,18 @@ public class Stargate extends JavaPlugin {
event.setUseItemInHand(Result.DENY);
event.setUseInteractedBlock(Result.DENY);
if (!Stargate.canAccessNetwork(player, portal.getNetwork())) {
// Check if we're bypassing the perm check
StargateAccessEvent access = canAccessPortal(player, portal);
if (access.getDeny()) {
Stargate.sendMessage(player, Stargate.getString("denyMsg"));
return;
}
if (!access.getBypassPerms()) {
if (!Stargate.canAccessNetwork(player, portal.getNetwork())) {
Stargate.sendMessage(player, Stargate.getString("denyMsg"));
return;
}
}
onButtonPressed(player, portal);
}
return;
@ -793,10 +839,18 @@ public class Stargate extends JavaPlugin {
event.setCancelled(true);
}
if (!Stargate.canAccessNetwork(player, portal.getNetwork())) {
// Check if we're bypassing the perm check
StargateAccessEvent access = canAccessPortal(player, portal);
if (access.getDeny()) {
Stargate.sendMessage(player, Stargate.getString("denyMsg"));
return;
}
if (!access.getBypassPerms()) {
if (!Stargate.canAccessNetwork(player, portal.getNetwork())) {
Stargate.sendMessage(player, Stargate.getString("denyMsg"));
return;
}
}
if ((!portal.isOpen()) && (!portal.isFixed())) {
portal.cycleDestination(player, -1);
@ -814,10 +868,18 @@ public class Stargate extends JavaPlugin {
event.setCancelled(true);
}
if (!Stargate.canAccessNetwork(player, portal.getNetwork())) {
// Check if we're bypassing the perm check
StargateAccessEvent access = canAccessPortal(player, portal);
if (access.getDeny()) {
Stargate.sendMessage(player, Stargate.getString("denyMsg"));
return;
}
if (!access.getBypassPerms()) {
if (!Stargate.canAccessNetwork(player, portal.getNetwork())) {
Stargate.sendMessage(player, Stargate.getString("denyMsg"));
return;
}
}
onButtonPressed(player, portal);
}
}

View File

@ -0,0 +1,44 @@
package net.TheDgtl.Stargate.event;
import org.bukkit.entity.Player;
import net.TheDgtl.Stargate.Portal;
public class StargateAccessEvent extends StargateEvent {
/**
*
*/
private static final long serialVersionUID = -1009056668229801760L;
private Player player;
private boolean bypassPerms;
private boolean deny;
public StargateAccessEvent(Player player, Portal portal) {
super("StargateAccessEvent", portal);
this.player = player;
this.bypassPerms = false;
this.deny = false;
}
public void setBypassPerms(boolean access) {
this.bypassPerms = access;
}
public boolean getBypassPerms() {
return this.bypassPerms;
}
public boolean getDeny() {
return this.deny;
}
public void setDeny(boolean deny) {
this.deny = deny;
}
public Player getPlayer() {
return this.player;
}
}

View File

@ -29,6 +29,10 @@ public class StargateListener extends CustomEventListener implements Listener {
}
public void onStargateAccess(StargateAccessEvent event) {
}
@Override
public void onCustomEvent(Event event) {
if (event instanceof StargateOpenEvent) {
@ -41,6 +45,8 @@ public class StargateListener extends CustomEventListener implements Listener {
onStargateDeactivate((StargateDeactivateEvent)event);
} else if (event instanceof StargatePortalEvent) {
onStargatePortal((StargatePortalEvent)event);
} else if (event instanceof StargateAccessEvent) {
onStargateAccess((StargateAccessEvent)event);
}
}
}

View File

@ -1,6 +1,6 @@
name: Stargate
main: net.TheDgtl.Stargate.Stargate
version: 0.7.4.2
version: 0.7.4.3
description: Stargate mod for Bukkit
author: Drakia
website: http://www.thedgtl.net