Improve faction fly
This commit is contained in:
parent
59d8091ca8
commit
9e81d6d865
@ -6,8 +6,8 @@ public class CmdFactionsFlag extends FactionsCommand
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
CmdFactionsFlagList cmdFactionsFlagList = new CmdFactionsFlagList();
|
||||
CmdFactionsFlagShow cmdFactionsFlagShow = new CmdFactionsFlagShow();
|
||||
CmdFactionsFlagSet cmdFactionsFlagSet = new CmdFactionsFlagSet();
|
||||
public CmdFactionsFlagList cmdFactionsFlagList = new CmdFactionsFlagList();
|
||||
public CmdFactionsFlagShow cmdFactionsFlagShow = new CmdFactionsFlagShow();
|
||||
public CmdFactionsFlagSet cmdFactionsFlagSet = new CmdFactionsFlagSet();
|
||||
|
||||
}
|
||||
|
@ -4,9 +4,9 @@ import com.massivecraft.factions.engine.EngineFly;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.command.MassiveCommandToggle;
|
||||
import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer;
|
||||
import com.massivecraft.massivecore.engine.EngineMassiveCorePlayerUpdate;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.util.IdUtil;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class CmdFactionsFly extends MassiveCommandToggle
|
||||
@ -24,8 +24,7 @@ public class CmdFactionsFly extends MassiveCommandToggle
|
||||
|
||||
public CmdFactionsFly()
|
||||
{
|
||||
super();
|
||||
this.setAliases("fly");
|
||||
this.addRequirements(RequirementIsPlayer.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
@ -47,14 +46,11 @@ public class CmdFactionsFly extends MassiveCommandToggle
|
||||
public void setValue(boolean value) throws MassiveException
|
||||
{
|
||||
MPlayer mplayer = MPlayer.get(sender);
|
||||
Player player = IdUtil.getPlayer(sender);
|
||||
Player player = me;
|
||||
if (player == null) throw new MassiveException().addMsg("<b>Could not find player.");
|
||||
|
||||
PS ps = PS.valueOf(player);
|
||||
if (value && !EngineFly.canFlyInTerritory(mplayer, ps))
|
||||
{
|
||||
throw new MassiveException().addMsg("<b>You can't fly where you are.");
|
||||
}
|
||||
if (value) EngineFly.canFlyInTerritoryOrThrow(mplayer, ps);
|
||||
|
||||
mplayer.setFlying(value);
|
||||
EngineMassiveCorePlayerUpdate.update(player, false);
|
||||
|
@ -19,7 +19,7 @@ public class FactionsCommand extends MassiveCommand
|
||||
|
||||
public FactionsCommand()
|
||||
{
|
||||
this.setSetupEnabled(true);
|
||||
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
|
@ -1,19 +1,28 @@
|
||||
package com.massivecraft.factions.engine;
|
||||
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.CmdFactions;
|
||||
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.MFlagColl;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.factions.event.EventFactionsFlagChange;
|
||||
import com.massivecraft.massivecore.Engine;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.event.EventMassiveCorePlayerUpdate;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.store.DriverFlatfile;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class EngineFly extends Engine
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
@ -78,15 +87,99 @@ public class EngineFly extends Engine
|
||||
deactivateForPlayer(player);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void flagUpdate(EventFactionsFlagChange event)
|
||||
{
|
||||
if (event.getFlag() != MFlag.getFlagFly()) return;
|
||||
if (event.isNewValue() == true) return;
|
||||
|
||||
// Disable for all players when disabled
|
||||
event.getFaction().getOnlinePlayers().forEach(EngineFly::deactivateForPlayer);
|
||||
}
|
||||
|
||||
public static boolean canFlyInTerritory(MPlayer mplayer, PS ps)
|
||||
{
|
||||
try
|
||||
{
|
||||
canFlyInTerritoryOrThrow(mplayer, ps);
|
||||
return true;
|
||||
}
|
||||
catch (MassiveException ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void canFlyInTerritoryOrThrow(MPlayer mplayer, PS ps) throws MassiveException
|
||||
{
|
||||
if (!mplayer.isPlayer())
|
||||
{
|
||||
throw new MassiveException().addMsg("<b>Only players can fly");
|
||||
}
|
||||
|
||||
Faction faction = mplayer.getFaction();
|
||||
Faction locationFaction = BoardColl.get().getFactionAt(ps.getChunk(true));
|
||||
|
||||
if (faction != locationFaction) return false;
|
||||
if (!faction.getFlag(MFlag.getFlagFly())) return false;
|
||||
if (faction != locationFaction)
|
||||
{
|
||||
throw new MassiveException().addMsg("<b>You can only fly within your own faction.");
|
||||
}
|
||||
|
||||
return true;
|
||||
// If the faction does not have the flag ...
|
||||
if (!faction.getFlag(MFlag.getFlagFly()))
|
||||
{
|
||||
MFlag flag = MFlag.getFlagFly();
|
||||
MassiveException ex = new MassiveException()
|
||||
.addMsg("<b>Flying requires that the <h>%s <b>flag is enabled for your faction.", flag.getName());
|
||||
|
||||
// ... but they can change ...
|
||||
if (flag.isEditable()) {
|
||||
boolean canEdit = MPerm.getPermFlags().has(mplayer, faction, false);
|
||||
// ... and the player can edit it themselves ...
|
||||
if (canEdit) {
|
||||
// ... tell them to edit.
|
||||
ex.addMsg("<i>You can edit the flag with: ");
|
||||
ex.addMessage(CmdFactions.get().cmdFactionsFlag.cmdFactionsFlagSet.getTemplate(false, true, mplayer.getSender()));
|
||||
}
|
||||
// ... otherwise ...
|
||||
else {
|
||||
// .. tell them to have someone else edit it ...
|
||||
ex.addMsg("<i>You can ask a faction admin to change the flag");
|
||||
}
|
||||
}
|
||||
// ... or only server admins can change it ...
|
||||
else
|
||||
{
|
||||
boolean isAdmin = Perm.OVERRIDE.has(mplayer.getSender());
|
||||
boolean isDefault = flag.isDefault();
|
||||
if (isAdmin)
|
||||
{
|
||||
boolean overriding = mplayer.isOverriding();
|
||||
ex.addMsg("<i>You can change the flag if you are overriding.");
|
||||
if (overriding) ex.addMsg("<i>You are already overriding.");
|
||||
else
|
||||
{
|
||||
ex.addMsg("<i>You can enable override with:");
|
||||
ex.addMessage(CmdFactions.get().cmdFactionsOverride.getTemplate(false, true, mplayer.getSender()));
|
||||
}
|
||||
|
||||
if (!isDefault)
|
||||
{
|
||||
ex.addMsg("<i>You can also ask someone with access to the configuration files to make flying enabled by default.");
|
||||
if (MFlagColl.get().getDb().getDriver() instanceof DriverFlatfile)
|
||||
{
|
||||
File file = DriverFlatfile.getDirectory(MFlagColl.get());
|
||||
ex.addMsg("<i>Configuring the flags can be done by editing the files in <h>%s<i>.", file.getAbsoluteFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ex.addMsg("<b>Only server admins can change the flag. Per default flying is %s.", isDefault ? "enabled" : "disabled");
|
||||
}
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
public static void deactivateForPlayer(Player player)
|
||||
|
Loading…
Reference in New Issue
Block a user