mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 05:06:45 +01:00
Early version of setting up a users txt file
This commit is contained in:
parent
ce26a1c524
commit
04f46a5527
@ -11,7 +11,9 @@ public class vMinecraft extends Plugin {
|
||||
|
||||
public void enable() {
|
||||
vMinecraftSettings.getInstance().loadSettings();
|
||||
vMinecraftUsers.getInstance().loadUsers();
|
||||
vMinecraftCommands.loadCommands();
|
||||
|
||||
}
|
||||
|
||||
public void disable() {
|
||||
@ -21,6 +23,7 @@ public class vMinecraft extends Plugin {
|
||||
public void initialize() {
|
||||
//Here we add the hook we're going to use. In this case it's the arm swing event.
|
||||
etc.getLoader().addListener(PluginLoader.Hook.CHAT, listener, this, PluginListener.Priority.MEDIUM);
|
||||
etc.getLoader().addListener(PluginLoader.Hook.LOGIN, listener, this, PluginListener.Priority.MEDIUM);
|
||||
etc.getLoader().addListener(PluginLoader.Hook.COMMAND, listener, this, PluginListener.Priority.HIGH);
|
||||
etc.getLoader().addListener(PluginLoader.Hook.IGNITE, listener, this, PluginListener.Priority.HIGH);
|
||||
etc.getLoader().addListener(PluginLoader.Hook.DAMAGE, listener, this, PluginListener.Priority.MEDIUM);
|
||||
|
@ -90,6 +90,10 @@ public class vMinecraftListener extends PluginListener {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onLogin(Player player){
|
||||
vMinecraftUsers.addUser(player);
|
||||
}
|
||||
/** Not working yet, I posted the issue to hMod on github though
|
||||
public boolean onDamage(DamageType type, BaseEntity attacker, BaseEntity defender, int amount) {
|
||||
|
||||
|
58
vMinecraftUsers.java
Normal file
58
vMinecraftUsers.java
Normal file
@ -0,0 +1,58 @@
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
public class vMinecraftUsers {
|
||||
private static volatile vMinecraftUsers instance;
|
||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||
String file = "vminecraftusers.txt";
|
||||
private PropertiesFile properties;
|
||||
String location = "vminecraftusers.txt";
|
||||
public void loadUsers(){
|
||||
File theDir = new File("vminecraftusers.txt");
|
||||
if(!theDir.exists()){
|
||||
properties = new PropertiesFile("vminecraftusers.txt");
|
||||
FileWriter writer = null;
|
||||
try {
|
||||
writer = new FileWriter(location);
|
||||
writer.write("#Storage place for user information\r\n");
|
||||
writer.write("#username:nickname:suffix:ignore,list,names:alias,commands,here\r\n");
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE, "Exception while creating " + location, e);
|
||||
} finally {
|
||||
try {
|
||||
if (writer != null) {
|
||||
writer.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.log(Level.SEVERE, "Exception while closing writer for " + location, e);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
properties = new PropertiesFile("vminecraftusers.txt");
|
||||
try {
|
||||
properties.load();
|
||||
} catch (IOException e) {
|
||||
log.log(Level.SEVERE, "Exception while loading vminecraftusers.txt", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void addUser(Player player){
|
||||
FileWriter writer = null;
|
||||
String location = "vminecraftusers.txt";
|
||||
try {
|
||||
writer = new FileWriter(location);
|
||||
writer.write(player.getName()+"::::");
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE, "Exception while trying to add user with writer to " + location, e);
|
||||
}
|
||||
|
||||
}
|
||||
public static vMinecraftUsers getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new vMinecraftUsers();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user