From 3f360a4d5e0347fd9941cde060aad2ca0c2f5e75 Mon Sep 17 00:00:00 2001 From: Seth <13510767+ZeroEpoch1969@users.noreply.github.com> Date: Mon, 1 Jan 2018 19:46:35 -0700 Subject: [PATCH] Bug fixes and improvements (#16) * Bug fixes and improvements * Re-add Marco's name * Actually make the logfile page load. --- .../totalfreedommod/EntityWiper.java | 7 +++ .../totalfreedommod/admin/AdminList.java | 2 +- .../totalfreedommod/command/Command_doom.java | 8 ++-- .../totalfreedommod/command/Command_gtfo.java | 3 +- .../command/Command_opall.java | 2 +- .../command/Command_radar.java | 16 +++---- .../command/Command_saconfig.java | 8 ++-- .../command/Command_verify.java | 2 +- .../totalfreedommod/httpd/HTTPDaemon.java | 13 +++++ .../httpd/module/Module_admins.java | 47 ++++++++++++++++++ .../httpd/module/Module_bans.java | 48 +++++++++++++++++++ .../totalfreedommod/util/FUtil.java | 2 +- 12 files changed, 138 insertions(+), 20 deletions(-) create mode 100644 src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_admins.java create mode 100644 src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_bans.java diff --git a/src/main/java/me/totalfreedom/totalfreedommod/EntityWiper.java b/src/main/java/me/totalfreedom/totalfreedommod/EntityWiper.java index b5dce0a9..ed6d8b0b 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/EntityWiper.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/EntityWiper.java @@ -26,6 +26,9 @@ import org.bukkit.entity.Minecart; import org.bukkit.entity.Projectile; import org.bukkit.entity.ThrownExpBottle; import org.bukkit.entity.ThrownPotion; +import org.bukkit.entity.DragonFireball; +import org.bukkit.entity.Fireball; +import org.bukkit.entity.EnderPearl; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.entity.ItemSpawnEvent; @@ -48,6 +51,7 @@ public class EntityWiper extends FreedomService super(plugin); wipables.add(EnderCrystal.class); wipables.add(EnderSignal.class); + wipables.add(EnderPearl.class); wipables.add(ExperienceOrb.class); wipables.add(Projectile.class); wipables.add(FallingBlock.class); @@ -60,6 +64,8 @@ public class EntityWiper extends FreedomService wipables.add(Boat.class); wipables.add(FallingBlock.class); wipables.add(ArmorStand.class); + wipables.add(Fireball.class); + wipables.add(DragonFireball.class); } @Override @@ -166,6 +172,7 @@ public class EntityWiper extends FreedomService for (Entity e : cel) { e.remove(); + removed++; } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java b/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java index 9a1d2e71..13b0a6fa 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java @@ -358,7 +358,7 @@ public class AdminList extends FreedomService if (verbose) { - FUtil.adminAction("TotalFreedomMod", "Deactivating superadmin " + admin.getName() + ", inactive for " + lastLoginHours + " hours", true); + FUtil.adminAction("TotalFreedomMod", "Deactivating admin " + admin.getName() + ", inactive for " + lastLoginHours + " hours", true); } admin.setActive(false); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_doom.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_doom.java index 55de2a64..9763fa54 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_doom.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_doom.java @@ -38,12 +38,14 @@ public class Command_doom extends FreedomCommand final String ip = player.getAddress().getAddress().getHostAddress().trim(); - // Remove from superadmin + // Remove from admin Admin admin = getAdmin(player); if (admin != null) { - FUtil.adminAction(sender.getName(), "Removing " + player.getName() + " from the superadmin list", true); - plugin.al.removeAdmin(admin); + FUtil.adminAction(sender.getName(), "Removing " + player.getName() + " from the admin list", true); + admin.setActive(false); + plugin.al.save(); + plugin.al.updateTables(); } // Remove from whitelist diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gtfo.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gtfo.java index 09b90f40..bced1639 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gtfo.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gtfo.java @@ -89,7 +89,8 @@ public class Command_gtfo extends FreedomCommand // Broadcast final StringBuilder bcast = new StringBuilder() .append(ChatColor.RED) - .append("Banning: ") + .append(sender.getName()) + .append(" - Banning ") .append(player.getName()) .append(", IP: ") .append(ip); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_opall.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_opall.java index 070bc2ca..6c25b53d 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_opall.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_opall.java @@ -38,7 +38,7 @@ public class Command_opall extends FreedomCommand player.setOp(true); player.sendMessage(FreedomCommand.YOU_ARE_OP); - if (doSetGamemode && !plugin.al.isAdmin(player)) + if (doSetGamemode && !player.getGameMode().equals(GameMode.SPECTATOR)) { player.setGameMode(targetGamemode); } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_radar.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_radar.java index 5384510d..30dba22b 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_radar.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_radar.java @@ -21,7 +21,7 @@ public class Command_radar extends FreedomCommand { Location playerSenderos = playerSender.getLocation(); - List radar_data = new ArrayList<>(); + List radar_data = new ArrayList<>(); for (Player player : playerSenderos.getWorld().getPlayers()) { @@ -29,7 +29,7 @@ public class Command_radar extends FreedomCommand { try { - radar_data.add(new TFM_RadarData(player, playerSenderos.distance(player.getLocation()), player.getLocation())); + radar_data.add(new RadarData(player, playerSenderos.distance(player.getLocation()), player.getLocation())); } catch (IllegalArgumentException ex) { @@ -43,7 +43,7 @@ public class Command_radar extends FreedomCommand return true; } - Collections.sort(radar_data, new TFM_RadarData()); + Collections.sort(radar_data, new RadarData()); msg("People nearby in " + playerSenderos.getWorld().getName() + ":", ChatColor.YELLOW); @@ -59,7 +59,7 @@ public class Command_radar extends FreedomCommand } } - for (TFM_RadarData i : radar_data) + for (RadarData i : radar_data) { msg(String.format("%s - %d", i.player.getName(), @@ -74,26 +74,26 @@ public class Command_radar extends FreedomCommand return true; } - private class TFM_RadarData implements Comparator + private class RadarData implements Comparator { public Player player; public double distance; public Location location; - public TFM_RadarData(Player player, double distance, Location location) + public RadarData(Player player, double distance, Location location) { this.player = player; this.distance = distance; this.location = location; } - public TFM_RadarData() + public RadarData() { } @Override - public int compare(TFM_RadarData t1, TFM_RadarData t2) + public int compare(RadarData t1, RadarData t2) { if (t1.distance > t2.distance) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_saconfig.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_saconfig.java index 92b7301f..aadafb33 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_saconfig.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_saconfig.java @@ -29,7 +29,7 @@ public class Command_saconfig extends FreedomCommand { case "list": { - msg("Superadmins: " + StringUtils.join(plugin.al.getAdminNames(), ", "), ChatColor.GOLD); + msg("Admins: " + StringUtils.join(plugin.al.getAdminNames(), ", "), ChatColor.GOLD); return true; } @@ -41,7 +41,7 @@ public class Command_saconfig extends FreedomCommand FUtil.adminAction(sender.getName(), "Cleaning admin list", true); plugin.al.deactivateOldEntries(true); - msg("Superadmins: " + StringUtils.join(plugin.al.getAdminNames(), ", "), ChatColor.GOLD); + msg("Admins: " + StringUtils.join(plugin.al.getAdminNames(), ", "), ChatColor.GOLD); return true; } @@ -124,7 +124,7 @@ public class Command_saconfig extends FreedomCommand if (admin == null) { - msg("Superadmin not found: " + args[1]); + msg("Admin not found: " + args[1]); } else { @@ -220,7 +220,7 @@ public class Command_saconfig extends FreedomCommand if (admin == null) { - msg("Superadmin not found: " + args[1]); + msg("Admin not found: " + args[1]); return true; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_verify.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_verify.java index 174309a2..317a9129 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_verify.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_verify.java @@ -65,7 +65,7 @@ public class Command_verify extends FreedomCommand { plugin.dc.VERIFY_CODES.remove(code); FUtil.bcastMsg(playerSender.getName() + " has verified themself!", ChatColor.GOLD); - FUtil.adminAction(ConfigEntry.SERVER_NAME.getString(), "Readding " + admin.getName() + " to the staff list", true); + FUtil.adminAction(ConfigEntry.SERVER_NAME.getString(), "Readding " + admin.getName() + " to the admin list", true); if (playerSender != null) { admin.setName(playerSender.getName()); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDaemon.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDaemon.java index fae0937c..7b970e2b 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDaemon.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDaemon.java @@ -13,10 +13,13 @@ import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.HTTPSession; import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.Response; import me.totalfreedom.totalfreedommod.httpd.module.HTTPDModule; +import me.totalfreedom.totalfreedommod.httpd.module.Module_admins; +import me.totalfreedom.totalfreedommod.httpd.module.Module_bans; import me.totalfreedom.totalfreedommod.httpd.module.Module_dump; import me.totalfreedom.totalfreedommod.httpd.module.Module_file; import me.totalfreedom.totalfreedommod.httpd.module.Module_help; import me.totalfreedom.totalfreedommod.httpd.module.Module_list; +import me.totalfreedom.totalfreedommod.httpd.module.Module_logfile; import me.totalfreedom.totalfreedommod.httpd.module.Module_logs; import me.totalfreedom.totalfreedommod.httpd.module.Module_permbans; import me.totalfreedom.totalfreedommod.httpd.module.Module_players; @@ -24,6 +27,7 @@ import me.totalfreedom.totalfreedommod.httpd.module.Module_schematic; import me.totalfreedom.totalfreedommod.util.FLog; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; +import org.apache.commons.io.FilenameUtils; public class HTTPDaemon extends FreedomService { @@ -53,10 +57,13 @@ public class HTTPDaemon extends FreedomService // Modules modules.clear(); + module("admins", Module_admins.class, true); + module("bans", Module_bans.class, true); module("dump", Module_dump.class, true); module("file", Module_file.class, true); module("help", Module_help.class, false); module("list", Module_list.class, false); + module("logfile", Module_logfile.class, true); module("logs", Module_logs.class, true); module("permbans", Module_permbans.class, true); module("players", Module_players.class, false); @@ -160,6 +167,12 @@ public class HTTPDaemon extends FreedomService { mimetype = MIME_DEFAULT_BINARY; } + + // Some browsers like firefox download the file for text/yaml mime types + if (FilenameUtils.getExtension(file.getName()).equals("yml")) + { + mimetype = NanoHTTPD.MIME_PLAINTEXT; + } response = new Response(Response.Status.OK, mimetype, new FileInputStream(file)); response.addHeader("Content-Length", "" + file.length()); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_admins.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_admins.java new file mode 100644 index 00000000..bee811c3 --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_admins.java @@ -0,0 +1,47 @@ +package me.totalfreedom.totalfreedommod.httpd.module; + +import java.io.File; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import me.totalfreedom.totalfreedommod.admin.Admin; +import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon; +import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD; + +public class Module_admins extends HTTPDModule +{ + + public Module_admins(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session) + { + super(plugin, session); + } + + @Override + public NanoHTTPD.Response getResponse() + { + File adminFile = new File(plugin.getDataFolder(), Admin.CONFIG_FILENAME); + if (adminFile.exists()) + { + final String remoteAddress = socket.getInetAddress().getHostAddress(); + if (!isAuthorized(remoteAddress)) + { + return new NanoHTTPD.Response(NanoHTTPD.Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT, + "You may not view the admin list, Your IP, " + remoteAddress + ", is not registered to an admin on the server."); + } + else + { + return HTTPDaemon.serveFileBasic(new File(plugin.getDataFolder(), Admin.CONFIG_FILENAME)); + } + + } + else + { + return new NanoHTTPD.Response(NanoHTTPD.Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT, + "Error 404: Not Found - The requested resource was not found on this server."); + } + } + + private boolean isAuthorized(String remoteAddress) + { + Admin entry = plugin.al.getEntryByIp(remoteAddress); + return entry != null && entry.isActive(); + } +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_bans.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_bans.java new file mode 100644 index 00000000..e51dfb2f --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_bans.java @@ -0,0 +1,48 @@ +package me.totalfreedom.totalfreedommod.httpd.module; + +import java.io.File; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import me.totalfreedom.totalfreedommod.admin.Admin; +import me.totalfreedom.totalfreedommod.banning.BanManager; +import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon; +import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD; + +public class Module_bans extends HTTPDModule +{ + + public Module_bans(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session) + { + super(plugin, session); + } + + @Override + public NanoHTTPD.Response getResponse() + { + File banFile = new File(plugin.getDataFolder(), BanManager.CONFIG_FILENAME); + if (banFile.exists()) + { + final String remoteAddress = socket.getInetAddress().getHostAddress(); + if (!isAuthorized(remoteAddress)) + { + return new NanoHTTPD.Response(NanoHTTPD.Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT, + "You may not view the ban list, Your IP, " + remoteAddress + ", is not registered to an admin on the server."); + } + else + { + return HTTPDaemon.serveFileBasic(new File(plugin.getDataFolder(), BanManager.CONFIG_FILENAME)); + } + + } + else + { + return new NanoHTTPD.Response(NanoHTTPD.Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT, + "Error 404: Not Found - The requested resource was not found on this server."); + } + } + + private boolean isAuthorized(String remoteAddress) + { + Admin entry = plugin.al.getEntryByIp(remoteAddress); + return entry != null && entry.isActive(); + } +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java b/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java index 424f986e..22e14b70 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java @@ -37,7 +37,7 @@ public class FUtil // public static final String SAVED_FLAGS_FILENAME = "savedflags.dat"; // See https://github.com/TotalFreedom/License - None of the listed names may be removed. - public static final List DEVELOPERS = Arrays.asList("Madgeek1450", "Prozza", "WickedGamingUK", "aggelosQQ", "OxLemonxO", "Commodore64x", "Wild1145"); + public static final List DEVELOPERS = Arrays.asList("Madgeek1450", "Prozza", "WickedGamingUK", "aggelosQQ", "OxLemonxO", "Commodore64x", "Wild1145", "marcocorriero"); public static String DATE_STORAGE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z"; public static final Map CHAT_COLOR_NAMES = new HashMap<>(); public static final List CHAT_COLOR_POOL = Arrays.asList(