Skip to content
This repository has been archived by the owner on Jan 31, 2018. It is now read-only.

Commit

Permalink
Commit or not commit, that is the question.
Browse files Browse the repository at this point in the history
  • Loading branch information
Syst3ms committed Jan 30, 2017
1 parent 1779d29 commit 06920b1
Show file tree
Hide file tree
Showing 8 changed files with 623 additions and 118 deletions.
520 changes: 409 additions & 111 deletions .idea/workspace.xml

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/fr/syst3ms/quarsk/QuarSk.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import ch.njol.skript.lang.*;
import ch.njol.skript.registrations.Classes;
import ch.njol.skript.util.Color;
import ch.njol.skript.util.PotionEffectUtils;
import ch.njol.skript.util.Timespan;
import com.sun.istack.internal.Nullable;
import fr.syst3ms.quarsk.classes.EnumType;
import fr.syst3ms.quarsk.conditions.CondHasPotionEffect;
import fr.syst3ms.quarsk.conditions.CondIsWallBanner;
import fr.syst3ms.quarsk.effects.EffLinkReference;
import fr.syst3ms.quarsk.effects.EffOrientTowards;
import fr.syst3ms.quarsk.effects.EffUnlinkReference;
Expand Down Expand Up @@ -79,7 +81,7 @@ public PotionEffect parse(String obj, ParseContext context) {

@Override
public String toString(PotionEffect potionEffect, int i) {
return "effect" + potionEffect.getType() + ", tier " + potionEffect.getAmplifier() + ", duration " + potionEffect.getDuration() + ", particles " + potionEffect.hasParticles() + ", ambient " + potionEffect.isAmbient() + ", color " + potionEffect.getColor();
return PotionEffectUtils.toString(potionEffect.getType()) + " of tier " + potionEffect.getAmplifier() + " lasting " + potionEffect.getDuration() + " with particles " + (potionEffect.hasParticles() ? "enabled" : "disabled") + ", ambient effect " + (potionEffect.isAmbient() ? "enabled" : "disabled");
}

@Override
Expand Down Expand Up @@ -138,6 +140,7 @@ public String getVariableNamePattern() {
*/
//Potions
newCondition(CondHasPotionEffect.class, "[entity] %livingentity% (0¦has [got]|1¦has( not|n't) [got]) [(the|a)] %potioneffecttype% [potion] effect");
newCondition(CondIsWallBanner.class, "[banner] [block] %block% (0¦is|1¦is(n't| not)) [a] wall banner");
/*
* EXPRESSIONS
*/
Expand All @@ -153,6 +156,7 @@ public String getVariableNamePattern() {
newExpression(ExprPotionEffectTier.class, Number.class, ExpressionType.COMBINED, "(tier|amplifier) of [potion] [effect] %potioneffect%", "[potion] [effect] %potioneffect%['s] (tier|amplifier)");
newExpression(SExprItemEffectTypeAmplifier.class, Number.class, ExpressionType.COMBINED, "(tier|amplifier) of [[potion] effect [type]] %potioneffecttype% on [item] %itemstack%", "[[potion] effect [type]] %potioneffecttype%['s] (tier|amplifier) on [item] %itemstack%");
newExpression(SExprItemEffectTypeDuration.class, Timespan.class, ExpressionType.COMBINED, "(duration|length) of [[potion] effect [type]] %potioneffecttype% on [item] %itemstack%", "[[potion] effect [type]] %potioneffecttype%['s] (duration|length) on [item] %itemstack%");
newExpression(SExprThrownPotionEffects.class, PotionEffect.class, ExpressionType.COMBINED, "[all] [potion] effects (of|on) (entity|thrown potion|tipped arrow) %entity%");
//Beacons
newExpression(ExprEntitiesInRange.class, LivingEntity.class, ExpressionType.COMBINED, "[(all|every|each)] ([living] entit(ies|y)|player[s]) in range of %block%");
newExpression(ExprBeaconTier.class, Number.class, ExpressionType.COMBINED, "beacon (tier|level) of %block%", "%block%['s] beacon (tier|level)");
Expand Down
11 changes: 7 additions & 4 deletions src/fr/syst3ms/quarsk/conditions/CondHasPotionEffect.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
/**
* Created by ARTHUR on 12/01/2017.
*/
@SuppressWarnings({"unused", "unchecked"})
public class CondHasPotionEffect extends Condition {
private Expression<LivingEntity> entity;
private Expression<PotionEffectType> type;
Expand All @@ -19,16 +20,18 @@ public class CondHasPotionEffect extends Condition {
public boolean init(Expression<?>[] expr, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) {
entity = (Expression<LivingEntity>) expr[0];
type = (Expression<PotionEffectType>) expr[1];
setNegated(parseResult.mark == 1);
return true;
}

@Override
public boolean check(Event e) {
if (entity.getSingle(e) != null && type.getSingle(e) != null) {
return (entity.getSingle(e).hasPotionEffect(type.getSingle(e)));
} else {
return false;
if (entity != null && type != null) {
if (entity.getSingle(e) != null && type.getSingle(e) != null) {
return isNegated() != entity.getSingle(e).hasPotionEffect(type.getSingle(e));
}
}
return false;
}

@Override
Expand Down
45 changes: 45 additions & 0 deletions src/fr/syst3ms/quarsk/conditions/CondIsWallBanner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package fr.syst3ms.quarsk.conditions;

import ch.njol.skript.lang.Condition;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.util.Kleenean;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.event.Event;
import org.bukkit.material.Banner;

import java.util.Comparator;

/**
* Created by PRODSEB on 30/01/2017.
*/
@SuppressWarnings({"unused", "unchecked"})
public class CondIsWallBanner extends Condition {
private Expression<Block> block;

@Override
public boolean init(Expression<?>[] expr, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) {
block = (Expression<Block>) expr[0];
setNegated(parseResult.mark == 1);
return true;
}

@Override
public boolean check(Event e) {
if (block != null) {
if (block.getSingle(e) != null) {
if (block.getSingle(e).getType() == Material.STANDING_BANNER || block.getSingle(e).getType() == Material.WALL_BANNER) {
Banner banner = (Banner) block.getSingle(e).getState();
return isNegated() != banner.isWallBanner();
}
}
}
return false;
}

@Override
public String toString(Event event, boolean b) {
return getClass().getName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public boolean init(Expression<?>[] expr, int i, Kleenean kleenean, SkriptParser
protected Color[] get(Event e) {
if (block != null) {
if (block.getSingle(e) != null) {
if (block.getSingle(e).getType() == Material.BANNER) {
if (block.getSingle(e).getType() == Material.STANDING_BANNER || block.getSingle(e).getType() == Material.WALL_BANNER) {
Banner banner = ((Banner) block.getSingle(e).getState());
return new Color[]{Color.byWoolColor(banner.getBaseColor())};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public boolean init(Expression<?>[] expr, int i, Kleenean kleenean, SkriptParser
protected Pattern[] get(Event e) {
if (block != null) {
if (block.getSingle(e) != null) {
if (block.getSingle(e).getType() == Material.BANNER) {
if (block.getSingle(e).getType() == Material.STANDING_BANNER || block.getSingle(e).getType() == Material.WALL_BANNER) {
Banner banner = ((Banner) block.getSingle(e).getState());
return banner.getPatterns().toArray(new Pattern[banner.getPatterns().size()]);
}
Expand Down
137 changes: 137 additions & 0 deletions src/fr/syst3ms/quarsk/expressions/potion/SExprThrownPotionEffects.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package fr.syst3ms.quarsk.expressions.potion;

import ch.njol.skript.classes.Changer;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils;
import fr.syst3ms.quarsk.util.PotionUtils;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ThrownPotion;
import org.bukkit.entity.TippedArrow;
import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

/**
* Created by PRODSEB on 29/01/2017.
*/
@SuppressWarnings({"unused", "unchecked"})
public class SExprThrownPotionEffects extends SimpleExpression<PotionEffect> {
private Expression<Entity> entity;

@Override
public boolean init(Expression<?>[] expr, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) {
entity = (Expression<Entity>) expr[0];
return true;
}

@Override
protected PotionEffect[] get(Event e) {
if (entity != null) {
if (entity.getSingle(e) != null) {
if (PotionUtils.getInstance().isEntityThrownPotion(entity.getSingle(e))) {
ThrownPotion thrownPotion = ((ThrownPotion) entity.getSingle(e));
return thrownPotion.getEffects().toArray(new PotionEffect[thrownPotion.getEffects().size()]);
} else if (entity.getSingle(e).getType() == EntityType.TIPPED_ARROW) {
TippedArrow tippedArrow = ((TippedArrow) entity.getSingle(e));
return tippedArrow.getCustomEffects().toArray(new PotionEffect[tippedArrow.getCustomEffects().size()]);
}
}
}
return null;
}

@Override
public void change(Event e, Object[] delta, Changer.ChangeMode mode) {
if (entity != null) {
if (PotionUtils.getInstance().isEntityThrownPotion(entity.getSingle(e))) {
ItemStack item = ((ThrownPotion) entity.getSingle(e)).getItem();
PotionMeta potionMeta = ((PotionMeta) ((ThrownPotion) entity.getSingle(e)).getItem().getItemMeta());
switch (mode) {
case ADD:
if (delta[0] instanceof PotionEffect) {
for (PotionEffect effect : (PotionEffect[]) delta) {
potionMeta.addCustomEffect(effect, true);
}
}
break;
case SET:
if (delta[0] instanceof PotionEffect) {
potionMeta.clearCustomEffects();
for (PotionEffect effect : (PotionEffect[]) delta) {
potionMeta.addCustomEffect(effect, true);
}
}
break;
case REMOVE:
if (delta[0] instanceof PotionEffectType) {
potionMeta.removeCustomEffect((PotionEffectType) delta[0]);
}
break;
case DELETE:
potionMeta.clearCustomEffects();
break;
}
item.setItemMeta(potionMeta);
((ThrownPotion) entity.getSingle(e)).setItem(item);
} else if (entity.getSingle(e).getType() == EntityType.TIPPED_ARROW) {
TippedArrow tippedArrow = (TippedArrow) entity.getSingle(e);
switch (mode) {
case ADD:
if (delta[0] instanceof PotionEffect) {
for (PotionEffect effect : (PotionEffect[]) delta) {
tippedArrow.addCustomEffect(effect, true);
}
}
break;
case SET:
if (delta[0] instanceof PotionEffect) {
tippedArrow.clearCustomEffects();
for (PotionEffect effect : (PotionEffect[]) delta) {
tippedArrow.addCustomEffect(effect, true);
}
}
break;
case REMOVE:
if (delta[0] instanceof PotionEffectType) {
tippedArrow.removeCustomEffect((PotionEffectType) delta[0]);
}
break;
case DELETE:
tippedArrow.clearCustomEffects();
break;
}
}
}
}

@Override
public Class<?>[] acceptChange(Changer.ChangeMode mode) {
if (mode == Changer.ChangeMode.REMOVE) {
return CollectionUtils.array(PotionEffectType.class);
} else if (mode != Changer.ChangeMode.RESET) {
return CollectionUtils.array(PotionEffect[].class);
}
return null;
}

@Override
public Class<? extends PotionEffect> getReturnType() {
return PotionEffect.class;
}

@Override
public boolean isSingle() {
return false;
}

@Override
public String toString(Event event, boolean b) {
return getClass().getName();
}
}
18 changes: 18 additions & 0 deletions src/fr/syst3ms/quarsk/util/PotionUtils.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
package fr.syst3ms.quarsk.util;

import com.sun.istack.internal.NotNull;
import jdk.nashorn.internal.runtime.regexp.joni.constants.EncloseType;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BannerMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* Created by PRODSEB on 27/01/2017.
Expand Down Expand Up @@ -82,4 +91,13 @@ public PotionEffect fromPotionData(PotionData data) {
public PotionData emptyPotionData() {
return new PotionData(PotionType.WATER);
}

public boolean isEntityThrownPotion(Entity entity) {
return entity.getType() == EntityType.SPLASH_POTION || entity.getType() == EntityType.LINGERING_POTION;
}

public PotionMeta emptyPotionMeta() {
ItemStack item = new ItemStack(Material.POTION);
return (PotionMeta) item.getItemMeta();
}
}

0 comments on commit 06920b1

Please sign in to comment.