Advertisement
Gamebuster

ExprSaturation.class

Mar 28th, 2016
441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.75 KB | None | 0 0
  1. //PACKAGE
  2.  
  3. import org.bukkit.event.Event;
  4. import org.bukkit.entity.Player;
  5.  
  6. import ch.njol.skript.classes.Changer;
  7. import ch.njol.skript.classes.Changer.ChangeMode;
  8. import ch.njol.skript.lang.Expression;
  9. import ch.njol.skript.lang.SkriptParser.ParseResult;
  10. import ch.njol.skript.lang.util.SimpleExpression;
  11. import ch.njol.util.Kleenean;
  12. import ch.njol.util.coll.CollectionUtils;
  13.  
  14. public class ExprSaturation extends SimpleExpression<Float>{
  15.     private Expression<Player> player;
  16.     @Override
  17.     public Class<? extends Float> getReturnType() {
  18.         // TODO Auto-generated method stub
  19.         return Float.class;
  20.     }
  21.  
  22.     @Override
  23.     public boolean isSingle() {
  24.         // TODO Auto-generated method stub
  25.         return true;
  26.     }
  27.  
  28.     @Override
  29.     public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
  30.         // TODO Auto-generated method stub
  31.         player = (Expression<Player>) expr[0];
  32.         return true;
  33.     }
  34.  
  35.     @Override
  36.     public String toString(Event arg0, boolean arg1) {
  37.         // TODO Auto-generated method stub
  38.         return "saturation of player";
  39.     }
  40.  
  41.     @Override
  42.     protected Float[] get(Event arg0) {
  43.         // TODO Auto-generated method stub
  44.         return new Float[]{player.getSingle(arg0).getSaturation()};
  45.     }
  46.    
  47.     public void change(Event e, Object[] d, Changer.ChangeMode mode){
  48.         Player p = player.getSingle(e);
  49.         if (mode == ChangeMode.SET){
  50.             p.setSaturation((Float)d[0]);
  51.         }
  52.         else if (mode == ChangeMode.ADD){
  53.             p.setSaturation(p.getSaturation() + (Float)d[0]);
  54.         }
  55.         else if (mode == ChangeMode.RESET){
  56.             p.setSaturation(20f);
  57.         }
  58.     }
  59.  
  60.     public Class<?>[] acceptChange(final Changer.ChangeMode mode){
  61.         if (mode == ChangeMode.SET || mode == ChangeMode.ADD || mode == ChangeMode.RESET){
  62.             return CollectionUtils.array(Float.class);
  63.         }
  64.         return null;
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement