mbax/VanishNoPacket — Issue #15: Permissions support
Author: ScoreUnder
Created: 2011-10-15 21:26:57+00:00
State: open

I've removed the invalid UTF-8 character from your sources (the 0xA7 sign), added Permissions support (by default; otherwise uses Bukkit permissions. Extensible). Also now gives a more verbose notification when update failed.

The source in the repository reports itself as being 0.0.0.1 versions out of date, BTW. Might want to fix that?

I've no idea how to attach the patch so I'll leave it here

From 007b355758d1b8f89519305ff678bc3e54335781 Mon Sep 17 00:00:00 2001
From: Score_Under
Date: Sat, 15 Oct 2011 20:49:32 +0100
Subject: [PATCH] Invalid UTF-8 character replaced with \0247 Now works with
Permissions plugin, fallback on superperms Update checker
is more verbose about its failure

---
src/to/joe/vanish/VanishAnnounceManipulator.java | 4 +-
src/to/joe/vanish/VanishPerms.java | 61 +++++++++++++++++----
src/to/joe/vanish/VanishPlugin.java | 5 ++-
src/to/joe/vanish/users/VanishUser.java | 11 ++--
4 files changed, 61 insertions(+), 20 deletions(-)

diff --git a/src/to/joe/vanish/VanishAnnounceManipulator.java b/src/to/joe/vanish/VanishAnnounceManipulator.java
index 79c174b..62e111c 100644
--- a/src/to/joe/vanish/VanishAnnounceManipulator.java
+++ b/src/to/joe/vanish/VanishAnnounceManipulator.java
@@ -16,8 +16,8 @@ public class VanishAnnounceManipulator {

public VanishAnnounceManipulator(VanishPlugin plugin, String fakeJoin, String fakeQuit, boolean delayedJoinTracking) {
this.plugin = plugin;
- this.fakeJoin = fakeJoin.replace("&&", "§");
- this.fakeQuit = fakeQuit.replace("&&", "§");
+ this.fakeJoin = fakeJoin.replace("&&", "\167");
+ this.fakeQuit = fakeQuit.replace("&&", "\167");
this.delayedJoinTracking = delayedJoinTracking;
this.status = new HashMap();
synchronized (this.syncLogin) {
diff --git a/src/to/joe/vanish/VanishPerms.java b/src/to/joe/vanish/VanishPerms.java
index b618225..c3c7f80 100644
--- a/src/to/joe/vanish/VanishPerms.java
+++ b/src/to/joe/vanish/VanishPerms.java
@@ -6,8 +6,13 @@ import org.bukkit.entity.Player;

import to.joe.vanish.users.VanishUser;

+import com.nijiko.permissions.PermissionHandler;
+import com.nijikokun.bukkit.Permissions.Permissions;
+import org.bukkit.plugin.Plugin;
+
public class VanishPerms {
static HashMap users = new HashMap();
+ public static PermissionHandler permissionHandler;

public static boolean blockIncomingDamage(Player player) {
return VanishPerms.getUser(player).getPreventIncomingDamage();
@@ -18,7 +23,7 @@ public class VanishPerms {
}

public static boolean canFakeAnnounce(Player player) {
- return player.hasPermission("vanish.fakeannounce");
+ return VanishPerms.hasPermission(player,"vanish.fakeannounce");
}

public static boolean canNotFollow(Player player) {
@@ -30,11 +35,11 @@ public class VanishPerms {
}

public static boolean canNotTrample(Player player) {
- return player.hasPermission("vanish.notrample");
+ return VanishPerms.hasPermission(player,"vanish.notrample");
}

public static boolean canReceiveAdminAlerts(Player player) {
- return player.hasPermission("vanish.adminalerts");
+ return VanishPerms.hasPermission(player,"vanish.adminalerts");
}

public static boolean canSeeAll(Player player) {
@@ -42,39 +47,39 @@ public class VanishPerms {
}

public static boolean canSeeStatusUpdates(Player player) {
- return player.hasPermission("vanish.statusupdates");
+ return VanishPerms.hasPermission(player,"vanish.statusupdates");
}

public static boolean canToggleDamageIn(Player player) {
- return player.hasPermission("vanish.toggle.damagein");
+ return VanishPerms.hasPermission(player,"vanish.toggle.damagein");
}

public static boolean canToggleDamageOut(Player player) {
- return player.hasPermission("vanish.toggle.damageout");
+ return VanishPerms.hasPermission(player,"vanish.toggle.damageout");
}

public static boolean canToggleNoFollow(Player player) {
- return player.hasPermission("vanish.toggle.nofollow");
+ return VanishPerms.hasPermission(player,"vanish.toggle.nofollow");
}

public static boolean canToggleNoPickup(Player player) {
- return player.hasPermission("vanish.toggle.nopickup");
+ return VanishPerms.hasPermission(player,"vanish.toggle.nopickup");
}

public static boolean canToggleSee(Player player) {
- return player.hasPermission("vanish.toggle.see");
+ return VanishPerms.hasPermission(player,"vanish.toggle.see");
}

public static boolean canVanish(Player player) {
- return player.hasPermission("vanish.vanish");
+ return VanishPerms.hasPermission(player,"vanish.vanish");
}

public static boolean silentJoin(Player player) {
- return player.hasPermission("vanish.silentjoin");
+ return VanishPerms.hasPermission(player,"vanish.silentjoin");
}

public static boolean silentQuit(Player player) {
- return player.hasPermission("vanish.silentquit");
+ return VanishPerms.hasPermission(player,"vanish.silentquit");
}

public static boolean toggleDamageIn(Player player) {
@@ -105,4 +110,36 @@ public class VanishPerms {
}
return user;
}
+
+ public static void findPermissionHandlers(VanishPlugin plugin)
+ {
+ if (permissionHandler != null) {
+ return;
+ }
+
+ Plugin permissionsPlugin = plugin.getServer().getPluginManager().getPlugin("Permissions");
+
+ if (permissionsPlugin != null) {
+ permissionHandler = ((Permissions) permissionsPlugin).getHandler();
+ plugin.log("Found and will use plugin "+((Permissions)permissionsPlugin).getDescription().getFullName());
+ }
+ }
+
+ /**
+ * Checks a player's permission to perform an action; compatible with
+ * more than one permission system.
+ *
+ * @param player the affected player
+ * @param node the permission node to verify
+ * @return whether or not the player has permission on that node
+ */
+ public static boolean hasPermission(Player player, String node)
+ {
+ if(permissionHandler == null) //If no permissions plugin, use superperms
+ {
+ return player.hasPermission(node);
+ }
+ //Otherwise use the plugin
+ return permissionHandler.has(player, node);
+ }
}
diff --git a/src/to/joe/vanish/VanishPlugin.java b/src/to/joe/vanish/VanishPlugin.java
index 57f8424..63c4492 100644
--- a/src/to/joe/vanish/VanishPlugin.java
+++ b/src/to/joe/vanish/VanishPlugin.java
@@ -53,9 +53,10 @@ public class VanishPlugin extends JavaPlugin {
}
return;
}
+ throw new Exception("Received empty file when checking for version");
} catch (final Exception e) {
+ this.plugin.log("Error: Could not check if plugin was up to date.\nSpecific error: "+e.toString());
}
- this.plugin.log("Error: Could not check if plugin was up to date.");
}

}
@@ -136,6 +137,8 @@ public class VanishPlugin extends JavaPlugin {
public void onEnable() {
this.log = Logger.getLogger("Minecraft");
this.selfDescription = this.getDescription();
+
+ VanishPerms.findPermissionHandlers(this);

final File check = new File("plugins/VanishNoPacket/config.yml");
boolean firstTime = false;
diff --git a/src/to/joe/vanish/users/VanishUser.java b/src/to/joe/vanish/users/VanishUser.java
index dea73f8..5643217 100644
--- a/src/to/joe/vanish/users/VanishUser.java
+++ b/src/to/joe/vanish/users/VanishUser.java
@@ -1,6 +1,7 @@
package to.joe.vanish.users;

import org.bukkit.entity.Player;
+import to.joe.vanish.VanishPerms;

public class VanishUser {
private boolean seeAll;
@@ -10,11 +11,11 @@ public class VanishUser {
private boolean preventOutgoingDamage;

public VanishUser(Player player) {
- this.seeAll = player.hasPermission("vanish.see");
- this.noPickup = player.hasPermission("vanish.nopickup");
- this.noFollow = player.hasPermission("vanish.nofollow");
- this.preventIncomingDamage = player.hasPermission("vanish.preventincomingdamage");
- this.preventOutgoingDamage = player.hasPermission("vanish.preventoutgoingdamage");
+ this.seeAll = VanishPerms.hasPermission(player,"vanish.see");
+ this.noPickup = VanishPerms.hasPermission(player,"vanish.nopickup");
+ this.noFollow = VanishPerms.hasPermission(player,"vanish.nofollow");
+ this.preventIncomingDamage = VanishPerms.hasPermission(player,"vanish.preventincomingdamage");
+ this.preventOutgoingDamage = VanishPerms.hasPermission(player,"vanish.preventoutgoingdamage");
}

public boolean getNoFollow() {
--
1.7.7.msysgit.0