Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //PACKAGE
- import org.bukkit.event.Event;
- import org.bukkit.entity.Player;
- import ch.njol.skript.classes.Changer;
- import ch.njol.skript.classes.Changer.ChangeMode;
- import ch.njol.skript.lang.Expression;
- import ch.njol.skript.lang.SkriptParser.ParseResult;
- import ch.njol.skript.lang.util.SimpleExpression;
- import ch.njol.util.Kleenean;
- import ch.njol.util.coll.CollectionUtils;
- public class ExprSaturation extends SimpleExpression<Float>{
- private Expression<Player> player;
- @Override
- public Class<? extends Float> getReturnType() {
- // TODO Auto-generated method stub
- return Float.class;
- }
- @Override
- public boolean isSingle() {
- // TODO Auto-generated method stub
- return true;
- }
- @Override
- public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
- // TODO Auto-generated method stub
- player = (Expression<Player>) expr[0];
- return true;
- }
- @Override
- public String toString(Event arg0, boolean arg1) {
- // TODO Auto-generated method stub
- return "saturation of player";
- }
- @Override
- protected Float[] get(Event arg0) {
- // TODO Auto-generated method stub
- return new Float[]{player.getSingle(arg0).getSaturation()};
- }
- public void change(Event e, Object[] d, Changer.ChangeMode mode){
- Player p = player.getSingle(e);
- if (mode == ChangeMode.SET){
- p.setSaturation((Float)d[0]);
- }
- else if (mode == ChangeMode.ADD){
- p.setSaturation(p.getSaturation() + (Float)d[0]);
- }
- else if (mode == ChangeMode.RESET){
- p.setSaturation(20f);
- }
- }
- public Class<?>[] acceptChange(final Changer.ChangeMode mode){
- if (mode == ChangeMode.SET || mode == ChangeMode.ADD || mode == ChangeMode.RESET){
- return CollectionUtils.array(Float.class);
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement