jonassvensson4

Bukkit event

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