Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.greenadine.advancedspawners.runnable;
- import java.util.ArrayList;
- import java.util.Set;
- import org.bukkit.Effect;
- import org.bukkit.Location;
- import org.bukkit.Particle;
- import org.bukkit.World;
- import org.bukkit.block.Block;
- import org.bukkit.entity.Entity;
- import org.bukkit.entity.EntityType;
- import me.greenadine.advancedspawners.Main;
- import me.greenadine.advancedspawners.Spawner;
- public class SpawnerEffectPlayer implements Runnable{
- private Main main = Main.PLUGIN;
- public SpawnerEffectPlayer() {
- }
- @Override
- public void run() {
- Set<String> slist = main.getSaver().getConfigurationSection("spawners").getKeys(false);
- for(String id : slist) {
- if(id.contains("@")) {
- String[] s1 = id.split("@");
- if(s1[1].contains(";")) {
- String[] s2 = s1[1].split(";");
- String world = s1[0];
- World w = main.getServer().getWorld(world);
- int x = Integer.valueOf(s2[0]);
- int y = Integer.valueOf(s2[1]);
- int z = Integer.valueOf(s2[2]);
- Block b = w.getBlockAt(x, y, z);
- if(b.getType() != main.items().spawner().getType()) {
- continue;
- }
- Spawner spawner = new Spawner(b);
- if(!spawner.isValid()) {
- main.getSaver().set("spawners." + spawner.getID(), null);
- continue;
- }
- boolean bool = false;
- for (Entity entity : b.getWorld().getNearbyEntities(b.getLocation(), 50, 50, 50)) {
- if(entity.getType() != EntityType.PLAYER) {
- continue;
- }
- bool = true;
- break;
- }
- if(!bool) {
- continue;
- }
- if(spawner.getLevel() == 0) {
- continue;
- }
- String effectType = main.getConfig().getString("spawners." + spawner.getLevel() + ".effectType");
- if(effectType == null) {
- spawner.playEffect(Particle.BARRIER, getCircle(b.getLocation(), 1, 4));
- continue;
- }
- if(effectType.equalsIgnoreCase("none")) {
- continue;
- }
- if(effectType.equals("particle")) {
- Particle effect = null;
- try {
- effect = Particle.valueOf(main.getConfig().getString("spawners." + spawner.getLevel() + ".effect"));
- } catch(IllegalArgumentException e) {
- spawner.playEffect(Particle.BARRIER, getCircle(b.getLocation(), 1, 4));
- continue;
- }
- spawner.playEffect(effect, getCircle(b.getLocation(), 1, 100));
- continue;
- }
- if(effectType.equals("effect")) {
- Effect effect = null;
- try {
- effect = Effect.valueOf(main.getConfig().getString("spawners." + spawner.getLevel() + ".effect"));
- } catch(IllegalArgumentException e) {
- spawner.playEffect(Particle.BARRIER, getCircle(b.getLocation(), 1, 4));
- continue;
- }
- spawner.playEffect(effect, getCircle(b.getLocation(), 1, 100));
- continue;
- } else {
- spawner.playEffect(Particle.BARRIER, getCircle(b.getLocation(), 1, 4));
- continue;
- }
- }
- }
- }
- }
- private ArrayList<Location> getCircle(Location center, double radius, int amount)
- {
- World world = center.getWorld();
- double increment = (2 * Math.PI) / amount;
- ArrayList<Location> locations = new ArrayList<Location>();
- for(int i = 0;i < amount; i++)
- {
- double angle = i * increment;
- double x = center.getX() + 0.50 + (radius * Math.cos(angle));
- double z = center.getZ() + 0.50 + (radius * Math.sin(angle));
- locations.add(new Location(world, x, center.getY() + 0.5, z));
- }
- return locations;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment