Removed metadata folder from repository
This commit is contained in:
parent
3a00450e3e
commit
c95c042925
454 changed files with 0 additions and 139699 deletions
14027
.metadata/.bak_0.log
14027
.metadata/.bak_0.log
File diff suppressed because it is too large
Load diff
10959
.metadata/.log
10959
.metadata/.log
File diff suppressed because it is too large
Load diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,316 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerChatTabCompleteEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import au.com.mineauz.minigames.Minigames;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerListener implements Listener { // 2015.07.16.
|
||||
public static HashMap<String, UUID> nicknames = new HashMap<>();
|
||||
|
||||
public static boolean Enable = false; // 2015.08.29.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
final MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p
|
||||
.getUniqueId());
|
||||
mp.PlayerName = p.getName(); // 2015.10.17. 0:58
|
||||
if (mp.CommentedOnReddit)
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); // 2015.08.09.
|
||||
else { // 2015.07.20.
|
||||
Timer timer = new Timer();
|
||||
timer.schedule(new TimerTask()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (!mp.IgnoredFlair) {
|
||||
String message = "§bIf you'd like your flair displayed ingame, write your §6Minecraft name to this thread:§r";
|
||||
String json = "[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your §6Minecraft name to \"},{\"text\":\"[this thread.]\",\"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§r\"}]}}}]";
|
||||
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console, "tellraw "+mp.PlayerName+" "+json);
|
||||
message = "§6If you don't want the flair, type /u ignore to prevent this message on login.§r";
|
||||
}
|
||||
}
|
||||
}, 15*1000)
|
||||
}
|
||||
|
||||
/* NICKNAME LOGIC */
|
||||
|
||||
UUID id = p.getUniqueId();
|
||||
|
||||
File f = new File("plugins/Essentials/userdata/" + id + ".yml");
|
||||
if (f.exists()) {
|
||||
YamlConfiguration yc = new YamlConfiguration();
|
||||
try {
|
||||
yc.load(f);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String nickname = yc.getString("nickname");
|
||||
if (nickname != null) {
|
||||
nicknames.put(nickname, id);
|
||||
|
||||
if (Enable) {
|
||||
if (!p.getName().equals("NorbiPeti")) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.chat("Hey, " + nickname + "!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mp.RPMode = true; // 2015.08.25.
|
||||
|
||||
if (p.getName().equals("FigyTuna") && Commands.PluginUpdated)
|
||||
p.sendMessage("§bThe The Button MC plugin got updated. Please restart the server. :P§r");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
String deletenick = null;
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
UUID uuid = nicknames.get(nickname);
|
||||
if (event.getPlayer().getUniqueId().equals(uuid)) {
|
||||
deletenick = nickname;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (deletenick != null)
|
||||
nicknames.remove(deletenick);
|
||||
}
|
||||
|
||||
public static String NotificationSound; // 2015.08.14.
|
||||
public static double NotificationPitch; // 2015.08.14.
|
||||
|
||||
public static boolean ShowRPTag = false; // 2015.08.31.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.GetFromName(event
|
||||
.getPlayer().getName());
|
||||
String flair = player.Flair; // 2015.08.08.
|
||||
if (player.IgnoredFlair)
|
||||
flair = "";
|
||||
String message = event.getMessage(); // 2015.08.08.
|
||||
for (Player p : PluginMain.GetPlayers()) { // 2015.08.12.
|
||||
String color = ""; // 2015.08.17.
|
||||
if (message.contains(p.getName())) {
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(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);
|
||||
}
|
||||
|
||||
message = message.replaceAll(p.getName(), color + p.getName()
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
for (String n : nicknames.keySet()) {
|
||||
Player p = null;
|
||||
String nwithoutformatting = new String(n);
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (message.contains(nwithoutformatting)) {
|
||||
p = Bukkit.getPlayer(nicknames.get(n));
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(float) NotificationPitch); // 2015.08.14.
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()); // 2015.08.17.
|
||||
}
|
||||
if (p != null) {
|
||||
message = message.replaceAll(nwithoutformatting, n
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
}
|
||||
|
||||
event.setMessage(message); // 2015.09.05.
|
||||
|
||||
event.setFormat(event
|
||||
.getFormat()
|
||||
.replace(
|
||||
"{rptag}",
|
||||
(player.RPMode ? (ShowRPTag ? "§2[RP]§r" : "")
|
||||
: "§8[OOC]§r"))
|
||||
.replace("{buttonflair}", flair)
|
||||
.replace(
|
||||
"{isitwilds}",
|
||||
(event.getPlayer().getWorld().getName()
|
||||
.equalsIgnoreCase("wilds") ? "[PVP]" : ""))); // 2015.09.04.
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTabComplete(PlayerChatTabCompleteEvent e) {
|
||||
String name = e.getLastToken();
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
String nwithoutformatting = nickname;
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (nwithoutformatting.startsWith(name)
|
||||
&& !nwithoutformatting.equals(Bukkit.getPlayer(
|
||||
nicknames.get(nickname)).getName()))
|
||||
e.getTabCompletions().add(nwithoutformatting);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean DebugMode = false;
|
||||
|
||||
public void SendForDebug(String message) {
|
||||
if (DebugMode) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.sendMessage("[DEBUG] " + message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean ActiveF = false;
|
||||
private int FCount = 0;
|
||||
private long FTime;
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMessage(AsyncPlayerChatEvent e) {
|
||||
if (ActiveF) {
|
||||
if (System.currentTimeMillis() - FTime > 10000) {
|
||||
ActiveF = false;
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
p.sendMessage("§b" + FCount + " "
|
||||
+ (FCount == 1 ? "person" : "people")
|
||||
+ " paid their respects.§r");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e.getMessage().equalsIgnoreCase("F")) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(e
|
||||
.getPlayer().getName());
|
||||
if (!mp.PressedF && ActiveF) {
|
||||
FCount++;
|
||||
mp.PressedF = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (e.getMessage().startsWith(">"))
|
||||
e.setMessage("§2" + e.getMessage());
|
||||
|
||||
/*
|
||||
* Channel c = ((Chat) Bukkit.getPluginManager().getPlugin("TownyChat"))
|
||||
* .getChannelsHandler().getActiveChannel(e.getPlayer(),
|
||||
* channelTypes.GLOBAL);
|
||||
*/
|
||||
/*
|
||||
* List<String> modes = ((Chat) Bukkit.getPluginManager().getPlugin(
|
||||
* "TownyChat")).getTowny().getPlayerMode(e.getPlayer()); if
|
||||
* (modes.size() == 0 || modes.contains("g")) {
|
||||
*/
|
||||
if (e.getFormat().contains("[g]")) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("tellraw @a [\"\"");
|
||||
sb.append(",{\"text\":\"Hashtags:\"}");
|
||||
int index = -1;
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
while ((index = e.getMessage().indexOf("#", index + 1)) != -1) {
|
||||
int index2 = e.getMessage().indexOf(" ", index + 1);
|
||||
if (index2 == -1)
|
||||
index2 = e.getMessage().length();
|
||||
int index3 = e.getMessage().indexOf("#", index + 1);
|
||||
if (index3 != -1 && index3 < index2) // A # occurs before a
|
||||
// space
|
||||
index2 = index3;
|
||||
String original = e.getMessage().substring(index, index2);
|
||||
list.add(original);
|
||||
sb.append(",{\"text\":\" \"}");
|
||||
sb.append(",{\"text\":\"");
|
||||
sb.append(original);
|
||||
sb.append("\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://twitter.com/hashtag/");
|
||||
sb.append(original.substring(1));
|
||||
sb.append("\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open on Twitter\",\"color\":\"blue\"}]}}}");
|
||||
}
|
||||
for (String original : list)
|
||||
e.setMessage(e.getMessage().replace(
|
||||
original,
|
||||
"§9"
|
||||
+ original
|
||||
+ (e.getMessage().startsWith("§2>") ? "§2"
|
||||
: "§r")));
|
||||
/*
|
||||
* for (String original : list)
|
||||
* System.out.println(e.getMessage().replace( original, "§9" +
|
||||
* original + (e.getMessage().startsWith("§2>") ? "§2" : "§r")));
|
||||
*/
|
||||
|
||||
sb.append("]");
|
||||
|
||||
if (list.size() > 0)
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Instance.getServer().getConsoleSender(),
|
||||
sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDeath(PlayerDeathEvent e) {
|
||||
if (!Minigames.plugin.pdata.getMinigamePlayer(e.getEntity())
|
||||
.isInMinigame() && new Random().nextBoolean()) {
|
||||
ActiveF = true;
|
||||
FCount = 0;
|
||||
FTime = System.currentTimeMillis();
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(p
|
||||
.getName());
|
||||
mp.PressedF = false;
|
||||
p.sendMessage("§bPress F to pay respects.§r");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,374 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
|
||||
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/
|
||||
private static PluginMain Instance;
|
||||
// Fired when plugin is first enabled
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
this.getCommand("u").setExecutor(new Commands());
|
||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||
Instance=this; //2015.08.08.
|
||||
LoadFiles(false); //2015.08.09.
|
||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||
Thread t=new Thread(r);
|
||||
t.start();
|
||||
}
|
||||
Boolean stop=false;
|
||||
// Fired when plugin is disabled
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
try
|
||||
{
|
||||
FileWriter fw;
|
||||
fw = new FileWriter("flairsaccepted.txt");
|
||||
fw.close();
|
||||
fw = new FileWriter("flairsignored.txt");
|
||||
fw.close();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.AcceptedFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
file=new File("flairsignored.txt");
|
||||
bw = new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.IgnoredFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
stop=true;
|
||||
}
|
||||
|
||||
public void ThreadMethod() //<-- 2015.07.16.
|
||||
{
|
||||
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();
|
||||
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();
|
||||
if(HasIGFlair(ign))
|
||||
continue;
|
||||
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";
|
||||
else
|
||||
flair = "non-presser";
|
||||
String flairclass;
|
||||
if(flairdata.length>2)
|
||||
flairclass = flairdata[2];
|
||||
else
|
||||
flairclass="unknown";
|
||||
SetFlair(ign, flair, flairclass, author);
|
||||
}
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Exception LastException; //2015.08.09.
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||
public Boolean HasIGFlair(String playername)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
return p.Flair!=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
String finalflair;
|
||||
p.FlairDecided=true;
|
||||
switch(flairclass)
|
||||
{
|
||||
case "press-1":
|
||||
finalflair="§c("+text+")§r";
|
||||
break;
|
||||
case "press-2":
|
||||
finalflair="§6("+text+")§r";
|
||||
break;
|
||||
case "press-3":
|
||||
finalflair="§e("+text+")§r";
|
||||
break;
|
||||
case "press-4":
|
||||
finalflair="§a("+text+")§r";
|
||||
break;
|
||||
case "press-5":
|
||||
finalflair="§9("+text+")§r";
|
||||
break;
|
||||
case "press-6":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "no-press":
|
||||
finalflair="§7(non-pr.)§r";
|
||||
break;
|
||||
case "cheater":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "cant-press": //2015.08.08.
|
||||
finalflair="§r(can't press)§r";
|
||||
break;
|
||||
case "undecided": //2015.08.09.
|
||||
p.FlairDecided=false;
|
||||
finalflair="";
|
||||
break;
|
||||
default:
|
||||
finalflair="";
|
||||
break;
|
||||
}
|
||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||
return;
|
||||
p.Flair=finalflair; //2015.08.08.
|
||||
p.UserName=username; //2015.08.08.
|
||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||
{
|
||||
if(player.getName().equals(playername))
|
||||
{
|
||||
//AppendPlayerDisplayFlair(player, username, finalflair);
|
||||
AppendPlayerDisplayFlair(p, player);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String GetFlair(Player player)
|
||||
{ //2015.07.16.
|
||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||
return flair==null ? "" : flair;
|
||||
}
|
||||
|
||||
//public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||
public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09.
|
||||
{
|
||||
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair)
|
||||
return;
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair)
|
||||
{
|
||||
AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20.
|
||||
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");
|
||||
}
|
||||
|
||||
private static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||
String[] colors = color.substring(1).split("§");
|
||||
String displayname=player.getName(); //2015.08.08.
|
||||
ArrayList<Integer> Positions=new ArrayList<>();
|
||||
for(int i=0; i<displayname.length(); i++) {
|
||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||
Positions.add(i);
|
||||
}
|
||||
}
|
||||
String finalname=""; //TODO
|
||||
if(Positions.size()>=colors.length)
|
||||
{
|
||||
int x=0;
|
||||
for(int i=0; i<Positions.size(); i++)
|
||||
{
|
||||
int pos=Positions.get(i);
|
||||
int nextpos;
|
||||
if(i!=Positions.size()-1)
|
||||
nextpos=Positions.get(i+1);
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Positions.clear();
|
||||
int unit=displayname.length()/colors.length;
|
||||
int x=0;
|
||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||
{
|
||||
int pos=i;
|
||||
int nextpos;
|
||||
if(i<displayname.length()-unit-unit)
|
||||
nextpos=i+unit;
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||
}
|
||||
|
||||
public static String GetColorForTown(String townname)
|
||||
{ //2015.07.20.
|
||||
if(TownColors.containsKey(townname))
|
||||
return TownColors.get(townname);
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String GetPlayerTown(Player player)
|
||||
{ //2015.07.20.
|
||||
try {
|
||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||
return town.getName();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public static Collection<? extends Player> GetPlayers()
|
||||
{
|
||||
return Instance.getServer().getOnlinePlayers();
|
||||
}
|
||||
|
||||
public static void LoadFiles(boolean reload) //<-- 2015.08.09.
|
||||
{
|
||||
if(reload)
|
||||
{
|
||||
System.out.println("Auto-flair plugin cleanup for reloading..."); //2015.08.09.
|
||||
MaybeOfflinePlayer.AllPlayers.clear(); //2015.08.09.
|
||||
}
|
||||
System.out.println("Loading files for auto-flair plugin..."); //2015.08.09.
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
//System.out.println("Name: " + name);
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("flairsignored.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while((line=br.readLine())!=null)
|
||||
{
|
||||
String[] s=line.split(" ");
|
||||
TownColors.put(s[0], s[1]);
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
//throw new IOException("Test"); //2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,306 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.String;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
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/
|
||||
public static PluginMain Instance;
|
||||
public static ConsoleCommandSender Console; // 2015.08.12.
|
||||
|
||||
// Fired when plugin is first enabled
|
||||
@Override
|
||||
public void onEnable() {
|
||||
System.out.println("The Button Minecraft server plugin");
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(),
|
||||
this);
|
||||
Commands comm = new Commands();
|
||||
this.getCommand("u").setExecutor(comm);
|
||||
this.getCommand("u").setUsage(
|
||||
this.getCommand("u").getUsage().replace('&', '§'));
|
||||
this.getCommand("nrp").setExecutor(comm);
|
||||
this.getCommand("nrp").setUsage(
|
||||
this.getCommand("nrp").getUsage().replace('&', '§'));
|
||||
this.getCommand("ooc").setExecutor(comm);
|
||||
this.getCommand("ooc").setUsage(
|
||||
this.getCommand("ooc").getUsage().replace('&', '§'));
|
||||
this.getCommand("skype").setExecutor(comm);
|
||||
Instance = this; // 2015.08.08.
|
||||
Console = this.getServer().getConsoleSender(); // 2015.08.12.
|
||||
LoadFiles(false); // 2015.08.09.
|
||||
Runnable r = new Runnable() {
|
||||
public void run() {
|
||||
ThreadMethod();
|
||||
}
|
||||
};
|
||||
Thread t = new Thread(r);
|
||||
t.start();
|
||||
r = new Runnable() {
|
||||
public void run() {
|
||||
AnnouncerThread.Run();
|
||||
}
|
||||
};
|
||||
t = new Thread(r);
|
||||
t.start();
|
||||
}
|
||||
|
||||
public Boolean stop = false;
|
||||
|
||||
// Fired when plugin is disabled
|
||||
@Override
|
||||
public void onDisable() {
|
||||
SaveFiles(); // 2015.08.09.
|
||||
stop = true;
|
||||
}
|
||||
|
||||
public void ThreadMethod() // <-- 2015.07.16.
|
||||
{
|
||||
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();
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(ign);
|
||||
if (mp == null)
|
||||
continue;
|
||||
if (HasIGFlair(mp.UUID))
|
||||
continue;
|
||||
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);
|
||||
} catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// System.out.println("Error!\n" + e);
|
||||
LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Exception LastException; // 2015.08.09.
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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,
|
||||
String username) {
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AddPlayerIfNeeded(uuid); // 2015.08.08.
|
||||
String finalflair;
|
||||
p.FlairDecided = true;
|
||||
p.FlairRecognised = true;
|
||||
switch (flairclass) {
|
||||
case "press-1":
|
||||
finalflair = "§c(" + text + ")§r";
|
||||
break;
|
||||
case "press-2":
|
||||
finalflair = "§6(" + text + ")§r";
|
||||
break;
|
||||
case "press-3":
|
||||
finalflair = "§e(" + text + ")§r";
|
||||
break;
|
||||
case "press-4":
|
||||
finalflair = "§a(" + text + ")§r";
|
||||
break;
|
||||
case "press-5":
|
||||
finalflair = "§9(" + text + ")§r";
|
||||
break;
|
||||
case "press-6":
|
||||
finalflair = "§5(" + text + ")§r";
|
||||
break;
|
||||
case "no-press":
|
||||
finalflair = "§7(--s)§r";
|
||||
break;
|
||||
case "cheater":
|
||||
finalflair = "§5(" + text + ")§r";
|
||||
break;
|
||||
case "cant-press": // 2015.08.08.
|
||||
finalflair = "§r(??s)§r";
|
||||
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;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
p.Flair = finalflair; // 2015.08.08.
|
||||
p.CommentedOnReddit = true; // 2015.08.10.
|
||||
p.UserName = username; // 2015.08.08.
|
||||
System.out.println("Added flair for " + p.PlayerName);
|
||||
AppendPlayerDisplayFlair(p, Bukkit.getPlayer(uuid));
|
||||
}
|
||||
|
||||
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 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 Collection<? extends Player> GetPlayers() {
|
||||
return Instance.getServer().getOnlinePlayers();
|
||||
}
|
||||
|
||||
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.
|
||||
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.
|
||||
try {
|
||||
File file = new File("announcemessages.txt");
|
||||
if (file.exists())
|
||||
file.delete();
|
||||
file = new File("flairsaccepted.txt");
|
||||
if (file.exists())
|
||||
file.delete();
|
||||
file = new File("flairsignored.txt");
|
||||
if (file.exists())
|
||||
file.delete();
|
||||
file = new File("thebuttonmc.yml");
|
||||
if (file.exists()) {
|
||||
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"));
|
||||
Commands.Quiz.addAll(yc.getStringList("quiz"));
|
||||
}
|
||||
System.out.println("The Button Minecraft plugin loaded files!");
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
LastException = e; // 2015.08.09.
|
||||
} catch (InvalidConfigurationException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
public static void SaveFiles() // <-- 2015.08.09.
|
||||
{
|
||||
System.out.println("Saving files for The Button Minecraft plugin..."); // 2015.08.09.
|
||||
try {
|
||||
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);
|
||||
yc.set("quiz", Commands.Quiz);
|
||||
yc.save(file);
|
||||
System.out.println("The Button Minecraft plugin saved files!");
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,575 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
|
||||
public static boolean PluginUpdated = false; // 2015.08.31.
|
||||
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label,
|
||||
String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
switch (cmd.getName()) {
|
||||
case "u": {
|
||||
if (args.length < 1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(player
|
||||
.getName()); // 2015.08.08.
|
||||
if (!p.CommentedOnReddit
|
||||
&& !args[0].toLowerCase().equals("admin")
|
||||
&& !args[0].toLowerCase().equals("ignore")) {
|
||||
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")) { // 2015.08.10.
|
||||
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")) { // 2015.08.19.
|
||||
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
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
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");
|
||||
} else
|
||||
player.sendMessage("§cYou already ignored this request.§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
|
||||
break;
|
||||
case "announce":
|
||||
DoAnnounce(player, args, null);
|
||||
break;
|
||||
case "name":
|
||||
if (args.length == 1) {
|
||||
player.sendMessage("§cUsage: /u name <playername>§r");
|
||||
break;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[1])) {
|
||||
player.sendMessage("§cUnknown user: " + args[1]);
|
||||
break;
|
||||
}
|
||||
player.sendMessage("§bUsername of "
|
||||
+ args[1]
|
||||
+ ": "
|
||||
+ MaybeOfflinePlayer.AllPlayers.get(args[1]).UserName);
|
||||
break;
|
||||
case "enable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = true;
|
||||
player.sendMessage("Enabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
case "disable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = false;
|
||||
player.sendMessage("Disabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "nrp":
|
||||
case "ooc":
|
||||
if (args.length == 0) {
|
||||
return false;
|
||||
} else {
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = false;
|
||||
String message = "";
|
||||
for (String arg : args)
|
||||
message += arg + " ";
|
||||
player.chat(message.substring(0, message.length() - 1));
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = true;
|
||||
}
|
||||
return true;
|
||||
case "skype":
|
||||
// "skype:?chat&blob=Y_5Ob1BEcw0ZlstdUHyf0ENS5n1Xz2Huhx-5b-pB2JyMSRO5QMEALkJuTSuUaAb3-XfWXwCndwhGex_UpXDbyQ";
|
||||
return true;
|
||||
default:
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
}
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("admin")) // 2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); // 2015.08.09.
|
||||
return true; // 2015.08.09.
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("announce")) {
|
||||
if (sender instanceof BlockCommandSender)
|
||||
DoAnnounce(null, args, (BlockCommandSender) sender);
|
||||
else
|
||||
DoAnnounce(null, args, null);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void DoReload(Player player) { // 2015.07.20.
|
||||
try {
|
||||
PluginMain.Console
|
||||
.sendMessage("§6-- Reloading The Button Minecraft plugin...§r");
|
||||
PluginMain.LoadFiles(true); // 2015.08.09.
|
||||
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.
|
||||
}
|
||||
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.
|
||||
}
|
||||
PluginMain.Console.sendMessage("§6-- Reloading done!§r");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
if (player != null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static Player ReloadPlayer; // 2015.08.09.
|
||||
|
||||
private static String DoAdminUsage = "§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin|togglerpshow|toggledebug|savepos|loadpos§r";
|
||||
|
||||
private static void DoAdmin(Player player, String[] args) { // 2015.08.09.
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// args[0] is "admin"
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "reload":
|
||||
ReloadPlayer = player; // 2015.08.09.
|
||||
SendMessage(
|
||||
player,
|
||||
"§bMake sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
break; // <-- 2015.08.10.
|
||||
case "confirm":
|
||||
if (ReloadPlayer == player)
|
||||
DoReload(player); // 2015.08.09.
|
||||
else
|
||||
SendMessage(player,
|
||||
"§cYou need to do /u admin reload first.§r");
|
||||
break;
|
||||
case "save":
|
||||
PluginMain.SaveFiles(); // 2015.08.09.
|
||||
SendMessage(player,
|
||||
"§bSaved files. Now you can edit them and reload if you want.§r");
|
||||
break;
|
||||
case "setflair":
|
||||
DoSetFlair(player, args);
|
||||
break;
|
||||
case "updateplugin": // 2015.08.10.
|
||||
DoUpdatePlugin(player);
|
||||
break;
|
||||
case "togglerpshow":
|
||||
PlayerListener.ShowRPTag = !PlayerListener.ShowRPTag;
|
||||
SendMessage(player, "RP tag showing "
|
||||
+ (PlayerListener.ShowRPTag ? "enabled" : "disabled"));
|
||||
break;
|
||||
case "toggledebug":
|
||||
PlayerListener.DebugMode = !PlayerListener.DebugMode;
|
||||
SendMessage(player, "DebugMode: " + PlayerListener.DebugMode);
|
||||
break;
|
||||
case "savepos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "loadpos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "updatedynmap":
|
||||
DoUpdateDynmap(player, args);
|
||||
default:
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
|
||||
private static void DoPlayerInfo(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "playerinfo"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(args[2]);
|
||||
if (p == null) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
SendMessage(player, "Player name: " + p.PlayerName);
|
||||
SendMessage(player, "User flair: " + p.Flair);
|
||||
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);
|
||||
}
|
||||
|
||||
private static void SendMessage(Player player, String message) { // 2015.08.09.
|
||||
if (player == null)
|
||||
PluginMain.Console.sendMessage(message); // 2015.08.12.
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
private static void DoGetLastError(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "getlasterror"
|
||||
if (PluginMain.LastException != null) {
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException = null;
|
||||
} else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
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");
|
||||
return;
|
||||
}
|
||||
Player p = Bukkit.getPlayer(args[2]);
|
||||
if (p == null) {
|
||||
SendMessage(player, "§cPLayer not found.&r");
|
||||
return;
|
||||
}
|
||||
SetPlayerFlair(player,
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()), args[3]);
|
||||
}
|
||||
|
||||
private static void DoUpdatePlugin(Player player) { // 2015.08.10.
|
||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
||||
System.out.println("Forced updating of Auto-Flair plugin.");
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(
|
||||
"https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
||||
FileUtils.copyURLToFile(url, new File(
|
||||
"plugins/TheButtonAutoFlair.jar"));
|
||||
PluginUpdated = true; // 2015.08.31.
|
||||
SendMessage(player, "Updating done!");
|
||||
} catch (MalformedURLException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoAnnounce(Player player, String[] args,
|
||||
BlockCommandSender commandblock) {
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "add":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce add <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
PluginMain.AnnounceMessages.add(finalmessage);
|
||||
SendMessage(player, "§bAnnouncement added.§r");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce remove <index>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceMessages.remove(Integer.parseInt(args[2]));
|
||||
break;
|
||||
case "settime":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player,
|
||||
"§cUsage: /u announce settime <minutes>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceTime = Integer.parseInt(args[2]) * 60 * 1000;
|
||||
SendMessage(player, "Time set between announce messages");
|
||||
break;
|
||||
case "list":
|
||||
SendMessage(player, "§bList of announce messages:§r");
|
||||
SendMessage(player, "§bFormat: [index] message§r");
|
||||
int i = 0;
|
||||
for (String message : PluginMain.AnnounceMessages)
|
||||
SendMessage(player, "[" + i++ + "] " + message);
|
||||
SendMessage(player,
|
||||
"§bCurrent wait time between announcements: "
|
||||
+ PluginMain.AnnounceTime / 60 / 1000
|
||||
+ " minute(s)§r");
|
||||
break;
|
||||
case "edit":
|
||||
if (commandblock == null) {
|
||||
SendMessage(
|
||||
player,
|
||||
"§cError: This command can only be used from a command block. Use /u announce remove.");
|
||||
break;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
commandblock
|
||||
.sendMessage("§cUsage: /u announce edit <index> <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 3; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§');
|
||||
int index = Integer.parseInt(args[2]);
|
||||
if (index > 100)
|
||||
break;
|
||||
while (PluginMain.AnnounceMessages.size() <= index)
|
||||
PluginMain.AnnounceMessages.add("");
|
||||
PluginMain.AnnounceMessages.set(Integer.parseInt(args[2]),
|
||||
finalmessage1);
|
||||
commandblock.sendMessage("Announcement edited.");
|
||||
break;
|
||||
default:
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoSaveLoadPos(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "savepos|loadpos"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
Player p = null;
|
||||
for (Player pl : PluginMain.GetPlayers()) {
|
||||
if (pl.getName().equals(args[2])) {
|
||||
p = pl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (p == null) {
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer is not online: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (args[1].equalsIgnoreCase("savepos")) {
|
||||
mp.SavedLocation = p.getLocation();
|
||||
} else if (args[1].equalsIgnoreCase("loadpos")) {
|
||||
if (mp.SavedLocation != null)
|
||||
p.teleport(mp.SavedLocation);
|
||||
} else {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// SendMessage(player, "Player " + p.getName() +
|
||||
// " position saved/loaded.");s
|
||||
}
|
||||
|
||||
private static void DoUpdateDynmap(Player player, String[] args) {
|
||||
// args[0] is "admin" - args[1] is "updatedynmap"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin updatedynmap <password>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static ArrayList<String> Quiz = new ArrayList<>();
|
||||
|
||||
private static void DoQuiz(Player player, String[] args,
|
||||
BlockCommandSender commandblock) {
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = "§cUsage: /u quiz add|remove|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "add":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u quiz add <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
Quiz.add(finalmessage);
|
||||
SendMessage(player, "§Quiz question added.§r");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u quiz remove <index>");
|
||||
return;
|
||||
}
|
||||
Quiz.remove(Integer.parseInt(args[2]));
|
||||
break;
|
||||
case "list":
|
||||
SendMessage(player, "§bList of quiz questions:§r");
|
||||
SendMessage(player, "§bFormat: [index] question§r");
|
||||
int i = 0;
|
||||
for (String question : Quiz)
|
||||
SendMessage(player, "[" + i++ + "] " + question);
|
||||
break;
|
||||
case "edit":
|
||||
if (commandblock == null) {
|
||||
SendMessage(
|
||||
player,
|
||||
"§cError: This command can only be used from a command block. Use /u quiz remove.");
|
||||
break;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
commandblock
|
||||
.sendMessage("§cUsage: /u quiz edit <index> <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 3; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§');
|
||||
int index = Integer.parseInt(args[2]);
|
||||
if (index > 100)
|
||||
break;
|
||||
while (Quiz.size() <= index)
|
||||
Quiz.add("");
|
||||
Quiz.set(Integer.parseInt(args[2]),
|
||||
finalmessage1);
|
||||
commandblock.sendMessage("Question edited.");
|
||||
break;
|
||||
default:
|
||||
String message = "§cUsage: /u quiz add|remove|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,362 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
|
||||
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/
|
||||
private static PluginMain Instance;
|
||||
// Fired when plugin is first enabled
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
this.getCommand("u").setExecutor(new Commands());
|
||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||
Instance=this; //2015.08.08.
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
//System.out.println("Name: " + name);
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("flairsignored.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while((line=br.readLine())!=null)
|
||||
{
|
||||
String[] s=line.split(" ");
|
||||
TownColors.put(s[0], s[1]);
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
//throw new IOException("Test"); //2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||
Thread t=new Thread(r);
|
||||
t.start();
|
||||
}
|
||||
Boolean stop=false;
|
||||
// Fired when plugin is disabled
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
try
|
||||
{
|
||||
FileWriter fw;
|
||||
fw = new FileWriter("flairsaccepted.txt");
|
||||
fw.close();
|
||||
fw = new FileWriter("flairsignored.txt");
|
||||
fw.close();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.AcceptedFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
file=new File("flairsignored.txt");
|
||||
bw = new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.IgnoredFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
stop=true;
|
||||
}
|
||||
|
||||
public void ThreadMethod() //<-- 2015.07.16.
|
||||
{
|
||||
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();
|
||||
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();
|
||||
if(HasIGFlair(ign))
|
||||
continue;
|
||||
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";
|
||||
else
|
||||
flair = "non-presser";
|
||||
String flairclass;
|
||||
if(flairdata.length>2)
|
||||
flairclass = flairdata[2];
|
||||
else
|
||||
flairclass="unknown";
|
||||
SetFlair(ign, flair, flairclass, author);
|
||||
}
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Exception LastException; //2015.08.09.
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||
public Boolean HasIGFlair(String playername)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
return p.Flair!=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
String finalflair;
|
||||
p.FlairDecided=true;
|
||||
switch(flairclass)
|
||||
{
|
||||
case "press-1":
|
||||
finalflair="§c("+text+")§r";
|
||||
break;
|
||||
case "press-2":
|
||||
finalflair="§6("+text+")§r";
|
||||
break;
|
||||
case "press-3":
|
||||
finalflair="§e("+text+")§r";
|
||||
break;
|
||||
case "press-4":
|
||||
finalflair="§a("+text+")§r";
|
||||
break;
|
||||
case "press-5":
|
||||
finalflair="§9("+text+")§r";
|
||||
break;
|
||||
case "press-6":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "no-press":
|
||||
finalflair="§7(non-pr.)§r";
|
||||
break;
|
||||
case "cheater":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "cant-press": //2015.08.08.
|
||||
finalflair="§r(can't press)§r";
|
||||
break;
|
||||
case "undecided": //2015.08.09.
|
||||
p.FlairDecided=false;
|
||||
finalflair="";
|
||||
break;
|
||||
default:
|
||||
finalflair="";
|
||||
break;
|
||||
}
|
||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||
return;
|
||||
p.Flair=finalflair; //2015.08.08.
|
||||
p.UserName=username; //2015.08.08.
|
||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||
{
|
||||
if(player.getName().equals(playername))
|
||||
{
|
||||
AppendPlayerDisplayFlair(player, username, finalflair);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String GetFlair(Player player)
|
||||
{ //2015.07.16.
|
||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||
return flair==null ? "" : flair;
|
||||
}
|
||||
|
||||
//public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||
public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09.
|
||||
{
|
||||
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair)
|
||||
return;
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair)
|
||||
{
|
||||
AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20.
|
||||
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
|
||||
player.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r");
|
||||
}
|
||||
|
||||
private static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||
String[] colors = color.substring(1).split("§");
|
||||
String displayname=player.getName(); //2015.08.08.
|
||||
ArrayList<Integer> Positions=new ArrayList<>();
|
||||
for(int i=0; i<displayname.length(); i++) {
|
||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||
Positions.add(i);
|
||||
}
|
||||
}
|
||||
String finalname=""; //TODO
|
||||
if(Positions.size()>=colors.length)
|
||||
{
|
||||
int x=0;
|
||||
for(int i=0; i<Positions.size(); i++)
|
||||
{
|
||||
int pos=Positions.get(i);
|
||||
int nextpos;
|
||||
if(i!=Positions.size()-1)
|
||||
nextpos=Positions.get(i+1);
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Positions.clear();
|
||||
int unit=displayname.length()/colors.length;
|
||||
int x=0;
|
||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||
{
|
||||
int pos=i;
|
||||
int nextpos;
|
||||
if(i<displayname.length()-unit-unit)
|
||||
nextpos=i+unit;
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||
}
|
||||
|
||||
public static String GetColorForTown(String townname)
|
||||
{ //2015.07.20.
|
||||
if(TownColors.containsKey(townname))
|
||||
return TownColors.get(townname);
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String GetPlayerTown(Player player)
|
||||
{ //2015.07.20.
|
||||
try {
|
||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||
return town.getName();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public static Collection<? extends Player> GetPlayers()
|
||||
{
|
||||
return Instance.getServer().getOnlinePlayers();
|
||||
}
|
||||
}
|
|
@ -1,215 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if(args.length<1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||
if(p.Flair==null)
|
||||
{
|
||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||
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.
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
||||
p.AcceptedFlair=true; //2015.08.08.
|
||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
break;
|
||||
}
|
||||
case "ignore":
|
||||
{
|
||||
if(p.AcceptedFlair)
|
||||
p.AcceptedFlair=false; //2015.08.08.
|
||||
if(!p.IgnoredFlair)
|
||||
{
|
||||
p.IgnoredFlair=true;
|
||||
String flair=p.Flair; //2015.08.08.
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already ignored this request.§r");
|
||||
break;
|
||||
}
|
||||
/*case "reload": //2015.07.20.
|
||||
DoReload(player);
|
||||
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;
|
||||
}
|
||||
p.Flair="§7(non-pr.)§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.§r");
|
||||
break;
|
||||
}
|
||||
p.Flair="§r(can't press)§r";
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*if(args[0].toLowerCase()=="reload")
|
||||
DoReload(null); //2015.07.20.*/
|
||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); //2015.08.09.
|
||||
return true; //2015.08.09.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static void DoReload(Player player)
|
||||
{ //2015.07.20.
|
||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
//{
|
||||
try
|
||||
{
|
||||
File file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
PluginMain.LoadFiles(true;
|
||||
for(Player p : PluginMain.GetPlayers())
|
||||
{
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||
if(mp.Flair!=null)
|
||||
{
|
||||
String flair=mp.Flair;
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
||||
}
|
||||
}
|
||||
//String msg="§6Reloaded config file.§r";
|
||||
String msg="§6Reloaded all files.§r";
|
||||
SendMessage(player, msg); //2015.08.09.
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
if(player!=null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
//}
|
||||
//else
|
||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoAdmin(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
{
|
||||
//System.out.println("Args length: " + args.length);
|
||||
if(args.length==1)
|
||||
{
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
//args[0] is "admin"
|
||||
switch(args[1].toLowerCase())
|
||||
{
|
||||
case "reload":
|
||||
DoReload(player);
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
default:
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoPlayerInfo(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "playerinfo"
|
||||
if(args.length==2)
|
||||
{
|
||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||
{
|
||||
String message="§cPlayer not found: "+args[2]+"§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
SendMessage(player, "Player name: "+p.PlayerName);
|
||||
SendMessage(player, "User flair: "+p.Flair);
|
||||
SendMessage(player, "Username: "+p.UserName);
|
||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
||||
}
|
||||
private static void SendMessage(Player player, String message)
|
||||
{ //2015.08.09.
|
||||
if(player==null)
|
||||
System.out.println(message);
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
private static void DoGetLastError(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "getlasterror"
|
||||
if(PluginMain.LastException!=null)
|
||||
{
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException=null;
|
||||
}
|
||||
else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
}
|
|
@ -1,583 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
|
||||
public static boolean PluginUpdated = false; // 2015.08.31.
|
||||
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label,
|
||||
String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
switch (cmd.getName()) {
|
||||
case "u": {
|
||||
if (args.length < 1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(player
|
||||
.getName()); // 2015.08.08.
|
||||
if (!p.CommentedOnReddit
|
||||
&& !args[0].toLowerCase().equals("admin")
|
||||
&& !args[0].toLowerCase().equals("ignore")) {
|
||||
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")) { // 2015.08.10.
|
||||
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")) { // 2015.08.19.
|
||||
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
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
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");
|
||||
} else
|
||||
player.sendMessage("§cYou already ignored this request.§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
|
||||
break;
|
||||
case "announce":
|
||||
DoAnnounce(player, args, null);
|
||||
break;
|
||||
case "name":
|
||||
if (args.length == 1) {
|
||||
player.sendMessage("§cUsage: /u name <playername>§r");
|
||||
break;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[1])) {
|
||||
player.sendMessage("§cUnknown user: " + args[1]);
|
||||
break;
|
||||
}
|
||||
player.sendMessage("§bUsername of "
|
||||
+ args[1]
|
||||
+ ": "
|
||||
+ MaybeOfflinePlayer.AllPlayers.get(args[1]).UserName);
|
||||
break;
|
||||
case "enable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = true;
|
||||
player.sendMessage("Enabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
case "disable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = false;
|
||||
player.sendMessage("Disabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
case "quiz":
|
||||
DoQuiz(player, args, null);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "nrp":
|
||||
case "ooc":
|
||||
if (args.length == 0) {
|
||||
return false;
|
||||
} else {
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = false;
|
||||
String message = "";
|
||||
for (String arg : args)
|
||||
message += arg + " ";
|
||||
player.chat(message.substring(0, message.length() - 1));
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = true;
|
||||
}
|
||||
return true;
|
||||
case "skype":
|
||||
// "skype:?chat&blob=Y_5Ob1BEcw0ZlstdUHyf0ENS5n1Xz2Huhx-5b-pB2JyMSRO5QMEALkJuTSuUaAb3-XfWXwCndwhGex_UpXDbyQ";
|
||||
return true;
|
||||
default:
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
}
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("admin")) // 2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); // 2015.08.09.
|
||||
return true; // 2015.08.09.
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("announce")) {
|
||||
if (sender instanceof BlockCommandSender)
|
||||
DoAnnounce(null, args, (BlockCommandSender) sender);
|
||||
else
|
||||
DoAnnounce(null, args, null);
|
||||
return true;
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("quiz")) {
|
||||
if (sender instanceof BlockCommandSender)
|
||||
DoAnnounce(null, args, (BlockCommandSender) sender);
|
||||
else
|
||||
DoAnnounce(null, args, null);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void DoReload(Player player) { // 2015.07.20.
|
||||
try {
|
||||
PluginMain.Console
|
||||
.sendMessage("§6-- Reloading The Button Minecraft plugin...§r");
|
||||
PluginMain.LoadFiles(true); // 2015.08.09.
|
||||
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.
|
||||
}
|
||||
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.
|
||||
}
|
||||
PluginMain.Console.sendMessage("§6-- Reloading done!§r");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
if (player != null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static Player ReloadPlayer; // 2015.08.09.
|
||||
|
||||
private static String DoAdminUsage = "§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin|togglerpshow|toggledebug|savepos|loadpos§r";
|
||||
|
||||
private static void DoAdmin(Player player, String[] args) { // 2015.08.09.
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// args[0] is "admin"
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "reload":
|
||||
ReloadPlayer = player; // 2015.08.09.
|
||||
SendMessage(
|
||||
player,
|
||||
"§bMake sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
break; // <-- 2015.08.10.
|
||||
case "confirm":
|
||||
if (ReloadPlayer == player)
|
||||
DoReload(player); // 2015.08.09.
|
||||
else
|
||||
SendMessage(player,
|
||||
"§cYou need to do /u admin reload first.§r");
|
||||
break;
|
||||
case "save":
|
||||
PluginMain.SaveFiles(); // 2015.08.09.
|
||||
SendMessage(player,
|
||||
"§bSaved files. Now you can edit them and reload if you want.§r");
|
||||
break;
|
||||
case "setflair":
|
||||
DoSetFlair(player, args);
|
||||
break;
|
||||
case "updateplugin": // 2015.08.10.
|
||||
DoUpdatePlugin(player);
|
||||
break;
|
||||
case "togglerpshow":
|
||||
PlayerListener.ShowRPTag = !PlayerListener.ShowRPTag;
|
||||
SendMessage(player, "RP tag showing "
|
||||
+ (PlayerListener.ShowRPTag ? "enabled" : "disabled"));
|
||||
break;
|
||||
case "toggledebug":
|
||||
PlayerListener.DebugMode = !PlayerListener.DebugMode;
|
||||
SendMessage(player, "DebugMode: " + PlayerListener.DebugMode);
|
||||
break;
|
||||
case "savepos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "loadpos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "updatedynmap":
|
||||
DoUpdateDynmap(player, args);
|
||||
default:
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
|
||||
private static void DoPlayerInfo(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "playerinfo"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(args[2]);
|
||||
if (p == null) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
SendMessage(player, "Player name: " + p.PlayerName);
|
||||
SendMessage(player, "User flair: " + p.Flair);
|
||||
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);
|
||||
}
|
||||
|
||||
private static void SendMessage(Player player, String message) { // 2015.08.09.
|
||||
if (player == null)
|
||||
PluginMain.Console.sendMessage(message); // 2015.08.12.
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
private static void DoGetLastError(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "getlasterror"
|
||||
if (PluginMain.LastException != null) {
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException = null;
|
||||
} else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
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");
|
||||
return;
|
||||
}
|
||||
Player p = Bukkit.getPlayer(args[2]);
|
||||
if (p == null) {
|
||||
SendMessage(player, "§cPLayer not found.&r");
|
||||
return;
|
||||
}
|
||||
SetPlayerFlair(player,
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()), args[3]);
|
||||
}
|
||||
|
||||
private static void DoUpdatePlugin(Player player) { // 2015.08.10.
|
||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
||||
System.out.println("Forced updating of Auto-Flair plugin.");
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(
|
||||
"https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
||||
FileUtils.copyURLToFile(url, new File(
|
||||
"plugins/TheButtonAutoFlair.jar"));
|
||||
PluginUpdated = true; // 2015.08.31.
|
||||
SendMessage(player, "Updating done!");
|
||||
} catch (MalformedURLException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoAnnounce(Player player, String[] args,
|
||||
BlockCommandSender commandblock) {
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "add":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce add <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
PluginMain.AnnounceMessages.add(finalmessage);
|
||||
SendMessage(player, "§bAnnouncement added.§r");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce remove <index>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceMessages.remove(Integer.parseInt(args[2]));
|
||||
break;
|
||||
case "settime":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player,
|
||||
"§cUsage: /u announce settime <minutes>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceTime = Integer.parseInt(args[2]) * 60 * 1000;
|
||||
SendMessage(player, "Time set between announce messages");
|
||||
break;
|
||||
case "list":
|
||||
SendMessage(player, "§bList of announce messages:§r");
|
||||
SendMessage(player, "§bFormat: [index] message§r");
|
||||
int i = 0;
|
||||
for (String message : PluginMain.AnnounceMessages)
|
||||
SendMessage(player, "[" + i++ + "] " + message);
|
||||
SendMessage(player,
|
||||
"§bCurrent wait time between announcements: "
|
||||
+ PluginMain.AnnounceTime / 60 / 1000
|
||||
+ " minute(s)§r");
|
||||
break;
|
||||
case "edit":
|
||||
if (commandblock == null) {
|
||||
SendMessage(
|
||||
player,
|
||||
"§cError: This command can only be used from a command block. Use /u announce remove.");
|
||||
break;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
commandblock
|
||||
.sendMessage("§cUsage: /u announce edit <index> <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 3; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§');
|
||||
int index = Integer.parseInt(args[2]);
|
||||
if (index > 100)
|
||||
break;
|
||||
while (PluginMain.AnnounceMessages.size() <= index)
|
||||
PluginMain.AnnounceMessages.add("");
|
||||
PluginMain.AnnounceMessages.set(Integer.parseInt(args[2]),
|
||||
finalmessage1);
|
||||
commandblock.sendMessage("Announcement edited.");
|
||||
break;
|
||||
default:
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoSaveLoadPos(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "savepos|loadpos"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
Player p = null;
|
||||
for (Player pl : PluginMain.GetPlayers()) {
|
||||
if (pl.getName().equals(args[2])) {
|
||||
p = pl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (p == null) {
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer is not online: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (args[1].equalsIgnoreCase("savepos")) {
|
||||
mp.SavedLocation = p.getLocation();
|
||||
} else if (args[1].equalsIgnoreCase("loadpos")) {
|
||||
if (mp.SavedLocation != null)
|
||||
p.teleport(mp.SavedLocation);
|
||||
} else {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// SendMessage(player, "Player " + p.getName() +
|
||||
// " position saved/loaded.");s
|
||||
}
|
||||
|
||||
private static void DoUpdateDynmap(Player player, String[] args) {
|
||||
// args[0] is "admin" - args[1] is "updatedynmap"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin updatedynmap <password>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<String> Quiz = new ArrayList<>();
|
||||
|
||||
private static void DoQuiz(Player player, String[] args,
|
||||
BlockCommandSender commandblock) {
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = "§cUsage: /u quiz add|remove|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "add":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u quiz add <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
Quiz.add(finalmessage);
|
||||
SendMessage(player, "§Quiz question added.§r");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u quiz remove <index>");
|
||||
return;
|
||||
}
|
||||
Quiz.remove(Integer.parseInt(args[2]));
|
||||
break;
|
||||
case "list":
|
||||
SendMessage(player, "§bList of quiz questions:§r");
|
||||
SendMessage(player, "§bFormat: [index] question§r");
|
||||
int i = 0;
|
||||
for (String question : Quiz)
|
||||
SendMessage(player, "[" + i++ + "] " + question);
|
||||
break;
|
||||
case "edit":
|
||||
if (commandblock == null) {
|
||||
SendMessage(
|
||||
player,
|
||||
"§cError: This command can only be used from a command block. Use /u quiz remove.");
|
||||
break;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
commandblock
|
||||
.sendMessage("§cUsage: /u quiz edit <index> <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 3; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§');
|
||||
int index = Integer.parseInt(args[2]);
|
||||
if (index > 100)
|
||||
break;
|
||||
while (Quiz.size() <= index)
|
||||
Quiz.add("");
|
||||
Quiz.set(Integer.parseInt(args[2]), finalmessage1);
|
||||
commandblock.sendMessage("Question edited.");
|
||||
break;
|
||||
default:
|
||||
String message = "§cUsage: /u quiz add|remove|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,221 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if(args.length<1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||
if(p.Flair==null)
|
||||
{
|
||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||
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.
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
||||
p.AcceptedFlair=true; //2015.08.08.
|
||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
break;
|
||||
}
|
||||
case "ignore":
|
||||
{
|
||||
if(p.AcceptedFlair)
|
||||
p.AcceptedFlair=false; //2015.08.08.
|
||||
if(!p.IgnoredFlair)
|
||||
{
|
||||
p.IgnoredFlair=true;
|
||||
String flair=p.Flair; //2015.08.08.
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already ignored this request.§r");
|
||||
break;
|
||||
}
|
||||
/*case "reload": //2015.07.20.
|
||||
DoReload(player);
|
||||
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;
|
||||
}
|
||||
p.Flair="§7(non-pr.)§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.§r");
|
||||
break;
|
||||
}
|
||||
p.Flair="§r(can't press)§r";
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*if(args[0].toLowerCase()=="reload")
|
||||
DoReload(null); //2015.07.20.*/
|
||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); //2015.08.09.
|
||||
return true; //2015.08.09.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static void DoReload(Player player)
|
||||
{ //2015.07.20.
|
||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
//{
|
||||
try
|
||||
{
|
||||
File file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
PluginMain.LoadFiles(true); //2015.08.09.
|
||||
for(Player p : PluginMain.GetPlayers())
|
||||
{
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
||||
if(mp.Flair!=null)
|
||||
{
|
||||
String flair=mp.Flair;
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
||||
}
|
||||
String msg="§6Note: 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.
|
||||
}
|
||||
//String msg="§6Reloaded config file.§r";
|
||||
//SendMessage(player, msg); //2015.08.09.
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
if(player!=null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
//}
|
||||
//else
|
||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static Player ReloadPlayer; //2015.08.09.
|
||||
private static void DoAdmin(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
{
|
||||
//System.out.println("Args length: " + args.length);
|
||||
if(args.length==1)
|
||||
{
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
//args[0] is "admin"
|
||||
switch(args[1].toLowerCase())
|
||||
{
|
||||
case "reload":
|
||||
ReloadPlayer=player; //2015.08.09.
|
||||
SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.");
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
case "confirm":
|
||||
DoReload(player); //2015.08.09.
|
||||
break;
|
||||
default:
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoPlayerInfo(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "playerinfo"
|
||||
if(args.length==2)
|
||||
{
|
||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||
{
|
||||
String message="§cPlayer not found: "+args[2]+"§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
SendMessage(player, "Player name: "+p.PlayerName);
|
||||
SendMessage(player, "User flair: "+p.Flair);
|
||||
SendMessage(player, "Username: "+p.UserName);
|
||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
||||
}
|
||||
private static void SendMessage(Player player, String message)
|
||||
{ //2015.08.09.
|
||||
if(player==null)
|
||||
System.out.println(message);
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
private static void DoGetLastError(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "getlasterror"
|
||||
if(PluginMain.LastException!=null)
|
||||
{
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException=null;
|
||||
}
|
||||
else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
}
|
|
@ -1,577 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
|
||||
public static boolean PluginUpdated = false; // 2015.08.31.
|
||||
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label,
|
||||
String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
switch (cmd.getName()) {
|
||||
case "u": {
|
||||
if (args.length < 1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(player
|
||||
.getName()); // 2015.08.08.
|
||||
if (!p.CommentedOnReddit
|
||||
&& !args[0].toLowerCase().equals("admin")
|
||||
&& !args[0].toLowerCase().equals("ignore")) {
|
||||
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")) { // 2015.08.10.
|
||||
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")) { // 2015.08.19.
|
||||
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
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
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");
|
||||
} else
|
||||
player.sendMessage("§cYou already ignored this request.§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
|
||||
break;
|
||||
case "announce":
|
||||
DoAnnounce(player, args, null);
|
||||
break;
|
||||
case "name":
|
||||
if (args.length == 1) {
|
||||
player.sendMessage("§cUsage: /u name <playername>§r");
|
||||
break;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[1])) {
|
||||
player.sendMessage("§cUnknown user: " + args[1]);
|
||||
break;
|
||||
}
|
||||
player.sendMessage("§bUsername of "
|
||||
+ args[1]
|
||||
+ ": "
|
||||
+ MaybeOfflinePlayer.AllPlayers.get(args[1]).UserName);
|
||||
break;
|
||||
case "enable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = true;
|
||||
player.sendMessage("Enabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
case "disable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = false;
|
||||
player.sendMessage("Disabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
case "quiz":
|
||||
DoQuiz(player, args, null);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "nrp":
|
||||
case "ooc":
|
||||
if (args.length == 0) {
|
||||
return false;
|
||||
} else {
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = false;
|
||||
String message = "";
|
||||
for (String arg : args)
|
||||
message += arg + " ";
|
||||
player.chat(message.substring(0, message.length() - 1));
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = true;
|
||||
}
|
||||
return true;
|
||||
case "skype":
|
||||
// "skype:?chat&blob=Y_5Ob1BEcw0ZlstdUHyf0ENS5n1Xz2Huhx-5b-pB2JyMSRO5QMEALkJuTSuUaAb3-XfWXwCndwhGex_UpXDbyQ";
|
||||
return true;
|
||||
default:
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
}
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("admin")) // 2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); // 2015.08.09.
|
||||
return true; // 2015.08.09.
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("announce")) {
|
||||
if (sender instanceof BlockCommandSender)
|
||||
DoAnnounce(null, args, (BlockCommandSender) sender);
|
||||
else
|
||||
DoAnnounce(null, args, null);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void DoReload(Player player) { // 2015.07.20.
|
||||
try {
|
||||
PluginMain.Console
|
||||
.sendMessage("§6-- Reloading The Button Minecraft plugin...§r");
|
||||
PluginMain.LoadFiles(true); // 2015.08.09.
|
||||
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.
|
||||
}
|
||||
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.
|
||||
}
|
||||
PluginMain.Console.sendMessage("§6-- Reloading done!§r");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
if (player != null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static Player ReloadPlayer; // 2015.08.09.
|
||||
|
||||
private static String DoAdminUsage = "§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin|togglerpshow|toggledebug|savepos|loadpos§r";
|
||||
|
||||
private static void DoAdmin(Player player, String[] args) { // 2015.08.09.
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// args[0] is "admin"
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "reload":
|
||||
ReloadPlayer = player; // 2015.08.09.
|
||||
SendMessage(
|
||||
player,
|
||||
"§bMake sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
break; // <-- 2015.08.10.
|
||||
case "confirm":
|
||||
if (ReloadPlayer == player)
|
||||
DoReload(player); // 2015.08.09.
|
||||
else
|
||||
SendMessage(player,
|
||||
"§cYou need to do /u admin reload first.§r");
|
||||
break;
|
||||
case "save":
|
||||
PluginMain.SaveFiles(); // 2015.08.09.
|
||||
SendMessage(player,
|
||||
"§bSaved files. Now you can edit them and reload if you want.§r");
|
||||
break;
|
||||
case "setflair":
|
||||
DoSetFlair(player, args);
|
||||
break;
|
||||
case "updateplugin": // 2015.08.10.
|
||||
DoUpdatePlugin(player);
|
||||
break;
|
||||
case "togglerpshow":
|
||||
PlayerListener.ShowRPTag = !PlayerListener.ShowRPTag;
|
||||
SendMessage(player, "RP tag showing "
|
||||
+ (PlayerListener.ShowRPTag ? "enabled" : "disabled"));
|
||||
break;
|
||||
case "toggledebug":
|
||||
PlayerListener.DebugMode = !PlayerListener.DebugMode;
|
||||
SendMessage(player, "DebugMode: " + PlayerListener.DebugMode);
|
||||
break;
|
||||
case "savepos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "loadpos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "updatedynmap":
|
||||
DoUpdateDynmap(player, args);
|
||||
default:
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
|
||||
private static void DoPlayerInfo(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "playerinfo"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(args[2]);
|
||||
if (p == null) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
SendMessage(player, "Player name: " + p.PlayerName);
|
||||
SendMessage(player, "User flair: " + p.Flair);
|
||||
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);
|
||||
}
|
||||
|
||||
private static void SendMessage(Player player, String message) { // 2015.08.09.
|
||||
if (player == null)
|
||||
PluginMain.Console.sendMessage(message); // 2015.08.12.
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
private static void DoGetLastError(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "getlasterror"
|
||||
if (PluginMain.LastException != null) {
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException = null;
|
||||
} else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
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");
|
||||
return;
|
||||
}
|
||||
Player p = Bukkit.getPlayer(args[2]);
|
||||
if (p == null) {
|
||||
SendMessage(player, "§cPLayer not found.&r");
|
||||
return;
|
||||
}
|
||||
SetPlayerFlair(player,
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()), args[3]);
|
||||
}
|
||||
|
||||
private static void DoUpdatePlugin(Player player) { // 2015.08.10.
|
||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
||||
System.out.println("Forced updating of Auto-Flair plugin.");
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(
|
||||
"https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
||||
FileUtils.copyURLToFile(url, new File(
|
||||
"plugins/TheButtonAutoFlair.jar"));
|
||||
PluginUpdated = true; // 2015.08.31.
|
||||
SendMessage(player, "Updating done!");
|
||||
} catch (MalformedURLException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoAnnounce(Player player, String[] args,
|
||||
BlockCommandSender commandblock) {
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "add":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce add <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
PluginMain.AnnounceMessages.add(finalmessage);
|
||||
SendMessage(player, "§bAnnouncement added.§r");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce remove <index>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceMessages.remove(Integer.parseInt(args[2]));
|
||||
break;
|
||||
case "settime":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player,
|
||||
"§cUsage: /u announce settime <minutes>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceTime = Integer.parseInt(args[2]) * 60 * 1000;
|
||||
SendMessage(player, "Time set between announce messages");
|
||||
break;
|
||||
case "list":
|
||||
SendMessage(player, "§bList of announce messages:§r");
|
||||
SendMessage(player, "§bFormat: [index] message§r");
|
||||
int i = 0;
|
||||
for (String message : PluginMain.AnnounceMessages)
|
||||
SendMessage(player, "[" + i++ + "] " + message);
|
||||
SendMessage(player,
|
||||
"§bCurrent wait time between announcements: "
|
||||
+ PluginMain.AnnounceTime / 60 / 1000
|
||||
+ " minute(s)§r");
|
||||
break;
|
||||
case "edit":
|
||||
if (commandblock == null) {
|
||||
SendMessage(
|
||||
player,
|
||||
"§cError: This command can only be used from a command block. Use /u announce remove.");
|
||||
break;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
commandblock
|
||||
.sendMessage("§cUsage: /u announce edit <index> <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 3; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§');
|
||||
int index = Integer.parseInt(args[2]);
|
||||
if (index > 100)
|
||||
break;
|
||||
while (PluginMain.AnnounceMessages.size() <= index)
|
||||
PluginMain.AnnounceMessages.add("");
|
||||
PluginMain.AnnounceMessages.set(Integer.parseInt(args[2]),
|
||||
finalmessage1);
|
||||
commandblock.sendMessage("Announcement edited.");
|
||||
break;
|
||||
default:
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoSaveLoadPos(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "savepos|loadpos"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
Player p = null;
|
||||
for (Player pl : PluginMain.GetPlayers()) {
|
||||
if (pl.getName().equals(args[2])) {
|
||||
p = pl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (p == null) {
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer is not online: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (args[1].equalsIgnoreCase("savepos")) {
|
||||
mp.SavedLocation = p.getLocation();
|
||||
} else if (args[1].equalsIgnoreCase("loadpos")) {
|
||||
if (mp.SavedLocation != null)
|
||||
p.teleport(mp.SavedLocation);
|
||||
} else {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// SendMessage(player, "Player " + p.getName() +
|
||||
// " position saved/loaded.");s
|
||||
}
|
||||
|
||||
private static void DoUpdateDynmap(Player player, String[] args) {
|
||||
// args[0] is "admin" - args[1] is "updatedynmap"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin updatedynmap <password>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<String> Quiz = new ArrayList<>();
|
||||
|
||||
private static void DoQuiz(Player player, String[] args,
|
||||
BlockCommandSender commandblock) {
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = "§cUsage: /u quiz add|remove|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "add":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u quiz add <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
Quiz.add(finalmessage);
|
||||
SendMessage(player, "§Quiz question added.§r");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u quiz remove <index>");
|
||||
return;
|
||||
}
|
||||
Quiz.remove(Integer.parseInt(args[2]));
|
||||
break;
|
||||
case "list":
|
||||
SendMessage(player, "§bList of quiz questions:§r");
|
||||
SendMessage(player, "§bFormat: [index] question§r");
|
||||
int i = 0;
|
||||
for (String question : Quiz)
|
||||
SendMessage(player, "[" + i++ + "] " + question);
|
||||
break;
|
||||
case "edit":
|
||||
if (commandblock == null) {
|
||||
SendMessage(
|
||||
player,
|
||||
"§cError: This command can only be used from a command block. Use /u quiz remove.");
|
||||
break;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
commandblock
|
||||
.sendMessage("§cUsage: /u quiz edit <index> <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 3; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§');
|
||||
int index = Integer.parseInt(args[2]);
|
||||
if (index > 100)
|
||||
break;
|
||||
while (Quiz.size() <= index)
|
||||
Quiz.add("");
|
||||
Quiz.set(Integer.parseInt(args[2]), finalmessage1);
|
||||
commandblock.sendMessage("Question edited.");
|
||||
break;
|
||||
default:
|
||||
String message = "§cUsage: /u quiz add|remove|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,491 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
|
||||
public static boolean PluginUpdated = false; // 2015.08.31.
|
||||
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label,
|
||||
String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
switch (cmd.getName()) {
|
||||
case "u": {
|
||||
if (args.length < 1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(player
|
||||
.getName()); // 2015.08.08.
|
||||
if (!p.CommentedOnReddit
|
||||
&& !args[0].toLowerCase().equals("admin")
|
||||
&& !args[0].toLowerCase().equals("ignore")) {
|
||||
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")) { // 2015.08.10.
|
||||
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")) { // 2015.08.19.
|
||||
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
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
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");
|
||||
} else
|
||||
player.sendMessage("§cYou already ignored this request.§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
|
||||
break;
|
||||
case "announce":
|
||||
DoAnnounce(player, args, null);
|
||||
break;
|
||||
case "name":
|
||||
if (args.length == 1) {
|
||||
player.sendMessage("§cUsage: /u name <playername>§r");
|
||||
break;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[1])) {
|
||||
player.sendMessage("§cUnknown user: " + args[1]);
|
||||
break;
|
||||
}
|
||||
player.sendMessage("§bUsername of "
|
||||
+ args[1]
|
||||
+ ": "
|
||||
+ MaybeOfflinePlayer.AllPlayers.get(args[1]).UserName);
|
||||
break;
|
||||
case "enable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = true;
|
||||
player.sendMessage("Enabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
case "disable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = false;
|
||||
player.sendMessage("Disabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "nrp":
|
||||
case "ooc":
|
||||
if (args.length == 0) {
|
||||
return false;
|
||||
} else {
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = false;
|
||||
String message = "";
|
||||
for (String arg : args)
|
||||
message += arg + " ";
|
||||
player.chat(message.substring(0, message.length() - 1));
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = true;
|
||||
}
|
||||
return true;
|
||||
case "skype":
|
||||
// "skype:?chat&blob=Y_5Ob1BEcw0ZlstdUHyf0ENS5n1Xz2Huhx-5b-pB2JyMSRO5QMEALkJuTSuUaAb3-XfWXwCndwhGex_UpXDbyQ";
|
||||
return true;
|
||||
default:
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
}
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("admin")) // 2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); // 2015.08.09.
|
||||
return true; // 2015.08.09.
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("announce")) {
|
||||
if (sender instanceof BlockCommandSender)
|
||||
DoAnnounce(null, args, (BlockCommandSender) sender);
|
||||
else
|
||||
DoAnnounce(null, args, null);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void DoReload(Player player) { // 2015.07.20.
|
||||
try {
|
||||
PluginMain.Console
|
||||
.sendMessage("§6-- Reloading The Button Minecraft plugin...§r");
|
||||
PluginMain.LoadFiles(true); // 2015.08.09.
|
||||
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.
|
||||
}
|
||||
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.
|
||||
}
|
||||
PluginMain.Console.sendMessage("§6-- Reloading done!§r");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
if (player != null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static Player ReloadPlayer; // 2015.08.09.
|
||||
|
||||
private static String DoAdminUsage = "§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin|togglerpshow|toggledebug|savepos|loadpos§r";
|
||||
|
||||
private static void DoAdmin(Player player, String[] args) { // 2015.08.09.
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// args[0] is "admin"
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "reload":
|
||||
ReloadPlayer = player; // 2015.08.09.
|
||||
SendMessage(
|
||||
player,
|
||||
"§bMake sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
break; // <-- 2015.08.10.
|
||||
case "confirm":
|
||||
if (ReloadPlayer == player)
|
||||
DoReload(player); // 2015.08.09.
|
||||
else
|
||||
SendMessage(player,
|
||||
"§cYou need to do /u admin reload first.§r");
|
||||
break;
|
||||
case "save":
|
||||
PluginMain.SaveFiles(); // 2015.08.09.
|
||||
SendMessage(player,
|
||||
"§bSaved files. Now you can edit them and reload if you want.§r");
|
||||
break;
|
||||
case "setflair":
|
||||
DoSetFlair(player, args);
|
||||
break;
|
||||
case "updateplugin": // 2015.08.10.
|
||||
DoUpdatePlugin(player);
|
||||
break;
|
||||
case "togglerpshow":
|
||||
PlayerListener.ShowRPTag = !PlayerListener.ShowRPTag;
|
||||
SendMessage(player, "RP tag showing "
|
||||
+ (PlayerListener.ShowRPTag ? "enabled" : "disabled"));
|
||||
break;
|
||||
case "toggledebug":
|
||||
PlayerListener.DebugMode = !PlayerListener.DebugMode;
|
||||
SendMessage(player, "DebugMode: " + PlayerListener.DebugMode);
|
||||
break;
|
||||
case "savepos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "loadpos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "updatedynmap":
|
||||
DoUpdateDynmap(player, args);
|
||||
default:
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
|
||||
private static void DoPlayerInfo(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "playerinfo"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(args[2]);
|
||||
if (p == null) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
SendMessage(player, "Player name: " + p.PlayerName);
|
||||
SendMessage(player, "User flair: " + p.Flair);
|
||||
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);
|
||||
}
|
||||
|
||||
private static void SendMessage(Player player, String message) { // 2015.08.09.
|
||||
if (player == null)
|
||||
PluginMain.Console.sendMessage(message); // 2015.08.12.
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
private static void DoGetLastError(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "getlasterror"
|
||||
if (PluginMain.LastException != null) {
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException = null;
|
||||
} else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
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");
|
||||
return;
|
||||
}
|
||||
Player p = Bukkit.getPlayer(args[2]);
|
||||
if (p == null) {
|
||||
SendMessage(player, "§cPLayer not found.&r");
|
||||
return;
|
||||
}
|
||||
SetPlayerFlair(player,
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()), args[3]);
|
||||
}
|
||||
|
||||
private static void DoUpdatePlugin(Player player) { // 2015.08.10.
|
||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
||||
System.out.println("Forced updating of Auto-Flair plugin.");
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(
|
||||
"https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
||||
FileUtils.copyURLToFile(url, new File(
|
||||
"plugins/TheButtonAutoFlair.jar"));
|
||||
PluginUpdated = true; // 2015.08.31.
|
||||
SendMessage(player, "Updating done!");
|
||||
} catch (MalformedURLException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoAnnounce(Player player, String[] args,
|
||||
BlockCommandSender commandblock) {
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "add":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce add <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
PluginMain.AnnounceMessages.add(finalmessage);
|
||||
SendMessage(player, "§bAnnouncement added.§r");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce remove <index>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceMessages.remove(Integer.parseInt(args[2]));
|
||||
break;
|
||||
case "settime":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player,
|
||||
"§cUsage: /u announce settime <minutes>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceTime = Integer.parseInt(args[2]) * 60 * 1000;
|
||||
SendMessage(player, "Time set between announce messages");
|
||||
break;
|
||||
case "list":
|
||||
SendMessage(player, "§bList of announce messages:§r");
|
||||
SendMessage(player, "§bFormat: [index] message§r");
|
||||
int i = 0;
|
||||
for (String message : PluginMain.AnnounceMessages)
|
||||
SendMessage(player, "[" + i++ + "] " + message);
|
||||
SendMessage(player,
|
||||
"§bCurrent wait time between announcements: "
|
||||
+ PluginMain.AnnounceTime / 60 / 1000
|
||||
+ " minute(s)§r");
|
||||
break;
|
||||
case "edit":
|
||||
if (commandblock == null) {
|
||||
SendMessage(
|
||||
player,
|
||||
"§cError: This command can only be used from a command block. Use /u announce remove.");
|
||||
break;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
commandblock
|
||||
.sendMessage("§cUsage: /u announce edit <index> <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 3; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§');
|
||||
PluginMain.AnnounceMessages.set(Integer.parseInt(args[2]),
|
||||
finalmessage1);
|
||||
commandblock.sendMessage("Announcement edited.");
|
||||
break;
|
||||
default:
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoSaveLoadPos(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "savepos|loadpos"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
Player p = null;
|
||||
for (Player pl : PluginMain.GetPlayers()) {
|
||||
if (pl.getName().equals(args[2])) {
|
||||
p = pl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (p == null) {
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer is not online: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (args[1].equalsIgnoreCase("savepos")) {
|
||||
mp.SavedLocation = p.getLocation();
|
||||
} else if (args[1].equalsIgnoreCase("loadpos")) {
|
||||
if (mp.SavedLocation != null)
|
||||
p.teleport(mp.SavedLocation);
|
||||
} else {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// SendMessage(player, "Player " + p.getName() +
|
||||
// " position saved/loaded.");s
|
||||
}
|
||||
|
||||
private static void DoUpdateDynmap(Player player, String[] args) {
|
||||
// args[0] is "admin" - args[1] is "updatedynmap"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin updatedynmap <password>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,354 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
|
||||
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/
|
||||
private static PluginMain Instance;
|
||||
// Fired when plugin is first enabled
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
this.getCommand("u").setExecutor(new Commands());
|
||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||
Instance=this; //2015.08.08.
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
//System.out.println("Name: " + name);
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("flairsignored.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while((line=br.readLine())!=null)
|
||||
{
|
||||
String[] s=line.split(" ");
|
||||
TownColors.put(s[0], s[1]);
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
//throw new IOException("Test"); //2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||
Thread t=new Thread(r);
|
||||
t.start();
|
||||
}
|
||||
Boolean stop=false;
|
||||
// Fired when plugin is disabled
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
try
|
||||
{
|
||||
FileWriter fw;
|
||||
fw = new FileWriter("flairsaccepted.txt");
|
||||
fw.close();
|
||||
fw = new FileWriter("flairsignored.txt");
|
||||
fw.close();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.AcceptedFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
file=new File("flairsignored.txt");
|
||||
bw = new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.IgnoredFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
stop=true;
|
||||
}
|
||||
|
||||
public void ThreadMethod() //<-- 2015.07.16.
|
||||
{
|
||||
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();
|
||||
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();
|
||||
if(HasIGFlair(ign))
|
||||
continue;
|
||||
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";
|
||||
else
|
||||
flair = "non-presser";
|
||||
String flairclass;
|
||||
if(flairdata.length>2)
|
||||
flairclass = flairdata[2];
|
||||
else
|
||||
flairclass="unknown";
|
||||
SetFlair(ign, flair, flairclass, author);
|
||||
}
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Exception LastException; //2015.08.09.
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||
public Boolean HasIGFlair(String playername)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
return p.Flair!=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||
{
|
||||
String finalflair;
|
||||
switch(flairclass)
|
||||
{
|
||||
case "press-1":
|
||||
finalflair="§c("+text+")§r";
|
||||
break;
|
||||
case "press-2":
|
||||
finalflair="§6("+text+")§r";
|
||||
break;
|
||||
case "press-3":
|
||||
finalflair="§e("+text+")§r";
|
||||
break;
|
||||
case "press-4":
|
||||
finalflair="§a("+text+")§r";
|
||||
break;
|
||||
case "press-5":
|
||||
finalflair="§9("+text+")§r";
|
||||
break;
|
||||
case "press-6":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "no-press":
|
||||
finalflair="§7(non-pr.)§r";
|
||||
break;
|
||||
case "cheater":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "cant-press": //2015.08.08.
|
||||
finalflair="§r(can't press)§r";
|
||||
break;
|
||||
case "undecided":
|
||||
finalflair=""; //2015.08.09.
|
||||
break;
|
||||
default:
|
||||
finalflair="";
|
||||
break;
|
||||
}
|
||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||
return;
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
p.Flair=finalflair; //2015.08.08.
|
||||
p.UserName=username; //2015.08.08.
|
||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||
{
|
||||
if(player.getName().equals(playername))
|
||||
{
|
||||
AppendPlayerDisplayFlair(player, username, finalflair);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String GetFlair(Player player)
|
||||
{ //2015.07.16.
|
||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||
return flair==null ? "" : flair;
|
||||
}
|
||||
|
||||
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||
{
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
||||
return;
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
||||
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
else
|
||||
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
||||
}
|
||||
|
||||
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||
String[] colors = color.substring(1).split("§");
|
||||
String displayname=player.getName(); //2015.08.08.
|
||||
ArrayList<Integer> Positions=new ArrayList<>();
|
||||
for(int i=0; i<displayname.length(); i++) {
|
||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||
Positions.add(i);
|
||||
}
|
||||
}
|
||||
String finalname=""; //TODO
|
||||
if(Positions.size()>=colors.length)
|
||||
{
|
||||
int x=0;
|
||||
for(int i=0; i<Positions.size(); i++)
|
||||
{
|
||||
int pos=Positions.get(i);
|
||||
int nextpos;
|
||||
if(i!=Positions.size()-1)
|
||||
nextpos=Positions.get(i+1);
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Positions.clear();
|
||||
int unit=displayname.length()/colors.length;
|
||||
int x=0;
|
||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||
{
|
||||
int pos=i;
|
||||
int nextpos;
|
||||
if(i<displayname.length()-unit-unit)
|
||||
nextpos=i+unit;
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||
}
|
||||
|
||||
public static String GetColorForTown(String townname)
|
||||
{ //2015.07.20.
|
||||
if(TownColors.containsKey(townname))
|
||||
return TownColors.get(townname);
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String GetPlayerTown(Player player)
|
||||
{ //2015.07.20.
|
||||
try {
|
||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||
return town.getName();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public static Collection<? extends Player> GetPlayers()
|
||||
{
|
||||
return Instance.getServer().getOnlinePlayers();
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
public class PlayerJoinTimerTask {
|
||||
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
||||
|
||||
public class PlayerListener implements Listener
|
||||
{ //2015.07.16.
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
Player p=event.getPlayer();
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
||||
if(mp.CommentedOnReddit)
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
||||
else
|
||||
{ //2015.07.20.
|
||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your §6Minecraft name to \"},{\"text\":\"[this thread.]\",\"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§r\"}]}}}]";
|
||||
sendRawMessage(p, json);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event)
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
||||
{
|
||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
||||
String flair=player.Flair; //2015.08.08.
|
||||
if(player.IgnoredFlair)
|
||||
flair="";
|
||||
String message=event.getMessage(); //2015.08.08.
|
||||
for(Player p : PluginMain.GetPlayers())
|
||||
{ //2015.08.12.
|
||||
message = message.replaceAll(p.getName(), "§6"+p.getName()+"§r");
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, arg2, arg3)
|
||||
}
|
||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
||||
}
|
||||
|
||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
||||
public static void sendRawMessage(Player player, String message)
|
||||
{
|
||||
try {
|
||||
System.out.println("1");
|
||||
Object handle = Reflection.getHandle(player);
|
||||
System.out.println("2");
|
||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
||||
System.out.println("3");
|
||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
||||
System.out.println("4");
|
||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
||||
System.out.println("5");
|
||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
||||
System.out.println("6");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,376 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
|
||||
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/
|
||||
private static PluginMain Instance;
|
||||
// Fired when plugin is first enabled
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
this.getCommand("u").setExecutor(new Commands());
|
||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||
Instance=this; //2015.08.08.
|
||||
LoadFiles(false); //2015.08.09.
|
||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||
Thread t=new Thread(r);
|
||||
t.start();
|
||||
}
|
||||
Boolean stop=false;
|
||||
// Fired when plugin is disabled
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
try
|
||||
{
|
||||
FileWriter fw;
|
||||
fw = new FileWriter("flairsaccepted.txt");
|
||||
fw.close();
|
||||
fw = new FileWriter("flairsignored.txt");
|
||||
fw.close();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.AcceptedFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
file=new File("flairsignored.txt");
|
||||
bw = new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.IgnoredFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
stop=true;
|
||||
}
|
||||
|
||||
public void ThreadMethod() //<-- 2015.07.16.
|
||||
{
|
||||
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();
|
||||
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();
|
||||
if(HasIGFlair(ign))
|
||||
continue;
|
||||
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";
|
||||
else
|
||||
flair = "non-presser";
|
||||
String flairclass;
|
||||
if(flairdata.length>2)
|
||||
flairclass = flairdata[2];
|
||||
else
|
||||
flairclass="unknown";
|
||||
SetFlair(ign, flair, flairclass, author);
|
||||
}
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Exception LastException; //2015.08.09.
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||
public Boolean HasIGFlair(String playername)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
return p.Flair!=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
String finalflair;
|
||||
p.FlairDecided=true;
|
||||
switch(flairclass)
|
||||
{
|
||||
case "press-1":
|
||||
finalflair="§c("+text+")§r";
|
||||
break;
|
||||
case "press-2":
|
||||
finalflair="§6("+text+")§r";
|
||||
break;
|
||||
case "press-3":
|
||||
finalflair="§e("+text+")§r";
|
||||
break;
|
||||
case "press-4":
|
||||
finalflair="§a("+text+")§r";
|
||||
break;
|
||||
case "press-5":
|
||||
finalflair="§9("+text+")§r";
|
||||
break;
|
||||
case "press-6":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "no-press":
|
||||
finalflair="§7(non-pr.)§r";
|
||||
break;
|
||||
case "cheater":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "cant-press": //2015.08.08.
|
||||
finalflair="§r(can't press)§r";
|
||||
break;
|
||||
case "undecided": //2015.08.09.
|
||||
p.FlairDecided=false;
|
||||
finalflair="";
|
||||
break;
|
||||
default:
|
||||
finalflair="";
|
||||
break;
|
||||
}
|
||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||
return;
|
||||
p.Flair=finalflair; //2015.08.08.
|
||||
p.UserName=username; //2015.08.08.
|
||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||
{
|
||||
if(player.getName().equals(playername))
|
||||
{
|
||||
//AppendPlayerDisplayFlair(player, username, finalflair);
|
||||
AppendPlayerDisplayFlair(p, player);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String GetFlair(Player player)
|
||||
{ //2015.07.16.
|
||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||
return flair==null ? "" : flair;
|
||||
}
|
||||
|
||||
//public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||
public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09.
|
||||
{
|
||||
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair)
|
||||
return;
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair)
|
||||
{
|
||||
AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20.
|
||||
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");
|
||||
}
|
||||
|
||||
private static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||
String[] colors = color.substring(1).split("§");
|
||||
String displayname=player.getName(); //2015.08.08.
|
||||
ArrayList<Integer> Positions=new ArrayList<>();
|
||||
for(int i=0; i<displayname.length(); i++) {
|
||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||
Positions.add(i);
|
||||
}
|
||||
}
|
||||
String finalname=""; //TODO
|
||||
if(Positions.size()>=colors.length)
|
||||
{
|
||||
int x=0;
|
||||
for(int i=0; i<Positions.size(); i++)
|
||||
{
|
||||
int pos=Positions.get(i);
|
||||
int nextpos;
|
||||
if(i!=Positions.size()-1)
|
||||
nextpos=Positions.get(i+1);
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Positions.clear();
|
||||
int unit=displayname.length()/colors.length;
|
||||
int x=0;
|
||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||
{
|
||||
int pos=i;
|
||||
int nextpos;
|
||||
if(i<displayname.length()-unit-unit)
|
||||
nextpos=i+unit;
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||
}
|
||||
|
||||
public static String GetColorForTown(String townname)
|
||||
{ //2015.07.20.
|
||||
if(TownColors.containsKey(townname))
|
||||
return TownColors.get(townname);
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String GetPlayerTown(Player player)
|
||||
{ //2015.07.20.
|
||||
try {
|
||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||
return town.getName();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public static Collection<? extends Player> GetPlayers()
|
||||
{
|
||||
return Instance.getServer().getOnlinePlayers();
|
||||
}
|
||||
|
||||
public static void LoadFiles(boolean reload) //<-- 2015.08.09.
|
||||
{
|
||||
if(reload)
|
||||
{ //2015.08.09.
|
||||
System.out.println("Auto-flair plugin cleanup for reloading...");
|
||||
MaybeOfflinePlayer.AllPlayers.clear();
|
||||
TownColors.clear();
|
||||
}
|
||||
System.out.println("Loading files for auto-flair plugin..."); //2015.08.09.
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
//System.out.println("Name: " + name);
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("flairsignored.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while((line=br.readLine())!=null)
|
||||
{
|
||||
String[] s=line.split(" ");
|
||||
TownColors.put(s[0], s[1]);
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
//throw new IOException("Test"); //2015.08.09.
|
||||
System.out.println("Auto-flair plugin loaded files!");
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,376 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
|
||||
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/
|
||||
private static PluginMain Instance;
|
||||
// Fired when plugin is first enabled
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
this.getCommand("u").setExecutor(new Commands());
|
||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||
Instance=this; //2015.08.08.
|
||||
LoadFiles(false); //2015.08.09.
|
||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||
Thread t=new Thread(r);
|
||||
t.start();
|
||||
}
|
||||
Boolean stop=false;
|
||||
// Fired when plugin is disabled
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
try
|
||||
{
|
||||
FileWriter fw;
|
||||
fw = new FileWriter("flairsaccepted.txt");
|
||||
fw.close();
|
||||
fw = new FileWriter("flairsignored.txt");
|
||||
fw.close();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.AcceptedFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
file=new File("flairsignored.txt");
|
||||
bw = new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.IgnoredFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
stop=true;
|
||||
}
|
||||
|
||||
public void ThreadMethod() //<-- 2015.07.16.
|
||||
{
|
||||
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();
|
||||
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();
|
||||
if(HasIGFlair(ign))
|
||||
continue;
|
||||
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";
|
||||
else
|
||||
flair = "non-presser";
|
||||
String flairclass;
|
||||
if(flairdata.length>2)
|
||||
flairclass = flairdata[2];
|
||||
else
|
||||
flairclass="unknown";
|
||||
SetFlair(ign, flair, flairclass, author);
|
||||
}
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Exception LastException; //2015.08.09.
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||
public Boolean HasIGFlair(String playername)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
return p.Flair!=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
String finalflair;
|
||||
p.FlairDecided=true;
|
||||
switch(flairclass)
|
||||
{
|
||||
case "press-1":
|
||||
finalflair="§c("+text+")§r";
|
||||
break;
|
||||
case "press-2":
|
||||
finalflair="§6("+text+")§r";
|
||||
break;
|
||||
case "press-3":
|
||||
finalflair="§e("+text+")§r";
|
||||
break;
|
||||
case "press-4":
|
||||
finalflair="§a("+text+")§r";
|
||||
break;
|
||||
case "press-5":
|
||||
finalflair="§9("+text+")§r";
|
||||
break;
|
||||
case "press-6":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "no-press":
|
||||
finalflair="§7(non-pr.)§r";
|
||||
break;
|
||||
case "cheater":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "cant-press": //2015.08.08.
|
||||
finalflair="§r(can't press)§r";
|
||||
break;
|
||||
case "undecided": //2015.08.09.
|
||||
p.FlairDecided=false;
|
||||
finalflair="";
|
||||
break;
|
||||
default:
|
||||
finalflair="";
|
||||
break;
|
||||
}
|
||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||
return;
|
||||
p.Flair=finalflair; //2015.08.08.
|
||||
p.UserName=username; //2015.08.08.
|
||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||
{
|
||||
if(player.getName().equals(playername))
|
||||
{
|
||||
//AppendPlayerDisplayFlair(player, username, finalflair);
|
||||
AppendPlayerDisplayFlair(p, player);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String GetFlair(Player player)
|
||||
{ //2015.07.16.
|
||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||
return flair==null ? "" : flair;
|
||||
}
|
||||
|
||||
//public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||
public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09.
|
||||
{
|
||||
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair)
|
||||
return;
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair)
|
||||
{
|
||||
AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20.
|
||||
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");
|
||||
}
|
||||
|
||||
private static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||
String[] colors = color.substring(1).split("§");
|
||||
String displayname=player.getName(); //2015.08.08.
|
||||
ArrayList<Integer> Positions=new ArrayList<>();
|
||||
for(int i=0; i<displayname.length(); i++) {
|
||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||
Positions.add(i);
|
||||
}
|
||||
}
|
||||
String finalname=""; //TODO
|
||||
if(Positions.size()>=colors.length)
|
||||
{
|
||||
int x=0;
|
||||
for(int i=0; i<Positions.size(); i++)
|
||||
{
|
||||
int pos=Positions.get(i);
|
||||
int nextpos;
|
||||
if(i!=Positions.size()-1)
|
||||
nextpos=Positions.get(i+1);
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Positions.clear();
|
||||
int unit=displayname.length()/colors.length;
|
||||
int x=0;
|
||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||
{
|
||||
int pos=i;
|
||||
int nextpos;
|
||||
if(i<displayname.length()-unit-unit)
|
||||
nextpos=i+unit;
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||
}
|
||||
|
||||
public static String GetColorForTown(String townname)
|
||||
{ //2015.07.20.
|
||||
if(TownColors.containsKey(townname))
|
||||
return TownColors.get(townname);
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String GetPlayerTown(Player player)
|
||||
{ //2015.07.20.
|
||||
try {
|
||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||
return town.getName();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public static Collection<? extends Player> GetPlayers()
|
||||
{
|
||||
return Instance.getServer().getOnlinePlayers();
|
||||
}
|
||||
|
||||
public static void LoadFiles(boolean reload) //<-- 2015.08.09.
|
||||
{
|
||||
if(reload)
|
||||
{ //2015.08.09.
|
||||
System.out.println("Auto-flair plugin cleanup for reloading...");
|
||||
MaybeOfflinePlayer.AllPlayers.clear();
|
||||
TownColors.clear();
|
||||
}
|
||||
System.out.println("Loading files for auto-flair plugin..."); //2015.08.09.
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
//System.out.println("Name: " + name);
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("flairsignored.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while((line=br.readLine())!=null)
|
||||
{
|
||||
String[] s=line.split(" ");
|
||||
TownColors.put(s[0], s[1]);
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
//throw new IOException("Test"); //2015.08.09.
|
||||
System.out.println("Auto-flair plugin loaded files!");
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,579 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
|
||||
public static boolean PluginUpdated = false; // 2015.08.31.
|
||||
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label,
|
||||
String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
switch (cmd.getName()) {
|
||||
case "u": {
|
||||
if (args.length < 1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(player
|
||||
.getName()); // 2015.08.08.
|
||||
if (!p.CommentedOnReddit
|
||||
&& !args[0].toLowerCase().equals("admin")
|
||||
&& !args[0].toLowerCase().equals("ignore")) {
|
||||
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")) { // 2015.08.10.
|
||||
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")) { // 2015.08.19.
|
||||
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
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
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");
|
||||
} else
|
||||
player.sendMessage("§cYou already ignored this request.§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
|
||||
break;
|
||||
case "announce":
|
||||
DoAnnounce(player, args, null);
|
||||
break;
|
||||
case "name":
|
||||
if (args.length == 1) {
|
||||
player.sendMessage("§cUsage: /u name <playername>§r");
|
||||
break;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[1])) {
|
||||
player.sendMessage("§cUnknown user: " + args[1]);
|
||||
break;
|
||||
}
|
||||
player.sendMessage("§bUsername of "
|
||||
+ args[1]
|
||||
+ ": "
|
||||
+ MaybeOfflinePlayer.AllPlayers.get(args[1]).UserName);
|
||||
break;
|
||||
case "enable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = true;
|
||||
player.sendMessage("Enabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
case "disable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = false;
|
||||
player.sendMessage("Disabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "nrp":
|
||||
case "ooc":
|
||||
if (args.length == 0) {
|
||||
return false;
|
||||
} else {
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = false;
|
||||
String message = "";
|
||||
for (String arg : args)
|
||||
message += arg + " ";
|
||||
player.chat(message.substring(0, message.length() - 1));
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = true;
|
||||
}
|
||||
return true;
|
||||
case "skype":
|
||||
// "skype:?chat&blob=Y_5Ob1BEcw0ZlstdUHyf0ENS5n1Xz2Huhx-5b-pB2JyMSRO5QMEALkJuTSuUaAb3-XfWXwCndwhGex_UpXDbyQ";
|
||||
return true;
|
||||
default:
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
}
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("admin")) // 2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); // 2015.08.09.
|
||||
return true; // 2015.08.09.
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("announce")) {
|
||||
if (sender instanceof BlockCommandSender)
|
||||
DoAnnounce(null, args, (BlockCommandSender) sender);
|
||||
else
|
||||
DoAnnounce(null, args, null);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void DoReload(Player player) { // 2015.07.20.
|
||||
try {
|
||||
PluginMain.Console
|
||||
.sendMessage("§6-- Reloading The Button Minecraft plugin...§r");
|
||||
PluginMain.LoadFiles(true); // 2015.08.09.
|
||||
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.
|
||||
}
|
||||
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.
|
||||
}
|
||||
PluginMain.Console.sendMessage("§6-- Reloading done!§r");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
if (player != null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static Player ReloadPlayer; // 2015.08.09.
|
||||
|
||||
private static String DoAdminUsage = "§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin|togglerpshow|toggledebug|savepos|loadpos§r";
|
||||
|
||||
private static void DoAdmin(Player player, String[] args) { // 2015.08.09.
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// args[0] is "admin"
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "reload":
|
||||
ReloadPlayer = player; // 2015.08.09.
|
||||
SendMessage(
|
||||
player,
|
||||
"§bMake sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
break; // <-- 2015.08.10.
|
||||
case "confirm":
|
||||
if (ReloadPlayer == player)
|
||||
DoReload(player); // 2015.08.09.
|
||||
else
|
||||
SendMessage(player,
|
||||
"§cYou need to do /u admin reload first.§r");
|
||||
break;
|
||||
case "save":
|
||||
PluginMain.SaveFiles(); // 2015.08.09.
|
||||
SendMessage(player,
|
||||
"§bSaved files. Now you can edit them and reload if you want.§r");
|
||||
break;
|
||||
case "setflair":
|
||||
DoSetFlair(player, args);
|
||||
break;
|
||||
case "updateplugin": // 2015.08.10.
|
||||
DoUpdatePlugin(player);
|
||||
break;
|
||||
case "togglerpshow":
|
||||
PlayerListener.ShowRPTag = !PlayerListener.ShowRPTag;
|
||||
SendMessage(player, "RP tag showing "
|
||||
+ (PlayerListener.ShowRPTag ? "enabled" : "disabled"));
|
||||
break;
|
||||
case "toggledebug":
|
||||
PlayerListener.DebugMode = !PlayerListener.DebugMode;
|
||||
SendMessage(player, "DebugMode: " + PlayerListener.DebugMode);
|
||||
break;
|
||||
case "savepos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "loadpos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "updatedynmap":
|
||||
DoUpdateDynmap(player, args);
|
||||
default:
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
|
||||
private static void DoPlayerInfo(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "playerinfo"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(args[2]);
|
||||
if (p == null) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
SendMessage(player, "Player name: " + p.PlayerName);
|
||||
SendMessage(player, "User flair: " + p.Flair);
|
||||
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);
|
||||
}
|
||||
|
||||
private static void SendMessage(Player player, String message) { // 2015.08.09.
|
||||
if (player == null)
|
||||
PluginMain.Console.sendMessage(message); // 2015.08.12.
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
private static void DoGetLastError(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "getlasterror"
|
||||
if (PluginMain.LastException != null) {
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException = null;
|
||||
} else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
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");
|
||||
return;
|
||||
}
|
||||
Player p = Bukkit.getPlayer(args[2]);
|
||||
if (p == null) {
|
||||
SendMessage(player, "§cPLayer not found.&r");
|
||||
return;
|
||||
}
|
||||
SetPlayerFlair(player,
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()), args[3]);
|
||||
}
|
||||
|
||||
private static void DoUpdatePlugin(Player player) { // 2015.08.10.
|
||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
||||
System.out.println("Forced updating of Auto-Flair plugin.");
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(
|
||||
"https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
||||
FileUtils.copyURLToFile(url, new File(
|
||||
"plugins/TheButtonAutoFlair.jar"));
|
||||
PluginUpdated = true; // 2015.08.31.
|
||||
SendMessage(player, "Updating done!");
|
||||
} catch (MalformedURLException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoAnnounce(Player player, String[] args,
|
||||
BlockCommandSender commandblock) {
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "add":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce add <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
PluginMain.AnnounceMessages.add(finalmessage);
|
||||
SendMessage(player, "§bAnnouncement added.§r");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce remove <index>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceMessages.remove(Integer.parseInt(args[2]));
|
||||
break;
|
||||
case "settime":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player,
|
||||
"§cUsage: /u announce settime <minutes>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceTime = Integer.parseInt(args[2]) * 60 * 1000;
|
||||
SendMessage(player, "Time set between announce messages");
|
||||
break;
|
||||
case "list":
|
||||
SendMessage(player, "§bList of announce messages:§r");
|
||||
SendMessage(player, "§bFormat: [index] message§r");
|
||||
int i = 0;
|
||||
for (String message : PluginMain.AnnounceMessages)
|
||||
SendMessage(player, "[" + i++ + "] " + message);
|
||||
SendMessage(player,
|
||||
"§bCurrent wait time between announcements: "
|
||||
+ PluginMain.AnnounceTime / 60 / 1000
|
||||
+ " minute(s)§r");
|
||||
break;
|
||||
case "edit":
|
||||
if (commandblock == null) {
|
||||
SendMessage(
|
||||
player,
|
||||
"§cError: This command can only be used from a command block. Use /u announce remove.");
|
||||
break;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
commandblock
|
||||
.sendMessage("§cUsage: /u announce edit <index> <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 3; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§');
|
||||
int index = Integer.parseInt(args[2]);
|
||||
if (index > 100)
|
||||
break;
|
||||
while (PluginMain.AnnounceMessages.size() <= index)
|
||||
PluginMain.AnnounceMessages.add("");
|
||||
PluginMain.AnnounceMessages.set(Integer.parseInt(args[2]),
|
||||
finalmessage1);
|
||||
commandblock.sendMessage("Announcement edited.");
|
||||
break;
|
||||
default:
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoSaveLoadPos(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "savepos|loadpos"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
Player p = null;
|
||||
for (Player pl : PluginMain.GetPlayers()) {
|
||||
if (pl.getName().equals(args[2])) {
|
||||
p = pl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (p == null) {
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer is not online: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (args[1].equalsIgnoreCase("savepos")) {
|
||||
mp.SavedLocation = p.getLocation();
|
||||
} else if (args[1].equalsIgnoreCase("loadpos")) {
|
||||
if (mp.SavedLocation != null)
|
||||
p.teleport(mp.SavedLocation);
|
||||
} else {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// SendMessage(player, "Player " + p.getName() +
|
||||
// " position saved/loaded.");s
|
||||
}
|
||||
|
||||
private static void DoUpdateDynmap(Player player, String[] args) {
|
||||
// args[0] is "admin" - args[1] is "updatedynmap"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin updatedynmap <password>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static ArrayList<String> Quiz = new ArrayList<>();
|
||||
|
||||
private static void DoQuiz(Player player, String[] args,
|
||||
BlockCommandSender commandblock) {
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = "§cUsage: /u quiz add|remove|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "add":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u quiz add <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
Quiz.add(finalmessage);
|
||||
SendMessage(player, "§Quiz question added.§r");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u quiz remove <index>");
|
||||
return;
|
||||
}
|
||||
Quiz.remove(Integer.parseInt(args[2]));
|
||||
break;
|
||||
case "list":
|
||||
SendMessage(player, "§bList of quiz questions:§r");
|
||||
SendMessage(player, "§bFormat: [index] question§r");
|
||||
int i = 0;
|
||||
for (String question : Quiz)
|
||||
SendMessage(player, "[" + i++ + "] " + question);
|
||||
SendMessage(player,
|
||||
"§bCurrent wait time between announcements: "
|
||||
+ PluginMain.AnnounceTime / 60 / 1000
|
||||
+ " minute(s)§r");
|
||||
break;
|
||||
case "edit":
|
||||
if (commandblock == null) {
|
||||
SendMessage(
|
||||
player,
|
||||
"§cError: This command can only be used from a command block. Use /u announce remove.");
|
||||
break;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
commandblock
|
||||
.sendMessage("§cUsage: /u announce edit <index> <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 3; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§');
|
||||
int index = Integer.parseInt(args[2]);
|
||||
if (index > 100)
|
||||
break;
|
||||
while (PluginMain.AnnounceMessages.size() <= index)
|
||||
PluginMain.AnnounceMessages.add("");
|
||||
PluginMain.AnnounceMessages.set(Integer.parseInt(args[2]),
|
||||
finalmessage1);
|
||||
commandblock.sendMessage("Announcement edited.");
|
||||
break;
|
||||
default:
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
name: TheButtonMCPlugin
|
||||
main: tk.sznp.thebuttonautoflair.PluginMain
|
||||
version: 2.0
|
||||
commands:
|
||||
u:
|
||||
description: Auto-flair system. Accept or ignore flair.
|
||||
usage: "&cUsage: /u accept|ignore|opme&r"
|
||||
nrp:
|
||||
description: Send message in Out-of-Character
|
||||
usage: "&cUsage: /nrp <message>&r"
|
||||
ooc:
|
||||
description: Send message in Out-of-Character
|
||||
usage: "&cUsage: /ooc <message>&r"
|
||||
author: NorbiPeti
|
||||
depend: [Essentials, Towny]
|
|
@ -1,224 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if(args.length<1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||
if(p.Flair==null)
|
||||
{
|
||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||
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.
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
||||
p.AcceptedFlair=true; //2015.08.08.
|
||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
break;
|
||||
}
|
||||
case "ignore":
|
||||
{
|
||||
if(p.AcceptedFlair)
|
||||
p.AcceptedFlair=false; //2015.08.08.
|
||||
if(!p.IgnoredFlair)
|
||||
{
|
||||
p.IgnoredFlair=true;
|
||||
String flair=p.Flair; //2015.08.08.
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already ignored this request.§r");
|
||||
break;
|
||||
}
|
||||
/*case "reload": //2015.07.20.
|
||||
DoReload(player);
|
||||
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;
|
||||
}
|
||||
p.Flair="§7(non-pr.)§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.§r");
|
||||
break;
|
||||
}
|
||||
p.Flair="§r(can't press)§r";
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*if(args[0].toLowerCase()=="reload")
|
||||
DoReload(null); //2015.07.20.*/
|
||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); //2015.08.09.
|
||||
return true; //2015.08.09.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static void DoReload(Player player)
|
||||
{ //2015.07.20.
|
||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
//{
|
||||
try
|
||||
{
|
||||
File file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
PluginMain.LoadFiles(true); //2015.08.09.
|
||||
for(Player p : PluginMain.GetPlayers())
|
||||
{
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
||||
if(mp.Flair!=null)
|
||||
{
|
||||
String flair=mp.Flair;
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
||||
}
|
||||
String msg="§6Note: 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.
|
||||
}
|
||||
//String msg="§6Reloaded config file.§r";
|
||||
//SendMessage(player, msg); //2015.08.09.
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
if(player!=null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
//}
|
||||
//else
|
||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static Player ReloadPlayer; //2015.08.09.
|
||||
private static void DoAdmin(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
{
|
||||
//System.out.println("Args length: " + args.length);
|
||||
if(args.length==1)
|
||||
{
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
//args[0] is "admin"
|
||||
switch(args[1].toLowerCase())
|
||||
{
|
||||
case "reload":
|
||||
ReloadPlayer=player; //2015.08.09.
|
||||
SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.");
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
case "confirm":
|
||||
if(ReloadPlayer.equals(player))
|
||||
DoReload(player); //2015.08.09.
|
||||
else
|
||||
SendMessage(player, "§cYou need to do /u admin reload first.§r");
|
||||
break;
|
||||
default:
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoPlayerInfo(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "playerinfo"
|
||||
if(args.length==2)
|
||||
{
|
||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||
{
|
||||
String message="§cPlayer not found: "+args[2]+"§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
SendMessage(player, "Player name: "+p.PlayerName);
|
||||
SendMessage(player, "User flair: "+p.Flair);
|
||||
SendMessage(player, "Username: "+p.UserName);
|
||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
||||
}
|
||||
private static void SendMessage(Player player, String message)
|
||||
{ //2015.08.09.
|
||||
if(player==null)
|
||||
System.out.println(message);
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
private static void DoGetLastError(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "getlasterror"
|
||||
if(PluginMain.LastException!=null)
|
||||
{
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException=null;
|
||||
}
|
||||
else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
}
|
|
@ -1,297 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if(args.length<1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||
if(!p.CommentedOnReddit && !args[0].toLowerCase().equals("admin"))
|
||||
{
|
||||
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"))
|
||||
{ //2015.08.10.
|
||||
player.sendMessage("Sorry, but your flair isn't recorded. Please ask a mod to set it for you.");
|
||||
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.
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
p.AcceptedFlair=true; //2015.08.08.
|
||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
break;
|
||||
}
|
||||
case "ignore":
|
||||
{
|
||||
if(p.AcceptedFlair)
|
||||
p.AcceptedFlair=false; //2015.08.08.
|
||||
if(!p.IgnoredFlair)
|
||||
{
|
||||
p.IgnoredFlair=true;
|
||||
//String flair=p.Flair; //2015.08.08.
|
||||
//PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already ignored this request.§r");
|
||||
break;
|
||||
}
|
||||
/*case "reload": //2015.07.20.
|
||||
DoReload(player);
|
||||
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
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*if(args[0].toLowerCase()=="reload")
|
||||
DoReload(null); //2015.07.20.*/
|
||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); //2015.08.09.
|
||||
return true; //2015.08.09.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static void DoReload(Player player)
|
||||
{ //2015.07.20.
|
||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
//{
|
||||
try
|
||||
{
|
||||
File file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
PluginMain.LoadFiles(true); //2015.08.09.
|
||||
for(Player p : PluginMain.GetPlayers())
|
||||
{
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
||||
//if(mp.Flair!=null)
|
||||
if(mp.CommentedOnReddit)
|
||||
{
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
||||
}
|
||||
String msg="§6Note: 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.
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
if(player!=null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
//}
|
||||
//else
|
||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static Player ReloadPlayer; //2015.08.09.
|
||||
private static void DoAdmin(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
if(player==null || player.isOp() || player.getName().equals("NorbiPeti"))
|
||||
{
|
||||
//System.out.println("Args length: " + args.length);
|
||||
if(args.length==1)
|
||||
{
|
||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
//args[0] is "admin"
|
||||
switch(args[1].toLowerCase())
|
||||
{
|
||||
case "reload":
|
||||
ReloadPlayer=player; //2015.08.09.
|
||||
SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
break; //<-- 2015.08.10.
|
||||
case "confirm":
|
||||
if(ReloadPlayer==player)
|
||||
DoReload(player); //2015.08.09.
|
||||
else
|
||||
SendMessage(player, "§cYou need to do /u admin reload first.§r");
|
||||
break;
|
||||
case "save":
|
||||
PluginMain.SaveFiles(); //2015.08.09.
|
||||
SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r");
|
||||
break;
|
||||
case "setflair":
|
||||
DoSetFlair(player, args);
|
||||
break;
|
||||
case "updateplugin": //2015.08.10.
|
||||
DoUpdatePlugin(player);
|
||||
break;
|
||||
default:
|
||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoPlayerInfo(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "playerinfo"
|
||||
if(args.length==2)
|
||||
{
|
||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||
{
|
||||
String message="§cPlayer not found: "+args[2]+"§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
SendMessage(player, "Player name: "+p.PlayerName);
|
||||
SendMessage(player, "User flair: "+p.Flair);
|
||||
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);
|
||||
}
|
||||
private static void SendMessage(Player player, String message)
|
||||
{ //2015.08.09.
|
||||
if(player==null)
|
||||
System.out.println(message);
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
private static void DoGetLastError(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "getlasterror"
|
||||
if(PluginMain.LastException!=null)
|
||||
{
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException=null;
|
||||
}
|
||||
else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
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
|
||||
if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName))
|
||||
{
|
||||
SendMessage(player, "§cError removing previous custom flair!§r");
|
||||
return;
|
||||
}
|
||||
File file=new File("customflairs.txt");
|
||||
try {
|
||||
BufferedWriter bw;
|
||||
bw = new BufferedWriter(new FileWriter(file, true));
|
||||
bw.write(targetplayer.PlayerName+targetplayer.Flair+"\n");
|
||||
bw.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§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;
|
||||
}
|
||||
SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]);
|
||||
}
|
||||
private static void DoUpdatePlugin(Player player)
|
||||
{ //2015.08.10.
|
||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
||||
System.out.println("Forced updating of Auto-Flair plugin.");
|
||||
URL url;
|
||||
try {
|
||||
url = new URL("https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
||||
FileUtils.copyURLToFile(url, new File("plugins/TheButtonAutoFlair.jar"));
|
||||
SendMessage(player, "Updating done!");
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,220 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if(args.length<1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||
if(p.Flair==null)
|
||||
{
|
||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||
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.
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
||||
p.AcceptedFlair=true; //2015.08.08.
|
||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
break;
|
||||
}
|
||||
case "ignore":
|
||||
{
|
||||
if(p.AcceptedFlair)
|
||||
p.AcceptedFlair=false; //2015.08.08.
|
||||
if(!p.IgnoredFlair)
|
||||
{
|
||||
p.IgnoredFlair=true;
|
||||
String flair=p.Flair; //2015.08.08.
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already ignored this request.§r");
|
||||
break;
|
||||
}
|
||||
/*case "reload": //2015.07.20.
|
||||
DoReload(player);
|
||||
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;
|
||||
}
|
||||
p.Flair="§7(non-pr.)§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.§r");
|
||||
break;
|
||||
}
|
||||
p.Flair="§r(can't press)§r";
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*if(args[0].toLowerCase()=="reload")
|
||||
DoReload(null); //2015.07.20.*/
|
||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); //2015.08.09.
|
||||
return true; //2015.08.09.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static void DoReload(Player player)
|
||||
{ //2015.07.20.
|
||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
//{
|
||||
try
|
||||
{
|
||||
File file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
PluginMain.LoadFiles(true); //2015.08.09.
|
||||
for(Player p : PluginMain.GetPlayers())
|
||||
{
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
||||
if(mp.Flair!=null)
|
||||
{
|
||||
String flair=mp.Flair;
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
||||
}
|
||||
String msg="§6Note: 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.
|
||||
}
|
||||
//String msg="§6Reloaded config file.§r";
|
||||
//SendMessage(player, msg); //2015.08.09.
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
if(player!=null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
//}
|
||||
//else
|
||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static Player ReloadPlayer; //2015.08.09.
|
||||
private static void DoAdmin(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
{
|
||||
//System.out.println("Args length: " + args.length);
|
||||
if(args.length==1)
|
||||
{
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
//args[0] is "admin"
|
||||
switch(args[1].toLowerCase())
|
||||
{
|
||||
case "reload":
|
||||
SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.");
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
case "confirm":
|
||||
DoReload(player); //2015.08.09.
|
||||
break;
|
||||
default:
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoPlayerInfo(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "playerinfo"
|
||||
if(args.length==2)
|
||||
{
|
||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||
{
|
||||
String message="§cPlayer not found: "+args[2]+"§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
SendMessage(player, "Player name: "+p.PlayerName);
|
||||
SendMessage(player, "User flair: "+p.Flair);
|
||||
SendMessage(player, "Username: "+p.UserName);
|
||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
||||
}
|
||||
private static void SendMessage(Player player, String message)
|
||||
{ //2015.08.09.
|
||||
if(player==null)
|
||||
System.out.println(message);
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
private static void DoGetLastError(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "getlasterror"
|
||||
if(PluginMain.LastException!=null)
|
||||
{
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException=null;
|
||||
}
|
||||
else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class MaybeOfflinePlayer
|
||||
{ //2015.08.08.
|
||||
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 FlairClassType FlairType; //2015.08.09.
|
||||
public static HashMap<String, MaybeOfflinePlayer> AllPlayers=new HashMap<>(); //2015.08.08.
|
||||
public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername)
|
||||
{
|
||||
if(!AllPlayers.containsKey(playername))
|
||||
{
|
||||
MaybeOfflinePlayer player=new MaybeOfflinePlayer();
|
||||
player.PlayerName=playername;
|
||||
AllPlayers.put(playername, player);
|
||||
return player;
|
||||
}
|
||||
return AllPlayers.get(playername);
|
||||
}
|
||||
/*public enum FlairClassType
|
||||
{ //2015.08.09.
|
||||
NonPresser,
|
||||
CantPress,
|
||||
Undecided
|
||||
}*/
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
||||
|
||||
public class PlayerListener implements Listener
|
||||
{ //2015.07.16.
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
Player p=event.getPlayer();
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
||||
if(mp.CommentedOnReddit)
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
||||
else
|
||||
{ //2015.07.20.
|
||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your §6Minecraft name to \"},{\"text\":\"[this thread.]\",\"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§r\"}]}}}]";
|
||||
sendRawMessage(p, json);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event)
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
||||
{
|
||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
||||
String flair=player.Flair; //2015.08.08.
|
||||
if(player.IgnoredFlair)
|
||||
flair="";
|
||||
String message=event.getMessage(); //2015.08.08.
|
||||
for(Player p : PluginMain.GetPlayers())
|
||||
{ //2015.08.12.
|
||||
message = message.replaceAll(p.getName(), "§6"+p.getName()+"§r");
|
||||
}
|
||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
||||
}
|
||||
|
||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
||||
public static void sendRawMessage(Player player, String message)
|
||||
{
|
||||
try {
|
||||
System.out.println("1");
|
||||
Object handle = Reflection.getHandle(player);
|
||||
System.out.println("2");
|
||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
||||
System.out.println("3");
|
||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
||||
System.out.println("4");
|
||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
||||
System.out.println("5");
|
||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
||||
System.out.println("6");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,380 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
|
||||
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/
|
||||
private static PluginMain Instance;
|
||||
// Fired when plugin is first enabled
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
this.getCommand("u").setExecutor(new Commands());
|
||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||
Instance=this; //2015.08.08.
|
||||
LoadFiles(false); //2015.08.09.
|
||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||
Thread t=new Thread(r);
|
||||
t.start();
|
||||
}
|
||||
Boolean stop=false;
|
||||
// Fired when plugin is disabled
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
try
|
||||
{
|
||||
FileWriter fw;
|
||||
fw = new FileWriter("flairsaccepted.txt");
|
||||
fw.close();
|
||||
fw = new FileWriter("flairsignored.txt");
|
||||
fw.close();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.AcceptedFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
file=new File("flairsignored.txt");
|
||||
bw = new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.IgnoredFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
stop=true;
|
||||
}
|
||||
|
||||
public void ThreadMethod() //<-- 2015.07.16.
|
||||
{
|
||||
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();
|
||||
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();
|
||||
if(HasIGFlair(ign))
|
||||
continue;
|
||||
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";
|
||||
else
|
||||
flair = "non-presser";
|
||||
String flairclass;
|
||||
if(flairdata.length>2)
|
||||
flairclass = flairdata[2];
|
||||
else
|
||||
flairclass="unknown";
|
||||
SetFlair(ign, flair, flairclass, author);
|
||||
}
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Exception LastException; //2015.08.09.
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||
public Boolean HasIGFlair(String playername)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
return p.Flair!=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
String finalflair;
|
||||
p.FlairDecided=true;
|
||||
switch(flairclass)
|
||||
{
|
||||
case "press-1":
|
||||
finalflair="§c("+text+")§r";
|
||||
break;
|
||||
case "press-2":
|
||||
finalflair="§6("+text+")§r";
|
||||
break;
|
||||
case "press-3":
|
||||
finalflair="§e("+text+")§r";
|
||||
break;
|
||||
case "press-4":
|
||||
finalflair="§a("+text+")§r";
|
||||
break;
|
||||
case "press-5":
|
||||
finalflair="§9("+text+")§r";
|
||||
break;
|
||||
case "press-6":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "no-press":
|
||||
finalflair="§7(non-pr.)§r";
|
||||
break;
|
||||
case "cheater":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "cant-press": //2015.08.08.
|
||||
finalflair="§r(can't press)§r";
|
||||
break;
|
||||
case "undecided": //2015.08.09.
|
||||
p.FlairDecided=false;
|
||||
finalflair="";
|
||||
break;
|
||||
default:
|
||||
finalflair="";
|
||||
break;
|
||||
}
|
||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||
return;
|
||||
p.Flair=finalflair; //2015.08.08.
|
||||
p.UserName=username; //2015.08.08.
|
||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||
{
|
||||
if(player.getName().equals(playername))
|
||||
{
|
||||
//AppendPlayerDisplayFlair(player, username, finalflair);
|
||||
AppendPlayerDisplayFlair(p, player);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String GetFlair(Player player)
|
||||
{ //2015.07.16.
|
||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||
return flair==null ? "" : flair;
|
||||
}
|
||||
|
||||
//public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||
public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09.
|
||||
{
|
||||
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair)
|
||||
return;
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair)
|
||||
{
|
||||
AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20.
|
||||
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");
|
||||
}
|
||||
|
||||
private static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||
String[] colors = color.substring(1).split("§");
|
||||
String displayname=player.getName(); //2015.08.08.
|
||||
ArrayList<Integer> Positions=new ArrayList<>();
|
||||
for(int i=0; i<displayname.length(); i++) {
|
||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||
Positions.add(i);
|
||||
}
|
||||
}
|
||||
String finalname=""; //TODO
|
||||
if(Positions.size()>=colors.length)
|
||||
{
|
||||
int x=0;
|
||||
for(int i=0; i<Positions.size(); i++)
|
||||
{
|
||||
int pos=Positions.get(i);
|
||||
int nextpos;
|
||||
if(i!=Positions.size()-1)
|
||||
nextpos=Positions.get(i+1);
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Positions.clear();
|
||||
int unit=displayname.length()/colors.length;
|
||||
int x=0;
|
||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||
{
|
||||
int pos=i;
|
||||
int nextpos;
|
||||
if(i<displayname.length()-unit-unit)
|
||||
nextpos=i+unit;
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||
}
|
||||
|
||||
public static String GetColorForTown(String townname)
|
||||
{ //2015.07.20.
|
||||
if(TownColors.containsKey(townname))
|
||||
return TownColors.get(townname);
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String GetPlayerTown(Player player)
|
||||
{ //2015.07.20.
|
||||
try {
|
||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||
return town.getName();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public static Collection<? extends Player> GetPlayers()
|
||||
{
|
||||
return Instance.getServer().getOnlinePlayers();
|
||||
}
|
||||
|
||||
public static void LoadFiles(boolean reload) //<-- 2015.08.09.
|
||||
{
|
||||
if(reload)
|
||||
{ //2015.08.09.
|
||||
System.out.println("Auto-flair plugin cleanup for reloading...");
|
||||
MaybeOfflinePlayer.AllPlayers.clear();
|
||||
TownColors.clear();
|
||||
}
|
||||
System.out.println("Loading files for auto-flair plugin..."); //2015.08.09.
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
//System.out.println("Name: " + name);
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("flairsignored.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while((line=br.readLine())!=null)
|
||||
{
|
||||
String[] s=line.split(" ");
|
||||
TownColors.put(s[0], s[1]);
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
//throw new IOException("Test"); //2015.08.09.
|
||||
System.out.println("Auto-flair plugin loaded files!");
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
public static void SaveFiles() //<-- 2015.08.09.
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
||||
|
||||
public class PlayerListener implements Listener
|
||||
{ //2015.07.16.
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
Player p=event.getPlayer();
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
||||
if(mp.CommentedOnReddit)
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
||||
else
|
||||
{ //2015.07.20.
|
||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your §6Minecraft name to \"},{\"text\":\"[this thread.]\",\"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§r\"}]}}}]";
|
||||
sendRawMessage(p, json);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event)
|
||||
{
|
||||
}
|
||||
|
||||
public static String NotificationSound; //2015.08.14.
|
||||
public static float NotificationPitch; //2015.08.14.
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
||||
{
|
||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
||||
String flair=player.Flair; //2015.08.08.
|
||||
if(player.IgnoredFlair)
|
||||
flair="";
|
||||
String message=event.getMessage(); //2015.08.08.
|
||||
for(Player p : PluginMain.GetPlayers())
|
||||
{ //2015.08.12.
|
||||
String color=""; //2015.08.17.
|
||||
if(message.contains(p.getName()))
|
||||
{
|
||||
if(NotificationSound==null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); //2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f, NotificationPitch); //2015.08.14.
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.17.
|
||||
color=mp.Flair.substring(0, 2);
|
||||
}
|
||||
message = message.replaceAll(p.getName(), color+p.getName()+"§r");
|
||||
}
|
||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
||||
}
|
||||
|
||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
||||
public static void sendRawMessage(Player player, String message)
|
||||
{
|
||||
try {
|
||||
Object handle = Reflection.getHandle(player);
|
||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,219 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if(args.length<1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||
if(p.Flair==null)
|
||||
{
|
||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||
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.
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
||||
p.AcceptedFlair=true; //2015.08.08.
|
||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
break;
|
||||
}
|
||||
case "ignore":
|
||||
{
|
||||
if(p.AcceptedFlair)
|
||||
p.AcceptedFlair=false; //2015.08.08.
|
||||
if(!p.IgnoredFlair)
|
||||
{
|
||||
p.IgnoredFlair=true;
|
||||
String flair=p.Flair; //2015.08.08.
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already ignored this request.§r");
|
||||
break;
|
||||
}
|
||||
/*case "reload": //2015.07.20.
|
||||
DoReload(player);
|
||||
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;
|
||||
}
|
||||
p.Flair="§7(non-pr.)§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.§r");
|
||||
break;
|
||||
}
|
||||
p.Flair="§r(can't press)§r";
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*if(args[0].toLowerCase()=="reload")
|
||||
DoReload(null); //2015.07.20.*/
|
||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); //2015.08.09.
|
||||
return true; //2015.08.09.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static void DoReload(Player player)
|
||||
{ //2015.07.20.
|
||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
//{
|
||||
try
|
||||
{
|
||||
File file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
PluginMain.LoadFiles(true); //2015.08.09.
|
||||
for(Player p : PluginMain.GetPlayers())
|
||||
{
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
||||
if(mp.Flair!=null)
|
||||
{
|
||||
String flair=mp.Flair;
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
||||
}
|
||||
String msg="§6Note: 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.
|
||||
}
|
||||
//String msg="§6Reloaded config file.§r";
|
||||
//SendMessage(player, msg); //2015.08.09.
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
if(player!=null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
//}
|
||||
//else
|
||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoAdmin(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
{
|
||||
//System.out.println("Args length: " + args.length);
|
||||
if(args.length==1)
|
||||
{
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
//args[0] is "admin"
|
||||
switch(args[1].toLowerCase())
|
||||
{
|
||||
case "reload":
|
||||
DoReload(player);
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
case "confirm":
|
||||
DoReload(player); //2015.08.09.
|
||||
break;
|
||||
default:
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoPlayerInfo(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "playerinfo"
|
||||
if(args.length==2)
|
||||
{
|
||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||
{
|
||||
String message="§cPlayer not found: "+args[2]+"§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
SendMessage(player, "Player name: "+p.PlayerName);
|
||||
SendMessage(player, "User flair: "+p.Flair);
|
||||
SendMessage(player, "Username: "+p.UserName);
|
||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
||||
}
|
||||
private static void SendMessage(Player player, String message)
|
||||
{ //2015.08.09.
|
||||
if(player==null)
|
||||
System.out.println(message);
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
private static void DoGetLastError(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "getlasterror"
|
||||
if(PluginMain.LastException!=null)
|
||||
{
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException=null;
|
||||
}
|
||||
else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
||||
|
||||
public class PlayerListener implements Listener
|
||||
{ //2015.07.16.
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
Player p=event.getPlayer();
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
||||
if(mp.CommentedOnReddit)
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
||||
else
|
||||
{ //2015.07.20.
|
||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your §6Minecraft name to \"},{\"text\":\"[this thread.]\",\"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§r\"}]}}}]";
|
||||
sendRawMessage(p, json);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event)
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
||||
{
|
||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
||||
String flair=player.Flair; //2015.08.08.
|
||||
if(player.IgnoredFlair)
|
||||
flair="";
|
||||
String message=event.getMessage(); //2015.08.08.
|
||||
for(Player p : PluginMain.GetPlayers())
|
||||
{ //2015.08.12.
|
||||
message.replaceAll(p.getName(), )
|
||||
}
|
||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
||||
}
|
||||
|
||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
||||
public static void sendRawMessage(Player player, String message)
|
||||
{
|
||||
try {
|
||||
System.out.println("1");
|
||||
Object handle = Reflection.getHandle(player);
|
||||
System.out.println("2");
|
||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
||||
System.out.println("3");
|
||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
||||
System.out.println("4");
|
||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
||||
System.out.println("5");
|
||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
||||
System.out.println("6");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,364 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import tk.sznp.thebuttonautoflair.MaybeOfflinePlayer.FlairClassType;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
|
||||
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/
|
||||
private static PluginMain Instance;
|
||||
// Fired when plugin is first enabled
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
this.getCommand("u").setExecutor(new Commands());
|
||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||
Instance=this; //2015.08.08.
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
//System.out.println("Name: " + name);
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("flairsignored.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while((line=br.readLine())!=null)
|
||||
{
|
||||
String[] s=line.split(" ");
|
||||
TownColors.put(s[0], s[1]);
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
//throw new IOException("Test"); //2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||
Thread t=new Thread(r);
|
||||
t.start();
|
||||
}
|
||||
Boolean stop=false;
|
||||
// Fired when plugin is disabled
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
try
|
||||
{
|
||||
FileWriter fw;
|
||||
fw = new FileWriter("flairsaccepted.txt");
|
||||
fw.close();
|
||||
fw = new FileWriter("flairsignored.txt");
|
||||
fw.close();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.AcceptedFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
file=new File("flairsignored.txt");
|
||||
bw = new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.IgnoredFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
stop=true;
|
||||
}
|
||||
|
||||
public void ThreadMethod() //<-- 2015.07.16.
|
||||
{
|
||||
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();
|
||||
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();
|
||||
if(HasIGFlair(ign))
|
||||
continue;
|
||||
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";
|
||||
else
|
||||
flair = "non-presser";
|
||||
String flairclass;
|
||||
if(flairdata.length>2)
|
||||
flairclass = flairdata[2];
|
||||
else
|
||||
flairclass="unknown";
|
||||
SetFlair(ign, flair, flairclass, author);
|
||||
}
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Exception LastException; //2015.08.09.
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||
public Boolean HasIGFlair(String playername)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
return p.Flair!=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
String finalflair;
|
||||
p.FlairDecided=true;
|
||||
switch(flairclass)
|
||||
{
|
||||
case "press-1":
|
||||
finalflair="§c("+text+")§r";
|
||||
break;
|
||||
case "press-2":
|
||||
finalflair="§6("+text+")§r";
|
||||
break;
|
||||
case "press-3":
|
||||
finalflair="§e("+text+")§r";
|
||||
break;
|
||||
case "press-4":
|
||||
finalflair="§a("+text+")§r";
|
||||
break;
|
||||
case "press-5":
|
||||
finalflair="§9("+text+")§r";
|
||||
break;
|
||||
case "press-6":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "no-press":
|
||||
finalflair="§7(non-pr.)§r";
|
||||
break;
|
||||
case "cheater":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "cant-press": //2015.08.08.
|
||||
finalflair="§r(can't press)§r";
|
||||
break;
|
||||
case "undecided": //2015.08.09.
|
||||
p.FlairDecided=false;
|
||||
finalflair="";
|
||||
break;
|
||||
default:
|
||||
finalflair="";
|
||||
break;
|
||||
}
|
||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||
return;
|
||||
p.Flair=finalflair; //2015.08.08.
|
||||
p.UserName=username; //2015.08.08.
|
||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||
{
|
||||
if(player.getName().equals(playername))
|
||||
{
|
||||
AppendPlayerDisplayFlair(player, username, finalflair);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String GetFlair(Player player)
|
||||
{ //2015.07.16.
|
||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||
return flair==null ? "" : flair;
|
||||
}
|
||||
|
||||
//public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||
public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09.
|
||||
{
|
||||
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair)
|
||||
return;
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair)
|
||||
{
|
||||
AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20.
|
||||
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
|
||||
player.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r");
|
||||
}
|
||||
|
||||
private static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||
String[] colors = color.substring(1).split("§");
|
||||
String displayname=player.getName(); //2015.08.08.
|
||||
ArrayList<Integer> Positions=new ArrayList<>();
|
||||
for(int i=0; i<displayname.length(); i++) {
|
||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||
Positions.add(i);
|
||||
}
|
||||
}
|
||||
String finalname=""; //TODO
|
||||
if(Positions.size()>=colors.length)
|
||||
{
|
||||
int x=0;
|
||||
for(int i=0; i<Positions.size(); i++)
|
||||
{
|
||||
int pos=Positions.get(i);
|
||||
int nextpos;
|
||||
if(i!=Positions.size()-1)
|
||||
nextpos=Positions.get(i+1);
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Positions.clear();
|
||||
int unit=displayname.length()/colors.length;
|
||||
int x=0;
|
||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||
{
|
||||
int pos=i;
|
||||
int nextpos;
|
||||
if(i<displayname.length()-unit-unit)
|
||||
nextpos=i+unit;
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||
}
|
||||
|
||||
public static String GetColorForTown(String townname)
|
||||
{ //2015.07.20.
|
||||
if(TownColors.containsKey(townname))
|
||||
return TownColors.get(townname);
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String GetPlayerTown(Player player)
|
||||
{ //2015.07.20.
|
||||
try {
|
||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||
return town.getName();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public static Collection<? extends Player> GetPlayers()
|
||||
{
|
||||
return Instance.getServer().getOnlinePlayers();
|
||||
}
|
||||
}
|
|
@ -1,328 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerChatTabCompleteEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import au.com.mineauz.minigames.Minigames;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerListener implements Listener { // 2015.07.16.
|
||||
public static HashMap<String, UUID> nicknames = new HashMap<>();
|
||||
|
||||
public static boolean Enable = false; // 2015.08.29.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p
|
||||
.getUniqueId());
|
||||
mp.PlayerName = p.getName(); // 2015.10.17. 0:58
|
||||
if (mp.CommentedOnReddit)
|
||||
// if (false)
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); // 2015.08.09.
|
||||
else { // 2015.07.20.
|
||||
Timer timer = new Timer();
|
||||
PlayerJoinTimerTask tt = new PlayerJoinTimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!mp.IgnoredFlair) {
|
||||
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,
|
||||
"tellraw " + mp.PlayerName + " " + json);
|
||||
json = "[\"\",{\"text\":\"If you don't want the flair, type /u ignore to prevent this message after next login.\",\"color\":\"aqua\"}]";
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Console,
|
||||
"tellraw " + mp.PlayerName + " " + json);
|
||||
}
|
||||
}
|
||||
};
|
||||
tt.mp = mp;
|
||||
timer.schedule(tt, 15 * 1000);
|
||||
}
|
||||
|
||||
/* NICKNAME LOGIC */
|
||||
|
||||
UUID id = p.getUniqueId();
|
||||
|
||||
File f = new File("plugins/Essentials/userdata/" + id + ".yml");
|
||||
if (f.exists()) {
|
||||
YamlConfiguration yc = new YamlConfiguration();
|
||||
try {
|
||||
yc.load(f);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String nickname = yc.getString("nickname");
|
||||
if (nickname != null) {
|
||||
nicknames.put(nickname, id);
|
||||
|
||||
if (Enable) {
|
||||
if (!p.getName().equals("NorbiPeti")) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.chat("Hey, " + nickname + "!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mp.RPMode = true; // 2015.08.25.
|
||||
|
||||
if (p.getName().equals("FigyTuna") && Commands.PluginUpdated)
|
||||
p.sendMessage("§bThe The Button MC plugin got updated. Please restart the server. :P§r");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
String deletenick = null;
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
UUID uuid = nicknames.get(nickname);
|
||||
if (event.getPlayer().getUniqueId().equals(uuid)) {
|
||||
deletenick = nickname;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (deletenick != null)
|
||||
nicknames.remove(deletenick);
|
||||
}
|
||||
|
||||
public static String NotificationSound; // 2015.08.14.
|
||||
public static double NotificationPitch; // 2015.08.14.
|
||||
|
||||
public static boolean ShowRPTag = false; // 2015.08.31.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.GetFromName(event
|
||||
.getPlayer().getName());
|
||||
String flair = player.Flair; // 2015.08.08.
|
||||
if (player.IgnoredFlair)
|
||||
flair = "";
|
||||
String message = event.getMessage(); // 2015.08.08.
|
||||
for (Player p : PluginMain.GetPlayers()) { // 2015.08.12.
|
||||
String color = ""; // 2015.08.17.
|
||||
if (message.contains(p.getName())) {
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(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);
|
||||
}
|
||||
|
||||
message = message.replaceAll(p.getName(), color + p.getName()
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
for (String n : nicknames.keySet()) {
|
||||
Player p = null;
|
||||
String nwithoutformatting = new String(n);
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (message.contains(nwithoutformatting)) {
|
||||
p = Bukkit.getPlayer(nicknames.get(n));
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(float) NotificationPitch); // 2015.08.14.
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()); // 2015.08.17.
|
||||
}
|
||||
if (p != null) {
|
||||
message = message.replaceAll(nwithoutformatting, n
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
}
|
||||
|
||||
event.setMessage(message); // 2015.09.05.
|
||||
|
||||
event.setFormat(event
|
||||
.getFormat()
|
||||
.replace(
|
||||
"{rptag}",
|
||||
(player.RPMode ? (ShowRPTag ? "§2[RP]§r" : "")
|
||||
: "§8[OOC]§r"))
|
||||
.replace("{buttonflair}", flair)
|
||||
.replace(
|
||||
"{isitwilds}",
|
||||
(event.getPlayer().getWorld().getName()
|
||||
.equalsIgnoreCase("wilds") ? "[PVP]" : ""))); // 2015.09.04.
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTabComplete(PlayerChatTabCompleteEvent e) {
|
||||
String name = e.getLastToken();
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
String nwithoutformatting = nickname;
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (nwithoutformatting.startsWith(name)
|
||||
&& !nwithoutformatting.equals(Bukkit.getPlayer(
|
||||
nicknames.get(nickname)).getName()))
|
||||
e.getTabCompletions().add(nwithoutformatting);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean DebugMode = false;
|
||||
|
||||
public void SendForDebug(String message) {
|
||||
if (DebugMode) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.sendMessage("[DEBUG] " + message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean ActiveF = false;
|
||||
private int FCount = 0;
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMessage(AsyncPlayerChatEvent e) {
|
||||
if (e.getMessage().equalsIgnoreCase("F")) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(e
|
||||
.getPlayer().getName());
|
||||
if (!mp.PressedF && ActiveF) {
|
||||
FCount++;
|
||||
mp.PressedF = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (e.getMessage().startsWith(">"))
|
||||
e.setMessage("§2" + e.getMessage());
|
||||
|
||||
/*
|
||||
* Channel c = ((Chat) Bukkit.getPluginManager().getPlugin("TownyChat"))
|
||||
* .getChannelsHandler().getActiveChannel(e.getPlayer(),
|
||||
* channelTypes.GLOBAL);
|
||||
*/
|
||||
/*
|
||||
* List<String> modes = ((Chat) Bukkit.getPluginManager().getPlugin(
|
||||
* "TownyChat")).getTowny().getPlayerMode(e.getPlayer()); if
|
||||
* (modes.size() == 0 || modes.contains("g")) {
|
||||
*/
|
||||
if (e.getFormat().contains("[g]")) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("tellraw @a [\"\"");
|
||||
sb.append(",{\"text\":\"Hashtags:\"}");
|
||||
int index = -1;
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
while ((index = e.getMessage().indexOf("#", index + 1)) != -1) {
|
||||
int index2 = e.getMessage().indexOf(" ", index + 1);
|
||||
if (index2 == -1)
|
||||
index2 = e.getMessage().length();
|
||||
int index3 = e.getMessage().indexOf("#", index + 1);
|
||||
if (index3 != -1 && index3 < index2) // A # occurs before a
|
||||
// space
|
||||
index2 = index3;
|
||||
String original = e.getMessage().substring(index, index2);
|
||||
list.add(original);
|
||||
sb.append(",{\"text\":\" \"}");
|
||||
sb.append(",{\"text\":\"");
|
||||
sb.append(original);
|
||||
sb.append("\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://twitter.com/hashtag/");
|
||||
sb.append(original.substring(1));
|
||||
sb.append("\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open on Twitter\",\"color\":\"blue\"}]}}}");
|
||||
}
|
||||
for (String original : list)
|
||||
e.setMessage(e.getMessage().replace(
|
||||
original,
|
||||
"§9"
|
||||
+ original
|
||||
+ (e.getMessage().startsWith("§2>") ? "§2"
|
||||
: "§r")));
|
||||
/*
|
||||
* for (String original : list)
|
||||
* System.out.println(e.getMessage().replace( original, "§9" +
|
||||
* original + (e.getMessage().startsWith("§2>") ? "§2" : "§r")));
|
||||
*/
|
||||
|
||||
sb.append("]");
|
||||
|
||||
if (list.size() > 0)
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Instance.getServer().getConsoleSender(),
|
||||
sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private Timer Ftimer;
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDeath(PlayerDeathEvent e) {
|
||||
if (!Minigames.plugin.pdata.getMinigamePlayer(e.getEntity())
|
||||
.isInMinigame() && new Random().nextBoolean()) {
|
||||
if (Ftimer != null)
|
||||
Ftimer.cancel();
|
||||
ActiveF = true;
|
||||
FCount = 0;
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(p
|
||||
.getName());
|
||||
mp.PressedF = false;
|
||||
p.sendMessage("§bPress F to pay respects.§r");
|
||||
}
|
||||
Ftimer = new Timer();
|
||||
TimerTask tt = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (ActiveF) {
|
||||
ActiveF = false;
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
p.sendMessage("§b" + FCount + " "
|
||||
+ (FCount == 1 ? "person" : "people")
|
||||
+ " paid their respects.§r");
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Ftimer.schedule(tt, 15 * 1000);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
||||
|
||||
public class PlayerListener implements Listener
|
||||
{ //2015.07.16.
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
Player p=event.getPlayer();
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
||||
if(mp.CommentedOnReddit)
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
||||
else
|
||||
{ //2015.07.20.
|
||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your §6Minecraft name to \"},{\"text\":\"[this thread.]\",\"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§r\"}]}}}]";
|
||||
sendRawMessage(p, json);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event)
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
||||
{
|
||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
||||
String flair=player.Flair; //2015.08.08.
|
||||
if(player.IgnoredFlair)
|
||||
flair="";
|
||||
String message=event.getMessage(); //2015.08.08.
|
||||
for(Player p : PluginMain.GetPlayers())
|
||||
{ //2015.08.12.
|
||||
if(message.contains(p.getName()))
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 1.0f); //2015.08.12.
|
||||
message = message.replaceAll(p.getName(), "§6"+p.getName()+"§r");
|
||||
}
|
||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
||||
}
|
||||
|
||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
||||
public static void sendRawMessage(Player player, String message)
|
||||
{
|
||||
try {
|
||||
System.out.println("1");
|
||||
Object handle = Reflection.getHandle(player);
|
||||
System.out.println("2");
|
||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
||||
System.out.println("3");
|
||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
||||
System.out.println("4");
|
||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
||||
System.out.println("5");
|
||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
||||
System.out.println("6");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
||||
|
||||
public class PlayerListener implements Listener
|
||||
{ //2015.07.16.
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
Player p=event.getPlayer();
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
||||
if(mp.CommentedOnReddit)
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
||||
else
|
||||
{ //2015.07.20.
|
||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your §6Minecraft name to \"},{\"text\":\"[this thread.]\",\"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§r\"}]}}}]";
|
||||
sendRawMessage(p, json);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event)
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
||||
{
|
||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
||||
String flair=player.Flair; //2015.08.08.
|
||||
if(player.IgnoredFlair)
|
||||
flair="";
|
||||
String message=event.getMessage(); //2015.08.08.
|
||||
for(Player p : PluginMain.GetPlayers())
|
||||
{ //2015.08.12.
|
||||
message = message.replaceAll(p.getName(), "§6"+p.getName()+"§r");
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0, 1.0); //2015.08.12.
|
||||
}
|
||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
||||
}
|
||||
|
||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
||||
public static void sendRawMessage(Player player, String message)
|
||||
{
|
||||
try {
|
||||
System.out.println("1");
|
||||
Object handle = Reflection.getHandle(player);
|
||||
System.out.println("2");
|
||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
||||
System.out.println("3");
|
||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
||||
System.out.println("4");
|
||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
||||
System.out.println("5");
|
||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
||||
System.out.println("6");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,215 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if(args.length<1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||
if(p.Flair==null)
|
||||
{
|
||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||
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.
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
||||
p.AcceptedFlair=true; //2015.08.08.
|
||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
break;
|
||||
}
|
||||
case "ignore":
|
||||
{
|
||||
if(p.AcceptedFlair)
|
||||
p.AcceptedFlair=false; //2015.08.08.
|
||||
if(!p.IgnoredFlair)
|
||||
{
|
||||
p.IgnoredFlair=true;
|
||||
String flair=p.Flair; //2015.08.08.
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already ignored this request.§r");
|
||||
break;
|
||||
}
|
||||
/*case "reload": //2015.07.20.
|
||||
DoReload(player);
|
||||
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;
|
||||
}
|
||||
p.Flair="§7(non-pr.)§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.§r");
|
||||
break;
|
||||
}
|
||||
p.Flair="§r(can't press)§r";
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*if(args[0].toLowerCase()=="reload")
|
||||
DoReload(null); //2015.07.20.*/
|
||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); //2015.08.09.
|
||||
return true; //2015.08.09.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static void DoReload(Player player)
|
||||
{ //2015.07.20.
|
||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
//{
|
||||
try
|
||||
{
|
||||
File file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
PluginMain.LoadFiles(true); //2015.08.09.
|
||||
for(Player p : PluginMain.GetPlayers())
|
||||
{
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||
if(mp.Flair!=null)
|
||||
{
|
||||
String flair=mp.Flair;
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
||||
}
|
||||
}
|
||||
//String msg="§6Reloaded config file.§r";
|
||||
String msg="§6Reloaded all files.§r";
|
||||
SendMessage(player, msg); //2015.08.09.
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
if(player!=null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
//}
|
||||
//else
|
||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoAdmin(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
{
|
||||
//System.out.println("Args length: " + args.length);
|
||||
if(args.length==1)
|
||||
{
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
//args[0] is "admin"
|
||||
switch(args[1].toLowerCase())
|
||||
{
|
||||
case "reload":
|
||||
DoReload(player);
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
default:
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoPlayerInfo(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "playerinfo"
|
||||
if(args.length==2)
|
||||
{
|
||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||
{
|
||||
String message="§cPlayer not found: "+args[2]+"§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
SendMessage(player, "Player name: "+p.PlayerName);
|
||||
SendMessage(player, "User flair: "+p.Flair);
|
||||
SendMessage(player, "Username: "+p.UserName);
|
||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
||||
}
|
||||
private static void SendMessage(Player player, String message)
|
||||
{ //2015.08.09.
|
||||
if(player==null)
|
||||
System.out.println(message);
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
private static void DoGetLastError(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "getlasterror"
|
||||
if(PluginMain.LastException!=null)
|
||||
{
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException=null;
|
||||
}
|
||||
else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
}
|
|
@ -1,216 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if(args.length<1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||
if(p.Flair==null)
|
||||
{
|
||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||
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.
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
||||
p.AcceptedFlair=true; //2015.08.08.
|
||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
break;
|
||||
}
|
||||
case "ignore":
|
||||
{
|
||||
if(p.AcceptedFlair)
|
||||
p.AcceptedFlair=false; //2015.08.08.
|
||||
if(!p.IgnoredFlair)
|
||||
{
|
||||
p.IgnoredFlair=true;
|
||||
String flair=p.Flair; //2015.08.08.
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already ignored this request.§r");
|
||||
break;
|
||||
}
|
||||
/*case "reload": //2015.07.20.
|
||||
DoReload(player);
|
||||
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;
|
||||
}
|
||||
p.Flair="§7(non-pr.)§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.§r");
|
||||
break;
|
||||
}
|
||||
p.Flair="§r(can't press)§r";
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*if(args[0].toLowerCase()=="reload")
|
||||
DoReload(null); //2015.07.20.*/
|
||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); //2015.08.09.
|
||||
return true; //2015.08.09.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static void DoReload(Player player)
|
||||
{ //2015.07.20.
|
||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
//{
|
||||
try
|
||||
{
|
||||
File file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
PluginMain.LoadFiles(true); //2015.08.09.
|
||||
for(Player p : PluginMain.GetPlayers())
|
||||
{
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
||||
if(mp.Flair!=null)
|
||||
{
|
||||
String flair=mp.Flair;
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
||||
}
|
||||
}
|
||||
//String msg="§6Reloaded config file.§r";
|
||||
String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r";
|
||||
//SendMessage(player, msg); //2015.08.09.
|
||||
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
if(player!=null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
//}
|
||||
//else
|
||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoAdmin(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
{
|
||||
//System.out.println("Args length: " + args.length);
|
||||
if(args.length==1)
|
||||
{
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
//args[0] is "admin"
|
||||
switch(args[1].toLowerCase())
|
||||
{
|
||||
case "reload":
|
||||
DoReload(player);
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
default:
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoPlayerInfo(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "playerinfo"
|
||||
if(args.length==2)
|
||||
{
|
||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||
{
|
||||
String message="§cPlayer not found: "+args[2]+"§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
SendMessage(player, "Player name: "+p.PlayerName);
|
||||
SendMessage(player, "User flair: "+p.Flair);
|
||||
SendMessage(player, "Username: "+p.UserName);
|
||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
||||
}
|
||||
private static void SendMessage(Player player, String message)
|
||||
{ //2015.08.09.
|
||||
if(player==null)
|
||||
System.out.println(message);
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
private static void DoGetLastError(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "getlasterror"
|
||||
if(PluginMain.LastException!=null)
|
||||
{
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException=null;
|
||||
}
|
||||
else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
}
|
|
@ -1,326 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
|
||||
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/
|
||||
private static PluginMain Instance;
|
||||
// Fired when plugin is first enabled
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
this.getCommand("u").setExecutor(new Commands());
|
||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||
Instance=this; //2015.08.08.
|
||||
Load(false);
|
||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||
Thread t=new Thread(r);
|
||||
t.start();
|
||||
}
|
||||
Boolean stop=false;
|
||||
// Fired when plugin is disabled
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
try
|
||||
{
|
||||
FileWriter fw;
|
||||
fw = new FileWriter("flairsaccepted.txt");
|
||||
fw.close();
|
||||
fw = new FileWriter("flairsignored.txt");
|
||||
fw.close();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.AcceptedFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
file=new File("flairsignored.txt");
|
||||
bw = new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.IgnoredFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
stop=true;
|
||||
}
|
||||
|
||||
public void ThreadMethod() //<-- 2015.07.16.
|
||||
{
|
||||
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();
|
||||
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();
|
||||
if(HasIGFlair(ign))
|
||||
continue;
|
||||
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";
|
||||
else
|
||||
flair = "non-presser";
|
||||
String flairclass;
|
||||
if(flairdata.length>2)
|
||||
flairclass = flairdata[2];
|
||||
else
|
||||
flairclass="unknown";
|
||||
SetFlair(ign, flair, flairclass, author);
|
||||
}
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Exception LastException; //2015.08.09.
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||
public Boolean HasIGFlair(String playername)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
return p.Flair!=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
String finalflair;
|
||||
p.FlairDecided=true;
|
||||
switch(flairclass)
|
||||
{
|
||||
case "press-1":
|
||||
finalflair="§c("+text+")§r";
|
||||
break;
|
||||
case "press-2":
|
||||
finalflair="§6("+text+")§r";
|
||||
break;
|
||||
case "press-3":
|
||||
finalflair="§e("+text+")§r";
|
||||
break;
|
||||
case "press-4":
|
||||
finalflair="§a("+text+")§r";
|
||||
break;
|
||||
case "press-5":
|
||||
finalflair="§9("+text+")§r";
|
||||
break;
|
||||
case "press-6":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "no-press":
|
||||
finalflair="§7(non-pr.)§r";
|
||||
break;
|
||||
case "cheater":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "cant-press": //2015.08.08.
|
||||
finalflair="§r(can't press)§r";
|
||||
break;
|
||||
case "undecided": //2015.08.09.
|
||||
p.FlairDecided=false;
|
||||
finalflair="";
|
||||
break;
|
||||
default:
|
||||
finalflair="";
|
||||
break;
|
||||
}
|
||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||
return;
|
||||
p.Flair=finalflair; //2015.08.08.
|
||||
p.UserName=username; //2015.08.08.
|
||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||
{
|
||||
if(player.getName().equals(playername))
|
||||
{
|
||||
//AppendPlayerDisplayFlair(player, username, finalflair);
|
||||
AppendPlayerDisplayFlair(p, player);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String GetFlair(Player player)
|
||||
{ //2015.07.16.
|
||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||
return flair==null ? "" : flair;
|
||||
}
|
||||
|
||||
//public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||
public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09.
|
||||
{
|
||||
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair)
|
||||
return;
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair)
|
||||
{
|
||||
AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20.
|
||||
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");
|
||||
}
|
||||
|
||||
private static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||
String[] colors = color.substring(1).split("§");
|
||||
String displayname=player.getName(); //2015.08.08.
|
||||
ArrayList<Integer> Positions=new ArrayList<>();
|
||||
for(int i=0; i<displayname.length(); i++) {
|
||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||
Positions.add(i);
|
||||
}
|
||||
}
|
||||
String finalname=""; //TODO
|
||||
if(Positions.size()>=colors.length)
|
||||
{
|
||||
int x=0;
|
||||
for(int i=0; i<Positions.size(); i++)
|
||||
{
|
||||
int pos=Positions.get(i);
|
||||
int nextpos;
|
||||
if(i!=Positions.size()-1)
|
||||
nextpos=Positions.get(i+1);
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Positions.clear();
|
||||
int unit=displayname.length()/colors.length;
|
||||
int x=0;
|
||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||
{
|
||||
int pos=i;
|
||||
int nextpos;
|
||||
if(i<displayname.length()-unit-unit)
|
||||
nextpos=i+unit;
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||
}
|
||||
|
||||
public static String GetColorForTown(String townname)
|
||||
{ //2015.07.20.
|
||||
if(TownColors.containsKey(townname))
|
||||
return TownColors.get(townname);
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String GetPlayerTown(Player player)
|
||||
{ //2015.07.20.
|
||||
try {
|
||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||
return town.getName();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public static Collection<? extends Player> GetPlayers()
|
||||
{
|
||||
return Instance.getServer().getOnlinePlayers();
|
||||
}
|
||||
|
||||
public static void LoadFiles(boolean reload)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -1,491 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
|
||||
public static boolean PluginUpdated = false; // 2015.08.31.
|
||||
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label,
|
||||
String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
switch (cmd.getName()) {
|
||||
case "u": {
|
||||
if (args.length < 1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(player
|
||||
.getName()); // 2015.08.08.
|
||||
if (!p.CommentedOnReddit
|
||||
&& !args[0].toLowerCase().equals("admin")
|
||||
&& !args[0].toLowerCase().equals("ignore")) {
|
||||
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")) { // 2015.08.10.
|
||||
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")) { // 2015.08.19.
|
||||
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
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
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");
|
||||
} else
|
||||
player.sendMessage("§cYou already ignored this request.§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
|
||||
break;
|
||||
case "announce":
|
||||
DoAnnounce(player, args, null);
|
||||
break;
|
||||
case "name":
|
||||
if (args.length == 1) {
|
||||
player.sendMessage("§cUsage: /u name <playername>§r");
|
||||
break;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[1])) {
|
||||
player.sendMessage("§cUnknown user: " + args[1]);
|
||||
break;
|
||||
}
|
||||
player.sendMessage("§bUsername of "
|
||||
+ args[1]
|
||||
+ ": "
|
||||
+ MaybeOfflinePlayer.AllPlayers.get(args[1]).UserName);
|
||||
break;
|
||||
case "enable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = true;
|
||||
player.sendMessage("Enabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
case "disable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = false;
|
||||
player.sendMessage("Disabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "nrp":
|
||||
case "ooc":
|
||||
if (args.length == 0) {
|
||||
return false;
|
||||
} else {
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = false;
|
||||
String message = "";
|
||||
for (String arg : args)
|
||||
message += arg + " ";
|
||||
player.chat(message.substring(0, message.length() - 1));
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = true;
|
||||
}
|
||||
return true;
|
||||
case "skype":
|
||||
// "skype:?chat&blob=Y_5Ob1BEcw0ZlstdUHyf0ENS5n1Xz2Huhx-5b-pB2JyMSRO5QMEALkJuTSuUaAb3-XfWXwCndwhGex_UpXDbyQ";
|
||||
return true;
|
||||
default:
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
}
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("admin")) // 2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); // 2015.08.09.
|
||||
return true; // 2015.08.09.
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("announce")) {
|
||||
if (sender instanceof BlockCommandSender)
|
||||
DoAnnounce(null, args, (BlockCommandSender) sender);
|
||||
else
|
||||
DoAnnounce(null, args, null);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void DoReload(Player player) { // 2015.07.20.
|
||||
try {
|
||||
PluginMain.Console
|
||||
.sendMessage("§6-- Reloading The Button Minecraft plugin...§r");
|
||||
PluginMain.LoadFiles(true); // 2015.08.09.
|
||||
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.
|
||||
}
|
||||
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.
|
||||
}
|
||||
PluginMain.Console.sendMessage("§6-- Reloading done!§r");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
if (player != null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static Player ReloadPlayer; // 2015.08.09.
|
||||
|
||||
private static String DoAdminUsage = "§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin|togglerpshow|toggledebug|savepos|loadpos§r";
|
||||
|
||||
private static void DoAdmin(Player player, String[] args) { // 2015.08.09.
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// args[0] is "admin"
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "reload":
|
||||
ReloadPlayer = player; // 2015.08.09.
|
||||
SendMessage(
|
||||
player,
|
||||
"§bMake sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
break; // <-- 2015.08.10.
|
||||
case "confirm":
|
||||
if (ReloadPlayer == player)
|
||||
DoReload(player); // 2015.08.09.
|
||||
else
|
||||
SendMessage(player,
|
||||
"§cYou need to do /u admin reload first.§r");
|
||||
break;
|
||||
case "save":
|
||||
PluginMain.SaveFiles(); // 2015.08.09.
|
||||
SendMessage(player,
|
||||
"§bSaved files. Now you can edit them and reload if you want.§r");
|
||||
break;
|
||||
case "setflair":
|
||||
DoSetFlair(player, args);
|
||||
break;
|
||||
case "updateplugin": // 2015.08.10.
|
||||
DoUpdatePlugin(player);
|
||||
break;
|
||||
case "togglerpshow":
|
||||
PlayerListener.ShowRPTag = !PlayerListener.ShowRPTag;
|
||||
SendMessage(player, "RP tag showing "
|
||||
+ (PlayerListener.ShowRPTag ? "enabled" : "disabled"));
|
||||
break;
|
||||
case "toggledebug":
|
||||
PlayerListener.DebugMode = !PlayerListener.DebugMode;
|
||||
SendMessage(player, "DebugMode: " + PlayerListener.DebugMode);
|
||||
break;
|
||||
case "savepos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "loadpos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "updatedynmap":
|
||||
DoUpdateDynmap(player, args);
|
||||
default:
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
|
||||
private static void DoPlayerInfo(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "playerinfo"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(args[2]);
|
||||
if (p == null) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
SendMessage(player, "Player name: " + p.PlayerName);
|
||||
SendMessage(player, "User flair: " + p.Flair);
|
||||
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);
|
||||
}
|
||||
|
||||
private static void SendMessage(Player player, String message) { // 2015.08.09.
|
||||
if (player == null)
|
||||
PluginMain.Console.sendMessage(message); // 2015.08.12.
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
private static void DoGetLastError(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "getlasterror"
|
||||
if (PluginMain.LastException != null) {
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException = null;
|
||||
} else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
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");
|
||||
return;
|
||||
}
|
||||
Player p = Bukkit.getPlayer(args[2]);
|
||||
if (p == null) {
|
||||
SendMessage(player, "§cPLayer not found.&r");
|
||||
return;
|
||||
}
|
||||
SetPlayerFlair(player,
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()), args[3]);
|
||||
}
|
||||
|
||||
private static void DoUpdatePlugin(Player player) { // 2015.08.10.
|
||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
||||
System.out.println("Forced updating of Auto-Flair plugin.");
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(
|
||||
"https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
||||
FileUtils.copyURLToFile(url, new File(
|
||||
"plugins/TheButtonAutoFlair.jar"));
|
||||
PluginUpdated = true; // 2015.08.31.
|
||||
SendMessage(player, "Updating done!");
|
||||
} catch (MalformedURLException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoAnnounce(Player player, String[] args,
|
||||
BlockCommandSender commandblock) {
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "add":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce add <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
PluginMain.AnnounceMessages.add(finalmessage);
|
||||
SendMessage(player, "§bAnnouncement added.§r");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce remove <index>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceMessages.remove(Integer.parseInt(args[2]));
|
||||
break;
|
||||
case "settime":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player,
|
||||
"§cUsage: /u announce settime <minutes>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceTime = Integer.parseInt(args[2]) * 60 * 1000;
|
||||
SendMessage(player, "Time set between announce messages");
|
||||
break;
|
||||
case "list":
|
||||
SendMessage(player, "§bList of announce messages:§r");
|
||||
SendMessage(player, "§bFormat: [index] message§r");
|
||||
int i = 0;
|
||||
for (String message : PluginMain.AnnounceMessages)
|
||||
SendMessage(player, "[" + i++ + "] " + message);
|
||||
SendMessage(player,
|
||||
"§bCurrent wait time between announcements: "
|
||||
+ PluginMain.AnnounceTime / 60 / 1000
|
||||
+ " minute(s)§r");
|
||||
break;
|
||||
case "edit":
|
||||
if (commandblock == null) {
|
||||
SendMessage(
|
||||
player,
|
||||
"§cError: This command can only be used from a command block. Use /u announce remove.");
|
||||
break;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
commandblock
|
||||
.sendMessage("§cUsage: /u announce edit <index> <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 3; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§'),
|
||||
PluginMain.AnnounceMessages.set(Integer.parseInt(args[2]),
|
||||
finalmessage1);
|
||||
commandblock.sendMessage("Announcement edited.");
|
||||
break;
|
||||
default:
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoSaveLoadPos(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "savepos|loadpos"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
Player p = null;
|
||||
for (Player pl : PluginMain.GetPlayers()) {
|
||||
if (pl.getName().equals(args[2])) {
|
||||
p = pl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (p == null) {
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer is not online: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (args[1].equalsIgnoreCase("savepos")) {
|
||||
mp.SavedLocation = p.getLocation();
|
||||
} else if (args[1].equalsIgnoreCase("loadpos")) {
|
||||
if (mp.SavedLocation != null)
|
||||
p.teleport(mp.SavedLocation);
|
||||
} else {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// SendMessage(player, "Player " + p.getName() +
|
||||
// " position saved/loaded.");s
|
||||
}
|
||||
|
||||
private static void DoUpdateDynmap(Player player, String[] args) {
|
||||
// args[0] is "admin" - args[1] is "updatedynmap"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin updatedynmap <password>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
||||
|
||||
public class PlayerListener implements Listener
|
||||
{ //2015.07.16.
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
Player p=event.getPlayer();
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
||||
if(mp.CommentedOnReddit)
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
||||
else
|
||||
{ //2015.07.20.
|
||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your §6Minecraft name to \"},{\"text\":\"[this thread.]\",\"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§r\"}]}}}]";
|
||||
sendRawMessage(p, json);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event)
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
||||
{
|
||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
||||
String flair=player.Flair; //2015.08.08.
|
||||
if(player.IgnoredFlair)
|
||||
flair="";
|
||||
String message=event.getMessage(); //2015.08.08.
|
||||
for(Player p : PluginMain.GetPlayers())
|
||||
{ //2015.08.12.
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 1.0f); //2015.08.12.
|
||||
message = message.replaceAll(p.getName(), "§6"+p.getName()+"§r");
|
||||
}
|
||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
||||
}
|
||||
|
||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
||||
public static void sendRawMessage(Player player, String message)
|
||||
{
|
||||
try {
|
||||
System.out.println("1");
|
||||
Object handle = Reflection.getHandle(player);
|
||||
System.out.println("2");
|
||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
||||
System.out.println("3");
|
||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
||||
System.out.println("4");
|
||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
||||
System.out.println("5");
|
||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
||||
System.out.println("6");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,323 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerChatTabCompleteEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import au.com.mineauz.minigames.Minigames;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerListener implements Listener { // 2015.07.16.
|
||||
public static HashMap<String, UUID> nicknames = new HashMap<>();
|
||||
|
||||
public static boolean Enable = false; // 2015.08.29.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p
|
||||
.getUniqueId());
|
||||
mp.PlayerName = p.getName(); // 2015.10.17. 0:58
|
||||
// if (mp.CommentedOnReddit)
|
||||
if (false)
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); // 2015.08.09.
|
||||
else { // 2015.07.20.
|
||||
Timer timer = new Timer();
|
||||
PlayerJoinTimerTask tt = new PlayerJoinTimerTask() {
|
||||
public MaybeOfflinePlayer mp;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!mp.IgnoredFlair) {
|
||||
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,
|
||||
"tellraw " + mp.PlayerName + " " + json);
|
||||
json = "[\"\",{\"text\":\"If you don't want the flair, type /u ignore to prevent this message after next login.\",\"color\":\"aqua\"}]";
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Console,
|
||||
"tellraw " + mp.PlayerName + " " + json);
|
||||
}
|
||||
}
|
||||
};
|
||||
tt.mp=mp;
|
||||
timer.schedule(tt, 15 * 1000);
|
||||
}
|
||||
|
||||
/* NICKNAME LOGIC */
|
||||
|
||||
UUID id = p.getUniqueId();
|
||||
|
||||
File f = new File("plugins/Essentials/userdata/" + id + ".yml");
|
||||
if (f.exists()) {
|
||||
YamlConfiguration yc = new YamlConfiguration();
|
||||
try {
|
||||
yc.load(f);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String nickname = yc.getString("nickname");
|
||||
if (nickname != null) {
|
||||
nicknames.put(nickname, id);
|
||||
|
||||
if (Enable) {
|
||||
if (!p.getName().equals("NorbiPeti")) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.chat("Hey, " + nickname + "!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mp.RPMode = true; // 2015.08.25.
|
||||
|
||||
if (p.getName().equals("FigyTuna") && Commands.PluginUpdated)
|
||||
p.sendMessage("§bThe The Button MC plugin got updated. Please restart the server. :P§r");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
String deletenick = null;
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
UUID uuid = nicknames.get(nickname);
|
||||
if (event.getPlayer().getUniqueId().equals(uuid)) {
|
||||
deletenick = nickname;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (deletenick != null)
|
||||
nicknames.remove(deletenick);
|
||||
}
|
||||
|
||||
public static String NotificationSound; // 2015.08.14.
|
||||
public static double NotificationPitch; // 2015.08.14.
|
||||
|
||||
public static boolean ShowRPTag = false; // 2015.08.31.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.GetFromName(event
|
||||
.getPlayer().getName());
|
||||
String flair = player.Flair; // 2015.08.08.
|
||||
if (player.IgnoredFlair)
|
||||
flair = "";
|
||||
String message = event.getMessage(); // 2015.08.08.
|
||||
for (Player p : PluginMain.GetPlayers()) { // 2015.08.12.
|
||||
String color = ""; // 2015.08.17.
|
||||
if (message.contains(p.getName())) {
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(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);
|
||||
}
|
||||
|
||||
message = message.replaceAll(p.getName(), color + p.getName()
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
for (String n : nicknames.keySet()) {
|
||||
Player p = null;
|
||||
String nwithoutformatting = new String(n);
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (message.contains(nwithoutformatting)) {
|
||||
p = Bukkit.getPlayer(nicknames.get(n));
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(float) NotificationPitch); // 2015.08.14.
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()); // 2015.08.17.
|
||||
}
|
||||
if (p != null) {
|
||||
message = message.replaceAll(nwithoutformatting, n
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
}
|
||||
|
||||
event.setMessage(message); // 2015.09.05.
|
||||
|
||||
event.setFormat(event
|
||||
.getFormat()
|
||||
.replace(
|
||||
"{rptag}",
|
||||
(player.RPMode ? (ShowRPTag ? "§2[RP]§r" : "")
|
||||
: "§8[OOC]§r"))
|
||||
.replace("{buttonflair}", flair)
|
||||
.replace(
|
||||
"{isitwilds}",
|
||||
(event.getPlayer().getWorld().getName()
|
||||
.equalsIgnoreCase("wilds") ? "[PVP]" : ""))); // 2015.09.04.
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTabComplete(PlayerChatTabCompleteEvent e) {
|
||||
String name = e.getLastToken();
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
String nwithoutformatting = nickname;
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (nwithoutformatting.startsWith(name)
|
||||
&& !nwithoutformatting.equals(Bukkit.getPlayer(
|
||||
nicknames.get(nickname)).getName()))
|
||||
e.getTabCompletions().add(nwithoutformatting);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean DebugMode = false;
|
||||
|
||||
public void SendForDebug(String message) {
|
||||
if (DebugMode) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.sendMessage("[DEBUG] " + message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean ActiveF = false;
|
||||
private int FCount = 0;
|
||||
private long FTime;
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMessage(AsyncPlayerChatEvent e) {
|
||||
if (ActiveF) {
|
||||
if (System.currentTimeMillis() - FTime > 10000) {
|
||||
ActiveF = false;
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
p.sendMessage("§b" + FCount + " "
|
||||
+ (FCount == 1 ? "person" : "people")
|
||||
+ " paid their respects.§r");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e.getMessage().equalsIgnoreCase("F")) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(e
|
||||
.getPlayer().getName());
|
||||
if (!mp.PressedF && ActiveF) {
|
||||
FCount++;
|
||||
mp.PressedF = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (e.getMessage().startsWith(">"))
|
||||
e.setMessage("§2" + e.getMessage());
|
||||
|
||||
/*
|
||||
* Channel c = ((Chat) Bukkit.getPluginManager().getPlugin("TownyChat"))
|
||||
* .getChannelsHandler().getActiveChannel(e.getPlayer(),
|
||||
* channelTypes.GLOBAL);
|
||||
*/
|
||||
/*
|
||||
* List<String> modes = ((Chat) Bukkit.getPluginManager().getPlugin(
|
||||
* "TownyChat")).getTowny().getPlayerMode(e.getPlayer()); if
|
||||
* (modes.size() == 0 || modes.contains("g")) {
|
||||
*/
|
||||
if (e.getFormat().contains("[g]")) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("tellraw @a [\"\"");
|
||||
sb.append(",{\"text\":\"Hashtags:\"}");
|
||||
int index = -1;
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
while ((index = e.getMessage().indexOf("#", index + 1)) != -1) {
|
||||
int index2 = e.getMessage().indexOf(" ", index + 1);
|
||||
if (index2 == -1)
|
||||
index2 = e.getMessage().length();
|
||||
int index3 = e.getMessage().indexOf("#", index + 1);
|
||||
if (index3 != -1 && index3 < index2) // A # occurs before a
|
||||
// space
|
||||
index2 = index3;
|
||||
String original = e.getMessage().substring(index, index2);
|
||||
list.add(original);
|
||||
sb.append(",{\"text\":\" \"}");
|
||||
sb.append(",{\"text\":\"");
|
||||
sb.append(original);
|
||||
sb.append("\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://twitter.com/hashtag/");
|
||||
sb.append(original.substring(1));
|
||||
sb.append("\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open on Twitter\",\"color\":\"blue\"}]}}}");
|
||||
}
|
||||
for (String original : list)
|
||||
e.setMessage(e.getMessage().replace(
|
||||
original,
|
||||
"§9"
|
||||
+ original
|
||||
+ (e.getMessage().startsWith("§2>") ? "§2"
|
||||
: "§r")));
|
||||
/*
|
||||
* for (String original : list)
|
||||
* System.out.println(e.getMessage().replace( original, "§9" +
|
||||
* original + (e.getMessage().startsWith("§2>") ? "§2" : "§r")));
|
||||
*/
|
||||
|
||||
sb.append("]");
|
||||
|
||||
if (list.size() > 0)
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Instance.getServer().getConsoleSender(),
|
||||
sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDeath(PlayerDeathEvent e) {
|
||||
if (!Minigames.plugin.pdata.getMinigamePlayer(e.getEntity())
|
||||
.isInMinigame() && new Random().nextBoolean()) {
|
||||
ActiveF = true;
|
||||
FCount = 0;
|
||||
FTime = System.currentTimeMillis();
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(p
|
||||
.getName());
|
||||
mp.PressedF = false;
|
||||
p.sendMessage("§bPress F to pay respects.§r");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,360 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import tk.sznp.thebuttonautoflair.MaybeOfflinePlayer.FlairClassType;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
|
||||
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/
|
||||
private static PluginMain Instance;
|
||||
// Fired when plugin is first enabled
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
this.getCommand("u").setExecutor(new Commands());
|
||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||
Instance=this; //2015.08.08.
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
//System.out.println("Name: " + name);
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("flairsignored.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while((line=br.readLine())!=null)
|
||||
{
|
||||
String[] s=line.split(" ");
|
||||
TownColors.put(s[0], s[1]);
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
//throw new IOException("Test"); //2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||
Thread t=new Thread(r);
|
||||
t.start();
|
||||
}
|
||||
Boolean stop=false;
|
||||
// Fired when plugin is disabled
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
try
|
||||
{
|
||||
FileWriter fw;
|
||||
fw = new FileWriter("flairsaccepted.txt");
|
||||
fw.close();
|
||||
fw = new FileWriter("flairsignored.txt");
|
||||
fw.close();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.AcceptedFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
file=new File("flairsignored.txt");
|
||||
bw = new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.IgnoredFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
stop=true;
|
||||
}
|
||||
|
||||
public void ThreadMethod() //<-- 2015.07.16.
|
||||
{
|
||||
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();
|
||||
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();
|
||||
if(HasIGFlair(ign))
|
||||
continue;
|
||||
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";
|
||||
else
|
||||
flair = "non-presser";
|
||||
String flairclass;
|
||||
if(flairdata.length>2)
|
||||
flairclass = flairdata[2];
|
||||
else
|
||||
flairclass="unknown";
|
||||
SetFlair(ign, flair, flairclass, author);
|
||||
}
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Exception LastException; //2015.08.09.
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||
public Boolean HasIGFlair(String playername)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
return p.Flair!=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
String finalflair;
|
||||
p.FlairDecided=true;
|
||||
switch(flairclass)
|
||||
{
|
||||
case "press-1":
|
||||
finalflair="§c("+text+")§r";
|
||||
break;
|
||||
case "press-2":
|
||||
finalflair="§6("+text+")§r";
|
||||
break;
|
||||
case "press-3":
|
||||
finalflair="§e("+text+")§r";
|
||||
break;
|
||||
case "press-4":
|
||||
finalflair="§a("+text+")§r";
|
||||
break;
|
||||
case "press-5":
|
||||
finalflair="§9("+text+")§r";
|
||||
break;
|
||||
case "press-6":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "no-press":
|
||||
finalflair="§7(non-pr.)§r";
|
||||
break;
|
||||
case "cheater":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "cant-press": //2015.08.08.
|
||||
finalflair="§r(can't press)§r";
|
||||
break;
|
||||
case "undecided": //2015.08.09.
|
||||
p.FlairDecided=false;
|
||||
finalflair="";
|
||||
break;
|
||||
default:
|
||||
finalflair="";
|
||||
break;
|
||||
}
|
||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||
return;
|
||||
p.Flair=finalflair; //2015.08.08.
|
||||
p.UserName=username; //2015.08.08.
|
||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||
{
|
||||
if(player.getName().equals(playername))
|
||||
{
|
||||
AppendPlayerDisplayFlair(player, username, finalflair);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String GetFlair(Player player)
|
||||
{ //2015.07.16.
|
||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||
return flair==null ? "" : flair;
|
||||
}
|
||||
|
||||
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||
{
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
||||
return;
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
||||
{
|
||||
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
}
|
||||
else
|
||||
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
||||
}
|
||||
|
||||
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||
String[] colors = color.substring(1).split("§");
|
||||
String displayname=player.getName(); //2015.08.08.
|
||||
ArrayList<Integer> Positions=new ArrayList<>();
|
||||
for(int i=0; i<displayname.length(); i++) {
|
||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||
Positions.add(i);
|
||||
}
|
||||
}
|
||||
String finalname=""; //TODO
|
||||
if(Positions.size()>=colors.length)
|
||||
{
|
||||
int x=0;
|
||||
for(int i=0; i<Positions.size(); i++)
|
||||
{
|
||||
int pos=Positions.get(i);
|
||||
int nextpos;
|
||||
if(i!=Positions.size()-1)
|
||||
nextpos=Positions.get(i+1);
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Positions.clear();
|
||||
int unit=displayname.length()/colors.length;
|
||||
int x=0;
|
||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||
{
|
||||
int pos=i;
|
||||
int nextpos;
|
||||
if(i<displayname.length()-unit-unit)
|
||||
nextpos=i+unit;
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||
}
|
||||
|
||||
public static String GetColorForTown(String townname)
|
||||
{ //2015.07.20.
|
||||
if(TownColors.containsKey(townname))
|
||||
return TownColors.get(townname);
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String GetPlayerTown(Player player)
|
||||
{ //2015.07.20.
|
||||
try {
|
||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||
return town.getName();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public static Collection<? extends Player> GetPlayers()
|
||||
{
|
||||
return Instance.getServer().getOnlinePlayers();
|
||||
}
|
||||
}
|
|
@ -1,215 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if(args.length<1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||
if(p.Flair==null)
|
||||
{
|
||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||
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.
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
||||
p.AcceptedFlair=true; //2015.08.08.
|
||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
break;
|
||||
}
|
||||
case "ignore":
|
||||
{
|
||||
if(p.AcceptedFlair)
|
||||
p.AcceptedFlair=false; //2015.08.08.
|
||||
if(!p.IgnoredFlair)
|
||||
{
|
||||
p.IgnoredFlair=true;
|
||||
String flair=p.Flair; //2015.08.08.
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already ignored this request.§r");
|
||||
break;
|
||||
}
|
||||
/*case "reload": //2015.07.20.
|
||||
DoReload(player);
|
||||
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;
|
||||
}
|
||||
p.Flair="§7(non-pr.)§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.§r");
|
||||
break;
|
||||
}
|
||||
p.Flair="§r(can't press)§r";
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*if(args[0].toLowerCase()=="reload")
|
||||
DoReload(null); //2015.07.20.*/
|
||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); //2015.08.09.
|
||||
return true; //2015.08.09.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static void DoReload(Player player)
|
||||
{ //2015.07.20.
|
||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
//{
|
||||
try
|
||||
{
|
||||
File file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
PluginMain.LoadFiles(true); //2015.08.09.
|
||||
for(Player p : PluginMain.GetPlayers())
|
||||
{
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
||||
if(mp.Flair!=null)
|
||||
{
|
||||
String flair=mp.Flair;
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
||||
}
|
||||
}
|
||||
//String msg="§6Reloaded config file.§r";
|
||||
String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r";
|
||||
//SendMessage(player, msg); //2015.08.09.
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
if(player!=null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
//}
|
||||
//else
|
||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoAdmin(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
{
|
||||
//System.out.println("Args length: " + args.length);
|
||||
if(args.length==1)
|
||||
{
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
//args[0] is "admin"
|
||||
switch(args[1].toLowerCase())
|
||||
{
|
||||
case "reload":
|
||||
DoReload(player);
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
default:
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoPlayerInfo(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "playerinfo"
|
||||
if(args.length==2)
|
||||
{
|
||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||
{
|
||||
String message="§cPlayer not found: "+args[2]+"§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
SendMessage(player, "Player name: "+p.PlayerName);
|
||||
SendMessage(player, "User flair: "+p.Flair);
|
||||
SendMessage(player, "Username: "+p.UserName);
|
||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
||||
}
|
||||
private static void SendMessage(Player player, String message)
|
||||
{ //2015.08.09.
|
||||
if(player==null)
|
||||
System.out.println(message);
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
private static void DoGetLastError(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "getlasterror"
|
||||
if(PluginMain.LastException!=null)
|
||||
{
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException=null;
|
||||
}
|
||||
else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
}
|
|
@ -1,215 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if(args.length<1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||
if(p.Flair==null)
|
||||
{
|
||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||
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.
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
||||
p.AcceptedFlair=true; //2015.08.08.
|
||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
break;
|
||||
}
|
||||
case "ignore":
|
||||
{
|
||||
if(p.AcceptedFlair)
|
||||
p.AcceptedFlair=false; //2015.08.08.
|
||||
if(!p.IgnoredFlair)
|
||||
{
|
||||
p.IgnoredFlair=true;
|
||||
String flair=p.Flair; //2015.08.08.
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already ignored this request.§r");
|
||||
break;
|
||||
}
|
||||
/*case "reload": //2015.07.20.
|
||||
DoReload(player);
|
||||
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;
|
||||
}
|
||||
p.Flair="§7(non-pr.)§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.§r");
|
||||
break;
|
||||
}
|
||||
p.Flair="§r(can't press)§r";
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*if(args[0].toLowerCase()=="reload")
|
||||
DoReload(null); //2015.07.20.*/
|
||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); //2015.08.09.
|
||||
return true; //2015.08.09.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static void DoReload(Player player)
|
||||
{ //2015.07.20.
|
||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
//{
|
||||
try
|
||||
{
|
||||
File file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
PluginMain.LoadFiles(true);
|
||||
for(Player p : PluginMain.GetPlayers())
|
||||
{
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||
if(mp.Flair!=null)
|
||||
{
|
||||
String flair=mp.Flair;
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
||||
}
|
||||
}
|
||||
//String msg="§6Reloaded config file.§r";
|
||||
String msg="§6Reloaded all files.§r";
|
||||
SendMessage(player, msg); //2015.08.09.
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
if(player!=null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
//}
|
||||
//else
|
||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoAdmin(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
{
|
||||
//System.out.println("Args length: " + args.length);
|
||||
if(args.length==1)
|
||||
{
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
//args[0] is "admin"
|
||||
switch(args[1].toLowerCase())
|
||||
{
|
||||
case "reload":
|
||||
DoReload(player);
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
default:
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoPlayerInfo(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "playerinfo"
|
||||
if(args.length==2)
|
||||
{
|
||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||
{
|
||||
String message="§cPlayer not found: "+args[2]+"§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
SendMessage(player, "Player name: "+p.PlayerName);
|
||||
SendMessage(player, "User flair: "+p.Flair);
|
||||
SendMessage(player, "Username: "+p.UserName);
|
||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
||||
}
|
||||
private static void SendMessage(Player player, String message)
|
||||
{ //2015.08.09.
|
||||
if(player==null)
|
||||
System.out.println(message);
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
private static void DoGetLastError(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "getlasterror"
|
||||
if(PluginMain.LastException!=null)
|
||||
{
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException=null;
|
||||
}
|
||||
else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
}
|
|
@ -1,362 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import tk.sznp.thebuttonautoflair.MaybeOfflinePlayer.FlairClassType;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
|
||||
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/
|
||||
private static PluginMain Instance;
|
||||
// Fired when plugin is first enabled
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
this.getCommand("u").setExecutor(new Commands());
|
||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||
Instance=this; //2015.08.08.
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
//System.out.println("Name: " + name);
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("flairsignored.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while((line=br.readLine())!=null)
|
||||
{
|
||||
String[] s=line.split(" ");
|
||||
TownColors.put(s[0], s[1]);
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
//throw new IOException("Test"); //2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||
Thread t=new Thread(r);
|
||||
t.start();
|
||||
}
|
||||
Boolean stop=false;
|
||||
// Fired when plugin is disabled
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
try
|
||||
{
|
||||
FileWriter fw;
|
||||
fw = new FileWriter("flairsaccepted.txt");
|
||||
fw.close();
|
||||
fw = new FileWriter("flairsignored.txt");
|
||||
fw.close();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.AcceptedFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
file=new File("flairsignored.txt");
|
||||
bw = new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.IgnoredFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
stop=true;
|
||||
}
|
||||
|
||||
public void ThreadMethod() //<-- 2015.07.16.
|
||||
{
|
||||
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();
|
||||
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();
|
||||
if(HasIGFlair(ign))
|
||||
continue;
|
||||
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";
|
||||
else
|
||||
flair = "non-presser";
|
||||
String flairclass;
|
||||
if(flairdata.length>2)
|
||||
flairclass = flairdata[2];
|
||||
else
|
||||
flairclass="unknown";
|
||||
SetFlair(ign, flair, flairclass, author);
|
||||
}
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Exception LastException; //2015.08.09.
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||
public Boolean HasIGFlair(String playername)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
return p.Flair!=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
String finalflair;
|
||||
p.FlairDecided=true;
|
||||
switch(flairclass)
|
||||
{
|
||||
case "press-1":
|
||||
finalflair="§c("+text+")§r";
|
||||
break;
|
||||
case "press-2":
|
||||
finalflair="§6("+text+")§r";
|
||||
break;
|
||||
case "press-3":
|
||||
finalflair="§e("+text+")§r";
|
||||
break;
|
||||
case "press-4":
|
||||
finalflair="§a("+text+")§r";
|
||||
break;
|
||||
case "press-5":
|
||||
finalflair="§9("+text+")§r";
|
||||
break;
|
||||
case "press-6":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "no-press":
|
||||
finalflair="§7(non-pr.)§r";
|
||||
break;
|
||||
case "cheater":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "cant-press": //2015.08.08.
|
||||
finalflair="§r(can't press)§r";
|
||||
break;
|
||||
case "undecided": //2015.08.09.
|
||||
p.FlairDecided=false;
|
||||
finalflair="";
|
||||
break;
|
||||
default:
|
||||
finalflair="";
|
||||
break;
|
||||
}
|
||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||
return;
|
||||
p.Flair=finalflair; //2015.08.08.
|
||||
p.UserName=username; //2015.08.08.
|
||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||
{
|
||||
if(player.getName().equals(playername))
|
||||
{
|
||||
AppendPlayerDisplayFlair(player, username, finalflair);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String GetFlair(Player player)
|
||||
{ //2015.07.16.
|
||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||
return flair==null ? "" : flair;
|
||||
}
|
||||
|
||||
//public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||
public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p)
|
||||
{
|
||||
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
||||
return;
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
||||
{
|
||||
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
}
|
||||
else
|
||||
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
||||
}
|
||||
|
||||
private static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||
String[] colors = color.substring(1).split("§");
|
||||
String displayname=player.getName(); //2015.08.08.
|
||||
ArrayList<Integer> Positions=new ArrayList<>();
|
||||
for(int i=0; i<displayname.length(); i++) {
|
||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||
Positions.add(i);
|
||||
}
|
||||
}
|
||||
String finalname=""; //TODO
|
||||
if(Positions.size()>=colors.length)
|
||||
{
|
||||
int x=0;
|
||||
for(int i=0; i<Positions.size(); i++)
|
||||
{
|
||||
int pos=Positions.get(i);
|
||||
int nextpos;
|
||||
if(i!=Positions.size()-1)
|
||||
nextpos=Positions.get(i+1);
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Positions.clear();
|
||||
int unit=displayname.length()/colors.length;
|
||||
int x=0;
|
||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||
{
|
||||
int pos=i;
|
||||
int nextpos;
|
||||
if(i<displayname.length()-unit-unit)
|
||||
nextpos=i+unit;
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||
}
|
||||
|
||||
public static String GetColorForTown(String townname)
|
||||
{ //2015.07.20.
|
||||
if(TownColors.containsKey(townname))
|
||||
return TownColors.get(townname);
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String GetPlayerTown(Player player)
|
||||
{ //2015.07.20.
|
||||
try {
|
||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||
return town.getName();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public static Collection<? extends Player> GetPlayers()
|
||||
{
|
||||
return Instance.getServer().getOnlinePlayers();
|
||||
}
|
||||
}
|
|
@ -1,216 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if(args.length<1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||
if(p.Flair==null)
|
||||
{
|
||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||
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.
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
||||
p.AcceptedFlair=true; //2015.08.08.
|
||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
break;
|
||||
}
|
||||
case "ignore":
|
||||
{
|
||||
if(p.AcceptedFlair)
|
||||
p.AcceptedFlair=false; //2015.08.08.
|
||||
if(!p.IgnoredFlair)
|
||||
{
|
||||
p.IgnoredFlair=true;
|
||||
String flair=p.Flair; //2015.08.08.
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already ignored this request.§r");
|
||||
break;
|
||||
}
|
||||
/*case "reload": //2015.07.20.
|
||||
DoReload(player);
|
||||
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;
|
||||
}
|
||||
p.Flair="§7(non-pr.)§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.§r");
|
||||
break;
|
||||
}
|
||||
p.Flair="§r(can't press)§r";
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*if(args[0].toLowerCase()=="reload")
|
||||
DoReload(null); //2015.07.20.*/
|
||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); //2015.08.09.
|
||||
return true; //2015.08.09.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static void DoReload(Player player)
|
||||
{ //2015.07.20.
|
||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
//{
|
||||
try
|
||||
{
|
||||
File file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
PluginMain.LoadFiles(true); //2015.08.09.
|
||||
for(Player p : PluginMain.GetPlayers())
|
||||
{
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
||||
if(mp.Flair!=null)
|
||||
{
|
||||
String flair=mp.Flair;
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
||||
}
|
||||
String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09.
|
||||
p.sendMessage(msg);
|
||||
}
|
||||
//String msg="§6Reloaded config file.§r";
|
||||
//SendMessage(player, msg); //2015.08.09.
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
if(player!=null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
//}
|
||||
//else
|
||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoAdmin(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
{
|
||||
//System.out.println("Args length: " + args.length);
|
||||
if(args.length==1)
|
||||
{
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
//args[0] is "admin"
|
||||
switch(args[1].toLowerCase())
|
||||
{
|
||||
case "reload":
|
||||
DoReload(player);
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
default:
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoPlayerInfo(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "playerinfo"
|
||||
if(args.length==2)
|
||||
{
|
||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||
{
|
||||
String message="§cPlayer not found: "+args[2]+"§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
SendMessage(player, "Player name: "+p.PlayerName);
|
||||
SendMessage(player, "User flair: "+p.Flair);
|
||||
SendMessage(player, "Username: "+p.UserName);
|
||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
||||
}
|
||||
private static void SendMessage(Player player, String message)
|
||||
{ //2015.08.09.
|
||||
if(player==null)
|
||||
System.out.println(message);
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
private static void DoGetLastError(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "getlasterror"
|
||||
if(PluginMain.LastException!=null)
|
||||
{
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException=null;
|
||||
}
|
||||
else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class PlayerJoinTimerTask extends TimerTask {
|
||||
|
||||
@Override
|
||||
public abstract void run();
|
||||
|
||||
}
|
|
@ -1,295 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if(args.length<1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||
if(!p.CommentedOnReddit && !args[0].toLowerCase().equals("admin"))
|
||||
{
|
||||
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"))
|
||||
{ //2015.08.10.
|
||||
player.sendMessage("Sorry, but your flair isn't recorded. Please ask a mod to set it for you.");
|
||||
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.
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
p.AcceptedFlair=true; //2015.08.08.
|
||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
||||
player.sendMessage("§9Your flair has been set:§r "+flair);
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
break;
|
||||
}
|
||||
case "ignore":
|
||||
{
|
||||
if(p.AcceptedFlair)
|
||||
p.AcceptedFlair=false; //2015.08.08.
|
||||
if(!p.IgnoredFlair)
|
||||
{
|
||||
p.IgnoredFlair=true;
|
||||
//String flair=p.Flair; //2015.08.08.
|
||||
//PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
player.sendMessage("§9You have ignored this request. You can still use /u accept though.§r");
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already ignored this request.§r");
|
||||
break;
|
||||
}
|
||||
/*case "reload": //2015.07.20.
|
||||
DoReload(player);
|
||||
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
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*if(args[0].toLowerCase()=="reload")
|
||||
DoReload(null); //2015.07.20.*/
|
||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); //2015.08.09.
|
||||
return true; //2015.08.09.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static void DoReload(Player player)
|
||||
{ //2015.07.20.
|
||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
//{
|
||||
try
|
||||
{
|
||||
PluginMain.Console.sendMessage("§6-- Reloading Auto-flair plugin...§r");
|
||||
PluginMain.LoadFiles(true); //2015.08.09.
|
||||
for(Player p : PluginMain.GetPlayers())
|
||||
{
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
||||
//if(mp.Flair!=null)
|
||||
if(mp.CommentedOnReddit)
|
||||
{
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
||||
}
|
||||
String msg="§9Note: 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.
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
if(player!=null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
//}
|
||||
//else
|
||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static Player ReloadPlayer; //2015.08.09.
|
||||
private static void DoAdmin(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
if(player==null || player.isOp() || player.getName().equals("NorbiPeti"))
|
||||
{
|
||||
//System.out.println("Args length: " + args.length);
|
||||
if(args.length==1)
|
||||
{
|
||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
//args[0] is "admin"
|
||||
switch(args[1].toLowerCase())
|
||||
{
|
||||
case "reload":
|
||||
ReloadPlayer=player; //2015.08.09.
|
||||
SendMessage(player, "§9Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
break; //<-- 2015.08.10.
|
||||
case "confirm":
|
||||
if(ReloadPlayer==player)
|
||||
DoReload(player); //2015.08.09.
|
||||
else
|
||||
SendMessage(player, "§cYou need to do /u admin reload first.§r");
|
||||
break;
|
||||
case "save":
|
||||
PluginMain.SaveFiles(); //2015.08.09.
|
||||
SendMessage(player, "§9Saved files. Now you can edit them and reload if you want.§r");
|
||||
break;
|
||||
case "setflair":
|
||||
DoSetFlair(player, args);
|
||||
break;
|
||||
case "updateplugin": //2015.08.10.
|
||||
DoUpdatePlugin(player);
|
||||
break;
|
||||
default:
|
||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoPlayerInfo(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "playerinfo"
|
||||
if(args.length==2)
|
||||
{
|
||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||
{
|
||||
String message="§cPlayer not found: "+args[2]+"§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
SendMessage(player, "Player name: "+p.PlayerName);
|
||||
SendMessage(player, "User flair: "+p.Flair);
|
||||
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);
|
||||
}
|
||||
private static void SendMessage(Player player, String message)
|
||||
{ //2015.08.09.
|
||||
if(player==null)
|
||||
//System.out.println(message);
|
||||
PluginMain.Console.sendMessage(message); //2015.08.12.
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
private static void DoGetLastError(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "getlasterror"
|
||||
if(PluginMain.LastException!=null)
|
||||
{
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException=null;
|
||||
}
|
||||
else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
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
|
||||
if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName))
|
||||
{
|
||||
SendMessage(player, "§cError removing previous custom flair!§r");
|
||||
return;
|
||||
}
|
||||
File file=new File("customflairs.txt");
|
||||
try {
|
||||
BufferedWriter bw;
|
||||
bw = new BufferedWriter(new FileWriter(file, true));
|
||||
bw.write(targetplayer.PlayerName+targetplayer.Flair+"\n");
|
||||
bw.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
SendMessage(player, "§9The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§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;
|
||||
}
|
||||
SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]);
|
||||
}
|
||||
private static void DoUpdatePlugin(Player player)
|
||||
{ //2015.08.10.
|
||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
||||
System.out.println("Forced updating of Auto-Flair plugin.");
|
||||
URL url;
|
||||
try {
|
||||
url = new URL("https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
||||
FileUtils.copyURLToFile(url, new File("plugins/TheButtonAutoFlair.jar"));
|
||||
SendMessage(player, "Updating done!");
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,298 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if(args.length<1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||
if(!p.CommentedOnReddit && !args[0].toLowerCase().equals("admin"))
|
||||
{
|
||||
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"))
|
||||
{ //2015.08.10.
|
||||
player.sendMessage("Sorry, but your flair isn't recorded. Please ask a mod to set it for you.");
|
||||
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.
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
p.AcceptedFlair=true; //2015.08.08.
|
||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
||||
player.sendMessage("§9Your flair has been set:§r "+flair);
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
break;
|
||||
}
|
||||
case "ignore":
|
||||
{
|
||||
if(p.AcceptedFlair)
|
||||
p.AcceptedFlair=false; //2015.08.08.
|
||||
if(!p.IgnoredFlair)
|
||||
{
|
||||
p.IgnoredFlair=true;
|
||||
//String flair=p.Flair; //2015.08.08.
|
||||
//PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
player.sendMessage("§9You have ignored this request. You can still use /u accept though.§r");
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already ignored this request.§r");
|
||||
break;
|
||||
}
|
||||
/*case "reload": //2015.07.20.
|
||||
DoReload(player);
|
||||
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
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*if(args[0].toLowerCase()=="reload")
|
||||
DoReload(null); //2015.07.20.*/
|
||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); //2015.08.09.
|
||||
return true; //2015.08.09.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static void DoReload(Player player)
|
||||
{ //2015.07.20.
|
||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
//{
|
||||
try
|
||||
{
|
||||
File file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
PluginMain.LoadFiles(true); //2015.08.09.
|
||||
for(Player p : PluginMain.GetPlayers())
|
||||
{
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
||||
//if(mp.Flair!=null)
|
||||
if(mp.CommentedOnReddit)
|
||||
{
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
||||
}
|
||||
String msg="§9Note: 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.
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
if(player!=null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
//}
|
||||
//else
|
||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static Player ReloadPlayer; //2015.08.09.
|
||||
private static void DoAdmin(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
if(player==null || player.isOp() || player.getName().equals("NorbiPeti"))
|
||||
{
|
||||
//System.out.println("Args length: " + args.length);
|
||||
if(args.length==1)
|
||||
{
|
||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
//args[0] is "admin"
|
||||
switch(args[1].toLowerCase())
|
||||
{
|
||||
case "reload":
|
||||
ReloadPlayer=player; //2015.08.09.
|
||||
SendMessage(player, "§9Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
break; //<-- 2015.08.10.
|
||||
case "confirm":
|
||||
if(ReloadPlayer==player)
|
||||
DoReload(player); //2015.08.09.
|
||||
else
|
||||
SendMessage(player, "§cYou need to do /u admin reload first.§r");
|
||||
break;
|
||||
case "save":
|
||||
PluginMain.SaveFiles(); //2015.08.09.
|
||||
SendMessage(player, "§9Saved files. Now you can edit them and reload if you want.§r");
|
||||
break;
|
||||
case "setflair":
|
||||
DoSetFlair(player, args);
|
||||
break;
|
||||
case "updateplugin": //2015.08.10.
|
||||
DoUpdatePlugin(player);
|
||||
break;
|
||||
default:
|
||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoPlayerInfo(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "playerinfo"
|
||||
if(args.length==2)
|
||||
{
|
||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||
{
|
||||
String message="§cPlayer not found: "+args[2]+"§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
SendMessage(player, "Player name: "+p.PlayerName);
|
||||
SendMessage(player, "User flair: "+p.Flair);
|
||||
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);
|
||||
}
|
||||
private static void SendMessage(Player player, String message)
|
||||
{ //2015.08.09.
|
||||
if(player==null)
|
||||
//System.out.println(message);
|
||||
PluginMain.Console.sendMessage(message); //2015.08.12.
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
private static void DoGetLastError(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "getlasterror"
|
||||
if(PluginMain.LastException!=null)
|
||||
{
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException=null;
|
||||
}
|
||||
else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
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
|
||||
if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName))
|
||||
{
|
||||
SendMessage(player, "§cError removing previous custom flair!§r");
|
||||
return;
|
||||
}
|
||||
File file=new File("customflairs.txt");
|
||||
try {
|
||||
BufferedWriter bw;
|
||||
bw = new BufferedWriter(new FileWriter(file, true));
|
||||
bw.write(targetplayer.PlayerName+targetplayer.Flair+"\n");
|
||||
bw.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
SendMessage(player, "§9The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§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;
|
||||
}
|
||||
SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]);
|
||||
}
|
||||
private static void DoUpdatePlugin(Player player)
|
||||
{ //2015.08.10.
|
||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
||||
System.out.println("Forced updating of Auto-Flair plugin.");
|
||||
URL url;
|
||||
try {
|
||||
url = new URL("https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
||||
FileUtils.copyURLToFile(url, new File("plugins/TheButtonAutoFlair.jar"));
|
||||
SendMessage(player, "Updating done!");
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,363 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
|
||||
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/
|
||||
private static PluginMain Instance;
|
||||
// Fired when plugin is first enabled
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
this.getCommand("u").setExecutor(new Commands());
|
||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||
Instance=this; //2015.08.08.
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
//System.out.println("Name: " + name);
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("flairsignored.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while((line=br.readLine())!=null)
|
||||
{
|
||||
String[] s=line.split(" ");
|
||||
TownColors.put(s[0], s[1]);
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
//throw new IOException("Test"); //2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||
Thread t=new Thread(r);
|
||||
t.start();
|
||||
}
|
||||
Boolean stop=false;
|
||||
// Fired when plugin is disabled
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
try
|
||||
{
|
||||
FileWriter fw;
|
||||
fw = new FileWriter("flairsaccepted.txt");
|
||||
fw.close();
|
||||
fw = new FileWriter("flairsignored.txt");
|
||||
fw.close();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.AcceptedFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
file=new File("flairsignored.txt");
|
||||
bw = new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.IgnoredFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
stop=true;
|
||||
}
|
||||
|
||||
public void ThreadMethod() //<-- 2015.07.16.
|
||||
{
|
||||
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();
|
||||
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();
|
||||
if(HasIGFlair(ign))
|
||||
continue;
|
||||
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";
|
||||
else
|
||||
flair = "non-presser";
|
||||
String flairclass;
|
||||
if(flairdata.length>2)
|
||||
flairclass = flairdata[2];
|
||||
else
|
||||
flairclass="unknown";
|
||||
SetFlair(ign, flair, flairclass, author);
|
||||
}
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Exception LastException; //2015.08.09.
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||
public Boolean HasIGFlair(String playername)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
return p.Flair!=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
String finalflair;
|
||||
p.FlairDecided=true;
|
||||
switch(flairclass)
|
||||
{
|
||||
case "press-1":
|
||||
finalflair="§c("+text+")§r";
|
||||
break;
|
||||
case "press-2":
|
||||
finalflair="§6("+text+")§r";
|
||||
break;
|
||||
case "press-3":
|
||||
finalflair="§e("+text+")§r";
|
||||
break;
|
||||
case "press-4":
|
||||
finalflair="§a("+text+")§r";
|
||||
break;
|
||||
case "press-5":
|
||||
finalflair="§9("+text+")§r";
|
||||
break;
|
||||
case "press-6":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "no-press":
|
||||
finalflair="§7(non-pr.)§r";
|
||||
break;
|
||||
case "cheater":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "cant-press": //2015.08.08.
|
||||
finalflair="§r(can't press)§r";
|
||||
break;
|
||||
case "undecided": //2015.08.09.
|
||||
p.FlairDecided=false;
|
||||
finalflair="";
|
||||
break;
|
||||
default:
|
||||
finalflair="";
|
||||
break;
|
||||
}
|
||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||
return;
|
||||
p.Flair=finalflair; //2015.08.08.
|
||||
p.UserName=username; //2015.08.08.
|
||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||
{
|
||||
if(player.getName().equals(playername))
|
||||
{
|
||||
//AppendPlayerDisplayFlair(player, username, finalflair);
|
||||
AppendPlayerDisplayFlair(p, player);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String GetFlair(Player player)
|
||||
{ //2015.07.16.
|
||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||
return flair==null ? "" : flair;
|
||||
}
|
||||
|
||||
//public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||
public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09.
|
||||
{
|
||||
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair)
|
||||
return;
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair)
|
||||
{
|
||||
AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20.
|
||||
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
|
||||
player.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r");
|
||||
}
|
||||
|
||||
private static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||
String[] colors = color.substring(1).split("§");
|
||||
String displayname=player.getName(); //2015.08.08.
|
||||
ArrayList<Integer> Positions=new ArrayList<>();
|
||||
for(int i=0; i<displayname.length(); i++) {
|
||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||
Positions.add(i);
|
||||
}
|
||||
}
|
||||
String finalname=""; //TODO
|
||||
if(Positions.size()>=colors.length)
|
||||
{
|
||||
int x=0;
|
||||
for(int i=0; i<Positions.size(); i++)
|
||||
{
|
||||
int pos=Positions.get(i);
|
||||
int nextpos;
|
||||
if(i!=Positions.size()-1)
|
||||
nextpos=Positions.get(i+1);
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Positions.clear();
|
||||
int unit=displayname.length()/colors.length;
|
||||
int x=0;
|
||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||
{
|
||||
int pos=i;
|
||||
int nextpos;
|
||||
if(i<displayname.length()-unit-unit)
|
||||
nextpos=i+unit;
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||
}
|
||||
|
||||
public static String GetColorForTown(String townname)
|
||||
{ //2015.07.20.
|
||||
if(TownColors.containsKey(townname))
|
||||
return TownColors.get(townname);
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String GetPlayerTown(Player player)
|
||||
{ //2015.07.20.
|
||||
try {
|
||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||
return town.getName();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public static Collection<? extends Player> GetPlayers()
|
||||
{
|
||||
return Instance.getServer().getOnlinePlayers();
|
||||
}
|
||||
}
|
|
@ -1,318 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerChatTabCompleteEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import au.com.mineauz.minigames.Minigames;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerListener implements Listener { // 2015.07.16.
|
||||
public static HashMap<String, UUID> nicknames = new HashMap<>();
|
||||
|
||||
public static boolean Enable = false; // 2015.08.29.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
final MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p
|
||||
.getUniqueId());
|
||||
mp.PlayerName = p.getName(); // 2015.10.17. 0:58
|
||||
if (mp.CommentedOnReddit && !mp.PlayerName.equals("NorbiPeti"))
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); // 2015.08.09.
|
||||
else { // 2015.07.20.
|
||||
Timer timer = new Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!mp.IgnoredFlair) {
|
||||
String json = "[\"\",{\"text\":\"If you'd like your 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,
|
||||
"tellraw " + mp.PlayerName + " " + json);
|
||||
json = "[\"\",{\"text\":\"If you don't want the flair, type /u ignore to prevent this message after next login.\",\"color\":\"aqua\"}]";
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Console,
|
||||
"tellraw " + mp.PlayerName + " " + json);
|
||||
}
|
||||
}
|
||||
}, 15 * 1000);
|
||||
}
|
||||
|
||||
/* NICKNAME LOGIC */
|
||||
|
||||
UUID id = p.getUniqueId();
|
||||
|
||||
File f = new File("plugins/Essentials/userdata/" + id + ".yml");
|
||||
if (f.exists()) {
|
||||
YamlConfiguration yc = new YamlConfiguration();
|
||||
try {
|
||||
yc.load(f);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String nickname = yc.getString("nickname");
|
||||
if (nickname != null) {
|
||||
nicknames.put(nickname, id);
|
||||
|
||||
if (Enable) {
|
||||
if (!p.getName().equals("NorbiPeti")) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.chat("Hey, " + nickname + "!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mp.RPMode = true; // 2015.08.25.
|
||||
|
||||
if (p.getName().equals("FigyTuna") && Commands.PluginUpdated)
|
||||
p.sendMessage("§bThe The Button MC plugin got updated. Please restart the server. :P§r");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
String deletenick = null;
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
UUID uuid = nicknames.get(nickname);
|
||||
if (event.getPlayer().getUniqueId().equals(uuid)) {
|
||||
deletenick = nickname;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (deletenick != null)
|
||||
nicknames.remove(deletenick);
|
||||
}
|
||||
|
||||
public static String NotificationSound; // 2015.08.14.
|
||||
public static double NotificationPitch; // 2015.08.14.
|
||||
|
||||
public static boolean ShowRPTag = false; // 2015.08.31.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.GetFromName(event
|
||||
.getPlayer().getName());
|
||||
String flair = player.Flair; // 2015.08.08.
|
||||
if (player.IgnoredFlair)
|
||||
flair = "";
|
||||
String message = event.getMessage(); // 2015.08.08.
|
||||
for (Player p : PluginMain.GetPlayers()) { // 2015.08.12.
|
||||
String color = ""; // 2015.08.17.
|
||||
if (message.contains(p.getName())) {
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(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);
|
||||
}
|
||||
|
||||
message = message.replaceAll(p.getName(), color + p.getName()
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
for (String n : nicknames.keySet()) {
|
||||
Player p = null;
|
||||
String nwithoutformatting = new String(n);
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (message.contains(nwithoutformatting)) {
|
||||
p = Bukkit.getPlayer(nicknames.get(n));
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(float) NotificationPitch); // 2015.08.14.
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()); // 2015.08.17.
|
||||
}
|
||||
if (p != null) {
|
||||
message = message.replaceAll(nwithoutformatting, n
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
}
|
||||
|
||||
event.setMessage(message); // 2015.09.05.
|
||||
|
||||
event.setFormat(event
|
||||
.getFormat()
|
||||
.replace(
|
||||
"{rptag}",
|
||||
(player.RPMode ? (ShowRPTag ? "§2[RP]§r" : "")
|
||||
: "§8[OOC]§r"))
|
||||
.replace("{buttonflair}", flair)
|
||||
.replace(
|
||||
"{isitwilds}",
|
||||
(event.getPlayer().getWorld().getName()
|
||||
.equalsIgnoreCase("wilds") ? "[PVP]" : ""))); // 2015.09.04.
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTabComplete(PlayerChatTabCompleteEvent e) {
|
||||
String name = e.getLastToken();
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
String nwithoutformatting = nickname;
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (nwithoutformatting.startsWith(name)
|
||||
&& !nwithoutformatting.equals(Bukkit.getPlayer(
|
||||
nicknames.get(nickname)).getName()))
|
||||
e.getTabCompletions().add(nwithoutformatting);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean DebugMode = false;
|
||||
|
||||
public void SendForDebug(String message) {
|
||||
if (DebugMode) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.sendMessage("[DEBUG] " + message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean ActiveF = false;
|
||||
private int FCount = 0;
|
||||
private long FTime;
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMessage(AsyncPlayerChatEvent e) {
|
||||
if (ActiveF) {
|
||||
if (System.currentTimeMillis() - FTime > 10000) {
|
||||
ActiveF = false;
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
p.sendMessage("§b" + FCount + " "
|
||||
+ (FCount == 1 ? "person" : "people")
|
||||
+ " paid their respects.§r");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e.getMessage().equalsIgnoreCase("F")) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(e
|
||||
.getPlayer().getName());
|
||||
if (!mp.PressedF && ActiveF) {
|
||||
FCount++;
|
||||
mp.PressedF = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (e.getMessage().startsWith(">"))
|
||||
e.setMessage("§2" + e.getMessage());
|
||||
|
||||
/*
|
||||
* Channel c = ((Chat) Bukkit.getPluginManager().getPlugin("TownyChat"))
|
||||
* .getChannelsHandler().getActiveChannel(e.getPlayer(),
|
||||
* channelTypes.GLOBAL);
|
||||
*/
|
||||
/*
|
||||
* List<String> modes = ((Chat) Bukkit.getPluginManager().getPlugin(
|
||||
* "TownyChat")).getTowny().getPlayerMode(e.getPlayer()); if
|
||||
* (modes.size() == 0 || modes.contains("g")) {
|
||||
*/
|
||||
if (e.getFormat().contains("[g]")) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("tellraw @a [\"\"");
|
||||
sb.append(",{\"text\":\"Hashtags:\"}");
|
||||
int index = -1;
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
while ((index = e.getMessage().indexOf("#", index + 1)) != -1) {
|
||||
int index2 = e.getMessage().indexOf(" ", index + 1);
|
||||
if (index2 == -1)
|
||||
index2 = e.getMessage().length();
|
||||
int index3 = e.getMessage().indexOf("#", index + 1);
|
||||
if (index3 != -1 && index3 < index2) // A # occurs before a
|
||||
// space
|
||||
index2 = index3;
|
||||
String original = e.getMessage().substring(index, index2);
|
||||
list.add(original);
|
||||
sb.append(",{\"text\":\" \"}");
|
||||
sb.append(",{\"text\":\"");
|
||||
sb.append(original);
|
||||
sb.append("\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://twitter.com/hashtag/");
|
||||
sb.append(original.substring(1));
|
||||
sb.append("\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open on Twitter\",\"color\":\"blue\"}]}}}");
|
||||
}
|
||||
for (String original : list)
|
||||
e.setMessage(e.getMessage().replace(
|
||||
original,
|
||||
"§9"
|
||||
+ original
|
||||
+ (e.getMessage().startsWith("§2>") ? "§2"
|
||||
: "§r")));
|
||||
/*
|
||||
* for (String original : list)
|
||||
* System.out.println(e.getMessage().replace( original, "§9" +
|
||||
* original + (e.getMessage().startsWith("§2>") ? "§2" : "§r")));
|
||||
*/
|
||||
|
||||
sb.append("]");
|
||||
|
||||
if (list.size() > 0)
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Instance.getServer().getConsoleSender(),
|
||||
sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDeath(PlayerDeathEvent e) {
|
||||
if (!Minigames.plugin.pdata.getMinigamePlayer(e.getEntity())
|
||||
.isInMinigame() && new Random().nextBoolean()) {
|
||||
ActiveF = true;
|
||||
FCount = 0;
|
||||
FTime = System.currentTimeMillis();
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(p
|
||||
.getName());
|
||||
mp.PressedF = false;
|
||||
p.sendMessage("§bPress F to pay respects.§r");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,297 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if(args.length<1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||
if(!p.CommentedOnReddit && !args[0].toLowerCase().equals("admin"))
|
||||
{
|
||||
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"))
|
||||
{ //2015.08.10.
|
||||
player.sendMessage("Sorry, but your flair isn't recorded. Please ask a mod to set it for you.");
|
||||
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.
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
p.AcceptedFlair=true; //2015.08.08.
|
||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
||||
player.sendMessage("§9Your flair has been set:§r "+flair);
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
break;
|
||||
}
|
||||
case "ignore":
|
||||
{
|
||||
if(p.AcceptedFlair)
|
||||
p.AcceptedFlair=false; //2015.08.08.
|
||||
if(!p.IgnoredFlair)
|
||||
{
|
||||
p.IgnoredFlair=true;
|
||||
//String flair=p.Flair; //2015.08.08.
|
||||
//PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
player.sendMessage("§9You have ignored this request. You can still use /u accept though.§r");
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already ignored this request.§r");
|
||||
break;
|
||||
}
|
||||
/*case "reload": //2015.07.20.
|
||||
DoReload(player);
|
||||
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
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*if(args[0].toLowerCase()=="reload")
|
||||
DoReload(null); //2015.07.20.*/
|
||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); //2015.08.09.
|
||||
return true; //2015.08.09.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static void DoReload(Player player)
|
||||
{ //2015.07.20.
|
||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
//{
|
||||
try
|
||||
{
|
||||
File file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
PluginMain.LoadFiles(true); //2015.08.09.
|
||||
for(Player p : PluginMain.GetPlayers())
|
||||
{
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
||||
//if(mp.Flair!=null)
|
||||
if(mp.CommentedOnReddit)
|
||||
{
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
||||
}
|
||||
String msg="§9Note: 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.
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
if(player!=null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
//}
|
||||
//else
|
||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static Player ReloadPlayer; //2015.08.09.
|
||||
private static void DoAdmin(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
if(player==null || player.isOp() || player.getName().equals("NorbiPeti"))
|
||||
{
|
||||
//System.out.println("Args length: " + args.length);
|
||||
if(args.length==1)
|
||||
{
|
||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
//args[0] is "admin"
|
||||
switch(args[1].toLowerCase())
|
||||
{
|
||||
case "reload":
|
||||
ReloadPlayer=player; //2015.08.09.
|
||||
SendMessage(player, "§9Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
break; //<-- 2015.08.10.
|
||||
case "confirm":
|
||||
if(ReloadPlayer==player)
|
||||
DoReload(player); //2015.08.09.
|
||||
else
|
||||
SendMessage(player, "§cYou need to do /u admin reload first.§r");
|
||||
break;
|
||||
case "save":
|
||||
PluginMain.SaveFiles(); //2015.08.09.
|
||||
SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r");
|
||||
break;
|
||||
case "setflair":
|
||||
DoSetFlair(player, args);
|
||||
break;
|
||||
case "updateplugin": //2015.08.10.
|
||||
DoUpdatePlugin(player);
|
||||
break;
|
||||
default:
|
||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoPlayerInfo(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "playerinfo"
|
||||
if(args.length==2)
|
||||
{
|
||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||
{
|
||||
String message="§cPlayer not found: "+args[2]+"§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
SendMessage(player, "Player name: "+p.PlayerName);
|
||||
SendMessage(player, "User flair: "+p.Flair);
|
||||
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);
|
||||
}
|
||||
private static void SendMessage(Player player, String message)
|
||||
{ //2015.08.09.
|
||||
if(player==null)
|
||||
System.out.println(message);
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
private static void DoGetLastError(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "getlasterror"
|
||||
if(PluginMain.LastException!=null)
|
||||
{
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException=null;
|
||||
}
|
||||
else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
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
|
||||
if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName))
|
||||
{
|
||||
SendMessage(player, "§cError removing previous custom flair!§r");
|
||||
return;
|
||||
}
|
||||
File file=new File("customflairs.txt");
|
||||
try {
|
||||
BufferedWriter bw;
|
||||
bw = new BufferedWriter(new FileWriter(file, true));
|
||||
bw.write(targetplayer.PlayerName+targetplayer.Flair+"\n");
|
||||
bw.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
SendMessage(player, "§9The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§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;
|
||||
}
|
||||
SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]);
|
||||
}
|
||||
private static void DoUpdatePlugin(Player player)
|
||||
{ //2015.08.10.
|
||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
||||
System.out.println("Forced updating of Auto-Flair plugin.");
|
||||
URL url;
|
||||
try {
|
||||
url = new URL("https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
||||
FileUtils.copyURLToFile(url, new File("plugins/TheButtonAutoFlair.jar"));
|
||||
SendMessage(player, "Updating done!");
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class PlayerJoinTimerTask extends TimerTask {
|
||||
|
||||
}
|
|
@ -1,306 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.String;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
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/
|
||||
public static PluginMain Instance;
|
||||
public static ConsoleCommandSender Console; // 2015.08.12.
|
||||
|
||||
// Fired when plugin is first enabled
|
||||
@Override
|
||||
public void onEnable() {
|
||||
System.out.println("The Button Minecraft server plugin");
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(),
|
||||
this);
|
||||
Commands comm = new Commands();
|
||||
this.getCommand("u").setExecutor(comm);
|
||||
this.getCommand("u").setUsage(
|
||||
this.getCommand("u").getUsage().replace('&', '§'));
|
||||
this.getCommand("nrp").setExecutor(comm);
|
||||
this.getCommand("nrp").setUsage(
|
||||
this.getCommand("nrp").getUsage().replace('&', '§'));
|
||||
this.getCommand("ooc").setExecutor(comm);
|
||||
this.getCommand("ooc").setUsage(
|
||||
this.getCommand("ooc").getUsage().replace('&', '§'));
|
||||
this.getCommand("skype").setExecutor(comm);
|
||||
Instance = this; // 2015.08.08.
|
||||
Console = this.getServer().getConsoleSender(); // 2015.08.12.
|
||||
LoadFiles(false); // 2015.08.09.
|
||||
Runnable r = new Runnable() {
|
||||
public void run() {
|
||||
ThreadMethod();
|
||||
}
|
||||
};
|
||||
Thread t = new Thread(r);
|
||||
t.start();
|
||||
r = new Runnable() {
|
||||
public void run() {
|
||||
AnnouncerThread.Run();
|
||||
}
|
||||
};
|
||||
t = new Thread(r);
|
||||
t.start();
|
||||
}
|
||||
|
||||
public Boolean stop = false;
|
||||
|
||||
// Fired when plugin is disabled
|
||||
@Override
|
||||
public void onDisable() {
|
||||
SaveFiles(); // 2015.08.09.
|
||||
stop = true;
|
||||
}
|
||||
|
||||
public void ThreadMethod() // <-- 2015.07.16.
|
||||
{
|
||||
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();
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(ign);
|
||||
if (mp == null)
|
||||
continue;
|
||||
if (HasIGFlair(mp.UUID))
|
||||
continue;
|
||||
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);
|
||||
} catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// System.out.println("Error!\n" + e);
|
||||
LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Exception LastException; // 2015.08.09.
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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,
|
||||
String username) {
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AddPlayerIfNeeded(uuid); // 2015.08.08.
|
||||
String finalflair;
|
||||
p.FlairDecided = true;
|
||||
p.FlairRecognised = true;
|
||||
switch (flairclass) {
|
||||
case "press-1":
|
||||
finalflair = "§c(" + text + ")§r";
|
||||
break;
|
||||
case "press-2":
|
||||
finalflair = "§6(" + text + ")§r";
|
||||
break;
|
||||
case "press-3":
|
||||
finalflair = "§e(" + text + ")§r";
|
||||
break;
|
||||
case "press-4":
|
||||
finalflair = "§a(" + text + ")§r";
|
||||
break;
|
||||
case "press-5":
|
||||
finalflair = "§9(" + text + ")§r";
|
||||
break;
|
||||
case "press-6":
|
||||
finalflair = "§5(" + text + ")§r";
|
||||
break;
|
||||
case "no-press":
|
||||
finalflair = "§7(--s)§r";
|
||||
break;
|
||||
case "cheater":
|
||||
finalflair = "§5(" + text + ")§r";
|
||||
break;
|
||||
case "cant-press": // 2015.08.08.
|
||||
finalflair = "§r(??s)§r";
|
||||
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;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
p.Flair = finalflair; // 2015.08.08.
|
||||
p.CommentedOnReddit = true; // 2015.08.10.
|
||||
p.UserName = username; // 2015.08.08.
|
||||
System.out.println("Added flair for " + p.PlayerName);
|
||||
AppendPlayerDisplayFlair(p, Bukkit.getPlayer(uuid));
|
||||
}
|
||||
|
||||
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 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 Collection<? extends Player> GetPlayers() {
|
||||
return Instance.getServer().getOnlinePlayers();
|
||||
}
|
||||
|
||||
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.
|
||||
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.
|
||||
try {
|
||||
File file = new File("announcemessages.txt");
|
||||
if (file.exists())
|
||||
file.delete();
|
||||
file = new File("flairsaccepted.txt");
|
||||
if (file.exists())
|
||||
file.delete();
|
||||
file = new File("flairsignored.txt");
|
||||
if (file.exists())
|
||||
file.delete();
|
||||
file = new File("thebuttonmc.yml");
|
||||
if (file.exists()) {
|
||||
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"));
|
||||
Commands.Quiz.addAll(yc.getStringList("quiz"));
|
||||
}
|
||||
System.out.println("The Button Minecraft plugin loaded files!");
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
LastException = e; // 2015.08.09.
|
||||
} catch (InvalidConfigurationException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
public static void SaveFiles() // <-- 2015.08.09.
|
||||
{
|
||||
System.out.println("Saving files for The Button Minecraft plugin..."); // 2015.08.09.
|
||||
try {
|
||||
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);
|
||||
yc.set("quiz", Commands.Quiz);
|
||||
yc.save(file);
|
||||
System.out.println("The Button Minecraft plugin saved files!");
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,215 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if(args.length<1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||
if(p.Flair==null)
|
||||
{
|
||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||
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.
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
||||
p.AcceptedFlair=true; //2015.08.08.
|
||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
break;
|
||||
}
|
||||
case "ignore":
|
||||
{
|
||||
if(p.AcceptedFlair)
|
||||
p.AcceptedFlair=false; //2015.08.08.
|
||||
if(!p.IgnoredFlair)
|
||||
{
|
||||
p.IgnoredFlair=true;
|
||||
String flair=p.Flair; //2015.08.08.
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already ignored this request.§r");
|
||||
break;
|
||||
}
|
||||
/*case "reload": //2015.07.20.
|
||||
DoReload(player);
|
||||
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;
|
||||
}
|
||||
p.Flair="§7(non-pr.)§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.§r");
|
||||
break;
|
||||
}
|
||||
p.Flair="§r(can't press)§r";
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*if(args[0].toLowerCase()=="reload")
|
||||
DoReload(null); //2015.07.20.*/
|
||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); //2015.08.09.
|
||||
return true; //2015.08.09.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static void DoReload(Player player)
|
||||
{ //2015.07.20.
|
||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
//{
|
||||
try
|
||||
{
|
||||
File file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
PluginMain.LoadFiles(true);
|
||||
for(Player p : PluginMain.GetPlayers())
|
||||
{
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||
if(mp.Flair!=null)
|
||||
{
|
||||
String flair=mp.Flair;
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
||||
}
|
||||
}
|
||||
//String msg="§6Reloaded config file.§r";
|
||||
String msg="§6Reloaded all files.§r";
|
||||
SendMessage(player, msg); //2015.08.09.
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
if(player!=null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
//}
|
||||
//else
|
||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoAdmin(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
{
|
||||
//System.out.println("Args length: " + args.length);
|
||||
if(args.length==1)
|
||||
{
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
//args[0] is "admin"
|
||||
switch(args[1].toLowerCase())
|
||||
{
|
||||
case "reload":
|
||||
DoReload(player);
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
default:
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoPlayerInfo(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "playerinfo"
|
||||
if(args.length==2)
|
||||
{
|
||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||
{
|
||||
String message="§cPlayer not found: "+args[2]+"§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
SendMessage(player, "Player name: "+p.PlayerName);
|
||||
SendMessage(player, "User flair: "+p.Flair);
|
||||
SendMessage(player, "Username: "+p.UserName);
|
||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
||||
}
|
||||
private static void SendMessage(Player player, String message)
|
||||
{ //2015.08.09.
|
||||
if(player==null)
|
||||
System.out.println(message);
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
private static void DoGetLastError(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "getlasterror"
|
||||
if(PluginMain.LastException!=null)
|
||||
{
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException=null;
|
||||
}
|
||||
else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
}
|
|
@ -1,345 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
|
||||
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/
|
||||
private static PluginMain Instance;
|
||||
// Fired when plugin is first enabled
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
this.getCommand("u").setExecutor(new Commands());
|
||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||
Instance=this; //2015.08.08.
|
||||
LoadFiles(false); //2015.08.09.
|
||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||
Thread t=new Thread(r);
|
||||
t.start();
|
||||
}
|
||||
Boolean stop=false;
|
||||
// Fired when plugin is disabled
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
SaveFiles(); //2015.08.09.
|
||||
stop=true;
|
||||
}
|
||||
|
||||
public void ThreadMethod() //<-- 2015.07.16.
|
||||
{
|
||||
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();
|
||||
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();
|
||||
if(HasIGFlair(ign))
|
||||
continue;
|
||||
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";
|
||||
else
|
||||
flair = "non-presser";
|
||||
String flairclass;
|
||||
if(flairdata.length>2)
|
||||
flairclass = flairdata[2];
|
||||
else
|
||||
flairclass="unknown";
|
||||
SetFlair(ign, flair, flairclass, author);
|
||||
}
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Exception LastException; //2015.08.09.
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||
public Boolean HasIGFlair(String playername)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
return p.Flair!=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
String finalflair;
|
||||
p.FlairDecided=true;
|
||||
switch(flairclass)
|
||||
{
|
||||
case "press-1":
|
||||
finalflair="§c("+text+")§r";
|
||||
break;
|
||||
case "press-2":
|
||||
finalflair="§6("+text+")§r";
|
||||
break;
|
||||
case "press-3":
|
||||
finalflair="§e("+text+")§r";
|
||||
break;
|
||||
case "press-4":
|
||||
finalflair="§a("+text+")§r";
|
||||
break;
|
||||
case "press-5":
|
||||
finalflair="§9("+text+")§r";
|
||||
break;
|
||||
case "press-6":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "no-press":
|
||||
finalflair="§7(non-pr.)§r";
|
||||
break;
|
||||
case "cheater":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "cant-press": //2015.08.08.
|
||||
finalflair="§r(can't press)§r";
|
||||
break;
|
||||
case "undecided": //2015.08.09.
|
||||
p.FlairDecided=false;
|
||||
finalflair="";
|
||||
break;
|
||||
default:
|
||||
finalflair="";
|
||||
break;
|
||||
}
|
||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||
return;
|
||||
p.Flair=finalflair; //2015.08.08.
|
||||
p.UserName=username; //2015.08.08.
|
||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||
{
|
||||
if(player.getName().equals(playername))
|
||||
{
|
||||
//AppendPlayerDisplayFlair(player, username, finalflair);
|
||||
AppendPlayerDisplayFlair(p, player);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String GetFlair(Player player)
|
||||
{ //2015.07.16.
|
||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||
return flair==null ? "" : flair;
|
||||
}
|
||||
|
||||
//public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||
public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09.
|
||||
{
|
||||
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair)
|
||||
return;
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair)
|
||||
{
|
||||
AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20.
|
||||
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");
|
||||
}
|
||||
|
||||
private static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||
String[] colors = color.substring(1).split("§");
|
||||
String displayname=player.getName(); //2015.08.08.
|
||||
ArrayList<Integer> Positions=new ArrayList<>();
|
||||
for(int i=0; i<displayname.length(); i++) {
|
||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||
Positions.add(i);
|
||||
}
|
||||
}
|
||||
String finalname=""; //TODO
|
||||
if(Positions.size()>=colors.length)
|
||||
{
|
||||
int x=0;
|
||||
for(int i=0; i<Positions.size(); i++)
|
||||
{
|
||||
int pos=Positions.get(i);
|
||||
int nextpos;
|
||||
if(i!=Positions.size()-1)
|
||||
nextpos=Positions.get(i+1);
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Positions.clear();
|
||||
int unit=displayname.length()/colors.length;
|
||||
int x=0;
|
||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||
{
|
||||
int pos=i;
|
||||
int nextpos;
|
||||
if(i<displayname.length()-unit-unit)
|
||||
nextpos=i+unit;
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||
}
|
||||
|
||||
public static String GetColorForTown(String townname)
|
||||
{ //2015.07.20.
|
||||
if(TownColors.containsKey(townname))
|
||||
return TownColors.get(townname);
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String GetPlayerTown(Player player)
|
||||
{ //2015.07.20.
|
||||
try {
|
||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||
return town.getName();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public static Collection<? extends Player> GetPlayers()
|
||||
{
|
||||
return Instance.getServer().getOnlinePlayers();
|
||||
}
|
||||
|
||||
public static void LoadFiles(boolean reload) //<-- 2015.08.09.
|
||||
{
|
||||
if(reload)
|
||||
{ //2015.08.09.
|
||||
System.out.println("Auto-flair plugin cleanup for reloading...");
|
||||
MaybeOfflinePlayer.AllPlayers.clear();
|
||||
TownColors.clear();
|
||||
}
|
||||
System.out.println("Loading files for auto-flair plugin..."); //2015.08.09.
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
//System.out.println("Name: " + name);
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("flairsignored.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while((line=br.readLine())!=null)
|
||||
{
|
||||
String[] s=line.split(" ");
|
||||
TownColors.put(s[0], s[1]);
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
//throw new IOException("Test"); //2015.08.09.
|
||||
System.out.println("Auto-flair plugin loaded files!");
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
public static void SaveFiles() //<-- 2015.08.09.
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
name: TheButtonMCPlugin
|
||||
main: tk.sznp.thebuttonautoflair.PluginMain
|
||||
version: 2.0
|
||||
commands:
|
||||
u:
|
||||
description: Auto-flair system. Accept or ignore flair.
|
||||
usage: "&cUsage: /u accept|ignore|opme&r"
|
||||
nrp:
|
||||
description: Send message in Out-of-Character
|
||||
usage: "&cUsage: /nrp <message>&r"
|
||||
ooc:
|
||||
description: Send message in Out-of-Character
|
||||
usage: "&cUsage: /ooc <message>&r"
|
||||
author: NorbiPeti
|
||||
depend: [Essentials, Towny]
|
|
@ -1,322 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerChatTabCompleteEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import au.com.mineauz.minigames.Minigames;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerListener implements Listener { // 2015.07.16.
|
||||
public static HashMap<String, UUID> nicknames = new HashMap<>();
|
||||
|
||||
public static boolean Enable = false; // 2015.08.29.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p
|
||||
.getUniqueId());
|
||||
mp.PlayerName = p.getName(); // 2015.10.17. 0:58
|
||||
// if (mp.CommentedOnReddit)
|
||||
if (false)
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); // 2015.08.09.
|
||||
else { // 2015.07.20.
|
||||
Timer timer = new Timer();
|
||||
TimerTask tt=new TimerTask() {
|
||||
public MaybeOfflinePlayer mp;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!mp.IgnoredFlair) {
|
||||
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,
|
||||
"tellraw " + mp.PlayerName + " " + json);
|
||||
json = "[\"\",{\"text\":\"If you don't want the flair, type /u ignore to prevent this message after next login.\",\"color\":\"aqua\"}]";
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Console,
|
||||
"tellraw " + mp.PlayerName + " " + json);
|
||||
}
|
||||
}
|
||||
}
|
||||
timer.schedule(tt, 15 * 1000);
|
||||
}
|
||||
|
||||
/* NICKNAME LOGIC */
|
||||
|
||||
UUID id = p.getUniqueId();
|
||||
|
||||
File f = new File("plugins/Essentials/userdata/" + id + ".yml");
|
||||
if (f.exists()) {
|
||||
YamlConfiguration yc = new YamlConfiguration();
|
||||
try {
|
||||
yc.load(f);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String nickname = yc.getString("nickname");
|
||||
if (nickname != null) {
|
||||
nicknames.put(nickname, id);
|
||||
|
||||
if (Enable) {
|
||||
if (!p.getName().equals("NorbiPeti")) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.chat("Hey, " + nickname + "!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mp.RPMode = true; // 2015.08.25.
|
||||
|
||||
if (p.getName().equals("FigyTuna") && Commands.PluginUpdated)
|
||||
p.sendMessage("§bThe The Button MC plugin got updated. Please restart the server. :P§r");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
String deletenick = null;
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
UUID uuid = nicknames.get(nickname);
|
||||
if (event.getPlayer().getUniqueId().equals(uuid)) {
|
||||
deletenick = nickname;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (deletenick != null)
|
||||
nicknames.remove(deletenick);
|
||||
}
|
||||
|
||||
public static String NotificationSound; // 2015.08.14.
|
||||
public static double NotificationPitch; // 2015.08.14.
|
||||
|
||||
public static boolean ShowRPTag = false; // 2015.08.31.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.GetFromName(event
|
||||
.getPlayer().getName());
|
||||
String flair = player.Flair; // 2015.08.08.
|
||||
if (player.IgnoredFlair)
|
||||
flair = "";
|
||||
String message = event.getMessage(); // 2015.08.08.
|
||||
for (Player p : PluginMain.GetPlayers()) { // 2015.08.12.
|
||||
String color = ""; // 2015.08.17.
|
||||
if (message.contains(p.getName())) {
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(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);
|
||||
}
|
||||
|
||||
message = message.replaceAll(p.getName(), color + p.getName()
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
for (String n : nicknames.keySet()) {
|
||||
Player p = null;
|
||||
String nwithoutformatting = new String(n);
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (message.contains(nwithoutformatting)) {
|
||||
p = Bukkit.getPlayer(nicknames.get(n));
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(float) NotificationPitch); // 2015.08.14.
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()); // 2015.08.17.
|
||||
}
|
||||
if (p != null) {
|
||||
message = message.replaceAll(nwithoutformatting, n
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
}
|
||||
|
||||
event.setMessage(message); // 2015.09.05.
|
||||
|
||||
event.setFormat(event
|
||||
.getFormat()
|
||||
.replace(
|
||||
"{rptag}",
|
||||
(player.RPMode ? (ShowRPTag ? "§2[RP]§r" : "")
|
||||
: "§8[OOC]§r"))
|
||||
.replace("{buttonflair}", flair)
|
||||
.replace(
|
||||
"{isitwilds}",
|
||||
(event.getPlayer().getWorld().getName()
|
||||
.equalsIgnoreCase("wilds") ? "[PVP]" : ""))); // 2015.09.04.
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTabComplete(PlayerChatTabCompleteEvent e) {
|
||||
String name = e.getLastToken();
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
String nwithoutformatting = nickname;
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (nwithoutformatting.startsWith(name)
|
||||
&& !nwithoutformatting.equals(Bukkit.getPlayer(
|
||||
nicknames.get(nickname)).getName()))
|
||||
e.getTabCompletions().add(nwithoutformatting);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean DebugMode = false;
|
||||
|
||||
public void SendForDebug(String message) {
|
||||
if (DebugMode) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.sendMessage("[DEBUG] " + message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean ActiveF = false;
|
||||
private int FCount = 0;
|
||||
private long FTime;
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMessage(AsyncPlayerChatEvent e) {
|
||||
if (ActiveF) {
|
||||
if (System.currentTimeMillis() - FTime > 10000) {
|
||||
ActiveF = false;
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
p.sendMessage("§b" + FCount + " "
|
||||
+ (FCount == 1 ? "person" : "people")
|
||||
+ " paid their respects.§r");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e.getMessage().equalsIgnoreCase("F")) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(e
|
||||
.getPlayer().getName());
|
||||
if (!mp.PressedF && ActiveF) {
|
||||
FCount++;
|
||||
mp.PressedF = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (e.getMessage().startsWith(">"))
|
||||
e.setMessage("§2" + e.getMessage());
|
||||
|
||||
/*
|
||||
* Channel c = ((Chat) Bukkit.getPluginManager().getPlugin("TownyChat"))
|
||||
* .getChannelsHandler().getActiveChannel(e.getPlayer(),
|
||||
* channelTypes.GLOBAL);
|
||||
*/
|
||||
/*
|
||||
* List<String> modes = ((Chat) Bukkit.getPluginManager().getPlugin(
|
||||
* "TownyChat")).getTowny().getPlayerMode(e.getPlayer()); if
|
||||
* (modes.size() == 0 || modes.contains("g")) {
|
||||
*/
|
||||
if (e.getFormat().contains("[g]")) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("tellraw @a [\"\"");
|
||||
sb.append(",{\"text\":\"Hashtags:\"}");
|
||||
int index = -1;
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
while ((index = e.getMessage().indexOf("#", index + 1)) != -1) {
|
||||
int index2 = e.getMessage().indexOf(" ", index + 1);
|
||||
if (index2 == -1)
|
||||
index2 = e.getMessage().length();
|
||||
int index3 = e.getMessage().indexOf("#", index + 1);
|
||||
if (index3 != -1 && index3 < index2) // A # occurs before a
|
||||
// space
|
||||
index2 = index3;
|
||||
String original = e.getMessage().substring(index, index2);
|
||||
list.add(original);
|
||||
sb.append(",{\"text\":\" \"}");
|
||||
sb.append(",{\"text\":\"");
|
||||
sb.append(original);
|
||||
sb.append("\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://twitter.com/hashtag/");
|
||||
sb.append(original.substring(1));
|
||||
sb.append("\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open on Twitter\",\"color\":\"blue\"}]}}}");
|
||||
}
|
||||
for (String original : list)
|
||||
e.setMessage(e.getMessage().replace(
|
||||
original,
|
||||
"§9"
|
||||
+ original
|
||||
+ (e.getMessage().startsWith("§2>") ? "§2"
|
||||
: "§r")));
|
||||
/*
|
||||
* for (String original : list)
|
||||
* System.out.println(e.getMessage().replace( original, "§9" +
|
||||
* original + (e.getMessage().startsWith("§2>") ? "§2" : "§r")));
|
||||
*/
|
||||
|
||||
sb.append("]");
|
||||
|
||||
if (list.size() > 0)
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Instance.getServer().getConsoleSender(),
|
||||
sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDeath(PlayerDeathEvent e) {
|
||||
if (!Minigames.plugin.pdata.getMinigamePlayer(e.getEntity())
|
||||
.isInMinigame() && new Random().nextBoolean()) {
|
||||
ActiveF = true;
|
||||
FCount = 0;
|
||||
FTime = System.currentTimeMillis();
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(p
|
||||
.getName());
|
||||
mp.PressedF = false;
|
||||
p.sendMessage("§bPress F to pay respects.§r");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,321 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerChatTabCompleteEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import au.com.mineauz.minigames.Minigames;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerListener implements Listener { // 2015.07.16.
|
||||
public static HashMap<String, UUID> nicknames = new HashMap<>();
|
||||
|
||||
public static boolean Enable = false; // 2015.08.29.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
final MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p
|
||||
.getUniqueId());
|
||||
mp.PlayerName = p.getName(); // 2015.10.17. 0:58
|
||||
if (mp.CommentedOnReddit)
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); // 2015.08.09.
|
||||
else { // 2015.07.20.
|
||||
Timer timer = new Timer();
|
||||
timer.schedule(new TimerTask()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (!mp.IgnoredFlair) {
|
||||
String message = "§bIf you'd like your flair displayed ingame, write your §6Minecraft name to this thread:§r";
|
||||
String json = "[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your §6Minecraft name to \"},{\"text\":\"[this thread.]\",\"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§r\"}]}}}]";
|
||||
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console, "tellraw ")
|
||||
message = "§bhttps://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/§r";
|
||||
p.sendMessage(message);
|
||||
message = "§6If you don't want the flair, type /u ignore to prevent this message on login.§r";
|
||||
p.sendMessage(message);
|
||||
message = "§bIf you already commented your name, then please wait a few seconds.§r";
|
||||
p.sendMessage(message);
|
||||
}
|
||||
}
|
||||
}, 15*1000)
|
||||
}
|
||||
|
||||
/* NICKNAME LOGIC */
|
||||
|
||||
UUID id = p.getUniqueId();
|
||||
|
||||
File f = new File("plugins/Essentials/userdata/" + id + ".yml");
|
||||
if (f.exists()) {
|
||||
YamlConfiguration yc = new YamlConfiguration();
|
||||
try {
|
||||
yc.load(f);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String nickname = yc.getString("nickname");
|
||||
if (nickname != null) {
|
||||
nicknames.put(nickname, id);
|
||||
|
||||
if (Enable) {
|
||||
if (!p.getName().equals("NorbiPeti")) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.chat("Hey, " + nickname + "!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mp.RPMode = true; // 2015.08.25.
|
||||
|
||||
if (p.getName().equals("FigyTuna") && Commands.PluginUpdated)
|
||||
p.sendMessage("§bThe The Button MC plugin got updated. Please restart the server. :P§r");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
String deletenick = null;
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
UUID uuid = nicknames.get(nickname);
|
||||
if (event.getPlayer().getUniqueId().equals(uuid)) {
|
||||
deletenick = nickname;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (deletenick != null)
|
||||
nicknames.remove(deletenick);
|
||||
}
|
||||
|
||||
public static String NotificationSound; // 2015.08.14.
|
||||
public static double NotificationPitch; // 2015.08.14.
|
||||
|
||||
public static boolean ShowRPTag = false; // 2015.08.31.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.GetFromName(event
|
||||
.getPlayer().getName());
|
||||
String flair = player.Flair; // 2015.08.08.
|
||||
if (player.IgnoredFlair)
|
||||
flair = "";
|
||||
String message = event.getMessage(); // 2015.08.08.
|
||||
for (Player p : PluginMain.GetPlayers()) { // 2015.08.12.
|
||||
String color = ""; // 2015.08.17.
|
||||
if (message.contains(p.getName())) {
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(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);
|
||||
}
|
||||
|
||||
message = message.replaceAll(p.getName(), color + p.getName()
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
for (String n : nicknames.keySet()) {
|
||||
Player p = null;
|
||||
String nwithoutformatting = new String(n);
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (message.contains(nwithoutformatting)) {
|
||||
p = Bukkit.getPlayer(nicknames.get(n));
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(float) NotificationPitch); // 2015.08.14.
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()); // 2015.08.17.
|
||||
}
|
||||
if (p != null) {
|
||||
message = message.replaceAll(nwithoutformatting, n
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
}
|
||||
|
||||
event.setMessage(message); // 2015.09.05.
|
||||
|
||||
event.setFormat(event
|
||||
.getFormat()
|
||||
.replace(
|
||||
"{rptag}",
|
||||
(player.RPMode ? (ShowRPTag ? "§2[RP]§r" : "")
|
||||
: "§8[OOC]§r"))
|
||||
.replace("{buttonflair}", flair)
|
||||
.replace(
|
||||
"{isitwilds}",
|
||||
(event.getPlayer().getWorld().getName()
|
||||
.equalsIgnoreCase("wilds") ? "[PVP]" : ""))); // 2015.09.04.
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTabComplete(PlayerChatTabCompleteEvent e) {
|
||||
String name = e.getLastToken();
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
String nwithoutformatting = nickname;
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (nwithoutformatting.startsWith(name)
|
||||
&& !nwithoutformatting.equals(Bukkit.getPlayer(
|
||||
nicknames.get(nickname)).getName()))
|
||||
e.getTabCompletions().add(nwithoutformatting);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean DebugMode = false;
|
||||
|
||||
public void SendForDebug(String message) {
|
||||
if (DebugMode) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.sendMessage("[DEBUG] " + message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean ActiveF = false;
|
||||
private int FCount = 0;
|
||||
private long FTime;
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMessage(AsyncPlayerChatEvent e) {
|
||||
if (ActiveF) {
|
||||
if (System.currentTimeMillis() - FTime > 10000) {
|
||||
ActiveF = false;
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
p.sendMessage("§b" + FCount + " "
|
||||
+ (FCount == 1 ? "person" : "people")
|
||||
+ " paid their respects.§r");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e.getMessage().equalsIgnoreCase("F")) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(e
|
||||
.getPlayer().getName());
|
||||
if (!mp.PressedF && ActiveF) {
|
||||
FCount++;
|
||||
mp.PressedF = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (e.getMessage().startsWith(">"))
|
||||
e.setMessage("§2" + e.getMessage());
|
||||
|
||||
/*
|
||||
* Channel c = ((Chat) Bukkit.getPluginManager().getPlugin("TownyChat"))
|
||||
* .getChannelsHandler().getActiveChannel(e.getPlayer(),
|
||||
* channelTypes.GLOBAL);
|
||||
*/
|
||||
/*
|
||||
* List<String> modes = ((Chat) Bukkit.getPluginManager().getPlugin(
|
||||
* "TownyChat")).getTowny().getPlayerMode(e.getPlayer()); if
|
||||
* (modes.size() == 0 || modes.contains("g")) {
|
||||
*/
|
||||
if (e.getFormat().contains("[g]")) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("tellraw @a [\"\"");
|
||||
sb.append(",{\"text\":\"Hashtags:\"}");
|
||||
int index = -1;
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
while ((index = e.getMessage().indexOf("#", index + 1)) != -1) {
|
||||
int index2 = e.getMessage().indexOf(" ", index + 1);
|
||||
if (index2 == -1)
|
||||
index2 = e.getMessage().length();
|
||||
int index3 = e.getMessage().indexOf("#", index + 1);
|
||||
if (index3 != -1 && index3 < index2) // A # occurs before a
|
||||
// space
|
||||
index2 = index3;
|
||||
String original = e.getMessage().substring(index, index2);
|
||||
list.add(original);
|
||||
sb.append(",{\"text\":\" \"}");
|
||||
sb.append(",{\"text\":\"");
|
||||
sb.append(original);
|
||||
sb.append("\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://twitter.com/hashtag/");
|
||||
sb.append(original.substring(1));
|
||||
sb.append("\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open on Twitter\",\"color\":\"blue\"}]}}}");
|
||||
}
|
||||
for (String original : list)
|
||||
e.setMessage(e.getMessage().replace(
|
||||
original,
|
||||
"§9"
|
||||
+ original
|
||||
+ (e.getMessage().startsWith("§2>") ? "§2"
|
||||
: "§r")));
|
||||
/*
|
||||
* for (String original : list)
|
||||
* System.out.println(e.getMessage().replace( original, "§9" +
|
||||
* original + (e.getMessage().startsWith("§2>") ? "§2" : "§r")));
|
||||
*/
|
||||
|
||||
sb.append("]");
|
||||
|
||||
if (list.size() > 0)
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Instance.getServer().getConsoleSender(),
|
||||
sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDeath(PlayerDeathEvent e) {
|
||||
if (!Minigames.plugin.pdata.getMinigamePlayer(e.getEntity())
|
||||
.isInMinigame() && new Random().nextBoolean()) {
|
||||
ActiveF = true;
|
||||
FCount = 0;
|
||||
FTime = System.currentTimeMillis();
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(p
|
||||
.getName());
|
||||
mp.PressedF = false;
|
||||
p.sendMessage("§bPress F to pay respects.§r");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,363 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
|
||||
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/
|
||||
private static PluginMain Instance;
|
||||
// Fired when plugin is first enabled
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
this.getCommand("u").setExecutor(new Commands());
|
||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||
Instance=this; //2015.08.08.
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
//System.out.println("Name: " + name);
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("flairsignored.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while((line=br.readLine())!=null)
|
||||
{
|
||||
String[] s=line.split(" ");
|
||||
TownColors.put(s[0], s[1]);
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
//throw new IOException("Test"); //2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||
Thread t=new Thread(r);
|
||||
t.start();
|
||||
}
|
||||
Boolean stop=false;
|
||||
// Fired when plugin is disabled
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
try
|
||||
{
|
||||
FileWriter fw;
|
||||
fw = new FileWriter("flairsaccepted.txt");
|
||||
fw.close();
|
||||
fw = new FileWriter("flairsignored.txt");
|
||||
fw.close();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.AcceptedFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
file=new File("flairsignored.txt");
|
||||
bw = new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.IgnoredFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
stop=true;
|
||||
}
|
||||
|
||||
public void ThreadMethod() //<-- 2015.07.16.
|
||||
{
|
||||
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();
|
||||
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();
|
||||
if(HasIGFlair(ign))
|
||||
continue;
|
||||
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";
|
||||
else
|
||||
flair = "non-presser";
|
||||
String flairclass;
|
||||
if(flairdata.length>2)
|
||||
flairclass = flairdata[2];
|
||||
else
|
||||
flairclass="unknown";
|
||||
SetFlair(ign, flair, flairclass, author);
|
||||
}
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Exception LastException; //2015.08.09.
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||
public Boolean HasIGFlair(String playername)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
return p.Flair!=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
String finalflair;
|
||||
p.FlairDecided=true;
|
||||
switch(flairclass)
|
||||
{
|
||||
case "press-1":
|
||||
finalflair="§c("+text+")§r";
|
||||
break;
|
||||
case "press-2":
|
||||
finalflair="§6("+text+")§r";
|
||||
break;
|
||||
case "press-3":
|
||||
finalflair="§e("+text+")§r";
|
||||
break;
|
||||
case "press-4":
|
||||
finalflair="§a("+text+")§r";
|
||||
break;
|
||||
case "press-5":
|
||||
finalflair="§9("+text+")§r";
|
||||
break;
|
||||
case "press-6":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "no-press":
|
||||
finalflair="§7(non-pr.)§r";
|
||||
break;
|
||||
case "cheater":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "cant-press": //2015.08.08.
|
||||
finalflair="§r(can't press)§r";
|
||||
break;
|
||||
case "undecided": //2015.08.09.
|
||||
p.FlairDecided=false;
|
||||
finalflair="";
|
||||
break;
|
||||
default:
|
||||
finalflair="";
|
||||
break;
|
||||
}
|
||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||
return;
|
||||
p.Flair=finalflair; //2015.08.08.
|
||||
p.UserName=username; //2015.08.08.
|
||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||
{
|
||||
if(player.getName().equals(playername))
|
||||
{
|
||||
//AppendPlayerDisplayFlair(player, username, finalflair);
|
||||
AppendPlayerDisplayFlair(player, p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String GetFlair(Player player)
|
||||
{ //2015.07.16.
|
||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||
return flair==null ? "" : flair;
|
||||
}
|
||||
|
||||
//public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||
public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09.
|
||||
{
|
||||
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair)
|
||||
return;
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair)
|
||||
{
|
||||
AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20.
|
||||
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
|
||||
player.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r");
|
||||
}
|
||||
|
||||
private static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||
String[] colors = color.substring(1).split("§");
|
||||
String displayname=player.getName(); //2015.08.08.
|
||||
ArrayList<Integer> Positions=new ArrayList<>();
|
||||
for(int i=0; i<displayname.length(); i++) {
|
||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||
Positions.add(i);
|
||||
}
|
||||
}
|
||||
String finalname=""; //TODO
|
||||
if(Positions.size()>=colors.length)
|
||||
{
|
||||
int x=0;
|
||||
for(int i=0; i<Positions.size(); i++)
|
||||
{
|
||||
int pos=Positions.get(i);
|
||||
int nextpos;
|
||||
if(i!=Positions.size()-1)
|
||||
nextpos=Positions.get(i+1);
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Positions.clear();
|
||||
int unit=displayname.length()/colors.length;
|
||||
int x=0;
|
||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||
{
|
||||
int pos=i;
|
||||
int nextpos;
|
||||
if(i<displayname.length()-unit-unit)
|
||||
nextpos=i+unit;
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||
}
|
||||
|
||||
public static String GetColorForTown(String townname)
|
||||
{ //2015.07.20.
|
||||
if(TownColors.containsKey(townname))
|
||||
return TownColors.get(townname);
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String GetPlayerTown(Player player)
|
||||
{ //2015.07.20.
|
||||
try {
|
||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||
return town.getName();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public static Collection<? extends Player> GetPlayers()
|
||||
{
|
||||
return Instance.getServer().getOnlinePlayers();
|
||||
}
|
||||
}
|
|
@ -1,577 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
|
||||
public static boolean PluginUpdated = false; // 2015.08.31.
|
||||
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label,
|
||||
String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
switch (cmd.getName()) {
|
||||
case "u": {
|
||||
if (args.length < 1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(player
|
||||
.getName()); // 2015.08.08.
|
||||
if (!p.CommentedOnReddit
|
||||
&& !args[0].toLowerCase().equals("admin")
|
||||
&& !args[0].toLowerCase().equals("ignore")) {
|
||||
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")) { // 2015.08.10.
|
||||
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")) { // 2015.08.19.
|
||||
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
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
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");
|
||||
} else
|
||||
player.sendMessage("§cYou already ignored this request.§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
|
||||
break;
|
||||
case "announce":
|
||||
DoAnnounce(player, args, null);
|
||||
break;
|
||||
case "name":
|
||||
if (args.length == 1) {
|
||||
player.sendMessage("§cUsage: /u name <playername>§r");
|
||||
break;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[1])) {
|
||||
player.sendMessage("§cUnknown user: " + args[1]);
|
||||
break;
|
||||
}
|
||||
player.sendMessage("§bUsername of "
|
||||
+ args[1]
|
||||
+ ": "
|
||||
+ MaybeOfflinePlayer.AllPlayers.get(args[1]).UserName);
|
||||
break;
|
||||
case "enable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = true;
|
||||
player.sendMessage("Enabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
case "disable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = false;
|
||||
player.sendMessage("Disabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
case "quiz":
|
||||
DoQuiz(player, args, commandblock);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "nrp":
|
||||
case "ooc":
|
||||
if (args.length == 0) {
|
||||
return false;
|
||||
} else {
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = false;
|
||||
String message = "";
|
||||
for (String arg : args)
|
||||
message += arg + " ";
|
||||
player.chat(message.substring(0, message.length() - 1));
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = true;
|
||||
}
|
||||
return true;
|
||||
case "skype":
|
||||
// "skype:?chat&blob=Y_5Ob1BEcw0ZlstdUHyf0ENS5n1Xz2Huhx-5b-pB2JyMSRO5QMEALkJuTSuUaAb3-XfWXwCndwhGex_UpXDbyQ";
|
||||
return true;
|
||||
default:
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
}
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("admin")) // 2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); // 2015.08.09.
|
||||
return true; // 2015.08.09.
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("announce")) {
|
||||
if (sender instanceof BlockCommandSender)
|
||||
DoAnnounce(null, args, (BlockCommandSender) sender);
|
||||
else
|
||||
DoAnnounce(null, args, null);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void DoReload(Player player) { // 2015.07.20.
|
||||
try {
|
||||
PluginMain.Console
|
||||
.sendMessage("§6-- Reloading The Button Minecraft plugin...§r");
|
||||
PluginMain.LoadFiles(true); // 2015.08.09.
|
||||
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.
|
||||
}
|
||||
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.
|
||||
}
|
||||
PluginMain.Console.sendMessage("§6-- Reloading done!§r");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
if (player != null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static Player ReloadPlayer; // 2015.08.09.
|
||||
|
||||
private static String DoAdminUsage = "§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin|togglerpshow|toggledebug|savepos|loadpos§r";
|
||||
|
||||
private static void DoAdmin(Player player, String[] args) { // 2015.08.09.
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// args[0] is "admin"
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "reload":
|
||||
ReloadPlayer = player; // 2015.08.09.
|
||||
SendMessage(
|
||||
player,
|
||||
"§bMake sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
break; // <-- 2015.08.10.
|
||||
case "confirm":
|
||||
if (ReloadPlayer == player)
|
||||
DoReload(player); // 2015.08.09.
|
||||
else
|
||||
SendMessage(player,
|
||||
"§cYou need to do /u admin reload first.§r");
|
||||
break;
|
||||
case "save":
|
||||
PluginMain.SaveFiles(); // 2015.08.09.
|
||||
SendMessage(player,
|
||||
"§bSaved files. Now you can edit them and reload if you want.§r");
|
||||
break;
|
||||
case "setflair":
|
||||
DoSetFlair(player, args);
|
||||
break;
|
||||
case "updateplugin": // 2015.08.10.
|
||||
DoUpdatePlugin(player);
|
||||
break;
|
||||
case "togglerpshow":
|
||||
PlayerListener.ShowRPTag = !PlayerListener.ShowRPTag;
|
||||
SendMessage(player, "RP tag showing "
|
||||
+ (PlayerListener.ShowRPTag ? "enabled" : "disabled"));
|
||||
break;
|
||||
case "toggledebug":
|
||||
PlayerListener.DebugMode = !PlayerListener.DebugMode;
|
||||
SendMessage(player, "DebugMode: " + PlayerListener.DebugMode);
|
||||
break;
|
||||
case "savepos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "loadpos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "updatedynmap":
|
||||
DoUpdateDynmap(player, args);
|
||||
default:
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
|
||||
private static void DoPlayerInfo(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "playerinfo"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(args[2]);
|
||||
if (p == null) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
SendMessage(player, "Player name: " + p.PlayerName);
|
||||
SendMessage(player, "User flair: " + p.Flair);
|
||||
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);
|
||||
}
|
||||
|
||||
private static void SendMessage(Player player, String message) { // 2015.08.09.
|
||||
if (player == null)
|
||||
PluginMain.Console.sendMessage(message); // 2015.08.12.
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
private static void DoGetLastError(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "getlasterror"
|
||||
if (PluginMain.LastException != null) {
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException = null;
|
||||
} else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
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");
|
||||
return;
|
||||
}
|
||||
Player p = Bukkit.getPlayer(args[2]);
|
||||
if (p == null) {
|
||||
SendMessage(player, "§cPLayer not found.&r");
|
||||
return;
|
||||
}
|
||||
SetPlayerFlair(player,
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()), args[3]);
|
||||
}
|
||||
|
||||
private static void DoUpdatePlugin(Player player) { // 2015.08.10.
|
||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
||||
System.out.println("Forced updating of Auto-Flair plugin.");
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(
|
||||
"https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
||||
FileUtils.copyURLToFile(url, new File(
|
||||
"plugins/TheButtonAutoFlair.jar"));
|
||||
PluginUpdated = true; // 2015.08.31.
|
||||
SendMessage(player, "Updating done!");
|
||||
} catch (MalformedURLException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoAnnounce(Player player, String[] args,
|
||||
BlockCommandSender commandblock) {
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "add":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce add <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
PluginMain.AnnounceMessages.add(finalmessage);
|
||||
SendMessage(player, "§bAnnouncement added.§r");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce remove <index>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceMessages.remove(Integer.parseInt(args[2]));
|
||||
break;
|
||||
case "settime":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player,
|
||||
"§cUsage: /u announce settime <minutes>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceTime = Integer.parseInt(args[2]) * 60 * 1000;
|
||||
SendMessage(player, "Time set between announce messages");
|
||||
break;
|
||||
case "list":
|
||||
SendMessage(player, "§bList of announce messages:§r");
|
||||
SendMessage(player, "§bFormat: [index] message§r");
|
||||
int i = 0;
|
||||
for (String message : PluginMain.AnnounceMessages)
|
||||
SendMessage(player, "[" + i++ + "] " + message);
|
||||
SendMessage(player,
|
||||
"§bCurrent wait time between announcements: "
|
||||
+ PluginMain.AnnounceTime / 60 / 1000
|
||||
+ " minute(s)§r");
|
||||
break;
|
||||
case "edit":
|
||||
if (commandblock == null) {
|
||||
SendMessage(
|
||||
player,
|
||||
"§cError: This command can only be used from a command block. Use /u announce remove.");
|
||||
break;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
commandblock
|
||||
.sendMessage("§cUsage: /u announce edit <index> <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 3; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§');
|
||||
int index = Integer.parseInt(args[2]);
|
||||
if (index > 100)
|
||||
break;
|
||||
while (PluginMain.AnnounceMessages.size() <= index)
|
||||
PluginMain.AnnounceMessages.add("");
|
||||
PluginMain.AnnounceMessages.set(Integer.parseInt(args[2]),
|
||||
finalmessage1);
|
||||
commandblock.sendMessage("Announcement edited.");
|
||||
break;
|
||||
default:
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoSaveLoadPos(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "savepos|loadpos"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
Player p = null;
|
||||
for (Player pl : PluginMain.GetPlayers()) {
|
||||
if (pl.getName().equals(args[2])) {
|
||||
p = pl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (p == null) {
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer is not online: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (args[1].equalsIgnoreCase("savepos")) {
|
||||
mp.SavedLocation = p.getLocation();
|
||||
} else if (args[1].equalsIgnoreCase("loadpos")) {
|
||||
if (mp.SavedLocation != null)
|
||||
p.teleport(mp.SavedLocation);
|
||||
} else {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// SendMessage(player, "Player " + p.getName() +
|
||||
// " position saved/loaded.");s
|
||||
}
|
||||
|
||||
private static void DoUpdateDynmap(Player player, String[] args) {
|
||||
// args[0] is "admin" - args[1] is "updatedynmap"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin updatedynmap <password>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<String> Quiz = new ArrayList<>();
|
||||
|
||||
private static void DoQuiz(Player player, String[] args,
|
||||
BlockCommandSender commandblock) {
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = "§cUsage: /u quiz add|remove|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "add":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u quiz add <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
Quiz.add(finalmessage);
|
||||
SendMessage(player, "§Quiz question added.§r");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u quiz remove <index>");
|
||||
return;
|
||||
}
|
||||
Quiz.remove(Integer.parseInt(args[2]));
|
||||
break;
|
||||
case "list":
|
||||
SendMessage(player, "§bList of quiz questions:§r");
|
||||
SendMessage(player, "§bFormat: [index] question§r");
|
||||
int i = 0;
|
||||
for (String question : Quiz)
|
||||
SendMessage(player, "[" + i++ + "] " + question);
|
||||
break;
|
||||
case "edit":
|
||||
if (commandblock == null) {
|
||||
SendMessage(
|
||||
player,
|
||||
"§cError: This command can only be used from a command block. Use /u quiz remove.");
|
||||
break;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
commandblock
|
||||
.sendMessage("§cUsage: /u quiz edit <index> <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 3; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§');
|
||||
int index = Integer.parseInt(args[2]);
|
||||
if (index > 100)
|
||||
break;
|
||||
while (Quiz.size() <= index)
|
||||
Quiz.add("");
|
||||
Quiz.set(Integer.parseInt(args[2]), finalmessage1);
|
||||
commandblock.sendMessage("Question edited.");
|
||||
break;
|
||||
default:
|
||||
String message = "§cUsage: /u quiz add|remove|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,318 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerChatTabCompleteEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import au.com.mineauz.minigames.Minigames;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerListener implements Listener { // 2015.07.16.
|
||||
public static HashMap<String, UUID> nicknames = new HashMap<>();
|
||||
|
||||
public static boolean Enable = false; // 2015.08.29.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
final MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p
|
||||
.getUniqueId());
|
||||
mp.PlayerName = p.getName(); // 2015.10.17. 0:58
|
||||
if (mp.CommentedOnReddit && !mp.PlayerName.equals("NorbiPeti"))
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); // 2015.08.09.
|
||||
else { // 2015.07.20.
|
||||
Timer timer = new Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!mp.IgnoredFlair) {
|
||||
String json = "[\"\",{\"text\":\"§bIf you'd like your flair displayed ingame, write your §bMinecraft §bname to \"},{\"text\":\"[this thread.]\",\"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§r\"}]}}}]";
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Console,
|
||||
"tellraw " + mp.PlayerName + " " + json);
|
||||
json = "[\"\",{\"text\":\"§bIf you don't want the flair, type /u ignore to prevent this message on login.§r\"}]";
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Console,
|
||||
"tellraw " + mp.PlayerName + " " + json);
|
||||
}
|
||||
}
|
||||
}, 15 * 1000);
|
||||
}
|
||||
|
||||
/* NICKNAME LOGIC */
|
||||
|
||||
UUID id = p.getUniqueId();
|
||||
|
||||
File f = new File("plugins/Essentials/userdata/" + id + ".yml");
|
||||
if (f.exists()) {
|
||||
YamlConfiguration yc = new YamlConfiguration();
|
||||
try {
|
||||
yc.load(f);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String nickname = yc.getString("nickname");
|
||||
if (nickname != null) {
|
||||
nicknames.put(nickname, id);
|
||||
|
||||
if (Enable) {
|
||||
if (!p.getName().equals("NorbiPeti")) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.chat("Hey, " + nickname + "!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mp.RPMode = true; // 2015.08.25.
|
||||
|
||||
if (p.getName().equals("FigyTuna") && Commands.PluginUpdated)
|
||||
p.sendMessage("§bThe The Button MC plugin got updated. Please restart the server. :P§r");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
String deletenick = null;
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
UUID uuid = nicknames.get(nickname);
|
||||
if (event.getPlayer().getUniqueId().equals(uuid)) {
|
||||
deletenick = nickname;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (deletenick != null)
|
||||
nicknames.remove(deletenick);
|
||||
}
|
||||
|
||||
public static String NotificationSound; // 2015.08.14.
|
||||
public static double NotificationPitch; // 2015.08.14.
|
||||
|
||||
public static boolean ShowRPTag = false; // 2015.08.31.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.GetFromName(event
|
||||
.getPlayer().getName());
|
||||
String flair = player.Flair; // 2015.08.08.
|
||||
if (player.IgnoredFlair)
|
||||
flair = "";
|
||||
String message = event.getMessage(); // 2015.08.08.
|
||||
for (Player p : PluginMain.GetPlayers()) { // 2015.08.12.
|
||||
String color = ""; // 2015.08.17.
|
||||
if (message.contains(p.getName())) {
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(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);
|
||||
}
|
||||
|
||||
message = message.replaceAll(p.getName(), color + p.getName()
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
for (String n : nicknames.keySet()) {
|
||||
Player p = null;
|
||||
String nwithoutformatting = new String(n);
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (message.contains(nwithoutformatting)) {
|
||||
p = Bukkit.getPlayer(nicknames.get(n));
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(float) NotificationPitch); // 2015.08.14.
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()); // 2015.08.17.
|
||||
}
|
||||
if (p != null) {
|
||||
message = message.replaceAll(nwithoutformatting, n
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
}
|
||||
|
||||
event.setMessage(message); // 2015.09.05.
|
||||
|
||||
event.setFormat(event
|
||||
.getFormat()
|
||||
.replace(
|
||||
"{rptag}",
|
||||
(player.RPMode ? (ShowRPTag ? "§2[RP]§r" : "")
|
||||
: "§8[OOC]§r"))
|
||||
.replace("{buttonflair}", flair)
|
||||
.replace(
|
||||
"{isitwilds}",
|
||||
(event.getPlayer().getWorld().getName()
|
||||
.equalsIgnoreCase("wilds") ? "[PVP]" : ""))); // 2015.09.04.
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTabComplete(PlayerChatTabCompleteEvent e) {
|
||||
String name = e.getLastToken();
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
String nwithoutformatting = nickname;
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (nwithoutformatting.startsWith(name)
|
||||
&& !nwithoutformatting.equals(Bukkit.getPlayer(
|
||||
nicknames.get(nickname)).getName()))
|
||||
e.getTabCompletions().add(nwithoutformatting);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean DebugMode = false;
|
||||
|
||||
public void SendForDebug(String message) {
|
||||
if (DebugMode) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.sendMessage("[DEBUG] " + message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean ActiveF = false;
|
||||
private int FCount = 0;
|
||||
private long FTime;
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMessage(AsyncPlayerChatEvent e) {
|
||||
if (ActiveF) {
|
||||
if (System.currentTimeMillis() - FTime > 10000) {
|
||||
ActiveF = false;
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
p.sendMessage("§b" + FCount + " "
|
||||
+ (FCount == 1 ? "person" : "people")
|
||||
+ " paid their respects.§r");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e.getMessage().equalsIgnoreCase("F")) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(e
|
||||
.getPlayer().getName());
|
||||
if (!mp.PressedF && ActiveF) {
|
||||
FCount++;
|
||||
mp.PressedF = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (e.getMessage().startsWith(">"))
|
||||
e.setMessage("§2" + e.getMessage());
|
||||
|
||||
/*
|
||||
* Channel c = ((Chat) Bukkit.getPluginManager().getPlugin("TownyChat"))
|
||||
* .getChannelsHandler().getActiveChannel(e.getPlayer(),
|
||||
* channelTypes.GLOBAL);
|
||||
*/
|
||||
/*
|
||||
* List<String> modes = ((Chat) Bukkit.getPluginManager().getPlugin(
|
||||
* "TownyChat")).getTowny().getPlayerMode(e.getPlayer()); if
|
||||
* (modes.size() == 0 || modes.contains("g")) {
|
||||
*/
|
||||
if (e.getFormat().contains("[g]")) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("tellraw @a [\"\"");
|
||||
sb.append(",{\"text\":\"Hashtags:\"}");
|
||||
int index = -1;
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
while ((index = e.getMessage().indexOf("#", index + 1)) != -1) {
|
||||
int index2 = e.getMessage().indexOf(" ", index + 1);
|
||||
if (index2 == -1)
|
||||
index2 = e.getMessage().length();
|
||||
int index3 = e.getMessage().indexOf("#", index + 1);
|
||||
if (index3 != -1 && index3 < index2) // A # occurs before a
|
||||
// space
|
||||
index2 = index3;
|
||||
String original = e.getMessage().substring(index, index2);
|
||||
list.add(original);
|
||||
sb.append(",{\"text\":\" \"}");
|
||||
sb.append(",{\"text\":\"");
|
||||
sb.append(original);
|
||||
sb.append("\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://twitter.com/hashtag/");
|
||||
sb.append(original.substring(1));
|
||||
sb.append("\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open on Twitter\",\"color\":\"blue\"}]}}}");
|
||||
}
|
||||
for (String original : list)
|
||||
e.setMessage(e.getMessage().replace(
|
||||
original,
|
||||
"§9"
|
||||
+ original
|
||||
+ (e.getMessage().startsWith("§2>") ? "§2"
|
||||
: "§r")));
|
||||
/*
|
||||
* for (String original : list)
|
||||
* System.out.println(e.getMessage().replace( original, "§9" +
|
||||
* original + (e.getMessage().startsWith("§2>") ? "§2" : "§r")));
|
||||
*/
|
||||
|
||||
sb.append("]");
|
||||
|
||||
if (list.size() > 0)
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Instance.getServer().getConsoleSender(),
|
||||
sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDeath(PlayerDeathEvent e) {
|
||||
if (!Minigames.plugin.pdata.getMinigamePlayer(e.getEntity())
|
||||
.isInMinigame() && new Random().nextBoolean()) {
|
||||
ActiveF = true;
|
||||
FCount = 0;
|
||||
FTime = System.currentTimeMillis();
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(p
|
||||
.getName());
|
||||
mp.PressedF = false;
|
||||
p.sendMessage("§bPress F to pay respects.§r");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,319 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerChatTabCompleteEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import au.com.mineauz.minigames.Minigames;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerListener implements Listener { // 2015.07.16.
|
||||
public static HashMap<String, UUID> nicknames = new HashMap<>();
|
||||
|
||||
public static boolean Enable = false; // 2015.08.29.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
final MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p
|
||||
.getUniqueId());
|
||||
mp.PlayerName = p.getName(); // 2015.10.17. 0:58
|
||||
// if (mp.CommentedOnReddit)
|
||||
if (false)
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); // 2015.08.09.
|
||||
else { // 2015.07.20.
|
||||
Timer timer = new Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!mp.IgnoredFlair) {
|
||||
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,
|
||||
"tellraw " + mp.PlayerName + " " + json);
|
||||
json = "[\"\",{\"text\":\"If you don't want the flair, type /u ignore to prevent this message after next login.\",\"color\":\"aqua\"}]";
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Console,
|
||||
"tellraw " + mp.PlayerName + " " + json);
|
||||
}
|
||||
}
|
||||
}, 15 * 1000);
|
||||
}
|
||||
|
||||
/* NICKNAME LOGIC */
|
||||
|
||||
UUID id = p.getUniqueId();
|
||||
|
||||
File f = new File("plugins/Essentials/userdata/" + id + ".yml");
|
||||
if (f.exists()) {
|
||||
YamlConfiguration yc = new YamlConfiguration();
|
||||
try {
|
||||
yc.load(f);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String nickname = yc.getString("nickname");
|
||||
if (nickname != null) {
|
||||
nicknames.put(nickname, id);
|
||||
|
||||
if (Enable) {
|
||||
if (!p.getName().equals("NorbiPeti")) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.chat("Hey, " + nickname + "!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mp.RPMode = true; // 2015.08.25.
|
||||
|
||||
if (p.getName().equals("FigyTuna") && Commands.PluginUpdated)
|
||||
p.sendMessage("§bThe The Button MC plugin got updated. Please restart the server. :P§r");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
String deletenick = null;
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
UUID uuid = nicknames.get(nickname);
|
||||
if (event.getPlayer().getUniqueId().equals(uuid)) {
|
||||
deletenick = nickname;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (deletenick != null)
|
||||
nicknames.remove(deletenick);
|
||||
}
|
||||
|
||||
public static String NotificationSound; // 2015.08.14.
|
||||
public static double NotificationPitch; // 2015.08.14.
|
||||
|
||||
public static boolean ShowRPTag = false; // 2015.08.31.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.GetFromName(event
|
||||
.getPlayer().getName());
|
||||
String flair = player.Flair; // 2015.08.08.
|
||||
if (player.IgnoredFlair)
|
||||
flair = "";
|
||||
String message = event.getMessage(); // 2015.08.08.
|
||||
for (Player p : PluginMain.GetPlayers()) { // 2015.08.12.
|
||||
String color = ""; // 2015.08.17.
|
||||
if (message.contains(p.getName())) {
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(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);
|
||||
}
|
||||
|
||||
message = message.replaceAll(p.getName(), color + p.getName()
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
for (String n : nicknames.keySet()) {
|
||||
Player p = null;
|
||||
String nwithoutformatting = new String(n);
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (message.contains(nwithoutformatting)) {
|
||||
p = Bukkit.getPlayer(nicknames.get(n));
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(float) NotificationPitch); // 2015.08.14.
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()); // 2015.08.17.
|
||||
}
|
||||
if (p != null) {
|
||||
message = message.replaceAll(nwithoutformatting, n
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
}
|
||||
|
||||
event.setMessage(message); // 2015.09.05.
|
||||
|
||||
event.setFormat(event
|
||||
.getFormat()
|
||||
.replace(
|
||||
"{rptag}",
|
||||
(player.RPMode ? (ShowRPTag ? "§2[RP]§r" : "")
|
||||
: "§8[OOC]§r"))
|
||||
.replace("{buttonflair}", flair)
|
||||
.replace(
|
||||
"{isitwilds}",
|
||||
(event.getPlayer().getWorld().getName()
|
||||
.equalsIgnoreCase("wilds") ? "[PVP]" : ""))); // 2015.09.04.
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTabComplete(PlayerChatTabCompleteEvent e) {
|
||||
String name = e.getLastToken();
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
String nwithoutformatting = nickname;
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (nwithoutformatting.startsWith(name)
|
||||
&& !nwithoutformatting.equals(Bukkit.getPlayer(
|
||||
nicknames.get(nickname)).getName()))
|
||||
e.getTabCompletions().add(nwithoutformatting);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean DebugMode = false;
|
||||
|
||||
public void SendForDebug(String message) {
|
||||
if (DebugMode) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.sendMessage("[DEBUG] " + message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean ActiveF = false;
|
||||
private int FCount = 0;
|
||||
private long FTime;
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMessage(AsyncPlayerChatEvent e) {
|
||||
if (ActiveF) {
|
||||
if (System.currentTimeMillis() - FTime > 10000) {
|
||||
ActiveF = false;
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
p.sendMessage("§b" + FCount + " "
|
||||
+ (FCount == 1 ? "person" : "people")
|
||||
+ " paid their respects.§r");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e.getMessage().equalsIgnoreCase("F")) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(e
|
||||
.getPlayer().getName());
|
||||
if (!mp.PressedF && ActiveF) {
|
||||
FCount++;
|
||||
mp.PressedF = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (e.getMessage().startsWith(">"))
|
||||
e.setMessage("§2" + e.getMessage());
|
||||
|
||||
/*
|
||||
* Channel c = ((Chat) Bukkit.getPluginManager().getPlugin("TownyChat"))
|
||||
* .getChannelsHandler().getActiveChannel(e.getPlayer(),
|
||||
* channelTypes.GLOBAL);
|
||||
*/
|
||||
/*
|
||||
* List<String> modes = ((Chat) Bukkit.getPluginManager().getPlugin(
|
||||
* "TownyChat")).getTowny().getPlayerMode(e.getPlayer()); if
|
||||
* (modes.size() == 0 || modes.contains("g")) {
|
||||
*/
|
||||
if (e.getFormat().contains("[g]")) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("tellraw @a [\"\"");
|
||||
sb.append(",{\"text\":\"Hashtags:\"}");
|
||||
int index = -1;
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
while ((index = e.getMessage().indexOf("#", index + 1)) != -1) {
|
||||
int index2 = e.getMessage().indexOf(" ", index + 1);
|
||||
if (index2 == -1)
|
||||
index2 = e.getMessage().length();
|
||||
int index3 = e.getMessage().indexOf("#", index + 1);
|
||||
if (index3 != -1 && index3 < index2) // A # occurs before a
|
||||
// space
|
||||
index2 = index3;
|
||||
String original = e.getMessage().substring(index, index2);
|
||||
list.add(original);
|
||||
sb.append(",{\"text\":\" \"}");
|
||||
sb.append(",{\"text\":\"");
|
||||
sb.append(original);
|
||||
sb.append("\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://twitter.com/hashtag/");
|
||||
sb.append(original.substring(1));
|
||||
sb.append("\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open on Twitter\",\"color\":\"blue\"}]}}}");
|
||||
}
|
||||
for (String original : list)
|
||||
e.setMessage(e.getMessage().replace(
|
||||
original,
|
||||
"§9"
|
||||
+ original
|
||||
+ (e.getMessage().startsWith("§2>") ? "§2"
|
||||
: "§r")));
|
||||
/*
|
||||
* for (String original : list)
|
||||
* System.out.println(e.getMessage().replace( original, "§9" +
|
||||
* original + (e.getMessage().startsWith("§2>") ? "§2" : "§r")));
|
||||
*/
|
||||
|
||||
sb.append("]");
|
||||
|
||||
if (list.size() > 0)
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Instance.getServer().getConsoleSender(),
|
||||
sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDeath(PlayerDeathEvent e) {
|
||||
if (!Minigames.plugin.pdata.getMinigamePlayer(e.getEntity())
|
||||
.isInMinigame() && new Random().nextBoolean()) {
|
||||
ActiveF = true;
|
||||
FCount = 0;
|
||||
FTime = System.currentTimeMillis();
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(p
|
||||
.getName());
|
||||
mp.PressedF = false;
|
||||
p.sendMessage("§bPress F to pay respects.§r");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,319 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerChatTabCompleteEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import au.com.mineauz.minigames.Minigames;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerListener implements Listener { // 2015.07.16.
|
||||
public static HashMap<String, UUID> nicknames = new HashMap<>();
|
||||
|
||||
public static boolean Enable = false; // 2015.08.29.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
final MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p
|
||||
.getUniqueId());
|
||||
mp.PlayerName = p.getName(); // 2015.10.17. 0:58
|
||||
if (mp.CommentedOnReddit)
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); // 2015.08.09.
|
||||
else { // 2015.07.20.
|
||||
Timer timer = new Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!mp.IgnoredFlair) {
|
||||
String message = "§bIf you'd like your flair displayed ingame, write your §6Minecraft name to this thread:§r";
|
||||
String json = "[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your §6Minecraft name to \"},{\"text\":\"[this thread.]\",\"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§r\"}]}}}]";
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Console,
|
||||
"tellraw " + mp.PlayerName + " " + json);
|
||||
json = "[\"\",{\"text\":\"§6If you don't want the flair, type /u ignore to prevent this message on login.§r\"}]";
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Console,
|
||||
"tellraw " + mp.PlayerName + " " + json);
|
||||
}
|
||||
}
|
||||
}, 15 * 1000);
|
||||
}
|
||||
|
||||
/* NICKNAME LOGIC */
|
||||
|
||||
UUID id = p.getUniqueId();
|
||||
|
||||
File f = new File("plugins/Essentials/userdata/" + id + ".yml");
|
||||
if (f.exists()) {
|
||||
YamlConfiguration yc = new YamlConfiguration();
|
||||
try {
|
||||
yc.load(f);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String nickname = yc.getString("nickname");
|
||||
if (nickname != null) {
|
||||
nicknames.put(nickname, id);
|
||||
|
||||
if (Enable) {
|
||||
if (!p.getName().equals("NorbiPeti")) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.chat("Hey, " + nickname + "!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mp.RPMode = true; // 2015.08.25.
|
||||
|
||||
if (p.getName().equals("FigyTuna") && Commands.PluginUpdated)
|
||||
p.sendMessage("§bThe The Button MC plugin got updated. Please restart the server. :P§r");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
String deletenick = null;
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
UUID uuid = nicknames.get(nickname);
|
||||
if (event.getPlayer().getUniqueId().equals(uuid)) {
|
||||
deletenick = nickname;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (deletenick != null)
|
||||
nicknames.remove(deletenick);
|
||||
}
|
||||
|
||||
public static String NotificationSound; // 2015.08.14.
|
||||
public static double NotificationPitch; // 2015.08.14.
|
||||
|
||||
public static boolean ShowRPTag = false; // 2015.08.31.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.GetFromName(event
|
||||
.getPlayer().getName());
|
||||
String flair = player.Flair; // 2015.08.08.
|
||||
if (player.IgnoredFlair)
|
||||
flair = "";
|
||||
String message = event.getMessage(); // 2015.08.08.
|
||||
for (Player p : PluginMain.GetPlayers()) { // 2015.08.12.
|
||||
String color = ""; // 2015.08.17.
|
||||
if (message.contains(p.getName())) {
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(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);
|
||||
}
|
||||
|
||||
message = message.replaceAll(p.getName(), color + p.getName()
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
for (String n : nicknames.keySet()) {
|
||||
Player p = null;
|
||||
String nwithoutformatting = new String(n);
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (message.contains(nwithoutformatting)) {
|
||||
p = Bukkit.getPlayer(nicknames.get(n));
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(float) NotificationPitch); // 2015.08.14.
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()); // 2015.08.17.
|
||||
}
|
||||
if (p != null) {
|
||||
message = message.replaceAll(nwithoutformatting, n
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
}
|
||||
|
||||
event.setMessage(message); // 2015.09.05.
|
||||
|
||||
event.setFormat(event
|
||||
.getFormat()
|
||||
.replace(
|
||||
"{rptag}",
|
||||
(player.RPMode ? (ShowRPTag ? "§2[RP]§r" : "")
|
||||
: "§8[OOC]§r"))
|
||||
.replace("{buttonflair}", flair)
|
||||
.replace(
|
||||
"{isitwilds}",
|
||||
(event.getPlayer().getWorld().getName()
|
||||
.equalsIgnoreCase("wilds") ? "[PVP]" : ""))); // 2015.09.04.
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTabComplete(PlayerChatTabCompleteEvent e) {
|
||||
String name = e.getLastToken();
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
String nwithoutformatting = nickname;
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (nwithoutformatting.startsWith(name)
|
||||
&& !nwithoutformatting.equals(Bukkit.getPlayer(
|
||||
nicknames.get(nickname)).getName()))
|
||||
e.getTabCompletions().add(nwithoutformatting);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean DebugMode = false;
|
||||
|
||||
public void SendForDebug(String message) {
|
||||
if (DebugMode) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.sendMessage("[DEBUG] " + message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean ActiveF = false;
|
||||
private int FCount = 0;
|
||||
private long FTime;
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMessage(AsyncPlayerChatEvent e) {
|
||||
if (ActiveF) {
|
||||
if (System.currentTimeMillis() - FTime > 10000) {
|
||||
ActiveF = false;
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
p.sendMessage("§b" + FCount + " "
|
||||
+ (FCount == 1 ? "person" : "people")
|
||||
+ " paid their respects.§r");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e.getMessage().equalsIgnoreCase("F")) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(e
|
||||
.getPlayer().getName());
|
||||
if (!mp.PressedF && ActiveF) {
|
||||
FCount++;
|
||||
mp.PressedF = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (e.getMessage().startsWith(">"))
|
||||
e.setMessage("§2" + e.getMessage());
|
||||
|
||||
/*
|
||||
* Channel c = ((Chat) Bukkit.getPluginManager().getPlugin("TownyChat"))
|
||||
* .getChannelsHandler().getActiveChannel(e.getPlayer(),
|
||||
* channelTypes.GLOBAL);
|
||||
*/
|
||||
/*
|
||||
* List<String> modes = ((Chat) Bukkit.getPluginManager().getPlugin(
|
||||
* "TownyChat")).getTowny().getPlayerMode(e.getPlayer()); if
|
||||
* (modes.size() == 0 || modes.contains("g")) {
|
||||
*/
|
||||
if (e.getFormat().contains("[g]")) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("tellraw @a [\"\"");
|
||||
sb.append(",{\"text\":\"Hashtags:\"}");
|
||||
int index = -1;
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
while ((index = e.getMessage().indexOf("#", index + 1)) != -1) {
|
||||
int index2 = e.getMessage().indexOf(" ", index + 1);
|
||||
if (index2 == -1)
|
||||
index2 = e.getMessage().length();
|
||||
int index3 = e.getMessage().indexOf("#", index + 1);
|
||||
if (index3 != -1 && index3 < index2) // A # occurs before a
|
||||
// space
|
||||
index2 = index3;
|
||||
String original = e.getMessage().substring(index, index2);
|
||||
list.add(original);
|
||||
sb.append(",{\"text\":\" \"}");
|
||||
sb.append(",{\"text\":\"");
|
||||
sb.append(original);
|
||||
sb.append("\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://twitter.com/hashtag/");
|
||||
sb.append(original.substring(1));
|
||||
sb.append("\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open on Twitter\",\"color\":\"blue\"}]}}}");
|
||||
}
|
||||
for (String original : list)
|
||||
e.setMessage(e.getMessage().replace(
|
||||
original,
|
||||
"§9"
|
||||
+ original
|
||||
+ (e.getMessage().startsWith("§2>") ? "§2"
|
||||
: "§r")));
|
||||
/*
|
||||
* for (String original : list)
|
||||
* System.out.println(e.getMessage().replace( original, "§9" +
|
||||
* original + (e.getMessage().startsWith("§2>") ? "§2" : "§r")));
|
||||
*/
|
||||
|
||||
sb.append("]");
|
||||
|
||||
if (list.size() > 0)
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Instance.getServer().getConsoleSender(),
|
||||
sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDeath(PlayerDeathEvent e) {
|
||||
if (!Minigames.plugin.pdata.getMinigamePlayer(e.getEntity())
|
||||
.isInMinigame() && new Random().nextBoolean()) {
|
||||
ActiveF = true;
|
||||
FCount = 0;
|
||||
FTime = System.currentTimeMillis();
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(p
|
||||
.getName());
|
||||
mp.PressedF = false;
|
||||
p.sendMessage("§bPress F to pay respects.§r");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,574 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
|
||||
public static boolean PluginUpdated = false; // 2015.08.31.
|
||||
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label,
|
||||
String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
switch (cmd.getName()) {
|
||||
case "u": {
|
||||
if (args.length < 1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(player
|
||||
.getName()); // 2015.08.08.
|
||||
if (!p.CommentedOnReddit
|
||||
&& !args[0].toLowerCase().equals("admin")
|
||||
&& !args[0].toLowerCase().equals("ignore")) {
|
||||
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")) { // 2015.08.10.
|
||||
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")) { // 2015.08.19.
|
||||
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
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
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");
|
||||
} else
|
||||
player.sendMessage("§cYou already ignored this request.§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
|
||||
break;
|
||||
case "announce":
|
||||
DoAnnounce(player, args, null);
|
||||
break;
|
||||
case "name":
|
||||
if (args.length == 1) {
|
||||
player.sendMessage("§cUsage: /u name <playername>§r");
|
||||
break;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[1])) {
|
||||
player.sendMessage("§cUnknown user: " + args[1]);
|
||||
break;
|
||||
}
|
||||
player.sendMessage("§bUsername of "
|
||||
+ args[1]
|
||||
+ ": "
|
||||
+ MaybeOfflinePlayer.AllPlayers.get(args[1]).UserName);
|
||||
break;
|
||||
case "enable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = true;
|
||||
player.sendMessage("Enabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
case "disable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = false;
|
||||
player.sendMessage("Disabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "nrp":
|
||||
case "ooc":
|
||||
if (args.length == 0) {
|
||||
return false;
|
||||
} else {
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = false;
|
||||
String message = "";
|
||||
for (String arg : args)
|
||||
message += arg + " ";
|
||||
player.chat(message.substring(0, message.length() - 1));
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = true;
|
||||
}
|
||||
return true;
|
||||
case "skype":
|
||||
// "skype:?chat&blob=Y_5Ob1BEcw0ZlstdUHyf0ENS5n1Xz2Huhx-5b-pB2JyMSRO5QMEALkJuTSuUaAb3-XfWXwCndwhGex_UpXDbyQ";
|
||||
return true;
|
||||
default:
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
}
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("admin")) // 2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); // 2015.08.09.
|
||||
return true; // 2015.08.09.
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("announce")) {
|
||||
if (sender instanceof BlockCommandSender)
|
||||
DoAnnounce(null, args, (BlockCommandSender) sender);
|
||||
else
|
||||
DoAnnounce(null, args, null);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void DoReload(Player player) { // 2015.07.20.
|
||||
try {
|
||||
PluginMain.Console
|
||||
.sendMessage("§6-- Reloading The Button Minecraft plugin...§r");
|
||||
PluginMain.LoadFiles(true); // 2015.08.09.
|
||||
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.
|
||||
}
|
||||
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.
|
||||
}
|
||||
PluginMain.Console.sendMessage("§6-- Reloading done!§r");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
if (player != null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static Player ReloadPlayer; // 2015.08.09.
|
||||
|
||||
private static String DoAdminUsage = "§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin|togglerpshow|toggledebug|savepos|loadpos§r";
|
||||
|
||||
private static void DoAdmin(Player player, String[] args) { // 2015.08.09.
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// args[0] is "admin"
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "reload":
|
||||
ReloadPlayer = player; // 2015.08.09.
|
||||
SendMessage(
|
||||
player,
|
||||
"§bMake sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
break; // <-- 2015.08.10.
|
||||
case "confirm":
|
||||
if (ReloadPlayer == player)
|
||||
DoReload(player); // 2015.08.09.
|
||||
else
|
||||
SendMessage(player,
|
||||
"§cYou need to do /u admin reload first.§r");
|
||||
break;
|
||||
case "save":
|
||||
PluginMain.SaveFiles(); // 2015.08.09.
|
||||
SendMessage(player,
|
||||
"§bSaved files. Now you can edit them and reload if you want.§r");
|
||||
break;
|
||||
case "setflair":
|
||||
DoSetFlair(player, args);
|
||||
break;
|
||||
case "updateplugin": // 2015.08.10.
|
||||
DoUpdatePlugin(player);
|
||||
break;
|
||||
case "togglerpshow":
|
||||
PlayerListener.ShowRPTag = !PlayerListener.ShowRPTag;
|
||||
SendMessage(player, "RP tag showing "
|
||||
+ (PlayerListener.ShowRPTag ? "enabled" : "disabled"));
|
||||
break;
|
||||
case "toggledebug":
|
||||
PlayerListener.DebugMode = !PlayerListener.DebugMode;
|
||||
SendMessage(player, "DebugMode: " + PlayerListener.DebugMode);
|
||||
break;
|
||||
case "savepos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "loadpos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "updatedynmap":
|
||||
DoUpdateDynmap(player, args);
|
||||
default:
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
|
||||
private static void DoPlayerInfo(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "playerinfo"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(args[2]);
|
||||
if (p == null) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
SendMessage(player, "Player name: " + p.PlayerName);
|
||||
SendMessage(player, "User flair: " + p.Flair);
|
||||
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);
|
||||
}
|
||||
|
||||
private static void SendMessage(Player player, String message) { // 2015.08.09.
|
||||
if (player == null)
|
||||
PluginMain.Console.sendMessage(message); // 2015.08.12.
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
private static void DoGetLastError(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "getlasterror"
|
||||
if (PluginMain.LastException != null) {
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException = null;
|
||||
} else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
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");
|
||||
return;
|
||||
}
|
||||
Player p = Bukkit.getPlayer(args[2]);
|
||||
if (p == null) {
|
||||
SendMessage(player, "§cPLayer not found.&r");
|
||||
return;
|
||||
}
|
||||
SetPlayerFlair(player,
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()), args[3]);
|
||||
}
|
||||
|
||||
private static void DoUpdatePlugin(Player player) { // 2015.08.10.
|
||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
||||
System.out.println("Forced updating of Auto-Flair plugin.");
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(
|
||||
"https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
||||
FileUtils.copyURLToFile(url, new File(
|
||||
"plugins/TheButtonAutoFlair.jar"));
|
||||
PluginUpdated = true; // 2015.08.31.
|
||||
SendMessage(player, "Updating done!");
|
||||
} catch (MalformedURLException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoAnnounce(Player player, String[] args,
|
||||
BlockCommandSender commandblock) {
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "add":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce add <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
PluginMain.AnnounceMessages.add(finalmessage);
|
||||
SendMessage(player, "§bAnnouncement added.§r");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce remove <index>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceMessages.remove(Integer.parseInt(args[2]));
|
||||
break;
|
||||
case "settime":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player,
|
||||
"§cUsage: /u announce settime <minutes>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceTime = Integer.parseInt(args[2]) * 60 * 1000;
|
||||
SendMessage(player, "Time set between announce messages");
|
||||
break;
|
||||
case "list":
|
||||
SendMessage(player, "§bList of announce messages:§r");
|
||||
SendMessage(player, "§bFormat: [index] message§r");
|
||||
int i = 0;
|
||||
for (String message : PluginMain.AnnounceMessages)
|
||||
SendMessage(player, "[" + i++ + "] " + message);
|
||||
SendMessage(player,
|
||||
"§bCurrent wait time between announcements: "
|
||||
+ PluginMain.AnnounceTime / 60 / 1000
|
||||
+ " minute(s)§r");
|
||||
break;
|
||||
case "edit":
|
||||
if (commandblock == null) {
|
||||
SendMessage(
|
||||
player,
|
||||
"§cError: This command can only be used from a command block. Use /u announce remove.");
|
||||
break;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
commandblock
|
||||
.sendMessage("§cUsage: /u announce edit <index> <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 3; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§');
|
||||
int index = Integer.parseInt(args[2]);
|
||||
if (index > 100)
|
||||
break;
|
||||
while (PluginMain.AnnounceMessages.size() <= index)
|
||||
PluginMain.AnnounceMessages.add("");
|
||||
PluginMain.AnnounceMessages.set(Integer.parseInt(args[2]),
|
||||
finalmessage1);
|
||||
commandblock.sendMessage("Announcement edited.");
|
||||
break;
|
||||
default:
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoSaveLoadPos(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "savepos|loadpos"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
Player p = null;
|
||||
for (Player pl : PluginMain.GetPlayers()) {
|
||||
if (pl.getName().equals(args[2])) {
|
||||
p = pl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (p == null) {
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer is not online: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (args[1].equalsIgnoreCase("savepos")) {
|
||||
mp.SavedLocation = p.getLocation();
|
||||
} else if (args[1].equalsIgnoreCase("loadpos")) {
|
||||
if (mp.SavedLocation != null)
|
||||
p.teleport(mp.SavedLocation);
|
||||
} else {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// SendMessage(player, "Player " + p.getName() +
|
||||
// " position saved/loaded.");s
|
||||
}
|
||||
|
||||
private static void DoUpdateDynmap(Player player, String[] args) {
|
||||
// args[0] is "admin" - args[1] is "updatedynmap"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin updatedynmap <password>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<String> Quiz = new ArrayList<>();
|
||||
|
||||
private static void DoQuiz(Player player, String[] args,
|
||||
BlockCommandSender commandblock) {
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = "§cUsage: /u quiz add|remove|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "add":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u quiz add <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
Quiz.add(finalmessage);
|
||||
SendMessage(player, "§Quiz question added.§r");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u quiz remove <index>");
|
||||
return;
|
||||
}
|
||||
Quiz.remove(Integer.parseInt(args[2]));
|
||||
break;
|
||||
case "list":
|
||||
SendMessage(player, "§bList of quiz questions:§r");
|
||||
SendMessage(player, "§bFormat: [index] question§r");
|
||||
int i = 0;
|
||||
for (String question : Quiz)
|
||||
SendMessage(player, "[" + i++ + "] " + question);
|
||||
break;
|
||||
case "edit":
|
||||
if (commandblock == null) {
|
||||
SendMessage(
|
||||
player,
|
||||
"§cError: This command can only be used from a command block. Use /u quiz remove.");
|
||||
break;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
commandblock
|
||||
.sendMessage("§cUsage: /u quiz edit <index> <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 3; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§');
|
||||
int index = Integer.parseInt(args[2]);
|
||||
if (index > 100)
|
||||
break;
|
||||
while (Quiz.size() <= index)
|
||||
Quiz.add("");
|
||||
Quiz.set(Integer.parseInt(args[2]), finalmessage1);
|
||||
commandblock.sendMessage("Question edited.");
|
||||
break;
|
||||
default:
|
||||
String message = "§cUsage: /u quiz add|remove|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,588 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
|
||||
public static boolean PluginUpdated = false; // 2015.08.31.
|
||||
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label,
|
||||
String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
switch (cmd.getName()) {
|
||||
case "u": {
|
||||
if (args.length < 1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(player
|
||||
.getName()); // 2015.08.08.
|
||||
if (!p.CommentedOnReddit
|
||||
&& !args[0].toLowerCase().equals("admin")
|
||||
&& !args[0].toLowerCase().equals("ignore")) {
|
||||
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")) { // 2015.08.10.
|
||||
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")) { // 2015.08.19.
|
||||
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
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
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");
|
||||
} else
|
||||
player.sendMessage("§cYou already ignored this request.§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
|
||||
break;
|
||||
case "announce":
|
||||
DoAnnounce(player, args, null);
|
||||
break;
|
||||
case "name":
|
||||
if (args.length == 1) {
|
||||
player.sendMessage("§cUsage: /u name <playername>§r");
|
||||
break;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[1])) {
|
||||
player.sendMessage("§cUnknown user: " + args[1]);
|
||||
break;
|
||||
}
|
||||
player.sendMessage("§bUsername of "
|
||||
+ args[1]
|
||||
+ ": "
|
||||
+ MaybeOfflinePlayer.AllPlayers.get(args[1]).UserName);
|
||||
break;
|
||||
case "enable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = true;
|
||||
player.sendMessage("Enabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
case "disable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = false;
|
||||
player.sendMessage("Disabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "nrp":
|
||||
case "ooc":
|
||||
if (args.length == 0) {
|
||||
return false;
|
||||
} else {
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = false;
|
||||
String message = "";
|
||||
for (String arg : args)
|
||||
message += arg + " ";
|
||||
player.chat(message.substring(0, message.length() - 1));
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = true;
|
||||
}
|
||||
return true;
|
||||
case "skype":
|
||||
// "skype:?chat&blob=Y_5Ob1BEcw0ZlstdUHyf0ENS5n1Xz2Huhx-5b-pB2JyMSRO5QMEALkJuTSuUaAb3-XfWXwCndwhGex_UpXDbyQ";
|
||||
return true;
|
||||
default:
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
}
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("admin")) // 2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); // 2015.08.09.
|
||||
return true; // 2015.08.09.
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("announce")) {
|
||||
if (sender instanceof BlockCommandSender)
|
||||
DoAnnounce(null, args, (BlockCommandSender) sender);
|
||||
else
|
||||
DoAnnounce(null, args, null);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void DoReload(Player player) { // 2015.07.20.
|
||||
try {
|
||||
PluginMain.Console
|
||||
.sendMessage("§6-- Reloading The Button Minecraft plugin...§r");
|
||||
PluginMain.LoadFiles(true); // 2015.08.09.
|
||||
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.
|
||||
}
|
||||
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.
|
||||
}
|
||||
PluginMain.Console.sendMessage("§6-- Reloading done!§r");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
if (player != null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static Player ReloadPlayer; // 2015.08.09.
|
||||
|
||||
private static String DoAdminUsage = "§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin|togglerpshow|toggledebug|savepos|loadpos§r";
|
||||
|
||||
private static void DoAdmin(Player player, String[] args) { // 2015.08.09.
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// args[0] is "admin"
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "reload":
|
||||
ReloadPlayer = player; // 2015.08.09.
|
||||
SendMessage(
|
||||
player,
|
||||
"§bMake sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
break; // <-- 2015.08.10.
|
||||
case "confirm":
|
||||
if (ReloadPlayer == player)
|
||||
DoReload(player); // 2015.08.09.
|
||||
else
|
||||
SendMessage(player,
|
||||
"§cYou need to do /u admin reload first.§r");
|
||||
break;
|
||||
case "save":
|
||||
PluginMain.SaveFiles(); // 2015.08.09.
|
||||
SendMessage(player,
|
||||
"§bSaved files. Now you can edit them and reload if you want.§r");
|
||||
break;
|
||||
case "setflair":
|
||||
DoSetFlair(player, args);
|
||||
break;
|
||||
case "updateplugin": // 2015.08.10.
|
||||
DoUpdatePlugin(player);
|
||||
break;
|
||||
case "togglerpshow":
|
||||
PlayerListener.ShowRPTag = !PlayerListener.ShowRPTag;
|
||||
SendMessage(player, "RP tag showing "
|
||||
+ (PlayerListener.ShowRPTag ? "enabled" : "disabled"));
|
||||
break;
|
||||
case "toggledebug":
|
||||
PlayerListener.DebugMode = !PlayerListener.DebugMode;
|
||||
SendMessage(player, "DebugMode: " + PlayerListener.DebugMode);
|
||||
break;
|
||||
case "savepos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "loadpos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "updatedynmap":
|
||||
DoUpdateDynmap(player, args);
|
||||
default:
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
|
||||
private static void DoPlayerInfo(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "playerinfo"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(args[2]);
|
||||
if (p == null) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
SendMessage(player, "Player name: " + p.PlayerName);
|
||||
SendMessage(player, "User flair: " + p.Flair);
|
||||
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);
|
||||
}
|
||||
|
||||
private static void SendMessage(Player player, String message) { // 2015.08.09.
|
||||
if (player == null)
|
||||
PluginMain.Console.sendMessage(message); // 2015.08.12.
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
private static void DoGetLastError(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "getlasterror"
|
||||
if (PluginMain.LastException != null) {
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException = null;
|
||||
} else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
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");
|
||||
return;
|
||||
}
|
||||
Player p = Bukkit.getPlayer(args[2]);
|
||||
if (p == null) {
|
||||
SendMessage(player, "§cPLayer not found.&r");
|
||||
return;
|
||||
}
|
||||
SetPlayerFlair(player,
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()), args[3]);
|
||||
}
|
||||
|
||||
private static void DoUpdatePlugin(Player player) { // 2015.08.10.
|
||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
||||
System.out.println("Forced updating of Auto-Flair plugin.");
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(
|
||||
"https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
||||
FileUtils.copyURLToFile(url, new File(
|
||||
"plugins/TheButtonAutoFlair.jar"));
|
||||
PluginUpdated = true; // 2015.08.31.
|
||||
SendMessage(player, "Updating done!");
|
||||
} catch (MalformedURLException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoAnnounce(Player player, String[] args,
|
||||
BlockCommandSender commandblock) {
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "add":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce add <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
PluginMain.AnnounceMessages.add(finalmessage);
|
||||
SendMessage(player, "§bAnnouncement added.§r");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce remove <index>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceMessages.remove(Integer.parseInt(args[2]));
|
||||
break;
|
||||
case "settime":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player,
|
||||
"§cUsage: /u announce settime <minutes>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceTime = Integer.parseInt(args[2]) * 60 * 1000;
|
||||
SendMessage(player, "Time set between announce messages");
|
||||
break;
|
||||
case "list":
|
||||
SendMessage(player, "§bList of announce messages:§r");
|
||||
SendMessage(player, "§bFormat: [index] message§r");
|
||||
int i = 0;
|
||||
for (String message : PluginMain.AnnounceMessages)
|
||||
SendMessage(player, "[" + i++ + "] " + message);
|
||||
SendMessage(player,
|
||||
"§bCurrent wait time between announcements: "
|
||||
+ PluginMain.AnnounceTime / 60 / 1000
|
||||
+ " minute(s)§r");
|
||||
break;
|
||||
case "edit":
|
||||
if (commandblock == null) {
|
||||
SendMessage(
|
||||
player,
|
||||
"§cError: This command can only be used from a command block. Use /u announce remove.");
|
||||
break;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
commandblock
|
||||
.sendMessage("§cUsage: /u announce edit <index> <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 3; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§');
|
||||
int index = Integer.parseInt(args[2]);
|
||||
if (index > 100)
|
||||
break;
|
||||
while (PluginMain.AnnounceMessages.size() <= index)
|
||||
PluginMain.AnnounceMessages.add("");
|
||||
PluginMain.AnnounceMessages.set(Integer.parseInt(args[2]),
|
||||
finalmessage1);
|
||||
commandblock.sendMessage("Announcement edited.");
|
||||
break;
|
||||
default:
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoSaveLoadPos(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "savepos|loadpos"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
Player p = null;
|
||||
for (Player pl : PluginMain.GetPlayers()) {
|
||||
if (pl.getName().equals(args[2])) {
|
||||
p = pl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (p == null) {
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer is not online: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (args[1].equalsIgnoreCase("savepos")) {
|
||||
mp.SavedLocation = p.getLocation();
|
||||
} else if (args[1].equalsIgnoreCase("loadpos")) {
|
||||
if (mp.SavedLocation != null)
|
||||
p.teleport(mp.SavedLocation);
|
||||
} else {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// SendMessage(player, "Player " + p.getName() +
|
||||
// " position saved/loaded.");s
|
||||
}
|
||||
|
||||
private static void DoUpdateDynmap(Player player, String[] args) {
|
||||
// args[0] is "admin" - args[1] is "updatedynmap"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin updatedynmap <password>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static ArrayList<String> Quiz = new ArrayList<>();
|
||||
|
||||
private static void DoQuiz(Player player, String[] args,
|
||||
BlockCommandSender commandblock) {
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = "§cUsage: /u quiz add|remove|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "add":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u quiz add <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
Quiz.add(finalmessage);
|
||||
SendMessage(player, "§bAnnouncement added.§r");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce remove <index>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceMessages.remove(Integer.parseInt(args[2]));
|
||||
break;
|
||||
case "settime":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player,
|
||||
"§cUsage: /u announce settime <minutes>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceTime = Integer.parseInt(args[2]) * 60 * 1000;
|
||||
SendMessage(player, "Time set between announce messages");
|
||||
break;
|
||||
case "list":
|
||||
SendMessage(player, "§bList of announce messages:§r");
|
||||
SendMessage(player, "§bFormat: [index] message§r");
|
||||
int i = 0;
|
||||
for (String message : PluginMain.AnnounceMessages)
|
||||
SendMessage(player, "[" + i++ + "] " + message);
|
||||
SendMessage(player,
|
||||
"§bCurrent wait time between announcements: "
|
||||
+ PluginMain.AnnounceTime / 60 / 1000
|
||||
+ " minute(s)§r");
|
||||
break;
|
||||
case "edit":
|
||||
if (commandblock == null) {
|
||||
SendMessage(
|
||||
player,
|
||||
"§cError: This command can only be used from a command block. Use /u announce remove.");
|
||||
break;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
commandblock
|
||||
.sendMessage("§cUsage: /u announce edit <index> <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 3; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§');
|
||||
int index = Integer.parseInt(args[2]);
|
||||
if (index > 100)
|
||||
break;
|
||||
while (PluginMain.AnnounceMessages.size() <= index)
|
||||
PluginMain.AnnounceMessages.add("");
|
||||
PluginMain.AnnounceMessages.set(Integer.parseInt(args[2]),
|
||||
finalmessage1);
|
||||
commandblock.sendMessage("Announcement edited.");
|
||||
break;
|
||||
default:
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,354 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
|
||||
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/
|
||||
private static PluginMain Instance;
|
||||
// Fired when plugin is first enabled
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
this.getCommand("u").setExecutor(new Commands());
|
||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||
Instance=this; //2015.08.08.
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
//System.out.println("Name: " + name);
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("flairsignored.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while((line=br.readLine())!=null)
|
||||
{
|
||||
String[] s=line.split(" ");
|
||||
TownColors.put(s[0], s[1]);
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
//throw new IOException("Test"); //2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||
Thread t=new Thread(r);
|
||||
t.start();
|
||||
}
|
||||
Boolean stop=false;
|
||||
// Fired when plugin is disabled
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
try
|
||||
{
|
||||
FileWriter fw;
|
||||
fw = new FileWriter("flairsaccepted.txt");
|
||||
fw.close();
|
||||
fw = new FileWriter("flairsignored.txt");
|
||||
fw.close();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.AcceptedFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
file=new File("flairsignored.txt");
|
||||
bw = new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.IgnoredFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
stop=true;
|
||||
}
|
||||
|
||||
public void ThreadMethod() //<-- 2015.07.16.
|
||||
{
|
||||
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();
|
||||
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();
|
||||
if(HasIGFlair(ign))
|
||||
continue;
|
||||
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";
|
||||
else
|
||||
flair = "non-presser";
|
||||
String flairclass;
|
||||
if(flairdata.length>2)
|
||||
flairclass = flairdata[2];
|
||||
else
|
||||
flairclass="unknown";
|
||||
SetFlair(ign, flair, flairclass, author);
|
||||
}
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Exception LastException; //2015.08.09.
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||
public Boolean HasIGFlair(String playername)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
return p.Flair!=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||
{
|
||||
String finalflair;
|
||||
switch(flairclass)
|
||||
{
|
||||
case "press-1":
|
||||
finalflair="§c("+text+")§r";
|
||||
break;
|
||||
case "press-2":
|
||||
finalflair="§6("+text+")§r";
|
||||
break;
|
||||
case "press-3":
|
||||
finalflair="§e("+text+")§r";
|
||||
break;
|
||||
case "press-4":
|
||||
finalflair="§a("+text+")§r";
|
||||
break;
|
||||
case "press-5":
|
||||
finalflair="§9("+text+")§r";
|
||||
break;
|
||||
case "press-6":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "no-press":
|
||||
finalflair="§7(non-pr.)§r";
|
||||
break;
|
||||
case "cheater":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "cant-press": //2015.08.08.
|
||||
finalflair="§r(can't press)§r";
|
||||
break;
|
||||
case "undecided": //2015.08.09.
|
||||
finalflair="";
|
||||
break;
|
||||
default:
|
||||
finalflair="";
|
||||
break;
|
||||
}
|
||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||
return;
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
p.Flair=finalflair; //2015.08.08.
|
||||
p.UserName=username; //2015.08.08.
|
||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||
{
|
||||
if(player.getName().equals(playername))
|
||||
{
|
||||
AppendPlayerDisplayFlair(player, username, finalflair);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String GetFlair(Player player)
|
||||
{ //2015.07.16.
|
||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||
return flair==null ? "" : flair;
|
||||
}
|
||||
|
||||
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||
{
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
||||
return;
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
||||
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
else
|
||||
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
||||
}
|
||||
|
||||
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||
String[] colors = color.substring(1).split("§");
|
||||
String displayname=player.getName(); //2015.08.08.
|
||||
ArrayList<Integer> Positions=new ArrayList<>();
|
||||
for(int i=0; i<displayname.length(); i++) {
|
||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||
Positions.add(i);
|
||||
}
|
||||
}
|
||||
String finalname=""; //TODO
|
||||
if(Positions.size()>=colors.length)
|
||||
{
|
||||
int x=0;
|
||||
for(int i=0; i<Positions.size(); i++)
|
||||
{
|
||||
int pos=Positions.get(i);
|
||||
int nextpos;
|
||||
if(i!=Positions.size()-1)
|
||||
nextpos=Positions.get(i+1);
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Positions.clear();
|
||||
int unit=displayname.length()/colors.length;
|
||||
int x=0;
|
||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||
{
|
||||
int pos=i;
|
||||
int nextpos;
|
||||
if(i<displayname.length()-unit-unit)
|
||||
nextpos=i+unit;
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||
}
|
||||
|
||||
public static String GetColorForTown(String townname)
|
||||
{ //2015.07.20.
|
||||
if(TownColors.containsKey(townname))
|
||||
return TownColors.get(townname);
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String GetPlayerTown(Player player)
|
||||
{ //2015.07.20.
|
||||
try {
|
||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||
return town.getName();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public static Collection<? extends Player> GetPlayers()
|
||||
{
|
||||
return Instance.getServer().getOnlinePlayers();
|
||||
}
|
||||
}
|
|
@ -1,583 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
|
||||
public static boolean PluginUpdated = false; // 2015.08.31.
|
||||
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label,
|
||||
String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
switch (cmd.getName()) {
|
||||
case "u": {
|
||||
if (args.length < 1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(player
|
||||
.getName()); // 2015.08.08.
|
||||
if (!p.CommentedOnReddit
|
||||
&& !args[0].toLowerCase().equals("admin")
|
||||
&& !args[0].toLowerCase().equals("ignore")) {
|
||||
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")) { // 2015.08.10.
|
||||
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")) { // 2015.08.19.
|
||||
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
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
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");
|
||||
} else
|
||||
player.sendMessage("§cYou already ignored this request.§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
|
||||
break;
|
||||
case "announce":
|
||||
DoAnnounce(player, args, null);
|
||||
break;
|
||||
case "name":
|
||||
if (args.length == 1) {
|
||||
player.sendMessage("§cUsage: /u name <playername>§r");
|
||||
break;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[1])) {
|
||||
player.sendMessage("§cUnknown user: " + args[1]);
|
||||
break;
|
||||
}
|
||||
player.sendMessage("§bUsername of "
|
||||
+ args[1]
|
||||
+ ": "
|
||||
+ MaybeOfflinePlayer.AllPlayers.get(args[1]).UserName);
|
||||
break;
|
||||
case "enable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = true;
|
||||
player.sendMessage("Enabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
case "disable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = false;
|
||||
player.sendMessage("Disabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
case "quiz":
|
||||
DoQuiz(player, args, null);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "nrp":
|
||||
case "ooc":
|
||||
if (args.length == 0) {
|
||||
return false;
|
||||
} else {
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = false;
|
||||
String message = "";
|
||||
for (String arg : args)
|
||||
message += arg + " ";
|
||||
player.chat(message.substring(0, message.length() - 1));
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = true;
|
||||
}
|
||||
return true;
|
||||
case "skype":
|
||||
// "skype:?chat&blob=Y_5Ob1BEcw0ZlstdUHyf0ENS5n1Xz2Huhx-5b-pB2JyMSRO5QMEALkJuTSuUaAb3-XfWXwCndwhGex_UpXDbyQ";
|
||||
return true;
|
||||
default:
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
}
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("admin")) // 2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); // 2015.08.09.
|
||||
return true; // 2015.08.09.
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("announce")) {
|
||||
if (sender instanceof BlockCommandSender)
|
||||
DoAnnounce(null, args, (BlockCommandSender) sender);
|
||||
else
|
||||
DoAnnounce(null, args, null);
|
||||
return true;
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("announce")) {
|
||||
if (sender instanceof BlockCommandSender)
|
||||
DoAnnounce(null, args, (BlockCommandSender) sender);
|
||||
else
|
||||
DoAnnounce(null, args, null);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void DoReload(Player player) { // 2015.07.20.
|
||||
try {
|
||||
PluginMain.Console
|
||||
.sendMessage("§6-- Reloading The Button Minecraft plugin...§r");
|
||||
PluginMain.LoadFiles(true); // 2015.08.09.
|
||||
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.
|
||||
}
|
||||
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.
|
||||
}
|
||||
PluginMain.Console.sendMessage("§6-- Reloading done!§r");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
if (player != null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static Player ReloadPlayer; // 2015.08.09.
|
||||
|
||||
private static String DoAdminUsage = "§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin|togglerpshow|toggledebug|savepos|loadpos§r";
|
||||
|
||||
private static void DoAdmin(Player player, String[] args) { // 2015.08.09.
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// args[0] is "admin"
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "reload":
|
||||
ReloadPlayer = player; // 2015.08.09.
|
||||
SendMessage(
|
||||
player,
|
||||
"§bMake sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
break; // <-- 2015.08.10.
|
||||
case "confirm":
|
||||
if (ReloadPlayer == player)
|
||||
DoReload(player); // 2015.08.09.
|
||||
else
|
||||
SendMessage(player,
|
||||
"§cYou need to do /u admin reload first.§r");
|
||||
break;
|
||||
case "save":
|
||||
PluginMain.SaveFiles(); // 2015.08.09.
|
||||
SendMessage(player,
|
||||
"§bSaved files. Now you can edit them and reload if you want.§r");
|
||||
break;
|
||||
case "setflair":
|
||||
DoSetFlair(player, args);
|
||||
break;
|
||||
case "updateplugin": // 2015.08.10.
|
||||
DoUpdatePlugin(player);
|
||||
break;
|
||||
case "togglerpshow":
|
||||
PlayerListener.ShowRPTag = !PlayerListener.ShowRPTag;
|
||||
SendMessage(player, "RP tag showing "
|
||||
+ (PlayerListener.ShowRPTag ? "enabled" : "disabled"));
|
||||
break;
|
||||
case "toggledebug":
|
||||
PlayerListener.DebugMode = !PlayerListener.DebugMode;
|
||||
SendMessage(player, "DebugMode: " + PlayerListener.DebugMode);
|
||||
break;
|
||||
case "savepos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "loadpos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "updatedynmap":
|
||||
DoUpdateDynmap(player, args);
|
||||
default:
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
|
||||
private static void DoPlayerInfo(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "playerinfo"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(args[2]);
|
||||
if (p == null) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
SendMessage(player, "Player name: " + p.PlayerName);
|
||||
SendMessage(player, "User flair: " + p.Flair);
|
||||
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);
|
||||
}
|
||||
|
||||
private static void SendMessage(Player player, String message) { // 2015.08.09.
|
||||
if (player == null)
|
||||
PluginMain.Console.sendMessage(message); // 2015.08.12.
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
private static void DoGetLastError(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "getlasterror"
|
||||
if (PluginMain.LastException != null) {
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException = null;
|
||||
} else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
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");
|
||||
return;
|
||||
}
|
||||
Player p = Bukkit.getPlayer(args[2]);
|
||||
if (p == null) {
|
||||
SendMessage(player, "§cPLayer not found.&r");
|
||||
return;
|
||||
}
|
||||
SetPlayerFlair(player,
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()), args[3]);
|
||||
}
|
||||
|
||||
private static void DoUpdatePlugin(Player player) { // 2015.08.10.
|
||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
||||
System.out.println("Forced updating of Auto-Flair plugin.");
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(
|
||||
"https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
||||
FileUtils.copyURLToFile(url, new File(
|
||||
"plugins/TheButtonAutoFlair.jar"));
|
||||
PluginUpdated = true; // 2015.08.31.
|
||||
SendMessage(player, "Updating done!");
|
||||
} catch (MalformedURLException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoAnnounce(Player player, String[] args,
|
||||
BlockCommandSender commandblock) {
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "add":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce add <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
PluginMain.AnnounceMessages.add(finalmessage);
|
||||
SendMessage(player, "§bAnnouncement added.§r");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce remove <index>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceMessages.remove(Integer.parseInt(args[2]));
|
||||
break;
|
||||
case "settime":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player,
|
||||
"§cUsage: /u announce settime <minutes>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceTime = Integer.parseInt(args[2]) * 60 * 1000;
|
||||
SendMessage(player, "Time set between announce messages");
|
||||
break;
|
||||
case "list":
|
||||
SendMessage(player, "§bList of announce messages:§r");
|
||||
SendMessage(player, "§bFormat: [index] message§r");
|
||||
int i = 0;
|
||||
for (String message : PluginMain.AnnounceMessages)
|
||||
SendMessage(player, "[" + i++ + "] " + message);
|
||||
SendMessage(player,
|
||||
"§bCurrent wait time between announcements: "
|
||||
+ PluginMain.AnnounceTime / 60 / 1000
|
||||
+ " minute(s)§r");
|
||||
break;
|
||||
case "edit":
|
||||
if (commandblock == null) {
|
||||
SendMessage(
|
||||
player,
|
||||
"§cError: This command can only be used from a command block. Use /u announce remove.");
|
||||
break;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
commandblock
|
||||
.sendMessage("§cUsage: /u announce edit <index> <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 3; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§');
|
||||
int index = Integer.parseInt(args[2]);
|
||||
if (index > 100)
|
||||
break;
|
||||
while (PluginMain.AnnounceMessages.size() <= index)
|
||||
PluginMain.AnnounceMessages.add("");
|
||||
PluginMain.AnnounceMessages.set(Integer.parseInt(args[2]),
|
||||
finalmessage1);
|
||||
commandblock.sendMessage("Announcement edited.");
|
||||
break;
|
||||
default:
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoSaveLoadPos(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "savepos|loadpos"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
Player p = null;
|
||||
for (Player pl : PluginMain.GetPlayers()) {
|
||||
if (pl.getName().equals(args[2])) {
|
||||
p = pl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (p == null) {
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer is not online: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (args[1].equalsIgnoreCase("savepos")) {
|
||||
mp.SavedLocation = p.getLocation();
|
||||
} else if (args[1].equalsIgnoreCase("loadpos")) {
|
||||
if (mp.SavedLocation != null)
|
||||
p.teleport(mp.SavedLocation);
|
||||
} else {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// SendMessage(player, "Player " + p.getName() +
|
||||
// " position saved/loaded.");s
|
||||
}
|
||||
|
||||
private static void DoUpdateDynmap(Player player, String[] args) {
|
||||
// args[0] is "admin" - args[1] is "updatedynmap"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin updatedynmap <password>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<String> Quiz = new ArrayList<>();
|
||||
|
||||
private static void DoQuiz(Player player, String[] args,
|
||||
BlockCommandSender commandblock) {
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = "§cUsage: /u quiz add|remove|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "add":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u quiz add <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
Quiz.add(finalmessage);
|
||||
SendMessage(player, "§Quiz question added.§r");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u quiz remove <index>");
|
||||
return;
|
||||
}
|
||||
Quiz.remove(Integer.parseInt(args[2]));
|
||||
break;
|
||||
case "list":
|
||||
SendMessage(player, "§bList of quiz questions:§r");
|
||||
SendMessage(player, "§bFormat: [index] question§r");
|
||||
int i = 0;
|
||||
for (String question : Quiz)
|
||||
SendMessage(player, "[" + i++ + "] " + question);
|
||||
break;
|
||||
case "edit":
|
||||
if (commandblock == null) {
|
||||
SendMessage(
|
||||
player,
|
||||
"§cError: This command can only be used from a command block. Use /u quiz remove.");
|
||||
break;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
commandblock
|
||||
.sendMessage("§cUsage: /u quiz edit <index> <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 3; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§');
|
||||
int index = Integer.parseInt(args[2]);
|
||||
if (index > 100)
|
||||
break;
|
||||
while (Quiz.size() <= index)
|
||||
Quiz.add("");
|
||||
Quiz.set(Integer.parseInt(args[2]), finalmessage1);
|
||||
commandblock.sendMessage("Question edited.");
|
||||
break;
|
||||
default:
|
||||
String message = "§cUsage: /u quiz add|remove|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,370 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
|
||||
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/
|
||||
private static PluginMain Instance;
|
||||
// Fired when plugin is first enabled
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
this.getCommand("u").setExecutor(new Commands());
|
||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||
Instance=this; //2015.08.08.
|
||||
LoadFiles(false); //2015.08.09.
|
||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||
Thread t=new Thread(r);
|
||||
t.start();
|
||||
}
|
||||
Boolean stop=false;
|
||||
// Fired when plugin is disabled
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
try
|
||||
{
|
||||
FileWriter fw;
|
||||
fw = new FileWriter("flairsaccepted.txt");
|
||||
fw.close();
|
||||
fw = new FileWriter("flairsignored.txt");
|
||||
fw.close();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.AcceptedFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
file=new File("flairsignored.txt");
|
||||
bw = new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.IgnoredFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
stop=true;
|
||||
}
|
||||
|
||||
public void ThreadMethod() //<-- 2015.07.16.
|
||||
{
|
||||
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();
|
||||
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();
|
||||
if(HasIGFlair(ign))
|
||||
continue;
|
||||
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";
|
||||
else
|
||||
flair = "non-presser";
|
||||
String flairclass;
|
||||
if(flairdata.length>2)
|
||||
flairclass = flairdata[2];
|
||||
else
|
||||
flairclass="unknown";
|
||||
SetFlair(ign, flair, flairclass, author);
|
||||
}
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Exception LastException; //2015.08.09.
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||
public Boolean HasIGFlair(String playername)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
return p.Flair!=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
String finalflair;
|
||||
p.FlairDecided=true;
|
||||
switch(flairclass)
|
||||
{
|
||||
case "press-1":
|
||||
finalflair="§c("+text+")§r";
|
||||
break;
|
||||
case "press-2":
|
||||
finalflair="§6("+text+")§r";
|
||||
break;
|
||||
case "press-3":
|
||||
finalflair="§e("+text+")§r";
|
||||
break;
|
||||
case "press-4":
|
||||
finalflair="§a("+text+")§r";
|
||||
break;
|
||||
case "press-5":
|
||||
finalflair="§9("+text+")§r";
|
||||
break;
|
||||
case "press-6":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "no-press":
|
||||
finalflair="§7(non-pr.)§r";
|
||||
break;
|
||||
case "cheater":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "cant-press": //2015.08.08.
|
||||
finalflair="§r(can't press)§r";
|
||||
break;
|
||||
case "undecided": //2015.08.09.
|
||||
p.FlairDecided=false;
|
||||
finalflair="";
|
||||
break;
|
||||
default:
|
||||
finalflair="";
|
||||
break;
|
||||
}
|
||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||
return;
|
||||
p.Flair=finalflair; //2015.08.08.
|
||||
p.UserName=username; //2015.08.08.
|
||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||
{
|
||||
if(player.getName().equals(playername))
|
||||
{
|
||||
//AppendPlayerDisplayFlair(player, username, finalflair);
|
||||
AppendPlayerDisplayFlair(p, player);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String GetFlair(Player player)
|
||||
{ //2015.07.16.
|
||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||
return flair==null ? "" : flair;
|
||||
}
|
||||
|
||||
//public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||
public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09.
|
||||
{
|
||||
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair)
|
||||
return;
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair)
|
||||
{
|
||||
AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20.
|
||||
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");
|
||||
}
|
||||
|
||||
private static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||
String[] colors = color.substring(1).split("§");
|
||||
String displayname=player.getName(); //2015.08.08.
|
||||
ArrayList<Integer> Positions=new ArrayList<>();
|
||||
for(int i=0; i<displayname.length(); i++) {
|
||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||
Positions.add(i);
|
||||
}
|
||||
}
|
||||
String finalname=""; //TODO
|
||||
if(Positions.size()>=colors.length)
|
||||
{
|
||||
int x=0;
|
||||
for(int i=0; i<Positions.size(); i++)
|
||||
{
|
||||
int pos=Positions.get(i);
|
||||
int nextpos;
|
||||
if(i!=Positions.size()-1)
|
||||
nextpos=Positions.get(i+1);
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Positions.clear();
|
||||
int unit=displayname.length()/colors.length;
|
||||
int x=0;
|
||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||
{
|
||||
int pos=i;
|
||||
int nextpos;
|
||||
if(i<displayname.length()-unit-unit)
|
||||
nextpos=i+unit;
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||
}
|
||||
|
||||
public static String GetColorForTown(String townname)
|
||||
{ //2015.07.20.
|
||||
if(TownColors.containsKey(townname))
|
||||
return TownColors.get(townname);
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String GetPlayerTown(Player player)
|
||||
{ //2015.07.20.
|
||||
try {
|
||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||
return town.getName();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public static Collection<? extends Player> GetPlayers()
|
||||
{
|
||||
return Instance.getServer().getOnlinePlayers();
|
||||
}
|
||||
|
||||
public static void LoadFiles(boolean reload) //<-- 2015.08.09.
|
||||
{
|
||||
if(reload)
|
||||
MaybeOfflinePlayer.AllPlayers.clear(); //2015.08.09.
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
//System.out.println("Name: " + name);
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("flairsignored.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while((line=br.readLine())!=null)
|
||||
{
|
||||
String[] s=line.split(" ");
|
||||
TownColors.put(s[0], s[1]);
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
//throw new IOException("Test"); //2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,584 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
|
||||
public static boolean PluginUpdated = false; // 2015.08.31.
|
||||
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label,
|
||||
String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
switch (cmd.getName()) {
|
||||
case "u": {
|
||||
if (args.length < 1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(player
|
||||
.getName()); // 2015.08.08.
|
||||
if (!p.CommentedOnReddit
|
||||
&& !args[0].toLowerCase().equals("admin")
|
||||
&& !args[0].toLowerCase().equals("ignore")) {
|
||||
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")) { // 2015.08.10.
|
||||
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")) { // 2015.08.19.
|
||||
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
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
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");
|
||||
} else
|
||||
player.sendMessage("§cYou already ignored this request.§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
|
||||
break;
|
||||
case "announce":
|
||||
DoAnnounce(player, args, null);
|
||||
break;
|
||||
case "name":
|
||||
if (args.length == 1) {
|
||||
player.sendMessage("§cUsage: /u name <playername>§r");
|
||||
break;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[1])) {
|
||||
player.sendMessage("§cUnknown user: " + args[1]);
|
||||
break;
|
||||
}
|
||||
player.sendMessage("§bUsername of "
|
||||
+ args[1]
|
||||
+ ": "
|
||||
+ MaybeOfflinePlayer.AllPlayers.get(args[1]).UserName);
|
||||
break;
|
||||
case "enable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = true;
|
||||
player.sendMessage("Enabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
case "disable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = false;
|
||||
player.sendMessage("Disabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "nrp":
|
||||
case "ooc":
|
||||
if (args.length == 0) {
|
||||
return false;
|
||||
} else {
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = false;
|
||||
String message = "";
|
||||
for (String arg : args)
|
||||
message += arg + " ";
|
||||
player.chat(message.substring(0, message.length() - 1));
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = true;
|
||||
}
|
||||
return true;
|
||||
case "skype":
|
||||
// "skype:?chat&blob=Y_5Ob1BEcw0ZlstdUHyf0ENS5n1Xz2Huhx-5b-pB2JyMSRO5QMEALkJuTSuUaAb3-XfWXwCndwhGex_UpXDbyQ";
|
||||
return true;
|
||||
default:
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
}
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("admin")) // 2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); // 2015.08.09.
|
||||
return true; // 2015.08.09.
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("announce")) {
|
||||
if (sender instanceof BlockCommandSender)
|
||||
DoAnnounce(null, args, (BlockCommandSender) sender);
|
||||
else
|
||||
DoAnnounce(null, args, null);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void DoReload(Player player) { // 2015.07.20.
|
||||
try {
|
||||
PluginMain.Console
|
||||
.sendMessage("§6-- Reloading The Button Minecraft plugin...§r");
|
||||
PluginMain.LoadFiles(true); // 2015.08.09.
|
||||
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.
|
||||
}
|
||||
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.
|
||||
}
|
||||
PluginMain.Console.sendMessage("§6-- Reloading done!§r");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
if (player != null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static Player ReloadPlayer; // 2015.08.09.
|
||||
|
||||
private static String DoAdminUsage = "§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin|togglerpshow|toggledebug|savepos|loadpos§r";
|
||||
|
||||
private static void DoAdmin(Player player, String[] args) { // 2015.08.09.
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// args[0] is "admin"
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "reload":
|
||||
ReloadPlayer = player; // 2015.08.09.
|
||||
SendMessage(
|
||||
player,
|
||||
"§bMake sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
break; // <-- 2015.08.10.
|
||||
case "confirm":
|
||||
if (ReloadPlayer == player)
|
||||
DoReload(player); // 2015.08.09.
|
||||
else
|
||||
SendMessage(player,
|
||||
"§cYou need to do /u admin reload first.§r");
|
||||
break;
|
||||
case "save":
|
||||
PluginMain.SaveFiles(); // 2015.08.09.
|
||||
SendMessage(player,
|
||||
"§bSaved files. Now you can edit them and reload if you want.§r");
|
||||
break;
|
||||
case "setflair":
|
||||
DoSetFlair(player, args);
|
||||
break;
|
||||
case "updateplugin": // 2015.08.10.
|
||||
DoUpdatePlugin(player);
|
||||
break;
|
||||
case "togglerpshow":
|
||||
PlayerListener.ShowRPTag = !PlayerListener.ShowRPTag;
|
||||
SendMessage(player, "RP tag showing "
|
||||
+ (PlayerListener.ShowRPTag ? "enabled" : "disabled"));
|
||||
break;
|
||||
case "toggledebug":
|
||||
PlayerListener.DebugMode = !PlayerListener.DebugMode;
|
||||
SendMessage(player, "DebugMode: " + PlayerListener.DebugMode);
|
||||
break;
|
||||
case "savepos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "loadpos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "updatedynmap":
|
||||
DoUpdateDynmap(player, args);
|
||||
default:
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
|
||||
private static void DoPlayerInfo(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "playerinfo"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(args[2]);
|
||||
if (p == null) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
SendMessage(player, "Player name: " + p.PlayerName);
|
||||
SendMessage(player, "User flair: " + p.Flair);
|
||||
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);
|
||||
}
|
||||
|
||||
private static void SendMessage(Player player, String message) { // 2015.08.09.
|
||||
if (player == null)
|
||||
PluginMain.Console.sendMessage(message); // 2015.08.12.
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
private static void DoGetLastError(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "getlasterror"
|
||||
if (PluginMain.LastException != null) {
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException = null;
|
||||
} else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
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");
|
||||
return;
|
||||
}
|
||||
Player p = Bukkit.getPlayer(args[2]);
|
||||
if (p == null) {
|
||||
SendMessage(player, "§cPLayer not found.&r");
|
||||
return;
|
||||
}
|
||||
SetPlayerFlair(player,
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()), args[3]);
|
||||
}
|
||||
|
||||
private static void DoUpdatePlugin(Player player) { // 2015.08.10.
|
||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
||||
System.out.println("Forced updating of Auto-Flair plugin.");
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(
|
||||
"https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
||||
FileUtils.copyURLToFile(url, new File(
|
||||
"plugins/TheButtonAutoFlair.jar"));
|
||||
PluginUpdated = true; // 2015.08.31.
|
||||
SendMessage(player, "Updating done!");
|
||||
} catch (MalformedURLException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoAnnounce(Player player, String[] args,
|
||||
BlockCommandSender commandblock) {
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "add":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce add <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
PluginMain.AnnounceMessages.add(finalmessage);
|
||||
SendMessage(player, "§bAnnouncement added.§r");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce remove <index>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceMessages.remove(Integer.parseInt(args[2]));
|
||||
break;
|
||||
case "settime":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player,
|
||||
"§cUsage: /u announce settime <minutes>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceTime = Integer.parseInt(args[2]) * 60 * 1000;
|
||||
SendMessage(player, "Time set between announce messages");
|
||||
break;
|
||||
case "list":
|
||||
SendMessage(player, "§bList of announce messages:§r");
|
||||
SendMessage(player, "§bFormat: [index] message§r");
|
||||
int i = 0;
|
||||
for (String message : PluginMain.AnnounceMessages)
|
||||
SendMessage(player, "[" + i++ + "] " + message);
|
||||
SendMessage(player,
|
||||
"§bCurrent wait time between announcements: "
|
||||
+ PluginMain.AnnounceTime / 60 / 1000
|
||||
+ " minute(s)§r");
|
||||
break;
|
||||
case "edit":
|
||||
if (commandblock == null) {
|
||||
SendMessage(
|
||||
player,
|
||||
"§cError: This command can only be used from a command block. Use /u announce remove.");
|
||||
break;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
commandblock
|
||||
.sendMessage("§cUsage: /u announce edit <index> <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 3; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§');
|
||||
int index = Integer.parseInt(args[2]);
|
||||
if (index > 100)
|
||||
break;
|
||||
while (PluginMain.AnnounceMessages.size() <= index)
|
||||
PluginMain.AnnounceMessages.add("");
|
||||
PluginMain.AnnounceMessages.set(Integer.parseInt(args[2]),
|
||||
finalmessage1);
|
||||
commandblock.sendMessage("Announcement edited.");
|
||||
break;
|
||||
default:
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoAnnounce(Player player, String[] args,
|
||||
BlockCommandSender commandblock) {
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "add":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce add <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
PluginMain.AnnounceMessages.add(finalmessage);
|
||||
SendMessage(player, "§bAnnouncement added.§r");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce remove <index>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceMessages.remove(Integer.parseInt(args[2]));
|
||||
break;
|
||||
case "settime":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player,
|
||||
"§cUsage: /u announce settime <minutes>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceTime = Integer.parseInt(args[2]) * 60 * 1000;
|
||||
SendMessage(player, "Time set between announce messages");
|
||||
break;
|
||||
case "list":
|
||||
SendMessage(player, "§bList of announce messages:§r");
|
||||
SendMessage(player, "§bFormat: [index] message§r");
|
||||
int i = 0;
|
||||
for (String message : PluginMain.AnnounceMessages)
|
||||
SendMessage(player, "[" + i++ + "] " + message);
|
||||
SendMessage(player,
|
||||
"§bCurrent wait time between announcements: "
|
||||
+ PluginMain.AnnounceTime / 60 / 1000
|
||||
+ " minute(s)§r");
|
||||
break;
|
||||
case "edit":
|
||||
if (commandblock == null) {
|
||||
SendMessage(
|
||||
player,
|
||||
"§cError: This command can only be used from a command block. Use /u announce remove.");
|
||||
break;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
commandblock
|
||||
.sendMessage("§cUsage: /u announce edit <index> <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 3; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§');
|
||||
int index = Integer.parseInt(args[2]);
|
||||
if (index > 100)
|
||||
break;
|
||||
while (PluginMain.AnnounceMessages.size() <= index)
|
||||
PluginMain.AnnounceMessages.add("");
|
||||
PluginMain.AnnounceMessages.set(Integer.parseInt(args[2]),
|
||||
finalmessage1);
|
||||
commandblock.sendMessage("Announcement edited.");
|
||||
break;
|
||||
default:
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoSaveLoadPos(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "savepos|loadpos"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
Player p = null;
|
||||
for (Player pl : PluginMain.GetPlayers()) {
|
||||
if (pl.getName().equals(args[2])) {
|
||||
p = pl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (p == null) {
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer is not online: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (args[1].equalsIgnoreCase("savepos")) {
|
||||
mp.SavedLocation = p.getLocation();
|
||||
} else if (args[1].equalsIgnoreCase("loadpos")) {
|
||||
if (mp.SavedLocation != null)
|
||||
p.teleport(mp.SavedLocation);
|
||||
} else {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// SendMessage(player, "Player " + p.getName() +
|
||||
// " position saved/loaded.");s
|
||||
}
|
||||
|
||||
private static void DoUpdateDynmap(Player player, String[] args) {
|
||||
// args[0] is "admin" - args[1] is "updatedynmap"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin updatedynmap <password>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,451 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
|
||||
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/
|
||||
private static PluginMain Instance;
|
||||
public static ConsoleSender Console; //2015.08.12.
|
||||
// Fired when plugin is first enabled
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
this.getCommand("u").setExecutor(new Commands());
|
||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||
Instance=this; //2015.08.08.
|
||||
LoadFiles(false); //2015.08.09.
|
||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||
Thread t=new Thread(r);
|
||||
t.start();
|
||||
}
|
||||
Boolean stop=false;
|
||||
// Fired when plugin is disabled
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
SaveFiles(); //2015.08.09.
|
||||
stop=true;
|
||||
}
|
||||
|
||||
public void ThreadMethod() //<-- 2015.07.16.
|
||||
{
|
||||
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();
|
||||
//System.out.println("Start: "+start);
|
||||
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.
|
||||
//System.out.println("End: "+end);
|
||||
if (end == -1 || end == start)
|
||||
ign = ign.substring(start);
|
||||
else
|
||||
ign = ign.substring(start, end);
|
||||
//System.out.println("IGN: "+ign);
|
||||
ign = ign.trim();
|
||||
//System.out.println("Trimmed IGN: "+ign);
|
||||
if(HasIGFlair(ign))
|
||||
continue;
|
||||
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";
|
||||
/*else
|
||||
flair = "non-presser";*/
|
||||
String flairclass;
|
||||
if(flairdata.length>2)
|
||||
flairclass = flairdata[2];
|
||||
else
|
||||
flairclass="unknown";
|
||||
SetFlair(ign, flair, flairclass, author);
|
||||
}
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Exception LastException; //2015.08.09.
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||
public Boolean HasIGFlair(String playername)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
//return p.Flair!=null; //2015.08.08.
|
||||
return p.CommentedOnReddit; //2015.08.10.
|
||||
}
|
||||
|
||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
String finalflair;
|
||||
p.FlairDecided=true;
|
||||
p.FlairRecognised=true;
|
||||
switch(flairclass)
|
||||
{
|
||||
case "press-1":
|
||||
finalflair="§c("+text+")§r";
|
||||
break;
|
||||
case "press-2":
|
||||
finalflair="§6("+text+")§r";
|
||||
break;
|
||||
case "press-3":
|
||||
finalflair="§e("+text+")§r";
|
||||
break;
|
||||
case "press-4":
|
||||
finalflair="§a("+text+")§r";
|
||||
break;
|
||||
case "press-5":
|
||||
finalflair="§9("+text+")§r";
|
||||
break;
|
||||
case "press-6":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "no-press":
|
||||
finalflair="§7(--s)§r";
|
||||
break;
|
||||
case "cheater":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "cant-press": //2015.08.08.
|
||||
finalflair="§r(??s)§r";
|
||||
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;
|
||||
default:
|
||||
//finalflair="";
|
||||
//break;
|
||||
return;
|
||||
}
|
||||
/*if(finalflair.length()==0) //<-- 2015.07.20.
|
||||
return;*/
|
||||
p.Flair=finalflair; //2015.08.08.
|
||||
p.CommentedOnReddit=true; //2015.08.10.
|
||||
p.UserName=username; //2015.08.08.
|
||||
if(finalflair.length()==0) //Just for the message
|
||||
finalflair="undecided";
|
||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||
{
|
||||
if(player.getName().equals(playername))
|
||||
{
|
||||
//AppendPlayerDisplayFlair(player, username, finalflair);
|
||||
AppendPlayerDisplayFlair(p, player);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String GetFlair(Player player)
|
||||
{ //2015.07.16.
|
||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||
//return flair==null ? "" : flair;
|
||||
return flair; //2015.08.10.
|
||||
}
|
||||
|
||||
//public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||
public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09.
|
||||
{
|
||||
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair)
|
||||
return;
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair)
|
||||
{
|
||||
//AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20.
|
||||
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");
|
||||
}
|
||||
|
||||
/*private static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
*String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||
String[] colors = color.substring(1).split("§");
|
||||
String displayname=player.getName(); //2015.08.08.
|
||||
ArrayList<Integer> Positions=new ArrayList<>();
|
||||
for(int i=0; i<displayname.length(); i++) {
|
||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||
Positions.add(i);
|
||||
}
|
||||
}
|
||||
String finalname=""; //TODO
|
||||
if(Positions.size()>=colors.length)
|
||||
{
|
||||
int x=0;
|
||||
for(int i=0; i<Positions.size(); i++)
|
||||
{
|
||||
int pos=Positions.get(i);
|
||||
int nextpos;
|
||||
if(i!=Positions.size()-1)
|
||||
nextpos=Positions.get(i+1);
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Positions.clear();
|
||||
int unit=displayname.length()/colors.length;
|
||||
int x=0;
|
||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||
{
|
||||
int pos=i;
|
||||
int nextpos;
|
||||
if(i<displayname.length()-unit-unit)
|
||||
nextpos=i+unit;
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}*
|
||||
}*/
|
||||
|
||||
public static String GetColorForTown(String townname)
|
||||
{ //2015.07.20.
|
||||
if(TownColors.containsKey(townname))
|
||||
return TownColors.get(townname);
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String GetPlayerTown(Player player)
|
||||
{ //2015.07.20.
|
||||
try {
|
||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||
return town.getName();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/*public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||
}*/
|
||||
|
||||
public static Collection<? extends Player> GetPlayers()
|
||||
{
|
||||
return Instance.getServer().getOnlinePlayers();
|
||||
}
|
||||
|
||||
public static void LoadFiles(boolean reload) //<-- 2015.08.09.
|
||||
{
|
||||
if(reload)
|
||||
{ //2015.08.09.
|
||||
System.out.println("Auto-flair plugin cleanup for reloading...");
|
||||
MaybeOfflinePlayer.AllPlayers.clear();
|
||||
TownColors.clear();
|
||||
}
|
||||
System.out.println("Loading files for auto-flair plugin..."); //2015.08.09.
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
//System.out.println("Name: " + name);
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("flairsignored.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while((line=br.readLine())!=null)
|
||||
{
|
||||
String[] s=line.split(" ");
|
||||
if(s.length>=2) //<-- 2015.08.10.
|
||||
TownColors.put(s[0], s[1]);
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("customflairs.txt"); //2015.08.09.
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while((line=br.readLine())!=null)
|
||||
{
|
||||
String[] s=line.split(" ");
|
||||
if(s.length>=2) //2015.08.10.
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]);
|
||||
p.Flair=s[1]; //2015.08.09.
|
||||
p.CommentedOnReddit=true; //Kind of
|
||||
}
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
//throw new IOException("Test"); //2015.08.09.
|
||||
System.out.println("Auto-flair plugin loaded files!");
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
public static void SaveFiles() //<-- 2015.08.09.
|
||||
{
|
||||
try
|
||||
{
|
||||
FileWriter fw;
|
||||
fw = new FileWriter("flairsaccepted.txt");
|
||||
fw.close();
|
||||
fw = new FileWriter("flairsignored.txt");
|
||||
fw.close();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.AcceptedFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
file=new File("flairsignored.txt");
|
||||
bw = new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.IgnoredFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
public static boolean RemoveLineFromFile(String file, String line)
|
||||
{ //2015.08.09.
|
||||
File inputFile = new File(file);
|
||||
File tempFile = new File("_temp.txt");
|
||||
|
||||
if(!inputFile.exists())
|
||||
return true; //2015.08.10.
|
||||
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(inputFile));
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
|
||||
|
||||
String lineToRemove = line;
|
||||
String currentLine;
|
||||
|
||||
while((currentLine = reader.readLine()) != null) {
|
||||
// trim newline when comparing with lineToRemove
|
||||
String trimmedLine = currentLine.trim();
|
||||
//if(trimmedLine.equals(lineToRemove)) continue;
|
||||
if(trimmedLine.contains(lineToRemove)) continue; //2015.08.09.
|
||||
writer.write(currentLine + System.getProperty("line.separator"));
|
||||
}
|
||||
writer.close();
|
||||
reader.close();
|
||||
if(!tempFile.renameTo(inputFile))
|
||||
{
|
||||
inputFile.delete();
|
||||
return tempFile.renameTo(inputFile);
|
||||
}
|
||||
else
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,574 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
|
||||
public static boolean PluginUpdated = false; // 2015.08.31.
|
||||
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label,
|
||||
String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
switch (cmd.getName()) {
|
||||
case "u": {
|
||||
if (args.length < 1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(player
|
||||
.getName()); // 2015.08.08.
|
||||
if (!p.CommentedOnReddit
|
||||
&& !args[0].toLowerCase().equals("admin")
|
||||
&& !args[0].toLowerCase().equals("ignore")) {
|
||||
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")) { // 2015.08.10.
|
||||
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")) { // 2015.08.19.
|
||||
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
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
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");
|
||||
} else
|
||||
player.sendMessage("§cYou already ignored this request.§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
|
||||
break;
|
||||
case "announce":
|
||||
DoAnnounce(player, args, null);
|
||||
break;
|
||||
case "name":
|
||||
if (args.length == 1) {
|
||||
player.sendMessage("§cUsage: /u name <playername>§r");
|
||||
break;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[1])) {
|
||||
player.sendMessage("§cUnknown user: " + args[1]);
|
||||
break;
|
||||
}
|
||||
player.sendMessage("§bUsername of "
|
||||
+ args[1]
|
||||
+ ": "
|
||||
+ MaybeOfflinePlayer.AllPlayers.get(args[1]).UserName);
|
||||
break;
|
||||
case "enable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = true;
|
||||
player.sendMessage("Enabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
case "disable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = false;
|
||||
player.sendMessage("Disabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "nrp":
|
||||
case "ooc":
|
||||
if (args.length == 0) {
|
||||
return false;
|
||||
} else {
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = false;
|
||||
String message = "";
|
||||
for (String arg : args)
|
||||
message += arg + " ";
|
||||
player.chat(message.substring(0, message.length() - 1));
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = true;
|
||||
}
|
||||
return true;
|
||||
case "skype":
|
||||
// "skype:?chat&blob=Y_5Ob1BEcw0ZlstdUHyf0ENS5n1Xz2Huhx-5b-pB2JyMSRO5QMEALkJuTSuUaAb3-XfWXwCndwhGex_UpXDbyQ";
|
||||
return true;
|
||||
default:
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
}
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("admin")) // 2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); // 2015.08.09.
|
||||
return true; // 2015.08.09.
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("announce")) {
|
||||
if (sender instanceof BlockCommandSender)
|
||||
DoAnnounce(null, args, (BlockCommandSender) sender);
|
||||
else
|
||||
DoAnnounce(null, args, null);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void DoReload(Player player) { // 2015.07.20.
|
||||
try {
|
||||
PluginMain.Console
|
||||
.sendMessage("§6-- Reloading The Button Minecraft plugin...§r");
|
||||
PluginMain.LoadFiles(true); // 2015.08.09.
|
||||
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.
|
||||
}
|
||||
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.
|
||||
}
|
||||
PluginMain.Console.sendMessage("§6-- Reloading done!§r");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
if (player != null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static Player ReloadPlayer; // 2015.08.09.
|
||||
|
||||
private static String DoAdminUsage = "§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin|togglerpshow|toggledebug|savepos|loadpos§r";
|
||||
|
||||
private static void DoAdmin(Player player, String[] args) { // 2015.08.09.
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// args[0] is "admin"
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "reload":
|
||||
ReloadPlayer = player; // 2015.08.09.
|
||||
SendMessage(
|
||||
player,
|
||||
"§bMake sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
break; // <-- 2015.08.10.
|
||||
case "confirm":
|
||||
if (ReloadPlayer == player)
|
||||
DoReload(player); // 2015.08.09.
|
||||
else
|
||||
SendMessage(player,
|
||||
"§cYou need to do /u admin reload first.§r");
|
||||
break;
|
||||
case "save":
|
||||
PluginMain.SaveFiles(); // 2015.08.09.
|
||||
SendMessage(player,
|
||||
"§bSaved files. Now you can edit them and reload if you want.§r");
|
||||
break;
|
||||
case "setflair":
|
||||
DoSetFlair(player, args);
|
||||
break;
|
||||
case "updateplugin": // 2015.08.10.
|
||||
DoUpdatePlugin(player);
|
||||
break;
|
||||
case "togglerpshow":
|
||||
PlayerListener.ShowRPTag = !PlayerListener.ShowRPTag;
|
||||
SendMessage(player, "RP tag showing "
|
||||
+ (PlayerListener.ShowRPTag ? "enabled" : "disabled"));
|
||||
break;
|
||||
case "toggledebug":
|
||||
PlayerListener.DebugMode = !PlayerListener.DebugMode;
|
||||
SendMessage(player, "DebugMode: " + PlayerListener.DebugMode);
|
||||
break;
|
||||
case "savepos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "loadpos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "updatedynmap":
|
||||
DoUpdateDynmap(player, args);
|
||||
default:
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
|
||||
private static void DoPlayerInfo(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "playerinfo"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(args[2]);
|
||||
if (p == null) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
SendMessage(player, "Player name: " + p.PlayerName);
|
||||
SendMessage(player, "User flair: " + p.Flair);
|
||||
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);
|
||||
}
|
||||
|
||||
private static void SendMessage(Player player, String message) { // 2015.08.09.
|
||||
if (player == null)
|
||||
PluginMain.Console.sendMessage(message); // 2015.08.12.
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
private static void DoGetLastError(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "getlasterror"
|
||||
if (PluginMain.LastException != null) {
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException = null;
|
||||
} else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
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");
|
||||
return;
|
||||
}
|
||||
Player p = Bukkit.getPlayer(args[2]);
|
||||
if (p == null) {
|
||||
SendMessage(player, "§cPLayer not found.&r");
|
||||
return;
|
||||
}
|
||||
SetPlayerFlair(player,
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()), args[3]);
|
||||
}
|
||||
|
||||
private static void DoUpdatePlugin(Player player) { // 2015.08.10.
|
||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
||||
System.out.println("Forced updating of Auto-Flair plugin.");
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(
|
||||
"https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
||||
FileUtils.copyURLToFile(url, new File(
|
||||
"plugins/TheButtonAutoFlair.jar"));
|
||||
PluginUpdated = true; // 2015.08.31.
|
||||
SendMessage(player, "Updating done!");
|
||||
} catch (MalformedURLException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoAnnounce(Player player, String[] args,
|
||||
BlockCommandSender commandblock) {
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "add":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce add <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
PluginMain.AnnounceMessages.add(finalmessage);
|
||||
SendMessage(player, "§bAnnouncement added.§r");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce remove <index>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceMessages.remove(Integer.parseInt(args[2]));
|
||||
break;
|
||||
case "settime":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player,
|
||||
"§cUsage: /u announce settime <minutes>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceTime = Integer.parseInt(args[2]) * 60 * 1000;
|
||||
SendMessage(player, "Time set between announce messages");
|
||||
break;
|
||||
case "list":
|
||||
SendMessage(player, "§bList of announce messages:§r");
|
||||
SendMessage(player, "§bFormat: [index] message§r");
|
||||
int i = 0;
|
||||
for (String message : PluginMain.AnnounceMessages)
|
||||
SendMessage(player, "[" + i++ + "] " + message);
|
||||
SendMessage(player,
|
||||
"§bCurrent wait time between announcements: "
|
||||
+ PluginMain.AnnounceTime / 60 / 1000
|
||||
+ " minute(s)§r");
|
||||
break;
|
||||
case "edit":
|
||||
if (commandblock == null) {
|
||||
SendMessage(
|
||||
player,
|
||||
"§cError: This command can only be used from a command block. Use /u announce remove.");
|
||||
break;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
commandblock
|
||||
.sendMessage("§cUsage: /u announce edit <index> <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 3; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§');
|
||||
int index = Integer.parseInt(args[2]);
|
||||
if (index > 100)
|
||||
break;
|
||||
while (PluginMain.AnnounceMessages.size() <= index)
|
||||
PluginMain.AnnounceMessages.add("");
|
||||
PluginMain.AnnounceMessages.set(Integer.parseInt(args[2]),
|
||||
finalmessage1);
|
||||
commandblock.sendMessage("Announcement edited.");
|
||||
break;
|
||||
default:
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoSaveLoadPos(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "savepos|loadpos"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
Player p = null;
|
||||
for (Player pl : PluginMain.GetPlayers()) {
|
||||
if (pl.getName().equals(args[2])) {
|
||||
p = pl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (p == null) {
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer is not online: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (args[1].equalsIgnoreCase("savepos")) {
|
||||
mp.SavedLocation = p.getLocation();
|
||||
} else if (args[1].equalsIgnoreCase("loadpos")) {
|
||||
if (mp.SavedLocation != null)
|
||||
p.teleport(mp.SavedLocation);
|
||||
} else {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// SendMessage(player, "Player " + p.getName() +
|
||||
// " position saved/loaded.");s
|
||||
}
|
||||
|
||||
private static void DoUpdateDynmap(Player player, String[] args) {
|
||||
// args[0] is "admin" - args[1] is "updatedynmap"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin updatedynmap <password>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static ArrayList<String> Quiz = new ArrayList<>();
|
||||
|
||||
private static void DoQuiz(Player player, String[] args,
|
||||
BlockCommandSender commandblock) {
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = "§cUsage: /u quiz add|remove|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "add":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u quiz add <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
Quiz.add(finalmessage);
|
||||
SendMessage(player, "§Quiz question added.§r");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u quiz remove <index>");
|
||||
return;
|
||||
}
|
||||
Quiz.remove(Integer.parseInt(args[2]));
|
||||
break;
|
||||
case "list":
|
||||
SendMessage(player, "§bList of quiz questions:§r");
|
||||
SendMessage(player, "§bFormat: [index] question§r");
|
||||
int i = 0;
|
||||
for (String question : Quiz)
|
||||
SendMessage(player, "[" + i++ + "] " + question);
|
||||
break;
|
||||
case "edit":
|
||||
if (commandblock == null) {
|
||||
SendMessage(
|
||||
player,
|
||||
"§cError: This command can only be used from a command block. Use /u quiz remove.");
|
||||
break;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
commandblock
|
||||
.sendMessage("§cUsage: /u quiz edit <index> <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 3; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§');
|
||||
int index = Integer.parseInt(args[2]);
|
||||
if (index > 100)
|
||||
break;
|
||||
while (Quiz.size() <= index)
|
||||
Quiz.add("");
|
||||
Quiz.set(Integer.parseInt(args[2]), finalmessage1);
|
||||
commandblock.sendMessage("Question edited.");
|
||||
break;
|
||||
default:
|
||||
String message = "§cUsage: /u quiz add|remove|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,197 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if(args.length<1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||
if(p.Flair==null)
|
||||
{
|
||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||
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.
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
PluginMain.AppendPlayerDisplayFlair(player, p);
|
||||
p.AcceptedFlair=true; //2015.08.08.
|
||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
break;
|
||||
}
|
||||
case "ignore":
|
||||
{
|
||||
if(p.AcceptedFlair)
|
||||
p.AcceptedFlair=false; //2015.08.08.
|
||||
if(!p.IgnoredFlair)
|
||||
{
|
||||
p.IgnoredFlair=true;
|
||||
String flair=p.Flair; //2015.08.08.
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already ignored this request.§r");
|
||||
break;
|
||||
}
|
||||
/*case "reload": //2015.07.20.
|
||||
DoReload(player);
|
||||
break;*/
|
||||
case "admin": //2015.08.09.
|
||||
DoAdmin(player, args);
|
||||
break;
|
||||
case "nonpresser": //2015.08.09.
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*if(args[0].toLowerCase()=="reload")
|
||||
DoReload(null); //2015.07.20.*/
|
||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); //2015.08.09.
|
||||
return true; //2015.08.09.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static void DoReload(Player player)
|
||||
{ //2015.07.20.
|
||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
//{
|
||||
try
|
||||
{
|
||||
File file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
PluginMain.TownColors.clear();
|
||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while((line=br.readLine())!=null)
|
||||
{
|
||||
String[] s=line.split(" ");
|
||||
PluginMain.TownColors.put(s[0], s[1]);
|
||||
}
|
||||
br.close();
|
||||
for(Player p : PluginMain.GetPlayers())
|
||||
{
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||
if(mp.Flair!=null)
|
||||
{
|
||||
String flair=mp.Flair;
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||
}
|
||||
}
|
||||
String msg="§6Reloaded config file.§r";
|
||||
SendMessage(player, msg); //2015.08.09.
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
if(player!=null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
//}
|
||||
//else
|
||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoAdmin(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
{
|
||||
//System.out.println("Args length: " + args.length);
|
||||
if(args.length==1)
|
||||
{
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
//args[0] is "admin"
|
||||
switch(args[1].toLowerCase())
|
||||
{
|
||||
case "reload":
|
||||
DoReload(player);
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
default:
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoPlayerInfo(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "playerinfo"
|
||||
if(args.length==2)
|
||||
{
|
||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||
{
|
||||
String message="§cPlayer not found: "+args[2]+"§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
SendMessage(player, "Player name: "+p.PlayerName);
|
||||
SendMessage(player, "User flair: "+p.Flair);
|
||||
SendMessage(player, "Username: "+p.UserName);
|
||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
||||
}
|
||||
private static void SendMessage(Player player, String message)
|
||||
{ //2015.08.09.
|
||||
if(player==null)
|
||||
System.out.println(message);
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
private static void DoGetLastError(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "getlasterror"
|
||||
if(PluginMain.LastException!=null)
|
||||
{
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException=null;
|
||||
}
|
||||
else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
}
|
|
@ -1,336 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerChatTabCompleteEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import au.com.mineauz.minigames.Minigames;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import java.util.Timer;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerListener implements Listener { // 2015.07.16.
|
||||
public static HashMap<String, UUID> nicknames = new HashMap<>();
|
||||
|
||||
public static boolean Enable = false; // 2015.08.29.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p
|
||||
.getUniqueId());
|
||||
mp.PlayerName = p.getName(); // 2015.10.17. 0:58
|
||||
if (mp.CommentedOnReddit)
|
||||
// if (false)
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); // 2015.08.09.
|
||||
else { // 2015.07.20.
|
||||
Timer timer = new Timer();
|
||||
PlayerJoinTimerTask tt = new PlayerJoinTimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!mp.IgnoredFlair) {
|
||||
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,
|
||||
"tellraw " + mp.PlayerName + " " + json);
|
||||
json = "[\"\",{\"text\":\"If you don't want the flair, type /u ignore to prevent this message after next login.\",\"color\":\"aqua\"}]";
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Console,
|
||||
"tellraw " + mp.PlayerName + " " + json);
|
||||
}
|
||||
}
|
||||
};
|
||||
tt.mp = mp;
|
||||
timer.schedule(tt, 15 * 1000);
|
||||
}
|
||||
|
||||
/* NICKNAME LOGIC */
|
||||
|
||||
UUID id = p.getUniqueId();
|
||||
|
||||
File f = new File("plugins/Essentials/userdata/" + id + ".yml");
|
||||
if (f.exists()) {
|
||||
YamlConfiguration yc = new YamlConfiguration();
|
||||
try {
|
||||
yc.load(f);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String nickname = yc.getString("nickname");
|
||||
if (nickname != null) {
|
||||
nicknames.put(nickname, id);
|
||||
|
||||
if (Enable) {
|
||||
if (!p.getName().equals("NorbiPeti")) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.chat("Hey, " + nickname + "!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mp.RPMode = true; // 2015.08.25.
|
||||
|
||||
if (p.getName().equals("FigyTuna") && Commands.PluginUpdated)
|
||||
p.sendMessage("§bThe The Button MC plugin got updated. Please restart the server. :P§r");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
String deletenick = null;
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
UUID uuid = nicknames.get(nickname);
|
||||
if (event.getPlayer().getUniqueId().equals(uuid)) {
|
||||
deletenick = nickname;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (deletenick != null)
|
||||
nicknames.remove(deletenick);
|
||||
}
|
||||
|
||||
public static String NotificationSound; // 2015.08.14.
|
||||
public static double NotificationPitch; // 2015.08.14.
|
||||
|
||||
public static boolean ShowRPTag = false; // 2015.08.31.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.GetFromName(event
|
||||
.getPlayer().getName());
|
||||
String flair = player.Flair; // 2015.08.08.
|
||||
if (player.IgnoredFlair)
|
||||
flair = "";
|
||||
String message = event.getMessage(); // 2015.08.08.
|
||||
for (Player p : PluginMain.GetPlayers()) { // 2015.08.12.
|
||||
String color = ""; // 2015.08.17.
|
||||
if (message.contains(p.getName())) {
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(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);
|
||||
}
|
||||
|
||||
message = message.replaceAll(p.getName(), color + p.getName()
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
for (String n : nicknames.keySet()) {
|
||||
Player p = null;
|
||||
String nwithoutformatting = new String(n);
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (message.contains(nwithoutformatting)) {
|
||||
p = Bukkit.getPlayer(nicknames.get(n));
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(float) NotificationPitch); // 2015.08.14.
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()); // 2015.08.17.
|
||||
}
|
||||
if (p != null) {
|
||||
message = message.replaceAll(nwithoutformatting, n
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
}
|
||||
|
||||
event.setMessage(message); // 2015.09.05.
|
||||
|
||||
event.setFormat(event
|
||||
.getFormat()
|
||||
.replace(
|
||||
"{rptag}",
|
||||
(player.RPMode ? (ShowRPTag ? "§2[RP]§r" : "")
|
||||
: "§8[OOC]§r"))
|
||||
.replace("{buttonflair}", flair)
|
||||
.replace(
|
||||
"{isitwilds}",
|
||||
(event.getPlayer().getWorld().getName()
|
||||
.equalsIgnoreCase("wilds") ? "[PVP]" : ""))); // 2015.09.04.
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTabComplete(PlayerChatTabCompleteEvent e) {
|
||||
String name = e.getLastToken();
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
String nwithoutformatting = nickname;
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (nwithoutformatting.startsWith(name)
|
||||
&& !nwithoutformatting.equals(Bukkit.getPlayer(
|
||||
nicknames.get(nickname)).getName()))
|
||||
e.getTabCompletions().add(nwithoutformatting);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean DebugMode = false;
|
||||
|
||||
public void SendForDebug(String message) {
|
||||
if (DebugMode) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.sendMessage("[DEBUG] " + message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean ActiveF = false;
|
||||
private int FCount = 0;
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMessage(AsyncPlayerChatEvent e) {
|
||||
if (ActiveF) {
|
||||
if (System.currentTimeMillis() - FTime > 10000) {
|
||||
ActiveF = false;
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
p.sendMessage("§b" + FCount + " "
|
||||
+ (FCount == 1 ? "person" : "people")
|
||||
+ " paid their respects.§r");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e.getMessage().equalsIgnoreCase("F")) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(e
|
||||
.getPlayer().getName());
|
||||
if (!mp.PressedF && ActiveF) {
|
||||
FCount++;
|
||||
mp.PressedF = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (e.getMessage().startsWith(">"))
|
||||
e.setMessage("§2" + e.getMessage());
|
||||
|
||||
/*
|
||||
* Channel c = ((Chat) Bukkit.getPluginManager().getPlugin("TownyChat"))
|
||||
* .getChannelsHandler().getActiveChannel(e.getPlayer(),
|
||||
* channelTypes.GLOBAL);
|
||||
*/
|
||||
/*
|
||||
* List<String> modes = ((Chat) Bukkit.getPluginManager().getPlugin(
|
||||
* "TownyChat")).getTowny().getPlayerMode(e.getPlayer()); if
|
||||
* (modes.size() == 0 || modes.contains("g")) {
|
||||
*/
|
||||
if (e.getFormat().contains("[g]")) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("tellraw @a [\"\"");
|
||||
sb.append(",{\"text\":\"Hashtags:\"}");
|
||||
int index = -1;
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
while ((index = e.getMessage().indexOf("#", index + 1)) != -1) {
|
||||
int index2 = e.getMessage().indexOf(" ", index + 1);
|
||||
if (index2 == -1)
|
||||
index2 = e.getMessage().length();
|
||||
int index3 = e.getMessage().indexOf("#", index + 1);
|
||||
if (index3 != -1 && index3 < index2) // A # occurs before a
|
||||
// space
|
||||
index2 = index3;
|
||||
String original = e.getMessage().substring(index, index2);
|
||||
list.add(original);
|
||||
sb.append(",{\"text\":\" \"}");
|
||||
sb.append(",{\"text\":\"");
|
||||
sb.append(original);
|
||||
sb.append("\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://twitter.com/hashtag/");
|
||||
sb.append(original.substring(1));
|
||||
sb.append("\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open on Twitter\",\"color\":\"blue\"}]}}}");
|
||||
}
|
||||
for (String original : list)
|
||||
e.setMessage(e.getMessage().replace(
|
||||
original,
|
||||
"§9"
|
||||
+ original
|
||||
+ (e.getMessage().startsWith("§2>") ? "§2"
|
||||
: "§r")));
|
||||
/*
|
||||
* for (String original : list)
|
||||
* System.out.println(e.getMessage().replace( original, "§9" +
|
||||
* original + (e.getMessage().startsWith("§2>") ? "§2" : "§r")));
|
||||
*/
|
||||
|
||||
sb.append("]");
|
||||
|
||||
if (list.size() > 0)
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Instance.getServer().getConsoleSender(),
|
||||
sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDeath(PlayerDeathEvent e) {
|
||||
if (!Minigames.plugin.pdata.getMinigamePlayer(e.getEntity())
|
||||
.isInMinigame() && new Random().nextBoolean()) {
|
||||
ActiveF = true;
|
||||
FCount = 0;
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(p
|
||||
.getName());
|
||||
mp.PressedF = false;
|
||||
p.sendMessage("§bPress F to pay respects.§r");
|
||||
}
|
||||
Timer timer = new Timer();
|
||||
TimerTask tt = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!mp.IgnoredFlair) {
|
||||
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,
|
||||
"tellraw " + mp.PlayerName + " " + json);
|
||||
json = "[\"\",{\"text\":\"If you don't want the flair, type /u ignore to prevent this message after next login.\",\"color\":\"aqua\"}]";
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Console,
|
||||
"tellraw " + mp.PlayerName + " " + json);
|
||||
}
|
||||
}
|
||||
};
|
||||
tt.mp = mp;
|
||||
timer.schedule(tt, 15 * 1000);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,201 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if(args.length<1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||
if(p.Flair==null)
|
||||
{
|
||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||
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.
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
||||
p.AcceptedFlair=true; //2015.08.08.
|
||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
break;
|
||||
}
|
||||
case "ignore":
|
||||
{
|
||||
if(p.AcceptedFlair)
|
||||
p.AcceptedFlair=false; //2015.08.08.
|
||||
if(!p.IgnoredFlair)
|
||||
{
|
||||
p.IgnoredFlair=true;
|
||||
String flair=p.Flair; //2015.08.08.
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already ignored this request.§r");
|
||||
break;
|
||||
}
|
||||
/*case "reload": //2015.07.20.
|
||||
DoReload(player);
|
||||
break;*/
|
||||
case "admin": //2015.08.09.
|
||||
DoAdmin(player, args);
|
||||
break;
|
||||
case "nonpresser": //2015.08.09.
|
||||
|
||||
break;
|
||||
case "cantpress": //2015.08.09.
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*if(args[0].toLowerCase()=="reload")
|
||||
DoReload(null); //2015.07.20.*/
|
||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); //2015.08.09.
|
||||
return true; //2015.08.09.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static void DoReload(Player player)
|
||||
{ //2015.07.20.
|
||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
//{
|
||||
try
|
||||
{
|
||||
File file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
PluginMain.TownColors.clear();
|
||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while((line=br.readLine())!=null)
|
||||
{
|
||||
String[] s=line.split(" ");
|
||||
PluginMain.TownColors.put(s[0], s[1]);
|
||||
}
|
||||
br.close();
|
||||
for(Player p : PluginMain.GetPlayers())
|
||||
{
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||
if(mp.Flair!=null)
|
||||
{
|
||||
String flair=mp.Flair;
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
||||
}
|
||||
}
|
||||
String msg="§6Reloaded config file.§r";
|
||||
SendMessage(player, msg); //2015.08.09.
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
if(player!=null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
//}
|
||||
//else
|
||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoAdmin(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
{
|
||||
//System.out.println("Args length: " + args.length);
|
||||
if(args.length==1)
|
||||
{
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
//args[0] is "admin"
|
||||
switch(args[1].toLowerCase())
|
||||
{
|
||||
case "reload":
|
||||
DoReload(player);
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
default:
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoPlayerInfo(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "playerinfo"
|
||||
if(args.length==2)
|
||||
{
|
||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||
{
|
||||
String message="§cPlayer not found: "+args[2]+"§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
SendMessage(player, "Player name: "+p.PlayerName);
|
||||
SendMessage(player, "User flair: "+p.Flair);
|
||||
SendMessage(player, "Username: "+p.UserName);
|
||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
||||
}
|
||||
private static void SendMessage(Player player, String message)
|
||||
{ //2015.08.09.
|
||||
if(player==null)
|
||||
System.out.println(message);
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
private static void DoGetLastError(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "getlasterror"
|
||||
if(PluginMain.LastException!=null)
|
||||
{
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException=null;
|
||||
}
|
||||
else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class MaybeOfflinePlayer
|
||||
{ //2015.08.08.
|
||||
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
|
||||
public static HashMap<String, MaybeOfflinePlayer> AllPlayers=new HashMap<>(); //2015.08.08.
|
||||
public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername)
|
||||
{
|
||||
if(!AllPlayers.containsKey(playername))
|
||||
{
|
||||
MaybeOfflinePlayer player=new MaybeOfflinePlayer();
|
||||
player.PlayerName=playername;
|
||||
AllPlayers.put(playername, player);
|
||||
return player;
|
||||
}
|
||||
return AllPlayers.get(playername);
|
||||
}
|
||||
}
|
|
@ -1,318 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerChatTabCompleteEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import au.com.mineauz.minigames.Minigames;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerListener implements Listener { // 2015.07.16.
|
||||
public static HashMap<String, UUID> nicknames = new HashMap<>();
|
||||
|
||||
public static boolean Enable = false; // 2015.08.29.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
final MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p
|
||||
.getUniqueId());
|
||||
mp.PlayerName = p.getName(); // 2015.10.17. 0:58
|
||||
if (mp.CommentedOnReddit)
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); // 2015.08.09.
|
||||
else { // 2015.07.20.
|
||||
Timer timer = new Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!mp.IgnoredFlair) {
|
||||
String json = "[\"\",{\"text\":\"§6If you'd like your flair displayed ingame, write your §6Minecraft name to \"},{\"text\":\"[this thread.]\",\"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§r\"}]}}}]";
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Console,
|
||||
"tellraw " + mp.PlayerName + " " + json);
|
||||
json = "[\"\",{\"text\":\"§6If you don't want the flair, type /u ignore to prevent this message on login.§r\"}]";
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Console,
|
||||
"tellraw " + mp.PlayerName + " " + json);
|
||||
}
|
||||
}
|
||||
}, 15 * 1000);
|
||||
}
|
||||
|
||||
/* NICKNAME LOGIC */
|
||||
|
||||
UUID id = p.getUniqueId();
|
||||
|
||||
File f = new File("plugins/Essentials/userdata/" + id + ".yml");
|
||||
if (f.exists()) {
|
||||
YamlConfiguration yc = new YamlConfiguration();
|
||||
try {
|
||||
yc.load(f);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String nickname = yc.getString("nickname");
|
||||
if (nickname != null) {
|
||||
nicknames.put(nickname, id);
|
||||
|
||||
if (Enable) {
|
||||
if (!p.getName().equals("NorbiPeti")) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.chat("Hey, " + nickname + "!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mp.RPMode = true; // 2015.08.25.
|
||||
|
||||
if (p.getName().equals("FigyTuna") && Commands.PluginUpdated)
|
||||
p.sendMessage("§bThe The Button MC plugin got updated. Please restart the server. :P§r");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
String deletenick = null;
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
UUID uuid = nicknames.get(nickname);
|
||||
if (event.getPlayer().getUniqueId().equals(uuid)) {
|
||||
deletenick = nickname;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (deletenick != null)
|
||||
nicknames.remove(deletenick);
|
||||
}
|
||||
|
||||
public static String NotificationSound; // 2015.08.14.
|
||||
public static double NotificationPitch; // 2015.08.14.
|
||||
|
||||
public static boolean ShowRPTag = false; // 2015.08.31.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.GetFromName(event
|
||||
.getPlayer().getName());
|
||||
String flair = player.Flair; // 2015.08.08.
|
||||
if (player.IgnoredFlair)
|
||||
flair = "";
|
||||
String message = event.getMessage(); // 2015.08.08.
|
||||
for (Player p : PluginMain.GetPlayers()) { // 2015.08.12.
|
||||
String color = ""; // 2015.08.17.
|
||||
if (message.contains(p.getName())) {
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(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);
|
||||
}
|
||||
|
||||
message = message.replaceAll(p.getName(), color + p.getName()
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
for (String n : nicknames.keySet()) {
|
||||
Player p = null;
|
||||
String nwithoutformatting = new String(n);
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (message.contains(nwithoutformatting)) {
|
||||
p = Bukkit.getPlayer(nicknames.get(n));
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(float) NotificationPitch); // 2015.08.14.
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()); // 2015.08.17.
|
||||
}
|
||||
if (p != null) {
|
||||
message = message.replaceAll(nwithoutformatting, n
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
}
|
||||
|
||||
event.setMessage(message); // 2015.09.05.
|
||||
|
||||
event.setFormat(event
|
||||
.getFormat()
|
||||
.replace(
|
||||
"{rptag}",
|
||||
(player.RPMode ? (ShowRPTag ? "§2[RP]§r" : "")
|
||||
: "§8[OOC]§r"))
|
||||
.replace("{buttonflair}", flair)
|
||||
.replace(
|
||||
"{isitwilds}",
|
||||
(event.getPlayer().getWorld().getName()
|
||||
.equalsIgnoreCase("wilds") ? "[PVP]" : ""))); // 2015.09.04.
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTabComplete(PlayerChatTabCompleteEvent e) {
|
||||
String name = e.getLastToken();
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
String nwithoutformatting = nickname;
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (nwithoutformatting.startsWith(name)
|
||||
&& !nwithoutformatting.equals(Bukkit.getPlayer(
|
||||
nicknames.get(nickname)).getName()))
|
||||
e.getTabCompletions().add(nwithoutformatting);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean DebugMode = false;
|
||||
|
||||
public void SendForDebug(String message) {
|
||||
if (DebugMode) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.sendMessage("[DEBUG] " + message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean ActiveF = false;
|
||||
private int FCount = 0;
|
||||
private long FTime;
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMessage(AsyncPlayerChatEvent e) {
|
||||
if (ActiveF) {
|
||||
if (System.currentTimeMillis() - FTime > 10000) {
|
||||
ActiveF = false;
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
p.sendMessage("§b" + FCount + " "
|
||||
+ (FCount == 1 ? "person" : "people")
|
||||
+ " paid their respects.§r");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e.getMessage().equalsIgnoreCase("F")) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(e
|
||||
.getPlayer().getName());
|
||||
if (!mp.PressedF && ActiveF) {
|
||||
FCount++;
|
||||
mp.PressedF = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (e.getMessage().startsWith(">"))
|
||||
e.setMessage("§2" + e.getMessage());
|
||||
|
||||
/*
|
||||
* Channel c = ((Chat) Bukkit.getPluginManager().getPlugin("TownyChat"))
|
||||
* .getChannelsHandler().getActiveChannel(e.getPlayer(),
|
||||
* channelTypes.GLOBAL);
|
||||
*/
|
||||
/*
|
||||
* List<String> modes = ((Chat) Bukkit.getPluginManager().getPlugin(
|
||||
* "TownyChat")).getTowny().getPlayerMode(e.getPlayer()); if
|
||||
* (modes.size() == 0 || modes.contains("g")) {
|
||||
*/
|
||||
if (e.getFormat().contains("[g]")) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("tellraw @a [\"\"");
|
||||
sb.append(",{\"text\":\"Hashtags:\"}");
|
||||
int index = -1;
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
while ((index = e.getMessage().indexOf("#", index + 1)) != -1) {
|
||||
int index2 = e.getMessage().indexOf(" ", index + 1);
|
||||
if (index2 == -1)
|
||||
index2 = e.getMessage().length();
|
||||
int index3 = e.getMessage().indexOf("#", index + 1);
|
||||
if (index3 != -1 && index3 < index2) // A # occurs before a
|
||||
// space
|
||||
index2 = index3;
|
||||
String original = e.getMessage().substring(index, index2);
|
||||
list.add(original);
|
||||
sb.append(",{\"text\":\" \"}");
|
||||
sb.append(",{\"text\":\"");
|
||||
sb.append(original);
|
||||
sb.append("\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://twitter.com/hashtag/");
|
||||
sb.append(original.substring(1));
|
||||
sb.append("\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open on Twitter\",\"color\":\"blue\"}]}}}");
|
||||
}
|
||||
for (String original : list)
|
||||
e.setMessage(e.getMessage().replace(
|
||||
original,
|
||||
"§9"
|
||||
+ original
|
||||
+ (e.getMessage().startsWith("§2>") ? "§2"
|
||||
: "§r")));
|
||||
/*
|
||||
* for (String original : list)
|
||||
* System.out.println(e.getMessage().replace( original, "§9" +
|
||||
* original + (e.getMessage().startsWith("§2>") ? "§2" : "§r")));
|
||||
*/
|
||||
|
||||
sb.append("]");
|
||||
|
||||
if (list.size() > 0)
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Instance.getServer().getConsoleSender(),
|
||||
sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDeath(PlayerDeathEvent e) {
|
||||
if (!Minigames.plugin.pdata.getMinigamePlayer(e.getEntity())
|
||||
.isInMinigame() && new Random().nextBoolean()) {
|
||||
ActiveF = true;
|
||||
FCount = 0;
|
||||
FTime = System.currentTimeMillis();
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(p
|
||||
.getName());
|
||||
mp.PressedF = false;
|
||||
p.sendMessage("§bPress F to pay respects.§r");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,215 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if(args.length<1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||
if(p.Flair==null)
|
||||
{
|
||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||
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.
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
||||
p.AcceptedFlair=true; //2015.08.08.
|
||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
break;
|
||||
}
|
||||
case "ignore":
|
||||
{
|
||||
if(p.AcceptedFlair)
|
||||
p.AcceptedFlair=false; //2015.08.08.
|
||||
if(!p.IgnoredFlair)
|
||||
{
|
||||
p.IgnoredFlair=true;
|
||||
String flair=p.Flair; //2015.08.08.
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already ignored this request.§r");
|
||||
break;
|
||||
}
|
||||
/*case "reload": //2015.07.20.
|
||||
DoReload(player);
|
||||
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;
|
||||
}
|
||||
p.Flair="§7(non-pr.)§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.§r");
|
||||
break;
|
||||
}
|
||||
p.Flair="§r(can't press)§r";
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*if(args[0].toLowerCase()=="reload")
|
||||
DoReload(null); //2015.07.20.*/
|
||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); //2015.08.09.
|
||||
return true; //2015.08.09.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static void DoReload(Player player)
|
||||
{ //2015.07.20.
|
||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
//{
|
||||
try
|
||||
{
|
||||
File file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
PluginMain.LoadFiles(true)
|
||||
for(Player p : PluginMain.GetPlayers())
|
||||
{
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||
if(mp.Flair!=null)
|
||||
{
|
||||
String flair=mp.Flair;
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
||||
}
|
||||
}
|
||||
//String msg="§6Reloaded config file.§r";
|
||||
String msg="§6Reloaded all files.§r";
|
||||
SendMessage(player, msg); //2015.08.09.
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
if(player!=null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
//}
|
||||
//else
|
||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoAdmin(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
{
|
||||
//System.out.println("Args length: " + args.length);
|
||||
if(args.length==1)
|
||||
{
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
//args[0] is "admin"
|
||||
switch(args[1].toLowerCase())
|
||||
{
|
||||
case "reload":
|
||||
DoReload(player);
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
default:
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoPlayerInfo(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "playerinfo"
|
||||
if(args.length==2)
|
||||
{
|
||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||
{
|
||||
String message="§cPlayer not found: "+args[2]+"§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
SendMessage(player, "Player name: "+p.PlayerName);
|
||||
SendMessage(player, "User flair: "+p.Flair);
|
||||
SendMessage(player, "Username: "+p.UserName);
|
||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
||||
}
|
||||
private static void SendMessage(Player player, String message)
|
||||
{ //2015.08.09.
|
||||
if(player==null)
|
||||
System.out.println(message);
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
private static void DoGetLastError(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "getlasterror"
|
||||
if(PluginMain.LastException!=null)
|
||||
{
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException=null;
|
||||
}
|
||||
else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
}
|
|
@ -1,450 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
|
||||
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/
|
||||
private static PluginMain Instance;
|
||||
// Fired when plugin is first enabled
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
this.getCommand("u").setExecutor(new Commands());
|
||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||
Instance=this; //2015.08.08.
|
||||
LoadFiles(false); //2015.08.09.
|
||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||
Thread t=new Thread(r);
|
||||
t.start();
|
||||
}
|
||||
Boolean stop=false;
|
||||
// Fired when plugin is disabled
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
SaveFiles(); //2015.08.09.
|
||||
stop=true;
|
||||
}
|
||||
|
||||
public void ThreadMethod() //<-- 2015.07.16.
|
||||
{
|
||||
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();
|
||||
//System.out.println("Start: "+start);
|
||||
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.
|
||||
//System.out.println("End: "+end);
|
||||
if (end == -1 || end == start)
|
||||
ign = ign.substring(start);
|
||||
else
|
||||
ign = ign.substring(start, end);
|
||||
//System.out.println("IGN: "+ign);
|
||||
ign = ign.trim();
|
||||
//System.out.println("Trimmed IGN: "+ign);
|
||||
if(HasIGFlair(ign))
|
||||
continue;
|
||||
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";
|
||||
/*else
|
||||
flair = "non-presser";*/
|
||||
String flairclass;
|
||||
if(flairdata.length>2)
|
||||
flairclass = flairdata[2];
|
||||
else
|
||||
flairclass="unknown";
|
||||
SetFlair(ign, flair, flairclass, author);
|
||||
}
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Exception LastException; //2015.08.09.
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||
public Boolean HasIGFlair(String playername)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
//return p.Flair!=null; //2015.08.08.
|
||||
return p.CommentedOnReddit; //2015.08.10.
|
||||
}
|
||||
|
||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
String finalflair;
|
||||
p.FlairDecided=true;
|
||||
p.FlairRecognised=true;
|
||||
switch(flairclass)
|
||||
{
|
||||
case "press-1":
|
||||
finalflair="§c("+text+")§r";
|
||||
break;
|
||||
case "press-2":
|
||||
finalflair="§6("+text+")§r";
|
||||
break;
|
||||
case "press-3":
|
||||
finalflair="§e("+text+")§r";
|
||||
break;
|
||||
case "press-4":
|
||||
finalflair="§a("+text+")§r";
|
||||
break;
|
||||
case "press-5":
|
||||
finalflair="§9("+text+")§r";
|
||||
break;
|
||||
case "press-6":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "no-press":
|
||||
finalflair="§7(--s)§r";
|
||||
break;
|
||||
case "cheater":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "cant-press": //2015.08.08.
|
||||
finalflair="§r(??s)§r";
|
||||
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;
|
||||
default:
|
||||
//finalflair="";
|
||||
//break;
|
||||
return;
|
||||
}
|
||||
/*if(finalflair.length()==0) //<-- 2015.07.20.
|
||||
return;*/
|
||||
p.Flair=finalflair; //2015.08.08.
|
||||
p.CommentedOnReddit=true; //2015.08.10.
|
||||
p.UserName=username; //2015.08.08.
|
||||
if(finalflair.length()==0) //Just for the message
|
||||
finalflair="undecided";
|
||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||
{
|
||||
if(player.getName().equals(playername))
|
||||
{
|
||||
//AppendPlayerDisplayFlair(player, username, finalflair);
|
||||
AppendPlayerDisplayFlair(p, player);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String GetFlair(Player player)
|
||||
{ //2015.07.16.
|
||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||
//return flair==null ? "" : flair;
|
||||
return flair; //2015.08.10.
|
||||
}
|
||||
|
||||
//public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||
public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09.
|
||||
{
|
||||
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair)
|
||||
return;
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair)
|
||||
{
|
||||
//AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20.
|
||||
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");
|
||||
}
|
||||
|
||||
/*private static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
*String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||
String[] colors = color.substring(1).split("§");
|
||||
String displayname=player.getName(); //2015.08.08.
|
||||
ArrayList<Integer> Positions=new ArrayList<>();
|
||||
for(int i=0; i<displayname.length(); i++) {
|
||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||
Positions.add(i);
|
||||
}
|
||||
}
|
||||
String finalname=""; //TODO
|
||||
if(Positions.size()>=colors.length)
|
||||
{
|
||||
int x=0;
|
||||
for(int i=0; i<Positions.size(); i++)
|
||||
{
|
||||
int pos=Positions.get(i);
|
||||
int nextpos;
|
||||
if(i!=Positions.size()-1)
|
||||
nextpos=Positions.get(i+1);
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Positions.clear();
|
||||
int unit=displayname.length()/colors.length;
|
||||
int x=0;
|
||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||
{
|
||||
int pos=i;
|
||||
int nextpos;
|
||||
if(i<displayname.length()-unit-unit)
|
||||
nextpos=i+unit;
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}*
|
||||
}*/
|
||||
|
||||
public static String GetColorForTown(String townname)
|
||||
{ //2015.07.20.
|
||||
if(TownColors.containsKey(townname))
|
||||
return TownColors.get(townname);
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String GetPlayerTown(Player player)
|
||||
{ //2015.07.20.
|
||||
try {
|
||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||
return town.getName();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/*public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||
}*/
|
||||
|
||||
public static Collection<? extends Player> GetPlayers()
|
||||
{
|
||||
return Instance.getServer().getOnlinePlayers();
|
||||
}
|
||||
|
||||
public static void LoadFiles(boolean reload) //<-- 2015.08.09.
|
||||
{
|
||||
if(reload)
|
||||
{ //2015.08.09.
|
||||
System.out.println("Auto-flair plugin cleanup for reloading...");
|
||||
MaybeOfflinePlayer.AllPlayers.clear();
|
||||
TownColors.clear();
|
||||
}
|
||||
System.out.println("Loading files for auto-flair plugin..."); //2015.08.09.
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
//System.out.println("Name: " + name);
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("flairsignored.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while((line=br.readLine())!=null)
|
||||
{
|
||||
String[] s=line.split(" ");
|
||||
if(s.length>=2) //<-- 2015.08.10.
|
||||
TownColors.put(s[0], s[1]);
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("customflairs.txt"); //2015.08.09.
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while((line=br.readLine())!=null)
|
||||
{
|
||||
String[] s=line.split(" ");
|
||||
if(s.length>=2) //2015.08.10.
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]);
|
||||
p.Flair=s[1]; //2015.08.09.
|
||||
p.CommentedOnReddit=true; //Kind of
|
||||
}
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
//throw new IOException("Test"); //2015.08.09.
|
||||
System.out.println("Auto-flair plugin loaded files!");
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
public static void SaveFiles() //<-- 2015.08.09.
|
||||
{
|
||||
try
|
||||
{
|
||||
FileWriter fw;
|
||||
fw = new FileWriter("flairsaccepted.txt");
|
||||
fw.close();
|
||||
fw = new FileWriter("flairsignored.txt");
|
||||
fw.close();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.AcceptedFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
file=new File("flairsignored.txt");
|
||||
bw = new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.IgnoredFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
public static boolean RemoveLineFromFile(String file, String line)
|
||||
{ //2015.08.09.
|
||||
File inputFile = new File(file);
|
||||
File tempFile = new File("_temp.txt");
|
||||
|
||||
if(!inputFile.exists())
|
||||
return true; //2015.08.10.
|
||||
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(inputFile));
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
|
||||
|
||||
String lineToRemove = line;
|
||||
String currentLine;
|
||||
|
||||
while((currentLine = reader.readLine()) != null) {
|
||||
// trim newline when comparing with lineToRemove
|
||||
String trimmedLine = currentLine.trim();
|
||||
//if(trimmedLine.equals(lineToRemove)) continue;
|
||||
if(trimmedLine.contains(lineToRemove)) continue; //2015.08.09.
|
||||
writer.write(currentLine + System.getProperty("line.separator"));
|
||||
}
|
||||
writer.close();
|
||||
reader.close();
|
||||
if(!tempFile.renameTo(inputFile))
|
||||
{
|
||||
inputFile.delete();
|
||||
return tempFile.renameTo(inputFile);
|
||||
}
|
||||
else
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,452 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
|
||||
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/
|
||||
private static PluginMain Instance;
|
||||
public static ConsoleCommandSender Console; //2015.08.12.
|
||||
// Fired when plugin is first enabled
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
this.getCommand("u").setExecutor(new Commands());
|
||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||
Instance=this; //2015.08.08.
|
||||
LoadFiles(false); //2015.08.09.
|
||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||
Thread t=new Thread(r);
|
||||
t.start();
|
||||
}
|
||||
Boolean stop=false;
|
||||
// Fired when plugin is disabled
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
SaveFiles(); //2015.08.09.
|
||||
stop=true;
|
||||
}
|
||||
|
||||
public void ThreadMethod() //<-- 2015.07.16.
|
||||
{
|
||||
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();
|
||||
//System.out.println("Start: "+start);
|
||||
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.
|
||||
//System.out.println("End: "+end);
|
||||
if (end == -1 || end == start)
|
||||
ign = ign.substring(start);
|
||||
else
|
||||
ign = ign.substring(start, end);
|
||||
//System.out.println("IGN: "+ign);
|
||||
ign = ign.trim();
|
||||
//System.out.println("Trimmed IGN: "+ign);
|
||||
if(HasIGFlair(ign))
|
||||
continue;
|
||||
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";
|
||||
/*else
|
||||
flair = "non-presser";*/
|
||||
String flairclass;
|
||||
if(flairdata.length>2)
|
||||
flairclass = flairdata[2];
|
||||
else
|
||||
flairclass="unknown";
|
||||
SetFlair(ign, flair, flairclass, author);
|
||||
}
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Exception LastException; //2015.08.09.
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||
public Boolean HasIGFlair(String playername)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
//return p.Flair!=null; //2015.08.08.
|
||||
return p.CommentedOnReddit; //2015.08.10.
|
||||
}
|
||||
|
||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
String finalflair;
|
||||
p.FlairDecided=true;
|
||||
p.FlairRecognised=true;
|
||||
switch(flairclass)
|
||||
{
|
||||
case "press-1":
|
||||
finalflair="§c("+text+")§r";
|
||||
break;
|
||||
case "press-2":
|
||||
finalflair="§6("+text+")§r";
|
||||
break;
|
||||
case "press-3":
|
||||
finalflair="§e("+text+")§r";
|
||||
break;
|
||||
case "press-4":
|
||||
finalflair="§a("+text+")§r";
|
||||
break;
|
||||
case "press-5":
|
||||
finalflair="§9("+text+")§r";
|
||||
break;
|
||||
case "press-6":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "no-press":
|
||||
finalflair="§7(--s)§r";
|
||||
break;
|
||||
case "cheater":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "cant-press": //2015.08.08.
|
||||
finalflair="§r(??s)§r";
|
||||
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;
|
||||
default:
|
||||
//finalflair="";
|
||||
//break;
|
||||
return;
|
||||
}
|
||||
/*if(finalflair.length()==0) //<-- 2015.07.20.
|
||||
return;*/
|
||||
p.Flair=finalflair; //2015.08.08.
|
||||
p.CommentedOnReddit=true; //2015.08.10.
|
||||
p.UserName=username; //2015.08.08.
|
||||
if(finalflair.length()==0) //Just for the message
|
||||
finalflair="undecided";
|
||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||
{
|
||||
if(player.getName().equals(playername))
|
||||
{
|
||||
//AppendPlayerDisplayFlair(player, username, finalflair);
|
||||
AppendPlayerDisplayFlair(p, player);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String GetFlair(Player player)
|
||||
{ //2015.07.16.
|
||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||
//return flair==null ? "" : flair;
|
||||
return flair; //2015.08.10.
|
||||
}
|
||||
|
||||
//public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||
public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09.
|
||||
{
|
||||
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair)
|
||||
return;
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair)
|
||||
{
|
||||
//AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20.
|
||||
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");
|
||||
}
|
||||
|
||||
/*private static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
*String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||
String[] colors = color.substring(1).split("§");
|
||||
String displayname=player.getName(); //2015.08.08.
|
||||
ArrayList<Integer> Positions=new ArrayList<>();
|
||||
for(int i=0; i<displayname.length(); i++) {
|
||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||
Positions.add(i);
|
||||
}
|
||||
}
|
||||
String finalname=""; //TODO
|
||||
if(Positions.size()>=colors.length)
|
||||
{
|
||||
int x=0;
|
||||
for(int i=0; i<Positions.size(); i++)
|
||||
{
|
||||
int pos=Positions.get(i);
|
||||
int nextpos;
|
||||
if(i!=Positions.size()-1)
|
||||
nextpos=Positions.get(i+1);
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Positions.clear();
|
||||
int unit=displayname.length()/colors.length;
|
||||
int x=0;
|
||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||
{
|
||||
int pos=i;
|
||||
int nextpos;
|
||||
if(i<displayname.length()-unit-unit)
|
||||
nextpos=i+unit;
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}*
|
||||
}*/
|
||||
|
||||
public static String GetColorForTown(String townname)
|
||||
{ //2015.07.20.
|
||||
if(TownColors.containsKey(townname))
|
||||
return TownColors.get(townname);
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String GetPlayerTown(Player player)
|
||||
{ //2015.07.20.
|
||||
try {
|
||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||
return town.getName();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/*public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||
}*/
|
||||
|
||||
public static Collection<? extends Player> GetPlayers()
|
||||
{
|
||||
return Instance.getServer().getOnlinePlayers();
|
||||
}
|
||||
|
||||
public static void LoadFiles(boolean reload) //<-- 2015.08.09.
|
||||
{
|
||||
if(reload)
|
||||
{ //2015.08.09.
|
||||
System.out.println("Auto-flair plugin cleanup for reloading...");
|
||||
MaybeOfflinePlayer.AllPlayers.clear();
|
||||
TownColors.clear();
|
||||
}
|
||||
System.out.println("Loading files for auto-flair plugin..."); //2015.08.09.
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
//System.out.println("Name: " + name);
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("flairsignored.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while((line=br.readLine())!=null)
|
||||
{
|
||||
String[] s=line.split(" ");
|
||||
if(s.length>=2) //<-- 2015.08.10.
|
||||
TownColors.put(s[0], s[1]);
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("customflairs.txt"); //2015.08.09.
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while((line=br.readLine())!=null)
|
||||
{
|
||||
String[] s=line.split(" ");
|
||||
if(s.length>=2) //2015.08.10.
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]);
|
||||
p.Flair=s[1]; //2015.08.09.
|
||||
p.CommentedOnReddit=true; //Kind of
|
||||
}
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
//throw new IOException("Test"); //2015.08.09.
|
||||
System.out.println("Auto-flair plugin loaded files!");
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
public static void SaveFiles() //<-- 2015.08.09.
|
||||
{
|
||||
try
|
||||
{
|
||||
FileWriter fw;
|
||||
fw = new FileWriter("flairsaccepted.txt");
|
||||
fw.close();
|
||||
fw = new FileWriter("flairsignored.txt");
|
||||
fw.close();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.AcceptedFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
file=new File("flairsignored.txt");
|
||||
bw = new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.IgnoredFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
public static boolean RemoveLineFromFile(String file, String line)
|
||||
{ //2015.08.09.
|
||||
File inputFile = new File(file);
|
||||
File tempFile = new File("_temp.txt");
|
||||
|
||||
if(!inputFile.exists())
|
||||
return true; //2015.08.10.
|
||||
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(inputFile));
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
|
||||
|
||||
String lineToRemove = line;
|
||||
String currentLine;
|
||||
|
||||
while((currentLine = reader.readLine()) != null) {
|
||||
// trim newline when comparing with lineToRemove
|
||||
String trimmedLine = currentLine.trim();
|
||||
//if(trimmedLine.equals(lineToRemove)) continue;
|
||||
if(trimmedLine.contains(lineToRemove)) continue; //2015.08.09.
|
||||
writer.write(currentLine + System.getProperty("line.separator"));
|
||||
}
|
||||
writer.close();
|
||||
reader.close();
|
||||
if(!tempFile.renameTo(inputFile))
|
||||
{
|
||||
inputFile.delete();
|
||||
return tempFile.renameTo(inputFile);
|
||||
}
|
||||
else
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,496 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
|
||||
public static boolean PluginUpdated = false; // 2015.08.31.
|
||||
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label,
|
||||
String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
switch (cmd.getName()) {
|
||||
case "u": {
|
||||
if (args.length < 1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(player
|
||||
.getName()); // 2015.08.08.
|
||||
if (!p.CommentedOnReddit
|
||||
&& !args[0].toLowerCase().equals("admin")
|
||||
&& !args[0].toLowerCase().equals("ignore")) {
|
||||
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")) { // 2015.08.10.
|
||||
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")) { // 2015.08.19.
|
||||
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
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
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");
|
||||
} else
|
||||
player.sendMessage("§cYou already ignored this request.§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
|
||||
break;
|
||||
case "announce":
|
||||
DoAnnounce(player, args, null);
|
||||
break;
|
||||
case "name":
|
||||
if (args.length == 1) {
|
||||
player.sendMessage("§cUsage: /u name <playername>§r");
|
||||
break;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[1])) {
|
||||
player.sendMessage("§cUnknown user: " + args[1]);
|
||||
break;
|
||||
}
|
||||
player.sendMessage("§bUsername of "
|
||||
+ args[1]
|
||||
+ ": "
|
||||
+ MaybeOfflinePlayer.AllPlayers.get(args[1]).UserName);
|
||||
break;
|
||||
case "enable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = true;
|
||||
player.sendMessage("Enabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
case "disable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = false;
|
||||
player.sendMessage("Disabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "nrp":
|
||||
case "ooc":
|
||||
if (args.length == 0) {
|
||||
return false;
|
||||
} else {
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = false;
|
||||
String message = "";
|
||||
for (String arg : args)
|
||||
message += arg + " ";
|
||||
player.chat(message.substring(0, message.length() - 1));
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = true;
|
||||
}
|
||||
return true;
|
||||
case "skype":
|
||||
// "skype:?chat&blob=Y_5Ob1BEcw0ZlstdUHyf0ENS5n1Xz2Huhx-5b-pB2JyMSRO5QMEALkJuTSuUaAb3-XfWXwCndwhGex_UpXDbyQ";
|
||||
return true;
|
||||
default:
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
}
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("admin")) // 2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); // 2015.08.09.
|
||||
return true; // 2015.08.09.
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("announce")) {
|
||||
if (sender instanceof BlockCommandSender)
|
||||
DoAnnounce(null, args, (BlockCommandSender) sender);
|
||||
else
|
||||
DoAnnounce(null, args, null);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void DoReload(Player player) { // 2015.07.20.
|
||||
try {
|
||||
PluginMain.Console
|
||||
.sendMessage("§6-- Reloading The Button Minecraft plugin...§r");
|
||||
PluginMain.LoadFiles(true); // 2015.08.09.
|
||||
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.
|
||||
}
|
||||
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.
|
||||
}
|
||||
PluginMain.Console.sendMessage("§6-- Reloading done!§r");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
if (player != null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static Player ReloadPlayer; // 2015.08.09.
|
||||
|
||||
private static String DoAdminUsage = "§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin|togglerpshow|toggledebug|savepos|loadpos§r";
|
||||
|
||||
private static void DoAdmin(Player player, String[] args) { // 2015.08.09.
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// args[0] is "admin"
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "reload":
|
||||
ReloadPlayer = player; // 2015.08.09.
|
||||
SendMessage(
|
||||
player,
|
||||
"§bMake sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
break; // <-- 2015.08.10.
|
||||
case "confirm":
|
||||
if (ReloadPlayer == player)
|
||||
DoReload(player); // 2015.08.09.
|
||||
else
|
||||
SendMessage(player,
|
||||
"§cYou need to do /u admin reload first.§r");
|
||||
break;
|
||||
case "save":
|
||||
PluginMain.SaveFiles(); // 2015.08.09.
|
||||
SendMessage(player,
|
||||
"§bSaved files. Now you can edit them and reload if you want.§r");
|
||||
break;
|
||||
case "setflair":
|
||||
DoSetFlair(player, args);
|
||||
break;
|
||||
case "updateplugin": // 2015.08.10.
|
||||
DoUpdatePlugin(player);
|
||||
break;
|
||||
case "togglerpshow":
|
||||
PlayerListener.ShowRPTag = !PlayerListener.ShowRPTag;
|
||||
SendMessage(player, "RP tag showing "
|
||||
+ (PlayerListener.ShowRPTag ? "enabled" : "disabled"));
|
||||
break;
|
||||
case "toggledebug":
|
||||
PlayerListener.DebugMode = !PlayerListener.DebugMode;
|
||||
SendMessage(player, "DebugMode: " + PlayerListener.DebugMode);
|
||||
break;
|
||||
case "savepos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "loadpos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "updatedynmap":
|
||||
DoUpdateDynmap(player, args);
|
||||
default:
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
|
||||
private static void DoPlayerInfo(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "playerinfo"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(args[2]);
|
||||
if (p == null) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
SendMessage(player, "Player name: " + p.PlayerName);
|
||||
SendMessage(player, "User flair: " + p.Flair);
|
||||
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);
|
||||
}
|
||||
|
||||
private static void SendMessage(Player player, String message) { // 2015.08.09.
|
||||
if (player == null)
|
||||
PluginMain.Console.sendMessage(message); // 2015.08.12.
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
private static void DoGetLastError(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "getlasterror"
|
||||
if (PluginMain.LastException != null) {
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException = null;
|
||||
} else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
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");
|
||||
return;
|
||||
}
|
||||
Player p = Bukkit.getPlayer(args[2]);
|
||||
if (p == null) {
|
||||
SendMessage(player, "§cPLayer not found.&r");
|
||||
return;
|
||||
}
|
||||
SetPlayerFlair(player,
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()), args[3]);
|
||||
}
|
||||
|
||||
private static void DoUpdatePlugin(Player player) { // 2015.08.10.
|
||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
||||
System.out.println("Forced updating of Auto-Flair plugin.");
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(
|
||||
"https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
||||
FileUtils.copyURLToFile(url, new File(
|
||||
"plugins/TheButtonAutoFlair.jar"));
|
||||
PluginUpdated = true; // 2015.08.31.
|
||||
SendMessage(player, "Updating done!");
|
||||
} catch (MalformedURLException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoAnnounce(Player player, String[] args,
|
||||
BlockCommandSender commandblock) {
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "add":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce add <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
PluginMain.AnnounceMessages.add(finalmessage);
|
||||
SendMessage(player, "§bAnnouncement added.§r");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce remove <index>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceMessages.remove(Integer.parseInt(args[2]));
|
||||
break;
|
||||
case "settime":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player,
|
||||
"§cUsage: /u announce settime <minutes>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceTime = Integer.parseInt(args[2]) * 60 * 1000;
|
||||
SendMessage(player, "Time set between announce messages");
|
||||
break;
|
||||
case "list":
|
||||
SendMessage(player, "§bList of announce messages:§r");
|
||||
SendMessage(player, "§bFormat: [index] message§r");
|
||||
int i = 0;
|
||||
for (String message : PluginMain.AnnounceMessages)
|
||||
SendMessage(player, "[" + i++ + "] " + message);
|
||||
SendMessage(player,
|
||||
"§bCurrent wait time between announcements: "
|
||||
+ PluginMain.AnnounceTime / 60 / 1000
|
||||
+ " minute(s)§r");
|
||||
break;
|
||||
case "edit":
|
||||
if (commandblock == null) {
|
||||
SendMessage(
|
||||
player,
|
||||
"§cError: This command can only be used from a command block. Use /u announce remove.");
|
||||
break;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
commandblock
|
||||
.sendMessage("§cUsage: /u announce edit <index> <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 3; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§');
|
||||
int index = Integer.parseInt(args[2]);
|
||||
if (index > 100)
|
||||
break;
|
||||
while (PluginMain.AnnounceMessages.size() <= index)
|
||||
PluginMain.AnnounceMessages.add("");
|
||||
PluginMain.AnnounceMessages.set(Integer.parseInt(args[2]),
|
||||
finalmessage1);
|
||||
commandblock.sendMessage("Announcement edited.");
|
||||
break;
|
||||
default:
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoSaveLoadPos(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "savepos|loadpos"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
Player p = null;
|
||||
for (Player pl : PluginMain.GetPlayers()) {
|
||||
if (pl.getName().equals(args[2])) {
|
||||
p = pl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (p == null) {
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer is not online: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (args[1].equalsIgnoreCase("savepos")) {
|
||||
mp.SavedLocation = p.getLocation();
|
||||
} else if (args[1].equalsIgnoreCase("loadpos")) {
|
||||
if (mp.SavedLocation != null)
|
||||
p.teleport(mp.SavedLocation);
|
||||
} else {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// SendMessage(player, "Player " + p.getName() +
|
||||
// " position saved/loaded.");s
|
||||
}
|
||||
|
||||
private static void DoUpdateDynmap(Player player, String[] args) {
|
||||
// args[0] is "admin" - args[1] is "updatedynmap"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin updatedynmap <password>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,362 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import tk.sznp.thebuttonautoflair.MaybeOfflinePlayer.FlairClassType;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
|
||||
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/
|
||||
private static PluginMain Instance;
|
||||
// Fired when plugin is first enabled
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
this.getCommand("u").setExecutor(new Commands());
|
||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||
Instance=this; //2015.08.08.
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
//System.out.println("Name: " + name);
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("flairsignored.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while((line=br.readLine())!=null)
|
||||
{
|
||||
String[] s=line.split(" ");
|
||||
TownColors.put(s[0], s[1]);
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
//throw new IOException("Test"); //2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||
Thread t=new Thread(r);
|
||||
t.start();
|
||||
}
|
||||
Boolean stop=false;
|
||||
// Fired when plugin is disabled
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
try
|
||||
{
|
||||
FileWriter fw;
|
||||
fw = new FileWriter("flairsaccepted.txt");
|
||||
fw.close();
|
||||
fw = new FileWriter("flairsignored.txt");
|
||||
fw.close();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.AcceptedFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
file=new File("flairsignored.txt");
|
||||
bw = new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.IgnoredFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
stop=true;
|
||||
}
|
||||
|
||||
public void ThreadMethod() //<-- 2015.07.16.
|
||||
{
|
||||
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();
|
||||
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();
|
||||
if(HasIGFlair(ign))
|
||||
continue;
|
||||
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";
|
||||
else
|
||||
flair = "non-presser";
|
||||
String flairclass;
|
||||
if(flairdata.length>2)
|
||||
flairclass = flairdata[2];
|
||||
else
|
||||
flairclass="unknown";
|
||||
SetFlair(ign, flair, flairclass, author);
|
||||
}
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Exception LastException; //2015.08.09.
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||
public Boolean HasIGFlair(String playername)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
return p.Flair!=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
String finalflair;
|
||||
p.FlairDecided=true;
|
||||
switch(flairclass)
|
||||
{
|
||||
case "press-1":
|
||||
finalflair="§c("+text+")§r";
|
||||
break;
|
||||
case "press-2":
|
||||
finalflair="§6("+text+")§r";
|
||||
break;
|
||||
case "press-3":
|
||||
finalflair="§e("+text+")§r";
|
||||
break;
|
||||
case "press-4":
|
||||
finalflair="§a("+text+")§r";
|
||||
break;
|
||||
case "press-5":
|
||||
finalflair="§9("+text+")§r";
|
||||
break;
|
||||
case "press-6":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "no-press":
|
||||
finalflair="§7(non-pr.)§r";
|
||||
break;
|
||||
case "cheater":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "cant-press": //2015.08.08.
|
||||
finalflair="§r(can't press)§r";
|
||||
break;
|
||||
case "undecided": //2015.08.09.
|
||||
p.FlairDecided=false;
|
||||
finalflair="";
|
||||
break;
|
||||
default:
|
||||
finalflair="";
|
||||
break;
|
||||
}
|
||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||
return;
|
||||
p.Flair=finalflair; //2015.08.08.
|
||||
p.UserName=username; //2015.08.08.
|
||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||
{
|
||||
if(player.getName().equals(playername))
|
||||
{
|
||||
AppendPlayerDisplayFlair(player, username, finalflair);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String GetFlair(Player player)
|
||||
{ //2015.07.16.
|
||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||
return flair==null ? "" : flair;
|
||||
}
|
||||
|
||||
//public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||
public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p)
|
||||
{
|
||||
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair)
|
||||
return;
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair)
|
||||
{
|
||||
AppendPlayerDisplayFlairFinal(p, flair); //2015.07.20.
|
||||
}
|
||||
else
|
||||
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
||||
}
|
||||
|
||||
private static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||
String[] colors = color.substring(1).split("§");
|
||||
String displayname=player.getName(); //2015.08.08.
|
||||
ArrayList<Integer> Positions=new ArrayList<>();
|
||||
for(int i=0; i<displayname.length(); i++) {
|
||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||
Positions.add(i);
|
||||
}
|
||||
}
|
||||
String finalname=""; //TODO
|
||||
if(Positions.size()>=colors.length)
|
||||
{
|
||||
int x=0;
|
||||
for(int i=0; i<Positions.size(); i++)
|
||||
{
|
||||
int pos=Positions.get(i);
|
||||
int nextpos;
|
||||
if(i!=Positions.size()-1)
|
||||
nextpos=Positions.get(i+1);
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Positions.clear();
|
||||
int unit=displayname.length()/colors.length;
|
||||
int x=0;
|
||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||
{
|
||||
int pos=i;
|
||||
int nextpos;
|
||||
if(i<displayname.length()-unit-unit)
|
||||
nextpos=i+unit;
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||
}
|
||||
|
||||
public static String GetColorForTown(String townname)
|
||||
{ //2015.07.20.
|
||||
if(TownColors.containsKey(townname))
|
||||
return TownColors.get(townname);
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String GetPlayerTown(Player player)
|
||||
{ //2015.07.20.
|
||||
try {
|
||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||
return town.getName();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public static Collection<? extends Player> GetPlayers()
|
||||
{
|
||||
return Instance.getServer().getOnlinePlayers();
|
||||
}
|
||||
}
|
|
@ -1,323 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerChatTabCompleteEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import au.com.mineauz.minigames.Minigames;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerListener implements Listener { // 2015.07.16.
|
||||
public static HashMap<String, UUID> nicknames = new HashMap<>();
|
||||
|
||||
public static boolean Enable = false; // 2015.08.29.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p
|
||||
.getUniqueId());
|
||||
mp.PlayerName = p.getName(); // 2015.10.17. 0:58
|
||||
// if (mp.CommentedOnReddit)
|
||||
if (false)
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); // 2015.08.09.
|
||||
else { // 2015.07.20.
|
||||
Timer timer = new Timer();
|
||||
var tt = new TimerTask() {
|
||||
public MaybeOfflinePlayer mp;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!mp.IgnoredFlair) {
|
||||
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,
|
||||
"tellraw " + mp.PlayerName + " " + json);
|
||||
json = "[\"\",{\"text\":\"If you don't want the flair, type /u ignore to prevent this message after next login.\",\"color\":\"aqua\"}]";
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Console,
|
||||
"tellraw " + mp.PlayerName + " " + json);
|
||||
}
|
||||
}
|
||||
};
|
||||
tt.mp=mp;
|
||||
timer.schedule(tt, 15 * 1000);
|
||||
}
|
||||
|
||||
/* NICKNAME LOGIC */
|
||||
|
||||
UUID id = p.getUniqueId();
|
||||
|
||||
File f = new File("plugins/Essentials/userdata/" + id + ".yml");
|
||||
if (f.exists()) {
|
||||
YamlConfiguration yc = new YamlConfiguration();
|
||||
try {
|
||||
yc.load(f);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String nickname = yc.getString("nickname");
|
||||
if (nickname != null) {
|
||||
nicknames.put(nickname, id);
|
||||
|
||||
if (Enable) {
|
||||
if (!p.getName().equals("NorbiPeti")) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.chat("Hey, " + nickname + "!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mp.RPMode = true; // 2015.08.25.
|
||||
|
||||
if (p.getName().equals("FigyTuna") && Commands.PluginUpdated)
|
||||
p.sendMessage("§bThe The Button MC plugin got updated. Please restart the server. :P§r");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
String deletenick = null;
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
UUID uuid = nicknames.get(nickname);
|
||||
if (event.getPlayer().getUniqueId().equals(uuid)) {
|
||||
deletenick = nickname;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (deletenick != null)
|
||||
nicknames.remove(deletenick);
|
||||
}
|
||||
|
||||
public static String NotificationSound; // 2015.08.14.
|
||||
public static double NotificationPitch; // 2015.08.14.
|
||||
|
||||
public static boolean ShowRPTag = false; // 2015.08.31.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.GetFromName(event
|
||||
.getPlayer().getName());
|
||||
String flair = player.Flair; // 2015.08.08.
|
||||
if (player.IgnoredFlair)
|
||||
flair = "";
|
||||
String message = event.getMessage(); // 2015.08.08.
|
||||
for (Player p : PluginMain.GetPlayers()) { // 2015.08.12.
|
||||
String color = ""; // 2015.08.17.
|
||||
if (message.contains(p.getName())) {
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(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);
|
||||
}
|
||||
|
||||
message = message.replaceAll(p.getName(), color + p.getName()
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
for (String n : nicknames.keySet()) {
|
||||
Player p = null;
|
||||
String nwithoutformatting = new String(n);
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (message.contains(nwithoutformatting)) {
|
||||
p = Bukkit.getPlayer(nicknames.get(n));
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(float) NotificationPitch); // 2015.08.14.
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()); // 2015.08.17.
|
||||
}
|
||||
if (p != null) {
|
||||
message = message.replaceAll(nwithoutformatting, n
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
}
|
||||
|
||||
event.setMessage(message); // 2015.09.05.
|
||||
|
||||
event.setFormat(event
|
||||
.getFormat()
|
||||
.replace(
|
||||
"{rptag}",
|
||||
(player.RPMode ? (ShowRPTag ? "§2[RP]§r" : "")
|
||||
: "§8[OOC]§r"))
|
||||
.replace("{buttonflair}", flair)
|
||||
.replace(
|
||||
"{isitwilds}",
|
||||
(event.getPlayer().getWorld().getName()
|
||||
.equalsIgnoreCase("wilds") ? "[PVP]" : ""))); // 2015.09.04.
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTabComplete(PlayerChatTabCompleteEvent e) {
|
||||
String name = e.getLastToken();
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
String nwithoutformatting = nickname;
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (nwithoutformatting.startsWith(name)
|
||||
&& !nwithoutformatting.equals(Bukkit.getPlayer(
|
||||
nicknames.get(nickname)).getName()))
|
||||
e.getTabCompletions().add(nwithoutformatting);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean DebugMode = false;
|
||||
|
||||
public void SendForDebug(String message) {
|
||||
if (DebugMode) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.sendMessage("[DEBUG] " + message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean ActiveF = false;
|
||||
private int FCount = 0;
|
||||
private long FTime;
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMessage(AsyncPlayerChatEvent e) {
|
||||
if (ActiveF) {
|
||||
if (System.currentTimeMillis() - FTime > 10000) {
|
||||
ActiveF = false;
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
p.sendMessage("§b" + FCount + " "
|
||||
+ (FCount == 1 ? "person" : "people")
|
||||
+ " paid their respects.§r");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e.getMessage().equalsIgnoreCase("F")) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(e
|
||||
.getPlayer().getName());
|
||||
if (!mp.PressedF && ActiveF) {
|
||||
FCount++;
|
||||
mp.PressedF = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (e.getMessage().startsWith(">"))
|
||||
e.setMessage("§2" + e.getMessage());
|
||||
|
||||
/*
|
||||
* Channel c = ((Chat) Bukkit.getPluginManager().getPlugin("TownyChat"))
|
||||
* .getChannelsHandler().getActiveChannel(e.getPlayer(),
|
||||
* channelTypes.GLOBAL);
|
||||
*/
|
||||
/*
|
||||
* List<String> modes = ((Chat) Bukkit.getPluginManager().getPlugin(
|
||||
* "TownyChat")).getTowny().getPlayerMode(e.getPlayer()); if
|
||||
* (modes.size() == 0 || modes.contains("g")) {
|
||||
*/
|
||||
if (e.getFormat().contains("[g]")) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("tellraw @a [\"\"");
|
||||
sb.append(",{\"text\":\"Hashtags:\"}");
|
||||
int index = -1;
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
while ((index = e.getMessage().indexOf("#", index + 1)) != -1) {
|
||||
int index2 = e.getMessage().indexOf(" ", index + 1);
|
||||
if (index2 == -1)
|
||||
index2 = e.getMessage().length();
|
||||
int index3 = e.getMessage().indexOf("#", index + 1);
|
||||
if (index3 != -1 && index3 < index2) // A # occurs before a
|
||||
// space
|
||||
index2 = index3;
|
||||
String original = e.getMessage().substring(index, index2);
|
||||
list.add(original);
|
||||
sb.append(",{\"text\":\" \"}");
|
||||
sb.append(",{\"text\":\"");
|
||||
sb.append(original);
|
||||
sb.append("\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://twitter.com/hashtag/");
|
||||
sb.append(original.substring(1));
|
||||
sb.append("\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open on Twitter\",\"color\":\"blue\"}]}}}");
|
||||
}
|
||||
for (String original : list)
|
||||
e.setMessage(e.getMessage().replace(
|
||||
original,
|
||||
"§9"
|
||||
+ original
|
||||
+ (e.getMessage().startsWith("§2>") ? "§2"
|
||||
: "§r")));
|
||||
/*
|
||||
* for (String original : list)
|
||||
* System.out.println(e.getMessage().replace( original, "§9" +
|
||||
* original + (e.getMessage().startsWith("§2>") ? "§2" : "§r")));
|
||||
*/
|
||||
|
||||
sb.append("]");
|
||||
|
||||
if (list.size() > 0)
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Instance.getServer().getConsoleSender(),
|
||||
sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDeath(PlayerDeathEvent e) {
|
||||
if (!Minigames.plugin.pdata.getMinigamePlayer(e.getEntity())
|
||||
.isInMinigame() && new Random().nextBoolean()) {
|
||||
ActiveF = true;
|
||||
FCount = 0;
|
||||
FTime = System.currentTimeMillis();
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(p
|
||||
.getName());
|
||||
mp.PressedF = false;
|
||||
p.sendMessage("§bPress F to pay respects.§r");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,322 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerChatTabCompleteEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import au.com.mineauz.minigames.Minigames;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerListener implements Listener { // 2015.07.16.
|
||||
public static HashMap<String, UUID> nicknames = new HashMap<>();
|
||||
|
||||
public static boolean Enable = false; // 2015.08.29.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
final MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p
|
||||
.getUniqueId());
|
||||
mp.PlayerName = p.getName(); // 2015.10.17. 0:58
|
||||
if (mp.CommentedOnReddit)
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); // 2015.08.09.
|
||||
else { // 2015.07.20.
|
||||
Timer timer = new Timer();
|
||||
timer.schedule(new TimerTask()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (!mp.IgnoredFlair) {
|
||||
String message = "§bIf you'd like your flair displayed ingame, write your §6Minecraft name to this thread:§r";
|
||||
String json = "[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your §6Minecraft name to \"},{\"text\":\"[this thread.]\",\"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§r\"}]}}}]";
|
||||
- sendRawMessage(p, json);
|
||||
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console, "tellraw ")
|
||||
message = "§bhttps://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/§r";
|
||||
p.sendMessage(message);
|
||||
message = "§6If you don't want the flair, type /u ignore to prevent this message on login.§r";
|
||||
p.sendMessage(message);
|
||||
message = "§bIf you already commented your name, then please wait a few seconds.§r";
|
||||
p.sendMessage(message);
|
||||
}
|
||||
}
|
||||
}, 15*1000)
|
||||
}
|
||||
|
||||
/* NICKNAME LOGIC */
|
||||
|
||||
UUID id = p.getUniqueId();
|
||||
|
||||
File f = new File("plugins/Essentials/userdata/" + id + ".yml");
|
||||
if (f.exists()) {
|
||||
YamlConfiguration yc = new YamlConfiguration();
|
||||
try {
|
||||
yc.load(f);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String nickname = yc.getString("nickname");
|
||||
if (nickname != null) {
|
||||
nicknames.put(nickname, id);
|
||||
|
||||
if (Enable) {
|
||||
if (!p.getName().equals("NorbiPeti")) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.chat("Hey, " + nickname + "!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mp.RPMode = true; // 2015.08.25.
|
||||
|
||||
if (p.getName().equals("FigyTuna") && Commands.PluginUpdated)
|
||||
p.sendMessage("§bThe The Button MC plugin got updated. Please restart the server. :P§r");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
String deletenick = null;
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
UUID uuid = nicknames.get(nickname);
|
||||
if (event.getPlayer().getUniqueId().equals(uuid)) {
|
||||
deletenick = nickname;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (deletenick != null)
|
||||
nicknames.remove(deletenick);
|
||||
}
|
||||
|
||||
public static String NotificationSound; // 2015.08.14.
|
||||
public static double NotificationPitch; // 2015.08.14.
|
||||
|
||||
public static boolean ShowRPTag = false; // 2015.08.31.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.GetFromName(event
|
||||
.getPlayer().getName());
|
||||
String flair = player.Flair; // 2015.08.08.
|
||||
if (player.IgnoredFlair)
|
||||
flair = "";
|
||||
String message = event.getMessage(); // 2015.08.08.
|
||||
for (Player p : PluginMain.GetPlayers()) { // 2015.08.12.
|
||||
String color = ""; // 2015.08.17.
|
||||
if (message.contains(p.getName())) {
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(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);
|
||||
}
|
||||
|
||||
message = message.replaceAll(p.getName(), color + p.getName()
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
for (String n : nicknames.keySet()) {
|
||||
Player p = null;
|
||||
String nwithoutformatting = new String(n);
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (message.contains(nwithoutformatting)) {
|
||||
p = Bukkit.getPlayer(nicknames.get(n));
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(float) NotificationPitch); // 2015.08.14.
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()); // 2015.08.17.
|
||||
}
|
||||
if (p != null) {
|
||||
message = message.replaceAll(nwithoutformatting, n
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
}
|
||||
|
||||
event.setMessage(message); // 2015.09.05.
|
||||
|
||||
event.setFormat(event
|
||||
.getFormat()
|
||||
.replace(
|
||||
"{rptag}",
|
||||
(player.RPMode ? (ShowRPTag ? "§2[RP]§r" : "")
|
||||
: "§8[OOC]§r"))
|
||||
.replace("{buttonflair}", flair)
|
||||
.replace(
|
||||
"{isitwilds}",
|
||||
(event.getPlayer().getWorld().getName()
|
||||
.equalsIgnoreCase("wilds") ? "[PVP]" : ""))); // 2015.09.04.
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTabComplete(PlayerChatTabCompleteEvent e) {
|
||||
String name = e.getLastToken();
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
String nwithoutformatting = nickname;
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (nwithoutformatting.startsWith(name)
|
||||
&& !nwithoutformatting.equals(Bukkit.getPlayer(
|
||||
nicknames.get(nickname)).getName()))
|
||||
e.getTabCompletions().add(nwithoutformatting);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean DebugMode = false;
|
||||
|
||||
public void SendForDebug(String message) {
|
||||
if (DebugMode) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.sendMessage("[DEBUG] " + message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean ActiveF = false;
|
||||
private int FCount = 0;
|
||||
private long FTime;
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMessage(AsyncPlayerChatEvent e) {
|
||||
if (ActiveF) {
|
||||
if (System.currentTimeMillis() - FTime > 10000) {
|
||||
ActiveF = false;
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
p.sendMessage("§b" + FCount + " "
|
||||
+ (FCount == 1 ? "person" : "people")
|
||||
+ " paid their respects.§r");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e.getMessage().equalsIgnoreCase("F")) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(e
|
||||
.getPlayer().getName());
|
||||
if (!mp.PressedF && ActiveF) {
|
||||
FCount++;
|
||||
mp.PressedF = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (e.getMessage().startsWith(">"))
|
||||
e.setMessage("§2" + e.getMessage());
|
||||
|
||||
/*
|
||||
* Channel c = ((Chat) Bukkit.getPluginManager().getPlugin("TownyChat"))
|
||||
* .getChannelsHandler().getActiveChannel(e.getPlayer(),
|
||||
* channelTypes.GLOBAL);
|
||||
*/
|
||||
/*
|
||||
* List<String> modes = ((Chat) Bukkit.getPluginManager().getPlugin(
|
||||
* "TownyChat")).getTowny().getPlayerMode(e.getPlayer()); if
|
||||
* (modes.size() == 0 || modes.contains("g")) {
|
||||
*/
|
||||
if (e.getFormat().contains("[g]")) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("tellraw @a [\"\"");
|
||||
sb.append(",{\"text\":\"Hashtags:\"}");
|
||||
int index = -1;
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
while ((index = e.getMessage().indexOf("#", index + 1)) != -1) {
|
||||
int index2 = e.getMessage().indexOf(" ", index + 1);
|
||||
if (index2 == -1)
|
||||
index2 = e.getMessage().length();
|
||||
int index3 = e.getMessage().indexOf("#", index + 1);
|
||||
if (index3 != -1 && index3 < index2) // A # occurs before a
|
||||
// space
|
||||
index2 = index3;
|
||||
String original = e.getMessage().substring(index, index2);
|
||||
list.add(original);
|
||||
sb.append(",{\"text\":\" \"}");
|
||||
sb.append(",{\"text\":\"");
|
||||
sb.append(original);
|
||||
sb.append("\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://twitter.com/hashtag/");
|
||||
sb.append(original.substring(1));
|
||||
sb.append("\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open on Twitter\",\"color\":\"blue\"}]}}}");
|
||||
}
|
||||
for (String original : list)
|
||||
e.setMessage(e.getMessage().replace(
|
||||
original,
|
||||
"§9"
|
||||
+ original
|
||||
+ (e.getMessage().startsWith("§2>") ? "§2"
|
||||
: "§r")));
|
||||
/*
|
||||
* for (String original : list)
|
||||
* System.out.println(e.getMessage().replace( original, "§9" +
|
||||
* original + (e.getMessage().startsWith("§2>") ? "§2" : "§r")));
|
||||
*/
|
||||
|
||||
sb.append("]");
|
||||
|
||||
if (list.size() > 0)
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Instance.getServer().getConsoleSender(),
|
||||
sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDeath(PlayerDeathEvent e) {
|
||||
if (!Minigames.plugin.pdata.getMinigamePlayer(e.getEntity())
|
||||
.isInMinigame() && new Random().nextBoolean()) {
|
||||
ActiveF = true;
|
||||
FCount = 0;
|
||||
FTime = System.currentTimeMillis();
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(p
|
||||
.getName());
|
||||
mp.PressedF = false;
|
||||
p.sendMessage("§bPress F to pay respects.§r");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class MaybeOfflinePlayer
|
||||
{ //2015.08.08.
|
||||
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
|
||||
public static HashMap<String, MaybeOfflinePlayer> AllPlayers=new HashMap<>(); //2015.08.08.
|
||||
public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername)
|
||||
{
|
||||
if(!AllPlayers.containsKey(playername))
|
||||
{
|
||||
MaybeOfflinePlayer player=new MaybeOfflinePlayer();
|
||||
player.PlayerName=playername;
|
||||
AllPlayers.put(playername, player);
|
||||
return player;
|
||||
}
|
||||
return AllPlayers.get(playername);
|
||||
}
|
||||
public enum FlairClassType
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -1,588 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
|
||||
public static boolean PluginUpdated = false; // 2015.08.31.
|
||||
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label,
|
||||
String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
switch (cmd.getName()) {
|
||||
case "u": {
|
||||
if (args.length < 1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(player
|
||||
.getName()); // 2015.08.08.
|
||||
if (!p.CommentedOnReddit
|
||||
&& !args[0].toLowerCase().equals("admin")
|
||||
&& !args[0].toLowerCase().equals("ignore")) {
|
||||
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")) { // 2015.08.10.
|
||||
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")) { // 2015.08.19.
|
||||
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
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
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");
|
||||
} else
|
||||
player.sendMessage("§cYou already ignored this request.§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
|
||||
break;
|
||||
case "announce":
|
||||
DoAnnounce(player, args, null);
|
||||
break;
|
||||
case "name":
|
||||
if (args.length == 1) {
|
||||
player.sendMessage("§cUsage: /u name <playername>§r");
|
||||
break;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[1])) {
|
||||
player.sendMessage("§cUnknown user: " + args[1]);
|
||||
break;
|
||||
}
|
||||
player.sendMessage("§bUsername of "
|
||||
+ args[1]
|
||||
+ ": "
|
||||
+ MaybeOfflinePlayer.AllPlayers.get(args[1]).UserName);
|
||||
break;
|
||||
case "enable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = true;
|
||||
player.sendMessage("Enabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
case "disable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = false;
|
||||
player.sendMessage("Disabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "nrp":
|
||||
case "ooc":
|
||||
if (args.length == 0) {
|
||||
return false;
|
||||
} else {
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = false;
|
||||
String message = "";
|
||||
for (String arg : args)
|
||||
message += arg + " ";
|
||||
player.chat(message.substring(0, message.length() - 1));
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = true;
|
||||
}
|
||||
return true;
|
||||
case "skype":
|
||||
// "skype:?chat&blob=Y_5Ob1BEcw0ZlstdUHyf0ENS5n1Xz2Huhx-5b-pB2JyMSRO5QMEALkJuTSuUaAb3-XfWXwCndwhGex_UpXDbyQ";
|
||||
return true;
|
||||
default:
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
}
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("admin")) // 2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); // 2015.08.09.
|
||||
return true; // 2015.08.09.
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("announce")) {
|
||||
if (sender instanceof BlockCommandSender)
|
||||
DoAnnounce(null, args, (BlockCommandSender) sender);
|
||||
else
|
||||
DoAnnounce(null, args, null);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void DoReload(Player player) { // 2015.07.20.
|
||||
try {
|
||||
PluginMain.Console
|
||||
.sendMessage("§6-- Reloading The Button Minecraft plugin...§r");
|
||||
PluginMain.LoadFiles(true); // 2015.08.09.
|
||||
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.
|
||||
}
|
||||
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.
|
||||
}
|
||||
PluginMain.Console.sendMessage("§6-- Reloading done!§r");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
if (player != null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static Player ReloadPlayer; // 2015.08.09.
|
||||
|
||||
private static String DoAdminUsage = "§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin|togglerpshow|toggledebug|savepos|loadpos§r";
|
||||
|
||||
private static void DoAdmin(Player player, String[] args) { // 2015.08.09.
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// args[0] is "admin"
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "reload":
|
||||
ReloadPlayer = player; // 2015.08.09.
|
||||
SendMessage(
|
||||
player,
|
||||
"§bMake sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
break; // <-- 2015.08.10.
|
||||
case "confirm":
|
||||
if (ReloadPlayer == player)
|
||||
DoReload(player); // 2015.08.09.
|
||||
else
|
||||
SendMessage(player,
|
||||
"§cYou need to do /u admin reload first.§r");
|
||||
break;
|
||||
case "save":
|
||||
PluginMain.SaveFiles(); // 2015.08.09.
|
||||
SendMessage(player,
|
||||
"§bSaved files. Now you can edit them and reload if you want.§r");
|
||||
break;
|
||||
case "setflair":
|
||||
DoSetFlair(player, args);
|
||||
break;
|
||||
case "updateplugin": // 2015.08.10.
|
||||
DoUpdatePlugin(player);
|
||||
break;
|
||||
case "togglerpshow":
|
||||
PlayerListener.ShowRPTag = !PlayerListener.ShowRPTag;
|
||||
SendMessage(player, "RP tag showing "
|
||||
+ (PlayerListener.ShowRPTag ? "enabled" : "disabled"));
|
||||
break;
|
||||
case "toggledebug":
|
||||
PlayerListener.DebugMode = !PlayerListener.DebugMode;
|
||||
SendMessage(player, "DebugMode: " + PlayerListener.DebugMode);
|
||||
break;
|
||||
case "savepos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "loadpos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "updatedynmap":
|
||||
DoUpdateDynmap(player, args);
|
||||
default:
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
|
||||
private static void DoPlayerInfo(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "playerinfo"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(args[2]);
|
||||
if (p == null) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
SendMessage(player, "Player name: " + p.PlayerName);
|
||||
SendMessage(player, "User flair: " + p.Flair);
|
||||
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);
|
||||
}
|
||||
|
||||
private static void SendMessage(Player player, String message) { // 2015.08.09.
|
||||
if (player == null)
|
||||
PluginMain.Console.sendMessage(message); // 2015.08.12.
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
private static void DoGetLastError(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "getlasterror"
|
||||
if (PluginMain.LastException != null) {
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException = null;
|
||||
} else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
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");
|
||||
return;
|
||||
}
|
||||
Player p = Bukkit.getPlayer(args[2]);
|
||||
if (p == null) {
|
||||
SendMessage(player, "§cPLayer not found.&r");
|
||||
return;
|
||||
}
|
||||
SetPlayerFlair(player,
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()), args[3]);
|
||||
}
|
||||
|
||||
private static void DoUpdatePlugin(Player player) { // 2015.08.10.
|
||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
||||
System.out.println("Forced updating of Auto-Flair plugin.");
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(
|
||||
"https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
||||
FileUtils.copyURLToFile(url, new File(
|
||||
"plugins/TheButtonAutoFlair.jar"));
|
||||
PluginUpdated = true; // 2015.08.31.
|
||||
SendMessage(player, "Updating done!");
|
||||
} catch (MalformedURLException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoAnnounce(Player player, String[] args,
|
||||
BlockCommandSender commandblock) {
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "add":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce add <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
PluginMain.AnnounceMessages.add(finalmessage);
|
||||
SendMessage(player, "§bAnnouncement added.§r");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce remove <index>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceMessages.remove(Integer.parseInt(args[2]));
|
||||
break;
|
||||
case "settime":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player,
|
||||
"§cUsage: /u announce settime <minutes>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceTime = Integer.parseInt(args[2]) * 60 * 1000;
|
||||
SendMessage(player, "Time set between announce messages");
|
||||
break;
|
||||
case "list":
|
||||
SendMessage(player, "§bList of announce messages:§r");
|
||||
SendMessage(player, "§bFormat: [index] message§r");
|
||||
int i = 0;
|
||||
for (String message : PluginMain.AnnounceMessages)
|
||||
SendMessage(player, "[" + i++ + "] " + message);
|
||||
SendMessage(player,
|
||||
"§bCurrent wait time between announcements: "
|
||||
+ PluginMain.AnnounceTime / 60 / 1000
|
||||
+ " minute(s)§r");
|
||||
break;
|
||||
case "edit":
|
||||
if (commandblock == null) {
|
||||
SendMessage(
|
||||
player,
|
||||
"§cError: This command can only be used from a command block. Use /u announce remove.");
|
||||
break;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
commandblock
|
||||
.sendMessage("§cUsage: /u announce edit <index> <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 3; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§');
|
||||
int index = Integer.parseInt(args[2]);
|
||||
if (index > 100)
|
||||
break;
|
||||
while (PluginMain.AnnounceMessages.size() <= index)
|
||||
PluginMain.AnnounceMessages.add("");
|
||||
PluginMain.AnnounceMessages.set(Integer.parseInt(args[2]),
|
||||
finalmessage1);
|
||||
commandblock.sendMessage("Announcement edited.");
|
||||
break;
|
||||
default:
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoSaveLoadPos(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "savepos|loadpos"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
Player p = null;
|
||||
for (Player pl : PluginMain.GetPlayers()) {
|
||||
if (pl.getName().equals(args[2])) {
|
||||
p = pl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (p == null) {
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer is not online: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (args[1].equalsIgnoreCase("savepos")) {
|
||||
mp.SavedLocation = p.getLocation();
|
||||
} else if (args[1].equalsIgnoreCase("loadpos")) {
|
||||
if (mp.SavedLocation != null)
|
||||
p.teleport(mp.SavedLocation);
|
||||
} else {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// SendMessage(player, "Player " + p.getName() +
|
||||
// " position saved/loaded.");s
|
||||
}
|
||||
|
||||
private static void DoUpdateDynmap(Player player, String[] args) {
|
||||
// args[0] is "admin" - args[1] is "updatedynmap"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin updatedynmap <password>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static ArrayList<String> Quiz = new ArrayList<>();
|
||||
|
||||
private static void DoQuiz(Player player, String[] args,
|
||||
BlockCommandSender commandblock) {
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = "§cUsage: /u quiz add|remove|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "add":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u quiz add <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
PluginMain.AnnounceMessages.add(finalmessage);
|
||||
SendMessage(player, "§bAnnouncement added.§r");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce remove <index>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceMessages.remove(Integer.parseInt(args[2]));
|
||||
break;
|
||||
case "settime":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player,
|
||||
"§cUsage: /u announce settime <minutes>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceTime = Integer.parseInt(args[2]) * 60 * 1000;
|
||||
SendMessage(player, "Time set between announce messages");
|
||||
break;
|
||||
case "list":
|
||||
SendMessage(player, "§bList of announce messages:§r");
|
||||
SendMessage(player, "§bFormat: [index] message§r");
|
||||
int i = 0;
|
||||
for (String message : PluginMain.AnnounceMessages)
|
||||
SendMessage(player, "[" + i++ + "] " + message);
|
||||
SendMessage(player,
|
||||
"§bCurrent wait time between announcements: "
|
||||
+ PluginMain.AnnounceTime / 60 / 1000
|
||||
+ " minute(s)§r");
|
||||
break;
|
||||
case "edit":
|
||||
if (commandblock == null) {
|
||||
SendMessage(
|
||||
player,
|
||||
"§cError: This command can only be used from a command block. Use /u announce remove.");
|
||||
break;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
commandblock
|
||||
.sendMessage("§cUsage: /u announce edit <index> <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 3; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§');
|
||||
int index = Integer.parseInt(args[2]);
|
||||
if (index > 100)
|
||||
break;
|
||||
while (PluginMain.AnnounceMessages.size() <= index)
|
||||
PluginMain.AnnounceMessages.add("");
|
||||
PluginMain.AnnounceMessages.set(Integer.parseInt(args[2]),
|
||||
finalmessage1);
|
||||
commandblock.sendMessage("Announcement edited.");
|
||||
break;
|
||||
default:
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,588 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
|
||||
public static boolean PluginUpdated = false; // 2015.08.31.
|
||||
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label,
|
||||
String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
switch (cmd.getName()) {
|
||||
case "u": {
|
||||
if (args.length < 1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(player
|
||||
.getName()); // 2015.08.08.
|
||||
if (!p.CommentedOnReddit
|
||||
&& !args[0].toLowerCase().equals("admin")
|
||||
&& !args[0].toLowerCase().equals("ignore")) {
|
||||
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")) { // 2015.08.10.
|
||||
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")) { // 2015.08.19.
|
||||
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
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
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");
|
||||
} else
|
||||
player.sendMessage("§cYou already ignored this request.§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
|
||||
break;
|
||||
case "announce":
|
||||
DoAnnounce(player, args, null);
|
||||
break;
|
||||
case "name":
|
||||
if (args.length == 1) {
|
||||
player.sendMessage("§cUsage: /u name <playername>§r");
|
||||
break;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[1])) {
|
||||
player.sendMessage("§cUnknown user: " + args[1]);
|
||||
break;
|
||||
}
|
||||
player.sendMessage("§bUsername of "
|
||||
+ args[1]
|
||||
+ ": "
|
||||
+ MaybeOfflinePlayer.AllPlayers.get(args[1]).UserName);
|
||||
break;
|
||||
case "enable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = true;
|
||||
player.sendMessage("Enabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
case "disable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = false;
|
||||
player.sendMessage("Disabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "nrp":
|
||||
case "ooc":
|
||||
if (args.length == 0) {
|
||||
return false;
|
||||
} else {
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = false;
|
||||
String message = "";
|
||||
for (String arg : args)
|
||||
message += arg + " ";
|
||||
player.chat(message.substring(0, message.length() - 1));
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = true;
|
||||
}
|
||||
return true;
|
||||
case "skype":
|
||||
// "skype:?chat&blob=Y_5Ob1BEcw0ZlstdUHyf0ENS5n1Xz2Huhx-5b-pB2JyMSRO5QMEALkJuTSuUaAb3-XfWXwCndwhGex_UpXDbyQ";
|
||||
return true;
|
||||
default:
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
}
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("admin")) // 2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); // 2015.08.09.
|
||||
return true; // 2015.08.09.
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("announce")) {
|
||||
if (sender instanceof BlockCommandSender)
|
||||
DoAnnounce(null, args, (BlockCommandSender) sender);
|
||||
else
|
||||
DoAnnounce(null, args, null);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void DoReload(Player player) { // 2015.07.20.
|
||||
try {
|
||||
PluginMain.Console
|
||||
.sendMessage("§6-- Reloading The Button Minecraft plugin...§r");
|
||||
PluginMain.LoadFiles(true); // 2015.08.09.
|
||||
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.
|
||||
}
|
||||
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.
|
||||
}
|
||||
PluginMain.Console.sendMessage("§6-- Reloading done!§r");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
if (player != null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static Player ReloadPlayer; // 2015.08.09.
|
||||
|
||||
private static String DoAdminUsage = "§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin|togglerpshow|toggledebug|savepos|loadpos§r";
|
||||
|
||||
private static void DoAdmin(Player player, String[] args) { // 2015.08.09.
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// args[0] is "admin"
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "reload":
|
||||
ReloadPlayer = player; // 2015.08.09.
|
||||
SendMessage(
|
||||
player,
|
||||
"§bMake sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
break; // <-- 2015.08.10.
|
||||
case "confirm":
|
||||
if (ReloadPlayer == player)
|
||||
DoReload(player); // 2015.08.09.
|
||||
else
|
||||
SendMessage(player,
|
||||
"§cYou need to do /u admin reload first.§r");
|
||||
break;
|
||||
case "save":
|
||||
PluginMain.SaveFiles(); // 2015.08.09.
|
||||
SendMessage(player,
|
||||
"§bSaved files. Now you can edit them and reload if you want.§r");
|
||||
break;
|
||||
case "setflair":
|
||||
DoSetFlair(player, args);
|
||||
break;
|
||||
case "updateplugin": // 2015.08.10.
|
||||
DoUpdatePlugin(player);
|
||||
break;
|
||||
case "togglerpshow":
|
||||
PlayerListener.ShowRPTag = !PlayerListener.ShowRPTag;
|
||||
SendMessage(player, "RP tag showing "
|
||||
+ (PlayerListener.ShowRPTag ? "enabled" : "disabled"));
|
||||
break;
|
||||
case "toggledebug":
|
||||
PlayerListener.DebugMode = !PlayerListener.DebugMode;
|
||||
SendMessage(player, "DebugMode: " + PlayerListener.DebugMode);
|
||||
break;
|
||||
case "savepos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "loadpos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "updatedynmap":
|
||||
DoUpdateDynmap(player, args);
|
||||
default:
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
|
||||
private static void DoPlayerInfo(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "playerinfo"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(args[2]);
|
||||
if (p == null) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
SendMessage(player, "Player name: " + p.PlayerName);
|
||||
SendMessage(player, "User flair: " + p.Flair);
|
||||
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);
|
||||
}
|
||||
|
||||
private static void SendMessage(Player player, String message) { // 2015.08.09.
|
||||
if (player == null)
|
||||
PluginMain.Console.sendMessage(message); // 2015.08.12.
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
private static void DoGetLastError(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "getlasterror"
|
||||
if (PluginMain.LastException != null) {
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException = null;
|
||||
} else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
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");
|
||||
return;
|
||||
}
|
||||
Player p = Bukkit.getPlayer(args[2]);
|
||||
if (p == null) {
|
||||
SendMessage(player, "§cPLayer not found.&r");
|
||||
return;
|
||||
}
|
||||
SetPlayerFlair(player,
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()), args[3]);
|
||||
}
|
||||
|
||||
private static void DoUpdatePlugin(Player player) { // 2015.08.10.
|
||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
||||
System.out.println("Forced updating of Auto-Flair plugin.");
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(
|
||||
"https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
||||
FileUtils.copyURLToFile(url, new File(
|
||||
"plugins/TheButtonAutoFlair.jar"));
|
||||
PluginUpdated = true; // 2015.08.31.
|
||||
SendMessage(player, "Updating done!");
|
||||
} catch (MalformedURLException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoAnnounce(Player player, String[] args,
|
||||
BlockCommandSender commandblock) {
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "add":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce add <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
PluginMain.AnnounceMessages.add(finalmessage);
|
||||
SendMessage(player, "§bAnnouncement added.§r");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce remove <index>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceMessages.remove(Integer.parseInt(args[2]));
|
||||
break;
|
||||
case "settime":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player,
|
||||
"§cUsage: /u announce settime <minutes>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceTime = Integer.parseInt(args[2]) * 60 * 1000;
|
||||
SendMessage(player, "Time set between announce messages");
|
||||
break;
|
||||
case "list":
|
||||
SendMessage(player, "§bList of announce messages:§r");
|
||||
SendMessage(player, "§bFormat: [index] message§r");
|
||||
int i = 0;
|
||||
for (String message : PluginMain.AnnounceMessages)
|
||||
SendMessage(player, "[" + i++ + "] " + message);
|
||||
SendMessage(player,
|
||||
"§bCurrent wait time between announcements: "
|
||||
+ PluginMain.AnnounceTime / 60 / 1000
|
||||
+ " minute(s)§r");
|
||||
break;
|
||||
case "edit":
|
||||
if (commandblock == null) {
|
||||
SendMessage(
|
||||
player,
|
||||
"§cError: This command can only be used from a command block. Use /u announce remove.");
|
||||
break;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
commandblock
|
||||
.sendMessage("§cUsage: /u announce edit <index> <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 3; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§');
|
||||
int index = Integer.parseInt(args[2]);
|
||||
if (index > 100)
|
||||
break;
|
||||
while (PluginMain.AnnounceMessages.size() <= index)
|
||||
PluginMain.AnnounceMessages.add("");
|
||||
PluginMain.AnnounceMessages.set(Integer.parseInt(args[2]),
|
||||
finalmessage1);
|
||||
commandblock.sendMessage("Announcement edited.");
|
||||
break;
|
||||
default:
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoSaveLoadPos(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "savepos|loadpos"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
Player p = null;
|
||||
for (Player pl : PluginMain.GetPlayers()) {
|
||||
if (pl.getName().equals(args[2])) {
|
||||
p = pl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (p == null) {
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer is not online: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (args[1].equalsIgnoreCase("savepos")) {
|
||||
mp.SavedLocation = p.getLocation();
|
||||
} else if (args[1].equalsIgnoreCase("loadpos")) {
|
||||
if (mp.SavedLocation != null)
|
||||
p.teleport(mp.SavedLocation);
|
||||
} else {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// SendMessage(player, "Player " + p.getName() +
|
||||
// " position saved/loaded.");s
|
||||
}
|
||||
|
||||
private static void DoUpdateDynmap(Player player, String[] args) {
|
||||
// args[0] is "admin" - args[1] is "updatedynmap"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin updatedynmap <password>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static ArrayList<String> Quiz = new ArrayList<>();
|
||||
|
||||
private static void DoQuiz(Player player, String[] args,
|
||||
BlockCommandSender commandblock) {
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = "§cUsage: /u quiz add|remove|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "add":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u quiz add <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
Quiz.add(finalmessage);
|
||||
SendMessage(player, "§Quiz question added.§r");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u quiz remove <index>");
|
||||
return;
|
||||
}
|
||||
Quiz.remove(Integer.parseInt(args[2]));
|
||||
break;
|
||||
case "settime":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player,
|
||||
"§cUsage: /u announce settime <minutes>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceTime = Integer.parseInt(args[2]) * 60 * 1000;
|
||||
SendMessage(player, "Time set between announce messages");
|
||||
break;
|
||||
case "list":
|
||||
SendMessage(player, "§bList of announce messages:§r");
|
||||
SendMessage(player, "§bFormat: [index] message§r");
|
||||
int i = 0;
|
||||
for (String message : PluginMain.AnnounceMessages)
|
||||
SendMessage(player, "[" + i++ + "] " + message);
|
||||
SendMessage(player,
|
||||
"§bCurrent wait time between announcements: "
|
||||
+ PluginMain.AnnounceTime / 60 / 1000
|
||||
+ " minute(s)§r");
|
||||
break;
|
||||
case "edit":
|
||||
if (commandblock == null) {
|
||||
SendMessage(
|
||||
player,
|
||||
"§cError: This command can only be used from a command block. Use /u announce remove.");
|
||||
break;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
commandblock
|
||||
.sendMessage("§cUsage: /u announce edit <index> <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 3; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§');
|
||||
int index = Integer.parseInt(args[2]);
|
||||
if (index > 100)
|
||||
break;
|
||||
while (PluginMain.AnnounceMessages.size() <= index)
|
||||
PluginMain.AnnounceMessages.add("");
|
||||
PluginMain.AnnounceMessages.set(Integer.parseInt(args[2]),
|
||||
finalmessage1);
|
||||
commandblock.sendMessage("Announcement edited.");
|
||||
break;
|
||||
default:
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,338 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerChatTabCompleteEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import au.com.mineauz.minigames.Minigames;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerListener implements Listener { // 2015.07.16.
|
||||
public static HashMap<String, UUID> nicknames = new HashMap<>();
|
||||
|
||||
public static boolean Enable = false; // 2015.08.29.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p
|
||||
.getUniqueId());
|
||||
mp.PlayerName = p.getName(); // 2015.10.17. 0:58
|
||||
if (mp.CommentedOnReddit)
|
||||
// if (false)
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); // 2015.08.09.
|
||||
else { // 2015.07.20.
|
||||
Timer timer = new Timer();
|
||||
PlayerJoinTimerTask tt = new PlayerJoinTimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!mp.IgnoredFlair) {
|
||||
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,
|
||||
"tellraw " + mp.PlayerName + " " + json);
|
||||
json = "[\"\",{\"text\":\"If you don't want the flair, type /u ignore to prevent this message after next login.\",\"color\":\"aqua\"}]";
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Console,
|
||||
"tellraw " + mp.PlayerName + " " + json);
|
||||
}
|
||||
}
|
||||
};
|
||||
tt.mp = mp;
|
||||
timer.schedule(tt, 15 * 1000);
|
||||
}
|
||||
|
||||
/* NICKNAME LOGIC */
|
||||
|
||||
UUID id = p.getUniqueId();
|
||||
|
||||
File f = new File("plugins/Essentials/userdata/" + id + ".yml");
|
||||
if (f.exists()) {
|
||||
YamlConfiguration yc = new YamlConfiguration();
|
||||
try {
|
||||
yc.load(f);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String nickname = yc.getString("nickname");
|
||||
if (nickname != null) {
|
||||
nicknames.put(nickname, id);
|
||||
|
||||
if (Enable) {
|
||||
if (!p.getName().equals("NorbiPeti")) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.chat("Hey, " + nickname + "!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mp.RPMode = true; // 2015.08.25.
|
||||
|
||||
if (p.getName().equals("FigyTuna") && Commands.PluginUpdated)
|
||||
p.sendMessage("§bThe The Button MC plugin got updated. Please restart the server. :P§r");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
String deletenick = null;
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
UUID uuid = nicknames.get(nickname);
|
||||
if (event.getPlayer().getUniqueId().equals(uuid)) {
|
||||
deletenick = nickname;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (deletenick != null)
|
||||
nicknames.remove(deletenick);
|
||||
}
|
||||
|
||||
public static String NotificationSound; // 2015.08.14.
|
||||
public static double NotificationPitch; // 2015.08.14.
|
||||
|
||||
public static boolean ShowRPTag = false; // 2015.08.31.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.GetFromName(event
|
||||
.getPlayer().getName());
|
||||
String flair = player.Flair; // 2015.08.08.
|
||||
if (player.IgnoredFlair)
|
||||
flair = "";
|
||||
String message = event.getMessage(); // 2015.08.08.
|
||||
for (Player p : PluginMain.GetPlayers()) { // 2015.08.12.
|
||||
String color = ""; // 2015.08.17.
|
||||
if (message.contains(p.getName())) {
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(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);
|
||||
}
|
||||
|
||||
message = message.replaceAll(p.getName(), color + p.getName()
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
for (String n : nicknames.keySet()) {
|
||||
Player p = null;
|
||||
String nwithoutformatting = new String(n);
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (message.contains(nwithoutformatting)) {
|
||||
p = Bukkit.getPlayer(nicknames.get(n));
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(float) NotificationPitch); // 2015.08.14.
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()); // 2015.08.17.
|
||||
}
|
||||
if (p != null) {
|
||||
message = message.replaceAll(nwithoutformatting, n
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
}
|
||||
|
||||
event.setMessage(message); // 2015.09.05.
|
||||
|
||||
event.setFormat(event
|
||||
.getFormat()
|
||||
.replace(
|
||||
"{rptag}",
|
||||
(player.RPMode ? (ShowRPTag ? "§2[RP]§r" : "")
|
||||
: "§8[OOC]§r"))
|
||||
.replace("{buttonflair}", flair)
|
||||
.replace(
|
||||
"{isitwilds}",
|
||||
(event.getPlayer().getWorld().getName()
|
||||
.equalsIgnoreCase("wilds") ? "[PVP]" : ""))); // 2015.09.04.
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTabComplete(PlayerChatTabCompleteEvent e) {
|
||||
String name = e.getLastToken();
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
String nwithoutformatting = nickname;
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (nwithoutformatting.startsWith(name)
|
||||
&& !nwithoutformatting.equals(Bukkit.getPlayer(
|
||||
nicknames.get(nickname)).getName()))
|
||||
e.getTabCompletions().add(nwithoutformatting);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean DebugMode = false;
|
||||
|
||||
public void SendForDebug(String message) {
|
||||
if (DebugMode) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.sendMessage("[DEBUG] " + message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean ActiveF = false;
|
||||
private int FCount = 0;
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMessage(AsyncPlayerChatEvent e) {
|
||||
if (ActiveF) {
|
||||
if (System.currentTimeMillis() - FTime > 10000) {
|
||||
ActiveF = false;
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
p.sendMessage("§b" + FCount + " "
|
||||
+ (FCount == 1 ? "person" : "people")
|
||||
+ " paid their respects.§r");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e.getMessage().equalsIgnoreCase("F")) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(e
|
||||
.getPlayer().getName());
|
||||
if (!mp.PressedF && ActiveF) {
|
||||
FCount++;
|
||||
mp.PressedF = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (e.getMessage().startsWith(">"))
|
||||
e.setMessage("§2" + e.getMessage());
|
||||
|
||||
/*
|
||||
* Channel c = ((Chat) Bukkit.getPluginManager().getPlugin("TownyChat"))
|
||||
* .getChannelsHandler().getActiveChannel(e.getPlayer(),
|
||||
* channelTypes.GLOBAL);
|
||||
*/
|
||||
/*
|
||||
* List<String> modes = ((Chat) Bukkit.getPluginManager().getPlugin(
|
||||
* "TownyChat")).getTowny().getPlayerMode(e.getPlayer()); if
|
||||
* (modes.size() == 0 || modes.contains("g")) {
|
||||
*/
|
||||
if (e.getFormat().contains("[g]")) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("tellraw @a [\"\"");
|
||||
sb.append(",{\"text\":\"Hashtags:\"}");
|
||||
int index = -1;
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
while ((index = e.getMessage().indexOf("#", index + 1)) != -1) {
|
||||
int index2 = e.getMessage().indexOf(" ", index + 1);
|
||||
if (index2 == -1)
|
||||
index2 = e.getMessage().length();
|
||||
int index3 = e.getMessage().indexOf("#", index + 1);
|
||||
if (index3 != -1 && index3 < index2) // A # occurs before a
|
||||
// space
|
||||
index2 = index3;
|
||||
String original = e.getMessage().substring(index, index2);
|
||||
list.add(original);
|
||||
sb.append(",{\"text\":\" \"}");
|
||||
sb.append(",{\"text\":\"");
|
||||
sb.append(original);
|
||||
sb.append("\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://twitter.com/hashtag/");
|
||||
sb.append(original.substring(1));
|
||||
sb.append("\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open on Twitter\",\"color\":\"blue\"}]}}}");
|
||||
}
|
||||
for (String original : list)
|
||||
e.setMessage(e.getMessage().replace(
|
||||
original,
|
||||
"§9"
|
||||
+ original
|
||||
+ (e.getMessage().startsWith("§2>") ? "§2"
|
||||
: "§r")));
|
||||
/*
|
||||
* for (String original : list)
|
||||
* System.out.println(e.getMessage().replace( original, "§9" +
|
||||
* original + (e.getMessage().startsWith("§2>") ? "§2" : "§r")));
|
||||
*/
|
||||
|
||||
sb.append("]");
|
||||
|
||||
if (list.size() > 0)
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Instance.getServer().getConsoleSender(),
|
||||
sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private Timer Ftimer;
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDeath(PlayerDeathEvent e) {
|
||||
if (!Minigames.plugin.pdata.getMinigamePlayer(e.getEntity())
|
||||
.isInMinigame() && new Random().nextBoolean()) {
|
||||
if (Ftimer != null)
|
||||
Ftimer.cancel();
|
||||
ActiveF = true;
|
||||
FCount = 0;
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(p
|
||||
.getName());
|
||||
mp.PressedF = false;
|
||||
p.sendMessage("§bPress F to pay respects.§r");
|
||||
}
|
||||
Ftimer = new Timer();
|
||||
TimerTask tt = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (ActiveF) {
|
||||
ActiveF = false;
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
p.sendMessage("§b" + FCount + " "
|
||||
+ (FCount == 1 ? "person" : "people")
|
||||
+ " paid their respects.§r");
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Ftimer.schedule(tt, 15 * 1000);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,496 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
|
||||
public static boolean PluginUpdated = false; // 2015.08.31.
|
||||
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label,
|
||||
String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
switch (cmd.getName()) {
|
||||
case "u": {
|
||||
if (args.length < 1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(player
|
||||
.getName()); // 2015.08.08.
|
||||
if (!p.CommentedOnReddit
|
||||
&& !args[0].toLowerCase().equals("admin")
|
||||
&& !args[0].toLowerCase().equals("ignore")) {
|
||||
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")) { // 2015.08.10.
|
||||
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")) { // 2015.08.19.
|
||||
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
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
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");
|
||||
} else
|
||||
player.sendMessage("§cYou already ignored this request.§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
|
||||
break;
|
||||
case "announce":
|
||||
DoAnnounce(player, args, null);
|
||||
break;
|
||||
case "name":
|
||||
if (args.length == 1) {
|
||||
player.sendMessage("§cUsage: /u name <playername>§r");
|
||||
break;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[1])) {
|
||||
player.sendMessage("§cUnknown user: " + args[1]);
|
||||
break;
|
||||
}
|
||||
player.sendMessage("§bUsername of "
|
||||
+ args[1]
|
||||
+ ": "
|
||||
+ MaybeOfflinePlayer.AllPlayers.get(args[1]).UserName);
|
||||
break;
|
||||
case "enable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = true;
|
||||
player.sendMessage("Enabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
case "disable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = false;
|
||||
player.sendMessage("Disabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "nrp":
|
||||
case "ooc":
|
||||
if (args.length == 0) {
|
||||
return false;
|
||||
} else {
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = false;
|
||||
String message = "";
|
||||
for (String arg : args)
|
||||
message += arg + " ";
|
||||
player.chat(message.substring(0, message.length() - 1));
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = true;
|
||||
}
|
||||
return true;
|
||||
case "skype":
|
||||
// "skype:?chat&blob=Y_5Ob1BEcw0ZlstdUHyf0ENS5n1Xz2Huhx-5b-pB2JyMSRO5QMEALkJuTSuUaAb3-XfWXwCndwhGex_UpXDbyQ";
|
||||
return true;
|
||||
default:
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
}
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("admin")) // 2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); // 2015.08.09.
|
||||
return true; // 2015.08.09.
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("announce")) {
|
||||
if (sender instanceof BlockCommandSender)
|
||||
DoAnnounce(null, args, (BlockCommandSender) sender);
|
||||
else
|
||||
DoAnnounce(null, args, null);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void DoReload(Player player) { // 2015.07.20.
|
||||
try {
|
||||
PluginMain.Console
|
||||
.sendMessage("§6-- Reloading The Button Minecraft plugin...§r");
|
||||
PluginMain.LoadFiles(true); // 2015.08.09.
|
||||
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.
|
||||
}
|
||||
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.
|
||||
}
|
||||
PluginMain.Console.sendMessage("§6-- Reloading done!§r");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
if (player != null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static Player ReloadPlayer; // 2015.08.09.
|
||||
|
||||
private static String DoAdminUsage = "§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin|togglerpshow|toggledebug|savepos|loadpos§r";
|
||||
|
||||
private static void DoAdmin(Player player, String[] args) { // 2015.08.09.
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// args[0] is "admin"
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "reload":
|
||||
ReloadPlayer = player; // 2015.08.09.
|
||||
SendMessage(
|
||||
player,
|
||||
"§bMake sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
break; // <-- 2015.08.10.
|
||||
case "confirm":
|
||||
if (ReloadPlayer == player)
|
||||
DoReload(player); // 2015.08.09.
|
||||
else
|
||||
SendMessage(player,
|
||||
"§cYou need to do /u admin reload first.§r");
|
||||
break;
|
||||
case "save":
|
||||
PluginMain.SaveFiles(); // 2015.08.09.
|
||||
SendMessage(player,
|
||||
"§bSaved files. Now you can edit them and reload if you want.§r");
|
||||
break;
|
||||
case "setflair":
|
||||
DoSetFlair(player, args);
|
||||
break;
|
||||
case "updateplugin": // 2015.08.10.
|
||||
DoUpdatePlugin(player);
|
||||
break;
|
||||
case "togglerpshow":
|
||||
PlayerListener.ShowRPTag = !PlayerListener.ShowRPTag;
|
||||
SendMessage(player, "RP tag showing "
|
||||
+ (PlayerListener.ShowRPTag ? "enabled" : "disabled"));
|
||||
break;
|
||||
case "toggledebug":
|
||||
PlayerListener.DebugMode = !PlayerListener.DebugMode;
|
||||
SendMessage(player, "DebugMode: " + PlayerListener.DebugMode);
|
||||
break;
|
||||
case "savepos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "loadpos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "updatedynmap":
|
||||
DoUpdateDynmap(player, args);
|
||||
default:
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
|
||||
private static void DoPlayerInfo(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "playerinfo"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(args[2]);
|
||||
if (p == null) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
SendMessage(player, "Player name: " + p.PlayerName);
|
||||
SendMessage(player, "User flair: " + p.Flair);
|
||||
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);
|
||||
}
|
||||
|
||||
private static void SendMessage(Player player, String message) { // 2015.08.09.
|
||||
if (player == null)
|
||||
PluginMain.Console.sendMessage(message); // 2015.08.12.
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
private static void DoGetLastError(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "getlasterror"
|
||||
if (PluginMain.LastException != null) {
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException = null;
|
||||
} else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
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");
|
||||
return;
|
||||
}
|
||||
Player p = Bukkit.getPlayer(args[2]);
|
||||
if (p == null) {
|
||||
SendMessage(player, "§cPLayer not found.&r");
|
||||
return;
|
||||
}
|
||||
SetPlayerFlair(player,
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()), args[3]);
|
||||
}
|
||||
|
||||
private static void DoUpdatePlugin(Player player) { // 2015.08.10.
|
||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
||||
System.out.println("Forced updating of Auto-Flair plugin.");
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(
|
||||
"https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
||||
FileUtils.copyURLToFile(url, new File(
|
||||
"plugins/TheButtonAutoFlair.jar"));
|
||||
PluginUpdated = true; // 2015.08.31.
|
||||
SendMessage(player, "Updating done!");
|
||||
} catch (MalformedURLException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoAnnounce(Player player, String[] args,
|
||||
BlockCommandSender commandblock) {
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "add":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce add <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
PluginMain.AnnounceMessages.add(finalmessage);
|
||||
SendMessage(player, "§bAnnouncement added.§r");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce remove <index>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceMessages.remove(Integer.parseInt(args[2]));
|
||||
break;
|
||||
case "settime":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player,
|
||||
"§cUsage: /u announce settime <minutes>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceTime = Integer.parseInt(args[2]) * 60 * 1000;
|
||||
SendMessage(player, "Time set between announce messages");
|
||||
break;
|
||||
case "list":
|
||||
SendMessage(player, "§bList of announce messages:§r");
|
||||
SendMessage(player, "§bFormat: [index] message§r");
|
||||
int i = 0;
|
||||
for (String message : PluginMain.AnnounceMessages)
|
||||
SendMessage(player, "[" + i++ + "] " + message);
|
||||
SendMessage(player,
|
||||
"§bCurrent wait time between announcements: "
|
||||
+ PluginMain.AnnounceTime / 60 / 1000
|
||||
+ " minute(s)§r");
|
||||
break;
|
||||
case "edit":
|
||||
if (commandblock == null) {
|
||||
SendMessage(
|
||||
player,
|
||||
"§cError: This command can only be used from a command block. Use /u announce remove.");
|
||||
break;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
commandblock
|
||||
.sendMessage("§cUsage: /u announce edit <index> <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 3; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§');
|
||||
int index=Integer.parseInt(args[2]);
|
||||
if(index>100)
|
||||
break;
|
||||
while(PluginMain.AnnounceMessages.size()<=)
|
||||
|
||||
PluginMain.AnnounceMessages.set(Integer.parseInt(args[2]),
|
||||
finalmessage1);
|
||||
commandblock.sendMessage("Announcement edited.");
|
||||
break;
|
||||
default:
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoSaveLoadPos(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "savepos|loadpos"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
Player p = null;
|
||||
for (Player pl : PluginMain.GetPlayers()) {
|
||||
if (pl.getName().equals(args[2])) {
|
||||
p = pl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (p == null) {
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer is not online: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (args[1].equalsIgnoreCase("savepos")) {
|
||||
mp.SavedLocation = p.getLocation();
|
||||
} else if (args[1].equalsIgnoreCase("loadpos")) {
|
||||
if (mp.SavedLocation != null)
|
||||
p.teleport(mp.SavedLocation);
|
||||
} else {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// SendMessage(player, "Player " + p.getName() +
|
||||
// " position saved/loaded.");s
|
||||
}
|
||||
|
||||
private static void DoUpdateDynmap(Player player, String[] args) {
|
||||
// args[0] is "admin" - args[1] is "updatedynmap"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin updatedynmap <password>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,215 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if(args.length<1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||
if(p.Flair==null)
|
||||
{
|
||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||
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.
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
||||
p.AcceptedFlair=true; //2015.08.08.
|
||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
break;
|
||||
}
|
||||
case "ignore":
|
||||
{
|
||||
if(p.AcceptedFlair)
|
||||
p.AcceptedFlair=false; //2015.08.08.
|
||||
if(!p.IgnoredFlair)
|
||||
{
|
||||
p.IgnoredFlair=true;
|
||||
String flair=p.Flair; //2015.08.08.
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already ignored this request.§r");
|
||||
break;
|
||||
}
|
||||
/*case "reload": //2015.07.20.
|
||||
DoReload(player);
|
||||
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;
|
||||
}
|
||||
p.Flair="§7(non-pr.)§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.§r");
|
||||
break;
|
||||
}
|
||||
p.Flair="§r(can't press)§r";
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*if(args[0].toLowerCase()=="reload")
|
||||
DoReload(null); //2015.07.20.*/
|
||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); //2015.08.09.
|
||||
return true; //2015.08.09.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static void DoReload(Player player)
|
||||
{ //2015.07.20.
|
||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
//{
|
||||
try
|
||||
{
|
||||
File file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
PluginMain.LoadFiles(true);
|
||||
for(Player p : PluginMain.GetPlayers())
|
||||
{
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||
if(mp.Flair!=null)
|
||||
{
|
||||
String flair=mp.Flair;
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
||||
}
|
||||
}
|
||||
//String msg="§6Reloaded config file.§r";
|
||||
String msg="§6Reloaded all files.§r";
|
||||
SendMessage(player, msg); //2015.08.09.
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
if(player!=null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
//}
|
||||
//else
|
||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoAdmin(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
{
|
||||
//System.out.println("Args length: " + args.length);
|
||||
if(args.length==1)
|
||||
{
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
//args[0] is "admin"
|
||||
switch(args[1].toLowerCase())
|
||||
{
|
||||
case "reload":
|
||||
DoReload(player);
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
default:
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoPlayerInfo(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "playerinfo"
|
||||
if(args.length==2)
|
||||
{
|
||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||
{
|
||||
String message="§cPlayer not found: "+args[2]+"§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
SendMessage(player, "Player name: "+p.PlayerName);
|
||||
SendMessage(player, "User flair: "+p.Flair);
|
||||
SendMessage(player, "Username: "+p.UserName);
|
||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
||||
}
|
||||
private static void SendMessage(Player player, String message)
|
||||
{ //2015.08.09.
|
||||
if(player==null)
|
||||
System.out.println(message);
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
private static void DoGetLastError(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "getlasterror"
|
||||
if(PluginMain.LastException!=null)
|
||||
{
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException=null;
|
||||
}
|
||||
else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
}
|
|
@ -1,302 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerChatTabCompleteEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import au.com.mineauz.minigames.Minigames;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import java.util.Timer;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerListener implements Listener { // 2015.07.16.
|
||||
public static HashMap<String, UUID> nicknames = new HashMap<>();
|
||||
|
||||
public static boolean Enable = false; // 2015.08.29.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p
|
||||
.getUniqueId());
|
||||
mp.PlayerName = p.getName(); // 2015.10.17. 0:58
|
||||
if (mp.CommentedOnReddit)
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); // 2015.08.09.
|
||||
else { // 2015.07.20.
|
||||
Timer timer = new Timer();
|
||||
}
|
||||
|
||||
/* NICKNAME LOGIC */
|
||||
|
||||
UUID id = p.getUniqueId();
|
||||
|
||||
File f = new File("plugins/Essentials/userdata/" + id + ".yml");
|
||||
if (f.exists()) {
|
||||
YamlConfiguration yc = new YamlConfiguration();
|
||||
try {
|
||||
yc.load(f);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String nickname = yc.getString("nickname");
|
||||
if (nickname != null) {
|
||||
nicknames.put(nickname, id);
|
||||
|
||||
if (Enable) {
|
||||
if (!p.getName().equals("NorbiPeti")) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.chat("Hey, " + nickname + "!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mp.RPMode = true; // 2015.08.25.
|
||||
|
||||
if (p.getName().equals("FigyTuna") && Commands.PluginUpdated)
|
||||
p.sendMessage("§bThe The Button MC plugin got updated. Please restart the server. :P§r");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
String deletenick = null;
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
UUID uuid = nicknames.get(nickname);
|
||||
if (event.getPlayer().getUniqueId().equals(uuid)) {
|
||||
deletenick = nickname;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (deletenick != null)
|
||||
nicknames.remove(deletenick);
|
||||
}
|
||||
|
||||
public static String NotificationSound; // 2015.08.14.
|
||||
public static double NotificationPitch; // 2015.08.14.
|
||||
|
||||
public static boolean ShowRPTag = false; // 2015.08.31.
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.GetFromName(event
|
||||
.getPlayer().getName());
|
||||
String flair = player.Flair; // 2015.08.08.
|
||||
if (player.IgnoredFlair)
|
||||
flair = "";
|
||||
String message = event.getMessage(); // 2015.08.08.
|
||||
for (Player p : PluginMain.GetPlayers()) { // 2015.08.12.
|
||||
String color = ""; // 2015.08.17.
|
||||
if (message.contains(p.getName())) {
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(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);
|
||||
}
|
||||
|
||||
message = message.replaceAll(p.getName(), color + p.getName()
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
for (String n : nicknames.keySet()) {
|
||||
Player p = null;
|
||||
String nwithoutformatting = new String(n);
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (message.contains(nwithoutformatting)) {
|
||||
p = Bukkit.getPlayer(nicknames.get(n));
|
||||
if (NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||
else
|
||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||
(float) NotificationPitch); // 2015.08.14.
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()); // 2015.08.17.
|
||||
}
|
||||
if (p != null) {
|
||||
message = message.replaceAll(nwithoutformatting, n
|
||||
+ (event.getMessage().startsWith("§2>") ? "§2" : "§r"));
|
||||
}
|
||||
}
|
||||
|
||||
event.setMessage(message); // 2015.09.05.
|
||||
|
||||
event.setFormat(event
|
||||
.getFormat()
|
||||
.replace(
|
||||
"{rptag}",
|
||||
(player.RPMode ? (ShowRPTag ? "§2[RP]§r" : "")
|
||||
: "§8[OOC]§r"))
|
||||
.replace("{buttonflair}", flair)
|
||||
.replace(
|
||||
"{isitwilds}",
|
||||
(event.getPlayer().getWorld().getName()
|
||||
.equalsIgnoreCase("wilds") ? "[PVP]" : ""))); // 2015.09.04.
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTabComplete(PlayerChatTabCompleteEvent e) {
|
||||
String name = e.getLastToken();
|
||||
for (String nickname : nicknames.keySet()) {
|
||||
String nwithoutformatting = nickname;
|
||||
int index;
|
||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§k"
|
||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||
// for
|
||||
// one
|
||||
// random
|
||||
// char
|
||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||
+ nwithoutformatting.charAt(index + 1), "");
|
||||
if (nwithoutformatting.startsWith(name)
|
||||
&& !nwithoutformatting.equals(Bukkit.getPlayer(
|
||||
nicknames.get(nickname)).getName()))
|
||||
e.getTabCompletions().add(nwithoutformatting);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean DebugMode = false;
|
||||
|
||||
public void SendForDebug(String message) {
|
||||
if (DebugMode) {
|
||||
for (Player player : PluginMain.GetPlayers()) {
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
player.sendMessage("[DEBUG] " + message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean ActiveF = false;
|
||||
private int FCount = 0;
|
||||
private long FTime;
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMessage(AsyncPlayerChatEvent e) {
|
||||
if (ActiveF) {
|
||||
if (System.currentTimeMillis() - FTime > 10000) {
|
||||
ActiveF = false;
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
p.sendMessage("§b" + FCount + " "
|
||||
+ (FCount == 1 ? "person" : "people")
|
||||
+ " paid their respects.§r");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e.getMessage().equalsIgnoreCase("F")) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(e
|
||||
.getPlayer().getName());
|
||||
if (!mp.PressedF && ActiveF) {
|
||||
FCount++;
|
||||
mp.PressedF = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (e.getMessage().startsWith(">"))
|
||||
e.setMessage("§2" + e.getMessage());
|
||||
|
||||
/*
|
||||
* Channel c = ((Chat) Bukkit.getPluginManager().getPlugin("TownyChat"))
|
||||
* .getChannelsHandler().getActiveChannel(e.getPlayer(),
|
||||
* channelTypes.GLOBAL);
|
||||
*/
|
||||
/*
|
||||
* List<String> modes = ((Chat) Bukkit.getPluginManager().getPlugin(
|
||||
* "TownyChat")).getTowny().getPlayerMode(e.getPlayer()); if
|
||||
* (modes.size() == 0 || modes.contains("g")) {
|
||||
*/
|
||||
if (e.getFormat().contains("[g]")) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("tellraw @a [\"\"");
|
||||
sb.append(",{\"text\":\"Hashtags:\"}");
|
||||
int index = -1;
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
while ((index = e.getMessage().indexOf("#", index + 1)) != -1) {
|
||||
int index2 = e.getMessage().indexOf(" ", index + 1);
|
||||
if (index2 == -1)
|
||||
index2 = e.getMessage().length();
|
||||
int index3 = e.getMessage().indexOf("#", index + 1);
|
||||
if (index3 != -1 && index3 < index2) // A # occurs before a
|
||||
// space
|
||||
index2 = index3;
|
||||
String original = e.getMessage().substring(index, index2);
|
||||
list.add(original);
|
||||
sb.append(",{\"text\":\" \"}");
|
||||
sb.append(",{\"text\":\"");
|
||||
sb.append(original);
|
||||
sb.append("\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://twitter.com/hashtag/");
|
||||
sb.append(original.substring(1));
|
||||
sb.append("\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open on Twitter\",\"color\":\"blue\"}]}}}");
|
||||
}
|
||||
for (String original : list)
|
||||
e.setMessage(e.getMessage().replace(
|
||||
original,
|
||||
"§9"
|
||||
+ original
|
||||
+ (e.getMessage().startsWith("§2>") ? "§2"
|
||||
: "§r")));
|
||||
/*
|
||||
* for (String original : list)
|
||||
* System.out.println(e.getMessage().replace( original, "§9" +
|
||||
* original + (e.getMessage().startsWith("§2>") ? "§2" : "§r")));
|
||||
*/
|
||||
|
||||
sb.append("]");
|
||||
|
||||
if (list.size() > 0)
|
||||
PluginMain.Instance.getServer().dispatchCommand(
|
||||
PluginMain.Instance.getServer().getConsoleSender(),
|
||||
sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDeath(PlayerDeathEvent e) {
|
||||
if (!Minigames.plugin.pdata.getMinigamePlayer(e.getEntity())
|
||||
.isInMinigame() && new Random().nextBoolean()) {
|
||||
ActiveF = true;
|
||||
FCount = 0;
|
||||
FTime = System.currentTimeMillis();
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(p
|
||||
.getName());
|
||||
mp.PressedF = false;
|
||||
p.sendMessage("§bPress F to pay respects.§r");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,306 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.String;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
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/
|
||||
public static PluginMain Instance;
|
||||
public static ConsoleCommandSender Console; // 2015.08.12.
|
||||
|
||||
// Fired when plugin is first enabled
|
||||
@Override
|
||||
public void onEnable() {
|
||||
System.out.println("The Button Minecraft server plugin");
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(),
|
||||
this);
|
||||
Commands comm = new Commands();
|
||||
this.getCommand("u").setExecutor(comm);
|
||||
this.getCommand("u").setUsage(
|
||||
this.getCommand("u").getUsage().replace('&', '§'));
|
||||
this.getCommand("nrp").setExecutor(comm);
|
||||
this.getCommand("nrp").setUsage(
|
||||
this.getCommand("nrp").getUsage().replace('&', '§'));
|
||||
this.getCommand("ooc").setExecutor(comm);
|
||||
this.getCommand("ooc").setUsage(
|
||||
this.getCommand("ooc").getUsage().replace('&', '§'));
|
||||
this.getCommand("skype").setExecutor(comm);
|
||||
Instance = this; // 2015.08.08.
|
||||
Console = this.getServer().getConsoleSender(); // 2015.08.12.
|
||||
LoadFiles(false); // 2015.08.09.
|
||||
Runnable r = new Runnable() {
|
||||
public void run() {
|
||||
ThreadMethod();
|
||||
}
|
||||
};
|
||||
Thread t = new Thread(r);
|
||||
t.start();
|
||||
r = new Runnable() {
|
||||
public void run() {
|
||||
AnnouncerThread.Run();
|
||||
}
|
||||
};
|
||||
t = new Thread(r);
|
||||
t.start();
|
||||
}
|
||||
|
||||
public Boolean stop = false;
|
||||
|
||||
// Fired when plugin is disabled
|
||||
@Override
|
||||
public void onDisable() {
|
||||
SaveFiles(); // 2015.08.09.
|
||||
stop = true;
|
||||
}
|
||||
|
||||
public void ThreadMethod() // <-- 2015.07.16.
|
||||
{
|
||||
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();
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(ign);
|
||||
if (mp == null)
|
||||
continue;
|
||||
if (HasIGFlair(mp.UUID))
|
||||
continue;
|
||||
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);
|
||||
} catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// System.out.println("Error!\n" + e);
|
||||
LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Exception LastException; // 2015.08.09.
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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,
|
||||
String username) {
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AddPlayerIfNeeded(uuid); // 2015.08.08.
|
||||
String finalflair;
|
||||
p.FlairDecided = true;
|
||||
p.FlairRecognised = true;
|
||||
switch (flairclass) {
|
||||
case "press-1":
|
||||
finalflair = "§c(" + text + ")§r";
|
||||
break;
|
||||
case "press-2":
|
||||
finalflair = "§6(" + text + ")§r";
|
||||
break;
|
||||
case "press-3":
|
||||
finalflair = "§e(" + text + ")§r";
|
||||
break;
|
||||
case "press-4":
|
||||
finalflair = "§a(" + text + ")§r";
|
||||
break;
|
||||
case "press-5":
|
||||
finalflair = "§9(" + text + ")§r";
|
||||
break;
|
||||
case "press-6":
|
||||
finalflair = "§5(" + text + ")§r";
|
||||
break;
|
||||
case "no-press":
|
||||
finalflair = "§7(--s)§r";
|
||||
break;
|
||||
case "cheater":
|
||||
finalflair = "§5(" + text + ")§r";
|
||||
break;
|
||||
case "cant-press": // 2015.08.08.
|
||||
finalflair = "§r(??s)§r";
|
||||
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;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
p.Flair = finalflair; // 2015.08.08.
|
||||
p.CommentedOnReddit = true; // 2015.08.10.
|
||||
p.UserName = username; // 2015.08.08.
|
||||
System.out.println("Added flair for " + p.PlayerName);
|
||||
AppendPlayerDisplayFlair(p, Bukkit.getPlayer(uuid));
|
||||
}
|
||||
|
||||
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 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 Collection<? extends Player> GetPlayers() {
|
||||
return Instance.getServer().getOnlinePlayers();
|
||||
}
|
||||
|
||||
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.
|
||||
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.
|
||||
try {
|
||||
File file = new File("announcemessages.txt");
|
||||
if (file.exists())
|
||||
file.delete();
|
||||
file = new File("flairsaccepted.txt");
|
||||
if (file.exists())
|
||||
file.delete();
|
||||
file = new File("flairsignored.txt");
|
||||
if (file.exists())
|
||||
file.delete();
|
||||
file = new File("thebuttonmc.yml");
|
||||
if (file.exists()) {
|
||||
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"));
|
||||
Commands.Quiz.addAll(yc.getStringList("quiz"));
|
||||
}
|
||||
System.out.println("The Button Minecraft plugin loaded files!");
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
LastException = e; // 2015.08.09.
|
||||
} catch (InvalidConfigurationException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
public static void SaveFiles() // <-- 2015.08.09.
|
||||
{
|
||||
System.out.println("Saving files for The Button Minecraft plugin..."); // 2015.08.09.
|
||||
try {
|
||||
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);
|
||||
yc.set("quiz", Commands.Quiz);
|
||||
yc.save(file);
|
||||
System.out.println("The Button Minecraft plugin saved files!");
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,221 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if(args.length<1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||
if(p.Flair==null)
|
||||
{
|
||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||
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.
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
||||
p.AcceptedFlair=true; //2015.08.08.
|
||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
break;
|
||||
}
|
||||
case "ignore":
|
||||
{
|
||||
if(p.AcceptedFlair)
|
||||
p.AcceptedFlair=false; //2015.08.08.
|
||||
if(!p.IgnoredFlair)
|
||||
{
|
||||
p.IgnoredFlair=true;
|
||||
String flair=p.Flair; //2015.08.08.
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou already ignored this request.§r");
|
||||
break;
|
||||
}
|
||||
/*case "reload": //2015.07.20.
|
||||
DoReload(player);
|
||||
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;
|
||||
}
|
||||
p.Flair="§7(non-pr.)§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.§r");
|
||||
break;
|
||||
}
|
||||
p.Flair="§r(can't press)§r";
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*if(args[0].toLowerCase()=="reload")
|
||||
DoReload(null); //2015.07.20.*/
|
||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); //2015.08.09.
|
||||
return true; //2015.08.09.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static void DoReload(Player player)
|
||||
{ //2015.07.20.
|
||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
//{
|
||||
try
|
||||
{
|
||||
File file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
PluginMain.LoadFiles(true); //2015.08.09.
|
||||
for(Player p : PluginMain.GetPlayers())
|
||||
{
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
||||
if(mp.Flair!=null)
|
||||
{
|
||||
String flair=mp.Flair;
|
||||
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
||||
}
|
||||
String msg="§6Note: 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.
|
||||
}
|
||||
//String msg="§6Reloaded config file.§r";
|
||||
//SendMessage(player, msg); //2015.08.09.
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
if(player!=null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException=e; //2015.08.09.
|
||||
}
|
||||
//}
|
||||
//else
|
||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static Player ReloadPlayer; //2015.08.09.
|
||||
private static void DoAdmin(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||
{
|
||||
//System.out.println("Args length: " + args.length);
|
||||
if(args.length==1)
|
||||
{
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
//args[0] is "admin"
|
||||
switch(args[1].toLowerCase())
|
||||
{
|
||||
case "reload":
|
||||
|
||||
SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.");
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
case "confirm":
|
||||
DoReload(player); //2015.08.09.
|
||||
break;
|
||||
default:
|
||||
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
private static void DoPlayerInfo(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "playerinfo"
|
||||
if(args.length==2)
|
||||
{
|
||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||
{
|
||||
String message="§cPlayer not found: "+args[2]+"§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
SendMessage(player, "Player name: "+p.PlayerName);
|
||||
SendMessage(player, "User flair: "+p.Flair);
|
||||
SendMessage(player, "Username: "+p.UserName);
|
||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
||||
}
|
||||
private static void SendMessage(Player player, String message)
|
||||
{ //2015.08.09.
|
||||
if(player==null)
|
||||
System.out.println(message);
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
private static void DoGetLastError(Player player, String[] args)
|
||||
{ //2015.08.09.
|
||||
//args[0] is "admin" - args[1] is "getlasterror"
|
||||
if(PluginMain.LastException!=null)
|
||||
{
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException=null;
|
||||
}
|
||||
else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
}
|
|
@ -1,491 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
|
||||
public static boolean PluginUpdated = false; // 2015.08.31.
|
||||
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label,
|
||||
String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
switch (cmd.getName()) {
|
||||
case "u": {
|
||||
if (args.length < 1)
|
||||
return false;
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(player
|
||||
.getName()); // 2015.08.08.
|
||||
if (!p.CommentedOnReddit
|
||||
&& !args[0].toLowerCase().equals("admin")
|
||||
&& !args[0].toLowerCase().equals("ignore")) {
|
||||
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")) { // 2015.08.10.
|
||||
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")) { // 2015.08.19.
|
||||
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
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
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");
|
||||
} else
|
||||
player.sendMessage("§cYou already ignored this request.§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
|
||||
break;
|
||||
case "announce":
|
||||
DoAnnounce(player, args, null);
|
||||
break;
|
||||
case "name":
|
||||
if (args.length == 1) {
|
||||
player.sendMessage("§cUsage: /u name <playername>§r");
|
||||
break;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[1])) {
|
||||
player.sendMessage("§cUnknown user: " + args[1]);
|
||||
break;
|
||||
}
|
||||
player.sendMessage("§bUsername of "
|
||||
+ args[1]
|
||||
+ ": "
|
||||
+ MaybeOfflinePlayer.AllPlayers.get(args[1]).UserName);
|
||||
break;
|
||||
case "enable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = true;
|
||||
player.sendMessage("Enabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
case "disable":
|
||||
if (player.getName().equals("NorbiPeti")) {
|
||||
PlayerListener.Enable = false;
|
||||
player.sendMessage("Disabled.");
|
||||
} else
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "nrp":
|
||||
case "ooc":
|
||||
if (args.length == 0) {
|
||||
return false;
|
||||
} else {
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = false;
|
||||
String message = "";
|
||||
for (String arg : args)
|
||||
message += arg + " ";
|
||||
player.chat(message.substring(0, message.length() - 1));
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = true;
|
||||
}
|
||||
return true;
|
||||
case "skype":
|
||||
// "skype:?chat&blob=Y_5Ob1BEcw0ZlstdUHyf0ENS5n1Xz2Huhx-5b-pB2JyMSRO5QMEALkJuTSuUaAb3-XfWXwCndwhGex_UpXDbyQ";
|
||||
return true;
|
||||
default:
|
||||
player.sendMessage("Unknown command: " + cmd.getName());
|
||||
break;
|
||||
}
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("admin")) // 2015.08.09.
|
||||
{
|
||||
DoAdmin(null, args); // 2015.08.09.
|
||||
return true; // 2015.08.09.
|
||||
} else if (args.length > 0 && args[0].toLowerCase().equals("announce")) {
|
||||
if (sender instanceof BlockCommandSender)
|
||||
DoAnnounce(null, args, (BlockCommandSender) sender);
|
||||
else
|
||||
DoAnnounce(null, args, null);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void DoReload(Player player) { // 2015.07.20.
|
||||
try {
|
||||
PluginMain.Console
|
||||
.sendMessage("§6-- Reloading The Button Minecraft plugin...§r");
|
||||
PluginMain.LoadFiles(true); // 2015.08.09.
|
||||
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.
|
||||
}
|
||||
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.
|
||||
}
|
||||
PluginMain.Console.sendMessage("§6-- Reloading done!§r");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
if (player != null)
|
||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static Player ReloadPlayer; // 2015.08.09.
|
||||
|
||||
private static String DoAdminUsage = "§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin|togglerpshow|toggledebug|savepos|loadpos§r";
|
||||
|
||||
private static void DoAdmin(Player player, String[] args) { // 2015.08.09.
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// args[0] is "admin"
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "reload":
|
||||
ReloadPlayer = player; // 2015.08.09.
|
||||
SendMessage(
|
||||
player,
|
||||
"§bMake sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
||||
break;
|
||||
case "playerinfo":
|
||||
DoPlayerInfo(player, args);
|
||||
break;
|
||||
case "getlasterror":
|
||||
DoGetLastError(player, args);
|
||||
break; // <-- 2015.08.10.
|
||||
case "confirm":
|
||||
if (ReloadPlayer == player)
|
||||
DoReload(player); // 2015.08.09.
|
||||
else
|
||||
SendMessage(player,
|
||||
"§cYou need to do /u admin reload first.§r");
|
||||
break;
|
||||
case "save":
|
||||
PluginMain.SaveFiles(); // 2015.08.09.
|
||||
SendMessage(player,
|
||||
"§bSaved files. Now you can edit them and reload if you want.§r");
|
||||
break;
|
||||
case "setflair":
|
||||
DoSetFlair(player, args);
|
||||
break;
|
||||
case "updateplugin": // 2015.08.10.
|
||||
DoUpdatePlugin(player);
|
||||
break;
|
||||
case "togglerpshow":
|
||||
PlayerListener.ShowRPTag = !PlayerListener.ShowRPTag;
|
||||
SendMessage(player, "RP tag showing "
|
||||
+ (PlayerListener.ShowRPTag ? "enabled" : "disabled"));
|
||||
break;
|
||||
case "toggledebug":
|
||||
PlayerListener.DebugMode = !PlayerListener.DebugMode;
|
||||
SendMessage(player, "DebugMode: " + PlayerListener.DebugMode);
|
||||
break;
|
||||
case "savepos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "loadpos":
|
||||
DoSaveLoadPos(player, args);
|
||||
break;
|
||||
case "updatedynmap":
|
||||
DoUpdateDynmap(player, args);
|
||||
default:
|
||||
String message = DoAdminUsage;
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||
}
|
||||
|
||||
private static void DoPlayerInfo(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "playerinfo"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin playerinfo <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(args[2]);
|
||||
if (p == null) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
SendMessage(player, "Player name: " + p.PlayerName);
|
||||
SendMessage(player, "User flair: " + p.Flair);
|
||||
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);
|
||||
}
|
||||
|
||||
private static void SendMessage(Player player, String message) { // 2015.08.09.
|
||||
if (player == null)
|
||||
PluginMain.Console.sendMessage(message); // 2015.08.12.
|
||||
else
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
private static void DoGetLastError(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "getlasterror"
|
||||
if (PluginMain.LastException != null) {
|
||||
SendMessage(player, "Last error:");
|
||||
SendMessage(player, PluginMain.LastException.toString());
|
||||
PluginMain.LastException = null;
|
||||
} else
|
||||
SendMessage(player, "There were no exceptions.");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
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");
|
||||
return;
|
||||
}
|
||||
Player p = Bukkit.getPlayer(args[2]);
|
||||
if (p == null) {
|
||||
SendMessage(player, "§cPLayer not found.&r");
|
||||
return;
|
||||
}
|
||||
SetPlayerFlair(player,
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()), args[3]);
|
||||
}
|
||||
|
||||
private static void DoUpdatePlugin(Player player) { // 2015.08.10.
|
||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
||||
System.out.println("Forced updating of Auto-Flair plugin.");
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(
|
||||
"https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
||||
FileUtils.copyURLToFile(url, new File(
|
||||
"plugins/TheButtonAutoFlair.jar"));
|
||||
PluginUpdated = true; // 2015.08.31.
|
||||
SendMessage(player, "Updating done!");
|
||||
} catch (MalformedURLException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
PluginMain.LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoAnnounce(Player player, String[] args,
|
||||
BlockCommandSender commandblock) {
|
||||
if (player == null || player.isOp()
|
||||
|| player.getName().equals("NorbiPeti")) {
|
||||
if (args.length == 1) {
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "add":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce add <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
PluginMain.AnnounceMessages.add(finalmessage);
|
||||
SendMessage(player, "§bAnnouncement added.§r");
|
||||
break;
|
||||
case "remove":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player, "§cUsage: /u announce remove <index>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceMessages.remove(Integer.parseInt(args[2]));
|
||||
break;
|
||||
case "settime":
|
||||
if (args.length < 3) {
|
||||
SendMessage(player,
|
||||
"§cUsage: /u announce settime <minutes>");
|
||||
return;
|
||||
}
|
||||
PluginMain.AnnounceTime = Integer.parseInt(args[2]) * 60 * 1000;
|
||||
SendMessage(player, "Time set between announce messages");
|
||||
break;
|
||||
case "list":
|
||||
SendMessage(player, "§bList of announce messages:§r");
|
||||
SendMessage(player, "§bFormat: [index] message§r");
|
||||
int i = 0;
|
||||
for (String message : PluginMain.AnnounceMessages)
|
||||
SendMessage(player, "[" + i++ + "] " + message);
|
||||
SendMessage(player,
|
||||
"§bCurrent wait time between announcements: "
|
||||
+ PluginMain.AnnounceTime / 60 / 1000
|
||||
+ " minute(s)§r");
|
||||
break;
|
||||
case "edit":
|
||||
if (commandblock == null) {
|
||||
SendMessage(
|
||||
player,
|
||||
"§cError: This command can only be used from a command block. Use /u announce remove.");
|
||||
break;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
commandblock
|
||||
.sendMessage("§cUsage: /u announce edit <index> <message>");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 3; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§');)
|
||||
PluginMain.AnnounceMessages.set(Integer.parseInt(args[2]),
|
||||
finalmessage1);
|
||||
commandblock.sendMessage("Announcement edited.");
|
||||
break;
|
||||
default:
|
||||
String message = "§cUsage: /u announce add|remove|settime|list|edit§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoSaveLoadPos(Player player, String[] args) { // 2015.08.09.
|
||||
// args[0] is "admin" - args[1] is "savepos|loadpos"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||
Player p = null;
|
||||
for (Player pl : PluginMain.GetPlayers()) {
|
||||
if (pl.getName().equals(args[2])) {
|
||||
p = pl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (p == null) {
|
||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||
String message = "§cPlayer is not online: " + args[2] + "§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (args[1].equalsIgnoreCase("savepos")) {
|
||||
mp.SavedLocation = p.getLocation();
|
||||
} else if (args[1].equalsIgnoreCase("loadpos")) {
|
||||
if (mp.SavedLocation != null)
|
||||
p.teleport(mp.SavedLocation);
|
||||
} else {
|
||||
String message = "§cUsage: /u admin savepos|loadpos <player>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
// SendMessage(player, "Player " + p.getName() +
|
||||
// " position saved/loaded.");s
|
||||
}
|
||||
|
||||
private static void DoUpdateDynmap(Player player, String[] args) {
|
||||
// args[0] is "admin" - args[1] is "updatedynmap"
|
||||
if (args.length == 2) {
|
||||
String message = "§cUsage: /u admin updatedynmap <password>§r";
|
||||
SendMessage(player, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,370 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
|
||||
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/
|
||||
private static PluginMain Instance;
|
||||
// Fired when plugin is first enabled
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
this.getCommand("u").setExecutor(new Commands());
|
||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||
Instance=this; //2015.08.08.
|
||||
LoadFiles(false); //2015.08.09.
|
||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||
Thread t=new Thread(r);
|
||||
t.start();
|
||||
}
|
||||
Boolean stop=false;
|
||||
// Fired when plugin is disabled
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
try
|
||||
{
|
||||
FileWriter fw;
|
||||
fw = new FileWriter("flairsaccepted.txt");
|
||||
fw.close();
|
||||
fw = new FileWriter("flairsignored.txt");
|
||||
fw.close();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.AcceptedFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
file=new File("flairsignored.txt");
|
||||
bw = new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.IgnoredFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
stop=true;
|
||||
}
|
||||
|
||||
public void ThreadMethod() //<-- 2015.07.16.
|
||||
{
|
||||
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();
|
||||
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();
|
||||
if(HasIGFlair(ign))
|
||||
continue;
|
||||
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";
|
||||
else
|
||||
flair = "non-presser";
|
||||
String flairclass;
|
||||
if(flairdata.length>2)
|
||||
flairclass = flairdata[2];
|
||||
else
|
||||
flairclass="unknown";
|
||||
SetFlair(ign, flair, flairclass, author);
|
||||
}
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Exception LastException; //2015.08.09.
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||
public Boolean HasIGFlair(String playername)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
return p.Flair!=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
String finalflair;
|
||||
p.FlairDecided=true;
|
||||
switch(flairclass)
|
||||
{
|
||||
case "press-1":
|
||||
finalflair="§c("+text+")§r";
|
||||
break;
|
||||
case "press-2":
|
||||
finalflair="§6("+text+")§r";
|
||||
break;
|
||||
case "press-3":
|
||||
finalflair="§e("+text+")§r";
|
||||
break;
|
||||
case "press-4":
|
||||
finalflair="§a("+text+")§r";
|
||||
break;
|
||||
case "press-5":
|
||||
finalflair="§9("+text+")§r";
|
||||
break;
|
||||
case "press-6":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "no-press":
|
||||
finalflair="§7(non-pr.)§r";
|
||||
break;
|
||||
case "cheater":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "cant-press": //2015.08.08.
|
||||
finalflair="§r(can't press)§r";
|
||||
break;
|
||||
case "undecided": //2015.08.09.
|
||||
p.FlairDecided=false;
|
||||
finalflair="";
|
||||
break;
|
||||
default:
|
||||
finalflair="";
|
||||
break;
|
||||
}
|
||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||
return;
|
||||
p.Flair=finalflair; //2015.08.08.
|
||||
p.UserName=username; //2015.08.08.
|
||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||
{
|
||||
if(player.getName().equals(playername))
|
||||
{
|
||||
//AppendPlayerDisplayFlair(player, username, finalflair);
|
||||
AppendPlayerDisplayFlair(p, player);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String GetFlair(Player player)
|
||||
{ //2015.07.16.
|
||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||
return flair==null ? "" : flair;
|
||||
}
|
||||
|
||||
//public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||
public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09.
|
||||
{
|
||||
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair)
|
||||
return;
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair)
|
||||
{
|
||||
AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20.
|
||||
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");
|
||||
}
|
||||
|
||||
private static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||
String[] colors = color.substring(1).split("§");
|
||||
String displayname=player.getName(); //2015.08.08.
|
||||
ArrayList<Integer> Positions=new ArrayList<>();
|
||||
for(int i=0; i<displayname.length(); i++) {
|
||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||
Positions.add(i);
|
||||
}
|
||||
}
|
||||
String finalname=""; //TODO
|
||||
if(Positions.size()>=colors.length)
|
||||
{
|
||||
int x=0;
|
||||
for(int i=0; i<Positions.size(); i++)
|
||||
{
|
||||
int pos=Positions.get(i);
|
||||
int nextpos;
|
||||
if(i!=Positions.size()-1)
|
||||
nextpos=Positions.get(i+1);
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Positions.clear();
|
||||
int unit=displayname.length()/colors.length;
|
||||
int x=0;
|
||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||
{
|
||||
int pos=i;
|
||||
int nextpos;
|
||||
if(i<displayname.length()-unit-unit)
|
||||
nextpos=i+unit;
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||
}
|
||||
|
||||
public static String GetColorForTown(String townname)
|
||||
{ //2015.07.20.
|
||||
if(TownColors.containsKey(townname))
|
||||
return TownColors.get(townname);
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String GetPlayerTown(Player player)
|
||||
{ //2015.07.20.
|
||||
try {
|
||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||
return town.getName();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public static Collection<? extends Player> GetPlayers()
|
||||
{
|
||||
return Instance.getServer().getOnlinePlayers();
|
||||
}
|
||||
|
||||
public static void LoadFiles(boolean reload)
|
||||
{
|
||||
if(reload)
|
||||
MaybeOfflinePlayer.AllPlayers.clear(); //2015.08.09.
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
//System.out.println("Name: " + name);
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("flairsignored.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while((line=br.readLine())!=null)
|
||||
{
|
||||
String[] s=line.split(" ");
|
||||
TownColors.put(s[0], s[1]);
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
//throw new IOException("Test"); //2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,368 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
|
||||
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/
|
||||
private static PluginMain Instance;
|
||||
// Fired when plugin is first enabled
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
this.getCommand("u").setExecutor(new Commands());
|
||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||
Instance=this; //2015.08.08.
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
//System.out.println("Name: " + name);
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("flairsignored.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String name=line.replace("\n", "");
|
||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
file=new File("autoflairconfig.txt");
|
||||
if(file.exists())
|
||||
{
|
||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while((line=br.readLine())!=null)
|
||||
{
|
||||
String[] s=line.split(" ");
|
||||
TownColors.put(s[0], s[1]);
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
//throw new IOException("Test"); //2015.08.09.
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||
Thread t=new Thread(r);
|
||||
t.start();
|
||||
}
|
||||
Boolean stop=false;
|
||||
// Fired when plugin is disabled
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
try
|
||||
{
|
||||
FileWriter fw;
|
||||
fw = new FileWriter("flairsaccepted.txt");
|
||||
fw.close();
|
||||
fw = new FileWriter("flairsignored.txt");
|
||||
fw.close();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
try {
|
||||
File file=new File("flairsaccepted.txt");
|
||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.AcceptedFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
file=new File("flairsignored.txt");
|
||||
bw = new BufferedWriter(new FileWriter(file, true));
|
||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||
{
|
||||
if(!player.IgnoredFlair)
|
||||
continue; //2015.08.08.
|
||||
bw.write(player.PlayerName+"\n");
|
||||
}
|
||||
bw.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
stop=true;
|
||||
}
|
||||
|
||||
public void ThreadMethod() //<-- 2015.07.16.
|
||||
{
|
||||
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();
|
||||
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();
|
||||
if(HasIGFlair(ign))
|
||||
continue;
|
||||
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";
|
||||
else
|
||||
flair = "non-presser";
|
||||
String flairclass;
|
||||
if(flairdata.length>2)
|
||||
flairclass = flairdata[2];
|
||||
else
|
||||
flairclass="unknown";
|
||||
SetFlair(ign, flair, flairclass, author);
|
||||
}
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Error!\n"+e);
|
||||
LastException=e; //2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Exception LastException; //2015.08.09.
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||
public Boolean HasIGFlair(String playername)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
return p.Flair!=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||
{
|
||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||
String finalflair;
|
||||
p.FlairDecided=true;
|
||||
switch(flairclass)
|
||||
{
|
||||
case "press-1":
|
||||
finalflair="§c("+text+")§r";
|
||||
break;
|
||||
case "press-2":
|
||||
finalflair="§6("+text+")§r";
|
||||
break;
|
||||
case "press-3":
|
||||
finalflair="§e("+text+")§r";
|
||||
break;
|
||||
case "press-4":
|
||||
finalflair="§a("+text+")§r";
|
||||
break;
|
||||
case "press-5":
|
||||
finalflair="§9("+text+")§r";
|
||||
break;
|
||||
case "press-6":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "no-press":
|
||||
finalflair="§7(non-pr.)§r";
|
||||
break;
|
||||
case "cheater":
|
||||
finalflair="§5("+text+")§r";
|
||||
break;
|
||||
case "cant-press": //2015.08.08.
|
||||
finalflair="§r(can't press)§r";
|
||||
break;
|
||||
case "undecided": //2015.08.09.
|
||||
p.FlairDecided=false;
|
||||
finalflair="";
|
||||
break;
|
||||
default:
|
||||
finalflair="";
|
||||
break;
|
||||
}
|
||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||
return;
|
||||
p.Flair=finalflair; //2015.08.08.
|
||||
p.UserName=username; //2015.08.08.
|
||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||
{
|
||||
if(player.getName().equals(playername))
|
||||
{
|
||||
//AppendPlayerDisplayFlair(player, username, finalflair);
|
||||
AppendPlayerDisplayFlair(p, player);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String GetFlair(Player player)
|
||||
{ //2015.07.16.
|
||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||
return flair==null ? "" : flair;
|
||||
}
|
||||
|
||||
//public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||
public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09.
|
||||
{
|
||||
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair)
|
||||
return;
|
||||
if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair)
|
||||
{
|
||||
AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20.
|
||||
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");
|
||||
}
|
||||
|
||||
private static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||
String[] colors = color.substring(1).split("§");
|
||||
String displayname=player.getName(); //2015.08.08.
|
||||
ArrayList<Integer> Positions=new ArrayList<>();
|
||||
for(int i=0; i<displayname.length(); i++) {
|
||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||
Positions.add(i);
|
||||
}
|
||||
}
|
||||
String finalname=""; //TODO
|
||||
if(Positions.size()>=colors.length)
|
||||
{
|
||||
int x=0;
|
||||
for(int i=0; i<Positions.size(); i++)
|
||||
{
|
||||
int pos=Positions.get(i);
|
||||
int nextpos;
|
||||
if(i!=Positions.size()-1)
|
||||
nextpos=Positions.get(i+1);
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Positions.clear();
|
||||
int unit=displayname.length()/colors.length;
|
||||
int x=0;
|
||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||
{
|
||||
int pos=i;
|
||||
int nextpos;
|
||||
if(i<displayname.length()-unit-unit)
|
||||
nextpos=i+unit;
|
||||
else
|
||||
nextpos=displayname.length();
|
||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||
finalname+=substr;
|
||||
}
|
||||
}
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||
}
|
||||
|
||||
public static String GetColorForTown(String townname)
|
||||
{ //2015.07.20.
|
||||
if(TownColors.containsKey(townname))
|
||||
return TownColors.get(townname);
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String GetPlayerTown(Player player)
|
||||
{ //2015.07.20.
|
||||
try {
|
||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||
return town.getName();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||
{ //2015.07.20.
|
||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||
}
|
||||
|
||||
public static Collection<? extends Player> GetPlayers()
|
||||
{
|
||||
return Instance.getServer().getOnlinePlayers();
|
||||
}
|
||||
|
||||
public static void LoadFiles(boolean reload)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -1,305 +0,0 @@
|
|||
package tk.sznp.thebuttonautoflair;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.String;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
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/
|
||||
public static PluginMain Instance;
|
||||
public static ConsoleCommandSender Console; // 2015.08.12.
|
||||
|
||||
// Fired when plugin is first enabled
|
||||
@Override
|
||||
public void onEnable() {
|
||||
System.out.println("The Button Minecraft server plugin");
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(),
|
||||
this);
|
||||
Commands comm = new Commands();
|
||||
this.getCommand("u").setExecutor(comm);
|
||||
this.getCommand("u").setUsage(
|
||||
this.getCommand("u").getUsage().replace('&', '§'));
|
||||
this.getCommand("nrp").setExecutor(comm);
|
||||
this.getCommand("nrp").setUsage(
|
||||
this.getCommand("nrp").getUsage().replace('&', '§'));
|
||||
this.getCommand("ooc").setExecutor(comm);
|
||||
this.getCommand("ooc").setUsage(
|
||||
this.getCommand("ooc").getUsage().replace('&', '§'));
|
||||
this.getCommand("skype").setExecutor(comm);
|
||||
Instance = this; // 2015.08.08.
|
||||
Console = this.getServer().getConsoleSender(); // 2015.08.12.
|
||||
LoadFiles(false); // 2015.08.09.
|
||||
Runnable r = new Runnable() {
|
||||
public void run() {
|
||||
ThreadMethod();
|
||||
}
|
||||
};
|
||||
Thread t = new Thread(r);
|
||||
t.start();
|
||||
r = new Runnable() {
|
||||
public void run() {
|
||||
AnnouncerThread.Run();
|
||||
}
|
||||
};
|
||||
t = new Thread(r);
|
||||
t.start();
|
||||
}
|
||||
|
||||
public Boolean stop = false;
|
||||
|
||||
// Fired when plugin is disabled
|
||||
@Override
|
||||
public void onDisable() {
|
||||
SaveFiles(); // 2015.08.09.
|
||||
stop = true;
|
||||
}
|
||||
|
||||
public void ThreadMethod() // <-- 2015.07.16.
|
||||
{
|
||||
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();
|
||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(ign);
|
||||
if (mp == null)
|
||||
continue;
|
||||
if (HasIGFlair(mp.UUID))
|
||||
continue;
|
||||
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);
|
||||
} catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// System.out.println("Error!\n" + e);
|
||||
LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Exception LastException; // 2015.08.09.
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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,
|
||||
String username) {
|
||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AddPlayerIfNeeded(uuid); // 2015.08.08.
|
||||
String finalflair;
|
||||
p.FlairDecided = true;
|
||||
p.FlairRecognised = true;
|
||||
switch (flairclass) {
|
||||
case "press-1":
|
||||
finalflair = "§c(" + text + ")§r";
|
||||
break;
|
||||
case "press-2":
|
||||
finalflair = "§6(" + text + ")§r";
|
||||
break;
|
||||
case "press-3":
|
||||
finalflair = "§e(" + text + ")§r";
|
||||
break;
|
||||
case "press-4":
|
||||
finalflair = "§a(" + text + ")§r";
|
||||
break;
|
||||
case "press-5":
|
||||
finalflair = "§9(" + text + ")§r";
|
||||
break;
|
||||
case "press-6":
|
||||
finalflair = "§5(" + text + ")§r";
|
||||
break;
|
||||
case "no-press":
|
||||
finalflair = "§7(--s)§r";
|
||||
break;
|
||||
case "cheater":
|
||||
finalflair = "§5(" + text + ")§r";
|
||||
break;
|
||||
case "cant-press": // 2015.08.08.
|
||||
finalflair = "§r(??s)§r";
|
||||
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;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
p.Flair = finalflair; // 2015.08.08.
|
||||
p.CommentedOnReddit = true; // 2015.08.10.
|
||||
p.UserName = username; // 2015.08.08.
|
||||
System.out.println("Added flair for " + p.PlayerName);
|
||||
AppendPlayerDisplayFlair(p, Bukkit.getPlayer(uuid));
|
||||
}
|
||||
|
||||
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 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 Collection<? extends Player> GetPlayers() {
|
||||
return Instance.getServer().getOnlinePlayers();
|
||||
}
|
||||
|
||||
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.
|
||||
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.
|
||||
try {
|
||||
File file = new File("announcemessages.txt");
|
||||
if (file.exists())
|
||||
file.delete();
|
||||
file = new File("flairsaccepted.txt");
|
||||
if (file.exists())
|
||||
file.delete();
|
||||
file = new File("flairsignored.txt");
|
||||
if (file.exists())
|
||||
file.delete();
|
||||
file = new File("thebuttonmc.yml");
|
||||
if (file.exists()) {
|
||||
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"));
|
||||
Commands.Quiz.addAll(yc.getStringList("quiz"));
|
||||
}
|
||||
System.out.println("The Button Minecraft plugin loaded files!");
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
LastException = e; // 2015.08.09.
|
||||
} catch (InvalidConfigurationException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
|
||||
public static void SaveFiles() // <-- 2015.08.09.
|
||||
{
|
||||
System.out.println("Saving files for The Button Minecraft plugin..."); // 2015.08.09.
|
||||
try {
|
||||
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);
|
||||
yc.save(file);
|
||||
System.out.println("The Button Minecraft plugin saved files!");
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error!\n" + e);
|
||||
LastException = e; // 2015.08.09.
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue