GJ před 13 roky
rodič
revize
bce418bee8

+ 102 - 80
src/main/java/com/gmail/nossr50/Users.java

@@ -1,114 +1,136 @@
 package com.gmail.nossr50;
 
 import java.io.*;
-import java.util.Properties;
 import java.util.logging.Logger;
 import java.util.HashMap;
 
-import org.bukkit.entity.*;
+import org.bukkit.entity.Player;
 import com.gmail.nossr50.datatypes.PlayerProfile;
 
-
 public class Users {
     private static volatile Users instance;
     protected static final Logger log = Logger.getLogger("Minecraft");
+
     String location = "plugins/mcMMO/FlatFileStuff/mcmmo.users";
     String directory = "plugins/mcMMO/FlatFileStuff/";
     String directoryb = "plugins/mcMMO/FlatFileStuff/Leaderboards/";
-    
-    //public static ArrayList<PlayerProfile> players;
+
     public static HashMap<Player, PlayerProfile> players = new HashMap<Player, PlayerProfile>();
-    private Properties properties = new Properties();
-    
-    //To load
-    public void load() throws IOException {
-        properties.load(new FileInputStream(location));
-    }
-    //To save
-    public void save() 
-    {
-        try 
-        {
-	        properties.store(new FileOutputStream(location), null);
-	        }catch(IOException ex) {
-	        }
-    }
-    
-    public void loadUsers()
-    {
-    	new File(directory).mkdir();
-    	new File(directoryb).mkdir();
+
+    /**
+     * Load users.
+     */
+    public void loadUsers() {
+        new File(directory).mkdir();
+        new File(directoryb).mkdir();
         File theDir = new File(location);
-		if(!theDir.exists())
-		{
-			try {
-				FileWriter writer = new FileWriter(theDir);
-				writer.close();
-			} catch (IOException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
-		}
+
+        if (!theDir.exists()) {
+            try {
+                FileWriter writer = new FileWriter(theDir);
+                writer.close();
+            }
+            catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
     }
 
-	
-    public static void addUser(Player player)
-    {
-    	if(!players.containsKey(player)) 
-    		players.put(player, new PlayerProfile(player.getName()));
+    /**
+     * Add a new user.
+     *
+     * @param player The player to create a user record for
+     */
+    public static void addUser(Player player) {
+        if (!players.containsKey(player)) {
+            players.put(player, new PlayerProfile(player.getName()));
+        }
     }
-    public static void clearUsers()
-    {
-    	players.clear();
+
+    /**
+     * Clear all users.
+     */
+    public static void clearUsers() {
+        players.clear();
     }
-    public static HashMap<Player, PlayerProfile> getProfiles(){
-    	return players;
+
+    /**
+     * Get all PlayerProfiles.
+     *
+     * @return a HashMap containing the PlayerProfile of everyone in the database
+     */
+    public static HashMap<Player, PlayerProfile> getProfiles() {
+        return players;
     }
-    
-    public static void removeUser(Player player)
-    {    	
-    	//Only remove PlayerProfile if user is offline and we have it in memory
-    	if(!player.isOnline() && players.containsKey(player))
-    	{
-	    	players.get(player).save();
-	    	players.remove(player);
-    	}
+
+    /**
+     * Remove a user from the database.
+     *
+     * @param player The player to remove
+     */
+    public static void removeUser(Player player) {
+
+        //Only remove PlayerProfile if user is offline and we have it in memory
+        if (!player.isOnline() && players.containsKey(player)) {
+            players.get(player).save();
+            players.remove(player);
+        }
     }
-    
-    public static void removeUserByName(String playerName)
-    {
+
+    /**
+     * Remove a user from the DB by name.
+     *
+     * @param playerName The name of the player to remove
+     */
+    public static void removeUserByName(String playerName) {
         Player target = null;
-        for(Player player : players.keySet())
-        {
+
+        for (Player player : players.keySet()) {
             PlayerProfile PP = players.get(player);
-            if(PP.getPlayerName().equals(playerName))
-            {
+
+            if (PP.getPlayerName().equals(playerName)) {
                 target = player;
             }
         }
-        
+
         players.remove(target);
     }
 
-    public static PlayerProfile getProfile(Player player){
-    	if(players.get(player) != null)
-    		return players.get(player);
-    	else
-    	{
-    		players.put(player, new PlayerProfile(player.getName()));
-    		return players.get(player);
-    	}
+    /**
+     * Get the profile of an online player.
+     *
+     * @param player The player whose profile to retrieve
+     * @return the player's profile
+     */
+    public static PlayerProfile getProfile(Player player) {
+        if(players.get(player) != null) {
+            return players.get(player);
+        }
+        else {
+            players.put(player, new PlayerProfile(player.getName()));
+            return players.get(player);
+        }
     }
-    
-    public static PlayerProfile getOfflineProfile(String playerName){
+
+    /**
+     * Get the profile of an offline player.
+     *
+     * @param playerName Name of the player whose profile to retrieve
+     * @return the player's profile
+     */
+    public static PlayerProfile getOfflineProfile(String playerName) {
         return new PlayerProfile(playerName, false);
     }
-    
-    public static Users getInstance() {
-		if (instance == null) {
-			instance = new Users();
-		}
-		return instance;
-	}
 
-}
+    /**
+     * Get an instance of this class.
+     *
+     * @return an instance of this class
+     */
+    public static Users getInstance() {
+        if (instance == null) {
+            instance = new Users();
+        }
+        return instance;
+    }
+}

+ 57 - 22
src/main/java/com/gmail/nossr50/mcPermissions.java

@@ -2,118 +2,153 @@ package com.gmail.nossr50;
 
 import org.bukkit.entity.Player;
 
-public class mcPermissions 
-{
+public class mcPermissions {
     private static volatile mcPermissions instance;
-    
+
     public boolean permission(Player player, String perm) {
         return player.hasPermission(perm);
     }
-    public boolean admin(Player player){
+
+    public boolean admin(Player player) {
         return player.hasPermission("mcmmo.admin");
     }
+
     public boolean mcrefresh(Player player) {
         return player.hasPermission("mcmmo.tools.mcrefresh");
     }
+
     public boolean mcremove(Player player) {
         return player.hasPermission("mcmmo.tools.mcremove");
     }
+
     public boolean mmoedit(Player player) {
         return player.hasPermission("mcmmo.tools.mmoedit");
     }
-    public boolean herbalismAbility(Player player){
+
+    public boolean herbalismAbility(Player player) {
         return player.hasPermission("mcmmo.ability.herbalism");
     }
-    public boolean excavationAbility(Player player){
+
+    public boolean excavationAbility(Player player) {
         return player.hasPermission("mcmmo.ability.excavation");
     }
-    public boolean unarmedAbility(Player player){
-    	return player.hasPermission("mcmmo.ability.unarmed");
+
+    public boolean unarmedAbility(Player player) {
+        return player.hasPermission("mcmmo.ability.unarmed");
     }
-    public boolean chimaeraWing(Player player){
-    	return player.hasPermission("mcmmo.item.chimaerawing");
+
+    public boolean chimaeraWing(Player player) {
+        return player.hasPermission("mcmmo.item.chimaerawing");
     }
-    public boolean miningAbility(Player player){
-    	return player.hasPermission("mcmmo.ability.mining");    	
+
+    public boolean miningAbility(Player player) {
+        return player.hasPermission("mcmmo.ability.mining");
     }
-    public boolean axesAbility(Player player){
-    	return player.hasPermission("mcmmo.ability.axes");
+
+    public boolean axesAbility(Player player) {
+        return player.hasPermission("mcmmo.ability.axes");
     }
-    public boolean swordsAbility(Player player){
-    	return player.hasPermission("mcmmo.ability.swords");
+
+    public boolean swordsAbility(Player player) {
+        return player.hasPermission("mcmmo.ability.swords");
     }
+
     public boolean woodCuttingAbility(Player player) {
-    	return player.hasPermission("mcmmo.ability.woodcutting");
+        return player.hasPermission("mcmmo.ability.woodcutting");
     }
+
     public boolean mcgod(Player player) {
-    	return player.hasPermission("mcmmo.tools.mcgod");
+        return player.hasPermission("mcmmo.tools.mcgod");
     }
+
     public boolean motd(Player player) {
         return player.hasPermission("mcmmo.motd");
     }
+
     public boolean mcAbility(Player player) {
         return player.hasPermission("mcmmo.commands.ability");
     }
+
     public boolean partyChat(Player player) {
         return player.hasPermission("mcmmo.chat.partychat");
     }
+
     public boolean partyLock(Player player) {
         return player.hasPermission("mcmmo.chat.partylock");
     }
+
     public boolean partyTeleport(Player player) {
         return player.hasPermission("mcmmo.commands.ptp");
     }
+
     public boolean inspect(Player player) {
         return player.hasPermission("mcmmo.commands.inspect");
     }
+
     public boolean party(Player player) {
         return player.hasPermission("mcmmo.commands.party");
     }
+
     public boolean adminChat(Player player) {
         return player.hasPermission("mcmmo.chat.adminchat");
     }
+
     public static mcPermissions getInstance() {
-    	if (instance == null) {
-    	    instance = new mcPermissions();
-    	}
-    	return instance;
+        if (instance == null) {
+            instance = new mcPermissions();
+        }
+
+        return instance;
     }
+
     public boolean taming(Player player) {
         return player.hasPermission("mcmmo.skills.taming");
     }
+
     public boolean mining(Player player) {
         return player.hasPermission("mcmmo.skills.mining");
     }
+
     public boolean blastMining(Player player) {
         return player.hasPermission("mcmmo.skills.blastmining");
     }
+
     public boolean fishing(Player player) {
         return player.hasPermission("mcmmo.skills.fishing");
     }
+
     public boolean woodcutting(Player player) {
         return player.hasPermission("mcmmo.skills.woodcutting");
     }
+
     public boolean repair(Player player) {
         return player.hasPermission("mcmmo.skills.repair");
     }
+
     public boolean unarmed(Player player) {
         return player.hasPermission("mcmmo.skills.unarmed");
     }
+
     public boolean archery(Player player) {
         return player.hasPermission("mcmmo.skills.archery");
     }
+
     public boolean herbalism(Player player) {
         return player.hasPermission("mcmmo.skills.herbalism");
     }
+
     public boolean excavation(Player player) {
         return player.hasPermission("mcmmo.skills.excavation");
     }
+
     public boolean swords(Player player) {
         return player.hasPermission("mcmmo.skills.swords");
     }
+
     public boolean axes(Player player) {
         return player.hasPermission("mcmmo.skills.axes");
     }
+
     public boolean acrobatics(Player player) {
         return player.hasPermission("mcmmo.skills.acrobatics");
     }