Solved Need Help saving and callin block locations

Discussion in 'Plugin Development' started by IKFFxRaPiDzZ, Apr 18, 2019.

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

    IKFFxRaPiDzZ

    Hi there im new to the whole plugin dev stuff, i have everything working but i cant figure out how to save block locations as at the moment EVERY emerald block will heal where as i want only emerald blocks the OP has placed to heal any ideas?

    here is the code i have for healing

    Code:
    if (action.equals(Action.RIGHT_CLICK_BLOCK)) {
                if (block.getType().equals(Material.getMaterial(plugin.getConfig().getString("Healingstone.BlockType")))) {
                    if (player.hasPermission("hs.maxhealth")) {
                        if (player.getHealth() == player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()) {
                            player.sendMessage(ChatColor.translateAlternateColorCodes('&',
                                    plugin.getConfig().getString("Message.Healthfull")));
                            return;
                        }
    
                        final EconomyResponse response = plugin.getEconomy().withdrawPlayer(player,
                                plugin.getConfig().getDouble("Economy.Cost"));
                        if (!response.transactionSuccess()) {
                            player.sendMessage(ChatColor.translateAlternateColorCodes('&',
                                    plugin.getConfig().getString("Message.Nofunds")));
                            player.sendMessage(ChatColor.GREEN + "You Need" + " " + "$"
                                    + (plugin.getConfig().getString("Economy.Cost")) + " " + "To Heal");
                            // Not enough money
    
                        } else {
                            player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
                            player.sendMessage(ChatColor.translateAlternateColorCodes('&',
                                    plugin.getConfig().getString("Message.Healthrestored")));
                            return;
    
                        }
    
                    }
    
                }
            }

    Ive tried doing this for the block saving but it just gives me the red squigly under the text..

    Code:
    if (player.isOp()) {
                if (action.equals(Action.LEFT_CLICK_BLOCK)) {
                    if (block.getType().equals(Material.getMaterial(plugin.getConfig().getString("Healingstone.BlockType")))) {
                        Location loc = block.getLocation();
                        getconfig.set("location.World", loc.getWorld().getName());
                        getconfig.set("location.X", loc.getX());
                        getconfig.set("location.Y", loc.getY());
                        getconfig.set("location.Z", loc.getZ());
                        getconfig.set("location.Yaw", loc.getYaw());
                        getconfig.set("location.Pitch", loc.getPitch());
                        saveConfig();
                       
                    }
                }
            }
     
  2. Online

    timtower Administrator Administrator Moderator

    @IKFFxRaPiDzZ Hover your mouse over the red line, it will say what is wrong.
    My guess is that it doesn't know getconfig() though, so you need to replace that with plugin.getConfig()
     
  3. Offline

    IKFFxRaPiDzZ

    plugin.getConfig() is calling it is it not? im trying to save the location again im new at this xD
     
  4. Online

    timtower Administrator Administrator Moderator

    getconfig.set
    And that line?
     
  5. Offline

    IKFFxRaPiDzZ

    i did this and all errors have gone but nothing is bring saved to the config and every BlockType is healing


    if (player.isOp()) {
    if (action.equals(Action.LEFT_CLICK_BLOCK)) {
    if (block.getType().equals(Material.getMaterial(plugin.getConfig().getString("Healingstone.BlockType")))) {
    Location loc = block.getLocation();
    plugin.getConfig();
    plugin.getConfig().set("location.World", loc.getWorld().getName());
    plugin.getConfig().set("location.X", loc.getX());
    plugin.getConfig().set("location.Y", loc.getY());
    plugin.getConfig().set("location.Z", loc.getZ());
    plugin.getConfig().set("location.Yaw", loc.getYaw());
    plugin.getConfig().set("location.Pitch", loc.getPitch());
    plugin.saveConfig();

    }
    }
    }
     
  6. Online

    timtower Administrator Administrator Moderator

  7. Offline

    IKFFxRaPiDzZ

    its all worked out, just need to get it to look for the data before running the healing event xD

    Code:
            Location b_loc = block.getLocation();
            if (player.hasPermission("hs.hs")) {
                player.sendMessage(ChatColor.GOLD + "You Placed A Healing Block");
                if (block.getType().equals(Material.getMaterial(plugin.getConfig().getString("Healingstone.BlockType")))) {
                    plugin.getConfig().set("HealingBlocks." + ".Block_" + count + ".world", b_loc.getWorld().getName());
                    plugin.getConfig().set("HealingBlocks." + ".Block_" + count + ".x", b_loc.getBlockX());
                    plugin.getConfig().set("HealingBlocks." + ".Block_" + count + ".y", b_loc.getBlockY());
                    plugin.getConfig().set("HealingBlocks." + ".Block_" + count + ".z", b_loc.getBlockZ());
                    plugin.saveConfig();
                    count++;
                }
            }
        }
     
Thread Status:
Not open for further replies.

Share This Page