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;
|
if ( ! Econ.hasAtLeast(payee, cost, "to claim this land")) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
FactionsEventLandClaim claimEvent = new FactionsEventLandClaim(sender, forFaction, flocation);
|
// Event
|
||||||
claimEvent.run();
|
FactionsEventLandClaim event = new FactionsEventLandClaim(sender, forFaction, flocation);
|
||||||
if (claimEvent.isCancelled()) return false;
|
event.run();
|
||||||
|
if (event.isCancelled()) return false;
|
||||||
|
|
||||||
// then make 'em pay (if applicable)
|
// then make 'em pay (if applicable)
|
||||||
// TODO: The economy integration should cancel the event above!
|
// TODO: The economy integration should cancel the event above!
|
||||||
|
@ -2,8 +2,6 @@ package com.massivecraft.factions.cmd;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
|
|
||||||
import com.massivecraft.factions.ConfServer;
|
import com.massivecraft.factions.ConfServer;
|
||||||
import com.massivecraft.factions.FPlayer;
|
import com.massivecraft.factions.FPlayer;
|
||||||
import com.massivecraft.factions.FPlayerColl;
|
import com.massivecraft.factions.FPlayerColl;
|
||||||
@ -30,48 +28,49 @@ public class CmdFactionsCreate extends FCommand
|
|||||||
@Override
|
@Override
|
||||||
public void perform()
|
public void perform()
|
||||||
{
|
{
|
||||||
String tag = this.arg(0);
|
// Args
|
||||||
|
String newTag = this.arg(0);
|
||||||
|
|
||||||
|
// Verify
|
||||||
if (fme.hasFaction())
|
if (fme.hasFaction())
|
||||||
{
|
{
|
||||||
msg("<b>You must leave your current faction first.");
|
msg("<b>You must leave your current faction first.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FactionColl.get().isTagTaken(tag))
|
if (FactionColl.get().isTagTaken(newTag))
|
||||||
{
|
{
|
||||||
msg("<b>That tag is already in use.");
|
msg("<b>That tag is already in use.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<String> tagValidationErrors = FactionColl.validateTag(tag);
|
ArrayList<String> tagValidationErrors = FactionColl.validateTag(newTag);
|
||||||
if (tagValidationErrors.size() > 0)
|
if (tagValidationErrors.size() > 0)
|
||||||
{
|
{
|
||||||
sendMessage(tagValidationErrors);
|
sendMessage(tagValidationErrors);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// trigger the faction creation event (cancellable)
|
// Pre-Generate Id
|
||||||
String factionId = FactionColl.get().getIdStrategy().generate(FactionColl.get());
|
String factionId = FactionColl.get().getIdStrategy().generate(FactionColl.get());
|
||||||
|
|
||||||
FactionsEventCreate createEvent = new FactionsEventCreate(sender, tag, factionId);
|
// Event
|
||||||
Bukkit.getServer().getPluginManager().callEvent(createEvent);
|
FactionsEventCreate createEvent = new FactionsEventCreate(sender, newTag, factionId);
|
||||||
|
createEvent.run();
|
||||||
if (createEvent.isCancelled()) return;
|
if (createEvent.isCancelled()) return;
|
||||||
|
|
||||||
|
// Apply
|
||||||
Faction faction = FactionColl.get().create(factionId);
|
Faction faction = FactionColl.get().create(factionId);
|
||||||
|
faction.setTag(newTag);
|
||||||
|
|
||||||
// finish setting up the Faction
|
fme.setRole(Rel.LEADER);
|
||||||
faction.setTag(tag);
|
fme.setFaction(faction);
|
||||||
|
|
||||||
// trigger the faction join event for the creator
|
|
||||||
FactionsEventJoin joinEvent = new FactionsEventJoin(sender, fme, faction, FactionsEventJoin.PlayerJoinReason.CREATE);
|
FactionsEventJoin joinEvent = new FactionsEventJoin(sender, fme, faction, FactionsEventJoin.PlayerJoinReason.CREATE);
|
||||||
joinEvent.run();
|
joinEvent.run();
|
||||||
// NOTE: join event cannot be cancelled or you'll have an empty faction
|
// NOTE: join event cannot be cancelled or you'll have an empty faction
|
||||||
|
|
||||||
// finish setting up the FPlayer
|
// Inform
|
||||||
fme.setRole(Rel.LEADER);
|
|
||||||
fme.setFaction(faction);
|
|
||||||
|
|
||||||
for (FPlayer follower : FPlayerColl.get().getAllOnline())
|
for (FPlayer follower : FPlayerColl.get().getAllOnline())
|
||||||
{
|
{
|
||||||
follower.msg("%s<i> created a new faction %s", fme.describeTo(follower, true), faction.getTag(follower));
|
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());
|
msg("<i>You should now: %s", Factions.get().getOuterCmdFactions().cmdFactionsDescription.getUseageTemplate());
|
||||||
|
|
||||||
if (ConfServer.logFactionCreate)
|
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;
|
package com.massivecraft.factions.cmd;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
|
|
||||||
import com.massivecraft.factions.ConfServer;
|
import com.massivecraft.factions.ConfServer;
|
||||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||||
import com.massivecraft.factions.event.FactionsEventLeave;
|
import com.massivecraft.factions.event.FactionsEventLeave;
|
||||||
@ -31,20 +29,26 @@ public class CmdFactionsDisband extends FCommand
|
|||||||
@Override
|
@Override
|
||||||
public void perform()
|
public void perform()
|
||||||
{
|
{
|
||||||
|
// Args
|
||||||
Faction faction = this.arg(0, ARFaction.get(), myFaction);
|
Faction faction = this.arg(0, ARFaction.get(), myFaction);
|
||||||
if (faction == null) return;
|
if (faction == null) return;
|
||||||
|
|
||||||
|
// FPerm
|
||||||
if ( ! FPerm.DISBAND.has(sender, faction, true)) return;
|
if ( ! FPerm.DISBAND.has(sender, faction, true)) return;
|
||||||
|
|
||||||
|
// Verify
|
||||||
if (faction.getFlag(FFlag.PERMANENT))
|
if (faction.getFlag(FFlag.PERMANENT))
|
||||||
{
|
{
|
||||||
msg("<i>This faction is designated as permanent, so you cannot disband it.");
|
msg("<i>This faction is designated as permanent, so you cannot disband it.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FactionsEventDisband disbandEvent = new FactionsEventDisband(me, faction);
|
// Event
|
||||||
Bukkit.getServer().getPluginManager().callEvent(disbandEvent);
|
FactionsEventDisband event = new FactionsEventDisband(me, faction);
|
||||||
if(disbandEvent.isCancelled()) return;
|
event.run();
|
||||||
|
if (event.isCancelled()) return;
|
||||||
|
|
||||||
|
// Merged Apply and Inform
|
||||||
|
|
||||||
// Send FPlayerLeaveEvent for each player in the faction
|
// Send FPlayerLeaveEvent for each player in the faction
|
||||||
for ( FPlayer fplayer : faction.getFPlayers() )
|
for ( FPlayer fplayer : faction.getFPlayers() )
|
||||||
|
@ -14,6 +14,7 @@ import com.massivecraft.factions.Factions;
|
|||||||
import com.massivecraft.factions.Perm;
|
import com.massivecraft.factions.Perm;
|
||||||
import com.massivecraft.factions.Rel;
|
import com.massivecraft.factions.Rel;
|
||||||
import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast;
|
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.ReqHasPerm;
|
||||||
import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
|
import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
|
||||||
import com.massivecraft.mcore.mixin.Mixin;
|
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
|
try
|
||||||
{
|
{
|
||||||
Mixin.teleport(me, myFaction.getHome(), "your faction home", sender);
|
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)
|
catch (TeleporterException e)
|
||||||
{
|
{
|
||||||
|
@ -33,28 +33,32 @@ public class CmdFactionsSethome extends FCommand
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Args
|
||||||
Faction faction = this.arg(0, ARFaction.get(), myFaction);
|
Faction faction = this.arg(0, ARFaction.get(), myFaction);
|
||||||
if (faction == null) return;
|
if (faction == null) return;
|
||||||
|
|
||||||
// Has faction permission?
|
|
||||||
if ( ! FPerm.SETHOME.has(sender, faction, true)) return;
|
|
||||||
|
|
||||||
PS newHome = PS.valueOf(me.getLocation());
|
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))
|
if (!fme.isUsingAdminMode() && !faction.isValidHome(newHome))
|
||||||
{
|
{
|
||||||
fme.msg("<b>Sorry, your faction home can only be set inside your own claimed territory.");
|
fme.msg("<b>Sorry, your faction home can only be set inside your own claimed territory.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Event
|
||||||
FactionsEventHomeChange event = new FactionsEventHomeChange(sender, faction, newHome);
|
FactionsEventHomeChange event = new FactionsEventHomeChange(sender, faction, newHome);
|
||||||
event.run();
|
event.run();
|
||||||
if (event.isCancelled()) return;
|
if (event.isCancelled()) return;
|
||||||
newHome = event.getNewHome();
|
newHome = event.getNewHome();
|
||||||
|
|
||||||
|
// Apply
|
||||||
faction.setHome(newHome);
|
faction.setHome(newHome);
|
||||||
|
|
||||||
|
// Inform
|
||||||
faction.msg("%s<i> set the home for your faction. You can now use:", fme.describeTo(myFaction, true));
|
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());
|
faction.sendMessage(Factions.get().getOuterCmdFactions().cmdFactionsHome.getUseageTemplate());
|
||||||
if (faction != myFaction)
|
if (faction != myFaction)
|
||||||
|
@ -2,8 +2,6 @@ package com.massivecraft.factions.cmd;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
|
|
||||||
import com.massivecraft.factions.ConfServer;
|
import com.massivecraft.factions.ConfServer;
|
||||||
import com.massivecraft.factions.Faction;
|
import com.massivecraft.factions.Faction;
|
||||||
import com.massivecraft.factions.FactionColl;
|
import com.massivecraft.factions.FactionColl;
|
||||||
@ -50,10 +48,10 @@ public class CmdFactionsTag extends FCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Event
|
// Event
|
||||||
FactionsEventTagChange renameEvent = new FactionsEventTagChange(sender, myFaction, newTag);
|
FactionsEventTagChange event = new FactionsEventTagChange(sender, myFaction, newTag);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(renameEvent);
|
event.run();
|
||||||
if (renameEvent.isCancelled()) return;
|
if (event.isCancelled()) return;
|
||||||
newTag = renameEvent.getNewTag();
|
newTag = event.getNewTag();
|
||||||
|
|
||||||
// Apply
|
// Apply
|
||||||
String oldtag = myFaction.getTag();
|
String oldtag = myFaction.getTag();
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package com.massivecraft.factions.cmd;
|
package com.massivecraft.factions.cmd;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
|
|
||||||
import com.massivecraft.factions.ConfServer;
|
import com.massivecraft.factions.ConfServer;
|
||||||
import com.massivecraft.factions.event.FactionsEventLandUnclaim;
|
import com.massivecraft.factions.event.FactionsEventLandUnclaim;
|
||||||
import com.massivecraft.factions.integration.Econ;
|
import com.massivecraft.factions.integration.Econ;
|
||||||
@ -28,14 +26,17 @@ public class CmdFactionsUnclaim extends FCommand
|
|||||||
@Override
|
@Override
|
||||||
public void perform()
|
public void perform()
|
||||||
{
|
{
|
||||||
|
// Args
|
||||||
PS chunk = PS.valueOf(me).getChunk(true);
|
PS chunk = PS.valueOf(me).getChunk(true);
|
||||||
Faction otherFaction = BoardColl.get().getFactionAt(chunk);
|
Faction otherFaction = BoardColl.get().getFactionAt(chunk);
|
||||||
|
|
||||||
|
// FPerm
|
||||||
if ( ! FPerm.TERRITORY.has(sender, otherFaction, true)) return;
|
if ( ! FPerm.TERRITORY.has(sender, otherFaction, true)) return;
|
||||||
|
|
||||||
FactionsEventLandUnclaim unclaimEvent = new FactionsEventLandUnclaim(sender, otherFaction, chunk);
|
// Event
|
||||||
Bukkit.getServer().getPluginManager().callEvent(unclaimEvent);
|
FactionsEventLandUnclaim event = new FactionsEventLandUnclaim(sender, otherFaction, chunk);
|
||||||
if(unclaimEvent.isCancelled()) return;
|
event.run();
|
||||||
|
if (event.isCancelled()) return;
|
||||||
|
|
||||||
//String moneyBack = "<i>";
|
//String moneyBack = "<i>";
|
||||||
if (Econ.isEnabled())
|
if (Econ.isEnabled())
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package com.massivecraft.factions.cmd;
|
package com.massivecraft.factions.cmd;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
|
|
||||||
import com.massivecraft.factions.BoardColl;
|
import com.massivecraft.factions.BoardColl;
|
||||||
import com.massivecraft.factions.ConfServer;
|
import com.massivecraft.factions.ConfServer;
|
||||||
import com.massivecraft.factions.Factions;
|
import com.massivecraft.factions.Factions;
|
||||||
@ -26,6 +24,7 @@ public class CmdFactionsUnclaimall extends FCommand
|
|||||||
@Override
|
@Override
|
||||||
public void perform()
|
public void perform()
|
||||||
{
|
{
|
||||||
|
// TODO: Put this as a listener and not in here!
|
||||||
if (Econ.isEnabled())
|
if (Econ.isEnabled())
|
||||||
{
|
{
|
||||||
double refund = Econ.calculateTotalLandRefund(myFaction.getLandCount());
|
double refund = Econ.calculateTotalLandRefund(myFaction.getLandCount());
|
||||||
@ -39,12 +38,18 @@ public class CmdFactionsUnclaimall extends FCommand
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FactionsEventLandUnclaimAll unclaimAllEvent = new FactionsEventLandUnclaimAll(sender, myFaction);
|
// Event
|
||||||
Bukkit.getServer().getPluginManager().callEvent(unclaimAllEvent);
|
FactionsEventLandUnclaimAll event = new FactionsEventLandUnclaimAll(sender, myFaction);
|
||||||
// this event cannot be cancelled
|
event.run();
|
||||||
|
// TODO: this event cannot be cancelled yet.
|
||||||
|
|
||||||
|
// Apply
|
||||||
BoardColl.get().removeAll(myFaction);
|
BoardColl.get().removeAll(myFaction);
|
||||||
|
|
||||||
|
// Inform
|
||||||
myFaction.msg("%s<i> unclaimed ALL of your faction's land.", fme.describeTo(myFaction, true));
|
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);
|
SpoutFeatures.updateTerritoryDisplayLoc(null);
|
||||||
|
|
||||||
if (ConfServer.logLandUnclaims)
|
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.FactionsEventCreate;
|
||||||
import com.massivecraft.factions.event.FactionsEventDescriptionChange;
|
import com.massivecraft.factions.event.FactionsEventDescriptionChange;
|
||||||
import com.massivecraft.factions.event.FactionsEventHomeChange;
|
import com.massivecraft.factions.event.FactionsEventHomeChange;
|
||||||
|
import com.massivecraft.factions.event.FactionsEventHomeTeleport;
|
||||||
import com.massivecraft.factions.event.FactionsEventInvitedChange;
|
import com.massivecraft.factions.event.FactionsEventInvitedChange;
|
||||||
import com.massivecraft.factions.event.FactionsEventOpenChange;
|
import com.massivecraft.factions.event.FactionsEventOpenChange;
|
||||||
import com.massivecraft.factions.event.FactionsEventRelationChange;
|
import com.massivecraft.factions.event.FactionsEventRelationChange;
|
||||||
@ -102,4 +103,11 @@ public class FactionsListenerEcon implements Listener
|
|||||||
double cost = event.isNewInvited() ? ConfServer.econCostInvite : ConfServer.econCostDeinvite;
|
double cost = event.isNewInvited() ? ConfServer.econCostInvite : ConfServer.econCostDeinvite;
|
||||||
payForCommand(event, cost, Factions.get().getOuterCmdFactions().cmdFactionsInvite);
|
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