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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.github.tbmcplugins</groupId>
|
<groupId>com.github.tbmcplugins</groupId>
|
||||||
<artifactId>AliPresents</artifactId>
|
<artifactId>AliPresents</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<name>AliPresents</name>
|
<name>AliPresents</name>
|
||||||
<description>A bucket of aaall the stuff Ali makes. It's a bit smelly.</description>
|
<description>A bucket of aaall the stuff Ali makes. It's a bit smelly.</description>
|
||||||
<build>
|
<build>
|
||||||
<sourceDirectory>src</sourceDirectory>
|
<sourceDirectory>src</sourceDirectory>
|
||||||
<resources>
|
<resources>
|
||||||
<resource>
|
<resource>
|
||||||
<directory>src</directory>
|
<directory>src</directory>
|
||||||
<excludes>
|
<excludes>
|
||||||
<exclude>**/*.java</exclude>
|
<exclude>**/*.java</exclude>
|
||||||
</excludes>
|
</excludes>
|
||||||
</resource>
|
</resource>
|
||||||
<resource>
|
<resource>
|
||||||
<directory>.</directory>
|
<directory>.</directory>
|
||||||
<includes>
|
<includes>
|
||||||
<include>*.yml</include>
|
<include>*.yml</include>
|
||||||
</includes>
|
</includes>
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.3</version>
|
<version>3.3</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.8</source>
|
<source>1.8</source>
|
||||||
<target>1.8</target>
|
<target>1.8</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>spigot-repo</id>
|
<id>spigot-repo</id>
|
||||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository> <!-- This repo fixes issues with transitive dependencies -->
|
<repository> <!-- This repo fixes issues with transitive dependencies -->
|
||||||
<id>jcenter</id>
|
<id>jcenter</id>
|
||||||
<url>http://jcenter.bintray.com</url>
|
<url>http://jcenter.bintray.com</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>jitpack.io</id>
|
<id>jitpack.io</id>
|
||||||
<url>https://jitpack.io</url>
|
<url>https://jitpack.io</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>ess-repo</id>
|
<id>ess-repo</id>
|
||||||
<url>http://repo.ess3.net/content/groups/essentials</url>
|
<url>http://repo.ess3.net/content/groups/essentials</url>
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
<version>1.11-R0.1-SNAPSHOT</version>
|
<version>1.11-R0.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
|
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
<version>3.4</version>
|
<version>3.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.TBMCPlugins.ButtonCore</groupId>
|
<groupId>com.github.TBMCPlugins.ButtonCore</groupId>
|
||||||
<artifactId>ButtonCore</artifactId>
|
<artifactId>ButtonCore</artifactId>
|
||||||
<version>master-SNAPSHOT</version>
|
<version>master-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.ess3</groupId>
|
<groupId>net.ess3</groupId>
|
||||||
<artifactId>Essentials</artifactId>
|
<artifactId>Essentials</artifactId>
|
||||||
<version>2.13.1</version>
|
<version>2.13.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
<dependency>
|
||||||
</project>
|
<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;
|
package alisolarflare.components.flairdoor;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import alisolarflare.architecture.Component;
|
import alisolarflare.architecture.Component;
|
||||||
import alisolarflare.components.flairdoor.flairme.FlairMe;
|
import alisolarflare.components.flairdoor.flairme.FlairMe;
|
||||||
import alisolarflare.components.flairdoor.listeners.PortalListener;
|
import alisolarflare.components.flairdoor.listeners.PortalListener;
|
||||||
import alisolarflare.components.flairdoor.playerproximity.PlayerProximityTaskLauncher;
|
import alisolarflare.components.flairdoor.proximitydetector.PlayerProximityLoop;
|
||||||
import alisolarflare.components.flairdoor.playerproximity.SetProximityLocation;
|
import alisolarflare.components.flairdoor.proximitydetector.SetProximityLocation;
|
||||||
|
|
||||||
public class FlairDoorComponent extends Component {
|
public class FlairDoorComponent extends Component {
|
||||||
public List<Player> playersToBeFlaired = new ArrayList<Player>();
|
public List<Player> playersToBeFlaired = new ArrayList<Player>();
|
||||||
public Location startLocation = null;
|
public Location startLocation = null;
|
||||||
public Location endLocation = null;
|
public Location endLocation = null;
|
||||||
@Override
|
@Override
|
||||||
public void register(JavaPlugin plugin) {
|
public void register(JavaPlugin plugin) {
|
||||||
registerCommand(plugin, new FlairMe(this));
|
registerCommand(plugin, new FlairMe(this));
|
||||||
registerCommand(plugin, new SetProximityLocation(this));
|
registerCommand(plugin, new SetProximityLocation(this));
|
||||||
registerListener(plugin, new PortalListener(plugin, this));
|
registerListener(plugin, new PortalListener(plugin, this));
|
||||||
registerListener(plugin, new PlayerProximityTaskLauncher(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.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import alisolarflare.components.flairdoor.FlairDoorComponent;
|
import alisolarflare.components.flairdoor.FlairDoorComponent;
|
||||||
|
|
||||||
public class PlayerProximityTask extends BukkitRunnable{
|
public class PlayerProximityLoop extends BukkitRunnable implements Listener{
|
||||||
private JavaPlugin plugin;
|
private JavaPlugin plugin;
|
||||||
private FlairDoorComponent component;
|
private FlairDoorComponent component;
|
||||||
private Location startLocation;
|
private Location startLocation;
|
||||||
private Location endLocation;
|
private Location endLocation;
|
||||||
|
|
||||||
public PlayerProximityTask(JavaPlugin plugin, FlairDoorComponent component) {
|
public PlayerProximityLoop(JavaPlugin plugin, FlairDoorComponent component) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.component = component;
|
this.component = component;
|
||||||
this.startLocation = component.startLocation;
|
this.startLocation = component.startLocation;
|
||||||
this.endLocation = component.endLocation;
|
this.endLocation = component.endLocation;
|
||||||
|
this.runTaskTimer(plugin, 0, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
|
@ -1,4 +1,4 @@
|
||||||
package alisolarflare.components.flairdoor.playerproximity;
|
package alisolarflare.components.flairdoor.proximitydetector;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
|
@ -4,7 +4,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import alisolarflare.architecture.Component;
|
import alisolarflare.architecture.Component;
|
||||||
import alisolarflare.components.gpowers.commands.GPower;
|
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.PowerDown;
|
||||||
import alisolarflare.components.gpowers.powerstate.PowerUp;
|
import alisolarflare.components.gpowers.powerstate.PowerUp;
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ public class GPowerComponent extends Component {
|
||||||
registerCommand(plugin, new PowerUp(gPowerMemory));
|
registerCommand(plugin, new PowerUp(gPowerMemory));
|
||||||
registerCommand(plugin, new PowerDown(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;
|
package alisolarflare.components.gpowers.enchant;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import alisolarflare.components.gpowers.GPowerMemory;
|
import alisolarflare.components.gpowers.GPowerMemory;
|
||||||
import alisolarflare.components.gpowers.GPowerMemory.poweredPlayer;
|
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 int powerLength = 300;
|
||||||
private Server server;
|
private Server server;
|
||||||
private Map<UUID, poweredPlayer> poweredPlayerList;
|
private Map<UUID, poweredPlayer> poweredPlayerList;
|
||||||
|
|
||||||
|
|
||||||
public Enchanter(JavaPlugin plugin, GPowerMemory gPowerMemory){
|
public EnchantingLoop(JavaPlugin plugin, GPowerMemory gPowerMemory){
|
||||||
this.server = plugin.getServer();
|
this.server = plugin.getServer();
|
||||||
this.poweredPlayerList = gPowerMemory.poweredPlayerList;
|
this.poweredPlayerList = gPowerMemory.poweredPlayerList;
|
||||||
this.runTaskTimer(plugin, 0, 190);
|
this.runTaskTimer(plugin, 0, 190);
|
||||||
}
|
}
|
||||||
|
|
||||||
//REPEATS EVERY 5 SECONDS
|
//REPEATS EVERY 5 SECONDS
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
//server.broadcastMessage("ping!");
|
//server.broadcastMessage("ping!");
|
||||||
for (Player player : server.getOnlinePlayers()){
|
for (Player player : server.getOnlinePlayers()){
|
||||||
if(poweredPlayerList.containsKey(player.getUniqueId()) && poweredPlayerList.get(player.getUniqueId()).isPowersActive){
|
if(poweredPlayerList.containsKey(player.getUniqueId()) && poweredPlayerList.get(player.getUniqueId()).isPowersActive){
|
||||||
activatePower(player, poweredPlayerList.get(player.getUniqueId()).colour);
|
activatePower(player, poweredPlayerList.get(player.getUniqueId()).colour);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void activatePower(Player player, String colour) {
|
private void activatePower(Player player, String colour) {
|
||||||
//GREY
|
//GREY
|
||||||
for (PotionEffect potionEffect : player.getActivePotionEffects()){
|
for (PotionEffect potionEffect : player.getActivePotionEffects()){
|
||||||
player.removePotionEffect(potionEffect.getType());
|
player.removePotionEffect(potionEffect.getType());
|
||||||
}
|
}
|
||||||
if ((colour.startsWith("grey") || colour.startsWith("gra")) && (player.getWorld().getTime() > 12575 && player.getWorld().getTime() < 22925)){
|
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.REGENERATION, powerLength, 0, true, false, Color.GRAY), true);
|
||||||
player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, powerLength+100, 0, true, false, Color.GRAY), true);
|
player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, powerLength+100, 0, true, false, Color.GRAY), true);
|
||||||
//RED
|
//RED
|
||||||
}else if (colour.startsWith("r")){
|
}else if (colour.startsWith("r")){
|
||||||
player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, powerLength, 0, true, false, Color.RED), true);
|
player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, powerLength, 0, true, false, Color.RED), true);
|
||||||
//ORANGE
|
//ORANGE
|
||||||
}else if (colour.startsWith("o")){
|
}else if (colour.startsWith("o")){
|
||||||
player.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, powerLength, 0, true, false, Color.ORANGE), true);
|
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);
|
player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, powerLength, 0, true, false, Color.ORANGE), true);
|
||||||
//YELLOW
|
//YELLOW
|
||||||
}else if (colour.startsWith("y") && player.getLocation().getBlock().getLightFromSky() == 15 && player.getLocation().getBlock().getLightFromBlocks() == 15){
|
}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);
|
player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, powerLength, 0, true, false, Color.YELLOW), true);
|
||||||
//GREEN
|
//GREEN
|
||||||
}else if (colour.startsWith("g") && !colour.startsWith("gra") && !colour.startsWith("grey")){
|
}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.LUCK, powerLength, 1, true, false, Color.GREEN), true);
|
||||||
player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, powerLength, 0, true, false, Color.GREEN), true);
|
player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, powerLength, 0, true, false, Color.GREEN), true);
|
||||||
//BLUE
|
//BLUE
|
||||||
}else if (colour.startsWith("b")){
|
}else if (colour.startsWith("b")){
|
||||||
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, powerLength, 1, true, false, Color.BLUE), true);
|
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);
|
player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, powerLength, 0, true, false, Color.BLUE), true);
|
||||||
//PURPLE
|
//PURPLE
|
||||||
}else if (colour.startsWith("p")){
|
}else if (colour.startsWith("p")){
|
||||||
player.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, powerLength, 0, true, false, Color.PURPLE), true);
|
player.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, powerLength, 0, true, false, Color.PURPLE), true);
|
||||||
//NULL
|
//NULL
|
||||||
}else{
|
}else{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,54 +1,29 @@
|
||||||
package alisolarflare.components.metrics;
|
package alisolarflare.components.metrics;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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 org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import alisolarflare.architecture.Component;
|
import alisolarflare.architecture.Component;
|
||||||
import alisolarflare.components.metrics.collection.PlayerJoinListener;
|
import alisolarflare.components.metrics.collection.PlayerJoinListener;
|
||||||
|
import alisolarflare.components.metrics.files.MetricsFile;
|
||||||
import alisolarflare.components.metrics.output.GetLoginMetrics;
|
import alisolarflare.components.metrics.output.GetLoginMetrics;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
|
||||||
|
|
||||||
public class MetricsComponent extends Component{
|
public class MetricsComponent extends Component{
|
||||||
|
String defaultPath = "metrics";
|
||||||
public FileConfiguration metricsYml; // DATA - STRING
|
String defaultFilePath = (defaultPath + "/metrics.txt");
|
||||||
|
String playerLoginsFilePath = (defaultPath + "/playerLogins.txt");
|
||||||
|
|
||||||
|
public MetricsFile playerLoginsFile; // DATA - STRING
|
||||||
public List<String> metricsList;
|
public List<String> metricsList;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void register(JavaPlugin plugin){
|
public void register(JavaPlugin plugin){
|
||||||
|
playerLoginsFile = new MetricsFile(playerLoginsFilePath);
|
||||||
registerCommand(plugin, new GetLoginMetrics(this));
|
registerCommand(plugin, new GetLoginMetrics(this));
|
||||||
registerListener(plugin, new PlayerJoinListener(this));
|
registerListener(plugin, new PlayerJoinListener(this, playerLoginsFile));
|
||||||
|
|
||||||
metricsList = new ArrayList<String>();
|
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 org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
import alisolarflare.components.metrics.MetricsComponent;
|
import alisolarflare.components.metrics.MetricsComponent;
|
||||||
import buttondevteam.lib.DebugPotato;
|
import alisolarflare.components.metrics.files.MetricsFile;
|
||||||
|
|
||||||
public class PlayerJoinListener implements Listener{
|
public class PlayerJoinListener implements Listener{
|
||||||
|
|
||||||
private MetricsComponent module;
|
private MetricsComponent module;
|
||||||
public PlayerJoinListener(MetricsComponent module){
|
private MetricsFile playerLoginsFile;
|
||||||
|
public PlayerJoinListener(MetricsComponent module, MetricsFile playerLoginsFile){
|
||||||
this.module = module;
|
this.module = module;
|
||||||
|
this.playerLoginsFile = playerLoginsFile;
|
||||||
}
|
}
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoin(PlayerJoinEvent event){
|
public void onPlayerJoin(PlayerJoinEvent event){
|
||||||
try{
|
playerLoginsFile.AddLine("loginlog."+System.currentTimeMillis()+event.getPlayer().getName());
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
module.metricsList.add("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
|
@Override
|
||||||
public boolean OnCommand(Player player, String alias, String[] args) {
|
public boolean OnCommand(Player player, String alias, String[] args) {
|
||||||
for (String metric : module.metricsList){
|
for (String metric : module.playerLoginsFile.toArrayList()){
|
||||||
player.sendMessage(metric);
|
player.sendMessage(metric);
|
||||||
}
|
}
|
||||||
if (args.length < 1){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue