Factions/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSethome.java

84 lines
2.3 KiB
Java
Raw Normal View History

2011-10-09 21:57:43 +02:00
package com.massivecraft.factions.cmd;
2011-03-23 17:39:56 +01:00
import com.massivecraft.factions.FPerm;
2013-04-16 11:27:03 +02:00
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm;
2013-04-16 11:05:49 +02:00
import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
2013-04-22 09:37:53 +02:00
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.UConf;
2014-06-04 16:47:01 +02:00
import com.massivecraft.factions.event.EventFactionsHomeChange;
2014-06-04 14:02:23 +02:00
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
import com.massivecraft.massivecore.cmd.req.ReqIsPlayer;
import com.massivecraft.massivecore.ps.PS;
2011-03-23 17:39:56 +01:00
2013-04-10 13:12:22 +02:00
public class CmdFactionsSethome extends FCommand
2011-10-09 18:35:39 +02:00
{
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
2013-04-10 13:12:22 +02:00
public CmdFactionsSethome()
2011-10-09 18:35:39 +02:00
{
2013-11-11 09:31:04 +01:00
// Aliases
2013-04-16 10:11:59 +02:00
this.addAliases("sethome");
2013-11-11 09:31:04 +01:00
// Args
this.addOptionalArg("faction", "you");
2013-11-11 09:31:04 +01:00
// Requirements
this.addRequirements(ReqFactionsEnabled.get());
this.addRequirements(ReqIsPlayer.get());
this.addRequirements(ReqHasPerm.get(Perm.SETHOME.node));
2011-03-23 17:39:56 +01:00
}
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
2011-03-23 17:39:56 +01:00
@Override
2011-10-09 18:35:39 +02:00
public void perform()
{
// Args
Faction faction = this.arg(0, ARFaction.get(usenderFaction), usenderFaction);
2011-10-09 18:35:39 +02:00
if (faction == null) return;
2013-04-19 09:50:33 +02:00
PS newHome = PS.valueOf(me.getLocation());
// Validate
if ( ! UConf.get(faction).homesEnabled)
{
usender.msg("<b>Sorry, Faction homes are disabled on this server.");
return;
}
// FPerm
if ( ! FPerm.SETHOME.has(usender, faction, true)) return;
// Verify
if (!usender.isUsingAdminMode() && !faction.isValidHome(newHome))
2011-10-09 18:35:39 +02:00
{
usender.msg("<b>Sorry, your faction home can only be set inside your own claimed territory.");
return;
}
2013-04-19 09:50:33 +02:00
// Event
2014-06-04 16:47:01 +02:00
EventFactionsHomeChange event = new EventFactionsHomeChange(sender, faction, newHome);
2013-04-19 09:50:33 +02:00
event.run();
if (event.isCancelled()) return;
newHome = event.getNewHome();
// Apply
2013-04-19 09:50:33 +02:00
faction.setHome(newHome);
2011-03-23 17:39:56 +01:00
// Inform
faction.msg("%s<i> set the home for your faction. You can now use:", usender.describeTo(usenderFaction, true));
2013-04-16 11:27:03 +02:00
faction.sendMessage(Factions.get().getOuterCmdFactions().cmdFactionsHome.getUseageTemplate());
if (faction != usenderFaction)
2011-10-09 18:35:39 +02:00
{
usender.msg("<b>You have set the home for the "+faction.getName(usender)+"<i> faction.");
}
2011-03-23 17:39:56 +01:00
}
}