mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-23 17:47:34 +01:00
Add and implement sign break/create/interact events to EssAPI
Implement AfkStatusChangeEvent
This commit is contained in:
parent
0b71b6e93d
commit
d48c02021d
@ -13,6 +13,7 @@ import java.util.GregorianCalendar;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.events.AfkStatusChangeEvent;
|
||||
import net.ess3.api.events.UserBalanceUpdateEvent;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
@ -486,6 +487,13 @@ public class User extends UserData implements Comparable<User>, IReplyTo, net.es
|
||||
@Override
|
||||
public void setAfk(final boolean set)
|
||||
{
|
||||
final AfkStatusChangeEvent afkEvent = new AfkStatusChangeEvent(this, set);
|
||||
ess.getServer().getPluginManager().callEvent(afkEvent);
|
||||
if (afkEvent.isCancelled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.setSleepingIgnored(this.isAuthorized("essentials.sleepingignored") ? true : set);
|
||||
if (set && !isAfk())
|
||||
{
|
||||
@ -495,15 +503,13 @@ public class User extends UserData implements Comparable<User>, IReplyTo, net.es
|
||||
{
|
||||
afkPosition = null;
|
||||
}
|
||||
super.setAfk(set);
|
||||
_setAfk(set);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public boolean toggleAfk()
|
||||
{
|
||||
final boolean now = super.toggleAfk();
|
||||
this.setSleepingIgnored(this.isAuthorized("essentials.sleepingignored") ? true : now);
|
||||
return now;
|
||||
setAfk(!isAfk());
|
||||
return isAfk();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -729,19 +729,13 @@ public abstract class UserData extends PlayerExtension implements IConf
|
||||
return afk;
|
||||
}
|
||||
|
||||
public void setAfk(boolean set)
|
||||
public void _setAfk(boolean set)
|
||||
{
|
||||
afk = set;
|
||||
config.setProperty("afk", set);
|
||||
config.save();
|
||||
}
|
||||
|
||||
public boolean toggleAfk()
|
||||
{
|
||||
boolean ret = !isAfk();
|
||||
setAfk(ret);
|
||||
return ret;
|
||||
}
|
||||
private boolean newplayer;
|
||||
private String geolocation;
|
||||
|
||||
|
@ -8,6 +8,9 @@ import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.events.SignBreakEvent;
|
||||
import net.ess3.api.events.SignCreateEvent;
|
||||
import net.ess3.api.events.SignInteractEvent;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
@ -28,7 +31,7 @@ public class EssentialsSign
|
||||
this.signName = signName;
|
||||
}
|
||||
|
||||
public final boolean onSignCreate(final SignChangeEvent event, final IEssentials ess)
|
||||
protected final boolean onSignCreate(final SignChangeEvent event, final IEssentials ess)
|
||||
{
|
||||
final ISign sign = new EventSign(event);
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
@ -40,6 +43,14 @@ public class EssentialsSign
|
||||
return true;
|
||||
}
|
||||
sign.setLine(0, _("signFormatFail", this.signName));
|
||||
|
||||
final SignCreateEvent signEvent = new SignCreateEvent(sign, this, user);
|
||||
ess.getServer().getPluginManager().callEvent(signEvent);
|
||||
if (signEvent.isCancelled())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
final boolean ret = onSignCreate(sign, user, getUsername(user), ess);
|
||||
@ -76,12 +87,12 @@ public class EssentialsSign
|
||||
return this.signName;
|
||||
}
|
||||
|
||||
private String getUsername(final User user)
|
||||
public String getUsername(final User user)
|
||||
{
|
||||
return user.getName().substring(0, user.getName().length() > 13 ? 13 : user.getName().length());
|
||||
}
|
||||
|
||||
public final boolean onSignInteract(final Block block, final Player player, final IEssentials ess)
|
||||
protected final boolean onSignInteract(final Block block, final Player player, final IEssentials ess)
|
||||
{
|
||||
final ISign sign = new BlockSign(block);
|
||||
final User user = ess.getUser(player);
|
||||
@ -91,9 +102,20 @@ public class EssentialsSign
|
||||
}
|
||||
try
|
||||
{
|
||||
return (!user.isDead() && (user.isAuthorized("essentials.signs." + signName.toLowerCase(Locale.ENGLISH) + ".use")
|
||||
|| user.isAuthorized("essentials.signs.use." + signName.toLowerCase(Locale.ENGLISH))))
|
||||
&& onSignInteract(sign, user, getUsername(user), ess);
|
||||
if (user.isDead() || !(user.isAuthorized("essentials.signs." + signName.toLowerCase(Locale.ENGLISH) + ".use")
|
||||
|| user.isAuthorized("essentials.signs.use." + signName.toLowerCase(Locale.ENGLISH))))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final SignInteractEvent signEvent = new SignInteractEvent(sign, this, user);
|
||||
ess.getServer().getPluginManager().callEvent(signEvent);
|
||||
if (signEvent.isCancelled())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return onSignInteract(sign, user, getUsername(user), ess);
|
||||
}
|
||||
catch (ChargeException ex)
|
||||
{
|
||||
@ -107,15 +129,26 @@ public class EssentialsSign
|
||||
}
|
||||
}
|
||||
|
||||
public final boolean onSignBreak(final Block block, final Player player, final IEssentials ess)
|
||||
protected final boolean onSignBreak(final Block block, final Player player, final IEssentials ess)
|
||||
{
|
||||
final ISign sign = new BlockSign(block);
|
||||
final User user = ess.getUser(player);
|
||||
try
|
||||
{
|
||||
return (user.isAuthorized("essentials.signs." + signName.toLowerCase(Locale.ENGLISH) + ".break")
|
||||
|| user.isAuthorized("essentials.signs.break." + signName.toLowerCase(Locale.ENGLISH)))
|
||||
&& onSignBreak(sign, user, getUsername(user), ess);
|
||||
if (!(user.isAuthorized("essentials.signs." + signName.toLowerCase(Locale.ENGLISH) + ".break")
|
||||
|| user.isAuthorized("essentials.signs.break." + signName.toLowerCase(Locale.ENGLISH))))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final SignBreakEvent signEvent = new SignBreakEvent(sign, this, user);
|
||||
ess.getServer().getPluginManager().callEvent(signEvent);
|
||||
if (signEvent.isCancelled())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return onSignBreak(sign, user, getUsername(user), ess);
|
||||
}
|
||||
catch (SignException ex)
|
||||
{
|
||||
@ -139,7 +172,7 @@ public class EssentialsSign
|
||||
return true;
|
||||
}
|
||||
|
||||
public final boolean onBlockPlace(final Block block, final Player player, final IEssentials ess)
|
||||
protected final boolean onBlockPlace(final Block block, final Player player, final IEssentials ess)
|
||||
{
|
||||
User user = ess.getUser(player);
|
||||
try
|
||||
@ -157,7 +190,7 @@ public class EssentialsSign
|
||||
return false;
|
||||
}
|
||||
|
||||
public final boolean onBlockInteract(final Block block, final Player player, final IEssentials ess)
|
||||
protected final boolean onBlockInteract(final Block block, final Player player, final IEssentials ess)
|
||||
{
|
||||
User user = ess.getUser(player);
|
||||
try
|
||||
@ -175,7 +208,7 @@ public class EssentialsSign
|
||||
return false;
|
||||
}
|
||||
|
||||
public final boolean onBlockBreak(final Block block, final Player player, final IEssentials ess)
|
||||
protected final boolean onBlockBreak(final Block block, final Player player, final IEssentials ess)
|
||||
{
|
||||
User user = ess.getUser(player);
|
||||
try
|
||||
@ -189,32 +222,32 @@ public class EssentialsSign
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean onBlockBreak(final Block block, final IEssentials ess)
|
||||
protected boolean onBlockBreak(final Block block, final IEssentials ess)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean onBlockExplode(final Block block, final IEssentials ess)
|
||||
protected boolean onBlockExplode(final Block block, final IEssentials ess)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean onBlockBurn(final Block block, final IEssentials ess)
|
||||
protected boolean onBlockBurn(final Block block, final IEssentials ess)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean onBlockIgnite(final Block block, final IEssentials ess)
|
||||
protected boolean onBlockIgnite(final Block block, final IEssentials ess)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean onBlockPush(final Block block, final IEssentials ess)
|
||||
protected boolean onBlockPush(final Block block, final IEssentials ess)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean checkIfBlockBreaksSigns(final Block block)
|
||||
protected static boolean checkIfBlockBreaksSigns(final Block block)
|
||||
{
|
||||
final Block sign = block.getRelative(BlockFace.UP);
|
||||
if (sign.getType() == Material.SIGN_POST && isValidSign(new BlockSign(sign)))
|
||||
@ -508,8 +541,10 @@ public class EssentialsSign
|
||||
public final String getLine(final int index)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (char c : event.getLine(index).toCharArray()) {
|
||||
if (c < 0xF700 || c > 0xF747) {
|
||||
for (char c : event.getLine(index).toCharArray())
|
||||
{
|
||||
if (c < 0xF700 || c > 0xF747)
|
||||
{
|
||||
builder.append(c);
|
||||
}
|
||||
}
|
||||
@ -578,12 +613,12 @@ public class EssentialsSign
|
||||
|
||||
public interface ISign
|
||||
{
|
||||
String getLine(final int index);
|
||||
public String getLine(final int index);
|
||||
|
||||
void setLine(final int index, final String text);
|
||||
public void setLine(final int index, final String text);
|
||||
|
||||
public Block getBlock();
|
||||
|
||||
void updateSign();
|
||||
public void updateSign();
|
||||
}
|
||||
}
|
||||
|
@ -94,6 +94,7 @@ public class SignBlockListener implements Listener
|
||||
}
|
||||
|
||||
final String topLine = event.getLine(0);
|
||||
//We loop through all sign types here to prevent clashes with preexisting signs later
|
||||
for (Signs signs : Signs.values())
|
||||
{
|
||||
final EssentialsSign sign = signs.getSign();
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.earth2me.essentials.signs;
|
||||
|
||||
|
||||
//This enum is used when checking to see what signs are enabled
|
||||
public enum Signs
|
||||
{
|
||||
BALANCE(new SignBalance()),
|
||||
@ -21,7 +21,6 @@ public enum Signs
|
||||
TRADE(new SignTrade()),
|
||||
WARP(new SignWarp()),
|
||||
WEATHER(new SignWeather());
|
||||
|
||||
private final EssentialsSign sign;
|
||||
|
||||
private Signs(final EssentialsSign sign)
|
||||
|
@ -5,8 +5,8 @@ import net.ess3.api.IUser;
|
||||
|
||||
public class AfkStatusChangeEvent extends StatusChangeEvent
|
||||
{
|
||||
public AfkStatusChangeEvent(IUser affected, IUser controller, boolean value)
|
||||
public AfkStatusChangeEvent(IUser affected, boolean value)
|
||||
{
|
||||
super(affected, controller, value);
|
||||
super(affected, affected, value);
|
||||
}
|
||||
}
|
||||
|
@ -14,12 +14,6 @@ public class NickChangeEvent extends StateChangeEvent implements Cancellable
|
||||
this.newValue = value;
|
||||
}
|
||||
|
||||
public NickChangeEvent(boolean isAsync, IUser affected, IUser controller, String value)
|
||||
{
|
||||
super(isAsync, affected, controller);
|
||||
this.newValue = value;
|
||||
}
|
||||
|
||||
public String getValue()
|
||||
{
|
||||
return newValue;
|
||||
|
13
Essentials/src/net/ess3/api/events/SignBreakEvent.java
Normal file
13
Essentials/src/net/ess3/api/events/SignBreakEvent.java
Normal file
@ -0,0 +1,13 @@
|
||||
package net.ess3.api.events;
|
||||
|
||||
import com.earth2me.essentials.signs.EssentialsSign;
|
||||
import net.ess3.api.IUser;
|
||||
|
||||
|
||||
public class SignBreakEvent extends SignEvent
|
||||
{
|
||||
public SignBreakEvent(EssentialsSign.ISign sign, EssentialsSign essSign, IUser user)
|
||||
{
|
||||
super(sign, essSign, user);
|
||||
}
|
||||
}
|
13
Essentials/src/net/ess3/api/events/SignCreateEvent.java
Normal file
13
Essentials/src/net/ess3/api/events/SignCreateEvent.java
Normal file
@ -0,0 +1,13 @@
|
||||
package net.ess3.api.events;
|
||||
|
||||
import com.earth2me.essentials.signs.EssentialsSign;
|
||||
import net.ess3.api.IUser;
|
||||
|
||||
|
||||
public class SignCreateEvent extends SignEvent
|
||||
{
|
||||
public SignCreateEvent(EssentialsSign.ISign sign, EssentialsSign essSign, IUser user)
|
||||
{
|
||||
super(sign, essSign, user);
|
||||
}
|
||||
}
|
68
Essentials/src/net/ess3/api/events/SignEvent.java
Normal file
68
Essentials/src/net/ess3/api/events/SignEvent.java
Normal file
@ -0,0 +1,68 @@
|
||||
package net.ess3.api.events;
|
||||
|
||||
import com.earth2me.essentials.signs.EssentialsSign;
|
||||
import com.earth2me.essentials.signs.EssentialsSign.ISign;
|
||||
import net.ess3.api.IUser;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
|
||||
/**
|
||||
* This handles common boilerplate for other SignEvent
|
||||
*
|
||||
*/
|
||||
public class SignEvent extends Event implements Cancellable
|
||||
{
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled = false;
|
||||
ISign sign;
|
||||
EssentialsSign essSign;
|
||||
IUser user;
|
||||
|
||||
public SignEvent(final ISign sign, final EssentialsSign essSign, final IUser user)
|
||||
{
|
||||
super();
|
||||
this.sign = sign;
|
||||
this.essSign = essSign;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public ISign getSign()
|
||||
{
|
||||
return sign;
|
||||
}
|
||||
|
||||
public EssentialsSign getEssentialsSign()
|
||||
{
|
||||
return essSign;
|
||||
}
|
||||
|
||||
public IUser getUser()
|
||||
{
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled()
|
||||
{
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled)
|
||||
{
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
}
|
13
Essentials/src/net/ess3/api/events/SignInteractEvent.java
Normal file
13
Essentials/src/net/ess3/api/events/SignInteractEvent.java
Normal file
@ -0,0 +1,13 @@
|
||||
package net.ess3.api.events;
|
||||
|
||||
import com.earth2me.essentials.signs.EssentialsSign;
|
||||
import net.ess3.api.IUser;
|
||||
|
||||
|
||||
public class SignInteractEvent extends SignEvent
|
||||
{
|
||||
public SignInteractEvent(EssentialsSign.ISign sign, EssentialsSign essSign, IUser user)
|
||||
{
|
||||
super(sign, essSign, user);
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ import org.bukkit.event.HandlerList;
|
||||
|
||||
|
||||
/**
|
||||
* This handles common boilerplate for other StatusChangeEvents
|
||||
* This handles common boilerplate for other StateChangeEvents
|
||||
*
|
||||
*/
|
||||
public class StateChangeEvent extends Event implements Cancellable
|
||||
|
Loading…
Reference in New Issue
Block a user