Saved Player Metrics to .txt file

This commit is contained in:
alisolarflare 2016-11-25 19:23:34 -05:00
parent 173c0d5a70
commit 630d8ee23e
12 changed files with 267 additions and 258 deletions

1
metrics/playerLogins.txt Normal file
View file

@ -0,0 +1 @@
Login List:

10
pom.xml
View file

@ -78,5 +78,15 @@
<artifactId>Essentials</artifactId>
<version>2.13.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.7</version>
</dependency>
</dependencies>
</project>

View file

@ -10,8 +10,8 @@ import org.bukkit.plugin.java.JavaPlugin;
import alisolarflare.architecture.Component;
import alisolarflare.components.flairdoor.flairme.FlairMe;
import alisolarflare.components.flairdoor.listeners.PortalListener;
import alisolarflare.components.flairdoor.playerproximity.PlayerProximityTaskLauncher;
import alisolarflare.components.flairdoor.playerproximity.SetProximityLocation;
import alisolarflare.components.flairdoor.proximitydetector.PlayerProximityLoop;
import alisolarflare.components.flairdoor.proximitydetector.SetProximityLocation;
public class FlairDoorComponent extends Component {
public List<Player> playersToBeFlaired = new ArrayList<Player>();
@ -22,6 +22,6 @@ public class FlairDoorComponent extends Component {
registerCommand(plugin, new FlairMe(this));
registerCommand(plugin, new SetProximityLocation(this));
registerListener(plugin, new PortalListener(plugin, this));
registerListener(plugin, new PlayerProximityTaskLauncher(plugin, this));
registerListener(plugin, new PlayerProximityLoop(plugin, this));
}
}

View file

@ -1,12 +0,0 @@
package alisolarflare.components.flairdoor.playerproximity;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import alisolarflare.components.flairdoor.FlairDoorComponent;
public class PlayerProximityTaskLauncher implements Listener{
public PlayerProximityTaskLauncher(JavaPlugin plugin, FlairDoorComponent component){
new PlayerProximityTask(plugin, component).runTaskTimer(plugin, 0, 20);
}
}

View file

@ -1,23 +1,25 @@
package alisolarflare.components.flairdoor.playerproximity;
package alisolarflare.components.flairdoor.proximitydetector;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import alisolarflare.components.flairdoor.FlairDoorComponent;
public class PlayerProximityTask extends BukkitRunnable{
public class PlayerProximityLoop extends BukkitRunnable implements Listener{
private JavaPlugin plugin;
private FlairDoorComponent component;
private Location startLocation;
private Location endLocation;
public PlayerProximityTask(JavaPlugin plugin, FlairDoorComponent component) {
public PlayerProximityLoop(JavaPlugin plugin, FlairDoorComponent component) {
this.plugin = plugin;
this.component = component;
this.startLocation = component.startLocation;
this.endLocation = component.endLocation;
this.runTaskTimer(plugin, 0, 20);
}
@Override

View file

@ -1,4 +1,4 @@
package alisolarflare.components.flairdoor.playerproximity;
package alisolarflare.components.flairdoor.proximitydetector;
import org.bukkit.entity.Player;

View file

@ -4,7 +4,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import alisolarflare.architecture.Component;
import alisolarflare.components.gpowers.commands.GPower;
import alisolarflare.components.gpowers.enchant.Enchanter;
import alisolarflare.components.gpowers.enchant.EnchantingLoop;
import alisolarflare.components.gpowers.powerstate.PowerDown;
import alisolarflare.components.gpowers.powerstate.PowerUp;
@ -17,7 +17,7 @@ public class GPowerComponent extends Component {
registerCommand(plugin, new PowerUp(gPowerMemory));
registerCommand(plugin, new PowerDown(gPowerMemory));
registerListener(plugin, new Enchanter(plugin, gPowerMemory));
registerListener(plugin, new EnchantingLoop(plugin, gPowerMemory));
}

View file

@ -15,13 +15,13 @@ import org.bukkit.scheduler.BukkitRunnable;
import alisolarflare.components.gpowers.GPowerMemory;
import alisolarflare.components.gpowers.GPowerMemory.poweredPlayer;
public class Enchanter extends BukkitRunnable implements Listener{
public class EnchantingLoop extends BukkitRunnable implements Listener{
private int powerLength = 300;
private Server server;
private Map<UUID, poweredPlayer> poweredPlayerList;
public Enchanter(JavaPlugin plugin, GPowerMemory gPowerMemory){
public EnchantingLoop(JavaPlugin plugin, GPowerMemory gPowerMemory){
this.server = plugin.getServer();
this.poweredPlayerList = gPowerMemory.poweredPlayerList;
this.runTaskTimer(plugin, 0, 190);

View file

@ -1,54 +1,29 @@
package alisolarflare.components.metrics;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import alisolarflare.architecture.Component;
import alisolarflare.components.metrics.collection.PlayerJoinListener;
import alisolarflare.components.metrics.files.MetricsFile;
import alisolarflare.components.metrics.output.GetLoginMetrics;
import buttondevteam.lib.TBMCCoreAPI;
public class MetricsComponent extends Component{
String defaultPath = "metrics";
String defaultFilePath = (defaultPath + "/metrics.txt");
String playerLoginsFilePath = (defaultPath + "/playerLogins.txt");
public FileConfiguration metricsYml; // DATA - STRING
public MetricsFile playerLoginsFile; // DATA - STRING
public List<String> metricsList;
@Override
public void register(JavaPlugin plugin){
playerLoginsFile = new MetricsFile(playerLoginsFilePath);
registerCommand(plugin, new GetLoginMetrics(this));
registerListener(plugin, new PlayerJoinListener(this));
registerListener(plugin, new PlayerJoinListener(this, playerLoginsFile));
metricsList = new ArrayList<String>();
try {
metricsYml = loadFileConfiguration(plugin, "metrics.yml");
metricsList = metricsYml.getStringList("playerLogins");
} catch (IOException | InvalidConfigurationException e) {
TBMCCoreAPI.SendException("metrics.yml in AliPresents could not be created!", e);
return;
}
}
private FileConfiguration loadFileConfiguration(JavaPlugin plugin, String fileName) throws FileNotFoundException, IOException, InvalidConfigurationException {
File file = new File(plugin.getDataFolder(), fileName);
if (!file.exists()) {
file.getParentFile().mkdirs();
plugin.saveResource(fileName, false);
}
FileConfiguration config = new YamlConfiguration();
config.load(file);
return config;
}
}

View file

@ -5,33 +5,19 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import alisolarflare.components.metrics.MetricsComponent;
import buttondevteam.lib.DebugPotato;
import alisolarflare.components.metrics.files.MetricsFile;
public class PlayerJoinListener implements Listener{
private MetricsComponent module;
public PlayerJoinListener(MetricsComponent module){
private MetricsFile playerLoginsFile;
public PlayerJoinListener(MetricsComponent module, MetricsFile playerLoginsFile){
this.module = module;
this.playerLoginsFile = playerLoginsFile;
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event){
try{
module.saveData(module.metricsYml, "loginlog."+System.currentTimeMillis()+event.getPlayer().getName(), event.getPlayer().getName());
}catch(NullPointerException e){
try{
DebugPotato potato = new DebugPotato();
potato.setMessage(new String[]{
"Module: "+ module.toString(),
"Time: " + System.currentTimeMillis(),
"MetricsYML: " + module.metricsYml.toString()
});
potato.Send(event.getPlayer());
}catch (Exception ex){
DebugPotato potato = new DebugPotato();
potato.setMessage("Something went REALLLY wrong");
potato.Send(event.getPlayer());
}
}
playerLoginsFile.AddLine("loginlog."+System.currentTimeMillis()+event.getPlayer().getName());
module.metricsList.add("loginlog."+System.currentTimeMillis()+event.getPlayer().getName());
}

View file

@ -0,0 +1,50 @@
package alisolarflare.components.metrics.files;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import buttondevteam.lib.TBMCCoreAPI;
public class MetricsFile {
private String fileName = "metrics/playerLogins.txt";
public MetricsFile(String directory){
this.fileName = directory;
}
public void AddLine(String string){
BufferedWriter outputStream = null;
try {
outputStream = new BufferedWriter(new FileWriter(fileName, true));
outputStream.write(string);
outputStream.newLine();
outputStream.close();
} catch (IOException e) {
TBMCCoreAPI.SendException(fileName +" Output Stream could not be created!", e);
}
}
public List<String> toArrayList(){
BufferedReader inputStream = null;
try {
inputStream = new BufferedReader(new FileReader(fileName));
List<String> outputList = new ArrayList<String>();
String currentLine;
while ((currentLine = inputStream.readLine()) != null){
outputList.add(currentLine);
}
inputStream.close();
return outputList;
} catch (FileNotFoundException e) {
TBMCCoreAPI.SendException(" could not be found", e);
} catch (IOException e1) {
TBMCCoreAPI.SendException("encountered an I/O Exception!", e1);
}
return new ArrayList<String>();
}
}

View file

@ -15,12 +15,9 @@ public class GetLoginMetrics extends ModCommand{
@Override
public boolean OnCommand(Player player, String alias, String[] args) {
for (String metric : module.metricsList){
for (String metric : module.playerLoginsFile.toArrayList()){
player.sendMessage(metric);
}
if (args.length < 1){
return true;
}
return true;
}
}