Merge pull request #1 from Sciguymjm/master
Clean up code and add nickname support
This commit is contained in:
commit
5a048c4486
27 changed files with 719 additions and 717 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -215,3 +215,8 @@ pip-log.txt
|
||||||
#Mr Developer
|
#Mr Developer
|
||||||
.mr.developer.cfg
|
.mr.developer.cfg
|
||||||
.metadata/*
|
.metadata/*
|
||||||
|
TheButtonAutoFlair/out/artifacts/Autoflair/Autoflair.jar
|
||||||
|
*.iml
|
||||||
|
*.name
|
||||||
|
.idea/compiler.xml
|
||||||
|
*.xml
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,5 +1,11 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
|
@ -7,295 +13,260 @@ import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
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 {
|
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, String[] args) {
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
if(args.length<1)
|
if (args.length < 1)
|
||||||
return false;
|
return false;
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
if(!p.CommentedOnReddit && !args[0].toLowerCase().equals("admin"))
|
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");
|
||||||
player.sendMessage("§cError: You need to write your username to the reddit thread at /r/TheButtonMinecraft§r");
|
return true;
|
||||||
return true;
|
}
|
||||||
}
|
if (!p.FlairRecognised && !args[0].toLowerCase().equals("admin")) { //2015.08.10.
|
||||||
if(!p.FlairRecognised && !args[0].toLowerCase().equals("admin"))
|
player.sendMessage("Sorry, but your flair isn't recorded. Please ask a mod to set it for you.");
|
||||||
{ //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;
|
switch (args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
}
|
{
|
||||||
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
case "accept": {
|
||||||
{
|
if (p.IgnoredFlair)
|
||||||
case "accept":
|
p.IgnoredFlair = false; //2015.08.08.
|
||||||
{
|
if (!p.AcceptedFlair) {
|
||||||
if(p.IgnoredFlair)
|
String flair = p.Flair; //2015.08.08.
|
||||||
p.IgnoredFlair=false; //2015.08.08.
|
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
if(!p.AcceptedFlair)
|
p.AcceptedFlair = true; //2015.08.08.
|
||||||
{
|
PluginMain.AppendPlayerDisplayFlair(p, player);
|
||||||
String flair=p.Flair; //2015.08.08.
|
player.sendMessage("§bYour flair has been set:§r " + flair);
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
} else
|
||||||
p.AcceptedFlair=true; //2015.08.08.
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
break;
|
||||||
player.sendMessage("§bYour flair has been set:§r "+flair);
|
}
|
||||||
}
|
case "ignore": {
|
||||||
else
|
if (p.AcceptedFlair)
|
||||||
player.sendMessage("§cYou already have this user's flair.§r");
|
p.AcceptedFlair = false; //2015.08.08.
|
||||||
break;
|
if (!p.IgnoredFlair) {
|
||||||
}
|
p.IgnoredFlair = true;
|
||||||
case "ignore":
|
//String flair=p.Flair; //2015.08.08.
|
||||||
{
|
//PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
if(p.AcceptedFlair)
|
player.sendMessage("§bYou have ignored this request. You can still use /u accept though.§r");
|
||||||
p.AcceptedFlair=false; //2015.08.08.
|
} else
|
||||||
if(!p.IgnoredFlair)
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
{
|
break;
|
||||||
p.IgnoredFlair=true;
|
}
|
||||||
//String flair=p.Flair; //2015.08.08.
|
/*case "reload": //2015.07.20.
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
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 "reload": //2015.07.20.
|
|
||||||
DoReload(player);
|
DoReload(player);
|
||||||
break;*/
|
break;*/
|
||||||
case "admin": //2015.08.09.
|
case "admin": //2015.08.09.
|
||||||
DoAdmin(player, args);
|
DoAdmin(player, args);
|
||||||
break;
|
break;
|
||||||
case "nonpresser": //2015.08.09.
|
case "nonpresser": //2015.08.09.
|
||||||
if(!p.AcceptedFlair)
|
if (!p.AcceptedFlair) {
|
||||||
{
|
player.sendMessage("§cYou need to accept the flair first.§r");
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
break;
|
||||||
break;
|
}
|
||||||
}
|
if (p.FlairDecided) {
|
||||||
if(p.FlairDecided)
|
player.sendMessage("§cYou have already set the flair type.§r");
|
||||||
{
|
break;
|
||||||
player.sendMessage("§cYou have already set the flair type.§r");
|
}
|
||||||
break;
|
SetPlayerFlair(player, p, "§7(--s)§r");
|
||||||
}
|
break;
|
||||||
SetPlayerFlair(player, p, "§7(--s)§r");
|
case "cantpress": //2015.08.09.
|
||||||
break;
|
if (!p.AcceptedFlair) {
|
||||||
case "cantpress": //2015.08.09.
|
player.sendMessage("§cYou need to accept the flair first.§r");
|
||||||
if(!p.AcceptedFlair)
|
break;
|
||||||
{
|
}
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
if (p.FlairDecided) {
|
||||||
break;
|
player.sendMessage("§cYou have already set the flair type or your flair type is known.§r");
|
||||||
}
|
break;
|
||||||
if(p.FlairDecided)
|
}
|
||||||
{
|
SetPlayerFlair(player, p, "§r(??s)§r");
|
||||||
player.sendMessage("§cYou have already set the flair type or your flair type is known.§r");
|
break;
|
||||||
break;
|
case "opme": //2015.08.10.
|
||||||
}
|
player.sendMessage("It would be nice, isn't it?"); //Sometimes I'm bored too
|
||||||
SetPlayerFlair(player, p, "§r(??s)§r");
|
break;
|
||||||
break;
|
default:
|
||||||
case "opme": //2015.08.10.
|
return false;
|
||||||
player.sendMessage("It would be nice, isn't it?"); //Sometimes I'm bored too
|
}
|
||||||
break;
|
return true;
|
||||||
default:
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/*if(args[0].toLowerCase()=="reload")
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
DoReload(null); //2015.07.20.*/
|
DoReload(null); //2015.07.20.*/
|
||||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
else if (args.length > 0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||||
{
|
{
|
||||||
DoAdmin(null, args); //2015.08.09.
|
DoAdmin(null, args); //2015.08.09.
|
||||||
return true; //2015.08.09.
|
return true; //2015.08.09.
|
||||||
}
|
}
|
||||||
return false;
|
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 The Button Minecraft 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="§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.
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
//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, "§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;
|
|
||||||
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, "§bThe flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r");
|
|
||||||
}
|
}
|
||||||
private static void DoSetFlair(Player player, String[] args)
|
|
||||||
{
|
private static void DoReload(Player player) { //2015.07.20.
|
||||||
//args[0] is "admin" - args[1] is "setflair"
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
if(args.length<4)
|
//{
|
||||||
{
|
try {
|
||||||
SendMessage(player, "§cUsage: /u admin setflair <playername> <flair>");
|
PluginMain.Console.sendMessage("§6-- Reloading The Button Minecraft plugin...§r");
|
||||||
return;
|
PluginMain.LoadFiles(true); //2015.08.09.
|
||||||
}
|
for (Player p : PluginMain.GetPlayers()) {
|
||||||
if(args[3].charAt(0)!='&')
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
||||||
{
|
//if(mp.Flair!=null)
|
||||||
SendMessage(player, "§cYou need to start the flair with a color code: &6(19s)&r");
|
if (mp.CommentedOnReddit) {
|
||||||
return;
|
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
||||||
}
|
}
|
||||||
SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]);
|
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.
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
}
|
}
|
||||||
private static void DoUpdatePlugin(Player player)
|
|
||||||
{ //2015.08.10.
|
private static Player ReloadPlayer; //2015.08.09.
|
||||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
|
||||||
System.out.println("Forced updating of Auto-Flair plugin.");
|
private static void DoAdmin(Player player, String[] args) { //2015.08.09.
|
||||||
URL url;
|
if (player == null || player.isOp() || player.getName().equals("NorbiPeti")) {
|
||||||
try {
|
//System.out.println("Args length: " + args.length);
|
||||||
url = new URL("https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
if (args.length == 1) {
|
||||||
FileUtils.copyURLToFile(url, new File("plugins/TheButtonAutoFlair.jar"));
|
String message = "§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
||||||
SendMessage(player, "Updating done!");
|
SendMessage(player, message);
|
||||||
}
|
return;
|
||||||
catch (MalformedURLException e) {
|
}
|
||||||
System.out.println("Error!\n"+e);
|
//args[0] is "admin"
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
switch (args[1].toLowerCase()) {
|
||||||
}
|
case "reload":
|
||||||
catch (IOException e) {
|
ReloadPlayer = player; //2015.08.09.
|
||||||
System.out.println("Error!\n"+e);
|
SendMessage(player, "§bMake sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
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;
|
||||||
|
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, "§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;
|
||||||
|
}
|
||||||
|
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,78 +1,135 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import de.inventivegames.TellRawAutoMessage.Reflection;
|
||||||
|
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.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
|
import org.bukkit.event.player.PlayerChatTabCompleteEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
public class PlayerListener implements Listener { //2015.07.16.
|
||||||
{ //2015.07.16.
|
public static HashMap<String, UUID> nicknames = new HashMap<>();
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
{
|
Player p = event.getPlayer();
|
||||||
Player p=event.getPlayer();
|
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
if (mp.CommentedOnReddit)
|
||||||
if(mp.CommentedOnReddit)
|
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
||||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
else { //2015.07.20.
|
||||||
else
|
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\"}]}}}]";
|
||||||
{ //2015.07.20.
|
sendRawMessage(p, json);
|
||||||
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.
|
/* NICKNAME LOGIC */
|
||||||
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");
|
UUID id = p.getUniqueId();
|
||||||
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.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
File f =new File("plugins/essentials/userdata/"+id+".yml");
|
||||||
|
YamlConfiguration yc = new YamlConfiguration();
|
||||||
|
try {
|
||||||
|
yc.load(f);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (InvalidConfigurationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
String nickname = yc.getString("nickname");
|
||||||
|
nicknames.put(nickname, id);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@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");
|
||||||
|
}
|
||||||
|
for (String n : nicknames.keySet())
|
||||||
|
{
|
||||||
|
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");
|
||||||
|
|
||||||
|
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.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onTabComplete(PlayerChatTabCompleteEvent e)
|
||||||
|
{
|
||||||
|
String name = e.getLastToken();
|
||||||
|
for(String nickname : nicknames.keySet())
|
||||||
|
{
|
||||||
|
if(nickname.startsWith(name))
|
||||||
|
e.getTabCompletions().add(nickname);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,7 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
import java.io.BufferedWriter;
|
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||||
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.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -21,211 +9,209 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
import java.io.*;
|
||||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
import java.lang.String;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
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
|
// 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);
|
this.getCommand("u").setExecutor(new Commands());
|
||||||
this.getCommand("u").setExecutor(new Commands());
|
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
Instance = this; //2015.08.08.
|
||||||
Instance=this; //2015.08.08.
|
Console = this.getServer().getConsoleSender(); //2015.08.12.
|
||||||
Console=this.getServer().getConsoleSender(); //2015.08.12.
|
LoadFiles(false); //2015.08.09.
|
||||||
LoadFiles(false); //2015.08.09.
|
Runnable r = new Runnable() {
|
||||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
public void run() {
|
||||||
Thread t=new Thread(r);
|
ThreadMethod();
|
||||||
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");
|
||||||
{
|
JSONArray json = new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
||||||
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
for (Object obj : json) {
|
||||||
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
JSONObject item = (JSONObject) obj;
|
||||||
for(Object obj : json)
|
String author = item.getJSONObject("data").getString("author");
|
||||||
{
|
String ign = item.getJSONObject("data").getString("body");
|
||||||
JSONObject item = (JSONObject)obj;
|
int start = ign.indexOf("IGN:") + "IGN:".length();
|
||||||
String author=item.getJSONObject("data").getString("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("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
flair = flairdata[1];
|
||||||
String flair;
|
else
|
||||||
if(flairdata.length > 1) //2015.07.15.
|
flair = "";
|
||||||
flair = flairdata[1];
|
if (flair != "-1")
|
||||||
else
|
flair = flair + "s";
|
||||||
flair="";
|
/*else
|
||||||
if (flair != "-1")
|
|
||||||
flair = flair + "s";
|
|
||||||
/*else
|
|
||||||
flair = "non-presser";*/
|
flair = "non-presser";*/
|
||||||
String flairclass;
|
String flairclass;
|
||||||
if(flairdata.length>2)
|
if (flairdata.length > 2)
|
||||||
flairclass = flairdata[2];
|
flairclass = flairdata[2];
|
||||||
else
|
else
|
||||||
flairclass="unknown";
|
flairclass = "unknown";
|
||||||
SetFlair(ign, flair, flairclass, author);
|
SetFlair(ign, flair, flairclass, author);
|
||||||
}
|
}
|
||||||
Thread.sleep(10000);
|
Thread.sleep(10000);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch(Exception e)
|
System.out.println("Error!\n" + e);
|
||||||
{
|
LastException = e; //2015.08.09.
|
||||||
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, IOException {
|
||||||
{
|
URL url = new URL(urlstr);
|
||||||
URL url = new URL(urlstr);
|
URLConnection con = url.openConnection();
|
||||||
URLConnection con = url.openConnection();
|
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
||||||
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
InputStream in = con.getInputStream();
|
||||||
InputStream in = con.getInputStream();
|
String encoding = con.getContentEncoding();
|
||||||
String encoding = con.getContentEncoding();
|
encoding = encoding == null ? "UTF-8" : encoding;
|
||||||
encoding = encoding == null ? "UTF-8" : encoding;
|
String body = IOUtils.toString(in, encoding);
|
||||||
String body = IOUtils.toString(in, encoding);
|
in.close();
|
||||||
in.close();
|
return body;
|
||||||
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, String username) {
|
||||||
{
|
MaybeOfflinePlayer p = MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
String finalflair;
|
||||||
String finalflair;
|
p.FlairDecided = true;
|
||||||
p.FlairDecided=true;
|
p.FlairRecognised = true;
|
||||||
p.FlairRecognised=true;
|
switch (flairclass) {
|
||||||
switch(flairclass)
|
case "press-1":
|
||||||
{
|
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 false, any flair
|
else
|
||||||
p.FlairDecided=false;
|
p.FlairRecognised = false;
|
||||||
else
|
finalflair = "";
|
||||||
p.FlairRecognised=false;
|
break;
|
||||||
finalflair="";
|
default:
|
||||||
break;
|
//finalflair="";
|
||||||
default:
|
//break;
|
||||||
//finalflair="";
|
return;
|
||||||
//break;
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
/*if(finalflair.length()==0) //<-- 2015.07.20.
|
/*if(finalflair.length()==0) //<-- 2015.07.20.
|
||||||
return;*/
|
return;*/
|
||||||
p.Flair=finalflair; //2015.08.08.
|
p.Flair = finalflair; //2015.08.08.
|
||||||
p.CommentedOnReddit=true; //2015.08.10.
|
p.CommentedOnReddit = true; //2015.08.10.
|
||||||
p.UserName=username; //2015.08.08.
|
p.UserName = username; //2015.08.08.
|
||||||
/*if(finalflair.length()==0) //Just for the message
|
/*if(finalflair.length()==0) //Just for the message
|
||||||
finalflair="undecided";*/
|
finalflair="undecided";*/
|
||||||
//System.out.println("Added new flair to "+playername+": "+finalflair);
|
//System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||||
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
for (Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||||
{
|
{
|
||||||
if(player.getName().equals(playername))
|
if (player.getName().equals(playername)) {
|
||||||
{
|
//AppendPlayerDisplayFlair(player, username, finalflair);
|
||||||
//AppendPlayerDisplayFlair(player, username, finalflair);
|
AppendPlayerDisplayFlair(p, player);
|
||||||
AppendPlayerDisplayFlair(p, player);
|
break;
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String GetFlair(Player player)
|
public static String GetFlair(Player player) { //2015.07.16.
|
||||||
{ //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 username, String flair)
|
||||||
public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09.
|
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
|
||||||
}
|
p.sendMessage("§9Are you Reddit user " + player.UserName + "?§r §6Type /u accept or /u ignore§r");
|
||||||
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)
|
/*private static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
@ -274,21 +260,19 @@ public class PluginMain extends JavaPlugin
|
||||||
}*
|
}*
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
public static String GetColorForTown(String townname)
|
public static String GetColorForTown(String townname) { //2015.07.20.
|
||||||
{ //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)
|
public static String GetPlayerTown(Player player) { //2015.07.20.
|
||||||
{ //2015.07.20.
|
try {
|
||||||
try {
|
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
return town.getName();
|
||||||
return town.getName();
|
} catch (Exception e) {
|
||||||
} catch (Exception e) {
|
return "";
|
||||||
return "";
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
/*public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
@ -296,166 +280,151 @@ public class PluginMain extends JavaPlugin
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
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)
|
if (reload) { //2015.08.09.
|
||||||
{ //2015.08.09.
|
System.out.println("The Button Minecraft plugin cleanup for reloading...");
|
||||||
System.out.println("The Button Minecraft plugin cleanup for reloading...");
|
MaybeOfflinePlayer.AllPlayers.clear();
|
||||||
MaybeOfflinePlayer.AllPlayers.clear();
|
TownColors.clear();
|
||||||
TownColors.clear();
|
}
|
||||||
}
|
System.out.println("Loading files for The Button Minecraft plugin..."); //2015.08.09.
|
||||||
System.out.println("Loading files for The Button Minecraft plugin..."); //2015.08.09.
|
try {
|
||||||
try {
|
File file = new File("flairsaccepted.txt");
|
||||||
File file=new File("flairsaccepted.txt");
|
if (file.exists()) {
|
||||||
if(file.exists())
|
BufferedReader br = new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||||
{
|
String line;
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
while ((line = br.readLine()) != null) {
|
||||||
String line;
|
String name = line.replace("\n", "");
|
||||||
while ((line = br.readLine()) != null)
|
//System.out.println("Name: " + name);
|
||||||
{
|
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) {
|
||||||
{
|
String name = line.replace("\n", "");
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair = true; //2015.08.08.
|
||||||
String line;
|
}
|
||||||
while ((line = br.readLine()) != null)
|
br.close();
|
||||||
{
|
}
|
||||||
String name=line.replace("\n", "");
|
file = new File("autoflairconfig.txt");
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
if (file.exists()) {
|
||||||
}
|
BufferedReader br = new BufferedReader(new FileReader(file));
|
||||||
br.close();
|
String line;
|
||||||
}
|
while ((line = br.readLine()) != null) {
|
||||||
file=new File("autoflairconfig.txt");
|
String[] s = line.split(" ");
|
||||||
if(file.exists())
|
if (s.length >= 2) //<-- 2015.08.10.
|
||||||
{
|
TownColors.put(s[0], s[1]);
|
||||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
}
|
||||||
String line;
|
br.close();
|
||||||
while((line=br.readLine())!=null)
|
}
|
||||||
{
|
file = new File("customflairs.txt"); //2015.08.09.
|
||||||
String[] s=line.split(" ");
|
if (file.exists()) {
|
||||||
if(s.length>=2) //<-- 2015.08.10.
|
BufferedReader br = new BufferedReader(new FileReader(file));
|
||||||
TownColors.put(s[0], s[1]);
|
String line;
|
||||||
}
|
while ((line = br.readLine()) != null) {
|
||||||
br.close();
|
String[] s = line.split(" ");
|
||||||
}
|
if (s.length >= 2) //2015.08.10.
|
||||||
file=new File("customflairs.txt"); //2015.08.09.
|
{
|
||||||
if(file.exists())
|
MaybeOfflinePlayer p = MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]);
|
||||||
{
|
p.Flair = s[1]; //2015.08.09.
|
||||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
p.CommentedOnReddit = true; //Kind of
|
||||||
String line;
|
}
|
||||||
while((line=br.readLine())!=null)
|
}
|
||||||
{
|
br.close();
|
||||||
String[] s=line.split(" ");
|
}
|
||||||
if(s.length>=2) //2015.08.10.
|
file = new File("notificationsound.txt"); //2015.08.09.
|
||||||
{
|
if (file.exists()) {
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]);
|
BufferedReader br = new BufferedReader(new FileReader(file));
|
||||||
p.Flair=s[1]; //2015.08.09.
|
String line = br.readLine();
|
||||||
p.CommentedOnReddit=true; //Kind of
|
String[] split = line.split(" ");
|
||||||
}
|
PlayerListener.NotificationSound = split[0];
|
||||||
}
|
PlayerListener.NotificationPitch = Float.parseFloat(split[1]);
|
||||||
br.close();
|
br.close();
|
||||||
}
|
}
|
||||||
file=new File("notificationsound.txt"); //2015.08.09.
|
//throw new IOException("Test"); //2015.08.09.
|
||||||
if(file.exists())
|
System.out.println("The Button Minecraft plugin loaded files!");
|
||||||
{
|
} catch (IOException e) {
|
||||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
System.out.println("Error!\n" + e);
|
||||||
String line=br.readLine();
|
LastException = e; //2015.08.09.
|
||||||
String[] split=line.split(" ");
|
}
|
||||||
PlayerListener.NotificationSound=split[0];
|
|
||||||
PlayerListener.NotificationPitch=Float.parseFloat(split[1]);
|
|
||||||
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) {
|
||||||
}
|
System.out.println("Error!\n" + e);
|
||||||
catch(Exception e)
|
LastException = e; //2015.08.09.
|
||||||
{
|
}
|
||||||
System.out.println("Error!\n"+e);
|
try {
|
||||||
LastException=e; //2015.08.09.
|
File file = new File("flairsaccepted.txt");
|
||||||
}
|
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
||||||
try {
|
for (MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
File file=new File("flairsaccepted.txt");
|
{
|
||||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
if (!player.AcceptedFlair)
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
continue; //2015.08.08.
|
||||||
{
|
bw.write(player.PlayerName + "\n");
|
||||||
if(!player.AcceptedFlair)
|
}
|
||||||
continue; //2015.08.08.
|
bw.close();
|
||||||
bw.write(player.PlayerName+"\n");
|
file = new File("flairsignored.txt");
|
||||||
}
|
bw = new BufferedWriter(new FileWriter(file, true));
|
||||||
bw.close();
|
for (MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
file=new File("flairsignored.txt");
|
{
|
||||||
bw = new BufferedWriter(new FileWriter(file, true));
|
if (!player.IgnoredFlair)
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.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.
|
|
||||||
File inputFile = new File(file);
|
|
||||||
File tempFile = new File("_temp.txt");
|
|
||||||
|
|
||||||
if(!inputFile.exists())
|
public static boolean RemoveLineFromFile(String file, String line) { //2015.08.09.
|
||||||
return true; //2015.08.10.
|
File inputFile = new File(file);
|
||||||
|
File tempFile = new File("_temp.txt");
|
||||||
|
|
||||||
try {
|
if (!inputFile.exists())
|
||||||
BufferedReader reader = new BufferedReader(new FileReader(inputFile));
|
return true; //2015.08.10.
|
||||||
BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
|
|
||||||
|
|
||||||
String lineToRemove = line;
|
try {
|
||||||
String currentLine;
|
BufferedReader reader = new BufferedReader(new FileReader(inputFile));
|
||||||
|
BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
|
||||||
|
|
||||||
while((currentLine = reader.readLine()) != null) {
|
String lineToRemove = line;
|
||||||
// trim newline when comparing with lineToRemove
|
String currentLine;
|
||||||
String trimmedLine = currentLine.trim();
|
|
||||||
if(trimmedLine.split(" ")[0].equals(lineToRemove)) continue; //2015.08.17.
|
while ((currentLine = reader.readLine()) != null) {
|
||||||
writer.write(currentLine + System.getProperty("line.separator"));
|
// trim newline when comparing with lineToRemove
|
||||||
}
|
String trimmedLine = currentLine.trim();
|
||||||
writer.close();
|
if (trimmedLine.split(" ")[0].equals(lineToRemove)) continue; //2015.08.17.
|
||||||
reader.close();
|
writer.write(currentLine + System.getProperty("line.separator"));
|
||||||
if(!tempFile.renameTo(inputFile))
|
}
|
||||||
{
|
writer.close();
|
||||||
inputFile.delete();
|
reader.close();
|
||||||
return tempFile.renameTo(inputFile);
|
if (!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