Add Faction warps
This commit is contained in:
@@ -29,14 +29,12 @@ public class CmdFactions extends FactionsCommand
|
||||
public CmdFactionsStatus cmdFactionsStatus = new CmdFactionsStatus();
|
||||
public CmdFactionsJoin cmdFactionsJoin = new CmdFactionsJoin();
|
||||
public CmdFactionsLeave cmdFactionsLeave = new CmdFactionsLeave();
|
||||
public CmdFactionsHome cmdFactionsHome = new CmdFactionsHome();
|
||||
public CmdFactionsWarp cmdFactionsWarp = new CmdFactionsWarp();
|
||||
public CmdFactionsMap cmdFactionsMap = new CmdFactionsMap();
|
||||
public CmdFactionsCreate cmdFactionsCreate = new CmdFactionsCreate();
|
||||
public CmdFactionsName cmdFactionsName = new CmdFactionsName();
|
||||
public CmdFactionsDescription cmdFactionsDescription = new CmdFactionsDescription();
|
||||
public CmdFactionsMotd cmdFactionsMotd = new CmdFactionsMotd();
|
||||
public CmdFactionsSethome cmdFactionsSethome = new CmdFactionsSethome();
|
||||
public CmdFactionsUnsethome cmdFactionsUnsethome = new CmdFactionsUnsethome();
|
||||
public CmdFactionsInvite cmdFactionsInvite = new CmdFactionsInvite();
|
||||
public CmdFactionsKick cmdFactionsKick = new CmdFactionsKick();
|
||||
public CmdFactionsTitle cmdFactionsTitle = new CmdFactionsTitle();
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.type.TypeFaction;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.factions.event.EventFactionsHomeChange;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
|
||||
import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
|
||||
public class CmdFactionsSethome extends FactionsCommandHome
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsSethome()
|
||||
{
|
||||
// Parameters
|
||||
this.addParameter(TypeFaction.get(), "faction", "you");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(RequirementHasPerm.get(Perm.SETHOME));
|
||||
this.addRequirements(RequirementIsPlayer.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
// Args
|
||||
Faction faction = this.readArg(msenderFaction);
|
||||
|
||||
PS newHome = PS.valueOf(me.getLocation());
|
||||
|
||||
// MPerm
|
||||
if ( ! MPerm.getPermSethome().has(msender, faction, true)) return;
|
||||
|
||||
// Verify
|
||||
if (!msender.isOverriding() && !faction.isValidHome(newHome))
|
||||
{
|
||||
msender.msg("<b>Sorry, your faction home can only be set inside your own claimed territory.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Event
|
||||
EventFactionsHomeChange event = new EventFactionsHomeChange(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:", msender.describeTo(msenderFaction, true));
|
||||
faction.sendMessage(CmdFactions.get().cmdFactionsHome.getTemplate());
|
||||
if (faction != msenderFaction)
|
||||
{
|
||||
msender.msg("<i>You have set the home for " + faction.getName(msender) + "<i>.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
14
src/com/massivecraft/factions/cmd/CmdFactionsWarp.java
Normal file
14
src/com/massivecraft/factions/cmd/CmdFactionsWarp.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
public class CmdFactionsWarp extends FactionsCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsWarpGo cmdFactionsWarpGo = new CmdFactionsWarpGo();
|
||||
public CmdFactionsWarpList cmdFactionsWarpList = new CmdFactionsWarpList();
|
||||
public CmdFactionsWarpAdd cmdFactionWarpAdd = new CmdFactionsWarpAdd();
|
||||
public CmdFactionsWarpRemove cmdFactionWarpRemove = new CmdFactionsWarpRemove();
|
||||
|
||||
}
|
||||
85
src/com/massivecraft/factions/cmd/CmdFactionsWarpAdd.java
Normal file
85
src/com/massivecraft/factions/cmd/CmdFactionsWarpAdd.java
Normal file
@@ -0,0 +1,85 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.cmd.type.TypeFaction;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.factions.entity.Warp;
|
||||
import com.massivecraft.factions.event.EventFactionsWarpAdd;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeString;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
|
||||
public class CmdFactionsWarpAdd extends FactionsCommandWarp
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsWarpAdd()
|
||||
{
|
||||
// Parameters
|
||||
this.addParameter(TypeString.get(), "name");
|
||||
this.addParameter(TypeFaction.get(), "faction", "you");
|
||||
|
||||
// Aliases
|
||||
this.addAliases("create");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(RequirementIsPlayer.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
// Args
|
||||
String name = this.readArg();
|
||||
Faction faction = this.readArg(msenderFaction);
|
||||
|
||||
|
||||
PS ps = PS.valueOf(me.getLocation());
|
||||
Warp warp = new Warp(name, ps);
|
||||
|
||||
// MPerm
|
||||
if ( ! MPerm.getPermSethome().has(msender, faction, true)) return;
|
||||
|
||||
if (faction.getWarps().getAll().stream().map(Warp::getName).anyMatch(s -> s.equalsIgnoreCase(name)))
|
||||
{
|
||||
throw new MassiveException().addMsg("<b>There is already a warp called <h>%s<b>.", name);
|
||||
}
|
||||
|
||||
// Verify
|
||||
if (!msender.isOverriding() && !warp.isValidFor(faction))
|
||||
{
|
||||
throw new MassiveException().addMsg("<b>Sorry, your faction warps can only be set inside your own claimed territory.");
|
||||
}
|
||||
|
||||
if (!msender.isOverriding() && faction.getWarps().size() >= MConf.get().warpsMax && MConf.get().warpsMax >= 0)
|
||||
{
|
||||
throw new MassiveException().addMsg("<b>You can at most have <h>%d <b>warps at a time.", MConf.get().warpsMax);
|
||||
}
|
||||
|
||||
// Event
|
||||
EventFactionsWarpAdd event = new EventFactionsWarpAdd(sender, faction, warp);
|
||||
event.run();
|
||||
if (event.isCancelled()) return;
|
||||
warp = event.getNewWarp();
|
||||
|
||||
// Apply
|
||||
faction.getWarps().attach(warp);
|
||||
|
||||
// Inform
|
||||
faction.msg("%s<i> added the warp <h>%s <i>to your faction. You can now use:", msender.describeTo(msenderFaction, true), warp.getName());
|
||||
faction.sendMessage(CmdFactions.get().cmdFactionsWarp.cmdFactionsWarpGo.getTemplateWithArgs(null, warp.getName()));
|
||||
if (faction != msenderFaction)
|
||||
{
|
||||
msender.msg("<i>You added the warp <h>%s <i>to %s<i>.", warp.getName(), faction.describeTo(msender));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,13 +2,15 @@ package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.cmd.type.TypeFaction;
|
||||
import com.massivecraft.factions.cmd.type.TypeWarp;
|
||||
import com.massivecraft.factions.entity.BoardColl;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.entity.MFlag;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.factions.event.EventFactionsHomeTeleport;
|
||||
import com.massivecraft.factions.entity.Warp;
|
||||
import com.massivecraft.factions.event.EventFactionsWarpTeleport;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer;
|
||||
import com.massivecraft.massivecore.mixin.MixinMessage;
|
||||
@@ -18,19 +20,21 @@ import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.teleport.Destination;
|
||||
import com.massivecraft.massivecore.teleport.DestinationSimple;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class CmdFactionsHome extends FactionsCommandHome
|
||||
public class CmdFactionsWarpGo extends FactionsCommandWarp
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsHome()
|
||||
public CmdFactionsWarpGo()
|
||||
{
|
||||
// Parameters
|
||||
this.addParameter(TypeWarp.get(), "warp");
|
||||
this.addParameter(TypeFaction.get(), "faction", "you");
|
||||
|
||||
// Requirements
|
||||
@@ -44,53 +48,31 @@ public class CmdFactionsHome extends FactionsCommandHome
|
||||
@Override
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
if ( ! MConf.get().homesTeleportCommandEnabled)
|
||||
{
|
||||
msender.msg("<b>Sorry, the ability to teleport to Faction homes is disabled on this server.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Args
|
||||
Faction faction = this.readArg(msenderFaction);
|
||||
PS home = faction.getHome();
|
||||
String homeDesc = "home for " + faction.describeTo(msender, false);
|
||||
Faction faction = this.readArgAt(1, msenderFaction);
|
||||
Warp warp = TypeWarp.get(faction).read(this.argAt(0), sender);
|
||||
String warpDesc = Txt.parse("<h>%s <i>in <reset>%s<i>.", warp.getName(), faction.describeTo(msender, false));
|
||||
|
||||
// Any and MPerm
|
||||
if ( ! MPerm.getPermHome().has(msender, faction, true)) return;
|
||||
|
||||
if (home == null)
|
||||
if ( ! MConf.get().warpsTeleportAllowedFromEnemyTerritory && msender.isInEnemyTerritory())
|
||||
{
|
||||
msender.msg("<b>%s <b>does not have a home.", faction.describeTo(msender, true));
|
||||
|
||||
if (MPerm.getPermSethome().has(msender, faction, false))
|
||||
{
|
||||
msender.msg("<i>You should:");
|
||||
msender.message(CmdFactions.get().cmdFactionsSethome.getTemplate());
|
||||
}
|
||||
|
||||
return;
|
||||
throw new MassiveException().addMsg("<b>You cannot teleport to %s <b>while in the territory of an enemy faction.", warp);
|
||||
}
|
||||
|
||||
if ( ! MConf.get().homesTeleportAllowedFromEnemyTerritory && msender.isInEnemyTerritory())
|
||||
if ( ! MConf.get().warpsTeleportAllowedFromDifferentWorld && !me.getWorld().getName().equalsIgnoreCase(warp.getWorld()))
|
||||
{
|
||||
msender.msg("<b>You cannot teleport to %s <b>while in the territory of an enemy faction.", homeDesc);
|
||||
return;
|
||||
throw new MassiveException().addMsg("<b>You cannot teleport to %s <b>while in a different world.", warpDesc);
|
||||
}
|
||||
|
||||
if ( ! MConf.get().homesTeleportAllowedFromDifferentWorld && !me.getWorld().getName().equalsIgnoreCase(home.getWorld()))
|
||||
{
|
||||
msender.msg("<b>You cannot teleport to %s <b>while in a different world.", homeDesc);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Faction factionHere = BoardColl.get().getFactionAt(PS.valueOf(me.getLocation()));
|
||||
Location locationHere = me.getLocation().clone();
|
||||
|
||||
// if player is not in a safe zone or their own faction territory, only allow teleport if no enemies are nearby
|
||||
if
|
||||
(
|
||||
MConf.get().homesTeleportAllowedEnemyDistance > 0
|
||||
MConf.get().warpsTeleportAllowedEnemyDistance > 0
|
||||
&&
|
||||
factionHere.getFlag(MFlag.getFlagPvp())
|
||||
&&
|
||||
@@ -100,7 +82,7 @@ public class CmdFactionsHome extends FactionsCommandHome
|
||||
(
|
||||
msender.isInOwnTerritory()
|
||||
&&
|
||||
! MConf.get().homesTeleportIgnoreEnemiesIfInOwnTerritory
|
||||
! MConf.get().warpsTeleportIgnoreEnemiesIfInOwnTerritory
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -110,41 +92,38 @@ public class CmdFactionsHome extends FactionsCommandHome
|
||||
double y = locationHere.getY();
|
||||
double z = locationHere.getZ();
|
||||
|
||||
for (Player p : me.getServer().getOnlinePlayers())
|
||||
for (Player p : w.getPlayers())
|
||||
{
|
||||
if (MUtil.isntPlayer(p)) continue;
|
||||
|
||||
if (p == null || !p.isOnline() || p.isDead() || p == me || p.getWorld() != w)
|
||||
continue;
|
||||
if (p == null || !p.isOnline() || p.isDead() || p == me || p.getWorld() != w) continue;
|
||||
|
||||
MPlayer fp = MPlayer.get(p);
|
||||
if (msender.getRelationTo(fp) != Rel.ENEMY)
|
||||
continue;
|
||||
if (msender.getRelationTo(fp) != Rel.ENEMY) continue;
|
||||
|
||||
Location l = p.getLocation();
|
||||
double dx = Math.abs(x - l.getX());
|
||||
double dy = Math.abs(y - l.getY());
|
||||
double dz = Math.abs(z - l.getZ());
|
||||
double max = MConf.get().homesTeleportAllowedEnemyDistance;
|
||||
double max = MConf.get().warpsTeleportAllowedEnemyDistance;
|
||||
|
||||
// box-shaped distance check
|
||||
if (dx > max || dy > max || dz > max)
|
||||
continue;
|
||||
|
||||
msender.msg("<b>You cannot teleport to %s <b>while an enemy is within %f blocks of you.", homeDesc, MConf.get().homesTeleportAllowedEnemyDistance);
|
||||
return;
|
||||
throw new MassiveException().addMsg("<b>You cannot teleport to %s <b>while an enemy is within %f blocks of you.", warpDesc, max);
|
||||
}
|
||||
}
|
||||
|
||||
// Event
|
||||
EventFactionsHomeTeleport event = new EventFactionsHomeTeleport(sender);
|
||||
EventFactionsWarpTeleport event = new EventFactionsWarpTeleport(sender, warp);
|
||||
event.run();
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
// Apply
|
||||
try
|
||||
{
|
||||
Destination destination = new DestinationSimple(home, homeDesc);
|
||||
Destination destination = new DestinationSimple(warp.getLocation(), warpDesc);
|
||||
MixinTeleport.get().teleport(me, destination, sender);
|
||||
}
|
||||
catch (TeleporterException e)
|
||||
48
src/com/massivecraft/factions/cmd/CmdFactionsWarpList.java
Normal file
48
src/com/massivecraft/factions/cmd/CmdFactionsWarpList.java
Normal file
@@ -0,0 +1,48 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.cmd.type.TypeFaction;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.factions.entity.Warp;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.command.Parameter;
|
||||
import com.massivecraft.massivecore.pager.Pager;
|
||||
import com.massivecraft.massivecore.pager.Stringifier;
|
||||
import com.massivecraft.massivecore.ps.PSFormatDesc;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class CmdFactionsWarpList extends FactionsCommandWarp
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsWarpList()
|
||||
{
|
||||
// Parameters
|
||||
this.addParameter(TypeFaction.get(), "faction", "you");
|
||||
this.addParameter(Parameter.getPage());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
// Args
|
||||
Faction faction = this.readArg(msenderFaction);
|
||||
int idx = this.readArg();
|
||||
|
||||
// Any and MPerm
|
||||
if ( ! MPerm.getPermHome().has(msender, faction, true)) return;
|
||||
|
||||
Pager<Warp> pager = new Pager<>(this, "Warps for " + faction.getName(), idx, faction.getWarps().getAll());
|
||||
pager.setMsonifier((Stringifier<Warp>) (warp, i) ->
|
||||
Txt.parse("<lime>%s<i>: %s", warp.getName(), warp.getLocation().getBlock(true).toString(PSFormatDesc.get())));
|
||||
|
||||
pager.message();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +1,23 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.cmd.type.TypeFaction;
|
||||
import com.massivecraft.factions.cmd.type.TypeWarp;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.factions.event.EventFactionsHomeChange;
|
||||
import com.massivecraft.factions.entity.Warp;
|
||||
import com.massivecraft.factions.event.EventFactionsWarpRemove;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
|
||||
public class CmdFactionsUnsethome extends FactionsCommandHome
|
||||
public class CmdFactionsWarpRemove extends FactionsCommandWarp
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsUnsethome()
|
||||
public CmdFactionsWarpRemove()
|
||||
{
|
||||
// Parameters
|
||||
this.addParameter(TypeWarp.get(), "warp");
|
||||
this.addParameter(TypeFaction.get(), "faction", "you");
|
||||
}
|
||||
|
||||
@@ -26,31 +29,25 @@ public class CmdFactionsUnsethome extends FactionsCommandHome
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
// Args
|
||||
Faction faction = this.readArg(msenderFaction);
|
||||
Faction faction = this.readArgAt(1, msenderFaction);
|
||||
Warp warp = TypeWarp.get(faction).read(this.argAt(0), sender);
|
||||
|
||||
// Any and MPerm
|
||||
if ( ! MPerm.getPermSethome().has(msender, faction, true)) return;
|
||||
|
||||
// NoChange
|
||||
if ( ! faction.hasHome())
|
||||
{
|
||||
msender.msg("<i>%s <i>does already not have a home.", faction.describeTo(msender));
|
||||
return;
|
||||
}
|
||||
|
||||
// Event
|
||||
EventFactionsHomeChange event = new EventFactionsHomeChange(sender, faction, null);
|
||||
EventFactionsWarpRemove event = new EventFactionsWarpRemove(sender, faction, warp);
|
||||
event.run();
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
// Apply
|
||||
faction.setHome(null);
|
||||
warp.detach();
|
||||
|
||||
// Inform
|
||||
faction.msg("%s<i> unset the home for your faction.", msender.describeTo(msenderFaction, true));
|
||||
faction.msg("%s<i> removed the warp <h>%s <i>for your faction.", msender.describeTo(msenderFaction, true), warp.getName());
|
||||
if (faction != msenderFaction)
|
||||
{
|
||||
msender.msg("<i>You have unset the home for " + faction.getName(msender) + "<i>.");
|
||||
msender.msg("<i>You have removed the warp <h>%s <i>for %s<i>.", warp.getName(), faction.getName(msender));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionHomesEnabled;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionWarpsEnabled;
|
||||
import com.massivecraft.massivecore.mson.Mson;
|
||||
|
||||
public class FactionsCommandDocumentation extends FactionsCommand
|
||||
@@ -11,7 +11,7 @@ public class FactionsCommandDocumentation extends FactionsCommand
|
||||
|
||||
public FactionsCommandDocumentation()
|
||||
{
|
||||
this.addRequirements(ReqFactionHomesEnabled.get());
|
||||
this.addRequirements(ReqFactionWarpsEnabled.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionHomesEnabled;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionWarpsEnabled;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.massivecore.command.Visibility;
|
||||
|
||||
public class FactionsCommandHome extends FactionsCommand
|
||||
public class FactionsCommandWarp extends FactionsCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public FactionsCommandHome()
|
||||
public FactionsCommandWarp()
|
||||
{
|
||||
this.addRequirements(ReqFactionHomesEnabled.get());
|
||||
this.addRequirements(ReqFactionWarpsEnabled.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
@@ -22,7 +22,7 @@ public class FactionsCommandHome extends FactionsCommand
|
||||
@Override
|
||||
public Visibility getVisibility()
|
||||
{
|
||||
return MConf.get().homesEnabled ? super.getVisibility() : Visibility.INVISIBLE;
|
||||
return MConf.get().warpsEnabled ? super.getVisibility() : Visibility.INVISIBLE;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,40 +1,40 @@
|
||||
package com.massivecraft.factions.cmd.req;
|
||||
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.massivecore.command.MassiveCommand;
|
||||
import com.massivecraft.massivecore.command.requirement.RequirementAbstract;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class ReqFactionHomesEnabled extends RequirementAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// SERIALIZABLE
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static ReqFactionHomesEnabled i = new ReqFactionHomesEnabled();
|
||||
public static ReqFactionHomesEnabled get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public boolean apply(CommandSender sender, MassiveCommand command)
|
||||
{
|
||||
return MConf.get().homesEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createErrorMessage(CommandSender sender, MassiveCommand command)
|
||||
{
|
||||
return Txt.parse("<b>Homes must be enabled on the server to %s.", getDesc(command));
|
||||
}
|
||||
|
||||
}
|
||||
package com.massivecraft.factions.cmd.req;
|
||||
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.massivecore.command.MassiveCommand;
|
||||
import com.massivecraft.massivecore.command.requirement.RequirementAbstract;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class ReqFactionWarpsEnabled extends RequirementAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// SERIALIZABLE
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static ReqFactionWarpsEnabled i = new ReqFactionWarpsEnabled();
|
||||
public static ReqFactionWarpsEnabled get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public boolean apply(CommandSender sender, MassiveCommand command)
|
||||
{
|
||||
return MConf.get().warpsEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createErrorMessage(CommandSender sender, MassiveCommand command)
|
||||
{
|
||||
return Txt.parse("<b>Warps must be enabled on the server to %s.", getDesc(command));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.massivecraft.factions.cmd.type;
|
||||
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.massivecore.command.type.TypeAbstractChoice;
|
||||
import com.massivecraft.massivecore.store.EntityInternal;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public abstract class TypeEntityInternalFaction<E extends EntityInternal<E>> extends TypeAbstractChoice<E>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
protected TypeEntityInternalFaction(Class<E> clazz)
|
||||
{
|
||||
super(clazz);
|
||||
|
||||
this.faction = null;
|
||||
this.setAll(Collections.emptyList());
|
||||
}
|
||||
|
||||
protected TypeEntityInternalFaction(Class<E> clazz, Faction faction)
|
||||
{
|
||||
super(clazz);
|
||||
if (faction == null) throw new NullPointerException("faction");
|
||||
|
||||
this.faction = faction;
|
||||
|
||||
this.setAll(this.getAll(faction));
|
||||
}
|
||||
|
||||
protected abstract Collection<E> getAll(Faction faction);
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final Faction faction;
|
||||
public Faction getFaction() { return this.faction; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public boolean isValid(String arg, CommandSender sender)
|
||||
{
|
||||
// In the generic case accept all
|
||||
if (this.getAll().isEmpty()) return true;
|
||||
else return super.isValid(arg, sender);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,16 +1,13 @@
|
||||
package com.massivecraft.factions.cmd.type;
|
||||
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.Rank;
|
||||
import com.massivecraft.massivecore.command.type.TypeAbstractChoice;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
public class TypeRank extends TypeAbstractChoice<Rank>
|
||||
public class TypeRank extends TypeEntityInternalFaction<Rank>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
@@ -21,39 +18,22 @@ public class TypeRank extends TypeAbstractChoice<Rank>
|
||||
private TypeRank()
|
||||
{
|
||||
super(Rank.class);
|
||||
|
||||
this.faction = null;
|
||||
this.setAll(Collections.emptyList());
|
||||
}
|
||||
|
||||
public static TypeRank get(Faction faction) { return new TypeRank(faction); }
|
||||
public TypeRank(Faction faction)
|
||||
{
|
||||
super(Rel.class);
|
||||
if (faction == null) throw new NullPointerException("faction");
|
||||
|
||||
this.faction = faction;
|
||||
|
||||
this.setAll(faction.getRanks().getAll());
|
||||
super(Rank.class, faction);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final Faction faction;
|
||||
public Faction getFaction() { return this.faction; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public boolean isValid(String arg, CommandSender sender)
|
||||
public Collection<Rank> getAll(Faction faction)
|
||||
{
|
||||
// In the generic case accept all
|
||||
if (this.getAll().isEmpty()) return true;
|
||||
else return super.isValid(arg, sender);
|
||||
return faction.getRanks().getAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
37
src/com/massivecraft/factions/cmd/type/TypeWarp.java
Normal file
37
src/com/massivecraft/factions/cmd/type/TypeWarp.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package com.massivecraft.factions.cmd.type;
|
||||
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.Warp;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class TypeWarp extends TypeEntityInternalFaction<Warp>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static TypeWarp i = new TypeWarp();
|
||||
public static TypeWarp get() { return i; }
|
||||
private TypeWarp()
|
||||
{
|
||||
super(Warp.class);
|
||||
}
|
||||
|
||||
public static TypeWarp get(Faction faction) { return new TypeWarp(faction); }
|
||||
public TypeWarp(Faction faction)
|
||||
{
|
||||
super(Warp.class, faction);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Collection<Warp> getAll(Faction faction)
|
||||
{
|
||||
return faction.getWarps().getAll();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user