Advertisement
Guest User

Untitled

a guest
Dec 24th, 2012
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.87 KB | None | 0 0
  1. package de.DeadCrafter.Core.commands;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.Location;
  6. import org.bukkit.command.Command;
  7. import org.bukkit.command.CommandExecutor;
  8. import org.bukkit.command.CommandSender;
  9. import org.bukkit.entity.Player;
  10.  
  11. import com.sk89q.worldedit.BlockVector;
  12. import com.sk89q.worldedit.bukkit.selections.Selection;
  13. import com.sk89q.worldguard.domains.DefaultDomain;
  14. import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
  15.  
  16. import de.DeadCrafter.Core.Main;
  17.  
  18. public class ProtectCommand implements CommandExecutor {
  19.    
  20.     public Main plugin;
  21.    
  22.     public ProtectCommand(Main main) {
  23.         plugin = main;
  24.         main.getCommand("protect").setExecutor(this);
  25.     }
  26.    
  27.     public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
  28.         Player p;
  29.         if(!(sender instanceof Player)) {
  30.             sender.sendMessage(plugin.notPlayer);
  31.             return true;
  32.         }
  33.         p = (Player) sender;
  34.        
  35.         if((cmd.getName().equalsIgnoreCase("p")) || (cmd.getName().equalsIgnoreCase("protect"))) {
  36.            
  37.             if(!p.hasPermission("dc.mod")) {
  38.                 p.sendMessage(plugin.nopermissions);
  39.                 return true;
  40.             }
  41.            
  42.             if(args.length == 0) {
  43.                 p.sendMessage(plugin.prefix + ChatColor.AQUA + "Verwendung: " + ChatColor.GREEN + "/protect <Region-ID> [Weiterer Spieler]");
  44.                 return true;
  45.             }
  46.            
  47.             if(args.length == 1) {
  48.                 Selection sel = plugin.wep.getSelection(p);
  49.                
  50.                 if(plugin.wgp.getGlobalRegionManager().get(sel.getWorld()).hasRegion(args[0])) {
  51.                     p.sendMessage(plugin.prefix + ChatColor.RED + "Diese Region exestiert bereits!");
  52.                     return true;
  53.                 }
  54.                 if(sel == null) {
  55.                     p.sendMessage(plugin.prefix + ChatColor.RED + "Du musst zwei Punkte auswählen um fortzufahren!");
  56.                     return true;
  57.                 }
  58.                 ProtectedCuboidRegion region = new ProtectedCuboidRegion(args[0], BukkitToWorldGuard(sel.getMinimumPoint()), BukkitToWorldGuard(sel.getMaximumPoint()));
  59.                 DefaultDomain dDomain = new DefaultDomain();
  60.                 dDomain.addPlayer(p.getName());
  61.                 region.setOwners(dDomain);
  62.                 plugin.wgp.getGlobalRegionManager().get(sel.getWorld()).addRegion(region);
  63.                 p.sendMessage(plugin.prefix + ChatColor.GREEN + "Du hast die Region " + ChatColor.BLUE + region.getId() + ChatColor.GREEN + " erfolgreich erstellt.");
  64.                 return true;
  65.             }
  66.            
  67.             if(args.length == 2) {
  68.                 Player target = Bukkit.getPlayer(args[1]);
  69.                
  70.                 if(target == null) {
  71.                     p.sendMessage(plugin.playerNotFound);
  72.                     return true;
  73.                 }
  74.                
  75.                 Selection sel = plugin.wep.getSelection(p);
  76.                
  77.                 if(plugin.wgp.getGlobalRegionManager().get(sel.getWorld()).hasRegion(args[0])) {
  78.                     p.sendMessage(plugin.prefix + ChatColor.RED + "Diese Region exestiert bereits!");
  79.                     return true;
  80.                 }
  81.                 if(sel == null) {
  82.                     p.sendMessage(plugin.prefix + ChatColor.RED + "Du musst zwei Punkte auswählen um fortzufahren!");
  83.                     return true;
  84.                 }
  85.                 ProtectedCuboidRegion region = new ProtectedCuboidRegion(args[0], BukkitToWorldGuard(sel.getMinimumPoint()), BukkitToWorldGuard(sel.getMaximumPoint()));
  86.                 DefaultDomain dDomain = new DefaultDomain();
  87.                 dDomain.addPlayer(p.getName());
  88.                 dDomain.addPlayer(target.getName());
  89.                 region.setOwners(dDomain);
  90.                 plugin.wgp.getGlobalRegionManager().get(sel.getWorld()).addRegion(region);
  91.                 p.sendMessage(plugin.prefix + ChatColor.GREEN + "Du hast die Region " + ChatColor.BLUE + region.getId() + ChatColor.GREEN + " erfolgreich erstellt und den Spieler " + target.getName() + " zur Protection hinzugefügt!");
  92.                 return true;
  93.             }
  94.            
  95.             if(args.length >2) {
  96.                 p.sendMessage(plugin.prefix + ChatColor.AQUA + "Verwendung: " + ChatColor.GREEN + "/protect <Region-ID> [Weiterer Spieler]");
  97.                 return true;
  98.             }
  99.            
  100.         }
  101.        
  102.         return false;
  103.     }
  104.    
  105.     private BlockVector BukkitToWorldGuard(Location loc) {
  106.        
  107.         return BlockVector.toBlockPoint(loc.getX(), loc.getY(), loc.getZ());
  108.     }
  109.  
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement