Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.bukkit.Matthijs.MarkLog;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import org.bukkit.Location;
- import org.bukkit.Server;
- import org.bukkit.entity.Player;
- import org.bukkit.event.player.PlayerChatEvent;
- import org.bukkit.event.player.PlayerEvent;
- import org.bukkit.event.player.PlayerListener;
- import org.bukkit.event.player.PlayerMoveEvent;
- /**
- * Handle events for all Player related events
- *
- * @author Matthijs
- */
- public class MarkLogPlayerListener extends PlayerListener
- {
- private final MarkLog plugin;
- private final Server server;
- final Logger logger = Logger.getLogger("Minecraft");
- public MarkLogPlayerListener(MarkLog instance)
- {
- this.plugin = instance;
- this.server = plugin.getServer();
- }
- //Insert Player related code here
- @Override
- public void onPlayerCommand(PlayerChatEvent event)
- {
- if (event.isCancelled())
- return;
- // The player that issued the command
- Player player = event.getPlayer();
- // This will contain two strings: the command, and everything else.
- String[] sects = event.getMessage().split(" +", 2);
- // This will contain all the arguments after the command, space-delimited.
- String[] args = (sects.length > 1 ? sects[1].split(" +") : new String[0]);
- // This will hold the command ID. See the Commands enum at the bottom of this class.
- Commands cmd;
- try
- {
- // Determine a matching command based on sects[0], but remove the leading "/".
- cmd = Commands.valueOf(sects[0].substring(1).toUpperCase());
- } catch (Exception ex)
- {
- // The command is either too short (Bukkit is misbehaving) or doesn't match one for which we are listening.
- return;
- }
- try
- {
- // We can use a switch because we converted the command string into an enum.
- switch (cmd) {
- case MARK :
- case MARKLOG :
- case LOG :
- String nick = player.getName();
- long timestamp = server.getTime();
- System.out.println("********MARK BY: " + nick + " ******** time:" + timestamp + "********");
- logger.log(Level.INFO, "********MARK BY: " + nick + " ******** time:" + timestamp + "********");
- server.broadcastMessage("TEST PLUGIN VAN MATTIE");
- break;
- default:
- return; // We forgot to implement a command: treat it as non-existent.
- }
- } catch (NoSuchMethodError ex)
- {
- player.sendMessage("The server is not recent enough to support " + sects[0].toLowerCase() + ".");
- } catch (Exception ex)
- {
- // Unexpected error encountered. Tell the user. Can be thrown on purpose to notify the user of syntax errors and such.
- player.sendMessage("§cError: " + ex.getMessage());
- }
- }
- private enum Commands {
- MARK, MARKLOG, LOG
- }
- }
Add Comment
Please, Sign In to add comment