Advertisement
Jnk1296

IP-Check Main File

Jun 20th, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.34 KB | None | 0 0
  1. package net.risenphoenix.jnk.ipcheck;
  2.  
  3. import net.risenphoenix.jnk.ipcheck.commands.CommandManager;
  4. import net.risenphoenix.jnk.ipcheck.commands.IpcCommand;
  5. import net.risenphoenix.jnk.ipcheck.configuration.ConfigurationManager;
  6. import net.risenphoenix.jnk.ipcheck.database.DatabaseManager;
  7. import net.risenphoenix.jnk.ipcheck.listeners.PlayerJoinListener;
  8. import net.risenphoenix.jnk.ipcheck.listeners.PlayerLoginListener;
  9. import net.risenphoenix.jnk.ipcheck.logging.DateStamp;
  10. import net.risenphoenix.jnk.ipcheck.logging.ErrorLogger;
  11. import net.risenphoenix.jnk.ipcheck.translation.TranslationManager;
  12. import org.bukkit.Bukkit;
  13. import org.bukkit.ChatColor;
  14. import org.bukkit.command.Command;
  15. import org.bukkit.command.CommandSender;
  16. import org.bukkit.event.EventHandler;
  17. import org.bukkit.event.EventPriority;
  18. import org.bukkit.event.Listener;
  19. import org.bukkit.event.player.PlayerJoinEvent;
  20. import org.bukkit.event.player.PlayerLoginEvent;
  21. import org.bukkit.plugin.java.JavaPlugin;
  22.  
  23. /**
  24.  * @version 1.3.1
  25.  * @author Jacob Keep (Jnk1296), FR34KYN01535
  26.  */
  27.  
  28. public class IPcheck extends JavaPlugin implements Listener{
  29.     public static IPcheck Instance;
  30.    
  31.     public final static String PLUG_NAME = "[IP-Check] ";
  32.     public final static String ROOT_COMMAND = "c";
  33.    
  34.     //Configuration
  35.     public ConfigurationManager Configuration;
  36.  
  37.     //Database
  38.     public DatabaseManager Database;
  39.    
  40.     //Commands
  41.     public CommandManager Commands;
  42.    
  43.     //Translation
  44.     public TranslationManager Translation;
  45.    
  46.  
  47.     //Event Listeners
  48.     public static PlayerLoginListener PLL = new PlayerLoginListener();
  49.     public static PlayerJoinListener PJL = new PlayerJoinListener();
  50.  
  51.  
  52.     //Methods
  53.     // Called when plugin is enabled
  54.     @Override
  55.     public void onEnable() {
  56.         saveDefaultConfig(); // Create config if there is none
  57.         this.Instance=this;
  58.         Configuration = new ConfigurationManager();
  59.         Translation = new TranslationManager(getConfig().getString("language"));
  60.         Database = new DatabaseManager(getConfig().getBoolean("use-mysql"));
  61.         Commands = new CommandManager();
  62.        
  63.         getServer().getPluginManager().registerEvents(this, this); // Register the Player Login Listener
  64.         showRandomMessage();
  65.     }
  66.    
  67.     private void showRandomMessage(){
  68.         DateStamp ds = new DateStamp();
  69.         String random = RandomMessages.getSeasonalMessage(ds.getCustomStamp("MM-dd")); // Is there an overriding message coded for this date?
  70.         if (random != null) {
  71.             Bukkit.getLogger().info(random);
  72.         } else {
  73.             Bukkit.getLogger().info(PLUG_NAME + RandomMessages.getRandomMessage()); // A Nice random Message
  74.         }
  75.     }
  76.  
  77.     // Called when plugin is disabled
  78.     @Override
  79.     public void onDisable() {
  80.         Database.close();
  81.     }
  82.  
  83.     // Event Handler for PlayerLoginEvents
  84.     @EventHandler (priority = EventPriority.MONITOR)
  85.     public void onPlayerLogin(PlayerLoginEvent e) {
  86.         PLL.execute(e);
  87.     }
  88.  
  89.     // Event Handler for PlayerJoinEvents
  90.     @EventHandler (priority = EventPriority.MONITOR)
  91.     public void onPlayerJoin(PlayerJoinEvent e) {
  92.         PJL.execute(e);
  93.     }
  94.  
  95.     // Called when a command is entered
  96.     @Override
  97.     public boolean onCommand(CommandSender sender, Command root, String commandLabel, String[] args) {
  98.         if (root.getName().equalsIgnoreCase(ROOT_COMMAND)) {
  99.             if (sender.hasPermission("ipcheck.use") || sender.isOp()) {
  100.                 IpcCommand command = Commands.executeCommand(args,sender);
  101.  
  102.                 if (command == null) {
  103.                     return false;
  104.                 }
  105.                
  106.                 try {
  107.                     command.execute(sender, commandLabel, args); // Execute
  108.                     return true;
  109.                 } catch (Exception e) {
  110.                     ErrorLogger EL = new ErrorLogger();
  111.                     EL.execute(e);
  112.                     sender.sendMessage(ChatColor.GOLD + PLUG_NAME + ChatColor.YELLOW + Translation.getTranslation("ERROR_LOG_RMDR"));
  113.                 } finally {
  114.                     return true;
  115.                 }
  116.             } else {
  117.                 sender.sendMessage(Translation.getTranslation("NO_PERM_ERR"));
  118.                 return true;
  119.             }
  120.         }
  121.  
  122.         return false;
  123.     }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement