From 46fca2ab49638da1cfd70e222c4a5c56be2a2a41 Mon Sep 17 00:00:00 2001 From: "Arnaud G. GIBERT" Date: Wed, 19 May 2021 01:00:13 +0200 Subject: [PATCH] Add in other faction fly support Add auto fly support Add fly perm Add autofly permission node Fix fly shutdown handling --- plugin.yml | 2 + src/com/massivecraft/factions/Perm.java | 1 + .../factions/cmd/CmdFactionsFly.java | 1 - .../factions/engine/EngineFly.java | 59 ++++++++++++++----- .../factions/engine/EnginePlayerDamage.java | 4 +- .../massivecraft/factions/entity/MConf.java | 6 +- .../massivecraft/factions/entity/MFlag.java | 2 +- .../massivecraft/factions/entity/MPerm.java | 4 ++ 8 files changed, 57 insertions(+), 22 deletions(-) diff --git a/plugin.yml b/plugin.yml index 9c38b562..20756cab 100644 --- a/plugin.yml +++ b/plugin.yml @@ -24,6 +24,7 @@ permissions: factions.access.grant.circle: {description: grant access by circle and radius, default: false} factions.access.inspect: {description: inspect where someone has access, default: false} factions.access.view: {description: view access, default: false} + factions.autofly: {description: enable auto_fly mode, default: false} factions.override: {description: enable override mode, default: false} factions.basecommand: {description: use factions base command, default: false} factions.chunkname: {description: set chunk name, default: false} @@ -162,6 +163,7 @@ permissions: factions.access.grant.circle: true factions.access.inspect: true factions.access.view: true + factions.autofly: true factions.override: true factions.basecommand: true factions.chunkname: true diff --git a/src/com/massivecraft/factions/Perm.java b/src/com/massivecraft/factions/Perm.java index 73b1c44a..6e786ef8 100644 --- a/src/com/massivecraft/factions/Perm.java +++ b/src/com/massivecraft/factions/Perm.java @@ -20,6 +20,7 @@ public enum Perm implements Identified ACCESS_DENY_FILL, ACCESS_DENY_SQUARE, ACCESS_DENY_CIRCLE, + AUTOFLY, CLAIM_ONE, CLAIM_AUTO, CLAIM_FILL, diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsFly.java b/src/com/massivecraft/factions/cmd/CmdFactionsFly.java index ec5334a9..c720f9db 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsFly.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsFly.java @@ -55,5 +55,4 @@ public class CmdFactionsFly extends MassiveCommandToggle mplayer.setFlying(value); EngineMassiveCorePlayerUpdate.update(player, false); } - } diff --git a/src/com/massivecraft/factions/engine/EngineFly.java b/src/com/massivecraft/factions/engine/EngineFly.java index 03a86449..e1cebb0e 100644 --- a/src/com/massivecraft/factions/engine/EngineFly.java +++ b/src/com/massivecraft/factions/engine/EngineFly.java @@ -11,11 +11,13 @@ 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.engine.EngineMassiveCorePlayerUpdate; 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.Bukkit; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -54,16 +56,42 @@ public class EngineFly extends Engine MPlayer mplayer = MPlayer.get(player); // ... and the player enables flying ... - if (!mplayer.isFlying()) return; + if (mplayer.isFlying()) + { + // ... and the player can't fly here... + if (!canFlyInTerritory(mplayer, PS.valueOf(player))) + { + event.setAllowed(false); - // ... and the player can fly here... - if (!canFlyInTerritory(mplayer, PS.valueOf(player))) return; + mplayer.setFlying(false); + deactivateForPlayer(player); - // ... set allowed ... - event.setAllowed(true); - - // ... set speed ... - event.setFlySpeed(MConf.get().flySpeed); + return; + } + + // ... set allowed ... + event.setAllowed(true); + + // ... set speed ... + event.setFlySpeed(MConf.get().flySpeed); + } + else + { + // ... and the player can fly here... + if (canFlyInTerritory(mplayer, PS.valueOf(player)) && Perm.AUTOFLY.has(mplayer.getSender())) + { + // Bukkit.getServer().getLogger().info("Event : " + player.getName() + ": [AUTOFLY]"); + + mplayer.setFlying(true); + EngineMassiveCorePlayerUpdate.update(player, false); + + // ... set allowed ... + event.setAllowed(true); + + // ... set speed ... + event.setFlySpeed(MConf.get().flySpeed); + } + } } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @@ -155,22 +183,23 @@ public class EngineFly extends Engine Faction faction = mplayer.getFaction(); Faction locationFaction = BoardColl.get().getFactionAt(ps.getChunk(true)); - - if (faction != locationFaction) + + // If the location faction doesn't allows the player to fly... + if (!MPerm.getPermFly().has(mplayer, locationFaction, false)) { - throw new MassiveException().addMsg("You can only fly within your own faction."); + throw new MassiveException().addMsg("You are not allowed to fly within " + locationFaction.getName() + " faction."); } - + // If the faction does not have the flag ... - if (!faction.getFlag(MFlag.getFlagFly())) + if (!locationFaction.getFlag(MFlag.getFlagFly())) { MFlag flag = MFlag.getFlagFly(); MassiveException ex = new MassiveException() - .addMsg("Flying requires that the %s flag is enabled for your faction.", flag.getName()); + .addMsg("Flying requires that the %s flag is enabled for " + locationFaction.getName() + " faction.", flag.getName()); // ... but they can change ... if (flag.isEditable()) { - boolean canEdit = MPerm.getPermFlags().has(mplayer, faction, false); + boolean canEdit = MPerm.getPermFlags().has(mplayer, locationFaction, false); // ... and the player can edit it themselves ... if (canEdit) { // ... tell them to edit. diff --git a/src/com/massivecraft/factions/engine/EnginePlayerDamage.java b/src/com/massivecraft/factions/engine/EnginePlayerDamage.java index a288e9cf..0b739734 100644 --- a/src/com/massivecraft/factions/engine/EnginePlayerDamage.java +++ b/src/com/massivecraft/factions/engine/EnginePlayerDamage.java @@ -8,7 +8,6 @@ import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayerColl; import com.massivecraft.massivecore.Engine; import com.massivecraft.massivecore.ps.PS; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -29,8 +28,7 @@ public class EnginePlayerDamage extends Engine // MANAGE PLAYER DAMAGE / IMMORTAL FLAG // -------------------------------------------- // - // @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - @EventHandler(priority = EventPriority.HIGHEST) + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onEntityDamaged(EntityDamageEvent event) { if (!(event.getEntity() instanceof Player)) diff --git a/src/com/massivecraft/factions/entity/MConf.java b/src/com/massivecraft/factions/entity/MConf.java index 5388ddfd..a6523b08 100644 --- a/src/com/massivecraft/factions/entity/MConf.java +++ b/src/com/massivecraft/factions/entity/MConf.java @@ -35,7 +35,8 @@ public class MConf extends Entity // -------------------------------------------- // protected static transient MConf i; - public static MConf get() { return i; } + public static MConf get() { + return i; } // -------------------------------------------- // // OVERRIDE: ENTITY @@ -588,7 +589,8 @@ public class MConf extends Entity MPerm.ID_REL, MUtil.set("LEADER", "OFFICER"), MPerm.ID_DISBAND, MUtil.set("LEADER"), MPerm.ID_FLAGS, MUtil.set("LEADER"), - MPerm.ID_PERMS, MUtil.set("LEADER") + MPerm.ID_PERMS, MUtil.set("LEADER"), + MPerm.ID_FLY, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY") ); // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/entity/MFlag.java b/src/com/massivecraft/factions/entity/MFlag.java index 9d974e9a..9eb921fa 100644 --- a/src/com/massivecraft/factions/entity/MFlag.java +++ b/src/com/massivecraft/factions/entity/MFlag.java @@ -116,7 +116,7 @@ public class MFlag extends Entity implements Prioritized, Registerable, N public static MFlag getFlagPermanent() { return getCreative(PRIORITY_PERMANENT, ID_PERMANENT, ID_PERMANENT, "Is the faction immune to deletion?", "The faction can NOT be deleted.", "The faction can be deleted.", false, false, true); } public static MFlag getFlagPeaceful() { return getCreative(PRIORITY_PEACEFUL, ID_PEACEFUL, ID_PEACEFUL, "Is the faction in truce with everyone?", "The faction is in truce with everyone.", "The faction relations work as usual.", false, false, true); } public static MFlag getFlagInfpower() { return getCreative(PRIORITY_INFPOWER, ID_INFPOWER, ID_INFPOWER, "Does the faction have infinite power?", "The faction has infinite power.", "The faction power works as usual.", false, false, true); } - public static MFlag getFlagFly() { return getCreative(PRIORITY_FLY, ID_FLY, ID_FLY, "Is flying allowed for members in faction territory?", "Members can fly in faction territory.", "Members can not fly in faction territory.", false, false, true); } + public static MFlag getFlagFly() { return getCreative(PRIORITY_FLY, ID_FLY, ID_FLY, "Is flying allowed in faction territory?", "Players can fly in faction territory.", "Players can not fly in faction territory.", false, false, true); } public static MFlag getFlagTaxKick() { return getCreative(PRIORITY_TAXKICK, ID_TAXKICK, ID_TAXKICK, "Are players kicked for not paying taxes?", "Members are kicked for not paying taxes.", "Members are not kicked for not paying taxes.", false, true, true); } public static MFlag getFlagImmortal() { return getCreative(PRIORITY_IMMORTAL, ID_IMMORTAL, ID_IMMORTAL, "Are players immortal in this territory?", "Players are immortal in this territory.", "Players are NOT immortal in this territory.", false, false, true); } diff --git a/src/com/massivecraft/factions/entity/MPerm.java b/src/com/massivecraft/factions/entity/MPerm.java index d6dd1976..8909cae8 100644 --- a/src/com/massivecraft/factions/entity/MPerm.java +++ b/src/com/massivecraft/factions/entity/MPerm.java @@ -62,6 +62,7 @@ public class MPerm extends Entity implements Prioritized, Registerable, N public final static transient String ID_DISBAND = "disband"; public final static transient String ID_FLAGS = "flags"; public final static transient String ID_PERMS = "perms"; + public final static transient String ID_FLY = "fly"; public final static transient int PRIORITY_BUILD = 1000; public final static transient int PRIORITY_PAINBUILD = 2000; @@ -91,6 +92,7 @@ public class MPerm extends Entity implements Prioritized, Registerable, N public final static transient int PRIORITY_DISBAND = 21000; public final static transient int PRIORITY_FLAGS = 22000; public final static transient int PRIORITY_PERMS = 23000; + public final static transient int PRIORITY_FLY = 24000; // -------------------------------------------- // // META: CORE @@ -144,6 +146,7 @@ public class MPerm extends Entity implements Prioritized, Registerable, N getPermDisband(); getPermFlags(); getPermPerms(); + getPermFly(); } public static MPerm getPermBuild() { return getCreative(PRIORITY_BUILD, ID_BUILD, ID_BUILD, "edit the terrain", true, true, true); } @@ -174,6 +177,7 @@ public class MPerm extends Entity implements Prioritized, Registerable, N public static MPerm getPermDisband() { return getCreative(PRIORITY_DISBAND, ID_DISBAND, ID_DISBAND, "disband the faction", false, true, true); } public static MPerm getPermFlags() { return getCreative(PRIORITY_FLAGS, ID_FLAGS, ID_FLAGS, "manage flags", false, true, true); } public static MPerm getPermPerms() { return getCreative(PRIORITY_PERMS, ID_PERMS, ID_PERMS, "manage permissions", false, true, true); } + public static MPerm getPermFly() { return getCreative(PRIORITY_FLY, ID_FLY, ID_FLY, "manage fly", false, true, true); } public static MPerm getCreative(int priority, String id, String name, String desc, boolean territory, boolean editable, boolean visible) {