Advertisement
Guest User

Apocalypse

a guest
Jun 15th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.20 KB | None | 0 0
  1. package Apocalypse;
  2.  
  3. import java.util.HashMap;
  4.  
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.GameMode;
  7. import org.bukkit.Location;
  8. import org.bukkit.block.Block;
  9. import org.bukkit.entity.Player;
  10. import org.bukkit.plugin.Plugin;
  11. import org.bukkit.plugin.java.JavaPlugin;
  12.  
  13. public class Main extends JavaPlugin{
  14.    
  15.    
  16.     public static Plugin plugin;
  17.     public static String prefix = "Apocalypse";
  18.    
  19.    
  20.     //## PLUGIN ACTIVATION ##
  21.     @Override
  22.     public void onEnable() {
  23.         super.onEnable();
  24.        
  25.         System.out.println("["+ prefix +"] ##############################");
  26.         System.out.println("["+ prefix +"]      Plugin made by Rail");
  27.         System.out.println("["+ prefix +"] ------------------------------");
  28.         System.out.println("["+ prefix +"] <> Activating Plugin <>");
  29.         System.out.println("["+ prefix +"] Starting System..");
  30.        
  31.         plugin = this;
  32.         repeatingTask();
  33.        
  34.         System.out.println("["+ prefix +"] - Ok!");
  35.         System.out.println("["+ prefix +"] ##############################");
  36.     }
  37.     //## PLUGIN DEACTIVATION ##
  38.     @Override
  39.     public void onDisable() {
  40.         System.out.println("["+ prefix +"] - Plugin deactivated!");
  41.     }  
  42.    
  43.    
  44.     //## Plugin GET Method ##
  45.     public static Plugin getPlugin() {
  46.         return plugin;
  47.     }
  48.    
  49.    
  50.     static int burnInSeconds = 5;
  51.     static int burnAfterSeconds = 3;
  52.     static HashMap<Player, Integer> timerList = new HashMap<>();
  53.    
  54.     public void repeatingTask(){
  55.        
  56.         Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
  57.         {  
  58.             @Override
  59.             public void run()                                   // This runs every 5 Ticks (~ 4 Times /second)
  60.             {
  61.                 for(Player p : Bukkit.getOnlinePlayers()){      // Cycle thru every Player Online
  62.                     if(p.getGameMode() != GameMode.CREATIVE && p.getGameMode() != GameMode.SPECTATOR){  // Filter Creative & Spectator Players
  63.                        
  64.                         if(timerList.get(p) != null){               // Catch Errors
  65.                             int timer = timerList.get(p);
  66.                             boolean isUnderBlock = isUnderBlock(p);
  67.                            
  68.                             if(!isUnderBlock){                      // Player is not under a Block
  69.                                
  70.                                 if(timer < 0){                  // Set timer (to 'burnAfterSeconds')
  71.                                    
  72.                                     timer = burnAfterSeconds*4;
  73.                                     timerList.put(p, timer);
  74.                                    
  75.                                 }else if(timer > 0){            // Run timer   
  76.                                    
  77.                                     timer--;
  78.                                     timerList.put(p, timer);
  79.                                    
  80.                                 }else if(timer == 0){           // Timer has reached 0, BURN!! (for 'burnInSeconds')
  81.                                    
  82.                                     p.setFireTicks(burnInSeconds*20);
  83.                                
  84.                                 }
  85.                                
  86.                             }else{                                  // Player is under a Block
  87.                                
  88.                                 if(timer >= 0){
  89.                                    
  90.                                     timer = -1;                     // Stop & Reset Timer
  91.                                     timerList.put(p, timer);
  92.                                    
  93.                                 }
  94.                                
  95.                                
  96.                             }
  97.                            
  98.                         }else{
  99.                            
  100.                             timerList.put(p, -1);                   // Put new Player in List (default: timer off)
  101.                            
  102.                         }
  103.                     }
  104.                 }
  105.                
  106.             }
  107.         }, 20, 5);
  108.        
  109.     }
  110.    
  111.    
  112.     public boolean isUnderBlock(Player p){
  113.        
  114.         Location loc = p.getLocation();
  115.         Block highestBlock = loc.getWorld().getHighestBlockAt(loc);
  116.         Location locBlock = highestBlock.getLocation();
  117.        
  118.         double y = loc.getY();
  119.         double yBlock = locBlock.getY();
  120.        
  121.         if(y < yBlock){
  122.            
  123.             return true;
  124.            
  125.         }else{
  126.            
  127.             return false;
  128.            
  129.         }
  130.     }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement