This repository has been archived by the owner on Jan 31, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Commit or not commit, that is the question.
- Loading branch information
Showing
8 changed files
with
623 additions
and
118 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
src/fr/syst3ms/quarsk/expressions/potion/SExprThrownPotionEffects.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters