Fixes
- Fixed custom flair loading - Added colored name handling for nicknames - It will now remove nicknames on disconnect (so if the nickname gets changed, a relog will make the changes in name mentioning)
This commit is contained in:
parent
fc2ff7db1e
commit
36d98719a7
14 changed files with 797 additions and 735 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,5 +1,5 @@
|
||||||
INDEX VERSION 1.126+D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin\.metadata\.plugins\org.eclipse.jdt.core
|
INDEX VERSION 1.126+D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin\.metadata\.plugins\org.eclipse.jdt.core
|
||||||
3045053200.index
|
3656756579.index
|
||||||
3089967703.index
|
3089967703.index
|
||||||
2674037006.index
|
2674037006.index
|
||||||
323251068.index
|
323251068.index
|
||||||
|
@ -23,4 +23,4 @@ INDEX VERSION 1.126+D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spi
|
||||||
994834796.index
|
994834796.index
|
||||||
3604769962.index
|
3604769962.index
|
||||||
1508644233.index
|
1508644233.index
|
||||||
3656756579.index
|
3045053200.index
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -14,259 +14,286 @@ import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
public class Commands implements CommandExecutor {
|
public class Commands implements CommandExecutor {
|
||||||
// This method is called, when somebody uses our command
|
// This method is called, when somebody uses our command
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command cmd, String label,
|
||||||
if (sender instanceof Player) {
|
String[] args) {
|
||||||
Player player = (Player) sender;
|
if (sender instanceof Player) {
|
||||||
if (args.length < 1)
|
Player player = (Player) sender;
|
||||||
return false;
|
if (args.length < 1)
|
||||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
return false;
|
||||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(player
|
||||||
if (!p.CommentedOnReddit && !args[0].toLowerCase().equals("admin")) {
|
.getName()); // 2015.08.08.
|
||||||
player.sendMessage("§cError: You need to write your username to the reddit thread at /r/TheButtonMinecraft§r");
|
// if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
return true;
|
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");
|
||||||
if (!p.FlairRecognised && !args[0].toLowerCase().equals("admin")) { //2015.08.10.
|
return true;
|
||||||
player.sendMessage("Sorry, but your flair isn't recorded. Please ask a mod to set it for you.");
|
}
|
||||||
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.");
|
||||||
switch (args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
return true;
|
||||||
{
|
}
|
||||||
case "accept": {
|
if (!p.FlairDecided && !args[0].toLowerCase().equals("admin")) { // 2015.08.19.
|
||||||
if (p.IgnoredFlair)
|
player.sendMessage("Please select between /u nonpresser and /u cantpress");
|
||||||
p.IgnoredFlair = false; //2015.08.08.
|
return true;
|
||||||
if (!p.AcceptedFlair) {
|
}
|
||||||
String flair = p.Flair; //2015.08.08.
|
switch (args[0].toLowerCase()) // toLowerCase: 2015.08.09.
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
{
|
||||||
p.AcceptedFlair = true; //2015.08.08.
|
case "accept": {
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
if (p.IgnoredFlair)
|
||||||
player.sendMessage("§bYour flair has been set:§r " + flair);
|
p.IgnoredFlair = false; // 2015.08.08.
|
||||||
} else
|
if (!p.AcceptedFlair) {
|
||||||
player.sendMessage("§cYou already have this user's flair.§r");
|
String flair = p.Flair; // 2015.08.08.
|
||||||
break;
|
// PluginMain.AppendPlayerDisplayFlairFinal(player, flair);
|
||||||
}
|
// //2015.07.20.
|
||||||
case "ignore": {
|
p.AcceptedFlair = true; // 2015.08.08.
|
||||||
if (p.AcceptedFlair)
|
PluginMain.AppendPlayerDisplayFlair(p, player);
|
||||||
p.AcceptedFlair = false; //2015.08.08.
|
player.sendMessage("§bYour flair has been set:§r " + flair);
|
||||||
if (!p.IgnoredFlair) {
|
} else
|
||||||
p.IgnoredFlair = true;
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
//String flair=p.Flair; //2015.08.08.
|
break;
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
}
|
||||||
player.sendMessage("§bYou have ignored this request. You can still use /u accept though.§r");
|
case "ignore": {
|
||||||
} else
|
if (p.AcceptedFlair)
|
||||||
player.sendMessage("§cYou already ignored this request.§r");
|
p.AcceptedFlair = false; // 2015.08.08.
|
||||||
break;
|
if (!p.IgnoredFlair) {
|
||||||
}
|
p.IgnoredFlair = true;
|
||||||
/*case "reload": //2015.07.20.
|
// String flair=p.Flair; //2015.08.08.
|
||||||
DoReload(player);
|
// PluginMain.RemovePlayerDisplayFlairFinal(player, flair);
|
||||||
break;*/
|
// //2015.07.20.
|
||||||
case "admin": //2015.08.09.
|
player.sendMessage("§bYou have ignored this request. You can still use /u accept though.§r");
|
||||||
DoAdmin(player, args);
|
} else
|
||||||
break;
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
case "nonpresser": //2015.08.09.
|
break;
|
||||||
if (!p.AcceptedFlair) {
|
}
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
/*
|
||||||
break;
|
* case "reload": //2015.07.20. DoReload(player); break;
|
||||||
}
|
*/
|
||||||
if (p.FlairDecided) {
|
case "admin": // 2015.08.09.
|
||||||
player.sendMessage("§cYou have already set the flair type.§r");
|
DoAdmin(player, args);
|
||||||
break;
|
break;
|
||||||
}
|
case "nonpresser": // 2015.08.09.
|
||||||
SetPlayerFlair(player, p, "§7(--s)§r");
|
if (!p.AcceptedFlair) {
|
||||||
break;
|
player.sendMessage("§cYou need to accept the flair first.§r");
|
||||||
case "cantpress": //2015.08.09.
|
break;
|
||||||
if (!p.AcceptedFlair) {
|
}
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
if (p.FlairDecided) {
|
||||||
break;
|
player.sendMessage("§cYou have already set the flair type.§r");
|
||||||
}
|
break;
|
||||||
if (p.FlairDecided) {
|
}
|
||||||
player.sendMessage("§cYou have already set the flair type or your flair type is known.§r");
|
SetPlayerFlair(player, p, "§7(--s)§r");
|
||||||
break;
|
break;
|
||||||
}
|
case "cantpress": // 2015.08.09.
|
||||||
SetPlayerFlair(player, p, "§r(??s)§r");
|
if (!p.AcceptedFlair) {
|
||||||
break;
|
player.sendMessage("§cYou need to accept the flair first.§r");
|
||||||
case "opme": //2015.08.10.
|
break;
|
||||||
player.sendMessage("It would be nice, isn't it?"); //Sometimes I'm bored too
|
}
|
||||||
break;
|
if (p.FlairDecided) {
|
||||||
default:
|
player.sendMessage("§cYou have already set the flair type or your flair type is known.§r");
|
||||||
return false;
|
break;
|
||||||
}
|
}
|
||||||
return true;
|
SetPlayerFlair(player, p, "§r(??s)§r");
|
||||||
}
|
break;
|
||||||
/*if(args[0].toLowerCase()=="reload")
|
case "opme": // 2015.08.10.
|
||||||
DoReload(null); //2015.07.20.*/
|
player.sendMessage("It would be nice, isn't it?"); // Sometimes
|
||||||
else if (args.length > 0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
// I'm bored
|
||||||
{
|
// too
|
||||||
DoAdmin(null, args); //2015.08.09.
|
break;
|
||||||
return true; //2015.08.09.
|
default:
|
||||||
}
|
return false;
|
||||||
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.
|
private static void DoReload(Player player) { // 2015.07.20.
|
||||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
// if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
//{
|
// {
|
||||||
try {
|
try {
|
||||||
PluginMain.Console.sendMessage("§6-- Reloading The Button Minecraft plugin...§r");
|
PluginMain.Console
|
||||||
PluginMain.LoadFiles(true); //2015.08.09.
|
.sendMessage("§6-- Reloading The Button Minecraft plugin...§r");
|
||||||
for (Player p : PluginMain.GetPlayers()) {
|
PluginMain.LoadFiles(true); // 2015.08.09.
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
for (Player p : PluginMain.GetPlayers()) {
|
||||||
//if(mp.Flair!=null)
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p
|
||||||
if (mp.CommentedOnReddit) {
|
.getName());
|
||||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
// if(mp.Flair!=null)
|
||||||
}
|
if (mp.CommentedOnReddit) {
|
||||||
String msg = "§bNote: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09.
|
PluginMain.AppendPlayerDisplayFlair(mp, p); // 2015.08.09.
|
||||||
p.sendMessage(msg); //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.
|
||||||
PluginMain.Console.sendMessage("§6-- Reloading done!§r");
|
p.sendMessage(msg); // 2015.08.09.
|
||||||
} catch (Exception e) {
|
}
|
||||||
System.out.println("Error!\n" + e);
|
PluginMain.Console.sendMessage("§6-- Reloading done!§r");
|
||||||
if (player != null)
|
} catch (Exception e) {
|
||||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
System.out.println("Error!\n" + e);
|
||||||
PluginMain.LastException = e; //2015.08.09.
|
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");
|
// }
|
||||||
}
|
// else
|
||||||
|
// player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
|
||||||
private static Player ReloadPlayer; //2015.08.09.
|
private static Player ReloadPlayer; // 2015.08.09.
|
||||||
|
|
||||||
private static void DoAdmin(Player player, String[] args) { //2015.08.09.
|
private static void DoAdmin(Player player, String[] args) { // 2015.08.09.
|
||||||
if (player == null || player.isOp() || player.getName().equals("NorbiPeti")) {
|
if (player == null || player.isOp()
|
||||||
//System.out.println("Args length: " + args.length);
|
|| player.getName().equals("NorbiPeti")) {
|
||||||
if (args.length == 1) {
|
// System.out.println("Args length: " + args.length);
|
||||||
String message = "§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
if (args.length == 1) {
|
||||||
SendMessage(player, message);
|
String message = "§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
||||||
return;
|
SendMessage(player, message);
|
||||||
}
|
return;
|
||||||
//args[0] is "admin"
|
}
|
||||||
switch (args[1].toLowerCase()) {
|
// args[0] is "admin"
|
||||||
case "reload":
|
switch (args[1].toLowerCase()) {
|
||||||
ReloadPlayer = player; //2015.08.09.
|
case "reload":
|
||||||
SendMessage(player, "§bMake sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
ReloadPlayer = player; // 2015.08.09.
|
||||||
break;
|
SendMessage(
|
||||||
case "playerinfo":
|
player,
|
||||||
DoPlayerInfo(player, args);
|
"§bMake sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
||||||
break;
|
break;
|
||||||
case "getlasterror":
|
case "playerinfo":
|
||||||
DoGetLastError(player, args);
|
DoPlayerInfo(player, args);
|
||||||
break; //<-- 2015.08.10.
|
break;
|
||||||
case "confirm":
|
case "getlasterror":
|
||||||
if (ReloadPlayer == player)
|
DoGetLastError(player, args);
|
||||||
DoReload(player); //2015.08.09.
|
break; // <-- 2015.08.10.
|
||||||
else
|
case "confirm":
|
||||||
SendMessage(player, "§cYou need to do /u admin reload first.§r");
|
if (ReloadPlayer == player)
|
||||||
break;
|
DoReload(player); // 2015.08.09.
|
||||||
case "save":
|
else
|
||||||
PluginMain.SaveFiles(); //2015.08.09.
|
SendMessage(player,
|
||||||
SendMessage(player, "§bSaved files. Now you can edit them and reload if you want.§r");
|
"§cYou need to do /u admin reload first.§r");
|
||||||
break;
|
break;
|
||||||
case "setflair":
|
case "save":
|
||||||
DoSetFlair(player, args);
|
PluginMain.SaveFiles(); // 2015.08.09.
|
||||||
break;
|
SendMessage(player,
|
||||||
case "updateplugin": //2015.08.10.
|
"§bSaved files. Now you can edit them and reload if you want.§r");
|
||||||
DoUpdatePlugin(player);
|
break;
|
||||||
break;
|
case "setflair":
|
||||||
default:
|
DoSetFlair(player, args);
|
||||||
String message = "§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
break;
|
||||||
SendMessage(player, message);
|
case "updateplugin": // 2015.08.10.
|
||||||
return;
|
DoUpdatePlugin(player);
|
||||||
}
|
break;
|
||||||
} else
|
default:
|
||||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
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.
|
private static void DoPlayerInfo(Player player, String[] args) { // 2015.08.09.
|
||||||
//args[0] is "admin" - args[1] is "playerinfo"
|
// args[0] is "admin" - args[1] is "playerinfo"
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
String message = "§cUsage: /u admin playerinfo <player>§r";
|
String message = "§cUsage: /u admin playerinfo <player>§r";
|
||||||
SendMessage(player, message);
|
SendMessage(player, message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
if (!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) {
|
||||||
String message = "§cPlayer not found: " + args[2] + "§r";
|
String message = "§cPlayer not found: " + args[2] + "§r";
|
||||||
SendMessage(player, message);
|
SendMessage(player, message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||||
SendMessage(player, "Player name: " + p.PlayerName);
|
SendMessage(player, "Player name: " + p.PlayerName);
|
||||||
SendMessage(player, "User flair: " + p.Flair);
|
SendMessage(player, "User flair: " + p.Flair);
|
||||||
SendMessage(player, "Username: " + p.UserName);
|
SendMessage(player, "Username: " + p.UserName);
|
||||||
SendMessage(player, "Flair accepted: " + p.AcceptedFlair);
|
SendMessage(player, "Flair accepted: " + p.AcceptedFlair);
|
||||||
SendMessage(player, "Flair ignored: " + p.IgnoredFlair);
|
SendMessage(player, "Flair ignored: " + p.IgnoredFlair);
|
||||||
SendMessage(player, "Flair decided: " + p.FlairDecided);
|
SendMessage(player, "Flair decided: " + p.FlairDecided);
|
||||||
SendMessage(player, "Flair recognised: " + p.FlairRecognised);
|
SendMessage(player, "Flair recognised: " + p.FlairRecognised);
|
||||||
SendMessage(player, "Commented on Reddit: " + p.CommentedOnReddit);
|
SendMessage(player, "Commented on Reddit: " + p.CommentedOnReddit);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SendMessage(Player player, String message) { //2015.08.09.
|
private static void SendMessage(Player player, String message) { // 2015.08.09.
|
||||||
if (player == null)
|
if (player == null)
|
||||||
//System.out.println(message);
|
// System.out.println(message);
|
||||||
PluginMain.Console.sendMessage(message); //2015.08.12.
|
PluginMain.Console.sendMessage(message); // 2015.08.12.
|
||||||
else
|
else
|
||||||
player.sendMessage(message);
|
player.sendMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void DoGetLastError(Player player, String[] args) { //2015.08.09.
|
private static void DoGetLastError(Player player, String[] args) { // 2015.08.09.
|
||||||
//args[0] is "admin" - args[1] is "getlasterror"
|
// args[0] is "admin" - args[1] is "getlasterror"
|
||||||
if (PluginMain.LastException != null) {
|
if (PluginMain.LastException != null) {
|
||||||
SendMessage(player, "Last error:");
|
SendMessage(player, "Last error:");
|
||||||
SendMessage(player, PluginMain.LastException.toString());
|
SendMessage(player, PluginMain.LastException.toString());
|
||||||
PluginMain.LastException = null;
|
PluginMain.LastException = null;
|
||||||
} else
|
} else
|
||||||
SendMessage(player, "There were no exceptions.");
|
SendMessage(player, "There were no exceptions.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair) { //2015.08.09.
|
private static void SetPlayerFlair(Player player,
|
||||||
flair = flair.replace('&', '§');
|
MaybeOfflinePlayer targetplayer, String flair) { // 2015.08.09.
|
||||||
targetplayer.Flair = flair;
|
flair = flair.replace('&', '§');
|
||||||
targetplayer.CommentedOnReddit = true; //Or at least has a flair in some way
|
targetplayer.Flair = flair;
|
||||||
if (!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName)) {
|
targetplayer.CommentedOnReddit = true; // Or at least has a flair in
|
||||||
SendMessage(player, "§cError removing previous custom flair!§r");
|
// some way
|
||||||
return;
|
if (!PluginMain.RemoveLineFromFile("customflairs.txt",
|
||||||
}
|
targetplayer.PlayerName)) {
|
||||||
File file = new File("customflairs.txt");
|
SendMessage(player, "§cError removing previous custom flair!§r");
|
||||||
try {
|
return;
|
||||||
BufferedWriter bw;
|
}
|
||||||
bw = new BufferedWriter(new FileWriter(file, true));
|
File file = new File("customflairs.txt");
|
||||||
bw.write(targetplayer.PlayerName + " " + targetplayer.Flair + "\n");
|
try {
|
||||||
bw.close();
|
BufferedWriter bw;
|
||||||
} catch (IOException e) {
|
bw = new BufferedWriter(new FileWriter(file, true));
|
||||||
System.out.println("Error!\n" + e);
|
bw.write(targetplayer.PlayerName + " " + targetplayer.Flair + "\n");
|
||||||
PluginMain.LastException = e; //2015.08.09.
|
bw.close();
|
||||||
}
|
} catch (IOException e) {
|
||||||
SendMessage(player, "§bThe flair has been set. Player: " + targetplayer.PlayerName + " Flair: " + flair + "§r");
|
System.out.println("Error!\n" + e);
|
||||||
}
|
PluginMain.LastException = e; // 2015.08.09.
|
||||||
|
}
|
||||||
|
SendMessage(player, "§bThe flair has been set. Player: "
|
||||||
|
+ targetplayer.PlayerName + " Flair: " + flair + "§r");
|
||||||
|
}
|
||||||
|
|
||||||
private static void DoSetFlair(Player player, String[] args) {
|
private static void DoSetFlair(Player player, String[] args) {
|
||||||
//args[0] is "admin" - args[1] is "setflair"
|
// args[0] is "admin" - args[1] is "setflair"
|
||||||
if (args.length < 4) {
|
if (args.length < 4) {
|
||||||
SendMessage(player, "§cUsage: /u admin setflair <playername> <flair>");
|
SendMessage(player,
|
||||||
return;
|
"§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");
|
if (args[3].charAt(0) != '&') {
|
||||||
return;
|
SendMessage(player,
|
||||||
}
|
"§cYou need to start the flair with a color code: &6(19s)&r");
|
||||||
SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]);
|
return;
|
||||||
}
|
}
|
||||||
|
SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]),
|
||||||
|
args[3]);
|
||||||
|
}
|
||||||
|
|
||||||
private static void DoUpdatePlugin(Player player) { //2015.08.10.
|
private static void DoUpdatePlugin(Player player) { // 2015.08.10.
|
||||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
SendMessage(player, "Updating Auto-Flair plugin...");
|
||||||
System.out.println("Forced updating of Auto-Flair plugin.");
|
System.out.println("Forced updating of Auto-Flair plugin.");
|
||||||
URL url;
|
URL url;
|
||||||
try {
|
try {
|
||||||
url = new URL("https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
url = new URL(
|
||||||
FileUtils.copyURLToFile(url, new File("plugins/TheButtonAutoFlair.jar"));
|
"https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
||||||
SendMessage(player, "Updating done!");
|
FileUtils.copyURLToFile(url, new File(
|
||||||
} catch (MalformedURLException e) {
|
"plugins/TheButtonAutoFlair.jar"));
|
||||||
System.out.println("Error!\n" + e);
|
SendMessage(player, "Updating done!");
|
||||||
PluginMain.LastException = e; //2015.08.09.
|
} catch (MalformedURLException e) {
|
||||||
} catch (IOException e) {
|
System.out.println("Error!\n" + e);
|
||||||
System.out.println("Error!\n" + e);
|
PluginMain.LastException = e; // 2015.08.09.
|
||||||
PluginMain.LastException = e; //2015.08.09.
|
} catch (IOException e) {
|
||||||
}
|
System.out.println("Error!\n" + e);
|
||||||
}
|
PluginMain.LastException = e; // 2015.08.09.
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,6 @@ package tk.sznp.thebuttonautoflair;
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
import de.inventivegames.TellRawAutoMessage.Reflection;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.command.TabCompleter;
|
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -19,117 +16,150 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener { //2015.07.16.
|
public class PlayerListener implements Listener { // 2015.07.16.
|
||||||
public static HashMap<String, UUID> nicknames = new HashMap<>();
|
public static HashMap<String, UUID> nicknames = new HashMap<>();
|
||||||
@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 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);
|
||||||
|
}
|
||||||
|
|
||||||
/* NICKNAME LOGIC */
|
/* NICKNAME LOGIC */
|
||||||
|
|
||||||
UUID id = p.getUniqueId();
|
UUID id = p.getUniqueId();
|
||||||
|
|
||||||
File f =new File("plugins/essentials/userdata/"+id+".yml");
|
File f = new File("plugins/essentials/userdata/" + id + ".yml");
|
||||||
YamlConfiguration yc = new YamlConfiguration();
|
YamlConfiguration yc = new YamlConfiguration();
|
||||||
try {
|
try {
|
||||||
yc.load(f);
|
yc.load(f);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (InvalidConfigurationException e) {
|
} catch (InvalidConfigurationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
String nickname = yc.getString("nickname");
|
String nickname = yc.getString("nickname");
|
||||||
nicknames.put(nickname, id);
|
nicknames.put(nickname, id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
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 String NotificationSound; // 2015.08.14.
|
||||||
public static float NotificationPitch; //2015.08.14.
|
public static float NotificationPitch; // 2015.08.14.
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event
|
||||||
String flair = player.Flair; //2015.08.08.
|
.getPlayer().getName());
|
||||||
if (player.IgnoredFlair)
|
String flair = player.Flair; // 2015.08.08.
|
||||||
flair = "";
|
if (player.IgnoredFlair)
|
||||||
String message = event.getMessage(); //2015.08.08.
|
flair = "";
|
||||||
for (Player p : PluginMain.GetPlayers()) { //2015.08.12.
|
String message = event.getMessage(); // 2015.08.08.
|
||||||
String color = ""; //2015.08.17.
|
for (Player p : PluginMain.GetPlayers()) { // 2015.08.12.
|
||||||
if (message.contains(p.getName())) {
|
String color = ""; // 2015.08.17.
|
||||||
if (NotificationSound == null)
|
if (message.contains(p.getName())) {
|
||||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); //2015.08.12.
|
if (NotificationSound == null)
|
||||||
else
|
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f, 0.5f); // 2015.08.12.
|
||||||
p.playSound(p.getLocation(), NotificationSound, 1.0f, NotificationPitch); //2015.08.14.
|
else
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.17.
|
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
||||||
color = mp.Flair.substring(0, 2);
|
NotificationPitch); // 2015.08.14.
|
||||||
}
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p
|
||||||
|
.getName()); // 2015.08.17.
|
||||||
|
if (mp.Flair.length() > 1)
|
||||||
|
color = mp.Flair.substring(0, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
message = message.replaceAll(p.getName(), color + p.getName()
|
||||||
|
+ "§r");
|
||||||
|
}
|
||||||
|
for (String n : nicknames.keySet()) {
|
||||||
|
Player p = null;
|
||||||
|
String nwithoutformatting = n;
|
||||||
|
int index;
|
||||||
|
// System.out.println("n: " + n);
|
||||||
|
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||||
|
// if ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||||
|
//{
|
||||||
|
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||||
|
+ nwithoutformatting.charAt(index + 1), "");
|
||||||
|
// System.out.println("Index: "+index+" "+"CharAt(index+1): "+nwithoutformatting.charAt(index+1));
|
||||||
|
//}
|
||||||
|
System.out.println("nwithoutformatting: " + nwithoutformatting);
|
||||||
|
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,
|
||||||
|
NotificationPitch); // 2015.08.14.
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); // 2015.08.17.
|
||||||
|
}
|
||||||
|
if (p != null) {
|
||||||
|
message = message.replaceAll(nwithoutformatting, n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
message = message.replaceAll(p.getName(), color + p.getName() + "§r");
|
event.setFormat(event.getFormat().substring(0,
|
||||||
}
|
event.getFormat().indexOf(">"))
|
||||||
for (String n : nicknames.keySet())
|
+ flair + "> " + message); // 2015.08.08.
|
||||||
{
|
}
|
||||||
String color = ""; //2015.08.17.
|
|
||||||
Player p = null;
|
|
||||||
if (message.contains(n)) {
|
|
||||||
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, NotificationPitch); //2015.08.14.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.17.
|
|
||||||
color = mp.Flair.substring(0, 2);
|
|
||||||
}
|
|
||||||
if (p != null)
|
|
||||||
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");
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
public static void sendRawMessage(Player player, String message) {
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
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.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void sendRawMessage(Player player, String message) {
|
@EventHandler
|
||||||
try {
|
public void onTabComplete(PlayerChatTabCompleteEvent e) {
|
||||||
Object handle = Reflection.getHandle(player);
|
String name = e.getLastToken();
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
for (String nickname : nicknames.keySet()) {
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
String nwithoutformatting = nickname;
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
int index;
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||||
} catch (Exception e) {
|
nwithoutformatting = nwithoutformatting.replaceAll("§"
|
||||||
e.printStackTrace();
|
+ nwithoutformatting.charAt(index + 1), "");
|
||||||
PluginMain.LastException = e; //2015.08.09.
|
if (nwithoutformatting.startsWith(name))
|
||||||
}
|
e.getTabCompletions().add(nwithoutformatting);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
}
|
||||||
public void onTabComplete(PlayerChatTabCompleteEvent e)
|
|
||||||
{
|
|
||||||
String name = e.getLastToken();
|
|
||||||
for(String nickname : nicknames.keySet())
|
|
||||||
{
|
|
||||||
if(nickname.startsWith(name))
|
|
||||||
e.getTabCompletions().add(nickname);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,413 +18,418 @@ import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class PluginMain extends JavaPlugin { //Translated to Java: 2015.07.15.
|
public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
||||||
//A user, which flair isn't obtainable:
|
// A user, which flair isn't obtainable:
|
||||||
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
// https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
||||||
private static PluginMain Instance;
|
private static PluginMain Instance;
|
||||||
public static ConsoleCommandSender Console; //2015.08.12.
|
public static ConsoleCommandSender Console; // 2015.08.12.
|
||||||
|
|
||||||
// Fired when plugin is first enabled
|
// Fired when plugin is first enabled
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
System.out.println("The Button Minecraft server plugin by NorbiPeti");
|
System.out.println("The Button Minecraft server plugin by NorbiPeti");
|
||||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
getServer().getPluginManager().registerEvents(new PlayerListener(),
|
||||||
this.getCommand("u").setExecutor(new Commands());
|
this);
|
||||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
this.getCommand("u").setExecutor(new Commands());
|
||||||
Instance = this; //2015.08.08.
|
this.getCommand("u").setUsage(
|
||||||
Console = this.getServer().getConsoleSender(); //2015.08.12.
|
this.getCommand("u").getUsage().replace('&', '§'));
|
||||||
LoadFiles(false); //2015.08.09.
|
Instance = this; // 2015.08.08.
|
||||||
Runnable r = new Runnable() {
|
Console = this.getServer().getConsoleSender(); // 2015.08.12.
|
||||||
public void run() {
|
LoadFiles(false); // 2015.08.09.
|
||||||
ThreadMethod();
|
Runnable r = new Runnable() {
|
||||||
}
|
public void run() {
|
||||||
};
|
ThreadMethod();
|
||||||
Thread t = new Thread(r);
|
}
|
||||||
t.start();
|
};
|
||||||
}
|
Thread t = new Thread(r);
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
|
||||||
Boolean stop = false;
|
Boolean stop = false;
|
||||||
|
|
||||||
// Fired when plugin is disabled
|
// Fired when plugin is disabled
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
SaveFiles(); //2015.08.09.
|
SaveFiles(); // 2015.08.09.
|
||||||
stop = true;
|
stop = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ThreadMethod() //<-- 2015.07.16.
|
public void ThreadMethod() // <-- 2015.07.16.
|
||||||
{
|
{
|
||||||
while (!stop) {
|
while (!stop) {
|
||||||
try {
|
try {
|
||||||
String body = DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
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");
|
JSONArray json = new JSONArray(body).getJSONObject(1)
|
||||||
for (Object obj : json) {
|
.getJSONObject("data").getJSONArray("children");
|
||||||
JSONObject item = (JSONObject) obj;
|
for (Object obj : json) {
|
||||||
String author = item.getJSONObject("data").getString("author");
|
JSONObject item = (JSONObject) obj;
|
||||||
String ign = item.getJSONObject("data").getString("body");
|
String author = item.getJSONObject("data").getString(
|
||||||
int start = ign.indexOf("IGN:") + "IGN:".length();
|
"author");
|
||||||
//System.out.println("Start: "+start);
|
String ign = item.getJSONObject("data").getString("body");
|
||||||
if (start == -1 + "IGN:".length()) //+length: 2015.08.10.
|
int start = ign.indexOf("IGN:") + "IGN:".length();
|
||||||
continue; //2015.08.09.
|
// System.out.println("Start: "+start);
|
||||||
int end = ign.indexOf(' ', start);
|
if (start == -1 + "IGN:".length()) // +length: 2015.08.10.
|
||||||
if (end == -1 || end == start)
|
continue; // 2015.08.09.
|
||||||
end = ign.indexOf('\n', start); //2015.07.15.
|
int end = ign.indexOf(' ', start);
|
||||||
//System.out.println("End: "+end);
|
if (end == -1 || end == start)
|
||||||
if (end == -1 || end == start)
|
end = ign.indexOf('\n', start); // 2015.07.15.
|
||||||
ign = ign.substring(start);
|
// System.out.println("End: "+end);
|
||||||
else
|
if (end == -1 || end == start)
|
||||||
ign = ign.substring(start, end);
|
ign = ign.substring(start);
|
||||||
//System.out.println("IGN: "+ign);
|
else
|
||||||
ign = ign.trim();
|
ign = ign.substring(start, end);
|
||||||
//System.out.println("Trimmed IGN: "+ign);
|
// System.out.println("IGN: "+ign);
|
||||||
if (HasIGFlair(ign))
|
ign = ign.trim();
|
||||||
continue;
|
// System.out.println("Trimmed IGN: "+ign);
|
||||||
try {
|
if (HasIGFlair(ign))
|
||||||
Thread.sleep(10);
|
continue;
|
||||||
} catch (InterruptedException ex) {
|
try {
|
||||||
Thread.currentThread().interrupt();
|
Thread.sleep(10);
|
||||||
}
|
} catch (InterruptedException ex) {
|
||||||
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
Thread.currentThread().interrupt();
|
||||||
String flair;
|
}
|
||||||
if (flairdata.length > 1) //2015.07.15.
|
String[] flairdata = DownloadString(
|
||||||
flair = flairdata[1];
|
"http://karmadecay.com/thebutton-data.php?users="
|
||||||
else
|
+ author).replace("\"", "").split(":");
|
||||||
flair = "";
|
String flair;
|
||||||
if (flair != "-1")
|
if (flairdata.length > 1) // 2015.07.15.
|
||||||
flair = flair + "s";
|
flair = flairdata[1];
|
||||||
/*else
|
else
|
||||||
flair = "non-presser";*/
|
flair = "";
|
||||||
String flairclass;
|
if (flair != "-1")
|
||||||
if (flairdata.length > 2)
|
flair = flair + "s";
|
||||||
flairclass = flairdata[2];
|
/*
|
||||||
else
|
* else flair = "non-presser";
|
||||||
flairclass = "unknown";
|
*/
|
||||||
SetFlair(ign, flair, flairclass, author);
|
String flairclass;
|
||||||
}
|
if (flairdata.length > 2)
|
||||||
Thread.sleep(10000);
|
flairclass = flairdata[2];
|
||||||
} catch (Exception e) {
|
else
|
||||||
System.out.println("Error!\n" + e);
|
flairclass = "unknown";
|
||||||
LastException = e; //2015.08.09.
|
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 static Exception LastException; // 2015.08.09.
|
||||||
|
|
||||||
public String DownloadString(String urlstr) throws MalformedURLException, IOException {
|
public String DownloadString(String urlstr) throws MalformedURLException,
|
||||||
URL url = new URL(urlstr);
|
IOException {
|
||||||
URLConnection con = url.openConnection();
|
URL url = new URL(urlstr);
|
||||||
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
URLConnection con = url.openConnection();
|
||||||
InputStream in = con.getInputStream();
|
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
||||||
String encoding = con.getContentEncoding();
|
InputStream in = con.getInputStream();
|
||||||
encoding = encoding == null ? "UTF-8" : encoding;
|
String encoding = con.getContentEncoding();
|
||||||
String body = IOUtils.toString(in, encoding);
|
encoding = encoding == null ? "UTF-8" : encoding;
|
||||||
in.close();
|
String body = IOUtils.toString(in, encoding);
|
||||||
return body;
|
in.close();
|
||||||
}
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
public static Map<String, String> TownColors = new HashMap<String, String>(); //2015.07.20.
|
public static Map<String, String> TownColors = new HashMap<String, String>(); // 2015.07.20.
|
||||||
|
|
||||||
public Boolean HasIGFlair(String playername) {
|
public Boolean HasIGFlair(String playername) {
|
||||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
MaybeOfflinePlayer p = MaybeOfflinePlayer.AddPlayerIfNeeded(playername); // 2015.08.08.
|
||||||
//return p.Flair!=null; //2015.08.08.
|
// return p.Flair!=null; //2015.08.08.
|
||||||
return p.CommentedOnReddit; //2015.08.10.
|
return p.CommentedOnReddit; // 2015.08.10.
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetFlair(String playername, String text, String flairclass, String username) {
|
public void SetFlair(String playername, String text, String flairclass,
|
||||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
String username) {
|
||||||
String finalflair;
|
MaybeOfflinePlayer p = MaybeOfflinePlayer.AddPlayerIfNeeded(playername); // 2015.08.08.
|
||||||
p.FlairDecided = true;
|
String finalflair;
|
||||||
p.FlairRecognised = true;
|
p.FlairDecided = true;
|
||||||
switch (flairclass) {
|
p.FlairRecognised = true;
|
||||||
case "press-1":
|
switch (flairclass) {
|
||||||
finalflair = "§c(" + text + ")§r";
|
case "press-1":
|
||||||
break;
|
finalflair = "§c(" + text + ")§r";
|
||||||
case "press-2":
|
break;
|
||||||
finalflair = "§6(" + text + ")§r";
|
case "press-2":
|
||||||
break;
|
finalflair = "§6(" + text + ")§r";
|
||||||
case "press-3":
|
break;
|
||||||
finalflair = "§e(" + text + ")§r";
|
case "press-3":
|
||||||
break;
|
finalflair = "§e(" + text + ")§r";
|
||||||
case "press-4":
|
break;
|
||||||
finalflair = "§a(" + text + ")§r";
|
case "press-4":
|
||||||
break;
|
finalflair = "§a(" + text + ")§r";
|
||||||
case "press-5":
|
break;
|
||||||
finalflair = "§9(" + text + ")§r";
|
case "press-5":
|
||||||
break;
|
finalflair = "§9(" + text + ")§r";
|
||||||
case "press-6":
|
break;
|
||||||
finalflair = "§5(" + text + ")§r";
|
case "press-6":
|
||||||
break;
|
finalflair = "§5(" + text + ")§r";
|
||||||
case "no-press":
|
break;
|
||||||
finalflair = "§7(--s)§r";
|
case "no-press":
|
||||||
break;
|
finalflair = "§7(--s)§r";
|
||||||
case "cheater":
|
break;
|
||||||
finalflair = "§5(" + text + ")§r";
|
case "cheater":
|
||||||
break;
|
finalflair = "§5(" + text + ")§r";
|
||||||
case "cant-press": //2015.08.08.
|
break;
|
||||||
finalflair = "§r(??s)§r";
|
case "cant-press": // 2015.08.08.
|
||||||
break;
|
finalflair = "§r(??s)§r";
|
||||||
case "unknown":
|
break;
|
||||||
if (text.equals("-1")) //If true, only non-presser/can't press; if false, any flair
|
case "unknown":
|
||||||
p.FlairDecided = false;
|
if (text.equals("-1")) // If true, only non-presser/can't press; if
|
||||||
else
|
// false, any flair
|
||||||
p.FlairRecognised = false;
|
p.FlairDecided = false;
|
||||||
finalflair = "";
|
else
|
||||||
break;
|
p.FlairRecognised = false;
|
||||||
default:
|
finalflair = "";
|
||||||
//finalflair="";
|
break;
|
||||||
//break;
|
default:
|
||||||
return;
|
// finalflair="";
|
||||||
}
|
// break;
|
||||||
/*if(finalflair.length()==0) //<-- 2015.07.20.
|
return;
|
||||||
return;*/
|
}
|
||||||
p.Flair = finalflair; //2015.08.08.
|
/*
|
||||||
p.CommentedOnReddit = true; //2015.08.10.
|
* if(finalflair.length()==0) //<-- 2015.07.20. return;
|
||||||
p.UserName = username; //2015.08.08.
|
*/
|
||||||
/*if(finalflair.length()==0) //Just for the message
|
p.Flair = finalflair; // 2015.08.08.
|
||||||
finalflair="undecided";*/
|
p.CommentedOnReddit = true; // 2015.08.10.
|
||||||
//System.out.println("Added new flair to "+playername+": "+finalflair);
|
p.UserName = username; // 2015.08.08.
|
||||||
for (Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
/*
|
||||||
{
|
* if(finalflair.length()==0) //Just for the message
|
||||||
if (player.getName().equals(playername)) {
|
* finalflair="undecided";
|
||||||
//AppendPlayerDisplayFlair(player, username, finalflair);
|
*/
|
||||||
AppendPlayerDisplayFlair(p, player);
|
// System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||||
break;
|
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.
|
public static String GetFlair(Player player) { // 2015.07.16.
|
||||||
String flair = MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
String flair = MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; // 2015.08.08.
|
||||||
//return flair==null ? "" : flair;
|
// return flair==null ? "" : flair;
|
||||||
return flair; //2015.08.10.
|
return flair; // 2015.08.10.
|
||||||
}
|
}
|
||||||
|
|
||||||
//public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
// public static void AppendPlayerDisplayFlair(Player player, String
|
||||||
public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09.
|
// username, String flair)
|
||||||
{
|
public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player,
|
||||||
|
Player p) // <-- 2015.08.09.
|
||||||
|
{
|
||||||
|
|
||||||
if (MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair)
|
if (MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair)
|
||||||
return;
|
return;
|
||||||
if (MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) {
|
if (MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) {
|
||||||
//AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20.
|
// AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20.
|
||||||
if (!player.FlairDecided)
|
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.
|
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
|
} else
|
||||||
p.sendMessage("§9Are you Reddit user " + player.UserName + "?§r §6Type /u accept or /u ignore§r");
|
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.
|
* private static void AppendPlayerDisplayFlairFinal(Player player, String
|
||||||
*String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
* flair) { //2015.07.20.String color =
|
||||||
String[] colors = color.substring(1).split("§");
|
* GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on
|
||||||
String displayname=player.getName(); //2015.08.08.
|
* first capital letters String[] colors = color.substring(1).split("§");
|
||||||
ArrayList<Integer> Positions=new ArrayList<>();
|
* String displayname=player.getName(); //2015.08.08. ArrayList<Integer>
|
||||||
for(int i=0; i<displayname.length(); i++) {
|
* Positions=new ArrayList<>(); for(int i=0; i<displayname.length(); i++) {
|
||||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
* if(Character.isUpperCase(displayname.charAt(i))) { Positions.add(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
|
||||||
String finalname=""; //TODO
|
* nextpos=displayname.length(); String
|
||||||
if(Positions.size()>=colors.length)
|
* substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
{
|
* finalname+=substr; } } else { Positions.clear(); int
|
||||||
int x=0;
|
* unit=displayname.length()/colors.length; int x=0; for(int i=0;
|
||||||
for(int i=0; i<Positions.size(); i++)
|
* i<displayname.length()-unit; i+=unit) { int pos=i; int nextpos;
|
||||||
{
|
* if(i<displayname.length()-unit-unit) nextpos=i+unit; else
|
||||||
int pos=Positions.get(i);
|
* nextpos=displayname.length(); String
|
||||||
int nextpos;
|
* substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
if(i!=Positions.size()-1)
|
* finalname+=substr; } }* }
|
||||||
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.
|
public static String GetColorForTown(String townname) { // 2015.07.20.
|
||||||
if (TownColors.containsKey(townname))
|
if (TownColors.containsKey(townname))
|
||||||
return TownColors.get(townname);
|
return TownColors.get(townname);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String GetPlayerTown(Player player) { //2015.07.20.
|
public static String GetPlayerTown(Player player) { // 2015.07.20.
|
||||||
try {
|
try {
|
||||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
Town town = WorldCoord.parseWorldCoord(player).getTownBlock()
|
||||||
return town.getName();
|
.getTown(); // TODO
|
||||||
} catch (Exception e) {
|
return town.getName();
|
||||||
return "";
|
} catch (Exception e) {
|
||||||
}
|
return "";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
/*
|
||||||
{ //2015.07.20.
|
* public static void RemovePlayerDisplayFlairFinal(Player player, String
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
* flair) { //2015.07.20.
|
||||||
}*/
|
* MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null;
|
||||||
|
* //2015.08.08. }
|
||||||
|
*/
|
||||||
|
|
||||||
public static Collection<? extends Player> GetPlayers() {
|
public static Collection<? extends Player> GetPlayers() {
|
||||||
return Instance.getServer().getOnlinePlayers();
|
return Instance.getServer().getOnlinePlayers();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadFiles(boolean reload) //<-- 2015.08.09.
|
public static void LoadFiles(boolean reload) // <-- 2015.08.09.
|
||||||
{
|
{
|
||||||
if (reload) { //2015.08.09.
|
if (reload) { // 2015.08.09.
|
||||||
System.out.println("The Button Minecraft plugin cleanup for reloading...");
|
System.out
|
||||||
MaybeOfflinePlayer.AllPlayers.clear();
|
.println("The Button Minecraft plugin cleanup for reloading...");
|
||||||
TownColors.clear();
|
MaybeOfflinePlayer.AllPlayers.clear();
|
||||||
}
|
TownColors.clear();
|
||||||
System.out.println("Loading files for The Button Minecraft plugin..."); //2015.08.09.
|
}
|
||||||
try {
|
System.out.println("Loading files for The Button Minecraft plugin..."); // 2015.08.09.
|
||||||
File file = new File("flairsaccepted.txt");
|
try {
|
||||||
if (file.exists()) {
|
File file = new File("flairsaccepted.txt");
|
||||||
BufferedReader br = new BufferedReader(new FileReader("flairsaccepted.txt"));
|
if (file.exists()) {
|
||||||
String line;
|
BufferedReader br = new BufferedReader(new FileReader(
|
||||||
while ((line = br.readLine()) != null) {
|
"flairsaccepted.txt"));
|
||||||
String name = line.replace("\n", "");
|
String line;
|
||||||
//System.out.println("Name: " + name);
|
while ((line = br.readLine()) != null) {
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair = true; //2015.08.08.
|
String name = line.replace("\n", "");
|
||||||
}
|
// System.out.println("Name: " + name);
|
||||||
br.close();
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair = true; // 2015.08.08.
|
||||||
}
|
}
|
||||||
file = new File("flairsignored.txt");
|
br.close();
|
||||||
if (file.exists()) {
|
}
|
||||||
BufferedReader br = new BufferedReader(new FileReader("flairsignored.txt"));
|
file = new File("flairsignored.txt");
|
||||||
String line;
|
if (file.exists()) {
|
||||||
while ((line = br.readLine()) != null) {
|
BufferedReader br = new BufferedReader(new FileReader(
|
||||||
String name = line.replace("\n", "");
|
"flairsignored.txt"));
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair = true; //2015.08.08.
|
String line;
|
||||||
}
|
while ((line = br.readLine()) != null) {
|
||||||
br.close();
|
String name = line.replace("\n", "");
|
||||||
}
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair = true; // 2015.08.08.
|
||||||
file = new File("autoflairconfig.txt");
|
}
|
||||||
if (file.exists()) {
|
br.close();
|
||||||
BufferedReader br = new BufferedReader(new FileReader(file));
|
}
|
||||||
String line;
|
file = new File("autoflairconfig.txt");
|
||||||
while ((line = br.readLine()) != null) {
|
if (file.exists()) {
|
||||||
String[] s = line.split(" ");
|
BufferedReader br = new BufferedReader(new FileReader(file));
|
||||||
if (s.length >= 2) //<-- 2015.08.10.
|
String line;
|
||||||
TownColors.put(s[0], s[1]);
|
while ((line = br.readLine()) != null) {
|
||||||
}
|
String[] s = line.split(" ");
|
||||||
br.close();
|
if (s.length >= 2) // <-- 2015.08.10.
|
||||||
}
|
TownColors.put(s[0], s[1]);
|
||||||
file = new File("customflairs.txt"); //2015.08.09.
|
}
|
||||||
if (file.exists()) {
|
br.close();
|
||||||
BufferedReader br = new BufferedReader(new FileReader(file));
|
}
|
||||||
String line;
|
file = new File("customflairs.txt"); // 2015.08.09.
|
||||||
while ((line = br.readLine()) != null) {
|
if (file.exists()) {
|
||||||
String[] s = line.split(" ");
|
BufferedReader br = new BufferedReader(new FileReader(file));
|
||||||
if (s.length >= 2) //2015.08.10.
|
String line;
|
||||||
{
|
while ((line = br.readLine()) != null) {
|
||||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]);
|
String[] s = line.split(" ");
|
||||||
p.Flair = s[1]; //2015.08.09.
|
if (s.length >= 2) // 2015.08.10.
|
||||||
p.CommentedOnReddit = true; //Kind of
|
{
|
||||||
}
|
MaybeOfflinePlayer p = MaybeOfflinePlayer
|
||||||
}
|
.AddPlayerIfNeeded(s[0]);
|
||||||
br.close();
|
p.Flair = s[1]; // 2015.08.09.
|
||||||
}
|
p.CommentedOnReddit = true; // Kind of
|
||||||
file = new File("notificationsound.txt"); //2015.08.09.
|
p.FlairDecided = true;
|
||||||
if (file.exists()) {
|
p.FlairRecognised = true;
|
||||||
BufferedReader br = new BufferedReader(new FileReader(file));
|
}
|
||||||
String line = br.readLine();
|
}
|
||||||
String[] split = line.split(" ");
|
br.close();
|
||||||
PlayerListener.NotificationSound = split[0];
|
}
|
||||||
PlayerListener.NotificationPitch = Float.parseFloat(split[1]);
|
file = new File("notificationsound.txt"); // 2015.08.09.
|
||||||
br.close();
|
if (file.exists()) {
|
||||||
}
|
BufferedReader br = new BufferedReader(new FileReader(file));
|
||||||
//throw new IOException("Test"); //2015.08.09.
|
String line = br.readLine();
|
||||||
System.out.println("The Button Minecraft plugin loaded files!");
|
String[] split = line.split(" ");
|
||||||
} catch (IOException e) {
|
PlayerListener.NotificationSound = split[0];
|
||||||
System.out.println("Error!\n" + e);
|
PlayerListener.NotificationPitch = Float.parseFloat(split[1]);
|
||||||
LastException = e; //2015.08.09.
|
br.close();
|
||||||
}
|
}
|
||||||
}
|
// throw new IOException("Test"); //2015.08.09.
|
||||||
|
System.out.println("The Button Minecraft plugin loaded files!");
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n" + e);
|
||||||
|
LastException = e; // 2015.08.09.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void SaveFiles() //<-- 2015.08.09.
|
public static void SaveFiles() // <-- 2015.08.09.
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
FileWriter fw;
|
FileWriter fw;
|
||||||
fw = new FileWriter("flairsaccepted.txt");
|
fw = new FileWriter("flairsaccepted.txt");
|
||||||
fw.close();
|
fw.close();
|
||||||
fw = new FileWriter("flairsignored.txt");
|
fw = new FileWriter("flairsignored.txt");
|
||||||
fw.close();
|
fw.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("Error!\n" + e);
|
System.out.println("Error!\n" + e);
|
||||||
LastException = e; //2015.08.09.
|
LastException = e; // 2015.08.09.
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
File file = new File("flairsaccepted.txt");
|
File file = new File("flairsaccepted.txt");
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
||||||
for (MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
for (MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers
|
||||||
{
|
.values()) // <-- 2015.08.08.
|
||||||
if (!player.AcceptedFlair)
|
{
|
||||||
continue; //2015.08.08.
|
if (!player.AcceptedFlair)
|
||||||
bw.write(player.PlayerName + "\n");
|
continue; // 2015.08.08.
|
||||||
}
|
bw.write(player.PlayerName + "\n");
|
||||||
bw.close();
|
}
|
||||||
file = new File("flairsignored.txt");
|
bw.close();
|
||||||
bw = new BufferedWriter(new FileWriter(file, true));
|
file = new File("flairsignored.txt");
|
||||||
for (MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
bw = new BufferedWriter(new FileWriter(file, true));
|
||||||
{
|
for (MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers
|
||||||
if (!player.IgnoredFlair)
|
.values()) // <-- 2015.08.08.
|
||||||
continue; //2015.08.08.
|
{
|
||||||
bw.write(player.PlayerName + "\n");
|
if (!player.IgnoredFlair)
|
||||||
}
|
continue; // 2015.08.08.
|
||||||
bw.close();
|
bw.write(player.PlayerName + "\n");
|
||||||
} catch (IOException e) {
|
}
|
||||||
System.out.println("Error!\n" + e);
|
bw.close();
|
||||||
LastException = e; //2015.08.09.
|
} 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.
|
public static boolean RemoveLineFromFile(String file, String line) { // 2015.08.09.
|
||||||
File inputFile = new File(file);
|
File inputFile = new File(file);
|
||||||
File tempFile = new File("_temp.txt");
|
File tempFile = new File("_temp.txt");
|
||||||
|
|
||||||
if (!inputFile.exists())
|
if (!inputFile.exists())
|
||||||
return true; //2015.08.10.
|
return true; // 2015.08.10.
|
||||||
|
|
||||||
try {
|
try {
|
||||||
BufferedReader reader = new BufferedReader(new FileReader(inputFile));
|
BufferedReader reader = new BufferedReader(
|
||||||
BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
|
new FileReader(inputFile));
|
||||||
|
BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
|
||||||
|
|
||||||
String lineToRemove = line;
|
String lineToRemove = line;
|
||||||
String currentLine;
|
String currentLine;
|
||||||
|
|
||||||
while ((currentLine = reader.readLine()) != null) {
|
while ((currentLine = reader.readLine()) != null) {
|
||||||
// trim newline when comparing with lineToRemove
|
// trim newline when comparing with lineToRemove
|
||||||
String trimmedLine = currentLine.trim();
|
String trimmedLine = currentLine.trim();
|
||||||
if (trimmedLine.split(" ")[0].equals(lineToRemove)) continue; //2015.08.17.
|
if (trimmedLine.split(" ")[0].equals(lineToRemove))
|
||||||
writer.write(currentLine + System.getProperty("line.separator"));
|
continue; // 2015.08.17.
|
||||||
}
|
writer.write(currentLine + System.getProperty("line.separator"));
|
||||||
writer.close();
|
}
|
||||||
reader.close();
|
writer.close();
|
||||||
if (!tempFile.renameTo(inputFile)) {
|
reader.close();
|
||||||
inputFile.delete();
|
if (!tempFile.renameTo(inputFile)) {
|
||||||
return tempFile.renameTo(inputFile);
|
inputFile.delete();
|
||||||
} else
|
return tempFile.renameTo(inputFile);
|
||||||
return true;
|
} else
|
||||||
} catch (IOException e) {
|
return true;
|
||||||
System.out.println("Error!\n" + e);
|
} catch (IOException e) {
|
||||||
LastException = e; //2015.08.09.
|
System.out.println("Error!\n" + e);
|
||||||
}
|
LastException = e; // 2015.08.09.
|
||||||
return false;
|
}
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue