Advertisement
Guest User

Untitled

a guest
Apr 8th, 2011
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 17.22 KB | None | 0 0
  1. package com.vildaberper.Edit;
  2.  
  3. import java.util.LinkedList;
  4. import java.util.List;
  5.  
  6. import org.bukkit.Material;
  7. import org.bukkit.block.Block;
  8. import org.bukkit.block.BlockFace;
  9. import org.bukkit.command.Command;
  10. import org.bukkit.command.CommandSender;
  11. import org.bukkit.entity.Player;
  12. import org.bukkit.event.Event.Priority;
  13. import org.bukkit.event.Event.Type;
  14. import org.bukkit.plugin.java.JavaPlugin;
  15.  
  16. public class Edit extends JavaPlugin{
  17.     private final EditPlayerListener playerListener = new EditPlayerListener();
  18.     private int taskId = 0;
  19.     private List<Block> unchecked = new LinkedList<Block>();
  20.  
  21.     public void onDisable(){
  22.         this.getServer().getScheduler().cancelTask(this.taskId);
  23.         System.out.println(this.getDescription().getName() + " " + this.getDescription().getVersion() + " is disabled.");
  24.     }
  25.  
  26.     public void onEnable(){
  27.         this.getServer().getPluginManager().registerEvent(Type.PLAYER_INTERACT, playerListener, Priority.Normal, this);
  28.         System.out.println(this.getDescription().getName() + " " + this.getDescription().getVersion() + " is enabled.");
  29.     }
  30.  
  31.     public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args){
  32.         if(sender instanceof Player){
  33.             Player player = (Player) sender;
  34.  
  35.             if(!player.isOp()){
  36.                 return false;
  37.             }
  38.             if(command.getName().equalsIgnoreCase("cuboid") || command.getName().equalsIgnoreCase("c")){
  39.                 if(args.length != 1){
  40.                     return false;
  41.                 }
  42.                 if(Material.matchMaterial(args[0]) == null){
  43.                     player.sendMessage("Fail material.");
  44.                 }
  45.                 if(EditList.getSelection(player.getName()) != null){
  46.                     if(EditList.getSelection(player.getName()).getBlock1() == null || EditList.getSelection(player.getName()).getBlock2() == null){
  47.                         player.sendMessage("Fail region.");
  48.                     }
  49.                     int x1, x2, y1, y2, z1, z2;
  50.                     if(EditList.getSelection(player.getName()).getBlock1().getX() < EditList.getSelection(player.getName()).getBlock2().getX()){
  51.                         x1 = EditList.getSelection(player.getName()).getBlock1().getX();
  52.                         x2 = EditList.getSelection(player.getName()).getBlock2().getX();
  53.                     }else{
  54.                         x2 = EditList.getSelection(player.getName()).getBlock1().getX();
  55.                         x1 = EditList.getSelection(player.getName()).getBlock2().getX();
  56.                     }
  57.                     if(EditList.getSelection(player.getName()).getBlock1().getY() < EditList.getSelection(player.getName()).getBlock2().getY()){
  58.                         y1 = EditList.getSelection(player.getName()).getBlock1().getY();
  59.                         y2 = EditList.getSelection(player.getName()).getBlock2().getY();
  60.                     }else{
  61.                         y2 = EditList.getSelection(player.getName()).getBlock1().getY();
  62.                         y1 = EditList.getSelection(player.getName()).getBlock2().getY();
  63.                     }
  64.                     if(EditList.getSelection(player.getName()).getBlock1().getZ() < EditList.getSelection(player.getName()).getBlock2().getZ()){
  65.                         z1 = EditList.getSelection(player.getName()).getBlock1().getZ();
  66.                         z2 = EditList.getSelection(player.getName()).getBlock2().getZ();
  67.                     }else{
  68.                         z2 = EditList.getSelection(player.getName()).getBlock1().getZ();
  69.                         z1 = EditList.getSelection(player.getName()).getBlock2().getZ();
  70.                     }
  71.                     for(int i1 = x1; i1 <= x2; i1++){
  72.                         for(int i2 = y1; i2 <= y2; i2++){
  73.                             for(int i3 = z1; i3 <= z2; i3++){
  74.                                 player.getWorld().getBlockAt(i1, i2, i3).setType(Material.matchMaterial(args[0]));
  75.                             }
  76.                         }
  77.                     }
  78.                     return true;
  79.                 }
  80.                 player.sendMessage("Fail region.");
  81.             }else if(command.getName().equalsIgnoreCase("replace") || command.getName().equalsIgnoreCase("r")){
  82.                 if(args.length < 2){
  83.                     return false;
  84.                 }
  85.                 for(int i = 0; i < args.length; i++){
  86.                     if(Material.matchMaterial(args[i]) == null){
  87.                         player.sendMessage("Fail material.");
  88.                     }
  89.                 }
  90.                 if(EditList.getSelection(player.getName()) != null){
  91.                     if(EditList.getSelection(player.getName()).getBlock1() == null || EditList.getSelection(player.getName()).getBlock2() == null){
  92.                         player.sendMessage("Fail region.");
  93.                     }
  94.                     int x1, x2, y1, y2, z1, z2;
  95.                     if(EditList.getSelection(player.getName()).getBlock1().getX() < EditList.getSelection(player.getName()).getBlock2().getX()){
  96.                         x1 = EditList.getSelection(player.getName()).getBlock1().getX();
  97.                         x2 = EditList.getSelection(player.getName()).getBlock2().getX();
  98.                     }else{
  99.                         x2 = EditList.getSelection(player.getName()).getBlock1().getX();
  100.                         x1 = EditList.getSelection(player.getName()).getBlock2().getX();
  101.                     }
  102.                     if(EditList.getSelection(player.getName()).getBlock1().getY() < EditList.getSelection(player.getName()).getBlock2().getY()){
  103.                         y1 = EditList.getSelection(player.getName()).getBlock1().getY();
  104.                         y2 = EditList.getSelection(player.getName()).getBlock2().getY();
  105.                     }else{
  106.                         y2 = EditList.getSelection(player.getName()).getBlock1().getY();
  107.                         y1 = EditList.getSelection(player.getName()).getBlock2().getY();
  108.                     }
  109.                     if(EditList.getSelection(player.getName()).getBlock1().getZ() < EditList.getSelection(player.getName()).getBlock2().getZ()){
  110.                         z1 = EditList.getSelection(player.getName()).getBlock1().getZ();
  111.                         z2 = EditList.getSelection(player.getName()).getBlock2().getZ();
  112.                     }else{
  113.                         z2 = EditList.getSelection(player.getName()).getBlock1().getZ();
  114.                         z1 = EditList.getSelection(player.getName()).getBlock2().getZ();
  115.                     }
  116.                     for(int i1 = x1; i1 <= x2; i1++){
  117.                         for(int i2 = y1; i2 <= y2; i2++){
  118.                             for(int i3 = z1; i3 <= z2; i3++){
  119.                                 for(int i = 0; i < args.length - 1; i++){
  120.                                     if(Material.matchMaterial(args[i]) == player.getWorld().getBlockAt(i1, i2, i3).getType()){
  121.                                         player.getWorld().getBlockAt(i1, i2, i3).setType(Material.matchMaterial(args[args.length - 1]));
  122.                                     }
  123.                                 }
  124.                             }
  125.                         }
  126.                     }
  127.                     return true;
  128.                 }
  129.                 player.sendMessage("Fail region.");
  130.             }else if(command.getName().equalsIgnoreCase("walls") || command.getName().equalsIgnoreCase("w")){
  131.                 if(args.length != 1){
  132.                     return false;
  133.                 }
  134.                 if(Material.matchMaterial(args[0]) == null){
  135.                     player.sendMessage("Fail material.");
  136.                 }
  137.                 if(EditList.getSelection(player.getName()) != null){
  138.                     if(EditList.getSelection(player.getName()).getBlock1() == null || EditList.getSelection(player.getName()).getBlock2() == null){
  139.                         player.sendMessage("Fail region.");
  140.                     }
  141.                     int x1, x2, y1, y2, z1, z2;
  142.                     if(EditList.getSelection(player.getName()).getBlock1().getX() < EditList.getSelection(player.getName()).getBlock2().getX()){
  143.                         x1 = EditList.getSelection(player.getName()).getBlock1().getX();
  144.                         x2 = EditList.getSelection(player.getName()).getBlock2().getX();
  145.                     }else{
  146.                         x2 = EditList.getSelection(player.getName()).getBlock1().getX();
  147.                         x1 = EditList.getSelection(player.getName()).getBlock2().getX();
  148.                     }
  149.                     if(EditList.getSelection(player.getName()).getBlock1().getY() < EditList.getSelection(player.getName()).getBlock2().getY()){
  150.                         y1 = EditList.getSelection(player.getName()).getBlock1().getY();
  151.                         y2 = EditList.getSelection(player.getName()).getBlock2().getY();
  152.                     }else{
  153.                         y2 = EditList.getSelection(player.getName()).getBlock1().getY();
  154.                         y1 = EditList.getSelection(player.getName()).getBlock2().getY();
  155.                     }
  156.                     if(EditList.getSelection(player.getName()).getBlock1().getZ() < EditList.getSelection(player.getName()).getBlock2().getZ()){
  157.                         z1 = EditList.getSelection(player.getName()).getBlock1().getZ();
  158.                         z2 = EditList.getSelection(player.getName()).getBlock2().getZ();
  159.                     }else{
  160.                         z2 = EditList.getSelection(player.getName()).getBlock1().getZ();
  161.                         z1 = EditList.getSelection(player.getName()).getBlock2().getZ();
  162.                     }
  163.                     for(int i1 = x1; i1 <= x2; i1++){
  164.                         for(int i2 = y1; i2 <= y2; i2++){
  165.                             player.getWorld().getBlockAt(i1, i2, z1).setType(Material.matchMaterial(args[0]));
  166.                         }
  167.                     }
  168.                     for(int i1 = x1; i1 <= x2; i1++){
  169.                         for(int i2 = y1; i2 <= y2; i2++){
  170.                             player.getWorld().getBlockAt(i1, i2, z2).setType(Material.matchMaterial(args[0]));
  171.                         }
  172.                     }
  173.                     for(int i2 = y1; i2 <= y2; i2++){
  174.                         for(int i3 = z1; i3 <= z2; i3++){
  175.                             player.getWorld().getBlockAt(x1, i2, i3).setType(Material.matchMaterial(args[0]));
  176.                         }
  177.                     }
  178.                     for(int i2 = y1; i2 <= y2; i2++){
  179.                         for(int i3 = z1; i3 <= z2; i3++){
  180.                             player.getWorld().getBlockAt(x2, i2, i3).setType(Material.matchMaterial(args[0]));
  181.                         }
  182.                     }
  183.                 }
  184.                 return true;
  185.             }else if(command.getName().equalsIgnoreCase("cuboidhollow") || command.getName().equalsIgnoreCase("ch")){
  186.                 if(args.length != 1){
  187.                     return false;
  188.                 }
  189.                 if(Material.matchMaterial(args[0]) == null){
  190.                     player.sendMessage("Fail material.");
  191.                 }
  192.                 if(EditList.getSelection(player.getName()) != null){
  193.                     if(EditList.getSelection(player.getName()).getBlock1() == null || EditList.getSelection(player.getName()).getBlock2() == null){
  194.                         player.sendMessage("Fail region.");
  195.                     }
  196.                     int x1, x2, y1, y2, z1, z2;
  197.                     if(EditList.getSelection(player.getName()).getBlock1().getX() < EditList.getSelection(player.getName()).getBlock2().getX()){
  198.                         x1 = EditList.getSelection(player.getName()).getBlock1().getX();
  199.                         x2 = EditList.getSelection(player.getName()).getBlock2().getX();
  200.                     }else{
  201.                         x2 = EditList.getSelection(player.getName()).getBlock1().getX();
  202.                         x1 = EditList.getSelection(player.getName()).getBlock2().getX();
  203.                     }
  204.                     if(EditList.getSelection(player.getName()).getBlock1().getY() < EditList.getSelection(player.getName()).getBlock2().getY()){
  205.                         y1 = EditList.getSelection(player.getName()).getBlock1().getY();
  206.                         y2 = EditList.getSelection(player.getName()).getBlock2().getY();
  207.                     }else{
  208.                         y2 = EditList.getSelection(player.getName()).getBlock1().getY();
  209.                         y1 = EditList.getSelection(player.getName()).getBlock2().getY();
  210.                     }
  211.                     if(EditList.getSelection(player.getName()).getBlock1().getZ() < EditList.getSelection(player.getName()).getBlock2().getZ()){
  212.                         z1 = EditList.getSelection(player.getName()).getBlock1().getZ();
  213.                         z2 = EditList.getSelection(player.getName()).getBlock2().getZ();
  214.                     }else{
  215.                         z2 = EditList.getSelection(player.getName()).getBlock1().getZ();
  216.                         z1 = EditList.getSelection(player.getName()).getBlock2().getZ();
  217.                     }
  218.                     for(int i1 = x1; i1 <= x2; i1++){
  219.                         for(int i2 = y1; i2 <= y2; i2++){
  220.                             player.getWorld().getBlockAt(i1, i2, z1).setType(Material.matchMaterial(args[0]));
  221.                         }
  222.                     }
  223.                     for(int i1 = x1; i1 <= x2; i1++){
  224.                         for(int i2 = y1; i2 <= y2; i2++){
  225.                             player.getWorld().getBlockAt(i1, i2, z2).setType(Material.matchMaterial(args[0]));
  226.                         }
  227.                     }
  228.                     for(int i2 = y1; i2 <= y2; i2++){
  229.                         for(int i3 = z1; i3 <= z2; i3++){
  230.                             player.getWorld().getBlockAt(x1, i2, i3).setType(Material.matchMaterial(args[0]));
  231.                         }
  232.                     }
  233.                     for(int i2 = y1; i2 <= y2; i2++){
  234.                         for(int i3 = z1; i3 <= z2; i3++){
  235.                             player.getWorld().getBlockAt(x2, i2, i3).setType(Material.matchMaterial(args[0]));
  236.                         }
  237.                     }
  238.                     for(int i1 = x1; i1 <= x2; i1++){
  239.                         for(int i3 = z1; i3 <= z2; i3++){
  240.                             player.getWorld().getBlockAt(i1, y1, i3).setType(Material.matchMaterial(args[0]));
  241.                         }
  242.                     }
  243.                     for(int i1 = x1; i1 <= x2; i1++){
  244.                         for(int i3 = z1; i3 <= z2; i3++){
  245.                             player.getWorld().getBlockAt(i1, y2, i3).setType(Material.matchMaterial(args[0]));
  246.                         }
  247.                     }
  248.                 }
  249.                 return true;
  250.             }else if(command.getName().equalsIgnoreCase("cuboidwireframe") || command.getName().equalsIgnoreCase("cw")){
  251.                 if(args.length != 1){
  252.                     return false;
  253.                 }
  254.                 if(Material.matchMaterial(args[0]) == null){
  255.                     player.sendMessage("Fail material.");
  256.                 }
  257.                 if(EditList.getSelection(player.getName()) != null){
  258.                     if(EditList.getSelection(player.getName()).getBlock1() == null || EditList.getSelection(player.getName()).getBlock2() == null){
  259.                         player.sendMessage("Fail region.");
  260.                     }
  261.                     int x1, x2, y1, y2, z1, z2;
  262.                     if(EditList.getSelection(player.getName()).getBlock1().getX() < EditList.getSelection(player.getName()).getBlock2().getX()){
  263.                         x1 = EditList.getSelection(player.getName()).getBlock1().getX();
  264.                         x2 = EditList.getSelection(player.getName()).getBlock2().getX();
  265.                     }else{
  266.                         x2 = EditList.getSelection(player.getName()).getBlock1().getX();
  267.                         x1 = EditList.getSelection(player.getName()).getBlock2().getX();
  268.                     }
  269.                     if(EditList.getSelection(player.getName()).getBlock1().getY() < EditList.getSelection(player.getName()).getBlock2().getY()){
  270.                         y1 = EditList.getSelection(player.getName()).getBlock1().getY();
  271.                         y2 = EditList.getSelection(player.getName()).getBlock2().getY();
  272.                     }else{
  273.                         y2 = EditList.getSelection(player.getName()).getBlock1().getY();
  274.                         y1 = EditList.getSelection(player.getName()).getBlock2().getY();
  275.                     }
  276.                     if(EditList.getSelection(player.getName()).getBlock1().getZ() < EditList.getSelection(player.getName()).getBlock2().getZ()){
  277.                         z1 = EditList.getSelection(player.getName()).getBlock1().getZ();
  278.                         z2 = EditList.getSelection(player.getName()).getBlock2().getZ();
  279.                     }else{
  280.                         z2 = EditList.getSelection(player.getName()).getBlock1().getZ();
  281.                         z1 = EditList.getSelection(player.getName()).getBlock2().getZ();
  282.                     }
  283.                     for(int i1 = x1; i1 <= x2; i1++){
  284.                         player.getWorld().getBlockAt(i1, y1, z1).setType(Material.matchMaterial(args[0]));
  285.                     }
  286.                     for(int i1 = x1; i1 <= x2; i1++){
  287.                         player.getWorld().getBlockAt(i1, y1, z2).setType(Material.matchMaterial(args[0]));
  288.                     }
  289.                     for(int i1 = x1; i1 <= x2; i1++){
  290.                         player.getWorld().getBlockAt(i1, y2, z1).setType(Material.matchMaterial(args[0]));
  291.                     }
  292.                     for(int i1 = x1; i1 <= x2; i1++){
  293.                         player.getWorld().getBlockAt(i1, y2, z2).setType(Material.matchMaterial(args[0]));
  294.                     }
  295.                     for(int i2 = y1; i2 <= y2; i2++){
  296.                         player.getWorld().getBlockAt(x1, i2, z1).setType(Material.matchMaterial(args[0]));
  297.                     }
  298.                     for(int i2 = y1; i2 <= y2; i2++){
  299.                         player.getWorld().getBlockAt(x2, i2, z1).setType(Material.matchMaterial(args[0]));
  300.                     }
  301.                     for(int i2 = y1; i2 <= y2; i2++){
  302.                         player.getWorld().getBlockAt(x1, i2, z2).setType(Material.matchMaterial(args[0]));
  303.                     }
  304.                     for(int i2 = y1; i2 <= y2; i2++){
  305.                         player.getWorld().getBlockAt(x2, i2, z2).setType(Material.matchMaterial(args[0]));
  306.                     }
  307.                     for(int i3 = z1; i3 <= z2; i3++){
  308.                         player.getWorld().getBlockAt(x1, y1, i3).setType(Material.matchMaterial(args[0]));
  309.                     }
  310.                     for(int i3 = z1; i3 <= z2; i3++){
  311.                         player.getWorld().getBlockAt(x1, y2, i3).setType(Material.matchMaterial(args[0]));
  312.                     }
  313.                     for(int i3 = z1; i3 <= z2; i3++){
  314.                         player.getWorld().getBlockAt(x2, y1, i3).setType(Material.matchMaterial(args[0]));
  315.                     }
  316.                     for(int i3 = z1; i3 <= z2; i3++){
  317.                         player.getWorld().getBlockAt(x2, y2, i3).setType(Material.matchMaterial(args[0]));
  318.                     }
  319.                 }
  320.                 return true;
  321.             }else if(command.getName().equalsIgnoreCase("/")){
  322.                 if(!EditList.getPickaxe(player.getName())){
  323.                     player.sendMessage("Pickaxe enabled.");
  324.                     EditList.setPickaxe(player.getName(), true);
  325.                 }else{
  326.                     player.sendMessage("Pickaxe disabled.");
  327.                     EditList.setPickaxe(player.getName(), false);
  328.                 }
  329.                 return true;
  330.             }else if(command.getName().equalsIgnoreCase("//")){
  331.                 if(!EditList.getBuilder(player.getName())){
  332.                     player.sendMessage("Builder enabled.");
  333.                     EditList.setBuilder(player.getName(), true);
  334.                 }else{
  335.                     player.sendMessage("Builder disabled.");
  336.                     EditList.setBuilder(player.getName(), false);
  337.                 }
  338.                 return true;
  339.             }else if(command.getName().equalsIgnoreCase("rf")){
  340.                 unchecked.clear();
  341.                 unchecked.add(player.getTargetBlock(null, 100));
  342.                 System.out.println("starting");
  343.                 this.taskId = this.getServer().getScheduler().scheduleSyncRepeatingTask(
  344.                         this,
  345.                         new Runnable(){
  346.                             @Override
  347.                             public void run(){
  348.                                 BlockFace bf = null;
  349.                                 int count = 0;
  350.  
  351.                                 if(unchecked.size() != 0){
  352.                                     System.out.println("running");
  353.                                     for(int i = 0; i < 6; i++){
  354.                                         if(i == 0){
  355.                                             bf = BlockFace.DOWN;
  356.                                         }else if(i == 1){
  357.                                             bf = BlockFace.EAST;
  358.                                         }else if(i == 2){
  359.                                             bf = BlockFace.NORTH;
  360.                                         }else if(i == 3){
  361.                                             bf = BlockFace.SOUTH;
  362.                                         }else if(i == 4){
  363.                                             bf = BlockFace.UP;
  364.                                         }else if(i == 5){
  365.                                             bf = BlockFace.WEST;
  366.                                         }
  367.                                         if(!unchecked.get(0).getFace(bf).getType().equals(Material.AIR) && !isUnchecked(unchecked.get(0).getFace(bf))){
  368.                                             unchecked.add(unchecked.get(0).getFace(bf));
  369.                                         }
  370.                                     }
  371.                                     try{
  372.                                         unchecked.get(0).setType(Material.AIR);
  373.                                     }catch(Exception e){
  374.                                         e.printStackTrace();
  375.                                     }
  376.                                     count++;
  377.                                     unchecked.remove(0);
  378.                                     try {
  379.                                         Thread.sleep(1);
  380.                                     } catch (InterruptedException e) {
  381.                                         e.printStackTrace();
  382.                                     }
  383.                                 }else{
  384.                                     System.out.println("canceling");
  385.                                     getServer().getScheduler().cancelTask(taskId);
  386.                                 }
  387.                             }
  388.  
  389.                             private boolean isUnchecked(Block block){
  390.                                 for(int i = 0; i < unchecked.size(); i++){
  391.                                     if(unchecked.get(i).equals(block)){
  392.                                         return true;
  393.                                     }
  394.                                 }
  395.                                 return false;
  396.                             }
  397.                         },
  398.                         1L,
  399.                         1L
  400.                 );
  401.                 return true;
  402.             }
  403.         }
  404.         return false;
  405.     }
  406. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement