Advertisement
morphesus

MessIt Main Class

Apr 24th, 2013
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.76 KB | None | 0 0
  1. package de.mdstv.bukkit.messit;
  2.  
  3. import java.io.File;
  4.  
  5. import org.bukkit.ChatColor;
  6. import org.bukkit.OfflinePlayer;
  7. import org.bukkit.command.Command;
  8. import org.bukkit.command.CommandSender;
  9. import org.bukkit.configuration.file.YamlConfiguration;
  10. import org.bukkit.entity.Player;
  11. import org.bukkit.plugin.java.JavaPlugin;
  12.  
  13. public class MessIt extends JavaPlugin {
  14.     private File              playerOnlineData;
  15.     private YamlConfiguration playerOnlineConfig;
  16.    
  17.     private PlayerListener pl = new PlayerListener(this);
  18.    
  19.     @Override
  20.     public void onEnable() {
  21.         this.playerOnlineData   = new File(getDataFolder(), "playerOnline.yml");
  22.         this.playerOnlineConfig = YamlConfiguration.loadConfiguration(this.playerOnlineData);
  23.        
  24.         // Init Listener
  25.         this.getServer().getPluginManager().registerEvents(this.pl, this);
  26.     }
  27.    
  28.     @Override
  29.     public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
  30.         if (label.equalsIgnoreCase("ptime")) {
  31.             if (sender.hasPermission("messit.ptime")) {
  32.                 if (args.length == 2) {
  33.                     OfflinePlayer op     = this.getServer().getOfflinePlayer(args[0]);
  34.                     String        action = args[1];
  35.                    
  36.                     if (action.equalsIgnoreCase("session")) {
  37.                         if (op.isOnline()) {
  38.                             Player p    = op.getPlayer();
  39.                             long   time = this.pl.getPlayerCurrentOnlineTime(p);
  40.                            
  41.                             sender.sendMessage(String.format("%s ist bereits %s online", op.getName(), this.pl.formatTime(time)));
  42.                            
  43.                             return true;
  44.                         } else {
  45.                             sender.sendMessage(ChatColor.RED + String.format("%s ist nicht online", op.getName()));
  46.                            
  47.                             return true;
  48.                         }
  49.                     } else if (action.equalsIgnoreCase("entire")) {
  50.                         long entireTime = this.pl.getPlayerEntireOnlineTime(op);
  51.                         if (entireTime > 0L) {
  52.                             sender.sendMessage(String.format("%s hat bereits %s gespielt", op.getName(), this.pl.formatTime(entireTime)));
  53.                             return true;
  54.                         } else {
  55.                             sender.sendMessage(ChatColor.GOLD + "Dieser Spieler war entweder noch nie auf diesem Server oder ist noch nicht gelistet.");
  56.                             return true;
  57.                         }
  58.                     } else {
  59.                         // Show usage
  60.                         return false;
  61.                     }
  62.                 } else {
  63.                     // Show usage
  64.                     return false;
  65.                 }
  66.             } else {
  67.                 sender.sendMessage(ChatColor.DARK_RED + "Sorry, no permission :(");
  68.                 return true;
  69.             }
  70.         } else {
  71.             return super.onCommand(sender, command, label, args);
  72.         }
  73.     }
  74.    
  75.     /**
  76.      * Returns the {@link YamlConfiguration} which contains the online times
  77.      * @return A {@link YamlConfiguration} with the online times
  78.      */
  79.     public YamlConfiguration getTimeConf() {
  80.         return this.playerOnlineConfig;
  81.     }
  82.  
  83.     /**
  84.      * Returns the {@link File} for the online time {@link YamlConfiguration}
  85.      * @return The {@link File} for the online time {@link YamlConfiguration}
  86.      */
  87.     public File getTimeConfFile() {
  88.         return this.playerOnlineData;
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement