WorldEdit from Console

Discussion in 'Plugin Development' started by Guccify, Jun 16, 2014.

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

    Guccify

    I'm developing a plugin that requires the constant change of blocks in the world. To accomplish this, I've been doing something like this:
    Code:java
    1.  
    2. List<Player> plist = Bukkit.getServer().getWorld(key).getPlayers();
    3. plist.get(0).setOp(true);
    4. Bukkit.getServer().dispatchCommand(plist.get(0), "/pos1 " + c1);
    5. Bukkit.getServer().dispatchCommand(plist.get(0), "/pos2 " + c2);
    6. Bukkit.getServer().dispatchCommand(plist.get(0), "/replace grass stone,dirt");
    7.  
    8. plist.get(0).setOp(false);
    9.  


    As you can't run any WorldEdit commands from console. This works without issue, however it spams whichever player that is selected, notifying them of the changes and selections. These commands are run about every second, so you can probably see how that'd be annoying.

    So, some ideas for solutions:
    -How can I disable the messages?
    -How can I create a fake sender so nobody is spammed?
    -How could I do this with the Block class?

    Thanks.
     
  2. Offline

    JBoss925

    It's semi-simple to make a block iterator even if it's 3d. Then all you have to do is run your own command through the console (similar to //replace), giving the world, pos1 coords and pos2 coords, as well as the block you want to change from and the blocks you want it to change to. Now you may be wondering what you would use for varying block types, well you could put them all in commas without spaces as 1 argument but I would put them all as different arguments because that allows you to use java.util.random. Let's say we had this command:

    /replace world 10 20 50 40 25 70 grass stone dirt

    1) Check the command is replace
    2)
    Code:java
    1. World w = Bukkit.getServer().getWorld(args[0]);

    3)
    Code:java
    1. Block pos1 = w.getBlockAt(args[1].intValue(), args[2].intValue(), args[3].intValue());

    4)
    Code:java
    1. Block pos1 = w.getBlockAt(args[4].intValue(), args[5].intValue(), args[6].intValue());

    5)
    Code:java
    1. Material orig = Material.getMaterial(args[7]);

    6a)
    Code:java
    1. if(args.length == 9){
    2. Material change = Material.getMaterial(args[8]);
    3. }

    6a2) Now iterate through the blocks, check if the block type is the original and if so change it to the change block type.
    6b)
    Code:java
    1. if(args.length > 9){
    2. Random gen = new Random();
    3. int prevargs = 8;
    4. int chosenmaterial = gen.nextInt(args.length - prevargs) + 9;
    5. Material changedynamic = Material.getMaterial(args[chosenmaterial]);
    6. }

    6b2) Now iterate through the blocks and after every iteration run that code again to get the change dynamic block type.
     
  3. Offline

    Razen

    I've got a question related to this.
    I search for a method to run Worldedit-Commands from the Console. Especially pos1, pos2 and set/replace...
    The major Problem here is to tell the console, which world to run the command in.
    1) Bukkit.getServer().dispatchCommand(plist.get(0), "/pos1 " + c1);
    I see you handover another Variable with the Command - what is this variable? The worldname?
    2) /replace world 10 20 50 40 25 70 grass stone dirt
    Is this a way to include the world in the Worldedit.Commands?
     
  4. Offline

    fireblast709

    Guccify you do know that you don't need to use commands to use WE. WE has an API for a reason :p
     
    korikisulda likes this.
Thread Status:
Not open for further replies.

Share This Page