resurrection/src/net/brysonsteck/Resurrection/Resurrection.java

135 lines
6 KiB
Java
Raw Normal View History

2021-06-06 11:49:01 -06:00
package net.brysonsteck.Resurrection;
2021-06-05 23:10:04 -06:00
2021-06-06 11:49:01 -06:00
import net.brysonsteck.Resurrection.commands.CommandAbout;
2021-06-06 12:18:29 -06:00
import net.brysonsteck.Resurrection.commands.CommandResurrect;
import net.brysonsteck.Resurrection.player.PlayerData;
2021-06-15 18:43:25 -06:00
import net.brysonsteck.Resurrection.player.PlayerListener;
2021-06-06 17:17:52 -06:00
import net.brysonsteck.Resurrection.startup.CheckForUpdate;
2021-06-06 19:10:32 -06:00
import org.bukkit.event.Listener;
2021-06-06 17:17:52 -06:00
import org.bukkit.plugin.PluginDescriptionFile;
2021-06-05 23:10:04 -06:00
import org.bukkit.plugin.java.JavaPlugin;
2021-06-06 19:10:32 -06:00
2021-06-16 17:15:44 -06:00
import java.io.File;
import java.io.IOException;
import java.util.Hashtable;
2021-06-06 19:10:32 -06:00
public class Resurrection extends JavaPlugin implements Listener {
2021-06-05 23:10:04 -06:00
//spigot things
@Override
public void onDisable() {
super.onDisable();
2021-06-15 20:23:28 -06:00
System.out.println("[Resurrection] Resurrection has completed shutdown.");
2021-06-05 23:10:04 -06:00
}
@Override
public void onEnable() {
super.onEnable();
2021-06-15 20:15:51 -06:00
System.out.println("[Resurrection] Resurrection is starting!");
2021-06-06 17:17:52 -06:00
PluginDescriptionFile pluginInfo = getDescription();
2021-06-06 19:10:32 -06:00
getServer().getPluginManager().registerEvents(this, this);
2021-06-06 17:17:52 -06:00
2021-06-15 20:23:28 -06:00
if (pluginInfo.getVersion().contains("beta")) {
// beta message
System.out.println("[Resurrection] ---------------------------------------------------------");
System.out.println("[Resurrection] WARNING!!!!");
System.out.println("[Resurrection] You are running a beta version of Resurrection!");
System.out.println("[Resurrection] ");
System.out.println("[Resurrection] This means that this plugin is early in development and");
System.out.println("[Resurrection] not completely finished, and as a result you may");
System.out.println("[Resurrection] experience unexpected doodads. Make sure that the plugin");
System.out.println("[Resurrection] is up-to-date for more features and bug fixes. The plugin");
System.out.println("[Resurrection] will now check for updates.");
System.out.println("[Resurrection] ---------------------------------------------------------");
2021-06-16 17:15:44 -06:00
} else {
System.out.println("[Resurrection] ---------------------------------------------------------");
}
System.out.println("[Resurrection] Locating the file \"playerData.resurrection\"...");
// check if playerData.resurrection exists
File playerFile = new File("playerData.resurrection");
if (!playerFile.exists()) {
System.out.println("[Resurrection] Player data file does not exist. Creating now in the \"plugins\" directory...");
try {
playerFile.createNewFile();
System.out.println("[Resurrection] Player data file created successfully.");
} catch (IOException e) {
System.out.println("[Resurrection] An error has occurred creating the player data file!");
e.printStackTrace();
}
} else {
System.out.println("[Resurrection] The player data file has been found!");
2021-06-15 20:23:28 -06:00
}
2021-06-15 20:15:51 -06:00
2021-06-16 17:15:44 -06:00
System.out.println("[Resurrection] ---------------------------------------------------------");
2021-06-06 17:17:52 -06:00
// check for updates
System.out.println("[Resurrection] Checking for updates...");
CheckForUpdate check = new CheckForUpdate();
String newestVersion = check.getVersion();
String newestVersionURL = check.getVersionURL();
if (pluginInfo.getVersion().equals(newestVersion)) {
System.out.println("[Resurrection] " + newestVersion + " is the latest version of Resurrection.");
} else {
System.out.println("[Resurrection] A new version of Resurrection is available! (current: " + pluginInfo.getVersion() + ", newest: " + newestVersion);
System.out.println("[Resurrection] You can download the latest release on GitHub here \\/");
System.out.println("[Resurrection] " + newestVersionURL);
}
2021-06-06 11:49:01 -06:00
2021-06-16 17:15:44 -06:00
System.out.println("[Resurrection] ---------------------------------------------------------");
2021-06-06 11:49:01 -06:00
// register listener
2021-06-06 11:06:51 -06:00
this.getServer().getPluginManager().registerEvents(new PlayerListener(), this);
2021-06-06 11:49:01 -06:00
// register commands
2021-06-15 20:15:51 -06:00
System.out.println("[Resurrection] Adding commands...");
2021-06-06 11:49:01 -06:00
this.getCommand("about").setExecutor(new CommandAbout());
2021-06-06 12:18:29 -06:00
this.getCommand("resurrect").setExecutor(new CommandResurrect());
2021-06-06 11:49:01 -06:00
2021-06-16 17:15:44 -06:00
System.out.println("[Resurrection] ---------------------------------------------------------");
2021-06-15 20:15:51 -06:00
System.out.println("[Resurrection] Successfully Started!");
2021-06-16 17:15:44 -06:00
System.out.println("[Resurrection] ---------------------------------------------------------");
2021-06-05 23:10:04 -06:00
}
public static void main(String[] args) {
2021-06-16 16:50:42 -06:00
// DO THIS
PlayerData playerData = new PlayerData();
System.out.println("--- Reading Player data file ---");
playerData.readData();
System.out.println(playerData.getPlayers());
System.out.println(playerData.getRawData());
System.out.println("--- Oh look! A new player joined. Adding them. ---");
2021-06-16 16:50:42 -06:00
String rawData = playerData.getRawData();
rawData = rawData + ";bryzinga,false,0";
playerData.saveData(rawData);
System.out.println(playerData.getPlayers());
System.out.println(playerData.getRawData());
System.out.println("--- A player has died! Update the data file! ---");
2021-06-16 16:50:42 -06:00
rawData = playerData.getRawData();
String[] rawPlayers = rawData.split(";");
String[] rawSinglePlayer = new String[3];
int index = 0;
for (String players : rawPlayers) {
if (players.startsWith("bryzinga")) {
String[] playerSplit = players.split(",");
playerSplit[1] = "true";
playerSplit[2] = "12345";
rawPlayers[index] = String.join(",", playerSplit);
break;
}
index++;
}
rawData = String.join(";", rawPlayers);
2021-06-16 16:50:42 -06:00
playerData.saveData(rawData);
System.out.println(rawData);
}
2021-06-05 23:10:04 -06:00
}