mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-17 21:06:11 +00:00
Merge branch 'TFM1.12-Alpha' into TFM1.12-Alpha
This commit is contained in:
commit
381c06e818
@ -43,12 +43,16 @@ public class PvpMonitor extends FreedomService {
|
|||||||
// Checks 4 cases
|
// Checks 4 cases
|
||||||
if (player.getGameMode() == GameMode.CREATIVE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { // This checks if player is on creative and god mode on.
|
if (player.getGameMode() == GameMode.CREATIVE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { // This checks if player is on creative and god mode on.
|
||||||
player.sendMessage(ChatColor.RED + "Hey! You cannot PVP with God Mode and creative!");
|
player.sendMessage(ChatColor.RED + "Hey! You cannot PVP with God Mode and creative!");
|
||||||
|
event.setCancelled(true);
|
||||||
} else if (player.getGameMode() == GameMode.CREATIVE && !plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { // This checks if player is on creative and god mode off.
|
} else if (player.getGameMode() == GameMode.CREATIVE && !plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { // This checks if player is on creative and god mode off.
|
||||||
player.sendMessage(ChatColor.RED + "Hey! You cannot PVP in creative!");
|
player.sendMessage(ChatColor.RED + "Hey! You cannot PVP in creative!");
|
||||||
|
event.setCancelled(true);
|
||||||
} else if (player.getGameMode() == GameMode.SURVIVAL && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { // This checks if player is on survival with god mode on.
|
} else if (player.getGameMode() == GameMode.SURVIVAL && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { // This checks if player is on survival with god mode on.
|
||||||
player.sendMessage(ChatColor.RED + "Hey! You can't PVP with godmode!");
|
player.sendMessage(ChatColor.RED + "Hey! You can't PVP with godmode!");
|
||||||
|
event.setCancelled(true);
|
||||||
} else if (player.getGameMode() == GameMode.ADVENTURE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { // This checks if player is on Adventure with god mode on.
|
} else if (player.getGameMode() == GameMode.ADVENTURE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { // This checks if player is on Adventure with god mode on.
|
||||||
player.sendMessage(ChatColor.RED + "Hey! You can't PVP with godmode!");
|
player.sendMessage(ChatColor.RED + "Hey! You can't PVP with godmode!");
|
||||||
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,12 +70,16 @@ public class PvpMonitor extends FreedomService {
|
|||||||
|
|
||||||
if (player.getGameMode() == GameMode.CREATIVE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { // This checks if player is on creative and god mode on.
|
if (player.getGameMode() == GameMode.CREATIVE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { // This checks if player is on creative and god mode on.
|
||||||
player.sendMessage(ChatColor.RED + "Hey! You cannot PVP with God Mode and creative!");
|
player.sendMessage(ChatColor.RED + "Hey! You cannot PVP with God Mode and creative!");
|
||||||
|
event.setCancelled(true);
|
||||||
} else if (player.getGameMode() == GameMode.CREATIVE && !plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { // This checks if player is on creative and god mode off.
|
} else if (player.getGameMode() == GameMode.CREATIVE && !plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { // This checks if player is on creative and god mode off.
|
||||||
player.sendMessage(ChatColor.RED + "Hey! You cannot PVP in creative!");
|
player.sendMessage(ChatColor.RED + "Hey! You cannot PVP in creative!");
|
||||||
|
event.setCancelled(true);
|
||||||
} else if (player.getGameMode() == GameMode.SURVIVAL && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { // This checks if player is on survival with god mode on.
|
} else if (player.getGameMode() == GameMode.SURVIVAL && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { // This checks if player is on survival with god mode on.
|
||||||
player.sendMessage(ChatColor.RED + "Hey! You can't PVP with godmode!");
|
player.sendMessage(ChatColor.RED + "Hey! You can't PVP with godmode!");
|
||||||
|
event.setCancelled(true);
|
||||||
} else if (player.getGameMode() == GameMode.ADVENTURE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { // This checks if player is on Adventure with god mode on.
|
} else if (player.getGameMode() == GameMode.ADVENTURE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { // This checks if player is on Adventure with god mode on.
|
||||||
player.sendMessage(ChatColor.RED + "Hey! You can't PVP with godmode!");
|
player.sendMessage(ChatColor.RED + "Hey! You can't PVP with godmode!");
|
||||||
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,32 +1,26 @@
|
|||||||
package me.totalfreedom.totalfreedommod.command;
|
package me.totalfreedom.totalfreedommod.command;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
|
||||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
|
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
|
||||||
@CommandParameters(description = "Essentials Interface Command - Rainbowify your nickname.", usage = "/<command> <<nick> | off>")
|
@CommandParameters(description = "Essentials Interface Command - Rainbowify your nickname.", usage = "/<command> <nick>")
|
||||||
public class Command_rainbownick extends FreedomCommand
|
public class Command_rainbownick extends FreedomCommand
|
||||||
{
|
{
|
||||||
|
|
||||||
public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole)
|
@Override
|
||||||
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
{
|
{
|
||||||
if (args.length != 1)
|
if (args.length != 1)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ("off".equals(args[0]))
|
|
||||||
{
|
|
||||||
((TotalFreedomMod) this.plugin).esb.setNickname(sender.getName(), null);
|
|
||||||
this.msg("Nickname cleared.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
final String nickPlain = ChatColor.stripColor(FUtil.colorize(args[0].trim()));
|
final String nickPlain = ChatColor.stripColor(FUtil.colorize(args[0].trim()));
|
||||||
|
|
||||||
@ -38,10 +32,11 @@ public class Command_rainbownick extends FreedomCommand
|
|||||||
|
|
||||||
if (nickPlain.length() < 4 || nickPlain.length() > 30)
|
if (nickPlain.length() < 4 || nickPlain.length() > 30)
|
||||||
{
|
{
|
||||||
this.msg("Your nickname must be between 4 and 30 characters long.");
|
msg("Your nickname must be between 4 and 30 characters long.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
for (final Player player : Bukkit.getOnlinePlayers())
|
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
if (player == playerSender)
|
if (player == playerSender)
|
||||||
{
|
{
|
||||||
@ -49,20 +44,17 @@ public class Command_rainbownick extends FreedomCommand
|
|||||||
}
|
}
|
||||||
if (player.getName().equalsIgnoreCase(nickPlain) || ChatColor.stripColor(player.getDisplayName()).trim().equalsIgnoreCase(nickPlain))
|
if (player.getName().equalsIgnoreCase(nickPlain) || ChatColor.stripColor(player.getDisplayName()).trim().equalsIgnoreCase(nickPlain))
|
||||||
{
|
{
|
||||||
this.msg("That nickname is already in use.");
|
msg("That nickname is already in use.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final StringBuilder newNick = new StringBuilder();
|
|
||||||
final char[] charArray;
|
final String newNick = FUtil.rainbowify(ChatColor.stripColor(FUtil.colorize(nickPlain)));
|
||||||
final char[] chars = charArray = nickPlain.toCharArray();
|
|
||||||
for (final char c : charArray)
|
plugin.esb.setNickname(sender.getName(), newNick);
|
||||||
{
|
|
||||||
newNick.append(FUtil.rainbowChatColor()).append(c);
|
msg("Your nickname is now: " + newNick);
|
||||||
}
|
|
||||||
newNick.append(ChatColor.WHITE);
|
|
||||||
((TotalFreedomMod) this.plugin).esb.setNickname(sender.getName(), newNick.toString());
|
|
||||||
this.msg("Your nickname is now: " + newNick.toString());
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,51 +1,48 @@
|
|||||||
package me.totalfreedom.totalfreedommod.command;
|
package me.totalfreedom.totalfreedommod.command;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
|
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
|
||||||
@CommandParameters(description = "Gives you a tag with Rainbow", usage = "/<command> <tag>", aliases = "tn")
|
@CommandParameters(description = "Gives you a rainbow tag", usage = "/<command> <tag>")
|
||||||
public class Command_rainbowtag extends FreedomCommand
|
public class Command_rainbowtag extends FreedomCommand
|
||||||
{
|
{
|
||||||
|
|
||||||
public static final List<String> FORBIDDEN_WORDS = Arrays.asList(new String[]
|
@Override
|
||||||
{
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
"admin", "owner", "moderator", "developer", "console", "SRA", "TCA", "SA"
|
|
||||||
});
|
|
||||||
|
|
||||||
public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole)
|
|
||||||
{
|
{
|
||||||
if (args.length < 1)
|
if (args.length < 1)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final StringBuilder tag = new StringBuilder();
|
|
||||||
for (final char c : ChatColor.stripColor(FUtil.colorize(StringUtils.join((Object[]) args, " "))).toCharArray())
|
final String tag = ChatColor.stripColor(FUtil.colorize(StringUtils.join(args, " ")));
|
||||||
|
|
||||||
|
if(tag.length() > 20)
|
||||||
{
|
{
|
||||||
tag.append(FUtil.rainbowChatColor()).append(c);
|
msg("That tag is too long (Max is 20 characters).");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
final String tagStr = tag.toString();
|
|
||||||
for (final String word : FORBIDDEN_WORDS)
|
for (String word : Command_tag.FORBIDDEN_WORDS)
|
||||||
{
|
{
|
||||||
if (tagStr.contains(word))
|
if (tag.contains(word))
|
||||||
{
|
{
|
||||||
this.msg("That tag contains a forbidden word.");
|
msg("That tag contains a forbidden word.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final FPlayer data = ((TotalFreedomMod) this.plugin).pl.getPlayer(playerSender);
|
|
||||||
data.setTag(tagStr);
|
plugin.pl.getPlayer(playerSender).setTag(FUtil.rainbowify(tag));
|
||||||
this.msg("Set tag to " + (Object) tag);
|
|
||||||
|
msg("Set tag to " + tag);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,12 +1,12 @@
|
|||||||
package me.totalfreedom.totalfreedommod.fun;
|
package me.totalfreedom.totalfreedommod.fun;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||||
import me.totalfreedom.totalfreedommod.util.DepreciationAggregator;
|
import me.totalfreedom.totalfreedommod.util.DepreciationAggregator;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -16,7 +16,6 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
|||||||
|
|
||||||
public class Trailer extends FreedomService
|
public class Trailer extends FreedomService
|
||||||
{
|
{
|
||||||
|
|
||||||
private final Random random = new Random();
|
private final Random random = new Random();
|
||||||
private final Set<String> trailPlayers = new HashSet<>(); // player name
|
private final Set<String> trailPlayers = new HashSet<>(); // player name
|
||||||
|
|
||||||
@ -60,8 +59,22 @@ public class Trailer extends FreedomService
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Location location = fromBlock.getLocation();
|
||||||
fromBlock.setType(Material.WOOL);
|
fromBlock.setType(Material.WOOL);
|
||||||
DepreciationAggregator.setData_Block(fromBlock, (byte) random.nextInt(16));
|
DepreciationAggregator.setData_Block(fromBlock, (byte) random.nextInt(16));
|
||||||
|
byte data = DepreciationAggregator.getData_Block(fromBlock);
|
||||||
|
Material material = Material.getMaterial(String.valueOf(fromBlock.getType()));
|
||||||
|
for (int x = -1; x <= 1; x++)
|
||||||
|
{
|
||||||
|
for (int z = -1; z <= 1; z++)
|
||||||
|
{
|
||||||
|
final Location trail_pos;
|
||||||
|
trail_pos = new Location(event.getPlayer().getWorld(), fromBlock.getX() + x, fromBlock.getY(), fromBlock.getZ() + z);
|
||||||
|
if (trailPlayers.contains(event.getPlayer().getName())) {
|
||||||
|
plugin.cpb.getCoreProtectAPI().logPlacement(event.getPlayer().getName(), trail_pos, material, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Player player)
|
public void remove(Player player)
|
||||||
|
@ -0,0 +1,234 @@
|
|||||||
|
package me.totalfreedom.totalfreedommod.httpd.module;
|
||||||
|
|
||||||
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||||
|
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||||
|
import me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools;
|
||||||
|
import me.totalfreedom.totalfreedommod.httpd.HTTPDPageBuilder;
|
||||||
|
import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon;
|
||||||
|
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
|
||||||
|
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.Response;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.apache.commons.lang3.StringEscapeUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
public class Module_logfile extends HTTPDModule
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final File LOG_FOLDER = new File("./logs/");
|
||||||
|
private static final String[] LOG_FILTER = new String[]
|
||||||
|
{
|
||||||
|
"log",
|
||||||
|
"gz"
|
||||||
|
};
|
||||||
|
|
||||||
|
public Module_logfile(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session)
|
||||||
|
{
|
||||||
|
super(plugin, session);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response getResponse()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return new HTTPDPageBuilder(body(), title(), null, null).getResponse();
|
||||||
|
}
|
||||||
|
catch (ResponseOverrideException ex)
|
||||||
|
{
|
||||||
|
return ex.getResponse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String title()
|
||||||
|
{
|
||||||
|
return "TotalFreedomMod :: Logfiles";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String body() throws ResponseOverrideException
|
||||||
|
{
|
||||||
|
if (!LOG_FOLDER.exists())
|
||||||
|
{
|
||||||
|
FLog.warning("The logfile module failed to find the logs folder.");
|
||||||
|
return HTMLGenerationTools.paragraph("Can't find the logs folder.");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
final StringBuilder out = new StringBuilder();
|
||||||
|
final String remoteAddress = socket.getInetAddress().getHostAddress();
|
||||||
|
final String[] args = StringUtils.split(uri, "/");
|
||||||
|
final ModuleMode mode = ModuleMode.getMode(getArg(args, 1));
|
||||||
|
|
||||||
|
switch (mode)
|
||||||
|
{
|
||||||
|
case LIST:
|
||||||
|
{
|
||||||
|
if (!isAuthorized(remoteAddress))
|
||||||
|
{
|
||||||
|
|
||||||
|
out.append(HTMLGenerationTools.paragraph("Log files access denied: Your IP, " + remoteAddress + ", is not registered to a superadmin on this server."));
|
||||||
|
FLog.info("An unregistered IP (" + remoteAddress + ") has tried to access the log files");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Collection<File> LogFiles = FileUtils.listFiles(LOG_FOLDER, LOG_FILTER, false);
|
||||||
|
|
||||||
|
final List<String> LogFilesFormatted = new ArrayList<>();
|
||||||
|
for (File logfile : LogFiles)
|
||||||
|
{
|
||||||
|
String filename = StringEscapeUtils.escapeHtml4(logfile.getName());
|
||||||
|
|
||||||
|
LogFilesFormatted.add("<li><a href=\"/logfile/download?logFileName=" + filename + "\">" + filename + "</a></li>");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(LogFilesFormatted, new Comparator<String>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public int compare(String a, String b)
|
||||||
|
{
|
||||||
|
return a.toLowerCase().compareTo(b.toLowerCase());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
out
|
||||||
|
.append(HTMLGenerationTools.heading("Logfiles:", 1))
|
||||||
|
.append("<ul>")
|
||||||
|
.append(StringUtils.join(LogFilesFormatted, "\r\n"))
|
||||||
|
.append("</ul>");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DOWNLOAD:
|
||||||
|
{
|
||||||
|
if (!isAuthorized(remoteAddress))
|
||||||
|
{
|
||||||
|
out.append(HTMLGenerationTools.paragraph("Log files access denied: Your IP, " + remoteAddress + ", is not registered to a superadmin on this server."));
|
||||||
|
FLog.info("An unregistered IP (" + remoteAddress + ") has tried to download a log file");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FLog.info("The IP \"" + remoteAddress + "\" is downloading log file:" + params.get("logFileName"));
|
||||||
|
throw new ResponseOverrideException(downloadLogFile(params.get("logFileName")));
|
||||||
|
}
|
||||||
|
catch (LogFileTransferException ex)
|
||||||
|
{
|
||||||
|
out.append(HTMLGenerationTools.paragraph("Error downloading logfile: " + ex.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
out.append(HTMLGenerationTools.paragraph("Invalid request mode."));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Response downloadLogFile(String LogFilesName) throws LogFileTransferException
|
||||||
|
{
|
||||||
|
if (LogFilesName == null)
|
||||||
|
{
|
||||||
|
throw new LogFileTransferException("Invalid logfile requested: " + LogFilesName);
|
||||||
|
}
|
||||||
|
|
||||||
|
final File targetFile = new File(LOG_FOLDER.getPath(), LogFilesName);
|
||||||
|
if (!targetFile.exists())
|
||||||
|
{
|
||||||
|
throw new LogFileTransferException("Logfile not found: " + LogFilesName);
|
||||||
|
}
|
||||||
|
|
||||||
|
Response response = HTTPDaemon.serveFileBasic(targetFile);
|
||||||
|
|
||||||
|
response.addHeader("Content-Disposition", "attachment; filename=" + targetFile.getName() + ";");
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isAuthorized(String remoteAddress)
|
||||||
|
{
|
||||||
|
Admin entry = plugin.al.getEntryByIp(remoteAddress);
|
||||||
|
return entry != null && entry.isActive();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class LogFileTransferException extends Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
public LogFileTransferException()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public LogFileTransferException(String string)
|
||||||
|
{
|
||||||
|
super(string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ResponseOverrideException extends Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
private final Response response;
|
||||||
|
|
||||||
|
public ResponseOverrideException(Response response)
|
||||||
|
{
|
||||||
|
this.response = response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Response getResponse()
|
||||||
|
{
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getArg(String[] args, int index)
|
||||||
|
{
|
||||||
|
String out = (args.length == index + 1 ? args[index] : null);
|
||||||
|
return (out == null ? null : (out.trim().isEmpty() ? null : out.trim()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static enum ModuleMode
|
||||||
|
{
|
||||||
|
|
||||||
|
LIST("list"),
|
||||||
|
DOWNLOAD("download"),
|
||||||
|
INVALID(null);
|
||||||
|
//
|
||||||
|
private final String modeName;
|
||||||
|
|
||||||
|
private ModuleMode(String modeName)
|
||||||
|
{
|
||||||
|
this.modeName = modeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return this.modeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ModuleMode getMode(String needle)
|
||||||
|
{
|
||||||
|
for (ModuleMode mode : values())
|
||||||
|
{
|
||||||
|
final String haystack = mode.toString();
|
||||||
|
if (haystack != null && haystack.equalsIgnoreCase(needle))
|
||||||
|
{
|
||||||
|
return mode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return INVALID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -4,6 +4,7 @@ import java.io.File;
|
|||||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
|
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
|
|
||||||
public class Module_logs extends Module_file
|
public class Module_logs extends Module_file
|
||||||
{
|
{
|
||||||
@ -18,6 +19,7 @@ public class Module_logs extends Module_file
|
|||||||
{
|
{
|
||||||
if (ConfigEntry.LOGS_SECRET.getString().equals(params.get("password")))
|
if (ConfigEntry.LOGS_SECRET.getString().equals(params.get("password")))
|
||||||
{
|
{
|
||||||
|
FLog.info(session.getSocket().getInetAddress() + " is downloading latest.log.");
|
||||||
return serveFile("latest.log", params, new File("./logs"));
|
return serveFile("latest.log", params, new File("./logs"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -2,6 +2,7 @@ package me.totalfreedom.totalfreedommod.httpd.module;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -137,7 +138,8 @@ public class Module_schematic extends HTTPDModule
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
uploadSchematic();
|
uploadSchematic(remoteAddress);
|
||||||
|
|
||||||
out.append(HTMLGenerationTools.paragraph("Schematic uploaded successfully."));
|
out.append(HTMLGenerationTools.paragraph("Schematic uploaded successfully."));
|
||||||
}
|
}
|
||||||
catch (SchematicTransferException ex)
|
catch (SchematicTransferException ex)
|
||||||
@ -162,7 +164,7 @@ public class Module_schematic extends HTTPDModule
|
|||||||
return out.toString();
|
return out.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean uploadSchematic() throws SchematicTransferException
|
private boolean uploadSchematic(String remoteAddress) throws SchematicTransferException
|
||||||
{
|
{
|
||||||
Map<String, String> files = getFiles();
|
Map<String, String> files = getFiles();
|
||||||
|
|
||||||
@ -203,6 +205,7 @@ public class Module_schematic extends HTTPDModule
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
FileUtils.copyFile(tempFile, targetFile);
|
FileUtils.copyFile(tempFile, targetFile);
|
||||||
|
FLog.info(remoteAddress + " uploaded schematic: " + targetFile.getName());
|
||||||
}
|
}
|
||||||
catch (IOException ex)
|
catch (IOException ex)
|
||||||
{
|
{
|
||||||
|
@ -20,8 +20,6 @@ import java.util.Set;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
import static me.totalfreedom.totalfreedommod.util.FUtil.CHAT_RAINBOW;
|
|
||||||
import static me.totalfreedom.totalfreedommod.util.FUtil.FOUNDER;
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -34,46 +32,36 @@ import org.bukkit.scheduler.BukkitTask;
|
|||||||
|
|
||||||
public class FUtil
|
public class FUtil
|
||||||
{
|
{
|
||||||
private static final Random RANDOM;
|
|
||||||
|
private static final Random RANDOM = new Random();
|
||||||
|
//
|
||||||
public static final String SAVED_FLAGS_FILENAME = "savedflags.dat";
|
public static final String SAVED_FLAGS_FILENAME = "savedflags.dat";
|
||||||
public static final List<String> DEVELOPERS;
|
// See https://github.com/TotalFreedom/License - None of the listed names may be removed.
|
||||||
public static final List<String> FOUNDER;
|
public static final DEVELOPERS = Arrays.asList("Madgeek1450", "Prozza", "WickedGamingUK", "aggelosQQ", "OxLemonxO", "Commodore64x", "Wild1145", "marcocorriero");
|
||||||
public static String DATE_STORAGE_FORMAT;
|
public static String DATE_STORAGE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z";
|
||||||
public static final Map<String, ChatColor> CHAT_COLOR_NAMES;
|
public static final Map<String, ChatColor> CHAT_COLOR_NAMES = new HashMap<>();
|
||||||
public static final Map<String, ChatColor> CHAT_RAINBOW_NAMES;
|
public static final List<ChatColor> CHAT_COLOR_POOL = Arrays.asList(
|
||||||
public static List<String> BLOCKED_CODES;
|
ChatColor.DARK_RED,
|
||||||
public static final List<ChatColor> CHAT_COLOR_POOL;
|
ChatColor.RED,
|
||||||
public static final List<ChatColor> CHAT_RAINBOW;
|
ChatColor.GOLD,
|
||||||
private static Iterator<ChatColor> color;
|
ChatColor.YELLOW,
|
||||||
private static final ChatColor[] BLOCKED = new ChatColor[]
|
ChatColor.GREEN,
|
||||||
|
ChatColor.DARK_GREEN,
|
||||||
|
ChatColor.AQUA,
|
||||||
|
ChatColor.DARK_AQUA,
|
||||||
|
ChatColor.BLUE,
|
||||||
|
ChatColor.DARK_BLUE,
|
||||||
|
ChatColor.DARK_PURPLE,
|
||||||
|
ChatColor.LIGHT_PURPLE);
|
||||||
|
private static Iterator<ChatColor> CHAT_COLOR_ITERATOR;
|
||||||
|
|
||||||
|
static
|
||||||
{
|
{
|
||||||
ChatColor.MAGIC,
|
for (ChatColor chatColor : CHAT_COLOR_POOL)
|
||||||
ChatColor.STRIKETHROUGH,
|
{
|
||||||
ChatColor.ITALIC,
|
CHAT_COLOR_NAMES.put(chatColor.name().toLowerCase().replace("_", ""), chatColor);
|
||||||
ChatColor.UNDERLINE,
|
|
||||||
ChatColor.BLACK
|
|
||||||
};
|
|
||||||
|
|
||||||
static {
|
|
||||||
RANDOM = new Random();
|
|
||||||
DEVELOPERS = Arrays.asList("Madgeek1450", "Prozza", "WickedGamingUK", "aggelosQQ", "OxLemonxO", "Commodore64x", "Wild1145", "marcocorriero");
|
|
||||||
FOUNDER = Arrays.asList("markbyron");
|
|
||||||
FUtil.DATE_STORAGE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z";
|
|
||||||
CHAT_COLOR_NAMES = new HashMap<String, ChatColor>();
|
|
||||||
CHAT_RAINBOW_NAMES = new HashMap<String, ChatColor>();
|
|
||||||
FUtil.BLOCKED_CODES = new ArrayList<String>();
|
|
||||||
CHAT_COLOR_POOL = Arrays.asList(ChatColor.DARK_BLUE, ChatColor.DARK_GREEN, ChatColor.DARK_AQUA, ChatColor.DARK_RED, ChatColor.DARK_PURPLE, ChatColor.GOLD, ChatColor.BLUE, ChatColor.GREEN, ChatColor.AQUA, ChatColor.RED, ChatColor.LIGHT_PURPLE, ChatColor.YELLOW);
|
|
||||||
CHAT_RAINBOW = Arrays.asList(ChatColor.DARK_RED, ChatColor.RED, ChatColor.GOLD, ChatColor.YELLOW, ChatColor.GREEN, ChatColor.DARK_GREEN, ChatColor.AQUA, ChatColor.DARK_AQUA, ChatColor.BLUE, ChatColor.DARK_BLUE, ChatColor.DARK_PURPLE, ChatColor.LIGHT_PURPLE);
|
|
||||||
for (final ChatColor chatColor : FUtil.CHAT_COLOR_POOL) {
|
|
||||||
FUtil.CHAT_COLOR_NAMES.put(chatColor.name().toLowerCase().replace("_", ""), chatColor);
|
|
||||||
}
|
}
|
||||||
for (final ChatColor chatColor : FUtil.CHAT_RAINBOW) {
|
|
||||||
FUtil.CHAT_RAINBOW_NAMES.put(chatColor.name().toLowerCase().replace("_", ""), chatColor);
|
|
||||||
}
|
}
|
||||||
FUtil.color = FUtil.CHAT_RAINBOW.iterator();
|
|
||||||
}
|
|
||||||
private static final Pattern REGEX = Pattern.compile(ChatColor.COLOR_CHAR + "[" + StringUtils.join(BLOCKED, "") + "]", Pattern.CASE_INSENSITIVE);
|
|
||||||
|
|
||||||
|
|
||||||
private FUtil()
|
private FUtil()
|
||||||
{
|
{
|
||||||
@ -368,29 +356,38 @@ public class FUtil
|
|||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
return (T) field.get(from);
|
return (T) field.get(from);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
catch (NoSuchFieldException | IllegalAccessException ex)
|
catch (NoSuchFieldException | IllegalAccessException ex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
} while (checkClass.getSuperclass() != Object.class
|
} while (checkClass.getSuperclass() != Object.class
|
||||||
|
&& ((checkClass = checkClass.getSuperclass()) != null));
|
||||||
&& ((checkClass = checkClass.getSuperclass()) != null));
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ChatColor randomChatColor() {
|
public static ChatColor randomChatColor()
|
||||||
return FUtil.CHAT_COLOR_POOL.get(FUtil.RANDOM.nextInt(FUtil.CHAT_COLOR_POOL.size()));
|
{
|
||||||
|
return CHAT_COLOR_POOL.get(RANDOM.nextInt(CHAT_COLOR_POOL.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ChatColor rainbowChatColor() {
|
public static String rainbowify(String string)
|
||||||
if (FUtil.color.hasNext()) {
|
{
|
||||||
return FUtil.color.next();
|
CHAT_COLOR_ITERATOR = CHAT_COLOR_POOL.iterator();
|
||||||
|
|
||||||
|
final StringBuilder newString = new StringBuilder();
|
||||||
|
final char[] chars = string.toCharArray();
|
||||||
|
|
||||||
|
for (char c : chars)
|
||||||
|
{
|
||||||
|
if (!CHAT_COLOR_ITERATOR.hasNext())
|
||||||
|
{
|
||||||
|
CHAT_COLOR_ITERATOR = CHAT_COLOR_POOL.iterator(); //Restart from first colour if there are no more colours in iterator.
|
||||||
}
|
}
|
||||||
FUtil.color = FUtil.CHAT_RAINBOW.iterator();
|
newString.append(CHAT_COLOR_ITERATOR.next()).append(c);
|
||||||
return FUtil.color.next();
|
}
|
||||||
|
|
||||||
|
return newString.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String colorize(String string)
|
public static String colorize(String string)
|
||||||
@ -398,22 +395,6 @@ public class FUtil
|
|||||||
return ChatColor.translateAlternateColorCodes('&', string);
|
return ChatColor.translateAlternateColorCodes('&', string);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String StrictColorize(String string)
|
|
||||||
{
|
|
||||||
String string2 = ChatColor.translateAlternateColorCodes('&', string);
|
|
||||||
final Matcher matcher = REGEX.matcher(string2);
|
|
||||||
if (matcher.find())
|
|
||||||
{
|
|
||||||
final String filteredcolorize = matcher.replaceAll("&");
|
|
||||||
if(matcher.find(REGEX.matcher(ChatColor.BLACK)))
|
|
||||||
return filteredcolorize;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return string2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Date getUnixDate(long unix)
|
public static Date getUnixDate(long unix)
|
||||||
{
|
{
|
||||||
return new Date(unix * 1000);
|
return new Date(unix * 1000);
|
||||||
|
Loading…
Reference in New Issue
Block a user