Saved Player Metrics to .txt file
This commit is contained in:
parent
173c0d5a70
commit
630d8ee23e
12 changed files with 267 additions and 258 deletions
1
metrics/playerLogins.txt
Normal file
1
metrics/playerLogins.txt
Normal file
|
@ -0,0 +1 @@
|
|||
Login List:
|
174
pom.xml
174
pom.xml
|
@ -1,82 +1,92 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.github.tbmcplugins</groupId>
|
||||
<artifactId>AliPresents</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>AliPresents</name>
|
||||
<description>A bucket of aaall the stuff Ali makes. It's a bit smelly.</description>
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src</directory>
|
||||
<excludes>
|
||||
<exclude>**/*.java</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>.</directory>
|
||||
<includes>
|
||||
<include>*.yml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.3</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository> <!-- This repo fixes issues with transitive dependencies -->
|
||||
<id>jcenter</id>
|
||||
<url>http://jcenter.bintray.com</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>ess-repo</id>
|
||||
<url>http://repo.ess3.net/content/groups/essentials</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.11-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.TBMCPlugins.ButtonCore</groupId>
|
||||
<artifactId>ButtonCore</artifactId>
|
||||
<version>master-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ess3</groupId>
|
||||
<artifactId>Essentials</artifactId>
|
||||
<version>2.13.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.github.tbmcplugins</groupId>
|
||||
<artifactId>AliPresents</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>AliPresents</name>
|
||||
<description>A bucket of aaall the stuff Ali makes. It's a bit smelly.</description>
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src</directory>
|
||||
<excludes>
|
||||
<exclude>**/*.java</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>.</directory>
|
||||
<includes>
|
||||
<include>*.yml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.3</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository> <!-- This repo fixes issues with transitive dependencies -->
|
||||
<id>jcenter</id>
|
||||
<url>http://jcenter.bintray.com</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>ess-repo</id>
|
||||
<url>http://repo.ess3.net/content/groups/essentials</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.11-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.TBMCPlugins.ButtonCore</groupId>
|
||||
<artifactId>ButtonCore</artifactId>
|
||||
<version>master-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ess3</groupId>
|
||||
<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>
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
package alisolarflare.components.flairdoor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
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;
|
||||
|
||||
public class FlairDoorComponent extends Component {
|
||||
public List<Player> playersToBeFlaired = new ArrayList<Player>();
|
||||
public Location startLocation = null;
|
||||
public Location endLocation = null;
|
||||
@Override
|
||||
public void register(JavaPlugin plugin) {
|
||||
registerCommand(plugin, new FlairMe(this));
|
||||
registerCommand(plugin, new SetProximityLocation(this));
|
||||
registerListener(plugin, new PortalListener(plugin, this));
|
||||
registerListener(plugin, new PlayerProximityTaskLauncher(plugin, this));
|
||||
}
|
||||
}
|
||||
package alisolarflare.components.flairdoor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
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.proximitydetector.PlayerProximityLoop;
|
||||
import alisolarflare.components.flairdoor.proximitydetector.SetProximityLocation;
|
||||
|
||||
public class FlairDoorComponent extends Component {
|
||||
public List<Player> playersToBeFlaired = new ArrayList<Player>();
|
||||
public Location startLocation = null;
|
||||
public Location endLocation = null;
|
||||
@Override
|
||||
public void register(JavaPlugin plugin) {
|
||||
registerCommand(plugin, new FlairMe(this));
|
||||
registerCommand(plugin, new SetProximityLocation(this));
|
||||
registerListener(plugin, new PortalListener(plugin, this));
|
||||
registerListener(plugin, new PlayerProximityLoop(plugin, this));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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
|
|
@ -1,4 +1,4 @@
|
|||
package alisolarflare.components.flairdoor.playerproximity;
|
||||
package alisolarflare.components.flairdoor.proximitydetector;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
|
@ -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));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,75 +1,75 @@
|
|||
package alisolarflare.components.gpowers.enchant;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import alisolarflare.components.gpowers.GPowerMemory;
|
||||
import alisolarflare.components.gpowers.GPowerMemory.poweredPlayer;
|
||||
|
||||
public class Enchanter extends BukkitRunnable implements Listener{
|
||||
private int powerLength = 300;
|
||||
private Server server;
|
||||
private Map<UUID, poweredPlayer> poweredPlayerList;
|
||||
|
||||
|
||||
public Enchanter(JavaPlugin plugin, GPowerMemory gPowerMemory){
|
||||
this.server = plugin.getServer();
|
||||
this.poweredPlayerList = gPowerMemory.poweredPlayerList;
|
||||
this.runTaskTimer(plugin, 0, 190);
|
||||
}
|
||||
|
||||
//REPEATS EVERY 5 SECONDS
|
||||
@Override
|
||||
public void run() {
|
||||
//server.broadcastMessage("ping!");
|
||||
for (Player player : server.getOnlinePlayers()){
|
||||
if(poweredPlayerList.containsKey(player.getUniqueId()) && poweredPlayerList.get(player.getUniqueId()).isPowersActive){
|
||||
activatePower(player, poweredPlayerList.get(player.getUniqueId()).colour);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void activatePower(Player player, String colour) {
|
||||
//GREY
|
||||
for (PotionEffect potionEffect : player.getActivePotionEffects()){
|
||||
player.removePotionEffect(potionEffect.getType());
|
||||
}
|
||||
if ((colour.startsWith("grey") || colour.startsWith("gra")) && (player.getWorld().getTime() > 12575 && player.getWorld().getTime() < 22925)){
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, powerLength, 0, true, false, Color.GRAY), true);
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, powerLength+100, 0, true, false, Color.GRAY), true);
|
||||
//RED
|
||||
}else if (colour.startsWith("r")){
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, powerLength, 0, true, false, Color.RED), true);
|
||||
//ORANGE
|
||||
}else if (colour.startsWith("o")){
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, powerLength, 0, true, false, Color.ORANGE), true);
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, powerLength, 0, true, false, Color.ORANGE), true);
|
||||
//YELLOW
|
||||
}else if (colour.startsWith("y") && player.getLocation().getBlock().getLightFromSky() == 15 && player.getLocation().getBlock().getLightFromBlocks() == 15){
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, powerLength, 0, true, false, Color.YELLOW), true);
|
||||
//GREEN
|
||||
}else if (colour.startsWith("g") && !colour.startsWith("gra") && !colour.startsWith("grey")){
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.LUCK, powerLength, 1, true, false, Color.GREEN), true);
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, powerLength, 0, true, false, Color.GREEN), true);
|
||||
//BLUE
|
||||
}else if (colour.startsWith("b")){
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, powerLength, 1, true, false, Color.BLUE), true);
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, powerLength, 0, true, false, Color.BLUE), true);
|
||||
//PURPLE
|
||||
}else if (colour.startsWith("p")){
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, powerLength, 0, true, false, Color.PURPLE), true);
|
||||
//NULL
|
||||
}else{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package alisolarflare.components.gpowers.enchant;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import alisolarflare.components.gpowers.GPowerMemory;
|
||||
import alisolarflare.components.gpowers.GPowerMemory.poweredPlayer;
|
||||
|
||||
public class EnchantingLoop extends BukkitRunnable implements Listener{
|
||||
private int powerLength = 300;
|
||||
private Server server;
|
||||
private Map<UUID, poweredPlayer> poweredPlayerList;
|
||||
|
||||
|
||||
public EnchantingLoop(JavaPlugin plugin, GPowerMemory gPowerMemory){
|
||||
this.server = plugin.getServer();
|
||||
this.poweredPlayerList = gPowerMemory.poweredPlayerList;
|
||||
this.runTaskTimer(plugin, 0, 190);
|
||||
}
|
||||
|
||||
//REPEATS EVERY 5 SECONDS
|
||||
@Override
|
||||
public void run() {
|
||||
//server.broadcastMessage("ping!");
|
||||
for (Player player : server.getOnlinePlayers()){
|
||||
if(poweredPlayerList.containsKey(player.getUniqueId()) && poweredPlayerList.get(player.getUniqueId()).isPowersActive){
|
||||
activatePower(player, poweredPlayerList.get(player.getUniqueId()).colour);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void activatePower(Player player, String colour) {
|
||||
//GREY
|
||||
for (PotionEffect potionEffect : player.getActivePotionEffects()){
|
||||
player.removePotionEffect(potionEffect.getType());
|
||||
}
|
||||
if ((colour.startsWith("grey") || colour.startsWith("gra")) && (player.getWorld().getTime() > 12575 && player.getWorld().getTime() < 22925)){
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, powerLength, 0, true, false, Color.GRAY), true);
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, powerLength+100, 0, true, false, Color.GRAY), true);
|
||||
//RED
|
||||
}else if (colour.startsWith("r")){
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, powerLength, 0, true, false, Color.RED), true);
|
||||
//ORANGE
|
||||
}else if (colour.startsWith("o")){
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, powerLength, 0, true, false, Color.ORANGE), true);
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, powerLength, 0, true, false, Color.ORANGE), true);
|
||||
//YELLOW
|
||||
}else if (colour.startsWith("y") && player.getLocation().getBlock().getLightFromSky() == 15 && player.getLocation().getBlock().getLightFromBlocks() == 15){
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, powerLength, 0, true, false, Color.YELLOW), true);
|
||||
//GREEN
|
||||
}else if (colour.startsWith("g") && !colour.startsWith("gra") && !colour.startsWith("grey")){
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.LUCK, powerLength, 1, true, false, Color.GREEN), true);
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, powerLength, 0, true, false, Color.GREEN), true);
|
||||
//BLUE
|
||||
}else if (colour.startsWith("b")){
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, powerLength, 1, true, false, Color.BLUE), true);
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, powerLength, 0, true, false, Color.BLUE), true);
|
||||
//PURPLE
|
||||
}else if (colour.startsWith("p")){
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, powerLength, 0, true, false, Color.PURPLE), true);
|
||||
//NULL
|
||||
}else{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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{
|
||||
|
||||
public FileConfiguration metricsYml; // DATA - STRING
|
||||
String defaultPath = "metrics";
|
||||
String defaultFilePath = (defaultPath + "/metrics.txt");
|
||||
String playerLoginsFilePath = (defaultPath + "/playerLogins.txt");
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
||||
}
|
||||
|
|
50
src/alisolarflare/components/metrics/files/MetricsFile.java
Normal file
50
src/alisolarflare/components/metrics/files/MetricsFile.java
Normal 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>();
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue