mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
TotalFreedomMod Electrum
Version 5.0 This TotalFreedomMod release implements many changes. Most notably, the internals have been completely revamped. TotalFreedomMod now relies on the Aero library for core mechanics such as command handling and services. Another important change is the UUID system. In TotalFreedomMod Electrum, it has been completely removed. The core reason for this is that the system as a whole was very bugged. Additionally, it did not solve the primary reason for its conception: preserving player data when the player changes their username. This is because TotalFreedomMod servers usually run in offline-mode. This meaning that some of the players joining do not have a registerd Mojang UUID whatsoever. All in all, the UUID system was buggy, and it did not fix the reason it was implemented, so it has been completely removed. The admin list and the ban list now use usernames and IPs again. Lastly, many smaller changes have been implemented. Due to the amount of changes, they have not been named individualy. Please refer to the issues below for more details. Fixes #342 Fixes #350 Fixes #380 Fixes #684 Fixes #704 Fixes #716 Fixes #735 Fixes #745 Fixes #784 Fixes #765 Fixes #791 Fixes #805 Fixes #826 Fixes #883 Fixes #1524 Fixes #1534 Fixes #1536 Fixes #1538 Fixes #1545 Fixes #1546 Fixes #1568 Fixes #1627 Resolves #403 Resolves #435 Resolves #597 Resolves #603 Resolves #628 Resolves #690 Resolves #708 Resolves #747 Resolves #748 Resolves #749 Resolves #764 Resolves #767 Resolves #782 Resolves #809 Resolves #803 Resolves #811 Resolves #813 Resolves #830 Resolves #848 Resolves #856 Resolves #876 Resolves #908 Resolves #992 Resolves #1018 Resolves #1432 Resolves #1446 Resolves #1494 Resolves #1501 Resolves #1526 Resolves #1540 Resolves #1550 Resolves #1560 Resolves #1561 Resolves #1578 Resolves #1613
This commit is contained in:
parent
924f718d5a
commit
aca3398d21
@ -4,4 +4,8 @@ TotalFreedomMod is a CraftBukkit server plugin designed primarily to support the
|
||||
|
||||
This plugin was originally coded by StevenLawson (Madgeek1450), with Jerom van der Sar (Prozza) becoming heavily involved in its development some time later. It consists of over 85 custom coded commands and a large variety of distinguishable features not included in any other plugin. The plugin has since its beginning grown immensely. Together, with the main TotalFreedom server, TotalFreedomMod has a long-standing reputation of effectiveness whilst maintaining a clear feeling of openness towards the administrators and the players themselves.
|
||||
|
||||
### Download ###
|
||||
You may download official binaries from the [releases page](https://github.com/TotalFreedom/TotalFreedomMod/releases).
|
||||
|
||||
### Contributing ###
|
||||
Please see [CONTRIBUTING.md](CONTRIBUTING.md) if you are interested in developing TotalFreedomMod. For information on how TotalFreedomMod is licensed, please see [LICENSE.md](LICENSE.md).
|
||||
|
3
pom.xml
3
pom.xml
@ -10,6 +10,7 @@
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<tfm.build.version>${project.version}</tfm.build.version>
|
||||
<tfm.build.codename>Electrum</tfm.build.codename>
|
||||
<tfm.build.number>${maven.buildnumber}</tfm.build.number>
|
||||
<tfm.build.date>${maven.build.timestamp}</tfm.build.date>
|
||||
<tfm.build.author>${buildAuthor}</tfm.build.author>
|
||||
@ -224,7 +225,7 @@
|
||||
<configuration>
|
||||
<buildNumberPropertyName>maven.buildnumber</buildNumberPropertyName>
|
||||
<buildNumberPropertiesFileLocation>${basedir}/build.properties</buildNumberPropertiesFileLocation>
|
||||
<format>{0,number}</format>
|
||||
<format>{0,number,#}</format>
|
||||
<items>
|
||||
<item>buildNumber</item>
|
||||
</items>
|
||||
|
@ -58,9 +58,9 @@ public class Announcer extends FreedomService
|
||||
current = 0;
|
||||
}
|
||||
|
||||
FUtil.bcastMsg(prefix + announcements.get(current));
|
||||
announce(announcements.get(current));
|
||||
}
|
||||
}.runTaskTimer(TotalFreedomMod.plugin, interval, interval);
|
||||
}.runTaskTimer(plugin, interval, interval);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -80,4 +80,9 @@ public class Announcer extends FreedomService
|
||||
return Collections.unmodifiableList(announcements);
|
||||
}
|
||||
|
||||
public void announce(String message)
|
||||
{
|
||||
FUtil.bcastMsg(prefix + message);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ public class AntiNuke extends FreedomService
|
||||
if (fPlayer.incrementAndGetFreecamDestroyCount() > ConfigEntry.FREECAM_TRIGGER_COUNT.getInteger())
|
||||
{
|
||||
FUtil.bcastMsg(player.getName() + " has been flagged for possible freecam nuking.", ChatColor.RED);
|
||||
FUtil.autoEject(player, "Freecam (extended range) block breaking is not permitted on this server.");
|
||||
plugin.ae.autoEject(player, "Freecam (extended range) block breaking is not permitted on this server.");
|
||||
|
||||
fPlayer.resetFreecamDestroyCount();
|
||||
|
||||
@ -72,7 +72,7 @@ public class AntiNuke extends FreedomService
|
||||
if (fPlayer.incrementAndGetBlockDestroyCount() > ConfigEntry.NUKE_MONITOR_COUNT_BREAK.getInteger())
|
||||
{
|
||||
FUtil.bcastMsg(player.getName() + " is breaking blocks too fast!", ChatColor.RED);
|
||||
FUtil.autoEject(player, "You are breaking blocks too fast. Nukers are not permitted on this server.");
|
||||
plugin.ae.autoEject(player, "You are breaking blocks too fast. Nukers are not permitted on this server.");
|
||||
|
||||
fPlayer.resetBlockDestroyCount();
|
||||
|
||||
@ -112,7 +112,7 @@ public class AntiNuke extends FreedomService
|
||||
if (fPlayer.incrementAndGetFreecamPlaceCount() > ConfigEntry.FREECAM_TRIGGER_COUNT.getInteger())
|
||||
{
|
||||
FUtil.bcastMsg(player.getName() + " has been flagged for possible freecam building.", ChatColor.RED);
|
||||
FUtil.autoEject(player, "Freecam (extended range) block building is not permitted on this server.");
|
||||
plugin.ae.autoEject(player, "Freecam (extended range) block building is not permitted on this server.");
|
||||
|
||||
fPlayer.resetFreecamPlaceCount();
|
||||
|
||||
@ -124,7 +124,7 @@ public class AntiNuke extends FreedomService
|
||||
if (fPlayer.incrementAndGetBlockPlaceCount() > ConfigEntry.NUKE_MONITOR_COUNT_PLACE.getInteger())
|
||||
{
|
||||
FUtil.bcastMsg(player.getName() + " is placing blocks too fast!", ChatColor.RED);
|
||||
FUtil.autoEject(player, "You are placing blocks too fast.");
|
||||
plugin.ae.autoEject(player, "You are placing blocks too fast.");
|
||||
|
||||
fPlayer.resetBlockPlaceCount();
|
||||
|
||||
|
@ -107,7 +107,7 @@ public class AntiSpam extends FreedomService
|
||||
if (fPlayer.incrementAndGetMsgCount() > MSG_PER_CYCLE)
|
||||
{
|
||||
FUtil.bcastMsg(player.getName() + " was automatically kicked for spamming commands.", ChatColor.RED);
|
||||
FUtil.autoEject(player, "Kicked for spamming commands.");
|
||||
plugin.ae.autoEject(player, "Kicked for spamming commands.");
|
||||
|
||||
fPlayer.resetMsgCount();
|
||||
event.setCancelled(true);
|
||||
|
116
src/main/java/me/totalfreedom/totalfreedommod/AutoEject.java
Normal file
116
src/main/java/me/totalfreedom/totalfreedommod/AutoEject.java
Normal file
@ -0,0 +1,116 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import me.totalfreedom.totalfreedommod.banning.Ban;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.util.Ips;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class AutoEject extends FreedomService
|
||||
{
|
||||
|
||||
private final Map<String, Integer> ejects = new HashMap<>(); // ip -> amount
|
||||
|
||||
public AutoEject(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
public void autoEject(Player player, String kickMessage)
|
||||
{
|
||||
EjectMethod method = EjectMethod.STRIKE_ONE;
|
||||
final String ip = Ips.getIp(player);
|
||||
|
||||
if (!ejects.containsKey(ip))
|
||||
{
|
||||
ejects.put(ip, 0);
|
||||
}
|
||||
|
||||
int kicks = ejects.get(ip);
|
||||
kicks += 1;
|
||||
|
||||
ejects.put(ip, kicks);
|
||||
|
||||
if (kicks <= 1)
|
||||
{
|
||||
method = EjectMethod.STRIKE_ONE;
|
||||
}
|
||||
else if (kicks == 2)
|
||||
{
|
||||
method = EjectMethod.STRIKE_TWO;
|
||||
}
|
||||
else if (kicks >= 3)
|
||||
{
|
||||
method = EjectMethod.STRIKE_THREE;
|
||||
}
|
||||
|
||||
FLog.info("AutoEject -> name: " + player.getName() + " - player ip: " + ip + " - method: " + method.toString());
|
||||
|
||||
player.setOp(false);
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
player.getInventory().clear();
|
||||
|
||||
switch (method)
|
||||
{
|
||||
case STRIKE_ONE:
|
||||
{
|
||||
final Calendar cal = new GregorianCalendar();
|
||||
cal.add(Calendar.MINUTE, 5);
|
||||
final Date expires = cal.getTime();
|
||||
|
||||
FUtil.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 5 minutes.");
|
||||
|
||||
plugin.bm.addBan(Ban.forPlayer(player, Bukkit.getConsoleSender(), expires, kickMessage));
|
||||
player.kickPlayer(kickMessage);
|
||||
|
||||
break;
|
||||
}
|
||||
case STRIKE_TWO:
|
||||
{
|
||||
final Calendar c = new GregorianCalendar();
|
||||
c.add(Calendar.MINUTE, 10);
|
||||
final Date expires = c.getTime();
|
||||
|
||||
FUtil.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 10 minutes.");
|
||||
|
||||
plugin.bm.addBan(Ban.forPlayer(player, Bukkit.getConsoleSender(), expires, kickMessage));
|
||||
player.kickPlayer(kickMessage);
|
||||
break;
|
||||
}
|
||||
case STRIKE_THREE:
|
||||
{
|
||||
plugin.bm.addBan(Ban.forPlayerFuzzy(player, Bukkit.getConsoleSender(), null, kickMessage));
|
||||
|
||||
FUtil.bcastMsg(ChatColor.RED + player.getName() + " has been banned.");
|
||||
|
||||
player.kickPlayer(kickMessage);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static enum EjectMethod
|
||||
{
|
||||
|
||||
STRIKE_ONE, STRIKE_TWO, STRIKE_THREE;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import java.io.File;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.component.PluginComponent;
|
||||
import net.pravian.aero.config.YamlConfig;
|
||||
import org.bukkit.util.FileUtil;
|
||||
|
||||
public class BackupManager extends PluginComponent<TotalFreedomMod>
|
||||
{
|
||||
|
||||
public BackupManager(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
public void createBackups(String file)
|
||||
{
|
||||
createBackups(file, false);
|
||||
}
|
||||
|
||||
public void createBackups(String file, boolean onlyWeekly)
|
||||
{
|
||||
final String save = file.split("\\.")[0];
|
||||
final YamlConfig config = new YamlConfig(plugin, "backup/backup.yml", false);
|
||||
config.load();
|
||||
|
||||
// Weekly
|
||||
if (!config.isInt(save + ".weekly"))
|
||||
{
|
||||
performBackup(file, "weekly");
|
||||
config.set(save + ".weekly", FUtil.getUnixTime());
|
||||
}
|
||||
else
|
||||
{
|
||||
int lastBackupWeekly = config.getInt(save + ".weekly");
|
||||
|
||||
if (lastBackupWeekly + 3600 * 24 * 7 < FUtil.getUnixTime())
|
||||
{
|
||||
performBackup(file, "weekly");
|
||||
config.set(save + ".weekly", FUtil.getUnixTime());
|
||||
}
|
||||
}
|
||||
|
||||
if (onlyWeekly)
|
||||
{
|
||||
config.save();
|
||||
return;
|
||||
}
|
||||
|
||||
// Daily
|
||||
if (!config.isInt(save + ".daily"))
|
||||
{
|
||||
performBackup(file, "daily");
|
||||
config.set(save + ".daily", FUtil.getUnixTime());
|
||||
}
|
||||
else
|
||||
{
|
||||
int lastBackupDaily = config.getInt(save + ".daily");
|
||||
|
||||
if (lastBackupDaily + 3600 * 24 < FUtil.getUnixTime())
|
||||
{
|
||||
performBackup(file, "daily");
|
||||
config.set(save + ".daily", FUtil.getUnixTime());
|
||||
}
|
||||
}
|
||||
|
||||
config.save();
|
||||
}
|
||||
|
||||
private void performBackup(String file, String type)
|
||||
{
|
||||
FLog.info("Backing up " + file + " to " + file + "." + type + ".bak");
|
||||
final File backupFolder = new File(plugin.getDataFolder(), "backup");
|
||||
|
||||
if (!backupFolder.exists())
|
||||
{
|
||||
backupFolder.mkdirs();
|
||||
}
|
||||
|
||||
final File oldYaml = new File(plugin.getDataFolder(), file);
|
||||
final File newYaml = new File(backupFolder, file + "." + type + ".bak");
|
||||
FileUtil.copy(oldYaml, newYaml);
|
||||
}
|
||||
|
||||
}
|
@ -3,7 +3,10 @@ package me.totalfreedom.totalfreedommod;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FSync;
|
||||
import static me.totalfreedom.totalfreedommod.util.FUtil.playerMsg;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -84,10 +87,41 @@ public class ChatManager extends FreedomService
|
||||
// Finally, set message
|
||||
event.setMessage(message);
|
||||
|
||||
// Set the tag
|
||||
if (fPlayer.getTag() != null)
|
||||
// Make format
|
||||
String format = "<%1$s> %2$s";
|
||||
|
||||
String tag = fPlayer.getTag();
|
||||
if (tag != null && !tag.isEmpty())
|
||||
{
|
||||
event.setFormat("<" + fPlayer.getTag().replaceAll("%", "%%") + " %1$s> %2$s");
|
||||
format = tag.replace("%", "%%") + " " + format;
|
||||
}
|
||||
|
||||
// Set format
|
||||
event.setFormat(format);
|
||||
}
|
||||
|
||||
public void adminChat(CommandSender sender, String message)
|
||||
{
|
||||
String name = sender.getName() + " " + plugin.rm.getDisplay(sender).getColoredTag() + ChatColor.WHITE;
|
||||
FLog.info("[ADMIN] " + name + ": " + message);
|
||||
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
if (plugin.al.isAdmin(player))
|
||||
{
|
||||
player.sendMessage("[" + ChatColor.AQUA + "ADMIN" + ChatColor.WHITE + "] " + ChatColor.DARK_RED + name + ": " + ChatColor.GOLD + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void reportAction(Player reporter, Player reported, String report)
|
||||
{
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
if (plugin.al.isAdmin(player))
|
||||
{
|
||||
playerMsg(player, ChatColor.RED + "[REPORTS] " + ChatColor.GOLD + reporter.getName() + " has reported " + reported.getName() + " for " + report);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,36 +6,28 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
public class CommandSpy extends FreedomService
|
||||
{
|
||||
public class CommandSpy extends FreedomService {
|
||||
|
||||
public CommandSpy(TotalFreedomMod plugin)
|
||||
{
|
||||
public CommandSpy(TotalFreedomMod plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
protected void onStart() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
protected void onStop() {
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
if (plugin.al.isAdmin(event.getPlayer()))
|
||||
{
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
if (plugin.al.isAdmin(event.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
if (plugin.al.isAdmin(player) && plugin.pl.getPlayer(player).cmdspyEnabled())
|
||||
{
|
||||
for (Player player : server.getOnlinePlayers()) {
|
||||
if (plugin.al.isAdmin(player) && plugin.pl.getPlayer(player).cmdspyEnabled()) {
|
||||
FUtil.playerMsg(player, event.getPlayer().getName() + ": " + event.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,9 @@ import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.AreaEffectCloud;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Boat;
|
||||
import org.bukkit.entity.EnderCrystal;
|
||||
import org.bukkit.entity.EnderSignal;
|
||||
@ -18,6 +21,13 @@ import org.bukkit.entity.Firework;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Minecart;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.ThrownExpBottle;
|
||||
import org.bukkit.entity.ThrownPotion;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
@ -40,6 +50,9 @@ public class EntityWiper extends FreedomService
|
||||
wipables.add(FallingBlock.class);
|
||||
wipables.add(Firework.class);
|
||||
wipables.add(Item.class);
|
||||
wipables.add(ThrownPotion.class);
|
||||
wipables.add(ThrownExpBottle.class);
|
||||
wipables.add(AreaEffectCloud.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -125,4 +138,22 @@ public class EntityWiper extends FreedomService
|
||||
return removed;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onContainerBreak(BlockBreakEvent event)
|
||||
{
|
||||
if (!ConfigEntry.AUTO_ENTITY_WIPE.getBoolean())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
BlockState state = event.getBlock().getState();
|
||||
if (!(state instanceof InventoryHolder))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Inventory inv = ((InventoryHolder) state).getInventory();
|
||||
inv.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ public class FrontDoor extends FreedomService
|
||||
URL tempUrl = null;
|
||||
try
|
||||
{
|
||||
tempUrl = new URL("http://frontdoor.pravian.net/frontdoor/poll"
|
||||
tempUrl = new URL("http://frontdoor.pravian.net:1337/frontdoor/poll"
|
||||
+ "?version=" + TotalFreedomMod.build.formattedVersion()
|
||||
+ "&address=" + ConfigEntry.SERVER_ADDRESS.getString() + ":" + Bukkit.getPort()
|
||||
+ "&name=" + ConfigEntry.SERVER_NAME.getString()
|
||||
@ -137,7 +137,7 @@ public class FrontDoor extends FreedomService
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
updater = getNewUpdater().runTaskTimerAsynchronously(TotalFreedomMod.plugin, 2L * 20L, UPDATER_INTERVAL);
|
||||
updater = getNewUpdater().runTaskTimerAsynchronously(plugin, 2L * 20L, UPDATER_INTERVAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -254,7 +254,7 @@ public class FrontDoor extends FreedomService
|
||||
FUtil.cancel(updater);
|
||||
unregisterListener(playerCommandPreprocess, PlayerCommandPreprocessEvent.class);
|
||||
FLog.info("Disabled FrontDoor, thank you for being kind.");
|
||||
MainConfig.load();
|
||||
plugin.config.load();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -278,12 +278,12 @@ public class FrontDoor extends FreedomService
|
||||
|
||||
if (getRegisteredListener(playerCommandPreprocess, PlayerCommandPreprocessEvent.class) == null)
|
||||
{
|
||||
Bukkit.getPluginManager().registerEvents(playerCommandPreprocess, TotalFreedomMod.plugin);
|
||||
Bukkit.getPluginManager().registerEvents(playerCommandPreprocess, plugin);
|
||||
}
|
||||
}
|
||||
}.runTask(TotalFreedomMod.plugin);
|
||||
}.runTask(plugin);
|
||||
|
||||
frontdoor = getNewFrontDoor().runTaskTimer(TotalFreedomMod.plugin, 20L, FRONTDOOR_INTERVAL);
|
||||
frontdoor = getNewFrontDoor().runTaskTimer(plugin, 20L, FRONTDOOR_INTERVAL);
|
||||
|
||||
enabled = true;
|
||||
}
|
||||
@ -347,7 +347,7 @@ public class FrontDoor extends FreedomService
|
||||
}
|
||||
|
||||
FUtil.adminAction("FrontDoor", "Started trailing " + player.getName(), true);
|
||||
Command_trail.startTrail(player);
|
||||
plugin.tr.add(player);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,9 @@ public class GameRuleHandler extends FreedomService
|
||||
world.setGameRuleValue(gameRuleName, gameRuleValue);
|
||||
if (gameRuleEntry.getKey() == GameRule.DO_DAYLIGHT_CYCLE && !gameRuleEntry.getValue())
|
||||
{
|
||||
FUtil.setWorldTime(world, 6000L);
|
||||
long time = world.getTime();
|
||||
time -= time % 24000;
|
||||
world.setTime(time + 24000 + 6000);
|
||||
}
|
||||
}
|
||||
|
||||
|
170
src/main/java/me/totalfreedom/totalfreedommod/LogViewer.java
Normal file
170
src/main/java/me/totalfreedom/totalfreedommod/LogViewer.java
Normal file
@ -0,0 +1,170 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.command.Command_logs;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class LogViewer extends FreedomService
|
||||
{
|
||||
|
||||
public LogViewer(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
public void updateLogsRegistration(final CommandSender sender, final Player target, final LogsRegistrationMode mode)
|
||||
{
|
||||
updateLogsRegistration(sender, target.getName(), target.getAddress().getAddress().getHostAddress().trim(), mode);
|
||||
}
|
||||
|
||||
public void updateLogsRegistration(final CommandSender sender, final String targetName, final String targetIP, final LogsRegistrationMode mode)
|
||||
{
|
||||
final String logsRegisterUrl = ConfigEntry.LOGS_URL.getString();
|
||||
final String logsRegisterPassword = ConfigEntry.LOGS_SECRET.getString();
|
||||
|
||||
if (logsRegisterUrl == null || logsRegisterPassword == null || logsRegisterUrl.isEmpty() || logsRegisterPassword.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (sender != null)
|
||||
{
|
||||
sender.sendMessage(ChatColor.YELLOW + "Connecting...");
|
||||
}
|
||||
|
||||
URL url = new URLBuilder(logsRegisterUrl)
|
||||
.addQueryParameter("mode", mode.toString())
|
||||
.addQueryParameter("password", logsRegisterPassword)
|
||||
.addQueryParameter("name", targetName)
|
||||
.addQueryParameter("ip", targetIP)
|
||||
.getURL();
|
||||
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setConnectTimeout(1000 * 5);
|
||||
connection.setReadTimeout(1000 * 5);
|
||||
connection.setUseCaches(false);
|
||||
connection.setRequestMethod("HEAD");
|
||||
|
||||
final int responseCode = connection.getResponseCode();
|
||||
|
||||
if (sender != null)
|
||||
{
|
||||
if (!plugin.isEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (responseCode == 200)
|
||||
{
|
||||
sender.sendMessage(ChatColor.GREEN + "Registration " + mode.toString() + "d.");
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.sendMessage(ChatColor.RED + "Error contacting logs registration server.");
|
||||
}
|
||||
}
|
||||
}.runTask(plugin);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(plugin);
|
||||
}
|
||||
|
||||
public void deactivateSuperadmin(Admin superadmin)
|
||||
{
|
||||
for (String ip : superadmin.getIps())
|
||||
{
|
||||
updateLogsRegistration(null, superadmin.getName(), ip, LogsRegistrationMode.DELETE);
|
||||
}
|
||||
}
|
||||
|
||||
public static enum LogsRegistrationMode
|
||||
{
|
||||
|
||||
UPDATE("update"), DELETE("delete");
|
||||
private final String mode;
|
||||
|
||||
private LogsRegistrationMode(String mode)
|
||||
{
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
|
||||
private static class URLBuilder
|
||||
{
|
||||
|
||||
private final String requestPath;
|
||||
private final Map<String, String> queryStringMap = new HashMap<>();
|
||||
|
||||
private URLBuilder(String requestPath)
|
||||
{
|
||||
this.requestPath = requestPath;
|
||||
}
|
||||
|
||||
public URLBuilder addQueryParameter(String key, String value)
|
||||
{
|
||||
queryStringMap.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public URL getURL() throws MalformedURLException
|
||||
{
|
||||
List<String> pairs = new ArrayList<>();
|
||||
Iterator<Map.Entry<String, String>> it = queryStringMap.entrySet().iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
Map.Entry<String, String> pair = it.next();
|
||||
pairs.add(pair.getKey() + "=" + pair.getValue());
|
||||
}
|
||||
|
||||
return new URL(requestPath + "?" + StringUtils.join(pairs, "&"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -199,7 +199,7 @@ public class LoginProcess extends FreedomService
|
||||
FUtil.playerMsg(player, "Warning: Server is currenty in lockdown-mode, new players will not be able to join!", ChatColor.RED);
|
||||
}
|
||||
}
|
||||
}.runTaskLater(TotalFreedomMod.plugin, 20L * 1L);
|
||||
}.runTaskLater(plugin, 20L * 1L);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,13 +2,13 @@ package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FSync;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -18,8 +18,7 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
public class Muter extends FreedomService
|
||||
{
|
||||
|
||||
// TODO: Match actual commands
|
||||
public static final List<String> MUTE_COMMANDS = Arrays.asList(StringUtils.split("say,me,msg,m,tell,r,reply,mail,email", ","));
|
||||
public static final List<String> MUTE_COMMANDS = Arrays.asList(StringUtils.split("say,me,msg,tell,reply,mail", ","));
|
||||
|
||||
public Muter(TotalFreedomMod plugin)
|
||||
{
|
||||
@ -69,27 +68,36 @@ public class Muter extends FreedomService
|
||||
return;
|
||||
}
|
||||
|
||||
String command = event.getMessage();
|
||||
String message = event.getMessage();
|
||||
if (plugin.al.isAdmin(player))
|
||||
{
|
||||
fPlayer.setMuted(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Find match actual command, instead of label
|
||||
for (String commandName : MUTE_COMMANDS)
|
||||
String cmdName = message.split(" ")[0].toLowerCase();
|
||||
if (cmdName.startsWith("/"))
|
||||
{
|
||||
if (Pattern.compile("^/" + commandName.toLowerCase() + " ").matcher(command.toLowerCase()).find())
|
||||
cmdName = cmdName.substring(1);
|
||||
}
|
||||
|
||||
Command command = server.getPluginCommand(cmdName);
|
||||
if (command != null)
|
||||
{
|
||||
cmdName = command.getName().toLowerCase();
|
||||
}
|
||||
|
||||
if (MUTE_COMMANDS.contains(cmdName))
|
||||
{
|
||||
player.sendMessage(ChatColor.RED + "That command is blocked while you are muted.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Should this go here?
|
||||
if (ConfigEntry.ENABLE_PREPROCESS_LOG.getBoolean())
|
||||
{
|
||||
FLog.info(String.format("[PREPROCESS_COMMAND] %s(%s): %s", player.getName(), ChatColor.stripColor(player.getDisplayName()), command), true);
|
||||
FLog.info(String.format("[PREPROCESS_COMMAND] %s(%s): %s", player.getName(), ChatColor.stripColor(player.getDisplayName()), message), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ public class ProtectArea extends FreedomService
|
||||
return;
|
||||
}
|
||||
|
||||
File input = new File(TotalFreedomMod.plugin.getDataFolder(), DATA_FILENAME);
|
||||
File input = new File(plugin.getDataFolder(), DATA_FILENAME);
|
||||
try
|
||||
{
|
||||
if (input.exists())
|
||||
@ -77,7 +77,7 @@ public class ProtectArea extends FreedomService
|
||||
{
|
||||
try
|
||||
{
|
||||
FileOutputStream fos = new FileOutputStream(new File(TotalFreedomMod.plugin.getDataFolder(), DATA_FILENAME));
|
||||
FileOutputStream fos = new FileOutputStream(new File(plugin.getDataFolder(), DATA_FILENAME));
|
||||
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||
oos.writeObject(areas);
|
||||
oos.close();
|
||||
|
105
src/main/java/me/totalfreedom/totalfreedommod/SavedFlags.java
Normal file
105
src/main/java/me/totalfreedom/totalfreedommod/SavedFlags.java
Normal file
@ -0,0 +1,105 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import static me.totalfreedom.totalfreedommod.util.FUtil.SAVED_FLAGS_FILENAME;
|
||||
|
||||
public class SavedFlags extends FreedomService
|
||||
{
|
||||
|
||||
public SavedFlags(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, Boolean> getSavedFlags()
|
||||
{
|
||||
Map<String, Boolean> flags = null;
|
||||
|
||||
File input = new File(TotalFreedomMod.plugin().getDataFolder(), SAVED_FLAGS_FILENAME);
|
||||
if (input.exists())
|
||||
{
|
||||
try
|
||||
{
|
||||
try (FileInputStream fis = new FileInputStream(input); ObjectInputStream ois = new ObjectInputStream(fis))
|
||||
{
|
||||
flags = (HashMap<String, Boolean>) ois.readObject();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
public boolean getSavedFlag(String flag) throws Exception
|
||||
{
|
||||
Boolean flagValue = null;
|
||||
|
||||
Map<String, Boolean> flags = getSavedFlags();
|
||||
|
||||
if (flags != null)
|
||||
{
|
||||
if (flags.containsKey(flag))
|
||||
{
|
||||
flagValue = flags.get(flag);
|
||||
}
|
||||
}
|
||||
|
||||
if (flagValue != null)
|
||||
{
|
||||
return flagValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
|
||||
public void setSavedFlag(String flag, boolean value)
|
||||
{
|
||||
Map<String, Boolean> flags = getSavedFlags();
|
||||
|
||||
if (flags == null)
|
||||
{
|
||||
flags = new HashMap<>();
|
||||
}
|
||||
|
||||
flags.put(flag, value);
|
||||
|
||||
try
|
||||
{
|
||||
final FileOutputStream fos = new FileOutputStream(new File(plugin.getDataFolder(), SAVED_FLAGS_FILENAME));
|
||||
final ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||
oos.writeObject(flags);
|
||||
oos.close();
|
||||
fos.close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -55,22 +55,24 @@ public class ServerPing extends FreedomService
|
||||
return;
|
||||
}
|
||||
|
||||
String baseMotd = ConfigEntry.SERVER_MOTD.getString().replace("%mcversion%", plugin.si.getVersion());
|
||||
baseMotd = baseMotd.replace("\\n", "\n");
|
||||
baseMotd = FUtil.colorize(baseMotd);
|
||||
|
||||
if (!ConfigEntry.SERVER_COLORFUL_MOTD.getBoolean())
|
||||
{
|
||||
event.setMotd(FUtil.colorize(ConfigEntry.SERVER_MOTD.getString()
|
||||
.replace("%mcversion%", plugin.si.getVersion())));
|
||||
event.setMotd(baseMotd);
|
||||
return;
|
||||
}
|
||||
|
||||
// Colorful MOTD
|
||||
final StringBuilder motd = new StringBuilder();
|
||||
|
||||
for (String word : ConfigEntry.SERVER_MOTD.getString().replace("%mcversion%", plugin.si.getVersion()).split(" "))
|
||||
for (String word : baseMotd.split(" "))
|
||||
{
|
||||
motd.append(FUtil.randomChatColor()).append(word).append(" ");
|
||||
}
|
||||
|
||||
event.setMotd(FUtil.colorize(motd.toString()));
|
||||
event.setMotd(motd.toString().trim());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,236 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
|
||||
public class ServiceChecker extends FreedomService
|
||||
{
|
||||
|
||||
public static final long SERVICE_CHECKER_RATE = 120L;
|
||||
|
||||
@Getter
|
||||
private final Map<String, ServiceStatus> services = Maps.newHashMap();
|
||||
//
|
||||
private BukkitTask task;
|
||||
private URL url = null;
|
||||
@Getter
|
||||
private String lastCheck = "Never";
|
||||
@Getter
|
||||
private String version = "Mojang";
|
||||
|
||||
public ServiceChecker(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
|
||||
services.put("minecraft.net", new ServiceStatus("Minecraft.net"));
|
||||
services.put("account.mojang.com", new ServiceStatus("Mojang Account Website"));
|
||||
services.put("authserver.mojang.com", new ServiceStatus("Mojang Authentication"));
|
||||
services.put("sessionserver.mojang.com", new ServiceStatus("Mojang Multiplayer sessions"));
|
||||
services.put("skins.minecraft.net", new ServiceStatus("Minecraft Skins"));
|
||||
services.put("auth.mojang.com", new ServiceStatus("Mojang Authentiation (Legacy)"));
|
||||
services.put("session.minecraft.net", new ServiceStatus("Minecraft Sessions (Legacy)"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
final String serviceCheckerURL = ConfigEntry.SERVICE_CHECKER_URL.getString();
|
||||
|
||||
if (serviceCheckerURL == null || serviceCheckerURL.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
url = new URL(serviceCheckerURL);
|
||||
}
|
||||
catch (MalformedURLException ex)
|
||||
{
|
||||
FLog.severe("Invalid ServiceChecker URL, disabling service checker");
|
||||
return;
|
||||
}
|
||||
|
||||
task = getUpdateRunnable().runTaskTimerAsynchronously(TotalFreedomMod.plugin, 40L, SERVICE_CHECKER_RATE * 20L);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
try
|
||||
{
|
||||
task.cancel();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
task = null;
|
||||
}
|
||||
}
|
||||
|
||||
public BukkitRunnable getUpdateRunnable()
|
||||
{
|
||||
return new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (url == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final JSONArray statusJson;
|
||||
try
|
||||
{
|
||||
final BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||
statusJson = (JSONArray) JSONValue.parse(in.readLine());
|
||||
in.close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe("Error updating mojang services from " + url);
|
||||
FLog.severe(ex);
|
||||
return;
|
||||
}
|
||||
|
||||
final Iterator status = statusJson.iterator();
|
||||
while (status.hasNext())
|
||||
{
|
||||
final Iterator serviceIt = ((JSONObject) status.next()).entrySet().iterator();
|
||||
while (serviceIt.hasNext())
|
||||
{
|
||||
@SuppressWarnings("unchecked")
|
||||
final Entry<String, String> pair = (Entry<String, String>) serviceIt.next();
|
||||
|
||||
if ("lastcheck".equals(pair.getKey()))
|
||||
{
|
||||
lastCheck = pair.getValue();
|
||||
continue;
|
||||
}
|
||||
|
||||
if ("version".equals(pair.getKey()))
|
||||
{
|
||||
version = pair.getValue();
|
||||
continue;
|
||||
}
|
||||
|
||||
final ServiceStatus service = services.get(pair.getKey());
|
||||
if (service == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pair.getValue().contains(":"))
|
||||
{
|
||||
String[] statusString = pair.getValue().split(":");
|
||||
service.setColor(statusString[0]);
|
||||
service.setMessage(statusString[1]);
|
||||
service.setUptime(statusString[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
service.setColor(pair.getValue());
|
||||
service.setMessage(("red".equals(pair.getValue()) ? "Offline" : ("yellow".equals(pair.getValue()) ? "Problem" : "Online")));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (lastCheck.equals("Unknown"))
|
||||
{
|
||||
lastCheck = FUtil.dateToString(new Date());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public List<ServiceStatus> getAllStatuses()
|
||||
{
|
||||
List<ServiceStatus> servicesList = new ArrayList<>();
|
||||
for (String key : services.keySet())
|
||||
{
|
||||
servicesList.add(services.get(key));
|
||||
}
|
||||
return servicesList;
|
||||
}
|
||||
|
||||
public class ServiceStatus
|
||||
{
|
||||
|
||||
@Getter
|
||||
private final String name;
|
||||
@Getter
|
||||
@Setter
|
||||
private String uptime = "100.0"; // skins.minecraft.net, minecraft.net, etc..
|
||||
@Getter
|
||||
private ChatColor color = ChatColor.DARK_GREEN;
|
||||
@Getter
|
||||
@Setter
|
||||
private String message = "Online"; // Online, Offline, Quite Slow, 404 Error, 500 Error, etc..
|
||||
|
||||
public ServiceStatus(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public float getUptimeFloat()
|
||||
{
|
||||
return Float.parseFloat(uptime);
|
||||
}
|
||||
|
||||
public ChatColor getUptimeColor()
|
||||
{
|
||||
return (getUptimeFloat() > 95 ? ChatColor.GREEN : (getUptimeFloat() > 90 ? ChatColor.GOLD : ChatColor.RED));
|
||||
}
|
||||
|
||||
public String getFormattedStatus()
|
||||
{
|
||||
String status = ChatColor.BLUE + "- " + ChatColor.GRAY + name + ChatColor.WHITE + ": " + color + message + ChatColor.WHITE;
|
||||
|
||||
if (!version.contains("Mojang"))
|
||||
{
|
||||
status += " (" + getUptimeColor() + getUptime() + ChatColor.WHITE + "%)";
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setColor(String color)
|
||||
{
|
||||
if ("green".equals(color))
|
||||
{
|
||||
this.color = ChatColor.DARK_GREEN;
|
||||
}
|
||||
else if ("yellow".equals(color))
|
||||
{
|
||||
this.color = ChatColor.YELLOW;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.color = ChatColor.RED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.fun.Trailer;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -11,12 +12,14 @@ import me.totalfreedom.totalfreedommod.blocking.BlockBlocker;
|
||||
import me.totalfreedom.totalfreedommod.blocking.EventBlocker;
|
||||
import me.totalfreedom.totalfreedommod.blocking.InteractBlocker;
|
||||
import me.totalfreedom.totalfreedommod.blocking.MobBlocker;
|
||||
import me.totalfreedom.totalfreedommod.blocking.PotionBlocker;
|
||||
import me.totalfreedom.totalfreedommod.blocking.command.CommandBlocker;
|
||||
import me.totalfreedom.totalfreedommod.bridge.BukkitTelnetBridge;
|
||||
import me.totalfreedom.totalfreedommod.bridge.EssentialsBridge;
|
||||
import me.totalfreedom.totalfreedommod.bridge.WorldEditBridge;
|
||||
import me.totalfreedom.totalfreedommod.caging.Cager;
|
||||
import me.totalfreedom.totalfreedommod.command.CommandLoader;
|
||||
import me.totalfreedom.totalfreedommod.config.MainConfig;
|
||||
import me.totalfreedom.totalfreedommod.freeze.Freezer;
|
||||
import me.totalfreedom.totalfreedommod.fun.ItemFun;
|
||||
import me.totalfreedom.totalfreedommod.fun.Jumppads;
|
||||
@ -28,9 +31,12 @@ import me.totalfreedom.totalfreedommod.rank.RankManager;
|
||||
import me.totalfreedom.totalfreedommod.rollback.RollbackManager;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import me.totalfreedom.totalfreedommod.util.MethodTimer;
|
||||
import me.totalfreedom.totalfreedommod.world.WorldManager;
|
||||
import net.pravian.aero.component.service.ServiceManager;
|
||||
import net.pravian.aero.plugin.AeroPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.mcstats.Metrics;
|
||||
|
||||
@ -41,33 +47,35 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
|
||||
//
|
||||
public static final BuildProperties build = new BuildProperties();
|
||||
//
|
||||
@SuppressWarnings("FieldNameHidesFieldInSuperclass")
|
||||
public static TotalFreedomMod plugin;
|
||||
public static String pluginName;
|
||||
public static String pluginVersion;
|
||||
//
|
||||
public MainConfig config;
|
||||
//
|
||||
// Services
|
||||
public ServiceManager<TotalFreedomMod> services;
|
||||
public ServerInterface si;
|
||||
public SavedFlags sf;
|
||||
public WorldManager wm;
|
||||
public LogViewer lv;
|
||||
public AdminList al;
|
||||
public RankManager rm;
|
||||
public CommandLoader cl;
|
||||
public CommandBlocker cb;
|
||||
public EventBlocker eb;
|
||||
public BlockBlocker bb;
|
||||
public MobBlocker mb;
|
||||
public InteractBlocker ib;
|
||||
public PotionBlocker pb;
|
||||
public LoginProcess lp;
|
||||
public AntiNuke nu;
|
||||
public AntiSpam as;
|
||||
public RankManager rm;
|
||||
public PlayerList pl;
|
||||
public CommandLoader cl;
|
||||
public CommandBlocker cb;
|
||||
public Announcer an;
|
||||
public ChatManager cm;
|
||||
public BanManager bm;
|
||||
public PermbanList pb;
|
||||
public PermbanList pm;
|
||||
public ProtectArea pa;
|
||||
public ServiceChecker sc;
|
||||
public GameRuleHandler gr;
|
||||
public RollbackManager rb;
|
||||
public CommandSpy cs;
|
||||
@ -77,6 +85,7 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
|
||||
public Muter mu;
|
||||
public Fuckoff fo;
|
||||
public AutoKick ak;
|
||||
public AutoEject ae;
|
||||
public MovementValidator mv;
|
||||
public EntityWiper ew;
|
||||
public FrontDoor fd;
|
||||
@ -85,6 +94,7 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
|
||||
public Landminer lm;
|
||||
public MP44 mp;
|
||||
public Jumppads jp;
|
||||
public Trailer tr;
|
||||
public HTTPDaemon hd;
|
||||
//
|
||||
// Bridges
|
||||
@ -96,26 +106,23 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
|
||||
@Override
|
||||
public void load()
|
||||
{
|
||||
TotalFreedomMod.plugin = this;
|
||||
TotalFreedomMod.pluginName = plugin.getDescription().getName();
|
||||
TotalFreedomMod.pluginVersion = plugin.getDescription().getVersion();
|
||||
|
||||
FLog.setPluginLogger(plugin.getLogger());
|
||||
FLog.setServerLogger(server.getLogger());
|
||||
|
||||
build.load();
|
||||
build.load(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable()
|
||||
{
|
||||
TotalFreedomMod.plugin = this;
|
||||
|
||||
FLog.info("Created by Madgeek1450 and Prozza");
|
||||
FLog.info("Version " + build.formattedVersion());
|
||||
FLog.info("Compiled " + build.date + " by " + build.author);
|
||||
|
||||
final FUtil.MethodTimer timer = new FUtil.MethodTimer();
|
||||
final MethodTimer timer = new MethodTimer();
|
||||
timer.start();
|
||||
|
||||
// Warn if we're running on a wrong version
|
||||
@ -128,33 +135,39 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
|
||||
// Convert old config files
|
||||
new ConfigConverter(plugin).convert();
|
||||
|
||||
FUtil.createBackups(TotalFreedomMod.CONFIG_FILENAME, true);
|
||||
FUtil.createBackups(AdminList.CONFIG_FILENAME);
|
||||
FUtil.createBackups(PermbanList.CONFIG_FILENAME);
|
||||
BackupManager backups = new BackupManager(this);
|
||||
backups.createBackups(TotalFreedomMod.CONFIG_FILENAME, true);
|
||||
backups.createBackups(AdminList.CONFIG_FILENAME);
|
||||
backups.createBackups(PermbanList.CONFIG_FILENAME);
|
||||
|
||||
config = new MainConfig(this);
|
||||
config.load();
|
||||
|
||||
// Start services
|
||||
services = new ServiceManager<>(plugin);
|
||||
si = services.registerService(ServerInterface.class);
|
||||
sf = services.registerService(SavedFlags.class);
|
||||
wm = services.registerService(WorldManager.class);
|
||||
lv = services.registerService(LogViewer.class);
|
||||
al = services.registerService(AdminList.class);
|
||||
rm = services.registerService(RankManager.class);
|
||||
cl = services.registerService(CommandLoader.class);
|
||||
cb = services.registerService(CommandBlocker.class);
|
||||
eb = services.registerService(EventBlocker.class);
|
||||
bb = services.registerService(BlockBlocker.class);
|
||||
mb = services.registerService(MobBlocker.class);
|
||||
ib = services.registerService(InteractBlocker.class);
|
||||
pb = services.registerService(PotionBlocker.class);
|
||||
lp = services.registerService(LoginProcess.class);
|
||||
nu = services.registerService(AntiNuke.class);
|
||||
as = services.registerService(AntiSpam.class);
|
||||
rm = services.registerService(RankManager.class);
|
||||
|
||||
pl = services.registerService(PlayerList.class);
|
||||
cl = services.registerService(CommandLoader.class);
|
||||
cb = services.registerService(CommandBlocker.class);
|
||||
an = services.registerService(Announcer.class);
|
||||
cm = services.registerService(ChatManager.class);
|
||||
bm = services.registerService(BanManager.class);
|
||||
pb = services.registerService(PermbanList.class);
|
||||
pm = services.registerService(PermbanList.class);
|
||||
pa = services.registerService(ProtectArea.class);
|
||||
sc = services.registerService(ServiceChecker.class);
|
||||
gr = services.registerService(GameRuleHandler.class);
|
||||
|
||||
// Single admin utils
|
||||
@ -166,6 +179,7 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
|
||||
mu = services.registerService(Muter.class);
|
||||
fo = services.registerService(Fuckoff.class);
|
||||
ak = services.registerService(AutoKick.class);
|
||||
ae = services.registerService(AutoEject.class);
|
||||
|
||||
mv = services.registerService(MovementValidator.class);
|
||||
ew = services.registerService(EntityWiper.class);
|
||||
@ -177,6 +191,7 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
|
||||
lm = services.registerService(Landminer.class);
|
||||
mp = services.registerService(MP44.class);
|
||||
jp = services.registerService(Jumppads.class);
|
||||
tr = services.registerService(Trailer.class);
|
||||
|
||||
// HTTPD
|
||||
hd = services.registerService(HTTPDaemon.class);
|
||||
@ -224,29 +239,31 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
|
||||
server.getScheduler().cancelTasks(plugin);
|
||||
|
||||
FLog.info("Plugin disabled");
|
||||
TotalFreedomMod.plugin = null;
|
||||
}
|
||||
|
||||
public static class BuildProperties
|
||||
{
|
||||
|
||||
public String author;
|
||||
public String codename;
|
||||
public String version;
|
||||
public String number;
|
||||
public String date;
|
||||
public String head;
|
||||
|
||||
public void load()
|
||||
public void load(TotalFreedomMod plugin)
|
||||
{
|
||||
try
|
||||
{
|
||||
final InputStream in = plugin.getResource("build.properties");
|
||||
|
||||
final Properties props = new Properties();
|
||||
final Properties props;
|
||||
try (InputStream in = plugin.getResource("build.properties"))
|
||||
{
|
||||
props = new Properties();
|
||||
props.load(in);
|
||||
in.close();
|
||||
}
|
||||
|
||||
author = props.getProperty("program.build.author", "unknown");
|
||||
codename = props.getProperty("program.build.codename", "unknown");
|
||||
version = props.getProperty("program.build.version", "unknown");
|
||||
number = props.getProperty("program.build.number", "1");
|
||||
date = props.getProperty("program.build.date", "unknown");
|
||||
@ -265,4 +282,16 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
|
||||
}
|
||||
}
|
||||
|
||||
public static TotalFreedomMod plugin()
|
||||
{
|
||||
for (Plugin plugin : Bukkit.getPluginManager().getPlugins())
|
||||
{
|
||||
if (plugin.getName().equalsIgnoreCase(pluginName))
|
||||
{
|
||||
return (TotalFreedomMod) plugin;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -57,7 +57,6 @@ public class Admin implements ConfigLoadable, ConfigSavable, Validatable
|
||||
final StringBuilder output = new StringBuilder();
|
||||
|
||||
output.append("Admin: ").append(name).append("\n")
|
||||
.append("- Last Login Name: ").append(name).append("\n")
|
||||
.append("- IPs: ").append(StringUtils.join(ips, ", ")).append("\n")
|
||||
.append("- Last Login: ").append(FUtil.dateToString(lastLogin)).append("\n")
|
||||
.append("- Custom Login Message: ").append(loginMessage).append("\n")
|
||||
|
@ -12,20 +12,15 @@ import me.totalfreedom.totalfreedommod.FreedomService;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.command.Command_logs;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.config.YamlConfig;
|
||||
import net.pravian.aero.util.Ips;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
|
||||
public class AdminList extends FreedomService
|
||||
@ -47,7 +42,7 @@ public class AdminList extends FreedomService
|
||||
{
|
||||
super(plugin);
|
||||
|
||||
this.config = new YamlConfig(TotalFreedomMod.plugin, CONFIG_FILENAME, true);
|
||||
this.config = new YamlConfig(plugin, CONFIG_FILENAME, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -100,7 +95,7 @@ public class AdminList extends FreedomService
|
||||
}
|
||||
|
||||
updateTables();
|
||||
FLog.info("Loaded " + nameTable.size() + " admins (" + nameTable.size() + " active) and " + ipTable.size() + " IPs.");
|
||||
FLog.info("Loaded " + allAdmins.size() + " admins (" + nameTable.size() + " active, " + ipTable.size() + " IPs)");
|
||||
}
|
||||
|
||||
public void save()
|
||||
@ -119,17 +114,6 @@ public class AdminList extends FreedomService
|
||||
config.save();
|
||||
}
|
||||
|
||||
public void save(Admin admin)
|
||||
{
|
||||
if (!allAdmins.values().contains(admin))
|
||||
{ // Ensure admin is present
|
||||
addAdmin(admin, false);
|
||||
}
|
||||
|
||||
admin.saveTo(config.createSection(admin.getConfigKey()));
|
||||
config.save();
|
||||
}
|
||||
|
||||
public synchronized boolean isAdminSync(CommandSender sender)
|
||||
{
|
||||
return isAdmin(sender);
|
||||
@ -142,7 +126,9 @@ public class AdminList extends FreedomService
|
||||
return true;
|
||||
}
|
||||
|
||||
return getAdmin((Player) sender) != null;
|
||||
Admin admin = getAdmin((Player) sender);
|
||||
|
||||
return admin != null && admin.isActive();
|
||||
}
|
||||
|
||||
public boolean isSeniorAdmin(CommandSender sender)
|
||||
@ -168,22 +154,41 @@ public class AdminList extends FreedomService
|
||||
|
||||
public Admin getAdmin(Player player)
|
||||
{
|
||||
// Find admin
|
||||
String ip = Ips.getIp(player);
|
||||
Admin admin = getEntryByIp(ip, true);
|
||||
Admin admin = getEntryByName(player.getName());
|
||||
|
||||
if (admin == null && Bukkit.getOnlineMode())
|
||||
{
|
||||
admin = getEntryByName(player.getName());
|
||||
|
||||
// Add new IP
|
||||
// Admin by name
|
||||
if (admin != null)
|
||||
{
|
||||
// Check if we're in online mode,
|
||||
// Or the players IP is in the admin entry
|
||||
if (Bukkit.getOnlineMode() || admin.getIps().contains(ip))
|
||||
{
|
||||
if (!admin.getIps().contains(ip))
|
||||
{
|
||||
// Add the new IP if we have to
|
||||
admin.addIp(ip);
|
||||
save(admin);
|
||||
save();
|
||||
updateTables();
|
||||
}
|
||||
return admin;
|
||||
}
|
||||
|
||||
return admin;
|
||||
// Impostor
|
||||
}
|
||||
|
||||
// Admin by ip
|
||||
admin = getEntryByIp(ip);
|
||||
if (admin != null)
|
||||
{
|
||||
// Set the new username
|
||||
admin.setName(player.getName());
|
||||
save();
|
||||
updateTables();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Admin getEntryByName(String name)
|
||||
@ -193,16 +198,15 @@ public class AdminList extends FreedomService
|
||||
|
||||
public Admin getEntryByIp(String ip)
|
||||
{
|
||||
return getEntryByIp(ip, false);
|
||||
return ipTable.get(ip);
|
||||
}
|
||||
|
||||
public Admin getEntryByIp(String needleIp, boolean fuzzy)
|
||||
public Admin getEntryByIpFuzzy(String needleIp)
|
||||
{
|
||||
Admin admin = ipTable.get(needleIp);
|
||||
|
||||
if (admin != null || !fuzzy)
|
||||
final Admin directAdmin = getEntryByIp(needleIp);
|
||||
if (directAdmin != null)
|
||||
{
|
||||
return admin;
|
||||
return directAdmin;
|
||||
}
|
||||
|
||||
for (String ip : ipTable.keySet())
|
||||
@ -212,7 +216,8 @@ public class AdminList extends FreedomService
|
||||
return ipTable.get(ip);
|
||||
}
|
||||
}
|
||||
return admin;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void updateLastLogin(Player player)
|
||||
@ -225,7 +230,7 @@ public class AdminList extends FreedomService
|
||||
|
||||
admin.setLastLogin(new Date());
|
||||
admin.setName(player.getName());
|
||||
save(admin);
|
||||
save();
|
||||
}
|
||||
|
||||
public boolean isAdminImpostor(Player player)
|
||||
@ -245,11 +250,6 @@ public class AdminList extends FreedomService
|
||||
}
|
||||
|
||||
public boolean addAdmin(Admin admin)
|
||||
{
|
||||
return addAdmin(admin, false);
|
||||
}
|
||||
|
||||
public boolean addAdmin(Admin admin, boolean overwrite)
|
||||
{
|
||||
if (!admin.isValid())
|
||||
{
|
||||
@ -259,11 +259,6 @@ public class AdminList extends FreedomService
|
||||
|
||||
final String key = admin.getConfigKey();
|
||||
|
||||
if (!overwrite && allAdmins.containsKey(key))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Store admin, update views
|
||||
allAdmins.put(key, admin);
|
||||
updateTables();
|
||||
@ -327,28 +322,6 @@ public class AdminList extends FreedomService
|
||||
return ipTable.keySet();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
final Player player = event.getPlayer();
|
||||
final FPlayer fPlayer = plugin.pl.getPlayer(player);
|
||||
|
||||
if (plugin.al.isAdmin(player))
|
||||
{
|
||||
// Verify strict IP match
|
||||
if (plugin.al.isIdentityMatched(player))
|
||||
{
|
||||
fPlayer.setSuperadminIdVerified(true);
|
||||
plugin.al.updateLastLogin(player);
|
||||
}
|
||||
else
|
||||
{
|
||||
fPlayer.setSuperadminIdVerified(false);
|
||||
FUtil.bcastMsg("Warning: " + player.getName() + " is an admin, but is using an account not registered to one of their ip-list.", ChatColor.RED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void deactivateOldEntries(boolean verbose)
|
||||
{
|
||||
for (Admin admin : allAdmins.values())
|
||||
@ -372,7 +345,7 @@ public class AdminList extends FreedomService
|
||||
}
|
||||
|
||||
admin.setActive(false);
|
||||
Command_logs.deactivateSuperadmin(admin);
|
||||
plugin.lv.deactivateSuperadmin(admin);
|
||||
}
|
||||
|
||||
save();
|
||||
|
@ -67,6 +67,7 @@ public class Ban implements ConfigLoadable, ConfigSavable, Validatable
|
||||
dedupeIps();
|
||||
this.by = by;
|
||||
this.expiryUnix = FUtil.getUnixTime(expire);
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -36,7 +36,7 @@ public class BanManager extends FreedomService
|
||||
public BanManager(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
this.config = new YamlConfig(TotalFreedomMod.plugin, "bans.yml");
|
||||
this.config = new YamlConfig(plugin, "bans.yml");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -36,7 +36,7 @@ public class PermbanList extends FreedomService
|
||||
permbannedNames.clear();
|
||||
permbannedIps.clear();
|
||||
|
||||
final YamlConfig config = new YamlConfig(TotalFreedomMod.plugin, CONFIG_FILENAME, true);
|
||||
final YamlConfig config = new YamlConfig(plugin, CONFIG_FILENAME, true);
|
||||
config.load();
|
||||
|
||||
for (String name : config.getKeys(false))
|
||||
|
@ -0,0 +1,62 @@
|
||||
package me.totalfreedom.totalfreedommod.blocking;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.PotionSplashEvent;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
|
||||
public class PotionBlocker extends FreedomService
|
||||
{
|
||||
|
||||
public static final int POTION_BLOCK_RADIUS_SQUARED = 20 * 20;
|
||||
|
||||
public PotionBlocker(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onThrowPotion(PotionSplashEvent event)
|
||||
{
|
||||
ProjectileSource source = event.getEntity().getShooter();
|
||||
|
||||
if (!(source instanceof Player))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Player thrower = (Player) source;
|
||||
|
||||
if (plugin.al.isAdmin(thrower))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (Player player : thrower.getWorld().getPlayers())
|
||||
{
|
||||
if (thrower.getLocation().distanceSquared(player.getLocation()) < POTION_BLOCK_RADIUS_SQUARED)
|
||||
{
|
||||
thrower.sendMessage(ChatColor.RED + "You cannot use splash potions close to other players.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package me.totalfreedom.totalfreedommod.blocking.command;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -38,7 +39,7 @@ public class CommandBlockerEntry
|
||||
{
|
||||
if (action == CommandBlockerAction.BLOCK_AND_EJECT && sender instanceof Player)
|
||||
{
|
||||
FUtil.autoEject((Player) sender, "You used a prohibited command: " + command);
|
||||
TotalFreedomMod.plugin().ae.autoEject((Player) sender, "You used a prohibited command: " + command);
|
||||
FUtil.bcastMsg(sender.getName() + " was automatically kicked for using harmful commands.", ChatColor.RED);
|
||||
return;
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ public enum CommandBlockerRank
|
||||
return TELNET;
|
||||
}
|
||||
|
||||
Admin admin = TotalFreedomMod.plugin.al.getAdmin(sender);
|
||||
Admin admin = TotalFreedomMod.plugin().al.getAdmin(sender);
|
||||
if (admin != null)
|
||||
{
|
||||
if (admin.getRank() == Rank.SENIOR_ADMIN)
|
||||
|
@ -41,9 +41,9 @@ public class BukkitTelnetBridge extends FreedomService
|
||||
return;
|
||||
}
|
||||
|
||||
final Admin admin = plugin.al.getEntryByIp(ip, true);
|
||||
final Admin admin = plugin.al.getEntryByIpFuzzy(ip);
|
||||
|
||||
if (admin == null || !admin.isActive() || !admin.getRank().hasConsole())
|
||||
if (admin == null || !admin.isActive() || !admin.getRank().hasConsoleVariant())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ public class CommandLoader extends FreedomService
|
||||
protected void onStart()
|
||||
{
|
||||
handler.clearCommands();
|
||||
handler.setExecutorFactory(new FreedomCommandExecutor.FreedomExecutorFactory());
|
||||
handler.setExecutorFactory(new FreedomCommandExecutor.FreedomExecutorFactory(plugin));
|
||||
handler.setCommandClassPrefix("Command_");
|
||||
handler.setPermissionMessage(ChatColor.RED + "You do not have permission to use this command.");
|
||||
handler.setOnlyConsoleMessage(ChatColor.RED + "This command can only be used from the console.");
|
||||
|
@ -33,7 +33,7 @@ public class Command_adminchat extends FreedomCommand
|
||||
}
|
||||
else
|
||||
{
|
||||
FUtil.adminChatMessage(sender, StringUtils.join(args, " "));
|
||||
plugin.cm.adminChat(sender, StringUtils.join(args, " "));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -0,0 +1,26 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Make an announcement", usage = "/<command> <message>")
|
||||
public class Command_announce extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
protected boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
plugin.an.announce(StringUtils.join(args, " "));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -9,16 +9,12 @@ import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Shows all banned player names. Superadmins may optionally use 'purge' to clear the list.", usage = "/<command> [purge]")
|
||||
public class Command_banlist extends FreedomCommand
|
||||
{
|
||||
public class Command_banlist extends FreedomCommand {
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length > 0)
|
||||
{
|
||||
if (args[0].equalsIgnoreCase("purge"))
|
||||
{
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
|
||||
if (args.length > 0) {
|
||||
if (args[0].equalsIgnoreCase("purge")) {
|
||||
checkRank(Rank.SENIOR_ADMIN);
|
||||
|
||||
FUtil.adminAction(sender.getName(), "Purging the ban list", true);
|
||||
|
@ -3,12 +3,13 @@ package me.totalfreedom.totalfreedommod.command;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Block all commands for a specific player.", usage = "/<command> <purge | <partialname>>", aliases = "blockcommands,blockcommand")
|
||||
@CommandParameters(description = "Block all commands for a specific player.", usage = "/<command> <-a | purge | <player>>", aliases = "blockcommands,blockcommand,bc,bcmd")
|
||||
public class Command_blockcmd extends FreedomCommand
|
||||
{
|
||||
|
||||
@ -20,7 +21,7 @@ public class Command_blockcmd extends FreedomCommand
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("purge"))
|
||||
if (args[0].equals("purge"))
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Unblocking commands for all players", true);
|
||||
int counter = 0;
|
||||
@ -37,6 +38,26 @@ public class Command_blockcmd extends FreedomCommand
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[0].equals("-a"))
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Blocking commands for all non-admins", true);
|
||||
int counter = 0;
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
if (isAdmin(player))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
counter += 1;
|
||||
plugin.pl.getPlayer(player).setCommandsBlocked(true);
|
||||
msg(player, "Your commands have been blocked by an admin.", ChatColor.RED);
|
||||
}
|
||||
|
||||
msg("Blocked commands for " + counter + " players.");
|
||||
return true;
|
||||
}
|
||||
|
||||
final Player player = getPlayer(args[0]);
|
||||
|
||||
if (player == null)
|
||||
@ -45,7 +66,7 @@ public class Command_blockcmd extends FreedomCommand
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isAdmin(sender))
|
||||
if (isAdmin(player))
|
||||
{
|
||||
msg(player.getName() + " is a Superadmin, and cannot have their commands blocked.");
|
||||
return true;
|
||||
|
@ -12,15 +12,19 @@ import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Essentials Interface Command - Color your current nickname.", usage = "/<command> <color>")
|
||||
public class Command_colorme extends FreedomCommand {
|
||||
public class Command_colorme extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
|
||||
if (args.length != 1) {
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ("list".equalsIgnoreCase(args[0])) {
|
||||
if ("list".equalsIgnoreCase(args[0]))
|
||||
{
|
||||
msg("Colors: " + StringUtils.join(FUtil.CHAT_COLOR_NAMES.keySet(), ", "));
|
||||
return true;
|
||||
}
|
||||
@ -28,15 +32,18 @@ public class Command_colorme extends FreedomCommand {
|
||||
final String needle = args[0].trim().toLowerCase();
|
||||
ChatColor color = null;
|
||||
final Iterator<Map.Entry<String, ChatColor>> it = FUtil.CHAT_COLOR_NAMES.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
while (it.hasNext())
|
||||
{
|
||||
final Map.Entry<String, ChatColor> entry = it.next();
|
||||
if (entry.getKey().contains(needle)) {
|
||||
if (entry.getKey().contains(needle))
|
||||
{
|
||||
color = entry.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (color == null) {
|
||||
if (color == null)
|
||||
{
|
||||
msg("Invalid color: " + needle + " - Use \"/colorme list\" to list colors.");
|
||||
return true;
|
||||
}
|
||||
|
@ -8,37 +8,30 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Quickly change your own gamemode to creative, or define someone's username to change theirs.", usage = "/<command> [partialname]", aliases = "gmc")
|
||||
@CommandParameters(description = "Quickly change your own gamemode to creative, or define someone's username to change theirs.", usage = "/<command> <-a | [partialname]>", aliases = "gmc")
|
||||
public class Command_creative extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (senderIsConsole)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
sender.sendMessage("When used from the console, you must define a target user to change gamemode on.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Player player;
|
||||
if (args.length == 0)
|
||||
if (isConsole())
|
||||
{
|
||||
player = playerSender;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (args[0].equalsIgnoreCase("-a"))
|
||||
{
|
||||
if (!isAdmin(sender))
|
||||
{
|
||||
noPerms();
|
||||
sender.sendMessage("When used from the console, you must define a target player.");
|
||||
return true;
|
||||
}
|
||||
|
||||
playerSender.setGameMode(GameMode.CREATIVE);
|
||||
msg("Gamemode set to creative.");
|
||||
return true;
|
||||
}
|
||||
|
||||
checkRank(Rank.SUPER_ADMIN);
|
||||
|
||||
if (args[0].equals("-a"))
|
||||
{
|
||||
for (Player targetPlayer : server.getOnlinePlayers())
|
||||
{
|
||||
targetPlayer.setGameMode(GameMode.CREATIVE);
|
||||
@ -48,13 +41,7 @@ public class Command_creative extends FreedomCommand
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(senderIsConsole || isAdmin(sender)))
|
||||
{
|
||||
msg("Only superadmins can change other user's gamemode.");
|
||||
return true;
|
||||
}
|
||||
|
||||
player = getPlayer(args[0]);
|
||||
Player player = getPlayer(args[0]);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
@ -62,10 +49,8 @@ public class Command_creative extends FreedomCommand
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
msg("Setting " + player.getName() + " to game mode 'Creative'.");
|
||||
msg(player, sender.getName() + " set your game mode to 'Creative'.");
|
||||
msg("Setting " + player.getName() + " to game mode creative");
|
||||
msg(player, sender.getName() + " set your game mode to creative");
|
||||
player.setGameMode(GameMode.CREATIVE);
|
||||
|
||||
return true;
|
||||
|
@ -13,7 +13,7 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.ONLY_CONSOLE, blockHostConsole = true)
|
||||
@CommandParameters(description = "For the bad Superadmins", usage = "/<command> <playername>")
|
||||
@CommandParameters(description = "For the bad admins", usage = "/<command> <playername>")
|
||||
public class Command_doom extends FreedomCommand
|
||||
{
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
@ -21,11 +21,11 @@ public class Command_enchant extends FreedomCommand
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack itemInHand = playerSender.getItemInHand();
|
||||
ItemStack item = playerSender.getEquipment().getItemInMainHand();
|
||||
|
||||
if (itemInHand == null)
|
||||
if (item == null || item.getType() == Material.AIR)
|
||||
{
|
||||
msg("You are holding an invalid item.");
|
||||
msg("You have to hold an item to enchant it");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ public class Command_enchant extends FreedomCommand
|
||||
StringBuilder possible_ench = new StringBuilder("Possible enchantments for held item: ");
|
||||
for (Enchantment ench : Enchantment.values())
|
||||
{
|
||||
if (ench.canEnchantItem(itemInHand))
|
||||
if (ench.canEnchantItem(item))
|
||||
{
|
||||
has_enchantments = true;
|
||||
possible_ench.append(ench.getName()).append(", ");
|
||||
@ -58,14 +58,14 @@ public class Command_enchant extends FreedomCommand
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ench.canEnchantItem(itemInHand))
|
||||
if (ench.canEnchantItem(item))
|
||||
{
|
||||
itemInHand.addEnchantment(ench, ench.getMaxLevel());
|
||||
item.addEnchantment(ench, ench.getMaxLevel());
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.info("Error using " + ench.getName() + " on " + itemInHand.getType().name() + " held by " + playerSender.getName() + ".");
|
||||
msg("Could not add enchantment: " + ench.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,9 +73,9 @@ public class Command_enchant extends FreedomCommand
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("reset"))
|
||||
{
|
||||
for (Enchantment ench : itemInHand.getEnchantments().keySet())
|
||||
for (Enchantment ench : item.getEnchantments().keySet())
|
||||
{
|
||||
itemInHand.removeEnchantment(ench);
|
||||
item.removeEnchantment(ench);
|
||||
}
|
||||
|
||||
msg("Removed all enchantments.");
|
||||
@ -105,9 +105,9 @@ public class Command_enchant extends FreedomCommand
|
||||
|
||||
if (args[0].equalsIgnoreCase("add"))
|
||||
{
|
||||
if (ench.canEnchantItem(itemInHand))
|
||||
if (ench.canEnchantItem(item))
|
||||
{
|
||||
itemInHand.addEnchantment(ench, ench.getMaxLevel());
|
||||
item.addEnchantment(ench, ench.getMaxLevel());
|
||||
|
||||
msg("Added enchantment: " + ench.getName());
|
||||
}
|
||||
@ -118,7 +118,7 @@ public class Command_enchant extends FreedomCommand
|
||||
}
|
||||
else if (args[0].equals("remove"))
|
||||
{
|
||||
itemInHand.removeEnchantment(ench);
|
||||
item.removeEnchantment(ench);
|
||||
|
||||
msg("Removed enchantment: " + ench.getName());
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ public class Command_ender extends FreedomCommand
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
FUtil.gotoWorld(playerSender, server.getWorlds().get(0).getName() + "_the_end");
|
||||
plugin.wm.gotoWorld(playerSender, server.getWorlds().get(0).getName() + "_the_end");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -29,8 +29,6 @@ public class Command_freeze extends FreedomCommand
|
||||
}
|
||||
|
||||
FUtil.adminAction(sender.getName(), "Enabling global player freeze", false);
|
||||
msg("Players are now frozen.");
|
||||
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
if (!isAdmin(player))
|
||||
@ -38,6 +36,8 @@ public class Command_freeze extends FreedomCommand
|
||||
msg(player, "You have been frozen due to rulebreakers, you will be unfrozen soon.", ChatColor.RED);
|
||||
}
|
||||
}
|
||||
msg("Players are now frozen.");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "You'll never even see it coming.", usage = "/<command>")
|
||||
@CommandParameters(description = "You'll never even see it coming.", usage = "/<command> <on [radius (default=25)] | off>")
|
||||
public class Command_fuckoff extends FreedomCommand
|
||||
{
|
||||
|
||||
|
@ -167,7 +167,7 @@ public class Command_gadmin extends FreedomCommand
|
||||
case OP:
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), String.format("Opping %s.", target.getName()), false);
|
||||
target.setOp(false);
|
||||
target.setOp(true);
|
||||
target.sendMessage(FreedomCommand.YOU_ARE_OP);
|
||||
|
||||
break;
|
||||
|
@ -73,7 +73,7 @@ public class Command_glist extends FreedomCommand
|
||||
|
||||
final String reason = args.length > 2 ? StringUtils.join(args, " ", 2, args.length) : null;
|
||||
|
||||
Ban ban = Ban.forPlayerName(player, sender, null, reason);
|
||||
Ban ban = Ban.forPlayerName(username, sender, null, reason);
|
||||
for (String ip : ips)
|
||||
{
|
||||
ban.addIp(ip);
|
||||
|
@ -45,6 +45,12 @@ public class Command_health extends FreedomCommand
|
||||
Thread.sleep(2500);
|
||||
final double ticksPerSecond = tickMeter.stopTicking();
|
||||
|
||||
// Plugin was disabled during async task
|
||||
if (!plugin.isEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
|
@ -0,0 +1,61 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Kick a player.", usage = "/<command> <player> [reason]", aliases = "k")
|
||||
public class Command_kick extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
protected boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Player player = getPlayer(args[0]);
|
||||
if (player == null)
|
||||
{
|
||||
msg(PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isAdmin(player))
|
||||
{
|
||||
msg("Admins can not be kicked", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
String reason = null;
|
||||
if (args.length > 1)
|
||||
{
|
||||
reason = StringUtils.join(args, " ", 1, args.length);
|
||||
}
|
||||
|
||||
StringBuilder builder = new StringBuilder()
|
||||
.append(ChatColor.RED).append("You have been kicked from the server.")
|
||||
.append("\n").append(ChatColor.RED).append("Kicked by: ").append(ChatColor.GOLD).append(sender.getName());
|
||||
|
||||
if (reason != null)
|
||||
{
|
||||
builder.append("\n").append(ChatColor.RED).append("Reason: ").append(ChatColor.GOLD).append(reason);
|
||||
FUtil.adminAction(sender.getName(), "Kicking " + player.getName() + " - Reason: " + reason, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Kicking " + player.getName(), true);
|
||||
}
|
||||
|
||||
player.kickPlayer(builder.toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -2,6 +2,8 @@ package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.rank.Displayable;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -10,16 +12,17 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.NON_OP, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Lists the real names of all online players.", usage = "/<command> [-a | -i]", aliases = "who")
|
||||
@CommandPermissions(level = Rank.IMPOSTOR, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Lists the real names of all online players.", usage = "/<command> [-a | -i | -f]", aliases = "who")
|
||||
public class Command_list extends FreedomCommand
|
||||
{
|
||||
|
||||
private static enum ListFilter
|
||||
{
|
||||
|
||||
ALL,
|
||||
PLAYERS,
|
||||
ADMINS,
|
||||
FAMOUS_PLAYERS,
|
||||
IMPOSTORS;
|
||||
}
|
||||
|
||||
@ -45,22 +48,24 @@ public class Command_list extends FreedomCommand
|
||||
final ListFilter listFilter;
|
||||
if (args.length == 1)
|
||||
{
|
||||
if ("-a".equals(args[0]))
|
||||
switch (args[0])
|
||||
{
|
||||
case "-a":
|
||||
listFilter = ListFilter.ADMINS;
|
||||
}
|
||||
else if ("-i".equals(args[0]))
|
||||
{
|
||||
break;
|
||||
case "-i":
|
||||
listFilter = ListFilter.IMPOSTORS;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
case "-f":
|
||||
listFilter = ListFilter.FAMOUS_PLAYERS;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
listFilter = ListFilter.ALL;
|
||||
listFilter = ListFilter.PLAYERS;
|
||||
}
|
||||
|
||||
final StringBuilder onlineStats = new StringBuilder();
|
||||
@ -83,11 +88,20 @@ public class Command_list extends FreedomCommand
|
||||
continue;
|
||||
}
|
||||
|
||||
names.add(plugin.rm.getDisplay(player).getColoredTag() + player.getName());
|
||||
if (listFilter == ListFilter.FAMOUS_PLAYERS && !ConfigEntry.FAMOUS_PLAYERS.getList().contains(player.getName().toLowerCase()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Displayable display = plugin.rm.getDisplay(player);
|
||||
|
||||
names.add(display.getColoredTag() + player.getName());
|
||||
}
|
||||
|
||||
String playerType = listFilter == null ? "players" : listFilter.toString().toLowerCase().replace('_', ' ');
|
||||
|
||||
onlineUsers.append("Connected ");
|
||||
onlineUsers.append(listFilter == ListFilter.ADMINS ? "admins: " : "players: ");
|
||||
onlineUsers.append(playerType + ": ");
|
||||
onlineUsers.append(StringUtils.join(names, ChatColor.WHITE + ", "));
|
||||
|
||||
if (senderIsConsole)
|
||||
|
@ -9,6 +9,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import me.totalfreedom.totalfreedommod.LogViewer.LogsRegistrationMode;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
@ -36,134 +37,9 @@ public class Command_logs extends FreedomCommand
|
||||
mode = ("off".equals(args[0]) ? LogsRegistrationMode.DELETE : LogsRegistrationMode.UPDATE);
|
||||
}
|
||||
|
||||
updateLogsRegistration(sender, playerSender, mode);
|
||||
plugin.lv.updateLogsRegistration(sender, playerSender, mode);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void updateLogsRegistration(final CommandSender sender, final Player target, final LogsRegistrationMode mode)
|
||||
{
|
||||
updateLogsRegistration(sender, target.getName(), target.getAddress().getAddress().getHostAddress().trim(), mode);
|
||||
}
|
||||
|
||||
public static void updateLogsRegistration(final CommandSender sender, final String targetName, final String targetIP, final LogsRegistrationMode mode)
|
||||
{
|
||||
final String logsRegisterUrl = ConfigEntry.LOGS_URL.getString();
|
||||
final String logsRegisterPassword = ConfigEntry.LOGS_SECRET.getString();
|
||||
|
||||
if (logsRegisterUrl == null || logsRegisterPassword == null || logsRegisterUrl.isEmpty() || logsRegisterPassword.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (sender != null)
|
||||
{
|
||||
sender.sendMessage(ChatColor.YELLOW + "Connecting...");
|
||||
}
|
||||
|
||||
URL url = new URLBuilder(logsRegisterUrl)
|
||||
.addQueryParameter("mode", mode.toString())
|
||||
.addQueryParameter("password", logsRegisterPassword)
|
||||
.addQueryParameter("name", targetName)
|
||||
.addQueryParameter("ip", targetIP)
|
||||
.getURL();
|
||||
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setConnectTimeout(1000 * 5);
|
||||
connection.setReadTimeout(1000 * 5);
|
||||
connection.setUseCaches(false);
|
||||
connection.setRequestMethod("HEAD");
|
||||
|
||||
final int responseCode = connection.getResponseCode();
|
||||
|
||||
if (sender != null)
|
||||
{
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (responseCode == 200)
|
||||
{
|
||||
sender.sendMessage(ChatColor.GREEN + "Registration " + mode.toString() + "d.");
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.sendMessage(ChatColor.RED + "Error contacting logs registration server.");
|
||||
}
|
||||
}
|
||||
}.runTask(TotalFreedomMod.plugin);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(TotalFreedomMod.plugin);
|
||||
}
|
||||
|
||||
public static void deactivateSuperadmin(Admin superadmin)
|
||||
{
|
||||
for (String ip : superadmin.getIps())
|
||||
{
|
||||
updateLogsRegistration(null, superadmin.getName(), ip, Command_logs.LogsRegistrationMode.DELETE);
|
||||
}
|
||||
}
|
||||
|
||||
public static enum LogsRegistrationMode
|
||||
{
|
||||
|
||||
UPDATE("update"), DELETE("delete");
|
||||
private final String mode;
|
||||
|
||||
private LogsRegistrationMode(String mode)
|
||||
{
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
|
||||
private static class URLBuilder
|
||||
{
|
||||
|
||||
private final String requestPath;
|
||||
private final Map<String, String> queryStringMap = new HashMap<>();
|
||||
|
||||
public URLBuilder(String requestPath)
|
||||
{
|
||||
this.requestPath = requestPath;
|
||||
}
|
||||
|
||||
public URLBuilder addQueryParameter(String key, String value)
|
||||
{
|
||||
queryStringMap.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public URL getURL() throws MalformedURLException
|
||||
{
|
||||
List<String> pairs = new ArrayList<>();
|
||||
Iterator<Entry<String, String>> it = queryStringMap.entrySet().iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
Entry<String, String> pair = it.next();
|
||||
pairs.add(pair.getKey() + "=" + pair.getValue());
|
||||
}
|
||||
|
||||
return new URL(requestPath + "?" + StringUtils.join(pairs, "&"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
@ -21,7 +22,7 @@ public class Command_mobpurge extends FreedomCommand
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
msg("Purging all mobs...");
|
||||
FUtil.adminAction(sender.getName(), "Purging all mobs", true);
|
||||
msg(purgeMobs() + " mobs removed.");
|
||||
return true;
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class Command_mp44 extends FreedomCommand
|
||||
msg("mp44 is ARMED! Left click with gunpowder to start firing, left click again to quit.", ChatColor.GREEN);
|
||||
msg("Type /mp44 sling to disable. -by Madgeek1450", ChatColor.GREEN);
|
||||
|
||||
playerSender.setItemInHand(new ItemStack(Material.SULPHUR, 1));
|
||||
playerSender.getEquipment().setItemInMainHand(new ItemStack(Material.SULPHUR, 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -0,0 +1,168 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import java.util.Arrays;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.util.ChatUtils;
|
||||
import net.pravian.aero.util.Ips;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Manage my admin entry", usage = "/<command> [-o <admin>] <clearips | clearip <ip> | setlogin <message> | clearlogin>")
|
||||
public class Command_myadmin extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
protected boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
checkPlayer();
|
||||
checkRank(Rank.SUPER_ADMIN);
|
||||
|
||||
if (args.length < 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Player init = null;
|
||||
Admin target = getAdmin(playerSender);
|
||||
Player targetPlayer = playerSender;
|
||||
String targetIp = Ips.getIp(targetPlayer);
|
||||
|
||||
// -o switch
|
||||
if (args[0].equals("-o"))
|
||||
{
|
||||
checkRank(Rank.SENIOR_ADMIN);
|
||||
init = playerSender;
|
||||
targetPlayer = getPlayer(args[1]);
|
||||
if (targetPlayer == null)
|
||||
{
|
||||
msg(FreedomCommand.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
target = getAdmin(targetPlayer);
|
||||
if (target == null)
|
||||
{
|
||||
msg("That player is not admin", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Shift 2
|
||||
args = Arrays.copyOfRange(args, 2, args.length);
|
||||
if (args.length < 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
switch (args[0])
|
||||
{
|
||||
case "clearips":
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
return false; // Double check: the player might mean "clearip"
|
||||
}
|
||||
|
||||
if (init == null)
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Clearing my supered IPs", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Clearing " + target.getName() + "' supered IPs", true);
|
||||
}
|
||||
|
||||
int counter = target.getIps().size() - 1;
|
||||
target.clearIPs();
|
||||
target.addIp(targetIp);
|
||||
|
||||
plugin.al.save();
|
||||
|
||||
msg(counter + " IPs removed.");
|
||||
msg(targetPlayer, target.getIps().get(0) + " is now your only IP address");
|
||||
return true;
|
||||
}
|
||||
|
||||
case "clearip":
|
||||
{
|
||||
if (args.length != 2)
|
||||
{
|
||||
return false; // Double check: the player might mean "clearips"
|
||||
}
|
||||
|
||||
if (!target.getIps().contains(args[1]))
|
||||
{
|
||||
if (init == null)
|
||||
{
|
||||
msg("That IP is not registered to you.");
|
||||
}
|
||||
else
|
||||
{
|
||||
msg("That IP does not belong to that player.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (targetIp.equals(args[1]))
|
||||
{
|
||||
if (init == null)
|
||||
{
|
||||
msg("You cannot remove your current IP.");
|
||||
}
|
||||
else
|
||||
{
|
||||
msg("You cannot remove that admin's current IP.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
FUtil.adminAction(sender.getName(), "Removing a supered IP" + (init == null ? "" : " from " + targetPlayer.getName() + "'s IPs"), true);
|
||||
|
||||
target.removeIp(args[1]);
|
||||
plugin.al.save();
|
||||
plugin.al.updateTables();
|
||||
|
||||
msg("Removed IP " + args[1]);
|
||||
msg("Current IPs: " + StringUtils.join(target.getIps(), ", "));
|
||||
return true;
|
||||
}
|
||||
|
||||
case "setlogin":
|
||||
{
|
||||
if (args.length < 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
String msg = StringUtils.join(args, " ", 1, args.length);
|
||||
FUtil.adminAction(sender.getName(), "Setting personal login message" + (init == null ? "" : " for " + targetPlayer.getName()), false);
|
||||
target.setLoginMessage(msg);
|
||||
msg((init == null ? "Your" : targetPlayer.getName() + "'s") + " login message is now: ");
|
||||
msg("> " + ChatColor.AQUA + targetPlayer.getName() + " is " + ChatUtils.colorize(target.getLoginMessage()));
|
||||
plugin.al.save();
|
||||
plugin.al.updateTables();
|
||||
return true;
|
||||
}
|
||||
|
||||
case "clearlogin":
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Clearing personal login message" + (init == null ? "" : " for " + targetPlayer.getName()), false);
|
||||
target.setLoginMessage(null);
|
||||
plugin.al.save();
|
||||
plugin.al.updateTables();
|
||||
return true;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -14,7 +14,7 @@ public class Command_nether extends FreedomCommand
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
FUtil.gotoWorld(playerSender, server.getWorlds().get(0).getName() + "_nether");
|
||||
plugin.wm.gotoWorld(playerSender, server.getWorlds().get(0).getName() + "_nether");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -23,12 +23,12 @@ public class Command_nickclean extends FreedomCommand
|
||||
ChatColor.UNDERLINE,
|
||||
ChatColor.BLACK
|
||||
};
|
||||
private static final Pattern REGEX = Pattern.compile(ChatColor.COLOR_CHAR + "[" + StringUtils.join(BLOCKED, "") + "]");
|
||||
private static final Pattern REGEX = Pattern.compile(ChatColor.COLOR_CHAR + "[" + StringUtils.join(BLOCKED, "") + "]", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Cleaning all nicknames.", false);
|
||||
FUtil.adminAction(sender.getName(), "Cleaning all nicknames", false);
|
||||
|
||||
for (final Player player : server.getOnlinePlayers())
|
||||
{
|
||||
|
@ -1,5 +1,6 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
@ -15,7 +16,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.IMPOSTOR, source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Overlord - control this server in-game", usage = "access", aliases = "ov")
|
||||
public class Command_overlord extends FreedomCommand
|
||||
public class Command_ov extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
@ -25,8 +26,8 @@ public class Command_overlord extends FreedomCommand
|
||||
{
|
||||
try
|
||||
{
|
||||
List<?> ips = (List) MainConfig.getDefaults().get(ConfigEntry.OVERLORD_IPS.getConfigName());
|
||||
if (!ips.contains(Ips.getIp(playerSender)))
|
||||
Object ips = plugin.config.getDefaults().get(ConfigEntry.OVERLORD_IPS.getConfigName());
|
||||
if (ips instanceof Collection && !((Collection) ips).contains(Ips.getIp(playerSender)))
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
@ -25,11 +25,11 @@ public class Command_permban extends FreedomCommand
|
||||
}
|
||||
|
||||
msg("Reloading permban list...", ChatColor.RED);
|
||||
plugin.pb.stop();
|
||||
plugin.pb.start();
|
||||
plugin.pm.stop();
|
||||
plugin.pm.start();
|
||||
msg("Reloaded permban list.");
|
||||
msg(plugin.pb.getPermbannedIps().size() + " IPs and "
|
||||
+ plugin.pb.getPermbannedNames().size() + " usernames loaded.");
|
||||
msg(plugin.pm.getPermbannedIps().size() + " IPs and "
|
||||
+ plugin.pm.getPermbannedNames().size() + " usernames loaded.");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,11 @@ public class Command_premium extends FreedomCommand
|
||||
final String message = ("false".equalsIgnoreCase(in.readLine()) ? ChatColor.RED + "No" : ChatColor.DARK_GREEN + "Yes");
|
||||
in.close();
|
||||
|
||||
if (!plugin.isEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
|
@ -1,5 +1,6 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.Displayable;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
@ -14,26 +15,26 @@ public class Command_rank extends FreedomCommand
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (senderIsConsole && args.length < 1)
|
||||
if (isConsole() && args.length == 0)
|
||||
{
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
msg(player.getName() + " is " + plugin.rm.getDisplay(player).getColoredLoginMessage());
|
||||
msg(message(player));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 0)
|
||||
{
|
||||
msg(message(playerSender));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length > 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.length == 0)
|
||||
{
|
||||
msg(sender.getName() + " is " + plugin.rm.getDisplay(sender).getColoredLoginMessage(), ChatColor.AQUA);
|
||||
return true;
|
||||
}
|
||||
|
||||
final Player player = getPlayer(args[0]);
|
||||
|
||||
if (player == null)
|
||||
@ -42,8 +43,33 @@ public class Command_rank extends FreedomCommand
|
||||
return true;
|
||||
}
|
||||
|
||||
msg(player.getName() + " is " + plugin.rm.getDisplay(player).getColoredLoginMessage(), ChatColor.AQUA);
|
||||
msg(message(player));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public String message(Player player)
|
||||
{
|
||||
Displayable display = plugin.rm.getDisplay(player);
|
||||
Rank rank = plugin.rm.getRank(player);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb
|
||||
.append(ChatColor.AQUA)
|
||||
.append(player.getName())
|
||||
.append(" is ")
|
||||
.append(display.getColoredLoginMessage());
|
||||
|
||||
if (rank != display)
|
||||
{
|
||||
sb
|
||||
.append(ChatColor.AQUA)
|
||||
.append(" (")
|
||||
.append(rank.getColoredName())
|
||||
.append(ChatColor.AQUA)
|
||||
.append(')');
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public class Command_report extends FreedomCommand
|
||||
}
|
||||
|
||||
String report = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " ");
|
||||
FUtil.reportAction(playerSender, player, report);
|
||||
plugin.cm.reportAction(playerSender, player, report);
|
||||
|
||||
msg(ChatColor.GREEN + "Thank you, your report has been successfully logged.");
|
||||
|
||||
|
@ -7,8 +7,10 @@ import me.totalfreedom.totalfreedommod.util.DepreciationAggregator;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -42,9 +44,9 @@ public class Command_ro extends FreedomCommand
|
||||
}
|
||||
}
|
||||
|
||||
if (fromMaterial == null)
|
||||
if (fromMaterial == null || fromMaterial == Material.AIR || !fromMaterial.isBlock())
|
||||
{
|
||||
msg("Invalid block: " + materialName, ChatColor.RED);
|
||||
msg("Invalid material: " + materialName, ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -105,7 +107,7 @@ public class Command_ro extends FreedomCommand
|
||||
|
||||
for (final Material material : materials)
|
||||
{
|
||||
affected += FUtil.replaceBlocks(player.getLocation(), material, Material.AIR, radius);
|
||||
affected += replaceBlocks(player.getLocation(), material, Material.AIR, radius);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -116,7 +118,7 @@ public class Command_ro extends FreedomCommand
|
||||
for (Material material : materials)
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Removing all " + names + " within " + radius + " blocks of " + targetPlayer.getName(), false);
|
||||
affected += FUtil.replaceBlocks(targetPlayer.getLocation(), material, Material.AIR, radius);
|
||||
affected += replaceBlocks(targetPlayer.getLocation(), material, Material.AIR, radius);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -125,4 +127,32 @@ public class Command_ro extends FreedomCommand
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static int replaceBlocks(Location center, Material fromMaterial, Material toMaterial, int radius)
|
||||
{
|
||||
int affected = 0;
|
||||
|
||||
Block centerBlock = center.getBlock();
|
||||
for (int xOffset = -radius; xOffset <= radius; xOffset++)
|
||||
{
|
||||
for (int yOffset = -radius; yOffset <= radius; yOffset++)
|
||||
{
|
||||
for (int zOffset = -radius; zOffset <= radius; zOffset++)
|
||||
{
|
||||
Block block = centerBlock.getRelative(xOffset, yOffset, zOffset);
|
||||
|
||||
if (block.getType().equals(fromMaterial))
|
||||
{
|
||||
if (block.getLocation().distanceSquared(center) < (radius * radius))
|
||||
{
|
||||
block.setType(toMaterial);
|
||||
affected++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return affected;
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Manage admins.", usage = "/<command> <list | clean | reload | clearme [ip] | setrank <username> <rank> | <add | remove | info> <username>>")
|
||||
@CommandParameters(description = "Manage admins.", usage = "/<command> <list | clean | reload | | setrank <username> <rank> | <add | remove | info> <username>>")
|
||||
public class Command_saconfig extends FreedomCommand
|
||||
{
|
||||
|
||||
@ -37,6 +37,7 @@ public class Command_saconfig extends FreedomCommand
|
||||
case "clean":
|
||||
{
|
||||
checkConsole();
|
||||
checkRank(Rank.TELNET_ADMIN);
|
||||
|
||||
FUtil.adminAction(sender.getName(), "Cleaning admin list", true);
|
||||
plugin.al.deactivateOldEntries(true);
|
||||
@ -55,71 +56,24 @@ public class Command_saconfig extends FreedomCommand
|
||||
return true;
|
||||
}
|
||||
|
||||
case "clearme":
|
||||
{
|
||||
checkPlayer();
|
||||
checkRank(Rank.SUPER_ADMIN);
|
||||
|
||||
final Admin admin = plugin.al.getAdmin(playerSender);
|
||||
|
||||
if (admin == null)
|
||||
{
|
||||
msg("Could not find your admin entry! Please notify a developer.", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
final String ip = Ips.getIp(playerSender);
|
||||
|
||||
if (args.length == 1)
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Cleaning my supered IPs", true);
|
||||
|
||||
int counter = admin.getIps().size() - 1;
|
||||
admin.clearIPs();
|
||||
admin.addIp(ip);
|
||||
|
||||
plugin.al.save(admin);
|
||||
|
||||
msg(counter + " IPs removed.");
|
||||
msg(admin.getIps().get(0) + " is now your only IP address");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!admin.getIps().contains(args[1]))
|
||||
{
|
||||
msg("That IP is not registered to you.");
|
||||
}
|
||||
else if (ip.equals(args[1]))
|
||||
{
|
||||
msg("You cannot remove your current IP.");
|
||||
}
|
||||
else
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Removing a supered IP", true);
|
||||
|
||||
admin.removeIp(args[1]);
|
||||
|
||||
plugin.al.save(admin);
|
||||
|
||||
msg("Removed IP " + args[1]);
|
||||
msg("Current IPs: " + StringUtils.join(admin.getIps(), ", "));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
case "setrank":
|
||||
{
|
||||
checkConsole();
|
||||
checkNotHostConsole();
|
||||
checkRank(Rank.SENIOR_CONSOLE);
|
||||
|
||||
if (args.length < 3)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
checkConsole();
|
||||
checkRank(Rank.SENIOR_CONSOLE);
|
||||
|
||||
Rank rank = Rank.findRank(args[2]);
|
||||
if (rank == null)
|
||||
{
|
||||
msg("Unknown rank: " + rank);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!rank.isAtLeast(Rank.SUPER_ADMIN))
|
||||
{
|
||||
msg("Rank must be superadmin or higher.", ChatColor.RED);
|
||||
@ -133,8 +87,10 @@ public class Command_saconfig extends FreedomCommand
|
||||
return true;
|
||||
}
|
||||
|
||||
FUtil.adminAction(sender.getName(), "Setting " + admin.getName() + "'s rank to " + rank.getName(), true);
|
||||
|
||||
admin.setRank(rank);
|
||||
plugin.al.save(admin);
|
||||
plugin.al.save();
|
||||
|
||||
msg("Set " + admin.getName() + "'s rank to " + rank.getName());
|
||||
return true;
|
||||
@ -182,16 +138,16 @@ public class Command_saconfig extends FreedomCommand
|
||||
checkConsole();
|
||||
checkRank(Rank.TELNET_ADMIN);
|
||||
|
||||
// Player already an admin?
|
||||
final Player player = getPlayer(args[1]);
|
||||
|
||||
if (plugin.al.isAdmin(player))
|
||||
if (player != null && plugin.al.isAdmin(player))
|
||||
{
|
||||
msg("That player is already admin.");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Find the old admin entry
|
||||
String name = player != null ? player.getName() : args[1];
|
||||
|
||||
Admin admin = null;
|
||||
for (Admin loopAdmin : plugin.al.getAllAdmins().values())
|
||||
{
|
||||
@ -202,29 +158,8 @@ public class Command_saconfig extends FreedomCommand
|
||||
}
|
||||
}
|
||||
|
||||
if (admin != null) // Existing admin
|
||||
if (admin == null) // New admin
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Readding " + admin.getName() + " to the admin list", true);
|
||||
|
||||
if (player != null)
|
||||
{
|
||||
admin.loadFrom(player); // Reset IP, username
|
||||
}
|
||||
|
||||
admin.setActive(true);
|
||||
admin.setLastLogin(new Date());
|
||||
|
||||
if (player != null)
|
||||
{
|
||||
admin.addIp(Ips.getIp(player));
|
||||
}
|
||||
|
||||
plugin.al.save(admin);
|
||||
plugin.al.updateTables();
|
||||
}
|
||||
else // New admin
|
||||
{
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
msg(FreedomCommand.PLAYER_NOT_FOUND);
|
||||
@ -233,7 +168,22 @@ public class Command_saconfig extends FreedomCommand
|
||||
|
||||
FUtil.adminAction(sender.getName(), "Adding " + player.getName() + " to the admin list", true);
|
||||
plugin.al.addAdmin(new Admin(player));
|
||||
}
|
||||
else // Existing admin
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Readding " + admin.getName() + " to the admin list", true);
|
||||
|
||||
if (player != null)
|
||||
{
|
||||
admin.setName(player.getName());
|
||||
admin.addIp(Ips.getIp(player));
|
||||
}
|
||||
|
||||
admin.setActive(true);
|
||||
admin.setLastLogin(new Date());
|
||||
|
||||
plugin.al.save();
|
||||
plugin.al.updateTables();
|
||||
}
|
||||
|
||||
if (player != null)
|
||||
@ -260,7 +210,7 @@ public class Command_saconfig extends FreedomCommand
|
||||
checkRank(Rank.TELNET_ADMIN);
|
||||
|
||||
Player player = getPlayer(args[1]);
|
||||
Admin admin = player == null ? plugin.al.getAdmin(player) : plugin.al.getEntryByName(args[1]);
|
||||
Admin admin = player != null ? plugin.al.getAdmin(player) : plugin.al.getEntryByName(args[1]);
|
||||
|
||||
if (admin == null)
|
||||
{
|
||||
@ -270,7 +220,7 @@ public class Command_saconfig extends FreedomCommand
|
||||
|
||||
FUtil.adminAction(sender.getName(), "Removing " + admin.getName() + " from the admin list", true);
|
||||
admin.setActive(false);
|
||||
plugin.al.save(admin);
|
||||
plugin.al.save();
|
||||
plugin.al.updateTables();
|
||||
return true;
|
||||
}
|
||||
|
@ -1,29 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.ServiceChecker.ServiceStatus;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.NON_OP, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Shows the status of all Mojang services", usage = "/<command>")
|
||||
public class Command_services extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
msg("Mojang Services" + ChatColor.WHITE + ":", ChatColor.BLUE);
|
||||
|
||||
for (ServiceStatus service : plugin.sc.getAllStatuses())
|
||||
{
|
||||
msg(service.getFormattedStatus());
|
||||
}
|
||||
msg("Version" + ChatColor.WHITE + ": " + plugin.sc.getVersion(), ChatColor.DARK_PURPLE);
|
||||
msg("Last Check" + ChatColor.WHITE + ": " + plugin.sc.getLastCheck(), ChatColor.DARK_PURPLE);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -7,8 +7,8 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Sets everyone's Worldedit block modification limit to 500.", usage = "/<command>")
|
||||
public class Command_setl extends FreedomCommand
|
||||
@CommandParameters(description = "Sets everyone's Worldedit block modification limit to the default.", usage = "/<command>", aliases = "setl,swl")
|
||||
public class Command_setlimit extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
@ -2,6 +2,7 @@ package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
@ -11,45 +12,60 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Someone being a little bitch? Smite them down...", usage = "/<command> [playername]")
|
||||
@CommandParameters(description = "Someone being a little bitch? Smite them down...", usage = "/<command> <player> [reason]")
|
||||
public class Command_smite extends FreedomCommand
|
||||
{
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
final Player player = getPlayer(args[0]);
|
||||
|
||||
String reason = null;
|
||||
if (args.length > 1)
|
||||
{
|
||||
reason = StringUtils.join(args, " ", 1, args.length);
|
||||
}
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
msg(FreedomCommand.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
smite(player);
|
||||
|
||||
smite(player, reason);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void smite(final Player player)
|
||||
public static void smite(Player player)
|
||||
{
|
||||
smite(player, null);
|
||||
}
|
||||
|
||||
public static void smite(Player player, String reason)
|
||||
{
|
||||
FUtil.bcastMsg(player.getName() + " has been a naughty, naughty boy.", ChatColor.RED);
|
||||
|
||||
//Deop
|
||||
if (reason != null)
|
||||
{
|
||||
FUtil.bcastMsg(" Reason: " + reason, ChatColor.RED);
|
||||
}
|
||||
|
||||
// Deop
|
||||
player.setOp(false);
|
||||
|
||||
//Set gamemode to survival:
|
||||
// Set gamemode to survival
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
|
||||
//Clear inventory:
|
||||
// Clear inventory
|
||||
player.getInventory().clear();
|
||||
|
||||
//Strike with lightning effect:
|
||||
// Strike with lightning effect
|
||||
final Location targetPos = player.getLocation();
|
||||
final World world = player.getWorld();
|
||||
for (int x = -1; x <= 1; x++)
|
||||
@ -61,7 +77,12 @@ public class Command_smite extends FreedomCommand
|
||||
}
|
||||
}
|
||||
|
||||
//Kill:
|
||||
// Kill
|
||||
player.setHealth(0.0);
|
||||
|
||||
if (reason != null)
|
||||
{
|
||||
player.sendMessage(ChatColor.RED + "You've been smitten. Reason: " + reason);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,78 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Make an announcement", usage = "/<command> <mobtype> [amount]")
|
||||
public class Command_spawnmob extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
protected boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
EntityType type = null;
|
||||
for (EntityType loop : EntityType.values())
|
||||
{
|
||||
if (loop.getName().equalsIgnoreCase(args[0]))
|
||||
{
|
||||
type = loop;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (type == null)
|
||||
{
|
||||
msg("Unknown entity type: " + args[0], ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!type.isSpawnable() || !type.isAlive())
|
||||
{
|
||||
msg("Can not spawn entity type: " + type.getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
int amount = 1;
|
||||
if (args.length > 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
amount = Integer.parseInt(args[1]);
|
||||
}
|
||||
catch (NumberFormatException nfex)
|
||||
{
|
||||
msg("Invalid amount: " + args[1], ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (amount > 10 || amount < 1)
|
||||
{
|
||||
msg("Invalid amount: " + args[1] + ". Must be 1-10.", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
Location l = playerSender.getLocation();
|
||||
World w = playerSender.getWorld();
|
||||
msg("Spawning " + amount + " of " + type.getName());
|
||||
|
||||
for (int i = 0; i < amount; amount++)
|
||||
{
|
||||
w.spawnEntity(l, type);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Quickly change your own gamemode to spectator.", usage = "/<command>", aliases = "gmsp")
|
||||
public class Command_spectator extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
playerSender.setGameMode(GameMode.SPECTATOR);
|
||||
msg("Gamemode set to spectator.");
|
||||
return true;
|
||||
}
|
||||
}
|
@ -3,19 +3,22 @@ package me.totalfreedom.totalfreedommod.command;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Mutes a player with brute force.", usage = "/<command> [<player> [-s] | list | purge | all]", aliases = "mute")
|
||||
@CommandParameters(description = "Mutes a player with brute force.", usage = "/<command> [[-s] <player> [reason] | list | purge | all]", aliases = "mute")
|
||||
public class Command_stfu extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length == 0 || args.length > 2)
|
||||
if (args.length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -38,8 +41,11 @@ public class Command_stfu extends FreedomCommand
|
||||
{
|
||||
msg("- none");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("purge"))
|
||||
|
||||
if (args[0].equalsIgnoreCase("purge"))
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Unmuting all players.", true);
|
||||
FPlayer info;
|
||||
@ -54,8 +60,10 @@ public class Command_stfu extends FreedomCommand
|
||||
}
|
||||
}
|
||||
msg("Unmuted " + count + " players.");
|
||||
return true;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("all"))
|
||||
|
||||
if (args[0].equalsIgnoreCase("all"))
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Muting all non-Superadmins", true);
|
||||
|
||||
@ -72,43 +80,64 @@ public class Command_stfu extends FreedomCommand
|
||||
}
|
||||
|
||||
msg("Muted " + counter + " players.");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
final Player player = getPlayer(args[0]);
|
||||
|
||||
boolean smite = args[0].equals("-s");
|
||||
if (smite)
|
||||
{
|
||||
args = ArrayUtils.subarray(args, 1, args.length);
|
||||
}
|
||||
|
||||
final Player player = getPlayer(args[0]);
|
||||
if (player == null)
|
||||
{
|
||||
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
String reason = null;
|
||||
if (args.length > 1)
|
||||
{
|
||||
reason = StringUtils.join(args, " ", 1, args.length);
|
||||
}
|
||||
|
||||
FPlayer playerdata = plugin.pl.getPlayer(player);
|
||||
if (playerdata.isMuted())
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Unmuting " + player.getName(), true);
|
||||
playerdata.setMuted(false);
|
||||
msg("Unmuted " + player.getName());
|
||||
|
||||
msg(player, "You have been unmuted.", ChatColor.RED);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!plugin.al.isAdmin(player))
|
||||
if (plugin.al.isAdmin(player))
|
||||
{
|
||||
msg(player.getName() + " is a superadmin, and can't be muted.");
|
||||
return true;
|
||||
}
|
||||
|
||||
FUtil.adminAction(sender.getName(), "Muting " + player.getName(), true);
|
||||
playerdata.setMuted(true);
|
||||
|
||||
if (args.length == 2 && args[1].equalsIgnoreCase("-s"))
|
||||
if (smite)
|
||||
{
|
||||
Command_smite.smite(player);
|
||||
}
|
||||
|
||||
msg("Muted " + player.getName());
|
||||
if (reason != null)
|
||||
{
|
||||
msg(player, "You have been muted. Reason: " + reason, ChatColor.RED);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg(player.getName() + " is a superadmin, and can't be muted.");
|
||||
}
|
||||
msg(player, "You have been muted.", ChatColor.RED);
|
||||
}
|
||||
|
||||
msg("Muted " + player.getName());
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -14,32 +14,24 @@ public class Command_survival extends FreedomCommand
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (senderIsConsole)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
msg("When used from the console, you must define a target user to change gamemode on.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Player player;
|
||||
|
||||
if (args.length == 0)
|
||||
if (isConsole())
|
||||
{
|
||||
player = playerSender;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (args[0].equalsIgnoreCase("-a"))
|
||||
{
|
||||
if (!plugin.al.isAdmin(sender) || senderIsConsole)
|
||||
{
|
||||
noPerms();
|
||||
sender.sendMessage("When used from the console, you must define a target player.");
|
||||
return true;
|
||||
}
|
||||
|
||||
playerSender.setGameMode(GameMode.SURVIVAL);
|
||||
msg("Gamemode set to survival.");
|
||||
return true;
|
||||
}
|
||||
|
||||
checkRank(Rank.SUPER_ADMIN);
|
||||
|
||||
if (args[0].equals("-a"))
|
||||
{
|
||||
for (Player targetPlayer : server.getOnlinePlayers())
|
||||
{
|
||||
targetPlayer.setGameMode(GameMode.SURVIVAL);
|
||||
@ -49,27 +41,17 @@ public class Command_survival extends FreedomCommand
|
||||
return true;
|
||||
}
|
||||
|
||||
if (senderIsConsole || plugin.al.isAdmin(sender))
|
||||
{
|
||||
player = getPlayer(args[0]);
|
||||
Player player = getPlayer(args[0]);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
msg(FreedomCommand.PLAYER_NOT_FOUND);
|
||||
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
msg("Only superadmins can change other user's gamemode.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
msg("Setting " + player.getName() + " to game mode 'Survival'.");
|
||||
player.sendMessage(sender.getName() + " set your game mode to 'Survival'.");
|
||||
msg("Setting " + player.getName() + " to game mode survival.");
|
||||
msg(player, sender.getName() + " set your game mode to survival.");
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -29,8 +29,18 @@ public class Command_tagnyan extends FreedomCommand
|
||||
tag.append(FUtil.randomChatColor()).append(c);
|
||||
}
|
||||
|
||||
String tagStr = tag.toString();
|
||||
for (String word : Command_tag.FORBIDDEN_WORDS)
|
||||
{
|
||||
if (tagStr.contains(word))
|
||||
{
|
||||
msg("That tag contains a forbidden word.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
final FPlayer data = plugin.pl.getPlayer(playerSender);
|
||||
data.setTag(tag.toString());
|
||||
data.setTag(tagStr);
|
||||
|
||||
msg("Set tag to " + tag);
|
||||
|
||||
|
@ -3,6 +3,7 @@ package me.totalfreedom.totalfreedommod.command;
|
||||
import me.totalfreedom.totalfreedommod.banning.Ban;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
@ -10,14 +11,14 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Temporarily bans a player for five minutes.", usage = "/<command> <partialname>", aliases = "noob")
|
||||
@CommandParameters(description = "Temporarily bans a player for five minutes.", usage = "/<command> <player> [reason]", aliases = "noob")
|
||||
public class Command_tban extends FreedomCommand
|
||||
{
|
||||
|
||||
@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;
|
||||
}
|
||||
@ -30,6 +31,16 @@ public class Command_tban extends FreedomCommand
|
||||
return true;
|
||||
}
|
||||
|
||||
String reason;
|
||||
if (args.length > 1)
|
||||
{
|
||||
reason = StringUtils.join(args, " ", 1, args.length);
|
||||
}
|
||||
else
|
||||
{
|
||||
reason = "You have been temporarily banned for 5 minutes.";
|
||||
}
|
||||
|
||||
// strike with lightning effect:
|
||||
final Location targetPos = player.getLocation();
|
||||
for (int x = -1; x <= 1; x++)
|
||||
@ -42,7 +53,7 @@ public class Command_tban extends FreedomCommand
|
||||
}
|
||||
|
||||
FUtil.adminAction(sender.getName(), "Tempbanning: " + player.getName() + " for 5 minutes.", true);
|
||||
plugin.bm.addBan(Ban.forPlayer(player, sender, FUtil.parseDateOffset("5m"), ChatColor.RED + "You have been temporarily banned for 5 minutes."));
|
||||
plugin.bm.addBan(Ban.forPlayer(player, sender, FUtil.parseDateOffset("5m"), reason));
|
||||
|
||||
player.kickPlayer(ChatColor.RED + "You have been temporarily banned for five minutes. Please read totalfreedom.me for more info.");
|
||||
|
||||
|
@ -1,70 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import java.io.File;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.ONLY_CONSOLE, blockHostConsole = true)
|
||||
@CommandParameters(description = "Update server files.", usage = "/<command>")
|
||||
public class Command_tfupdate extends FreedomCommand
|
||||
{
|
||||
|
||||
public static final String[] FILES
|
||||
=
|
||||
{
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (FILES.length == 0)
|
||||
{
|
||||
msg("This command is disabled.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!sender.getName().equalsIgnoreCase("madgeek1450"))
|
||||
{
|
||||
noPerms();
|
||||
return true;
|
||||
}
|
||||
|
||||
for (final String url : FILES)
|
||||
{
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
FLog.info("Downloading: " + url);
|
||||
|
||||
File file = new File("./updates/" + url.substring(url.lastIndexOf("/") + 1));
|
||||
if (file.exists())
|
||||
{
|
||||
file.delete();
|
||||
}
|
||||
if (!file.getParentFile().exists())
|
||||
{
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
FUtil.downloadFile(url, file, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(plugin);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -28,9 +28,9 @@ public class Command_toggle extends FreedomCommand
|
||||
msg("- prelog");
|
||||
msg("- lockdown");
|
||||
msg("- petprotect");
|
||||
msg("- droptoggle");
|
||||
msg("- nonuke");
|
||||
msg("- explosives");
|
||||
msg("- entitywipe");
|
||||
msg("- nonuke [range] [count]");
|
||||
msg("- explosives [radius]");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ public class Command_toggle extends FreedomCommand
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[0].equals("droptoggle"))
|
||||
if (args[0].equals("entitywipe"))
|
||||
{
|
||||
toggle("Automatic entity wiping is", ConfigEntry.AUTO_ENTITY_WIPE);
|
||||
return true;
|
||||
|
@ -3,6 +3,7 @@ package me.totalfreedom.totalfreedommod.command;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.DepreciationAggregator;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -30,7 +31,7 @@ public class Command_tossmob extends FreedomCommand
|
||||
|
||||
FPlayer playerData = plugin.pl.getPlayer(playerSender);
|
||||
|
||||
EntityType creature = EntityType.PIG;
|
||||
EntityType type = null;
|
||||
if (args.length >= 1)
|
||||
{
|
||||
if ("off".equals(args[0]))
|
||||
@ -42,19 +43,32 @@ public class Command_tossmob extends FreedomCommand
|
||||
|
||||
if (args[0].equalsIgnoreCase("list"))
|
||||
{
|
||||
msg("Supported mobs: " + StringUtils.join(FUtil.MOB_TYPES.keySet(), ", "), ChatColor.GREEN);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (EntityType loop : EntityType.values())
|
||||
{
|
||||
if (loop.isAlive())
|
||||
{
|
||||
sb.append(" ").append(DepreciationAggregator.getName_EntityType(loop));
|
||||
}
|
||||
}
|
||||
msg("Supported mobs: " + sb.toString().trim(), ChatColor.GREEN);
|
||||
return true;
|
||||
}
|
||||
|
||||
try
|
||||
for (EntityType loopType : EntityType.values())
|
||||
{
|
||||
creature = FUtil.getEntityType(args[0]);
|
||||
if (DepreciationAggregator.getName_EntityType(loopType).toLowerCase().equalsIgnoreCase(args[0]))
|
||||
{
|
||||
type = loopType;
|
||||
break;
|
||||
}
|
||||
catch (Exception ex)
|
||||
}
|
||||
|
||||
if (type == null)
|
||||
{
|
||||
msg(args[0] + " is not a supported mob type. Using a pig instead.", ChatColor.RED);
|
||||
msg("By the way, you can type /tossmob list to see all possible mobs.", ChatColor.RED);
|
||||
creature = EntityType.PIG;
|
||||
type = EntityType.PIG;
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,12 +93,12 @@ public class Command_tossmob extends FreedomCommand
|
||||
speed = 5.0;
|
||||
}
|
||||
|
||||
playerData.enableMobThrower(creature, speed);
|
||||
msg("MobThrower is enabled. Creature: " + creature + " - Speed: " + speed + ".", ChatColor.GREEN);
|
||||
playerData.enableMobThrower(type, speed);
|
||||
msg("MobThrower is enabled. Creature: " + type + " - Speed: " + speed + ".", ChatColor.GREEN);
|
||||
msg("Left click while holding a " + Material.BONE.toString() + " to throw mobs!", ChatColor.GREEN);
|
||||
msg("Type '/tossmob off' to disable. -By Madgeek1450", ChatColor.GREEN);
|
||||
|
||||
playerSender.setItemInHand(new ItemStack(Material.BONE, 1));
|
||||
playerSender.getEquipment().setItemInMainHand(new ItemStack(Material.BONE, 1));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -14,8 +14,8 @@ import org.bukkit.entity.Player;
|
||||
* See https://github.com/TotalFreedom/License - This file may not be edited or removed.
|
||||
*/
|
||||
@CommandPermissions(level = Rank.NON_OP, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Shows information about TotalFreedomMod or reloads it", usage = "/<command> [reload]")
|
||||
public class Command_tfm extends FreedomCommand
|
||||
@CommandParameters(description = "Shows information about TotalFreedomMod or reloads it", usage = "/<command> [reload]", aliases = "tfm")
|
||||
public class Command_totalfreedommod extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
@ -34,7 +34,7 @@ public class Command_tfm extends FreedomCommand
|
||||
return true;
|
||||
}
|
||||
|
||||
MainConfig.load();
|
||||
plugin.config.load();
|
||||
plugin.services.stop();
|
||||
plugin.services.start();
|
||||
|
||||
@ -52,8 +52,9 @@ public class Command_tfm extends FreedomCommand
|
||||
msg("Running on " + ConfigEntry.SERVER_NAME.getString() + ".", ChatColor.GOLD);
|
||||
msg("Created by Madgeek1450 and Prozza.", ChatColor.GOLD);
|
||||
msg(String.format("Version "
|
||||
+ ChatColor.BLUE + "%s.%s " + ChatColor.GOLD + "("
|
||||
+ ChatColor.BLUE + "%s %s.%s " + ChatColor.GOLD + "("
|
||||
+ ChatColor.BLUE + "%s" + ChatColor.GOLD + ")",
|
||||
build.codename,
|
||||
build.version,
|
||||
build.number,
|
||||
build.head), ChatColor.GOLD);
|
@ -23,111 +23,21 @@ import org.bukkit.plugin.RegisteredListener;
|
||||
public class Command_trail extends FreedomCommand
|
||||
{
|
||||
|
||||
private static Listener movementListener = null;
|
||||
private static final List<Player> trailPlayers = new ArrayList<>();
|
||||
private static final Random RANDOM = new Random();
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length > 0 && "off".equals(args[0]))
|
||||
{
|
||||
trailPlayers.remove(playerSender);
|
||||
|
||||
plugin.tr.remove(playerSender);
|
||||
msg("Trail disabled.");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!trailPlayers.contains(playerSender))
|
||||
{
|
||||
trailPlayers.add(playerSender);
|
||||
}
|
||||
|
||||
plugin.tr.add(playerSender);
|
||||
msg("Trail enabled. Use \"/trail off\" to disable.");
|
||||
}
|
||||
|
||||
if (!trailPlayers.isEmpty())
|
||||
{
|
||||
registerMovementHandler();
|
||||
}
|
||||
else
|
||||
{
|
||||
unregisterMovementHandler();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void registerMovementHandler()
|
||||
{
|
||||
if (getRegisteredListener(movementListener) == null)
|
||||
{
|
||||
Bukkit.getPluginManager().registerEvents(movementListener = new Listener()
|
||||
{
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerMove(PlayerMoveEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
if (trailPlayers.contains(player))
|
||||
{
|
||||
Block fromBlock = event.getFrom().getBlock();
|
||||
if (fromBlock.isEmpty())
|
||||
{
|
||||
Block toBlock = event.getTo().getBlock();
|
||||
if (!fromBlock.equals(toBlock))
|
||||
{
|
||||
fromBlock.setType(Material.WOOL);
|
||||
DepreciationAggregator.setData_Block(fromBlock, (byte) RANDOM.nextInt(16));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, TotalFreedomMod.plugin);
|
||||
}
|
||||
}
|
||||
|
||||
private static void unregisterMovementHandler()
|
||||
{
|
||||
Listener registeredListener = getRegisteredListener(movementListener);
|
||||
if (registeredListener != null)
|
||||
{
|
||||
PlayerMoveEvent.getHandlerList().unregister(registeredListener);
|
||||
}
|
||||
}
|
||||
|
||||
private static Listener getRegisteredListener(Listener listener)
|
||||
{
|
||||
RegisteredListener[] registeredListeners = PlayerMoveEvent.getHandlerList().getRegisteredListeners();
|
||||
for (RegisteredListener registeredListener : registeredListeners)
|
||||
{
|
||||
if (registeredListener.getListener() == listener)
|
||||
{
|
||||
return listener;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void startTrail(Player player)
|
||||
{
|
||||
if (!trailPlayers.contains(player))
|
||||
{
|
||||
trailPlayers.add(player);
|
||||
}
|
||||
|
||||
if (!trailPlayers.isEmpty())
|
||||
{
|
||||
registerMovementHandler();
|
||||
}
|
||||
}
|
||||
|
||||
public static void stopTrail(Player player)
|
||||
{
|
||||
trailPlayers.remove(player);
|
||||
|
||||
if (trailPlayers.isEmpty())
|
||||
{
|
||||
unregisterMovementHandler();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ public class Command_wipeflatlands extends FreedomCommand
|
||||
@Override
|
||||
public boolean run(final CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
FUtil.setSavedFlag("do_wipe_flatlands", true);
|
||||
plugin.sf.setSavedFlag("do_wipe_flatlands", true);
|
||||
|
||||
FUtil.bcastMsg("Server is going offline for flatlands wipe.", ChatColor.GRAY);
|
||||
|
||||
|
@ -4,8 +4,9 @@ import lombok.Getter;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
import me.totalfreedom.totalfreedommod.rank.RankBase;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.command.AbstractCommandBase;
|
||||
import net.pravian.aero.util.Players;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -83,7 +84,15 @@ public abstract class FreedomCommand extends AbstractCommandBase<TotalFreedomMod
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkRank(RankBase rank)
|
||||
protected void checkNotHostConsole()
|
||||
{
|
||||
if (isConsole() && FUtil.isFromHostConsole(sender.getName()))
|
||||
{
|
||||
throw new CommandFailException("This command can not be used from the host console.");
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkRank(Rank rank)
|
||||
{
|
||||
if (!plugin.rm.getRank(sender).isAtLeast(rank))
|
||||
{
|
||||
|
@ -3,7 +3,6 @@ package me.totalfreedom.totalfreedommod.command;
|
||||
import java.util.Arrays;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.rank.RankBase;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.command.AeroCommandBase;
|
||||
@ -20,9 +19,12 @@ import org.bukkit.entity.Player;
|
||||
public class FreedomCommandExecutor<C extends AeroCommandBase<?>> extends AbstractCommandExecutor<C>
|
||||
{
|
||||
|
||||
public FreedomCommandExecutor(AeroCommandHandler<?> handler, String name, C command)
|
||||
private final TotalFreedomMod plugin;
|
||||
|
||||
public FreedomCommandExecutor(TotalFreedomMod plugin, AeroCommandHandler<?> handler, String name, C command)
|
||||
{
|
||||
super(handler, name, command);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
protected FreedomCommand getCommand()
|
||||
@ -45,9 +47,25 @@ public class FreedomCommandExecutor<C extends AeroCommandBase<?>> extends Abstra
|
||||
return;
|
||||
}
|
||||
|
||||
String aliasString = params.aliases();
|
||||
|
||||
if (aliasString.length() > 0)
|
||||
{
|
||||
pluginCommand.setAliases(Arrays.asList(params.aliases().split(",")));
|
||||
}
|
||||
pluginCommand.setDescription(params.description());
|
||||
pluginCommand.setUsage(params.usage());
|
||||
|
||||
// Check if permisions are correctly set up
|
||||
CommandPermissions perms = command.getPerms();
|
||||
if (perms != null)
|
||||
{
|
||||
if (perms.level().isConsole())
|
||||
{
|
||||
FLog.warning("[Command] " + pluginCommand.getName() + " - permission is set to a console rank, "
|
||||
+ "should be set to player variant with 'source = SourceType.ONLY_CONSOLE'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -125,7 +143,7 @@ public class FreedomCommandExecutor<C extends AeroCommandBase<?>> extends Abstra
|
||||
// Player permissions
|
||||
if (player != null)
|
||||
{
|
||||
Rank rank = TotalFreedomMod.plugin.rm.getRank(player);
|
||||
Rank rank = plugin.rm.getRank(player);
|
||||
boolean result = rank.isAtLeast(perms.level());
|
||||
if (!result && sendMsg)
|
||||
{
|
||||
@ -135,7 +153,7 @@ public class FreedomCommandExecutor<C extends AeroCommandBase<?>> extends Abstra
|
||||
}
|
||||
|
||||
// Console permissions
|
||||
RankBase rank = TotalFreedomMod.plugin.rm.getRank(sender);
|
||||
Rank rank = plugin.rm.getRank(sender);
|
||||
boolean result = rank.isAtLeast(perms.level());
|
||||
if (!result && sendMsg)
|
||||
{
|
||||
@ -147,10 +165,17 @@ public class FreedomCommandExecutor<C extends AeroCommandBase<?>> extends Abstra
|
||||
public static class FreedomExecutorFactory implements AeroCommandExecutorFactory
|
||||
{
|
||||
|
||||
private final TotalFreedomMod plugin;
|
||||
|
||||
public FreedomExecutorFactory(TotalFreedomMod plugin)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AeroCommandExecutor<? extends AeroCommandBase<?>> newExecutor(AeroCommandHandler<?> handler, String name, AeroCommandBase<?> command)
|
||||
{
|
||||
return new FreedomCommandExecutor<>(handler, name, command);
|
||||
return new FreedomCommandExecutor<>(plugin, handler, name, command);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,34 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.UUID;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
|
||||
public class ConfigConverter
|
||||
{
|
||||
|
||||
public static void convert()
|
||||
{
|
||||
|
||||
for (File file : new File(TotalFreedomMod.plugin.getDataFolder(), "players").listFiles())
|
||||
{
|
||||
if (file.isDirectory())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
final UUID uuid;
|
||||
try
|
||||
{
|
||||
uuid = UUID.fromString(file.getName().split(".")[0]);
|
||||
}
|
||||
catch (IllegalArgumentException ex)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package me.totalfreedom.totalfreedommod.config;
|
||||
|
||||
import java.util.List;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
|
||||
public enum ConfigEntry
|
||||
{
|
||||
@ -106,51 +107,62 @@ public enum ConfigEntry
|
||||
|
||||
public String getString()
|
||||
{
|
||||
return MainConfig.getString(this);
|
||||
return getConfig().getString(this);
|
||||
}
|
||||
|
||||
public String setString(String value)
|
||||
{
|
||||
MainConfig.setString(this, value);
|
||||
getConfig().setString(this, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
public Double getDouble()
|
||||
{
|
||||
return MainConfig.getDouble(this);
|
||||
return getConfig().getDouble(this);
|
||||
}
|
||||
|
||||
public Double setDouble(Double value)
|
||||
{
|
||||
MainConfig.setDouble(this, value);
|
||||
getConfig().setDouble(this, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
public Boolean getBoolean()
|
||||
{
|
||||
return MainConfig.getBoolean(this);
|
||||
return getConfig().getBoolean(this);
|
||||
}
|
||||
|
||||
public Boolean setBoolean(Boolean value)
|
||||
{
|
||||
MainConfig.setBoolean(this, value);
|
||||
getConfig().setBoolean(this, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
public Integer getInteger()
|
||||
{
|
||||
return MainConfig.getInteger(this);
|
||||
return getConfig().getInteger(this);
|
||||
}
|
||||
|
||||
public Integer setInteger(Integer value)
|
||||
{
|
||||
MainConfig.setInteger(this, value);
|
||||
getConfig().setInteger(this, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
public List<?> getList()
|
||||
{
|
||||
return MainConfig.getList(this);
|
||||
return getConfig().getList(this);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<String> getStringList()
|
||||
{
|
||||
return (List<String>) getList();
|
||||
}
|
||||
|
||||
private MainConfig getConfig()
|
||||
{
|
||||
return TotalFreedomMod.plugin().config;
|
||||
}
|
||||
|
||||
public static ConfigEntry findConfigEntry(String name)
|
||||
|
@ -9,41 +9,45 @@ import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import net.pravian.aero.component.PluginComponent;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
public class MainConfig
|
||||
public class MainConfig extends PluginComponent<TotalFreedomMod>
|
||||
{
|
||||
|
||||
public static final File CONFIG_FILE = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.CONFIG_FILENAME);
|
||||
public static final String CONFIG_FILENAME = "config.yml";
|
||||
//
|
||||
private static final EnumMap<ConfigEntry, Object> ENTRY_MAP;
|
||||
private static final TFM_Defaults DEFAULTS;
|
||||
private final EnumMap<ConfigEntry, Object> entries;
|
||||
private final ConfigDefaults defaults;
|
||||
|
||||
static
|
||||
public MainConfig(TotalFreedomMod plugin)
|
||||
{
|
||||
ENTRY_MAP = new EnumMap<>(ConfigEntry.class);
|
||||
super(plugin);
|
||||
|
||||
TFM_Defaults tempDefaults = null;
|
||||
entries = new EnumMap<>(ConfigEntry.class);
|
||||
|
||||
ConfigDefaults tempDefaults = null;
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
InputStream defaultConfig = getDefaultConfig();
|
||||
tempDefaults = new TFM_Defaults(defaultConfig);
|
||||
try (InputStream defaultConfig = getDefaultConfig())
|
||||
{
|
||||
tempDefaults = new ConfigDefaults(defaultConfig);
|
||||
for (ConfigEntry entry : ConfigEntry.values())
|
||||
{
|
||||
ENTRY_MAP.put(entry, tempDefaults.get(entry.getConfigName()));
|
||||
entries.put(entry, tempDefaults.get(entry.getConfigName()));
|
||||
}
|
||||
}
|
||||
defaultConfig.close();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
|
||||
copyDefaultConfig(CONFIG_FILE);
|
||||
copyDefaultConfig(getConfigFile());
|
||||
|
||||
load();
|
||||
}
|
||||
@ -52,21 +56,16 @@ public class MainConfig
|
||||
FLog.severe(ex);
|
||||
}
|
||||
|
||||
DEFAULTS = tempDefaults;
|
||||
defaults = tempDefaults;
|
||||
}
|
||||
|
||||
private MainConfig()
|
||||
{
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static void load()
|
||||
public void load()
|
||||
{
|
||||
try
|
||||
{
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
|
||||
config.load(CONFIG_FILE);
|
||||
config.load(getConfigFile());
|
||||
|
||||
for (ConfigEntry entry : ConfigEntry.values())
|
||||
{
|
||||
@ -76,7 +75,7 @@ public class MainConfig
|
||||
Object value = config.get(path);
|
||||
if (value == null || entry.getType().isAssignableFrom(value.getClass()))
|
||||
{
|
||||
ENTRY_MAP.put(entry, value);
|
||||
entries.put(entry, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -90,21 +89,18 @@ public class MainConfig
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
catch (InvalidConfigurationException ex)
|
||||
catch (IOException | InvalidConfigurationException ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getString(ConfigEntry entry)
|
||||
private File getConfigFile()
|
||||
{
|
||||
return new File(plugin.getDataFolder(), "config.yml");
|
||||
}
|
||||
|
||||
public String getString(ConfigEntry entry)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -117,7 +113,7 @@ public class MainConfig
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void setString(ConfigEntry entry, String value)
|
||||
public void setString(ConfigEntry entry, String value)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -129,7 +125,7 @@ public class MainConfig
|
||||
}
|
||||
}
|
||||
|
||||
public static Double getDouble(ConfigEntry entry)
|
||||
public Double getDouble(ConfigEntry entry)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -142,7 +138,7 @@ public class MainConfig
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void setDouble(ConfigEntry entry, Double value)
|
||||
public void setDouble(ConfigEntry entry, Double value)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -154,7 +150,7 @@ public class MainConfig
|
||||
}
|
||||
}
|
||||
|
||||
public static Boolean getBoolean(ConfigEntry entry)
|
||||
public Boolean getBoolean(ConfigEntry entry)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -167,7 +163,7 @@ public class MainConfig
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void setBoolean(ConfigEntry entry, Boolean value)
|
||||
public void setBoolean(ConfigEntry entry, Boolean value)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -179,7 +175,7 @@ public class MainConfig
|
||||
}
|
||||
}
|
||||
|
||||
public static Integer getInteger(ConfigEntry entry)
|
||||
public Integer getInteger(ConfigEntry entry)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -192,7 +188,7 @@ public class MainConfig
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void setInteger(ConfigEntry entry, Integer value)
|
||||
public void setInteger(ConfigEntry entry, Integer value)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -204,7 +200,7 @@ public class MainConfig
|
||||
}
|
||||
}
|
||||
|
||||
public static List getList(ConfigEntry entry)
|
||||
public List getList(ConfigEntry entry)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -217,9 +213,9 @@ public class MainConfig
|
||||
return null;
|
||||
}
|
||||
|
||||
public static <T> T get(ConfigEntry entry, Class<T> type) throws IllegalArgumentException
|
||||
public <T> T get(ConfigEntry entry, Class<T> type) throws IllegalArgumentException
|
||||
{
|
||||
Object value = ENTRY_MAP.get(entry);
|
||||
Object value = entries.get(entry);
|
||||
try
|
||||
{
|
||||
return type.cast(value);
|
||||
@ -230,7 +226,7 @@ public class MainConfig
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> void set(ConfigEntry entry, T value, Class<T> type) throws IllegalArgumentException
|
||||
public <T> void set(ConfigEntry entry, T value, Class<T> type) throws IllegalArgumentException
|
||||
{
|
||||
if (!type.isAssignableFrom(entry.getType()))
|
||||
{
|
||||
@ -240,10 +236,10 @@ public class MainConfig
|
||||
{
|
||||
throw new IllegalArgumentException("Value is not of type " + type.getSimpleName());
|
||||
}
|
||||
ENTRY_MAP.put(entry, value);
|
||||
entries.put(entry, value);
|
||||
}
|
||||
|
||||
private static void copyDefaultConfig(File targetFile)
|
||||
private void copyDefaultConfig(File targetFile)
|
||||
{
|
||||
if (targetFile.exists())
|
||||
{
|
||||
@ -254,9 +250,10 @@ public class MainConfig
|
||||
|
||||
try
|
||||
{
|
||||
InputStream defaultConfig = getDefaultConfig();
|
||||
try (InputStream defaultConfig = getDefaultConfig())
|
||||
{
|
||||
FileUtils.copyInputStreamToFile(defaultConfig, targetFile);
|
||||
defaultConfig.close();
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
@ -264,22 +261,22 @@ public class MainConfig
|
||||
}
|
||||
}
|
||||
|
||||
private static InputStream getDefaultConfig()
|
||||
private InputStream getDefaultConfig()
|
||||
{
|
||||
return TotalFreedomMod.plugin.getResource(TotalFreedomMod.CONFIG_FILENAME);
|
||||
return plugin.getResource(TotalFreedomMod.CONFIG_FILENAME);
|
||||
}
|
||||
|
||||
public static TFM_Defaults getDefaults()
|
||||
public ConfigDefaults getDefaults()
|
||||
{
|
||||
return DEFAULTS;
|
||||
return defaults;
|
||||
}
|
||||
|
||||
public static class TFM_Defaults
|
||||
public static class ConfigDefaults
|
||||
{
|
||||
|
||||
private YamlConfiguration defaults = null;
|
||||
|
||||
private TFM_Defaults(InputStream defaultConfig)
|
||||
private ConfigDefaults(InputStream defaultConfig)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -56,6 +56,12 @@ public class FreezeData
|
||||
|
||||
location = player.getLocation(); // Blockify location
|
||||
FUtil.setFlying(player, true); // Avoid infinite falling
|
||||
|
||||
if (fPlayer.getPlugin().al.isAdminImpostor(player))
|
||||
{
|
||||
return; // Don't run unfreeze task for impostors
|
||||
}
|
||||
|
||||
unfreeze = new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
@ -65,7 +71,7 @@ public class FreezeData
|
||||
setFrozen(false);
|
||||
}
|
||||
|
||||
}.runTaskLater(TotalFreedomMod.plugin, AUTO_PURGE_TICKS);
|
||||
}.runTaskLater(fPlayer.getPlugin(), AUTO_PURGE_TICKS);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -34,12 +34,12 @@ public class Freezer extends FreedomService
|
||||
|
||||
public void setGlobalFreeze(boolean frozen)
|
||||
{
|
||||
this.globalFreeze = true;
|
||||
this.globalFreeze = frozen;
|
||||
}
|
||||
|
||||
public void purge()
|
||||
{
|
||||
setGlobalFreeze(false);
|
||||
this.globalFreeze = false;
|
||||
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
|
@ -70,14 +70,14 @@ public class ItemFun extends FreedomService
|
||||
if (!plugin.al.isSeniorAdmin(player))
|
||||
{
|
||||
final StringBuilder msg = new StringBuilder();
|
||||
final char[] chars = (player.getName() + " is a clown.").toCharArray();
|
||||
final char[] chars = ("You are a clown.").toCharArray();
|
||||
for (char c : chars)
|
||||
{
|
||||
msg.append(FUtil.randomChatColor()).append(c);
|
||||
}
|
||||
FUtil.bcastMsg(msg.toString());
|
||||
player.sendMessage(msg.toString());
|
||||
|
||||
player.getInventory().getItemInHand().setType(Material.POTATO_ITEM);
|
||||
player.getEquipment().getItemInMainHand().setType(Material.POTATO_ITEM);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -126,7 +126,7 @@ public class ItemFun extends FreedomService
|
||||
break;
|
||||
}
|
||||
|
||||
case CARROT:
|
||||
case CARROT_ITEM:
|
||||
{
|
||||
if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
|
||||
{
|
||||
@ -185,7 +185,7 @@ public class ItemFun extends FreedomService
|
||||
tntBlock.setType(Material.AIR);
|
||||
}
|
||||
}
|
||||
}.runTaskLater(TotalFreedomMod.plugin, 30L);
|
||||
}.runTaskLater(plugin, 30L);
|
||||
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
@ -220,7 +220,7 @@ public class ItemFun extends FreedomService
|
||||
|
||||
if (fPlayer.toggleMP44Firing())
|
||||
{
|
||||
fPlayer.startArrowShooter(TotalFreedomMod.plugin);
|
||||
fPlayer.startArrowShooter(plugin);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -0,0 +1,76 @@
|
||||
package me.totalfreedom.totalfreedommod.fun;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.util.DepreciationAggregator;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
public class Trailer extends FreedomService
|
||||
{
|
||||
|
||||
private final Random random = new Random();
|
||||
private final Set<String> trailPlayers = new HashSet<>(); // player name
|
||||
|
||||
public Trailer(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerMove(PlayerMoveEvent event)
|
||||
{
|
||||
if (trailPlayers.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!trailPlayers.contains(event.getPlayer().getName()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Block fromBlock = event.getFrom().getBlock();
|
||||
if (!fromBlock.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Block toBlock = event.getTo().getBlock();
|
||||
if (fromBlock.equals(toBlock))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
fromBlock.setType(Material.WOOL);
|
||||
DepreciationAggregator.setData_Block(fromBlock, (byte) random.nextInt(16));
|
||||
}
|
||||
|
||||
public void remove(Player player)
|
||||
{
|
||||
trailPlayers.remove(player.getName());
|
||||
}
|
||||
|
||||
public void add(Player player)
|
||||
{
|
||||
trailPlayers.add(player.getName());
|
||||
}
|
||||
}
|
@ -10,7 +10,6 @@ public class HTMLGenerationTools
|
||||
|
||||
private HTMLGenerationTools()
|
||||
{
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static String paragraph(String data)
|
||||
|
@ -3,7 +3,8 @@ package me.totalfreedom.totalfreedommod.httpd;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||
@ -11,6 +12,8 @@ import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
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_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;
|
||||
@ -21,18 +24,16 @@ 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.bukkit.Bukkit;
|
||||
|
||||
public class HTTPDaemon extends FreedomService
|
||||
{
|
||||
|
||||
public static String MIME_DEFAULT_BINARY = "application/octet-stream";
|
||||
//
|
||||
private static final Pattern EXT_REGEX = Pattern.compile("\\.([^\\.\\s]+)$");
|
||||
//
|
||||
public static final int PORT = ConfigEntry.HTTPD_PORT.getInteger();
|
||||
//
|
||||
private static final TFM_HTTPD HTTPD = new TFM_HTTPD(PORT);
|
||||
public int port;
|
||||
private HTTPD httpd;
|
||||
public Map<String, ModuleExecutable> modules = new HashMap<>();
|
||||
|
||||
public HTTPDaemon(TotalFreedomMod plugin)
|
||||
{
|
||||
@ -47,13 +48,27 @@ public class HTTPDaemon extends FreedomService
|
||||
return;
|
||||
}
|
||||
|
||||
port = ConfigEntry.HTTPD_PORT.getInteger();;
|
||||
httpd = new HTTPD(port);
|
||||
|
||||
// Modules
|
||||
modules.clear();
|
||||
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("logs", Module_logs.class, true);
|
||||
module("permbans", Module_permbans.class, true);
|
||||
module("players", Module_players.class, false);
|
||||
module("schematic", Module_schematic.class, true);
|
||||
|
||||
try
|
||||
{
|
||||
HTTPD.start();
|
||||
httpd.start();
|
||||
|
||||
if (HTTPD.isAlive())
|
||||
if (httpd.isAlive())
|
||||
{
|
||||
FLog.info("TFM HTTPd started. Listening on port: " + HTTPD.getListeningPort());
|
||||
FLog.info("TFM HTTPd started. Listening on port: " + httpd.getListeningPort());
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -74,160 +89,25 @@ public class HTTPDaemon extends FreedomService
|
||||
return;
|
||||
}
|
||||
|
||||
HTTPD.stop();
|
||||
httpd.stop();
|
||||
|
||||
FLog.info("TFM HTTPd stopped.");
|
||||
}
|
||||
|
||||
private static enum ModuleType
|
||||
private void module(String name, Class<? extends HTTPDModule> clazz, boolean async)
|
||||
{
|
||||
|
||||
DUMP(new ModuleExecutable(false, "dump")
|
||||
{
|
||||
@Override
|
||||
public Response getResponse(HTTPSession session)
|
||||
{
|
||||
return new Response(Response.Status.OK, NanoHTTPD.MIME_PLAINTEXT, "The DUMP module is disabled. It is intended for debugging use only.");
|
||||
}
|
||||
}),
|
||||
HELP(new ModuleExecutable(true, "help")
|
||||
{
|
||||
@Override
|
||||
public Response getResponse(HTTPSession session)
|
||||
{
|
||||
return new Module_help(session).getResponse();
|
||||
}
|
||||
}),
|
||||
LIST(new ModuleExecutable(true, "list")
|
||||
{
|
||||
@Override
|
||||
public Response getResponse(HTTPSession session)
|
||||
{
|
||||
return new Module_list(session).getResponse();
|
||||
}
|
||||
}),
|
||||
FILE(new ModuleExecutable(false, "file")
|
||||
{
|
||||
@Override
|
||||
public Response getResponse(HTTPSession session)
|
||||
{
|
||||
return new Module_file(session).getResponse();
|
||||
}
|
||||
}),
|
||||
SCHEMATIC(new ModuleExecutable(false, "schematic")
|
||||
{
|
||||
@Override
|
||||
public Response getResponse(HTTPSession session)
|
||||
{
|
||||
return new Module_schematic(session).getResponse();
|
||||
}
|
||||
}),
|
||||
PERMBANS(new ModuleExecutable(false, "permbans")
|
||||
{
|
||||
@Override
|
||||
public Response getResponse(HTTPSession session)
|
||||
{
|
||||
return new Module_permbans(session).getResponse();
|
||||
}
|
||||
}),
|
||||
PLAYERS(new ModuleExecutable(true, "players")
|
||||
{
|
||||
@Override
|
||||
public Response getResponse(HTTPSession session)
|
||||
{
|
||||
return new Module_players(session).getResponse();
|
||||
}
|
||||
}),
|
||||
LOGS(new ModuleExecutable(false, "logs")
|
||||
{
|
||||
@Override
|
||||
public Response getResponse(HTTPSession session)
|
||||
{
|
||||
return new Module_logs(session).getResponse();
|
||||
}
|
||||
});
|
||||
//
|
||||
private final ModuleExecutable moduleExecutable;
|
||||
|
||||
private ModuleType(ModuleExecutable moduleExecutable)
|
||||
{
|
||||
this.moduleExecutable = moduleExecutable;
|
||||
modules.put(name, ModuleExecutable.forClass(plugin, clazz, async));
|
||||
}
|
||||
|
||||
private abstract static class ModuleExecutable
|
||||
private class HTTPD extends NanoHTTPD
|
||||
{
|
||||
|
||||
private final boolean runOnBukkitThread;
|
||||
private final String name;
|
||||
|
||||
private ModuleExecutable(boolean runOnBukkitThread, String name)
|
||||
{
|
||||
this.runOnBukkitThread = runOnBukkitThread;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Response execute(final HTTPSession session)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (this.runOnBukkitThread)
|
||||
{
|
||||
return Bukkit.getScheduler().callSyncMethod(TotalFreedomMod.plugin, new Callable<Response>()
|
||||
{
|
||||
@Override
|
||||
public Response call() throws Exception
|
||||
{
|
||||
return getResponse(session);
|
||||
}
|
||||
}).get();
|
||||
}
|
||||
else
|
||||
{
|
||||
return getResponse(session);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract Response getResponse(HTTPSession session);
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
public ModuleExecutable getModuleExecutable()
|
||||
{
|
||||
return moduleExecutable;
|
||||
}
|
||||
|
||||
private static ModuleType getByName(String needle)
|
||||
{
|
||||
for (ModuleType type : values())
|
||||
{
|
||||
if (type.getModuleExecutable().getName().equalsIgnoreCase(needle))
|
||||
{
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return FILE;
|
||||
}
|
||||
}
|
||||
|
||||
private static class TFM_HTTPD extends NanoHTTPD
|
||||
{
|
||||
|
||||
public TFM_HTTPD(int port)
|
||||
private HTTPD(int port)
|
||||
{
|
||||
super(port);
|
||||
}
|
||||
|
||||
public TFM_HTTPD(String hostname, int port)
|
||||
private HTTPD(String hostname, int port)
|
||||
{
|
||||
super(hostname, port);
|
||||
}
|
||||
@ -235,25 +115,28 @@ public class HTTPDaemon extends FreedomService
|
||||
@Override
|
||||
public Response serve(HTTPSession session)
|
||||
{
|
||||
Response response;
|
||||
final String[] args = StringUtils.split(session.getUri(), "/");
|
||||
|
||||
ModuleExecutable mex = modules.get("file");
|
||||
if (args.length >= 1)
|
||||
{
|
||||
mex = modules.get(args[0].toLowerCase());
|
||||
}
|
||||
|
||||
if (mex == null)
|
||||
{
|
||||
return new Response(Response.Status.NOT_FOUND, MIME_PLAINTEXT, "Error 404: Not Found - The requested resource was not found on this server.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
final String[] args = StringUtils.split(session.getUri(), "/");
|
||||
final ModuleType moduleType = args.length >= 1 ? ModuleType.getByName(args[0]) : ModuleType.FILE;
|
||||
response = moduleType.getModuleExecutable().execute(session);
|
||||
return mex.execute(session);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
response = new Response(Response.Status.INTERNAL_ERROR, MIME_PLAINTEXT, "Error 500: Internal Server Error\r\n" + ex.getMessage() + "\r\n" + ExceptionUtils.getStackTrace(ex));
|
||||
FLog.severe(ex);
|
||||
return new Response(Response.Status.INTERNAL_ERROR, MIME_PLAINTEXT, "Error 500: Internal Server Error\r\n" + ex.getMessage() + "\r\n" + ExceptionUtils.getStackTrace(ex));
|
||||
}
|
||||
|
||||
if (response == null)
|
||||
{
|
||||
response = new Response(Response.Status.NOT_FOUND, MIME_PLAINTEXT, "Error 404: Not Found - The requested resource was not found on this server.");
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
@ -289,4 +172,5 @@ public class HTTPDaemon extends FreedomService
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,85 @@
|
||||
package me.totalfreedom.totalfreedommod.httpd;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import lombok.Getter;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.HTTPDModule;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import net.pravian.aero.component.PluginComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public abstract class ModuleExecutable
|
||||
{
|
||||
|
||||
@Getter
|
||||
private final boolean async;
|
||||
|
||||
public ModuleExecutable(boolean async)
|
||||
{
|
||||
this.async = async;
|
||||
}
|
||||
|
||||
public NanoHTTPD.Response execute(final NanoHTTPD.HTTPSession session)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (async)
|
||||
{
|
||||
return getResponse(session);
|
||||
}
|
||||
|
||||
// Sync to server thread
|
||||
return Bukkit.getScheduler().callSyncMethod(TotalFreedomMod.plugin(), new Callable<NanoHTTPD.Response>()
|
||||
{
|
||||
@Override
|
||||
public NanoHTTPD.Response call() throws Exception
|
||||
{
|
||||
return getResponse(session);
|
||||
}
|
||||
}).get();
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract NanoHTTPD.Response getResponse(NanoHTTPD.HTTPSession session);
|
||||
|
||||
public static ModuleExecutable forClass(final TotalFreedomMod plugin, Class<? extends HTTPDModule> clazz, boolean async)
|
||||
{
|
||||
final Constructor<? extends HTTPDModule> cons;
|
||||
try
|
||||
{
|
||||
cons = clazz.getConstructor(TotalFreedomMod.class, NanoHTTPD.HTTPSession.class);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new IllegalArgumentException("Improperly defined module!");
|
||||
}
|
||||
|
||||
return new ModuleExecutable(async)
|
||||
{
|
||||
@Override
|
||||
public NanoHTTPD.Response getResponse(NanoHTTPD.HTTPSession session)
|
||||
{
|
||||
try
|
||||
{
|
||||
return cons.newInstance(plugin, session).getResponse();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
@ -3,13 +3,16 @@ package me.totalfreedom.totalfreedommod.httpd.module;
|
||||
import java.net.Socket;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import lombok.Getter;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.httpd.HTTPDPageBuilder;
|
||||
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.HTTPSession;
|
||||
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.Method;
|
||||
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.Response;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import net.pravian.aero.component.PluginComponent;
|
||||
|
||||
public abstract class HTTPDModule
|
||||
public abstract class HTTPDModule extends PluginComponent<TotalFreedomMod>
|
||||
{
|
||||
|
||||
protected final String uri;
|
||||
@ -19,8 +22,9 @@ public abstract class HTTPDModule
|
||||
protected final Socket socket;
|
||||
protected final HTTPSession session;
|
||||
|
||||
public HTTPDModule(HTTPSession session)
|
||||
public HTTPDModule(TotalFreedomMod plugin, HTTPSession session)
|
||||
{
|
||||
super(plugin);
|
||||
this.uri = session.getUri();
|
||||
this.method = session.getMethod();
|
||||
this.headers = session.getHeaders();
|
||||
|
@ -4,6 +4,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import static me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools.list;
|
||||
import static me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools.paragraph;
|
||||
import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon;
|
||||
@ -18,9 +19,9 @@ public class Module_dump extends HTTPDModule
|
||||
private File echoFile = null;
|
||||
private final String body;
|
||||
|
||||
public Module_dump(NanoHTTPD.HTTPSession session)
|
||||
public Module_dump(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session)
|
||||
{
|
||||
super(session);
|
||||
super(plugin, session);
|
||||
|
||||
//Body needs to be computed before getResponse, so we know if a text response or a file echo is needed.
|
||||
this.body = body();
|
||||
|
@ -12,6 +12,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon;
|
||||
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
|
||||
@ -57,9 +58,9 @@ public class Module_file extends HTTPDModule
|
||||
MIME_TYPES.put("class", "application/octet-stream");
|
||||
}
|
||||
|
||||
public Module_file(NanoHTTPD.HTTPSession session)
|
||||
public Module_file(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session)
|
||||
{
|
||||
super(session);
|
||||
super(plugin, session);
|
||||
}
|
||||
|
||||
private File getRootDir()
|
||||
|
@ -13,7 +13,7 @@ import me.totalfreedom.totalfreedommod.command.FreedomCommand;
|
||||
import static me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools.heading;
|
||||
import static me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools.paragraph;
|
||||
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
|
||||
import me.totalfreedom.totalfreedommod.rank.RankBase;
|
||||
import me.totalfreedom.totalfreedommod.rank.Displayable;
|
||||
import net.pravian.aero.command.CommandReflection;
|
||||
import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -25,9 +25,9 @@ import org.bukkit.command.SimpleCommandMap;
|
||||
public class Module_help extends HTTPDModule
|
||||
{
|
||||
|
||||
public Module_help(NanoHTTPD.HTTPSession session)
|
||||
public Module_help(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session)
|
||||
{
|
||||
super(session);
|
||||
super(plugin, session);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -77,7 +77,7 @@ public class Module_help extends HTTPDModule
|
||||
|
||||
responseBody.append(heading(pluginName, 2)).append("<ul>\r\n");
|
||||
|
||||
RankBase lastTfmCommandLevel = null;
|
||||
Displayable lastTfmCommandLevel = null;
|
||||
for (Command command : commands)
|
||||
{
|
||||
if (!TotalFreedomMod.pluginName.equals(pluginName))
|
||||
@ -86,7 +86,7 @@ public class Module_help extends HTTPDModule
|
||||
continue;
|
||||
}
|
||||
|
||||
RankBase tfmCommandLevel = FreedomCommand.getFrom(command).getPerms().level();
|
||||
Displayable tfmCommandLevel = FreedomCommand.getFrom(command).getPerms().level();
|
||||
if (lastTfmCommandLevel == null || lastTfmCommandLevel != tfmCommandLevel)
|
||||
{
|
||||
responseBody.append("</ul>\r\n").append(heading(tfmCommandLevel.getName(), 3)).append("<ul>\r\n");
|
||||
|
@ -9,9 +9,9 @@ import org.bukkit.entity.Player;
|
||||
public class Module_list extends HTTPDModule
|
||||
{
|
||||
|
||||
public Module_list(NanoHTTPD.HTTPSession session)
|
||||
public Module_list(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session)
|
||||
{
|
||||
super(session);
|
||||
super(plugin, session);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -27,7 +27,7 @@ public class Module_list extends HTTPDModule
|
||||
|
||||
for (Player player : onlinePlayers)
|
||||
{
|
||||
String tag = TotalFreedomMod.plugin.rm.getDisplay(player).getTag();
|
||||
String tag = plugin.rm.getDisplay(player).getTag();
|
||||
body.append("<li>").append(tag).append(player.getName()).append("</li>\r\n");
|
||||
}
|
||||
|
||||
|
@ -1,15 +1,16 @@
|
||||
package me.totalfreedom.totalfreedommod.httpd.module;
|
||||
|
||||
import java.io.File;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
|
||||
|
||||
public class Module_logs extends Module_file
|
||||
{
|
||||
|
||||
public Module_logs(NanoHTTPD.HTTPSession session)
|
||||
public Module_logs(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session)
|
||||
{
|
||||
super(session);
|
||||
super(plugin, session);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -9,18 +9,18 @@ import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
|
||||
public class Module_permbans extends HTTPDModule
|
||||
{
|
||||
|
||||
public Module_permbans(NanoHTTPD.HTTPSession session)
|
||||
public Module_permbans(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session)
|
||||
{
|
||||
super(session);
|
||||
super(plugin, session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NanoHTTPD.Response getResponse()
|
||||
{
|
||||
File permbanFile = new File(TotalFreedomMod.plugin.getDataFolder(), PermbanList.CONFIG_FILENAME);
|
||||
File permbanFile = new File(plugin.getDataFolder(), PermbanList.CONFIG_FILENAME);
|
||||
if (permbanFile.exists())
|
||||
{
|
||||
return HTTPDaemon.serveFileBasic(new File(TotalFreedomMod.plugin.getDataFolder(), PermbanList.CONFIG_FILENAME));
|
||||
return HTTPDaemon.serveFileBasic(new File(plugin.getDataFolder(), PermbanList.CONFIG_FILENAME));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -12,9 +12,9 @@ import org.json.simple.JSONObject;
|
||||
public class Module_players extends HTTPDModule
|
||||
{
|
||||
|
||||
public Module_players(NanoHTTPD.HTTPSession session)
|
||||
public Module_players(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session)
|
||||
{
|
||||
super(session);
|
||||
super(plugin, session);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -36,7 +36,7 @@ public class Module_players extends HTTPDModule
|
||||
}
|
||||
|
||||
// Admins
|
||||
for (Admin admin : TotalFreedomMod.plugin.al.getAllAdmins().values())
|
||||
for (Admin admin : plugin.al.getAllAdmins().values())
|
||||
{
|
||||
final String username = admin.getName();
|
||||
|
||||
@ -49,7 +49,7 @@ public class Module_players extends HTTPDModule
|
||||
telnetadmins.add(username);
|
||||
break;
|
||||
case SENIOR_ADMIN:
|
||||
senioradmins.add(senioradmins);
|
||||
senioradmins.add(username);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -39,9 +39,9 @@ public class Module_schematic extends HTTPDModule
|
||||
+ "<button type=\"submit\">Submit</button>\n"
|
||||
+ "</form>";
|
||||
|
||||
public Module_schematic(NanoHTTPD.HTTPSession session)
|
||||
public Module_schematic(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session)
|
||||
{
|
||||
super(session);
|
||||
super(plugin, session);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -235,7 +235,7 @@ public class Module_schematic extends HTTPDModule
|
||||
|
||||
private boolean isAuthorized(String remoteAddress)
|
||||
{
|
||||
Admin entry = TotalFreedomMod.plugin.al.getEntryByIp(remoteAddress);
|
||||
Admin entry = plugin.al.getEntryByIp(remoteAddress);
|
||||
return entry != null && entry.isActive();
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,8 @@ public class FPlayer
|
||||
|
||||
public static final long AUTO_PURGE_TICKS = 5L * 60L * 20L;
|
||||
|
||||
@Getter
|
||||
private final TotalFreedomMod plugin;
|
||||
@Getter
|
||||
private final String name;
|
||||
@Getter
|
||||
@ -33,7 +35,6 @@ public class FPlayer
|
||||
private Player player;
|
||||
//
|
||||
private BukkitTask unmuteTask;
|
||||
private BukkitTask unfreezeTask;
|
||||
@Getter
|
||||
private final FreezeData freezeData = new FreezeData(this);
|
||||
@Getter
|
||||
@ -58,19 +59,22 @@ public class FPlayer
|
||||
private String lastMessage = "";
|
||||
private boolean inAdminchat = false;
|
||||
private boolean allCommandsBlocked = false;
|
||||
private boolean verifiedSuperadminId = false;
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean superadminIdVerified = false;
|
||||
private String lastCommand = "";
|
||||
private boolean cmdspyEnabled = false;
|
||||
private String tag = null;
|
||||
private int warningCount = 0;
|
||||
|
||||
public FPlayer(Player player)
|
||||
public FPlayer(TotalFreedomMod plugin, Player player)
|
||||
{
|
||||
this(player.getName(), Ips.getIp(player));
|
||||
this(plugin, player.getName(), Ips.getIp(player));
|
||||
}
|
||||
|
||||
private FPlayer(String name, String ip)
|
||||
private FPlayer(TotalFreedomMod plugin, String name, String ip)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
this.name = name;
|
||||
this.ip = ip;
|
||||
}
|
||||
@ -278,15 +282,19 @@ public class FPlayer
|
||||
return;
|
||||
}
|
||||
|
||||
if (getPlayer() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
unmuteTask = new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
FUtil.adminAction("TotalFreedom", "Unmuting " + player.getName(), false);
|
||||
FUtil.adminAction("TotalFreedom", "Unmuting " + getPlayer().getName(), false);
|
||||
setMuted(false);
|
||||
}
|
||||
}.runTaskLater(TotalFreedomMod.plugin, AUTO_PURGE_TICKS);
|
||||
}.runTaskLater(plugin, AUTO_PURGE_TICKS);
|
||||
}
|
||||
|
||||
public BukkitTask getLockupScheduleID()
|
||||
@ -329,20 +337,6 @@ public class FPlayer
|
||||
this.allCommandsBlocked = commandsBlocked;
|
||||
}
|
||||
|
||||
// If someone logs in to telnet or minecraft, and they are an admin, make sure that they are using a username that is associated with their IP.
|
||||
// After the check for this is done in TFM_PlayerListener, never change it elsewhere.
|
||||
public boolean isSuperadminIdVerified()
|
||||
{
|
||||
return this.verifiedSuperadminId;
|
||||
}
|
||||
|
||||
// If someone logs in to telnet or minecraft, and they are an admin, make sure that they are using a username that is associated with their IP.
|
||||
// After the check for this is done in TFM_PlayerListener, never change it elsewhere.
|
||||
public void setSuperadminIdVerified(boolean verifiedSuperadminId)
|
||||
{
|
||||
this.verifiedSuperadminId = verifiedSuperadminId;
|
||||
}
|
||||
|
||||
public String getLastCommand()
|
||||
{
|
||||
return lastCommand;
|
||||
@ -391,8 +385,9 @@ public class FPlayer
|
||||
|
||||
if (this.warningCount % 2 == 0)
|
||||
{
|
||||
this.player.getWorld().strikeLightning(this.player.getLocation());
|
||||
FUtil.playerMsg(this.player, ChatColor.RED + "You have been warned at least twice now, make sure to read the rules at " + ConfigEntry.SERVER_BAN_URL.getString());
|
||||
Player p = getPlayer();
|
||||
p.getWorld().strikeLightning(p.getLocation());
|
||||
FUtil.playerMsg(p, ChatColor.RED + "You have been warned at least twice now, make sure to read the rules at " + ConfigEntry.SERVER_BAN_URL.getString());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,7 @@ public class PlayerList extends FreedomService
|
||||
return tPlayer;
|
||||
}
|
||||
|
||||
tPlayer = new FPlayer(player);
|
||||
tPlayer = new FPlayer(plugin, player);
|
||||
playerMap.put(Ips.getIp(player), tPlayer);
|
||||
|
||||
return tPlayer;
|
||||
@ -214,7 +214,7 @@ public class PlayerList extends FreedomService
|
||||
|
||||
protected YamlConfig getConfig(PlayerData data)
|
||||
{
|
||||
final YamlConfig config = new YamlConfig(TotalFreedomMod.plugin, getConfigFile(data.getUsername().toLowerCase()), false);
|
||||
final YamlConfig config = new YamlConfig(plugin, getConfigFile(data.getUsername().toLowerCase()), false);
|
||||
config.load();
|
||||
return config;
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package me.totalfreedom.totalfreedommod.rank;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public interface RankBase
|
||||
public interface Displayable
|
||||
{
|
||||
|
||||
public String getName();
|
||||
@ -17,8 +17,4 @@ public interface RankBase
|
||||
|
||||
public String getColoredLoginMessage();
|
||||
|
||||
public boolean isAtLeast(RankBase rank);
|
||||
|
||||
public int getLevel();
|
||||
|
||||
}
|
@ -3,18 +3,17 @@ package me.totalfreedom.totalfreedommod.rank;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public enum Rank implements RankBase
|
||||
public enum Rank implements Displayable
|
||||
{
|
||||
|
||||
IMPOSTOR(Type.PLAYER, "an", "Imp", ChatColor.YELLOW),
|
||||
NON_OP(Type.PLAYER, "a", "", ChatColor.GREEN),
|
||||
OP(Type.PLAYER, "an", "OP", ChatColor.RED),
|
||||
SUPER_ADMIN(Type.ADMIN, "a", "SA", ChatColor.GOLD),
|
||||
TELNET_ADMIN(Type.ADMIN, "a", "STA", ChatColor.DARK_GREEN),
|
||||
SENIOR_ADMIN(Type.ADMIN, "a", "SrA", ChatColor.LIGHT_PURPLE),
|
||||
TELNET_CONSOLE(),
|
||||
SENIOR_CONSOLE();
|
||||
//
|
||||
IMPOSTOR("an", "Impostor", Type.PLAYER, "Imp", ChatColor.YELLOW),
|
||||
NON_OP("a", "Non-Op", Type.PLAYER, "", ChatColor.GREEN),
|
||||
OP("an", "Op", Type.PLAYER, "OP", ChatColor.RED),
|
||||
SUPER_ADMIN("a", "Super Admin", Type.ADMIN, "SA", ChatColor.AQUA),
|
||||
TELNET_ADMIN("a", "Telnet Admin", Type.ADMIN, "STA", ChatColor.DARK_GREEN),
|
||||
SENIOR_ADMIN("a", "Senior Admin", Type.ADMIN, "SrA", ChatColor.GOLD),
|
||||
TELNET_CONSOLE("the", "Console", Type.ADMIN_CONSOLE, "Console", ChatColor.DARK_PURPLE),
|
||||
SENIOR_CONSOLE("the", "Console", Type.ADMIN_CONSOLE, "Console", ChatColor.DARK_PURPLE);
|
||||
@Getter
|
||||
private final Type type;
|
||||
@Getter
|
||||
@ -23,58 +22,30 @@ public enum Rank implements RankBase
|
||||
@Getter
|
||||
private final String tag;
|
||||
@Getter
|
||||
private final String coloredTag;
|
||||
@Getter
|
||||
private final ChatColor color;
|
||||
|
||||
private Rank()
|
||||
{
|
||||
this("Console", Type.ADMIN_CONSOLE, "the", "Console", ChatColor.DARK_PURPLE);
|
||||
}
|
||||
|
||||
private Rank(Type type, String determiner, String tag, ChatColor color)
|
||||
{
|
||||
this.type = type;
|
||||
|
||||
// Name
|
||||
final String[] nameParts = name().toLowerCase().split("_");
|
||||
String tempName = "";
|
||||
for (String part : nameParts)
|
||||
{
|
||||
tempName += Character.toUpperCase(part.charAt(0)) + part.substring(1) + " ";
|
||||
}
|
||||
name = tempName.trim();
|
||||
|
||||
this.determiner = determiner;
|
||||
this.tag = tag.length() > 0 ? "[" + tag + "]" : "";
|
||||
|
||||
// Colors
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
private Rank(String name, Type type, String determiner, String tag, ChatColor color)
|
||||
private Rank(String determiner, String name, Type type, String abbr, ChatColor color)
|
||||
{
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.determiner = determiner;
|
||||
this.tag = "[" + tag + "]";
|
||||
this.tag = abbr.isEmpty() ? "" : "[" + abbr + "]";
|
||||
this.coloredTag = abbr.isEmpty() ? "" : ChatColor.DARK_GRAY + "[" + color + abbr + ChatColor.DARK_GRAY + "]" + color;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColoredName()
|
||||
{
|
||||
return getColor() + getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColoredTag()
|
||||
{
|
||||
return getColor() + getTag();
|
||||
return color + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColoredLoginMessage()
|
||||
{
|
||||
return determiner + " " + getColoredName();
|
||||
return determiner + " " + color + ChatColor.ITALIC + name;
|
||||
}
|
||||
|
||||
public boolean isConsole()
|
||||
@ -82,16 +53,24 @@ public enum Rank implements RankBase
|
||||
return getType() == Type.ADMIN_CONSOLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevel()
|
||||
{
|
||||
return ordinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAtLeast(RankBase rank)
|
||||
public boolean isAtLeast(Rank rank)
|
||||
{
|
||||
return getLevel() >= rank.getLevel();
|
||||
if (getLevel() < rank.getLevel())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!hasConsoleVariant() || !rank.hasConsoleVariant())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return getConsoleVariant().getLevel() >= rank.getConsoleVariant().getLevel();
|
||||
}
|
||||
|
||||
public boolean isAdmin()
|
||||
@ -99,7 +78,7 @@ public enum Rank implements RankBase
|
||||
return getType() == Type.ADMIN || getType() == Type.ADMIN_CONSOLE;
|
||||
}
|
||||
|
||||
public boolean hasConsole()
|
||||
public boolean hasConsoleVariant()
|
||||
{
|
||||
return getConsoleVariant() != null;
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
package me.totalfreedom.totalfreedommod.rank;
|
||||
|
||||
import java.util.List;
|
||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.config.MainConfig;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.util.ChatUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -34,7 +34,7 @@ public class RankManager extends FreedomService
|
||||
{
|
||||
}
|
||||
|
||||
public RankBase getDisplay(CommandSender sender)
|
||||
public Displayable getDisplay(CommandSender sender)
|
||||
{
|
||||
if (!(sender instanceof Player))
|
||||
{
|
||||
@ -64,7 +64,7 @@ public class RankManager extends FreedomService
|
||||
}
|
||||
|
||||
// If the player's an owner, display that
|
||||
if (MainConfig.get(ConfigEntry.SERVER_OWNERS, List.class).contains(player.getName()))
|
||||
if (ConfigEntry.SERVER_OWNERS.getList().contains(player.getName()))
|
||||
{
|
||||
return Title.OWNER;
|
||||
}
|
||||
@ -94,7 +94,14 @@ public class RankManager extends FreedomService
|
||||
return Rank.SENIOR_CONSOLE;
|
||||
}
|
||||
|
||||
return admin.getRank();
|
||||
Rank rank = admin.getRank();
|
||||
|
||||
// Get console
|
||||
if (rank.hasConsoleVariant())
|
||||
{
|
||||
rank = rank.getConsoleVariant();
|
||||
}
|
||||
return rank;
|
||||
}
|
||||
|
||||
public Rank getRank(Player player)
|
||||
@ -122,13 +129,13 @@ public class RankManager extends FreedomService
|
||||
|
||||
// Unban admins
|
||||
boolean isAdmin = plugin.al.isAdmin(player);
|
||||
fPlayer.setSuperadminIdVerified(false);
|
||||
if (isAdmin)
|
||||
{
|
||||
// Verify strict IP match
|
||||
if (!plugin.al.isIdentityMatched(player))
|
||||
{
|
||||
FUtil.bcastMsg("Warning: " + player.getName() + " is an admin, but is using an account not registered to one of their ip-list.", ChatColor.RED);
|
||||
fPlayer.setSuperadminIdVerified(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -153,7 +160,7 @@ public class RankManager extends FreedomService
|
||||
// Set display
|
||||
if (isAdmin || FUtil.DEVELOPERS.contains(player.getName()))
|
||||
{
|
||||
final RankBase display = getDisplay(player);
|
||||
final Displayable display = getDisplay(player);
|
||||
String loginMsg = display.getColoredLoginMessage();
|
||||
|
||||
if (isAdmin)
|
||||
@ -161,17 +168,17 @@ public class RankManager extends FreedomService
|
||||
Admin admin = plugin.al.getAdmin(player);
|
||||
if (admin.hasLoginMessage())
|
||||
{
|
||||
loginMsg = admin.getLoginMessage();
|
||||
loginMsg = ChatUtils.colorize(admin.getLoginMessage());
|
||||
}
|
||||
}
|
||||
|
||||
FUtil.bcastMsg(ChatColor.AQUA + player.getName() + " is " + loginMsg);
|
||||
plugin.pl.getPlayer(player).setTag(display.getColoredTag());
|
||||
|
||||
String displayName = display.getColor() + player.getName();
|
||||
try
|
||||
{
|
||||
String displayName = display.getColor() + player.getName();
|
||||
player.setPlayerListName(displayName.substring(0, Math.min(displayName.length(), 16)));
|
||||
player.setPlayerListName(StringUtils.substring(displayName, 0, 16));
|
||||
}
|
||||
catch (IllegalArgumentException ex)
|
||||
{
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user