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;
|
||||
|
||||
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()
|
||||
{
|
||||
/**
|
||||
* Load users.
|
||||
*/
|
||||
public void loadUsers() {
|
||||
new File(directory).mkdir();
|
||||
new File(directoryb).mkdir();
|
||||
File theDir = new File(location);
|
||||
if(!theDir.exists())
|
||||
{
|
||||
|
||||
if (!theDir.exists()) {
|
||||
try {
|
||||
FileWriter writer = new FileWriter(theDir);
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void addUser(Player player)
|
||||
{
|
||||
if(!players.containsKey(player))
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all users.
|
||||
*/
|
||||
public static void clearUsers() {
|
||||
players.clear();
|
||||
}
|
||||
public static HashMap<Player, PlayerProfile> getProfiles(){
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
/**
|
||||
* 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))
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -90,25 +96,41 @@ public class Users {
|
||||
players.remove(target);
|
||||
}
|
||||
|
||||
public static PlayerProfile getProfile(Player player){
|
||||
if(players.get(player) != null)
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an instance of this class.
|
||||
*
|
||||
* @return an instance of this class
|
||||
*/
|
||||
public static Users getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new Users();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
}
|
@ -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){
|
||||
|
||||
public boolean unarmedAbility(Player player) {
|
||||
return player.hasPermission("mcmmo.ability.unarmed");
|
||||
}
|
||||
public boolean chimaeraWing(Player player){
|
||||
|
||||
public boolean chimaeraWing(Player player) {
|
||||
return player.hasPermission("mcmmo.item.chimaerawing");
|
||||
}
|
||||
public boolean miningAbility(Player player){
|
||||
|
||||
public boolean miningAbility(Player player) {
|
||||
return player.hasPermission("mcmmo.ability.mining");
|
||||
}
|
||||
public boolean axesAbility(Player player){
|
||||
|
||||
public boolean axesAbility(Player player) {
|
||||
return player.hasPermission("mcmmo.ability.axes");
|
||||
}
|
||||
public boolean swordsAbility(Player player){
|
||||
|
||||
public boolean swordsAbility(Player player) {
|
||||
return player.hasPermission("mcmmo.ability.swords");
|
||||
}
|
||||
|
||||
public boolean woodCuttingAbility(Player player) {
|
||||
return player.hasPermission("mcmmo.ability.woodcutting");
|
||||
}
|
||||
|
||||
public boolean mcgod(Player player) {
|
||||
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;
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user