Spawn field

Discussion in 'Plugin Development' started by SynteX, Jan 24, 2014.

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

    SynteX

    I am making a plugin for a tnt spleef :D.
    But how do i spawn a field made of blocks?
     
  2. SynteX
    Use the getBlockAt(Location) method in World class, then modify its type. This works as setting a block in the world. Then you'll want to use some kind of loop to set a field of them.

    For a basic square platform, use this (pseudo) code.
    Code:
    for x = xMin to xMax
        for z = zMin to zMax
            set block at(x, original y, z)
     
  3. Offline

    SynteX

    Thanks i've made this code so far i know:

    Code:java
    1. public void makeArena(){
    2. for (int x = -174 to -207){
    3. for (int z = 204 to 170){
    4. World world = Bukkit.getWorld("spawn");
    5. world.getBlockAt(x, 30, z).setType(Material.TNT);
    6. }
    7. }
    8. }


    I don't know how to fix this?
     
  4. SynteX
    That was a pseudo example, you were supposed to turn it into working code.
    Code:
    public void makeArena(Location start, Location end) {
        int aX = Math.max(start.getBlockX() end.getBlockX());
        int bX = Math.min(start.getBlockX() end.getBlockX());
     
        int aZ = Math.max(start.getBlockZ() end.getBlockZ());
        int bZ = Math.min(start.getBlockZ() end.getBlockZ());
     
        for(int x = bX; x <= aX; x++) {
            for(int z = bZ; z <= aZ; z++) {
                Block block = start.getWorld().getBlockAt(x, start.getBlockY(), z);
                block.setType(Material.TNT);
            }
        }
    }
    I wrote it on my phone, so something might be wrong. Just call that method with the start and end locations (the two corners), and it should work.
     
  5. Offline

    SynteX

    Assist

    Sorry man i'm new to Java and i got an error with:
    Code:java
    1. int aX = Math.max(start.getBlockX() end.getBlockX());

    So i've fixt this with an , so now it is:
    Code:java
    1. int aX = Math.max(start.getBlockX(), end.getBlockX());

    But i got an error on the start of the code:
    Code:java
    1. public void makeArena(-174 30 204, -207 30 170) {
     
  6. SynteX
    Sorry, I missed the commas there.

    As for your second problem, make a Location out of the coordinates, then call the makeArena() method using those.
    Code:
    Location start = new Location(world, x, y, z);
    Location end = new Location(world, x, y, z);
     
    makeArena(start, end);
    Replace 'world' with your world, for instance, Bukkit.getWorld("world"). Then replace the first x, y and z with the first corner coordinates, and second x, y, z with the second corner coordinates.
     
  7. Offline

    SynteX

    Assist

    Thanks :D
    I think my code will work for now.
    I don't have errors now i need to test it on my server.

    Assist
    I've got a new problem when i make a command:
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    2. if (commandLabel.equalsIgnoreCase("tntm")){
    3. sender.sendMessage("Yeey ene command");
    4. if (args.length == 1){
    5. sender.sendMessage("Yes");
    6. } else {
    7. sender.sendMessage("Wrong");
    8. }
    9. }
    10. return false;
    11. }


    This works fine but it also give the usage in the chat?

    plugin.yml
    Code:
    name: TNT speelf
    main: plugin.arena
    version: 0.1
    description: >
                Menno's plugin.
    commands:
        tntm:
            description: Description
            usage: /tntm [optional, arguments]
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  8. SynteX
    I'm not too sure about that, I usually use my own command system. What happens if you return true after you send the "Yes" message?
     
  9. Offline

    SynteX

    Thanks it works
     
Thread Status:
Not open for further replies.

Share This Page