Add more API template and implement nick change event.

This commit is contained in:
KHobbits 2013-10-05 02:11:39 +01:00
parent 03368e45df
commit 122232a0e7
9 changed files with 146 additions and 57 deletions

View File

@ -4,6 +4,8 @@ import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.FormatUtil;
import java.util.Locale;
import net.ess3.api.events.LocalChatSpyEvent;
import net.ess3.api.events.NickChangeEvent;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -62,14 +64,12 @@ public class Commandnick extends EssentialsLoopCommand
final String nick = args[0];
if (target.getName().equalsIgnoreCase(nick))
{
target.setNickname(nick);
target.setDisplayNick();
setNickname(server, sender, target, nick);
target.sendMessage(_("nickNoMore"));
}
else if ("off".equalsIgnoreCase(nick))
{
target.setNickname(null);
target.setDisplayNick();
setNickname(server, sender, target, null);
target.sendMessage(_("nickNoMore"));
}
else if (nickInUse(server, target, nick))
@ -78,8 +78,7 @@ public class Commandnick extends EssentialsLoopCommand
}
else
{
target.setNickname(nick);
target.setDisplayNick();
setNickname(server, sender, target, nick);
target.sendMessage(_("nickSet", target.getDisplayName()));
}
}
@ -115,4 +114,16 @@ public class Commandnick extends EssentialsLoopCommand
}
return false;
}
private void setNickname(final Server server, final CommandSender sender, final User target, final String nickname)
{
final User controller = sender instanceof Player ? ess.getUser(sender) : null;
final NickChangeEvent nickEvent = new NickChangeEvent(controller, target, nickname);
server.getPluginManager().callEvent(nickEvent);
if (!nickEvent.isCancelled())
{
target.setNickname(nickname);
target.setDisplayNick();
}
}
}

View File

@ -1,10 +1,12 @@
package net.ess3.api.events;
import net.ess3.api.IUser;
public class AfkStatusChangeEvent extends StatusChangeEvent
{
public AfkStatusChangeEvent()
public AfkStatusChangeEvent(IUser affected, IUser controller, boolean value)
{
super(affected, controller, value);
}
}

View File

@ -1,10 +1,12 @@
package net.ess3.api.events;
import net.ess3.api.IUser;
public class GodStatusChangeEvent extends StatusChangeEvent
{
public GodStatusChangeEvent()
public GodStatusChangeEvent(IUser affected, IUser controller, boolean value)
{
super(affected, controller, value);
}
}

View File

@ -1,11 +1,13 @@
package net.ess3.api.events;
import net.ess3.api.IUser;
public class IgnoreStatusChangeEvent extends StatusChangeEvent
{
public IgnoreStatusChangeEvent()
public IgnoreStatusChangeEvent(IUser affected, IUser controller, boolean value)
{
super(affected, controller, value);
}
}

View File

@ -1,10 +1,12 @@
package net.ess3.api.events;
import net.ess3.api.IUser;
public class JailStatusChangeEvent extends StatusChangeEvent
{
public JailStatusChangeEvent()
public JailStatusChangeEvent(IUser affected, IUser controller, boolean value)
{
super(affected, controller, value);
}
}

View File

@ -1,10 +1,14 @@
package net.ess3.api.events;
import net.ess3.api.IUser;
public class MuteStatusChangeEvent extends StatusChangeEvent
{
public MuteStatusChangeEvent()
public MuteStatusChangeEvent(IUser affected, IUser controller, boolean value)
{
super(affected, controller, value);
}
}

View File

@ -0,0 +1,25 @@
package net.ess3.api.events;
import net.ess3.api.IUser;
import org.bukkit.event.Cancellable;
public class NickChangeEvent extends StateChangeEvent implements Cancellable
{
private String newValue;
public NickChangeEvent(IUser affected, IUser controller, String value) {
super(affected, controller);
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;
}
}

View File

@ -0,0 +1,65 @@
package net.ess3.api.events;
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 StatusChangeEvents
*
*/
public class StateChangeEvent extends Event implements Cancellable
{
private static final HandlerList handlers = new HandlerList();
private boolean cancelled = false;
IUser affected;
IUser controller;
public StateChangeEvent(IUser affected, IUser controller) {
super();
this.affected = affected;
this.controller = controller;
}
public StateChangeEvent(boolean isAsync, IUser affected, IUser controller) {
super(isAsync);
this.affected = affected;
this.controller = controller;
}
public IUser getAffected()
{
return this.affected;
}
public IUser getController()
{
return controller;
}
@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;
}
}

View File

@ -1,53 +1,29 @@
package net.ess3.api.events;
import com.earth2me.essentials.User;
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 StatusChangeEvents
*
*/
public class StatusChangeEvent extends Event implements Cancellable
public class StatusChangeEvent extends StateChangeEvent implements Cancellable
{
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
User affected;
User controller;
public User getAffected()
private boolean newValue;
public StatusChangeEvent(IUser affected, IUser controller, boolean value) {
super(affected, controller);
this.newValue = value;
}
public StatusChangeEvent(boolean isAsync, IUser affected, IUser controller, boolean value) {
super(isAsync, affected, controller);
this.newValue = value;
}
public boolean getValue()
{
return this.affected;
return newValue;
}
public User getController()
{
return controller;
}
@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;
}
}