From dc1543681a468f96aafad91df2f6116080771da5 Mon Sep 17 00:00:00 2001 From: "Arnaud G. GIBERT" Date: Tue, 11 May 2021 21:53:42 +0200 Subject: [PATCH] Add "Immortal" faction flag support Update version to 3.3.3 --- plugin.yml | 2 +- pom.xml | 2 +- src/com/massivecraft/factions/Factions.java | 2 + .../factions/engine/EnginePlayerDamage.java | 83 +++++++++++++++++++ .../massivecraft/factions/entity/MFlag.java | 4 + 5 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 src/com/massivecraft/factions/engine/EnginePlayerDamage.java diff --git a/plugin.yml b/plugin.yml index 93553fb1..9c38b562 100644 --- a/plugin.yml +++ b/plugin.yml @@ -3,7 +3,7 @@ name: ${project.name} version: ${project.version} website: ${project.url} description: ${project.description} -authors: [Madus, Cayorion, Ulumulu1510, MarkehMe, Brettflan] +authors: [Madus, Cayorion, Ulumulu1510, MarkehMe, Brettflan, AlkorZ3] depend: [MassiveCore] softdepend: [PermissionsEx, Permissions, Essentials, EssentialsChat, HeroChat, LocalAreaChat, LWC, ChatManager, AuthMe, Vault, WorldEdit, WorldGuard] api-version: 1.13 diff --git a/pom.xml b/pom.xml index b91ae769..e8dcfe6e 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.massivecraft.massivesuper MassiveSuper - 3.3.2 + 3.3.3 ../MassiveSuper diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index 2d8b965b..c7976d0a 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -38,6 +38,7 @@ import com.massivecraft.factions.engine.EngineLastActivity; import com.massivecraft.factions.engine.EngineMotd; import com.massivecraft.factions.engine.EngineMoveChunk; import com.massivecraft.factions.engine.EnginePermBuild; +import com.massivecraft.factions.engine.EnginePlayerDamage; import com.massivecraft.factions.engine.EnginePlayerData; import com.massivecraft.factions.engine.EnginePower; import com.massivecraft.factions.engine.EngineSeeChunk; @@ -234,6 +235,7 @@ public class Factions extends MassivePlugin EngineMotd.class, EngineMoveChunk.class, EnginePermBuild.class, + EnginePlayerDamage.class, EnginePlayerData.class, EnginePower.class, EngineSeeChunk.class, diff --git a/src/com/massivecraft/factions/engine/EnginePlayerDamage.java b/src/com/massivecraft/factions/engine/EnginePlayerDamage.java new file mode 100644 index 00000000..a288e9cf --- /dev/null +++ b/src/com/massivecraft/factions/engine/EnginePlayerDamage.java @@ -0,0 +1,83 @@ +package com.massivecraft.factions.engine; + +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.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; +import org.bukkit.event.entity.EntityDamageEvent; +import java.util.HashMap; + +public class EnginePlayerDamage extends Engine +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EnginePlayerDamage i = new EnginePlayerDamage(); + public static EnginePlayerDamage get() { return i; } + public HashMap coolDownTp = new HashMap(); + + // -------------------------------------------- // + // MANAGE PLAYER DAMAGE / IMMORTAL FLAG + // -------------------------------------------- // + + // @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + @EventHandler(priority = EventPriority.HIGHEST) + public void onEntityDamaged(EntityDamageEvent event) + { + if (!(event.getEntity() instanceof Player)) + { + return; + } + + // If a player receive some damage... + Player player = (Player)event.getEntity(); + + //PS playerPs = PS.valueOf(player.getLocation()); + Faction psFaction = BoardColl.get().getFactionAt(PS.valueOf(player.getLocation())); + + // Bukkit.getServer().getLogger().warning("Damage on Player : " + player.getName() + ": [" + psFaction.getName() + "]"); + + // Are we Immortal ? + if (psFaction.getFlag(MFlag.getFlagImmortal()) == true) + { + // Bukkit.getServer().getLogger().warning("Damage on Player " + player.getName() + ": " + event.getCause() + "=> Immortal !"); + // Bukkit.getServer().getLogger().warning("Loc: " + player.getLocation()); + + event.setCancelled(true); + + if ( event.getCause() == EntityDamageEvent.DamageCause.VOID) + { + // TP CoolDown? + if ( (coolDownTp.get(player.getEntityId()) == null) || ( ( System.nanoTime() - coolDownTp.get(player.getEntityId())) > 500000000)) + { + if( coolDownTp.get(player.getEntityId()) != null) + { + coolDownTp.remove(player.getEntityId()); + } + + coolDownTp.put(player.getEntityId(), System.nanoTime()); + + // Bukkit.getServer().getLogger().warning("Respawning to: " + player.getWorld().getSpawnLocation() + " @" + System.nanoTime() + "!"); + player.teleport(player.getWorld().getSpawnLocation()); + } + else + { + // Bukkit.getServer().getLogger().warning("Respawning Cooldown :" + System.nanoTime() + "!"); + } + } + } + else + { + // Bukkit.getServer().getLogger().warning("Damage on Player " + player.getName() + ": " + event.getCause() + "=> Mortal !"); + } + } +} diff --git a/src/com/massivecraft/factions/entity/MFlag.java b/src/com/massivecraft/factions/entity/MFlag.java index 4e631c88..9d974e9a 100644 --- a/src/com/massivecraft/factions/entity/MFlag.java +++ b/src/com/massivecraft/factions/entity/MFlag.java @@ -37,6 +37,7 @@ public class MFlag extends Entity implements Prioritized, Registerable, N public final static transient String ID_INFPOWER = "infpower"; public final static transient String ID_FLY = "fly"; public final static transient String ID_TAXKICK = "taxkick"; + public final static transient String ID_IMMORTAL = "immortal"; public final static transient int PRIORITY_OPEN = 1_000; public final static transient int PRIORITY_MONSTERS = 2_000; @@ -55,6 +56,7 @@ public class MFlag extends Entity implements Prioritized, Registerable, N public final static transient int PRIORITY_INFPOWER = 15_000; public final static transient int PRIORITY_FLY = 16_000; public final static transient int PRIORITY_TAXKICK = 17_000; + public final static transient int PRIORITY_IMMORTAL = 18_000; // -------------------------------------------- // // META: CORE @@ -96,6 +98,7 @@ public class MFlag extends Entity implements Prioritized, Registerable, N getFlagInfpower(); getFlagFly(); getFlagTaxKick(); + getFlagImmortal(); } public static MFlag getFlagOpen() { return getCreative(PRIORITY_OPEN, ID_OPEN, ID_OPEN, "Can the faction be joined without an invite?", "Anyone can join. No invite required.", "An invite is required to join.", false, true, true); } @@ -115,6 +118,7 @@ public class MFlag extends Entity implements Prioritized, Registerable, N 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 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); } public static MFlag getCreative(int priority, String id, String name, String desc, String descYes, String descNo, boolean standard, boolean editable, boolean visible) {