mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 06:36:45 +01:00
Fixed the flatfile system.
This commit is contained in:
parent
263a5701d7
commit
ebdda3afc0
2
TODO
2
TODO
@ -1,5 +1,4 @@
|
||||
Vminecraft b8 Todo:
|
||||
+ Finish work on the flat file system
|
||||
+ Antigriefs <Nos> Working on this
|
||||
? Time manipulation <Cere> Working on this
|
||||
* Have time changes not be instant but move the sky faster
|
||||
@ -47,5 +46,6 @@ DONE
|
||||
+ Allow players to nickname themselves or others
|
||||
+ Allow players to set suffixes
|
||||
+ ^r for rainbow color code
|
||||
+ Finish work on the flat file system
|
||||
|
||||
Notes: Let's try to to finish as much of this list as possible tomorrow and push for a b8 release soon :P
|
||||
|
@ -11,7 +11,7 @@ public class vMinecraft extends Plugin {
|
||||
|
||||
public void enable() {
|
||||
vMinecraftSettings.getInstance().loadSettings();
|
||||
vMinecraftUsers.getInstance().loadUsers();
|
||||
vMinecraftUsers.getInstance().loadUsers();
|
||||
vMinecraftCommands.loadCommands();
|
||||
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ public class vMinecraftCommands{
|
||||
cl.register("/slay", "slay", "Kill target player");
|
||||
|
||||
//Social
|
||||
cl.register("/colors", "colors");
|
||||
cl.register("/colors", "colors", "Set your default chat color: /colors <Color Char>");
|
||||
cl.register("/me", "me");
|
||||
cl.register("/fabulous", "fabulous", "makes text SUUUPER");
|
||||
cl.register("/msg", "message", "Send a message to a player /msg [Player] [Message]");
|
||||
@ -521,28 +521,36 @@ public class vMinecraftCommands{
|
||||
//Use: Displays a list of all colors and color codes
|
||||
//=====================================================================
|
||||
public static int colors(Player player, String[] args){
|
||||
player.sendMessage(Colors.Rose + "You use these color codes like in quake or MW2.");
|
||||
player.sendMessage(Colors.Rose + "^4 would make text " + Colors.Red
|
||||
+ "red" + Colors.Rose + ", ^a would make it " + Colors.LightGreen
|
||||
+ "light green" + Colors.Rose + ".");
|
||||
vMinecraftChat.sendMessage(player, player,
|
||||
Colors.Black + "0"
|
||||
+ Colors.Navy + "1"
|
||||
+ Colors.Green + "2"
|
||||
+ Colors.Blue + "3"
|
||||
+ Colors.Red + "4"
|
||||
+ Colors.Purple + "5"
|
||||
+ Colors.Gold + "6"
|
||||
+ Colors.LightGray + "7"
|
||||
+ Colors.Gray + "8"
|
||||
+ Colors.DarkPurple + "9"
|
||||
+ Colors.LightGreen + "a"
|
||||
+ Colors.LightBlue + "b"
|
||||
+ Colors.Rose + "c"
|
||||
+ Colors.LightPurple + "d"
|
||||
+ Colors.Yellow + "e"
|
||||
+ Colors.White + "f"
|
||||
+ "^r" + "rrrrrrrrrrr");
|
||||
if(args.length > 0)
|
||||
{
|
||||
vMinecraftUsers.getProfile(player).setColor(args[0]);
|
||||
vMinecraftChat.sendMessage(player, player,
|
||||
vMinecraftChat.colorChange(args[0].charAt(0))
|
||||
+ "Default chat color set.");
|
||||
} else {
|
||||
player.sendMessage(Colors.Rose + "You use these color codes like in quake or MW2.");
|
||||
player.sendMessage(Colors.Rose + "^4 would make text " + Colors.Red
|
||||
+ "red" + Colors.Rose + ", ^a would make it " + Colors.LightGreen
|
||||
+ "light green" + Colors.Rose + ".");
|
||||
vMinecraftChat.sendMessage(player, player,
|
||||
Colors.Black + "0"
|
||||
+ Colors.Navy + "1"
|
||||
+ Colors.Green + "2"
|
||||
+ Colors.Blue + "3"
|
||||
+ Colors.Red + "4"
|
||||
+ Colors.Purple + "5"
|
||||
+ Colors.Gold + "6"
|
||||
+ Colors.LightGray + "7"
|
||||
+ Colors.Gray + "8"
|
||||
+ Colors.DarkPurple + "9"
|
||||
+ Colors.LightGreen + "a"
|
||||
+ Colors.LightBlue + "b"
|
||||
+ Colors.Rose + "c"
|
||||
+ Colors.LightPurple + "d"
|
||||
+ Colors.Yellow + "e"
|
||||
+ Colors.White + "f"
|
||||
+ "^r" + "rrrrrrrrrrr");
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -1292,22 +1300,41 @@ public class vMinecraftCommands{
|
||||
//=====================================================================
|
||||
public static int modify(Player player, String[] args)
|
||||
{
|
||||
if(player.canUseCommand("/prefix"))
|
||||
if(player.canUseCommand("/prefixother"))
|
||||
vMinecraftChat.sendMessage(player, player, "/prefix [Player]" +
|
||||
" [Color] (Tag) - Set a players prefix and tag.");
|
||||
else if(player.canUseCommand("/prefix"))
|
||||
vMinecraftChat.sendMessage(player, player, "/prefix [Color]" +
|
||||
" (Tag) - Set your prefix and tag.");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
//=====================================================================
|
||||
//Function: Time Reverse
|
||||
//Input: long time: The time to reverse to.
|
||||
//Output: int: Exit Code
|
||||
//Use: List all invulnerable players
|
||||
//=====================================================================
|
||||
public static int timeReverse(long tarTime)
|
||||
{
|
||||
long curTime = etc.getServer().getRelativeTime();
|
||||
//if(cur)
|
||||
if(player.canUseCommand("/nickother"))
|
||||
vMinecraftChat.sendMessage(player, player, "/nick [Player]" +
|
||||
" [Nickname] - Set a players nickname.");
|
||||
else if(player.canUseCommand("/nick"))
|
||||
vMinecraftChat.sendMessage(player, player, "/nick [Nick]" +
|
||||
" - Set your nickname.");
|
||||
|
||||
if(player.canUseCommand("/suffixother"))
|
||||
vMinecraftChat.sendMessage(player, player, "/suffix [Player]" +
|
||||
" [Suffix] - Set a players suffix.");
|
||||
else if(player.canUseCommand("/suffix"))
|
||||
vMinecraftChat.sendMessage(player, player, "/suffix [Suffix]" +
|
||||
" - Set your suffix.");
|
||||
|
||||
if(player.canUseCommand("/suffixother"))
|
||||
vMinecraftChat.sendMessage(player, player, "/suffix [Player]" +
|
||||
" [Suffix] - Set a players suffix.");
|
||||
else if(player.canUseCommand("/suffix"))
|
||||
vMinecraftChat.sendMessage(player, player, "/suffix [Suffix]" +
|
||||
" - Set your suffix.");
|
||||
|
||||
if(player.canUseCommand("/vranks"))
|
||||
{
|
||||
vMinecraftChat.sendMessage(player, player, "/promote [Player]" +
|
||||
" - Promotes a player");
|
||||
vMinecraftChat.sendMessage(player, player, "/demote [Player]" +
|
||||
" - Demotes a player");
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
@ -1417,6 +1444,8 @@ class commandList {
|
||||
//=====================================================================
|
||||
//Function: call
|
||||
//Input: String name: The name of the command to be run
|
||||
// Player player: The player calling the command
|
||||
// String[] arg: The arguments being input for the command
|
||||
//Output: boolean: If the command was called successfully
|
||||
//Use: Attempts to call a command
|
||||
//=====================================================================
|
||||
@ -1443,6 +1472,25 @@ class commandList {
|
||||
return EXIT_FAIL;
|
||||
}
|
||||
|
||||
//=====================================================================
|
||||
//Function: toString
|
||||
//Input: None
|
||||
//Output: String: A string representation of the aliases in the list
|
||||
//Use: Displays all the aliases in thel ist
|
||||
//=====================================================================
|
||||
public String toString()
|
||||
{
|
||||
String temp = "";
|
||||
int i = 0;
|
||||
for(command comm : commands)
|
||||
{
|
||||
temp += comm.toString();
|
||||
if(i < commands.size() - 1)
|
||||
temp +=",";
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=====================================================================
|
||||
@ -1503,6 +1551,14 @@ class commandList {
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
//=====================================================================
|
||||
//Function: toString
|
||||
//Input: None
|
||||
//Output: String: null
|
||||
//Use: Returns null
|
||||
//=====================================================================
|
||||
public String toString() { return null; }
|
||||
}
|
||||
|
||||
//=====================================================================
|
||||
@ -1586,6 +1642,22 @@ class commandList {
|
||||
player.command(reference);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
//=====================================================================
|
||||
//Function: toString
|
||||
//Input: None
|
||||
//Output: String: A string representation of this command.
|
||||
// command@referencedcommand arg1 arg2 argn
|
||||
//Use: Returns the string representation of the alias
|
||||
//=====================================================================
|
||||
public String toString()
|
||||
{
|
||||
String temp = getName();
|
||||
temp += '@';
|
||||
temp += reference;
|
||||
temp += etc.combineSplit(0, args, " ");
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
||||
//=====================================================================
|
||||
@ -1684,5 +1756,13 @@ class commandList {
|
||||
}
|
||||
return EXIT_FAIL;
|
||||
}
|
||||
|
||||
//=====================================================================
|
||||
//Function: toString
|
||||
//Input: None
|
||||
//Output: String: null
|
||||
//Use: Returns null
|
||||
//=====================================================================
|
||||
public String toString() { return null; }
|
||||
}
|
||||
}
|
@ -2,7 +2,6 @@ import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class vMinecraftUsers {
|
||||
private static volatile vMinecraftUsers instance;
|
||||
@ -21,7 +20,7 @@ public class vMinecraftUsers {
|
||||
try {
|
||||
writer = new FileWriter(location);
|
||||
writer.write("#Storage place for user information\r\n");
|
||||
writer.write("#username:nickname:suffix:tag:ignore,list,names:alias,commands,here\r\n");
|
||||
writer.write("#username:nickname:suffix:tag:ignore,list,names:alias,commands,here\r\n");
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE, "Exception while creating " + location, e);
|
||||
} finally {
|
||||
@ -43,26 +42,6 @@ public class vMinecraftUsers {
|
||||
}
|
||||
}
|
||||
}
|
||||
public boolean doesPlayerExist(String player) {
|
||||
try {
|
||||
Scanner scanner = new Scanner(new File(location));
|
||||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine();
|
||||
if (line.startsWith("#") || line.equals("") || line.startsWith("")) {
|
||||
continue;
|
||||
}
|
||||
String[] split = line.split(":");
|
||||
if (!split[0].equalsIgnoreCase(player)) {
|
||||
continue;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
scanner.close();
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE, "Exception while reading " + location + " (Are you sure you formatted it correctly?)", e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//=====================================================================
|
||||
//Function: addUser
|
||||
@ -163,8 +142,9 @@ class PlayerList
|
||||
lastMessage,
|
||||
nickName,
|
||||
tag,
|
||||
suffix,
|
||||
defaultColor;
|
||||
suffix;
|
||||
|
||||
char defaultColor;
|
||||
|
||||
String location = "vminecraft.users";
|
||||
|
||||
@ -186,66 +166,78 @@ class PlayerList
|
||||
{
|
||||
//Declare things
|
||||
playerName = player.getName();
|
||||
nickName = new String();
|
||||
tag = new String();
|
||||
nickName = new String();
|
||||
suffix = new String();
|
||||
defaultColor = 'f';
|
||||
ignoreList = new ArrayList<String>();
|
||||
aliasList = new commandList();
|
||||
|
||||
//Try to apply what we can
|
||||
//Try to load the player and if they aren't found, append them
|
||||
if(!load())
|
||||
addPlayer();
|
||||
}
|
||||
|
||||
public boolean load()
|
||||
{
|
||||
try {
|
||||
Scanner scanner = new Scanner(new File(location));
|
||||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine();
|
||||
if (line.startsWith("#") || line.equals("") || line.startsWith("")) {
|
||||
continue;
|
||||
}
|
||||
String[] split = line.split(":");
|
||||
//Open the user file
|
||||
FileReader file = new FileReader(location);
|
||||
BufferedReader in = new BufferedReader(file);
|
||||
String line = "";
|
||||
while((line = in.readLine()) != null)
|
||||
{
|
||||
//Find if the line contains the player we want.
|
||||
String[] character = line.split(":");
|
||||
if(!character[0].equals(playerName)){continue;}
|
||||
|
||||
//If the player name is equal to the name in the list
|
||||
if (split.length > 0 && split[0].equalsIgnoreCase(player.getName())) {
|
||||
|
||||
//Get the tag from the 1st split
|
||||
if (split.length >= 2)
|
||||
nickName = split[1];
|
||||
|
||||
//Get the tag from the 2nd split
|
||||
if (split.length >= 3)
|
||||
suffix = split[2];
|
||||
|
||||
//Get the tag from the 3rd split
|
||||
if (split.length >= 4)
|
||||
tag = (split[3]);
|
||||
|
||||
//Add all the ignored people to the player's ignore list
|
||||
if (split.length >= 5) {
|
||||
for(String name : split[4].split(","))
|
||||
ignoreList.add(name);
|
||||
}
|
||||
|
||||
//Get the alias list, from the 5th split
|
||||
if (split.length >= 6) {
|
||||
//Loop through all the aliases
|
||||
for(String alias : split[5].split(","))
|
||||
{
|
||||
//Break apart the two parts of the alias
|
||||
String[] parts = alias.split("@");
|
||||
if(parts.length > 1)
|
||||
{
|
||||
//Register the alias to the player's aliasList
|
||||
aliasList.registerAlias(parts[0], parts[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
scanner.close();
|
||||
//Get the tag
|
||||
if(character.length > 1)
|
||||
tag = character[1];
|
||||
//Get the nickname
|
||||
if(character.length > 2)
|
||||
nickName = character[2];
|
||||
//Get the suffix
|
||||
if(character.length > 3)
|
||||
suffix = character[3];
|
||||
//Get the color
|
||||
if(character.length > 4)
|
||||
defaultColor = character[4].charAt(0);
|
||||
//Ignore previously ignored players
|
||||
if(character.length > 5)
|
||||
{
|
||||
String[] ignores = character[5].split(",");
|
||||
if(ignores.length > 0)
|
||||
{
|
||||
for(String ignore : ignores)
|
||||
ignoreList.add(ignore);
|
||||
}
|
||||
}
|
||||
//Register the aliases
|
||||
if(character.length > 6)
|
||||
{
|
||||
String[] allAliases = character[6].split(",");
|
||||
if(allAliases.length > 0)
|
||||
{
|
||||
for(String singleAlias : allAliases)
|
||||
{
|
||||
String[] parts = singleAlias.split("@");
|
||||
if(parts.length > 1)
|
||||
{
|
||||
aliasList.registerAlias(parts[0], parts[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
return true;
|
||||
}
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE, "Exception while reading "
|
||||
+ location + " (Are you sure you formatted it correctly?)", e);
|
||||
}
|
||||
save();
|
||||
return false;
|
||||
}
|
||||
|
||||
//=====================================================================
|
||||
@ -255,31 +247,91 @@ class PlayerList
|
||||
// Use: Writes current values of PlayerProfile to disk
|
||||
// Call this function to save current values
|
||||
//=====================================================================
|
||||
public void save(){
|
||||
public void save()
|
||||
{
|
||||
try {
|
||||
BufferedWriter bw = new BufferedWriter(new FileWriter(location, true));
|
||||
Scanner scanner = new Scanner(new File(location));
|
||||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine();
|
||||
if (line.startsWith("#") || line.equals("") || line.startsWith("")) {
|
||||
continue;
|
||||
}
|
||||
String[] split = line.split(":");
|
||||
if (!split[0].equalsIgnoreCase(playerName)) {
|
||||
continue;
|
||||
}
|
||||
String output =playerName + ":" + nickName + ":" + suffix + ":" + tag + ":";
|
||||
for(String player : ignoreList)
|
||||
output += player + ",";
|
||||
output += ":";
|
||||
bw.write(output);
|
||||
}
|
||||
scanner.close();
|
||||
//Open the file
|
||||
FileReader file = new FileReader(location);
|
||||
BufferedReader in = new BufferedReader(file);
|
||||
StringBuilder writer = new StringBuilder();
|
||||
String line = "";
|
||||
|
||||
//While not at the end of the file
|
||||
while((line = in.readLine()) != null)
|
||||
{
|
||||
//Read the line in and copy it to the output it's not the player
|
||||
//we want to edit
|
||||
if(!line.split(":")[0].equalsIgnoreCase(playerName))
|
||||
{
|
||||
writer.append(line).append("\r\n");
|
||||
|
||||
//Otherwise write the new player information
|
||||
} else {
|
||||
writer.append(playerName + ":");
|
||||
writer.append(tag + ":");
|
||||
writer.append(nickName + ":");
|
||||
writer.append(suffix + ":");
|
||||
writer.append(defaultColor + ":");
|
||||
|
||||
int i = 0;
|
||||
for(String ignore : ignoreList)
|
||||
{
|
||||
writer.append(ignore);
|
||||
if(i < ignoreList.size() - 1)
|
||||
writer.append(",");
|
||||
}
|
||||
writer.append(":");
|
||||
|
||||
writer.append(aliasList.toString());
|
||||
writer.append("\r\n");
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
|
||||
|
||||
//Write the new file
|
||||
FileWriter out = new FileWriter(location);
|
||||
out.write(writer.toString());
|
||||
out.close();
|
||||
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE, "Exception while writing to " + location + " (Are you sure you formatted it correctly?)", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void addPlayer()
|
||||
{
|
||||
try {
|
||||
//Open the file to write the player
|
||||
FileWriter file = new FileWriter(location);
|
||||
BufferedWriter out = new BufferedWriter(file);
|
||||
|
||||
//Add the player to the end
|
||||
out.append(playerName + ":");
|
||||
out.append(tag + ":");
|
||||
out.append(nickName + ":");
|
||||
out.append(suffix + ":");
|
||||
out.append(defaultColor + ":");
|
||||
|
||||
int i = 0;
|
||||
for(String ignore : ignoreList)
|
||||
{
|
||||
out.append(ignore);
|
||||
if(i < ignoreList.size() - 1)
|
||||
out.append(",");
|
||||
}
|
||||
out.append(":");
|
||||
|
||||
out.append(aliasList.toString());
|
||||
out.append("\r\n");
|
||||
|
||||
out.close();
|
||||
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE, "Exception while writing to " + location + " (Are you sure you formatted it correctly?)", e);
|
||||
}
|
||||
}
|
||||
|
||||
//=====================================================================
|
||||
//Function: isPlayer
|
||||
//Input: None
|
||||
@ -387,7 +439,11 @@ class PlayerList
|
||||
//Output: None
|
||||
//Use: Sets a player tag
|
||||
//=====================================================================
|
||||
public void setTag(String newTag){ tag = newTag; }
|
||||
public void setTag(String newTag)
|
||||
{
|
||||
tag = newTag;
|
||||
save();
|
||||
}
|
||||
|
||||
//=====================================================================
|
||||
//Function: getTag
|
||||
@ -403,7 +459,11 @@ class PlayerList
|
||||
//Output: None
|
||||
//Use: Sets a player nickname
|
||||
//=====================================================================
|
||||
public void setNick(String newNick){ nickName = newNick; }
|
||||
public void setNick(String newNick)
|
||||
{
|
||||
nickName = newNick;
|
||||
save();
|
||||
}
|
||||
|
||||
//=====================================================================
|
||||
//Function: getNick
|
||||
@ -419,7 +479,11 @@ class PlayerList
|
||||
//Output: None
|
||||
//Use: Sets a player suffix
|
||||
//=====================================================================
|
||||
public void setSuffix(String newSuffix){ suffix = newSuffix; }
|
||||
public void setSuffix(String newSuffix)
|
||||
{
|
||||
suffix = newSuffix;
|
||||
save();
|
||||
}
|
||||
|
||||
//=====================================================================
|
||||
//Function: getSuffix
|
||||
@ -435,7 +499,11 @@ class PlayerList
|
||||
//Output: None
|
||||
//Use: Sets a player color
|
||||
//=====================================================================
|
||||
public void setColor(String newColor){ defaultColor = newColor; }
|
||||
public void setColor(String newColor)
|
||||
{
|
||||
defaultColor = newColor.charAt(0);
|
||||
save();
|
||||
}
|
||||
|
||||
//=====================================================================
|
||||
//Function: getColor
|
||||
@ -443,7 +511,7 @@ class PlayerList
|
||||
//Output: String: The player color
|
||||
//Use: Gets a player color
|
||||
//=====================================================================
|
||||
public String getColor() { return defaultColor; }
|
||||
public String getColor() {return vMinecraftChat.colorChange(defaultColor);}
|
||||
|
||||
//=====================================================================
|
||||
//Function: setMessage
|
||||
|
Loading…
Reference in New Issue
Block a user