Help with magic carpet plugin

Discussion in 'Plugin Development' started by Trey2k, Sep 26, 2014.

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

    Trey2k

    so i am working on a magic carpet plugin so when u walk it always has a 3X3 area of glass under you but when you go forward it removes it behind you
    the code:
    Code:java
    1. package com.trey2k.lightning;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Material;
    6. import org.bukkit.block.Block;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.player.PlayerMoveEvent;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14.  
    15. public class Main extends JavaPlugin implements Listener {
    16.  
    17. boolean ison = false;
    18. public void onEnable(){
    19. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    20. }
    21.  
    22. @EventHandler
    23. public void onWalk(PlayerMoveEvent e){
    24. if(ison==false){
    25. return;
    26. }else{
    27. Block tp = e.getPlayer().getLocation().add(0, -1, 0).getBlock();
    28. Block tp1 = e.getPlayer().getLocation().add(0, -1, -1).getBlock();
    29. Block tp2 = e.getPlayer().getLocation().add(0, -1, +1).getBlock();
    30. Block tp3 = e.getPlayer().getLocation().add(-1, -1, 0).getBlock();
    31. Block tp4 = e.getPlayer().getLocation().add(+1, -1, 0).getBlock();
    32. Block tp5 = e.getPlayer().getLocation().add(-1, -1, -1).getBlock();
    33. Block tp6 = e.getPlayer().getLocation().add(-1, -1, +1).getBlock();
    34. Block tp7 = e.getPlayer().getLocation().add(+1, -1, -1).getBlock();
    35. Block tp8 = e.getPlayer().getLocation().add(+1, -1, +1).getBlock();
    36. Block behind = e.getPlayer().getLocation().add(0, -1, +2).getBlock();
    37. Block behind1 = e.getPlayer().getLocation().add(-1, -1, +2).getBlock();
    38. Block behind2 = e.getPlayer().getLocation().add(+1, -1, +2).getBlock();
    39. Block behind3 = e.getPlayer().getLocation().add(+1, -1, -2).getBlock();
    40. Block behind4 = e.getPlayer().getLocation().add(+1, -1, -2).getBlock();
    41. Block behind5 = e.getPlayer().getLocation().add(+2, -1, 0).getBlock();
    42. Block behind6 = e.getPlayer().getLocation().add(+2, -1, +1).getBlock();
    43. Block behind7 = e.getPlayer().getLocation().add(+2, -1, -1).getBlock();
    44. Block behind8 = e.getPlayer().getLocation().add(-2, -1, +1).getBlock();
    45. Block behind9 = e.getPlayer().getLocation().add(-2, -1, 0).getBlock();
    46. Block behind10 = e.getPlayer().getLocation().add(0, -1, -2).getBlock();
    47. Block behind11 = e.getPlayer().getLocation().add(+1, -1, -2).getBlock();
    48. if(!e.getPlayer().isSneaking()){
    49. tp.setType(Material.GLASS);
    50. tp1.setType(Material.GLASS);
    51. tp2.setType(Material.GLASS);
    52. tp3.setType(Material.GLASS);
    53. tp4.setType(Material.GLASS);
    54. tp5.setType(Material.GLASS);
    55. tp6.setType(Material.GLASS);
    56. tp7.setType(Material.GLASS);
    57. tp8.setType(Material.GLASS);
    58. behind.setType(Material.AIR);
    59. behind1.setType(Material.AIR);
    60. behind2.setType(Material.AIR);
    61. behind3.setType(Material.AIR);
    62. behind4.setType(Material.AIR);
    63. behind5.setType(Material.AIR);
    64. behind6.setType(Material.AIR);
    65. behind7.setType(Material.AIR);
    66. behind8.setType(Material.AIR);
    67. behind9.setType(Material.AIR);
    68. behind10.setType(Material.AIR);
    69. behind11.setType(Material.AIR);
    70. }else{
    71. return;
    72. }
    73. }
    74. }
    75. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    76. if(cmd.getName().equalsIgnoreCase("Carpet")) {
    77. Player player = (Player) sender;
    78. if(player.hasPermission("Carpet.toggle")){
    79. if(args.length==0){
    80. if(ison==true){
    81. ison=false;
    82. player.sendMessage(ChatColor.GREEN + "Carpet: " + ChatColor.GRAY + "Was Turned off!");
    83. }else{
    84. ison=true;
    85. player.sendMessage(ChatColor.GREEN + "Carpet: " + ChatColor.GRAY + "Was Turned on!");
    86. }
    87. }else if(args.length==1){
    88. if(args[0].equalsIgnoreCase("on")){
    89. ison=true;
    90. player.sendMessage(ChatColor.GREEN + "Carpet: " + ChatColor.GRAY + "Was Turned on!");
    91. }else if(args[0].equalsIgnoreCase("off")){
    92. ison=false;
    93. player.sendMessage(ChatColor.GREEN + "Carpet: " + ChatColor.GRAY + "Was Turned off!");
    94.  
    95. }else{
    96. player.sendMessage(ChatColor.GREEN + "Usage: " + ChatColor.GRAY + "/Carpet <on/off>");
    97. }
    98. }else if(args.length>1){
    99. player.sendMessage(ChatColor.GREEN + "Usage: " + ChatColor.GRAY + "/Carpet <on/off>");
    100. }
    101. }
    102. }
    103. return false;
    104. }
    105. }

    but the problem is it leaves a trail of glass when u walk a certain way:
    [​IMG]
     
  2. Offline

    97WaterPolo

    Trey2k
    From a glance I think you are missing one of the variables. You don't have 0,-1,0 that you are setting to air, but at line 27 you set it to glass.
     
  3. Offline

    Trey2k

    what i do is i only remove one line and thats the lines all around it so when u walk forward the on line that would still be there get removed
     
  4. Use a Block ArrayList, add new ones, remove the last ones.
     
Thread Status:
Not open for further replies.

Share This Page