mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-23 05:36:46 +01:00
Cleanup.
This commit is contained in:
parent
052e3cd997
commit
bce418bee8
@ -1,88 +1,94 @@
|
|||||||
package com.gmail.nossr50;
|
package com.gmail.nossr50;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import org.bukkit.entity.*;
|
import org.bukkit.entity.Player;
|
||||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||||
|
|
||||||
|
|
||||||
public class Users {
|
public class Users {
|
||||||
private static volatile Users instance;
|
private static volatile Users instance;
|
||||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||||
|
|
||||||
String location = "plugins/mcMMO/FlatFileStuff/mcmmo.users";
|
String location = "plugins/mcMMO/FlatFileStuff/mcmmo.users";
|
||||||
String directory = "plugins/mcMMO/FlatFileStuff/";
|
String directory = "plugins/mcMMO/FlatFileStuff/";
|
||||||
String directoryb = "plugins/mcMMO/FlatFileStuff/Leaderboards/";
|
String directoryb = "plugins/mcMMO/FlatFileStuff/Leaderboards/";
|
||||||
|
|
||||||
//public static ArrayList<PlayerProfile> players;
|
|
||||||
public static HashMap<Player, PlayerProfile> players = new HashMap<Player, PlayerProfile>();
|
public static HashMap<Player, PlayerProfile> players = new HashMap<Player, PlayerProfile>();
|
||||||
private Properties properties = new Properties();
|
|
||||||
|
|
||||||
//To load
|
/**
|
||||||
public void load() throws IOException {
|
* Load users.
|
||||||
properties.load(new FileInputStream(location));
|
*/
|
||||||
}
|
public void loadUsers() {
|
||||||
//To save
|
|
||||||
public void save()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
properties.store(new FileOutputStream(location), null);
|
|
||||||
}catch(IOException ex) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadUsers()
|
|
||||||
{
|
|
||||||
new File(directory).mkdir();
|
new File(directory).mkdir();
|
||||||
new File(directoryb).mkdir();
|
new File(directoryb).mkdir();
|
||||||
File theDir = new File(location);
|
File theDir = new File(location);
|
||||||
if(!theDir.exists())
|
|
||||||
{
|
if (!theDir.exists()) {
|
||||||
try {
|
try {
|
||||||
FileWriter writer = new FileWriter(theDir);
|
FileWriter writer = new FileWriter(theDir);
|
||||||
writer.close();
|
writer.close();
|
||||||
} catch (IOException e) {
|
}
|
||||||
// TODO Auto-generated catch block
|
catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
public static void addUser(Player player)
|
* Add a new user.
|
||||||
{
|
*
|
||||||
if(!players.containsKey(player))
|
* @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()));
|
players.put(player, new PlayerProfile(player.getName()));
|
||||||
}
|
}
|
||||||
public static void clearUsers()
|
}
|
||||||
{
|
|
||||||
|
/**
|
||||||
|
* Clear all users.
|
||||||
|
*/
|
||||||
|
public static void clearUsers() {
|
||||||
players.clear();
|
players.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all PlayerProfiles.
|
||||||
|
*
|
||||||
|
* @return a HashMap containing the PlayerProfile of everyone in the database
|
||||||
|
*/
|
||||||
public static HashMap<Player, PlayerProfile> getProfiles() {
|
public static HashMap<Player, PlayerProfile> getProfiles() {
|
||||||
return players;
|
return players;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeUser(Player 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
|
//Only remove PlayerProfile if user is offline and we have it in memory
|
||||||
if(!player.isOnline() && players.containsKey(player))
|
if (!player.isOnline() && players.containsKey(player)) {
|
||||||
{
|
|
||||||
players.get(player).save();
|
players.get(player).save();
|
||||||
players.remove(player);
|
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;
|
Player target = null;
|
||||||
for(Player player : players.keySet())
|
|
||||||
{
|
for (Player player : players.keySet()) {
|
||||||
PlayerProfile PP = players.get(player);
|
PlayerProfile PP = players.get(player);
|
||||||
if(PP.getPlayerName().equals(playerName))
|
|
||||||
{
|
if (PP.getPlayerName().equals(playerName)) {
|
||||||
target = player;
|
target = player;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,25 +96,41 @@ public class Users {
|
|||||||
players.remove(target);
|
players.remove(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
public static PlayerProfile getProfile(Player player) {
|
||||||
if(players.get(player) != null)
|
if(players.get(player) != null) {
|
||||||
return players.get(player);
|
return players.get(player);
|
||||||
else
|
}
|
||||||
{
|
else {
|
||||||
players.put(player, new PlayerProfile(player.getName()));
|
players.put(player, new PlayerProfile(player.getName()));
|
||||||
return players.get(player);
|
return players.get(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
public static PlayerProfile getOfflineProfile(String playerName) {
|
||||||
return new PlayerProfile(playerName, false);
|
return new PlayerProfile(playerName, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an instance of this class.
|
||||||
|
*
|
||||||
|
* @return an instance of this class
|
||||||
|
*/
|
||||||
public static Users getInstance() {
|
public static Users getInstance() {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
instance = new Users();
|
instance = new Users();
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -2,118 +2,153 @@ package com.gmail.nossr50;
|
|||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class mcPermissions
|
public class mcPermissions {
|
||||||
{
|
|
||||||
private static volatile mcPermissions instance;
|
private static volatile mcPermissions instance;
|
||||||
|
|
||||||
public boolean permission(Player player, String perm) {
|
public boolean permission(Player player, String perm) {
|
||||||
return player.hasPermission(perm);
|
return player.hasPermission(perm);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean admin(Player player) {
|
public boolean admin(Player player) {
|
||||||
return player.hasPermission("mcmmo.admin");
|
return player.hasPermission("mcmmo.admin");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean mcrefresh(Player player) {
|
public boolean mcrefresh(Player player) {
|
||||||
return player.hasPermission("mcmmo.tools.mcrefresh");
|
return player.hasPermission("mcmmo.tools.mcrefresh");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean mcremove(Player player) {
|
public boolean mcremove(Player player) {
|
||||||
return player.hasPermission("mcmmo.tools.mcremove");
|
return player.hasPermission("mcmmo.tools.mcremove");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean mmoedit(Player player) {
|
public boolean mmoedit(Player player) {
|
||||||
return player.hasPermission("mcmmo.tools.mmoedit");
|
return player.hasPermission("mcmmo.tools.mmoedit");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean herbalismAbility(Player player) {
|
public boolean herbalismAbility(Player player) {
|
||||||
return player.hasPermission("mcmmo.ability.herbalism");
|
return player.hasPermission("mcmmo.ability.herbalism");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean excavationAbility(Player player) {
|
public boolean excavationAbility(Player player) {
|
||||||
return player.hasPermission("mcmmo.ability.excavation");
|
return player.hasPermission("mcmmo.ability.excavation");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean unarmedAbility(Player player) {
|
public boolean unarmedAbility(Player player) {
|
||||||
return player.hasPermission("mcmmo.ability.unarmed");
|
return player.hasPermission("mcmmo.ability.unarmed");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean chimaeraWing(Player player) {
|
public boolean chimaeraWing(Player player) {
|
||||||
return player.hasPermission("mcmmo.item.chimaerawing");
|
return player.hasPermission("mcmmo.item.chimaerawing");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean miningAbility(Player player) {
|
public boolean miningAbility(Player player) {
|
||||||
return player.hasPermission("mcmmo.ability.mining");
|
return player.hasPermission("mcmmo.ability.mining");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean axesAbility(Player player) {
|
public boolean axesAbility(Player player) {
|
||||||
return player.hasPermission("mcmmo.ability.axes");
|
return player.hasPermission("mcmmo.ability.axes");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean swordsAbility(Player player) {
|
public boolean swordsAbility(Player player) {
|
||||||
return player.hasPermission("mcmmo.ability.swords");
|
return player.hasPermission("mcmmo.ability.swords");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean woodCuttingAbility(Player player) {
|
public boolean woodCuttingAbility(Player player) {
|
||||||
return player.hasPermission("mcmmo.ability.woodcutting");
|
return player.hasPermission("mcmmo.ability.woodcutting");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean mcgod(Player player) {
|
public boolean mcgod(Player player) {
|
||||||
return player.hasPermission("mcmmo.tools.mcgod");
|
return player.hasPermission("mcmmo.tools.mcgod");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean motd(Player player) {
|
public boolean motd(Player player) {
|
||||||
return player.hasPermission("mcmmo.motd");
|
return player.hasPermission("mcmmo.motd");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean mcAbility(Player player) {
|
public boolean mcAbility(Player player) {
|
||||||
return player.hasPermission("mcmmo.commands.ability");
|
return player.hasPermission("mcmmo.commands.ability");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean partyChat(Player player) {
|
public boolean partyChat(Player player) {
|
||||||
return player.hasPermission("mcmmo.chat.partychat");
|
return player.hasPermission("mcmmo.chat.partychat");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean partyLock(Player player) {
|
public boolean partyLock(Player player) {
|
||||||
return player.hasPermission("mcmmo.chat.partylock");
|
return player.hasPermission("mcmmo.chat.partylock");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean partyTeleport(Player player) {
|
public boolean partyTeleport(Player player) {
|
||||||
return player.hasPermission("mcmmo.commands.ptp");
|
return player.hasPermission("mcmmo.commands.ptp");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean inspect(Player player) {
|
public boolean inspect(Player player) {
|
||||||
return player.hasPermission("mcmmo.commands.inspect");
|
return player.hasPermission("mcmmo.commands.inspect");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean party(Player player) {
|
public boolean party(Player player) {
|
||||||
return player.hasPermission("mcmmo.commands.party");
|
return player.hasPermission("mcmmo.commands.party");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean adminChat(Player player) {
|
public boolean adminChat(Player player) {
|
||||||
return player.hasPermission("mcmmo.chat.adminchat");
|
return player.hasPermission("mcmmo.chat.adminchat");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static mcPermissions getInstance() {
|
public static mcPermissions getInstance() {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
instance = new mcPermissions();
|
instance = new mcPermissions();
|
||||||
}
|
}
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean taming(Player player) {
|
public boolean taming(Player player) {
|
||||||
return player.hasPermission("mcmmo.skills.taming");
|
return player.hasPermission("mcmmo.skills.taming");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean mining(Player player) {
|
public boolean mining(Player player) {
|
||||||
return player.hasPermission("mcmmo.skills.mining");
|
return player.hasPermission("mcmmo.skills.mining");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean blastMining(Player player) {
|
public boolean blastMining(Player player) {
|
||||||
return player.hasPermission("mcmmo.skills.blastmining");
|
return player.hasPermission("mcmmo.skills.blastmining");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean fishing(Player player) {
|
public boolean fishing(Player player) {
|
||||||
return player.hasPermission("mcmmo.skills.fishing");
|
return player.hasPermission("mcmmo.skills.fishing");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean woodcutting(Player player) {
|
public boolean woodcutting(Player player) {
|
||||||
return player.hasPermission("mcmmo.skills.woodcutting");
|
return player.hasPermission("mcmmo.skills.woodcutting");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean repair(Player player) {
|
public boolean repair(Player player) {
|
||||||
return player.hasPermission("mcmmo.skills.repair");
|
return player.hasPermission("mcmmo.skills.repair");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean unarmed(Player player) {
|
public boolean unarmed(Player player) {
|
||||||
return player.hasPermission("mcmmo.skills.unarmed");
|
return player.hasPermission("mcmmo.skills.unarmed");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean archery(Player player) {
|
public boolean archery(Player player) {
|
||||||
return player.hasPermission("mcmmo.skills.archery");
|
return player.hasPermission("mcmmo.skills.archery");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean herbalism(Player player) {
|
public boolean herbalism(Player player) {
|
||||||
return player.hasPermission("mcmmo.skills.herbalism");
|
return player.hasPermission("mcmmo.skills.herbalism");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean excavation(Player player) {
|
public boolean excavation(Player player) {
|
||||||
return player.hasPermission("mcmmo.skills.excavation");
|
return player.hasPermission("mcmmo.skills.excavation");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean swords(Player player) {
|
public boolean swords(Player player) {
|
||||||
return player.hasPermission("mcmmo.skills.swords");
|
return player.hasPermission("mcmmo.skills.swords");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean axes(Player player) {
|
public boolean axes(Player player) {
|
||||||
return player.hasPermission("mcmmo.skills.axes");
|
return player.hasPermission("mcmmo.skills.axes");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean acrobatics(Player player) {
|
public boolean acrobatics(Player player) {
|
||||||
return player.hasPermission("mcmmo.skills.acrobatics");
|
return player.hasPermission("mcmmo.skills.acrobatics");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user