mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-11-09 04:20:42 +01:00
Fix Protection signs
This commit is contained in:
parent
e596f85953
commit
ecaecc5e62
@ -35,11 +35,13 @@ public class SignProtection extends EssentialsSign
|
|||||||
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException
|
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException
|
||||||
{
|
{
|
||||||
sign.setLine(3, "§4" + username);
|
sign.setLine(3, "§4" + username);
|
||||||
if (hasAdjacentBlock(sign.getBlock()) && isBlockProtected(sign.getBlock(), player, username) != SignProtectionState.NOT_ALLOWED)
|
if (hasAdjacentBlock(sign.getBlock()) && isBlockProtected(sign.getBlock(), player, username, true) != SignProtectionState.NOT_ALLOWED)
|
||||||
{
|
{
|
||||||
sign.setLine(3, "§1" + username);
|
sign.setLine(3, "§1" + username);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
player.sendMessage("§4You are not allowed to create sign here.");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -71,7 +73,7 @@ public class SignProtection extends EssentialsSign
|
|||||||
|
|
||||||
private void checkIfSignsAreBroken(final Block block, final User player, final String username, final IEssentials ess)
|
private void checkIfSignsAreBroken(final Block block, final User player, final String username, final IEssentials ess)
|
||||||
{
|
{
|
||||||
final Map<Location, SignProtectionState> signs = getConnectedSigns(block, player, username);
|
final Map<Location, SignProtectionState> signs = getConnectedSigns(block, player, username, false);
|
||||||
for (Map.Entry<Location, SignProtectionState> entry : signs.entrySet())
|
for (Map.Entry<Location, SignProtectionState> entry : signs.entrySet())
|
||||||
{
|
{
|
||||||
if (entry.getValue() != SignProtectionState.NOSIGN)
|
if (entry.getValue() != SignProtectionState.NOSIGN)
|
||||||
@ -87,10 +89,10 @@ public class SignProtection extends EssentialsSign
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<Location, SignProtectionState> getConnectedSigns(final Block block, final User user, final String username)
|
private Map<Location, SignProtectionState> getConnectedSigns(final Block block, final User user, final String username, boolean secure)
|
||||||
{
|
{
|
||||||
final Map<Location, SignProtectionState> signs = new HashMap<Location, SignProtectionState>();
|
final Map<Location, SignProtectionState> signs = new HashMap<Location, SignProtectionState>();
|
||||||
getConnectedSigns(block, signs, user, username, 2);
|
getConnectedSigns(block, signs, user, username, secure ? 4 : 2);
|
||||||
return signs;
|
return signs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,7 +157,7 @@ public class SignProtection extends EssentialsSign
|
|||||||
return SignProtectionState.ALLOWED;
|
return SignProtectionState.ALLOWED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sign.getLine(3).equalsIgnoreCase(username))
|
if (sign.getLine(3).substring(2).equalsIgnoreCase(username))
|
||||||
{
|
{
|
||||||
return SignProtectionState.OWNER;
|
return SignProtectionState.OWNER;
|
||||||
}
|
}
|
||||||
@ -175,9 +177,9 @@ public class SignProtection extends EssentialsSign
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public SignProtectionState isBlockProtected(final Block block, final User user, final String username)
|
public SignProtectionState isBlockProtected(final Block block, final User user, final String username, boolean secure)
|
||||||
{
|
{
|
||||||
final Map<Location, SignProtectionState> signs = getConnectedSigns(block, user, username);
|
final Map<Location, SignProtectionState> signs = getConnectedSigns(block, user, username, secure);
|
||||||
SignProtectionState retstate = SignProtectionState.NOSIGN;
|
SignProtectionState retstate = SignProtectionState.NOSIGN;
|
||||||
for (SignProtectionState state : signs.values())
|
for (SignProtectionState state : signs.values())
|
||||||
{
|
{
|
||||||
@ -235,28 +237,25 @@ public class SignProtection extends EssentialsSign
|
|||||||
@Override
|
@Override
|
||||||
protected boolean onBlockPlace(final Block block, final User player, final String username, final IEssentials ess) throws SignException
|
protected boolean onBlockPlace(final Block block, final User player, final String username, final IEssentials ess) throws SignException
|
||||||
{
|
{
|
||||||
final SignProtectionState state = isBlockProtected(block, player, username);
|
for (Block adjBlock : getAdjacentBlocks(block))
|
||||||
|
|
||||||
if (state == SignProtectionState.OWNER || state == SignProtectionState.NOSIGN)
|
|
||||||
{
|
{
|
||||||
return true;
|
final SignProtectionState state = isBlockProtected(adjBlock, player, username, true);
|
||||||
|
|
||||||
|
if ((state == SignProtectionState.ALLOWED || state == SignProtectionState.NOT_ALLOWED)
|
||||||
|
&& !player.isAuthorized("essentials.signs.protection.override"))
|
||||||
|
{
|
||||||
|
player.sendMessage(Util.format("noPlacePermission", block.getType().toString().toLowerCase()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
if ((state == SignProtectionState.ALLOWED || state == SignProtectionState.NOT_ALLOWED)
|
|
||||||
&& player.isAuthorized("essentials.signs.protection.override"))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
player.sendMessage(Util.format("noPlacePermission", block.getType().toString().toLowerCase()));
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onBlockInteract(final Block block, final User player, final String username, final IEssentials ess) throws SignException
|
protected boolean onBlockInteract(final Block block, final User player, final String username, final IEssentials ess) throws SignException
|
||||||
{
|
{
|
||||||
final SignProtectionState state = isBlockProtected(block, player, username);
|
final SignProtectionState state = isBlockProtected(block, player, username, false);
|
||||||
|
|
||||||
if (state == SignProtectionState.OWNER || state == SignProtectionState.NOSIGN || state == SignProtectionState.ALLOWED)
|
if (state == SignProtectionState.OWNER || state == SignProtectionState.NOSIGN || state == SignProtectionState.ALLOWED)
|
||||||
{
|
{
|
||||||
@ -277,7 +276,7 @@ public class SignProtection extends EssentialsSign
|
|||||||
@Override
|
@Override
|
||||||
protected boolean onBlockBreak(final Block block, final User player, final String username, final IEssentials ess) throws SignException
|
protected boolean onBlockBreak(final Block block, final User player, final String username, final IEssentials ess) throws SignException
|
||||||
{
|
{
|
||||||
final SignProtectionState state = isBlockProtected(block, player, username);
|
final SignProtectionState state = isBlockProtected(block, player, username, false);
|
||||||
|
|
||||||
if (state == SignProtectionState.OWNER || state == SignProtectionState.NOSIGN)
|
if (state == SignProtectionState.OWNER || state == SignProtectionState.NOSIGN)
|
||||||
{
|
{
|
||||||
@ -300,7 +299,7 @@ public class SignProtection extends EssentialsSign
|
|||||||
@Override
|
@Override
|
||||||
public boolean onBlockExplode(final Block block, final IEssentials ess)
|
public boolean onBlockExplode(final Block block, final IEssentials ess)
|
||||||
{
|
{
|
||||||
final SignProtectionState state = isBlockProtected(block, null, null);
|
final SignProtectionState state = isBlockProtected(block, null, null, false);
|
||||||
|
|
||||||
return state == SignProtectionState.NOSIGN;
|
return state == SignProtectionState.NOSIGN;
|
||||||
}
|
}
|
||||||
@ -308,7 +307,7 @@ public class SignProtection extends EssentialsSign
|
|||||||
@Override
|
@Override
|
||||||
public boolean onBlockBurn(final Block block, final IEssentials ess)
|
public boolean onBlockBurn(final Block block, final IEssentials ess)
|
||||||
{
|
{
|
||||||
final SignProtectionState state = isBlockProtected(block, null, null);
|
final SignProtectionState state = isBlockProtected(block, null, null, false);
|
||||||
|
|
||||||
return state == SignProtectionState.NOSIGN;
|
return state == SignProtectionState.NOSIGN;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user