Mattie

Mattie

Jan 20th, 2011
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.70 KB | None | 0 0
  1. package com.bukkit.Matthijs.MarkLog;
  2.  
  3. import java.util.logging.Level;
  4. import java.util.logging.Logger;
  5.  
  6. import org.bukkit.Location;
  7. import org.bukkit.Server;
  8. import org.bukkit.entity.Player;
  9. import org.bukkit.event.player.PlayerChatEvent;
  10. import org.bukkit.event.player.PlayerEvent;
  11. import org.bukkit.event.player.PlayerListener;
  12. import org.bukkit.event.player.PlayerMoveEvent;
  13.  
  14. /**
  15.  * Handle events for all Player related events
  16.  *
  17.  * @author Matthijs
  18.  */
  19. public class MarkLogPlayerListener extends PlayerListener
  20. {
  21.     private final MarkLog   plugin;
  22.     private final Server    server;
  23.     final Logger logger = Logger.getLogger("Minecraft");
  24.  
  25.     public MarkLogPlayerListener(MarkLog instance)
  26.     {
  27.         this.plugin = instance;
  28.         this.server = plugin.getServer();
  29.     }
  30.  
  31.     //Insert Player related code here
  32.  
  33.     @Override
  34.     public void onPlayerCommand(PlayerChatEvent event)
  35.     {
  36.         if (event.isCancelled())
  37.             return;
  38.  
  39.         // The player that issued the command
  40.         Player player = event.getPlayer();
  41.         // This will contain two strings: the command, and everything else.
  42.         String[] sects = event.getMessage().split(" +", 2);
  43.         // This will contain all the arguments after the command, space-delimited.
  44.         String[] args = (sects.length > 1 ? sects[1].split(" +") : new String[0]);
  45.         // This will hold the command ID.  See the Commands enum at the bottom of this class.
  46.         Commands cmd;
  47.  
  48.         try
  49.         {
  50.             // Determine a matching command based on sects[0], but remove the leading "/".
  51.             cmd = Commands.valueOf(sects[0].substring(1).toUpperCase());
  52.         } catch (Exception ex)
  53.         {
  54.             // The command is either too short (Bukkit is misbehaving) or doesn't match one for which we are listening.
  55.             return;
  56.         }
  57.  
  58.         try
  59.         {
  60.             // We can use a switch because we converted the command string into an enum.
  61.             switch (cmd) {
  62.             case MARK :
  63.  
  64.             case MARKLOG :
  65.  
  66.             case LOG : 
  67.                 String nick = player.getName();
  68.                 long timestamp = server.getTime();
  69.                 System.out.println("********MARK BY: " + nick + " ******** time:" + timestamp + "********");
  70.                 logger.log(Level.INFO, "********MARK BY: " + nick + " ******** time:" + timestamp + "********");
  71.                 server.broadcastMessage("TEST PLUGIN VAN MATTIE");
  72.                
  73.             break;
  74.  
  75.             default:
  76.                 return; // We forgot to implement a command: treat it as non-existent.
  77.             }
  78.         } catch (NoSuchMethodError ex)
  79.         {
  80.            
  81.             player.sendMessage("The server is not recent enough to support " + sects[0].toLowerCase() + ".");
  82.         } catch (Exception ex)
  83.         {
  84.             // Unexpected error encountered.  Tell the user.  Can be thrown on purpose to notify the user of syntax errors and such.
  85.             player.sendMessage("§cError: " + ex.getMessage());
  86.         }
  87.  
  88.     }
  89.  
  90.     private enum Commands {
  91.         MARK, MARKLOG, LOG
  92.     }
  93. }
Add Comment
Please, Sign In to add comment