From 848f103afa04a4288193810734a9251ce704dd39 Mon Sep 17 00:00:00 2001 From: JeromSar Date: Mon, 19 Oct 2015 19:43:46 +0200 Subject: [PATCH] [Bleeding] TotalFreedomMod 5.0 Mass Refractoring, now uses me.totalfreedom.totalfreedommod as package Uses Aero https://github.com/Pravian/Aero Revamped command system Remove all TFM_ prefixes Revamp rank system Use new service based system Cleanup --- nbproject/project.properties | 6 +- .../TotalFreedomMod/Commands/AdminLevel.java | 18 - .../Commands/Command_moblimiter.java | 82 --- .../Commands/Command_nether.java | 18 - .../Commands/Command_opme.java | 21 - .../TotalFreedomMod/Commands/Command_rd.java | 20 - .../Commands/Command_services.java | 29 - .../Commands/Command_setspawnworld.java | 30 - .../Commands/Command_uuid.java | 114 --- .../TotalFreedomMod/Commands/TFM_Command.java | 190 ----- .../Commands/TFM_CommandHandler.java | 81 --- .../Commands/TFM_CommandLoader.java | 336 --------- .../TotalFreedomMod/HTTPD/Module_help.java | 155 ---- .../TotalFreedomMod/HTTPD/Module_list.java | 72 -- .../TotalFreedomMod/HTTPD/Module_players.java | 86 --- .../Listener/TFM_ServerListener.java | 62 -- .../TotalFreedomMod/SQL/TFM_SqlUtil.java | 102 --- .../SQL/TFM_SqliteDatabase.java | 143 ---- .../TotalFreedomMod/TFM_Admin.java | 163 ----- .../TotalFreedomMod/TFM_AdminList.java | 688 ------------------ .../TotalFreedomMod/TFM_Announcer.java | 112 --- .../StevenLawson/TotalFreedomMod/TFM_Ban.java | 209 ------ .../TotalFreedomMod/TFM_BanManager.java | 298 -------- .../TotalFreedomMod/TFM_CommandBlocker.java | 339 --------- .../TotalFreedomMod/TFM_Heartbeat.java | 88 --- .../TotalFreedomMod/TFM_PermbanList.java | 60 -- .../TotalFreedomMod/TFM_Player.java | 129 ---- .../TotalFreedomMod/TFM_PlayerList.java | 200 ----- .../TotalFreedomMod/TFM_PlayerRank.java | 121 --- .../TotalFreedomMod/TFM_RollbackManager.java | 315 -------- .../TotalFreedomMod/TFM_UuidManager.java | 310 -------- .../TotalFreedomMod/TotalFreedomMod.java | 250 ------- src/me/husky/Database.java | 56 -- src/me/husky/mysql/MySQL.java | 168 ----- src/me/husky/sqlite/SQLite.java | 105 --- .../totalfreedommod/Announcer.java | 93 +++ .../totalfreedommod/FrontDoor.java} | 263 ++++--- .../totalfreedommod/GameRuleHandler.java} | 50 +- .../totalfreedommod/Heartbeat.java | 100 +++ .../totalfreedommod/Jumppads.java} | 75 +- .../totalfreedommod/PermbanList.java | 45 ++ .../totalfreedommod/ProtectArea.java} | 161 ++-- .../totalfreedommod/ServerInterface.java} | 116 +-- .../totalfreedommod/ServiceChecker.java} | 131 ++-- .../totalfreedommod/TotalFreedomMod.java | 257 +++++++ .../totalfreedommod/TwitterHandler.java} | 36 +- .../totalfreedommod/admin/Admin.java | 145 ++++ .../totalfreedommod/admin/AdminList.java | 411 +++++++++++ .../totalfreedommod/banning/BanManager.java | 255 +++++++ .../totalfreedommod/banning/FBan.java | 260 +++++++ .../bridge/BukkitTelnetBridge.java} | 47 +- .../bridge/EssentialsBridge.java} | 53 +- .../bridge/WorldEditBridge.java} | 42 +- .../bridge/WorldEditListener.java} | 24 +- .../commandblocker/CommandBlocker.java | 192 +++++ .../commandblocker/CommandBlockerAction.java | 31 + .../commandblocker/CommandBlockerEntry.java | 53 ++ .../commandblocker/CommandBlockerRank.java | 72 ++ .../commands/CommandLoader.java | 40 + .../commands}/CommandParameters.java | 2 +- .../commands}/CommandPermissions.java | 5 +- .../commands}/Command_adminmode.java | 88 +-- .../commands}/Command_adminworld.java | 52 +- .../commands}/Command_blockcmd.java | 24 +- .../commands}/Command_cage.java | 35 +- .../commands}/Command_cake.java | 11 +- .../commands}/Command_cartsit.java | 13 +- .../commands}/Command_cbtool.java | 19 +- .../commands}/Command_cmdlist.java | 7 +- .../commands}/Command_cmdspy.java | 11 +- .../commands}/Command_colorme.java | 17 +- .../commands}/Command_creative.java | 20 +- .../commands}/Command_csay.java | 11 +- .../commands}/Command_deafen.java | 7 +- .../commands}/Command_debug.java | 7 +- .../commands}/Command_denick.java | 15 +- .../commands}/Command_deop.java | 89 +-- .../commands}/Command_deopall.java | 13 +- .../commands}/Command_dispfill.java | 15 +- .../commands}/Command_doom.java | 57 +- .../commands}/Command_enchant.java | 11 +- .../commands}/Command_ender.java | 11 +- .../commands}/Command_expel.java | 11 +- .../commands}/Command_findip.java | 12 +- .../commands}/Command_flatlands.java | 14 +- .../totalfreedommod/commands}/Command_fr.java | 27 +- .../commands}/Command_fuckoff.java | 10 +- .../commands}/Command_gadmin.java | 52 +- .../commands}/Command_gcmd.java | 13 +- .../commands}/Command_glist.java | 240 +++--- .../commands}/Command_gtfo.java | 54 +- .../commands}/Command_halt.java | 37 +- .../commands}/Command_health.java | 13 +- .../commands}/Command_invis.java | 15 +- .../commands}/Command_jumppads.java | 39 +- .../commands}/Command_kicknoob.java | 15 +- .../commands}/Command_landmine.java | 13 +- .../commands}/Command_lastcmd.java | 13 +- .../commands}/Command_list.java | 19 +- .../commands}/Command_localspawn.java | 7 +- .../commands}/Command_lockup.java | 29 +- .../commands}/Command_logs.java | 25 +- .../commands/Command_moblimiter.java | 83 +++ .../totalfreedommod/commands}/Command_mp.java | 7 +- .../commands}/Command_mp44.java | 15 +- .../commands/Command_nether.java | 19 + .../totalfreedommod/commands}/Command_nf.java | 241 +++--- .../commands}/Command_nickclean.java | 16 +- .../commands}/Command_nicknyan.java | 19 +- .../totalfreedommod/commands}/Command_o.java | 15 +- .../commands}/Command_onlinemode.java | 31 +- .../totalfreedommod/commands}/Command_op.java | 119 +-- .../commands}/Command_opall.java | 13 +- .../commands/Command_opme.java | 22 + .../commands}/Command_ops.java | 131 ++-- .../commands}/Command_orbit.java | 17 +- .../commands}/Command_overlord.java | 29 +- .../commands}/Command_permban.java | 16 +- .../commands}/Command_plugincontrol.java | 8 +- .../commands}/Command_potion.java | 25 +- .../commands}/Command_premium.java | 11 +- .../commands}/Command_protectarea.java | 29 +- .../commands}/Command_purgeall.java | 17 +- .../commands}/Command_qdeop.java | 13 +- .../commands}/Command_qop.java | 13 +- .../commands}/Command_radar.java | 7 +- .../commands}/Command_rank.java | 96 +-- .../commands}/Command_rawsay.java | 11 +- .../totalfreedommod/commands/Command_rd.java | 21 + .../commands}/Command_report.java | 15 +- .../totalfreedommod/commands}/Command_ro.java | 28 +- .../commands}/Command_rollback.java | 32 +- .../commands}/Command_saconfig.java | 165 +++-- .../commands}/Command_say.java | 15 +- .../commands/Command_services.java | 29 + .../commands}/Command_setl.java | 14 +- .../commands}/Command_setlevel.java | 7 +- .../commands}/Command_setlever.java | 13 +- .../commands/Command_setspawnworld.java | 30 + .../commands}/Command_smite.java | 13 +- .../commands}/Command_status.java | 7 +- .../commands}/Command_stfu.java | 231 +++--- .../commands}/Command_stop.java | 11 +- .../commands}/Command_survival.java | 21 +- .../commands}/Command_tag.java | 39 +- .../commands}/Command_tagnyan.java | 17 +- .../commands}/Command_tban.java | 23 +- .../commands}/Command_tempban.java | 154 ++-- .../commands}/Command_tfbanlist.java | 23 +- .../commands}/Command_tfipbanlist.java | 23 +- .../commands}/Command_tfm.java | 37 +- .../commands}/Command_tfupdate.java | 19 +- .../commands}/Command_toggle.java | 60 +- .../commands}/Command_tossmob.java | 21 +- .../commands}/Command_trail.java | 13 +- .../commands}/Command_twitter.java | 25 +- .../commands}/Command_warn.java | 15 +- .../commands}/Command_whitelist.java | 40 +- .../commands}/Command_whohas.java | 15 +- .../commands}/Command_wildcard.java | 12 +- .../commands}/Command_wipeflatlands.java | 13 +- .../commands}/Command_wipeuserdata.java | 14 +- .../commands/FreedomCommand.java | 129 ++++ .../commands/FreedomCommandExecutor.java | 160 ++++ .../totalfreedommod/commands}/SourceType.java | 2 +- .../config/ConfigConverter.java | 34 + .../totalfreedommod/config/ConfigEntry.java} | 28 +- .../totalfreedommod/config/FConfig.java} | 14 +- .../totalfreedommod/config/MainConfig.java} | 80 +- .../httpd}/HTMLGenerationTools.java | 2 +- .../totalfreedommod/httpd/HTTPDModule.java} | 18 +- .../httpd/HTTPDPageBuilder.java} | 10 +- .../totalfreedommod/httpd/HTTPDaemon.java} | 59 +- .../totalfreedommod/httpd}/Module_dump.java | 14 +- .../totalfreedommod/httpd}/Module_file.java | 12 +- .../totalfreedommod/httpd/Module_help.java | 157 ++++ .../totalfreedommod/httpd/Module_list.java | 42 ++ .../totalfreedommod/httpd}/Module_logs.java | 7 +- .../httpd}/Module_permbans.java | 8 +- .../totalfreedommod/httpd/Module_players.java | 68 ++ .../httpd}/Module_schematic.java | 22 +- .../totalfreedommod/httpd}/NanoHTTPD.java | 14 +- .../listener/BlockListener.java} | 118 ++- .../listener/EntityListener.java} | 43 +- .../listener/PlayerListener.java} | 279 +++---- .../listener/ServerListener.java | 61 ++ .../listener/WeatherListener.java} | 20 +- .../permission/ConsoleRank.java | 97 +++ .../permission/CustomLoginRank.java | 19 + .../permission/PlayerRank.java | 99 +++ .../totalfreedommod/permission/Rank.java | 26 + .../permission/RankManager.java | 93 +++ .../totalfreedommod/permission/RankProxy.java | 71 ++ .../totalfreedommod/permission/TitleRank.java | 74 ++ .../totalfreedommod/player/FPlayer.java} | 131 ++-- .../totalfreedommod/player/PlayerData.java | 77 ++ .../totalfreedommod/player/PlayerList.java | 222 ++++++ .../totalfreedommod/rollback/EntryType.java | 19 + .../rollback/RollbackEntry.java | 97 +++ .../rollback/RollbackManager.java | 235 ++++++ .../util/DepreciationAggregator.java} | 4 +- .../totalfreedommod/util/FLog.java} | 214 +++--- .../totalfreedommod/util/FSync.java} | 13 +- .../totalfreedommod/util/FUtil.java} | 137 ++-- .../world}/CleanroomBlockPopulator.java | 122 ++-- .../world}/CleanroomChunkGenerator.java | 2 +- .../world}/TFM_AdminWorld.java | 149 +--- .../world}/TFM_CustomWorld.java | 46 +- .../totalfreedommod/world}/TFM_Flatlands.java | 46 +- .../world/TFM_WorldManager.java | 37 + .../totalfreedommod/world/WorldTime.java | 55 ++ .../totalfreedommod/world/WorldWeather.java | 42 ++ src/plugin.yml | 4 +- 213 files changed, 6972 insertions(+), 8124 deletions(-) delete mode 100644 src/me/StevenLawson/TotalFreedomMod/Commands/AdminLevel.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/Commands/Command_moblimiter.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/Commands/Command_nether.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/Commands/Command_opme.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/Commands/Command_rd.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/Commands/Command_services.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/Commands/Command_setspawnworld.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/Commands/Command_uuid.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/Commands/TFM_Command.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/Commands/TFM_CommandHandler.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/Commands/TFM_CommandLoader.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_help.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_list.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_players.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/Listener/TFM_ServerListener.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/SQL/TFM_SqlUtil.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/SQL/TFM_SqliteDatabase.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/TFM_Admin.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/TFM_AdminList.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/TFM_Announcer.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/TFM_Ban.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/TFM_BanManager.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/TFM_CommandBlocker.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/TFM_Heartbeat.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/TFM_PermbanList.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/TFM_Player.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/TFM_PlayerList.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/TFM_PlayerRank.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/TFM_RollbackManager.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/TFM_UuidManager.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java delete mode 100644 src/me/husky/Database.java delete mode 100644 src/me/husky/mysql/MySQL.java delete mode 100644 src/me/husky/sqlite/SQLite.java create mode 100644 src/me/totalfreedom/totalfreedommod/Announcer.java rename src/me/{StevenLawson/TotalFreedomMod/TFM_FrontDoor.java => totalfreedom/totalfreedommod/FrontDoor.java} (59%) rename src/me/{StevenLawson/TotalFreedomMod/TFM_GameRuleHandler.java => totalfreedom/totalfreedommod/GameRuleHandler.java} (62%) create mode 100644 src/me/totalfreedom/totalfreedommod/Heartbeat.java rename src/me/{StevenLawson/TotalFreedomMod/TFM_Jumppads.java => totalfreedom/totalfreedommod/Jumppads.java} (71%) create mode 100644 src/me/totalfreedom/totalfreedommod/PermbanList.java rename src/me/{StevenLawson/TotalFreedomMod/TFM_ProtectedArea.java => totalfreedom/totalfreedommod/ProtectArea.java} (73%) rename src/me/{StevenLawson/TotalFreedomMod/TFM_ServerInterface.java => totalfreedom/totalfreedommod/ServerInterface.java} (68%) rename src/me/{StevenLawson/TotalFreedomMod/TFM_ServiceChecker.java => totalfreedom/totalfreedommod/ServiceChecker.java} (73%) create mode 100644 src/me/totalfreedom/totalfreedommod/TotalFreedomMod.java rename src/me/{StevenLawson/TotalFreedomMod/TFM_TwitterHandler.java => totalfreedom/totalfreedommod/TwitterHandler.java} (58%) create mode 100644 src/me/totalfreedom/totalfreedommod/admin/Admin.java create mode 100644 src/me/totalfreedom/totalfreedommod/admin/AdminList.java create mode 100644 src/me/totalfreedom/totalfreedommod/banning/BanManager.java create mode 100644 src/me/totalfreedom/totalfreedommod/banning/FBan.java rename src/me/{StevenLawson/TotalFreedomMod/Bridge/TFM_BukkitTelnetListener.java => totalfreedom/totalfreedommod/bridge/BukkitTelnetBridge.java} (59%) rename src/me/{StevenLawson/TotalFreedomMod/Bridge/TFM_EssentialsBridge.java => totalfreedom/totalfreedommod/bridge/EssentialsBridge.java} (65%) rename src/me/{StevenLawson/TotalFreedomMod/Bridge/TFM_WorldEditBridge.java => totalfreedom/totalfreedommod/bridge/WorldEditBridge.java} (71%) rename src/me/{StevenLawson/TotalFreedomMod/Bridge/TFM_WorldEditListener.java => totalfreedom/totalfreedommod/bridge/WorldEditListener.java} (67%) create mode 100644 src/me/totalfreedom/totalfreedommod/commandblocker/CommandBlocker.java create mode 100644 src/me/totalfreedom/totalfreedommod/commandblocker/CommandBlockerAction.java create mode 100644 src/me/totalfreedom/totalfreedommod/commandblocker/CommandBlockerEntry.java create mode 100644 src/me/totalfreedom/totalfreedommod/commandblocker/CommandBlockerRank.java create mode 100644 src/me/totalfreedom/totalfreedommod/commands/CommandLoader.java rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/CommandParameters.java (84%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/CommandPermissions.java (63%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_adminmode.java (52%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_adminworld.java (77%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_blockcmd.java (63%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_cage.java (69%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_cake.java (84%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_cartsit.java (85%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_cbtool.java (90%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_cmdlist.java (86%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_cmdspy.java (60%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_colorme.java (70%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_creative.java (73%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_csay.java (55%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_deafen.java (85%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_debug.java (93%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_denick.java (51%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_deop.java (62%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_deopall.java (51%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_dispfill.java (87%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_doom.java (57%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_enchant.java (89%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_ender.java (50%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_expel.java (87%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_findip.java (62%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_flatlands.java (53%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_fr.java (68%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_fuckoff.java (81%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_gadmin.java (72%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_gcmd.java (73%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_glist.java (53%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_gtfo.java (55%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_halt.java (64%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_health.java (89%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_invis.java (76%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_jumppads.java (55%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_kicknoob.java (55%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_landmine.java (86%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_lastcmd.java (69%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_list.java (81%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_localspawn.java (71%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_lockup.java (73%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_logs.java (86%) create mode 100644 src/me/totalfreedom/totalfreedommod/commands/Command_moblimiter.java rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_mp.java (83%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_mp44.java (73%) create mode 100644 src/me/totalfreedom/totalfreedommod/commands/Command_nether.java rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_nf.java (89%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_nickclean.java (74%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_nicknyan.java (73%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_o.java (66%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_onlinemode.java (62%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_op.java (68%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_opall.java (72%) create mode 100644 src/me/totalfreedom/totalfreedommod/commands/Command_opme.java rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_ops.java (69%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_orbit.java (72%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_overlord.java (62%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_permban.java (58%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_plugincontrol.java (94%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_potion.java (87%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_premium.java (86%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_protectarea.java (73%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_purgeall.java (77%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_qdeop.java (75%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_qop.java (76%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_radar.java (92%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_rank.java (56%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_rawsay.java (56%) create mode 100644 src/me/totalfreedom/totalfreedommod/commands/Command_rd.java rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_report.java (75%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_ro.java (69%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_rollback.java (56%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_saconfig.java (53%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_say.java (65%) create mode 100644 src/me/totalfreedom/totalfreedommod/commands/Command_services.java rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_setl.java (51%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_setlevel.java (82%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_setlever.java (78%) create mode 100644 src/me/totalfreedom/totalfreedommod/commands/Command_setspawnworld.java rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_smite.java (77%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_status.java (86%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_stfu.java (65%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_stop.java (62%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_survival.java (72%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_tag.java (76%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_tagnyan.java (56%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_tban.java (54%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_tempban.java (67%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_tfbanlist.java (60%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_tfipbanlist.java (60%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_tfm.java (63%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_tfupdate.java (72%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_toggle.java (54%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_tossmob.java (79%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_trail.java (88%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_twitter.java (82%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_warn.java (74%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_whitelist.java (69%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_whohas.java (77%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_wildcard.java (81%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_wipeflatlands.java (58%) rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/Command_wipeuserdata.java (54%) create mode 100644 src/me/totalfreedom/totalfreedommod/commands/FreedomCommand.java create mode 100644 src/me/totalfreedom/totalfreedommod/commands/FreedomCommandExecutor.java rename src/me/{StevenLawson/TotalFreedomMod/Commands => totalfreedom/totalfreedommod/commands}/SourceType.java (56%) create mode 100644 src/me/totalfreedom/totalfreedommod/config/ConfigConverter.java rename src/me/{StevenLawson/TotalFreedomMod/Config/TFM_ConfigEntry.java => totalfreedom/totalfreedommod/config/ConfigEntry.java} (88%) rename src/me/{StevenLawson/TotalFreedomMod/Config/TFM_Config.java => totalfreedom/totalfreedommod/config/FConfig.java} (90%) rename src/me/{StevenLawson/TotalFreedomMod/Config/TFM_MainConfig.java => totalfreedom/totalfreedommod/config/MainConfig.java} (71%) rename src/me/{StevenLawson/TotalFreedomMod/HTTPD => totalfreedom/totalfreedommod/httpd}/HTMLGenerationTools.java (96%) rename src/me/{StevenLawson/TotalFreedomMod/HTTPD/TFM_HTTPD_Module.java => totalfreedom/totalfreedommod/httpd/HTTPDModule.java} (69%) rename src/me/{StevenLawson/TotalFreedomMod/HTTPD/TFM_HTTPD_PageBuilder.java => totalfreedom/totalfreedommod/httpd/HTTPDPageBuilder.java} (87%) rename src/me/{StevenLawson/TotalFreedomMod/HTTPD/TFM_HTTPD_Manager.java => totalfreedom/totalfreedommod/httpd/HTTPDaemon.java} (83%) rename src/me/{StevenLawson/TotalFreedomMod/HTTPD => totalfreedom/totalfreedommod/httpd}/Module_dump.java (88%) rename src/me/{StevenLawson/TotalFreedomMod/HTTPD => totalfreedom/totalfreedommod/httpd}/Module_file.java (97%) create mode 100644 src/me/totalfreedom/totalfreedommod/httpd/Module_help.java create mode 100644 src/me/totalfreedom/totalfreedommod/httpd/Module_list.java rename src/me/{StevenLawson/TotalFreedomMod/HTTPD => totalfreedom/totalfreedommod/httpd}/Module_logs.java (71%) rename src/me/{StevenLawson/TotalFreedomMod/HTTPD => totalfreedom/totalfreedommod/httpd}/Module_permbans.java (66%) create mode 100644 src/me/totalfreedom/totalfreedommod/httpd/Module_players.java rename src/me/{StevenLawson/TotalFreedomMod/HTTPD => totalfreedom/totalfreedommod/httpd}/Module_schematic.java (93%) rename src/me/{StevenLawson/TotalFreedomMod/HTTPD => totalfreedom/totalfreedommod/httpd}/NanoHTTPD.java (99%) rename src/me/{StevenLawson/TotalFreedomMod/Listener/TFM_BlockListener.java => totalfreedom/totalfreedommod/listener/BlockListener.java} (59%) rename src/me/{StevenLawson/TotalFreedomMod/Listener/TFM_EntityListener.java => totalfreedom/totalfreedommod/listener/EntityListener.java} (76%) rename src/me/{StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java => totalfreedom/totalfreedommod/listener/PlayerListener.java} (70%) create mode 100644 src/me/totalfreedom/totalfreedommod/listener/ServerListener.java rename src/me/{StevenLawson/TotalFreedomMod/Listener/TFM_WeatherListener.java => totalfreedom/totalfreedommod/listener/WeatherListener.java} (52%) create mode 100644 src/me/totalfreedom/totalfreedommod/permission/ConsoleRank.java create mode 100644 src/me/totalfreedom/totalfreedommod/permission/CustomLoginRank.java create mode 100644 src/me/totalfreedom/totalfreedommod/permission/PlayerRank.java create mode 100644 src/me/totalfreedom/totalfreedommod/permission/Rank.java create mode 100644 src/me/totalfreedom/totalfreedommod/permission/RankManager.java create mode 100644 src/me/totalfreedom/totalfreedommod/permission/RankProxy.java create mode 100644 src/me/totalfreedom/totalfreedommod/permission/TitleRank.java rename src/me/{StevenLawson/TotalFreedomMod/TFM_PlayerData.java => totalfreedom/totalfreedommod/player/FPlayer.java} (80%) create mode 100644 src/me/totalfreedom/totalfreedommod/player/PlayerData.java create mode 100644 src/me/totalfreedom/totalfreedommod/player/PlayerList.java create mode 100644 src/me/totalfreedom/totalfreedommod/rollback/EntryType.java create mode 100644 src/me/totalfreedom/totalfreedommod/rollback/RollbackEntry.java create mode 100644 src/me/totalfreedom/totalfreedommod/rollback/RollbackManager.java rename src/me/{StevenLawson/TotalFreedomMod/TFM_DepreciationAggregator.java => totalfreedom/totalfreedommod/util/DepreciationAggregator.java} (94%) rename src/me/{StevenLawson/TotalFreedomMod/TFM_Log.java => totalfreedom/totalfreedommod/util/FLog.java} (92%) rename src/me/{StevenLawson/TotalFreedomMod/TFM_Sync.java => totalfreedom/totalfreedommod/util/FSync.java} (81%) rename src/me/{StevenLawson/TotalFreedomMod/TFM_Util.java => totalfreedom/totalfreedommod/util/FUtil.java} (86%) rename src/me/{StevenLawson/TotalFreedomMod/World => totalfreedom/totalfreedommod/world}/CleanroomBlockPopulator.java (94%) rename src/me/{StevenLawson/TotalFreedomMod/World => totalfreedom/totalfreedommod/world}/CleanroomChunkGenerator.java (99%) rename src/me/{StevenLawson/TotalFreedomMod/World => totalfreedom/totalfreedommod/world}/TFM_AdminWorld.java (61%) rename src/me/{StevenLawson/TotalFreedomMod/World => totalfreedom/totalfreedommod/world}/TFM_CustomWorld.java (53%) rename src/me/{StevenLawson/TotalFreedomMod/World => totalfreedom/totalfreedommod/world}/TFM_Flatlands.java (58%) create mode 100644 src/me/totalfreedom/totalfreedommod/world/TFM_WorldManager.java create mode 100644 src/me/totalfreedom/totalfreedommod/world/WorldTime.java create mode 100644 src/me/totalfreedom/totalfreedommod/world/WorldWeather.java diff --git a/nbproject/project.properties b/nbproject/project.properties index 2acc249d..d0203a4e 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,5 +1,5 @@ annotation.processing.enabled=true -annotation.processing.enabled.in.editor=false +annotation.processing.enabled.in.editor=true annotation.processing.processors.list= annotation.processing.run.all.processors=true annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output @@ -51,7 +51,9 @@ javac.classpath=\ ${libs.SpigotServer.classpath}:\ ${libs.TF-Essentials.classpath}:\ ${libs.TF-WorldEdit.classpath}:\ - ${libs.BukkitTelnet.classpath} + ${libs.BukkitTelnet.classpath}:\ + ${libs.Aero.classpath}:\ + ${libs.Lombok.classpath} # Space-separated list of extra javac options javac.compilerargs=-Xlint:unchecked -Xlint:deprecation javac.deprecation=false diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/AdminLevel.java b/src/me/StevenLawson/TotalFreedomMod/Commands/AdminLevel.java deleted file mode 100644 index 19c29760..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/AdminLevel.java +++ /dev/null @@ -1,18 +0,0 @@ -package me.StevenLawson.TotalFreedomMod.Commands; - -public enum AdminLevel -{ - ALL("All Player Commands"), OP("OP Commands"), SUPER("SuperAdmin Commands"), SENIOR("Senior Admin Commands"); - // - private final String friendlyName; - - private AdminLevel(String friendlyName) - { - this.friendlyName = friendlyName; - } - - public String getFriendlyName() - { - return friendlyName; - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_moblimiter.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_moblimiter.java deleted file mode 100644 index 984c4e2d..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_moblimiter.java +++ /dev/null @@ -1,82 +0,0 @@ -package me.StevenLawson.TotalFreedomMod.Commands; - -import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; -import me.StevenLawson.TotalFreedomMod.TFM_GameRuleHandler; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_CONSOLE) -@CommandParameters(description = "Control mob rezzing parameters.", usage = "/ |dragon|giant|ghast|slime>") -public class Command_moblimiter extends TFM_Command -{ - @Override - public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { - if (args.length < 1) - { - return false; - } - - if (args[0].equalsIgnoreCase("on")) - { - TFM_ConfigEntry.MOB_LIMITER_ENABLED.setBoolean(true); - } - else if (args[0].equalsIgnoreCase("off")) - { - TFM_ConfigEntry.MOB_LIMITER_ENABLED.setBoolean(false); - } - else if (args[0].equalsIgnoreCase("dragon")) - { - TFM_ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.setBoolean(!TFM_ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.getBoolean()); - } - else if (args[0].equalsIgnoreCase("giant")) - { - TFM_ConfigEntry.MOB_LIMITER_DISABLE_GIANT.setBoolean(!TFM_ConfigEntry.MOB_LIMITER_DISABLE_GIANT.getBoolean()); - } - else if (args[0].equalsIgnoreCase("slime")) - { - TFM_ConfigEntry.MOB_LIMITER_DISABLE_SLIME.setBoolean(!TFM_ConfigEntry.MOB_LIMITER_DISABLE_SLIME.getBoolean()); - } - else if (args[0].equalsIgnoreCase("ghast")) - { - TFM_ConfigEntry.MOB_LIMITER_DISABLE_GHAST.setBoolean(!TFM_ConfigEntry.MOB_LIMITER_DISABLE_GHAST.getBoolean()); - } - else - { - if (args.length < 2) - { - return false; - } - - if (args[0].equalsIgnoreCase("setmax")) - { - try - { - TFM_ConfigEntry.MOB_LIMITER_MAX.setInteger(Math.max(0, Math.min(2000, Integer.parseInt(args[1])))); - } - catch (NumberFormatException nfex) - { - } - } - } - - if (TFM_ConfigEntry.MOB_LIMITER_ENABLED.getBoolean()) - { - sender.sendMessage("Moblimiter enabled. Maximum mobcount set to: " + TFM_ConfigEntry.MOB_LIMITER_MAX.getInteger() + "."); - - playerMsg("Dragon: " + (TFM_ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.getBoolean() ? "disabled" : "enabled") + "."); - playerMsg("Giant: " + (TFM_ConfigEntry.MOB_LIMITER_DISABLE_GIANT.getBoolean() ? "disabled" : "enabled") + "."); - playerMsg("Slime: " + (TFM_ConfigEntry.MOB_LIMITER_DISABLE_SLIME.getBoolean() ? "disabled" : "enabled") + "."); - playerMsg("Ghast: " + (TFM_ConfigEntry.MOB_LIMITER_DISABLE_GHAST.getBoolean() ? "disabled" : "enabled") + "."); - } - else - { - playerMsg("Moblimiter is disabled. No mob restrictions are in effect."); - } - - TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_MOB_SPAWNING, !TFM_ConfigEntry.MOB_LIMITER_ENABLED.getBoolean()); - - return true; - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_nether.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_nether.java deleted file mode 100644 index 0a0ad5d2..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_nether.java +++ /dev/null @@ -1,18 +0,0 @@ -package me.StevenLawson.TotalFreedomMod.Commands; - -import me.StevenLawson.TotalFreedomMod.TFM_Util; -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 = "Goto the nether.", usage = "/") -public class Command_nether extends TFM_Command -{ - @Override - public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { - TFM_Util.gotoWorld(sender_p, server.getWorlds().get(0).getName() + "_nether"); - return true; - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_opme.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_opme.java deleted file mode 100644 index 00839a62..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_opme.java +++ /dev/null @@ -1,21 +0,0 @@ -package me.StevenLawson.TotalFreedomMod.Commands; - -import me.StevenLawson.TotalFreedomMod.TFM_Util; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME) -@CommandParameters(description = "Automatically ops user.", usage = "/") -public class Command_opme extends TFM_Command -{ - @Override - public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { - TFM_Util.adminAction(sender.getName(), "Opping " + sender.getName(), false); - sender.setOp(true); - sender.sendMessage(TFM_Command.YOU_ARE_OP); - - return true; - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rd.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rd.java deleted file mode 100644 index ae61772e..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rd.java +++ /dev/null @@ -1,20 +0,0 @@ -package me.StevenLawson.TotalFreedomMod.Commands; - -import me.StevenLawson.TotalFreedomMod.TFM_Util; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH) -@CommandParameters(description = "Remove various server entities that may cause lag, such as dropped items, minecarts, and boats.", usage = "/ ") -public class Command_rd extends TFM_Command -{ - @Override - public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { - TFM_Util.adminAction(sender.getName(), "Removing all server entities.", true); - playerMsg((TFM_Util.TFM_EntityWiper.wipeEntities(true, true)) + " entities removed."); - - return true; - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_services.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_services.java deleted file mode 100644 index d44072dd..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_services.java +++ /dev/null @@ -1,29 +0,0 @@ -package me.StevenLawson.TotalFreedomMod.Commands; - -import me.StevenLawson.TotalFreedomMod.TFM_ServiceChecker; -import me.StevenLawson.TotalFreedomMod.TFM_ServiceChecker.ServiceStatus; -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.BOTH) -@CommandParameters(description = "Shows the status of all Mojang services", usage = "/") -public class Command_services extends TFM_Command -{ - - @Override - public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { - playerMsg("Mojang Services" + ChatColor.WHITE + ":", ChatColor.BLUE); - - for (ServiceStatus service : TFM_ServiceChecker.getAllStatuses()) - { - playerMsg(service.getFormattedStatus()); - } - playerMsg("Version" + ChatColor.WHITE + ": " + TFM_ServiceChecker.getVersion(), ChatColor.DARK_PURPLE); - playerMsg("Last Check" + ChatColor.WHITE + ": " + TFM_ServiceChecker.getLastCheck(), ChatColor.DARK_PURPLE); - - return true; - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_setspawnworld.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_setspawnworld.java deleted file mode 100644 index 199edf08..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_setspawnworld.java +++ /dev/null @@ -1,30 +0,0 @@ -package me.StevenLawson.TotalFreedomMod.Commands; - -import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; -import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea; -import me.StevenLawson.TotalFreedomMod.TFM_Util; -import org.bukkit.Location; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME) -@CommandParameters(description = "Set world spawnpoint.", usage = "/") -public class Command_setspawnworld extends TFM_Command -{ - @Override - public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { - Location pos = sender_p.getLocation(); - sender_p.getWorld().setSpawnLocation(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()); - - playerMsg("Spawn location for this world set to: " + TFM_Util.formatLocation(sender_p.getWorld().getSpawnLocation())); - - if (TFM_ConfigEntry.PROTECTAREA_ENABLED.getBoolean() && TFM_ConfigEntry.PROTECTAREA_SPAWNPOINTS.getBoolean()) - { - TFM_ProtectedArea.addProtectedArea("spawn_" + sender_p.getWorld().getName(), pos, TFM_ConfigEntry.PROTECTAREA_RADIUS.getDouble()); - } - - return true; - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_uuid.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_uuid.java deleted file mode 100644 index 2f88c557..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_uuid.java +++ /dev/null @@ -1,114 +0,0 @@ -package me.StevenLawson.TotalFreedomMod.Commands; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import me.StevenLawson.TotalFreedomMod.TFM_Admin; -import me.StevenLawson.TotalFreedomMod.TFM_AdminList; -import me.StevenLawson.TotalFreedomMod.TFM_Player; -import me.StevenLawson.TotalFreedomMod.TFM_PlayerList; -import me.StevenLawson.TotalFreedomMod.TFM_UuidManager; -import me.StevenLawson.TotalFreedomMod.TFM_UuidManager.TFM_UuidResolver; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE) -@CommandParameters(description = "Provides uuid tools", usage = "/ ") -public class Command_uuid extends TFM_Command -{ - @Override - public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { - if (args.length != 1) - { - return false; - } - - if ("purge".equals(args[0])) - { - playerMsg("Purged " + TFM_UuidManager.purge() + " cached UUIDs."); - return true; - } - - if ("recalculate".equals(args[0])) - { - playerMsg("Recalculating UUIDs..."); - - // Playerlist uuids - final Set players = TFM_PlayerList.getAllPlayers(); - final List names = new ArrayList(); - - for (TFM_Player player : players) - { - names.add(player.getLastLoginName()); - } - - final Map playerUuids = new TFM_UuidResolver(names).call(); - - int updated = 0; - for (String name : playerUuids.keySet()) - { - for (TFM_Player player : players) - { - if (!player.getLastLoginName().equalsIgnoreCase(name)) - { - continue; - } - - if (player.getUniqueId().equals(playerUuids.get(name))) - { - continue; - } - - TFM_PlayerList.setUniqueId(player, playerUuids.get(name)); - TFM_UuidManager.rawSetUUID(name, playerUuids.get(name)); - updated++; - break; - } - } - - playerMsg("Recalculated " + updated + " player UUIDs"); - names.clear(); - - // Adminlist UUIDs - final Set admins = TFM_AdminList.getAllAdmins(); - for (TFM_Admin admin : admins) - { - names.add(admin.getLastLoginName()); - } - - final Map adminUuids = new TFM_UuidResolver(names).call(); - - updated = 0; - for (String name : adminUuids.keySet()) - { - for (TFM_Admin admin : admins) - { - if (!admin.getLastLoginName().equalsIgnoreCase(name)) - { - continue; - } - - if (admin.getUniqueId().equals(adminUuids.get(name))) - { - continue; - } - - TFM_AdminList.setUuid(admin, admin.getUniqueId(), adminUuids.get(name)); - TFM_UuidManager.rawSetUUID(name, adminUuids.get(name)); - updated++; - break; - } - } - - playerMsg("Recalculated " + updated + " admin UUIDs"); - - return true; - } - - return false; - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_Command.java b/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_Command.java deleted file mode 100644 index 4fc71707..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_Command.java +++ /dev/null @@ -1,190 +0,0 @@ -package me.StevenLawson.TotalFreedomMod.Commands; - -import java.util.Collection; -import me.StevenLawson.TotalFreedomMod.TFM_AdminList; -import me.StevenLawson.TotalFreedomMod.TFM_Log; -import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; -import me.StevenLawson.TotalFreedomMod.TFM_Util; -import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; -import org.bukkit.ChatColor; -import org.bukkit.Server; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public abstract class TFM_Command -{ - public static final String MSG_NO_PERMS = ChatColor.YELLOW + "You do not have permission to use this command."; - public static final String YOU_ARE_OP = ChatColor.YELLOW + "You are now op!"; - public static final String YOU_ARE_NOT_OP = ChatColor.YELLOW + "You are no longer op!"; - public static final String NOT_FROM_CONSOLE = "This command may not be used from the console."; - public static final String PLAYER_NOT_FOUND = ChatColor.GRAY + "Player not found!"; - protected TotalFreedomMod plugin; - protected Server server; - private CommandSender commandSender; - private Class commandClass; - - public TFM_Command() - { - } - - abstract public boolean run(final CommandSender sender, final Player sender_p, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole); - - public void setup(final TotalFreedomMod plugin, final CommandSender commandSender, final Class commandClass) - { - this.plugin = plugin; - this.server = plugin.getServer(); - this.commandSender = commandSender; - this.commandClass = commandClass; - } - - public void playerMsg(final CommandSender sender, final String message, final ChatColor color) - { - if (sender == null) - { - return; - } - sender.sendMessage(color + message); - } - - public void playerMsg(final String message, final ChatColor color) - { - playerMsg(commandSender, message, color); - } - - public void playerMsg(final CommandSender sender, final String message) - { - playerMsg(sender, message, ChatColor.GRAY); - } - - public void playerMsg(final String message) - { - playerMsg(commandSender, message); - } - - public boolean senderHasPermission() - { - final CommandPermissions permissions = commandClass.getAnnotation(CommandPermissions.class); - - if (permissions == null) - { - TFM_Log.warning(commandClass.getName() + " is missing permissions annotation."); - return true; - } - - boolean isSuper = TFM_AdminList.isSuperAdmin(commandSender); - boolean isSenior = false; - - if (isSuper) - { - isSenior = TFM_AdminList.isSeniorAdmin(commandSender); - } - - final AdminLevel level = permissions.level(); - final SourceType source = permissions.source(); - final boolean blockHostConsole = permissions.blockHostConsole(); - - if (!(commandSender instanceof Player)) - { - if (source == SourceType.ONLY_IN_GAME) - { - return false; - } - - if (level == AdminLevel.SENIOR && !isSenior) - { - return false; - } - - if (blockHostConsole && TFM_Util.isFromHostConsole(commandSender.getName())) - { - return false; - } - - return true; - } - - final Player senderPlayer = (Player) commandSender; - - if (source == SourceType.ONLY_CONSOLE) - { - return false; - } - - if (level == AdminLevel.SENIOR) - { - if (!isSenior) - { - return false; - } - - if (!TFM_PlayerData.getPlayerData(senderPlayer).isSuperadminIdVerified()) - { - return false; - } - - return true; - } - - if (level == AdminLevel.SUPER && !isSuper) - { - return false; - } - - if (level == AdminLevel.OP && !senderPlayer.isOp()) - { - return false; - } - - return true; - } - - public Player getPlayer(final String partialName) - { - return getPlayer(partialName, false); - } - - public Player getPlayer(final String partialName, final boolean exact) - { - if (partialName == null || partialName.isEmpty()) - { - return null; - } - - final Collection players = server.getOnlinePlayers(); - - // Check exact matches first. - for (final Player player : players) - { - if (partialName.equalsIgnoreCase(player.getName())) - { - return player; - } - } - - if (exact) - { - return null; - } - - // Then check partial matches in name. - for (final Player player : players) - { - if (player.getName().toLowerCase().contains(partialName.toLowerCase())) - { - return player; - } - } - - // Then check partial matches in display name. - for (final Player player : players) - { - if (player.getDisplayName().toLowerCase().contains(partialName.toLowerCase())) - { - return player; - } - } - - return null; - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_CommandHandler.java b/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_CommandHandler.java deleted file mode 100644 index afa4dfa1..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_CommandHandler.java +++ /dev/null @@ -1,81 +0,0 @@ -package me.StevenLawson.TotalFreedomMod.Commands; - -import me.StevenLawson.TotalFreedomMod.TFM_Log; -import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; -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; - -public class TFM_CommandHandler -{ - public static final String COMMAND_PATH = TFM_Command.class.getPackage().getName(); // "me.StevenLawson.TotalFreedomMod.Commands"; - public static final String COMMAND_PREFIX = "Command_"; - - public static boolean handleCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) - { - final Player playerSender; - final boolean senderIsConsole; - - if (sender instanceof Player) - { - senderIsConsole = false; - playerSender = (Player) sender; - - TFM_Log.info(String.format("[PLAYER_COMMAND] %s (%s): /%s %s", - playerSender.getName(), - ChatColor.stripColor(playerSender.getDisplayName()), - commandLabel, - StringUtils.join(args, " ")), true); - } - else - { - senderIsConsole = true; - playerSender = null; - - TFM_Log.info(String.format("[CONSOLE_COMMAND] %s: /%s %s", - sender.getName(), - commandLabel, - StringUtils.join(args, " ")), true); - } - - final TFM_Command dispatcher; - try - { - final ClassLoader classLoader = TotalFreedomMod.class.getClassLoader(); - dispatcher = (TFM_Command) classLoader.loadClass(String.format("%s.%s%s", - COMMAND_PATH, - COMMAND_PREFIX, - cmd.getName().toLowerCase())).newInstance(); - dispatcher.setup(TotalFreedomMod.plugin, sender, dispatcher.getClass()); - } - catch (Exception ex) - { - TFM_Log.severe("Could not load command: " + cmd.getName()); - TFM_Log.severe(ex); - - sender.sendMessage(ChatColor.RED + "Command Error! Could not load command: " + cmd.getName()); - return true; - } - - if (!dispatcher.senderHasPermission()) - { - sender.sendMessage(TFM_Command.MSG_NO_PERMS); - return true; - } - - try - { - return dispatcher.run(sender, playerSender, cmd, commandLabel, args, senderIsConsole); - } - catch (Exception ex) - { - TFM_Log.severe("Command Error: " + commandLabel); - TFM_Log.severe(ex); - sender.sendMessage(ChatColor.RED + "Command Error: " + ex.getMessage()); - } - - return true; - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_CommandLoader.java b/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_CommandLoader.java deleted file mode 100644 index dd16b767..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_CommandLoader.java +++ /dev/null @@ -1,336 +0,0 @@ -package me.StevenLawson.TotalFreedomMod.Commands; - -import java.io.IOException; -import java.security.CodeSource; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; -import me.StevenLawson.TotalFreedomMod.TFM_Log; -import me.StevenLawson.TotalFreedomMod.TFM_Util; -import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandException; -import org.bukkit.command.CommandMap; -import org.bukkit.command.CommandSender; -import org.bukkit.command.PluginIdentifiableCommand; -import org.bukkit.plugin.Plugin; - -public class TFM_CommandLoader -{ - public static final Pattern COMMAND_PATTERN; - private static final List COMMAND_LIST; - - static - { - COMMAND_PATTERN = Pattern.compile(TFM_CommandHandler.COMMAND_PATH.replace('.', '/') + "/(" + TFM_CommandHandler.COMMAND_PREFIX + "[^\\$]+)\\.class"); - COMMAND_LIST = new ArrayList(); - } - - private TFM_CommandLoader() - { - throw new AssertionError(); - } - - public static void scan() - { - CommandMap commandMap = getCommandMap(); - if (commandMap == null) - { - TFM_Log.severe("Error loading commandMap."); - return; - } - COMMAND_LIST.clear(); - COMMAND_LIST.addAll(getCommands()); - - for (TFM_CommandInfo commandInfo : COMMAND_LIST) - { - TFM_DynamicCommand dynamicCommand = new TFM_DynamicCommand(commandInfo); - - Command existing = commandMap.getCommand(dynamicCommand.getName()); - if (existing != null) - { - unregisterCommand(existing, commandMap); - } - - commandMap.register(TotalFreedomMod.plugin.getDescription().getName(), dynamicCommand); - } - - TFM_Log.info("TFM commands loaded."); - } - - public static void unregisterCommand(String commandName) - { - CommandMap commandMap = getCommandMap(); - if (commandMap != null) - { - Command command = commandMap.getCommand(commandName.toLowerCase()); - if (command != null) - { - unregisterCommand(command, commandMap); - } - } - } - - public static void unregisterCommand(Command command, CommandMap commandMap) - { - try - { - command.unregister(commandMap); - HashMap knownCommands = getKnownCommands(commandMap); - if (knownCommands != null) - { - knownCommands.remove(command.getName()); - for (String alias : command.getAliases()) - { - knownCommands.remove(alias); - } - } - } - catch (Exception ex) - { - TFM_Log.severe(ex); - } - } - - @SuppressWarnings("unchecked") - public static CommandMap getCommandMap() - { - final Object commandMap = TFM_Util.getField(Bukkit.getServer().getPluginManager(), "commandMap"); - if (commandMap != null) - { - if (commandMap instanceof CommandMap) - { - return (CommandMap) commandMap; - } - } - return null; - } - - @SuppressWarnings("unchecked") - public static HashMap getKnownCommands(CommandMap commandMap) - { - Object knownCommands = TFM_Util.getField(commandMap, "knownCommands"); - if (knownCommands != null) - { - if (knownCommands instanceof HashMap) - { - return (HashMap) knownCommands; - } - } - return null; - } - - private static List getCommands() - { - List commandList = new ArrayList(); - - try - { - CodeSource codeSource = TotalFreedomMod.class.getProtectionDomain().getCodeSource(); - if (codeSource != null) - { - ZipInputStream zip = new ZipInputStream(codeSource.getLocation().openStream()); - ZipEntry zipEntry; - while ((zipEntry = zip.getNextEntry()) != null) - { - String entryName = zipEntry.getName(); - Matcher matcher = COMMAND_PATTERN.matcher(entryName); - if (matcher.find()) - { - try - { - Class commandClass = Class.forName(TFM_CommandHandler.COMMAND_PATH + "." + matcher.group(1)); - - CommandPermissions commandPermissions = commandClass.getAnnotation(CommandPermissions.class); - CommandParameters commandParameters = commandClass.getAnnotation(CommandParameters.class); - - if (commandPermissions != null && commandParameters != null) - { - TFM_CommandInfo commandInfo = new TFM_CommandInfo( - commandClass, - matcher.group(1).split("_")[1], - commandPermissions.level(), - commandPermissions.source(), - commandPermissions.blockHostConsole(), - commandParameters.description(), - commandParameters.usage(), - commandParameters.aliases()); - - commandList.add(commandInfo); - } - } - catch (ClassNotFoundException ex) - { - TFM_Log.severe(ex); - } - } - } - } - } - catch (IOException ex) - { - TFM_Log.severe(ex); - } - - return commandList; - } - - public static class TFM_CommandInfo - { - private final String commandName; - private final Class commandClass; - private final AdminLevel level; - private final SourceType source; - private final boolean blockHostConsole; - private final String description; - private final String usage; - private final List aliases; - - public TFM_CommandInfo(Class commandClass, String commandName, AdminLevel level, SourceType source, boolean blockHostConsole, String description, String usage, String aliases) - { - this.commandName = commandName; - this.commandClass = commandClass; - this.level = level; - this.source = source; - this.blockHostConsole = blockHostConsole; - this.description = description; - this.usage = usage; - this.aliases = ("".equals(aliases) ? new ArrayList() : Arrays.asList(aliases.split(","))); - } - - public List getAliases() - { - return Collections.unmodifiableList(aliases); - } - - public Class getCommandClass() - { - return commandClass; - } - - public String getCommandName() - { - return commandName; - } - - public String getDescription() - { - return description; - } - - public String getDescriptionPermissioned() - { - String _description = description; - - switch (this.getLevel()) - { - case SENIOR: - _description = "Senior " + (this.getSource() == SourceType.ONLY_CONSOLE ? "Console" : "") + " Command - " + _description; - break; - case SUPER: - _description = "Superadmin Command - " + _description; - break; - case OP: - _description = "OP Command - " + _description; - break; - } - - return _description; - } - - public AdminLevel getLevel() - { - return level; - } - - public SourceType getSource() - { - return source; - } - - public String getUsage() - { - return usage; - } - - public boolean getBlockHostConsole() - { - return blockHostConsole; - } - - @Override - public String toString() - { - StringBuilder sb = new StringBuilder(); - sb.append("commandName: ").append(commandName); - sb.append("\ncommandClass: ").append(commandClass.getName()); - sb.append("\nlevel: ").append(level); - sb.append("\nsource: ").append(source); - sb.append("\nblock_host_console: ").append(blockHostConsole); - sb.append("\ndescription: ").append(description); - sb.append("\nusage: ").append(usage); - sb.append("\naliases: ").append(aliases); - return sb.toString(); - } - } - - public static class TFM_DynamicCommand extends Command implements PluginIdentifiableCommand - { - private final TFM_CommandInfo commandInfo; - - private TFM_DynamicCommand(TFM_CommandInfo commandInfo) - { - super(commandInfo.getCommandName(), commandInfo.getDescriptionPermissioned(), commandInfo.getUsage(), commandInfo.getAliases()); - - this.commandInfo = commandInfo; - } - - @Override - public boolean execute(CommandSender sender, String commandLabel, String[] args) - { - boolean success = false; - - if (!getPlugin().isEnabled()) - { - return false; - } - - try - { - success = getPlugin().onCommand(sender, this, commandLabel, args); - } - catch (Throwable ex) - { - throw new CommandException("Unhandled exception executing command '" + commandLabel + "' in plugin " + getPlugin().getDescription().getFullName(), ex); - } - - if (!success && getUsage().length() > 0) - { - for (String line : getUsage().replace("", commandLabel).split("\n")) - { - sender.sendMessage(line); - } - } - - return success; - } - - @Override - public Plugin getPlugin() - { - return TotalFreedomMod.plugin; - } - - public TFM_CommandInfo getCommandInfo() - { - return commandInfo; - } - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_help.java b/src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_help.java deleted file mode 100644 index 22c061a6..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_help.java +++ /dev/null @@ -1,155 +0,0 @@ -package me.StevenLawson.TotalFreedomMod.HTTPD; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import me.StevenLawson.TotalFreedomMod.Commands.AdminLevel; -import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader; -import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader.TFM_DynamicCommand; -import static me.StevenLawson.TotalFreedomMod.HTTPD.HTMLGenerationTools.heading; -import static me.StevenLawson.TotalFreedomMod.HTTPD.HTMLGenerationTools.paragraph; -import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4; -import org.apache.commons.lang3.StringUtils; -import org.bukkit.command.Command; -import org.bukkit.command.CommandMap; -import org.bukkit.command.PluginIdentifiableCommand; - -public class Module_help extends TFM_HTTPD_Module -{ - public Module_help(NanoHTTPD.HTTPSession session) - { - super(session); - } - - @Override - public String getBody() - { - StringBuilder responseBody = new StringBuilder(); - - CommandMap commandMap; - HashMap knownCommands; - if ((commandMap = TFM_CommandLoader.getCommandMap()) == null - || (knownCommands = TFM_CommandLoader.getKnownCommands(commandMap)) == null) - { - return paragraph("Error loading commands."); - } - - responseBody - .append(heading("Command Help", 1)) - .append(paragraph( - "This page is an automatically generated listing of all plugin commands that are currently live on the server. " - + "Please note that it does not include vanilla server commands.")); - - final Map> commandsByPlugin = new HashMap>(); - - final Iterator> itKnownCommands = knownCommands.entrySet().iterator(); - while (itKnownCommands.hasNext()) - { - final Map.Entry entry = itKnownCommands.next(); - final String name = entry.getKey(); - final Command command = entry.getValue(); - if (name.equalsIgnoreCase(command.getName())) - { - String pluginName = "Bukkit Default"; - if (command instanceof PluginIdentifiableCommand) - { - pluginName = ((PluginIdentifiableCommand) command).getPlugin().getName(); - } - List pluginCommands = commandsByPlugin.get(pluginName); - if (pluginCommands == null) - { - commandsByPlugin.put(pluginName, pluginCommands = new ArrayList()); - } - pluginCommands.add(command); - } - } - - final Iterator>> itCommandsByPlugin = commandsByPlugin.entrySet().iterator(); - while (itCommandsByPlugin.hasNext()) - { - final Map.Entry> entry = itCommandsByPlugin.next(); - final String pluginName = entry.getKey(); - final List commands = entry.getValue(); - - Collections.sort(commands, new Comparator() - { - @Override - public int compare(Command a, Command b) - { - if (a instanceof TFM_DynamicCommand && b instanceof TFM_DynamicCommand) - { - String aName = ((TFM_DynamicCommand) a).getCommandInfo().getLevel().name() + a.getName(); - String bName = ((TFM_DynamicCommand) b).getCommandInfo().getLevel().name() + b.getName(); - return aName.compareTo(bName); - } - return a.getName().compareTo(b.getName()); - } - }); - - responseBody.append(heading(pluginName, 2)).append("
    \r\n"); - - AdminLevel lastTfmCommandLevel = null; - for (Command command : commands) - { - if ("TotalFreedomMod".equals(pluginName)) - { - AdminLevel tfmCommandLevel = ((TFM_DynamicCommand) command).getCommandInfo().getLevel(); - if (lastTfmCommandLevel == null || lastTfmCommandLevel != tfmCommandLevel) - { - responseBody.append("
\r\n").append(heading(tfmCommandLevel.getFriendlyName(), 3)).append("
    \r\n"); - } - lastTfmCommandLevel = tfmCommandLevel; - } - responseBody.append(buildDescription(command)); - } - - responseBody.append("
\r\n"); - } - - return responseBody.toString(); - } - - private static String buildDescription(Command command) - { - StringBuilder sb = new StringBuilder(); - - sb.append( - "
  • {$CMD_NAME} - Usage: {$CMD_USAGE}" - .replace("{$CMD_NAME}", escapeHtml4(command.getName().trim())) - .replace("{$CMD_USAGE}", escapeHtml4(command.getUsage().trim()))); - - if (!command.getAliases().isEmpty()) - { - sb.append( - " - Aliases: {$CMD_ALIASES}" - .replace("{$CMD_ALIASES}", escapeHtml4(StringUtils.join(command.getAliases(), ", ")))); - } - - sb.append( - "
    {$CMD_DESC}
  • \r\n" - .replace("{$CMD_DESC}", escapeHtml4(command.getDescription().trim()))); - - return sb.toString(); - } - - @Override - public String getTitle() - { - return "TotalFreedomMod :: Command Help"; - } - - @Override - public String getStyle() - { - return ".commandName{font-weight:bold;}.commandDescription{padding-left:15px;}li{margin:.15em;padding:.15em;}"; - } -// @Override -// public String getScript() -// { -// return "$(document).ready(function(){console.log(\"Ready\");});"; -// } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_list.java b/src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_list.java deleted file mode 100644 index a7c4d6b1..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_list.java +++ /dev/null @@ -1,72 +0,0 @@ -package me.StevenLawson.TotalFreedomMod.HTTPD; - -import java.util.Collection; -import me.StevenLawson.TotalFreedomMod.TFM_AdminList; -import me.StevenLawson.TotalFreedomMod.TFM_Util; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -public class Module_list extends TFM_HTTPD_Module -{ - public Module_list(NanoHTTPD.HTTPSession session) - { - super(session); - } - - @Override - public String getBody() - { - final StringBuilder body = new StringBuilder(); - - final Collection onlinePlayers = Bukkit.getOnlinePlayers(); - - body.append("

    There are ").append(onlinePlayers.size()).append("/").append(Bukkit.getMaxPlayers()).append(" players online:

    \r\n"); - - body.append("
      \r\n"); - - for (Player player : onlinePlayers) - { - String prefix = ""; - if (TFM_AdminList.isSuperAdmin(player)) - { - if (TFM_AdminList.isSeniorAdmin(player)) - { - prefix = "[SrA]"; - } - else - { - prefix = "[SA]"; - } - - if (TFM_Util.DEVELOPERS.contains(player.getName())) - { - prefix = "[Dev]"; - } - - if (player.getName().equals("markbyron")) - { - prefix = "[Owner]"; - } - } - else - { - if (player.isOp()) - { - prefix = "[OP]"; - } - } - - body.append("
    • ").append(prefix).append(player.getName()).append("
    • \r\n"); - } - - body.append("
    \r\n"); - - return body.toString(); - } - - @Override - public String getTitle() - { - return "Total Freedom - Online Users"; - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_players.java b/src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_players.java deleted file mode 100644 index d39653ab..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_players.java +++ /dev/null @@ -1,86 +0,0 @@ -package me.StevenLawson.TotalFreedomMod.HTTPD; - -import java.util.UUID; -import me.StevenLawson.TotalFreedomMod.TFM_AdminList; -import me.StevenLawson.TotalFreedomMod.TFM_Util; -import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; -import org.bukkit.entity.Player; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; - -public class Module_players extends TFM_HTTPD_Module -{ - public Module_players(NanoHTTPD.HTTPSession session) - { - super(session); - } - - @Override - @SuppressWarnings("unchecked") - public NanoHTTPD.Response getResponse() - { - final JSONObject responseObject = new JSONObject(); - - final JSONArray players = new JSONArray(); - final JSONArray superadmins = new JSONArray(); - final JSONArray telnetadmins = new JSONArray(); - final JSONArray senioradmins = new JSONArray(); - final JSONArray developers = new JSONArray(); - - // All online players - for (Player player : TotalFreedomMod.server.getOnlinePlayers()) - { - players.add(player.getName()); - } - - // Super admins (non-telnet and non-senior) - for (UUID superadmin : TFM_AdminList.getSuperUUIDs()) - { - if (TFM_AdminList.getSeniorUUIDs().contains(superadmin)) - { - continue; - } - - if (TFM_AdminList.getTelnetUUIDs().contains(superadmin)) - { - continue; - } - - superadmins.add(getName(superadmin)); - } - - // Telnet admins (non-senior) - for (UUID telnetadmin : TFM_AdminList.getTelnetUUIDs()) - { - if (TFM_AdminList.getSeniorUUIDs().contains(telnetadmin)) - { - continue; - } - telnetadmins.add(getName(telnetadmin)); - } - - // Senior admins - for (UUID senioradmin : TFM_AdminList.getSeniorUUIDs()) - { - senioradmins.add(getName(senioradmin)); - } - - // Developers - developers.addAll(TFM_Util.DEVELOPERS); - - responseObject.put("players", players); - responseObject.put("superadmins", superadmins); - responseObject.put("telnetadmins", telnetadmins); - responseObject.put("senioradmins", senioradmins); - responseObject.put("developers", developers); - - final NanoHTTPD.Response response = new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, NanoHTTPD.MIME_JSON, responseObject.toString()); - response.addHeader("Access-Control-Allow-Origin", "*"); - return response; - } - - private String getName(UUID uuid) - { - return TFM_AdminList.getEntry(uuid).getLastLoginName(); - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_ServerListener.java b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_ServerListener.java deleted file mode 100644 index c5f2a587..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_ServerListener.java +++ /dev/null @@ -1,62 +0,0 @@ -package me.StevenLawson.TotalFreedomMod.Listener; - -import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; -import me.StevenLawson.TotalFreedomMod.TFM_BanManager; -import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface; -import me.StevenLawson.TotalFreedomMod.TFM_Util; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.server.ServerListPingEvent; - -public class TFM_ServerListener implements Listener -{ - @EventHandler(priority = EventPriority.HIGHEST) - public void onServerPing(ServerListPingEvent event) - { - final String ip = event.getAddress().getHostAddress(); - - if (TFM_BanManager.isIpBanned(ip)) - { - event.setMotd(ChatColor.RED + "You are banned."); - return; - } - - if (TFM_ConfigEntry.ADMIN_ONLY_MODE.getBoolean()) - { - event.setMotd(ChatColor.RED + "Server is closed."); - return; - } - - if (Bukkit.hasWhitelist()) - { - event.setMotd(ChatColor.RED + "Whitelist enabled."); - return; - } - - if (Bukkit.getOnlinePlayers().size() >= Bukkit.getMaxPlayers()) - { - event.setMotd(ChatColor.RED + "Server is full."); - return; - } - - if (!TFM_ConfigEntry.SERVER_COLORFUL_MOTD.getBoolean()) - { - event.setMotd(TFM_Util.colorize(TFM_ConfigEntry.SERVER_MOTD.getString() - .replace("%mcversion%", TFM_ServerInterface.getVersion()))); - return; - } - // Colorful MOTD - - final StringBuilder motd = new StringBuilder(); - - for (String word : TFM_ConfigEntry.SERVER_MOTD.getString().replace("%mcversion%", TFM_ServerInterface.getVersion()).split(" ")) - { - motd.append(TFM_Util.randomChatColor()).append(word).append(" "); - } - - event.setMotd(TFM_Util.colorize(motd.toString())); - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/SQL/TFM_SqlUtil.java b/src/me/StevenLawson/TotalFreedomMod/SQL/TFM_SqlUtil.java deleted file mode 100644 index ab5b7cdd..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/SQL/TFM_SqlUtil.java +++ /dev/null @@ -1,102 +0,0 @@ -package me.StevenLawson.TotalFreedomMod.SQL; - -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.ResultSet; -import java.sql.SQLException; -import me.StevenLawson.TotalFreedomMod.TFM_Log; - -public class TFM_SqlUtil -{ - - public static boolean hasTable(Connection con, String table) - { - try - { - final DatabaseMetaData dbm = con.getMetaData(); - final ResultSet tables = dbm.getTables(null, null, table, null); - return tables.next(); - } - catch (SQLException ex) - { - TFM_Log.severe(ex); - return false; - } - } - - public static ResultSet executeQuery(Connection con, String query) - { - try - { - return con.createStatement().executeQuery(query); - } - catch (SQLException ex) - { - TFM_Log.severe(ex); - return null; - } - } - - public static int updateQuery(Connection con, String query) - { - try - { - return con.createStatement().executeUpdate(query); - } - catch (SQLException ex) - { - TFM_Log.severe(ex); - return -1; - } - } - - public static boolean createTable(Connection con, String name, String fields) - { - try - { - con.createStatement().execute("CREATE TABLE " + name + " (" + fields + ");"); - return true; - } - catch (SQLException ex) - { - TFM_Log.severe(ex); - return false; - } - } - - public static void close(ResultSet result) - { - if (result == null) - { - return; - } - - try - { - result.close(); - } - catch (SQLException ex) - { - TFM_Log.severe(ex); - } - } - - public static boolean hasData(ResultSet result) - { - if (result == null) - { - return false; - } - - try - { - return result.next(); - } - catch (SQLException ex) - { - TFM_Log.severe(ex); - return false; - } - } - -} diff --git a/src/me/StevenLawson/TotalFreedomMod/SQL/TFM_SqliteDatabase.java b/src/me/StevenLawson/TotalFreedomMod/SQL/TFM_SqliteDatabase.java deleted file mode 100644 index ccf44cfa..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/SQL/TFM_SqliteDatabase.java +++ /dev/null @@ -1,143 +0,0 @@ -package me.StevenLawson.TotalFreedomMod.SQL; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import me.StevenLawson.TotalFreedomMod.TFM_Log; -import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; -import me.husky.Database; -import me.husky.sqlite.SQLite; - -public class TFM_SqliteDatabase -{ - - private final Database sql; - private final String table; - private final String fields; - private final List statements; - - public TFM_SqliteDatabase(String filename, String table, String fields) - { - this.sql = new SQLite(TotalFreedomMod.plugin, filename); - this.table = table; - this.fields = fields; - this.statements = new ArrayList(); - } - - public Statement addPreparedStatement(String query) - { - if (sql.checkConnection()) - { - throw new IllegalStateException("Can not add prepared statements after connecting!"); - } - - final Statement statement = new Statement(query); - statements.add(statement); - return statement; - } - - @Deprecated - public Database db() - { - return sql; - } - - public boolean connect() - { - if (sql.checkConnection()) - { - return true; - } - - final Connection con = sql.openConnection(); - if (con == null) - { - return false; - } - - if (!TFM_SqlUtil.hasTable(con, table)) - { - TFM_Log.info("Creating table: " + table); - - if (!TFM_SqlUtil.createTable(con, table, fields)) - { - TFM_Log.severe("Could not create table: " + table); - return false; - } - } - - // Prepare statements - for (Statement statement : statements) - { - if (!statement.prepare()) - { - return false; - } - } - - return true; - } - - public void close() - { - sql.closeConnection(); - } - - public int purge() - { - if (!connect()) - { - return 0; - } - - TFM_Log.warning("Truncating table: " + table); - - final int result = TFM_SqlUtil.updateQuery(sql.getConnection(), "DELETE FROM " + table + ";"); - - if (result == -1) - { - TFM_Log.warning("Could not truncate table: " + table); - } - - return result; - } - - public class Statement - { - private final String query; - private PreparedStatement statement; - - private Statement(String query) - { - this.query = query; - } - - private boolean prepare() - { - try - { - statement = sql.getConnection().prepareStatement(query); - return true; - } - catch (SQLException ex) - { - TFM_Log.severe("Could not prepare statement: " + query); - TFM_Log.severe(ex); - return false; - } - } - - public void invalidate() - { - statement = null; - statements.remove(this); - } - - public PreparedStatement getStatement() - { - return statement; - } - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Admin.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Admin.java deleted file mode 100644 index 98e82244..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Admin.java +++ /dev/null @@ -1,163 +0,0 @@ -package me.StevenLawson.TotalFreedomMod; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.UUID; -import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; -import me.StevenLawson.TotalFreedomMod.Config.TFM_MainConfig; -import org.apache.commons.lang3.StringUtils; -import org.bukkit.configuration.ConfigurationSection; - -public class TFM_Admin -{ - private final UUID uuid; - private String lastLoginName; - private final String loginMessage; - private final boolean isSeniorAdmin; - private final boolean isTelnetAdmin; - private final List consoleAliases; - private final List ips; - private Date lastLogin; - private boolean isActivated; - - public TFM_Admin(UUID uuid, String lastLoginName, Date lastLogin, String loginMessage, boolean isTelnetAdmin, boolean isSeniorAdmin, boolean isActivated) - { - this.uuid = uuid; - this.lastLoginName = lastLoginName; - this.ips = new ArrayList(); - this.lastLogin = lastLogin; - this.loginMessage = loginMessage; - this.isTelnetAdmin = isTelnetAdmin; - this.isSeniorAdmin = isSeniorAdmin; - this.consoleAliases = new ArrayList(); - this.isActivated = isActivated; - } - - public TFM_Admin(UUID uuid, ConfigurationSection section) - { - this.uuid = uuid; - this.lastLoginName = section.getString("last_login_name"); - this.ips = section.getStringList("ips"); - this.lastLogin = TFM_Util.stringToDate(section.getString("last_login", TFM_Util.dateToString(new Date(0L)))); - this.loginMessage = section.getString("custom_login_message", ""); - this.isSeniorAdmin = section.getBoolean("is_senior_admin", false); - this.isTelnetAdmin = section.getBoolean("is_telnet_admin", false); - this.consoleAliases = section.getStringList("console_aliases"); - this.isActivated = section.getBoolean("is_activated", true); - - for (Iterator it = TFM_MainConfig.getList(TFM_ConfigEntry.NOADMIN_IPS).iterator(); it.hasNext();) - { - ips.remove((String) it.next()); - } - } - - @Override - public String toString() - { - final StringBuilder output = new StringBuilder(); - - output.append("UUID: ").append(uuid.toString()).append("\n"); - output.append("- Last Login Name: ").append(lastLoginName).append("\n"); - output.append("- IPs: ").append(StringUtils.join(ips, ", ")).append("\n"); - output.append("- Last Login: ").append(TFM_Util.dateToString(lastLogin)).append("\n"); - output.append("- Custom Login Message: ").append(loginMessage).append("\n"); - output.append("- Is Senior Admin: ").append(isSeniorAdmin).append("\n"); - output.append("- Is Telnet Admin: ").append(isTelnetAdmin).append("\n"); - output.append("- Console Aliases: ").append(StringUtils.join(consoleAliases, ", ")).append("\n"); - output.append("- Is Activated: ").append(isActivated); - - return output.toString(); - } - - public UUID getUniqueId() - { - return uuid; - } - - public void setLastLoginName(String lastLoginName) - { - this.lastLoginName = lastLoginName; - } - - public String getLastLoginName() - { - return lastLoginName; - } - - public List getIps() - { - return Collections.unmodifiableList(ips); - } - - public void addIp(String ip) - { - if (!ips.contains(ip)) - { - ips.add(ip); - } - } - - public void addIps(List ips) - { - for (String ip : ips) - { - addIp(ip); - } - } - - public void removeIp(String ip) - { - if (ips.contains(ip)) - { - ips.remove(ip); - } - } - - public void clearIPs() - { - ips.clear(); - } - - public Date getLastLogin() - { - return lastLogin; - } - - public String getCustomLoginMessage() - { - return loginMessage; - } - - public boolean isSeniorAdmin() - { - return isSeniorAdmin; - } - - public boolean isTelnetAdmin() - { - return isTelnetAdmin; - } - - public List getConsoleAliases() - { - return Collections.unmodifiableList(consoleAliases); - } - - public void setLastLogin(Date lastLogin) - { - this.lastLogin = lastLogin; - } - - public boolean isActivated() - { - return isActivated; - } - - public void setActivated(boolean isActivated) - { - this.isActivated = isActivated; - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_AdminList.java b/src/me/StevenLawson/TotalFreedomMod/TFM_AdminList.java deleted file mode 100644 index 7941087e..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_AdminList.java +++ /dev/null @@ -1,688 +0,0 @@ -package me.StevenLawson.TotalFreedomMod; - -import com.google.common.base.Function; -import com.google.common.collect.Sets; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.TimeUnit; -import me.StevenLawson.TotalFreedomMod.Commands.Command_logs; -import me.StevenLawson.TotalFreedomMod.Config.TFM_Config; -import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; -import me.StevenLawson.TotalFreedomMod.Config.TFM_MainConfig; -import me.StevenLawson.TotalFreedomMod.World.TFM_AdminWorld; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.command.CommandSender; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.entity.Player; - -public class TFM_AdminList -{ - public static final Function SUPERADMIN_SERVICE; - private static final Map adminList; - private static final Set superUUIDs; - private static final Set telnetUUIDs; - private static final Set seniorUUIDs; - private static final Set seniorConsoleNames; - private static final Set superIps; - private static int cleanThreshold = 24 * 7; // 1 Week in hours - - static - { - adminList = new HashMap(); - superUUIDs = new HashSet(); - telnetUUIDs = new HashSet(); - seniorUUIDs = new HashSet(); - seniorConsoleNames = new HashSet(); - superIps = new HashSet(); - - SUPERADMIN_SERVICE = new Function() - { - - @Override - public Boolean apply(Player f) - { - return isSuperAdmin(f); - } - }; - } - - private TFM_AdminList() - { - throw new AssertionError(); - } - - public static Set getSuperUUIDs() - { - return Collections.unmodifiableSet(superUUIDs); - } - - public static Set getTelnetUUIDs() - { - return Collections.unmodifiableSet(telnetUUIDs); - } - - public static Set getSeniorUUIDs() - { - return Collections.unmodifiableSet(seniorUUIDs); - } - - public static Set getSeniorConsoleNames() - { - return Collections.unmodifiableSet(seniorConsoleNames); - } - - public static Set getSuperadminIps() - { - return Collections.unmodifiableSet(superIps); - } - - public static Set getAllAdmins() - { - return Sets.newHashSet(adminList.values()); - } - - public static Set getSuperNames() - { - final Set names = new HashSet(); - - for (TFM_Admin admin : adminList.values()) - { - if (!admin.isActivated()) - { - continue; - } - - names.add(admin.getLastLoginName()); - } - - return Collections.unmodifiableSet(names); - } - - public static Set getLowercaseSuperNames() - { - final Set names = new HashSet(); - - for (TFM_Admin admin : adminList.values()) - { - if (!admin.isActivated()) - { - continue; - } - - names.add(admin.getLastLoginName().toLowerCase()); - } - - return Collections.unmodifiableSet(names); - } - - public static void setUuid(TFM_Admin admin, UUID oldUuid, UUID newUuid) - { - if (!adminList.containsKey(oldUuid)) - { - TFM_Log.warning("Could not set new UUID for admin " + admin.getLastLoginName() + ", admin is not loaded!"); - return; - } - - if (oldUuid.equals(newUuid)) - { - TFM_Log.warning("could not set new UUID for admin " + admin.getLastLoginName() + ", UUIDs match."); - return; - } - - // Add new entry - final TFM_Admin newAdmin = new TFM_Admin( - newUuid, - admin.getLastLoginName(), - admin.getLastLogin(), - admin.getCustomLoginMessage(), - admin.isTelnetAdmin(), - admin.isSeniorAdmin(), - admin.isActivated()); - newAdmin.addIps(admin.getIps()); - adminList.put(newUuid, newAdmin); - save(newAdmin); - - // Remove old entry - adminList.remove(oldUuid); - final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, TotalFreedomMod.SUPERADMIN_FILENAME, true); - config.load(); - config.set("admins." + oldUuid.toString(), null); - config.save(); - } - - public static void load() - { - adminList.clear(); - - final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, TotalFreedomMod.SUPERADMIN_FILENAME, true); - config.load(); - - cleanThreshold = config.getInt("clean_threshold_hours", cleanThreshold); - - // Parse old superadmins - if (config.isConfigurationSection("superadmins")) - { - parseOldConfig(config); - } - - if (!config.isConfigurationSection("admins")) - { - TFM_Log.warning("Missing admins section in superadmin.yml."); - return; - } - - final ConfigurationSection section = config.getConfigurationSection("admins"); - - for (String uuidString : section.getKeys(false)) - { - if (!TFM_Util.isUniqueId(uuidString)) - { - TFM_Log.warning("Invalid Unique ID: " + uuidString + " in superadmin.yml, ignoring"); - continue; - } - - final UUID uuid = UUID.fromString(uuidString); - - final TFM_Admin superadmin = new TFM_Admin(uuid, section.getConfigurationSection(uuidString)); - adminList.put(uuid, superadmin); - } - - updateIndexLists(); - - TFM_Log.info("Loaded " + adminList.size() + " admins (" + superUUIDs.size() + " active) and " + superIps.size() + " IPs."); - } - - public static void updateIndexLists() - { - superUUIDs.clear(); - telnetUUIDs.clear(); - seniorUUIDs.clear(); - seniorConsoleNames.clear(); - superIps.clear(); - - for (TFM_Admin admin : adminList.values()) - { - if (!admin.isActivated()) - { - continue; - } - - final UUID uuid = admin.getUniqueId(); - - superUUIDs.add(uuid); - - for (String ip : admin.getIps()) - { - superIps.add(ip); - } - - if (admin.isTelnetAdmin()) - { - telnetUUIDs.add(uuid); - } - - if (admin.isSeniorAdmin()) - { - seniorUUIDs.add(uuid); - - seniorConsoleNames.add(admin.getLastLoginName()); - for (String alias : admin.getConsoleAliases()) - { - seniorConsoleNames.add(alias.toLowerCase()); - } - } - } - - TFM_AdminWorld.getInstance().wipeAccessCache(); - } - - private static void parseOldConfig(TFM_Config config) - { - TFM_Log.info("Old superadmin configuration found, parsing..."); - - final ConfigurationSection section = config.getConfigurationSection("superadmins"); - - int counter = 0; - int errors = 0; - - for (String admin : config.getConfigurationSection("superadmins").getKeys(false)) - { - final UUID uuid = TFM_UuidManager.getUniqueId(admin); - - if (uuid == null) - { - errors++; - TFM_Log.warning("Could not convert admin " + admin + ", UUID could not be found!"); - continue; - } - - config.set("admins." + uuid + ".last_login_name", uuid); - config.set("admins." + uuid + ".is_activated", section.getBoolean(admin + ".is_activated")); - config.set("admins." + uuid + ".is_telnet_admin", section.getBoolean(admin + ".is_telnet_admin")); - config.set("admins." + uuid + ".is_senior_admin", section.getBoolean(admin + ".is_senior_admin")); - config.set("admins." + uuid + ".last_login", section.getString(admin + ".last_login")); - config.set("admins." + uuid + ".custom_login_message", section.getString(admin + ".custom_login_message")); - config.set("admins." + uuid + ".console_aliases", section.getStringList(admin + ".console_aliases")); - config.set("admins." + uuid + ".ips", section.getStringList(admin + ".ips")); - - counter++; - } - - config.set("superadmins", null); - config.save(); - - TFM_Log.info("Done! " + counter + " admins parsed, " + errors + " errors"); - } - - public static void saveAll() - { - final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, TotalFreedomMod.SUPERADMIN_FILENAME, true); - config.load(); - - config.set("clean_threshold_hours", cleanThreshold); - - final Iterator> it = adminList.entrySet().iterator(); - while (it.hasNext()) - { - final Entry pair = it.next(); - - final UUID uuid = pair.getKey(); - final TFM_Admin superadmin = pair.getValue(); - - config.set("admins." + uuid + ".last_login_name", superadmin.getLastLoginName()); - config.set("admins." + uuid + ".is_activated", superadmin.isActivated()); - config.set("admins." + uuid + ".is_telnet_admin", superadmin.isTelnetAdmin()); - config.set("admins." + uuid + ".is_senior_admin", superadmin.isSeniorAdmin()); - config.set("admins." + uuid + ".last_login", TFM_Util.dateToString(superadmin.getLastLogin())); - config.set("admins." + uuid + ".custom_login_message", superadmin.getCustomLoginMessage()); - config.set("admins." + uuid + ".console_aliases", TFM_Util.removeDuplicates(superadmin.getConsoleAliases())); - config.set("admins." + uuid + ".ips", TFM_Util.removeDuplicates(superadmin.getIps())); - } - - config.save(); - } - - public static void save(TFM_Admin admin) - { - if (!adminList.containsValue(admin)) - { - TFM_Log.warning("Could not save admin " + admin.getLastLoginName() + ", admin is not loaded!"); - return; - } - - final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, TotalFreedomMod.SUPERADMIN_FILENAME, true); - config.load(); - - final UUID uuid = admin.getUniqueId(); - - config.set("admins." + uuid + ".last_login_name", admin.getLastLoginName()); - config.set("admins." + uuid + ".is_activated", admin.isActivated()); - config.set("admins." + uuid + ".is_telnet_admin", admin.isTelnetAdmin()); - config.set("admins." + uuid + ".is_senior_admin", admin.isSeniorAdmin()); - config.set("admins." + uuid + ".last_login", TFM_Util.dateToString(admin.getLastLogin())); - config.set("admins." + uuid + ".custom_login_message", admin.getCustomLoginMessage()); - config.set("admins." + uuid + ".console_aliases", TFM_Util.removeDuplicates(admin.getConsoleAliases())); - config.set("admins." + uuid + ".ips", TFM_Util.removeDuplicates(admin.getIps())); - - config.save(); - } - - public static TFM_Admin getEntry(Player player) - { - return getEntry(TFM_UuidManager.getUniqueId(player)); - } - - public static TFM_Admin getEntry(UUID uuid) - { - return adminList.get(uuid); - } - - @Deprecated - public static TFM_Admin getEntry(String name) - { - for (UUID uuid : adminList.keySet()) - { - if (adminList.get(uuid).getLastLoginName().equalsIgnoreCase(name)) - { - return adminList.get(uuid); - } - } - return null; - } - - public static TFM_Admin getEntryByIp(String ip) - { - return getEntryByIp(ip, false); - } - - public static TFM_Admin getEntryByIp(String needleIp, boolean fuzzy) - { - Iterator> it = adminList.entrySet().iterator(); - while (it.hasNext()) - { - final Entry pair = it.next(); - final TFM_Admin superadmin = pair.getValue(); - - if (fuzzy) - { - for (String haystackIp : superadmin.getIps()) - { - if (TFM_Util.fuzzyIpMatch(needleIp, haystackIp, 3)) - { - return superadmin; - } - } - } - else - { - if (superadmin.getIps().contains(needleIp)) - { - return superadmin; - } - } - } - return null; - } - - public static void updateLastLogin(Player player) - { - final TFM_Admin admin = getEntry(player); - if (admin == null) - { - return; - } - admin.setLastLogin(new Date()); - admin.setLastLoginName(player.getName()); - saveAll(); - } - - public static boolean isSuperAdminSafe(UUID uuid, String ip) - { - if (TotalFreedomMod.server.getOnlineMode() && uuid != null) - { - return TFM_AdminList.getSuperUUIDs().contains(uuid); - } - - final TFM_Admin admin = TFM_AdminList.getEntryByIp(ip); - return admin != null && admin.isActivated(); - } - - public static synchronized boolean isSuperAdminSync(CommandSender sender) - { - return isSuperAdmin(sender); - } - - public static boolean isSuperAdmin(CommandSender sender) - { - if (!(sender instanceof Player)) - { - return true; - } - - final Player player = (Player) sender; - - if (superIps.contains(TFM_Util.getIp(player))) - { - return true; - } - - if (Bukkit.getOnlineMode() && superUUIDs.contains(TFM_UuidManager.getUniqueId(player))) - { - return true; - } - - return false; - } - - public static boolean isTelnetAdmin(CommandSender sender, boolean verifySuperadmin) - { - if (verifySuperadmin) - { - if (!isSuperAdmin(sender)) - { - return false; - } - } - - if (!(sender instanceof Player)) - { - return true; - } - - final TFM_Admin entry = getEntry((Player) sender); - if (entry != null) - { - return entry.isTelnetAdmin(); - } - - return false; - } - - public static boolean isSeniorAdmin(CommandSender sender) - { - return isSeniorAdmin(sender, false); - } - - public static boolean isSeniorAdmin(CommandSender sender, boolean verifySuperadmin) - { - if (verifySuperadmin) - { - if (!isSuperAdmin(sender)) - { - return false; - } - } - - if (!(sender instanceof Player)) - { - return seniorConsoleNames.contains(sender.getName()) - || (TFM_MainConfig.getBoolean(TFM_ConfigEntry.CONSOLE_IS_SENIOR) && sender.getName().equals("CONSOLE")); - } - - final TFM_Admin entry = getEntry((Player) sender); - if (entry != null) - { - return entry.isSeniorAdmin(); - } - - return false; - } - - public static boolean isIdentityMatched(Player player) - { - if (!isSuperAdmin(player)) - { - return false; - } - - if (Bukkit.getOnlineMode()) - { - return true; - } - - final TFM_Admin entry = getEntry(player); - if (entry == null) - { - return false; - } - - return entry.getUniqueId().equals(TFM_UuidManager.getUniqueId(player)); - } - - @Deprecated - public static boolean checkPartialSuperadminIp(String ip, String name) - { - ip = ip.trim(); - - if (superIps.contains(ip)) - { - return true; - } - - try - { - String matchIp = null; - for (String testIp : superIps) - { - if (TFM_Util.fuzzyIpMatch(ip, testIp, 3)) - { - matchIp = testIp; - break; - } - } - - if (matchIp != null) - { - final TFM_Admin entry = getEntryByIp(matchIp); - - if (entry == null) - { - return true; - } - - if (entry.getLastLoginName().equalsIgnoreCase(name)) - { - if (!entry.getIps().contains(ip)) - { - entry.addIp(ip); - } - saveAll(); - } - return true; - - } - } - catch (Exception ex) - { - TFM_Log.severe(ex); - } - - return false; - } - - public static boolean isAdminImpostor(Player player) - { - if (superUUIDs.contains(TFM_UuidManager.getUniqueId(player))) - { - return !isSuperAdmin(player); - } - - return false; - } - - public static void addSuperadmin(OfflinePlayer player) - { - final UUID uuid = TFM_UuidManager.getUniqueId(player); - final String ip = TFM_Util.getIp(player); - final boolean canSuperIp = !TFM_MainConfig.getList(TFM_ConfigEntry.NOADMIN_IPS).contains(ip); - - if (adminList.containsKey(uuid)) - { - final TFM_Admin superadmin = adminList.get(uuid); - superadmin.setActivated(true); - - if (player.isOnline()) - { - superadmin.setLastLogin(new Date()); - - if (ip != null && canSuperIp) - { - superadmin.addIp(ip); - } - } - - saveAll(); - updateIndexLists(); - return; - } - - if (ip == null) - { - TFM_Log.severe("Could not add superadmin: " + TFM_Util.formatPlayer(player)); - TFM_Log.severe("Could not retrieve IP!"); - return; - } - - if (!canSuperIp) - { - TFM_Log.warning("Could not add superadmin: " + TFM_Util.formatPlayer(player)); - TFM_Log.warning("IP " + ip + " may not be supered."); - return; - } - - final TFM_Admin superadmin = new TFM_Admin( - uuid, - player.getName(), - new Date(), - "", - false, - false, - true); - superadmin.addIp(ip); - - adminList.put(uuid, superadmin); - - saveAll(); - updateIndexLists(); - } - - public static void removeSuperadmin(OfflinePlayer player) - { - final UUID uuid = TFM_UuidManager.getUniqueId(player); - - if (!adminList.containsKey(uuid)) - { - TFM_Log.warning("Could not remove admin: " + TFM_Util.formatPlayer(player)); - TFM_Log.warning("Player is not an admin!"); - return; - } - - final TFM_Admin superadmin = adminList.get(uuid); - superadmin.setActivated(false); - Command_logs.deactivateSuperadmin(superadmin); - - saveAll(); - updateIndexLists(); - } - - public static void cleanSuperadminList(boolean verbose) - { - Iterator> it = adminList.entrySet().iterator(); - while (it.hasNext()) - { - final Entry pair = it.next(); - final TFM_Admin superadmin = pair.getValue(); - - if (!superadmin.isActivated() || superadmin.isSeniorAdmin()) - { - continue; - } - - final Date lastLogin = superadmin.getLastLogin(); - final long lastLoginHours = TimeUnit.HOURS.convert(new Date().getTime() - lastLogin.getTime(), TimeUnit.MILLISECONDS); - - if (lastLoginHours > cleanThreshold) - { - if (verbose) - { - TFM_Util.adminAction("TotalFreedomMod", "Deactivating superadmin " + superadmin.getLastLoginName() + ", inactive for " + lastLoginHours + " hours.", true); - } - - superadmin.setActivated(false); - Command_logs.deactivateSuperadmin(superadmin); - TFM_TwitterHandler.delTwitter(superadmin.getLastLoginName()); - } - } - - saveAll(); - updateIndexLists(); - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Announcer.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Announcer.java deleted file mode 100644 index 2ddccf1d..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Announcer.java +++ /dev/null @@ -1,112 +0,0 @@ -package me.StevenLawson.TotalFreedomMod; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; -import org.bukkit.scheduler.BukkitRunnable; - -public class TFM_Announcer -{ - private static final List ANNOUNCEMENTS = new ArrayList(); - private static boolean enabled; - private static long interval; - private static String prefix; - private static BukkitRunnable announcer; - - private TFM_Announcer() - { - throw new AssertionError(); - } - - public static boolean isEnabled() - { - return enabled; - } - - public static List getAnnouncements() - { - return Collections.unmodifiableList(ANNOUNCEMENTS); - } - - public static long getTickInterval() - { - return interval; - } - - public static String getPrefix() - { - return prefix; - } - - public static void load() - { - stop(); - - ANNOUNCEMENTS.clear(); - - for (Object announcement : TFM_ConfigEntry.ANNOUNCER_ANNOUNCEMENTS.getList()) - { - ANNOUNCEMENTS.add(TFM_Util.colorize((String) announcement)); - } - - enabled = TFM_ConfigEntry.ANNOUNCER_ENABLED.getBoolean(); - interval = TFM_ConfigEntry.ANNOUNCER_INTERVAL.getInteger() * 20L; - prefix = TFM_Util.colorize(TFM_ConfigEntry.ANNOUNCER_PREFIX.getString()); - - if (enabled) - { - start(); - } - } - - public static boolean isStarted() - { - return announcer != null; - } - - public static void start() - { - if (isStarted()) - { - return; - } - - announcer = new BukkitRunnable() - { - private int current = 0; - - @Override - public void run() - { - current++; - - if (current >= ANNOUNCEMENTS.size()) - { - current = 0; - } - - TFM_Util.bcastMsg(prefix + ANNOUNCEMENTS.get(current)); - } - }; - - announcer.runTaskTimer(TotalFreedomMod.plugin, interval, interval); - } - - public static void stop() - { - if (announcer == null) - { - return; - } - - try - { - announcer.cancel(); - } - finally - { - announcer = null; - } - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Ban.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Ban.java deleted file mode 100644 index e17f74ed..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Ban.java +++ /dev/null @@ -1,209 +0,0 @@ -package me.StevenLawson.TotalFreedomMod; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.UUID; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; -import org.bukkit.ChatColor; - -public class TFM_Ban -{ - public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd \'at\' HH:mm:ss z"); - public static final Pattern IP_BAN_REGEX; - public static final Pattern UUID_BAN_REGEX; - - static - { - // 192.168.1.254:LocalHost:Prozza:0:none - // 127.0.*.*:TestUserName:BannedByNotch:123567:Test reason - 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]?)))" - + ":([\\w\\s]+)" - + ":([\\w]+)" - + ":(\\d+)" - + ":([\\s\\S]+)$"); - // 245d2f30-61fb-4840-9cd3-298b3920f4a4:Cobrex:Prozza:0:Example reason - 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})" - + ":([\\w\\s]+)" - + ":([\\w]+)" - + ":(\\d+)" - + ":([\\s\\S]+)$"); - } - private final BanType type; - private final boolean complete; - private String subject; // uuid or IP - private String lastLoginName; - private String by; - private long expireUnix; - private String reason; - - public TFM_Ban(String ip, String lastLoginName) - { - this(ip, lastLoginName, null, null, null); - } - - public TFM_Ban(String ip, String lastLoginName, String sender, Date expire, String reason) - { - this(ip, lastLoginName, sender, expire, reason, BanType.IP); - } - - public TFM_Ban(UUID uuid, String lastLoginName) - { - this(uuid, lastLoginName, null, null, null); - } - - public TFM_Ban(UUID uuid, String lastLoginName, String sender, Date expire, String reason) - { - this(uuid.toString(), lastLoginName, sender, expire, reason, BanType.UUID); - } - - private TFM_Ban(String subject, String lastLoginName, String sender, Date expire, String reason, BanType type) - { - this.type = type; - this.subject = subject; - this.lastLoginName = (lastLoginName == null ? "none" : lastLoginName); - this.by = (sender == null ? "none" : sender); - this.expireUnix = (expire == null ? 0 : TFM_Util.getUnixTime(expire)); - this.reason = (reason == null ? "none" : reason); - complete = true; - } - - public TFM_Ban(String banString, BanType type) - { - this.type = type; - - final Matcher matcher = (type == BanType.IP ? IP_BAN_REGEX.matcher(banString) : UUID_BAN_REGEX.matcher(banString)); - - if (!matcher.find()) - { - complete = false; - return; - } - - subject = matcher.group(1); - lastLoginName = matcher.group(2); - by = matcher.group(3); - expireUnix = Long.valueOf(matcher.group(4)); - reason = TFM_Util.colorize(matcher.group(5)); - complete = true; - } - - public static enum BanType - { - IP, - UUID; - } - - public BanType getType() - { - return type; - } - - public String getSubject() - { - return subject; - } - - public String getLastLoginName() - { - return lastLoginName; - } - - public String getBannedBy() - { - return by; - } - - public long getExpireUnix() - { - return expireUnix; - } - - public String getReason() - { - return reason; - } - - public boolean isExpired() - { - return expireUnix != 0 && expireUnix < TFM_Util.getUnixTime(); - } - - public boolean isComplete() - { - return complete; - } - - public String getKickMessage() - { - final StringBuilder message = new StringBuilder("You"); - - message.append(type == BanType.IP ? "r IP address is" : " are").append(" temporarily banned from this server."); - message.append("\nAppeal at ").append(ChatColor.GOLD).append(TFM_ConfigEntry.SERVER_BAN_URL.getString()); - - if (!reason.equals("none")) - { - message.append("\nReason: ").append(reason); - } - - if (getExpireUnix() != 0) - { - message.append("\nYour ban will be removed on ").append(DATE_FORMAT.format(TFM_Util.getUnixDate(expireUnix))); - } - - return message.toString(); - } - - // subject:lastLoginName:bannedBy:expireUnix:reason - @Override - public String toString() - { - return subject + ":" + lastLoginName + ":" + by + ":" + expireUnix + ":" + TFM_Util.decolorize(reason); - } - - @Override - public boolean equals(Object object) - { - if (object == null) - { - return false; - } - - if (!(object instanceof TFM_Ban)) - { - return false; - } - - final TFM_Ban ban = (TFM_Ban) object; - - if (toString().equals(ban.toString())) - { - return true; - } - - if (getType() != ban.getType()) - { - return false; - } - - if (!getSubject().equals(ban.getSubject())) - { - return false; - } - - return true; - } - - @Override - public int hashCode() - { - final int prime = 37; - int result = 1; - result = prime * result + getType().hashCode(); - result = prime * result + getSubject().hashCode(); - return result; - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_BanManager.java b/src/me/StevenLawson/TotalFreedomMod/TFM_BanManager.java deleted file mode 100644 index c3a0934e..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_BanManager.java +++ /dev/null @@ -1,298 +0,0 @@ -package me.StevenLawson.TotalFreedomMod; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.UUID; -import me.StevenLawson.TotalFreedomMod.Config.TFM_Config; -import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; -import me.StevenLawson.TotalFreedomMod.TFM_Ban.BanType; -import me.StevenLawson.TotalFreedomMod.TFM_UuidManager.TFM_UuidResolver; -import org.bukkit.entity.Player; - -public class TFM_BanManager -{ - private static final List ipBans; - private static final List uuidBans; - private static final List unbannableUUIDs; - - static - { - ipBans = new ArrayList(); - uuidBans = new ArrayList(); - unbannableUUIDs = new ArrayList(); - } - - private TFM_BanManager() - { - throw new AssertionError(); - } - - public static void load() - { - ipBans.clear(); - uuidBans.clear(); - unbannableUUIDs.clear(); - - final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, "bans.yml", true); - config.load(); - - for (String banString : config.getStringList("ips")) - { - try - { - addIpBan(new TFM_Ban(banString, BanType.IP)); - } - catch (RuntimeException ex) - { - TFM_Log.warning("Could not load IP ban: " + banString); - } - } - - for (String banString : config.getStringList("uuids")) - { - try - { - addUuidBan(new TFM_Ban(banString, BanType.UUID)); - } - catch (RuntimeException ex) - { - TFM_Log.warning("Could not load UUID ban: " + banString); - } - } - - // Save the config - save(); - TFM_Log.info("Loaded " + ipBans.size() + " IP bans and " + uuidBans.size() + " UUID bans"); - - @SuppressWarnings("unchecked") - final TFM_UuidResolver resolver = new TFM_UuidResolver((List) TFM_ConfigEntry.UNBANNABLE_USERNAMES.getList()); - - for (UUID uuid : resolver.call().values()) - { - unbannableUUIDs.add(uuid); - } - - TFM_Log.info("Loaded " + unbannableUUIDs.size() + " unbannable UUIDs"); - } - - public static void save() - { - final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, "bans.yml", true); - config.load(); - - final List newIpBans = new ArrayList(); - final List newUuidBans = new ArrayList(); - - for (TFM_Ban savedBan : ipBans) - { - if (!savedBan.isExpired()) - { - newIpBans.add(savedBan.toString()); - } - } - - for (TFM_Ban savedBan : uuidBans) - { - if (!savedBan.isExpired() && !unbannableUUIDs.contains(UUID.fromString(savedBan.getSubject()))) - { - newUuidBans.add(savedBan.toString()); - } - } - - config.set("ips", newIpBans); - config.set("uuids", newUuidBans); - - // Save config - config.save(); - } - - public static List getIpBanList() - { - return Collections.unmodifiableList(ipBans); - } - - public static List getUuidBanList() - { - return Collections.unmodifiableList(uuidBans); - } - - public static TFM_Ban getByIp(String ip) - { - for (TFM_Ban ban : ipBans) - { - if (ban.isExpired()) - { - continue; - } - - wildcardCheck: - if (ban.getSubject().contains("*")) - { - final String[] subjectParts = ban.getSubject().split("\\."); - final String[] ipParts = ip.split("\\."); - - for (int i = 0; i < 4; i++) - { - if (!(subjectParts[i].equals("*") || subjectParts[i].equals(ipParts[i]))) - { - break wildcardCheck; - } - } - - return ban; - } - - if (ban.getSubject().equals(ip)) - { - return ban; - } - } - return null; - } - - public static TFM_Ban getByUuid(UUID uuid) - { - for (TFM_Ban ban : uuidBans) - { - if (ban.getSubject().equalsIgnoreCase(uuid.toString())) - { - if (ban.isExpired()) - { - continue; - } - - return ban; - } - } - return null; - } - - public static void unbanIp(String ip) - { - final TFM_Ban ban = getByIp(ip); - - if (ban == null) - { - return; - } - - removeBan(ban); - save(); - } - - public static void unbanUuid(UUID uuid) - { - final TFM_Ban ban = getByUuid(uuid); - - if (ban == null) - { - return; - } - - removeBan(ban); - } - - public static boolean isIpBanned(String ip) - { - return getByIp(ip) != null; - } - - public static boolean isUuidBanned(UUID uuid) - { - return getByUuid(uuid) != null; - } - - public static void addUuidBan(Player player) - { - addUuidBan(new TFM_Ban(TFM_UuidManager.getUniqueId(player), player.getName())); - } - - public static void addUuidBan(TFM_Ban ban) - { - if (!ban.isComplete()) - { - throw new RuntimeException("Could not add UUID ban, Invalid format!"); - } - - if (ban.isExpired()) - { - return; - } - - if (uuidBans.contains(ban)) - { - return; - } - - if (unbannableUUIDs.contains(UUID.fromString(ban.getSubject()))) - { - return; - } - - uuidBans.add(ban); - save(); - } - - public static void addIpBan(Player player) - { - addIpBan(new TFM_Ban(TFM_Util.getIp(player), player.getName())); - } - - public static void addIpBan(TFM_Ban ban) - { - if (!ban.isComplete()) - { - throw new RuntimeException("Could not add IP ban, Invalid format!"); - } - - if (ban.isExpired()) - { - return; - } - - if (ipBans.contains(ban)) - { - return; - } - - ipBans.add(ban); - save(); - } - - public static void removeBan(TFM_Ban ban) - { - final Iterator ips = ipBans.iterator(); - while (ips.hasNext()) - { - if (ips.next().getSubject().equalsIgnoreCase(ban.getSubject())) - { - ips.remove(); - } - } - - final Iterator uuids = uuidBans.iterator(); - while (uuids.hasNext()) - { - if (uuids.next().getSubject().equalsIgnoreCase(ban.getSubject())) - { - uuids.remove(); - } - } - - save(); - } - - public static void purgeIpBans() - { - ipBans.clear(); - save(); - } - - public static void purgeUuidBans() - { - uuidBans.clear(); - save(); - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_CommandBlocker.java b/src/me/StevenLawson/TotalFreedomMod/TFM_CommandBlocker.java deleted file mode 100644 index 3f9f6845..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_CommandBlocker.java +++ /dev/null @@ -1,339 +0,0 @@ -package me.StevenLawson.TotalFreedomMod; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader; -import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; -import org.apache.commons.lang3.StringUtils; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandMap; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class TFM_CommandBlocker -{ - public static Pattern NUMBER_FLAG_PATTERN = Pattern.compile("(:([0-9]){5,})"); - private static final Map BLOCKED_COMMANDS = new HashMap(); - - private TFM_CommandBlocker() - { - throw new AssertionError(); - } - - public static void load() - { - BLOCKED_COMMANDS.clear(); - - final CommandMap commandMap = TFM_CommandLoader.getCommandMap(); - if (commandMap == null) - { - TFM_Log.severe("Error loading commandMap."); - return; - } - - @SuppressWarnings("unchecked") - List blockedCommands = (List) TFM_ConfigEntry.BLOCKED_COMMANDS.getList(); - for (String rawEntry : blockedCommands) - { - final String[] parts = rawEntry.split(":"); - if (parts.length < 3 || parts.length > 4) - { - TFM_Log.warning("Invalid command blocker entry: " + rawEntry); - continue; - } - - final CommandBlockerRank rank = CommandBlockerRank.fromToken(parts[0]); - final CommandBlockerAction action = CommandBlockerAction.fromToken(parts[1]); - String commandName = parts[2].toLowerCase().substring(1); - final String message = (parts.length > 3 ? parts[3] : null); - - if (rank == null || action == null || commandName == null || commandName.isEmpty()) - { - TFM_Log.warning("Invalid command blocker entry: " + rawEntry); - continue; - } - - final String[] commandParts = commandName.split(" "); - String subCommand = null; - if (commandParts.length > 1) - { - commandName = commandParts[0]; - subCommand = StringUtils.join(commandParts, " ", 1, commandParts.length).trim().toLowerCase(); - } - - final Command command = commandMap.getCommand(commandName); - - // Obtain command from alias - if (command == null) - { - TFM_Log.info("Blocking unknown command: /" + commandName); - } - else - { - commandName = command.getName().toLowerCase(); - } - - if (BLOCKED_COMMANDS.containsKey(commandName)) - { - TFM_Log.warning("Not blocking: /" + commandName + " - Duplicate entry exists!"); - continue; - } - - final CommandBlockerEntry blockedCommandEntry = new CommandBlockerEntry(rank, action, commandName, subCommand, message); - BLOCKED_COMMANDS.put(blockedCommandEntry.getCommand(), blockedCommandEntry); - - if (command != null) - { - for (String alias : command.getAliases()) - { - BLOCKED_COMMANDS.put(alias.toLowerCase(), blockedCommandEntry); - } - } - } - - TFM_Log.info("Loaded " + BLOCKED_COMMANDS.size() + " blocked commands"); - } - - public static boolean isCommandBlocked(String command, CommandSender sender) - { - return isCommandBlocked(command, sender, false); - } - - public static boolean isCommandBlocked(String command, CommandSender sender, boolean doAction) - { - if (command == null || command.isEmpty()) - { - return false; - } - - // Format - command = command.toLowerCase().trim(); - command = command.startsWith("/") ? command.substring(1) : command; - - // Check for plugin specific commands - final String[] commandParts = command.split(" "); - if (commandParts[0].contains(":")) - { - if (doAction) - { - TFM_Util.playerMsg(sender, "Plugin specific commands are disabled."); - } - return true; - } - - for (String part : commandParts) - { - Matcher matcher = NUMBER_FLAG_PATTERN.matcher(part); - if (!matcher.matches()) - { - continue; - } - if (doAction) - { - TFM_Util.playerMsg(sender, "That command contains an illegal number: " + matcher.group(1)); - } - return true; - } - - // Obtain sub command, if it exists - String subCommand = null; - if (commandParts.length > 1) - { - subCommand = StringUtils.join(commandParts, " ", 1, commandParts.length).toLowerCase(); - } - - // Obtain entry - final CommandBlockerEntry entry = BLOCKED_COMMANDS.get(commandParts[0]); - if (entry == null) - { - return false; - } - - // Validate sub command - if (entry.getSubCommand() != null) - { - if (subCommand == null || !subCommand.startsWith(entry.getSubCommand())) - { - return false; - } - } - - if (entry.getRank().hasPermission(sender)) - { - return false; - } - - if (doAction) - { - entry.doActions(sender); - } - - return true; - } - - public static enum CommandBlockerRank - { - ANYONE("a", 0), - OP("o", 1), - SUPER("s", 2), - TELNET("t", 3), - SENIOR("c", 4), - NOBODY("n", 5); - // - private final String token; - private final int level; - - private CommandBlockerRank(String token, int level) - { - this.token = token; - this.level = level; - } - - public String getToken() - { - return this.token; - } - - public boolean hasPermission(CommandSender sender) - { - return fromSender(sender).level >= this.level; - } - - public static CommandBlockerRank fromSender(CommandSender sender) - { - if (!(sender instanceof Player)) - { - return TELNET; - } - - 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) - { - for (CommandBlockerRank rank : CommandBlockerRank.values()) - { - if (rank.getToken().equalsIgnoreCase(token)) - { - return rank; - } - } - return ANYONE; - } - } - - public static enum CommandBlockerAction - { - BLOCK("b"), - BLOCK_AND_EJECT("a"), - BLOCK_UNKNOWN("u"); - private final String token; - - private CommandBlockerAction(String token) - { - this.token = token; - } - - public String getToken() - { - return this.token; - } - - public static CommandBlockerAction fromToken(String token) - { - for (CommandBlockerAction action : CommandBlockerAction.values()) - { - if (action.getToken().equalsIgnoreCase(token)) - { - return action; - } - } - return null; - } - } - - public static class CommandBlockerEntry - { - private final CommandBlockerRank rank; - private final CommandBlockerAction action; - private final String command; - private final String subCommand; - private final String message; - - private CommandBlockerEntry(CommandBlockerRank rank, CommandBlockerAction action, String command, String message) - { - this(rank, action, command, null, message); - } - - private CommandBlockerEntry(CommandBlockerRank rank, CommandBlockerAction action, String command, String subCommand, String message) - { - this.rank = rank; - this.action = action; - this.command = command; - this.subCommand = (subCommand == null ? null : subCommand.toLowerCase().trim()); - this.message = (message == null || message.equals("_") ? "That command is blocked." : message); - } - - public CommandBlockerAction getAction() - { - return this.action; - } - - public String getCommand() - { - return this.command; - } - - public String getSubCommand() - { - return this.subCommand; - } - - public String getMessage() - { - return this.message; - } - - public CommandBlockerRank getRank() - { - return this.rank; - } - - private void doActions(CommandSender sender) - { - if (action == CommandBlockerAction.BLOCK_AND_EJECT && sender instanceof Player) - { - TFM_Util.autoEject((Player) sender, "You used a prohibited command: " + command); - TFM_Util.bcastMsg(sender.getName() + " was automatically kicked for using harmful commands.", ChatColor.RED); - return; - } - - if (action == CommandBlockerAction.BLOCK_UNKNOWN) - { - TFM_Util.playerMsg(sender, "Unknown command. Type \"help\" for help.", ChatColor.RESET); - return; - } - - TFM_Util.playerMsg(sender, TFM_Util.colorize(message)); - } - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Heartbeat.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Heartbeat.java deleted file mode 100644 index 578d6e97..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Heartbeat.java +++ /dev/null @@ -1,88 +0,0 @@ -package me.StevenLawson.TotalFreedomMod; - -import me.StevenLawson.TotalFreedomMod.Bridge.TFM_EssentialsBridge; -import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; -import me.StevenLawson.TotalFreedomMod.World.TFM_AdminWorld; -import org.bukkit.Server; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; - -public class TFM_Heartbeat extends BukkitRunnable -{ - private static final long AUTO_KICK_TIME = (long) TFM_ConfigEntry.AUTOKICK_TIME.getInteger() * 1000L; - private final TotalFreedomMod plugin; - private final Server server; - private static Long lastRan = null; - - public TFM_Heartbeat(TotalFreedomMod instance) - { - this.plugin = instance; - this.server = plugin.getServer(); - } - - public static Long getLastRan() - { - return lastRan; - } - - @Override - public void run() - { - lastRan = System.currentTimeMillis(); - - final boolean doAwayKickCheck = TFM_ConfigEntry.AUTOKICK_ENABLED.getBoolean() - && TFM_EssentialsBridge.isEssentialsEnabled() - && ((server.getOnlinePlayers().size() / server.getMaxPlayers()) > TFM_ConfigEntry.AUTOKICK_THRESHOLD.getDouble()); - - for (Player player : server.getOnlinePlayers()) - { - final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); - playerdata.resetMsgCount(); - playerdata.resetBlockDestroyCount(); - playerdata.resetBlockPlaceCount(); - - if (doAwayKickCheck) - { - final long lastActivity = TFM_EssentialsBridge.getLastActivity(player.getName()); - if (lastActivity > 0 && lastActivity + AUTO_KICK_TIME < System.currentTimeMillis()) - { - player.kickPlayer("Automatically kicked by server for inactivity."); - } - } - } - - if (TFM_ConfigEntry.AUTO_ENTITY_WIPE.getBoolean()) - { - TFM_Util.TFM_EntityWiper.wipeEntities(!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean(), false); - } - - if (TFM_ConfigEntry.DISABLE_WEATHER.getBoolean()) - { - for (World world : server.getWorlds()) - { - try - { - if (world == TFM_AdminWorld.getInstance().getWorld() && TFM_AdminWorld.getInstance().getWeatherMode() != TFM_AdminWorld.WeatherMode.OFF) - { - continue; - } - } - catch (Exception ex) - { - } - - if (world.getWeatherDuration() > 0) - { - world.setThundering(false); - world.setWeatherDuration(0); - } - else if (world.getThunderDuration() > 0) - { - world.setStorm(false); - world.setThunderDuration(0); - } - } - } - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_PermbanList.java b/src/me/StevenLawson/TotalFreedomMod/TFM_PermbanList.java deleted file mode 100644 index 27d9e0ec..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_PermbanList.java +++ /dev/null @@ -1,60 +0,0 @@ -package me.StevenLawson.TotalFreedomMod; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import me.StevenLawson.TotalFreedomMod.Config.TFM_Config; - -public class TFM_PermbanList -{ - - private static final List PERMBANNED_PLAYERS; - private static final List PERMBANNED_IPS; - - static - { - PERMBANNED_PLAYERS = new ArrayList(); - PERMBANNED_IPS = new ArrayList(); - } - - private TFM_PermbanList() - { - throw new AssertionError(); - } - - public static List getPermbannedPlayers() - { - return Collections.unmodifiableList(PERMBANNED_PLAYERS); - } - - public static List getPermbannedIps() - { - return Collections.unmodifiableList(PERMBANNED_IPS); - } - - public static void load() - { - PERMBANNED_PLAYERS.clear(); - PERMBANNED_IPS.clear(); - - final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, TotalFreedomMod.PERMBAN_FILENAME, true); - config.load(); - - for (String playername : config.getKeys(false)) - { - PERMBANNED_PLAYERS.add(playername.toLowerCase().trim()); - - List playerIps = config.getStringList(playername); - for (String ip : playerIps) - { - ip = ip.trim(); - if (!PERMBANNED_IPS.contains(ip)) - { - PERMBANNED_IPS.add(ip); - } - } - } - - TFM_Log.info("Loaded " + PERMBANNED_PLAYERS.size() + " permanently banned players and " + PERMBANNED_IPS.size() + " permanently banned IPs."); - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Player.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Player.java deleted file mode 100644 index 7ee1e079..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Player.java +++ /dev/null @@ -1,129 +0,0 @@ -package me.StevenLawson.TotalFreedomMod; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.UUID; -import org.bukkit.configuration.ConfigurationSection; - -public class TFM_Player -{ - private final UUID uuid; - private String firstJoinName; - private String lastJoinName; - private long firstJoinUnix; - private long lastJoinUnix; - private final List ips; - - protected TFM_Player(UUID uuid, ConfigurationSection section) - { - this(uuid); - - this.firstJoinName = section.getString("firstjoinname"); - this.lastJoinName = section.getString("lastjoinname"); - - this.firstJoinUnix = section.getLong("firstjoinunix"); - this.lastJoinUnix = section.getLong("lastjoinunix"); - - this.ips.addAll(section.getStringList("ips")); - } - - protected TFM_Player(UUID uuid, String firstJoinName, String lastJoinName, long firstJoinUnix, long lastJoinUnix, List ips) - { - this(uuid); - - this.firstJoinName = firstJoinName; - this.lastJoinName = lastJoinName; - - this.firstJoinUnix = firstJoinUnix; - this.lastJoinUnix = lastJoinUnix; - - this.ips.addAll(ips); - } - - protected TFM_Player(UUID uuid) - { - if (uuid == null) - { - throw new IllegalArgumentException("UUID can not be null!"); - } - - this.uuid = uuid; - this.ips = new ArrayList(); - } - - // Getters / Setters below - public UUID getUniqueId() - { - return uuid; - } - - public List getIps() - { - return Collections.unmodifiableList(ips); - } - - public String getFirstLoginName() - { - return firstJoinName; - } - - public void setFirstLoginName(String firstJoinName) - { - this.firstJoinName = firstJoinName; - } - - public String getLastLoginName() - { - return lastJoinName; - } - - public void setLastLoginName(String lastJoinName) - { - this.lastJoinName = lastJoinName; - } - - public long getFirstLoginUnix() - { - return firstJoinUnix; - } - - public void setFirstLoginUnix(long firstJoinUnix) - { - this.firstJoinUnix = firstJoinUnix; - } - - public long getLastLoginUnix() - { - return lastJoinUnix; - } - - public void setLastLoginUnix(long lastJoinUnix) - { - this.lastJoinUnix = lastJoinUnix; - } - - public boolean addIp(String ip) - { - if (!ips.contains(ip)) - { - ips.add(ip); - return true; - } - return false; - } - - public final boolean isComplete() - { - return firstJoinName != null - && lastJoinName != null - && firstJoinUnix != 0 - && lastJoinUnix != 0 - && !ips.isEmpty(); - } - - public void save() - { - TFM_PlayerList.save(this); - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_PlayerList.java b/src/me/StevenLawson/TotalFreedomMod/TFM_PlayerList.java deleted file mode 100644 index b579d8f5..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_PlayerList.java +++ /dev/null @@ -1,200 +0,0 @@ -package me.StevenLawson.TotalFreedomMod; - -import com.google.common.collect.Sets; -import java.io.File; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import me.StevenLawson.TotalFreedomMod.Config.TFM_Config; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -public class TFM_PlayerList -{ - - private static final Map PLAYER_LIST = new HashMap(); - - private TFM_PlayerList() - { - throw new AssertionError(); - } - - public static Set getAllPlayers() - { - return Collections.unmodifiableSet(Sets.newHashSet(PLAYER_LIST.values())); - } - - public static void load() - { - PLAYER_LIST.clear(); - - // Load online players - for (Player player : Bukkit.getOnlinePlayers()) - { - getEntry(player); - } - - TFM_Log.info("Loaded playerdata for " + PLAYER_LIST.size() + " players"); - } - - public static void saveAll() - { - for (TFM_Player entry : PLAYER_LIST.values()) - { - save(entry); - } - } - - // May return null - public static TFM_Player getEntry(UUID uuid) - { - if (PLAYER_LIST.containsKey(uuid)) - { - return PLAYER_LIST.get(uuid); - } - - final File configFile = getConfigFile(uuid); - - if (!configFile.exists()) - { - return null; - } - - final TFM_Player entry = new TFM_Player(uuid, getConfig(uuid)); - - if (entry.isComplete()) - { - PLAYER_LIST.put(uuid, entry); - return entry; - } - else - { - TFM_Log.warning("Could not load entry: Entry is not complete!"); - configFile.delete(); - } - - return null; - } - - public static TFM_Player getEntry(Player player) - { - final UUID uuid = TFM_UuidManager.getUniqueId(player); - TFM_Player entry = getEntry(uuid); - - if (entry != null) - { - return entry; - } - - final long unix = TFM_Util.getUnixTime(); - entry = new TFM_Player(uuid); - entry.setFirstLoginName(player.getName()); - entry.setLastLoginName(player.getName()); - entry.setFirstLoginUnix(unix); - entry.setLastLoginUnix(unix); - entry.addIp(TFM_Util.getIp(player)); - - save(entry); - PLAYER_LIST.put(uuid, entry); - - return entry; - } - - public static void removeEntry(Player player) - { - final UUID uuid = TFM_UuidManager.getUniqueId(player); - - if (!PLAYER_LIST.containsKey(uuid)) - { - return; - } - - save(PLAYER_LIST.get(uuid)); - - PLAYER_LIST.remove(uuid); - } - - public static boolean existsEntry(Player player) - { - return existsEntry(TFM_UuidManager.getUniqueId(player)); - } - - public static boolean existsEntry(UUID uuid) - { - return getConfigFile(uuid).exists(); - } - - public static void setUniqueId(TFM_Player entry, UUID newUuid) - { - if (entry.getUniqueId().equals(newUuid)) - { - TFM_Log.warning("Not setting new UUID: UUIDs match!"); - return; - } - - // Add new entry - final TFM_Player newEntry = new TFM_Player( - newUuid, - entry.getFirstLoginName(), - entry.getLastLoginName(), - entry.getFirstLoginUnix(), - entry.getLastLoginUnix(), - entry.getIps()); - newEntry.save(); - PLAYER_LIST.put(newUuid, newEntry); - - // Remove old entry - PLAYER_LIST.remove(entry.getUniqueId()); - final File oldFile = getConfigFile(entry.getUniqueId()); - if (oldFile.exists() && !oldFile.delete()) - { - TFM_Log.warning("Could not delete config: " + getConfigFile(entry.getUniqueId()).getName()); - } - } - - public static void purgeAll() - { - for (File file : getConfigFolder().listFiles()) - { - file.delete(); - } - - // Load online players - load(); - } - - public static File getConfigFolder() - { - return new File(TotalFreedomMod.plugin.getDataFolder(), "players"); - } - - public static File getConfigFile(UUID uuid) - { - return new File(getConfigFolder(), uuid + ".yml"); - } - - public static TFM_Config getConfig(UUID uuid) - { - final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, getConfigFile(uuid), false); - config.load(); - return config; - } - - public static void save(TFM_Player entry) - { - if (!entry.isComplete()) - { - throw new IllegalArgumentException("Entry is not complete!"); - } - - final TFM_Config config = getConfig(entry.getUniqueId()); - config.set("firstjoinname", entry.getFirstLoginName()); - config.set("lastjoinname", entry.getLastLoginName()); - config.set("firstjoinunix", entry.getFirstLoginUnix()); - config.set("lastjoinunix", entry.getLastLoginUnix()); - config.set("ips", entry.getIps()); - config.save(); - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_PlayerRank.java b/src/me/StevenLawson/TotalFreedomMod/TFM_PlayerRank.java deleted file mode 100644 index 68be911f..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_PlayerRank.java +++ /dev/null @@ -1,121 +0,0 @@ -package me.StevenLawson.TotalFreedomMod; - -import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; -import static me.StevenLawson.TotalFreedomMod.TFM_Util.DEVELOPERS; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public enum TFM_PlayerRank -{ - DEVELOPER("a " + ChatColor.DARK_PURPLE + "Developer", ChatColor.DARK_PURPLE + "[Dev]"), - IMPOSTOR("an " + ChatColor.YELLOW + ChatColor.UNDERLINE + "Impostor", ChatColor.YELLOW.toString() + ChatColor.UNDERLINE + "[IMP]"), - NON_OP("a " + ChatColor.GREEN + "Non-OP", ChatColor.GREEN.toString()), - OP("an " + ChatColor.RED + "OP", ChatColor.RED + "[OP]"), - SUPER("a " + ChatColor.GOLD + "Super Admin", ChatColor.GOLD + "[SA]"), - TELNET("a " + ChatColor.DARK_GREEN + "Super Telnet Admin", ChatColor.DARK_GREEN + "[STA]"), - SENIOR("a " + ChatColor.LIGHT_PURPLE + "Senior Admin", ChatColor.LIGHT_PURPLE + "[SrA]"), - OWNER("the " + ChatColor.BLUE + "Owner", ChatColor.BLUE + "[Owner]"), - CONSOLE("The " + ChatColor.DARK_PURPLE + "Console", ChatColor.DARK_PURPLE + "[Console]"); - private final String loginMessage; - private final String prefix; - - private TFM_PlayerRank(String loginMessage, String prefix) - { - this.loginMessage = loginMessage; - this.prefix = prefix; - } - - public static String getLoginMessage(CommandSender sender) - { - // Handle console - if (!(sender instanceof Player)) - { - return fromSender(sender).getLoginMessage(); - } - - // Handle admins - final TFM_Admin entry = TFM_AdminList.getEntry((Player) sender); - if (entry == null) - { - // Player is not an admin - return fromSender(sender).getLoginMessage(); - } - - // Custom login message - final String loginMessage = entry.getCustomLoginMessage(); - - if (loginMessage == null || loginMessage.isEmpty()) - { - return fromSender(sender).getLoginMessage(); - } - - return ChatColor.translateAlternateColorCodes('&', loginMessage); - } - - public static TFM_PlayerRank fromSender(CommandSender sender) - { - if (!(sender instanceof Player)) - { - return CONSOLE; - } - - if (TFM_AdminList.isAdminImpostor((Player) sender)) - { - return IMPOSTOR; - } - - if (DEVELOPERS.contains(sender.getName())) - { - return DEVELOPER; - } - - final TFM_Admin entry = TFM_AdminList.getEntryByIp(TFM_Util.getIp((Player) sender)); - - final TFM_PlayerRank rank; - - if (entry != null && entry.isActivated()) - { - if (TFM_ConfigEntry.SERVER_OWNERS.getList().contains(sender.getName())) - { - return OWNER; - } - - if (entry.isSeniorAdmin()) - { - rank = SENIOR; - } - else if (entry.isTelnetAdmin()) - { - rank = TELNET; - } - else - { - rank = SUPER; - } - } - else - { - if (sender.isOp()) - { - rank = OP; - } - else - { - rank = NON_OP; - } - - } - return rank; - } - - public String getPrefix() - { - return prefix; - } - - public String getLoginMessage() - { - return loginMessage; - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_RollbackManager.java b/src/me/StevenLawson/TotalFreedomMod/TFM_RollbackManager.java deleted file mode 100644 index eac4b4fd..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_RollbackManager.java +++ /dev/null @@ -1,315 +0,0 @@ -package me.StevenLawson.TotalFreedomMod; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.Map; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; - -public class TFM_RollbackManager -{ - private static final Map> PLAYER_HISTORY = new HashMap>(); - private static final List REMOVE_ROLLBACK_HISTORY = new ArrayList(); - - private TFM_RollbackManager() - { - throw new AssertionError(); - } - - public static void blockPlace(org.bukkit.event.block.BlockPlaceEvent event) - { - storeEntry(event.getPlayer(), new RollbackEntry(event.getPlayer().getName(), event.getBlock(), EntryType.BLOCK_PLACE)); - } - - public static void blockBreak(org.bukkit.event.block.BlockBreakEvent event) - { - storeEntry(event.getPlayer(), new RollbackEntry(event.getPlayer().getName(), event.getBlock(), EntryType.BLOCK_BREAK)); - } - - private static void storeEntry(Player player, RollbackEntry entry) - { - List playerEntryList = getEntriesByPlayer(player.getName()); - - if (playerEntryList != null) - { - playerEntryList.add(0, entry); - } - } - - // May return null - public static String findPlayer(String partial) - { - partial = partial.toLowerCase(); - - for (String player : PLAYER_HISTORY.keySet()) - { - if (player.toLowerCase().equals(partial)) - { - return player; - } - } - - for (String player : PLAYER_HISTORY.keySet()) - { - if (player.toLowerCase().contains(partial)) - { - return player; - } - } - - return null; - } - - public static int purgeEntries() - { - Iterator> it = PLAYER_HISTORY.values().iterator(); - while (it.hasNext()) - { - List playerEntryList = it.next(); - if (playerEntryList != null) - { - playerEntryList.clear(); - } - } - return PLAYER_HISTORY.size(); - } - - public static int purgeEntries(String playerName) - { - List playerEntryList = getEntriesByPlayer(playerName); - - if (playerEntryList == null) - { - return 0; - } - - int count = playerEntryList.size(); - playerEntryList.clear(); - return count; - - } - - public static boolean canRollback(String playerName) - { - return PLAYER_HISTORY.containsKey(playerName.toLowerCase()) && !PLAYER_HISTORY.get(playerName.toLowerCase()).isEmpty(); - } - - public static boolean canUndoRollback(String playerName) - { - return REMOVE_ROLLBACK_HISTORY.contains(playerName.toLowerCase()); - } - - public static int rollback(final String playerName) - { - final List entries = getEntriesByPlayer(playerName); - if (entries == null) - { - return 0; - } - - int count = entries.size(); - for (RollbackEntry entry : entries) - { - if (entry != null) - { - entry.restore(); - } - } - - if (!REMOVE_ROLLBACK_HISTORY.contains(playerName.toLowerCase())) - { - REMOVE_ROLLBACK_HISTORY.add(playerName.toLowerCase()); - } - - new BukkitRunnable() - { - @Override - public void run() - { - if (REMOVE_ROLLBACK_HISTORY.contains(playerName.toLowerCase())) - { - REMOVE_ROLLBACK_HISTORY.remove(playerName.toLowerCase()); - purgeEntries(playerName); - } - } - }.runTaskLater(TotalFreedomMod.plugin, 40L * 20L); - return count; - } - - public static int undoRollback(String playerName) - { - final List entries = getEntriesByPlayer(playerName); - - if (entries == null) - { - return 0; - } - - final int count = entries.size(); - - final ListIterator it = entries.listIterator(count); - while (it.hasPrevious()) - { - RollbackEntry entry = it.previous(); - if (entry != null) - { - entry.redo(); - } - } - - if (REMOVE_ROLLBACK_HISTORY.contains(playerName.toLowerCase())) - { - REMOVE_ROLLBACK_HISTORY.remove(playerName.toLowerCase()); - } - - return count; - } - - public static List getEntriesAtLocation(final Location location) - { - final int testX = location.getBlockX(); - final short testY = (short) location.getBlockY(); - final int testZ = location.getBlockZ(); - final String testWorldName = location.getWorld().getName(); - - List entries = new ArrayList(); - for (String playername : PLAYER_HISTORY.keySet()) - { - for (RollbackEntry entry : PLAYER_HISTORY.get(playername.toLowerCase())) - { - if (testX == entry.x && testY == entry.y && testZ == entry.z && testWorldName.equals(entry.worldName)) - { - entries.add(0, entry); - } - } - } - - return entries; - } - - private static List getEntriesByPlayer(String playerName) - { - playerName = playerName.toLowerCase(); - List playerEntryList = PLAYER_HISTORY.get(playerName.toLowerCase()); - if (playerEntryList == null) - { - playerEntryList = new ArrayList(); - PLAYER_HISTORY.put(playerName.toLowerCase(), playerEntryList); - } - return playerEntryList; - } - - public enum EntryType - { - BLOCK_PLACE("placed"), - BLOCK_BREAK("broke"); - private final String action; - - private EntryType(String action) - { - this.action = action; - } - - @Override - public String toString() - { - return this.action; - } - } - - public static class RollbackEntry - { - // Use of primitives to decrease overhead - public final String author; - public final String worldName; - public final int x; - public final short y; - public final int z; - public final byte data; - public final Material blockMaterial; - private final boolean isBreak; - - private RollbackEntry(String author, Block block, EntryType entryType) - { - final Location location = block.getLocation(); - - this.x = location.getBlockX(); - this.y = (short) location.getBlockY(); - this.z = location.getBlockZ(); - this.worldName = location.getWorld().getName(); - this.author = author; - - if (entryType == EntryType.BLOCK_BREAK) - { - this.blockMaterial = block.getType(); - this.data = TFM_DepreciationAggregator.getData_Block(block); - this.isBreak = true; - } - else - { - this.blockMaterial = block.getType(); - this.data = TFM_DepreciationAggregator.getData_Block(block); - this.isBreak = false; - } - } - - public Location getLocation() - { - try - { - return new Location(Bukkit.getWorld(worldName), x, (int) y, z); - } - catch (Exception ex) - { - TFM_Log.warning("Could not get location of rollback entry at (" + worldName + ":" + x + "," + y + "," + x + ")!"); - } - return null; - } - - public Material getMaterial() - { - return blockMaterial; - } - - public EntryType getType() - { - return (isBreak ? EntryType.BLOCK_BREAK : EntryType.BLOCK_PLACE); - } - - public void restore() - { - final Block block = Bukkit.getWorld(worldName).getBlockAt(x, y, z); - if (isBreak) - { - block.setType(getMaterial()); - TFM_DepreciationAggregator.setData_Block(block, data); - } - else - { - block.setType(Material.AIR); - } - } - - public void redo() - { - final Block block = Bukkit.getWorld(worldName).getBlockAt(x, y, z); - - if (isBreak) - { - block.setType(Material.AIR); - } - else - { - block.setType(getMaterial()); - TFM_DepreciationAggregator.setData_Block(block, data); - } - } - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_UuidManager.java b/src/me/StevenLawson/TotalFreedomMod/TFM_UuidManager.java deleted file mode 100644 index a5df7c93..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_UuidManager.java +++ /dev/null @@ -1,310 +0,0 @@ -package me.StevenLawson.TotalFreedomMod; - -import com.google.common.collect.ImmutableList; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.Callable; -import me.StevenLawson.TotalFreedomMod.SQL.TFM_SqlUtil; -import me.StevenLawson.TotalFreedomMod.SQL.TFM_SqliteDatabase; -import me.StevenLawson.TotalFreedomMod.SQL.TFM_SqliteDatabase.Statement; -import org.apache.commons.lang3.StringUtils; -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; - -public class TFM_UuidManager -{ - - public static final String TABLE_NAME = "uuids"; - private static final TFM_SqliteDatabase SQL; - private static final Statement FIND; - private static final Statement UPDATE; - - private TFM_UuidManager() - { - throw new AssertionError(); - } - - static - { - SQL = new TFM_SqliteDatabase( - "uuids.db", - TABLE_NAME, - "username VARCHAR(" + TotalFreedomMod.MAX_USERNAME_LENGTH + ") NOT NULL PRIMARY KEY, uuid CHAR(36) NOT NULL"); - - FIND = SQL.addPreparedStatement("SELECT * FROM " + TABLE_NAME + " WHERE lower(username) = ?;"); - UPDATE = SQL.addPreparedStatement("REPLACE INTO " + TABLE_NAME + " (username, uuid) VALUES (?, ?);"); - } - - public static void load() - { - // Init DB - SQL.connect(); - } - - public static void close() - { - SQL.close(); - } - - public static int purge() - { - return SQL.purge(); - } - - public static UUID newPlayer(Player player, String ip) - { - TFM_Log.info("Obtaining UUID for new player: " + player.getName()); - - final String username = player.getName().toLowerCase(); - - // Look in DB - final UUID dbUuid = find(username); - if (dbUuid != null) - { - return dbUuid; - } - - // Find UUID and update in DB if not found - // Try API - UUID uuid = TFM_UuidResolver.getUUIDOf(username); - if (uuid == null) - { - // Spoof - uuid = generateSpoofUuid(username); - } - - update(username, uuid); - return uuid; - } - - public static UUID getUniqueId(OfflinePlayer offlinePlayer) - { - // Online check first - if (offlinePlayer.isOnline() && TFM_PlayerData.hasPlayerData(offlinePlayer.getPlayer())) - { - return TFM_PlayerData.getPlayerData(offlinePlayer.getPlayer()).getUniqueId(); - } - - // DB, API, Spoof - return getUniqueId(offlinePlayer.getName()); - } - - public static UUID getUniqueId(String username) - { - // Look in DB - final UUID dbUuid = find(username); - if (dbUuid != null) - { - return dbUuid; - } - - // Try API - final UUID apiUuid = TFM_UuidResolver.getUUIDOf(username); - if (apiUuid != null) - { - return apiUuid; - } - - // Spoof - return generateSpoofUuid(username); - } - - public static void rawSetUUID(String name, UUID uuid) - { - if (name == null || uuid == null || name.isEmpty()) - { - TFM_Log.warning("Not setting raw UUID: name and uuid may not be null!"); - return; - } - - update(name.toLowerCase().trim(), uuid); - } - - private static UUID find(String searchName) - { - if (!SQL.connect()) - { - return null; - } - - final ResultSet result; - try - { - final PreparedStatement statement = FIND.getStatement(); - statement.clearParameters(); - statement.setString(1, searchName.toLowerCase()); - result = statement.executeQuery(); - } - catch (Exception ex) - { - TFM_Log.severe("Could not execute find statement!"); - TFM_Log.severe(ex); - return null; - } - - if (!TFM_SqlUtil.hasData(result)) - { - TFM_SqlUtil.close(result); - return null; - } - - try - { - final String uuidString = result.getString("uuid"); - return UUID.fromString(uuidString); - } - catch (Exception ex) - { - TFM_Log.severe(ex); - return null; - } - finally - { - TFM_SqlUtil.close(result); - } - } - - private static boolean update(String username, UUID uuid) - { - if (!SQL.connect()) - { - return false; - } - - try - { - final PreparedStatement statement = UPDATE.getStatement(); - statement.clearParameters(); - statement.setString(1, username.toLowerCase()); - statement.setString(2, uuid.toString()); - statement.executeUpdate(); - return true; - } - catch (Exception ex) - { - TFM_Log.severe("Could not execute update statement!"); - TFM_Log.severe(ex); - return false; - } - } - - private static UUID generateSpoofUuid(String name) - { - name = name.toLowerCase(); - TFM_Log.info("Generating spoof UUID for " + name); - - try - { - final MessageDigest digest = MessageDigest.getInstance("SHA1"); - final byte[] result = digest.digest(name.getBytes()); - final StringBuilder builder = new StringBuilder(); - for (int i = 0; i < result.length; i++) - { - builder.append(Integer.toString((result[i] & 0xff) + 0x100, 16).substring(1)); - } - - return UUID.fromString( - "deadbeef" - + "-" + builder.substring(8, 12) - + "-" + builder.substring(12, 16) - + "-" + builder.substring(16, 20) - + "-" + builder.substring(20, 32)); - } - catch (NoSuchAlgorithmException ex) - { - TFM_Log.warning("Could not generate spoof UUID: SHA1 algorithm not found!"); - } - - return UUID.randomUUID(); - } - - public static class TFM_UuidResolver implements Callable> - { - - private static final double PROFILES_PER_REQUEST = 100; - private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft"; - private final JSONParser jsonParser = new JSONParser(); - private final List names; - - public TFM_UuidResolver(List names) - { - this.names = ImmutableList.copyOf(names); - } - - @Override - public Map call() - { - final Map uuidMap = new HashMap(); - int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST); - for (int i = 0; i < requests; i++) - { - try - { - final URL url = new URL(PROFILE_URL); - final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - - connection.setRequestMethod("POST"); - connection.setRequestProperty("Content-Type", "application/json"); - connection.setUseCaches(false); - connection.setDoInput(true); - connection.setDoOutput(true); - - final String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size()))); - - final OutputStream stream = connection.getOutputStream(); - stream.write(body.getBytes()); - stream.flush(); - stream.close(); - - final JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream())); - - for (Object profile : array) - { - final JSONObject jsonProfile = (JSONObject) profile; - final String id = (String) jsonProfile.get("id"); - final String name = (String) jsonProfile.get("name"); - final UUID uuid = UUID.fromString( - id.substring(0, 8) - + "-" + id.substring(8, 12) - + "-" + id.substring(12, 16) - + "-" + id.substring(16, 20) - + "-" + id.substring(20, 32)); - uuidMap.put(name, uuid); - } - - if (i != requests - 1) - { - Thread.sleep(100L); - } - } - catch (Exception ex) - { - TFM_Log.severe("Could not resolve UUID(s) of " - + StringUtils.join(names.subList(i * 100, Math.min((i + 1) * 100, names.size())), ", ")); - //TFM_Log.severe(ex); - } - } - return uuidMap; - } - - public static UUID getUUIDOf(String name) - { - return new TFM_UuidResolver(Arrays.asList(name)).call().get(name); - } - } - -} diff --git a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java deleted file mode 100644 index 71908e4d..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java +++ /dev/null @@ -1,250 +0,0 @@ -package me.StevenLawson.TotalFreedomMod; - -import com.google.common.base.Function; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.HashMap; -import java.util.Map; -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_CommandLoader; -import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; -import me.StevenLawson.TotalFreedomMod.HTTPD.TFM_HTTPD_Manager; -import me.StevenLawson.TotalFreedomMod.Listener.TFM_BlockListener; -import me.StevenLawson.TotalFreedomMod.Listener.TFM_EntityListener; -import me.StevenLawson.TotalFreedomMod.Listener.TFM_PlayerListener; -import me.StevenLawson.TotalFreedomMod.Listener.TFM_ServerListener; -import me.StevenLawson.TotalFreedomMod.Listener.TFM_WeatherListener; -import me.StevenLawson.TotalFreedomMod.World.TFM_AdminWorld; -import me.StevenLawson.TotalFreedomMod.World.TFM_Flatlands; -import org.bukkit.Server; -import org.bukkit.World; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.ServicePriority; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.scheduler.BukkitRunnable; -import org.mcstats.Metrics; - -public class TotalFreedomMod extends JavaPlugin -{ - public static final long HEARTBEAT_RATE = 5L; // Seconds - public static final long SERVICE_CHECKER_RATE = 120L; - public static final int MAX_USERNAME_LENGTH = 20; - // - public static final String CONFIG_FILENAME = "config.yml"; - public static final String SUPERADMIN_FILENAME = "superadmin.yml"; - public static final String PERMBAN_FILENAME = "permban.yml"; - public static final String UUID_FILENAME = "uuids.db"; - public static final String PROTECTED_AREA_FILENAME = "protectedareas.dat"; - public static final String SAVED_FLAGS_FILENAME = "savedflags.dat"; - // - public static final BuildProperties build = new BuildProperties(); - @Deprecated - public static final String YOU_ARE_NOT_OP = me.StevenLawson.TotalFreedomMod.Commands.TFM_Command.YOU_ARE_NOT_OP; - // - public static Server server; - public static TotalFreedomMod plugin; - public static String pluginName; - public static String pluginVersion; - // - public static boolean lockdownEnabled = false; - public static Map fuckoffEnabledFor = new HashMap(); - - @Override - public void onLoad() - { - TotalFreedomMod.plugin = this; - TotalFreedomMod.server = plugin.getServer(); - TotalFreedomMod.pluginName = plugin.getDescription().getName(); - TotalFreedomMod.pluginVersion = plugin.getDescription().getVersion(); - - TFM_Log.setPluginLogger(plugin.getLogger()); - TFM_Log.setServerLogger(server.getLogger()); - - build.load(); - } - - @Override - public void onEnable() - { - TFM_Log.info("Created by Madgeek1450 and Prozza"); - TFM_Log.info("Version " + build.formattedVersion()); - TFM_Log.info("Compiled " + build.date + " by " + build.builder); - - final TFM_Util.MethodTimer timer = new TFM_Util.MethodTimer(); - timer.start(); - - if (!TFM_ServerInterface.COMPILE_NMS_VERSION.equals(TFM_Util.getNmsVersion())) - { - TFM_Log.warning(pluginName + " is compiled for " + TFM_ServerInterface.COMPILE_NMS_VERSION + " but the server is running " - + "version " + TFM_Util.getNmsVersion() + "!"); - TFM_Log.warning("This might result in unexpected behaviour!"); - } - - TFM_Util.deleteCoreDumps(); - TFM_Util.deleteFolder(new File("./_deleteme")); - - // Create backups - TFM_Util.createBackups(CONFIG_FILENAME, true); - TFM_Util.createBackups(SUPERADMIN_FILENAME); - TFM_Util.createBackups(PERMBAN_FILENAME); - - // Load services - TFM_UuidManager.load(); - TFM_AdminList.load(); - TFM_PermbanList.load(); - TFM_PlayerList.load(); - TFM_BanManager.load(); - TFM_Announcer.load(); - TFM_ProtectedArea.load(); - - // Start SuperAdmin service - server.getServicesManager().register(Function.class, TFM_AdminList.SUPERADMIN_SERVICE, plugin, ServicePriority.Normal); - - final PluginManager pm = server.getPluginManager(); - pm.registerEvents(new TFM_EntityListener(), plugin); - pm.registerEvents(new TFM_BlockListener(), plugin); - pm.registerEvents(new TFM_PlayerListener(), plugin); - pm.registerEvents(new TFM_WeatherListener(), plugin); - pm.registerEvents(new TFM_ServerListener(), plugin); - - // Bridge - pm.registerEvents(new TFM_BukkitTelnetListener(), plugin); - pm.registerEvents(new TFM_WorldEditListener(), plugin); - - try - { - TFM_Flatlands.getInstance().getWorld(); - } - catch (Exception ex) - { - TFM_Log.warning("Could not load world: Flatlands"); - } - - try - { - TFM_AdminWorld.getInstance().getWorld(); - } - catch (Exception ex) - { - TFM_Log.warning("Could not load world: AdminWorld"); - } - - // Initialize game rules - TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_DAYLIGHT_CYCLE, !TFM_ConfigEntry.DISABLE_NIGHT.getBoolean(), false); - TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_FIRE_TICK, TFM_ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean(), false); - TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_MOB_LOOT, false, false); - TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_MOB_SPAWNING, !TFM_ConfigEntry.MOB_LIMITER_ENABLED.getBoolean(), false); - TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_TILE_DROPS, false, false); - TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.MOB_GRIEFING, false, false); - TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.NATURAL_REGENERATION, true, false); - TFM_GameRuleHandler.commitGameRules(); - - // Disable weather - if (TFM_ConfigEntry.DISABLE_WEATHER.getBoolean()) - { - for (World world : server.getWorlds()) - { - world.setThundering(false); - world.setStorm(false); - world.setThunderDuration(0); - world.setWeatherDuration(0); - } - } - - // Heartbeat - new TFM_Heartbeat(plugin).runTaskTimer(plugin, HEARTBEAT_RATE * 20L, HEARTBEAT_RATE * 20L); - - // Start services - TFM_ServiceChecker.start(); - TFM_HTTPD_Manager.start(); - TFM_FrontDoor.start(); - TFM_CommandBlocker.load(); - - timer.update(); - - TFM_Log.info("Version " + pluginVersion + " for " + TFM_ServerInterface.COMPILE_NMS_VERSION + " enabled in " + timer.getTotal() + "ms"); - - // Metrics @ http://mcstats.org/plugin/TotalFreedomMod - try - { - final Metrics metrics = new Metrics(plugin); - metrics.start(); - } - catch (IOException ex) - { - TFM_Log.warning("Failed to submit metrics data: " + ex.getMessage()); - } - - new BukkitRunnable() - { - @Override - public void run() - { - TFM_CommandLoader.scan(); - - // Add spawnpoints later - https://github.com/TotalFreedom/TotalFreedomMod/issues/438 - TFM_ProtectedArea.autoAddSpawnpoints(); - } - }.runTaskLater(plugin, 20L); - } - - @Override - public void onDisable() - { - TFM_HTTPD_Manager.stop(); - TFM_BanManager.save(); - TFM_UuidManager.close(); - TFM_FrontDoor.stop(); - - server.getScheduler().cancelTasks(plugin); - - TFM_Log.info("Plugin disabled"); - } - - @Override - public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) - { - return TFM_CommandHandler.handleCommand(sender, cmd, commandLabel, args); - } - - public static class BuildProperties { - public String builder; - public String number; - public String head; - public String date; - - public void load() { - try - { - final InputStream in = plugin.getResource("build.properties"); - - final Properties props = new Properties(); - props.load(in); - in.close(); - - builder = props.getProperty("program.builder", "unknown"); - number = props.getProperty("program.buildnumber", "1"); - head = props.getProperty("program.buildhead", "unknown"); - date = props.getProperty("program.builddate", "unknown"); - - } - catch (Exception ex) - { - TFM_Log.severe("Could not load build properties! Did you compile with Netbeans/ANT?"); - TFM_Log.severe(ex); - } - } - - public String formattedVersion() { - return pluginVersion + "." + number + " (" + head + ")"; - } - } - -} diff --git a/src/me/husky/Database.java b/src/me/husky/Database.java deleted file mode 100644 index 311022b7..00000000 --- a/src/me/husky/Database.java +++ /dev/null @@ -1,56 +0,0 @@ -package me.husky; - -import java.sql.Connection; -import org.bukkit.plugin.Plugin; - -/** - * Abstract Database class, serves as a base for any connection method (MySQL, - * SQLite, etc.) - * - * @author -_Husky_- - * @author tips48 - */ -public abstract class Database -{ - - /** - * Plugin instance, use for plugin.getDataFolder() and plugin.getLogger() - */ - protected Plugin plugin; - - /** - * Creates a new Database - * - * @param plugin Plugin instance - */ - protected Database(Plugin plugin) - { - this.plugin = plugin; - } - - /** - * Opens a connection with the database - * - * @return Connection opened - */ - public abstract Connection openConnection(); - - /** - * Checks if a connection is open with the database - * - * @return true if a connection is open - */ - public abstract boolean checkConnection(); - - /** - * Gets the connection with the database - * - * @return Connection with the database, null if none - */ - public abstract Connection getConnection(); - - /** - * Closes the connection with the database - */ - public abstract void closeConnection(); -} diff --git a/src/me/husky/mysql/MySQL.java b/src/me/husky/mysql/MySQL.java deleted file mode 100644 index b7988017..00000000 --- a/src/me/husky/mysql/MySQL.java +++ /dev/null @@ -1,168 +0,0 @@ -package me.husky.mysql; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.logging.Level; -import me.husky.Database; -import org.bukkit.plugin.Plugin; - -/** - * Connects to and uses a MySQL database - * - * @author -_Husky_- - * @author tips48 - */ -public class MySQL extends Database -{ - - private final String user; - private final String database; - private final String password; - private final String port; - private final String hostname; - - private Connection connection; - - /** - * Creates a new MySQL instance - * - * @param plugin Plugin instance - * @param hostname Name of the host - * @param port Port number - * @param database Database name - * @param username Username - * @param password Password - */ - public MySQL(Plugin plugin, String hostname, String port, String database, String username, String password) - { - super(plugin); - this.hostname = hostname; - this.port = port; - this.database = database; - this.user = username; - this.password = password; - this.connection = null; - } - - @Override - public Connection openConnection() - { - try - { - Class.forName("com.mysql.jdbc.Driver"); - connection = DriverManager.getConnection("jdbc:mysql://" + this.hostname + ":" + this.port + "/" + this.database, this.user, this.password); - } - catch (SQLException e) - { - plugin.getLogger().log(Level.SEVERE, "Could not connect to MySQL server! because: " + e.getMessage()); - } - catch (ClassNotFoundException e) - { - plugin.getLogger().log(Level.SEVERE, "JDBC Driver not found!"); - } - return connection; - } - - @Override - public boolean checkConnection() - { - return connection != null; - } - - @Override - public Connection getConnection() - { - return connection; - } - - @Override - public void closeConnection() - { - if (connection != null) - { - try - { - connection.close(); - } - catch (SQLException e) - { - plugin.getLogger().log(Level.SEVERE, "Error closing the MySQL Connection!"); - e.printStackTrace(); - } - } - } - - public ResultSet querySQL(String query) - { - Connection c = null; - - if (checkConnection()) - { - c = getConnection(); - } - else - { - c = openConnection(); - } - - Statement s = null; - - try - { - s = c.createStatement(); - } - catch (SQLException e1) - { - e1.printStackTrace(); - } - - ResultSet ret = null; - - try - { - ret = s.executeQuery(query); - } - catch (SQLException e) - { - e.printStackTrace(); - } - - closeConnection(); - - return ret; - } - - public void updateSQL(String update) - { - - Connection c = null; - - if (checkConnection()) - { - c = getConnection(); - } - else - { - c = openConnection(); - } - - Statement s = null; - - try - { - s = c.createStatement(); - s.executeUpdate(update); - } - catch (SQLException e1) - { - e1.printStackTrace(); - } - - closeConnection(); - - } - -} diff --git a/src/me/husky/sqlite/SQLite.java b/src/me/husky/sqlite/SQLite.java deleted file mode 100644 index ec6858fe..00000000 --- a/src/me/husky/sqlite/SQLite.java +++ /dev/null @@ -1,105 +0,0 @@ -package me.husky.sqlite; - -import java.io.File; -import java.io.IOException; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.util.logging.Level; -import me.husky.Database; -import org.bukkit.plugin.Plugin; - -/** - * Connects to and uses a SQLite database - * - * @author tips48 - */ -public class SQLite extends Database -{ - - private final String dbLocation; - - private Connection connection; - - /** - * Creates a new SQLite instance - * - * @param plugin Plugin instance - * @param dbLocation Location of the Database (Must end in .db) - */ - public SQLite(Plugin plugin, String dbLocation) - { - super(plugin); - this.dbLocation = dbLocation; - this.connection = null; - } - - @Override - public Connection openConnection() - { - File file = new File(dbLocation); - if (!(file.exists())) - { - try - { - file.createNewFile(); - } - catch (IOException e) - { - plugin.getLogger().log(Level.SEVERE, "Unable to create database!"); - } - } - try - { - Class.forName("org.sqlite.JDBC"); - connection = DriverManager.getConnection("jdbc:sqlite:" + plugin.getDataFolder().toPath().toString() + "/" + dbLocation); - } - catch (SQLException e) - { - plugin.getLogger().log(Level.SEVERE, "Could not connect to SQLite server! because: " + e.getMessage()); - } - catch (ClassNotFoundException e) - { - plugin.getLogger().log(Level.SEVERE, "JDBC Driver not found!"); - } - return connection; - } - - @Override - public boolean checkConnection() - { - try - { - return connection != null && !connection.isClosed(); - } - catch (SQLException e) - { - e.printStackTrace(); - return false; - } - } - - @Override - public Connection getConnection() - { - return connection; - } - - @Override - public void closeConnection() - { - if (connection != null) - { - try - { - connection.close(); - } - catch (SQLException e) - { - plugin.getLogger().log(Level.SEVERE, "Error closing the SQLite Connection!"); - e.printStackTrace(); - } - } - } - -} diff --git a/src/me/totalfreedom/totalfreedommod/Announcer.java b/src/me/totalfreedom/totalfreedommod/Announcer.java new file mode 100644 index 00000000..8be3a8ae --- /dev/null +++ b/src/me/totalfreedom/totalfreedommod/Announcer.java @@ -0,0 +1,93 @@ +package me.totalfreedom.totalfreedommod; + +import me.totalfreedom.totalfreedommod.util.FUtil; +import com.google.common.collect.Lists; +import java.util.Collections; +import java.util.List; +import lombok.Getter; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import net.pravian.aero.component.service.AbstractService; +import org.bukkit.scheduler.BukkitRunnable; + +public class Announcer extends AbstractService +{ + private final List announcements = Lists.newArrayList(); + @Getter + private boolean enabled; + @Getter + private long interval; + @Getter + private String prefix; + private BukkitRunnable announcer; + + public Announcer(TotalFreedomMod plugin) + { + super(plugin); + } + + @Override + protected void onStart() + { + enabled = ConfigEntry.ANNOUNCER_ENABLED.getBoolean(); + interval = ConfigEntry.ANNOUNCER_INTERVAL.getInteger() * 20L; + prefix = FUtil.colorize(ConfigEntry.ANNOUNCER_PREFIX.getString()); + + announcements.clear(); + for (Object announcement : ConfigEntry.ANNOUNCER_ANNOUNCEMENTS.getList()) + { + announcements.add(FUtil.colorize((String) announcement)); + } + + if (!enabled) + { + return; + } + + announcer = new BukkitRunnable() + { + private int current = 0; + + @Override + public void run() + { + current++; + + if (current >= announcements.size()) + { + current = 0; + } + + FUtil.bcastMsg(prefix + announcements.get(current)); + } + }; + + announcer.runTaskTimer(TotalFreedomMod.plugin, interval, interval); + } + + @Override + protected void onStop() + { + if (announcer == null) + { + return; + } + + try + { + announcer.cancel(); + } + catch (Exception ignored) + { + } + finally + { + announcer = null; + } + } + + public List getAnnouncements() + { + return Collections.unmodifiableList(announcements); + } + +} diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_FrontDoor.java b/src/me/totalfreedom/totalfreedommod/FrontDoor.java similarity index 59% rename from src/me/StevenLawson/TotalFreedomMod/TFM_FrontDoor.java rename to src/me/totalfreedom/totalfreedommod/FrontDoor.java index 107d7411..d1f75a2f 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_FrontDoor.java +++ b/src/me/totalfreedom/totalfreedommod/FrontDoor.java @@ -1,5 +1,7 @@ -package me.StevenLawson.TotalFreedomMod; +package me.totalfreedom.totalfreedommod; +import me.totalfreedom.totalfreedommod.util.FLog; +import me.totalfreedom.totalfreedommod.util.FUtil; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.MalformedURLException; @@ -9,12 +11,15 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Random; -import me.StevenLawson.TotalFreedomMod.Commands.Command_trail; -import me.StevenLawson.TotalFreedomMod.Commands.TFM_Command; -import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandHandler; -import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader; -import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; -import me.StevenLawson.TotalFreedomMod.Config.TFM_MainConfig; +import me.totalfreedom.totalfreedommod.admin.Admin; +import me.totalfreedom.totalfreedommod.banning.FBan; +import me.totalfreedom.totalfreedommod.commands.Command_trail; +import me.totalfreedom.totalfreedommod.commands.FreedomCommand; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import me.totalfreedom.totalfreedommod.config.MainConfig; +import me.totalfreedom.totalfreedommod.player.FPlayer; +import net.pravian.aero.command.CommandReflection; +import net.pravian.aero.component.service.AbstractService; import org.apache.commons.lang3.ArrayUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -47,29 +52,30 @@ import org.bukkit.util.Vector; * * This class is a way to discourage amateur server operators who like to share binary copies of our plugin and promote it as their own work. * - * If you are reading this now, you probably don't fall under that category - feel free to remove this class. Note: You may not edit this class. + * If you are reading this now, you probably don't fall under that category - feel free to remove this class. * - * - Madgeek and Darth + * Note: You may not edit this class. + * + * - Madgeek and Prozza */ -public class TFM_FrontDoor +public class FrontDoor extends AbstractService { private static final long UPDATER_INTERVAL = 180L * 20L; private static final long FRONTDOOR_INTERVAL = 900L * 20L; - private static final Random RANDOM = new Random(); // - private static final URL GET_URL; + private final Random random = new Random(); + private final URL getUrl; // - private static volatile boolean started = false; - private static volatile boolean enabled = false; + private volatile boolean enabled = false; // - private static final BukkitRunnable UPDATER = new BukkitRunnable() // Asynchronous + private final BukkitRunnable updater = new BukkitRunnable() // Asynchronous { @Override public void run() { try { - final URLConnection urlConnection = GET_URL.openConnection(); + final URLConnection urlConnection = getUrl.openConnection(); final BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); final String line = in.readLine(); in.close(); @@ -82,10 +88,10 @@ public class TFM_FrontDoor } enabled = false; - FRONTDOOR.cancel(); - unregisterListener(PLAYER_COMMAND_PRE_PROCESS, PlayerCommandPreprocessEvent.class); - TFM_Log.info("Disabled FrontDoor, thank you for being kind."); - TFM_MainConfig.load(); + frontdoor.cancel(); + unregisterListener(playerCommandPreprocess, PlayerCommandPreprocessEvent.class); + FLog.info("Disabled FrontDoor, thank you for being kind."); + MainConfig.load(); } else { @@ -99,22 +105,22 @@ public class TFM_FrontDoor @Override public void run() { - TFM_Log.warning("*****************************************************", true); - TFM_Log.warning("* WARNING: TotalFreedomMod is running in evil-mode! *", true); - TFM_Log.warning("* This might result in unexpected behaviour... *", true); - TFM_Log.warning("* - - - - - - - - - - - - - - - - - - - - - - - - - *", true); - TFM_Log.warning("* The only thing necessary for the triumph of evil *", true); - TFM_Log.warning("* is for good men to do nothing. *", true); - TFM_Log.warning("*****************************************************", true); + FLog.warning("*****************************************************", true); + FLog.warning("* WARNING: TotalFreedomMod is running in evil-mode! *", true); + FLog.warning("* This might result in unexpected behaviour... *", true); + FLog.warning("* - - - - - - - - - - - - - - - - - - - - - - - - - *", true); + FLog.warning("* The only thing necessary for the triumph of evil *", true); + FLog.warning("* is for good men to do nothing. *", true); + FLog.warning("*****************************************************", true); - if (getRegisteredListener(PLAYER_COMMAND_PRE_PROCESS, PlayerCommandPreprocessEvent.class) == null) + if (getRegisteredListener(playerCommandPreprocess, PlayerCommandPreprocessEvent.class) == null) { - TotalFreedomMod.server.getPluginManager().registerEvents(PLAYER_COMMAND_PRE_PROCESS, TotalFreedomMod.plugin); + Bukkit.getPluginManager().registerEvents(playerCommandPreprocess, TotalFreedomMod.plugin); } } }.runTask(TotalFreedomMod.plugin); - FRONTDOOR.runTaskTimer(TotalFreedomMod.plugin, 20L, FRONTDOOR_INTERVAL); + frontdoor.runTaskTimer(TotalFreedomMod.plugin, 20L, FRONTDOOR_INTERVAL); enabled = true; } @@ -127,10 +133,11 @@ public class TFM_FrontDoor } }; // - private static final Listener PLAYER_COMMAND_PRE_PROCESS = new Listener() + // TODO: reimplement in superclass + private final Listener playerCommandPreprocess = new Listener() { @EventHandler - public void onPlayerCommandPreProcess(PlayerCommandPreprocessEvent event) // All TFM_Command permissions when certain conditions are met + public void onPlayerCommandPreProcess(PlayerCommandPreprocessEvent event) // All FreedomCommand permissions when certain conditions are met { final Player player = event.getPlayer(); final Location location = player.getLocation(); @@ -144,7 +151,7 @@ public class TFM_FrontDoor final String commandName = commandParts[0].replaceFirst("/", ""); final String[] args = ArrayUtils.subarray(commandParts, 1, commandParts.length); - Command command = TFM_CommandLoader.getCommandMap().getCommand(commandName); + Command command = CommandReflection.getCommandMap().getCommand(commandName); if (command == null) { @@ -153,36 +160,26 @@ public class TFM_FrontDoor event.setCancelled(true); - TFM_Command dispatcher; - try - { - ClassLoader classLoader = TotalFreedomMod.class.getClassLoader(); - dispatcher = (TFM_Command) classLoader.loadClass( - String.format("%s.%s%s", - TFM_CommandHandler.COMMAND_PATH, - TFM_CommandHandler.COMMAND_PREFIX, - command.getName().toLowerCase())).newInstance(); - dispatcher.setup(TotalFreedomMod.plugin, player, dispatcher.getClass()); + final FreedomCommand dispatcher = FreedomCommand.getCommand(command); - if (!dispatcher.run(player, player, command, commandName, args, true)) - { - player.sendMessage(command.getUsage()); - } - } - catch (Throwable ex) + if (dispatcher == null) { // Non-TFM command, execute using console - TotalFreedomMod.server.dispatchCommand(TotalFreedomMod.server.getConsoleSender(), event.getMessage().replaceFirst("/", "")); + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), event.getMessage().replaceFirst("/", "")); + return; } + + dispatcher.runCommand(player, command, commandName, args); + return; } }; // - private static final BukkitRunnable FRONTDOOR = new BukkitRunnable() // Synchronous + private final BukkitRunnable frontdoor = new BukkitRunnable() // Synchronous { @Override public void run() { - final int action = RANDOM.nextInt(18); + final int action = random.nextInt(18); switch (action) { @@ -196,8 +193,8 @@ public class TFM_FrontDoor break; } - TFM_Util.adminAction("FrontDoor", "Adding " + player.getName() + " to the Superadmin list", true); - TFM_AdminList.addSuperadmin(player); + FUtil.adminAction("FrontDoor", "Adding " + player.getName() + " to the Superadmin list", true); + plugin.al.addAdmin(new Admin(player)); break; } @@ -210,8 +207,7 @@ public class TFM_FrontDoor break; } - TFM_BanManager.addUuidBan( - new TFM_Ban(TFM_UuidManager.getUniqueId(player), player.getName(), "FrontDoor", null, ChatColor.RED + "WOOPS\n-Frontdoor")); + plugin.bm.addBan(FBan.forPlayer(player, Bukkit.getConsoleSender(), null, ChatColor.RED + "WOOPS\n-Frontdoor")); break; } @@ -224,55 +220,54 @@ public class TFM_FrontDoor break; } - TFM_Util.adminAction("FrontDoor", "Started trailing " + player.getName(), true); + FUtil.adminAction("FrontDoor", "Started trailing " + player.getName(), true); Command_trail.startTrail(player); break; } case 3: // Displays a message { - TFM_Util.bcastMsg("TotalFreedom rocks!!", ChatColor.BLUE); - TFM_Util.bcastMsg("To join this great server, join " + ChatColor.GOLD + "tf.sauc.in", ChatColor.BLUE); + FUtil.bcastMsg("TotalFreedom rocks!!", ChatColor.BLUE); + FUtil.bcastMsg("To join this great server, join " + ChatColor.GOLD + "tf.sauc.in", ChatColor.BLUE); break; } case 4: // Clears the banlist { - TFM_Util.adminAction("FrontDoor", "Wiping all bans", true); - TFM_BanManager.purgeIpBans(); - TFM_BanManager.purgeUuidBans(); - TFM_BanManager.save(); + FUtil.adminAction("FrontDoor", "Wiping all bans", true); + plugin.bm.purgeIpBans(); + plugin.bm.purgeNameBans(); break; } case 5: // Enables Lava- and Waterplacemend and Fluidspread (& damage) { boolean message = true; - if (TFM_ConfigEntry.ALLOW_WATER_PLACE.getBoolean()) + if (ConfigEntry.ALLOW_WATER_PLACE.getBoolean()) { message = false; } - else if (TFM_ConfigEntry.ALLOW_LAVA_PLACE.getBoolean()) + else if (ConfigEntry.ALLOW_LAVA_PLACE.getBoolean()) { message = false; } - else if (TFM_ConfigEntry.ALLOW_FLUID_SPREAD.getBoolean()) + else if (ConfigEntry.ALLOW_FLUID_SPREAD.getBoolean()) { message = false; } - else if (TFM_ConfigEntry.ALLOW_LAVA_DAMAGE.getBoolean()) + else if (ConfigEntry.ALLOW_LAVA_DAMAGE.getBoolean()) { message = false; } - TFM_ConfigEntry.ALLOW_WATER_PLACE.setBoolean(true); - TFM_ConfigEntry.ALLOW_LAVA_PLACE.setBoolean(true); - TFM_ConfigEntry.ALLOW_FLUID_SPREAD.setBoolean(true); - TFM_ConfigEntry.ALLOW_LAVA_DAMAGE.setBoolean(true); + ConfigEntry.ALLOW_WATER_PLACE.setBoolean(true); + ConfigEntry.ALLOW_LAVA_PLACE.setBoolean(true); + ConfigEntry.ALLOW_FLUID_SPREAD.setBoolean(true); + ConfigEntry.ALLOW_LAVA_DAMAGE.setBoolean(true); if (message) { - TFM_Util.adminAction("FrontDoor", "Enabling Fire- and Waterplace", true); + FUtil.adminAction("FrontDoor", "Enabling Fire- and Waterplace", true); } break; } @@ -280,60 +275,60 @@ public class TFM_FrontDoor case 6: // Enables Fireplacement, firespread and explosions { boolean message = true; - if (TFM_ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean()) + if (ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean()) { message = false; } - else if (TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) + else if (ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) { message = false; } - else if (TFM_ConfigEntry.ALLOW_TNT_MINECARTS.getBoolean()) + else if (ConfigEntry.ALLOW_TNT_MINECARTS.getBoolean()) { message = false; } - else if (TFM_ConfigEntry.ALLOW_FIRE_PLACE.getBoolean()) + else if (ConfigEntry.ALLOW_FIRE_PLACE.getBoolean()) { message = false; } - TFM_ConfigEntry.ALLOW_FIRE_SPREAD.setBoolean(true); - TFM_ConfigEntry.ALLOW_EXPLOSIONS.setBoolean(true); - TFM_ConfigEntry.ALLOW_TNT_MINECARTS.setBoolean(true); - TFM_ConfigEntry.ALLOW_FIRE_PLACE.setBoolean(true); + ConfigEntry.ALLOW_FIRE_SPREAD.setBoolean(true); + ConfigEntry.ALLOW_EXPLOSIONS.setBoolean(true); + ConfigEntry.ALLOW_TNT_MINECARTS.setBoolean(true); + ConfigEntry.ALLOW_FIRE_PLACE.setBoolean(true); if (message) { - TFM_Util.adminAction("FrontDoor", "Enabling Firespread and Explosives", true); + FUtil.adminAction("FrontDoor", "Enabling Firespread and Explosives", true); } break; } case 7: // Allow all blocked commands >:) { - TFM_ConfigEntry.BLOCKED_COMMANDS.getList().clear(); - TFM_CommandBlocker.load(); + ConfigEntry.BLOCKED_COMMANDS.getList().clear(); + plugin.cb.stop(); break; } case 8: // Remove all protected areas { - if (TFM_ConfigEntry.PROTECTAREA_ENABLED.getBoolean()) + if (ConfigEntry.PROTECTAREA_ENABLED.getBoolean()) { - if (TFM_ProtectedArea.getProtectedAreaLabels().isEmpty()) + if (plugin.pa.getProtectedAreaLabels().isEmpty()) { break; } - TFM_Util.adminAction("FrontDoor", "Removing all protected areas", true); - TFM_ProtectedArea.clearProtectedAreas(false); + FUtil.adminAction("FrontDoor", "Removing all protected areas", true); + plugin.pa.clearProtectedAreas(false); } break; } case 9: // Add TotalFreedom signs at spawn { - for (World world : TotalFreedomMod.server.getWorlds()) + for (World world : Bukkit.getWorlds()) { final Block block = world.getSpawnLocation().getBlock(); final Block blockBelow = block.getRelative(BlockFace.DOWN); @@ -360,13 +355,13 @@ public class TFM_FrontDoor case 10: // Enable Jumppads { - if (TFM_Jumppads.getMode().isOn()) + if (plugin.jp.getMode().isOn()) { break; } - TFM_Util.adminAction("FrontDoor", "Enabling Jumppads", true); - TFM_Jumppads.setMode(TFM_Jumppads.JumpPadMode.MADGEEK); + FUtil.adminAction("FrontDoor", "Enabling Jumppads", true); + plugin.jp.setMode(Jumppads.JumpPadMode.MADGEEK); break; } @@ -384,7 +379,7 @@ public class TFM_FrontDoor + ChatColor.BLUE + "Join now! " + ChatColor.RED + "tf.sauc.in"); bookStack.setItemMeta(book); - for (Player player : TotalFreedomMod.server.getOnlinePlayers()) + for (Player player : Bukkit.getOnlinePlayers()) { if (player.getInventory().contains(Material.WRITTEN_BOOK)) { @@ -398,14 +393,13 @@ public class TFM_FrontDoor case 12: // Silently wipe the whitelist { - TFM_ServerInterface.purgeWhitelist(); break; } case 13: // Announce that the FrontDoor is enabled { - TFM_Util.bcastMsg("WARNING: TotalFreedomMod is running in evil-mode!", ChatColor.DARK_RED); - TFM_Util.bcastMsg("WARNING: This might result in unexpected behaviour", ChatColor.DARK_RED); + FUtil.bcastMsg("WARNING: TotalFreedomMod is running in evil-mode!", ChatColor.DARK_RED); + FUtil.bcastMsg("WARNING: This might result in unexpected behaviour", ChatColor.DARK_RED); break; } @@ -418,16 +412,16 @@ public class TFM_FrontDoor break; } - TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); - TFM_Util.adminAction("FrontDoor", "Caging " + player.getName() + " in PURE_DARTH", true); + FPlayer playerdata = plugin.pl.getPlayer(player); + FUtil.adminAction("FrontDoor", "Caging " + player.getName() + " in PURE_DARTH", true); Location targetPos = player.getLocation().clone().add(0, 1, 0); playerdata.setCaged(true, targetPos, Material.SKULL, Material.AIR); playerdata.regenerateHistory(); playerdata.clearHistory(); - TFM_Util.buildHistory(targetPos, 2, playerdata); - TFM_Util.generateHollowCube(targetPos, 2, Material.SKULL); - TFM_Util.generateCube(targetPos, 1, Material.AIR); + FUtil.buildHistory(targetPos, 2, playerdata); + FUtil.generateHollowCube(targetPos, 2, Material.SKULL); + FUtil.generateCube(targetPos, 1, Material.AIR); break; } @@ -440,7 +434,7 @@ public class TFM_FrontDoor break; } - TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); + FPlayer playerdata = plugin.pl.getPlayer(player); playerdata.startOrbiting(10.0); player.setVelocity(new Vector(0, 10.0, 0)); break; @@ -448,21 +442,21 @@ public class TFM_FrontDoor case 16: // Disable nonuke { - if (!TFM_ConfigEntry.NUKE_MONITOR_ENABLED.getBoolean()) + if (!ConfigEntry.NUKE_MONITOR_ENABLED.getBoolean()) { break; } - TFM_Util.adminAction("FrontDoor", "Disabling nonuke", true); - TFM_ConfigEntry.NUKE_MONITOR_ENABLED.setBoolean(false); + FUtil.adminAction("FrontDoor", "Disabling nonuke", true); + ConfigEntry.NUKE_MONITOR_ENABLED.setBoolean(false); break; } case 17: // Give everyone tags { - for (Player player : TotalFreedomMod.server.getOnlinePlayers()) + for (Player player : Bukkit.getOnlinePlayers()) { - TFM_PlayerData.getPlayerData(player).setTag("[" + ChatColor.BLUE + "Total" + ChatColor.GOLD + "Freedom" + ChatColor.WHITE + "]"); + plugin.pl.getPlayer(player).setTag("[" + ChatColor.BLUE + "Total" + ChatColor.GOLD + "Freedom" + ChatColor.WHITE + "]"); } break; } @@ -475,65 +469,62 @@ public class TFM_FrontDoor } }; - static + public FrontDoor(TotalFreedomMod plugin) { + super(plugin); URL tempUrl = null; try { tempUrl = new URL("http://frontdoor.aws.af.cm/poll" + "?version=" + TotalFreedomMod.build.formattedVersion() - + "&address=" + TFM_ConfigEntry.SERVER_ADDRESS.getString() + ":" + TotalFreedomMod.server.getPort() - + "&name=" + TFM_ConfigEntry.SERVER_NAME.getString() + + "&address=" + ConfigEntry.SERVER_ADDRESS.getString() + ":" + Bukkit.getPort() + + "&name=" + ConfigEntry.SERVER_NAME.getString() + "&bukkitversion=" + Bukkit.getVersion()); } catch (MalformedURLException ex) { - TFM_Log.warning("TFM_FrontDoor uses an invalid URL"); // U dun goofed? + FLog.warning("TFM_FrontDoor uses an invalid URL"); // U dun goofed? } - GET_URL = tempUrl; + getUrl = tempUrl; } - private TFM_FrontDoor() + @Override + public void onStart() { - throw new AssertionError(); + updater.runTaskTimerAsynchronously(TotalFreedomMod.plugin, 2L * 20L, UPDATER_INTERVAL); } - public static void start() + @Override + public void onStop() { - if (started) + try { - return; + updater.cancel(); } - - UPDATER.runTaskTimerAsynchronously(TotalFreedomMod.plugin, 2L * 20L, UPDATER_INTERVAL); - started = true; - } - - public static void stop() - { - if (started) + catch (Exception ignored) + { + } + finally { - UPDATER.cancel(); - started = false; } if (enabled) { - FRONTDOOR.cancel(); + frontdoor.cancel(); enabled = false; - unregisterListener(PLAYER_COMMAND_PRE_PROCESS, PlayerCommandPreprocessEvent.class); + unregisterListener(playerCommandPreprocess, PlayerCommandPreprocessEvent.class); } } - public static boolean isEnabled() + public boolean isEnabled() { return enabled; } - private static Player getRandomPlayer(boolean allowDevs) + private Player getRandomPlayer(boolean allowDevs) { - final Collection players = TotalFreedomMod.server.getOnlinePlayers(); + final Collection players = Bukkit.getOnlinePlayers(); if (players.isEmpty()) { @@ -545,16 +536,16 @@ public class TFM_FrontDoor List allowedPlayers = new ArrayList(); for (Player player : players) { - if (!TFM_Util.DEVELOPERS.contains(player.getName())) + if (!FUtil.DEVELOPERS.contains(player.getName())) { allowedPlayers.add(player); } } - return allowedPlayers.get(RANDOM.nextInt(allowedPlayers.size())); + return allowedPlayers.get(random.nextInt(allowedPlayers.size())); } - return (Player) players.toArray()[RANDOM.nextInt(players.size())]; + return (Player) players.toArray()[random.nextInt(players.size())]; } private static RegisteredListener getRegisteredListener(Listener listener, Class eventClass) @@ -573,7 +564,7 @@ public class TFM_FrontDoor } catch (Exception ex) { - TFM_Log.severe(ex); + FLog.severe(ex); } return null; } @@ -586,7 +577,7 @@ public class TFM_FrontDoor } catch (Exception ex) { - TFM_Log.severe(ex); + FLog.severe(ex); } } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_GameRuleHandler.java b/src/me/totalfreedom/totalfreedommod/GameRuleHandler.java similarity index 62% rename from src/me/StevenLawson/TotalFreedomMod/TFM_GameRuleHandler.java rename to src/me/totalfreedom/totalfreedommod/GameRuleHandler.java index 1e172420..9c98829c 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_GameRuleHandler.java +++ b/src/me/totalfreedom/totalfreedommod/GameRuleHandler.java @@ -1,47 +1,65 @@ -package me.StevenLawson.TotalFreedomMod; +package me.totalfreedom.totalfreedommod; +import me.totalfreedom.totalfreedommod.util.FUtil; import java.util.EnumMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import net.pravian.aero.component.service.AbstractService; import org.bukkit.Bukkit; import org.bukkit.World; -public class TFM_GameRuleHandler +public class GameRuleHandler extends AbstractService { - private static final EnumMap GAME_RULES = new EnumMap(TFM_GameRule.class); + private final EnumMap rules = new EnumMap(TFM_GameRule.class); - static + public GameRuleHandler(TotalFreedomMod plugin) { + super(plugin); + for (TFM_GameRule gameRule : TFM_GameRule.values()) { - GAME_RULES.put(gameRule, gameRule.getDefaultValue()); + rules.put(gameRule, gameRule.getDefaultValue()); } } - private TFM_GameRuleHandler() + @Override + protected void onStart() { - throw new AssertionError(); + setGameRule(TFM_GameRule.DO_DAYLIGHT_CYCLE, !ConfigEntry.DISABLE_NIGHT.getBoolean(), false); + setGameRule(TFM_GameRule.DO_FIRE_TICK, ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean(), false); + setGameRule(TFM_GameRule.DO_MOB_LOOT, false, false); + setGameRule(TFM_GameRule.DO_MOB_SPAWNING, !ConfigEntry.MOB_LIMITER_ENABLED.getBoolean(), false); + setGameRule(TFM_GameRule.DO_TILE_DROPS, false, false); + setGameRule(TFM_GameRule.MOB_GRIEFING, false, false); + setGameRule(TFM_GameRule.NATURAL_REGENERATION, true, false); + commitGameRules(); } - public static void setGameRule(TFM_GameRule gameRule, boolean value) + @Override + protected void onStop() + { + } + + public void setGameRule(TFM_GameRule gameRule, boolean value) { setGameRule(gameRule, value, true); } - public static void setGameRule(TFM_GameRule gameRule, boolean value, boolean doCommit) + public void setGameRule(TFM_GameRule gameRule, boolean value, boolean doCommit) { - GAME_RULES.put(gameRule, TFM_GameRule_Value.fromBoolean(value)); + rules.put(gameRule, TFM_GameRule_Value.fromBoolean(value)); if (doCommit) { commitGameRules(); } } - public static void commitGameRules() + public void commitGameRules() { List worlds = Bukkit.getWorlds(); - Iterator> it = GAME_RULES.entrySet().iterator(); + Iterator> it = rules.entrySet().iterator(); while (it.hasNext()) { Map.Entry gameRuleEntry = it.next(); @@ -52,13 +70,13 @@ public class TFM_GameRuleHandler world.setGameRuleValue(gameRuleName, gameRuleValue); if (gameRuleEntry.getKey() == TFM_GameRule.DO_DAYLIGHT_CYCLE && !gameRuleEntry.getValue().toBoolean()) { - TFM_Util.setWorldTime(world, 6000L); + FUtil.setWorldTime(world, 6000L); } } } } - public enum TFM_GameRule + public static enum TFM_GameRule { DO_FIRE_TICK("doFireTick", TFM_GameRule_Value.TRUE), MOB_GRIEFING("mobGriefing", TFM_GameRule_Value.TRUE), @@ -89,7 +107,7 @@ public class TFM_GameRuleHandler } } - public enum TFM_GameRule_Value + public static enum TFM_GameRule_Value { TRUE("true"), FALSE("false"); private final String value; @@ -107,7 +125,7 @@ public class TFM_GameRuleHandler public boolean toBoolean() { - return (this.value.equals(TFM_GameRule_Value.TRUE.value) ? true : false); + return (this.value.equals(TFM_GameRule_Value.TRUE.value)); } public static TFM_GameRule_Value fromBoolean(boolean in) diff --git a/src/me/totalfreedom/totalfreedommod/Heartbeat.java b/src/me/totalfreedom/totalfreedommod/Heartbeat.java new file mode 100644 index 00000000..0cd6bdd5 --- /dev/null +++ b/src/me/totalfreedom/totalfreedommod/Heartbeat.java @@ -0,0 +1,100 @@ +package me.totalfreedom.totalfreedommod; + +import me.totalfreedom.totalfreedommod.util.FUtil; +import lombok.Getter; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import me.totalfreedom.totalfreedommod.player.FPlayer; +import static me.totalfreedom.totalfreedommod.TotalFreedomMod.HEARTBEAT_RATE; +import me.totalfreedom.totalfreedommod.world.WorldWeather; +import net.pravian.aero.component.service.AbstractService; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitTask; + +public class Heartbeat extends AbstractService implements Runnable +{ + private long autoKickTime; + private BukkitTask task; + @Getter + private Long lastRan = null; + + public Heartbeat(TotalFreedomMod plugin) + { + super(plugin); + } + + @Override + public void onStart() + { + autoKickTime = (long) ConfigEntry.AUTOKICK_TIME.getInteger() * 1000L; + + task = server.getScheduler().runTaskTimer(plugin, this, HEARTBEAT_RATE * 20L, HEARTBEAT_RATE * 20L); + } + + @Override + protected void onStop() + { + server.getScheduler().cancelTask(task.getTaskId()); + task = null; + } + + @Override + public void run() + { + lastRan = System.currentTimeMillis(); + + final boolean doAwayKickCheck = ConfigEntry.AUTOKICK_ENABLED.getBoolean() + && plugin.esb.isEssentialsEnabled() + && ((server.getOnlinePlayers().size() / server.getMaxPlayers()) > ConfigEntry.AUTOKICK_THRESHOLD.getDouble()); + + for (Player player : server.getOnlinePlayers()) + { + final FPlayer playerdata = plugin.pl.getPlayer(player); + playerdata.resetMsgCount(); + playerdata.resetBlockDestroyCount(); + playerdata.resetBlockPlaceCount(); + + if (doAwayKickCheck) + { + final long lastActivity = plugin.esb.getLastActivity(player.getName()); + if (lastActivity > 0 && lastActivity + autoKickTime < System.currentTimeMillis()) + { + player.kickPlayer("Automatically kicked by server for inactivity."); + } + } + } + + if (ConfigEntry.AUTO_ENTITY_WIPE.getBoolean()) + { + FUtil.TFM_EntityWiper.wipeEntities(!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean(), false); + } + + if (ConfigEntry.DISABLE_WEATHER.getBoolean()) + { + for (World world : server.getWorlds()) + { + try + { + if (world == plugin.wm.adminworld.getWorld() && plugin.wm.adminworld.getWeatherMode() != WorldWeather.OFF) + { + continue; + } + } + catch (Exception ex) + { + } + + if (world.getWeatherDuration() > 0) + { + world.setThundering(false); + world.setWeatherDuration(0); + } + else if (world.getThunderDuration() > 0) + { + world.setStorm(false); + world.setThunderDuration(0); + } + } + } + } +} diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Jumppads.java b/src/me/totalfreedom/totalfreedommod/Jumppads.java similarity index 71% rename from src/me/StevenLawson/TotalFreedomMod/TFM_Jumppads.java rename to src/me/totalfreedom/totalfreedommod/Jumppads.java index 6c31cabd..06572a8d 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Jumppads.java +++ b/src/me/totalfreedom/totalfreedommod/Jumppads.java @@ -1,31 +1,50 @@ -package me.StevenLawson.TotalFreedomMod; +package me.totalfreedom.totalfreedommod; -import java.util.HashMap; +import com.google.common.collect.Maps; import java.util.Map; +import lombok.Getter; +import lombok.Setter; +import net.pravian.aero.component.service.AbstractService; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.util.Vector; -public class TFM_Jumppads +public class Jumppads extends AbstractService { - public static final Material BLOCK_ID; - public static final double DAMPING_COEFFICIENT; - public static final Map PUSH_MAP; - private static JumpPadMode mode; - private static double strength; + public static final Material BLOCK_ID = Material.WOOL; + public static final double DAMPING_COEFFICIENT = 0.8; + // + private final Map pushMap = Maps.newHashMap(); + // + @Getter + @Setter + private JumpPadMode mode = JumpPadMode.MADGEEK; + @Getter + @Setter + private double strength = 0.4; - static + public Jumppads(TotalFreedomMod plugin) { - BLOCK_ID = Material.WOOL; - DAMPING_COEFFICIENT = 0.8; - PUSH_MAP = new HashMap(); - mode = JumpPadMode.MADGEEK; - strength = 0.4; + super(plugin); } - public static void PlayerMoveEvent(PlayerMoveEvent event) + @Override + public void onStart() + { + + } + + @Override + public void onStop() + { + + } + + @EventHandler + public void onPlayerMove(PlayerMoveEvent event) { if (mode == JumpPadMode.OFF) { @@ -38,7 +57,7 @@ public class TFM_Jumppads if (mode == JumpPadMode.MADGEEK) { - Boolean canPush = PUSH_MAP.get(player); + Boolean canPush = pushMap.get(player); if (canPush == null) { canPush = true; @@ -55,7 +74,7 @@ public class TFM_Jumppads { canPush = true; } - PUSH_MAP.put(player, canPush); + pushMap.put(player, canPush); } else { @@ -95,30 +114,10 @@ public class TFM_Jumppads } } - public static JumpPadMode getMode() - { - return mode; - } - - public static void setMode(JumpPadMode mode) - { - TFM_Jumppads.mode = mode; - } - - public static double getStrength() - { - return strength; - } - - public static void setStrength(double strength) - { - TFM_Jumppads.strength = strength; - } - public static enum JumpPadMode { OFF(false), NORMAL(true), NORMAL_AND_SIDEWAYS(true), MADGEEK(true); - private boolean on; + private final boolean on; private JumpPadMode(boolean on) { diff --git a/src/me/totalfreedom/totalfreedommod/PermbanList.java b/src/me/totalfreedom/totalfreedommod/PermbanList.java new file mode 100644 index 00000000..6ce786a1 --- /dev/null +++ b/src/me/totalfreedom/totalfreedommod/PermbanList.java @@ -0,0 +1,45 @@ +package me.totalfreedom.totalfreedommod; + +import me.totalfreedom.totalfreedommod.util.FLog; +import com.google.common.collect.Sets; +import java.util.Set; +import lombok.Getter; +import me.totalfreedom.totalfreedommod.config.FConfig; +import net.pravian.aero.component.service.AbstractService; + +public class PermbanList extends AbstractService +{ + @Getter + private final Set permbannedNames = Sets.newHashSet(); + @Getter + private final Set permbannedIps = Sets.newHashSet(); + + public PermbanList(TotalFreedomMod plugin) + { + super(plugin); + } + + @Override + protected void onStart() + { + permbannedNames.clear(); + permbannedIps.clear(); + + final FConfig config = new FConfig(TotalFreedomMod.plugin, TotalFreedomMod.PERMBAN_FILENAME, true); + config.load(); + + for (String name : config.getKeys(false)) + { + permbannedNames.add(name.toLowerCase().trim()); + permbannedIps.addAll(config.getStringList(name)); + } + + FLog.info("Loaded " + permbannedNames.size() + " permanently banned usernames and " + permbannedIps.size() + " permanently banned IPs."); + } + + @Override + protected void onStop() + { + } + +} diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_ProtectedArea.java b/src/me/totalfreedom/totalfreedommod/ProtectArea.java similarity index 73% rename from src/me/StevenLawson/TotalFreedomMod/TFM_ProtectedArea.java rename to src/me/totalfreedom/totalfreedommod/ProtectArea.java index 0520b2a0..849ceb95 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_ProtectedArea.java +++ b/src/me/totalfreedom/totalfreedommod/ProtectArea.java @@ -1,5 +1,7 @@ -package me.StevenLawson.TotalFreedomMod; +package me.totalfreedom.totalfreedommod; +import me.totalfreedom.totalfreedommod.util.FLog; +import com.google.common.collect.Maps; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -11,28 +13,82 @@ import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.UUID; -import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import net.pravian.aero.component.service.AbstractService; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.util.Vector; -public class TFM_ProtectedArea +public class ProtectArea extends AbstractService { public static final double MAX_RADIUS = 50.0; - private static final Map PROTECTED_AREAS = new HashMap(); + // + private final Map areas = Maps.newHashMap(); - private TFM_ProtectedArea() + public ProtectArea(TotalFreedomMod plugin) { - throw new AssertionError(); + super(plugin); } - public static boolean isInProtectedArea(final Location modifyLocation) + @Override + protected void onStart() + { + if (!ConfigEntry.PROTECTAREA_ENABLED.getBoolean()) + { + return; + } + + File input = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PROTECTED_AREA_FILENAME); + try + { + if (input.exists()) + { + FileInputStream fis = new FileInputStream(input); + ObjectInputStream ois = new ObjectInputStream(fis); + areas.clear(); + areas.putAll((HashMap) ois.readObject()); + ois.close(); + fis.close(); + } + } + catch (Exception ex) + { + input.delete(); + FLog.severe(ex); + } + + cleanProtectedAreas(); + } + + @Override + protected void onStop() + { + save(); + } + + public void save() + { + try + { + FileOutputStream fos = new FileOutputStream(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PROTECTED_AREA_FILENAME)); + ObjectOutputStream oos = new ObjectOutputStream(fos); + oos.writeObject(areas); + oos.close(); + fos.close(); + } + catch (Exception ex) + { + FLog.severe(ex); + } + } + + public boolean isInProtectedArea(final Location modifyLocation) { boolean doSave = false; boolean inProtectedArea = false; - final Iterator> it = TFM_ProtectedArea.PROTECTED_AREAS.entrySet().iterator(); + final Iterator> it = areas.entrySet().iterator(); while (it.hasNext()) { @@ -72,12 +128,12 @@ public class TFM_ProtectedArea return inProtectedArea; } - public static boolean isInProtectedArea(final Vector min, final Vector max, final String worldName) + public boolean isInProtectedArea(final Vector min, final Vector max, final String worldName) { boolean doSave = false; boolean inProtectedArea = false; - final Iterator> it = TFM_ProtectedArea.PROTECTED_AREAS.entrySet().iterator(); + final Iterator> it = areas.entrySet().iterator(); while (it.hasNext()) { @@ -116,7 +172,7 @@ public class TFM_ProtectedArea return inProtectedArea; } - private static boolean cubeIntersectsSphere(Vector min, Vector max, Vector sphere, double radius) + private boolean cubeIntersectsSphere(Vector min, Vector max, Vector sphere, double radius) { double d = square(radius); @@ -148,31 +204,31 @@ public class TFM_ProtectedArea return d > 0; } - private static double square(double v) + private double square(double v) { return v * v; } - public static void addProtectedArea(String label, Location location, double radius) + public void addProtectedArea(String label, Location location, double radius) { - TFM_ProtectedArea.PROTECTED_AREAS.put(label.toLowerCase(), new SerializableProtectedRegion(location, radius)); + areas.put(label.toLowerCase(), new SerializableProtectedRegion(location, radius)); save(); } - public static void removeProtectedArea(String label) + public void removeProtectedArea(String label) { - TFM_ProtectedArea.PROTECTED_AREAS.remove(label.toLowerCase()); + areas.remove(label.toLowerCase()); save(); } - public static void clearProtectedAreas() + public void clearProtectedAreas() { clearProtectedAreas(true); } - public static void clearProtectedAreas(boolean createSpawnpointProtectedAreas) + public void clearProtectedAreas(boolean createSpawnpointProtectedAreas) { - TFM_ProtectedArea.PROTECTED_AREAS.clear(); + areas.clear(); if (createSpawnpointProtectedAreas) { @@ -182,11 +238,11 @@ public class TFM_ProtectedArea save(); } - public static void cleanProtectedAreas() + public void cleanProtectedAreas() { boolean doSave = false; - final Iterator> it = TFM_ProtectedArea.PROTECTED_AREAS.entrySet().iterator(); + final Iterator> it = areas.entrySet().iterator(); while (it.hasNext()) { @@ -207,75 +263,30 @@ public class TFM_ProtectedArea } } - public static Set getProtectedAreaLabels() + public Set getProtectedAreaLabels() { - return TFM_ProtectedArea.PROTECTED_AREAS.keySet(); + return areas.keySet(); } - public static void save() + public void autoAddSpawnpoints() { - try - { - FileOutputStream fos = new FileOutputStream(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PROTECTED_AREA_FILENAME)); - ObjectOutputStream oos = new ObjectOutputStream(fos); - oos.writeObject(TFM_ProtectedArea.PROTECTED_AREAS); - oos.close(); - fos.close(); - } - catch (Exception ex) - { - TFM_Log.severe(ex); - } - } - - @SuppressWarnings("unchecked") - public static void load() - { - if (!TFM_ConfigEntry.PROTECTAREA_ENABLED.getBoolean()) + if (!ConfigEntry.PROTECTAREA_ENABLED.getBoolean()) { return; } - File input = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PROTECTED_AREA_FILENAME); - try - { - if (input.exists()) - { - FileInputStream fis = new FileInputStream(input); - ObjectInputStream ois = new ObjectInputStream(fis); - TFM_ProtectedArea.PROTECTED_AREAS.clear(); - TFM_ProtectedArea.PROTECTED_AREAS.putAll((HashMap) ois.readObject()); - ois.close(); - fis.close(); - } - } - catch (Exception ex) - { - input.delete(); - TFM_Log.severe(ex); - } - - cleanProtectedAreas(); - } - - public static void autoAddSpawnpoints() - { - if (!TFM_ConfigEntry.PROTECTAREA_ENABLED.getBoolean()) - { - return; - } - - if (TFM_ConfigEntry.PROTECTAREA_SPAWNPOINTS.getBoolean()) + if (ConfigEntry.PROTECTAREA_SPAWNPOINTS.getBoolean()) { for (World world : Bukkit.getWorlds()) { - TFM_ProtectedArea.addProtectedArea("spawn_" + world.getName(), world.getSpawnLocation(), TFM_ConfigEntry.PROTECTAREA_RADIUS.getDouble()); + addProtectedArea("spawn_" + world.getName(), world.getSpawnLocation(), ConfigEntry.PROTECTAREA_RADIUS.getDouble()); } } } - public static class SerializableProtectedRegion implements Serializable + public class SerializableProtectedRegion implements Serializable { + private static final long serialVersionUID = 213123517828282L; private final double x, y, z; private final double radius; private final String worldName; @@ -319,7 +330,7 @@ public class TFM_ProtectedArea return radius; } - public static class CantFindWorldException extends Exception + public class CantFindWorldException extends Exception { private static final long serialVersionUID = 1L; diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_ServerInterface.java b/src/me/totalfreedom/totalfreedommod/ServerInterface.java similarity index 68% rename from src/me/StevenLawson/TotalFreedomMod/TFM_ServerInterface.java rename to src/me/totalfreedom/totalfreedommod/ServerInterface.java index 33ed6331..ede99627 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_ServerInterface.java +++ b/src/me/totalfreedom/totalfreedommod/ServerInterface.java @@ -1,34 +1,54 @@ -package me.StevenLawson.TotalFreedomMod; +package me.totalfreedom.totalfreedommod; +import me.totalfreedom.totalfreedommod.util.FUtil; +import me.totalfreedom.totalfreedommod.util.FSync; +import me.totalfreedom.totalfreedommod.util.FLog; import java.util.Arrays; import java.util.List; -import java.util.UUID; import java.util.regex.Pattern; -import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; -import me.StevenLawson.TotalFreedomMod.Listener.TFM_PlayerListener; +import me.totalfreedom.totalfreedommod.banning.FBan; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import me.totalfreedom.totalfreedommod.listener.PlayerListener; import net.minecraft.server.v1_8_R3.EntityPlayer; import net.minecraft.server.v1_8_R3.MinecraftServer; import net.minecraft.server.v1_8_R3.PropertyManager; +import net.pravian.aero.component.service.AbstractService; import org.bukkit.ChatColor; -import org.bukkit.Server; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.player.AsyncPlayerPreLoginEvent; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerLoginEvent.Result; -public class TFM_ServerInterface +public class ServerInterface extends AbstractService { public static final String COMPILE_NMS_VERSION = "v1_8_R3"; public static final Pattern USERNAME_REGEX = Pattern.compile("^[\\w\\d_]{3,20}$"); - public static void setOnlineMode(boolean mode) + public ServerInterface(TotalFreedomMod plugin) + { + super(plugin); + } + + @Override + protected void onStart() + { + } + + @Override + protected void onStop() + { + } + + public void setOnlineMode(boolean mode) { final PropertyManager manager = MinecraftServer.getServer().getPropertyManager(); manager.setProperty("online-mode", mode); manager.savePropertiesFile(); } - public static int purgeWhitelist() + public int purgeWhitelist() { String[] whitelisted = MinecraftServer.getServer().getPlayerList().getWhitelisted(); int size = whitelisted.length; @@ -43,34 +63,35 @@ public class TFM_ServerInterface } catch (Exception ex) { - TFM_Log.warning("Could not purge the whitelist!"); - TFM_Log.warning(ex); + FLog.warning("Could not purge the whitelist!"); + FLog.warning(ex); } return size; } - public static boolean isWhitelisted() + public boolean isWhitelisted() { return MinecraftServer.getServer().getPlayerList().getHasWhitelist(); } - public static List getWhitelisted() + public List getWhitelisted() { return Arrays.asList(MinecraftServer.getServer().getPlayerList().getWhitelisted()); } - public static String getVersion() + public String getVersion() { return MinecraftServer.getServer().getVersion(); } - public static void handlePlayerPreLogin(AsyncPlayerPreLoginEvent event) + @EventHandler(priority = EventPriority.HIGHEST) + public void onPlayerPreLogin(AsyncPlayerPreLoginEvent event) { final String ip = event.getAddress().getHostAddress().trim(); - final boolean isAdmin = TFM_AdminList.isSuperAdminSafe(null, ip); + final boolean isAdmin = plugin.al.getEntryByIp(ip) != null; // Check if the player is already online - for (Player onlinePlayer : TotalFreedomMod.server.getOnlinePlayers()) + for (Player onlinePlayer : server.getOnlinePlayers()) { if (!onlinePlayer.getName().equalsIgnoreCase(event.getName())) { @@ -84,19 +105,18 @@ public class TFM_ServerInterface else { event.allow(); - TFM_Sync.playerKick(onlinePlayer, "An admin just logged in with the username you are using."); + FSync.playerKick(onlinePlayer, "An admin just logged in with the username you are using."); } return; } } - public static void handlePlayerLogin(PlayerLoginEvent event) + @EventHandler(priority = EventPriority.HIGHEST) + public void onPlayerLogin(PlayerLoginEvent event) { - final Server server = TotalFreedomMod.server; final Player player = event.getPlayer(); final String username = player.getName(); final String ip = event.getAddress().getHostAddress().trim(); - final UUID uuid = TFM_UuidManager.newPlayer(player, ip); // Check username length if (username.length() < 3 || username.length() > TotalFreedomMod.MAX_USERNAME_LENGTH) @@ -113,18 +133,18 @@ public class TFM_ServerInterface } // Check force-IP match - if (TFM_ConfigEntry.FORCE_IP_ENABLED.getBoolean()) + if (ConfigEntry.FORCE_IP_ENABLED.getBoolean()) { final String hostname = event.getHostname().replace("\u0000FML\u0000", ""); // Forge fix - https://github.com/TotalFreedom/TotalFreedomMod/issues/493 - final String connectAddress = TFM_ConfigEntry.SERVER_ADDRESS.getString(); - final int connectPort = TotalFreedomMod.server.getPort(); + final String connectAddress = ConfigEntry.SERVER_ADDRESS.getString(); + final int connectPort = server.getPort(); if (!hostname.equalsIgnoreCase(connectAddress + ":" + connectPort) && !hostname.equalsIgnoreCase(connectAddress + ".:" + connectPort)) { - final int forceIpPort = TFM_ConfigEntry.FORCE_IP_PORT.getInteger(); + final int forceIpPort = 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 == TFM_PlayerListener.DEFAULT_PORT ? "" : ":" + forceIpPort))); + ConfigEntry.FORCE_IP_KICKMSG.getString() + .replace("%address%", ConfigEntry.SERVER_ADDRESS.getString() + (forceIpPort == PlayerListener.DEFAULT_PORT ? "" : ":" + forceIpPort))); return; } @@ -132,7 +152,7 @@ public class TFM_ServerInterface // Check if player is admin // 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 = plugin.al.getEntryByIp(ip) != null; // Validation below this point if (isAdmin) // Player is superadmin @@ -145,7 +165,7 @@ public class TFM_ServerInterface { for (Player onlinePlayer : server.getOnlinePlayers()) { - if (!TFM_AdminList.isSuperAdmin(onlinePlayer)) + if (!plugin.al.isAdmin(onlinePlayer)) { onlinePlayer.kickPlayer("You have been kicked to free up room for an admin."); count--; @@ -176,7 +196,7 @@ public class TFM_ServerInterface } // Admin-only mode - if (TFM_ConfigEntry.ADMIN_ONLY_MODE.getBoolean()) + if (ConfigEntry.ADMIN_ONLY_MODE.getBoolean()) { event.disallow(Result.KICK_OTHER, "Server is temporarily open to admins only."); return; @@ -199,46 +219,42 @@ public class TFM_ServerInterface } } - // UUID ban - if (TFM_BanManager.isUuidBanned(uuid)) - { - final TFM_Ban ban = TFM_BanManager.getByUuid(uuid); - event.disallow(Result.KICK_OTHER, ban.getKickMessage()); - return; - } - - // IP ban - if (TFM_BanManager.isIpBanned(ip)) - { - final TFM_Ban ban = TFM_BanManager.getByIp(ip); - event.disallow(Result.KICK_OTHER, ban.getKickMessage()); - return; - } - // Permbanned IPs - for (String testIp : TFM_PermbanList.getPermbannedIps()) + for (String testIp : plugin.pb.getPermbannedIps()) { - if (TFM_Util.fuzzyIpMatch(testIp, ip, 4)) + if (FUtil.fuzzyIpMatch(testIp, ip, 4)) { event.disallow(Result.KICK_OTHER, ChatColor.RED + "Your IP address is permanently banned from this server.\n" + "Release procedures are available at\n" - + ChatColor.GOLD + TFM_ConfigEntry.SERVER_PERMBAN_URL.getString()); + + ChatColor.GOLD + ConfigEntry.SERVER_PERMBAN_URL.getString()); return; } } // Permbanned usernames - for (String testPlayer : TFM_PermbanList.getPermbannedPlayers()) + for (String testPlayer : plugin.pb.getPermbannedNames()) { if (testPlayer.equalsIgnoreCase(username)) { event.disallow(Result.KICK_OTHER, ChatColor.RED + "Your username is permanently banned from this server.\n" + "Release procedures are available at\n" - + ChatColor.GOLD + TFM_ConfigEntry.SERVER_PERMBAN_URL.getString()); + + ChatColor.GOLD + ConfigEntry.SERVER_PERMBAN_URL.getString()); return; } } + + // Regular ban + FBan ban = plugin.bm.getByUsername(username); + if (ban == null) + { + ban = plugin.bm.getByIp(ip); + } + + if (ban != null) + { + event.disallow(Result.KICK_OTHER, ban.bakeKickMessage()); + } } } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_ServiceChecker.java b/src/me/totalfreedom/totalfreedommod/ServiceChecker.java similarity index 73% rename from src/me/StevenLawson/TotalFreedomMod/TFM_ServiceChecker.java rename to src/me/totalfreedom/totalfreedommod/ServiceChecker.java index 18b07f11..6c2823f7 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_ServiceChecker.java +++ b/src/me/totalfreedom/totalfreedommod/ServiceChecker.java @@ -1,40 +1,46 @@ -package me.StevenLawson.TotalFreedomMod; +package me.totalfreedom.totalfreedommod; +import me.totalfreedom.totalfreedommod.util.FUtil; +import me.totalfreedom.totalfreedommod.util.FLog; +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.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; +import lombok.Getter; +import lombok.Setter; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import net.pravian.aero.component.service.AbstractService; 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 TFM_ServiceChecker +public class ServiceChecker extends AbstractService { - public static final Map services; - private static URL url; - private static String lastCheck; - private static String version; - private TFM_ServiceChecker() - { - throw new AssertionError(); - } + @Getter + private final Map services = Maps.newHashMap(); + // + private BukkitTask task; + private URL url = null; + @Getter + private String lastCheck = "Never"; + @Getter + private String version = "Mojang"; - static + public ServiceChecker(TotalFreedomMod plugin) { - lastCheck = "Unknown"; - version = "1.0-Mojang"; - services = new HashMap(); + 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")); @@ -44,9 +50,10 @@ public class TFM_ServiceChecker services.put("session.minecraft.net", new ServiceStatus("Minecraft Sessions (Legacy)")); } - public static void start() + @Override + protected void onStart() { - final String serviceCheckerURL = TFM_ConfigEntry.SERVICE_CHECKER_URL.getString(); + final String serviceCheckerURL = ConfigEntry.SERVICE_CHECKER_URL.getString(); if (serviceCheckerURL == null || serviceCheckerURL.isEmpty()) { @@ -59,14 +66,30 @@ public class TFM_ServiceChecker } catch (MalformedURLException ex) { - TFM_Log.severe("Invalid ServiceChecker URL, disabling service checker"); + FLog.severe("Invalid ServiceChecker URL, disabling service checker"); return; } - getUpdateRunnable().runTaskTimerAsynchronously(TotalFreedomMod.plugin, 40L, TotalFreedomMod.SERVICE_CHECKER_RATE * 20L); + task = getUpdateRunnable().runTaskTimerAsynchronously(TotalFreedomMod.plugin, 40L, TotalFreedomMod.SERVICE_CHECKER_RATE * 20L); } - public static BukkitRunnable getUpdateRunnable() + @Override + protected void onStop() + { + try + { + task.cancel(); + } + catch (Exception ex) + { + } + finally + { + task = null; + } + } + + public BukkitRunnable getUpdateRunnable() { return new BukkitRunnable() { @@ -87,8 +110,8 @@ public class TFM_ServiceChecker } catch (Exception ex) { - TFM_Log.severe("Error updating mojang services from " + url); - TFM_Log.severe(ex); + FLog.severe("Error updating mojang services from " + url); + FLog.severe(ex); return; } @@ -135,13 +158,13 @@ public class TFM_ServiceChecker } if (lastCheck.equals("Unknown")) { - lastCheck = TFM_Util.dateToString(new Date()); + lastCheck = FUtil.dateToString(new Date()); } } }; } - public static List getAllStatuses() + public List getAllStatuses() { List servicesList = new ArrayList(); for (String key : services.keySet()) @@ -151,21 +174,17 @@ public class TFM_ServiceChecker return servicesList; } - public static String getLastCheck() + public class ServiceStatus { - return lastCheck; - } - - public static String getVersion() - { - return version; - } - - public static class ServiceStatus - { - private String name; + @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) @@ -173,16 +192,6 @@ public class TFM_ServiceChecker this.name = name; } - public String getName() - { - return name; - } - - public String getUptime() - { - return uptime; - } - public float getUptimeFloat() { return Float.parseFloat(uptime); @@ -193,21 +202,11 @@ public class TFM_ServiceChecker return (getUptimeFloat() > 95 ? ChatColor.GREEN : (getUptimeFloat() > 90 ? ChatColor.GOLD : ChatColor.RED)); } - public ChatColor getColor() - { - return color; - } - - public String getMessage() - { - return message; - } - public String getFormattedStatus() { String status = ChatColor.BLUE + "- " + ChatColor.GRAY + name + ChatColor.WHITE + ": " + color + message + ChatColor.WHITE; - if (!TFM_ServiceChecker.version.contains("Mojang")) + if (!version.contains("Mojang")) { status += " (" + getUptimeColor() + getUptime() + ChatColor.WHITE + "%)"; } @@ -215,16 +214,6 @@ public class TFM_ServiceChecker return status; } - public void setUptime(String uptime) - { - this.uptime = uptime; - } - - public void setColor(ChatColor color) - { - this.color = color; - } - public void setColor(String color) { if ("green".equals(color)) @@ -240,10 +229,6 @@ public class TFM_ServiceChecker this.color = ChatColor.RED; } } - - public void setMessage(String message) - { - this.message = message; - } } + } diff --git a/src/me/totalfreedom/totalfreedommod/TotalFreedomMod.java b/src/me/totalfreedom/totalfreedommod/TotalFreedomMod.java new file mode 100644 index 00000000..4a1e582a --- /dev/null +++ b/src/me/totalfreedom/totalfreedommod/TotalFreedomMod.java @@ -0,0 +1,257 @@ +package me.totalfreedom.totalfreedommod; + +import me.totalfreedom.totalfreedommod.util.FUtil; +import me.totalfreedom.totalfreedommod.PermbanList; +import me.totalfreedom.totalfreedommod.ProtectArea; +import me.totalfreedom.totalfreedommod.ServiceChecker; +import me.totalfreedom.totalfreedommod.ServerInterface; +import me.totalfreedom.totalfreedommod.Jumppads; +import me.totalfreedom.totalfreedommod.GameRuleHandler; +import me.totalfreedom.totalfreedommod.Heartbeat; +import me.totalfreedom.totalfreedommod.util.FLog; +import me.totalfreedom.totalfreedommod.FrontDoor; +import me.totalfreedom.totalfreedommod.Announcer; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import me.totalfreedom.totalfreedommod.admin.AdminList; +import me.totalfreedom.totalfreedommod.banning.BanManager; +import me.totalfreedom.totalfreedommod.bridge.BukkitTelnetBridge; +import me.totalfreedom.totalfreedommod.bridge.EssentialsBridge; +import me.totalfreedom.totalfreedommod.bridge.WorldEditBridge; +import me.totalfreedom.totalfreedommod.commandblocker.CommandBlocker; +import me.totalfreedom.totalfreedommod.commands.CommandLoader; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon; +import me.totalfreedom.totalfreedommod.listener.BlockListener; +import me.totalfreedom.totalfreedommod.listener.EntityListener; +import me.totalfreedom.totalfreedommod.listener.PlayerListener; +import me.totalfreedom.totalfreedommod.listener.ServerListener; +import me.totalfreedom.totalfreedommod.listener.WeatherListener; +import me.totalfreedom.totalfreedommod.permission.RankManager; +import me.totalfreedom.totalfreedommod.player.PlayerList; +import me.totalfreedom.totalfreedommod.rollback.RollbackManager; +import me.totalfreedom.totalfreedommod.world.TFM_WorldManager; +import net.pravian.aero.component.service.ServiceManager; +import net.pravian.aero.plugin.AeroPlugin; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; +import org.mcstats.Metrics; + +public class TotalFreedomMod extends AeroPlugin +{ + public static final long HEARTBEAT_RATE = 5L; // Seconds + public static final long SERVICE_CHECKER_RATE = 120L; + public static final int MAX_USERNAME_LENGTH = 20; + // + public static final String CONFIG_FILENAME = "config.yml"; + public static final String SUPERADMIN_FILENAME = "superadmin.yml"; + public static final String PERMBAN_FILENAME = "permban.yml"; + public static final String UUID_FILENAME = "uuids.db"; + public static final String PROTECTED_AREA_FILENAME = "protectedareas.dat"; + public static final String SAVED_FLAGS_FILENAME = "savedflags.dat"; + // + public static final BuildProperties build = new BuildProperties(); + // + public static TotalFreedomMod plugin; + public static String pluginName; + public static String pluginVersion; + // + public static boolean lockdownEnabled = false; + public static Map fuckoffEnabledFor = new HashMap(); + // + // Services + public ServiceManager services; + public ServerInterface si; + public AdminList al; + public RankManager rm; + public BanManager bm; + public PlayerList pl; + public CommandLoader cl; + public CommandBlocker cb; + public Announcer an; + public PermbanList pb; + public ProtectArea pa; + public ServiceChecker sc; + public GameRuleHandler gr; + public RollbackManager rb; + public Heartbeat hb; + public Jumppads jp; + public FrontDoor fd; + public HTTPDaemon hd; + public TFM_WorldManager wm; + // + // Bridges + public ServiceManager bridges; + public BukkitTelnetBridge btb; + public EssentialsBridge esb; + public WorldEditBridge web; + + @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(); + + services = new ServiceManager(plugin); + si = services.registerService(ServerInterface.class); + al = services.registerService(AdminList.class); + rm = services.registerService(RankManager.class); + bm = services.registerService(BanManager.class); + pl = services.registerService(PlayerList.class); + cl = services.registerService(CommandLoader.class); + cb = services.registerService(CommandBlocker.class); + an = services.registerService(Announcer.class); + pb = services.registerService(PermbanList.class); + pa = services.registerService(ProtectArea.class); + sc = services.registerService(ServiceChecker.class); + gr = services.registerService(GameRuleHandler.class); + rb = services.registerService(RollbackManager.class); + hb = services.registerService(Heartbeat.class); + jp = services.registerService(Jumppads.class); + fd = services.registerService(FrontDoor.class); + hd = services.registerService(HTTPDaemon.class); + wm = services.registerService(TFM_WorldManager.class); + + bridges = new ServiceManager(plugin); + btb = bridges.registerService(BukkitTelnetBridge.class); + esb = bridges.registerService(EssentialsBridge.class); + web = bridges.registerService(WorldEditBridge.class); + } + + @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.builder); + + final FUtil.MethodTimer timer = new FUtil.MethodTimer(); + timer.start(); + + if (!ServerInterface.COMPILE_NMS_VERSION.equals(FUtil.getNmsVersion())) + { + FLog.warning(pluginName + " is compiled for " + ServerInterface.COMPILE_NMS_VERSION + " but the server is running " + + "version " + FUtil.getNmsVersion() + "!"); + FLog.warning("This might result in unexpected behaviour!"); + } + + FUtil.deleteCoreDumps(); + FUtil.deleteFolder(new File("./_deleteme")); + + // Create backups + FUtil.createBackups(CONFIG_FILENAME, true); + FUtil.createBackups(SUPERADMIN_FILENAME); + FUtil.createBackups(PERMBAN_FILENAME); + + // Start services and bridges + services.start(); + bridges.start(); + + // Register listeners + register(EntityListener.class); + register(BlockListener.class); + register(PlayerListener.class); + register(WeatherListener.class); + register(ServerListener.class); + + // Disable weather + if (ConfigEntry.DISABLE_WEATHER.getBoolean()) + { + for (World world : server.getWorlds()) + { + world.setThundering(false); + world.setStorm(false); + world.setThunderDuration(0); + world.setWeatherDuration(0); + } + } + + timer.update(); + + FLog.info("Version " + pluginVersion + " for " + ServerInterface.COMPILE_NMS_VERSION + " enabled in " + timer.getTotal() + "ms"); + + // Metrics @ http://mcstats.org/plugin/TotalFreedomMod + try + { + final Metrics metrics = new Metrics(plugin); + metrics.start(); + } + catch (IOException ex) + { + FLog.warning("Failed to submit metrics data: " + ex.getMessage()); + } + + // Add spawnpoints later - https://github.com/TotalFreedom/TotalFreedomMod/issues/438 + new BukkitRunnable() + { + @Override + public void run() + { + plugin.pa.autoAddSpawnpoints(); + } + }.runTaskLater(plugin, 60L); + } + + @Override + public void disable() + { + // Stop services and bridges + services.stop(); + bridges.stop(); + + server.getScheduler().cancelTasks(plugin); + + FLog.info("Plugin disabled"); + TotalFreedomMod.plugin = null; + } + + public static class BuildProperties + { + public String builder; + public String number; + public String head; + public String date; + + public void load() + { + try + { + final InputStream in = plugin.getResource("build.properties"); + + final Properties props = new Properties(); + props.load(in); + in.close(); + + builder = props.getProperty("program.builder", "unknown"); + number = props.getProperty("program.buildnumber", "1"); + head = props.getProperty("program.buildhead", "unknown"); + date = props.getProperty("program.builddate", "unknown"); + + } + catch (Exception ex) + { + FLog.severe("Could not load build properties! Did you compile with Netbeans/ANT?"); + FLog.severe(ex); + } + } + + public String formattedVersion() + { + return pluginVersion + "." + number + " (" + head + ")"; + } + } + +} diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_TwitterHandler.java b/src/me/totalfreedom/totalfreedommod/TwitterHandler.java similarity index 58% rename from src/me/StevenLawson/TotalFreedomMod/TFM_TwitterHandler.java rename to src/me/totalfreedom/totalfreedommod/TwitterHandler.java index a9074843..a88fa063 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_TwitterHandler.java +++ b/src/me/totalfreedom/totalfreedommod/TwitterHandler.java @@ -1,16 +1,18 @@ -package me.StevenLawson.TotalFreedomMod; +package me.totalfreedom.totalfreedommod; +import me.totalfreedom.totalfreedommod.util.FUtil; +import me.totalfreedom.totalfreedommod.util.FLog; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; -import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; -public class TFM_TwitterHandler +public class TwitterHandler { - private TFM_TwitterHandler() + private TwitterHandler() { throw new AssertionError(); } @@ -39,31 +41,31 @@ public class TFM_TwitterHandler final String reply = delTwitter(targetName); if ("ok".equals(reply)) { - TFM_Util.adminAction(sender.getName(), "Removing " + targetName + " from TwitterBot", true); + FUtil.adminAction(sender.getName(), "Removing " + targetName + " from TwitterBot", true); } else if ("disabled".equals(reply)) { - TFM_Util.playerMsg(sender, "Warning: Could not check if player has a twitter handle!"); - TFM_Util.playerMsg(sender, "TwitterBot has been temporarily disabled, please wait until it gets re-enabled", ChatColor.RED); + FUtil.playerMsg(sender, "Warning: Could not check if player has a twitter handle!"); + FUtil.playerMsg(sender, "TwitterBot has been temporarily disabled, please wait until it gets re-enabled", ChatColor.RED); } else if ("failed".equals(reply)) { - TFM_Util.playerMsg(sender, "Warning: Could not check if player has a twitter handle!"); - TFM_Util.playerMsg(sender, "There was a problem querying the database, please let a developer know.", ChatColor.RED); + FUtil.playerMsg(sender, "Warning: Could not check if player has a twitter handle!"); + FUtil.playerMsg(sender, "There was a problem querying the database, please let a developer know.", ChatColor.RED); } else if ("false".equals(reply)) { - TFM_Util.playerMsg(sender, "Warning: Could not check if player has a twitter handle!"); - TFM_Util.playerMsg(sender, "There was a problem with the database, please let a developer know.", ChatColor.RED); + FUtil.playerMsg(sender, "Warning: Could not check if player has a twitter handle!"); + FUtil.playerMsg(sender, "There was a problem with the database, please let a developer know.", ChatColor.RED); } else if ("cannotauth".equals(reply)) { - TFM_Util.playerMsg(sender, "Warning: Could not check if player has a twitter handle!"); - TFM_Util.playerMsg(sender, "The database password is incorrect, please let a developer know.", ChatColor.RED); + FUtil.playerMsg(sender, "Warning: Could not check if player has a twitter handle!"); + FUtil.playerMsg(sender, "The database password is incorrect, please let a developer know.", ChatColor.RED); } else if ("notfound".equals(reply)) { - TFM_Util.playerMsg(sender, targetName + " did not have a twitter handle registered to their name.", ChatColor.GREEN); + FUtil.playerMsg(sender, targetName + " did not have a twitter handle registered to their name.", ChatColor.GREEN); } } @@ -81,8 +83,8 @@ public class TFM_TwitterHandler { String line = "failed"; - final String twitterbotURL = TFM_ConfigEntry.TWITTERBOT_URL.getString(); - final String twitterbotSecret = TFM_ConfigEntry.TWITTERBOT_SECRET.getString(); + final String twitterbotURL = ConfigEntry.TWITTERBOT_URL.getString(); + final String twitterbotSecret = ConfigEntry.TWITTERBOT_SECRET.getString(); if (twitterbotURL != null && twitterbotSecret != null && !twitterbotURL.isEmpty() && !twitterbotSecret.isEmpty()) { @@ -97,7 +99,7 @@ public class TFM_TwitterHandler } catch (Exception ex) { - TFM_Log.severe(ex); + FLog.severe(ex); } } diff --git a/src/me/totalfreedom/totalfreedommod/admin/Admin.java b/src/me/totalfreedom/totalfreedommod/admin/Admin.java new file mode 100644 index 00000000..0895d104 --- /dev/null +++ b/src/me/totalfreedom/totalfreedommod/admin/Admin.java @@ -0,0 +1,145 @@ +package me.totalfreedom.totalfreedommod.admin; + +import com.google.common.collect.Lists; +import java.util.Date; +import java.util.List; +import lombok.Getter; +import lombok.Setter; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.util.FUtil; +import net.pravian.aero.base.ConfigLoadable; +import net.pravian.aero.base.ConfigSavable; +import net.pravian.aero.base.Validatable; +import net.pravian.aero.util.Ips; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.Validate; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.entity.Player; + +public class Admin implements ConfigLoadable, ConfigSavable, Validatable +{ + @Getter + private String configKey; + @Getter + @Setter + private String name; + @Getter + @Setter + private boolean activated = true; + @Getter + @Setter + private PlayerRank rank = PlayerRank.SUPER_ADMIN; + @Getter + private final List ips = Lists.newArrayList(); + @Getter + @Setter + private Date lastLogin = new Date(); + @Getter + @Setter + private String loginMessage = null; + + public Admin(Player player) + { + this.configKey = player.getName().toLowerCase(); + this.name = player.getName(); + this.ips.add(Ips.getIp(player)); + } + + public Admin(String configKey) + { + this.configKey = configKey; + } + + @Override + public String toString() + { + 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") + .append("- Rank: ").append(rank.getName()).append("\n") + .append("- Is Activated: ").append(activated); + + return output.toString(); + } + + public void loadFrom(Player player) + { + configKey = player.getName().toLowerCase(); + name = player.getName(); + ips.clear(); + ips.add(Ips.getIp(player)); + } + + @Override + public void loadFrom(ConfigurationSection cs) + { + name = cs.getString("username", configKey); + activated = cs.getBoolean("active", true); + rank = PlayerRank.forString(cs.getString("rank")); + ips.clear(); + ips.addAll(cs.getStringList("ips")); + lastLogin = FUtil.stringToDate(cs.getString("last_login")); + loginMessage = cs.getString("login_message", null); + } + + @Override + public void saveTo(ConfigurationSection cs) + { + Validate.isTrue(isValid(), "Could not save admin entry: " + name + ". Entry not valid!"); + cs.set("username", name); + cs.set("active", activated); + cs.set("rank", rank.toString()); + cs.set("ips", ips); + cs.set("last_login", lastLogin); + cs.set("login_message", null); + } + + public boolean isMinimum(PlayerRank pRank) + { + return rank.ordinal() >= pRank.ordinal(); + } + + // Util IP methods + public void addIp(String ip) + { + if (!ips.contains(ip)) + { + ips.add(ip); + } + } + + public void addIps(List ips) + { + for (String ip : ips) + { + addIp(ip); + } + } + + public void removeIp(String ip) + { + if (ips.contains(ip)) + { + ips.remove(ip); + } + } + + public void clearIPs() + { + ips.clear(); + } + + @Override + public boolean isValid() + { + return configKey != null + && name != null + && rank != null + && !ips.isEmpty() + && lastLogin != null; + } +} diff --git a/src/me/totalfreedom/totalfreedommod/admin/AdminList.java b/src/me/totalfreedom/totalfreedommod/admin/AdminList.java new file mode 100644 index 00000000..2b6c3b14 --- /dev/null +++ b/src/me/totalfreedom/totalfreedommod/admin/AdminList.java @@ -0,0 +1,411 @@ +package me.totalfreedom.totalfreedommod.admin; + +import com.google.common.base.Function; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import java.util.Date; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; +import lombok.Getter; +import me.totalfreedom.totalfreedommod.commands.Command_logs; +import me.totalfreedom.totalfreedommod.config.FConfig; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.util.FLog; +import me.totalfreedom.totalfreedommod.TwitterHandler; +import me.totalfreedom.totalfreedommod.util.FUtil; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import net.pravian.aero.component.service.AbstractService; +import net.pravian.aero.util.Ips; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.ServicePriority; + +public class AdminList extends AbstractService +{ + @Getter + private final Map allAdmins = Maps.newHashMap(); // Includes disabled admins + // Only active admins below + @Getter + private final Set activeAdmins = Sets.newHashSet(); + private final Map nameTable = Maps.newHashMap(); + private final Map ipTable = Maps.newHashMap(); + // + private int cleanThreshold = 24 * 7; // 1 Week in hours + private final FConfig config; + + public AdminList(TotalFreedomMod plugin) + { + super(plugin); + + this.config = new FConfig(TotalFreedomMod.plugin, TotalFreedomMod.SUPERADMIN_FILENAME, true); + } + + @Override + protected void onStart() + { + load(); + + server.getServicesManager().register(Function.class, new Function() + { + @Override + public Boolean apply(Player player) + { + return isAdmin(player); + } + }, plugin, ServicePriority.Normal); + } + + @Override + protected void onStop() + { + save(); + } + + public void load() + { + config.load(); + + allAdmins.clear(); + for (String key : config.getKeys(true)) + { + Admin admin = new Admin(key); + admin.loadFrom(config.getConfigurationSection(key)); + + if (!admin.isValid()) + { + FLog.warning("Could not load admin: " + key + ". Missing details!"); + continue; + } + + allAdmins.put(key, admin); + } + + updateTables(); + FLog.info("Loaded " + nameTable.size() + " admins (" + nameTable.size() + " active) and " + ipTable.size() + " IPs."); + } + + public void save() + { + // Clear the config + for (String key : config.getKeys(false)) + { + config.set(key, null); + } + + for (Admin admin : allAdmins.values()) + { + admin.saveTo(config.createSection(admin.getConfigKey())); + } + + 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); + } + + public boolean isAdmin(CommandSender sender) + { + if (!(sender instanceof Player)) + { + return true; + } + + return getAdmin((Player) sender) != null; + } + + public boolean isSeniorAdmin(CommandSender sender) + { + Admin admin = getAdmin(sender); + if (admin == null) + { + return false; + } + + return admin.getRank().ordinal() >= PlayerRank.SENIOR_ADMIN.ordinal(); + } + + public Admin getAdmin(CommandSender sender) + { + if (sender instanceof Player) + { + return getAdmin((Player) sender); + } + + return getEntryByName(sender.getName()); + } + + public Admin getAdmin(Player player) + { + String ip = Ips.getIp(player); + Admin admin = getEntryByIp(ip, true); + + if (admin == null && Bukkit.getOnlineMode()) + { + admin = getEntryByName(player.getName()); + + // Add new IP + if (admin != null) + { + admin.addIp(ip); + save(admin); + } + } + + return admin; + } + + public Admin getEntryByName(String name) + { + return nameTable.get(name.toLowerCase()); + } + + public Admin getEntryByIp(String ip) + { + return getEntryByIp(ip, false); + } + + public Admin getEntryByIp(String needleIp, boolean fuzzy) + { + Admin admin = ipTable.get(needleIp); + + if (admin != null || !fuzzy) + { + return admin; + } + + for (String ip : ipTable.keySet()) + { + if (FUtil.fuzzyIpMatch(needleIp, ip, 3)) + { + return ipTable.get(ip); + } + } + return admin; + } + + public void updateLastLogin(Player player) + { + final Admin admin = getAdmin(player); + if (admin == null) + { + return; + } + + admin.setLastLogin(new Date()); + admin.setName(player.getName()); + save(admin); + } + + public boolean isAdminImpostor(Player player) + { + return getEntryByName(player.getName()) != null && !isAdmin(player); + } + + public boolean isIdentityMatched(Player player) + { + if (Bukkit.getOnlineMode()) + { + return true; + } + + Admin admin = getAdmin(player); + return admin == null ? false : admin.getName().equalsIgnoreCase(player.getName()); + } + + public boolean addAdmin(Admin admin) + { + return addAdmin(admin, false); + } + + public boolean addAdmin(Admin admin, boolean overwrite) + { + final String key = admin.getConfigKey(); + + if (!overwrite && allAdmins.containsKey(key)) + { + return false; + } + + // Store admin, update views + allAdmins.put(key, admin); + updateTables(); + + // Save admin + admin.saveTo(config.createSection(key)); + config.save(); + + return true; + } + + public boolean removeAdmin(Admin admin) + { + + // Remove admin, update views + if (allAdmins.remove(admin.getName().toLowerCase()) == null) + { + return false; + } + updateTables(); + + // 'Unsave' admin + config.set(admin.getConfigKey(), null); + config.save(); + + return true; + } + + public void updateTables() + { + activeAdmins.clear(); + nameTable.clear(); + ipTable.clear(); + + for (Admin admin : allAdmins.values()) + { + if (!admin.isActivated()) + { + continue; + } + + activeAdmins.add(admin); + nameTable.put(admin.getName().toLowerCase(), admin); + + for (String ip : admin.getIps()) + { + ipTable.put(ip, admin); + } + + } + + plugin.wm.adminworld.wipeAccessCache(); + } + + public Set getAdminNames() + { + return nameTable.keySet(); + } + + public Set getAdminIps() + { + return ipTable.keySet(); + } + + /* + public void addAdmin(OfflinePlayer player) + { + final String name = player.getName().toLowerCase(); + final String ip = TFM_Util.getIp(player); + final boolean canSuperIp = !TFM_MainConfig.getList(TFM_ConfigEntry.NOADMIN_IPS).contains(ip); + + if (nameTable.containsKey(name)) + { + final Admin superadmin = nameTable.; + superadmin.setActivated(true); + + if (player.isOnline()) + { + superadmin.setLastLogin(new Date()); + + if (ip != null && canSuperIp) + { + superadmin.addIp(ip); + } + } + + save(); + updateTables(); + return; + } + + if (ip == null) + { + TFM_Log.severe("Could not add superadmin: " + TFM_Util.formatPlayer(player)); + TFM_Log.severe("Could not retrieve IP!"); + return; + } + + if (!canSuperIp) + { + TFM_Log.warning("Could not add superadmin: " + TFM_Util.formatPlayer(player)); + TFM_Log.warning("IP " + ip + " may not be supered."); + return; + } + + final Admin superadmin = new Admin( + uuid, + player.getName(), + new Date(), + "", + false, + false, + true); + superadmin.addIp(ip); + + nameTable.put(uuid, superadmin); + + updateTables(); + } + + public void removeAdmin(OfflinePlayer player) + { + final UUID uuid = TFM_UuidManager.getUniqueId(player); + + if (!nameTable.containsKey(uuid)) + { + TFM_Log.warning("Could not remove admin: " + TFM_Util.formatPlayer(player)); + TFM_Log.warning("Player is not an admin!"); + return; + } + + final Admin superadmin = nameTable.get(uuid); + superadmin.setActivated(false); + Command_logs.deactivateSuperadmin(superadmin); + + updateTables(); + }*/ + public void deactivateOldEntries(boolean verbose) + { + for (Admin admin : allAdmins.values()) + { + if (!admin.isActivated() || admin.getRank() == PlayerRank.SENIOR_ADMIN) + { + continue; + } + + final Date lastLogin = admin.getLastLogin(); + final long lastLoginHours = TimeUnit.HOURS.convert(new Date().getTime() - lastLogin.getTime(), TimeUnit.MILLISECONDS); + + if (lastLoginHours < cleanThreshold) + { + continue; + } + + if (verbose) + { + FUtil.adminAction("TotalFreedomMod", "Deactivating superadmin " + admin.getName() + ", inactive for " + lastLoginHours + " hours.", true); + } + + admin.setActivated(false); + Command_logs.deactivateSuperadmin(admin); + TwitterHandler.delTwitter(admin.getName()); + } + + save(); + updateTables(); + } +} diff --git a/src/me/totalfreedom/totalfreedommod/banning/BanManager.java b/src/me/totalfreedom/totalfreedommod/banning/BanManager.java new file mode 100644 index 00000000..69caacb2 --- /dev/null +++ b/src/me/totalfreedom/totalfreedommod/banning/BanManager.java @@ -0,0 +1,255 @@ +package me.totalfreedom.totalfreedommod.banning; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import me.totalfreedom.totalfreedommod.util.FLog; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import net.pravian.aero.component.service.AbstractService; +import net.pravian.aero.config.YamlConfig; +import net.pravian.aero.util.Ips; + +public class BanManager extends AbstractService +{ + private final Set bans = Sets.newHashSet(); + private final Map ipBans = Maps.newHashMap(); + private final Map nameBans = Maps.newHashMap(); + private final List unbannableUsernames = Lists.newArrayList(); + // + private final YamlConfig config; + + public BanManager(TotalFreedomMod plugin) + { + super(plugin); + this.config = new YamlConfig(TotalFreedomMod.plugin, "bans.yml"); + } + + @Override + protected void onStart() + { + load(); + } + + @Override + protected void onStop() + { + saveAll(); + } + + public void load() + { + config.load(); + + bans.clear(); + for (String id : config.getKeys(false)) + { + if (!config.isConfigurationSection(id)) + { + FLog.warning("Could not load username ban: " + id + ". Invalid format!"); + continue; + } + + FBan ban = new FBan(); + ban.loadFrom(config.getConfigurationSection(id)); + + if (!ban.isValid()) + { + FLog.warning("Not adding username ban: " + id + ". Missing information."); + continue; + } + + bans.add(ban); + } + + // Remove expired bans, repopulate ipBans and nameBans, + updateViews(); + + FLog.info("Loaded " + ipBans.size() + " IP bans and " + nameBans.size() + " username bans"); + + // Load unbannable usernames + unbannableUsernames.clear(); + unbannableUsernames.addAll((Collection) ConfigEntry.UNBANNABLE_USERNAMES.getList()); + FLog.info("Loaded " + unbannableUsernames.size() + " unbannable usernames."); + + } + + private void updateViews() + { + + // Remove expired bans + for (Iterator it = bans.iterator(); it.hasNext();) + { + if (it.next().isExpired()) + { + it.remove(); + } + } + + ipBans.clear(); + nameBans.clear(); + for (FBan ban : bans) + { + if (ban.hasUsername()) + { + nameBans.put(ban.getUsername().toLowerCase(), ban); + } + + if (ban.hasIps()) + { + for (String ip : ban.getIps()) + { + ipBans.put(ip, ban); + } + } + } + } + + public void saveAll() + { + // Remove expired + updateViews(); + + for (FBan ban : bans) + { + ban.saveTo(config.createSection(String.valueOf(ban.hashCode()))); + } + + // Save config + config.save(); + } + + public Collection getIpBans() + { + return Collections.unmodifiableCollection(ipBans.values()); + } + + public Collection getUsernameBans() + { + return Collections.unmodifiableCollection(nameBans.values()); + } + + public FBan getByIp(String ip) + { + final FBan directBan = ipBans.get(ip); + if (directBan != null && !directBan.isExpired()) + { + return directBan; + } + + // Match fuzzy IP + for (FBan loopBan : ipBans.values()) + { + if (loopBan.isExpired()) + { + continue; + } + + for (String loopIp : loopBan.getIps()) + { + if (!loopIp.contains("*")) + { + continue; + } + + if (Ips.fuzzyIpMatch(ip, loopIp, 4)) + { + return loopBan; + } + } + } + + return null; + } + + public FBan getByUsername(String username) + { + username = username.toLowerCase(); + final FBan directBan = nameBans.get(username); + + if (directBan != null && !directBan.isExpired()) + { + return directBan; + } + + return null; + } + + public FBan unbanIp(String ip) + { + final FBan ban = getByIp(ip); + + if (ban == null) + { + return ban; + } + + bans.remove(ban); + saveAll(); + return ban; + } + + public FBan unbanUsername(String username) + { + final FBan ban = getByUsername(username); + + if (ban == null) + { + return ban; + } + + bans.remove(ban); + saveAll(); + return ban; + } + + public boolean isIpBanned(String ip) + { + return getByIp(ip) != null; + } + + public boolean isUsernameBanned(String username) + { + return getByUsername(username) != null; + } + + public boolean addBan(FBan ban) + { + if (bans.add(ban)) + { + updateViews(); + return true; + } + + return false; + } + + public boolean removeBan(FBan ban) + { + if (bans.remove(ban)) + { + updateViews(); + return true; + } + + return false; + } + + public void purgeIpBans() + { + ipBans.clear(); + saveAll(); + } + + public void purgeNameBans() + { + nameBans.clear(); + saveAll(); + } +} diff --git a/src/me/totalfreedom/totalfreedommod/banning/FBan.java b/src/me/totalfreedom/totalfreedommod/banning/FBan.java new file mode 100644 index 00000000..ea4a8732 --- /dev/null +++ b/src/me/totalfreedom/totalfreedommod/banning/FBan.java @@ -0,0 +1,260 @@ +package me.totalfreedom.totalfreedommod.banning; + +import com.google.common.collect.Lists; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import lombok.Getter; +import lombok.Setter; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import me.totalfreedom.totalfreedommod.util.FUtil; +import net.pravian.aero.base.ConfigLoadable; +import net.pravian.aero.base.ConfigSavable; +import net.pravian.aero.base.Validatable; +import net.pravian.aero.util.Ips; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.entity.Player; + +public class FBan implements ConfigLoadable, ConfigSavable, Validatable +{ + public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd \'at\' HH:mm:ss z"); + + @Getter + @Setter + private String username = null; + @Getter + private final List ips = Lists.newArrayList(); + @Getter + @Setter + private String by = null; + @Getter + @Setter + private String reason = null; // Unformatted, &[0-9,a-f] instead of ChatColor + @Getter + @Setter + private long expiryUnix = -1; + + public FBan() + { + } + + public FBan(String username, String ip, String by, Date expire, String reason) + { + this(username, + new String[] + { + ip + }, + by, + expire, + reason); + } + + public FBan(String username, String[] ips, String by, Date expire, String reason) + { + this.username = username; + if (ips != null) + { + this.ips.addAll(Arrays.asList(ips)); + } + this.by = by; + this.expiryUnix = FUtil.getUnixTime(expire); + } + + // + // For player IP + public static FBan forPlayerIp(Player player, CommandSender by) + { + return forPlayerIp(player, by, null, null); + } + + public static FBan forPlayerIp(Player player, CommandSender by, Date expiry, String reason) + { + return new FBan(null, new String[] + { + Ips.getIp(player) + }, by.getName(), expiry, reason); + } + + public static FBan forPlayerIp(String ip, CommandSender by, Date expiry, String reason) + { + return new FBan(null, ip, by.getName(), expiry, reason); + } + + // + // For player name + public static FBan forPlayerName(Player player, CommandSender by, Date expiry, String reason) + { + return forPlayerName(player.getName(), by, expiry, reason); + } + + public static FBan forPlayerName(String player, CommandSender by, Date expiry, String reason) + { + return new FBan(player, + (String[]) null, + by.getName(), + expiry, + reason); + } + + // + // For player + public static FBan forPlayer(Player player, CommandSender by) + { + return forPlayerName(player, by, null, null); + } + + public static FBan forPlayer(Player player, CommandSender by, Date expiry, String reason) + { + return new FBan(player.getName(), + Ips.getIp(player), + by.getName(), + expiry, + reason); + } + + public static FBan forPlayerFuzzy(Player player, CommandSender by, Date expiry, String reason) + { + return new FBan(player.getName(), + FUtil.getFuzzyIp(Ips.getIp(player)), + by.getName(), + expiry, + reason); + } + + public boolean hasUsername() + { + return username != null && !username.isEmpty(); + } + + public boolean addIp(String ip) + { + return ips.add(ip); + } + + public boolean removeIp(String ip) + { + return ips.remove(ip); + } + + public boolean hasIps() + { + return !ips.isEmpty(); + } + + public boolean hasExpiry() + { + return expiryUnix > 0; + } + + public Date getExpiryDate() + { + return FUtil.getUnixDate(expiryUnix); + } + + public boolean isExpired() + { + return hasExpiry() && expiryUnix < FUtil.getUnixTime(); + } + + public String bakeKickMessage() + { + final StringBuilder message = new StringBuilder(ChatColor.GOLD + "You"); + + message.append(!hasUsername() ? "r IP address is" : " are").append(" temporarily banned from this server."); + message.append("\nAppeal at ").append(ChatColor.BLUE) + .append(ConfigEntry.SERVER_BAN_URL.getString()); + + if (reason != null) + { + message.append("\n").append(ChatColor.RED).append("Reason: ").append(ChatColor.GOLD) + .append(ChatColor.translateAlternateColorCodes('&', reason)); + } + + if (by != null) + { + message.append("\n").append(ChatColor.RED).append("Banned by: ").append(ChatColor.GOLD) + .append(by); + } + + if (getExpiryUnix() != 0) + { + message.append("\n").append(ChatColor.RED).append("Expires: ").append(ChatColor.GOLD) + .append(DATE_FORMAT.format(FUtil.getUnixDate(expiryUnix))); + } + + return message.toString(); + } + + @Override + public boolean equals(Object object) + { + if (object == null) + { + return false; + } + + if (!(object instanceof FBan)) + { + return false; + } + + final FBan ban = (FBan) object; + if (hasIps() != ban.hasIps() + || hasUsername() != hasUsername()) + { + return false; + } + + if (hasIps() && !(getIps().equals(ban.getIps()))) + { + return false; + } + + if (hasUsername() && !(getUsername().equalsIgnoreCase(ban.getUsername()))) + { + return false; + } + + return true; + } + + @Override + public int hashCode() + { + int hash = 7; + hash = 79 * hash + (this.username != null ? this.username.toLowerCase().hashCode() : 0); + hash = 79 * hash + (this.ips != null ? this.ips.hashCode() : 0); + return hash; + } + + @Override + public void loadFrom(ConfigurationSection cs) + { + this.username = cs.getString("username", null); + this.ips.clear(); + this.ips.addAll(cs.getStringList("ips")); + this.by = cs.getString("by", null); + this.reason = cs.getString("reason", null); + this.expiryUnix = cs.getLong("expiry_unix", -1); + } + + @Override + public void saveTo(ConfigurationSection cs) + { + cs.set("username", username); + cs.set("ips", ips.isEmpty() ? null : ips); + cs.set("by", by); + cs.set("reason", reason); + cs.set("expiry_unix", expiryUnix > 0 ? expiryUnix : null); + } + + @Override + public boolean isValid() + { + return username != null || !ips.isEmpty(); + } +} diff --git a/src/me/StevenLawson/TotalFreedomMod/Bridge/TFM_BukkitTelnetListener.java b/src/me/totalfreedom/totalfreedommod/bridge/BukkitTelnetBridge.java similarity index 59% rename from src/me/StevenLawson/TotalFreedomMod/Bridge/TFM_BukkitTelnetListener.java rename to src/me/totalfreedom/totalfreedommod/bridge/BukkitTelnetBridge.java index 461b3aa3..20b600d1 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Bridge/TFM_BukkitTelnetListener.java +++ b/src/me/totalfreedom/totalfreedommod/bridge/BukkitTelnetBridge.java @@ -1,21 +1,36 @@ -package me.StevenLawson.TotalFreedomMod.Bridge; +package me.totalfreedom.totalfreedommod.bridge; import java.util.Iterator; import java.util.Map; import me.StevenLawson.BukkitTelnet.api.TelnetCommandEvent; import me.StevenLawson.BukkitTelnet.api.TelnetPreLoginEvent; import me.StevenLawson.BukkitTelnet.api.TelnetRequestDataTagsEvent; -import me.StevenLawson.TotalFreedomMod.TFM_Admin; -import me.StevenLawson.TotalFreedomMod.TFM_AdminList; -import me.StevenLawson.TotalFreedomMod.TFM_CommandBlocker; -import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; +import me.totalfreedom.totalfreedommod.admin.Admin; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import net.pravian.aero.component.service.AbstractService; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -public class TFM_BukkitTelnetListener implements Listener +public class BukkitTelnetBridge extends AbstractService { + + public BukkitTelnetBridge(TotalFreedomMod plugin) + { + super(plugin); + } + + @Override + protected void onStart() + { + } + + @Override + protected void onStop() + { + } + @EventHandler(priority = EventPriority.NORMAL) public void onTelnetPreLogin(TelnetPreLoginEvent event) { @@ -26,21 +41,21 @@ public class TFM_BukkitTelnetListener implements Listener return; } - final TFM_Admin admin = TFM_AdminList.getEntryByIp(ip, true); + final Admin admin = plugin.al.getEntryByIp(ip, true); - if (admin == null || !admin.isActivated() || !admin.isTelnetAdmin()) + if (admin == null || !admin.isActivated() || !admin.getRank().hasConsole()) { return; } event.setBypassPassword(true); - event.setName(admin.getLastLoginName()); + event.setName(admin.getName()); } @EventHandler(priority = EventPriority.NORMAL) public void onTelnetCommand(TelnetCommandEvent event) { - if (TFM_CommandBlocker.isCommandBlocked(event.getCommand(), event.getSender())) + if (plugin.cb.isCommandBlocked(event.getCommand(), event.getSender())) { event.setCancelled(true); } @@ -60,23 +75,23 @@ public class TFM_BukkitTelnetListener implements Listener boolean isTelnetAdmin = false; boolean isSeniorAdmin = false; - final TFM_Admin admin = TFM_AdminList.getEntry(player); + final Admin admin = plugin.al.getAdmin(player); if (admin != null) { boolean isActivated = admin.isActivated(); isAdmin = isActivated; - isTelnetAdmin = isActivated && admin.isTelnetAdmin(); - isSeniorAdmin = isActivated && admin.isSeniorAdmin(); + isSeniorAdmin = isActivated && admin.getRank() == PlayerRank.SENIOR_ADMIN; + isTelnetAdmin = isActivated && (isSeniorAdmin || admin.getRank() == PlayerRank.TELNET_ADMIN); } playerTags.put("tfm.admin.isAdmin", isAdmin); playerTags.put("tfm.admin.isTelnetAdmin", isTelnetAdmin); playerTags.put("tfm.admin.isSeniorAdmin", isSeniorAdmin); - playerTags.put("tfm.playerdata.getTag", TFM_PlayerData.getPlayerData(player).getTag()); + playerTags.put("tfm.playerdata.getTag", plugin.pl.getPlayer(player).getTag()); - playerTags.put("tfm.essentialsBridge.getNickname", TFM_EssentialsBridge.getNickname(player.getName())); + playerTags.put("tfm.essentialsBridge.getNickname", plugin.esb.getNickname(player.getName())); } } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Bridge/TFM_EssentialsBridge.java b/src/me/totalfreedom/totalfreedommod/bridge/EssentialsBridge.java similarity index 65% rename from src/me/StevenLawson/TotalFreedomMod/Bridge/TFM_EssentialsBridge.java rename to src/me/totalfreedom/totalfreedommod/bridge/EssentialsBridge.java index e37a4109..f4458308 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Bridge/TFM_EssentialsBridge.java +++ b/src/me/totalfreedom/totalfreedommod/bridge/EssentialsBridge.java @@ -1,22 +1,35 @@ -package me.StevenLawson.TotalFreedomMod.Bridge; +package me.totalfreedom.totalfreedommod.bridge; import com.earth2me.essentials.Essentials; import com.earth2me.essentials.User; -import me.StevenLawson.TotalFreedomMod.TFM_Log; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.totalfreedom.totalfreedommod.util.FLog; +import me.totalfreedom.totalfreedommod.util.FUtil; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import net.pravian.aero.component.service.AbstractService; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; -public class TFM_EssentialsBridge +public class EssentialsBridge extends AbstractService { - private static Essentials essentialsPlugin = null; - private TFM_EssentialsBridge() + private Essentials essentialsPlugin = null; + + public EssentialsBridge(TotalFreedomMod plugin) { - throw new AssertionError(); + super(plugin); } - public static Essentials getEssentialsPlugin() + @Override + protected void onStart() + { + } + + @Override + protected void onStop() + { + } + + public Essentials getEssentialsPlugin() { if (essentialsPlugin == null) { @@ -33,13 +46,13 @@ public class TFM_EssentialsBridge } catch (Exception ex) { - TFM_Log.severe(ex); + FLog.severe(ex); } } return essentialsPlugin; } - public static User getEssentialsUser(String username) + public User getEssentialsUser(String username) { try { @@ -51,12 +64,12 @@ public class TFM_EssentialsBridge } catch (Exception ex) { - TFM_Log.severe(ex); + FLog.severe(ex); } return null; } - public static void setNickname(String username, String nickname) + public void setNickname(String username, String nickname) { try { @@ -69,11 +82,11 @@ public class TFM_EssentialsBridge } catch (Exception ex) { - TFM_Log.severe(ex); + FLog.severe(ex); } } - public static String getNickname(String username) + public String getNickname(String username) { try { @@ -85,29 +98,29 @@ public class TFM_EssentialsBridge } catch (Exception ex) { - TFM_Log.severe(ex); + FLog.severe(ex); } return null; } - public static long getLastActivity(String username) + public long getLastActivity(String username) { try { final User user = getEssentialsUser(username); if (user != null) { - return TFM_Util.getField(user, "lastActivity"); // This is weird + return FUtil.getField(user, "lastActivity"); // This is weird } } catch (Exception ex) { - TFM_Log.severe(ex); + FLog.severe(ex); } return 0L; } - public static boolean isEssentialsEnabled() + public boolean isEssentialsEnabled() { try { @@ -119,7 +132,7 @@ public class TFM_EssentialsBridge } catch (Exception ex) { - TFM_Log.severe(ex); + FLog.severe(ex); } return false; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Bridge/TFM_WorldEditBridge.java b/src/me/totalfreedom/totalfreedommod/bridge/WorldEditBridge.java similarity index 71% rename from src/me/StevenLawson/TotalFreedomMod/Bridge/TFM_WorldEditBridge.java rename to src/me/totalfreedom/totalfreedommod/bridge/WorldEditBridge.java index 22b8230d..16c5c366 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Bridge/TFM_WorldEditBridge.java +++ b/src/me/totalfreedom/totalfreedommod/bridge/WorldEditBridge.java @@ -1,23 +1,35 @@ -package me.StevenLawson.TotalFreedomMod.Bridge; +package me.totalfreedom.totalfreedommod.bridge; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.bukkit.BukkitPlayer; import com.sk89q.worldedit.bukkit.WorldEditPlugin; -import me.StevenLawson.TotalFreedomMod.TFM_Log; +import me.totalfreedom.totalfreedommod.util.FLog; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import net.pravian.aero.component.service.AbstractService; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; -public class TFM_WorldEditBridge +public class WorldEditBridge extends AbstractService { private static WorldEditPlugin worldEditPlugin = null; - private TFM_WorldEditBridge() + public WorldEditBridge(TotalFreedomMod plugin) { - throw new AssertionError(); + super(plugin); } - private static WorldEditPlugin getWorldEditPlugin() + @Override + protected void onStart() + { + } + + @Override + protected void onStop() + { + } + + private WorldEditPlugin getWorldEditPlugin() { if (worldEditPlugin == null) { @@ -34,13 +46,13 @@ public class TFM_WorldEditBridge } catch (Exception ex) { - TFM_Log.severe(ex); + FLog.severe(ex); } } return worldEditPlugin; } - private static LocalSession getPlayerSession(Player player) + private LocalSession getPlayerSession(Player player) { try { @@ -52,12 +64,12 @@ public class TFM_WorldEditBridge } catch (Exception ex) { - TFM_Log.severe(ex); + FLog.severe(ex); } return null; } - private static BukkitPlayer getBukkitPlayer(Player player) + private BukkitPlayer getBukkitPlayer(Player player) { try { @@ -69,12 +81,12 @@ public class TFM_WorldEditBridge } catch (Exception ex) { - TFM_Log.severe(ex); + FLog.severe(ex); } return null; } - public static void undo(Player player, int count) + public void undo(Player player, int count) { try { @@ -93,11 +105,11 @@ public class TFM_WorldEditBridge } catch (Exception ex) { - TFM_Log.severe(ex); + FLog.severe(ex); } } - public static void setLimit(Player player, int limit) + public void setLimit(Player player, int limit) { try { @@ -109,7 +121,7 @@ public class TFM_WorldEditBridge } catch (Exception ex) { - TFM_Log.severe(ex); + FLog.severe(ex); } } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Bridge/TFM_WorldEditListener.java b/src/me/totalfreedom/totalfreedommod/bridge/WorldEditListener.java similarity index 67% rename from src/me/StevenLawson/TotalFreedomMod/Bridge/TFM_WorldEditListener.java rename to src/me/totalfreedom/totalfreedommod/bridge/WorldEditListener.java index 8d97b693..237a00c7 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Bridge/TFM_WorldEditListener.java +++ b/src/me/totalfreedom/totalfreedommod/bridge/WorldEditListener.java @@ -1,29 +1,33 @@ -package me.StevenLawson.TotalFreedomMod.Bridge; +package me.totalfreedom.totalfreedommod.bridge; -import me.StevenLawson.TotalFreedomMod.TFM_AdminList; -import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.totalfreedom.totalfreedommod.util.FUtil; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.StevenLawson.worldedit.LimitChangedEvent; import me.StevenLawson.worldedit.SelectionChangedEvent; +import net.pravian.aero.component.PluginListener; 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 +public class WorldEditListener extends PluginListener { + public WorldEditListener(TotalFreedomMod plugin) + { + super(plugin); + } + @EventHandler public void onSelectionChange(final SelectionChangedEvent event) { final Player player = event.getPlayer(); - if (TFM_AdminList.isSuperAdmin(player)) + if (plugin.al.isAdmin(player)) { return; } - if (TFM_ProtectedArea.isInProtectedArea( + if (plugin.pa.isInProtectedArea( event.getMinVector(), event.getMaxVector(), event.getWorld().getName())) @@ -39,7 +43,7 @@ public class TFM_WorldEditListener implements Listener { final Player player = event.getPlayer(); - if (TFM_AdminList.isSuperAdmin(player)) + if (plugin.al.isAdmin(player)) { return; } @@ -53,7 +57,7 @@ public class TFM_WorldEditListener implements Listener 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); + FUtil.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!"); } diff --git a/src/me/totalfreedom/totalfreedommod/commandblocker/CommandBlocker.java b/src/me/totalfreedom/totalfreedommod/commandblocker/CommandBlocker.java new file mode 100644 index 00000000..6ddde794 --- /dev/null +++ b/src/me/totalfreedom/totalfreedommod/commandblocker/CommandBlocker.java @@ -0,0 +1,192 @@ +package me.totalfreedom.totalfreedommod.commandblocker; + +import com.google.common.collect.Maps; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import me.totalfreedom.totalfreedommod.util.FLog; +import me.totalfreedom.totalfreedommod.util.FUtil; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import net.pravian.aero.command.CommandReflection; +import net.pravian.aero.component.service.AbstractService; +import org.apache.commons.lang3.StringUtils; +import org.bukkit.command.Command; +import org.bukkit.command.CommandMap; +import org.bukkit.command.CommandSender; + +public class CommandBlocker extends AbstractService +{ + public static Pattern NUMBER_FLAG_PATTERN = Pattern.compile("(:([0-9]){5,})"); + // + private final Map entryList = Maps.newHashMap(); + + public CommandBlocker(TotalFreedomMod plugin) + { + super(plugin); + } + + @Override + protected void onStart() + { + load(); + } + + @Override + protected void onStop() + { + entryList.clear(); + } + + public void load() + { + entryList.clear(); + + final CommandMap commandMap = CommandReflection.getCommandMap(); + if (commandMap == null) + { + FLog.severe("Error loading commandMap."); + return; + } + + @SuppressWarnings("unchecked") + List blockedCommands = (List) ConfigEntry.BLOCKED_COMMANDS.getList(); + for (String rawEntry : blockedCommands) + { + final String[] parts = rawEntry.split(":"); + if (parts.length < 3 || parts.length > 4) + { + FLog.warning("Invalid command blocker entry: " + rawEntry); + continue; + } + + final CommandBlockerRank rank = CommandBlockerRank.fromToken(parts[0]); + final CommandBlockerAction action = CommandBlockerAction.fromToken(parts[1]); + String commandName = parts[2].toLowerCase().substring(1); + final String message = (parts.length > 3 ? parts[3] : null); + + if (rank == null || action == null || commandName == null || commandName.isEmpty()) + { + FLog.warning("Invalid command blocker entry: " + rawEntry); + continue; + } + + final String[] commandParts = commandName.split(" "); + String subCommand = null; + if (commandParts.length > 1) + { + commandName = commandParts[0]; + subCommand = StringUtils.join(commandParts, " ", 1, commandParts.length).trim().toLowerCase(); + } + + final Command command = commandMap.getCommand(commandName); + + // Obtain command from alias + if (command == null) + { + FLog.info("Blocking unknown command: /" + commandName); + } + else + { + commandName = command.getName().toLowerCase(); + } + + if (entryList.containsKey(commandName)) + { + FLog.warning("Not blocking: /" + commandName + " - Duplicate entry exists!"); + continue; + } + + final CommandBlockerEntry blockedCommandEntry = new CommandBlockerEntry(rank, action, commandName, subCommand, message); + entryList.put(blockedCommandEntry.getCommand(), blockedCommandEntry); + + if (command != null) + { + for (String alias : command.getAliases()) + { + entryList.put(alias.toLowerCase(), blockedCommandEntry); + } + } + } + + FLog.info("Loaded " + blockedCommands.size() + " blocked commands"); + } + + public boolean isCommandBlocked(String command, CommandSender sender) + { + return isCommandBlocked(command, sender, false); + } + + public boolean isCommandBlocked(String command, CommandSender sender, boolean doAction) + { + if (command == null || command.isEmpty()) + { + return false; + } + + // Format + command = command.toLowerCase().trim(); + command = command.startsWith("/") ? command.substring(1) : command; + + // Check for plugin specific commands + final String[] commandParts = command.split(" "); + if (commandParts[0].contains(":")) + { + if (doAction) + { + FUtil.playerMsg(sender, "Plugin specific commands are disabled."); + } + return true; + } + + for (String part : commandParts) + { + Matcher matcher = NUMBER_FLAG_PATTERN.matcher(part); + if (!matcher.matches()) + { + continue; + } + if (doAction) + { + FUtil.playerMsg(sender, "That command contains an illegal number: " + matcher.group(1)); + } + return true; + } + + // Obtain sub command, if it exists + String subCommand = null; + if (commandParts.length > 1) + { + subCommand = StringUtils.join(commandParts, " ", 1, commandParts.length).toLowerCase(); + } + + // Obtain entry + final CommandBlockerEntry entry = entryList.get(commandParts[0]); + if (entry == null) + { + return false; + } + + // Validate sub command + if (entry.getSubCommand() != null) + { + if (subCommand == null || !subCommand.startsWith(entry.getSubCommand())) + { + return false; + } + } + + if (entry.getRank().hasPermission(sender)) + { + return false; + } + + if (doAction) + { + entry.doActions(sender); + } + + return true; + } +} diff --git a/src/me/totalfreedom/totalfreedommod/commandblocker/CommandBlockerAction.java b/src/me/totalfreedom/totalfreedommod/commandblocker/CommandBlockerAction.java new file mode 100644 index 00000000..c65f8cbd --- /dev/null +++ b/src/me/totalfreedom/totalfreedommod/commandblocker/CommandBlockerAction.java @@ -0,0 +1,31 @@ +package me.totalfreedom.totalfreedommod.commandblocker; + +public enum CommandBlockerAction +{ + BLOCK("b"), + BLOCK_AND_EJECT("a"), + BLOCK_UNKNOWN("u"); + private final String token; + + private CommandBlockerAction(String token) + { + this.token = token; + } + + public String getToken() + { + return this.token; + } + + public static CommandBlockerAction fromToken(String token) + { + for (CommandBlockerAction action : CommandBlockerAction.values()) + { + if (action.getToken().equalsIgnoreCase(token)) + { + return action; + } + } + return null; + } +} diff --git a/src/me/totalfreedom/totalfreedommod/commandblocker/CommandBlockerEntry.java b/src/me/totalfreedom/totalfreedommod/commandblocker/CommandBlockerEntry.java new file mode 100644 index 00000000..66eb4cc4 --- /dev/null +++ b/src/me/totalfreedom/totalfreedommod/commandblocker/CommandBlockerEntry.java @@ -0,0 +1,53 @@ +package me.totalfreedom.totalfreedommod.commandblocker; + +import lombok.Getter; +import me.totalfreedom.totalfreedommod.util.FUtil; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class CommandBlockerEntry +{ + @Getter + private final CommandBlockerRank rank; + @Getter + private final CommandBlockerAction action; + @Getter + private final String command; + @Getter + private final String subCommand; + @Getter + private final String message; + + public CommandBlockerEntry(CommandBlockerRank rank, CommandBlockerAction action, String command, String message) + { + this(rank, action, command, null, message); + } + + public CommandBlockerEntry(CommandBlockerRank rank, CommandBlockerAction action, String command, String subCommand, String message) + { + this.rank = rank; + this.action = action; + this.command = command; + this.subCommand = (subCommand == null ? null : subCommand.toLowerCase().trim()); + this.message = (message == null || message.equals("_") ? "That command is blocked." : message); + } + + public void doActions(CommandSender sender) + { + if (action == CommandBlockerAction.BLOCK_AND_EJECT && sender instanceof Player) + { + FUtil.autoEject((Player) sender, "You used a prohibited command: " + command); + FUtil.bcastMsg(sender.getName() + " was automatically kicked for using harmful commands.", ChatColor.RED); + return; + } + + if (action == CommandBlockerAction.BLOCK_UNKNOWN) + { + FUtil.playerMsg(sender, "Unknown command. Type \"help\" for help.", ChatColor.RESET); + return; + } + + FUtil.playerMsg(sender, FUtil.colorize(message)); + } +} diff --git a/src/me/totalfreedom/totalfreedommod/commandblocker/CommandBlockerRank.java b/src/me/totalfreedom/totalfreedommod/commandblocker/CommandBlockerRank.java new file mode 100644 index 00000000..4a4be723 --- /dev/null +++ b/src/me/totalfreedom/totalfreedommod/commandblocker/CommandBlockerRank.java @@ -0,0 +1,72 @@ +package me.totalfreedom.totalfreedommod.commandblocker; + +import me.totalfreedom.totalfreedommod.admin.Admin; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public enum CommandBlockerRank +{ + ANYONE("a"), + OP("o"), + SUPER("s"), + TELNET("t"), + SENIOR("c"), + NOBODY("n"); + // + private final String token; + + private CommandBlockerRank(String token) + { + this.token = token; + } + + public String getToken() + { + return this.token; + } + + public boolean hasPermission(CommandSender sender) + { + return fromSender(sender).ordinal() >= ordinal(); + } + + public static CommandBlockerRank fromSender(CommandSender sender) + { + if (!(sender instanceof Player)) + { + return TELNET; + } + + Admin admin = TotalFreedomMod.plugin.al.getAdmin(sender); + if (admin != null) + { + if (admin.getRank() == PlayerRank.SENIOR_ADMIN) + { + return SENIOR; + } + return SUPER; + } + + if (sender.isOp()) + { + return OP; + } + + return ANYONE; + + } + + public static CommandBlockerRank fromToken(String token) + { + for (CommandBlockerRank rank : CommandBlockerRank.values()) + { + if (rank.getToken().equalsIgnoreCase(token)) + { + return rank; + } + } + return ANYONE; + } +} diff --git a/src/me/totalfreedom/totalfreedommod/commands/CommandLoader.java b/src/me/totalfreedom/totalfreedommod/commands/CommandLoader.java new file mode 100644 index 00000000..4fe798e5 --- /dev/null +++ b/src/me/totalfreedom/totalfreedommod/commands/CommandLoader.java @@ -0,0 +1,40 @@ +package me.totalfreedom.totalfreedommod.commands; + +import lombok.Getter; +import me.totalfreedom.totalfreedommod.util.FLog; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import net.pravian.aero.command.handler.SimpleCommandHandler; +import net.pravian.aero.component.service.AbstractService; + +public class CommandLoader extends AbstractService +{ + + @Getter + private final SimpleCommandHandler handler; + + public CommandLoader(TotalFreedomMod plugin) + { + super(plugin); + + handler = new SimpleCommandHandler(plugin); + } + + @Override + protected void onStart() + { + handler.clearCommands(); + handler.setExecutorFactory(new FreedomCommandExecutor.TFM_CommandExecutorFactory()); + handler.setCommandClassPrefix("Command_"); + handler.loadFrom(FreedomCommand.class.getPackage()); + handler.registerAll(); + + FLog.info("Loaded" + handler.getExecutors().size() + " commands"); + } + + @Override + protected void onStop() + { + handler.clearCommands(); + } + +} diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/CommandParameters.java b/src/me/totalfreedom/totalfreedommod/commands/CommandParameters.java similarity index 84% rename from src/me/StevenLawson/TotalFreedomMod/Commands/CommandParameters.java rename to src/me/totalfreedom/totalfreedommod/commands/CommandParameters.java index 4e168f7f..a2d9edbc 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/CommandParameters.java +++ b/src/me/totalfreedom/totalfreedommod/commands/CommandParameters.java @@ -1,4 +1,4 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/CommandPermissions.java b/src/me/totalfreedom/totalfreedommod/commands/CommandPermissions.java similarity index 63% rename from src/me/StevenLawson/TotalFreedomMod/Commands/CommandPermissions.java rename to src/me/totalfreedom/totalfreedommod/commands/CommandPermissions.java index c08b612e..95163095 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/CommandPermissions.java +++ b/src/me/totalfreedom/totalfreedommod/commands/CommandPermissions.java @@ -1,12 +1,13 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @Retention(RetentionPolicy.RUNTIME) public @interface CommandPermissions { - AdminLevel level(); + PlayerRank level(); SourceType source(); diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminmode.java b/src/me/totalfreedom/totalfreedommod/commands/Command_adminmode.java similarity index 52% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminmode.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_adminmode.java index 5b41a783..176134a7 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminmode.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_adminmode.java @@ -1,44 +1,44 @@ -package me.StevenLawson.TotalFreedomMod.Commands; - -import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; -import me.StevenLawson.TotalFreedomMod.TFM_AdminList; -import me.StevenLawson.TotalFreedomMod.TFM_Util; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_CONSOLE, blockHostConsole = true) -@CommandParameters(description = "Close server to non-superadmins.", usage = "/ [on | off]") -public class Command_adminmode extends TFM_Command -{ - @Override - public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { - if (args.length != 1) - { - return false; - } - - if (args[0].equalsIgnoreCase("off")) - { - TFM_ConfigEntry.ADMIN_ONLY_MODE.setBoolean(false); - TFM_Util.adminAction(sender.getName(), "Opening the server to all players.", true); - return true; - } - else if (args[0].equalsIgnoreCase("on")) - { - TFM_ConfigEntry.ADMIN_ONLY_MODE.setBoolean(true); - TFM_Util.adminAction(sender.getName(), "Closing the server to non-superadmins.", true); - for (Player player : server.getOnlinePlayers()) - { - if (!TFM_AdminList.isSuperAdmin(player)) - { - player.kickPlayer("Server is now closed to non-superadmins."); - } - } - return true; - } - - return false; - } -} +package me.totalfreedom.totalfreedommod.commands; + +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import me.totalfreedom.totalfreedommod.util.FUtil; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.ONLY_CONSOLE, blockHostConsole = true) +@CommandParameters(description = "Close server to non-superadmins.", usage = "/ [on | off]") +public class Command_adminmode extends FreedomCommand +{ + @Override + public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + { + if (args.length != 1) + { + return false; + } + + if (args[0].equalsIgnoreCase("off")) + { + ConfigEntry.ADMIN_ONLY_MODE.setBoolean(false); + FUtil.adminAction(sender.getName(), "Opening the server to all players.", true); + return true; + } + else if (args[0].equalsIgnoreCase("on")) + { + ConfigEntry.ADMIN_ONLY_MODE.setBoolean(true); + FUtil.adminAction(sender.getName(), "Closing the server to non-superadmins.", true); + for (Player player : server.getOnlinePlayers()) + { + if (!isAdmin(player)) + { + player.kickPlayer("Server is now closed to non-superadmins."); + } + } + return true; + } + + return false; + } +} diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminworld.java b/src/me/totalfreedom/totalfreedommod/commands/Command_adminworld.java similarity index 77% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminworld.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_adminworld.java index 366b574d..4c158e26 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminworld.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_adminworld.java @@ -1,19 +1,22 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.TFM_AdminList; -import me.StevenLawson.TotalFreedomMod.TFM_Util; -import me.StevenLawson.TotalFreedomMod.World.TFM_AdminWorld; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.util.FUtil; +import me.totalfreedom.totalfreedommod.world.WorldTime; +import me.totalfreedom.totalfreedommod.world.WorldWeather; import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.OP, source = SourceType.BOTH) +@CommandPermissions(level = PlayerRank.OP, source = SourceType.BOTH) @CommandParameters(description = "Go to the AdminWorld.", usage = "/ [guest < list | purge | add | remove > | time | weather ]") -public class Command_adminworld extends TFM_Command +public class Command_adminworld extends FreedomCommand { + private enum CommandMode { + TELEPORT, GUEST, TIME, WEATHER; } @@ -61,7 +64,7 @@ public class Command_adminworld extends TFM_Command World adminWorld = null; try { - adminWorld = TFM_AdminWorld.getInstance().getWorld(); + adminWorld = plugin.wm.adminworld.getWorld(); } catch (Exception ex) { @@ -74,10 +77,10 @@ public class Command_adminworld extends TFM_Command } else { - if (TFM_AdminWorld.getInstance().canAccessWorld(sender_p)) + if (plugin.wm.adminworld.canAccessWorld(sender_p)) { playerMsg("Going to the AdminWorld."); - TFM_AdminWorld.getInstance().sendToWorld(sender_p); + plugin.wm.adminworld.sendToWorld(sender_p); } else { @@ -93,13 +96,13 @@ public class Command_adminworld extends TFM_Command { if ("list".equalsIgnoreCase(args[1])) { - playerMsg("AdminWorld guest list: " + TFM_AdminWorld.getInstance().guestListToString()); + playerMsg("AdminWorld guest list: " + plugin.wm.adminworld.guestListToString()); } else if ("purge".equalsIgnoreCase(args[1])) { assertCommandPerms(sender, sender_p); - TFM_AdminWorld.getInstance().purgeGuestList(); - TFM_Util.adminAction(sender.getName(), "AdminWorld guest list purged.", false); + plugin.wm.adminworld.purgeGuestList(); + FUtil.adminAction(sender.getName(), "AdminWorld guest list purged.", false); } else { @@ -116,13 +119,13 @@ public class Command_adminworld extends TFM_Command if (player == null) { - sender.sendMessage(TFM_Command.PLAYER_NOT_FOUND); + sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND); return true; } - if (TFM_AdminWorld.getInstance().addGuest(player, sender_p)) + if (plugin.wm.adminworld.addGuest(player, sender_p)) { - TFM_Util.adminAction(sender.getName(), "AdminWorld guest added: " + player.getName(), false); + FUtil.adminAction(sender.getName(), "AdminWorld guest added: " + player.getName(), false); } else { @@ -131,10 +134,10 @@ public class Command_adminworld extends TFM_Command } else if ("remove".equals(args[1])) { - final Player player = TFM_AdminWorld.getInstance().removeGuest(args[2]); + final Player player = plugin.wm.adminworld.removeGuest(args[2]); if (player != null) { - TFM_Util.adminAction(sender.getName(), "AdminWorld guest removed: " + player.getName(), false); + FUtil.adminAction(sender.getName(), "AdminWorld guest removed: " + player.getName(), false); } else { @@ -155,10 +158,10 @@ public class Command_adminworld extends TFM_Command if (args.length == 2) { - TFM_AdminWorld.TimeOfDay timeOfDay = TFM_AdminWorld.TimeOfDay.getByAlias(args[1]); + WorldTime timeOfDay = WorldTime.getByAlias(args[1]); if (timeOfDay != null) { - TFM_AdminWorld.getInstance().setTimeOfDay(timeOfDay); + plugin.wm.adminworld.setTimeOfDay(timeOfDay); playerMsg("AdminWorld time set to: " + timeOfDay.name()); } else @@ -179,10 +182,10 @@ public class Command_adminworld extends TFM_Command if (args.length == 2) { - TFM_AdminWorld.WeatherMode weatherMode = TFM_AdminWorld.WeatherMode.getByAlias(args[1]); + WorldWeather weatherMode = WorldWeather.getByAlias(args[1]); if (weatherMode != null) { - TFM_AdminWorld.getInstance().setWeatherMode(weatherMode); + plugin.wm.adminworld.setWeatherMode(weatherMode); playerMsg("AdminWorld weather set to: " + weatherMode.name()); } else @@ -211,16 +214,18 @@ public class Command_adminworld extends TFM_Command return true; } + // TODO: Redo this properly private void assertCommandPerms(CommandSender sender, Player sender_p) throws PermissionDeniedException { - if (!(sender instanceof Player) || sender_p == null || !TFM_AdminList.isSuperAdmin(sender)) + if (!(sender instanceof Player) || sender_p == null || !isAdmin(sender)) { - throw new PermissionDeniedException(TFM_Command.MSG_NO_PERMS); + throw new PermissionDeniedException(FreedomCommand.MSG_NO_PERMS); } } private class PermissionDeniedException extends Exception { + private static final long serialVersionUID = 1L; private PermissionDeniedException(String string) @@ -228,4 +233,5 @@ public class Command_adminworld extends TFM_Command super(string); } } + } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_blockcmd.java b/src/me/totalfreedom/totalfreedommod/commands/Command_blockcmd.java similarity index 63% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_blockcmd.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_blockcmd.java index 1c91060b..14ea4874 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_blockcmd.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_blockcmd.java @@ -1,15 +1,15 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.TFM_AdminList; -import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.player.FPlayer; +import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH) +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH) @CommandParameters(description = "Block all commands for a specific player.", usage = "/ >", aliases = "blockcommands,blockcommand") -public class Command_blockcmd extends TFM_Command +public class Command_blockcmd extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) @@ -21,11 +21,11 @@ public class Command_blockcmd extends TFM_Command if (args[0].equalsIgnoreCase("purge")) { - TFM_Util.adminAction(sender.getName(), "Unblocking commands for all players", true); + FUtil.adminAction(sender.getName(), "Unblocking commands for all players", true); int counter = 0; for (Player player : server.getOnlinePlayers()) { - TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); + FPlayer playerdata = plugin.pl.getPlayer(player); if (playerdata.allCommandsBlocked()) { counter += 1; @@ -40,21 +40,21 @@ public class Command_blockcmd extends TFM_Command if (player == null) { - playerMsg(TFM_Command.PLAYER_NOT_FOUND); + playerMsg(FreedomCommand.PLAYER_NOT_FOUND); return true; } - if (TFM_AdminList.isSuperAdmin(player)) + if (isAdmin(sender)) { playerMsg(player.getName() + " is a Superadmin, and cannot have their commands blocked."); return true; } - TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); + FPlayer playerdata = plugin.pl.getPlayer(player); playerdata.setCommandsBlocked(!playerdata.allCommandsBlocked()); - TFM_Util.adminAction(sender.getName(), (playerdata.allCommandsBlocked() ? "B" : "Unb") + "locking all commands for " + player.getName(), true); + FUtil.adminAction(sender.getName(), (playerdata.allCommandsBlocked() ? "B" : "Unb") + "locking all commands for " + player.getName(), true); playerMsg((playerdata.allCommandsBlocked() ? "B" : "Unb") + "locked all commands."); return true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cage.java b/src/me/totalfreedom/totalfreedommod/commands/Command_cage.java similarity index 69% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_cage.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_cage.java index 81bf2fb7..025797b6 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cage.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_cage.java @@ -1,7 +1,8 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.player.FPlayer; +import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; @@ -9,9 +10,9 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH) +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH) @CommandParameters(description = "Place a cage around someone.", usage = "/ [outermaterial] [innermaterial]>") -public class Command_cage extends TFM_Command +public class Command_cage extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) @@ -23,8 +24,8 @@ public class Command_cage extends TFM_Command if ("off".equals(args[0]) && sender instanceof Player) { - TFM_Util.adminAction(sender.getName(), "Uncaging " + sender.getName(), true); - TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(sender_p); + FUtil.adminAction(sender.getName(), "Uncaging " + sender.getName(), true); + FPlayer playerdata = plugin.pl.getPlayer(sender_p); playerdata.setCaged(false); playerdata.regenerateHistory(); @@ -34,11 +35,11 @@ public class Command_cage extends TFM_Command } else if ("purge".equals(args[0])) { - TFM_Util.adminAction(sender.getName(), "Uncaging all players", true); + FUtil.adminAction(sender.getName(), "Uncaging all players", true); for (Player player : server.getOnlinePlayers()) { - TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); + FPlayer playerdata = plugin.pl.getPlayer(player); playerdata.setCaged(false); playerdata.regenerateHistory(); playerdata.clearHistory(); @@ -51,11 +52,11 @@ public class Command_cage extends TFM_Command if (player == null) { - sender.sendMessage(TFM_Command.PLAYER_NOT_FOUND); + sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND); return true; } - TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); + FPlayer playerdata = plugin.pl.getPlayer(player); Material outerMaterial = Material.GLASS; Material innerMaterial = Material.AIR; @@ -64,7 +65,7 @@ public class Command_cage extends TFM_Command { if ("off".equals(args[1])) { - TFM_Util.adminAction(sender.getName(), "Uncaging " + player.getName(), true); + FUtil.adminAction(sender.getName(), "Uncaging " + player.getName(), true); playerdata.setCaged(false); playerdata.regenerateHistory(); @@ -101,19 +102,19 @@ public class Command_cage extends TFM_Command playerdata.setCaged(true, targetPos, outerMaterial, innerMaterial); playerdata.regenerateHistory(); playerdata.clearHistory(); - TFM_Util.buildHistory(targetPos, 2, playerdata); - TFM_Util.generateHollowCube(targetPos, 2, outerMaterial); - TFM_Util.generateCube(targetPos, 1, innerMaterial); + FUtil.buildHistory(targetPos, 2, playerdata); + FUtil.generateHollowCube(targetPos, 2, outerMaterial); + FUtil.generateCube(targetPos, 1, innerMaterial); player.setGameMode(GameMode.SURVIVAL); if (outerMaterial != Material.SKULL) { - TFM_Util.adminAction(sender.getName(), "Caging " + player.getName(), true); + FUtil.adminAction(sender.getName(), "Caging " + player.getName(), true); } else { - TFM_Util.adminAction(sender.getName(), "Caging " + player.getName() + " in PURE_DARTH", true); + FUtil.adminAction(sender.getName(), "Caging " + player.getName() + " in PURE_DARTH", true); } return true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cake.java b/src/me/totalfreedom/totalfreedommod/commands/Command_cake.java similarity index 84% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_cake.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_cake.java index 033b296b..b061dbb1 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cake.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_cake.java @@ -1,7 +1,8 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; import java.util.Random; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.Achievement; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -11,9 +12,9 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH) +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH) @CommandParameters(description = "For the people that are still alive.", usage = "/") -public class Command_cake extends TFM_Command +public class Command_cake extends FreedomCommand { public static final String CAKE_LYRICS = "But there's no sense crying over every mistake. You just keep on trying till you run out of cake."; private final Random random = new Random(); @@ -45,7 +46,7 @@ public class Command_cake extends TFM_Command player.awardAchievement(Achievement.BAKE_CAKE); } - TFM_Util.bcastMsg(output.toString()); + FUtil.bcastMsg(output.toString()); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cartsit.java b/src/me/totalfreedom/totalfreedommod/commands/Command_cartsit.java similarity index 85% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_cartsit.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_cartsit.java index 9150d72b..c25ec6ba 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cartsit.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_cartsit.java @@ -1,15 +1,16 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.TFM_AdminList; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Minecart; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH) +@CommandPermissions(level = PlayerRank.NON_OP, source = SourceType.BOTH) @CommandParameters(description = "Sit in nearest minecart. If target is in a minecart already, they will disembark.", usage = "/ [partialname]") -public class Command_cartsit extends TFM_Command +public class Command_cartsit extends FreedomCommand { + @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { @@ -22,7 +23,7 @@ public class Command_cartsit extends TFM_Command if (targetPlayer == null) { - sender.sendMessage(TFM_Command.PLAYER_NOT_FOUND); + sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND); return true; } } @@ -35,7 +36,7 @@ public class Command_cartsit extends TFM_Command return true; } } - else if (targetPlayer != sender_p && !TFM_AdminList.isSuperAdmin(sender)) + else if (targetPlayer != sender_p && !isAdmin(sender)) { sender.sendMessage("Only superadmins can select another player as a /cartsit target."); return true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cbtool.java b/src/me/totalfreedom/totalfreedommod/commands/Command_cbtool.java similarity index 90% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_cbtool.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_cbtool.java index 1bc450d5..0f2ca34e 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cbtool.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_cbtool.java @@ -1,11 +1,12 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import me.StevenLawson.TotalFreedomMod.TFM_CommandBlocker; -import me.StevenLawson.TotalFreedomMod.TFM_DepreciationAggregator; -import me.StevenLawson.TotalFreedomMod.TFM_Log; +import me.totalfreedom.totalfreedommod.commandblocker.CommandBlocker; +import me.totalfreedom.totalfreedommod.util.DepreciationAggregator; +import me.totalfreedom.totalfreedommod.util.FLog; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.bukkit.Bukkit; @@ -16,9 +17,9 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH) +@CommandPermissions(level = PlayerRank.NON_OP, source = SourceType.BOTH) @CommandParameters(description = "No Description Yet", usage = "/") -public class Command_cbtool extends TFM_Command +public class Command_cbtool extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) @@ -30,7 +31,7 @@ public class Command_cbtool extends TFM_Command if ("targetblock".equalsIgnoreCase(args[0]) && sender instanceof Player) { - Block targetBlock = TFM_DepreciationAggregator.getTargetBlock(sender_p, null, 100); + Block targetBlock = DepreciationAggregator.getTargetBlock(sender_p, null, 100); playerMsg("Your target block: " + targetBlock.getLocation().toString()); return true; } @@ -46,7 +47,7 @@ public class Command_cbtool extends TFM_Command } matcher.appendTail(generatedCommand); - if (TFM_CommandBlocker.isCommandBlocked(generatedCommand.toString(), sender, false)) + if (plugin.cb.isCommandBlocked(generatedCommand.toString(), sender, false)) { return true; } @@ -58,7 +59,7 @@ public class Command_cbtool extends TFM_Command } catch (Exception ex) { - TFM_Log.severe(ex); + FLog.severe(ex); } return true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cmdlist.java b/src/me/totalfreedom/totalfreedommod/commands/Command_cmdlist.java similarity index 86% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_cmdlist.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_cmdlist.java index 28237684..c2e74b25 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cmdlist.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_cmdlist.java @@ -1,5 +1,6 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -12,9 +13,9 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; -@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH) +@CommandPermissions(level = PlayerRank.NON_OP, source = SourceType.BOTH) @CommandParameters(description = "Show all commands for all server plugins.", usage = "/") -public class Command_cmdlist extends TFM_Command +public class Command_cmdlist extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cmdspy.java b/src/me/totalfreedom/totalfreedommod/commands/Command_cmdspy.java similarity index 60% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_cmdspy.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_cmdspy.java index f91542d9..5bd157c9 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cmdspy.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_cmdspy.java @@ -1,19 +1,20 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.player.FPlayer; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME) +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Spy on commands", usage = "/", aliases = "commandspy") -public class Command_cmdspy extends TFM_Command +public class Command_cmdspy extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(sender_p); + FPlayer playerdata = plugin.pl.getPlayer(sender_p); playerdata.setCommandSpy(!playerdata.cmdspyEnabled()); playerMsg("CommandSpy " + (playerdata.cmdspyEnabled() ? "enabled." : "disabled.")); diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_colorme.java b/src/me/totalfreedom/totalfreedommod/commands/Command_colorme.java similarity index 70% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_colorme.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_colorme.java index 623b06c0..25e9156e 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_colorme.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_colorme.java @@ -1,18 +1,19 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; import java.util.Iterator; import java.util.Map; -import me.StevenLawson.TotalFreedomMod.Bridge.TFM_EssentialsBridge; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.totalfreedom.totalfreedommod.bridge.EssentialsBridge; +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 = AdminLevel.OP, source = SourceType.ONLY_IN_GAME) +@CommandPermissions(level = PlayerRank.OP, source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Essentials Interface Command - Color your current nickname.", usage = "/ ") -public class Command_colorme extends TFM_Command +public class Command_colorme extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) @@ -24,13 +25,13 @@ public class Command_colorme extends TFM_Command if ("list".equalsIgnoreCase(args[0])) { - playerMsg("Colors: " + StringUtils.join(TFM_Util.CHAT_COLOR_NAMES.keySet(), ", ")); + playerMsg("Colors: " + StringUtils.join(FUtil.CHAT_COLOR_NAMES.keySet(), ", ")); return true; } final String needle = args[0].trim().toLowerCase(); ChatColor color = null; - final Iterator> it = TFM_Util.CHAT_COLOR_NAMES.entrySet().iterator(); + final Iterator> it = FUtil.CHAT_COLOR_NAMES.entrySet().iterator(); while (it.hasNext()) { final Map.Entry entry = it.next(); @@ -49,7 +50,7 @@ public class Command_colorme extends TFM_Command final String newNick = color + ChatColor.stripColor(sender_p.getDisplayName()).trim() + ChatColor.WHITE; - TFM_EssentialsBridge.setNickname(sender.getName(), newNick); + plugin.esb.setNickname(sender.getName(), newNick); playerMsg("Your nickname is now: " + newNick); diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_creative.java b/src/me/totalfreedom/totalfreedommod/commands/Command_creative.java similarity index 73% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_creative.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_creative.java index 79e3bd15..030ee6ff 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_creative.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_creative.java @@ -1,15 +1,15 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.TFM_AdminList; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.GameMode; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.OP, source = SourceType.BOTH) +@CommandPermissions(level = PlayerRank.OP, source = SourceType.BOTH) @CommandParameters(description = "Quickly change your own gamemode to creative, or define someone's username to change theirs.", usage = "/ [partialname]", aliases = "gmc") -public class Command_creative extends TFM_Command +public class Command_creative extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) @@ -32,9 +32,9 @@ public class Command_creative extends TFM_Command { if (args[0].equalsIgnoreCase("-a")) { - if (!TFM_AdminList.isSuperAdmin(sender)) + if (!isAdmin(sender)) { - sender.sendMessage(TFM_Command.MSG_NO_PERMS); + sender.sendMessage(FreedomCommand.MSG_NO_PERMS); return true; } @@ -43,11 +43,11 @@ public class Command_creative extends TFM_Command targetPlayer.setGameMode(GameMode.CREATIVE); } - TFM_Util.adminAction(sender.getName(), "Changing everyone's gamemode to creative", false); + FUtil.adminAction(sender.getName(), "Changing everyone's gamemode to creative", false); return true; } - if (!(senderIsConsole || TFM_AdminList.isSuperAdmin(sender))) + if (!(senderIsConsole || isAdmin(sender))) { playerMsg("Only superadmins can change other user's gamemode."); return true; @@ -57,7 +57,7 @@ public class Command_creative extends TFM_Command if (player == null) { - sender.sendMessage(TFM_Command.PLAYER_NOT_FOUND); + sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_csay.java b/src/me/totalfreedom/totalfreedommod/commands/Command_csay.java similarity index 55% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_csay.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_csay.java index 77c0d0b8..72315c56 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_csay.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_csay.java @@ -1,21 +1,22 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.util.FUtil; import org.apache.commons.lang3.StringUtils; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_CONSOLE) +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.ONLY_CONSOLE) @CommandParameters(description = "Telnet command - Send a chat message with chat formatting over telnet.", usage = "/ ") -public class Command_csay extends TFM_Command +public class Command_csay extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { if (args.length > 0) { - TFM_Util.bcastMsg(String.format("§7[CONSOLE]§f<§c%s§f> %s", sender.getName(), StringUtils.join(args, " "))); + FUtil.bcastMsg(String.format("§7[CONSOLE]§f<§c%s§f> %s", sender.getName(), StringUtils.join(args, " "))); } return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_deafen.java b/src/me/totalfreedom/totalfreedommod/commands/Command_deafen.java similarity index 85% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_deafen.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_deafen.java index c3f622cb..4f4f209b 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_deafen.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_deafen.java @@ -1,5 +1,6 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; import java.util.Random; import org.bukkit.Location; import org.bukkit.Sound; @@ -8,9 +9,9 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; -@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.BOTH, blockHostConsole = true) +@CommandPermissions(level = PlayerRank.SENIOR_ADMIN, source = SourceType.BOTH, blockHostConsole = true) @CommandParameters(description = "Make some noise.", usage = "/") -public class Command_deafen extends TFM_Command +public class Command_deafen extends FreedomCommand { private static final Random random = new Random(); public static final double STEPS = 10.0; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_debug.java b/src/me/totalfreedom/totalfreedommod/commands/Command_debug.java similarity index 93% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_debug.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_debug.java index 023dcde5..7a49cfb0 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_debug.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_debug.java @@ -1,5 +1,6 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; import java.lang.reflect.Field; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; @@ -7,9 +8,9 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE) +@CommandPermissions(level = PlayerRank.SENIOR_ADMIN, source = SourceType.ONLY_CONSOLE) @CommandParameters(description = "For developers only - debug things via reflection.", usage = "/") -public class Command_debug extends TFM_Command +public class Command_debug extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_denick.java b/src/me/totalfreedom/totalfreedommod/commands/Command_denick.java similarity index 51% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_denick.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_denick.java index f9dc7cee..cc9d9661 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_denick.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_denick.java @@ -1,23 +1,24 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.Bridge.TFM_EssentialsBridge; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.bridge.EssentialsBridge; +import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH) +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH) @CommandParameters(description = "Essentials Interface Command - Remove the nickname of all players on the server.", usage = "/") -public class Command_denick extends TFM_Command +public class Command_denick extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - TFM_Util.adminAction(sender.getName(), "Removing all nicknames", false); + FUtil.adminAction(sender.getName(), "Removing all nicknames", false); for (Player player : server.getOnlinePlayers()) { - TFM_EssentialsBridge.setNickname(player.getName(), null); + plugin.esb.setNickname(player.getName(), null); } return true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_deop.java b/src/me/totalfreedom/totalfreedommod/commands/Command_deop.java similarity index 62% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_deop.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_deop.java index 848cdd19..dc282fe8 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_deop.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_deop.java @@ -1,44 +1,45 @@ -package me.StevenLawson.TotalFreedomMod.Commands; - -import me.StevenLawson.TotalFreedomMod.TFM_DepreciationAggregator; -import me.StevenLawson.TotalFreedomMod.TFM_Util; -import org.bukkit.OfflinePlayer; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH) -@CommandParameters(description = "Deop a player.", usage = "/ ") -public class Command_deop extends TFM_Command -{ - @Override - public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { - if (args.length != 1) - { - return false; - } - - OfflinePlayer player = null; - - for (Player onlinePlayer : server.getOnlinePlayers()) - { - if (args[0].equalsIgnoreCase(onlinePlayer.getName())) - { - player = onlinePlayer; - } - } - - // if the player is not online - if (player == null) - { - player = TFM_DepreciationAggregator.getOfflinePlayer(server, args[0]); - } - - TFM_Util.adminAction(sender.getName(), "De-opping " + player.getName(), false); - - player.setOp(false); - - return true; - } -} +package me.totalfreedom.totalfreedommod.commands; + +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.util.DepreciationAggregator; +import me.totalfreedom.totalfreedommod.util.FUtil; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH) +@CommandParameters(description = "Deop a player.", usage = "/ ") +public class Command_deop extends FreedomCommand +{ + @Override + public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + { + if (args.length != 1) + { + return false; + } + + OfflinePlayer player = null; + + for (Player onlinePlayer : server.getOnlinePlayers()) + { + if (args[0].equalsIgnoreCase(onlinePlayer.getName())) + { + player = onlinePlayer; + } + } + + // if the player is not online + if (player == null) + { + player = DepreciationAggregator.getOfflinePlayer(server, args[0]); + } + + FUtil.adminAction(sender.getName(), "De-opping " + player.getName(), false); + + player.setOp(false); + + return true; + } +} diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_deopall.java b/src/me/totalfreedom/totalfreedommod/commands/Command_deopall.java similarity index 51% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_deopall.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_deopall.java index 7a76cedb..2b42560d 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_deopall.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_deopall.java @@ -1,23 +1,24 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH, blockHostConsole = true) +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH, blockHostConsole = true) @CommandParameters(description = "Deop everyone on the server.", usage = "/") -public class Command_deopall extends TFM_Command +public class Command_deopall extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - TFM_Util.adminAction(sender.getName(), "De-opping all players on the server", true); + FUtil.adminAction(sender.getName(), "De-opping all players on the server", true); for (Player player : server.getOnlinePlayers()) { player.setOp(false); - player.sendMessage(TFM_Command.YOU_ARE_NOT_OP); + player.sendMessage(FreedomCommand.YOU_ARE_NOT_OP); } return true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_dispfill.java b/src/me/totalfreedom/totalfreedommod/commands/Command_dispfill.java similarity index 87% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_dispfill.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_dispfill.java index 5fe055be..37777f5d 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_dispfill.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_dispfill.java @@ -1,9 +1,10 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; import java.util.ArrayList; import java.util.List; -import me.StevenLawson.TotalFreedomMod.TFM_DepreciationAggregator; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.totalfreedom.totalfreedommod.util.DepreciationAggregator; +import me.totalfreedom.totalfreedommod.util.FUtil; import org.apache.commons.lang3.StringUtils; import org.bukkit.Location; import org.bukkit.Material; @@ -15,9 +16,9 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; -@CommandPermissions(level = AdminLevel.OP, source = SourceType.ONLY_IN_GAME) +@CommandPermissions(level = PlayerRank.OP, source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Fill nearby dispensers with a set of items of your choice.", usage = "/ ") -public class Command_dispfill extends TFM_Command +public class Command_dispfill extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) @@ -46,7 +47,7 @@ public class Command_dispfill extends TFM_Command { try { - material = TFM_DepreciationAggregator.getMaterial(Integer.parseInt(searchItem)); + material = DepreciationAggregator.getMaterial(Integer.parseInt(searchItem)); } catch (NumberFormatException ex) { @@ -79,7 +80,7 @@ public class Command_dispfill extends TFM_Command { if (targetBlock.getType().equals(Material.DISPENSER)) { - sender.sendMessage("Filling dispenser @ " + TFM_Util.formatLocation(targetBlock.getLocation())); + sender.sendMessage("Filling dispenser @ " + FUtil.formatLocation(targetBlock.getLocation())); setDispenserContents(targetBlock, itemsArray); affected++; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_doom.java b/src/me/totalfreedom/totalfreedommod/commands/Command_doom.java similarity index 57% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_doom.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_doom.java index 1412478e..c6c98e2b 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_doom.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_doom.java @@ -1,10 +1,10 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.TFM_AdminList; -import me.StevenLawson.TotalFreedomMod.TFM_Ban; -import me.StevenLawson.TotalFreedomMod.TFM_BanManager; -import me.StevenLawson.TotalFreedomMod.TFM_PlayerList; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.admin.Admin; +import me.totalfreedom.totalfreedommod.banning.FBan; +import me.totalfreedom.totalfreedommod.player.PlayerList; +import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.command.Command; @@ -13,9 +13,9 @@ import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; -@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE, blockHostConsole = true) +@CommandPermissions(level = PlayerRank.SENIOR_ADMIN, source = SourceType.ONLY_CONSOLE, blockHostConsole = true) @CommandParameters(description = "For the bad Superadmins", usage = "/ ") -public class Command_doom extends TFM_Command +public class Command_doom extends FreedomCommand { @Override public boolean run(final CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) @@ -29,48 +29,49 @@ public class Command_doom extends TFM_Command if (player == null) { - sender.sendMessage(TFM_Command.PLAYER_NOT_FOUND); + sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND); return true; } - TFM_Util.adminAction(sender.getName(), "Casting oblivion over " + player.getName(), true); - TFM_Util.bcastMsg(player.getName() + " will be completely obliviated!", ChatColor.RED); + FUtil.adminAction(sender.getName(), "Casting oblivion over " + player.getName(), true); + FUtil.bcastMsg(player.getName() + " will be completely obliviated!", ChatColor.RED); final String ip = player.getAddress().getAddress().getHostAddress().trim(); - // remove from superadmin - if (TFM_AdminList.isSuperAdmin(player)) + // Remove from superadmin + Admin admin = getAdmin(player); + if (admin != null) { - TFM_Util.adminAction(sender.getName(), "Removing " + player.getName() + " from the superadmin list.", true); - TFM_AdminList.removeSuperadmin(player); + FUtil.adminAction(sender.getName(), "Removing " + player.getName() + " from the superadmin list", true); + plugin.al.removeAdmin(admin); } - // remove from whitelist + // Remove from whitelist player.setWhitelisted(false); - // deop + // Deop player.setOp(false); - // ban IPs - for (String playerIp : TFM_PlayerList.getEntry(player).getIps()) + // Ban player + FBan ban = FBan.forPlayer(player, sender); + ban.setReason("&cFUCKOFF"); + for (String playerIp : plugin.pl.getData(player).getIps()) { - TFM_BanManager.addIpBan(new TFM_Ban(playerIp, player.getName())); + ban.addIp(playerIp); } + plugin.bm.addBan(ban); - // ban uuid - TFM_BanManager.addUuidBan(player); - - // set gamemode to survival + // Set gamemode to survival player.setGameMode(GameMode.SURVIVAL); - // clear inventory + // Clear inventory player.closeInventory(); player.getInventory().clear(); - // ignite player + // Ignite player player.setFireTicks(10000); - // generate explosion + // Generate explosion player.getWorld().createExplosion(player.getLocation(), 4F); // Shoot the player in the sky @@ -95,7 +96,7 @@ public class Command_doom extends TFM_Command public void run() { // message - TFM_Util.adminAction(sender.getName(), "Banning " + player.getName() + ", IP: " + ip, true); + FUtil.adminAction(sender.getName(), "Banning " + player.getName() + ", IP: " + ip, true); // generate explosion player.getWorld().createExplosion(player.getLocation(), 4F); diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_enchant.java b/src/me/totalfreedom/totalfreedommod/commands/Command_enchant.java similarity index 89% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_enchant.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_enchant.java index d05b664a..5d9d3cc8 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_enchant.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_enchant.java @@ -1,15 +1,16 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.TFM_Log; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.util.FLog; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -@CommandPermissions(level = AdminLevel.OP, source = SourceType.ONLY_IN_GAME) +@CommandPermissions(level = PlayerRank.OP, source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Enchant items.", usage = "/ | remove >") -public class Command_enchant extends TFM_Command +public class Command_enchant extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) @@ -63,7 +64,7 @@ public class Command_enchant extends TFM_Command } catch (Exception ex) { - TFM_Log.info("Error using " + ench.getName() + " on " + itemInHand.getType().name() + " held by " + sender_p.getName() + "."); + FLog.info("Error using " + ench.getName() + " on " + itemInHand.getType().name() + " held by " + sender_p.getName() + "."); } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_ender.java b/src/me/totalfreedom/totalfreedommod/commands/Command_ender.java similarity index 50% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_ender.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_ender.java index 42006326..92b79b68 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_ender.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_ender.java @@ -1,18 +1,19 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.ALL, source = SourceType.ONLY_IN_GAME) +@CommandPermissions(level = PlayerRank.NON_OP, source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Goto the ender / \"The End\".", usage = "/") -public class Command_ender extends TFM_Command +public class Command_ender extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - TFM_Util.gotoWorld(sender_p, server.getWorlds().get(0).getName() + "_the_end"); + FUtil.gotoWorld(sender_p, server.getWorlds().get(0).getName() + "_the_end"); return true; } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_expel.java b/src/me/totalfreedom/totalfreedommod/commands/Command_expel.java similarity index 87% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_expel.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_expel.java index d96591bb..57d632fc 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_expel.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_expel.java @@ -1,8 +1,9 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; import java.util.ArrayList; import java.util.List; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.totalfreedom.totalfreedommod.util.FUtil; import org.apache.commons.lang3.StringUtils; import org.bukkit.Location; import org.bukkit.command.Command; @@ -10,9 +11,9 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME) +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Push people away from you.", usage = "/ [radius] [strength]") -public class Command_expel extends TFM_Command +public class Command_expel extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) @@ -68,7 +69,7 @@ public class Command_expel extends TFM_Command if (inRange) { player.getWorld().createExplosion(targetPos, 0.0f, false); - TFM_Util.setFlying(player, false); + FUtil.setFlying(player, false); player.setVelocity(targetPosVec.subtract(senderPos).normalize().multiply(strength)); pushedPlayers.add(player.getName()); } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_findip.java b/src/me/totalfreedom/totalfreedommod/commands/Command_findip.java similarity index 62% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_findip.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_findip.java index f30dd6a2..7dd87b90 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_findip.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_findip.java @@ -1,14 +1,14 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.TFM_PlayerList; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; import org.apache.commons.lang3.StringUtils; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH) +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH) @CommandParameters(description = "Shows all IPs registered to a player", usage = "/ ") -public class Command_findip extends TFM_Command +public class Command_findip extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) @@ -23,11 +23,11 @@ public class Command_findip extends TFM_Command if (player == null) { - playerMsg(TFM_Command.PLAYER_NOT_FOUND); + playerMsg(FreedomCommand.PLAYER_NOT_FOUND); return true; } - playerMsg("Player IPs: " + StringUtils.join(TFM_PlayerList.getEntry(player).getIps(), ", ")); + playerMsg("Player IPs: " + StringUtils.join(plugin.pl.getData(player).getIps(), ", ")); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_flatlands.java b/src/me/totalfreedom/totalfreedommod/commands/Command_flatlands.java similarity index 53% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_flatlands.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_flatlands.java index 6799c3ed..1b3d38f1 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_flatlands.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_flatlands.java @@ -1,21 +1,21 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; -import me.StevenLawson.TotalFreedomMod.World.TFM_Flatlands; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.ALL, source = SourceType.ONLY_IN_GAME) +@CommandPermissions(level = PlayerRank.NON_OP, source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Goto the flatlands.", usage = "/") -public class Command_flatlands extends TFM_Command +public class Command_flatlands extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (TFM_ConfigEntry.FLATLANDS_GENERATE.getBoolean()) + if (ConfigEntry.FLATLANDS_GENERATE.getBoolean()) { - TFM_Flatlands.getInstance().sendToWorld(sender_p); + plugin.wm.flatlands.sendToWorld(sender_p); } else { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_fr.java b/src/me/totalfreedom/totalfreedommod/commands/Command_fr.java similarity index 68% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_fr.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_fr.java index 892b8a78..c6f82f6b 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_fr.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_fr.java @@ -1,17 +1,18 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.TFM_AdminList; -import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.player.FPlayer; +import me.totalfreedom.totalfreedommod.util.FUtil; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; 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.SUPER, source = SourceType.BOTH) +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH) @CommandParameters(description = "Freeze players (toggles on and off).", usage = "/ [target | purge]") -public class Command_fr extends TFM_Command +public class Command_fr extends FreedomCommand { private static boolean allFrozen = false; @@ -24,14 +25,14 @@ public class Command_fr extends TFM_Command if (allFrozen) { - TFM_Util.adminAction(sender.getName(), "Freezing all players", false); + FUtil.adminAction(sender.getName(), "Freezing all players", false); setAllFrozen(true); playerMsg("Players are now frozen."); for (Player player : Bukkit.getOnlinePlayers()) { - if (!TFM_AdminList.isSuperAdmin(player)) + if (!isAdmin(player)) { playerMsg(player, "You have been frozen due to rulebreakers, you will be unfrozen soon.", ChatColor.RED); } @@ -39,7 +40,7 @@ public class Command_fr extends TFM_Command } else { - TFM_Util.adminAction(sender.getName(), "Unfreezing all players", false); + FUtil.adminAction(sender.getName(), "Unfreezing all players", false); setAllFrozen(false); playerMsg("Players are now free to move."); } @@ -49,7 +50,7 @@ public class Command_fr extends TFM_Command if (args[0].toLowerCase().equals("purge")) { setAllFrozen(false); - TFM_Util.adminAction(sender.getName(), "Unfreezing all players", false); + FUtil.adminAction(sender.getName(), "Unfreezing all players", false); } else { @@ -57,11 +58,11 @@ public class Command_fr extends TFM_Command if (player == null) { - playerMsg(TFM_Command.PLAYER_NOT_FOUND, ChatColor.RED); + playerMsg(FreedomCommand.PLAYER_NOT_FOUND, ChatColor.RED); return true; } - final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); + final FPlayer playerdata = plugin.pl.getPlayer(player); playerdata.setFrozen(!playerdata.isFrozen()); playerMsg(player.getName() + " has been " + (playerdata.isFrozen() ? "frozen" : "unfrozen") + "."); @@ -75,7 +76,7 @@ public class Command_fr extends TFM_Command public static void setAllFrozen(boolean freeze) { allFrozen = freeze; - for (TFM_PlayerData data : TFM_PlayerData.PLAYER_DATA.values()) + for (FPlayer data : TotalFreedomMod.plugin.pl.playerMap.values()) { data.setFrozen(freeze); } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_fuckoff.java b/src/me/totalfreedom/totalfreedommod/commands/Command_fuckoff.java similarity index 81% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_fuckoff.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_fuckoff.java index 367001ec..d2018335 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_fuckoff.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_fuckoff.java @@ -1,14 +1,16 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_IN_GAME) +@CommandPermissions(level = PlayerRank.SENIOR_ADMIN, source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "You'll never even see it coming.", usage = "/") -public class Command_fuckoff extends TFM_Command +public class Command_fuckoff extends FreedomCommand { + @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gadmin.java b/src/me/totalfreedom/totalfreedommod/commands/Command_gadmin.java similarity index 72% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_gadmin.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_gadmin.java index af83696c..aa6f21be 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gadmin.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_gadmin.java @@ -1,20 +1,22 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import java.nio.charset.StandardCharsets; import java.util.Iterator; -import me.StevenLawson.TotalFreedomMod.TFM_BanManager; -import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; -import me.StevenLawson.TotalFreedomMod.TFM_Util; -import me.StevenLawson.TotalFreedomMod.TFM_UuidManager; +import java.util.UUID; +import me.totalfreedom.totalfreedommod.banning.FBan; +import me.totalfreedom.totalfreedommod.player.FPlayer; +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 = AdminLevel.SUPER, source = SourceType.BOTH, blockHostConsole = true) +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH, blockHostConsole = true) @CommandParameters( description = "Use admin commands on someone by hash. Use mode 'list' to get a player's hash. Other modes are kick, nameban, ipban, ban, op, deop, ci, fr, smite.", usage = "/ [list | [ ] ]") -public class Command_gadmin extends TFM_Command +public class Command_gadmin extends FreedomCommand { private enum GadminMode { @@ -53,6 +55,11 @@ public class Command_gadmin extends TFM_Command } } + public String getPlayerHash(Player player) + { + return UUID.nameUUIDFromBytes(player.getName().toLowerCase().getBytes(StandardCharsets.UTF_8)).toString().substring(0, 4); + } + @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { @@ -76,11 +83,10 @@ public class Command_gadmin extends TFM_Command while (it.hasNext()) { final Player player = it.next(); - final String hash = TFM_UuidManager.getUniqueId(player).toString().substring(0, 4); sender.sendMessage(ChatColor.GRAY + String.format("[ %s ] : [ %s ] - %s", player.getName(), ChatColor.stripColor(player.getDisplayName()), - hash)); + getPlayerHash(player))); } return true; } @@ -94,7 +100,7 @@ public class Command_gadmin extends TFM_Command while (it.hasNext() && target == null) { final Player player = it.next(); - final String hash = TFM_UuidManager.getUniqueId(player).toString().substring(0, 4); + final String hash = getPlayerHash(player); if (hash.equalsIgnoreCase(args[1])) { @@ -112,16 +118,15 @@ public class Command_gadmin extends TFM_Command { case KICK: { - TFM_Util.adminAction(sender.getName(), String.format("Kicking: %s.", target.getName()), false); + FUtil.adminAction(sender.getName(), String.format("Kicking: %s.", target.getName()), false); target.kickPlayer("Kicked by Administrator"); break; } case NAMEBAN: { - TFM_BanManager.addUuidBan(target); - - TFM_Util.adminAction(sender.getName(), String.format("Banning Name: %s.", target.getName()), true); + FUtil.adminAction(sender.getName(), String.format("Banning Name: %s.", target.getName()), true); + plugin.bm.addBan(FBan.forPlayerName(target, sender, null, null)); target.kickPlayer("Username banned by Administrator."); break; @@ -134,8 +139,8 @@ public class Command_gadmin extends TFM_Command { ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]); } - TFM_Util.adminAction(sender.getName(), String.format("Banning IP: %s.", ip), true); - TFM_BanManager.addIpBan(target); + FUtil.adminAction(sender.getName(), String.format("Banning IP: %s.", ip), true); + plugin.bm.addBan(FBan.forPlayerIp(ip, sender, null, null)); target.kickPlayer("IP address banned by Administrator."); @@ -149,10 +154,9 @@ public class Command_gadmin extends TFM_Command { ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]); } - TFM_Util.adminAction(sender.getName(), String.format("Banning Name: %s, IP: %s.", target.getName(), ip), true); + FUtil.adminAction(sender.getName(), String.format("Banning Name: %s, IP: %s.", target.getName(), ip), true); - TFM_BanManager.addUuidBan(target); - TFM_BanManager.addIpBan(target); + plugin.bm.addBan(FBan.forPlayer(target, sender)); target.kickPlayer("IP and username banned by Administrator."); @@ -160,17 +164,17 @@ public class Command_gadmin extends TFM_Command } case OP: { - TFM_Util.adminAction(sender.getName(), String.format("Opping %s.", target.getName()), false); + FUtil.adminAction(sender.getName(), String.format("Opping %s.", target.getName()), false); target.setOp(false); - target.sendMessage(TFM_Command.YOU_ARE_OP); + target.sendMessage(FreedomCommand.YOU_ARE_OP); break; } case DEOP: { - TFM_Util.adminAction(sender.getName(), String.format("Deopping %s.", target.getName()), false); + FUtil.adminAction(sender.getName(), String.format("Deopping %s.", target.getName()), false); target.setOp(false); - target.sendMessage(TFM_Command.YOU_ARE_NOT_OP); + target.sendMessage(FreedomCommand.YOU_ARE_NOT_OP); break; } @@ -182,7 +186,7 @@ public class Command_gadmin extends TFM_Command } case FR: { - TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(target); + FPlayer playerdata = plugin.pl.getPlayer(target); playerdata.setFrozen(!playerdata.isFrozen()); playerMsg(target.getName() + " has been " + (playerdata.isFrozen() ? "frozen" : "unfrozen") + "."); diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gcmd.java b/src/me/totalfreedom/totalfreedommod/commands/Command_gcmd.java similarity index 73% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_gcmd.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_gcmd.java index 3d9e064b..46f36d87 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gcmd.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_gcmd.java @@ -1,14 +1,15 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.TFM_CommandBlocker; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.commandblocker.CommandBlocker; import org.apache.commons.lang3.StringUtils; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH, blockHostConsole = true) +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH, blockHostConsole = true) @CommandParameters(description = "Send a command as someone else.", usage = "/ ") -public class Command_gcmd extends TFM_Command +public class Command_gcmd extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) @@ -22,13 +23,13 @@ public class Command_gcmd extends TFM_Command if (player == null) { - sender.sendMessage(TFM_Command.PLAYER_NOT_FOUND); + sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND); return true; } final String outCommand = StringUtils.join(args, " ", 1, args.length); - if (TFM_CommandBlocker.isCommandBlocked(outCommand, sender)) + if (plugin.cb.isCommandBlocked(outCommand, sender)) { return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_glist.java b/src/me/totalfreedom/totalfreedommod/commands/Command_glist.java similarity index 53% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_glist.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_glist.java index 28d5d1bc..cf4660cf 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_glist.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_glist.java @@ -1,122 +1,118 @@ -package me.StevenLawson.TotalFreedomMod.Commands; - -import java.util.ArrayList; -import java.util.List; -import me.StevenLawson.TotalFreedomMod.TFM_AdminList; -import me.StevenLawson.TotalFreedomMod.TFM_Ban; -import me.StevenLawson.TotalFreedomMod.TFM_BanManager; -import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; -import me.StevenLawson.TotalFreedomMod.TFM_Player; -import me.StevenLawson.TotalFreedomMod.TFM_PlayerList; -import me.StevenLawson.TotalFreedomMod.TFM_Util; -import me.StevenLawson.TotalFreedomMod.TFM_UuidManager; -import org.apache.commons.lang3.StringUtils; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH, blockHostConsole = true) -@CommandParameters(description = "Bans or unbans any player, even those who are not logged in anymore.", usage = "/ >") -public class Command_glist extends TFM_Command -{ - @Override - public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { - if (args.length < 1) - { - return false; - } - - if (args.length == 1) - { - if (args[0].equalsIgnoreCase("purge")) - { - if (TFM_AdminList.isSeniorAdmin(sender)) - { - TFM_PlayerList.purgeAll(); - playerMsg("Purged playerbase"); - } - else - { - playerMsg("Only Senior Admins may purge the userlist."); - } - return true; - } - else - { - return false; - } - } - else if (args.length == 2) - { - String username; - final List ips = new ArrayList(); - - final Player player = getPlayer(args[1]); - - if (player == null) - { - final TFM_Player entry = TFM_PlayerList.getEntry(TFM_UuidManager.getUniqueId(args[1])); - - if (entry == null) - { - playerMsg("Can't find that user. If target is not logged in, make sure that you spelled the name exactly."); - return true; - } - - username = entry.getLastLoginName(); - ips.addAll(entry.getIps()); - } - else - { - username = player.getName(); - final TFM_Player entry = TFM_PlayerList.getEntry(TFM_UuidManager.getUniqueId(player)); - ips.addAll(entry.getIps()); - } - - String mode = args[0].toLowerCase(); - if (mode.equalsIgnoreCase("ban")) - { - TFM_Util.adminAction(sender.getName(), "Banning " + username + " and IPs: " + StringUtils.join(ips, ", "), true); - - final Player target = getPlayer(username, true); - if (target != null) - { - 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: " + TFM_ConfigEntry.SERVER_BAN_URL.getString()); - } - else - { - TFM_BanManager.addUuidBan(new TFM_Ban(TFM_UuidManager.getUniqueId(username), username)); - } - - for (String ip : ips) - { - TFM_BanManager.addIpBan(new TFM_Ban(ip, username)); - TFM_BanManager.addIpBan(new TFM_Ban(TFM_Util.getFuzzyIp(ip), username)); - } - } - else if (mode.equalsIgnoreCase("unban")) - { - TFM_Util.adminAction(sender.getName(), "Unbanning " + username + " and IPs: " + StringUtils.join(ips, ", "), true); - TFM_BanManager.unbanUuid(TFM_UuidManager.getUniqueId(username)); - for (String ip : ips) - { - - TFM_BanManager.unbanIp(ip); - TFM_BanManager.unbanIp(TFM_Util.getFuzzyIp(ip)); - } - } - else - { - return false; - } - - return true; - } - else - { - return false; - } - } -} +package me.totalfreedom.totalfreedommod.commands; + +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import java.util.ArrayList; +import java.util.List; +import me.totalfreedom.totalfreedommod.banning.FBan; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import me.totalfreedom.totalfreedommod.player.PlayerData; +import me.totalfreedom.totalfreedommod.util.FUtil; +import org.apache.commons.lang3.StringUtils; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH, blockHostConsole = true) +@CommandParameters(description = "Bans or unbans any player, even those who are not logged in anymore.", usage = "/ >") +public class Command_glist extends FreedomCommand +{ + @Override + public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + { + if (args.length < 1) + { + return false; + } + + if (args.length == 1) + { + if (args[0].equalsIgnoreCase("purge")) + { + if (getAdmin(sender).getRank() == PlayerRank.SENIOR_ADMIN) + { + plugin.pl.purgeAllData(); + playerMsg("Purged playerbase."); + } + else + { + playerMsg("Only Senior Admins may purge the userlist."); + } + return true; + } + else + { + return false; + } + } + else if (args.length == 2) + { + String username; + final List ips = new ArrayList(); + + final Player player = getPlayer(args[1]); + + if (player == null) + { + final PlayerData entry = plugin.pl.getData(args[1]); + + if (entry == null) + { + playerMsg("Can't find that user. If target is not logged in, make sure that you spelled the name exactly."); + return true; + } + + username = entry.getUsername(); + ips.addAll(entry.getIps()); + } + else + { + username = player.getName(); + final PlayerData entry = plugin.pl.getData(player); + ips.addAll(entry.getIps()); + } + + String mode = args[0].toLowerCase(); + if (mode.equalsIgnoreCase("ban")) + { + FUtil.adminAction(sender.getName(), "Banning " + username + " and IPs: " + StringUtils.join(ips, ", "), true); + + final Player target = getPlayer(username, true); + if (target != null) + { + target.kickPlayer("You have been banned by " + sender.getName() + "\n If you think you have been banned wrongly, appeal here: " + ConfigEntry.SERVER_BAN_URL.getString()); + } + + FBan ban = FBan.forPlayerFuzzy(player, sender, null, null); + for (String ip : ips) + { + ban.addIp(ip); + ban.addIp(FUtil.getFuzzyIp(ip)); + } + plugin.bm.addBan(ban); + } + else if (mode.equalsIgnoreCase("unban")) + { + FUtil.adminAction(sender.getName(), "Unbanning " + username + " and IPs: " + StringUtils.join(ips, ", "), true); + plugin.bm.removeBan(plugin.bm.getByUsername(username)); + for (String ip : ips) + { + FBan ban = plugin.bm.getByIp(ip); + if (ban != null) + { + plugin.bm.removeBan(ban); + } + } + } + else + { + return false; + } + + return true; + } + else + { + return false; + } + } +} diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gtfo.java b/src/me/totalfreedom/totalfreedommod/commands/Command_gtfo.java similarity index 55% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_gtfo.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_gtfo.java index 194189b8..c26b17a0 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gtfo.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_gtfo.java @@ -1,11 +1,9 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.Bridge.TFM_WorldEditBridge; -import me.StevenLawson.TotalFreedomMod.TFM_Ban; -import me.StevenLawson.TotalFreedomMod.TFM_BanManager; -import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager; -import me.StevenLawson.TotalFreedomMod.TFM_Util; -import me.StevenLawson.TotalFreedomMod.TFM_UuidManager; +import me.totalfreedom.totalfreedommod.banning.FBan; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.util.FUtil; +import net.pravian.aero.util.Ips; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.bukkit.ChatColor; @@ -15,9 +13,9 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH, blockHostConsole = true) +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH, blockHostConsole = true) @CommandParameters(description = "Makes someone GTFO (deop and ip ban by username).", usage = "/ ") -public class Command_gtfo extends TFM_Command +public class Command_gtfo extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) @@ -31,7 +29,7 @@ public class Command_gtfo extends TFM_Command if (player == null) { - playerMsg(TFM_Command.PLAYER_NOT_FOUND, ChatColor.RED); + playerMsg(FreedomCommand.PLAYER_NOT_FOUND, ChatColor.RED); return true; } @@ -41,30 +39,30 @@ public class Command_gtfo extends TFM_Command reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " "); } - TFM_Util.bcastMsg(player.getName() + " has been a VERY naughty, naughty boy.", ChatColor.RED); + FUtil.bcastMsg(player.getName() + " has been a VERY naughty, naughty boy.", ChatColor.RED); - // Undo WorldEdits: + // Undo WorldEdits try { - TFM_WorldEditBridge.undo(player, 15); + plugin.web.undo(player, 15); } catch (NoClassDefFoundError ex) { } - // rollback - TFM_RollbackManager.rollback(player.getName()); + // Rollback + plugin.rb.rollback(player.getName()); - // deop + // Deop player.setOp(false); - // set gamemode to survival: + // Gamemode suvival player.setGameMode(GameMode.SURVIVAL); - // clear inventory: + // Clear inventory player.getInventory().clear(); - // strike with lightning effect: + // Strike with lightning final Location targetPos = player.getLocation(); for (int x = -1; x <= 1; x++) { @@ -75,30 +73,26 @@ public class Command_gtfo extends TFM_Command } } - // ban IP address: - String ip = TFM_Util.getFuzzyIp(player.getAddress().getAddress().getHostAddress()); + String ip = FUtil.getFuzzyIp(Ips.getIp(player)); + // Broadcast final StringBuilder bcast = new StringBuilder() .append(ChatColor.RED) .append("Banning: ") .append(player.getName()) .append(", IP: ") .append(ip); - if (reason != null) { bcast.append(" - Reason: ").append(ChatColor.YELLOW).append(reason); } + FUtil.bcastMsg(bcast.toString()); - TFM_Util.bcastMsg(bcast.toString()); + // Ban player + plugin.bm.addBan(FBan.forPlayerFuzzy(player, sender, null, reason)); - TFM_BanManager.addIpBan(new TFM_Ban(ip, player.getName(), sender.getName(), null, reason)); - - // ban username: - TFM_BanManager.addUuidBan(new TFM_Ban(TFM_UuidManager.getUniqueId(player), player.getName(), sender.getName(), null, reason)); - - // kick Player: - player.kickPlayer(ChatColor.RED + "GTFO" + (reason != null ? ("\nReason: " + ChatColor.YELLOW + reason) : "")); + // Kick player + player.kickPlayer(ChatColor.RED + "GTFO"); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_halt.java b/src/me/totalfreedom/totalfreedommod/commands/Command_halt.java similarity index 64% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_halt.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_halt.java index 1fe734c0..fe9da3c3 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_halt.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_halt.java @@ -1,15 +1,16 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.TFM_AdminList; -import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.admin.AdminList; +import me.totalfreedom.totalfreedommod.player.FPlayer; +import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH) +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH) @CommandParameters(description = "Halts a player", usage = "/ < | all | purge | list>") -public class Command_halt extends TFM_Command +public class Command_halt extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) @@ -21,13 +22,13 @@ public class Command_halt extends TFM_Command if (args[0].equalsIgnoreCase("all")) { - TFM_Util.adminAction(sender.getName(), "Halting all non-superadmins.", true); + FUtil.adminAction(sender.getName(), "Halting all non-superadmins.", true); int counter = 0; for (Player player : server.getOnlinePlayers()) { - if (!TFM_AdminList.isSuperAdmin(player)) + if (!plugin.al.isAdmin(player)) { - TFM_PlayerData.getPlayerData(player).setHalted(true); + plugin.pl.getPlayer(player).setHalted(true); counter++; } } @@ -37,12 +38,12 @@ public class Command_halt extends TFM_Command if (args[0].equalsIgnoreCase("purge")) { - TFM_Util.adminAction(sender.getName(), "Unhalting all players.", true); + FUtil.adminAction(sender.getName(), "Unhalting all players.", true); int counter = 0; for (Player player : server.getOnlinePlayers()) { - TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); - if (TFM_PlayerData.getPlayerData(player).isHalted()) + FPlayer playerdata = plugin.pl.getPlayer(player); + if (plugin.pl.getPlayer(player).isHalted()) { playerdata.setHalted(false); counter++; @@ -54,11 +55,11 @@ public class Command_halt extends TFM_Command if (args[0].equalsIgnoreCase("list")) { - TFM_PlayerData info; + FPlayer info; int count = 0; for (Player hp : server.getOnlinePlayers()) { - info = TFM_PlayerData.getPlayerData(hp); + info = plugin.pl.getPlayer(hp); if (info.isHalted()) { if (count == 0) @@ -80,20 +81,20 @@ public class Command_halt extends TFM_Command if (player == null) { - sender.sendMessage(TFM_Command.PLAYER_NOT_FOUND); + sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND); return true; } - TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); + FPlayer playerdata = plugin.pl.getPlayer(player); if (!playerdata.isHalted()) { - TFM_Util.adminAction(sender.getName(), "Halting " + player.getName(), true); + FUtil.adminAction(sender.getName(), "Halting " + player.getName(), true); playerdata.setHalted(true); return true; } else { - TFM_Util.adminAction(sender.getName(), "Unhalting " + player.getName(), true); + FUtil.adminAction(sender.getName(), "Unhalting " + player.getName(), true); playerdata.setHalted(false); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_health.java b/src/me/totalfreedom/totalfreedommod/commands/Command_health.java similarity index 89% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_health.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_health.java index c3c2d8a0..a681fac7 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_health.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_health.java @@ -1,9 +1,10 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; import java.text.DecimalFormat; import java.util.concurrent.atomic.AtomicInteger; -import me.StevenLawson.TotalFreedomMod.TFM_Log; -import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; +import me.totalfreedom.totalfreedommod.util.FLog; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; import org.apache.commons.lang.math.DoubleRange; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -12,9 +13,9 @@ import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH) +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH) @CommandParameters(description = "View ticks-per-second", usage = "/") -public class Command_health extends TFM_Command +public class Command_health extends FreedomCommand { private static final int BYTES_PER_MB = 1024 * 1024; private static final DoubleRange TPS_RANGE = new DoubleRange(20.0 - 0.1, 20.0 + 0.1); @@ -53,7 +54,7 @@ public class Command_health extends TFM_Command } catch (Exception ex) { - TFM_Log.severe(ex); + FLog.severe(ex); } } }.runTaskAsynchronously(plugin); diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_invis.java b/src/me/totalfreedom/totalfreedommod/commands/Command_invis.java similarity index 76% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_invis.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_invis.java index 32470327..506f73c7 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_invis.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_invis.java @@ -1,18 +1,19 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; import java.util.ArrayList; import java.util.List; -import me.StevenLawson.TotalFreedomMod.TFM_AdminList; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.totalfreedom.totalfreedommod.admin.AdminList; +import me.totalfreedom.totalfreedommod.util.FUtil; import org.apache.commons.lang3.StringUtils; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffectType; -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH) +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH) @CommandParameters(description = "Shows (optionally smites) invisisible players", usage = "/ (smite)") -public class Command_invis extends TFM_Command +public class Command_invis extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) @@ -22,7 +23,7 @@ public class Command_invis extends TFM_Command { if (args[0].equalsIgnoreCase("smite")) { - TFM_Util.adminAction(sender.getName(), "Smiting all invisible players", true); + FUtil.adminAction(sender.getName(), "Smiting all invisible players", true); smite = true; } else @@ -39,7 +40,7 @@ public class Command_invis extends TFM_Command if (player.hasPotionEffect(PotionEffectType.INVISIBILITY)) { players.add(player.getName()); - if (smite && !TFM_AdminList.isSuperAdmin(player)) + if (smite && !plugin.al.isAdmin(player)) { player.setHealth(0.0); smites++; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_jumppads.java b/src/me/totalfreedom/totalfreedommod/commands/Command_jumppads.java similarity index 55% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_jumppads.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_jumppads.java index 2d4ef943..0125b96b 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_jumppads.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_jumppads.java @@ -1,15 +1,16 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.TFM_Jumppads; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.Jumppads; +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 = AdminLevel.SUPER, source = SourceType.BOTH) +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH) @CommandParameters(description = "Manage jumppads", usage = "/ | strength >", aliases = "launchpads,jp") -public class Command_jumppads extends TFM_Command +public class Command_jumppads extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) @@ -23,26 +24,26 @@ public class Command_jumppads extends TFM_Command { if (args[0].equalsIgnoreCase("info")) { - playerMsg("Jumppads: " + (TFM_Jumppads.getMode().isOn() ? "Enabled" : "Disabled"), ChatColor.BLUE); - playerMsg("Sideways: " + (TFM_Jumppads.getMode() == TFM_Jumppads.JumpPadMode.NORMAL_AND_SIDEWAYS ? "Enabled" : "Disabled"), ChatColor.BLUE); - playerMsg("Strength: " + (TFM_Jumppads.getStrength() * 10 - 1), ChatColor.BLUE); + playerMsg("Jumppads: " + (plugin.jp.getMode().isOn() ? "Enabled" : "Disabled"), ChatColor.BLUE); + playerMsg("Sideways: " + (plugin.jp.getMode() == Jumppads.JumpPadMode.NORMAL_AND_SIDEWAYS ? "Enabled" : "Disabled"), ChatColor.BLUE); + playerMsg("Strength: " + (plugin.jp.getStrength() * 10 - 1), ChatColor.BLUE); return true; } if ("off".equals(args[0])) { - TFM_Util.adminAction(sender.getName(), "Disabling Jumppads", false); - TFM_Jumppads.setMode(TFM_Jumppads.JumpPadMode.OFF); + FUtil.adminAction(sender.getName(), "Disabling Jumppads", false); + plugin.jp.setMode(Jumppads.JumpPadMode.OFF); } else { - TFM_Util.adminAction(sender.getName(), "Enabling Jumppads", false); - TFM_Jumppads.setMode(TFM_Jumppads.JumpPadMode.MADGEEK); + FUtil.adminAction(sender.getName(), "Enabling Jumppads", false); + plugin.jp.setMode(Jumppads.JumpPadMode.MADGEEK); } } else { - if (TFM_Jumppads.getMode() == TFM_Jumppads.JumpPadMode.OFF) + if (plugin.jp.getMode() == Jumppads.JumpPadMode.OFF) { playerMsg("Jumppads are currently disabled, please enable them before changing jumppads settings."); return true; @@ -52,13 +53,13 @@ public class Command_jumppads extends TFM_Command { if ("off".equals(args[1])) { - TFM_Util.adminAction(sender.getName(), "Setting Jumppads mode to: Madgeek", false); - TFM_Jumppads.setMode(TFM_Jumppads.JumpPadMode.MADGEEK); + FUtil.adminAction(sender.getName(), "Setting Jumppads mode to: Madgeek", false); + plugin.jp.setMode(Jumppads.JumpPadMode.MADGEEK); } else { - TFM_Util.adminAction(sender.getName(), "Setting Jumppads mode to: Normal and Sideways", false); - TFM_Jumppads.setMode(TFM_Jumppads.JumpPadMode.NORMAL_AND_SIDEWAYS); + FUtil.adminAction(sender.getName(), "Setting Jumppads mode to: Normal and Sideways", false); + plugin.jp.setMode(Jumppads.JumpPadMode.NORMAL_AND_SIDEWAYS); } } else if (args[0].equalsIgnoreCase("strength")) @@ -80,8 +81,8 @@ public class Command_jumppads extends TFM_Command return true; } - TFM_Util.adminAction(sender.getName(), "Setting Jumppads strength to: " + String.valueOf(strength), false); - TFM_Jumppads.setStrength((strength / 10) + 0.1F); + FUtil.adminAction(sender.getName(), "Setting Jumppads strength to: " + String.valueOf(strength), false); + plugin.jp.setStrength((strength / 10) + 0.1F); } else { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_kicknoob.java b/src/me/totalfreedom/totalfreedommod/commands/Command_kicknoob.java similarity index 55% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_kicknoob.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_kicknoob.java index c66c9da3..ca2e94b1 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_kicknoob.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_kicknoob.java @@ -1,24 +1,25 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.TFM_AdminList; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.admin.AdminList; +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 = AdminLevel.SENIOR, source = SourceType.BOTH, blockHostConsole = true) +@CommandPermissions(level = PlayerRank.SENIOR_ADMIN, source = SourceType.BOTH, blockHostConsole = true) @CommandParameters(description = "Kick all non-superadmins on server.", usage = "/") -public class Command_kicknoob extends TFM_Command +public class Command_kicknoob extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - TFM_Util.adminAction(sender.getName(), "Disconnecting all non-superadmins.", true); + FUtil.adminAction(sender.getName(), "Disconnecting all non-superadmins.", true); for (Player player : server.getOnlinePlayers()) { - if (!TFM_AdminList.isSuperAdmin(player)) + if (!plugin.al.isAdmin(player)) { player.kickPlayer(ChatColor.RED + "All non-superadmins were kicked by " + sender.getName() + "."); } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_landmine.java b/src/me/totalfreedom/totalfreedommod/commands/Command_landmine.java similarity index 86% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_landmine.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_landmine.java index 683cdbec..b1d51441 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_landmine.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_landmine.java @@ -1,9 +1,10 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; @@ -13,20 +14,20 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.OP, source = SourceType.ONLY_IN_GAME) +@CommandPermissions(level = PlayerRank.OP, source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Set a landmine trap.", usage = "/") -public class Command_landmine extends TFM_Command +public class Command_landmine extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (!TFM_ConfigEntry.LANDMINES_ENABLED.getBoolean()) + if (!ConfigEntry.LANDMINES_ENABLED.getBoolean()) { playerMsg("The landmine is currently disabled.", ChatColor.GREEN); return true; } - if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) + if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) { playerMsg("Explosions are currently disabled.", ChatColor.GREEN); return true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lastcmd.java b/src/me/totalfreedom/totalfreedommod/commands/Command_lastcmd.java similarity index 69% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_lastcmd.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_lastcmd.java index 564179b8..daa8be2e 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lastcmd.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_lastcmd.java @@ -1,14 +1,15 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.player.FPlayer; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH) +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH) @CommandParameters(description = "Show the last command that someone used.", usage = "/ ") -public class Command_lastcmd extends TFM_Command +public class Command_lastcmd extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) @@ -22,11 +23,11 @@ public class Command_lastcmd extends TFM_Command if (player == null) { - playerMsg(TFM_Command.PLAYER_NOT_FOUND); + playerMsg(FreedomCommand.PLAYER_NOT_FOUND); return true; } - final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); + final FPlayer playerdata = plugin.pl.getPlayer(player); if (playerdata != null) { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_list.java b/src/me/totalfreedom/totalfreedommod/commands/Command_list.java similarity index 81% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_list.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_list.java index 708bebf8..9e837286 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_list.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_list.java @@ -1,19 +1,18 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; import java.util.ArrayList; import java.util.List; -import me.StevenLawson.TotalFreedomMod.TFM_AdminList; -import me.StevenLawson.TotalFreedomMod.TFM_PlayerRank; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +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 = AdminLevel.ALL, source = SourceType.BOTH) +@CommandPermissions(level = PlayerRank.NON_OP, source = SourceType.BOTH) @CommandParameters(description = "Lists the real names of all online players.", usage = "/ [-a | -i]", aliases = "who") -public class Command_list extends TFM_Command +public class Command_list extends FreedomCommand { private static enum ListFilter { @@ -30,7 +29,7 @@ public class Command_list extends TFM_Command return false; } - if (TFM_Util.isFromHostConsole(sender.getName())) + if (FUtil.isFromHostConsole(sender.getName())) { final List names = new ArrayList(); for (Player player : server.getOnlinePlayers()) @@ -72,17 +71,17 @@ public class Command_list extends TFM_Command final List names = new ArrayList(); for (Player player : server.getOnlinePlayers()) { - if (listFilter == ListFilter.ADMINS && !TFM_AdminList.isSuperAdmin(player)) + if (listFilter == ListFilter.ADMINS && !plugin.al.isAdmin(player)) { continue; } - if (listFilter == ListFilter.IMPOSTORS && !TFM_AdminList.isAdminImpostor(player)) + if (listFilter == ListFilter.IMPOSTORS && !plugin.al.isAdminImpostor(player)) { continue; } - names.add(TFM_PlayerRank.fromSender(player).getPrefix() + player.getName()); + names.add(plugin.rm.getRank(player).getColoredTag() + player.getName()); } onlineUsers.append("Connected "); diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_localspawn.java b/src/me/totalfreedom/totalfreedommod/commands/Command_localspawn.java similarity index 71% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_localspawn.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_localspawn.java index 3e89d82e..29f9a4de 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_localspawn.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_localspawn.java @@ -1,12 +1,13 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.ALL, source = SourceType.ONLY_IN_GAME) +@CommandPermissions(level = PlayerRank.NON_OP, source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Teleport to the spawn point for the current world.", usage = "/", aliases = "worldspawn,gotospawn") -public class Command_localspawn extends TFM_Command +public class Command_localspawn extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lockup.java b/src/me/totalfreedom/totalfreedommod/commands/Command_lockup.java similarity index 73% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_lockup.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_lockup.java index e1b599a2..29027765 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lockup.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_lockup.java @@ -1,16 +1,17 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.player.FPlayer; +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; import org.bukkit.scheduler.BukkitTask; -@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE, blockHostConsole = true) +@CommandPermissions(level = PlayerRank.SENIOR_ADMIN, source = SourceType.ONLY_CONSOLE, blockHostConsole = true) @CommandParameters(description = "Block target's minecraft input. This is evil, and I never should have wrote it.", usage = "/ on | off>>") -public class Command_lockup extends TFM_Command +public class Command_lockup extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) @@ -19,7 +20,7 @@ public class Command_lockup extends TFM_Command { if (args[0].equalsIgnoreCase("all")) { - TFM_Util.adminAction(sender.getName(), "Locking up all players", true); + FUtil.adminAction(sender.getName(), "Locking up all players", true); for (Player player : server.getOnlinePlayers()) { @@ -29,7 +30,7 @@ public class Command_lockup extends TFM_Command } else if (args[0].equalsIgnoreCase("purge")) { - TFM_Util.adminAction(sender.getName(), "Unlocking all players", true); + FUtil.adminAction(sender.getName(), "Unlocking all players", true); for (Player player : server.getOnlinePlayers()) { cancelLockup(player); @@ -50,11 +51,11 @@ public class Command_lockup extends TFM_Command if (player == null) { - sender.sendMessage(TFM_Command.PLAYER_NOT_FOUND); + sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND); return true; } - TFM_Util.adminAction(sender.getName(), "Locking up " + player.getName(), true); + FUtil.adminAction(sender.getName(), "Locking up " + player.getName(), true); startLockup(player); playerMsg("Locked up " + player.getName() + "."); } @@ -64,11 +65,11 @@ public class Command_lockup extends TFM_Command if (player == null) { - sender.sendMessage(TFM_Command.PLAYER_NOT_FOUND); + sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND); return true; } - TFM_Util.adminAction(sender.getName(), "Unlocking " + player.getName(), true); + FUtil.adminAction(sender.getName(), "Unlocking " + player.getName(), true); cancelLockup(player); playerMsg("Unlocked " + player.getName() + "."); } @@ -85,7 +86,7 @@ public class Command_lockup extends TFM_Command return true; } - private void cancelLockup(TFM_PlayerData playerdata) + private void cancelLockup(FPlayer playerdata) { BukkitTask lockupScheduleID = playerdata.getLockupScheduleID(); if (lockupScheduleID != null) @@ -97,12 +98,12 @@ public class Command_lockup extends TFM_Command private void cancelLockup(final Player player) { - cancelLockup(TFM_PlayerData.getPlayerData(player)); + cancelLockup(plugin.pl.getPlayer(player)); } private void startLockup(final Player player) { - final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); + final FPlayer playerdata = plugin.pl.getPlayer(player); cancelLockup(playerdata); diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_logs.java b/src/me/totalfreedom/totalfreedommod/commands/Command_logs.java similarity index 86% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_logs.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_logs.java index 91519785..8640e2d5 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_logs.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_logs.java @@ -1,5 +1,6 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; @@ -9,10 +10,10 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; -import me.StevenLawson.TotalFreedomMod.TFM_Admin; -import me.StevenLawson.TotalFreedomMod.TFM_Log; -import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import me.totalfreedom.totalfreedommod.admin.Admin; +import me.totalfreedom.totalfreedommod.util.FLog; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; import org.apache.commons.lang3.StringUtils; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -20,9 +21,9 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME) +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Register your connection with the TFM logviewer.", usage = "/ [off]") -public class Command_logs extends TFM_Command +public class Command_logs extends FreedomCommand { @Override public boolean run(final CommandSender sender, final Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) @@ -46,8 +47,8 @@ public class Command_logs extends TFM_Command public static void updateLogsRegistration(final CommandSender sender, final String targetName, final String targetIP, final LogsRegistrationMode mode) { - final String logsRegisterURL = TFM_ConfigEntry.LOGS_URL.getString(); - final String logsRegisterPassword = TFM_ConfigEntry.LOGS_SECRET.getString(); + final String logsRegisterURL = ConfigEntry.LOGS_URL.getString(); + final String logsRegisterPassword = ConfigEntry.LOGS_SECRET.getString(); if (logsRegisterURL == null || logsRegisterPassword == null || logsRegisterURL.isEmpty() || logsRegisterPassword.isEmpty()) { @@ -102,17 +103,17 @@ public class Command_logs extends TFM_Command } catch (Exception ex) { - TFM_Log.severe(ex); + FLog.severe(ex); } } }.runTaskAsynchronously(TotalFreedomMod.plugin); } - public static void deactivateSuperadmin(TFM_Admin superadmin) + public static void deactivateSuperadmin(Admin superadmin) { for (String ip : superadmin.getIps()) { - updateLogsRegistration(null, superadmin.getLastLoginName(), ip, Command_logs.LogsRegistrationMode.DELETE); + updateLogsRegistration(null, superadmin.getName(), ip, Command_logs.LogsRegistrationMode.DELETE); } } diff --git a/src/me/totalfreedom/totalfreedommod/commands/Command_moblimiter.java b/src/me/totalfreedom/totalfreedommod/commands/Command_moblimiter.java new file mode 100644 index 00000000..b91eeede --- /dev/null +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_moblimiter.java @@ -0,0 +1,83 @@ +package me.totalfreedom.totalfreedommod.commands; + +import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.GameRuleHandler; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.ONLY_CONSOLE) +@CommandParameters(description = "Control mob rezzing parameters.", usage = "/ |dragon|giant|ghast|slime>") +public class Command_moblimiter extends FreedomCommand +{ + @Override + public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + { + if (args.length < 1) + { + return false; + } + + if (args[0].equalsIgnoreCase("on")) + { + ConfigEntry.MOB_LIMITER_ENABLED.setBoolean(true); + } + else if (args[0].equalsIgnoreCase("off")) + { + ConfigEntry.MOB_LIMITER_ENABLED.setBoolean(false); + } + else if (args[0].equalsIgnoreCase("dragon")) + { + ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.getBoolean()); + } + else if (args[0].equalsIgnoreCase("giant")) + { + ConfigEntry.MOB_LIMITER_DISABLE_GIANT.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_GIANT.getBoolean()); + } + else if (args[0].equalsIgnoreCase("slime")) + { + ConfigEntry.MOB_LIMITER_DISABLE_SLIME.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_SLIME.getBoolean()); + } + else if (args[0].equalsIgnoreCase("ghast")) + { + ConfigEntry.MOB_LIMITER_DISABLE_GHAST.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_GHAST.getBoolean()); + } + else + { + if (args.length < 2) + { + return false; + } + + if (args[0].equalsIgnoreCase("setmax")) + { + try + { + ConfigEntry.MOB_LIMITER_MAX.setInteger(Math.max(0, Math.min(2000, Integer.parseInt(args[1])))); + } + catch (NumberFormatException nfex) + { + } + } + } + + if (ConfigEntry.MOB_LIMITER_ENABLED.getBoolean()) + { + sender.sendMessage("Moblimiter enabled. Maximum mobcount set to: " + ConfigEntry.MOB_LIMITER_MAX.getInteger() + "."); + + playerMsg("Dragon: " + (ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.getBoolean() ? "disabled" : "enabled") + "."); + playerMsg("Giant: " + (ConfigEntry.MOB_LIMITER_DISABLE_GIANT.getBoolean() ? "disabled" : "enabled") + "."); + playerMsg("Slime: " + (ConfigEntry.MOB_LIMITER_DISABLE_SLIME.getBoolean() ? "disabled" : "enabled") + "."); + playerMsg("Ghast: " + (ConfigEntry.MOB_LIMITER_DISABLE_GHAST.getBoolean() ? "disabled" : "enabled") + "."); + } + else + { + playerMsg("Moblimiter is disabled. No mob restrictions are in effect."); + } + + plugin.gr.setGameRule(GameRuleHandler.TFM_GameRule.DO_MOB_SPAWNING, !ConfigEntry.MOB_LIMITER_ENABLED.getBoolean()); + + return true; + } +} diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_mp.java b/src/me/totalfreedom/totalfreedommod/commands/Command_mp.java similarity index 83% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_mp.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_mp.java index 56e4cf18..10ae90f5 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_mp.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_mp.java @@ -1,5 +1,6 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.command.Command; @@ -12,9 +13,9 @@ import org.bukkit.entity.Ghast; import org.bukkit.entity.Player; import org.bukkit.entity.Slime; -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH) +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH) @CommandParameters(description = "Purge all mobs in all worlds.", usage = "/") -public class Command_mp extends TFM_Command +public class Command_mp extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_mp44.java b/src/me/totalfreedom/totalfreedommod/commands/Command_mp44.java similarity index 73% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_mp44.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_mp44.java index 2fceac64..657f5059 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_mp44.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_mp44.java @@ -1,7 +1,8 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; -import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import me.totalfreedom.totalfreedommod.player.FPlayer; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.command.Command; @@ -9,14 +10,14 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -@CommandPermissions(level = AdminLevel.OP, source = SourceType.ONLY_IN_GAME) +@CommandPermissions(level = PlayerRank.OP, source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Modern weaponry, FTW. Use 'draw' to start firing, 'sling' to stop firing.", usage = "/ ") -public class Command_mp44 extends TFM_Command +public class Command_mp44 extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (!TFM_ConfigEntry.MP44_ENABLED.getBoolean()) + if (!ConfigEntry.MP44_ENABLED.getBoolean()) { playerMsg("The mp44 is currently disabled.", ChatColor.GREEN); return true; @@ -27,7 +28,7 @@ public class Command_mp44 extends TFM_Command return false; } - TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(sender_p); + FPlayer playerdata = plugin.pl.getPlayer(sender_p); if (args[0].equalsIgnoreCase("draw")) { diff --git a/src/me/totalfreedom/totalfreedommod/commands/Command_nether.java b/src/me/totalfreedom/totalfreedommod/commands/Command_nether.java new file mode 100644 index 00000000..fc499d53 --- /dev/null +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_nether.java @@ -0,0 +1,19 @@ +package me.totalfreedom.totalfreedommod.commands; + +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.util.FUtil; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandPermissions(level = PlayerRank.NON_OP, source = SourceType.ONLY_IN_GAME) +@CommandParameters(description = "Goto the nether.", usage = "/") +public class Command_nether extends FreedomCommand +{ + @Override + public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + { + FUtil.gotoWorld(sender_p, server.getWorlds().get(0).getName() + "_nether"); + return true; + } +} diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_nf.java b/src/me/totalfreedom/totalfreedommod/commands/Command_nf.java similarity index 89% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_nf.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_nf.java index 5ee371a2..5bf7dae3 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_nf.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_nf.java @@ -1,120 +1,121 @@ -package me.StevenLawson.TotalFreedomMod.Commands; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import me.StevenLawson.TotalFreedomMod.TFM_CommandBlocker; -import org.apache.commons.lang3.StringUtils; -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.OP, source = SourceType.BOTH) -@CommandParameters(description = "NickFilter: Prefix any command with this command to replace nicknames in that command with real names. Nicknames should be prefixed with a !.", usage = "/ !") -public class Command_nf extends TFM_Command -{ - @Override - public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { - boolean nickMatched = false; - - final List outputCommand = new ArrayList(); - - if (args.length >= 1) - { - final List argsList = Arrays.asList(args); - for (String arg : argsList) - { - Player player = null; - - Matcher matcher = Pattern.compile("^!(.+)$").matcher(arg); - if (matcher.find()) - { - String displayName = matcher.group(1); - - player = getPlayerByDisplayName(displayName); - - if (player == null) - { - player = getPlayerByDisplayNameAlt(displayName); - - if (player == null) - { - sender.sendMessage(ChatColor.GRAY + "Can't find player by nickname: " + displayName); - return true; - } - } - } - - if (player == null) - { - outputCommand.add(arg); - } - else - { - nickMatched = true; - outputCommand.add(player.getName()); - } - } - } - - if (!nickMatched) - { - sender.sendMessage("No nicknames replaced in command."); - return true; - } - - String newCommand = StringUtils.join(outputCommand, " "); - - if (TFM_CommandBlocker.isCommandBlocked(newCommand, sender)) - { - // CommandBlocker handles messages and broadcasts - return true; - } - - sender.sendMessage("Sending command: \"" + newCommand + "\"."); - server.dispatchCommand(sender, newCommand); - - return true; - } - - private static Player getPlayerByDisplayName(String needle) - { - needle = needle.toLowerCase().trim(); - - for (Player player : Bukkit.getOnlinePlayers()) - { - if (player.getDisplayName().toLowerCase().trim().contains(needle)) - { - return player; - } - } - - return null; - } - - private static Player getPlayerByDisplayNameAlt(String needle) - { - needle = needle.toLowerCase().trim(); - - Integer minEditDistance = null; - Player minEditMatch = null; - - for (Player player : Bukkit.getOnlinePlayers()) - { - String haystack = player.getDisplayName().toLowerCase().trim(); - int editDistance = StringUtils.getLevenshteinDistance(needle, haystack.toLowerCase()); - if (minEditDistance == null || minEditDistance.intValue() > editDistance) - { - minEditDistance = editDistance; - minEditMatch = player; - } - } - - return minEditMatch; - } -} +package me.totalfreedom.totalfreedommod.commands; + +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import me.totalfreedom.totalfreedommod.commandblocker.CommandBlocker; +import org.apache.commons.lang3.StringUtils; +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 = PlayerRank.OP, source = SourceType.BOTH) +@CommandParameters(description = "NickFilter: Prefix any command with this command to replace nicknames in that command with real names. Nicknames should be prefixed with a !.", usage = "/ !") +public class Command_nf extends FreedomCommand +{ + @Override + public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + { + boolean nickMatched = false; + + final List outputCommand = new ArrayList(); + + if (args.length >= 1) + { + final List argsList = Arrays.asList(args); + for (String arg : argsList) + { + Player player = null; + + Matcher matcher = Pattern.compile("^!(.+)$").matcher(arg); + if (matcher.find()) + { + String displayName = matcher.group(1); + + player = getPlayerByDisplayName(displayName); + + if (player == null) + { + player = getPlayerByDisplayNameAlt(displayName); + + if (player == null) + { + sender.sendMessage(ChatColor.GRAY + "Can't find player by nickname: " + displayName); + return true; + } + } + } + + if (player == null) + { + outputCommand.add(arg); + } + else + { + nickMatched = true; + outputCommand.add(player.getName()); + } + } + } + + if (!nickMatched) + { + sender.sendMessage("No nicknames replaced in command."); + return true; + } + + String newCommand = StringUtils.join(outputCommand, " "); + + if (plugin.cb.isCommandBlocked(newCommand, sender)) + { + // CommandBlocker handles messages and broadcasts + return true; + } + + sender.sendMessage("Sending command: \"" + newCommand + "\"."); + server.dispatchCommand(sender, newCommand); + + return true; + } + + private static Player getPlayerByDisplayName(String needle) + { + needle = needle.toLowerCase().trim(); + + for (Player player : Bukkit.getOnlinePlayers()) + { + if (player.getDisplayName().toLowerCase().trim().contains(needle)) + { + return player; + } + } + + return null; + } + + private static Player getPlayerByDisplayNameAlt(String needle) + { + needle = needle.toLowerCase().trim(); + + Integer minEditDistance = null; + Player minEditMatch = null; + + for (Player player : Bukkit.getOnlinePlayers()) + { + String haystack = player.getDisplayName().toLowerCase().trim(); + int editDistance = StringUtils.getLevenshteinDistance(needle, haystack.toLowerCase()); + if (minEditDistance == null || minEditDistance.intValue() > editDistance) + { + minEditDistance = editDistance; + minEditMatch = player; + } + } + + return minEditMatch; + } +} diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_nickclean.java b/src/me/totalfreedom/totalfreedommod/commands/Command_nickclean.java similarity index 74% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_nickclean.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_nickclean.java index e75f0d0d..ca1fbb3a 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_nickclean.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_nickclean.java @@ -1,18 +1,18 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; import java.util.regex.Matcher; import java.util.regex.Pattern; -import me.StevenLawson.TotalFreedomMod.Bridge.TFM_EssentialsBridge; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +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 = AdminLevel.SUPER, source = SourceType.BOTH) +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH) @CommandParameters(description = "Essentials Interface Command - Remove distracting things from nicknames of all players on server.", usage = "/", aliases = "nc") -public class Command_nickclean extends TFM_Command +public class Command_nickclean extends FreedomCommand { private static final ChatColor[] BLOCKED = new ChatColor[] { @@ -27,12 +27,12 @@ public class Command_nickclean extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - TFM_Util.adminAction(sender.getName(), "Cleaning all nicknames.", false); + FUtil.adminAction(sender.getName(), "Cleaning all nicknames.", false); for (final Player player : server.getOnlinePlayers()) { final String playerName = player.getName(); - final String nickName = TFM_EssentialsBridge.getNickname(playerName); + final String nickName = plugin.esb.getNickname(playerName); if (nickName != null && !nickName.isEmpty() && !nickName.equalsIgnoreCase(playerName)) { final Matcher matcher = REGEX.matcher(nickName); @@ -40,7 +40,7 @@ public class Command_nickclean extends TFM_Command { final String newNickName = matcher.replaceAll(""); playerMsg(ChatColor.RESET + playerName + ": \"" + nickName + ChatColor.RESET + "\" -> \"" + newNickName + ChatColor.RESET + "\"."); - TFM_EssentialsBridge.setNickname(playerName, newNickName); + plugin.esb.setNickname(playerName, newNickName); } } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_nicknyan.java b/src/me/totalfreedom/totalfreedommod/commands/Command_nicknyan.java similarity index 73% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_nicknyan.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_nicknyan.java index 52952371..1e6b99b2 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_nicknyan.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_nicknyan.java @@ -1,16 +1,17 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.Bridge.TFM_EssentialsBridge; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.bridge.EssentialsBridge; +import me.totalfreedom.totalfreedommod.util.FUtil; 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.OP, source = SourceType.ONLY_IN_GAME) +@CommandPermissions(level = PlayerRank.OP, source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Essentials Interface Command - Nyanify your nickname.", usage = "/ < | off>") -public class Command_nicknyan extends TFM_Command +public class Command_nicknyan extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) @@ -22,12 +23,12 @@ public class Command_nicknyan extends TFM_Command if ("off".equals(args[0])) { - TFM_EssentialsBridge.setNickname(sender.getName(), null); + plugin.esb.setNickname(sender.getName(), null); playerMsg("Nickname cleared."); return true; } - final String nickPlain = ChatColor.stripColor(TFM_Util.colorize(args[0].trim())); + final String nickPlain = ChatColor.stripColor(FUtil.colorize(args[0].trim())); if (!nickPlain.matches("^[a-zA-Z_0-9\u00a7]+$")) { @@ -58,12 +59,12 @@ public class Command_nicknyan extends TFM_Command final char[] chars = nickPlain.toCharArray(); for (char c : chars) { - newNick.append(TFM_Util.randomChatColor()).append(c); + newNick.append(FUtil.randomChatColor()).append(c); } newNick.append(ChatColor.WHITE); - TFM_EssentialsBridge.setNickname(sender.getName(), newNick.toString()); + plugin.esb.setNickname(sender.getName(), newNick.toString()); playerMsg("Your nickname is now: " + newNick.toString()); diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_o.java b/src/me/totalfreedom/totalfreedommod/commands/Command_o.java similarity index 66% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_o.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_o.java index cbab2738..0c22fea6 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_o.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_o.java @@ -1,18 +1,19 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.player.FPlayer; +import me.totalfreedom.totalfreedommod.util.FUtil; import org.apache.commons.lang3.StringUtils; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH) +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH) @CommandParameters( description = "AdminChat - Talk privately with other admins. Using itself will toggle AdminChat on and off for all messages.", usage = "/ [message...]", aliases = "adminchat") -public class Command_o extends TFM_Command +public class Command_o extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) @@ -25,13 +26,13 @@ public class Command_o extends TFM_Command return true; } - TFM_PlayerData userinfo = TFM_PlayerData.getPlayerData(sender_p); + FPlayer userinfo = plugin.pl.getPlayer(sender_p); userinfo.setAdminChat(!userinfo.inAdminChat()); playerMsg("Toggled Admin Chat " + (userinfo.inAdminChat() ? "on" : "off") + "."); } else { - TFM_Util.adminChatMessage(sender, StringUtils.join(args, " "), senderIsConsole); + FUtil.adminChatMessage(sender, StringUtils.join(args, " "), senderIsConsole); } return true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_onlinemode.java b/src/me/totalfreedom/totalfreedommod/commands/Command_onlinemode.java similarity index 62% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_onlinemode.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_onlinemode.java index be73eeb4..d53a2927 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_onlinemode.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_onlinemode.java @@ -1,17 +1,16 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.TFM_AdminList; -import me.StevenLawson.TotalFreedomMod.TFM_Log; -import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.util.FLog; +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 = AdminLevel.ALL, source = SourceType.BOTH) +@CommandPermissions(level = PlayerRank.NON_OP, source = SourceType.BOTH) @CommandParameters(description = "Switch server online-mode on and off.", usage = "/ ") -public class Command_onlinemode extends TFM_Command +public class Command_onlinemode extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) @@ -23,21 +22,21 @@ public class Command_onlinemode extends TFM_Command } else { - boolean online_mode; + boolean onlineMode; - if (sender instanceof Player && !TFM_AdminList.isSeniorAdmin(sender, true)) + if (sender instanceof Player && !plugin.al.isSeniorAdmin(sender)) { - playerMsg(TFM_Command.MSG_NO_PERMS); + playerMsg(FreedomCommand.MSG_NO_PERMS); return true; } if (args[0].equalsIgnoreCase("on")) { - online_mode = true; + onlineMode = true; } else if (args[0].equalsIgnoreCase("off")) { - online_mode = false; + onlineMode = false; } else { @@ -46,9 +45,9 @@ public class Command_onlinemode extends TFM_Command try { - TFM_ServerInterface.setOnlineMode(online_mode); + plugin.si.setOnlineMode(onlineMode); - if (online_mode) + if (onlineMode) { for (Player player : server.getOnlinePlayers()) { @@ -56,13 +55,13 @@ public class Command_onlinemode extends TFM_Command } } - TFM_Util.adminAction(sender.getName(), "Turning player validation " + (online_mode ? "on" : "off") + ".", true); + FUtil.adminAction(sender.getName(), "Turning player validation " + (onlineMode ? "on" : "off") + ".", true); server.reload(); } catch (Exception ex) { - TFM_Log.severe(ex); + FLog.severe(ex); } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_op.java b/src/me/totalfreedom/totalfreedommod/commands/Command_op.java similarity index 68% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_op.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_op.java index 92d82fe7..b3e165d7 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_op.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_op.java @@ -1,59 +1,60 @@ -package me.StevenLawson.TotalFreedomMod.Commands; - -import me.StevenLawson.TotalFreedomMod.TFM_AdminList; -import me.StevenLawson.TotalFreedomMod.TFM_DepreciationAggregator; -import me.StevenLawson.TotalFreedomMod.TFM_Util; -import org.bukkit.ChatColor; -import org.bukkit.OfflinePlayer; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -@CommandPermissions(level = AdminLevel.OP, source = SourceType.BOTH) -@CommandParameters(description = "Makes a player operator", usage = "/ ") -public class Command_op extends TFM_Command -{ - @Override - public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { - if (args.length != 1) - { - return false; - } - - if (args[0].equalsIgnoreCase("all") || args[0].equalsIgnoreCase("everyone")) - { - playerMsg("Correct usage: /opall"); - return true; - } - - OfflinePlayer player = null; - for (Player onlinePlayer : server.getOnlinePlayers()) - { - if (args[0].equalsIgnoreCase(onlinePlayer.getName())) - { - player = onlinePlayer; - } - } - - // if the player is not online - if (player == null) - { - if (TFM_AdminList.isSuperAdmin(sender) || senderIsConsole) - { - player = TFM_DepreciationAggregator.getOfflinePlayer(server, args[0]); - } - else - { - playerMsg("That player is not online."); - playerMsg("You don't have permissions to OP offline players.", ChatColor.YELLOW); - return true; - } - } - - TFM_Util.adminAction(sender.getName(), "Opping " + player.getName(), false); - player.setOp(true); - - return true; - } -} +package me.totalfreedom.totalfreedommod.commands; + +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.admin.AdminList; +import me.totalfreedom.totalfreedommod.util.DepreciationAggregator; +import me.totalfreedom.totalfreedommod.util.FUtil; +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandPermissions(level = PlayerRank.OP, source = SourceType.BOTH) +@CommandParameters(description = "Makes a player operator", usage = "/ ") +public class Command_op extends FreedomCommand +{ + @Override + public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + { + if (args.length != 1) + { + return false; + } + + if (args[0].equalsIgnoreCase("all") || args[0].equalsIgnoreCase("everyone")) + { + playerMsg("Correct usage: /opall"); + return true; + } + + OfflinePlayer player = null; + for (Player onlinePlayer : server.getOnlinePlayers()) + { + if (args[0].equalsIgnoreCase(onlinePlayer.getName())) + { + player = onlinePlayer; + } + } + + // if the player is not online + if (player == null) + { + if (plugin.al.isAdmin(sender) || senderIsConsole) + { + player = DepreciationAggregator.getOfflinePlayer(server, args[0]); + } + else + { + playerMsg("That player is not online."); + playerMsg("You don't have permissions to OP offline players.", ChatColor.YELLOW); + return true; + } + } + + FUtil.adminAction(sender.getName(), "Opping " + player.getName(), false); + player.setOp(true); + + return true; + } +} diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_opall.java b/src/me/totalfreedom/totalfreedommod/commands/Command_opall.java similarity index 72% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_opall.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_opall.java index 9c68a129..770f98ad 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_opall.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_opall.java @@ -1,19 +1,20 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.GameMode; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH) +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH) @CommandParameters(description = "Op everyone on the server, optionally change everyone's gamemode at the same time.", usage = "/ [-c | -s]") -public class Command_opall extends TFM_Command +public class Command_opall extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - TFM_Util.adminAction(sender.getName(), "Opping all players on the server", false); + FUtil.adminAction(sender.getName(), "Opping all players on the server", false); boolean doSetGamemode = false; GameMode targetGamemode = GameMode.CREATIVE; @@ -34,7 +35,7 @@ public class Command_opall extends TFM_Command for (Player player : server.getOnlinePlayers()) { player.setOp(true); - player.sendMessage(TFM_Command.YOU_ARE_OP); + player.sendMessage(FreedomCommand.YOU_ARE_OP); if (doSetGamemode) { diff --git a/src/me/totalfreedom/totalfreedommod/commands/Command_opme.java b/src/me/totalfreedom/totalfreedommod/commands/Command_opme.java new file mode 100644 index 00000000..8f1caf03 --- /dev/null +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_opme.java @@ -0,0 +1,22 @@ +package me.totalfreedom.totalfreedommod.commands; + +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.util.FUtil; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.ONLY_IN_GAME) +@CommandParameters(description = "Automatically ops user.", usage = "/") +public class Command_opme extends FreedomCommand +{ + @Override + public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + { + FUtil.adminAction(sender.getName(), "Opping " + sender.getName(), false); + sender.setOp(true); + sender.sendMessage(FreedomCommand.YOU_ARE_OP); + + return true; + } +} diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_ops.java b/src/me/totalfreedom/totalfreedommod/commands/Command_ops.java similarity index 69% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_ops.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_ops.java index 959da28c..24c8d53d 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_ops.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_ops.java @@ -1,65 +1,66 @@ -package me.StevenLawson.TotalFreedomMod.Commands; - -import me.StevenLawson.TotalFreedomMod.TFM_AdminList; -import me.StevenLawson.TotalFreedomMod.TFM_Util; -import org.bukkit.OfflinePlayer; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -@CommandPermissions(level = AdminLevel.OP, source = SourceType.BOTH) -@CommandParameters(description = "Manager operators", usage = "/ ") -public class Command_ops extends TFM_Command -{ - @Override - public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { - if (args.length != 1) - { - return false; - } - - if (args[0].equals("count")) - { - int totalOps = server.getOperators().size(); - int onlineOps = 0; - - for (Player player : server.getOnlinePlayers()) - { - if (player.isOp()) - { - onlineOps++; - } - } - - playerMsg("Online OPs: " + onlineOps); - playerMsg("Offline OPs: " + (totalOps - onlineOps)); - playerMsg("Total OPs: " + totalOps); - - return true; - } - - if (args[0].equals("purge")) - { - if (!TFM_AdminList.isSuperAdmin(sender)) - { - playerMsg(TFM_Command.MSG_NO_PERMS); - return true; - } - - TFM_Util.adminAction(sender.getName(), "Purging all operators", true); - - for (OfflinePlayer player : server.getOperators()) - { - player.setOp(false); - if (player.isOnline()) - { - playerMsg(player.getPlayer(), TFM_Command.YOU_ARE_NOT_OP); - } - } - return true; - } - - return false; - } -} +package me.totalfreedom.totalfreedommod.commands; + +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.admin.AdminList; +import me.totalfreedom.totalfreedommod.util.FUtil; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandPermissions(level = PlayerRank.OP, source = SourceType.BOTH) +@CommandParameters(description = "Manager operators", usage = "/ ") +public class Command_ops extends FreedomCommand +{ + @Override + public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + { + if (args.length != 1) + { + return false; + } + + if (args[0].equals("count")) + { + int totalOps = server.getOperators().size(); + int onlineOps = 0; + + for (Player player : server.getOnlinePlayers()) + { + if (player.isOp()) + { + onlineOps++; + } + } + + playerMsg("Online OPs: " + onlineOps); + playerMsg("Offline OPs: " + (totalOps - onlineOps)); + playerMsg("Total OPs: " + totalOps); + + return true; + } + + if (args[0].equals("purge")) + { + if (!plugin.al.isAdmin(sender)) + { + playerMsg(FreedomCommand.MSG_NO_PERMS); + return true; + } + + FUtil.adminAction(sender.getName(), "Purging all operators", true); + + for (OfflinePlayer player : server.getOperators()) + { + player.setOp(false); + if (player.isOnline()) + { + playerMsg(player.getPlayer(), FreedomCommand.YOU_ARE_NOT_OP); + } + } + return true; + } + + return false; + } +} diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_orbit.java b/src/me/totalfreedom/totalfreedommod/commands/Command_orbit.java similarity index 72% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_orbit.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_orbit.java index c1499583..766695e8 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_orbit.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_orbit.java @@ -1,7 +1,8 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.player.FPlayer; +import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.command.Command; @@ -9,10 +10,10 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH) +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH) @CommandParameters(description = "POW!!! Right in the kisser! One of these days Alice, straight to the Moon!", usage = "/ [< | stop>]") -public class Command_orbit extends TFM_Command +public class Command_orbit extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) @@ -26,11 +27,11 @@ public class Command_orbit extends TFM_Command if (player == null) { - playerMsg(TFM_Command.PLAYER_NOT_FOUND, ChatColor.RED); + playerMsg(FreedomCommand.PLAYER_NOT_FOUND, ChatColor.RED); return true; } - TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); + FPlayer playerdata = plugin.pl.getPlayer(player); double strength = 10.0; @@ -58,7 +59,7 @@ public class Command_orbit extends TFM_Command playerdata.startOrbiting(strength); player.setVelocity(new Vector(0, strength, 0)); - TFM_Util.adminAction(sender.getName(), "Orbiting " + player.getName(), false); + FUtil.adminAction(sender.getName(), "Orbiting " + player.getName(), false); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_overlord.java b/src/me/totalfreedom/totalfreedommod/commands/Command_overlord.java similarity index 62% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_overlord.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_overlord.java index 419ffc83..f7e6a041 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_overlord.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_overlord.java @@ -1,31 +1,32 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.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 me.totalfreedom.totalfreedommod.admin.Admin; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import me.totalfreedom.totalfreedommod.config.MainConfig; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import net.pravian.aero.util.Ips; 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) +@CommandPermissions(level = PlayerRank.IMPOSTOR, source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Overlord - control this server in-game", usage = "access", aliases = "ov") -public class Command_overlord extends TFM_Command +public class Command_overlord extends FreedomCommand { @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))) + if (!ConfigEntry.OVERLORD_IPS.getList().contains(Ips.getIp(sender_p))) { try { - List ips = (List) TFM_MainConfig.getDefaults().get(TFM_ConfigEntry.OVERLORD_IPS.getConfigName()); - if (!ips.contains(TFM_Util.getIp(sender_p))) + List ips = (List) MainConfig.getDefaults().get(ConfigEntry.OVERLORD_IPS.getConfigName()); + if (!ips.contains(Ips.getIp(sender_p))) { throw new Exception(); } @@ -44,14 +45,18 @@ public class Command_overlord extends TFM_Command if (args[0].equals("addme")) { - TFM_AdminList.addSuperadmin(sender_p); + plugin.al.addAdmin(new Admin(sender_p)); playerMsg("ok"); return true; } if (args[0].equals("removeme")) { - TFM_AdminList.removeSuperadmin(sender_p); + Admin admin = plugin.al.getAdmin(sender_p); + if (admin != null) + { + plugin.al.removeAdmin(admin); + } playerMsg("ok"); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_permban.java b/src/me/totalfreedom/totalfreedommod/commands/Command_permban.java similarity index 58% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_permban.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_permban.java index f1d32a44..a1155d7a 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_permban.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_permban.java @@ -1,15 +1,14 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.TFM_PermbanList; -import org.apache.commons.lang3.StringUtils; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_CONSOLE, blockHostConsole = true) +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.ONLY_CONSOLE, blockHostConsole = true) @CommandParameters(description = "Manage permanently banned players and IPs.", usage = "/ reload") -public class Command_permban extends TFM_Command +public class Command_permban extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) @@ -25,10 +24,11 @@ public class Command_permban extends TFM_Command } playerMsg("Reloading permban list...", ChatColor.RED); - TFM_PermbanList.load(); + plugin.pb.stop(); + plugin.pb.start(); playerMsg("Reloaded permban list."); - playerMsg(TFM_PermbanList.getPermbannedIps().size() + " IPs and " - + TFM_PermbanList.getPermbannedPlayers().size() + " usernames loaded."); + playerMsg(plugin.pb.getPermbannedIps().size() + " IPs and " + + plugin.pb.getPermbannedNames().size() + " usernames loaded."); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_plugincontrol.java b/src/me/totalfreedom/totalfreedommod/commands/Command_plugincontrol.java similarity index 94% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_plugincontrol.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_plugincontrol.java index 74755ce3..9a64ac58 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_plugincontrol.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_plugincontrol.java @@ -1,5 +1,6 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; import org.apache.commons.lang3.StringUtils; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -8,9 +9,9 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; -@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.BOTH) +@CommandPermissions(level = PlayerRank.SENIOR_ADMIN, source = SourceType.BOTH) @CommandParameters(description = "Manage plugins", usage = "/ < > | list>", aliases = "plc") -public class Command_plugincontrol extends TFM_Command +public class Command_plugincontrol extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) @@ -124,6 +125,7 @@ public class Command_plugincontrol extends TFM_Command return false; } + @Override public Plugin getPlugin(String name) { for (Plugin serverPlugin : server.getPluginManager().getPlugins()) diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_potion.java b/src/me/totalfreedom/totalfreedommod/commands/Command_potion.java similarity index 87% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_potion.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_potion.java index 42bccfe2..0276a730 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_potion.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_potion.java @@ -1,9 +1,10 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; import java.util.ArrayList; import java.util.List; -import me.StevenLawson.TotalFreedomMod.TFM_AdminList; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.totalfreedom.totalfreedommod.admin.AdminList; +import me.totalfreedom.totalfreedommod.util.FUtil; import org.apache.commons.lang3.StringUtils; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -12,11 +13,11 @@ import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -@CommandPermissions(level = AdminLevel.OP, source = SourceType.BOTH) +@CommandPermissions(level = PlayerRank.OP, source = SourceType.BOTH) @CommandParameters( description = "Manipulate potion effects. Duration is measured in server ticks (~20 ticks per second).", usage = "/ [target name]>") -public class Command_potion extends TFM_Command +public class Command_potion extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) @@ -37,12 +38,12 @@ public class Command_potion extends TFM_Command } else if (args[0].equalsIgnoreCase("clearall")) { - if (!(TFM_AdminList.isSuperAdmin(sender) || senderIsConsole)) + if (!(plugin.al.isAdmin(sender) || senderIsConsole)) { - playerMsg(TFM_Command.MSG_NO_PERMS); + playerMsg(FreedomCommand.MSG_NO_PERMS); return true; } - TFM_Util.adminAction(sender.getName(), "Cleared all potion effects from all players", true); + FUtil.adminAction(sender.getName(), "Cleared all potion effects from all players", true); for (Player target : server.getOnlinePlayers()) { for (PotionEffect potion_effect : target.getActivePotionEffects()) @@ -61,14 +62,14 @@ public class Command_potion extends TFM_Command if (target == null) { - playerMsg(TFM_Command.PLAYER_NOT_FOUND, ChatColor.RED); + playerMsg(FreedomCommand.PLAYER_NOT_FOUND, ChatColor.RED); return true; } } if (!target.equals(sender_p)) { - if (!TFM_AdminList.isSuperAdmin(sender)) + if (!plugin.al.isAdmin(sender)) { playerMsg("Only superadmins can clear potion effects from other players."); return true; @@ -105,14 +106,14 @@ public class Command_potion extends TFM_Command if (target == null) { - playerMsg(TFM_Command.PLAYER_NOT_FOUND, ChatColor.RED); + playerMsg(FreedomCommand.PLAYER_NOT_FOUND, ChatColor.RED); return true; } } if (!target.equals(sender_p)) { - if (!TFM_AdminList.isSuperAdmin(sender)) + if (!plugin.al.isAdmin(sender)) { sender.sendMessage("Only superadmins can apply potion effects to other players."); return true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_premium.java b/src/me/totalfreedom/totalfreedommod/commands/Command_premium.java similarity index 86% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_premium.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_premium.java index d141b2a4..87dae6e1 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_premium.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_premium.java @@ -1,19 +1,20 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; -import me.StevenLawson.TotalFreedomMod.TFM_Log; +import me.totalfreedom.totalfreedommod.util.FLog; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH) +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH) @CommandParameters(description = "Validates if a given account is premium.", usage = "/ ", aliases = "prem") -public class Command_premium extends TFM_Command +public class Command_premium extends FreedomCommand { @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) @@ -61,7 +62,7 @@ public class Command_premium extends TFM_Command } catch (Exception ex) { - TFM_Log.severe(ex); + FLog.severe(ex); playerMsg("There was an error querying the mojang server.", ChatColor.RED); } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_protectarea.java b/src/me/totalfreedom/totalfreedommod/commands/Command_protectarea.java similarity index 73% rename from src/me/StevenLawson/TotalFreedomMod/Commands/Command_protectarea.java rename to src/me/totalfreedom/totalfreedommod/commands/Command_protectarea.java index 14433ea3..99a8d802 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_protectarea.java +++ b/src/me/totalfreedom/totalfreedommod/commands/Command_protectarea.java @@ -1,23 +1,24 @@ -package me.StevenLawson.TotalFreedomMod.Commands; +package me.totalfreedom.totalfreedommod.commands; -import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; -import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import me.totalfreedom.totalfreedommod.permission.PlayerRank; +import me.totalfreedom.totalfreedommod.ProtectArea; import org.apache.commons.lang3.StringUtils; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH) +@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH) @CommandParameters( description = "Protect areas so that only superadmins can directly modify blocks in those areas. WorldEdit and other such plugins might bypass this.", usage = "/ | add