spenk

NoWeatherListener

Feb 13th, 2012
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.63 KB | None | 0 0
  1. public class NoWeatherListener extends PluginListener {
  2.     public boolean prevrain = true;
  3.     int time;
  4.     public boolean onWeatherChange(World world,boolean newValue){
  5.         if (prevrain){
  6.             return true;
  7.         }else{
  8.             return false;
  9.     }
  10.     }
  11.     public boolean onCommand(Player player,String[] split){
  12.         if ((split[0].equalsIgnoreCase("/w"))&&(player.canUseCommand("/weather"))){
  13.             if (split.length == 2){
  14.             if (split[1].equals("sun")){
  15.                 prevrain = false;
  16.                 World world = etc.getServer().getWorld(0);
  17.                 world.setThundering(false);
  18.                 world.setRaining(false);
  19.                 prevrain = true;
  20.                 etc.getServer().messageAll("§3"+player.getName()+"§2 Changed the weather.");
  21.                 return true;
  22.             }else{
  23.                 player.sendMessage("§cThe correct usage is '/weather <sun|rain|thunder> <rain/thunder time in seconds>'");
  24.                 return true;
  25.             }
  26.         }else if (split.length == 3){
  27.         try{Integer.parseInt(split[2]);}catch(NumberFormatException nfe){player.sendMessage("§cThe correct usage is '/weather <sun|rain|thunder> <rain/thunder time in seconds>'"); return true;}
  28.         if (split[1].equals("rain")){
  29.             prevrain = false;
  30.             time = Integer.parseInt(split[2])*1000;
  31.             World world = etc.getServer().getWorld(0);
  32.             world.setRaining(true);
  33.             etc.getServer().messageAll("§3"+player.getName()+"§2 Changed the weather for §4"+time/1000+"§2 seconds");
  34.              new Thread() {
  35.              public void run() {
  36.                   try{
  37.                         Thread.sleep(time);
  38.                        etc.getServer().getWorld(0).setRaining(false);
  39.                        etc.getServer().messageAll("§2The weather turned back!");
  40.                        prevrain = true;
  41.                        
  42.                   }catch(InterruptedException e) {}
  43.              }
  44.         }.start();
  45.         return true;
  46.         }  
  47.        
  48.         if (split[1].equals("thunder")){
  49.             prevrain = false;
  50.             time = Integer.parseInt(split[2])*1000;
  51.             etc.getServer().getWorld(0).setRaining(true);
  52.             etc.getServer().getWorld(0).setThundering(true);
  53.             etc.getServer().messageAll("§3"+player.getName()+"§2 Changed the weather for §4"+time/1000+"§2 seconds");
  54.              new Thread() {
  55.              public void run() {
  56.                   try{
  57.                         Thread.sleep(time);
  58.                            etc.getServer().getWorld(0).setThundering(false);
  59.                         etc.getServer().getWorld(0).setRaining(false);
  60.                         etc.getServer().messageAll("§2The weather turned back!");
  61.                        prevrain = true;
  62.                   }catch(InterruptedException e) {}
  63.              }
  64.         }.start();
  65.         return true;
  66.         }
  67.         }else{player.sendMessage("§cThe correct usage is '/weather <sun|rain|thunder> <rain/thunder time in seconds>'"); return true;}
  68.     }
  69.         return false;
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment