House system help

Discussion in 'Plugin Development' started by thewalkingplay, Jan 31, 2015.

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

    thewalkingplay

    Hi, i'm making a real life plugin and i'm making a house system. Exists any method to i check if the player is on the house and if the player is the owner of the house? the config for the houses:
    Code:
    Lotes:
      Claymore-A1:
        x1: 274
        y1: 69
        z1: 246
        x2: 301
        y2: 86
        z2: 272
    the house creation class:
    Code:
    package me.thewalkingplay.reallife.lotes;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.block.SignChangeEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    
    import me.thewalkingplay.reallife.Plugin;
    import me.thewalkingplay.reallife.eventos.Events;
    import me.thewalkingplay.reallife.utils.ChatUtilities;
    
    public class LoteRegionDefineManager extends Events {
    
        public LoteRegionDefineManager(Plugin pl) {
            super(pl);
        }
      
      
        int x1;
        int y1;
        int z1;
        int x2;
        int y2;
        int z2;
        int ready = 0;
        int sign = 0;
      
        @EventHandler
        public void aoDefinir(PlayerInteractEvent e) {
          
          
            Player p = e.getPlayer();
            if (e.getAction() == Action.LEFT_CLICK_BLOCK && p.getInventory().getItemInHand().getType() == Material.PRISMARINE_SHARD) {
              
                Block a = e.getClickedBlock();
                int x1_ = a.getLocation().getBlockX();
                int y1_ = a.getLocation().getBlockY();
                int z1_ = a.getLocation().getBlockZ();
                ChatUtilities.message(p, ChatColor.GREEN + "1 posiçao marcada com sucesso! (" + x1_ + " " + y1_ + " " + z1_ + ")");
                x1 = x1_;
                y1 = y1_;
                z1 = z1_;
                ready++;
              
            }
          
            if (e.getAction() == Action.RIGHT_CLICK_BLOCK && p.getInventory().getItemInHand().getType() == Material.PRISMARINE_SHARD) {
              
                Block a = e.getClickedBlock();
                int x2_ = a.getLocation().getBlockX();
                int y2_ = a.getLocation().getBlockY();
                int z2_ = a.getLocation().getBlockZ();
                ChatUtilities.message(p, ChatColor.GREEN + "2 posiçao marcada com sucesso! (" + x2_ + " " + y2_ + " " + z2_ + ")");
                x2 = x2_;
                y2 = y2_;
                z2 = z2_;
                ready++;
            }
          
            if (ready == 2) {
                ready = 0;
                ChatUtilities.message(p, ChatColor.GREEN + "Agora coloque a placa");
                sign = 1;
            }
          
        }
      
        @EventHandler
        public void aPlaca(SignChangeEvent e) {
    
            if (e.getLine(0).equalsIgnoreCase("[Lote]")) {
                if (sign == 1) {
                  
                    String name = e.getLine(1);
                    plugin.getConfig().set("Lotes." + name + ".x1", x1);
                    plugin.getConfig().set("Lotes." + name + ".y1", y1);
                    plugin.getConfig().set("Lotes." + name + ".z1", z1);
                    plugin.getConfig().set("Lotes." + name + ".x2", x2);
                    plugin.getConfig().set("Lotes." + name + ".y2", y2);
                    plugin.getConfig().set("Lotes." + name + ".z2", z2);
                    plugin.saveConfig();
                  
                    ChatUtilities.message(e.getPlayer(), ChatColor.GREEN + "Lote criado com sucesso!");
                    sign = 0;
                  
                    e.setLine(0, ChatColor.GREEN + "[LOTE]");
                    e.setLine(1, e.getLine(1));
                    e.setLine(2, ChatColor.GREEN + "");
                    e.setLine(3, e.getLine(3));
                  
                    x1 = 0;
                    y1 = 0;
                    z1 = 0;
                    x2 = 0;
                    y2 = 0;
                    z2 = 0;
                  
                  
                } else {
                    ChatUtilities.message(e.getPlayer(), ChatColor.RED + "Voce nao pode criar uma placa destas agora!");
                }
            }
          
        }
    
    }
    
    the house buy class:
    Code:
    package me.thewalkingplay.reallife.lotes;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.block.Sign;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    
    import me.thewalkingplay.reallife.Plugin;
    import me.thewalkingplay.reallife.dinheiro.MoneyManager;
    import me.thewalkingplay.reallife.eventos.Events;
    import me.thewalkingplay.reallife.utils.ChatUtilities;
    
    public class LoteSignClickManager extends Events {
    
        public LoteSignClickManager(Plugin pl) {
            super(pl);
        }
      
        @EventHandler
        public void aoClicar(PlayerInteractEvent e) {
            Player p = e.getPlayer();
            if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                if (e.getClickedBlock().getType() == Material.SIGN_POST) {
                    Sign s = (Sign) e.getClickedBlock().getState();
                    if (s.getLine(0).equalsIgnoreCase(ChatColor.GREEN + "[LOTE]")) {
                        if (plugin.getConfig().contains("Lotes." + s.getLine(1))) {
                            String preco = s.getLine(3);
                            int precoFinal = Integer.parseInt(preco);
                            if (MoneyManager.getMoney(p) >= precoFinal) {
                              
                                MoneyManager.removeMoney(p, precoFinal);
                                plugin.getConfig().set("Users." + p.getName() + ".lotes", s.getLine(1));
                                plugin.saveConfig();
                                s.setLine(0, ChatColor.RED + "[Lote]");
                                s.setLine(1, s.getLine(1));
                                s.setLine(2, ChatColor.RED + "");
                                s.setLine(3, ChatColor.RED + "ADQUIRIDO");
                                s.update();
                            } else {
                                ChatUtilities.message(p, ChatColor.RED + "Voce nao tem dinheiro suficiente para comprar este lote, desculpe");
                            }
                        } else {
                            ChatUtilities.message(p, ChatColor.RED + "Este lote nao consta na database, desculpe");
                        }
                    } else {
                        if (s.getLine(0).equalsIgnoreCase(ChatColor.RED + "[LOTE]"))
                        ChatUtilities.message(p, ChatColor.RED + "Este lote ja esta ocupado! procure outro");
                    }
                }
            }
        }
    
    }
    
    Exists any method to do this without make a class with all the houses region and check 1 by 1 ?

    Can anyone help me?
    Sorry for my english, i'm brazilian

    Anyone?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  2. Offline

    SuperOriginal

    @thewalkingplay Your class needs to implement Listener, not extend Events.

    Also, as far as I know the only way you could do this is by looping through each house and checking their coordinates relative to the Player's.
     
  3. Offline

    Permeer

    @thewalkingplayer cria uma nova hashmap
    Code:
    HashMap<UUID, String> save = new HashMap<UUID, String>();
    salva o uuid e o nome do lote usando
    Code:
    hash.put(UUID, nomedolote);
    e salva na config , no lote salva o UUID do player que comprou

    e voce coloca no Onable() ou no PlayerJoinEvent, se tiver o UUID do player em algum lote vc salva na hashmap

    e pra verificar se é o dono é so pegar o local do player e ver se é igual a de algum lote , logo voce pega o nome do lote e verifica se o UUID do player é o mesmo

    Translation:

    Create a new hashmap
    Code:
    HashMap<UUID, String> save = new HashMap<UUID, String>();
    , save the player UUID and his IGN and the location name using
    Code:
    hash.put(UUID, nomedolote);
    and salve in the config the location name and the player UUID who bought it
     
  4. Offline

    thewalkingplay

    @Permeer in this case i need to make somethink like this: ?
    Code:
    Vector location = p.getLocation().toVector();
    
    // and here check the lots cordinates 1 by 1 ?
    @thewalkingplay or have other method?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  5. Offline

    caderape

    @thewalkingplay
    Get minimum and maximum point for each house and loops.
     
  6. Offline

    thewalkingplay

    @caderape it will be tag a VERY LONG time of my life, because i need to add more lines of code each new house that i create .-. don't have other method?
     
  7. Offline

    nverdier

    What does that even mean? You could use WorldEdit's API to paste something...
     
  8. Offline

    caderape

    Create a private class House, put in the the player the minimumPoint and the MaximumPoint. Add it to an arraylist.
    And just do a loops for get back all the infos. This is 5-6 lines of code for check position, whatever how much houses u got.

    @thewalkingplay
     
  9. Offline

    nverdier

    @caderape Do you have any idea what you're talking about? Why would you need a private class? And your logic makes no sense to me..
     
  10. Offline

    caderape

  11. Offline

    thewalkingplay

    @caderape , @nverdier , @nverdier , @Permeer and @SuperOriginal i maked this:
    Code:
                if (plugin.getConfig().getList("Users." + e.getPlayer() + ".lotes").size() >= 1) {
                  
                    @SuppressWarnings("unchecked")
                    List<String> lotes = (List<String>) plugin.getConfig().getList("Users." + e.getPlayer() + ".lotes");
                  
                    if (lotes.size() == 1) {
                      
                        String casa1 = lotes.get(0);
                        int x1 = plugin.getConfig().getInt("Lotes." + casa1 + ".x1");
                        int y1 = plugin.getConfig().getInt("Lotes." + casa1 + ".y1");
                        int z1 = plugin.getConfig().getInt("Lotes." + casa1 + ".z1");
                        int x2 = plugin.getConfig().getInt("Lotes." + casa1 + ".x2");
                        int y2 = plugin.getConfig().getInt("Lotes." + casa1 + ".y2");
                        int z2 = plugin.getConfig().getInt("Lotes." + casa1 + ".z2");
                      
                        Vector min = new Vector(x1, y1, z1);
                        Vector max = new Vector(x2, y2, z2);
                        if (e.getBlock().getLocation().toVector().isInAABB(min, max)) {
                            e.setCancelled(false);
                        }
                      
                      
                    }
                  
                }
    it's correct?
     
Thread Status:
Not open for further replies.

Share This Page