From 4a66c2fe476bcf67a95476bddf84b67ad79cfe44 Mon Sep 17 00:00:00 2001 From: Magnus Ulf Date: Mon, 20 May 2019 17:44:52 +0200 Subject: [PATCH] Cleanup --- src/com/massivecraft/factions/Factions.java | 2 - .../adapter/TerritoryAccessAdapter.java | 8 +-- .../factions/cmd/type/TypeRel.java | 2 +- .../engine/EngineCanCombatHappen.java | 32 +++++++++ .../massivecraft/factions/entity/MConf.java | 1 - .../factions/integration/V19/EngineV19.java | 67 ------------------- .../integration/V19/IntegrationV19.java | 31 --------- .../factions/task/TaskPlayerPowerUpdate.java | 2 +- 8 files changed, 36 insertions(+), 109 deletions(-) delete mode 100644 src/com/massivecraft/factions/integration/V19/EngineV19.java delete mode 100644 src/com/massivecraft/factions/integration/V19/IntegrationV19.java diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index d697bfcd..9990ac71 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -66,7 +66,6 @@ import com.massivecraft.factions.entity.migrator.MigratorMPlayer001Ranks; import com.massivecraft.factions.entity.migrator.MigratorMPlayer002UsingAdminMode; import com.massivecraft.factions.entity.migrator.MigratorTerritoryAccess001Restructure; import com.massivecraft.factions.event.EventFactionsChunkChangeType; -import com.massivecraft.factions.integration.V19.IntegrationV19; import com.massivecraft.factions.integration.lwc.IntegrationLwc; import com.massivecraft.factions.integration.placeholderapi.IntegrationPlaceholderAPI; import com.massivecraft.factions.integration.venturechat.IntegrationVentureChat; @@ -195,7 +194,6 @@ public class Factions extends MassivePlugin return MUtil.list( IntegrationPlaceholderAPI.class, IntegrationVentureChat.class, - IntegrationV19.class, IntegrationLwc.class, IntegrationWorldGuard.class ); diff --git a/src/com/massivecraft/factions/adapter/TerritoryAccessAdapter.java b/src/com/massivecraft/factions/adapter/TerritoryAccessAdapter.java index 8a4d2354..623a9e20 100644 --- a/src/com/massivecraft/factions/adapter/TerritoryAccessAdapter.java +++ b/src/com/massivecraft/factions/adapter/TerritoryAccessAdapter.java @@ -25,8 +25,6 @@ public class TerritoryAccessAdapter implements JsonDeserializer public static final String HOST_FACTION_ID = "hostFactionId"; public static final String HOST_FACTION_ALLOWED = "hostFactionAllowed"; - /*public static final String FACTION_IDS = "factionIds"; - public static final String PLAYER_IDS = "playerIds";*/ public static final String GRANTED_IDS = "grantedIds"; public static final Type SET_OF_STRING_TYPE = new TypeToken>(){}.getType(); @@ -63,12 +61,10 @@ public class TerritoryAccessAdapter implements JsonDeserializer // Read variables (test old values first) JsonElement element = null; - element = obj.get("ID"); - if (element == null) element = obj.get(HOST_FACTION_ID); + element = obj.get(HOST_FACTION_ID); hostFactionId = element.getAsString(); - element = obj.get("open"); - if (element == null) element = obj.get(HOST_FACTION_ALLOWED); + element = obj.get(HOST_FACTION_ALLOWED); if (element != null) hostFactionAllowed = element.getAsBoolean(); element = obj.get(GRANTED_IDS); diff --git a/src/com/massivecraft/factions/cmd/type/TypeRel.java b/src/com/massivecraft/factions/cmd/type/TypeRel.java index 731b50f7..7ad6c3bd 100644 --- a/src/com/massivecraft/factions/cmd/type/TypeRel.java +++ b/src/com/massivecraft/factions/cmd/type/TypeRel.java @@ -22,7 +22,7 @@ public class TypeRel extends TypeEnum @Override public String getName() { - return "role"; + return "relation"; } @Override diff --git a/src/com/massivecraft/factions/engine/EngineCanCombatHappen.java b/src/com/massivecraft/factions/engine/EngineCanCombatHappen.java index 0c19357b..02a18b84 100644 --- a/src/com/massivecraft/factions/engine/EngineCanCombatHappen.java +++ b/src/com/massivecraft/factions/engine/EngineCanCombatHappen.java @@ -17,12 +17,16 @@ import org.bukkit.entity.Player; import org.bukkit.entity.Trident; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.AreaEffectCloudApplyEvent; import org.bukkit.event.entity.EntityCombustByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.PotionSplashEvent; import org.bukkit.projectiles.ProjectileSource; +import java.util.ArrayList; +import java.util.List; + public class EngineCanCombatHappen extends Engine { // -------------------------------------------- // @@ -82,6 +86,34 @@ public class EngineCanCombatHappen extends Engine } } + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void canCombatDamageHappen(AreaEffectCloudApplyEvent event) + { + // If a harmful potion effect cloud is present ... + if ( ! MUtil.isHarmfulPotion(event.getEntity().getBasePotionData().getType().getEffectType())) return; + + ProjectileSource projectileSource = event.getEntity().getSource(); + if ( ! (projectileSource instanceof Entity)) return; + + Entity thrower = (Entity)projectileSource; + + // ... create a dummy list to avoid ConcurrentModificationException ... + List affectedList = new ArrayList<>(); + + // ... then scan through affected entities to make sure they're all valid targets ... + for (LivingEntity affectedEntity : event.getAffectedEntities()) + { + EntityDamageByEntityEvent sub = new EntityDamageByEntityEvent(thrower, affectedEntity, EntityDamageEvent.DamageCause.CUSTOM, 0D); + // Notification disabled due to the iterating nature of effect clouds. + if (EngineCanCombatHappen.get().canCombatDamageHappen(sub, false)) continue; + + affectedList.add(affectedEntity); + } + + // finally, remove valid targets from the affected list. (Unlike splash potions, area effect cloud's affected entities list is mutable.) + event.getAffectedEntities().removeAll(affectedList); + } + // Utility method used in "canCombatDamageHappen" below. public static boolean falseUnlessDisallowedPvpEventCancelled(Player attacker, Player defender, DisallowCause reason, EntityDamageByEntityEvent event) { diff --git a/src/com/massivecraft/factions/entity/MConf.java b/src/com/massivecraft/factions/entity/MConf.java index da2eae39..583c45f4 100644 --- a/src/com/massivecraft/factions/entity/MConf.java +++ b/src/com/massivecraft/factions/entity/MConf.java @@ -95,7 +95,6 @@ public class MConf extends Entity // -------------------------------------------- // // Define the time in minutes between certain Factions system tasks is ran. - public double taskPlayerPowerUpdateMinutes = 1; public double taskEconLandRewardMinutes = 20; // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/integration/V19/EngineV19.java b/src/com/massivecraft/factions/integration/V19/EngineV19.java deleted file mode 100644 index 6b273a5a..00000000 --- a/src/com/massivecraft/factions/integration/V19/EngineV19.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.massivecraft.factions.integration.V19; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.engine.EngineCanCombatHappen; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.MassivePlugin; -import com.massivecraft.massivecore.util.MUtil; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.entity.AreaEffectCloudApplyEvent; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.projectiles.ProjectileSource; - -import java.util.ArrayList; -import java.util.List; - -public class EngineV19 extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineV19 i = new EngineV19 (); - public static EngineV19 get() { return i; } - - @Override - public MassivePlugin getActivePlugin() - { - return Factions.get(); - } - - // -------------------------------------------- // - // LISTENER - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void canCombatDamageHappen(AreaEffectCloudApplyEvent event) - { - // If a harmful potion effect cloud is present ... - if ( ! MUtil.isHarmfulPotion(event.getEntity().getBasePotionData().getType().getEffectType())) return; - - ProjectileSource projectileSource = event.getEntity().getSource(); - if ( ! (projectileSource instanceof Entity)) return; - - Entity thrower = (Entity)projectileSource; - - // ... create a dummy list to avoid ConcurrentModificationException ... - List affectedList = new ArrayList<>(); - - // ... then scan through affected entities to make sure they're all valid targets ... - for (LivingEntity affectedEntity : event.getAffectedEntities()) - { - EntityDamageByEntityEvent sub = new EntityDamageByEntityEvent(thrower, affectedEntity, EntityDamageEvent.DamageCause.CUSTOM, 0D); - // Notification disabled due to the iterating nature of effect clouds. - if (EngineCanCombatHappen.get().canCombatDamageHappen(sub, false)) continue; - - affectedList.add(affectedEntity); - } - - // finally, remove valid targets from the affected list. (Unlike splash potions, area effect cloud's affected entities list is mutable.) - event.getAffectedEntities().removeAll(affectedList); - } - -} diff --git a/src/com/massivecraft/factions/integration/V19/IntegrationV19.java b/src/com/massivecraft/factions/integration/V19/IntegrationV19.java deleted file mode 100644 index c7c398e6..00000000 --- a/src/com/massivecraft/factions/integration/V19/IntegrationV19.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.massivecraft.factions.integration.V19; - -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.Integration; - -public class IntegrationV19 extends Integration -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static IntegrationV19 i = new IntegrationV19(); - public static IntegrationV19 get() { return i; } - private IntegrationV19() - { - this.setClassNames( - "org.bukkit.event.entity.AreaEffectCloudApplyEvent" - ); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public Engine getEngine() - { - return EngineV19.get(); - } - -} diff --git a/src/com/massivecraft/factions/task/TaskPlayerPowerUpdate.java b/src/com/massivecraft/factions/task/TaskPlayerPowerUpdate.java index b00fcd62..379cad88 100644 --- a/src/com/massivecraft/factions/task/TaskPlayerPowerUpdate.java +++ b/src/com/massivecraft/factions/task/TaskPlayerPowerUpdate.java @@ -31,7 +31,7 @@ public class TaskPlayerPowerUpdate extends ModuloRepeatTask public long getDelayMillis() { // The interval is determined by the MConf rather than being set with setDelayMillis. - return (long) (MConf.get().taskPlayerPowerUpdateMinutes * TimeUnit.MILLIS_PER_MINUTE); + return TimeUnit.MILLIS_PER_MINUTE; } @Override