Command refactoring is in progress...

This commit is contained in:
Norbi Peti 2016-06-23 00:08:39 +02:00
parent da87a1293e
commit bce31de137
4 changed files with 1353 additions and 1750 deletions

View file

@ -1,37 +1,34 @@
name: TheButtonMCPlugin name: TheButtonMCPlugin
main: io.github.norbipeti.thebuttonmc.PluginMain main: io.github.norbipeti.thebuttonmc.PluginMain
version: 4.0 version: 4.0
commands: commands:
u: u:
description: Auto-flair system. Accept or ignore flair. description: Auto-flair system. Accept or ignore flair.
usage: "&cUsage: /u accept|ignore|opme&r" usage: "&cUsage: /u accept|ignore|opme&r"
nrp: ooc:
description: Send message in Out-of-Character. description: Send message in Out-of-Character.
usage: "&cUsage: /nrp <message>&r" usage: "&cUsage: /ooc <message>&r"
ooc: alias: nrp
description: Send message in Out-of-Character. unlol:
usage: "&cUsage: /ooc <message>&r" description: Unlaugh the last laugh.
unlol: alias: unlaugh
description: Unlaugh the last laugh. mwiki:
unlaugh: description: Search the wiki.
description: Unlaugh the last laugh. usage: "&cUsage: /mwiki [query]&r"
mwiki: dontrunthiscmd:
description: Search the wiki. tableflip:
usage: "&cUsage: /mwiki [query]&r" description: Flip a table.
dontrunthiscmd: usage: "&cUsage: /tableflip [message]&r"
tableflip: unflip:
description: Flip a table. description: Unflip a flip.
usage: "&cUsage: /tableflip [message]&r" usage: "&cUsage: /unflip [message]&r"
unflip: chatonly:
description: Unflip a flip. description: Enable chat only mode. Useful for chat clients.
usage: "&cUsage: /unflip [message]&r" usage: "&cUsage: /chatonly&r"
chatonly: author: NorbiPeti
description: Enable chat only mode. Useful for chat clients. depend: [Essentials, Towny, Minigames, Votifier, Factions, WorldGuard, WorldEdit, ProtocolLib, FastLogin, Vault, AuthMe]
usage: "&cUsage: /chatonly&r" permissions:
author: NorbiPeti tbmc.admin:
depend: [Essentials, Towny, Minigames, Votifier, Factions, WorldGuard, WorldEdit, ProtocolLib, FastLogin, Vault, AuthMe] description: Gives access to /un- commands and /u admin commands
permissions: tbmc.rainbow:
tbmc.admin: description: Gives access to rainbow colors (/u c).
description: Gives access to /un- commands and /u admin commands
tbmc.rainbow:
description: Gives access to rainbow colors (/u c).

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,429 +1,408 @@
package io.github.norbipeti.thebuttonmc; package io.github.norbipeti.thebuttonmc;
import net.milkbowl.vault.chat.Chat; import net.milkbowl.vault.chat.Chat;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission; import net.milkbowl.vault.permission.Permission;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Scoreboard;
import org.htmlcleaner.HtmlCleaner; import org.htmlcleaner.HtmlCleaner;
import org.htmlcleaner.TagNode; import org.htmlcleaner.TagNode;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import au.com.mineauz.minigames.mechanics.GameMechanics; import au.com.mineauz.minigames.mechanics.GameMechanics;
import com.palmergames.bukkit.towny.Towny; import com.palmergames.bukkit.towny.Towny;
import com.palmergames.bukkit.towny.object.Nation; import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownyUniverse; import com.palmergames.bukkit.towny.object.TownyUniverse;
import java.io.*; import io.github.norbipeti.thebuttonmc.commands.TBMCCommandBase;
import java.lang.String;
import java.lang.reflect.Method; import java.io.*;
import java.net.MalformedURLException; import java.lang.String;
import java.net.URL; import java.lang.reflect.Method;
import java.net.URLClassLoader; import java.net.MalformedURLException;
import java.net.URLConnection; import java.net.URL;
import java.text.SimpleDateFormat; import java.net.URLClassLoader;
import java.util.ArrayList; import java.net.URLConnection;
import java.util.Calendar; import java.text.SimpleDateFormat;
import java.util.Collection; import java.util.ArrayList;
import java.util.Date; import java.util.Calendar;
import java.util.TimeZone; import java.util.Collection;
import java.util.Date;
public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. import java.util.TimeZone;
// A user, which flair isn't obtainable:
// https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
public static PluginMain Instance; // A user, which flair isn't obtainable:
public static ConsoleCommandSender Console; // 2015.08.12. // https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
public static Scoreboard SB; public static PluginMain Instance;
public final static String FlairThreadURL = "https://www.reddit.com/r/TheButtonMinecraft/comments/433ptk/autoflair_thread/"; public static ConsoleCommandSender Console; // 2015.08.12.
public TownyUniverse TU; public static Scoreboard SB;
public ArrayList<Town> Towns; public final static String FlairThreadURL = "https://www.reddit.com/r/TheButtonMinecraft/comments/433ptk/autoflair_thread/";
public ArrayList<Nation> Nations; public TownyUniverse TU;
public ArrayList<Town> Towns;
// Fired when plugin is first enabled public ArrayList<Nation> Nations;
@Override
public void onEnable() { // Fired when plugin is first enabled
try { @Override
System.out.println("Extracting necessary libraries..."); public void onEnable() {
final File[] libs = new File[] { new File(getDataFolder(), try {
"htmlcleaner-2.16.jar") }; System.out.println("Extracting necessary libraries...");
for (final File lib : libs) { final File[] libs = new File[] { new File(getDataFolder(),
if (!lib.exists()) { "htmlcleaner-2.16.jar") };
JarUtils.extractFromJar(lib.getName(), for (final File lib : libs) {
lib.getAbsolutePath()); if (!lib.exists()) {
} JarUtils.extractFromJar(lib.getName(),
} lib.getAbsolutePath());
for (final File lib : libs) { }
if (!lib.exists()) { }
getLogger().warning( for (final File lib : libs) {
"Failed to load plugin! Could not find lib: " if (!lib.exists()) {
+ lib.getName()); getLogger().warning(
Bukkit.getServer().getPluginManager().disablePlugin(this); "Failed to load plugin! Could not find lib: "
return; + lib.getName());
} Bukkit.getServer().getPluginManager().disablePlugin(this);
addClassPath(JarUtils.getJarUrl(lib)); return;
} }
} catch (final Exception e) { addClassPath(JarUtils.getJarUrl(lib));
e.printStackTrace(); }
} } catch (final Exception e) {
e.printStackTrace();
getServer().getPluginManager().registerEvents(new PlayerListener(), }
this);
Commands comm = new Commands(); getServer().getPluginManager().registerEvents(new PlayerListener(),
this.getCommand("u").setExecutor(comm); this);
this.getCommand("u").setUsage( TBMCCommandBase.RegisterCommands(this);
this.getCommand("u").getUsage().replace('&', '§')); Instance = this;
this.getCommand("nrp").setExecutor(comm); Console = this.getServer().getConsoleSender();
this.getCommand("nrp").setUsage( LoadFiles(false);
this.getCommand("nrp").getUsage().replace('&', '§'));
this.getCommand("ooc").setExecutor(comm); SB = PluginMain.Instance.getServer().getScoreboardManager()
this.getCommand("ooc").setUsage( .getMainScoreboard(); // Main can be detected with @a[score_...]
this.getCommand("ooc").getUsage().replace('&', '§')); if (SB.getObjective("town") == null)
this.getCommand("unlol").setExecutor(comm); SB.registerNewObjective("town", "dummy");
this.getCommand("unlaugh").setExecutor(comm); if (SB.getObjective("nation") == null)
this.getCommand("mwiki").setExecutor(comm); SB.registerNewObjective("nation", "dummy");
this.getCommand("mwiki").setUsage( if (SB.getObjective("admin") == null)
this.getCommand("mwiki").getUsage().replace('&', '§')); SB.registerNewObjective("admin", "dummy");
this.getCommand("tableflip").setExecutor(comm); if (SB.getObjective("mod") == null)
this.getCommand("tableflip").setUsage( SB.registerNewObjective("mod", "dummy");
this.getCommand("tableflip").getUsage().replace('&', '§')); TU = ((Towny) Bukkit.getPluginManager().getPlugin("Towny"))
this.getCommand("unflip").setExecutor(comm); .getTownyUniverse();
this.getCommand("unflip").setUsage( Towns = new ArrayList<Town>(TU.getTownsMap().values());
this.getCommand("unflip").getUsage().replace('&', '§')); Nations = new ArrayList<Nation>(TU.getNationsMap().values());
this.getCommand("chatonly").setExecutor(comm);
this.getCommand("chatonly").setUsage( setupChat();
this.getCommand("chatonly").getUsage().replace('&', '§')); setupEconomy();
Instance = this; setupPermissions();
Console = this.getServer().getConsoleSender();
LoadFiles(false); GameMechanics.addGameMechanic(new CreativeGlobalMechanic());
SB = PluginMain.Instance.getServer().getScoreboardManager() Runnable r = new Runnable() {
.getMainScoreboard(); // Main can be detected with @a[score_...] public void run() {
if (SB.getObjective("town") == null) ThreadMethod();
SB.registerNewObjective("town", "dummy"); }
if (SB.getObjective("nation") == null) };
SB.registerNewObjective("nation", "dummy"); Thread t = new Thread(r);
if (SB.getObjective("admin") == null) t.start();
SB.registerNewObjective("admin", "dummy"); r = new Runnable() {
if (SB.getObjective("mod") == null) public void run() {
SB.registerNewObjective("mod", "dummy"); AnnouncerThread.Run();
TU = ((Towny) Bukkit.getPluginManager().getPlugin("Towny")) }
.getTownyUniverse(); };
Towns = new ArrayList<Town>(TU.getTownsMap().values()); t = new Thread(r);
Nations = new ArrayList<Nation>(TU.getNationsMap().values()); t.start();
}
setupChat();
setupEconomy(); public Boolean stop = false;
setupPermissions();
// Fired when plugin is disabled
GameMechanics.addGameMechanic(new CreativeGlobalMechanic()); @Override
public void onDisable() {
Runnable r = new Runnable() { SaveFiles(); // 2015.08.09.
public void run() { stop = true;
ThreadMethod(); }
}
}; private void ThreadMethod() {
Thread t = new Thread(r); while (!stop) {
t.start(); try {
r = new Runnable() { String body = DownloadString(FlairThreadURL
public void run() { + ".json?limit=1000");
AnnouncerThread.Run(); JSONArray json = new JSONArray(body).getJSONObject(1)
} .getJSONObject("data").getJSONArray("children");
}; for (Object obj : json) {
t = new Thread(r); JSONObject item = (JSONObject) obj;
t.start(); String author = item.getJSONObject("data").getString(
} "author");
String ign = item.getJSONObject("data").getString("body");
public Boolean stop = false; int start = ign.indexOf("IGN:") + "IGN:".length();
if (start == -1 + "IGN:".length()) // +length: 2015.08.10.
// Fired when plugin is disabled continue; // 2015.08.09.
@Override int end = ign.indexOf(' ', start);
public void onDisable() { if (end == -1 || end == start)
SaveFiles(); // 2015.08.09. end = ign.indexOf('\n', start); // 2015.07.15.
stop = true; if (end == -1 || end == start)
} ign = ign.substring(start);
else
private void ThreadMethod() { ign = ign.substring(start, end);
while (!stop) { ign = ign.trim();
try { MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(ign);
String body = DownloadString(FlairThreadURL if (mp == null)
+ ".json?limit=1000"); continue;
JSONArray json = new JSONArray(body).getJSONObject(1) if (!JoinedBefore(mp, 2015, 6, 5))
.getJSONObject("data").getJSONArray("children"); continue;
for (Object obj : json) { if (!mp.UserNames.contains(author))
JSONObject item = (JSONObject) obj; mp.UserNames.add(author);
String author = item.getJSONObject("data").getString( if (mp.FlairState.equals(FlairStates.NoComment)) {
"author"); mp.FlairState = FlairStates.Commented;
String ign = item.getJSONObject("data").getString("body"); ConfirmUserMessage(mp);
int start = ign.indexOf("IGN:") + "IGN:".length(); }
if (start == -1 + "IGN:".length()) // +length: 2015.08.10. try {
continue; // 2015.08.09. Thread.sleep(10);
int end = ign.indexOf(' ', start); } catch (InterruptedException ex) {
if (end == -1 || end == start) Thread.currentThread().interrupt();
end = ign.indexOf('\n', start); // 2015.07.15. }
if (end == -1 || end == start) }
ign = ign.substring(start); try {
else Thread.sleep(10000);
ign = ign.substring(start, end); } catch (InterruptedException ex) {
ign = ign.trim(); Thread.currentThread().interrupt();
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(ign); }
if (mp == null) } catch (Exception e) {
continue; // System.out.println("Error!\n" + e);
if (!JoinedBefore(mp, 2015, 6, 5)) LastException = e; // 2015.08.09.
continue; }
if (!mp.UserNames.contains(author)) }
mp.UserNames.add(author); }
if (mp.FlairState.equals(FlairStates.NoComment)) {
mp.FlairState = FlairStates.Commented; public void DownloadFlair(MaybeOfflinePlayer mp)
ConfirmUserMessage(mp); throws MalformedURLException, IOException {
} String[] flairdata = DownloadString(
try { "http://karmadecay.com/thebutton-data.php?users=" + mp.UserName)
Thread.sleep(10); .replace("\"", "").split(":");
} catch (InterruptedException ex) { String flair;
Thread.currentThread().interrupt(); if (flairdata.length > 1)
} flair = flairdata[1];
} else
try { flair = "";
Thread.sleep(10000); String flairclass;
} catch (InterruptedException ex) { if (flairdata.length > 2)
Thread.currentThread().interrupt(); flairclass = flairdata[2];
} else
} catch (Exception e) { flairclass = "unknown";
// System.out.println("Error!\n" + e); SetFlair(mp, flair, flairclass, mp.UserName);
LastException = e; // 2015.08.09. }
}
} public static Exception LastException; // 2015.08.09.
}
public String DownloadString(String urlstr) throws MalformedURLException,
public void DownloadFlair(MaybeOfflinePlayer mp) IOException {
throws MalformedURLException, IOException { URL url = new URL(urlstr);
String[] flairdata = DownloadString( URLConnection con = url.openConnection();
"http://karmadecay.com/thebutton-data.php?users=" + mp.UserName) con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
.replace("\"", "").split(":"); InputStream in = con.getInputStream();
String flair; String encoding = con.getContentEncoding();
if (flairdata.length > 1) encoding = encoding == null ? "UTF-8" : encoding;
flair = flairdata[1]; String body = IOUtils.toString(in, encoding);
else in.close();
flair = ""; return body;
String flairclass; }
if (flairdata.length > 2)
flairclass = flairdata[2]; private void SetFlair(MaybeOfflinePlayer p, String text, String flairclass,
else String username) {
flairclass = "unknown"; p.UserName = username;
SetFlair(mp, flair, flairclass, mp.UserName); p.FlairState = FlairStates.Recognised;
} switch (flairclass) {
case "cheater":
public static Exception LastException; // 2015.08.09. p.SetFlair((short) 0x5, true);
return;
public String DownloadString(String urlstr) throws MalformedURLException, case "unknown":
IOException { if (text.equals("-1")) // If true, only non-presser/can't press; if
URL url = new URL(urlstr); // false, any flair (but we can still detect
URLConnection con = url.openConnection(); // can't press)
con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); {
InputStream in = con.getInputStream(); try {
String encoding = con.getContentEncoding(); if (CheckForJoinDate(p)) {
encoding = encoding == null ? "UTF-8" : encoding; p.SetFlair(MaybeOfflinePlayer.FlairTimeNonPresser);
String body = IOUtils.toString(in, encoding); } else {
in.close(); p.SetFlair(MaybeOfflinePlayer.FlairTimeCantPress);
return body; }
} } catch (Exception e) {
p.FlairState = FlairStates.Commented; // Flair unknown
private void SetFlair(MaybeOfflinePlayer p, String text, String flairclass, p.SetFlair(MaybeOfflinePlayer.FlairTimeNone);
String username) { e.printStackTrace();
p.UserName = username; }
p.FlairState = FlairStates.Recognised; } else {
switch (flairclass) { try {
case "cheater": if (CheckForJoinDate(p)) {
p.SetFlair((short) 0x5, true); p.FlairState = FlairStates.Commented; // Flair unknown
return; p.SetFlair(MaybeOfflinePlayer.FlairTimeNone);
case "unknown": } else {
if (text.equals("-1")) // If true, only non-presser/can't press; if p.SetFlair(MaybeOfflinePlayer.FlairTimeCantPress);
// false, any flair (but we can still detect }
// can't press) } catch (Exception e) {
{ p.FlairState = FlairStates.Commented; // Flair unknown
try { p.SetFlair(MaybeOfflinePlayer.FlairTimeNone);
if (CheckForJoinDate(p)) { e.printStackTrace();
p.SetFlair(MaybeOfflinePlayer.FlairTimeNonPresser); }
} else { }
p.SetFlair(MaybeOfflinePlayer.FlairTimeCantPress); return;
} default:
} catch (Exception e) { break;
p.FlairState = FlairStates.Commented; // Flair unknown }
p.SetFlair(MaybeOfflinePlayer.FlairTimeNone); p.SetFlair(Short.parseShort(text));
e.printStackTrace(); }
}
} else { public static boolean CheckForJoinDate(MaybeOfflinePlayer mp)
try { throws Exception {
if (CheckForJoinDate(p)) { return JoinedBefore(mp, 2015, 4, 1);
p.FlairState = FlairStates.Commented; // Flair unknown }
p.SetFlair(MaybeOfflinePlayer.FlairTimeNone);
} else { public static boolean JoinedBefore(MaybeOfflinePlayer mp, int year,
p.SetFlair(MaybeOfflinePlayer.FlairTimeCantPress); int month, int day) throws Exception {
} URL url = new URL("https://www.reddit.com/u/" + mp.UserName);
} catch (Exception e) { URLConnection con = url.openConnection();
p.FlairState = FlairStates.Commented; // Flair unknown con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
p.SetFlair(MaybeOfflinePlayer.FlairTimeNone); InputStream in = con.getInputStream();
e.printStackTrace(); HtmlCleaner cleaner = new HtmlCleaner();
} TagNode node = cleaner.clean(in);
}
return; node = node.getElementsByAttValue("class", "age", true, true)[0];
default: node = node.getElementsByName("time", false)[0];
break; String joindate = node.getAttributeByName("datetime");
} SimpleDateFormat parserSDF = new SimpleDateFormat("yyyy-MM-dd");
p.SetFlair(Short.parseShort(text)); joindate = joindate.split("T")[0];
} Date date = parserSDF.parse(joindate);
return date.before(new Calendar.Builder()
public static boolean CheckForJoinDate(MaybeOfflinePlayer mp) .setTimeZone(TimeZone.getTimeZone("UTC"))
throws Exception { .setDate(year, month, day).build().getTime());
return JoinedBefore(mp, 2015, 4, 1); }
}
public static void ConfirmUserMessage(MaybeOfflinePlayer mp) {
public static boolean JoinedBefore(MaybeOfflinePlayer mp, int year, Player p = Bukkit.getPlayer(mp.UUID);
int month, int day) throws Exception { if (mp.FlairState.equals(FlairStates.Commented) && p != null)
URL url = new URL("https://www.reddit.com/u/" + mp.UserName); if (mp.UserNames.size() > 1)
URLConnection con = url.openConnection(); p.sendMessage("§9Multiple Reddit users commented your name. You can select with /u accept.§r §6Type /u accept or /u ignore§r");
con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); else
InputStream in = con.getInputStream(); p.sendMessage("§9A Reddit user commented your name. Is that you?§r §6Type /u accept or /u ignore§r");
HtmlCleaner cleaner = new HtmlCleaner(); }
TagNode node = cleaner.clean(in);
public static Collection<? extends Player> GetPlayers() {
node = node.getElementsByAttValue("class", "age", true, true)[0]; return Instance.getServer().getOnlinePlayers();
node = node.getElementsByName("time", false)[0]; }
String joindate = node.getAttributeByName("datetime");
SimpleDateFormat parserSDF = new SimpleDateFormat("yyyy-MM-dd"); public static ArrayList<String> AnnounceMessages = new ArrayList<>();
joindate = joindate.split("T")[0]; public static int AnnounceTime = 15 * 60 * 1000;
Date date = parserSDF.parse(joindate);
return date.before(new Calendar.Builder() public static void LoadFiles(boolean reload) {
.setTimeZone(TimeZone.getTimeZone("UTC")) if (reload) {
.setDate(year, month, day).build().getTime()); System.out
} .println("The Button Minecraft plugin cleanup for reloading...");
MaybeOfflinePlayer.AllPlayers.clear();
public static void ConfirmUserMessage(MaybeOfflinePlayer mp) { AnnounceMessages.clear();
Player p = Bukkit.getPlayer(mp.UUID); }
if (mp.FlairState.equals(FlairStates.Commented) && p != null) System.out.println("Loading files for The Button Minecraft plugin...");
if (mp.UserNames.size() > 1) try {
p.sendMessage("§9Multiple Reddit users commented your name. You can select with /u accept.§r §6Type /u accept or /u ignore§r"); File file = new File("thebuttonmc.yml");
else if (file.exists()) {
p.sendMessage("§9A Reddit user commented your name. Is that you?§r §6Type /u accept or /u ignore§r"); YamlConfiguration yc = new YamlConfiguration();
} yc.load(file);
MaybeOfflinePlayer.Load(yc);
public static Collection<? extends Player> GetPlayers() { PlayerListener.NotificationSound = yc
return Instance.getServer().getOnlinePlayers(); .getString("notificationsound");
} PlayerListener.NotificationPitch = yc
.getDouble("notificationpitch");
public static ArrayList<String> AnnounceMessages = new ArrayList<>(); AnnounceTime = yc.getInt("announcetime");
public static int AnnounceTime = 15 * 60 * 1000; AnnounceMessages.addAll(yc.getStringList("announcements"));
PlayerListener.AlphaDeaths = yc.getInt("alphadeaths");
public static void LoadFiles(boolean reload) { }
if (reload) { System.out.println("The Button Minecraft plugin loaded files!");
System.out } catch (IOException e) {
.println("The Button Minecraft plugin cleanup for reloading..."); System.out.println("Error!\n" + e);
MaybeOfflinePlayer.AllPlayers.clear(); LastException = e;
AnnounceMessages.clear(); } catch (InvalidConfigurationException e) {
} System.out.println("Error!\n" + e);
System.out.println("Loading files for The Button Minecraft plugin..."); LastException = e;
try { }
File file = new File("thebuttonmc.yml"); }
if (file.exists()) {
YamlConfiguration yc = new YamlConfiguration(); public static void SaveFiles() {
yc.load(file); System.out.println("Saving files for The Button Minecraft plugin...");
MaybeOfflinePlayer.Load(yc); try {
PlayerListener.NotificationSound = yc File file = new File("thebuttonmc.yml");
.getString("notificationsound"); YamlConfiguration yc = new YamlConfiguration();
PlayerListener.NotificationPitch = yc MaybeOfflinePlayer.Save(yc);
.getDouble("notificationpitch"); yc.set("notificationsound", PlayerListener.NotificationSound);
AnnounceTime = yc.getInt("announcetime"); yc.set("notificationpitch", PlayerListener.NotificationPitch);
AnnounceMessages.addAll(yc.getStringList("announcements")); yc.set("announcetime", AnnounceTime);
PlayerListener.AlphaDeaths = yc.getInt("alphadeaths"); yc.set("announcements", AnnounceMessages);
} yc.set("alphadeaths", PlayerListener.AlphaDeaths);
System.out.println("The Button Minecraft plugin loaded files!"); yc.save(file);
} catch (IOException e) { System.out.println("The Button Minecraft plugin saved files!");
System.out.println("Error!\n" + e); } catch (IOException e) {
LastException = e; System.out.println("Error!\n" + e);
} catch (InvalidConfigurationException e) { LastException = e;
System.out.println("Error!\n" + e); }
LastException = e; }
}
} private void addClassPath(final URL url) throws IOException {
final URLClassLoader sysloader = (URLClassLoader) ClassLoader
public static void SaveFiles() { .getSystemClassLoader();
System.out.println("Saving files for The Button Minecraft plugin..."); final Class<URLClassLoader> sysclass = URLClassLoader.class;
try { try {
File file = new File("thebuttonmc.yml"); final Method method = sysclass.getDeclaredMethod("addURL",
YamlConfiguration yc = new YamlConfiguration(); new Class[] { URL.class });
MaybeOfflinePlayer.Save(yc); method.setAccessible(true);
yc.set("notificationsound", PlayerListener.NotificationSound); method.invoke(sysloader, new Object[] { url });
yc.set("notificationpitch", PlayerListener.NotificationPitch); } catch (final Throwable t) {
yc.set("announcetime", AnnounceTime); t.printStackTrace();
yc.set("announcements", AnnounceMessages); throw new IOException("Error adding " + url
yc.set("alphadeaths", PlayerListener.AlphaDeaths); + " to system classloader");
yc.save(file); }
System.out.println("The Button Minecraft plugin saved files!"); }
} catch (IOException e) {
System.out.println("Error!\n" + e); public static Permission permission = null;
LastException = e; public static Economy economy = null;
} public static Chat chat = null;
}
private boolean setupPermissions() {
private void addClassPath(final URL url) throws IOException { RegisteredServiceProvider<Permission> permissionProvider = getServer()
final URLClassLoader sysloader = (URLClassLoader) ClassLoader .getServicesManager().getRegistration(
.getSystemClassLoader(); net.milkbowl.vault.permission.Permission.class);
final Class<URLClassLoader> sysclass = URLClassLoader.class; if (permissionProvider != null) {
try { permission = permissionProvider.getProvider();
final Method method = sysclass.getDeclaredMethod("addURL", }
new Class[] { URL.class }); return (permission != null);
method.setAccessible(true); }
method.invoke(sysloader, new Object[] { url });
} catch (final Throwable t) { private boolean setupChat() {
t.printStackTrace(); RegisteredServiceProvider<Chat> chatProvider = getServer()
throw new IOException("Error adding " + url .getServicesManager().getRegistration(
+ " to system classloader"); net.milkbowl.vault.chat.Chat.class);
} if (chatProvider != null) {
} chat = chatProvider.getProvider();
}
public static Permission permission = null;
public static Economy economy = null; return (chat != null);
public static Chat chat = null; }
private boolean setupPermissions() { private boolean setupEconomy() {
RegisteredServiceProvider<Permission> permissionProvider = getServer() RegisteredServiceProvider<Economy> economyProvider = getServer()
.getServicesManager().getRegistration( .getServicesManager().getRegistration(
net.milkbowl.vault.permission.Permission.class); net.milkbowl.vault.economy.Economy.class);
if (permissionProvider != null) { if (economyProvider != null) {
permission = permissionProvider.getProvider(); economy = economyProvider.getProvider();
} }
return (permission != null);
} return (economy != null);
}
private boolean setupChat() { }
RegisteredServiceProvider<Chat> chatProvider = getServer()
.getServicesManager().getRegistration(
net.milkbowl.vault.chat.Chat.class);
if (chatProvider != null) {
chat = chatProvider.getProvider();
}
return (chat != null);
}
private boolean setupEconomy() {
RegisteredServiceProvider<Economy> economyProvider = getServer()
.getServicesManager().getRegistration(
net.milkbowl.vault.economy.Economy.class);
if (economyProvider != null) {
economy = economyProvider.getProvider();
}
return (economy != null);
}
}