mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-14 18:44:48 +02:00
New permissions for signs
This commit is contained in:
@@ -32,8 +32,7 @@ public class EssentialsSign
|
|||||||
{
|
{
|
||||||
final ISign sign = new EventSign(event);
|
final ISign sign = new EventSign(event);
|
||||||
final IUser user = ess.getUser(event.getPlayer());
|
final IUser user = ess.getUser(event.getPlayer());
|
||||||
if (!(user.isAuthorized("essentials.signs." + signName.toLowerCase(Locale.ENGLISH) + ".create")
|
if (!SignsPermissions.getCreatePermission(signName).isAuthorized(user))
|
||||||
|| user.isAuthorized("essentials.signs.create." + signName.toLowerCase(Locale.ENGLISH))))
|
|
||||||
{
|
{
|
||||||
// Return true, so other plugins can use the same sign title, just hope
|
// Return true, so other plugins can use the same sign title, just hope
|
||||||
// they won't change it to §1[Signname]
|
// they won't change it to §1[Signname]
|
||||||
@@ -82,8 +81,7 @@ public class EssentialsSign
|
|||||||
final IUser user = ess.getUser(player);
|
final IUser user = ess.getUser(player);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return (user.isAuthorized("essentials.signs." + signName.toLowerCase(Locale.ENGLISH) + ".use")
|
return SignsPermissions.getUsePermission(signName).isAuthorized(user)
|
||||||
|| user.isAuthorized("essentials.signs.use." + signName.toLowerCase(Locale.ENGLISH)))
|
|
||||||
&& onSignInteract(sign, user, getUsername(user), ess);
|
&& onSignInteract(sign, user, getUsername(user), ess);
|
||||||
}
|
}
|
||||||
catch (ChargeException ex)
|
catch (ChargeException ex)
|
||||||
@@ -104,8 +102,7 @@ public class EssentialsSign
|
|||||||
final IUser user = ess.getUser(player);
|
final IUser user = ess.getUser(player);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return (user.isAuthorized("essentials.signs." + signName.toLowerCase(Locale.ENGLISH) + ".break")
|
return SignsPermissions.getBreakPermission(signName).isAuthorized(user)
|
||||||
|| user.isAuthorized("essentials.signs.break." + signName.toLowerCase(Locale.ENGLISH)))
|
|
||||||
&& onSignBreak(sign, user, getUsername(user), ess);
|
&& onSignBreak(sign, user, getUsername(user), ess);
|
||||||
}
|
}
|
||||||
catch (SignException ex)
|
catch (SignException ex)
|
||||||
|
@@ -84,7 +84,7 @@ public class SignBlockListener implements Listener
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
IUser user = ess.getUser(event.getPlayer());
|
IUser user = ess.getUser(event.getPlayer());
|
||||||
if (user.isAuthorized("essentials.signs.color"))
|
if (SignsPermissions.COLOR.isAuthorized(user))
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
|
@@ -4,6 +4,7 @@ import com.earth2me.essentials.ChargeException;
|
|||||||
import com.earth2me.essentials.Trade;
|
import com.earth2me.essentials.Trade;
|
||||||
import com.earth2me.essentials.api.IEssentials;
|
import com.earth2me.essentials.api.IEssentials;
|
||||||
import com.earth2me.essentials.api.IUser;
|
import com.earth2me.essentials.api.IUser;
|
||||||
|
import com.earth2me.essentials.perm.KitPermissions;
|
||||||
import com.earth2me.essentials.settings.Kit;
|
import com.earth2me.essentials.settings.Kit;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@@ -52,7 +53,7 @@ public class SignKit extends EssentialsSign
|
|||||||
final String kitName = sign.getLine(1).toLowerCase(Locale.ENGLISH);
|
final String kitName = sign.getLine(1).toLowerCase(Locale.ENGLISH);
|
||||||
final String group = sign.getLine(2);
|
final String group = sign.getLine(2);
|
||||||
if ((!group.isEmpty() && ("§2Everyone".equals(group) || player.inGroup(group)))
|
if ((!group.isEmpty() && ("§2Everyone".equals(group) || player.inGroup(group)))
|
||||||
|| (group.isEmpty() && (player.isAuthorized("essentials.kit." + kitName))))
|
|| (group.isEmpty() && KitPermissions.getPermission(kitName).isAuthorized(player)))
|
||||||
{
|
{
|
||||||
final Trade charge = getTrade(sign, 3, ess);
|
final Trade charge = getTrade(sign, 3, ess);
|
||||||
charge.isAffordableFor(player);
|
charge.isAffordableFor(player);
|
||||||
|
@@ -36,7 +36,7 @@ public class SignProtection extends EssentialsSign
|
|||||||
{
|
{
|
||||||
final SignProtectionState state = isBlockProtected(sign.getBlock(), player, username, true);
|
final SignProtectionState state = isBlockProtected(sign.getBlock(), player, username, true);
|
||||||
if (state == SignProtectionState.NOSIGN || state == SignProtectionState.OWNER
|
if (state == SignProtectionState.NOSIGN || state == SignProtectionState.OWNER
|
||||||
|| player.isAuthorized("essentials.signs.protection.override"))
|
|| SignsPermissions.PROTECTION_OVERRIDE.isAuthorized(player))
|
||||||
{
|
{
|
||||||
sign.setLine(3, "§1" + username);
|
sign.setLine(3, "§1" + username);
|
||||||
return true;
|
return true;
|
||||||
@@ -143,7 +143,7 @@ public class SignProtection extends EssentialsSign
|
|||||||
{
|
{
|
||||||
return SignProtectionState.NOT_ALLOWED;
|
return SignProtectionState.NOT_ALLOWED;
|
||||||
}
|
}
|
||||||
if (user.isAuthorized("essentials.signs.protection.override"))
|
if (SignsPermissions.PROTECTION_OVERRIDE.isAuthorized(user))
|
||||||
{
|
{
|
||||||
return SignProtectionState.OWNER;
|
return SignProtectionState.OWNER;
|
||||||
}
|
}
|
||||||
@@ -254,7 +254,7 @@ public class SignProtection extends EssentialsSign
|
|||||||
final SignProtectionState state = isBlockProtected(adjBlock, player, username, true);
|
final SignProtectionState state = isBlockProtected(adjBlock, player, username, true);
|
||||||
|
|
||||||
if ((state == SignProtectionState.ALLOWED || state == SignProtectionState.NOT_ALLOWED)
|
if ((state == SignProtectionState.ALLOWED || state == SignProtectionState.NOT_ALLOWED)
|
||||||
&& !player.isAuthorized("essentials.signs.protection.override"))
|
&& !SignsPermissions.PROTECTION_OVERRIDE.isAuthorized(player))
|
||||||
{
|
{
|
||||||
player.sendMessage(_("noPlacePermission", block.getType().toString().toLowerCase(Locale.ENGLISH)));
|
player.sendMessage(_("noPlacePermission", block.getType().toString().toLowerCase(Locale.ENGLISH)));
|
||||||
return false;
|
return false;
|
||||||
@@ -275,7 +275,7 @@ public class SignProtection extends EssentialsSign
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (state == SignProtectionState.NOT_ALLOWED
|
if (state == SignProtectionState.NOT_ALLOWED
|
||||||
&& player.isAuthorized("essentials.signs.protection.override"))
|
&& SignsPermissions.PROTECTION_OVERRIDE.isAuthorized(player))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -297,7 +297,7 @@ public class SignProtection extends EssentialsSign
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((state == SignProtectionState.ALLOWED || state == SignProtectionState.NOT_ALLOWED)
|
if ((state == SignProtectionState.ALLOWED || state == SignProtectionState.NOT_ALLOWED)
|
||||||
&& player.isAuthorized("essentials.signs.protection.override"))
|
&& SignsPermissions.PROTECTION_OVERRIDE.isAuthorized(player))
|
||||||
{
|
{
|
||||||
checkIfSignsAreBroken(block, player, username, ess);
|
checkIfSignsAreBroken(block, player, username, ess);
|
||||||
return true;
|
return true;
|
||||||
|
@@ -97,7 +97,7 @@ public class SignTrade extends EssentialsSign
|
|||||||
protected boolean onSignBreak(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException
|
protected boolean onSignBreak(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException
|
||||||
{
|
{
|
||||||
if ((sign.getLine(3).length() > 3 && sign.getLine(3).substring(2).equalsIgnoreCase(username))
|
if ((sign.getLine(3).length() > 3 && sign.getLine(3).substring(2).equalsIgnoreCase(username))
|
||||||
|| player.isAuthorized("essentials.signs.trade.override"))
|
|| SignsPermissions.TRADE_OVERRIDE.isAuthorized(player))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -109,7 +109,7 @@ public class SignTrade extends EssentialsSign
|
|||||||
}
|
}
|
||||||
catch (SignException e)
|
catch (SignException e)
|
||||||
{
|
{
|
||||||
if (player.isAuthorized("essentials.signs.trade.override"))
|
if (SignsPermissions.TRADE_OVERRIDE.isAuthorized(player))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,7 @@ import com.earth2me.essentials.ChargeException;
|
|||||||
import com.earth2me.essentials.Trade;
|
import com.earth2me.essentials.Trade;
|
||||||
import com.earth2me.essentials.api.IEssentials;
|
import com.earth2me.essentials.api.IEssentials;
|
||||||
import com.earth2me.essentials.api.IUser;
|
import com.earth2me.essentials.api.IUser;
|
||||||
|
import com.earth2me.essentials.perm.WarpPermissions;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||||
|
|
||||||
|
|
||||||
@@ -51,7 +52,7 @@ public class SignWarp extends EssentialsSign
|
|||||||
final String group = sign.getLine(2);
|
final String group = sign.getLine(2);
|
||||||
|
|
||||||
if ((!group.isEmpty() && ("§2Everyone".equals(group) || player.inGroup(group)))
|
if ((!group.isEmpty() && ("§2Everyone".equals(group) || player.inGroup(group)))
|
||||||
|| (group.isEmpty() && player.isAuthorized("essentials.warp." + warpName)))
|
|| (group.isEmpty() && WarpPermissions.getPermission(warpName).isAuthorized(player)))
|
||||||
{
|
{
|
||||||
final Trade charge = getTrade(sign, 3, ess);
|
final Trade charge = getTrade(sign, 3, ess);
|
||||||
try
|
try
|
||||||
|
@@ -0,0 +1,55 @@
|
|||||||
|
package com.earth2me.essentials.signs;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.api.IPermission;
|
||||||
|
import com.earth2me.essentials.perm.BasePermission;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class SignsPermissions {
|
||||||
|
public static final IPermission COLOR = new BasePermission("essentials.signs.","color");
|
||||||
|
|
||||||
|
public static final IPermission PROTECTION_OVERRIDE = new BasePermission("essentials.signs.protection.", "override");
|
||||||
|
|
||||||
|
public static final IPermission TRADE_OVERRIDE = new BasePermission("essentials.signs.trade.", "override");
|
||||||
|
|
||||||
|
|
||||||
|
private static Map<String, IPermission> createpermissions = new HashMap<String, IPermission>();
|
||||||
|
|
||||||
|
public static IPermission getCreatePermission(final String signName)
|
||||||
|
{
|
||||||
|
IPermission perm = createpermissions.get(signName);
|
||||||
|
if (perm == null)
|
||||||
|
{
|
||||||
|
perm = new BasePermission("essentials.signs.create.",signName.toLowerCase(Locale.ENGLISH));
|
||||||
|
createpermissions.put(signName, perm);
|
||||||
|
}
|
||||||
|
return perm;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Map<String, IPermission> usepermissions = new HashMap<String, IPermission>();
|
||||||
|
|
||||||
|
public static IPermission getUsePermission(final String signName)
|
||||||
|
{
|
||||||
|
IPermission perm = usepermissions.get(signName);
|
||||||
|
if (perm == null)
|
||||||
|
{
|
||||||
|
perm = new BasePermission("essentials.signs.create.",signName.toLowerCase(Locale.ENGLISH));
|
||||||
|
usepermissions.put(signName, perm);
|
||||||
|
}
|
||||||
|
return perm;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Map<String, IPermission> breakpermissions = new HashMap<String, IPermission>();
|
||||||
|
|
||||||
|
public static IPermission getBreakPermission(final String signName)
|
||||||
|
{
|
||||||
|
IPermission perm = breakpermissions.get(signName);
|
||||||
|
if (perm == null)
|
||||||
|
{
|
||||||
|
perm = new BasePermission("essentials.signs.create.",signName.toLowerCase(Locale.ENGLISH));
|
||||||
|
breakpermissions.put(signName, perm);
|
||||||
|
}
|
||||||
|
return perm;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user