Array Problems

Discussion in 'Plugin Development' started by JJSfluffyduck, Oct 3, 2012.

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

    JJSfluffyduck

    I try to only let people break some blocks and not others but when i list the breakable stuff and if it not one of these block message me it message me 9 times over any ideas here my code
    Code:
    package me.JJSfluffyduck.Logger;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.BlockPlaceEvent;
     
    public class LogListener implements Listener {
     
        public static LogMain plugin;
     
        public LogListener(LogMain instance) {
            plugin = instance;
        }
     
        public static Material[] whitelist = { Material.LEAVES, Material.VINE,
                Material.BROWN_MUSHROOM, Material.RED_MUSHROOM, Material.CROPS,
                Material.DEAD_BUSH, Material.LONG_GRASS, Material.YELLOW_FLOWER,
                Material.RED_ROSE };
     
        @EventHandler
        public void onBlockPlace(BlockPlaceEvent event) {
            Material BlockPlace = event.getBlock().getType();
            Player player = event.getPlayer();
            // Location LocPlayer = player.getLocation();
            System.out.println(ChatColor.BLUE + player.getName() + " placed "
                    + BlockPlace);
            player.sendMessage(ChatColor.BLUE + "You placed this type of block: "
                    + ChatColor.BLUE + BlockPlace);
        }
     
        @EventHandler
        public void onBlockBreak(BlockBreakEvent event) {
            Material BlockBreak = event.getBlock().getType();
            Player player = event.getPlayer();
     
            for (Material aloud : whitelist) {
                if (aloud != BlockBreak) {
                    Bukkit.broadcast(""+ChatColor.GREEN
                            + "You Broke this type of block: " + BlockBreak+"","bukkit.broadcast.admin");
                    //player.sendMessage(ChatColor.GREEN
                    //        + "You Broke this type of block: " + BlockBreak);
                    System.out.println(ChatColor.BLUE + player.getName()
                            + " broke " + BlockBreak);}
                }
            }
        }
     
  2. I should do it like this:
    Code:java
    1. for (Material aloud : whitelist) {
    2. if (aloud == BlockBreak) {return;
    3. }
    4. }Bukkit.broadcast(""+ChatColor.GREEN
    5. + "You Broke this type of block: " + BlockBreak+"","bukkit.broadcast.admin");
    6. //player.sendMessage(ChatColor.GREEN
    7. // + "You Broke this type of block: " + BlockBreak);
    8. System.out.println(ChatColor.BLUE + player.getName()
    9. + " broke " + BlockBreak);
    10.  
    so its only broadcastred when there was not total match, try to see what I did to understand de code, hope this helps
     
  3. Offline

    JJSfluffyduck

    do man you are the bomb!!
    how you so good!!!
    thanks so much

    is there a way so when a player breaks a block it give me the x, y, z axes?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  4. chance
    Bukkit.broadcast(""+ChatColor.GREEN
    + "You Broke this type of block: " + BlockBreak+"","bukkit.broadcast.admin");
    to
    Bukkit.broadcast(""+ChatColor.GREEN
    + "You Broke this type of block: " + BlockBreak+""+BlockBreak.getLocation.toString(),"bukkit.broadcast.admin");
    if its not the right format you want, try expirimenting whit "getX(), "getY()" "getZ()"
     
  5. Offline

    JJSfluffyduck

    yer thanks it works

    I did like this (This is just for other people).
    Code:
    //you can do double but i think int is better
    int LocX = (int) event.getBlock().getLocation().getX();
    int LocY = (int) event.getBlock().getLocation().getY();
    int LocZ = (int) event.getBlock().getLocation().getZ();
    player.sendMessage(ChatColor.BLUE + " at Location: "+ChatColor.RED+"x, " + LocX + " y, "+ LocY + " z, " + LocZ);
    
    is there a way to tele to x, y, and z axes?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  6. Offline

    HouseMD

    Code:
    Player p = event.getPlayer();
    Location l = new Location(<world>, <x>, <y>, <z>);
     
    p.teleport(l)
     
  7. Offline

    JJSfluffyduck

    i got a problem that i want a command that goes /setspawn and it set the player x y z to the var spawn
    then if he write later /spawn there tele to the axes
     
  8. Offline

    md_5

    So save a location Vector + world name to the config, and then use player.teleport(vector.getLocation(world))
    (pseudo code)
     
Thread Status:
Not open for further replies.

Share This Page