Cuboid Help (couldn't find anything in multiple google searches)

Discussion in 'Plugin Development' started by boss86741, Aug 26, 2013.

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

    boss86741

    Hey,

    I need a bit of help. I am not good with Locations and coords in bukkit. Basically I want to make it so that an admin can select an area and the area would be saved into the config file. Then I want to be able to select a block inside the cuboid that when a player from another team gets within a configurable radius, it is "captured" by that player's team. At the beginning of a game, all zones are neutral. When a team captures one, it become's that teams. I also need a formula to decide which team the player should go on PlayerJoinEvent and I need to be able to detect which zone the player is in.

    Thanks, any help provided is appreciated.

    Current Code:

    Main:
    Code:
    package com.boss86741.plugins.dimensionsapart.cc;
     
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class CampfireCapture extends JavaPlugin {
       
        @Override
        public void onEnable() {
            Commands c = new Commands(this);
            getCommand("ccap").setExecutor(c);
           
            getServer().getPluginManager().registerEvents(new Events(this), this);
           
            getConfig().addDefault("Radius", 1); // The radius the player must be within to have a "capture"
            getConfig().addDefault("Reward", 123); // Reward is itemstack ID.
            getConfig().addDefault("Teams", ""); // Team list.
           
            getConfig().getStringList("Teams").add("Red");
            getConfig().getStringList("Teams").add("Blue");
           
            saveConfig();
        }
    }
    
    Commands:
    Code:
    package com.boss86741.plugins.dimensionsapart.cc;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
     
    public class Commands implements CommandExecutor {
     
        private CampfireCapture plugin;
       
        public Commands(CampfireCapture plugin) {
            this.plugin = plugin;
        }
       
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("ccap")) {
                Player p = (Player) sender;
                String pl = p.getName();
                if (args[0].equalsIgnoreCase("tool")) {
                    if (p.hasPermission("ccap.tool")) {
                        ItemStack i = new ItemStack(Material.WOOD_SWORD);
                        p.getInventory().addItem(i);
                        p.sendMessage(ChatColor.GREEN + "You were given the selection tool!");
                    } else {
                        p.sendMessage(ChatColor.DARK_RED + "You don't have permission, " + pl + "!");
                    }
     
                } else if (args[0].equalsIgnoreCase("remove")) {
                    // Removes the zone that the player is in.
                    if (p.hasPermission("ccap.remove")) {
                       
                    } else {
                        p.sendMessage(ChatColor.DARK_RED + "You don't have permission, " + pl + "!");
                    }
                } else if (args[0].equalsIgnoreCase("reset")) {
                    // Makes all zones neutral and not belong to any team.
                    if (p.hasPermission("ccap.reset")) {
                       
                    } else {
                        p.sendMessage(ChatColor.DARK_RED + "You don't have permission, " + pl + "!");
                    }
                }
            return true;
            }
        return false;
        }
    }
    Events:
    Code:
    package com.boss86741.plugins.dimensionsapart.cc;
     
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
     
    public class Events implements Listener {
       
        private CampfireCapture plugin;
       
        public Events(CampfireCapture plugin) {
            this.plugin = plugin;
        }
       
        @EventHandler
        public void onPlayerInteractEvent(PlayerInteractEvent e) {
            Player p = e.getPlayer();
            Action a = e.getAction();
            Location loc1 = null;
            Location loc2 = null;
           
            if (p.hasPermission("ccap.set")) {
                if (a.equals(Action.LEFT_CLICK_BLOCK)) {
                    if (p.getItemInHand().equals(Material.WOOD_SWORD)) {
                        loc1 = e.getClickedBlock().getLocation();
                    }
                } else if (a.equals(Action.RIGHT_CLICK_BLOCK)) {
                    if (p.getItemInHand().equals(Material.WOOD_SWORD)) {
                        loc2 = e.getClickedBlock().getLocation();
                    }
                }   
            }
        }
       
        @EventHandler
        public void onPlayerLogin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            String pl = p.getName();
            plugin.getConfig().addDefault(pl, "");
            // Need to decide which team the player should go on after listing the teams.
        }
    }
    
     
  2. Offline

    beefjerky97

  3. Offline

    boss86741

    Please can someone help?
     
  4. Offline

    aredherring

    I actually wrote a plugin that did exactly this a few weeks ago, although I've lost it now.. I'll see if I can work something up quickly for you in the next 10 mins or so.
    EDIT: Well, I wrote a program that could capture 3d areas and persist them.

    Code:java
    1. private void create3DArea(World world, Location start, Location end) {
    2. // First we need to work out where the second location is in relation to the first.
    3. // This is simply because that if the start location had an X larger than the end,
    4. // but had a smaller y co-ordinate, then getting the blocks in this location would
    5. // work strange.
    6. double diffx = start.getX() - end.getX();
    7. double diffy = start.getY() - end.getY();
    8. double diffz = start.getZ() - end.getZ();
    9.  
    10. int incrementX = diffx>=0 ? 1 : -1;
    11. int incrementY = diffy>=0 ? 1 : -1;
    12. int incrementZ = diffz>=0 ? 1 : -1;
    13.  
    14.  
    15. // Should be fairly obvious why I am doing this.
    16. ArrayList<Block> blocks = new ArrayList<Block>();
    17. for(int xIdx = (int)start.getX(); xIdx != end.getX(); xIdx+=incrementX) {
    18. for(int yIdx = (int)start.getY(); yIdx != end.getY(); yIdx+=incrementY) {
    19. for(int zIdx = (int)start.getZ(); zIdx != end.getZ(); zIdx+=incrementZ) {
    20. blocks.add(world.getBlockAt(xIdx, yIdx, zIdx));
    21. // I think this would do it, can't test though,
    22. // it's similar to what I did before
    23. }
    24. }
    25. }
    26. // Now you just store this array somewhere safe.
    27. }
    28.  

    Not sure if this works, but it's probably similar to what I did before. This should let you create an area out of two locations.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
Thread Status:
Not open for further replies.

Share This Page