From ed9d488b7511c3f2febba3d2d2d9a4ab28ffa22b Mon Sep 17 00:00:00 2001 From: Electroid Date: Tue, 6 Jun 2017 01:19:12 -0700 Subject: [PATCH] Fix entity mutation collisions --- .../tc/oc/pgm/mutation/types/EntityMutation.java | 15 ++++++++------- .../oc/pgm/mutation/types/kit/BreadMutation.java | 14 +++++++------- .../mutation/types/kit/EquestrianMutation.java | 2 +- .../oc/pgm/mutation/types/kit/MobsMutation.java | 2 +- .../types/targetable/ApocalypseMutation.java | 2 +- .../mutation/types/targetable/BomberMutation.java | 2 +- 6 files changed, 19 insertions(+), 18 deletions(-) diff --git a/PGM/src/main/java/tc/oc/pgm/mutation/types/EntityMutation.java b/PGM/src/main/java/tc/oc/pgm/mutation/types/EntityMutation.java index 19e534c..6f13e63 100644 --- a/PGM/src/main/java/tc/oc/pgm/mutation/types/EntityMutation.java +++ b/PGM/src/main/java/tc/oc/pgm/mutation/types/EntityMutation.java @@ -3,7 +3,6 @@ package tc.oc.pgm.mutation.types; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.google.gson.reflect.TypeToken; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; @@ -35,13 +34,15 @@ import static tc.oc.commons.core.util.Optionals.cast; */ public class EntityMutation extends KitMutation { + final Class type; final Set entities; final Map> entitiesByTime; final Map> entitiesByPlayer; final Map playersByEntity; - public EntityMutation(Match match, boolean force) { + public EntityMutation(Match match, Class type, boolean force) { super(match, force); + this.type = type; this.entities = new WeakHashSet<>(); this.entitiesByTime = new WeakHashMap<>(); this.entitiesByPlayer = new WeakHashMap<>(); @@ -195,9 +196,9 @@ public class EntityMutation extends KitMutation { @EventHandler(ignoreCancelled = false, priority = EventPriority.HIGHEST) public void onPlayerSpawnEntity(PlayerSpawnEntityEvent event) { match().participant(event.getPlayer()) - .ifPresent(player -> cast(event.getEntity(), new TypeToken(){}.getRawType()) + .ifPresent(player -> cast(event.getEntity(), type) .ifPresent(entity -> { - register((E) entity, player); + register(entity, player); event.setCancelled(false); })); } @@ -207,9 +208,9 @@ public class EntityMutation extends KitMutation { boolean allowed = allowed(event.getSpawnReason()); event.setCancelled(!allowed); if(allowed) { - cast(event.getEntity(), new TypeToken(){}.getRawType()) - .filter(entity -> !playerByEntity((E) entity).isPresent()) - .ifPresent(entity -> register((E) entity, null)); + cast(event.getEntity(), type) + .filter(entity -> !playerByEntity(entity).isPresent()) + .ifPresent(entity -> register(entity, null)); } } diff --git a/PGM/src/main/java/tc/oc/pgm/mutation/types/kit/BreadMutation.java b/PGM/src/main/java/tc/oc/pgm/mutation/types/kit/BreadMutation.java index dbeb114..74c25f1 100644 --- a/PGM/src/main/java/tc/oc/pgm/mutation/types/kit/BreadMutation.java +++ b/PGM/src/main/java/tc/oc/pgm/mutation/types/kit/BreadMutation.java @@ -18,13 +18,13 @@ import java.util.List; public class BreadMutation extends KitMutation { final static ImmutableMap BREADS_MAP = new ImmutableMap.Builder() - .put(new FreeItemKit(new ItemBuilder(item(Material.BREAD)).enchant(Enchantment.FIRE_ASPECT, 1).name("Hot Bread").get()), 15) - .put(new FreeItemKit(new ItemBuilder(item(Material.BREAD)).enchant(Enchantment.DAMAGE_ALL, 3).health(20, EquipmentSlot.HAND).name("Whole Wheat Bread").get()), 10) - .put(new FreeItemKit(new ItemBuilder(item(Material.BREAD)).enchant(Enchantment.KNOCKBACK, 2).name("Bouncy Bread").get()), 10) - .put(new FreeItemKit(new ItemBuilder(item(Material.BREAD)).knockBackRestistance(1, EquipmentSlot.HAND).name("Iron Bread").get()), 5) - .put(new FreeItemKit(new ItemBuilder(item(Material.BREAD)).speed(1,EquipmentSlot.HAND).name("Fast Bread").get()), 5) - .put(new FreeItemKit(new ItemBuilder(item(Material.BREAD)).armor(10,EquipmentSlot.HAND).name("Armored Bread").get()), 5) - .put(new FreeItemKit(new ItemBuilder(item(Material.BREAD)).enchant(Enchantment.DAMAGE_ALL, 10).name("Very Sharp Bread").get()), 3) + .put(new FreeItemKit(new ItemBuilder(item(Material.BREAD)).enchant(Enchantment.FIRE_ASPECT, 1).name("Hot Bread").get()), 30) + .put(new FreeItemKit(new ItemBuilder(item(Material.BREAD)).enchant(Enchantment.DAMAGE_ALL, 5).name("Sharp Bread").get()), 20) + .put(new FreeItemKit(new ItemBuilder(item(Material.BREAD)).enchant(Enchantment.KNOCKBACK, 2).name("Bouncy Bread").get()), 20) + .put(new FreeItemKit(new ItemBuilder(item(Material.BREAD)).knockBackRestistance(1, EquipmentSlot.HAND).name("Iron Bread").get()), 10) + .put(new FreeItemKit(new ItemBuilder(item(Material.BREAD)).speed(1,EquipmentSlot.HAND).name("Fast Bread").get()), 10) + .put(new FreeItemKit(new ItemBuilder(item(Material.BREAD)).armor(10,EquipmentSlot.HAND).name("Armored Bread").get()), 10) + .put(new FreeItemKit(new ItemBuilder(item(Material.BREAD)).enchant(Enchantment.DAMAGE_ALL, 10).name("Very Sharp Bread").get()), 6) .put(new FreeItemKit(new ItemBuilder(item(Material.BREAD)).enchant(Enchantment.FIRE_ASPECT, 10).name("Very Hot Bread").get()), 3) .put(new FreeItemKit(new ItemBuilder(item(Material.BREAD)).enchant(Enchantment.KNOCKBACK, 10).name("Very Bouncy Bread").get()), 2) .put(new FreeItemKit(new ItemBuilder(item(Material.BREAD)).enchant(Enchantment.DAMAGE_ALL, 100).name("Insanely Sharp Bread").get()), 1) diff --git a/PGM/src/main/java/tc/oc/pgm/mutation/types/kit/EquestrianMutation.java b/PGM/src/main/java/tc/oc/pgm/mutation/types/kit/EquestrianMutation.java index 72a782c..7e590a3 100644 --- a/PGM/src/main/java/tc/oc/pgm/mutation/types/kit/EquestrianMutation.java +++ b/PGM/src/main/java/tc/oc/pgm/mutation/types/kit/EquestrianMutation.java @@ -49,7 +49,7 @@ public class EquestrianMutation extends EntityMutation { final static WeightedRandomChooser ARMOR = new ImmutableWeightedRandomChooser<>(ARMOR_MAP); public EquestrianMutation(Match match) { - super(match, false); + super(match, AbstractHorse.class, false); } @Override diff --git a/PGM/src/main/java/tc/oc/pgm/mutation/types/kit/MobsMutation.java b/PGM/src/main/java/tc/oc/pgm/mutation/types/kit/MobsMutation.java index 32c9e24..03f9c18 100644 --- a/PGM/src/main/java/tc/oc/pgm/mutation/types/kit/MobsMutation.java +++ b/PGM/src/main/java/tc/oc/pgm/mutation/types/kit/MobsMutation.java @@ -38,7 +38,7 @@ public class MobsMutation extends EntityMutation { final static Range AMOUNT = Range.closed(1, 3); public MobsMutation(Match match) { - super(match, false); + super(match, LivingEntity.class, false); } @Override diff --git a/PGM/src/main/java/tc/oc/pgm/mutation/types/targetable/ApocalypseMutation.java b/PGM/src/main/java/tc/oc/pgm/mutation/types/targetable/ApocalypseMutation.java index c835cc9..184db55 100644 --- a/PGM/src/main/java/tc/oc/pgm/mutation/types/targetable/ApocalypseMutation.java +++ b/PGM/src/main/java/tc/oc/pgm/mutation/types/targetable/ApocalypseMutation.java @@ -116,7 +116,7 @@ public class ApocalypseMutation extends EntityMutation implements final PointProviderAttributes attributes; // attributes to choosing random points public ApocalypseMutation(Match match) { - super(match, false); + super(match, LivingEntity.class, false); this.attributes = new PointProviderAttributes(null, null, true, false); } diff --git a/PGM/src/main/java/tc/oc/pgm/mutation/types/targetable/BomberMutation.java b/PGM/src/main/java/tc/oc/pgm/mutation/types/targetable/BomberMutation.java index fc5719e..cca527a 100644 --- a/PGM/src/main/java/tc/oc/pgm/mutation/types/targetable/BomberMutation.java +++ b/PGM/src/main/java/tc/oc/pgm/mutation/types/targetable/BomberMutation.java @@ -23,7 +23,7 @@ public class BomberMutation extends EntityMutation implements TargetM Instant next; public BomberMutation(Match match) { - super(match, false); + super(match, TNTPrimed.class, false); } @Override