knowing blocks locations

Discussion in 'Plugin Development' started by victot21, May 29, 2018.

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

    victot21

    I want to do a plugin where u have a machine textured skull block that when clicked with right button open an inventory, but i tried to use metadata to put a "ismachine" data inside the block but then i discovered that metadata is gone when u restart the server, what could I do to differentiate the blocks from other skullblocks ?

    Thanks
    Victot21
     
  2. Offline

    Artellet

    As for the block location(s), make a local variable, initialize it as the block you want the location of, then use #getLocation().
     
  3. Offline

    victot21

    but i want to put and take machines, if i initialized it would only show the same location
     
  4. Offline

    Zombie_Striker

    @victot21
    When you break the skull that is in the location, remove it from the location and turn the drop into a machine item.
     
  5. Offline

    victot21

    if I use a Location variable, when i restart the server it shouldn't go back to default ?
    and if so how i'm going to put it back on the list ?
     
  6. Offline

    Zombie_Striker

    @victot21
    Store the locations in a list in the config. When you reload/in the onEnable, set the list to be equal to the list in the config.
     
  7. Offline

    victot21

    i tried to save the strings in the config and to read them saving works but reading doesn't and it does not tell me any errors
    SavingCode (open)

    Code:
    public void Blockplace(BlockPlaceEvent e) {
            Location loc = e.getBlockPlaced().getLocation();
        
            String loq = loc.getWorld() + "," + loc.getX() + "," + loc.getY() + "," + loc.getZ();
            getConfig().set("Location." + number, loq);
            saveConfig();
            reloadConfig();
            number = number+ 1;
        
        
        
        
        
        
        
        }


    ReadingCode (open)

    Code:
    public void Playerint(PlayerInteractEvent e){
    if(e.getAction() == org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK ){
    if(e.getClickedBlock().getType() == Material.SKULL){     
            if (getConfig().getString("Location")!=null){
        for (int i = 0; i < number; i++ ) {
        
        
            String[] block = getConfig().getString("Location." + i).split(",");
            World world = Bukkit.getWorld(block[0]);
            float locx = Integer.parseInt(block[1]);
            float locy = Integer.parseInt(block[2]);
            float locz = Integer.parseInt(block[3]);
            Location blockl = new Location(world,locx, locy, locz);
            if(e.getClickedBlock().getLocation() == blockl) {
            
                e.setCancelled(true);
                break;
                       }
                 }
           }
            player.openInventory(inv);
        
                   }
            }
        }
     
    Last edited: May 30, 2018
  8. Offline

    Zombie_Striker

    Code:
            if (getConfig().getString("Location")!=null){
    This will always return null because there is no string at just Location. You need to also provide a number (Or, better yet, just get the keys for that configuration section.)

    Code:
            if(e.getClickedBlock().getLocation() == blockl) {
    Also, this will never be true. By creating a new instance of Location for the check, the instances will never be the same as the clicked block's location. Instead, use .equals()
     
Thread Status:
Not open for further replies.

Share This Page