Faction create event is no longer cancellable, and is called AFTER the faction is made. This allows people to hook into the event and manipulating the Faction without having a delay. And if the event was ever cancelled before, it was silent.

This commit is contained in:
Trent Hensler 2018-03-09 22:08:17 -08:00
parent 819cb542cd
commit 2291554e1e
2 changed files with 17 additions and 22 deletions

View File

@ -55,13 +55,6 @@ public class CmdCreate extends FCommand {
return;
}
// trigger the faction creation event (cancellable)
FactionCreateEvent createEvent = new FactionCreateEvent(me, tag);
Bukkit.getServer().getPluginManager().callEvent(createEvent);
if (createEvent.isCancelled()) {
return;
}
// then make 'em pay (if applicable)
if (!payForCommand(Conf.econCostCreate, TL.COMMAND_CREATE_TOCREATE, TL.COMMAND_CREATE_FORCREATE)) {
return;
@ -87,6 +80,10 @@ public class CmdCreate extends FCommand {
fme.setRole(Role.ADMIN);
fme.setFaction(faction);
// trigger the faction creation event
FactionCreateEvent createEvent = new FactionCreateEvent(me, tag, faction);
Bukkit.getServer().getPluginManager().callEvent(createEvent);
for (FPlayer follower : FPlayers.getInstance().getOnlinePlayers()) {
follower.msg(TL.COMMAND_CREATE_CREATED, fme.describeTo(follower, true), faction.getTag(follower));
}

View File

@ -2,6 +2,7 @@ package com.massivecraft.factions.event;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
@ -10,28 +11,34 @@ import org.bukkit.event.HandlerList;
/**
* Event called when a Faction is created.
*/
public class FactionCreateEvent extends Event implements Cancellable {
public class FactionCreateEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private String factionTag;
private Player sender;
private boolean cancelled;
private final String factionTag;
private final Player sender;
private final Faction faction;
public FactionCreateEvent(Player sender, String tag) {
public FactionCreateEvent(Player sender, String tag, Faction faction) {
this.factionTag = tag;
this.sender = sender;
this.cancelled = false;
this.faction = faction;
}
public FPlayer getFPlayer() {
return FPlayers.getInstance().getByPlayer(sender);
}
@Deprecated
public String getFactionTag() {
return factionTag;
}
public Faction getFaction() {
return this.faction;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
@ -40,13 +47,4 @@ public class FactionCreateEvent extends Event implements Cancellable {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean c) {
this.cancelled = c;
}
}