jonassvensson4

Bukkit event help

Jul 9th, 2014
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.92 KB | None | 0 0
  1. package event.main;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.Location;
  6. import org.bukkit.Material;
  7. import org.bukkit.World;
  8. import org.bukkit.block.Block;
  9. import org.bukkit.block.Sign;
  10. import org.bukkit.command.Command;
  11. import org.bukkit.command.CommandSender;
  12. import org.bukkit.configuration.ConfigurationSection;
  13. import org.bukkit.entity.Player;
  14. import org.bukkit.event.EventHandler;
  15. import org.bukkit.event.Listener;
  16. import org.bukkit.event.block.Action;
  17. import org.bukkit.event.block.SignChangeEvent;
  18. import org.bukkit.event.player.PlayerInteractEvent;
  19. import org.bukkit.plugin.java.JavaPlugin;
  20.  
  21. public class Event extends JavaPlugin implements Listener {
  22.    
  23.     @Override
  24.     public void onEnable(){
  25.         getLogger().info("Scoreboard plugin has been Enabled");
  26.        
  27.         this.getConfig();
  28.        
  29.         this.getServer().getPluginManager().registerEvents( this, this );
  30.     }
  31.    
  32.     @Override
  33.     public void onDisable(){
  34.         getLogger().info("Scoreboard plugin has been Disabled");
  35.        
  36.         this.saveConfig();
  37.     }
  38.    
  39.     @EventHandler
  40.         public void onSignChange(SignChangeEvent event) {
  41.             Player player = event.getPlayer();
  42.             String[] lines = event.getLines();
  43.             if(player.hasPermission("event.sign.join"))  {
  44.             if(event.getLine(0).contains("[join]")) {
  45.                 if(!lines[1].isEmpty()) {
  46.                 event.setLine(0, "§2[Join]");
  47.                 player.sendMessage(ChatColor.GREEN + "Join sign created!");
  48.                 }else{
  49.                     player.sendMessage(ChatColor.RED + "Please set a valid arena name on line 2");
  50.                     event.setCancelled(true);
  51.                 }
  52.                 }
  53.             }
  54.     }
  55.    
  56.     @EventHandler
  57.     public void onPlayerInteract(PlayerInteractEvent event) {
  58.         Player player = event.getPlayer();
  59.         Block block = event.getClickedBlock();
  60.         Action action = event.getAction();
  61.         if(action == Action.RIGHT_CLICK_BLOCK) {
  62.  
  63.         if(((block.getType() == Material.SIGN)
  64.                 || (block.getType() == Material.SIGN_POST)
  65.                 || (block.getType() == Material.WALL_SIGN)
  66.                 )){
  67.            
  68.             Sign sign = (Sign) block.getState();
  69.            
  70.             String textFromSign = sign.getLine(1);
  71.             ConfigurationSection section = this.getConfig().getConfigurationSection("root.arenor");
  72.            
  73.                 if(sign.getLine(0).contains("[Join]")) {
  74.                     if(section.contains(textFromSign)) {
  75.                        
  76.                         Bukkit.dispatchCommand(player, "arena" + sign.getLine(1));
  77.                        
  78.                     //String world = section.getString("world");
  79.                      // double x = section.getDouble( "x" );
  80.                     //  double y = section.getDouble( "y" );
  81.                       // double z = section.getDouble( "z" );
  82.                        
  83.                        //player.sendMessage(ChatColor.BLUE + wCoord);
  84.                        //player.teleport( new Location( this.getServer().getWorld( world ), x, y, z ) );
  85.                        
  86.                     }else{
  87.                         player.sendMessage(ChatColor.RED + "That arena does not exist");
  88.                 }
  89.                 }
  90.             }
  91.         }
  92.     }
  93.    
  94.     public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
  95.     {
  96.         if (!(sender instanceof Player) )
  97.         {
  98.             sender.sendMessage("Player command only");
  99.             return false;
  100.         }
  101.        
  102.         Player player = (Player)sender;
  103.         // setlobby
  104.         if( commandLabel.equalsIgnoreCase( "setlobby" ) )
  105.            
  106.             if(sender.hasPermission("event.setlobby") ) {
  107.                
  108.                 if(args.length == 1) {
  109.                    
  110.                 String world = player.getLocation().getWorld().getName();
  111.                 double x = player.getLocation().getX();
  112.                 double y = player.getLocation().getY();
  113.                 double z = player.getLocation().getZ();
  114.                
  115.                 this.getConfig().set("root.lobbies." + args[0] + "-lobby.world", world);
  116.                 this.getConfig().set("root.lobbies." + args[0] + "-lobby.x", x);
  117.                 this.getConfig().set("root.lobbies." + args[0] + "-lobby.y", y);
  118.                 this.getConfig().set("root.lobbies." + args[0] + "-lobby.z", z);
  119.                
  120.                 this.saveConfig();
  121.                
  122.                 player.sendMessage(ChatColor.GOLD + "Lobby "+ ChatColor.RED + args[0] + ChatColor.GOLD + " set!");
  123.                 }
  124.                 if(args.length == 0) {
  125.  
  126.                     player.sendMessage(ChatColor.RED + "Usage:" + ChatColor.GOLD + "/setlobby " + ChatColor.RED + " <Name>");
  127.                 }
  128.                
  129.             }else{
  130.                 player.sendMessage(ChatColor.RED + "You dont have permission");
  131.             }
  132.         // setarena
  133.         if( commandLabel.equalsIgnoreCase( "setarena" ) )
  134.            
  135.             if(sender.hasPermission("event.setarena") ) {
  136.                
  137.                 if(args.length == 1) {
  138.                    
  139.                 String world = player.getLocation().getWorld().getName();
  140.                 double x = player.getLocation().getX();
  141.                 double y = player.getLocation().getY();
  142.                 double z = player.getLocation().getZ();
  143.                
  144.                 this.getConfig().set("root.arenor." + args[0] + ".world", world);
  145.                 this.getConfig().set("root.arenor." + args[0] + ".x", x);
  146.                 this.getConfig().set("root.arenor." + args[0] + ".y", y);
  147.                 this.getConfig().set("root.arenor." + args[0] + ".z", z);
  148.                
  149.                 this.saveConfig();
  150.                
  151.                 player.sendMessage(ChatColor.GOLD + "Arena "+ ChatColor.RED + args[0] + ChatColor.GOLD + " set!");
  152.                 }
  153.                 if(args.length == 0) {
  154.  
  155.                     player.sendMessage(ChatColor.RED + "Usage:" + ChatColor.GOLD + "/setarena " + ChatColor.RED + " <Name>");
  156.                 }
  157.                
  158.             }else{
  159.                 player.sendMessage(ChatColor.RED + "You dont have permission");
  160.             }
  161.         // arena
  162.         ConfigurationSection section = this.getConfig().getConfigurationSection("root.arenor");
  163.         String arena = args[0];
  164.        
  165.         if( commandLabel.equalsIgnoreCase( "arena" ) )
  166.            
  167.             if(args.length == 1) {
  168.                
  169.                 if(section.contains(arena)) {
  170.  
  171.                 String worldName = section.getString("world");
  172.                 World world = this.getServer().getWorld(worldName);
  173.                
  174.                 double x = this.getConfig().getDouble("x");
  175.                 double y = this.getConfig().getDouble("y");
  176.                 double z = this.getConfig().getDouble("z");
  177.                
  178.                 Location loc = new Location(world, x, y, z);
  179.                
  180.                 player.teleport(loc);
  181.                    player.sendMessage(ChatColor.GOLD + "Teleported to: " + ChatColor.RED + args[0]);
  182.                 }else{
  183.                     player.sendMessage(ChatColor.RED + "That arena does not exist!");
  184.                 }
  185.             }else{
  186.                 player.sendMessage(ChatColor.RED + "Usage:" + ChatColor.GOLD + "/arena " + ChatColor.RED + " <Name>");
  187.             }
  188.         return false;  
  189.     }
  190.  
  191. }
Advertisement
Add Comment
Please, Sign In to add comment