2015-07-16 11:51:59 +00:00
|
|
|
|
package tk.sznp.thebuttonautoflair;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.io.IOUtils;
|
2015-10-17 00:06:32 +00:00
|
|
|
|
import org.bukkit.Bukkit;
|
2015-08-12 11:52:27 +00:00
|
|
|
|
import org.bukkit.command.ConsoleCommandSender;
|
2015-10-17 00:06:32 +00:00
|
|
|
|
import org.bukkit.configuration.InvalidConfigurationException;
|
|
|
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
2015-07-16 11:51:59 +00:00
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
2015-12-30 12:31:59 +00:00
|
|
|
|
import org.bukkit.scoreboard.Scoreboard;
|
2015-12-04 22:07:21 +00:00
|
|
|
|
import org.htmlcleaner.HtmlCleaner;
|
|
|
|
|
import org.htmlcleaner.TagNode;
|
2015-07-16 11:51:59 +00:00
|
|
|
|
import org.json.JSONArray;
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
2015-12-30 12:31:59 +00:00
|
|
|
|
import com.palmergames.bukkit.towny.Towny;
|
|
|
|
|
import com.palmergames.bukkit.towny.object.Nation;
|
|
|
|
|
import com.palmergames.bukkit.towny.object.Town;
|
|
|
|
|
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
|
|
|
|
|
2015-08-18 23:09:16 +00:00
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.lang.String;
|
2015-12-04 22:07:21 +00:00
|
|
|
|
import java.lang.reflect.Method;
|
2015-08-18 23:09:16 +00:00
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
|
import java.net.URL;
|
2015-12-04 22:07:21 +00:00
|
|
|
|
import java.net.URLClassLoader;
|
2015-08-18 23:09:16 +00:00
|
|
|
|
import java.net.URLConnection;
|
2015-12-04 22:07:21 +00:00
|
|
|
|
import java.text.SimpleDateFormat;
|
2015-08-19 19:30:27 +00:00
|
|
|
|
import java.util.ArrayList;
|
2015-12-04 22:07:21 +00:00
|
|
|
|
import java.util.Calendar;
|
2015-08-18 23:09:16 +00:00
|
|
|
|
import java.util.Collection;
|
2015-12-04 22:07:21 +00:00
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.TimeZone;
|
2015-08-18 23:09:16 +00:00
|
|
|
|
|
2015-08-19 09:40:47 +00:00
|
|
|
|
public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
|
|
|
|
// A user, which flair isn't obtainable:
|
|
|
|
|
// https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
2015-08-19 19:30:27 +00:00
|
|
|
|
public static PluginMain Instance;
|
2015-08-19 09:40:47 +00:00
|
|
|
|
public static ConsoleCommandSender Console; // 2015.08.12.
|
2015-12-30 12:31:59 +00:00
|
|
|
|
public static Scoreboard SB;
|
|
|
|
|
public TownyUniverse TU;
|
|
|
|
|
public ArrayList<Town> Towns;
|
|
|
|
|
public ArrayList<Nation> Nations;
|
2015-07-20 16:23:02 +00:00
|
|
|
|
|
2015-08-19 09:40:47 +00:00
|
|
|
|
// Fired when plugin is first enabled
|
|
|
|
|
@Override
|
|
|
|
|
public void onEnable() {
|
2015-12-04 22:07:21 +00:00
|
|
|
|
try {
|
|
|
|
|
System.out.println("Extracting necessary libraries...");
|
|
|
|
|
final File[] libs = new File[] { new File(getDataFolder(),
|
|
|
|
|
"htmlcleaner-2.16.jar") };
|
|
|
|
|
for (final File lib : libs) {
|
|
|
|
|
if (!lib.exists()) {
|
|
|
|
|
JarUtils.extractFromJar(lib.getName(),
|
|
|
|
|
lib.getAbsolutePath());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (final File lib : libs) {
|
|
|
|
|
if (!lib.exists()) {
|
|
|
|
|
getLogger().warning(
|
|
|
|
|
"Failed to load plugin! Could not find lib: "
|
|
|
|
|
+ lib.getName());
|
|
|
|
|
Bukkit.getServer().getPluginManager().disablePlugin(this);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
addClassPath(JarUtils.getJarUrl(lib));
|
|
|
|
|
}
|
|
|
|
|
} catch (final Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-19 09:40:47 +00:00
|
|
|
|
getServer().getPluginManager().registerEvents(new PlayerListener(),
|
|
|
|
|
this);
|
2015-08-25 14:28:33 +00:00
|
|
|
|
Commands comm = new Commands();
|
|
|
|
|
this.getCommand("u").setExecutor(comm);
|
2015-08-19 09:40:47 +00:00
|
|
|
|
this.getCommand("u").setUsage(
|
|
|
|
|
this.getCommand("u").getUsage().replace('&', '<27>'));
|
2015-08-25 14:28:33 +00:00
|
|
|
|
this.getCommand("nrp").setExecutor(comm);
|
|
|
|
|
this.getCommand("nrp").setUsage(
|
|
|
|
|
this.getCommand("nrp").getUsage().replace('&', '<27>'));
|
2015-08-31 19:21:20 +00:00
|
|
|
|
this.getCommand("ooc").setExecutor(comm);
|
|
|
|
|
this.getCommand("ooc").setUsage(
|
|
|
|
|
this.getCommand("ooc").getUsage().replace('&', '<27>'));
|
2015-12-19 12:42:04 +00:00
|
|
|
|
this.getCommand("unlol").setExecutor(comm);
|
2016-01-08 19:59:52 +00:00
|
|
|
|
this.getCommand("unlaugh").setExecutor(comm);
|
2015-08-19 09:40:47 +00:00
|
|
|
|
Instance = this; // 2015.08.08.
|
|
|
|
|
Console = this.getServer().getConsoleSender(); // 2015.08.12.
|
|
|
|
|
LoadFiles(false); // 2015.08.09.
|
2015-12-30 12:31:59 +00:00
|
|
|
|
|
|
|
|
|
SB = PluginMain.Instance.getServer().getScoreboardManager()
|
|
|
|
|
.getMainScoreboard(); // Main can be detected with @a[score_...]
|
|
|
|
|
if (SB.getObjective("town") == null)
|
|
|
|
|
SB.registerNewObjective("town", "dummy");
|
|
|
|
|
if (SB.getObjective("nation") == null)
|
|
|
|
|
SB.registerNewObjective("nation", "dummy");
|
2015-12-31 16:32:54 +00:00
|
|
|
|
if (SB.getObjective("admin") == null)
|
|
|
|
|
SB.registerNewObjective("admin", "dummy");
|
|
|
|
|
if (SB.getObjective("mod") == null)
|
|
|
|
|
SB.registerNewObjective("mod", "dummy");
|
2015-12-30 12:31:59 +00:00
|
|
|
|
TU = ((Towny) Bukkit.getPluginManager().getPlugin("Towny"))
|
|
|
|
|
.getTownyUniverse();
|
|
|
|
|
Towns = new ArrayList<Town>(TU.getTownsMap().values());
|
|
|
|
|
Nations = new ArrayList<Nation>(TU.getNationsMap().values());
|
2015-12-31 16:50:43 +00:00
|
|
|
|
|
2015-08-19 09:40:47 +00:00
|
|
|
|
Runnable r = new Runnable() {
|
|
|
|
|
public void run() {
|
|
|
|
|
ThreadMethod();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Thread t = new Thread(r);
|
|
|
|
|
t.start();
|
2015-08-19 19:30:27 +00:00
|
|
|
|
r = new Runnable() {
|
|
|
|
|
public void run() {
|
|
|
|
|
AnnouncerThread.Run();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
t = new Thread(r);
|
|
|
|
|
t.start();
|
2015-08-19 09:40:47 +00:00
|
|
|
|
}
|
2015-08-18 23:09:16 +00:00
|
|
|
|
|
2015-08-19 19:30:27 +00:00
|
|
|
|
public Boolean stop = false;
|
2015-08-18 23:09:16 +00:00
|
|
|
|
|
2015-08-19 09:40:47 +00:00
|
|
|
|
// Fired when plugin is disabled
|
|
|
|
|
@Override
|
|
|
|
|
public void onDisable() {
|
|
|
|
|
SaveFiles(); // 2015.08.09.
|
|
|
|
|
stop = true;
|
|
|
|
|
}
|
2015-08-18 23:09:16 +00:00
|
|
|
|
|
2015-12-04 22:07:21 +00:00
|
|
|
|
private void ThreadMethod() {
|
2015-08-19 09:40:47 +00:00
|
|
|
|
while (!stop) {
|
|
|
|
|
try {
|
|
|
|
|
String body = DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
|
|
|
|
JSONArray json = new JSONArray(body).getJSONObject(1)
|
|
|
|
|
.getJSONObject("data").getJSONArray("children");
|
|
|
|
|
for (Object obj : json) {
|
|
|
|
|
JSONObject item = (JSONObject) obj;
|
|
|
|
|
String author = item.getJSONObject("data").getString(
|
|
|
|
|
"author");
|
|
|
|
|
String ign = item.getJSONObject("data").getString("body");
|
|
|
|
|
int start = ign.indexOf("IGN:") + "IGN:".length();
|
|
|
|
|
if (start == -1 + "IGN:".length()) // +length: 2015.08.10.
|
|
|
|
|
continue; // 2015.08.09.
|
|
|
|
|
int end = ign.indexOf(' ', start);
|
|
|
|
|
if (end == -1 || end == start)
|
|
|
|
|
end = ign.indexOf('\n', start); // 2015.07.15.
|
|
|
|
|
if (end == -1 || end == start)
|
|
|
|
|
ign = ign.substring(start);
|
|
|
|
|
else
|
|
|
|
|
ign = ign.substring(start, end);
|
|
|
|
|
ign = ign.trim();
|
2015-10-17 00:06:32 +00:00
|
|
|
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(ign);
|
2015-10-25 19:32:14 +00:00
|
|
|
|
if (mp == null)
|
2015-10-17 00:06:32 +00:00
|
|
|
|
continue;
|
2015-12-04 22:07:21 +00:00
|
|
|
|
if (!mp.UserNames.contains(author))
|
|
|
|
|
mp.UserNames.add(author);
|
2015-12-04 22:51:41 +00:00
|
|
|
|
if (mp.FlairState.equals(FlairStates.NoComment)) {
|
2015-12-04 22:07:21 +00:00
|
|
|
|
mp.FlairState = FlairStates.Commented;
|
2015-12-04 22:51:41 +00:00
|
|
|
|
ConfirmUserMessage(mp);
|
|
|
|
|
}
|
2015-08-19 09:40:47 +00:00
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(10);
|
|
|
|
|
} catch (InterruptedException ex) {
|
|
|
|
|
Thread.currentThread().interrupt();
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-08-19 19:30:27 +00:00
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(10000);
|
|
|
|
|
} catch (InterruptedException ex) {
|
|
|
|
|
Thread.currentThread().interrupt();
|
|
|
|
|
}
|
2015-08-19 09:40:47 +00:00
|
|
|
|
} catch (Exception e) {
|
2015-10-17 00:06:32 +00:00
|
|
|
|
// System.out.println("Error!\n" + e);
|
2015-08-19 09:40:47 +00:00
|
|
|
|
LastException = e; // 2015.08.09.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-08-18 23:09:16 +00:00
|
|
|
|
|
2015-12-04 22:07:21 +00:00
|
|
|
|
public void DownloadFlair(MaybeOfflinePlayer mp)
|
|
|
|
|
throws MalformedURLException, IOException {
|
|
|
|
|
String[] flairdata = DownloadString(
|
|
|
|
|
"http://karmadecay.com/thebutton-data.php?users=" + mp.UserName)
|
|
|
|
|
.replace("\"", "").split(":");
|
|
|
|
|
String flair;
|
|
|
|
|
if (flairdata.length > 1)
|
|
|
|
|
flair = flairdata[1];
|
|
|
|
|
else
|
|
|
|
|
flair = "";
|
|
|
|
|
String flairclass;
|
|
|
|
|
if (flairdata.length > 2)
|
|
|
|
|
flairclass = flairdata[2];
|
|
|
|
|
else
|
|
|
|
|
flairclass = "unknown";
|
|
|
|
|
SetFlair(mp, flair, flairclass, mp.UserName);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-19 09:40:47 +00:00
|
|
|
|
public static Exception LastException; // 2015.08.09.
|
2015-08-18 23:09:16 +00:00
|
|
|
|
|
2015-08-19 09:40:47 +00:00
|
|
|
|
public String DownloadString(String urlstr) throws MalformedURLException,
|
|
|
|
|
IOException {
|
|
|
|
|
URL url = new URL(urlstr);
|
|
|
|
|
URLConnection con = url.openConnection();
|
|
|
|
|
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
|
|
|
|
InputStream in = con.getInputStream();
|
|
|
|
|
String encoding = con.getContentEncoding();
|
|
|
|
|
encoding = encoding == null ? "UTF-8" : encoding;
|
|
|
|
|
String body = IOUtils.toString(in, encoding);
|
|
|
|
|
in.close();
|
|
|
|
|
return body;
|
|
|
|
|
}
|
2015-07-16 11:51:59 +00:00
|
|
|
|
|
2015-12-04 22:07:21 +00:00
|
|
|
|
private void SetFlair(MaybeOfflinePlayer p, String text, String flairclass,
|
2015-08-19 09:40:47 +00:00
|
|
|
|
String username) {
|
2015-11-20 22:02:22 +00:00
|
|
|
|
p.UserName = username;
|
2015-12-04 22:07:21 +00:00
|
|
|
|
p.FlairState = FlairStates.Recognised;
|
2015-08-19 09:40:47 +00:00
|
|
|
|
switch (flairclass) {
|
|
|
|
|
case "press-1":
|
2015-12-19 12:42:04 +00:00
|
|
|
|
p.SetFlairColor(0xc);
|
2015-08-19 09:40:47 +00:00
|
|
|
|
break;
|
|
|
|
|
case "press-2":
|
2015-12-19 12:42:04 +00:00
|
|
|
|
p.SetFlairColor(0x6);
|
2015-08-19 09:40:47 +00:00
|
|
|
|
break;
|
|
|
|
|
case "press-3":
|
2015-12-19 12:42:04 +00:00
|
|
|
|
p.SetFlairColor(0xe);
|
2015-08-19 09:40:47 +00:00
|
|
|
|
break;
|
|
|
|
|
case "press-4":
|
2015-12-19 12:42:04 +00:00
|
|
|
|
p.SetFlairColor(0xa);
|
2015-08-19 09:40:47 +00:00
|
|
|
|
break;
|
|
|
|
|
case "press-5":
|
2015-12-19 12:42:04 +00:00
|
|
|
|
p.SetFlairColor(0x9);
|
2015-08-19 09:40:47 +00:00
|
|
|
|
break;
|
|
|
|
|
case "press-6":
|
2015-12-19 12:42:04 +00:00
|
|
|
|
p.SetFlairColor(0x5);
|
2015-08-19 09:40:47 +00:00
|
|
|
|
break;
|
|
|
|
|
case "no-press":
|
2015-12-19 12:42:04 +00:00
|
|
|
|
p.SetFlairColor(0x7);
|
2015-08-19 09:40:47 +00:00
|
|
|
|
break;
|
|
|
|
|
case "cheater":
|
2015-12-19 12:42:04 +00:00
|
|
|
|
p.SetFlairColor(0x5);
|
2015-08-19 09:40:47 +00:00
|
|
|
|
break;
|
2015-12-04 22:07:21 +00:00
|
|
|
|
case "cant-press":
|
2015-12-19 12:42:04 +00:00
|
|
|
|
p.SetFlairColor(0xf);
|
2015-08-19 09:40:47 +00:00
|
|
|
|
break;
|
|
|
|
|
case "unknown":
|
|
|
|
|
if (text.equals("-1")) // If true, only non-presser/can't press; if
|
2015-12-31 16:50:43 +00:00
|
|
|
|
// false, any flair (but we can still detect
|
|
|
|
|
// can't press)
|
2015-12-04 22:07:21 +00:00
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
if (CheckForJoinDate(p)) {
|
2015-12-19 12:42:04 +00:00
|
|
|
|
p.SetFlair(0x7, "--");
|
2015-12-04 22:07:21 +00:00
|
|
|
|
} else {
|
2015-12-19 12:42:04 +00:00
|
|
|
|
p.SetFlair(0xf, "--");
|
2015-12-04 22:07:21 +00:00
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
p.FlairState = FlairStates.Commented; // Flair unknown
|
2015-12-19 12:42:04 +00:00
|
|
|
|
p.SetFlairColor(0);
|
2015-12-04 22:07:21 +00:00
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2015-12-31 16:50:43 +00:00
|
|
|
|
try {
|
|
|
|
|
if (CheckForJoinDate(p)) {
|
|
|
|
|
p.FlairState = FlairStates.Commented; // Flair unknown
|
|
|
|
|
p.SetFlairColor(0);
|
|
|
|
|
} else {
|
|
|
|
|
p.SetFlair(0xf, "--");
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
p.FlairState = FlairStates.Commented; // Flair unknown
|
|
|
|
|
p.SetFlairColor(0);
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
2015-12-04 22:07:21 +00:00
|
|
|
|
}
|
|
|
|
|
return;
|
2015-08-19 09:40:47 +00:00
|
|
|
|
default:
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-12-05 14:27:33 +00:00
|
|
|
|
if (text.equals("-1"))
|
|
|
|
|
text = "--";
|
2015-12-19 12:42:04 +00:00
|
|
|
|
p.SetFlairTime(text);
|
2015-08-19 09:40:47 +00:00
|
|
|
|
}
|
2015-08-09 22:28:15 +00:00
|
|
|
|
|
2015-12-04 22:07:21 +00:00
|
|
|
|
public static boolean CheckForJoinDate(MaybeOfflinePlayer mp)
|
|
|
|
|
throws Exception {
|
|
|
|
|
URL url = new URL("https://www.reddit.com/u/" + mp.UserName);
|
|
|
|
|
URLConnection con = url.openConnection();
|
|
|
|
|
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
|
|
|
|
InputStream in = con.getInputStream();
|
|
|
|
|
HtmlCleaner cleaner = new HtmlCleaner();
|
|
|
|
|
TagNode node = cleaner.clean(in);
|
2015-08-18 23:09:16 +00:00
|
|
|
|
|
2015-12-04 22:07:21 +00:00
|
|
|
|
node = node.getElementsByAttValue("class", "age", true, true)[0];
|
|
|
|
|
node = node.getElementsByName("time", false)[0];
|
|
|
|
|
String joindate = node.getAttributeByName("datetime");
|
|
|
|
|
SimpleDateFormat parserSDF = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
joindate = joindate.split("T")[0];
|
|
|
|
|
Date date = parserSDF.parse(joindate);
|
|
|
|
|
return date.before(new Calendar.Builder()
|
|
|
|
|
.setTimeZone(TimeZone.getTimeZone("UTC")).setDate(2015, 4, 1)
|
2015-12-04 22:51:41 +00:00
|
|
|
|
.build().getTime());
|
2015-08-19 09:40:47 +00:00
|
|
|
|
}
|
2015-08-18 23:09:16 +00:00
|
|
|
|
|
2015-12-04 22:07:21 +00:00
|
|
|
|
public static void ConfirmUserMessage(MaybeOfflinePlayer mp) {
|
|
|
|
|
Player p = Bukkit.getPlayer(mp.UUID);
|
|
|
|
|
if (mp.FlairState.equals(FlairStates.Commented) && p != null)
|
2015-12-04 22:51:41 +00:00
|
|
|
|
if (mp.UserNames.size() > 1)
|
|
|
|
|
p.sendMessage("<EFBFBD>9Multiple Reddit users commented your name. You can select with /u accept.<2E>r <20>6Type /u accept or /u ignore<72>r");
|
|
|
|
|
else
|
|
|
|
|
p.sendMessage("<EFBFBD>9A Reddit user commented your name. Is that you?<3F>r <20>6Type /u accept or /u ignore<72>r");
|
2015-08-19 09:40:47 +00:00
|
|
|
|
}
|
2015-08-18 23:09:16 +00:00
|
|
|
|
|
2015-08-19 09:40:47 +00:00
|
|
|
|
public static Collection<? extends Player> GetPlayers() {
|
|
|
|
|
return Instance.getServer().getOnlinePlayers();
|
|
|
|
|
}
|
2015-08-18 23:09:16 +00:00
|
|
|
|
|
2015-08-19 19:30:27 +00:00
|
|
|
|
public static ArrayList<String> AnnounceMessages = new ArrayList<>();
|
|
|
|
|
public static int AnnounceTime = 15 * 60 * 1000;
|
|
|
|
|
|
2015-12-04 22:07:21 +00:00
|
|
|
|
public static void LoadFiles(boolean reload) {
|
|
|
|
|
if (reload) {
|
2015-08-19 09:40:47 +00:00
|
|
|
|
System.out
|
|
|
|
|
.println("The Button Minecraft plugin cleanup for reloading...");
|
|
|
|
|
MaybeOfflinePlayer.AllPlayers.clear();
|
2015-08-19 19:30:27 +00:00
|
|
|
|
AnnounceMessages.clear();
|
2015-08-19 09:40:47 +00:00
|
|
|
|
}
|
2015-12-04 22:07:21 +00:00
|
|
|
|
System.out.println("Loading files for The Button Minecraft plugin...");
|
2015-08-19 09:40:47 +00:00
|
|
|
|
try {
|
2015-12-30 12:31:59 +00:00
|
|
|
|
File file = new File("thebuttonmc.yml");
|
2015-08-19 09:40:47 +00:00
|
|
|
|
if (file.exists()) {
|
2015-10-17 00:06:32 +00:00
|
|
|
|
YamlConfiguration yc = new YamlConfiguration();
|
|
|
|
|
yc.load(file);
|
|
|
|
|
MaybeOfflinePlayer.Load(yc);
|
|
|
|
|
PlayerListener.NotificationSound = yc
|
|
|
|
|
.getString("notificationsound");
|
|
|
|
|
PlayerListener.NotificationPitch = yc
|
|
|
|
|
.getDouble("notificationpitch");
|
|
|
|
|
AnnounceTime = yc.getInt("announcetime");
|
|
|
|
|
AnnounceMessages.addAll(yc.getStringList("announcements"));
|
2015-12-31 16:50:43 +00:00
|
|
|
|
PlayerListener.AlphaDeaths = yc.getInt("alphadeaths");
|
2015-08-19 19:30:27 +00:00
|
|
|
|
}
|
2015-08-19 09:40:47 +00:00
|
|
|
|
System.out.println("The Button Minecraft plugin loaded files!");
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
System.out.println("Error!\n" + e);
|
2015-12-04 22:07:21 +00:00
|
|
|
|
LastException = e;
|
2015-10-17 00:06:32 +00:00
|
|
|
|
} catch (InvalidConfigurationException e) {
|
2015-08-19 09:40:47 +00:00
|
|
|
|
System.out.println("Error!\n" + e);
|
2015-12-04 22:07:21 +00:00
|
|
|
|
LastException = e;
|
2015-08-19 09:40:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-08-19 19:30:27 +00:00
|
|
|
|
|
2015-12-04 22:07:21 +00:00
|
|
|
|
public static void SaveFiles() {
|
|
|
|
|
System.out.println("Saving files for The Button Minecraft plugin...");
|
2015-08-19 19:30:27 +00:00
|
|
|
|
try {
|
2015-10-17 00:06:32 +00:00
|
|
|
|
File file = new File("thebuttonmc.yml");
|
|
|
|
|
YamlConfiguration yc = new YamlConfiguration();
|
|
|
|
|
MaybeOfflinePlayer.Save(yc);
|
|
|
|
|
yc.set("notificationsound", PlayerListener.NotificationSound);
|
|
|
|
|
yc.set("notificationpitch", PlayerListener.NotificationPitch);
|
|
|
|
|
yc.set("announcetime", AnnounceTime);
|
|
|
|
|
yc.set("announcements", AnnounceMessages);
|
2015-12-31 16:50:43 +00:00
|
|
|
|
yc.set("alphadeaths", PlayerListener.AlphaDeaths);
|
2015-10-17 00:06:32 +00:00
|
|
|
|
yc.save(file);
|
|
|
|
|
System.out.println("The Button Minecraft plugin saved files!");
|
2015-08-19 19:30:27 +00:00
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
System.out.println("Error!\n" + e);
|
2015-12-04 22:07:21 +00:00
|
|
|
|
LastException = e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addClassPath(final URL url) throws IOException {
|
|
|
|
|
final URLClassLoader sysloader = (URLClassLoader) ClassLoader
|
|
|
|
|
.getSystemClassLoader();
|
|
|
|
|
final Class<URLClassLoader> sysclass = URLClassLoader.class;
|
|
|
|
|
try {
|
|
|
|
|
final Method method = sysclass.getDeclaredMethod("addURL",
|
|
|
|
|
new Class[] { URL.class });
|
|
|
|
|
method.setAccessible(true);
|
|
|
|
|
method.invoke(sysloader, new Object[] { url });
|
|
|
|
|
} catch (final Throwable t) {
|
|
|
|
|
t.printStackTrace();
|
|
|
|
|
throw new IOException("Error adding " + url
|
|
|
|
|
+ " to system classloader");
|
2015-08-19 19:30:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-16 11:51:59 +00:00
|
|
|
|
}
|