Add cancellable FactionRelationWishEvent

This event is called before a faction relation wish is applied by a
player using `/f relation`
This commit is contained in:
eueln 2014-12-17 20:31:21 -06:00
parent 6a0d664cc2
commit 3733539077
2 changed files with 52 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.event.FactionRelationEvent;
import com.massivecraft.factions.event.FactionRelationWishEvent;
import com.massivecraft.factions.scoreboards.FTeamWrapper;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Relation;
@ -50,13 +51,19 @@ public abstract class FRelationCommand extends FCommand {
return;
}
Relation oldRelation = myFaction.getRelationTo(them, true);
FactionRelationWishEvent wishEvent = new FactionRelationWishEvent(fme, myFaction, them, oldRelation, targetRelation);
Bukkit.getPluginManager().callEvent(wishEvent);
if (wishEvent.isCancelled()) {
return;
}
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(targetRelation.getRelationCost(), TL.COMMAND_RELATIONS_TOMARRY, TL.COMMAND_RELATIONS_FORMARRY)) {
return;
}
// try to set the new relation
Relation oldRelation = myFaction.getRelationTo(them, true);
myFaction.setRelationWish(them, targetRelation);
Relation currentRelation = myFaction.getRelationTo(them, true);
ChatColor currentRelationColor = currentRelation.getColor();

View File

@ -0,0 +1,44 @@
package com.massivecraft.factions.event;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Relation;
import org.bukkit.event.Cancellable;
public class FactionRelationWishEvent extends FactionPlayerEvent implements Cancellable {
private final Faction targetFaction;
private final Relation currentRelation;
private final Relation targetRelation;
private boolean cancelled;
public FactionRelationWishEvent(FPlayer caller, Faction sender, Faction targetFaction, Relation currentRelation, Relation targetRelation) {
super(sender, caller);
this.targetFaction = targetFaction;
this.currentRelation = currentRelation;
this.targetRelation = targetRelation;
}
public Faction getTargetFaction() {
return targetFaction;
}
public Relation getCurrentRelation() {
return currentRelation;
}
public Relation getTargetRelation() {
return targetRelation;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}