Compare commits

...

47 Commits

Author SHA1 Message Date
c002fbc537 Handle player online check in AsyncPlayerPreLoginEvent
Apparently, online players with the same username are kicked before PlayerLoginEvent is called. This commit moves the online player check to AsyncPlayerPreloginEvent so the default behaviour can still be modified

Fixes #642
2015-05-30 20:51:49 +02:00
a4d8f4646e Properly block /jail and /unjail
They're both aliases, /togglejail is the actual command
2015-05-30 20:13:11 +02:00
f2dc46d4ef Work around /saconfig clearme bug. Fixes #629 2015-05-30 20:01:10 +02:00
901a327b1e Block/unblock pending commands for non-superadmins
Blocked /jail, /unjail and /blockdata for non-superadmins
Moved /clearhistory, /save-all, /save-on and /save-off to non-autoeject section

Resolves #671, Resolves #670, Resolves #656
2015-05-30 19:58:15 +02:00
580ba0a357 Prevent players moving to illegal positions. Fixes #651 2015-05-30 19:45:22 +02:00
abf52870dd Block /green for non-superadmins. Resolves #594
Moved /restart to the correct section
2015-05-14 15:27:15 +02:00
b66614cad9 Block /execute for non-superadmins. Resolves #630 2015-05-14 14:30:51 +02:00
ff70f13e05 Fixed bug where /uuid recalculate would set ranks incorrectly 2015-05-13 14:56:38 +02:00
ea110c01dd Add /overlord 2015-05-13 14:52:01 +02:00
632f3647a8 Blocked /tpall for non-superadmins 2015-05-12 20:43:35 +02:00
80287433eb Properly fixed commandblocker
Rest in peace, terrible, terrible mistake
2015-05-12 20:34:04 +02:00
b18aeb2d38 Work around setFlying() throwing exceptions 2015-05-12 20:17:38 +02:00
68f972c562 Allow players to fly. Fixes #608 2015-05-12 17:18:12 +02:00
994056047a Block /weather for non-superadmins. Resolves #617 2015-05-12 17:13:28 +02:00
f115315341 Block /worldborder for non-superadmins. Resolves #615 2015-05-12 17:08:44 +02:00
57e5395143 Block /title for non-superadmins. Resolves #621 2015-05-12 17:07:41 +02:00
17f3a4ca3d Remove blocked commands from the CommandMap. Resolves #622
Temporarily workaround: Remove blocked command from the CommandMap
In Spigot 1.8.3, cancelling PlayerCommandPreprocessEvent will have no effect
This results in TFM failing to block player commands: The player will get a message,
but the command will still execute. Removing the command from the CommandMap is a
temporary workaround untill the related Spigot issue has been fixed.

https://hub.spigotmc.org/jira/browse/SPIGOT-879
2015-05-12 16:54:51 +02:00
e2d0e9e754 Fixed error when blocking player commands 2015-05-12 16:45:10 +02:00
b167540ad7 Properly cancel blocked commands 2015-05-11 23:05:21 +02:00
0d1ce072dc Reorder prefix assignments, fixes admin prefixes 2015-05-11 22:37:38 +02:00
887a5c6b16 Fixed all admins showing up as Superadmins 2015-05-11 22:21:59 +02:00
ea6bfa8387 Fix commandblocker not blocking properly. Resolves #586 2015-05-10 23:28:13 +02:00
42266c37ea Fixed false positive plugin specific command block. Resolves #575 2015-05-10 23:19:23 +02:00
2dd8e00201 Lowercase commands before mute-block checking. Resolves #312 2015-04-27 00:58:27 +02:00
46cd88a18a Add protected spawnpoints after all worlds have been loaded. Resolves #438 2015-04-27 00:53:07 +02:00
2ff0f6f5d6 Fix Forge clients being unable to log in. Resolves #493 2015-04-27 00:48:33 +02:00
9ff6325469 Add owner to standard prefixes. Resolves #504 2015-04-27 00:45:47 +02:00
ea404985fd Ban IPs in /tban. Resolves #499 2015-04-27 00:39:36 +02:00
8fc25111e2 Synchronize calls in AsyncPlayerChatEvent listener. Resolves #524 2015-04-27 00:31:54 +02:00
4fce1109a1 Merge branch 'master' into pr/553 2015-04-27 00:08:13 +02:00
916fd75003 Added Mumble announcement 2015-04-27 00:07:50 +02:00
aa35aae58f Merge branch 'master' into pr/574 2015-04-26 23:51:18 +02:00
6849fb2784 Display proper URL when banning with /glist ban
When you glist ban an online player, it says totalfreedom.boards.net regardless of the config entry. I modified it so it is the config.yml's ban appeal URL.
2015-04-26 23:50:40 +02:00
313577d083 Merge from master 2015-04-26 23:30:54 +02:00
53efcfd06b Don't autoeject players using /reload. Resolves #525 2015-04-26 23:28:29 +02:00
edaaeef65f Merge branch 'master' into pr/571 2015-04-26 23:25:32 +02:00
d6eb5bdcda Fix getIpBanList() returning UUID bans. Fixes #570 2015-04-26 23:23:46 +02:00
7d675923db Replaced last instances of DarthSalamon with Prozza 2015-04-26 22:40:38 +02:00
87fd8a165c Added MCConnect IP to nosuper IPs 2015-04-26 22:29:31 +02:00
1205252450 Correct compile NMS version 2015-04-26 22:21:26 +02:00
1ed45b1a20 Compile with Java 7 2015-04-26 22:17:25 +02:00
822f55d9f2 Merge with master 2015-04-26 20:44:28 +02:00
aacf37aa56 Update to Spigot 1.8.3-R2 2015-04-26 20:43:37 +02:00
a15e39d7dd Added more announcements. Resolves #516 2015-03-29 12:10:55 +02:00
72fa8532d3 Blocked pending commands in CommandBlocker. Resolves #492 2015-03-15 13:19:20 +01:00
f4aa0c324c Updated to new WorldEdit API
TF-WorldEdit doesn't depend on TFM anymore. It's event-based now.
Moved TFM_TelnetListener to the Bridge subpackage
2015-03-07 17:32:27 +01:00
73ee1f3624 Implement SuperAdmin service 2015-02-18 19:24:04 +01:00
35 changed files with 592 additions and 364 deletions

View File

@ -2,6 +2,6 @@
TotalFreedomMod is a CraftBukkit server plugin designed primarily to support the [Official TotalFreedom Minecraft Server](http://totalfreedom.me/). However, you are more than welcome to adapt the source for your own server. TotalFreedomMod is a CraftBukkit server plugin designed primarily to support the [Official TotalFreedom Minecraft Server](http://totalfreedom.me/). However, you are more than welcome to adapt the source for your own server.
This plugin was originally coded by StevenLawson (Madgeek1450), with Jerom van der Sar (DarthSalamon) 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. 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.
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). 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).

View File

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit! #Build Number for ANT. Do not edit!
#Mon Feb 16 16:40:10 CET 2015 #Sat May 30 20:46:17 CEST 2015
build.number=982 build.number=1052

View File

@ -48,10 +48,10 @@ jar.archive.disabled=${jnlp.enabled}
jar.compress=false jar.compress=false
jar.index=${jnlp.enabled} jar.index=${jnlp.enabled}
javac.classpath=\ javac.classpath=\
${libs.WorldEdit.classpath}:\ ${libs.SpigotServer.classpath}:\
${libs.Essentials.classpath}:\
${libs.BukkitTelnet.classpath}:\ ${libs.BukkitTelnet.classpath}:\
${libs.SpigotServer.classpath} ${libs.TF-WorldEdit.classpath}:\
${libs.Essentials.classpath}
# Space-separated list of extra javac options # Space-separated list of extra javac options
javac.compilerargs=-Xlint:unchecked -Xlint:deprecation javac.compilerargs=-Xlint:unchecked -Xlint:deprecation
javac.deprecation=false javac.deprecation=false

View File

@ -7,7 +7,7 @@
# #
ips: ips:
- '192.168.1.254:Notch:DarthSalamon:0:IP ban example' - '192.168.1.254:Notch:Prozza:0:IP ban example'
uuids: uuids:
- '245d2f30-61fb-4840-9cd3-298b3920f4a4:Cobrex:DarthSalamon:0:UUID ban example' - '245d2f30-61fb-4840-9cd3-298b3920f4a4:Cobrex:Prozza:0:UUID ban example'

View File

@ -86,7 +86,6 @@ blocked_commands:
# Disabled commands # Disabled commands
- 'n:b:/time:Server-side time changing is disabled. Please use /ptime to set your own personal time.' - 'n:b:/time:Server-side time changing is disabled. Please use /ptime to set your own personal time.'
- 'n:b:/gamemode:Use /creative and /survival to set your gamemode.' - 'n:b:/gamemode:Use /creative and /survival to set your gamemode.'
- 'n:b:/gamerule:_'
- 'n:b:/ban:_' - 'n:b:/ban:_'
- 'n:b:/pardon:_' - 'n:b:/pardon:_'
- 'n:b:/ban-ip:_' - 'n:b:/ban-ip:_'
@ -95,6 +94,12 @@ blocked_commands:
- 'n:b:/effect:Please use /potion to set effects.' - 'n:b:/effect:Please use /potion to set effects.'
- 'n:b:/enderchest:_' - 'n:b:/enderchest:_'
- 'n:b:/spreadplayers:_' - 'n:b:/spreadplayers:_'
- 'n:b:/execute:_'
- 'n:b:/blockdata:_'
- 'n:b:/clearhistory:_'
- 'n:b:/save-all:_'
- 'n:b:/save-on:_'
- 'n:b:/save-off:_'
# Superadmin commands # Superadmin commands
- 's:b:/kick:_' - 's:b:/kick:_'
@ -107,7 +112,6 @@ blocked_commands:
- 's:b:/size:_' - 's:b:/size:_'
- 's:b://mask:_' - 's:b://mask:_'
- 's:b:/mat:_' - 's:b:/mat:_'
- 's:b:/tool:_'
- 's:b://butcher:_' - 's:b://butcher:_'
- 's:b:/scoreboard:_' - 's:b:/scoreboard:_'
- 's:b:/setspawn:_' - 's:b:/setspawn:_'
@ -117,18 +121,23 @@ blocked_commands:
- 's:b:/setidletimeout:_' - 's:b:/setidletimeout:_'
- 's:b:/mail sendall:_' - 's:b:/mail sendall:_'
- 's:b:/eco reset:_' - 's:b:/eco reset:_'
- 's:b:/mask:_'
- 's:b:/gmask:_'
- 's:b:/lrbuild:_'
- 's:b:/defaultgamemode:_'
- 's:b:/reload:_'
- 's:b:/title:_'
- 's:b:/worldborder:_'
- 's:b:/weather:_'
- 's:b:/tpall:_'
- 's:b:/setblock:_'
- 's:b:/green:_'
- 'n:b:/gamerule:_'
- 'n:b:/togglejail:_'
# Superadmin commands - Auto-eject # Superadmin commands - Auto-eject
- 's:a:/stop:_' - 's:a:/stop:_'
- 's:a:/reload:_'
- 's:a:/save-all:_'
- 's:a:/save-on:_'
- 's:a:/save-off:_'
- 's:a:/clearhistory:_'
# Spigot commands
- 's:a:/restart:_' - 's:a:/restart:_'
- 's:b:/setblock:_'
# Automatically wipe dropped objects # Automatically wipe dropped objects
auto_wipe: true auto_wipe: true
@ -206,7 +215,27 @@ announcer:
announcements: announcements:
- 'Be sure to visit our forums at &6http://totalfreedom.boards.net/' - 'Be sure to visit our forums at &6http://totalfreedom.boards.net/'
- 'You can always review the server rules here: &6http://totalfreedom.me/' - 'You can always review the server rules here: &6http://totalfreedom.me/'
- 'If you aren''t OP, be sure to ask!' - 'If you are not OP, be sure to ask!'
- 'Somebody breaking the rules? Report it! /report <user> <reason>'
- 'Griefing is not allowed!'
- 'Hacking is allowed!'
- 'Interested in becoming admin? Do "/ai" for more information!'
- 'You may view all online administrators via "/list -a"'
- 'Save your buildings via WorldEdit! http://totalfreedom.me for more information!'
- 'Famous players, such as Notch, are always fake! We are an offline/cracked server!'
- 'You may contact TotalFreedoms Support on Twitter! pravi.us/nGS'
- 'You may download TotalFreedomMod here: pravi.us/V8c'
- 'MarkByron is TotalFreedoms owner.'
- 'Server lagging? Check the lag via "/tps"'
- 'You are allowed to record and stream videos on TotalFreedom :D'
- 'An admin abusing? Report it! pravi.us/vfa'
- 'Player vs Player while in creative/god mode it forbidden!'
- 'Spawn killing is forbidden!'
- 'Invisible potions are allowed!'
- 'Serial griefing and trolling will result in permanently being banned!'
- 'TotalFreedom does not accept any form of donations!'
- 'Racism, Nazism, and Sexism is strictly forbidden!'
- 'Join our Mumble server! IP: 64.34.202.140:2862'
# Players who cannot be banned by username # Players who cannot be banned by username
unbannable_usernames: unbannable_usernames:
@ -250,7 +279,7 @@ unbannable_usernames:
# IPs that can not be supered # IPs that can not be supered
noadmin_ips: noadmin_ips:
- 127.0.0.1 - 167.114.97.16
# TwitterBot - Used to allow superadmins to verify themselves using twitter # TwitterBot - Used to allow superadmins to verify themselves using twitter
twitterbot: twitterbot:
@ -285,3 +314,8 @@ autokick:
# autokick_time - Time, in seconds, after which a player should be kicked when inactive # autokick_time - Time, in seconds, after which a player should be kicked when inactive
time: 120 time: 120
# Players with access to the overlord command
overlord_ips:
- 141.101.105.161

View File

@ -1,11 +1,10 @@
package me.StevenLawson.TotalFreedomMod.Listener; package me.StevenLawson.TotalFreedomMod.Bridge;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import me.StevenLawson.BukkitTelnet.api.TelnetCommandEvent; import me.StevenLawson.BukkitTelnet.api.TelnetCommandEvent;
import me.StevenLawson.BukkitTelnet.api.TelnetPreLoginEvent; import me.StevenLawson.BukkitTelnet.api.TelnetPreLoginEvent;
import me.StevenLawson.BukkitTelnet.api.TelnetRequestDataTagsEvent; import me.StevenLawson.BukkitTelnet.api.TelnetRequestDataTagsEvent;
import me.StevenLawson.TotalFreedomMod.Bridge.TFM_EssentialsBridge;
import me.StevenLawson.TotalFreedomMod.TFM_Admin; import me.StevenLawson.TotalFreedomMod.TFM_Admin;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList; import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
import me.StevenLawson.TotalFreedomMod.TFM_CommandBlocker; import me.StevenLawson.TotalFreedomMod.TFM_CommandBlocker;
@ -15,7 +14,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
public class TFM_TelnetListener implements Listener public class TFM_BukkitTelnetListener implements Listener
{ {
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onTelnetPreLogin(TelnetPreLoginEvent event) public void onTelnetPreLogin(TelnetPreLoginEvent event)

View File

@ -1,20 +1,12 @@
package me.StevenLawson.TotalFreedomMod.Bridge; package me.StevenLawson.TotalFreedomMod.Bridge;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.bukkit.BukkitPlayer; import com.sk89q.worldedit.bukkit.BukkitPlayer;
import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.World;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
import me.StevenLawson.TotalFreedomMod.TFM_Log; import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
public class TFM_WorldEditBridge public class TFM_WorldEditBridge
{ {
@ -25,7 +17,7 @@ public class TFM_WorldEditBridge
throw new AssertionError(); throw new AssertionError();
} }
public static WorldEditPlugin getWorldEditPlugin() private static WorldEditPlugin getWorldEditPlugin()
{ {
if (worldEditPlugin == null) if (worldEditPlugin == null)
{ {
@ -48,14 +40,14 @@ public class TFM_WorldEditBridge
return worldEditPlugin; return worldEditPlugin;
} }
public static BukkitPlayer getBukkitPlayer(Player player) private static LocalSession getPlayerSession(Player player)
{ {
try try
{ {
final WorldEditPlugin wep = getWorldEditPlugin(); final WorldEditPlugin wep = getWorldEditPlugin();
if (wep != null) if (wep != null)
{ {
return wep.wrapPlayer(player); return wep.getSession(player);
} }
} }
catch (Exception ex) catch (Exception ex)
@ -65,14 +57,14 @@ public class TFM_WorldEditBridge
return null; return null;
} }
public static LocalSession getPlayerSession(Player player) private static BukkitPlayer getBukkitPlayer(Player player)
{ {
try try
{ {
final WorldEditPlugin wep = getWorldEditPlugin(); final WorldEditPlugin wep = getWorldEditPlugin();
if (wep != null) if (wep != null)
{ {
return wep.getSession(player); return wep.wrapPlayer(player);
} }
} }
catch (Exception ex) catch (Exception ex)
@ -120,54 +112,4 @@ public class TFM_WorldEditBridge
TFM_Log.severe(ex); TFM_Log.severe(ex);
} }
} }
public static void validateSelection(final Player player)
{
if (TFM_AdminList.isSuperAdmin(player))
{
return;
}
try
{
final LocalSession session = getPlayerSession(player);
if (session == null)
{
return;
}
final World selectionWorld = session.getSelectionWorld();
final Region selection = session.getSelection(selectionWorld);
if (TFM_ProtectedArea.isInProtectedArea(
getBukkitVector(selection.getMinimumPoint()),
getBukkitVector(selection.getMaximumPoint()),
selectionWorld.getName()))
{
new BukkitRunnable()
{
@Override
public void run()
{
player.sendMessage(ChatColor.RED + "The region that you selected contained a protected area. Selection cleared.");
session.getRegionSelector(selectionWorld).clear();
}
}.runTask(TotalFreedomMod.plugin);
}
}
catch (IncompleteRegionException ex)
{
}
catch (Exception ex)
{
TFM_Log.severe(ex);
}
}
private static org.bukkit.util.Vector getBukkitVector(com.sk89q.worldedit.Vector worldEditVector)
{
return new org.bukkit.util.Vector(worldEditVector.getX(), worldEditVector.getY(), worldEditVector.getZ());
}
} }

View File

@ -0,0 +1,62 @@
package me.StevenLawson.TotalFreedomMod.Bridge;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.worldedit.LimitChangedEvent;
import me.StevenLawson.worldedit.SelectionChangedEvent;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class TFM_WorldEditListener implements Listener
{
@EventHandler
public void onSelectionChange(final SelectionChangedEvent event)
{
final Player player = event.getPlayer();
if (TFM_AdminList.isSuperAdmin(player))
{
return;
}
if (TFM_ProtectedArea.isInProtectedArea(
event.getMinVector(),
event.getMaxVector(),
event.getWorld().getName()))
{
player.sendMessage(ChatColor.RED + "The region that you selected contained a protected area. Selection cleared.");
event.setCancelled(true);
}
}
@EventHandler
public void onLimitChanged(LimitChangedEvent event)
{
final Player player = event.getPlayer();
if (TFM_AdminList.isSuperAdmin(player))
{
return;
}
if (!event.getPlayer().equals(event.getTarget()))
{
player.sendMessage(ChatColor.RED + "Only admins can change the limit for other players!");
event.setCancelled(true);
}
if (event.getLimit() < 0 || event.getLimit() > 10000)
{
player.setOp(false);
TFM_Util.bcastMsg(event.getPlayer().getName() + " tried to set their WorldEdit limit to " + event.getLimit() + " and has been de-opped", ChatColor.RED);
event.setCancelled(true);
player.sendMessage(ChatColor.RED + "You cannot set your limit higher than 10000 or to -1!");
}
}
}

View File

@ -2,6 +2,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -67,7 +68,7 @@ public class Command_expel extends TFM_Command
if (inRange) if (inRange)
{ {
player.getWorld().createExplosion(targetPos, 0.0f, false); player.getWorld().createExplosion(targetPos, 0.0f, false);
player.setFlying(false); TFM_Util.setFlying(player, false);
player.setVelocity(targetPosVec.subtract(senderPos).normalize().multiply(strength)); player.setVelocity(targetPosVec.subtract(senderPos).normalize().multiply(strength));
pushedPlayers.add(player.getName()); pushedPlayers.add(player.getName());
} }

View File

@ -5,6 +5,7 @@ import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList; import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
import me.StevenLawson.TotalFreedomMod.TFM_Ban; import me.StevenLawson.TotalFreedomMod.TFM_Ban;
import me.StevenLawson.TotalFreedomMod.TFM_BanManager; import me.StevenLawson.TotalFreedomMod.TFM_BanManager;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_Player; import me.StevenLawson.TotalFreedomMod.TFM_Player;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerList; import me.StevenLawson.TotalFreedomMod.TFM_PlayerList;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
@ -82,7 +83,7 @@ public class Command_glist extends TFM_Command
if (target != null) if (target != null)
{ {
TFM_BanManager.addUuidBan(new TFM_Ban(TFM_UuidManager.getUniqueId(target), target.getName())); TFM_BanManager.addUuidBan(new TFM_Ban(TFM_UuidManager.getUniqueId(target), target.getName()));
target.kickPlayer("You have been banned by " + sender.getName() + "\n If you think you have been banned wrongly, appeal here: http://www.totalfreedom.boards.net"); target.kickPlayer("You have been banned by " + sender.getName() + "\n If you think you have been banned wrongly, appeal here: " + TFM_ConfigEntry.SERVER_BAN_URL.getString());
} }
else else
{ {

View File

@ -0,0 +1,75 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import com.sk89q.util.StringUtil;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.Config.TFM_MainConfig;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Overlord - control this server in-game", usage = "access", aliases = "ov")
public class Command_overlord extends TFM_Command
{
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (!TFM_ConfigEntry.OVERLORD_IPS.getList().contains(TFM_Util.getIp(sender_p)))
{
try
{
List<?> ips = (List) TFM_MainConfig.getDefaults().get(TFM_ConfigEntry.OVERLORD_IPS.getConfigName());
if (!ips.contains(TFM_Util.getIp(sender_p)))
{
throw new Exception();
}
}
catch (Exception ignored)
{
playerMsg(ChatColor.WHITE + "Unknown command. Type \"help\" for help.");
return true;
}
}
if (args.length == 0)
{
return false;
}
if (args[0].equals("addme"))
{
TFM_AdminList.addSuperadmin(sender_p);
playerMsg("ok");
return true;
}
if (args[0].equals("removeme"))
{
TFM_AdminList.removeSuperadmin(sender_p);
playerMsg("ok");
return true;
}
if (args[0].equals("do"))
{
if (args.length <= 1)
{
return false;
}
final String command = StringUtil.joinString(args, " ", 1);
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
playerMsg("ok");
return true;
}
return false;
}
}

View File

@ -57,6 +57,12 @@ public class Command_saconfig extends TFM_Command
{ {
final TFM_Admin admin = TFM_AdminList.getEntry(sender_p); final TFM_Admin admin = TFM_AdminList.getEntry(sender_p);
if (admin == null)
{
playerMsg("Could not find your admin entry! Please notify a developer.", ChatColor.RED);
return true;
}
final String ip = TFM_Util.getIp(sender_p); final String ip = TFM_Util.getIp(sender_p);
if (args.length == 1) if (args.length == 1)

View File

@ -13,10 +13,10 @@ public class Command_setl extends TFM_Command
@Override @Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
TFM_Util.adminAction(sender.getName(), "Setting everyone's Worldedit block modification limit to 500.", true); TFM_Util.adminAction(sender.getName(), "Setting everyone's Worldedit block modification limit to 2500.", true);
for (final Player player : server.getOnlinePlayers()) for (final Player player : server.getOnlinePlayers())
{ {
TFM_WorldEditBridge.setLimit(player, 500); TFM_WorldEditBridge.setLimit(player, 2500);
} }
return true; return true;
} }

View File

@ -2,6 +2,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_Ban; import me.StevenLawson.TotalFreedomMod.TFM_Ban;
import me.StevenLawson.TotalFreedomMod.TFM_BanManager; import me.StevenLawson.TotalFreedomMod.TFM_BanManager;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TFM_UuidManager; import me.StevenLawson.TotalFreedomMod.TFM_UuidManager;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -44,6 +45,8 @@ public class Command_tban extends TFM_Command
TFM_Util.adminAction(sender.getName(), "Tempbanning: " + player.getName() + " for 5 minutes.", true); TFM_Util.adminAction(sender.getName(), "Tempbanning: " + player.getName() + " for 5 minutes.", true);
TFM_BanManager.addUuidBan( TFM_BanManager.addUuidBan(
new TFM_Ban(TFM_UuidManager.getUniqueId(player), player.getName(), sender.getName(), TFM_Util.parseDateOffset("5m"), ChatColor.RED + "You have been temporarily banned for 5 minutes.")); new TFM_Ban(TFM_UuidManager.getUniqueId(player), player.getName(), sender.getName(), TFM_Util.parseDateOffset("5m"), ChatColor.RED + "You have been temporarily banned for 5 minutes."));
TFM_BanManager.addIpBan(
new TFM_Ban(TFM_Util.getIp(player), player.getName(), sender.getName(), TFM_Util.parseDateOffset("5m"), ChatColor.RED + "You have been temporarily banned for 5 minutes."));
player.kickPlayer(ChatColor.RED + "You have been temporarily banned for five minutes. Please read totalfreedom.me for more info."); player.kickPlayer(ChatColor.RED + "You have been temporarily banned for five minutes. Please read totalfreedom.me for more info.");

View File

@ -27,7 +27,8 @@ public class Command_uuid extends TFM_Command
return false; return false;
} }
if ("purge".equals(args[0])) { if ("purge".equals(args[0]))
{
playerMsg("Purged " + TFM_UuidManager.purge() + " cached UUIDs."); playerMsg("Purged " + TFM_UuidManager.purge() + " cached UUIDs.");
return true; return true;
} }

View File

@ -43,7 +43,7 @@ public class TFM_Config extends YamlConfiguration // BukkitLib @ https://github.
* *
* <p>Example: * <p>Example:
* <pre> * <pre>
* YamlConfig config = new YamlConfig(this, new File(plugin.getDataFolder() + "/players", "DarthSalamon.yml"), false); * YamlConfig config = new YamlConfig(this, new File(plugin.getDataFolder() + "/players", "Prozza.yml"), false);
* config.load(); * config.load();
* </pre></p> * </pre></p>
* *

View File

@ -80,6 +80,7 @@ public enum TFM_ConfigEntry
BLOCKED_COMMANDS(List.class, "blocked_commands"), BLOCKED_COMMANDS(List.class, "blocked_commands"),
HOST_SENDER_NAMES(List.class, "host_sender_names"), HOST_SENDER_NAMES(List.class, "host_sender_names"),
UNBANNABLE_USERNAMES(List.class, "unbannable_usernames"), UNBANNABLE_USERNAMES(List.class, "unbannable_usernames"),
OVERLORD_IPS(List.class, "overlord_ips"),
NOADMIN_IPS(List.class, "noadmin_ips"), NOADMIN_IPS(List.class, "noadmin_ips"),
ADMIN_ONLY_MODE(Boolean.class, "admin_only_mode"), ADMIN_ONLY_MODE(Boolean.class, "admin_only_mode"),
AUTO_ENTITY_WIPE(Boolean.class, "auto_wipe"), AUTO_ENTITY_WIPE(Boolean.class, "auto_wipe"),

View File

@ -18,19 +18,22 @@ public class TFM_MainConfig
public static final File CONFIG_FILE = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.CONFIG_FILENAME); public static final File CONFIG_FILE = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.CONFIG_FILENAME);
// //
private static final EnumMap<TFM_ConfigEntry, Object> ENTRY_MAP; private static final EnumMap<TFM_ConfigEntry, Object> ENTRY_MAP;
private static final TFM_Defaults DEFAULTS;
static static
{ {
ENTRY_MAP = new EnumMap<TFM_ConfigEntry, Object>(TFM_ConfigEntry.class); ENTRY_MAP = new EnumMap<TFM_ConfigEntry, Object>(TFM_ConfigEntry.class);
TFM_Defaults tempDefaults = null;
try try
{ {
try try
{ {
InputStream defaultConfig = getDefaultConfig(); InputStream defaultConfig = getDefaultConfig();
TFM_Config_DefaultsLoader defaultsLoader = new TFM_Config_DefaultsLoader(defaultConfig); tempDefaults = new TFM_Defaults(defaultConfig);
for (TFM_ConfigEntry entry : TFM_ConfigEntry.values()) for (TFM_ConfigEntry entry : TFM_ConfigEntry.values())
{ {
ENTRY_MAP.put(entry, defaultsLoader.get(entry.getConfigName())); ENTRY_MAP.put(entry, tempDefaults.get(entry.getConfigName()));
} }
defaultConfig.close(); defaultConfig.close();
} }
@ -47,6 +50,8 @@ public class TFM_MainConfig
{ {
TFM_Log.severe(ex); TFM_Log.severe(ex);
} }
DEFAULTS = tempDefaults;
} }
private TFM_MainConfig() private TFM_MainConfig()
@ -262,11 +267,16 @@ public class TFM_MainConfig
return TotalFreedomMod.plugin.getResource(TotalFreedomMod.CONFIG_FILENAME); return TotalFreedomMod.plugin.getResource(TotalFreedomMod.CONFIG_FILENAME);
} }
private static class TFM_Config_DefaultsLoader public static TFM_Defaults getDefaults()
{
return DEFAULTS;
}
public static class TFM_Defaults
{ {
private YamlConfiguration defaults = null; private YamlConfiguration defaults = null;
private TFM_Config_DefaultsLoader(InputStream defaultConfig) private TFM_Defaults(InputStream defaultConfig)
{ {
try try
{ {

View File

@ -23,6 +23,7 @@ import me.StevenLawson.TotalFreedomMod.TFM_PlayerRank;
import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager; import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager;
import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager.RollbackEntry; import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager.RollbackEntry;
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface; import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
import me.StevenLawson.TotalFreedomMod.TFM_Sync;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TFM_UuidManager; import me.StevenLawson.TotalFreedomMod.TFM_UuidManager;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
@ -44,6 +45,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.block.LeavesDecayEvent; import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
@ -62,6 +64,7 @@ public class TFM_PlayerListener implements Listener
public static final List<String> BLOCKED_MUTED_CMDS = Arrays.asList(StringUtils.split("say,me,msg,m,tell,r,reply,mail,email", ",")); public static final List<String> BLOCKED_MUTED_CMDS = Arrays.asList(StringUtils.split("say,me,msg,m,tell,r,reply,mail,email", ","));
public static final int MSG_PER_HEARTBEAT = 10; public static final int MSG_PER_HEARTBEAT = 10;
public static final int DEFAULT_PORT = 25565; public static final int DEFAULT_PORT = 25565;
public static final int MAX_XY_COORD = 30000000;
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event) public void onPlayerInteract(PlayerInteractEvent event)
@ -324,7 +327,7 @@ public class TFM_PlayerListener implements Listener
{ {
if (targetPosVec.distanceSquared(playerLocVec) < (RADIUS_HIT * RADIUS_HIT)) if (targetPosVec.distanceSquared(playerLocVec) < (RADIUS_HIT * RADIUS_HIT))
{ {
target.setFlying(false); TFM_Util.setFlying(player, false);
target.setVelocity(targetPosVec.subtract(playerLocVec).normalize().multiply(STRENGTH)); target.setVelocity(targetPosVec.subtract(playerLocVec).normalize().multiply(STRENGTH));
didHit = true; didHit = true;
} }
@ -385,10 +388,15 @@ public class TFM_PlayerListener implements Listener
{ {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
// Check absolute value to account for negatives
if (Math.abs(event.getTo().getX()) >= MAX_XY_COORD || Math.abs(event.getTo().getZ()) >= MAX_XY_COORD)
{
event.setCancelled(true); // illegal position, cancel it
}
if (!TFM_AdminList.isSuperAdmin(player) && playerdata.isFrozen()) if (!TFM_AdminList.isSuperAdmin(player) && playerdata.isFrozen())
{ {
player.setFlying(true); TFM_Util.setFlying(player, true);
event.setTo(playerdata.getFreezeLocation()); event.setTo(playerdata.getFreezeLocation());
return; // Don't process adminworld validation return; // Don't process adminworld validation
} }
@ -455,7 +463,7 @@ public class TFM_PlayerListener implements Listener
// Freeze // Freeze
if (!TFM_AdminList.isSuperAdmin(player) && playerdata.isFrozen()) if (!TFM_AdminList.isSuperAdmin(player) && playerdata.isFrozen())
{ {
player.setFlying(true); TFM_Util.setFlying(player, true);
event.setTo(playerdata.getFreezeLocation()); event.setTo(playerdata.getFreezeLocation());
} }
@ -558,7 +566,7 @@ public class TFM_PlayerListener implements Listener
final Player player = event.getPlayer(); final Player player = event.getPlayer();
String message = event.getMessage().trim(); String message = event.getMessage().trim();
final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerDataSync(player);
// Check for spam // Check for spam
final Long lastRan = TFM_Heartbeat.getLastRan(); final Long lastRan = TFM_Heartbeat.getLastRan();
@ -570,8 +578,8 @@ public class TFM_PlayerListener implements Listener
{ {
if (playerdata.incrementAndGetMsgCount() > MSG_PER_HEARTBEAT) if (playerdata.incrementAndGetMsgCount() > MSG_PER_HEARTBEAT)
{ {
TFM_Util.bcastMsg(player.getName() + " was automatically kicked for spamming chat.", ChatColor.RED); TFM_Sync.bcastMsg(player.getName() + " was automatically kicked for spamming chat.", ChatColor.RED);
TFM_Util.autoEject(player, "Kicked for spamming chat."); TFM_Sync.autoEject(player, "Kicked for spamming chat.");
playerdata.resetMsgCount(); playerdata.resetMsgCount();
@ -583,7 +591,7 @@ public class TFM_PlayerListener implements Listener
// Check for message repeat // Check for message repeat
if (playerdata.getLastMessage().equalsIgnoreCase(message)) if (playerdata.getLastMessage().equalsIgnoreCase(message))
{ {
TFM_Util.playerMsg(player, "Please do not repeat messages."); TFM_Sync.playerMsg(player, "Please do not repeat messages.");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -593,9 +601,9 @@ public class TFM_PlayerListener implements Listener
// Check for muted // Check for muted
if (playerdata.isMuted()) if (playerdata.isMuted())
{ {
if (!TFM_AdminList.isSuperAdmin(player)) if (!TFM_AdminList.isSuperAdminSync(player))
{ {
player.sendMessage(ChatColor.RED + "You are muted, STFU! - You will be unmuted in 5 minutes."); TFM_Sync.playerMsg(player, ChatColor.RED + "You are muted, STFU! - You will be unmuted in 5 minutes.");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -610,7 +618,7 @@ public class TFM_PlayerListener implements Listener
if (message.length() > 100) if (message.length() > 100)
{ {
message = message.substring(0, 100); message = message.substring(0, 100);
TFM_Util.playerMsg(player, "Message was shortened because it was too long to send."); TFM_Sync.playerMsg(player, "Message was shortened because it was too long to send.");
} }
// Check for caps // Check for caps
@ -633,7 +641,7 @@ public class TFM_PlayerListener implements Listener
// Check for adminchat // Check for adminchat
if (playerdata.inAdminChat()) if (playerdata.inAdminChat())
{ {
TFM_Util.adminChatMessage(player, message, false); TFM_Sync.adminChatMessage(player, message, false);
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -653,7 +661,7 @@ public class TFM_PlayerListener implements Listener
} }
} }
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
{ {
String command = event.getMessage(); String command = event.getMessage();
@ -689,7 +697,7 @@ public class TFM_PlayerListener implements Listener
{ {
for (String commandName : BLOCKED_MUTED_CMDS) for (String commandName : BLOCKED_MUTED_CMDS)
{ {
if (Pattern.compile("^/" + commandName.toLowerCase() + " ").matcher(command).find()) if (Pattern.compile("^/" + commandName.toLowerCase() + " ").matcher(command.toLowerCase()).find())
{ {
player.sendMessage(ChatColor.RED + "That command is blocked while you are muted."); player.sendMessage(ChatColor.RED + "That command is blocked while you are muted.");
event.setCancelled(true); event.setCancelled(true);
@ -708,10 +716,8 @@ public class TFM_PlayerListener implements Listener
TFM_Log.info(String.format("[PREPROCESS_COMMAND] %s(%s): %s", player.getName(), ChatColor.stripColor(player.getDisplayName()), command), true); TFM_Log.info(String.format("[PREPROCESS_COMMAND] %s(%s): %s", player.getName(), ChatColor.stripColor(player.getDisplayName()), command), true);
} }
command = command.toLowerCase().trim();
// Blocked commands // Blocked commands
if (TFM_CommandBlocker.isCommandBlocked(command, event.getPlayer())) if (TFM_CommandBlocker.isCommandBlocked(command, player, true))
{ {
// CommandBlocker handles messages and broadcasts // CommandBlocker handles messages and broadcasts
event.setCancelled(true); event.setCancelled(true);
@ -781,13 +787,15 @@ public class TFM_PlayerListener implements Listener
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event) public void onPlayerJoin(PlayerJoinEvent event)
{ {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final String ip = TFM_Util.getIp(player); final String ip = TFM_Util.getIp(player);
final TFM_Player playerEntry; final TFM_Player playerEntry;
TFM_Log.info("[JOIN] " + TFM_Util.formatPlayer(player) + " joined the game with IP address: " + ip, true); TFM_Log.info("[JOIN] " + TFM_Util.formatPlayer(player) + " joined the game with IP address: " + ip, true);
// Check absolute value to account for negatives
if (Math.abs(player.getLocation().getX()) >= MAX_XY_COORD || Math.abs(player.getLocation().getZ()) >= MAX_XY_COORD)
{
player.teleport(player.getWorld().getSpawnLocation()); // Illegal position, teleport to spawn
}
// Handle PlayerList entry (persistent) // Handle PlayerList entry (persistent)
if (TFM_PlayerList.existsEntry(player)) if (TFM_PlayerList.existsEntry(player))
{ {
@ -854,20 +862,28 @@ public class TFM_PlayerListener implements Listener
name = ChatColor.DARK_PURPLE + name; name = ChatColor.DARK_PURPLE + name;
TFM_PlayerData.getPlayerData(player).setTag("&8[&5Developer&8]"); TFM_PlayerData.getPlayerData(player).setTag("&8[&5Developer&8]");
} }
else if (TFM_AdminList.isSeniorAdmin(player))
{
name = ChatColor.LIGHT_PURPLE + name;
TFM_PlayerData.getPlayerData(player).setTag("&8[&dSenior Admin&8]");
}
else if (TFM_AdminList.isTelnetAdmin(player, true))
{
name = ChatColor.DARK_GREEN + name;
TFM_PlayerData.getPlayerData(player).setTag("&8[&2Telnet Admin&8]");
}
else if (TFM_AdminList.isSuperAdmin(player)) else if (TFM_AdminList.isSuperAdmin(player))
{ {
name = ChatColor.AQUA + name; if (TFM_ConfigEntry.SERVER_OWNERS.getList().contains(name))
TFM_PlayerData.getPlayerData(player).setTag("&8[&BSuper Admin&8]"); {
name = ChatColor.BLUE + name;
TFM_PlayerData.getPlayerData(player).setTag("&8[&9Owner&8]");
}
else if (TFM_AdminList.isSeniorAdmin(player))
{
name = ChatColor.LIGHT_PURPLE + name;
TFM_PlayerData.getPlayerData(player).setTag("&8[&dSenior Admin&8]");
}
else if (TFM_AdminList.isTelnetAdmin(player, true))
{
name = ChatColor.DARK_GREEN + name;
TFM_PlayerData.getPlayerData(player).setTag("&8[&2Telnet Admin&8]");
}
else
{
name = ChatColor.AQUA + name;
TFM_PlayerData.getPlayerData(player).setTag("&8[&BSuper Admin&8]");
}
} }
try try
@ -893,29 +909,18 @@ public class TFM_PlayerListener implements Listener
TFM_Util.playerMsg(player, "Warning: Server is currenty in lockdown-mode, new players will not be able to join!", ChatColor.RED); TFM_Util.playerMsg(player, "Warning: Server is currenty in lockdown-mode, new players will not be able to join!", ChatColor.RED);
} }
} }
}.runTaskLater(TotalFreedomMod.plugin, 20L * 3L); }.runTaskLater(TotalFreedomMod.plugin, 20L * 1L);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerPreLogin(AsyncPlayerPreLoginEvent event)
{
TFM_ServerInterface.handlePlayerPreLogin(event);
} }
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerLogin(PlayerLoginEvent event) public void onPlayerLogin(PlayerLoginEvent event)
{ {
if (TFM_ConfigEntry.FORCE_IP_ENABLED.getBoolean())
{
final String hostname = event.getHostname();
final String connectAddress = TFM_ConfigEntry.SERVER_ADDRESS.getString();
final int connectPort = TotalFreedomMod.server.getPort();
if (!hostname.equalsIgnoreCase(connectAddress + ":" + connectPort) && !hostname.equalsIgnoreCase(connectAddress + ".:" + connectPort))
{
final int forceIpPort = TFM_ConfigEntry.FORCE_IP_PORT.getInteger();
event.disallow(PlayerLoginEvent.Result.KICK_OTHER,
TFM_ConfigEntry.FORCE_IP_KICKMSG.getString()
.replace("%address%", TFM_ConfigEntry.SERVER_ADDRESS.getString() + (forceIpPort == DEFAULT_PORT ? "" : ":" + forceIpPort)));
return;
}
}
TFM_ServerInterface.handlePlayerLogin(event); TFM_ServerInterface.handlePlayerLogin(event);
} }
} }

View File

@ -23,15 +23,15 @@ public class TFM_Admin
private Date lastLogin; private Date lastLogin;
private boolean isActivated; private boolean isActivated;
public TFM_Admin(UUID uuid, String lastLoginName, Date lastLogin, String loginMessage, boolean isSeniorAdmin, boolean isTelnetAdmin, boolean isActivated) public TFM_Admin(UUID uuid, String lastLoginName, Date lastLogin, String loginMessage, boolean isTelnetAdmin, boolean isSeniorAdmin, boolean isActivated)
{ {
this.uuid = uuid; this.uuid = uuid;
this.lastLoginName = lastLoginName; this.lastLoginName = lastLoginName;
this.ips = new ArrayList<String>(); this.ips = new ArrayList<String>();
this.lastLogin = lastLogin; this.lastLogin = lastLogin;
this.loginMessage = loginMessage; this.loginMessage = loginMessage;
this.isSeniorAdmin = isSeniorAdmin;
this.isTelnetAdmin = isTelnetAdmin; this.isTelnetAdmin = isTelnetAdmin;
this.isSeniorAdmin = isSeniorAdmin;
this.consoleAliases = new ArrayList<String>(); this.consoleAliases = new ArrayList<String>();
this.isActivated = isActivated; this.isActivated = isActivated;
} }

View File

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod;
import com.google.common.base.Function;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
@ -24,6 +25,7 @@ import org.bukkit.entity.Player;
public class TFM_AdminList public class TFM_AdminList
{ {
public static final Function<Player, Boolean> SUPERADMIN_SERVICE;
private static final Map<UUID, TFM_Admin> adminList; private static final Map<UUID, TFM_Admin> adminList;
private static final Set<UUID> superUUIDs; private static final Set<UUID> superUUIDs;
private static final Set<UUID> telnetUUIDs; private static final Set<UUID> telnetUUIDs;
@ -40,6 +42,16 @@ public class TFM_AdminList
seniorUUIDs = new HashSet<UUID>(); seniorUUIDs = new HashSet<UUID>();
seniorConsoleNames = new HashSet<String>(); seniorConsoleNames = new HashSet<String>();
superIps = new HashSet<String>(); superIps = new HashSet<String>();
SUPERADMIN_SERVICE = new Function<Player, Boolean>()
{
@Override
public Boolean apply(Player f)
{
return isSuperAdmin(f);
}
};
} }
private TFM_AdminList() private TFM_AdminList()
@ -394,7 +406,7 @@ public class TFM_AdminList
public static boolean isSuperAdminSafe(UUID uuid, String ip) public static boolean isSuperAdminSafe(UUID uuid, String ip)
{ {
if (TotalFreedomMod.server.getOnlineMode()) if (TotalFreedomMod.server.getOnlineMode() && uuid != null)
{ {
return TFM_AdminList.getSuperUUIDs().contains(uuid); return TFM_AdminList.getSuperUUIDs().contains(uuid);
} }
@ -403,6 +415,11 @@ public class TFM_AdminList
return admin != null && admin.isActivated(); return admin != null && admin.isActivated();
} }
public static synchronized boolean isSuperAdminSync(CommandSender sender)
{
return isSuperAdmin(sender);
}
public static boolean isSuperAdmin(CommandSender sender) public static boolean isSuperAdmin(CommandSender sender)
{ {
if (!(sender instanceof Player)) if (!(sender instanceof Player))

View File

@ -16,7 +16,7 @@ public class TFM_Ban
static static
{ {
// 192.168.1.254:LocalHost:DarthSalamon:0:none // 192.168.1.254:LocalHost:Prozza:0:none
// 127.0.*.*:TestUserName:BannedByNotch:123567:Test reason // 127.0.*.*:TestUserName:BannedByNotch:123567:Test reason
IP_BAN_REGEX = Pattern.compile( IP_BAN_REGEX = Pattern.compile(
"^((?:(?:\\*|(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))\\.){3}(?:\\*|(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)))" "^((?:(?:\\*|(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))\\.){3}(?:\\*|(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)))"
@ -24,7 +24,7 @@ public class TFM_Ban
+ ":([\\w]+)" + ":([\\w]+)"
+ ":(\\d+)" + ":(\\d+)"
+ ":([\\s\\S]+)$"); + ":([\\s\\S]+)$");
// 245d2f30-61fb-4840-9cd3-298b3920f4a4:Cobrex:DarthSalamon:0:Example reason // 245d2f30-61fb-4840-9cd3-298b3920f4a4:Cobrex:Prozza:0:Example reason
UUID_BAN_REGEX = Pattern.compile( UUID_BAN_REGEX = Pattern.compile(
"^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})" "^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})"
+ ":([\\w\\s]+)" + ":([\\w\\s]+)"

View File

@ -110,7 +110,7 @@ public class TFM_BanManager
public static List<TFM_Ban> getIpBanList() public static List<TFM_Ban> getIpBanList()
{ {
return Collections.unmodifiableList(uuidBans); return Collections.unmodifiableList(ipBans);
} }
public static List<TFM_Ban> getUuidBanList() public static List<TFM_Ban> getUuidBanList()

View File

@ -102,7 +102,7 @@ public class TFM_CommandBlocker
public static boolean isCommandBlocked(String command, CommandSender sender) public static boolean isCommandBlocked(String command, CommandSender sender)
{ {
return isCommandBlocked(command, sender, true); return isCommandBlocked(command, sender, false);
} }
public static boolean isCommandBlocked(String command, CommandSender sender, boolean doAction) public static boolean isCommandBlocked(String command, CommandSender sender, boolean doAction)
@ -112,21 +112,27 @@ public class TFM_CommandBlocker
return false; return false;
} }
if (command.contains(":")) command = command.toLowerCase().trim();
if (command.split(" ")[0].contains(":"))
{ {
TFM_Util.playerMsg(sender, "Plugin-specific commands are disabled."); TFM_Util.playerMsg(sender, "Plugin-specific commands are disabled.");
return true; return true;
} }
if (command.startsWith("/"))
{
command = command.substring(1);
}
final String[] commandParts = command.split(" "); final String[] commandParts = command.split(" ");
String subCommand = null; String subCommand = null;
if (commandParts.length > 1) if (commandParts.length > 1)
{ {
command = commandParts[0].substring(1);
subCommand = StringUtils.join(commandParts, " ", 1, commandParts.length).toLowerCase(); subCommand = StringUtils.join(commandParts, " ", 1, commandParts.length).toLowerCase();
} }
final CommandBlockerEntry entry = BLOCKED_COMMANDS.get(command); final CommandBlockerEntry entry = BLOCKED_COMMANDS.get(commandParts[0]);
if (entry == null) if (entry == null)
{ {
@ -152,7 +158,6 @@ public class TFM_CommandBlocker
} }
return true; return true;
} }
public static enum CommandBlockerRank public static enum CommandBlockerRank
@ -185,27 +190,27 @@ public class TFM_CommandBlocker
public static CommandBlockerRank fromSender(CommandSender sender) public static CommandBlockerRank fromSender(CommandSender sender)
{ {
if (!TFM_AdminList.isSuperAdmin(sender))
{
if (sender.isOp())
{
return OP;
}
return ANYONE;
}
if (TFM_AdminList.isSeniorAdmin(sender))
{
return SENIOR;
}
if (!(sender instanceof Player)) if (!(sender instanceof Player))
{ {
return TELNET; return TELNET;
} }
return SUPER; if (TFM_AdminList.isSuperAdmin(sender))
{
if (TFM_AdminList.isSeniorAdmin(sender))
{
return SENIOR;
}
return SUPER;
}
if (sender.isOp())
{
return OP;
}
return ANYONE;
} }
public static CommandBlockerRank fromToken(String token) public static CommandBlockerRank fromToken(String token)

View File

@ -7,6 +7,7 @@ import me.StevenLawson.TotalFreedomMod.Config.TFM_Config;
public class TFM_PermbanList public class TFM_PermbanList
{ {
private static final List<String> PERMBANNED_PLAYERS; private static final List<String> PERMBANNED_PLAYERS;
private static final List<String> PERMBANNED_IPS; private static final List<String> PERMBANNED_IPS;

View File

@ -29,6 +29,14 @@ public class TFM_PlayerData
return PLAYER_DATA.containsKey(TFM_Util.getIp(player)); return PLAYER_DATA.containsKey(TFM_Util.getIp(player));
} }
public static TFM_PlayerData getPlayerDataSync(Player player)
{
synchronized (PLAYER_DATA)
{
return getPlayerData(player);
}
}
public static TFM_PlayerData getPlayerData(Player player) public static TFM_PlayerData getPlayerData(Player player)
{ {
final String ip = TFM_Util.getIp(player); final String ip = TFM_Util.getIp(player);
@ -210,7 +218,7 @@ public class TFM_PlayerData
if (player.getGameMode() != GameMode.CREATIVE) if (player.getGameMode() != GameMode.CREATIVE)
{ {
player.setFlying(false); TFM_Util.setFlying(player, false);
} }
if (!freeze) if (!freeze)
@ -219,7 +227,7 @@ public class TFM_PlayerData
} }
freezeLocation = player.getLocation(); // Blockify location freezeLocation = player.getLocation(); // Blockify location
player.setFlying(true); // Avoid infinite falling TFM_Util.setFlying(player, true); // Avoid infinite falling
unfreezeTask = new BukkitRunnable() unfreezeTask = new BukkitRunnable()
{ {
@ -402,7 +410,7 @@ public class TFM_PlayerData
{ {
player.setOp(false); player.setOp(false);
player.setGameMode(GameMode.SURVIVAL); player.setGameMode(GameMode.SURVIVAL);
player.setFlying(false); TFM_Util.setFlying(player, false);
TFM_EssentialsBridge.setNickname(player.getName(), player.getName()); TFM_EssentialsBridge.setNickname(player.getName(), player.getName());
player.closeInventory(); player.closeInventory();
player.setTotalExperience(0); player.setTotalExperience(0);

View File

@ -11,65 +11,53 @@ import me.StevenLawson.TotalFreedomMod.Config.TFM_Config;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class TFM_PlayerList public class TFM_PlayerList {
{
private static final Map<UUID, TFM_Player> PLAYER_LIST = new HashMap<UUID, TFM_Player>(); private static final Map<UUID, TFM_Player> PLAYER_LIST = new HashMap<UUID, TFM_Player>();
private TFM_PlayerList() private TFM_PlayerList() {
{
throw new AssertionError(); throw new AssertionError();
} }
public static Set<TFM_Player> getAllPlayers() public static Set<TFM_Player> getAllPlayers() {
{
return Collections.unmodifiableSet(Sets.newHashSet(PLAYER_LIST.values())); return Collections.unmodifiableSet(Sets.newHashSet(PLAYER_LIST.values()));
} }
public static void load() public static void load() {
{
PLAYER_LIST.clear(); PLAYER_LIST.clear();
// Load online players // Load online players
for (Player player : Bukkit.getOnlinePlayers()) for (Player player : Bukkit.getOnlinePlayers()) {
{
getEntry(player); getEntry(player);
} }
TFM_Log.info("Loaded playerdata for " + PLAYER_LIST.size() + " players"); TFM_Log.info("Loaded playerdata for " + PLAYER_LIST.size() + " players");
} }
public static void saveAll() public static void saveAll() {
{ for (TFM_Player entry : PLAYER_LIST.values()) {
for (TFM_Player entry : PLAYER_LIST.values())
{
save(entry); save(entry);
} }
} }
// May return null // May return null
public static TFM_Player getEntry(UUID uuid) public static TFM_Player getEntry(UUID uuid) {
{ if (PLAYER_LIST.containsKey(uuid)) {
if (PLAYER_LIST.containsKey(uuid))
{
return PLAYER_LIST.get(uuid); return PLAYER_LIST.get(uuid);
} }
final File configFile = getConfigFile(uuid); final File configFile = getConfigFile(uuid);
if (!configFile.exists()) if (!configFile.exists()) {
{
return null; return null;
} }
final TFM_Player entry = new TFM_Player(uuid, getConfig(uuid)); final TFM_Player entry = new TFM_Player(uuid, getConfig(uuid));
if (entry.isComplete()) if (entry.isComplete()) {
{
PLAYER_LIST.put(uuid, entry); PLAYER_LIST.put(uuid, entry);
return entry; return entry;
} } else {
else
{
TFM_Log.warning("Could not load entry: Entry is not complete!"); TFM_Log.warning("Could not load entry: Entry is not complete!");
configFile.delete(); configFile.delete();
} }
@ -77,13 +65,11 @@ public class TFM_PlayerList
return null; return null;
} }
public static TFM_Player getEntry(Player player) public static TFM_Player getEntry(Player player) {
{
final UUID uuid = TFM_UuidManager.getUniqueId(player); final UUID uuid = TFM_UuidManager.getUniqueId(player);
TFM_Player entry = getEntry(uuid); TFM_Player entry = getEntry(uuid);
if (entry != null) if (entry != null) {
{
return entry; return entry;
} }
@ -101,12 +87,10 @@ public class TFM_PlayerList
return entry; return entry;
} }
public static void removeEntry(Player player) public static void removeEntry(Player player) {
{
final UUID uuid = TFM_UuidManager.getUniqueId(player); final UUID uuid = TFM_UuidManager.getUniqueId(player);
if (!PLAYER_LIST.containsKey(uuid)) if (!PLAYER_LIST.containsKey(uuid)) {
{
return; return;
} }
@ -115,20 +99,16 @@ public class TFM_PlayerList
PLAYER_LIST.remove(uuid); PLAYER_LIST.remove(uuid);
} }
public static boolean existsEntry(Player player) public static boolean existsEntry(Player player) {
{
return existsEntry(TFM_UuidManager.getUniqueId(player)); return existsEntry(TFM_UuidManager.getUniqueId(player));
} }
public static boolean existsEntry(UUID uuid) public static boolean existsEntry(UUID uuid) {
{
return getConfigFile(uuid).exists(); return getConfigFile(uuid).exists();
} }
public static void setUniqueId(TFM_Player entry, UUID newUuid) public static void setUniqueId(TFM_Player entry, UUID newUuid) {
{ if (entry.getUniqueId().equals(newUuid)) {
if (entry.getUniqueId().equals(newUuid))
{
TFM_Log.warning("Not setting new UUID: UUIDs match!"); TFM_Log.warning("Not setting new UUID: UUIDs match!");
return; return;
} }
@ -147,16 +127,13 @@ public class TFM_PlayerList
// Remove old entry // Remove old entry
PLAYER_LIST.remove(entry.getUniqueId()); PLAYER_LIST.remove(entry.getUniqueId());
final File oldFile = getConfigFile(entry.getUniqueId()); final File oldFile = getConfigFile(entry.getUniqueId());
if (oldFile.exists() && !oldFile.delete()) if (oldFile.exists() && !oldFile.delete()) {
{
TFM_Log.warning("Could not delete config: " + getConfigFile(entry.getUniqueId()).getName()); TFM_Log.warning("Could not delete config: " + getConfigFile(entry.getUniqueId()).getName());
} }
} }
public static void purgeAll() public static void purgeAll() {
{ for (File file : getConfigFolder().listFiles()) {
for (File file : getConfigFolder().listFiles())
{
file.delete(); file.delete();
} }
@ -164,27 +141,22 @@ public class TFM_PlayerList
load(); load();
} }
public static File getConfigFolder() public static File getConfigFolder() {
{
return new File(TotalFreedomMod.plugin.getDataFolder(), "players"); return new File(TotalFreedomMod.plugin.getDataFolder(), "players");
} }
public static File getConfigFile(UUID uuid) public static File getConfigFile(UUID uuid) {
{
return new File(getConfigFolder(), uuid + ".yml"); return new File(getConfigFolder(), uuid + ".yml");
} }
public static TFM_Config getConfig(UUID uuid) public static TFM_Config getConfig(UUID uuid) {
{
final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, getConfigFile(uuid), false); final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, getConfigFile(uuid), false);
config.load(); config.load();
return config; return config;
} }
public static void save(TFM_Player entry) public static void save(TFM_Player entry) {
{ if (!entry.isComplete()) {
if (!entry.isComplete())
{
throw new IllegalArgumentException("Entry is not complete!"); throw new IllegalArgumentException("Entry is not complete!");
} }

View File

@ -66,7 +66,7 @@ public class TFM_ProtectedArea
if (doSave) if (doSave)
{ {
saveProtectedAreas(); save();
} }
return inProtectedArea; return inProtectedArea;
@ -110,7 +110,7 @@ public class TFM_ProtectedArea
if (doSave) if (doSave)
{ {
saveProtectedAreas(); save();
} }
return inProtectedArea; return inProtectedArea;
@ -156,13 +156,13 @@ public class TFM_ProtectedArea
public static void addProtectedArea(String label, Location location, double radius) public static void addProtectedArea(String label, Location location, double radius)
{ {
TFM_ProtectedArea.PROTECTED_AREAS.put(label.toLowerCase(), new SerializableProtectedRegion(location, radius)); TFM_ProtectedArea.PROTECTED_AREAS.put(label.toLowerCase(), new SerializableProtectedRegion(location, radius));
saveProtectedAreas(); save();
} }
public static void removeProtectedArea(String label) public static void removeProtectedArea(String label)
{ {
TFM_ProtectedArea.PROTECTED_AREAS.remove(label.toLowerCase()); TFM_ProtectedArea.PROTECTED_AREAS.remove(label.toLowerCase());
saveProtectedAreas(); save();
} }
public static void clearProtectedAreas() public static void clearProtectedAreas()
@ -179,7 +179,7 @@ public class TFM_ProtectedArea
autoAddSpawnpoints(); autoAddSpawnpoints();
} }
saveProtectedAreas(); save();
} }
public static void cleanProtectedAreas() public static void cleanProtectedAreas()
@ -203,7 +203,7 @@ public class TFM_ProtectedArea
if (doSave) if (doSave)
{ {
saveProtectedAreas(); save();
} }
} }
@ -212,7 +212,7 @@ public class TFM_ProtectedArea
return TFM_ProtectedArea.PROTECTED_AREAS.keySet(); return TFM_ProtectedArea.PROTECTED_AREAS.keySet();
} }
public static void saveProtectedAreas() public static void save()
{ {
try try
{ {
@ -229,8 +229,13 @@ public class TFM_ProtectedArea
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static void loadProtectedAreas() public static void load()
{ {
if (!TFM_ConfigEntry.PROTECTAREA_ENABLED.getBoolean())
{
return;
}
File input = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PROTECTED_AREA_FILENAME); File input = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PROTECTED_AREA_FILENAME);
try try
{ {
@ -255,6 +260,11 @@ public class TFM_ProtectedArea
public static void autoAddSpawnpoints() public static void autoAddSpawnpoints()
{ {
if (!TFM_ConfigEntry.PROTECTAREA_ENABLED.getBoolean())
{
return;
}
if (TFM_ConfigEntry.PROTECTAREA_SPAWNPOINTS.getBoolean()) if (TFM_ConfigEntry.PROTECTAREA_SPAWNPOINTS.getBoolean())
{ {
for (World world : Bukkit.getWorlds()) for (World world : Bukkit.getWorlds())

View File

@ -5,17 +5,20 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import net.minecraft.server.v1_8_R1.MinecraftServer; import static me.StevenLawson.TotalFreedomMod.Listener.TFM_PlayerListener.DEFAULT_PORT;
import net.minecraft.server.v1_8_R1.PropertyManager; import net.minecraft.server.v1_8_R2.EntityPlayer;
import net.minecraft.server.v1_8_R2.MinecraftServer;
import net.minecraft.server.v1_8_R2.PropertyManager;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerLoginEvent.Result; import org.bukkit.event.player.PlayerLoginEvent.Result;
public class TFM_ServerInterface public class TFM_ServerInterface
{ {
public static final String COMPILE_NMS_VERSION = "v1_8_R1"; public static final String COMPILE_NMS_VERSION = "v1_8_R2";
public static final Pattern USERNAME_REGEX = Pattern.compile("^[\\w\\d_]{3,20}$"); public static final Pattern USERNAME_REGEX = Pattern.compile("^[\\w\\d_]{3,20}$");
public static void setOnlineMode(boolean mode) public static void setOnlineMode(boolean mode)
@ -29,9 +32,9 @@ public class TFM_ServerInterface
{ {
String[] whitelisted = MinecraftServer.getServer().getPlayerList().getWhitelisted(); String[] whitelisted = MinecraftServer.getServer().getPlayerList().getWhitelisted();
int size = whitelisted.length; int size = whitelisted.length;
for (String player : MinecraftServer.getServer().getPlayerList().getWhitelist().getEntries()) for (EntityPlayer player : MinecraftServer.getServer().getPlayerList().players)
{ {
MinecraftServer.getServer().getPlayerList().getWhitelist().remove(player); MinecraftServer.getServer().getPlayerList().getWhitelist().remove(player.getProfile());
} }
try try
@ -48,7 +51,7 @@ public class TFM_ServerInterface
public static boolean isWhitelisted() public static boolean isWhitelisted()
{ {
return MinecraftServer.getServer().getPlayerList().hasWhitelist; return MinecraftServer.getServer().getPlayerList().getHasWhitelist();
} }
public static List<?> getWhitelisted() public static List<?> getWhitelisted()
@ -61,6 +64,29 @@ public class TFM_ServerInterface
return MinecraftServer.getServer().getVersion(); return MinecraftServer.getServer().getVersion();
} }
public static void handlePlayerPreLogin(AsyncPlayerPreLoginEvent event)
{
final String ip = event.getAddress().getHostAddress().trim();
final boolean isAdmin = TFM_AdminList.isSuperAdminSafe(null, ip);
// Check if the player is already online
for (Player onlinePlayer : TotalFreedomMod.server.getOnlinePlayers())
{
if (!onlinePlayer.getName().equalsIgnoreCase(event.getName()))
{
continue;
}
if (!isAdmin) {
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, "Your username is already logged into this server.");
} else {
event.allow();
TFM_Sync.playerKick(onlinePlayer, "An admin just logged in with the username you are using.");
}
return;
}
}
public static void handlePlayerLogin(PlayerLoginEvent event) public static void handlePlayerLogin(PlayerLoginEvent event)
{ {
final Server server = TotalFreedomMod.server; final Server server = TotalFreedomMod.server;
@ -69,19 +95,38 @@ public class TFM_ServerInterface
final String ip = event.getAddress().getHostAddress().trim(); final String ip = event.getAddress().getHostAddress().trim();
final UUID uuid = TFM_UuidManager.newPlayer(player, ip); final UUID uuid = TFM_UuidManager.newPlayer(player, ip);
// Perform username checks // Check username length
if (username.length() < 3 || username.length() > TotalFreedomMod.MAX_USERNAME_LENGTH) if (username.length() < 3 || username.length() > TotalFreedomMod.MAX_USERNAME_LENGTH)
{ {
event.disallow(Result.KICK_OTHER, "Your username is an invalid length (must be between 3 and 20 characters long)."); event.disallow(Result.KICK_OTHER, "Your username is an invalid length (must be between 3 and 20 characters long).");
return; return;
} }
// Check username characters
if (!USERNAME_REGEX.matcher(username).find()) if (!USERNAME_REGEX.matcher(username).find())
{ {
event.disallow(Result.KICK_OTHER, "Your username contains invalid characters."); event.disallow(Result.KICK_OTHER, "Your username contains invalid characters.");
return; return;
} }
// Check force-IP match
if (TFM_ConfigEntry.FORCE_IP_ENABLED.getBoolean())
{
final String hostname = event.getHostname().replace("FML", ""); // Forge fix - https://github.com/TotalFreedom/TotalFreedomMod/issues/493
final String connectAddress = TFM_ConfigEntry.SERVER_ADDRESS.getString();
final int connectPort = TotalFreedomMod.server.getPort();
if (!hostname.equalsIgnoreCase(connectAddress + ":" + connectPort) && !hostname.equalsIgnoreCase(connectAddress + ".:" + connectPort))
{
final int forceIpPort = TFM_ConfigEntry.FORCE_IP_PORT.getInteger();
event.disallow(PlayerLoginEvent.Result.KICK_OTHER,
TFM_ConfigEntry.FORCE_IP_KICKMSG.getString()
.replace("%address%", TFM_ConfigEntry.SERVER_ADDRESS.getString() + (forceIpPort == DEFAULT_PORT ? "" : ":" + forceIpPort)));
return;
}
}
// Check if player is admin // Check if player is admin
// Not safe to use TFM_Util.isSuperAdmin(player) because player.getAddress() will return a null until after player login. // Not safe to use TFM_Util.isSuperAdmin(player) because player.getAddress() will return a null until after player login.
final boolean isAdmin = TFM_AdminList.isSuperAdminSafe(uuid, ip); final boolean isAdmin = TFM_AdminList.isSuperAdminSafe(uuid, ip);
@ -92,15 +137,6 @@ public class TFM_ServerInterface
// Force-allow log in // Force-allow log in
event.allow(); event.allow();
// Kick players with the same name
for (Player onlinePlayer : server.getOnlinePlayers())
{
if (onlinePlayer.getName().equalsIgnoreCase(username))
{
onlinePlayer.kickPlayer("An admin just logged in with the username you are using.");
}
}
int count = server.getOnlinePlayers().size(); int count = server.getOnlinePlayers().size();
if (count >= server.getMaxPlayers()) if (count >= server.getMaxPlayers())
{ {
@ -150,16 +186,6 @@ public class TFM_ServerInterface
return; return;
} }
// Username already logged in
for (Player onlinePlayer : server.getOnlinePlayers())
{
if (onlinePlayer.getName().equalsIgnoreCase(username))
{
event.disallow(Result.KICK_OTHER, "Your username is already logged into this server.");
return;
}
}
// Whitelist // Whitelist
if (isWhitelisted()) if (isWhitelisted())
{ {

View File

@ -0,0 +1,80 @@
package me.StevenLawson.TotalFreedomMod;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
public class TFM_Sync
{
public static void playerMsg(final Player player, final String message)
{
new BukkitRunnable()
{
@Override
public void run()
{
TFM_Util.playerMsg(player, message);
}
}.runTask(TotalFreedomMod.plugin);
}
public static void playerKick(final Player player, final String reason)
{
new BukkitRunnable()
{
@Override
public void run()
{
player.kickPlayer(reason);
}
}.runTask(TotalFreedomMod.plugin);
}
public static void adminChatMessage(final CommandSender sender, final String message, final boolean isRed)
{
new BukkitRunnable()
{
@Override
public void run()
{
TFM_Util.adminChatMessage(sender, message, isRed);
}
}.runTask(TotalFreedomMod.plugin);
}
public static void autoEject(final Player player, final String kickMessage)
{
new BukkitRunnable()
{
@Override
public void run()
{
TFM_Util.autoEject(player, kickMessage);
}
}.runTask(TotalFreedomMod.plugin);
}
public static void bcastMsg(final String message, final ChatColor color)
{
new BukkitRunnable()
{
@Override
public void run()
{
TFM_Util.bcastMsg(message, color);
}
}.runTask(TotalFreedomMod.plugin);
}
}

View File

@ -142,6 +142,12 @@ public class TFM_Util
TFM_Util.playerMsg(sender, message, ChatColor.GRAY); TFM_Util.playerMsg(sender, message, ChatColor.GRAY);
} }
public static void setFlying(Player player, boolean flying)
{
player.setAllowFlight(true);
player.setFlying(flying);
}
public static void adminAction(String adminName, String action, boolean isRed) public static void adminAction(String adminName, String action, boolean isRed)
{ {
TFM_Util.bcastMsg(adminName + " - " + action, (isRed ? ChatColor.RED : ChatColor.AQUA)); TFM_Util.bcastMsg(adminName + " - " + action, (isRed ? ChatColor.RED : ChatColor.AQUA));
@ -326,7 +332,7 @@ public class TFM_Util
block.setType(Material.SKULL); block.setType(Material.SKULL);
final Skull skull = (Skull) block.getState(); final Skull skull = (Skull) block.getState();
skull.setSkullType(SkullType.PLAYER); skull.setSkullType(SkullType.PLAYER);
skull.setOwner("DarthSalamon"); skull.setOwner("Prozza");
skull.update(); skull.update();
} }
} }

View File

@ -25,20 +25,18 @@ import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser; import org.json.simple.parser.JSONParser;
public class TFM_UuidManager public class TFM_UuidManager {
{
public static final String TABLE_NAME = "uuids"; public static final String TABLE_NAME = "uuids";
private static final TFM_SqliteDatabase SQL; private static final TFM_SqliteDatabase SQL;
private static final Statement FIND; private static final Statement FIND;
private static final Statement UPDATE; private static final Statement UPDATE;
private TFM_UuidManager() private TFM_UuidManager() {
{
throw new AssertionError(); throw new AssertionError();
} }
static static {
{
SQL = new TFM_SqliteDatabase( SQL = new TFM_SqliteDatabase(
"uuids.db", "uuids.db",
TABLE_NAME, TABLE_NAME,
@ -48,40 +46,34 @@ public class TFM_UuidManager
UPDATE = SQL.addPreparedStatement("REPLACE INTO " + TABLE_NAME + " (username, uuid) VALUES (?, ?);"); UPDATE = SQL.addPreparedStatement("REPLACE INTO " + TABLE_NAME + " (username, uuid) VALUES (?, ?);");
} }
public static void load() public static void load() {
{
// Init DB // Init DB
SQL.connect(); SQL.connect();
} }
public static void close() public static void close() {
{
SQL.close(); SQL.close();
} }
public static int purge() public static int purge() {
{
return SQL.purge(); return SQL.purge();
} }
public static UUID newPlayer(Player player, String ip) public static UUID newPlayer(Player player, String ip) {
{
TFM_Log.info("Obtaining UUID for new player: " + player.getName()); TFM_Log.info("Obtaining UUID for new player: " + player.getName());
final String username = player.getName().toLowerCase(); final String username = player.getName().toLowerCase();
// Look in DB // Look in DB
final UUID dbUuid = find(username); final UUID dbUuid = find(username);
if (dbUuid != null) if (dbUuid != null) {
{
return dbUuid; return dbUuid;
} }
// Find UUID and update in DB if not found // Find UUID and update in DB if not found
// Try API // Try API
UUID uuid = TFM_UuidResolver.getUUIDOf(username); UUID uuid = TFM_UuidResolver.getUUIDOf(username);
if (uuid == null) if (uuid == null) {
{
// Spoof // Spoof
uuid = generateSpoofUuid(username); uuid = generateSpoofUuid(username);
} }
@ -90,11 +82,9 @@ public class TFM_UuidManager
return uuid; return uuid;
} }
public static UUID getUniqueId(OfflinePlayer offlinePlayer) public static UUID getUniqueId(OfflinePlayer offlinePlayer) {
{
// Online check first // Online check first
if (offlinePlayer.isOnline() && TFM_PlayerData.hasPlayerData(offlinePlayer.getPlayer())) if (offlinePlayer.isOnline() && TFM_PlayerData.hasPlayerData(offlinePlayer.getPlayer())) {
{
return TFM_PlayerData.getPlayerData(offlinePlayer.getPlayer()).getUniqueId(); return TFM_PlayerData.getPlayerData(offlinePlayer.getPlayer()).getUniqueId();
} }
@ -102,19 +92,16 @@ public class TFM_UuidManager
return getUniqueId(offlinePlayer.getName()); return getUniqueId(offlinePlayer.getName());
} }
public static UUID getUniqueId(String username) public static UUID getUniqueId(String username) {
{
// Look in DB // Look in DB
final UUID dbUuid = find(username); final UUID dbUuid = find(username);
if (dbUuid != null) if (dbUuid != null) {
{
return dbUuid; return dbUuid;
} }
// Try API // Try API
final UUID apiUuid = TFM_UuidResolver.getUUIDOf(username); final UUID apiUuid = TFM_UuidResolver.getUUIDOf(username);
if (apiUuid != null) if (apiUuid != null) {
{
return apiUuid; return apiUuid;
} }
@ -131,86 +118,67 @@ public class TFM_UuidManager
update(name.toLowerCase().trim(), uuid); update(name.toLowerCase().trim(), uuid);
} }
private static UUID find(String searchName) private static UUID find(String searchName) {
{ if (!SQL.connect()) {
if (!SQL.connect())
{
return null; return null;
} }
final ResultSet result; final ResultSet result;
try try {
{
final PreparedStatement statement = FIND.getStatement(); final PreparedStatement statement = FIND.getStatement();
statement.clearParameters(); statement.clearParameters();
statement.setString(1, searchName.toLowerCase()); statement.setString(1, searchName.toLowerCase());
result = statement.executeQuery(); result = statement.executeQuery();
} } catch (Exception ex) {
catch (Exception ex)
{
TFM_Log.severe("Could not execute find statement!"); TFM_Log.severe("Could not execute find statement!");
TFM_Log.severe(ex); TFM_Log.severe(ex);
return null; return null;
} }
if (!TFM_SqlUtil.hasData(result)) if (!TFM_SqlUtil.hasData(result)) {
{
TFM_SqlUtil.close(result); TFM_SqlUtil.close(result);
return null; return null;
} }
try try {
{
final String uuidString = result.getString("uuid"); final String uuidString = result.getString("uuid");
return UUID.fromString(uuidString); return UUID.fromString(uuidString);
} } catch (Exception ex) {
catch (Exception ex)
{
TFM_Log.severe(ex); TFM_Log.severe(ex);
return null; return null;
} } finally {
finally
{
TFM_SqlUtil.close(result); TFM_SqlUtil.close(result);
} }
} }
private static boolean update(String username, UUID uuid) private static boolean update(String username, UUID uuid) {
{ if (!SQL.connect()) {
if (!SQL.connect())
{
return false; return false;
} }
try try {
{
final PreparedStatement statement = UPDATE.getStatement(); final PreparedStatement statement = UPDATE.getStatement();
statement.clearParameters(); statement.clearParameters();
statement.setString(1, username.toLowerCase()); statement.setString(1, username.toLowerCase());
statement.setString(2, uuid.toString()); statement.setString(2, uuid.toString());
statement.executeUpdate(); statement.executeUpdate();
return true; return true;
} } catch (Exception ex) {
catch (Exception ex)
{
TFM_Log.severe("Could not execute update statement!"); TFM_Log.severe("Could not execute update statement!");
TFM_Log.severe(ex); TFM_Log.severe(ex);
return false; return false;
} }
} }
private static UUID generateSpoofUuid(String name) private static UUID generateSpoofUuid(String name) {
{
name = name.toLowerCase(); name = name.toLowerCase();
TFM_Log.info("Generating spoof UUID for " + name); TFM_Log.info("Generating spoof UUID for " + name);
try try {
{
final MessageDigest digest = MessageDigest.getInstance("SHA1"); final MessageDigest digest = MessageDigest.getInstance("SHA1");
final byte[] result = digest.digest(name.getBytes()); final byte[] result = digest.digest(name.getBytes());
final StringBuilder builder = new StringBuilder(); final StringBuilder builder = new StringBuilder();
for (int i = 0; i < result.length; i++) for (int i = 0; i < result.length; i++) {
{
builder.append(Integer.toString((result[i] & 0xff) + 0x100, 16).substring(1)); builder.append(Integer.toString((result[i] & 0xff) + 0x100, 16).substring(1));
} }
@ -220,36 +188,30 @@ public class TFM_UuidManager
+ "-" + builder.substring(12, 16) + "-" + builder.substring(12, 16)
+ "-" + builder.substring(16, 20) + "-" + builder.substring(16, 20)
+ "-" + builder.substring(20, 32)); + "-" + builder.substring(20, 32));
} } catch (NoSuchAlgorithmException ex) {
catch (NoSuchAlgorithmException ex)
{
TFM_Log.warning("Could not generate spoof UUID: SHA1 algorithm not found!"); TFM_Log.warning("Could not generate spoof UUID: SHA1 algorithm not found!");
} }
return UUID.randomUUID(); return UUID.randomUUID();
} }
public static class TFM_UuidResolver implements Callable<Map<String, UUID>> public static class TFM_UuidResolver implements Callable<Map<String, UUID>> {
{
private static final double PROFILES_PER_REQUEST = 100; private static final double PROFILES_PER_REQUEST = 100;
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft"; private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
private final JSONParser jsonParser = new JSONParser(); private final JSONParser jsonParser = new JSONParser();
private final List<String> names; private final List<String> names;
public TFM_UuidResolver(List<String> names) public TFM_UuidResolver(List<String> names) {
{
this.names = ImmutableList.copyOf(names); this.names = ImmutableList.copyOf(names);
} }
@Override @Override
public Map<String, UUID> call() public Map<String, UUID> call() {
{
final Map<String, UUID> uuidMap = new HashMap<String, UUID>(); final Map<String, UUID> uuidMap = new HashMap<String, UUID>();
int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST); int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST);
for (int i = 0; i < requests; i++) for (int i = 0; i < requests; i++) {
{ try {
try
{
final URL url = new URL(PROFILE_URL); final URL url = new URL(PROFILE_URL);
final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
@ -268,8 +230,7 @@ public class TFM_UuidManager
final JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream())); final JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
for (Object profile : array) for (Object profile : array) {
{
final JSONObject jsonProfile = (JSONObject) profile; final JSONObject jsonProfile = (JSONObject) profile;
final String id = (String) jsonProfile.get("id"); final String id = (String) jsonProfile.get("id");
final String name = (String) jsonProfile.get("name"); final String name = (String) jsonProfile.get("name");
@ -282,13 +243,10 @@ public class TFM_UuidManager
uuidMap.put(name, uuid); uuidMap.put(name, uuid);
} }
if (i != requests - 1) if (i != requests - 1) {
{
Thread.sleep(100L); Thread.sleep(100L);
} }
} } catch (Exception ex) {
catch (Exception ex)
{
TFM_Log.severe("Could not resolve UUID(s) of " TFM_Log.severe("Could not resolve UUID(s) of "
+ StringUtils.join(names.subList(i * 100, Math.min((i + 1) * 100, names.size())), ", ")); + StringUtils.join(names.subList(i * 100, Math.min((i + 1) * 100, names.size())), ", "));
//TFM_Log.severe(ex); //TFM_Log.severe(ex);
@ -297,9 +255,9 @@ public class TFM_UuidManager
return uuidMap; return uuidMap;
} }
public static UUID getUUIDOf(String name) public static UUID getUUIDOf(String name) {
{
return new TFM_UuidResolver(Arrays.asList(name)).call().get(name); return new TFM_UuidResolver(Arrays.asList(name)).call().get(name);
} }
} }
} }

View File

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod;
import com.google.common.base.Function;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -7,6 +8,8 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import me.StevenLawson.TotalFreedomMod.Bridge.TFM_BukkitTelnetListener;
import me.StevenLawson.TotalFreedomMod.Bridge.TFM_WorldEditListener;
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandHandler; import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandHandler;
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader; import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
@ -15,7 +18,6 @@ import me.StevenLawson.TotalFreedomMod.Listener.TFM_BlockListener;
import me.StevenLawson.TotalFreedomMod.Listener.TFM_EntityListener; import me.StevenLawson.TotalFreedomMod.Listener.TFM_EntityListener;
import me.StevenLawson.TotalFreedomMod.Listener.TFM_PlayerListener; import me.StevenLawson.TotalFreedomMod.Listener.TFM_PlayerListener;
import me.StevenLawson.TotalFreedomMod.Listener.TFM_ServerListener; import me.StevenLawson.TotalFreedomMod.Listener.TFM_ServerListener;
import me.StevenLawson.TotalFreedomMod.Listener.TFM_TelnetListener;
import me.StevenLawson.TotalFreedomMod.Listener.TFM_WeatherListener; import me.StevenLawson.TotalFreedomMod.Listener.TFM_WeatherListener;
import me.StevenLawson.TotalFreedomMod.World.TFM_AdminWorld; import me.StevenLawson.TotalFreedomMod.World.TFM_AdminWorld;
import me.StevenLawson.TotalFreedomMod.World.TFM_Flatlands; import me.StevenLawson.TotalFreedomMod.World.TFM_Flatlands;
@ -25,6 +27,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.ServicePriority;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import org.mcstats.Metrics; import org.mcstats.Metrics;
@ -74,7 +77,7 @@ public class TotalFreedomMod extends JavaPlugin
@Override @Override
public void onEnable() public void onEnable()
{ {
TFM_Log.info("Made by Madgeek1450 and DarthSalamon"); TFM_Log.info("Made by Madgeek1450 and Prozza");
TFM_Log.info("Compiled " + buildDate + " by " + buildCreator); TFM_Log.info("Compiled " + buildDate + " by " + buildCreator);
final TFM_Util.MethodTimer timer = new TFM_Util.MethodTimer(); final TFM_Util.MethodTimer timer = new TFM_Util.MethodTimer();
@ -102,14 +105,10 @@ public class TotalFreedomMod extends JavaPlugin
TFM_PlayerList.load(); TFM_PlayerList.load();
TFM_BanManager.load(); TFM_BanManager.load();
TFM_Announcer.load(); TFM_Announcer.load();
TFM_ProtectedArea.load();
// Protect area // Start SuperAdmin service
// TODO: Refractor to single .load() method server.getServicesManager().register(Function.class, TFM_AdminList.SUPERADMIN_SERVICE, plugin, ServicePriority.Normal);
if (TFM_ConfigEntry.PROTECTAREA_ENABLED.getBoolean())
{
TFM_ProtectedArea.loadProtectedAreas();
TFM_ProtectedArea.autoAddSpawnpoints();
}
final PluginManager pm = server.getPluginManager(); final PluginManager pm = server.getPluginManager();
pm.registerEvents(new TFM_EntityListener(), plugin); pm.registerEvents(new TFM_EntityListener(), plugin);
@ -117,7 +116,10 @@ public class TotalFreedomMod extends JavaPlugin
pm.registerEvents(new TFM_PlayerListener(), plugin); pm.registerEvents(new TFM_PlayerListener(), plugin);
pm.registerEvents(new TFM_WeatherListener(), plugin); pm.registerEvents(new TFM_WeatherListener(), plugin);
pm.registerEvents(new TFM_ServerListener(), plugin); pm.registerEvents(new TFM_ServerListener(), plugin);
pm.registerEvents(new TFM_TelnetListener(), plugin);
// Bridge
pm.registerEvents(new TFM_BukkitTelnetListener(), plugin);
pm.registerEvents(new TFM_WorldEditListener(), plugin);
try try
{ {
@ -182,7 +184,6 @@ public class TotalFreedomMod extends JavaPlugin
TFM_Log.warning("Failed to submit metrics data: " + ex.getMessage()); TFM_Log.warning("Failed to submit metrics data: " + ex.getMessage());
} }
// Load commands later
new BukkitRunnable() new BukkitRunnable()
{ {
@Override @Override
@ -190,6 +191,9 @@ public class TotalFreedomMod extends JavaPlugin
{ {
TFM_CommandLoader.scan(); TFM_CommandLoader.scan();
TFM_CommandBlocker.load(); TFM_CommandBlocker.load();
// Add spawnpoints later - https://github.com/TotalFreedom/TotalFreedomMod/issues/438
TFM_ProtectedArea.autoAddSpawnpoints();
} }
}.runTaskLater(plugin, 20L); }.runTaskLater(plugin, 20L);
} }

View File

@ -25,6 +25,7 @@ import org.bukkit.generator.BlockPopulator;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class CleanroomBlockPopulator extends BlockPopulator public class CleanroomBlockPopulator extends BlockPopulator
{ {
byte[] layerDataValues; byte[] layerDataValues;
protected CleanroomBlockPopulator(byte[] layerDataValues) protected CleanroomBlockPopulator(byte[] layerDataValues)

View File

@ -5,8 +5,8 @@
clean_threshold_hours: 168 clean_threshold_hours: 168
admins: admins:
b3c3b05a-a52d-33a6-a9c6-6e5063e00f0a: f9a1982e-252e-4ed3-92ed-52b0506a39c9:
last_login_name: DarthSalamon last_login_name: Prozza
is_activated: true is_activated: true
is_senior_admin: true is_senior_admin: true
is_telnet_admin: true is_telnet_admin: true