Reworked flair system, made improvements

This commit is contained in:
Norbi Peti 2015-12-04 23:07:21 +01:00
parent 08398300f4
commit ffbd560c26
63 changed files with 607 additions and 225 deletions

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>RemoteSystemsTempFiles</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
<nature>org.eclipse.rse.ui.remoteSystemsTempNature</nature>
</natures>
</projectDescription>

Binary file not shown.

View file

@ -1,10 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="lib" path="D:/Z - Norbi cucca/0 Projektek/TheButtonMCAutoFlairProto/Spigot server (build)/Spigot/Spigot-API/target/spigot-api-1.8.7-R0.1-SNAPSHOT-shaded.jar">
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src">
<attributes>
<attribute name="javadoc_location" value="https://hub.spigotmc.org/javadocs/spigot/"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="D:/Downloads/commons-io-2.4-bin/commons-io-2.4/commons-io-2.4.jar"/>
@ -13,5 +17,11 @@
<classpathentry kind="lib" path="D:/Downloads/1404231200wpdm_Towny_Advanced/Towny.jar"/>
<classpathentry kind="lib" path="D:/Z - Norbi cucca/0 Projektek/TheButtonMCAutoFlairProto/Spigot server/plugins/_/Minigames-1.7.0.jar"/>
<classpathentry kind="lib" path="D:/Z - Norbi cucca/0 Projektek/TheButtonMCAutoFlairProto/Spigot server/plugins/_/TownyChat.jar"/>
<classpathentry kind="output" path="bin"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="D:/Downloads/htmlcleaner-2.16/htmlcleaner-2.16.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View file

@ -10,8 +10,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View file

@ -8,4 +8,5 @@ org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.7

View file

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

Binary file not shown.

View file

@ -0,0 +1,35 @@
Copyright (c) 2006-2015, the HTMLCleaner project
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* The name of HtmlCleaner may not be used to endorse or promote
products derived from this software without specific prior
written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
You can contact Vladimir Nikic by sending e-mail to
nikic_vladimir@yahoo.com. Please include the word "HtmlCleaner" in the
subject line.

View file

@ -11,5 +11,7 @@ commands:
ooc:
description: Send message in Out-of-Character
usage: "&cUsage: /ooc <message>&r"
unlol:
description: Unlol the last lol. Context: https://www.reddit.com/r/TheButtonMinecraft/comments/3urd29//cxnecs8
author: NorbiPeti
depend: [Essentials, Towny, TownyChat, Minigames]

View file

@ -0,0 +1,69 @@
<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>
<artifactId>TheButtonMCPlugin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>The Button Minecraft Plugin</name>
<description>The Button Minecraft Plugin</description>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<exclude>classworlds:classworlds</exclude>
<exclude>junit:junit</exclude>
<exclude>jmock:*</exclude>
<exclude>*:xml-apis</exclude>
<exclude>org.apache.maven:lib:tests</exclude>
<exclude>log4j:log4j:jar:</exclude>
</excludes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<groupId>tk.sznp</groupId>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View file

@ -27,6 +27,7 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Random;
import java.util.Timer;
public class Commands implements CommandExecutor {
@ -44,81 +45,102 @@ public class Commands implements CommandExecutor {
return false;
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(player
.getUniqueId()); // 2015.08.08.
if (!p.CommentedOnReddit
&& !args[0].toLowerCase().equals("admin")
&& !args[0].toLowerCase().equals("ignore")
&& !args[0].toLowerCase().equals("kittycannon")) {
if (p.FlairState.equals(FlairStates.NoComment)) {
player.sendMessage("§cError: You need to write your username to the reddit thread at /r/TheButtonMinecraft§r");
return true;
}
if (!p.FlairRecognised
&& !args[0].toLowerCase().equals("admin")
&& !args[0].toLowerCase().equals("ignore")
&& !args[0].toLowerCase().equals("kittycannon")) {
player.sendMessage("Sorry, but your flair isn't recorded. Please ask a mod to set it for you.");
return true;
}
if (!p.FlairDecided && !args[0].toLowerCase().equals("admin")
&& !args[0].toLowerCase().equals("ignore")
&& !args[0].toLowerCase().equals("kittycannon")) {
player.sendMessage("Please select between /u nonpresser and /u cantpress");
return true;
}
switch (args[0].toLowerCase()) // toLowerCase: 2015.08.09.
{
case "accept": {
if (p.IgnoredFlair)
p.IgnoredFlair = false; // 2015.08.08.
if (!p.AcceptedFlair) {
String flair = p.Flair; // 2015.08.08.
p.AcceptedFlair = true; // 2015.08.08.
PluginMain.AppendPlayerDisplayFlair(p, player);
player.sendMessage("§bYour flair has been set:§r "
+ flair);
} else
if (args.length < 2 && p.UserNames.size() > 1) {
player.sendMessage("§9Multiple users commented your name. §bPlease pick one using /u accept <username>");
StringBuilder sb = new StringBuilder();
sb.append("§6Usernames:");
for (String username : p.UserNames)
sb.append(" ").append(username);
player.sendMessage(sb.toString());
return true;
}
if (p.FlairState.equals(FlairStates.NoComment)
|| p.UserNames.size() == 0) {
player.sendMessage("§cError: You need to write your username to the reddit thread at /r/TheButtonMinecraft§r");
return true;
}
if (args.length > 1 && !p.UserNames.contains(args[1])) {
player.sendMessage("§cError: Unknown name: " + args[1]
+ "§r");
return true;
}
if (p.Working) {
player.sendMessage("§cError: Something is already in progress.§r");
return true;
}
if ((args.length > 1 ? args[1] : p.UserNames.get(0))
.equals(p.UserName)) {
player.sendMessage("§cYou already have this user's flair.§r");
return true;
}
if (args.length > 1)
p.UserName = args[1];
else
p.UserName = p.UserNames.get(0);
player.sendMessage("§bObtaining flair...");
p.Working = true;
Timer timer = new Timer();
PlayerJoinTimerTask tt = new PlayerJoinTimerTask() {
@Override
public void run() {
try {
PluginMain.Instance.DownloadFlair(mp);
} catch (Exception e) {
e.printStackTrace();
}
Player player = Bukkit.getPlayer(mp.UUID);
if (mp.FlairState.equals(FlairStates.Commented)) {
player.sendMessage("Sorry, but your flair isn't recorded. Please ask an admin to set it for you. Also, prepare a comment on /r/thebutton, if possible.");
return;
}
String flair = mp.GetFormattedFlair();
mp.FlairState = FlairStates.Accepted;
PluginMain.ConfirmUserMessage(mp);
player.sendMessage("§bYour flair has been set:§r "
+ flair);
mp.Working = false;
}
};
tt.mp = p;
timer.schedule(tt, 20);
break;
}
case "ignore": {
if (p.AcceptedFlair)
p.AcceptedFlair = false; // 2015.08.08.
if (!p.IgnoredFlair) {
p.IgnoredFlair = true;
player.sendMessage("§bYou have ignored this request. You can still use /u accept though.§r");
if (p.FlairState.equals(FlairStates.NoComment)) {
player.sendMessage("§cError: You need to write your username to the reddit thread at /r/TheButtonMinecraft§r");
return true;
}
if (p.FlairState.equals(FlairStates.Commented)) {
player.sendMessage("Sorry, but your flair isn't recorded. Please ask a mod to set it for you.");
return true;
}
if (!p.FlairState.equals(FlairStates.Ignored)) {
p.FlairState = FlairStates.Ignored;
p.FlairTime = "";
p.UserName = "";
player.sendMessage("§bYou have removed your flair. You can still use /u accept to get one.§r");
} else
player.sendMessage("§cYou already ignored this request.§r");
player.sendMessage("§cYou already removed your flair.§r");
break;
}
case "admin": // 2015.08.09.
DoAdmin(player, args);
break;
case "nonpresser": // 2015.08.09.
if (!p.AcceptedFlair) {
player.sendMessage("§cYou need to accept the flair first.§r");
break;
}
if (p.FlairDecided) {
player.sendMessage("§cYou have already set the flair type.§r");
break;
}
SetPlayerFlair(player, p, "§7(--s)§r");
break;
case "cantpress": // 2015.08.09.
if (!p.AcceptedFlair) {
player.sendMessage("§cYou need to accept the flair first.§r");
break;
}
if (p.FlairDecided) {
player.sendMessage("§cYou have already set the flair type or your flair type is known.§r");
break;
}
SetPlayerFlair(player, p, "§r(??s)§r");
break;
case "opme": // 2015.08.10.
player.sendMessage("It would be nice, isn't it?"); // Sometimes
// I'm
// bored
// too
player.sendMessage("It would be nice, wouldn't it?"); // Sometimes
// I'm
// bored
// too
break;
case "announce":
DoAnnounce(player, args, null);
@ -128,14 +150,14 @@ public class Commands implements CommandExecutor {
player.sendMessage("§cUsage: /u name <playername>§r");
break;
}
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[1])) {
MaybeOfflinePlayer mp = MaybeOfflinePlayer
.GetFromName(args[1]);
if (mp == null) {
player.sendMessage("§cUnknown user: " + args[1]);
break;
}
player.sendMessage("§bUsername of "
+ args[1]
+ ": "
+ MaybeOfflinePlayer.AllPlayers.get(args[1]).UserName);
player.sendMessage("§bUsername of " + args[1] + ": "
+ mp.UserName);
break;
case "enable":
if (player.getName().equals("NorbiPeti")) {
@ -175,6 +197,8 @@ public class Commands implements CommandExecutor {
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = true;
}
return true;
case "unlol": // TODO: Unlol
return true;
default:
player.sendMessage("Unknown command: " + cmd.getName());
break;
@ -207,9 +231,9 @@ public class Commands implements CommandExecutor {
for (Player p : PluginMain.GetPlayers()) {
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p
.getUniqueId());
// if(mp.Flair!=null)
if (mp.CommentedOnReddit) {
PluginMain.AppendPlayerDisplayFlair(mp, p); // 2015.08.09.
if (mp.FlairState.equals(FlairStates.Recognised)
|| mp.FlairState.equals(FlairStates.Commented)) {
PluginMain.ConfirmUserMessage(mp);
}
String msg = "§bNote: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; // 2015.08.09.
p.sendMessage(msg); // 2015.08.09.
@ -307,13 +331,9 @@ public class Commands implements CommandExecutor {
return;
}
SendMessage(player, "Player name: " + p.PlayerName);
SendMessage(player, "User flair: " + p.Flair);
SendMessage(player, "User flair: " + p.GetFormattedFlair());
SendMessage(player, "Username: " + p.UserName);
SendMessage(player, "Flair accepted: " + p.AcceptedFlair);
SendMessage(player, "Flair ignored: " + p.IgnoredFlair);
SendMessage(player, "Flair decided: " + p.FlairDecided);
SendMessage(player, "Flair recognised: " + p.FlairRecognised);
SendMessage(player, "Commented on Reddit: " + p.CommentedOnReddit);
SendMessage(player, "Flair state: " + p.FlairState);
}
private static void SendMessage(Player player, String message) { // 2015.08.09.
@ -334,26 +354,21 @@ public class Commands implements CommandExecutor {
}
private static void SetPlayerFlair(Player player,
MaybeOfflinePlayer targetplayer, String flair) { // 2015.08.09.
flair = flair.replace('&', '§');
targetplayer.Flair = flair;
targetplayer.CommentedOnReddit = true; // Or at least has a flair in
// some way
targetplayer.FlairRecognised = true;
SendMessage(player, "§bThe flair has been set. Player: "
+ targetplayer.PlayerName + " Flair: " + flair + "§r");
MaybeOfflinePlayer targetplayer, short flaircolor, String flairtime) {
targetplayer.FlairColor = flaircolor;
targetplayer.FlairTime = flairtime;
targetplayer.FlairState = FlairStates.Accepted;
targetplayer.UserName = "";
SendMessage(player,
"§bThe flair has been set. Player: " + targetplayer.PlayerName
+ " Flair: " + targetplayer.GetFormattedFlair() + "§r");
}
private static void DoSetFlair(Player player, String[] args) {
// args[0] is "admin" - args[1] is "setflair"
if (args.length < 4) {
SendMessage(player,
"§cUsage: /u admin setflair <playername> <flair>");
return;
}
if (args[3].charAt(0) != '&') {
SendMessage(player,
"§cYou need to start the flair with a color code: &6(19s)&r");
"§cUsage: /u admin setflair <playername> <flaircolor> [number]");
return;
}
Player p = Bukkit.getPlayer(args[2]);
@ -361,8 +376,17 @@ public class Commands implements CommandExecutor {
SendMessage(player, "§cPLayer not found.&r");
return;
}
short flaircolor = 0x00;
try {
flaircolor = Short.parseShort(args[3], 16);
} catch (Exception e) {
SendMessage(player,
"§cFlaircolor must be a hexadecimal number (don't include &).");
return;
}
SetPlayerFlair(player,
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()), args[3]);
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()),
flaircolor, (args.length < 5 ? "" : args[4]));
}
private static void DoUpdatePlugin(Player player) { // 2015.08.10.

View file

@ -0,0 +1,5 @@
package tk.sznp.thebuttonautoflair;
public enum FlairStates {
Accepted, Ignored, Recognised, Commented, NoComment
}

View file

@ -0,0 +1,90 @@
package tk.sznp.thebuttonautoflair;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLDecoder;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
public class JarUtils {
public static boolean extractFromJar(final String fileName,
final String dest) throws IOException {
if (getRunningJar() == null) {
return false;
}
final File file = new File(dest);
if (file.isDirectory()) {
file.mkdir();
return false;
}
if (!file.exists()) {
file.getParentFile().mkdirs();
}
final JarFile jar = getRunningJar();
final Enumeration<JarEntry> e = jar.entries();
while (e.hasMoreElements()) {
final JarEntry je = e.nextElement();
if (!je.getName().contains(fileName)) {
continue;
}
final InputStream in = new BufferedInputStream(
jar.getInputStream(je));
final OutputStream out = new BufferedOutputStream(
new FileOutputStream(file));
copyInputStream(in, out);
jar.close();
return true;
}
jar.close();
return false;
}
private final static void copyInputStream(final InputStream in,
final OutputStream out) throws IOException {
try {
final byte[] buff = new byte[4096];
int n;
while ((n = in.read(buff)) > 0) {
out.write(buff, 0, n);
}
} finally {
out.flush();
out.close();
in.close();
}
}
public static URL getJarUrl(final File file) throws IOException {
return new URL("jar:" + file.toURI().toURL().toExternalForm() + "!/");
}
public static JarFile getRunningJar() throws IOException {
if (!RUNNING_FROM_JAR) {
return null; // null if not running from jar
}
String path = new File(JarUtils.class.getProtectionDomain()
.getCodeSource().getLocation().getPath()).getAbsolutePath();
path = URLDecoder.decode(path, "UTF-8");
return new JarFile(path);
}
private static boolean RUNNING_FROM_JAR = false;
static {
final URL resource = JarUtils.class.getClassLoader().getResource(
"plugin.yml");
if (resource != null) {
RUNNING_FROM_JAR = true;
}
}
}

View file

@ -1,25 +1,25 @@
package tk.sznp.thebuttonautoflair;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
public class MaybeOfflinePlayer { // 2015.08.08.
public class MaybeOfflinePlayer {
public String PlayerName;
public String UserName;
public String Flair; // If the user comments their name, it gets set, it
// doesn't matter if they accepted it or not
public boolean AcceptedFlair;
public boolean IgnoredFlair;
public boolean FlairDecided; // 2015.08.09. //TODO: Detect date
public boolean FlairRecognised; // 2015.08.10.
public boolean CommentedOnReddit; // 2015.08.10.
public boolean RPMode; // 2015.08.25.
public boolean PressedF; // 2015.09.18.
public Location SavedLocation; // 2015.10.02.
public List<String> UserNames;
public String FlairTime;
public short FlairColor;
public FlairStates FlairState;
public boolean RPMode = true;
public boolean PressedF;
public Location SavedLocation;
public boolean Working;
public UUID UUID;
@ -28,9 +28,11 @@ public class MaybeOfflinePlayer { // 2015.08.08.
public static MaybeOfflinePlayer AddPlayerIfNeeded(UUID uuid) {
if (!AllPlayers.containsKey(uuid)) {
MaybeOfflinePlayer player = new MaybeOfflinePlayer();
// player.PlayerName = playername;
player.UUID = uuid;
player.Flair = ""; // 2015.08.10.
player.FlairColor = 0;
player.FlairTime = "";
player.FlairState = FlairStates.NoComment;
player.UserNames = new ArrayList<>();
AllPlayers.put(uuid, player);
return player;
}
@ -44,38 +46,44 @@ public class MaybeOfflinePlayer { // 2015.08.08.
MaybeOfflinePlayer mp = AddPlayerIfNeeded(java.util.UUID
.fromString(cs2.getString("uuid")));
mp.UserName = cs2.getString("username");
mp.Flair = cs2.getString("flair");
mp.AcceptedFlair = cs2.getBoolean("acceptedflair");
mp.IgnoredFlair = cs2.getBoolean("ignoredflair");
mp.FlairDecided = cs2.getBoolean("flairdecided");
mp.FlairRecognised = cs2.getBoolean("flairrecognised");
mp.CommentedOnReddit = cs2.getBoolean("commentedonreddit");
mp.FlairColor = (short) cs2.getInt("flaircolor");
mp.FlairTime = cs2.getString("flairtime");
String flairstate = cs2.getString("flairstate");
if (flairstate != null)
mp.FlairState = FlairStates.valueOf(flairstate);
else
mp.FlairState = FlairStates.NoComment;
mp.PlayerName = cs2.getString("playername");
mp.UserNames = cs2.getStringList("usernames");
}
}
public static void Save(YamlConfiguration yc) {
ConfigurationSection cs = yc
.createSection("players");
ConfigurationSection cs = yc.createSection("players");
for (MaybeOfflinePlayer mp : MaybeOfflinePlayer.AllPlayers.values()) {
ConfigurationSection cs2 = cs.createSection(mp.UUID.toString());
cs2.set("playername", mp.PlayerName);
cs2.set("username", mp.UserName);
cs2.set("flair", mp.Flair);
cs2.set("acceptedflair", mp.AcceptedFlair);
cs2.set("ignoredflair", mp.IgnoredFlair);
cs2.set("flairdecided", mp.FlairDecided);
cs2.set("flairrecognised", mp.FlairRecognised);
cs2.set("commentedonreddit", mp.CommentedOnReddit);
cs2.set("flaircolor", mp.FlairColor);
cs2.set("flairtime", mp.FlairTime);
cs2.set("flairstate", mp.FlairState.toString());
cs2.set("uuid", mp.UUID.toString());
cs2.set("usernames", mp.UserNames);
}
}
public static MaybeOfflinePlayer GetFromName(String name)
{
for(MaybeOfflinePlayer mp : AllPlayers.values())
if(mp.PlayerName.equalsIgnoreCase(name))
public static MaybeOfflinePlayer GetFromName(String name) {
for (MaybeOfflinePlayer mp : AllPlayers.values())
if (mp.PlayerName.equalsIgnoreCase(name))
return mp;
return null;
}
public String GetFormattedFlair() {
if (FlairColor == 0x00)
return "";
if (FlairTime == null || FlairTime.length() == 0)
return String.format("§%x(??s)§r", FlairColor);
return String.format("§%x(%ss)§r", FlairColor, FlairTime);
}
}

View file

@ -40,15 +40,15 @@ public class PlayerListener implements Listener { // 2015.07.16.
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p
.getUniqueId());
mp.PlayerName = p.getName(); // 2015.10.17. 0:58
if (mp.CommentedOnReddit)
if (!mp.FlairState.equals(FlairStates.NoComment))
// if (false)
PluginMain.AppendPlayerDisplayFlair(mp, p); // 2015.08.09.
PluginMain.ConfirmUserMessage(mp); // 2015.08.09.
else { // 2015.07.20.
Timer timer = new Timer();
PlayerJoinTimerTask tt = new PlayerJoinTimerTask() {
@Override
public void run() {
if (!mp.IgnoredFlair) {
if (mp.FlairState.equals(FlairStates.NoComment)) {
String json = "[\"\",{\"text\":\"If you'd like your /r/TheButton flair displayed ingame, write your Minecraft name to \",\"color\":\"aqua\"},{\"text\":\"[this thread].\",\"color\":\"aqua\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread\",\"color\":\"aqua\"}]}}}]";
PluginMain.Instance.getServer().dispatchCommand(
PluginMain.Console,
@ -121,9 +121,7 @@ public class PlayerListener implements Listener { // 2015.07.16.
public void onPlayerChat(AsyncPlayerChatEvent event) {
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event
.getPlayer().getUniqueId());
String flair = player.Flair; // 2015.08.08.
if (player.IgnoredFlair)
flair = "";
String flair = player.GetFormattedFlair();
String message = event.getMessage(); // 2015.08.08.
for (Player p : PluginMain.GetPlayers()) { // 2015.08.12.
String color = ""; // 2015.08.17.
@ -135,11 +133,10 @@ public class PlayerListener implements Listener { // 2015.07.16.
(float) NotificationPitch); // 2015.08.14.
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p
.getUniqueId()); // 2015.08.17.
if (mp.Flair.length() > 1)
color = mp.Flair.substring(0, 2);
color = String.format("%x", mp.FlairColor);
}
message = message.replaceAll(p.getName(), color + p.getName()
message = message.replace(p.getName(), color + p.getName()
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
}
for (String n : nicknames.keySet()) {
@ -147,14 +144,14 @@ public class PlayerListener implements Listener { // 2015.07.16.
String nwithoutformatting = new String(n);
int index;
while ((index = nwithoutformatting.indexOf("§k")) != -1)
nwithoutformatting = nwithoutformatting.replaceAll("§k"
nwithoutformatting = nwithoutformatting.replace("§k"
+ nwithoutformatting.charAt(index + 2), ""); // Support
// for
// one
// random
// char
while ((index = nwithoutformatting.indexOf('§')) != -1)
nwithoutformatting = nwithoutformatting.replaceAll("§"
nwithoutformatting = nwithoutformatting.replace("§"
+ nwithoutformatting.charAt(index + 1), "");
if (message.contains(nwithoutformatting)) {
p = Bukkit.getPlayer(nicknames.get(n));
@ -166,7 +163,7 @@ public class PlayerListener implements Listener { // 2015.07.16.
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()); // 2015.08.17.
}
if (p != null) {
message = message.replaceAll(nwithoutformatting, n
message = message.replace(nwithoutformatting, n
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
}
}
@ -193,14 +190,14 @@ public class PlayerListener implements Listener { // 2015.07.16.
String nwithoutformatting = nickname;
int index;
while ((index = nwithoutformatting.indexOf("§k")) != -1)
nwithoutformatting = nwithoutformatting.replaceAll("§k"
nwithoutformatting = nwithoutformatting.replace("§k"
+ nwithoutformatting.charAt(index + 2), ""); // Support
// for
// one
// random
// char
while ((index = nwithoutformatting.indexOf('§')) != -1)
nwithoutformatting = nwithoutformatting.replaceAll("§"
nwithoutformatting = nwithoutformatting.replace("§"
+ nwithoutformatting.charAt(index + 1), "");
if (nwithoutformatting.startsWith(name)
&& !nwithoutformatting.equals(Bukkit.getPlayer(

View file

@ -7,19 +7,24 @@ import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.htmlcleaner.HtmlCleaner;
import org.htmlcleaner.TagNode;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.*;
import java.lang.String;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.Date;
import java.util.TimeZone;
public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
// A user, which flair isn't obtainable:
@ -30,7 +35,30 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
// Fired when plugin is first enabled
@Override
public void onEnable() {
System.out.println("The Button Minecraft server plugin");
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();
}
getServer().getPluginManager().registerEvents(new PlayerListener(),
this);
Commands comm = new Commands();
@ -71,8 +99,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
stop = true;
}
public void ThreadMethod() // <-- 2015.07.16.
{
private void ThreadMethod() {
while (!stop) {
try {
String body = DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
@ -97,29 +124,15 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(ign);
if (mp == null)
continue;
if (HasIGFlair(mp.UUID))
continue;
if (!mp.UserNames.contains(author))
mp.UserNames.add(author);
if (mp.FlairState.equals(FlairStates.NoComment))
mp.FlairState = FlairStates.Commented;
try {
Thread.sleep(10);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
String[] flairdata = DownloadString(
"http://karmadecay.com/thebutton-data.php?users="
+ author).replace("\"", "").split(":");
String flair;
if (flairdata.length > 1) // 2015.07.15.
flair = flairdata[1];
else
flair = "";
if (flair != "-1")
flair = flair + "s";
String flairclass;
if (flairdata.length > 2)
flairclass = flairdata[2];
else
flairclass = "unknown";
SetFlair(mp.UUID, flair, flairclass, author);
}
try {
Thread.sleep(10000);
@ -133,6 +146,24 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
}
}
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);
}
public static Exception LastException; // 2015.08.09.
public String DownloadString(String urlstr) throws MalformedURLException,
@ -148,88 +179,90 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
return body;
}
public static Map<String, String> TownColors = new HashMap<String, String>(); // 2015.07.20.
public Boolean HasIGFlair(UUID uuid) {
MaybeOfflinePlayer p = MaybeOfflinePlayer.AddPlayerIfNeeded(uuid); // 2015.08.08.
return p.CommentedOnReddit; // 2015.08.10.
}
public void SetFlair(UUID uuid, String text, String flairclass,
private void SetFlair(MaybeOfflinePlayer p, String text, String flairclass,
String username) {
MaybeOfflinePlayer p = MaybeOfflinePlayer.AddPlayerIfNeeded(uuid); // 2015.08.08.
String finalflair;
p.FlairDecided = true;
p.FlairRecognised = true;
p.CommentedOnReddit = true;
p.UserName = username;
p.FlairState = FlairStates.Recognised;
switch (flairclass) {
case "press-1":
finalflair = "§c(" + text + ")§r";
p.FlairColor = 0xc;
break;
case "press-2":
finalflair = "§6(" + text + ")§r";
p.FlairColor = 0x6;
break;
case "press-3":
finalflair = "§e(" + text + ")§r";
p.FlairColor = 0xe;
break;
case "press-4":
finalflair = "§a(" + text + ")§r";
p.FlairColor = 0xa;
break;
case "press-5":
finalflair = "§9(" + text + ")§r";
p.FlairColor = 0x9;
break;
case "press-6":
finalflair = "§5(" + text + ")§r";
p.FlairColor = 0x5;
break;
case "no-press":
finalflair = "§7(--s)§r";
p.FlairColor = 0x7;
break;
case "cheater":
finalflair = "§5(" + text + ")§r";
p.FlairColor = 0x5;
break;
case "cant-press": // 2015.08.08.
finalflair = "§r(??s)§r";
case "cant-press":
p.FlairColor = 0xf;
break;
case "unknown":
if (text.equals("-1")) // If true, only non-presser/can't press; if
// false, any flair
p.FlairDecided = false;
else
p.FlairRecognised = false;
finalflair = "";
break;
{
try {
if (CheckForJoinDate(p)) {
p.FlairColor = 0x7;
p.FlairTime = "--";
} else {
p.FlairColor = 0xf;
p.FlairTime = "--";
}
} catch (Exception e) {
p.FlairState = FlairStates.Commented; // Flair unknown
p.FlairColor = 0;
e.printStackTrace();
}
} else {
p.FlairState = FlairStates.Commented; // Flair unknown
p.FlairColor = 0;
}
return;
default:
return;
}
p.Flair = finalflair; // 2015.08.08.
System.out.println("Added flair for " + p.PlayerName);
AppendPlayerDisplayFlair(p, Bukkit.getPlayer(uuid));
p.FlairTime = text;
}
public static String GetFlair(Player player) { // 2015.07.16.
String flair = MaybeOfflinePlayer.AllPlayers.get(player.getUniqueId()).Flair; // 2015.08.08.
return flair; // 2015.08.10.
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);
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)
.build().getTime());
}
public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player,
Player p) // <-- 2015.08.09.
{
if (MaybeOfflinePlayer.AllPlayers.get(p.getUniqueId()).IgnoredFlair)
return;
if (MaybeOfflinePlayer.AllPlayers.get(p.getUniqueId()).AcceptedFlair) {
if (!player.FlairDecided)
p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); // 2015.08.09.
} else
p.sendMessage("§9Are you Reddit user " + player.UserName
+ "?§r §6Type /u accept or /u ignore§r");
}
public static String GetColorForTown(String townname) { // 2015.07.20.
if (TownColors.containsKey(townname))
return TownColors.get(townname);
return "";
public static void ConfirmUserMessage(MaybeOfflinePlayer mp) {
Player p = Bukkit.getPlayer(mp.UUID);
if (mp.FlairState.equals(FlairStates.Commented) && p != null)
p.sendMessage("§9" + "?§r §6Type /u accept or /u ignore§r");
}
public static Collection<? extends Player> GetPlayers() {
@ -239,17 +272,15 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
public static ArrayList<String> AnnounceMessages = new ArrayList<>();
public static int AnnounceTime = 15 * 60 * 1000;
public static void LoadFiles(boolean reload) // <-- 2015.08.09.
{
if (reload) { // 2015.08.09.
public static void LoadFiles(boolean reload) {
if (reload) {
System.out
.println("The Button Minecraft plugin cleanup for reloading...");
MaybeOfflinePlayer.AllPlayers.clear();
TownColors.clear();
AnnounceMessages.clear();
Commands.Quiz.clear();
}
System.out.println("Loading files for The Button Minecraft plugin..."); // 2015.08.09.
System.out.println("Loading files for The Button Minecraft plugin...");
try {
File file = new File("announcemessages.txt");
if (file.exists())
@ -276,16 +307,15 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
System.out.println("The Button Minecraft plugin loaded files!");
} catch (IOException e) {
System.out.println("Error!\n" + e);
LastException = e; // 2015.08.09.
LastException = e;
} catch (InvalidConfigurationException e) {
System.out.println("Error!\n" + e);
LastException = e; // 2015.08.09.
LastException = e;
}
}
public static void SaveFiles() // <-- 2015.08.09.
{
System.out.println("Saving files for The Button Minecraft plugin..."); // 2015.08.09.
public static void SaveFiles() {
System.out.println("Saving files for The Button Minecraft plugin...");
try {
File file = new File("thebuttonmc.yml");
YamlConfiguration yc = new YamlConfiguration();
@ -299,7 +329,23 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
System.out.println("The Button Minecraft plugin saved files!");
} catch (IOException e) {
System.out.println("Error!\n" + e);
LastException = e; // 2015.08.09.
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");
}
}
}

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,73 @@
JSON in Java [package org.json]
This package needs a new owner. I have not used it in over a decade, and I do
not have time to maintain programs that I do not use.
If you think you can give this package a good home, please contact me.
Douglas Crockford
douglas@crockford.com
2015-02-06
JSON is a light-weight, language independent, data interchange format.
See http://www.JSON.org/
The files in this package implement JSON encoders/decoders in Java.
It also includes the capability to convert between JSON and XML, HTTP
headers, Cookies, and CDL.
This is a reference implementation. There is a large number of JSON packages
in Java. Perhaps someday the Java community will standardize on one. Until
then, choose carefully.
The license includes this restriction: "The software shall be used for good,
not evil." If your conscience cannot live with that, then choose a different
package.
The package compiles on Java 1.8.
JSONObject.java: The JSONObject can parse text from a String or a JSONTokener
to produce a map-like object. The object provides methods for manipulating its
contents, and for producing a JSON compliant object serialization.
JSONArray.java: The JSONObject can parse text from a String or a JSONTokener
to produce a vector-like object. The object provides methods for manipulating
its contents, and for producing a JSON compliant array serialization.
JSONTokener.java: The JSONTokener breaks a text into a sequence of individual
tokens. It can be constructed from a String, Reader, or InputStream.
JSONException.java: The JSONException is the standard exception type thrown
by this package.
JSONString.java: The JSONString interface requires a toJSONString method,
allowing an object to provide its own serialization.
JSONStringer.java: The JSONStringer provides a convenient facility for
building JSON strings.
JSONWriter.java: The JSONWriter provides a convenient facility for building
JSON text through a writer.
CDL.java: CDL provides support for converting between JSON and comma
delimited lists.
Cookie.java: Cookie provides support for converting between JSON and cookies.
CookieList.java: CookieList provides support for converting between JSON and
cookie lists.
HTTP.java: HTTP provides support for converting between JSON and HTTP headers.
HTTPTokener.java: HTTPTokener extends JSONTokener for parsing HTTP headers.
XML.java: XML provides support for converting between JSON and XML.
JSONML.java: JSONML provides support for converting between JSONML and XML.
XMLTokener.java: XMLTokener extends JSONTokener for parsing XML text.

Binary file not shown.