Fix entity mutation collisions
This commit is contained in:
parent
714eaaff6d
commit
ed9d488b75
|
@ -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<E extends Entity> extends KitMutation {
|
||||
|
||||
final Class<E> type;
|
||||
final Set<E> entities;
|
||||
final Map<Instant, Set<E>> entitiesByTime;
|
||||
final Map<MatchPlayer, Set<E>> entitiesByPlayer;
|
||||
final Map<E, MatchPlayer> playersByEntity;
|
||||
|
||||
public EntityMutation(Match match, boolean force) {
|
||||
public EntityMutation(Match match, Class<E> 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<E extends Entity> extends KitMutation {
|
|||
@EventHandler(ignoreCancelled = false, priority = EventPriority.HIGHEST)
|
||||
public void onPlayerSpawnEntity(PlayerSpawnEntityEvent event) {
|
||||
match().participant(event.getPlayer())
|
||||
.ifPresent(player -> cast(event.getEntity(), new TypeToken<E>(){}.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<E extends Entity> extends KitMutation {
|
|||
boolean allowed = allowed(event.getSpawnReason());
|
||||
event.setCancelled(!allowed);
|
||||
if(allowed) {
|
||||
cast(event.getEntity(), new TypeToken<E>(){}.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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,13 +18,13 @@ import java.util.List;
|
|||
public class BreadMutation extends KitMutation {
|
||||
|
||||
final static ImmutableMap<FreeItemKit, Integer> BREADS_MAP = new ImmutableMap.Builder<FreeItemKit, Integer>()
|
||||
.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)
|
||||
|
|
|
@ -49,7 +49,7 @@ public class EquestrianMutation extends EntityMutation<AbstractHorse> {
|
|||
final static WeightedRandomChooser<Material, Integer> ARMOR = new ImmutableWeightedRandomChooser<>(ARMOR_MAP);
|
||||
|
||||
public EquestrianMutation(Match match) {
|
||||
super(match, false);
|
||||
super(match, AbstractHorse.class, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -38,7 +38,7 @@ public class MobsMutation extends EntityMutation<LivingEntity> {
|
|||
final static Range<Integer> AMOUNT = Range.closed(1, 3);
|
||||
|
||||
public MobsMutation(Match match) {
|
||||
super(match, false);
|
||||
super(match, LivingEntity.class, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -116,7 +116,7 @@ public class ApocalypseMutation extends EntityMutation<LivingEntity> 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ public class BomberMutation extends EntityMutation<TNTPrimed> implements TargetM
|
|||
Instant next;
|
||||
|
||||
public BomberMutation(Match match) {
|
||||
super(match, false);
|
||||
super(match, TNTPrimed.class, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue