mirror of
https://github.com/MassiveCraft/Factions.git
synced 2024-11-23 10:45:51 +01:00
Achieve some minor symmetry increase and use listener for the home command.
This commit is contained in:
parent
61baf70ed1
commit
87ee57e004
@ -857,9 +857,10 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
|
||||
if ( ! Econ.hasAtLeast(payee, cost, "to claim this land")) return false;
|
||||
}
|
||||
|
||||
FactionsEventLandClaim claimEvent = new FactionsEventLandClaim(sender, forFaction, flocation);
|
||||
claimEvent.run();
|
||||
if (claimEvent.isCancelled()) return false;
|
||||
// Event
|
||||
FactionsEventLandClaim event = new FactionsEventLandClaim(sender, forFaction, flocation);
|
||||
event.run();
|
||||
if (event.isCancelled()) return false;
|
||||
|
||||
// then make 'em pay (if applicable)
|
||||
// TODO: The economy integration should cancel the event above!
|
||||
|
@ -2,8 +2,6 @@ package com.massivecraft.factions.cmd;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.massivecraft.factions.ConfServer;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FPlayerColl;
|
||||
@ -30,48 +28,49 @@ public class CmdFactionsCreate extends FCommand
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
String tag = this.arg(0);
|
||||
// Args
|
||||
String newTag = this.arg(0);
|
||||
|
||||
// Verify
|
||||
if (fme.hasFaction())
|
||||
{
|
||||
msg("<b>You must leave your current faction first.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (FactionColl.get().isTagTaken(tag))
|
||||
if (FactionColl.get().isTagTaken(newTag))
|
||||
{
|
||||
msg("<b>That tag is already in use.");
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<String> tagValidationErrors = FactionColl.validateTag(tag);
|
||||
ArrayList<String> tagValidationErrors = FactionColl.validateTag(newTag);
|
||||
if (tagValidationErrors.size() > 0)
|
||||
{
|
||||
sendMessage(tagValidationErrors);
|
||||
return;
|
||||
}
|
||||
|
||||
// trigger the faction creation event (cancellable)
|
||||
// Pre-Generate Id
|
||||
String factionId = FactionColl.get().getIdStrategy().generate(FactionColl.get());
|
||||
|
||||
FactionsEventCreate createEvent = new FactionsEventCreate(sender, tag, factionId);
|
||||
Bukkit.getServer().getPluginManager().callEvent(createEvent);
|
||||
// Event
|
||||
FactionsEventCreate createEvent = new FactionsEventCreate(sender, newTag, factionId);
|
||||
createEvent.run();
|
||||
if (createEvent.isCancelled()) return;
|
||||
|
||||
// Apply
|
||||
Faction faction = FactionColl.get().create(factionId);
|
||||
faction.setTag(newTag);
|
||||
|
||||
// finish setting up the Faction
|
||||
faction.setTag(tag);
|
||||
fme.setRole(Rel.LEADER);
|
||||
fme.setFaction(faction);
|
||||
|
||||
// trigger the faction join event for the creator
|
||||
FactionsEventJoin joinEvent = new FactionsEventJoin(sender, fme, faction, FactionsEventJoin.PlayerJoinReason.CREATE);
|
||||
joinEvent.run();
|
||||
// NOTE: join event cannot be cancelled or you'll have an empty faction
|
||||
|
||||
// finish setting up the FPlayer
|
||||
fme.setRole(Rel.LEADER);
|
||||
fme.setFaction(faction);
|
||||
|
||||
// Inform
|
||||
for (FPlayer follower : FPlayerColl.get().getAllOnline())
|
||||
{
|
||||
follower.msg("%s<i> created a new faction %s", fme.describeTo(follower, true), faction.getTag(follower));
|
||||
@ -80,7 +79,9 @@ public class CmdFactionsCreate extends FCommand
|
||||
msg("<i>You should now: %s", Factions.get().getOuterCmdFactions().cmdFactionsDescription.getUseageTemplate());
|
||||
|
||||
if (ConfServer.logFactionCreate)
|
||||
Factions.get().log(fme.getName()+" created a new faction: "+tag);
|
||||
{
|
||||
Factions.get().log(fme.getName()+" created a new faction: "+newTag);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.massivecraft.factions.ConfServer;
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.event.FactionsEventLeave;
|
||||
@ -31,20 +29,26 @@ public class CmdFactionsDisband extends FCommand
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
// Args
|
||||
Faction faction = this.arg(0, ARFaction.get(), myFaction);
|
||||
if (faction == null) return;
|
||||
|
||||
// FPerm
|
||||
if ( ! FPerm.DISBAND.has(sender, faction, true)) return;
|
||||
|
||||
// Verify
|
||||
if (faction.getFlag(FFlag.PERMANENT))
|
||||
{
|
||||
msg("<i>This faction is designated as permanent, so you cannot disband it.");
|
||||
return;
|
||||
}
|
||||
|
||||
FactionsEventDisband disbandEvent = new FactionsEventDisband(me, faction);
|
||||
Bukkit.getServer().getPluginManager().callEvent(disbandEvent);
|
||||
if(disbandEvent.isCancelled()) return;
|
||||
// Event
|
||||
FactionsEventDisband event = new FactionsEventDisband(me, faction);
|
||||
event.run();
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
// Merged Apply and Inform
|
||||
|
||||
// Send FPlayerLeaveEvent for each player in the faction
|
||||
for ( FPlayer fplayer : faction.getFPlayers() )
|
||||
|
@ -14,6 +14,7 @@ import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast;
|
||||
import com.massivecraft.factions.event.FactionsEventHomeTeleport;
|
||||
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
|
||||
import com.massivecraft.mcore.mixin.Mixin;
|
||||
@ -118,12 +119,15 @@ public class CmdFactionsHome extends FCommand
|
||||
}
|
||||
}
|
||||
|
||||
// Event
|
||||
FactionsEventHomeTeleport event = new FactionsEventHomeTeleport(sender);
|
||||
event.run();
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
// Apply
|
||||
try
|
||||
{
|
||||
Mixin.teleport(me, myFaction.getHome(), "your faction home", sender);
|
||||
|
||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||
if (!payForCommand(ConfServer.econCostHome)) return;
|
||||
}
|
||||
catch (TeleporterException e)
|
||||
{
|
||||
|
@ -33,28 +33,32 @@ public class CmdFactionsSethome extends FCommand
|
||||
return;
|
||||
}
|
||||
|
||||
// Args
|
||||
Faction faction = this.arg(0, ARFaction.get(), myFaction);
|
||||
if (faction == null) return;
|
||||
|
||||
// Has faction permission?
|
||||
if ( ! FPerm.SETHOME.has(sender, faction, true)) return;
|
||||
|
||||
PS newHome = PS.valueOf(me.getLocation());
|
||||
|
||||
// Can the player set the faction home HERE?
|
||||
// FPerm
|
||||
if ( ! FPerm.SETHOME.has(sender, faction, true)) return;
|
||||
|
||||
// Verify
|
||||
if (!fme.isUsingAdminMode() && !faction.isValidHome(newHome))
|
||||
{
|
||||
fme.msg("<b>Sorry, your faction home can only be set inside your own claimed territory.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Event
|
||||
FactionsEventHomeChange event = new FactionsEventHomeChange(sender, faction, newHome);
|
||||
event.run();
|
||||
if (event.isCancelled()) return;
|
||||
newHome = event.getNewHome();
|
||||
|
||||
// Apply
|
||||
faction.setHome(newHome);
|
||||
|
||||
// Inform
|
||||
faction.msg("%s<i> set the home for your faction. You can now use:", fme.describeTo(myFaction, true));
|
||||
faction.sendMessage(Factions.get().getOuterCmdFactions().cmdFactionsHome.getUseageTemplate());
|
||||
if (faction != myFaction)
|
||||
|
@ -2,8 +2,6 @@ package com.massivecraft.factions.cmd;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.massivecraft.factions.ConfServer;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.FactionColl;
|
||||
@ -50,10 +48,10 @@ public class CmdFactionsTag extends FCommand
|
||||
}
|
||||
|
||||
// Event
|
||||
FactionsEventTagChange renameEvent = new FactionsEventTagChange(sender, myFaction, newTag);
|
||||
Bukkit.getServer().getPluginManager().callEvent(renameEvent);
|
||||
if (renameEvent.isCancelled()) return;
|
||||
newTag = renameEvent.getNewTag();
|
||||
FactionsEventTagChange event = new FactionsEventTagChange(sender, myFaction, newTag);
|
||||
event.run();
|
||||
if (event.isCancelled()) return;
|
||||
newTag = event.getNewTag();
|
||||
|
||||
// Apply
|
||||
String oldtag = myFaction.getTag();
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.massivecraft.factions.ConfServer;
|
||||
import com.massivecraft.factions.event.FactionsEventLandUnclaim;
|
||||
import com.massivecraft.factions.integration.Econ;
|
||||
@ -28,14 +26,17 @@ public class CmdFactionsUnclaim extends FCommand
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
// Args
|
||||
PS chunk = PS.valueOf(me).getChunk(true);
|
||||
Faction otherFaction = BoardColl.get().getFactionAt(chunk);
|
||||
|
||||
// FPerm
|
||||
if ( ! FPerm.TERRITORY.has(sender, otherFaction, true)) return;
|
||||
|
||||
FactionsEventLandUnclaim unclaimEvent = new FactionsEventLandUnclaim(sender, otherFaction, chunk);
|
||||
Bukkit.getServer().getPluginManager().callEvent(unclaimEvent);
|
||||
if(unclaimEvent.isCancelled()) return;
|
||||
// Event
|
||||
FactionsEventLandUnclaim event = new FactionsEventLandUnclaim(sender, otherFaction, chunk);
|
||||
event.run();
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
//String moneyBack = "<i>";
|
||||
if (Econ.isEnabled())
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.massivecraft.factions.BoardColl;
|
||||
import com.massivecraft.factions.ConfServer;
|
||||
import com.massivecraft.factions.Factions;
|
||||
@ -26,6 +24,7 @@ public class CmdFactionsUnclaimall extends FCommand
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
// TODO: Put this as a listener and not in here!
|
||||
if (Econ.isEnabled())
|
||||
{
|
||||
double refund = Econ.calculateTotalLandRefund(myFaction.getLandCount());
|
||||
@ -39,12 +38,18 @@ public class CmdFactionsUnclaimall extends FCommand
|
||||
}
|
||||
}
|
||||
|
||||
FactionsEventLandUnclaimAll unclaimAllEvent = new FactionsEventLandUnclaimAll(sender, myFaction);
|
||||
Bukkit.getServer().getPluginManager().callEvent(unclaimAllEvent);
|
||||
// this event cannot be cancelled
|
||||
// Event
|
||||
FactionsEventLandUnclaimAll event = new FactionsEventLandUnclaimAll(sender, myFaction);
|
||||
event.run();
|
||||
// TODO: this event cannot be cancelled yet.
|
||||
|
||||
// Apply
|
||||
BoardColl.get().removeAll(myFaction);
|
||||
|
||||
// Inform
|
||||
myFaction.msg("%s<i> unclaimed ALL of your faction's land.", fme.describeTo(myFaction, true));
|
||||
|
||||
// TODO: Move this to a listener instead.
|
||||
SpoutFeatures.updateTerritoryDisplayLoc(null);
|
||||
|
||||
if (ConfServer.logLandUnclaims)
|
||||
|
@ -0,0 +1,25 @@
|
||||
package com.massivecraft.factions.event;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class FactionsEventHomeTeleport extends FactionsEventAbstractSender
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// REQUIRED EVENT CODE
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
@Override public HandlerList getHandlers() { return handlers; }
|
||||
public static HandlerList getHandlerList() { return handlers; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public FactionsEventHomeTeleport(CommandSender sender)
|
||||
{
|
||||
super(sender);
|
||||
}
|
||||
|
||||
}
|
@ -11,6 +11,7 @@ import com.massivecraft.factions.event.FactionsEventAbstractSender;
|
||||
import com.massivecraft.factions.event.FactionsEventCreate;
|
||||
import com.massivecraft.factions.event.FactionsEventDescriptionChange;
|
||||
import com.massivecraft.factions.event.FactionsEventHomeChange;
|
||||
import com.massivecraft.factions.event.FactionsEventHomeTeleport;
|
||||
import com.massivecraft.factions.event.FactionsEventInvitedChange;
|
||||
import com.massivecraft.factions.event.FactionsEventOpenChange;
|
||||
import com.massivecraft.factions.event.FactionsEventRelationChange;
|
||||
@ -102,4 +103,11 @@ public class FactionsListenerEcon implements Listener
|
||||
double cost = event.isNewInvited() ? ConfServer.econCostInvite : ConfServer.econCostDeinvite;
|
||||
payForCommand(event, cost, Factions.get().getOuterCmdFactions().cmdFactionsInvite);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void payForCommand(FactionsEventHomeTeleport event)
|
||||
{
|
||||
payForCommand(event, ConfServer.econCostHome, Factions.get().getOuterCmdFactions().cmdFactionsHome);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user