Finding Center

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

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

    WeDaBeast

    How would I set the block type at "loc" then add 1?



    Code:java
    1. package com.gmail.TheDevelopingGod.Middle;
    2.  
    3. import com.worldcretornica.plotme.Plot;
    4. import com.worldcretornica.plotme.PlotManager;
    5. import com.worldcretornica.plotme.PlotMapInfo;
    6. import com.worldcretornica.plotme.PlotMe;
    7.  
    8. import org.bukkit.Bukkit;
    9. import org.bukkit.ChatColor;
    10. import org.bukkit.Location;
    11. import org.bukkit.Material;
    12. import org.bukkit.World;
    13. import org.bukkit.block.Block;
    14. import org.bukkit.command.Command;
    15. import org.bukkit.command.CommandExecutor;
    16. import org.bukkit.command.CommandSender;
    17. import org.bukkit.entity.Player;
    18.  
    19. import java.util.UUID;
    20.  
    21. import static com.worldcretornica.plotme.PlotManager.*;
    22.  
    23. /**
    24. * Created by John on 6/12/2014.
    25. */
    26.  
    27. public class Commands implements CommandExecutor {
    28.  
    29.  
    30. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    31. if (cmd.getName().equalsIgnoreCase("middle")){
    32. if (sender instanceof Player) {
    33. Player player = (Player) sender;
    34. if (player.hasPermission("middle.*")) {
    35.  
    36. String id = PlotManager.getPlotId(player.getLocation());
    37.  
    38. Plot plot = PlotManager.getPlotById(player,id);
    39.  
    40. String name = player.getName();
    41.  
    42. if(plot.owner.equalsIgnoreCase(name)){
    43.  
    44.  
    45. World w = player.getWorld();
    46. Location top = PlotManager.getPlotTopLoc(w, id);
    47. Location bottom = PlotManager.getPlotBottomLoc(w, id);
    48.  
    49.  
    50. int tx = top.getBlockX();
    51. int bx = bottom.getBlockX();
    52. int tz = top.getBlockZ();
    53. int bz = bottom.getBlockZ();
    54. int ty = top.getBlockY();
    55. int by = bottom.getBlockY();
    56.  
    57. int midX = (top.getBlockX() + bottom.getBlockX()) / 2;
    58.  
    59. int loc = (tz + bz) / 2;
    60.  
    61.  
    62.  
    63.  
    64.  
    65.  
    66. Location locate = new Location(w, tx, ty, tz);
    67.  
    68.  
    69. ((Block) locate).setType(Material.REDSTONE_BLOCK);
    70.  
    71. for(int i = 0; i < 64; i++){
    72.  
    73. //loc.setType(Material.REDSTONE_BLOCK); how to
    74. }
    75.  
    76.  
    77.  
    78. sender.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.DARK_GREEN + "x" + ChatColor.DARK_GRAY + "]" +ChatColor.GRAY+" The center of your plot has been marked for 5 seconds.");
    79.  
    80.  
    81. Bukkit.getScheduler().runTaskLater(Main.getPlugin(), new Runnable() {
    82. @Override
    83. public void run() {
    84.  
    85. Location locate = new Location(w, tx, ty, tz);
    86. locate.setY(locate.getY() + 1);
    87. ((Block) locate).setType(Material.AIR);
    88.  
    89.  
    90. }
    91. }, 100L);
    92.  
    93.  
    94. }else{
    95. sender.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.RED + "x" + ChatColor.DARK_GRAY + "]" +ChatColor.GRAY+" You must be the owner of this plot to do that");
    96.  
    97. }
    98. }
    99. }
    100.  
    101. }
    102. return false;
    103. }
    104. }


    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  2. WeDaBeast didnt looked at the code, but if you want to set the block in certain location and add 1 to it,
    loc.getBlock().setType(...);
    loc.add(x, y, z); // OR loc = loc.add(x, y, z);
     
Thread Status:
Not open for further replies.

Share This Page