Greenadine

Untitled

Apr 3rd, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.63 KB | None | 0 0
  1. package me.greenadine.advancedspawners.runnable;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Set;
  5.  
  6. import org.bukkit.Effect;
  7. import org.bukkit.Location;
  8. import org.bukkit.Particle;
  9. import org.bukkit.World;
  10. import org.bukkit.block.Block;
  11. import org.bukkit.entity.Entity;
  12. import org.bukkit.entity.EntityType;
  13.  
  14. import me.greenadine.advancedspawners.Main;
  15. import me.greenadine.advancedspawners.Spawner;
  16.  
  17. public class SpawnerEffectPlayer implements Runnable{
  18.  
  19.     private Main main = Main.PLUGIN;
  20.    
  21.     public SpawnerEffectPlayer() {
  22.     }
  23.    
  24.     @Override
  25.     public void run() {
  26.         Set<String> slist = main.getSaver().getConfigurationSection("spawners").getKeys(false);
  27.         for(String id : slist) {
  28.             if(id.contains("@")) {
  29.                 String[] s1 = id.split("@");
  30.                 if(s1[1].contains(";")) {
  31.                     String[] s2 = s1[1].split(";");
  32.                    
  33.                     String world = s1[0];
  34.                     World w = main.getServer().getWorld(world);
  35.                     int x = Integer.valueOf(s2[0]);
  36.                     int y = Integer.valueOf(s2[1]);
  37.                     int z = Integer.valueOf(s2[2]);
  38.                    
  39.                     Block b = w.getBlockAt(x, y, z);
  40.                    
  41.                     if(b.getType() != main.items().spawner().getType()) {
  42.                         continue;
  43.                     }
  44.  
  45.                     Spawner spawner = new Spawner(b);
  46.                    
  47.                     if(!spawner.isValid()) {
  48.                         main.getSaver().set("spawners." + spawner.getID(), null);
  49.                         continue;
  50.                     }
  51.                    
  52.                     boolean bool = false;
  53.                     for (Entity entity : b.getWorld().getNearbyEntities(b.getLocation(), 50, 50, 50)) {
  54.                         if(entity.getType() != EntityType.PLAYER) {
  55.                             continue;
  56.                         }
  57.                        
  58.                         bool = true;
  59.                         break;
  60.                     }
  61.                    
  62.                     if(!bool) {
  63.                         continue;
  64.                     }
  65.                    
  66.                     if(spawner.getLevel() == 0) {
  67.                         continue;
  68.                     }
  69.                    
  70.                     String effectType = main.getConfig().getString("spawners." + spawner.getLevel() + ".effectType");
  71.                    
  72.                     if(effectType == null) {
  73.                         spawner.playEffect(Particle.BARRIER, getCircle(b.getLocation(), 1, 4));
  74.                         continue;
  75.                     }
  76.                    
  77.                     if(effectType.equalsIgnoreCase("none")) {
  78.                         continue;
  79.                     }
  80.                    
  81.                     if(effectType.equals("particle")) {
  82.                         Particle effect = null;
  83.                         try {
  84.                             effect = Particle.valueOf(main.getConfig().getString("spawners." + spawner.getLevel() + ".effect"));
  85.                         } catch(IllegalArgumentException e) {
  86.                             spawner.playEffect(Particle.BARRIER, getCircle(b.getLocation(), 1, 4));
  87.                             continue;
  88.                         }
  89.                        
  90.                         spawner.playEffect(effect, getCircle(b.getLocation(), 1, 100));
  91.                         continue;
  92.                     }
  93.                    
  94.                     if(effectType.equals("effect")) {
  95.                         Effect effect = null;
  96.                         try {
  97.                             effect = Effect.valueOf(main.getConfig().getString("spawners." + spawner.getLevel() + ".effect"));
  98.                         } catch(IllegalArgumentException e) {
  99.                             spawner.playEffect(Particle.BARRIER, getCircle(b.getLocation(), 1, 4));
  100.                             continue;
  101.                         }
  102.                        
  103.                         spawner.playEffect(effect, getCircle(b.getLocation(), 1, 100));
  104.                         continue;
  105.                     } else {
  106.                         spawner.playEffect(Particle.BARRIER, getCircle(b.getLocation(), 1, 4));
  107.                         continue;
  108.                     }
  109.                 }
  110.             }
  111.         }
  112.     }
  113.    
  114.     private ArrayList<Location> getCircle(Location center, double radius, int amount)
  115.     {
  116.         World world = center.getWorld();
  117.         double increment = (2 * Math.PI) / amount;
  118.         ArrayList<Location> locations = new ArrayList<Location>();
  119.         for(int i = 0;i < amount; i++)
  120.         {
  121.             double angle = i * increment;
  122.             double x = center.getX() + 0.50 + (radius * Math.cos(angle));
  123.             double z = center.getZ() + 0.50 + (radius * Math.sin(angle));
  124.             locations.add(new Location(world, x, center.getY() + 0.5, z));
  125.         }
  126.         return locations;
  127.     }
  128.  
  129. }
Advertisement
Add Comment
Please, Sign In to add comment