Update for async player chat stupidity

This commit is contained in:
zml2008 2012-08-04 19:17:52 -07:00
parent ba5be6071f
commit 684214ff6a
5 changed files with 46 additions and 28 deletions

View File

@ -47,7 +47,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.2.5-R4.1-SNAPSHOT</version>
<version>1.3.1-R0.1-SNAPSHOT</version>
</dependency>
<!-- CommandBook -->

View File

@ -24,6 +24,8 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import com.sk89q.commandbook.CommandBook;
import com.sk89q.commandbook.GodComponent;
@ -73,7 +75,7 @@ public class ConfigurationManager {
/**
* Holds configurations for different worlds.
*/
private Map<String, WorldConfiguration> worlds;
private ConcurrentMap<String, WorldConfiguration> worlds;
/**
* The global configuration for use when loading worlds
@ -115,7 +117,7 @@ public class ConfigurationManager {
*/
public ConfigurationManager(WorldGuardPlugin plugin) {
this.plugin = plugin;
this.worlds = new HashMap<String, WorldConfiguration>();
this.worlds = new ConcurrentHashMap<String, WorldConfiguration>();
}
/**
@ -145,7 +147,7 @@ public void load() {
config.removeProperty("auto-invincible-permission");
usePlayerMove = config.getBoolean(
"use-player-move-event", true);
hostKeys = new HashMap<String, String>();
Object hostKeysRaw = config.getProperty("host-keys");
if (hostKeysRaw == null || !(hostKeysRaw instanceof Map)) {
@ -193,10 +195,14 @@ public void unload() {
public WorldConfiguration get(World world) {
String worldName = world.getName();
WorldConfiguration config = worlds.get(worldName);
WorldConfiguration newConfig = null;
if (config == null) {
config = new WorldConfiguration(plugin, worldName, this.config);
worlds.put(worldName, config);
while (config == null) {
if (newConfig == null) {
newConfig = new WorldConfiguration(plugin, worldName, this.config);
}
worlds.putIfAbsent(world.getName(), newConfig);
config = worlds.get(world.getName());
}
return config;

View File

@ -37,10 +37,10 @@
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
@ -304,7 +304,7 @@ public void onPlayerJoin(PlayerJoinEvent event) {
}
@EventHandler(ignoreCancelled = true)
public void onPlayerChat(PlayerChatEvent event) {
public void onPlayerChat(AsyncPlayerChatEvent event) {
Player player = event.getPlayer();
WorldConfiguration wcfg = plugin.getGlobalStateManager().get(player.getWorld());
if (wcfg.useRegions) {
@ -329,7 +329,7 @@ public void onPlayerChat(PlayerChatEvent event) {
public void onPlayerLogin(PlayerLoginEvent event) {
Player player = event.getPlayer();
ConfigurationManager cfg = plugin.getGlobalStateManager();
String hostKey = cfg.hostKeys.get(player.getName().toLowerCase());
if (hostKey != null) {
String hostname = event.getHostname();
@ -337,7 +337,7 @@ public void onPlayerLogin(PlayerLoginEvent event) {
if (colonIndex != -1) {
hostname = hostname.substring(0, colonIndex);
}
if (!hostname.equals(hostKey)) {
event.disallow(PlayerLoginEvent.Result.KICK_OTHER,
"You did not join with the valid host key!");

View File

@ -23,6 +23,7 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import org.bukkit.Location;
@ -65,7 +66,7 @@ public class GlobalRegionManager {
/**
* Map of managers per-world.
*/
private HashMap<String, RegionManager> managers;
private ConcurrentHashMap<String, RegionManager> managers;
/**
* Stores the list of modification dates for the world files. This allows
@ -81,7 +82,7 @@ public class GlobalRegionManager {
public GlobalRegionManager(WorldGuardPlugin plugin) {
this.plugin = plugin;
config = plugin.getGlobalStateManager();
managers = new HashMap<String, RegionManager>();
managers = new ConcurrentHashMap<String, RegionManager>();
lastModified = new HashMap<String, Long>();
}
@ -125,19 +126,27 @@ public void unloadAll() {
lastModified.clear();
}
public RegionManager load(World world) {
RegionManager manager = create(world);
managers.put(world.getName(), manager);
return manager;
}
/**
* Load region information for a world.
*
* @param world The world to load a RegionManager for
* @return the loaded RegionManager
*/
public RegionManager load(World world) {
public RegionManager create(World world) {
String name = world.getName();
boolean sql = config.useSqlDatabase;
String sqlDsn = config.sqlDsn;
ProtectionDatabase database;
File file = null;
try {
if (!config.useSqlDatabase) {
if (!sql) {
file = getPath(name);
database = new YAMLDatabase(file, plugin.getLogger());
@ -149,8 +158,6 @@ public RegionManager load(World world) {
// Create a manager
RegionManager manager = new FlatRegionManager(database);
managers.put(name, manager);
manager.load();
plugin.getLogger().info(manager.getRegions().size()
@ -159,7 +166,7 @@ public RegionManager load(World world) {
return manager;
} catch (ProtectionDatabaseException e) {
String logStr = "Failed to load regions from ";
if (config.useSqlDatabase) {
if (sql) {
logStr += "SQL Database <" + config.sqlDsn + "> ";
} else {
logStr += "file \"" + file + "\" ";
@ -224,9 +231,14 @@ public void reloadChanged() {
*/
public RegionManager get(World world) {
RegionManager manager = managers.get(world.getName());
RegionManager newManager = null;
if (manager == null) {
manager = load(world);
while (manager == null) {
if (newManager == null) {
newManager = create(world);
}
managers.putIfAbsent(world.getName(), newManager);
manager = managers.get(world.getName());
}
return manager;
@ -353,7 +365,7 @@ public boolean allows(StateFlag flag, Location loc, LocalPlayer player) {
return true;
}
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
RegionManager mgr = get(world);
return mgr.getApplicableRegions(toVector(loc)).allows(flag, player);
}
}

View File

@ -70,7 +70,7 @@ public MySQLDatabase(ConfigurationManager config, String world, Logger logger) t
try {
connect();
try {
// Test if the database is up to date, if not throw a critical error
PreparedStatement verTest = this.conn.prepareStatement(
@ -132,7 +132,7 @@ private void connect() throws SQLException {
} catch (SQLException ex) {
// Test if the dummy query failed because the connection is dead,
// and if it is mark the connection as closed (the MySQL Driver
// does not ensure that the connection is marked as closed unless
// does not ensure that the connection is marked as closed unless
// the close() method has been called.
if ("08S01".equals(ex.getSQLState())) {
conn.close();
@ -148,7 +148,7 @@ private void loadFlags(ProtectedRegion region) {
// @TODO: Iterate _ONCE_
try {
PreparedStatement flagsStatement = this.conn.prepareStatement(
"SELECT " +
"SELECT " +
"`region_flag`.`flag`, " +
"`region_flag`.`value` " +
"FROM `region_flag` " +
@ -463,7 +463,7 @@ public void load() throws ProtectionDatabaseException {
parentSets = new HashMap<ProtectedRegion,String>();
// We load the cuboid regions first, as this is likely to be the
// largest dataset. This should save time in regards to the putAll()s
// largest dataset. This should save time in regards to the putAll()s
this.loadCuboid();
Map<String,ProtectedRegion> regions = this.cuboidRegions;
this.cuboidRegions = null;
@ -625,10 +625,10 @@ private Map<String,Integer> getGroupIds(String... groupnames) {
* b) If the region is not in the database, we insert it
* 3) We iterate over what remains of the in-database list and remove
* them from the database
*
*
* TODO: Look at adding/removing/updating the database when the in
* memory region is created/remove/updated
*
*
* @see com.sk89q.worldguard.protection.databases.ProtectionDatabase#save()
*/
public void save() throws ProtectionDatabaseException {