Play effect on block.

Discussion in 'Plugin Development' started by Plukkies, Feb 15, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    Plukkies

    Hello Bukkit persons,

    I have now this:
    Code:
    package me.Plukkies.TeleportBlock;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Effect;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.util.Vector;
    
    public class Main extends JavaPlugin implements Listener {
        public void onEnable(){
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            Bukkit.getScheduler().runTaskTimer(this, new Runnable(){
                public void run(){
    
                    World w = Bukkit.getServer().getWorld(getConfig().getString("location.World"));
                    double x = getConfig().getDouble("location.X");
                    double y = getConfig().getDouble("location.Y");
                    double z = getConfig().getDouble("location.Z");
                    World world = Bukkit.getWorld(getConfig().getString("location.World"));
                   w.playEffect(new Location(world, x, y, z), Effect.HAPPY_VILLAGER, 50);
                   w.playEffect(new Location(world, x, y - 0.5, z), Effect.HAPPY_VILLAGER, 50);
                   w.playEffect(new Location(world, x, y - 1, z), Effect.HAPPY_VILLAGER, 50);
                   w.playEffect(new Location(world, x, y - 1.5, z), Effect.HAPPY_VILLAGER, 50);
                   w.playEffect(new Location(world, x, y - 2, z), Effect.HAPPY_VILLAGER, 50);
                   w.playEffect(new Location(world, x, y - 2.5, z), Effect.HAPPY_VILLAGER, 50);
                   w.playEffect(new Location(world, x, y - 3.5, z), Effect.HAPPY_VILLAGER, 50);
                   w.playEffect(new Location(world, x, y - 4, z), Effect.HAPPY_VILLAGER, 50);
                   w.playEffect(new Location(world, x, y + 0.5, z), Effect.HAPPY_VILLAGER, 50);
                   w.playEffect(new Location(world, x, y + 1, z), Effect.HAPPY_VILLAGER, 50);
                   w.playEffect(new Location(world, x, y + 1.5, z), Effect.HAPPY_VILLAGER, 50);
                   w.playEffect(new Location(world, x, y + 3, z), Effect.HAPPY_VILLAGER, 50);
                }
            }, 10, 10);
        }
        @EventHandler
        public void onPlayerMove(final PlayerMoveEvent e) {
            final Player p = e.getPlayer();
            final Block block = p.getLocation().getBlock();
            final int x = block.getX();
            final int y = block.getY();
            final int z = block.getZ();
            final World w = block.getWorld();
            reloadConfig();
            if(p.hasPermission("teleport")){
            if (getConfig().contains(w+"."+x+"."+y+"."+z)){
                if(e.getTo().getX() == e.getFrom().getX()){
                Bukkit.getServer().dispatchCommand(p, getConfig().getString(w+"."+x+"."+y+"."+z));
               Vector v = p.getLocation().getDirection().multiply(1);
                p.setVelocity(v);
            }
            }
            }
           }
      
          
          
          
          
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            Player p = (Player)sender;
            if(cmd.getName().equalsIgnoreCase("stb")){
                Player player = (Player)sender;
                @SuppressWarnings("deprecation")
                Block block2 = p.getTargetBlock(null, 200);
                int x = block2.getX();
                int y = block2.getY();
                int z = block2.getZ();
                World world1 = block2.getWorld();
                if(player.hasPermission("setteleportblock")){
                    if(args.length == 0){
                        p.sendMessage(ChatColor.RED + "Welk commando moet de speler uitvoeren?");
                    } else {
                    if(args.length >= 2){
                    if(block2.getType() == Material.AIR){
                        p.sendMessage(ChatColor.RED + "Jammer de lucht kan je niet gebruiken.");
                    } else {
                getConfig().set(world1+"."+x+"."+y+"."+z, args[0] + " " +args[1]);
                saveConfig();
                p.sendMessage(ChatColor.RED + "Block set!" + " "+ x +" "+ y + " "+z);
                    }
                } else {
                    getConfig().set(world1+"."+x+"."+y+"."+z, args[0]);
                    saveConfig();
                    p.sendMessage(ChatColor.RED + "Block set!" +" "+ x +" "+ y + " "+z);
                }
               }
                }
            }
          
            if(cmd.getName().equalsIgnoreCase("stbrm")){
                Player player = (Player)sender;
                if(player.hasPermission("setteleportblock")){
                @SuppressWarnings("deprecation")
                Block block2 = p.getTargetBlock(null, 200);
                int x = block2.getX();
                int y = block2.getY();
                int z = block2.getZ();
                World world1 = block2.getWorld();
                getConfig().set(world1+"."+x+"."+y+"."+z, null);
                saveConfig();
                p.sendMessage(ChatColor.RED + "Removed block!" +" "+ x +" "+ y + " "+z);
            }
            }
                if(cmd.getName().equalsIgnoreCase("ssb")){
                    Player player = (Player)sender;
                    if(player.hasPermission("setspawnblock")){
                    @SuppressWarnings("deprecation")
                    Block block2 = p.getTargetBlock(null, 200);
                    int x = block2.getX();
                    int y = block2.getY();
                    int z = block2.getZ();
                    Location loc = player.getLocation();
                    FileConfiguration config = getConfig();
                    config.set("location.World", loc.getWorld().getName());
                    config.set("location.X", loc.getX());
                    config.set("location.Y", loc.getY());
                    config.set("location.Z", loc.getZ());
                    saveConfig();
                    p.sendMessage(ChatColor.RED + "Set spawn block!" +" "+ x +" "+ y + " "+z);
                }
                }      
        
      
            return false;
    }
    }
    
    
    Now plays the effect only on the block that I have set with ssb. Can i make that the plugin as well plays on the block what I set in the config:
    Code:
    location:
      World: world
      X: 43.627361415175656
      Y: 72.0
      Z: 23.58555406782002
    CraftWorld{name=world}: <--- 
      '43': <---
        '70': < ---
          '17': spawn <--
    
     
  2. load world and call getBlock with x y and z. then play effect
     
Thread Status:
Not open for further replies.

Share This Page