Allow projectiles to apply kits when they hit players
This commit is contained in:
parent
ae8a175eaa
commit
bcc44fadc6
|
@ -9,6 +9,7 @@ import java.time.Duration;
|
|||
import tc.oc.pgm.features.FeatureDefinition;
|
||||
import tc.oc.pgm.features.FeatureInfo;
|
||||
import tc.oc.pgm.filters.Filter;
|
||||
import tc.oc.pgm.kits.Kit;
|
||||
|
||||
@FeatureInfo(name = "projectile")
|
||||
public interface ProjectileDefinition extends FeatureDefinition {
|
||||
|
@ -30,6 +31,8 @@ public interface ProjectileDefinition extends FeatureDefinition {
|
|||
Duration cooldown();
|
||||
|
||||
boolean throwable();
|
||||
|
||||
Kit kit();
|
||||
}
|
||||
|
||||
class ProjectileDefinitionImpl extends FeatureDefinition.Impl implements ProjectileDefinition {
|
||||
|
@ -42,6 +45,7 @@ class ProjectileDefinitionImpl extends FeatureDefinition.Impl implements Project
|
|||
private @Inspect Filter destroyFilter;
|
||||
private @Inspect Duration coolDown;
|
||||
private @Inspect boolean throwable;
|
||||
private @Inspect Kit kit;
|
||||
|
||||
public ProjectileDefinitionImpl(@Nullable String name,
|
||||
@Nullable Double damage,
|
||||
|
@ -51,7 +55,8 @@ class ProjectileDefinitionImpl extends FeatureDefinition.Impl implements Project
|
|||
List<PotionEffect> potion,
|
||||
Filter destroyFilter,
|
||||
Duration coolDown,
|
||||
boolean throwable) {
|
||||
boolean throwable,
|
||||
Kit kit) {
|
||||
this.name = name;
|
||||
this.damage = damage;
|
||||
this.velocity = velocity;
|
||||
|
@ -61,6 +66,7 @@ class ProjectileDefinitionImpl extends FeatureDefinition.Impl implements Project
|
|||
this.destroyFilter = destroyFilter;
|
||||
this.coolDown = coolDown;
|
||||
this.throwable = throwable;
|
||||
this.kit = kit;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -108,4 +114,9 @@ class ProjectileDefinitionImpl extends FeatureDefinition.Impl implements Project
|
|||
public boolean throwable() {
|
||||
return throwable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kit kit() {
|
||||
return kit;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,12 @@ public class ProjectileMatchModule extends MatchModule implements Listener {
|
|||
if(projectileDefinition.damage() != null) {
|
||||
event.setDamage(projectileDefinition.damage());
|
||||
}
|
||||
|
||||
if (projectileDefinition.kit() != null) {
|
||||
if (event.getEntity() instanceof Player) {
|
||||
projectileDefinition.kit().apply(match.getPlayer((Player)event.getEntity()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
|
|
@ -13,6 +13,8 @@ import java.time.Duration;
|
|||
import tc.oc.pgm.filters.Filter;
|
||||
import tc.oc.pgm.filters.parser.FilterParser;
|
||||
import tc.oc.pgm.kits.ItemParser;
|
||||
import tc.oc.pgm.kits.Kit;
|
||||
import tc.oc.pgm.kits.KitParser;
|
||||
import tc.oc.pgm.map.MapModule;
|
||||
import tc.oc.pgm.map.MapModuleContext;
|
||||
import tc.oc.pgm.map.MapModuleFactory;
|
||||
|
@ -28,6 +30,7 @@ public class ProjectileModule implements MapModule {
|
|||
public @Nullable ProjectileModule parse(MapModuleContext context, Logger logger, Document doc) throws InvalidXMLException {
|
||||
final ItemParser itemParser = context.needModule(ItemParser.class);
|
||||
FilterParser filterParser = context.needModule(FilterParser.class);
|
||||
KitParser kitParser = context.needModule(KitParser.class);
|
||||
|
||||
for(Element projectileElement : XMLUtils.flattenElements(doc.getRootElement(), "projectiles", "projectile")) {
|
||||
String name = projectileElement.getAttributeValue("name");
|
||||
|
@ -39,8 +42,9 @@ public class ProjectileModule implements MapModule {
|
|||
Filter destroyFilter = filterParser.parseOptionalProperty(projectileElement, "destroy-filter").orElse(null);
|
||||
Duration coolDown = XMLUtils.parseDuration(projectileElement.getAttribute("cooldown"));
|
||||
boolean throwable = XMLUtils.parseBoolean(projectileElement.getAttribute("throwable"), true);
|
||||
Kit kit = kitParser.parseOptionalProperty(projectileElement, "kit").orElse(null);
|
||||
|
||||
context.features().define(projectileElement, new ProjectileDefinitionImpl(name, damage, velocity, clickAction, entity, potionKit, destroyFilter, coolDown, throwable));
|
||||
context.features().define(projectileElement, new ProjectileDefinitionImpl(name, damage, velocity, clickAction, entity, potionKit, destroyFilter, coolDown, throwable, kit));
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
Loading…
Reference in New Issue