'/block block X Z Y world' help

Discussion in 'Plugin Development' started by Meatiex, Aug 28, 2013.

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

    Meatiex

    I would like help making a command that is like you type in '/block glass 150 63 -17 games' and it sets 150 63 -17 in the games world to glass. Any ideas to make it exhaustible from console?
    This would be awesome. Meanwhile ill keep trying to make it work myself, Thanks! ~Meatie!
     
  2. Offline

    tommycake50

    exhaustible?
    Location l = new Location(world, x, y, z);
    l.getBlock().setType(Material.GLASS);
     
  3. Offline

    Meatiex

    yes, as a commad
     
  4. Offline

    smcerm

    Making such a command is simple enough, as tommycake50 demonstrated. But what do you mean by "exhaustible from console"?
     
  5. Offline

    chasechocolate

    smcerm I assume he means that it can be run through console.
     
  6. Offline

    Meatiex

    yes, for the use with command blocks. :D
     
  7. Offline

    chasechocolate

    Meatiex you can have it like that if you don't cast sender to Player.
     
  8. Offline

    Meatiex

    Sorry, im confused on how to create commands that use args...
     
  9. Offline

    Quantix

    Something like this should work. Note: If you don't enter integers for the coordinates the method will throw a NumberFormatException.
    Code:java
    1. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    2. if (sender instanceof ConsoleCommandSender) {
    3. ConsoleCommandSender console = (ConsoleCommandSender) sender;
    4. if (command.getName().equalsIgnoreCase("block")) {
    5. if (args.length == 5) {
    6. World world = Bukkit.getServer().getWorld(args[4);
    7. Material material = Material.matchMaterial(args[0]);
    8. int x = Integer.parseInt(args[1]);
    9. int y = Integer.parseInt(args[2]);
    10. int z = Integer.parseInt(args[3]);
    11. if (world != null && material != null) {
    12. world.getBlockAt(x, y, z).setType(material);
    13. console.sendMessage("Successfully placed block at " + x + ", " + y + ", " + z + ".");
    14. } else {
    15. console.sendMessage("Invalid arguments!");
    16. }
    17. } else {
    18. console.sendMessage(ChatColor.RED + "Please enter the material, x, y, and z coordinates and world of the block you want to change.");
    19. }
    20. }
    21. }
    22. }
     
  10. Offline

    Meatiex

    how do i define consle? is it logger?
     
  11. Offline

    Bammerbom

    Meatiex
    1. ConsoleCommandSender console = (ConsoleCommandSender) sender;
     
  12. Offline

    Meatiex

    I got a error when i ran it from command block, but from console worked fine :D
    could someone please help me fix this to work with command blocks?
    Code:java
    1. } else if (cmd.getName().equalsIgnoreCase("setblock")) {
    2. ConsoleCommandSender console = (ConsoleCommandSender) sender;
    3. if (args.length == 5) {
    4.  
    5. World world = Bukkit.getServer().getWorld(args[4]);
    6. Material material = Material.matchMaterial(args[0]);
    7. int x = Integer.parseInt(args[1]);
    8. int y = Integer.parseInt(args[2]);
    9. int z = Integer.parseInt(args[3]);
    10. if (world != null && material != null) {
    11. world.getBlockAt(x, y, z).setType(material);
    12. console.sendMessage("Successfully placed block at " + x + ", " + y + ", " + z + ".");
    13. } else {
    14. console.sendMessage("Invalid arguments!");
    15. }
    16. } else {
    17. console.sendMessage(ChatColor.RED + "Please enter the material, x, y, and z coordinates and world of the block you want to change.");
    18. }
    19. return true;
    20. }

    Code:text
    1. 18:08:05 [WARNING] CommandBlock at (1003,134,1012) failed to handle command
    2. org.bukkit.command.CommandException: Unhandled exception executing command 'setb
    3. lock' in plugin MeatiesTools v2.0
    4. at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
    5. at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:19
    6. 0)
    7. at net.minecraft.server.v1_6_R2.TileEntityCommand.a(TileEntityCommand.ja
    8. va:101)
    9. at net.minecraft.server.v1_6_R2.BlockCommand.a(BlockCommand.java:47)
    10. at net.minecraft.server.v1_6_R2.WorldServer.a(WorldServer.java:571)
    11. at net.minecraft.server.v1_6_R2.WorldServer.doTick(WorldServer.java:207)
    12.  
    13. at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:5
    14. 63)
    15. at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:2
    16. 39)
    17. at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:4
    18. 81)
    19. at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java
    20. :413)
    21. at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:5
    22. 82)
    23. Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_6_R2.command.
    24. CraftBlockCommandSender cannot be cast to org.bukkit.command.ConsoleCommandSende
    25. r
    26. at me.Meatie.plugin.main.onCommand(main.java:135)
    27. at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    28. ... 10 more
    29. >


    EDIT: I fixed it: Thanks guys :D
    Code:java
    1. } else if (cmd.getName().equalsIgnoreCase("setblock")) {
    2. if (args.length == 5) {
    3. World world = Bukkit.getServer().getWorld(args[4]);
    4. Material material = Material.matchMaterial(args[0]);
    5. int x = Integer.parseInt(args[1]);
    6. int y = Integer.parseInt(args[2]);
    7. int z = Integer.parseInt(args[3]);
    8. if (world != null && material != null) {
    9. world.getBlockAt(x, y, z).setType(material);
    10. }
    11. }
    12. return true;
    13. }


    oops, One more question. How would I set down things like Stairs, pumpkins, logs, chests or wool with difrent media? (directions or wool color) Thanks!

    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