mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-12-18 15:17:36 +01:00
Update for async player chat stupidity
This commit is contained in:
parent
ba5be6071f
commit
684214ff6a
2
pom.xml
2
pom.xml
@ -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 -->
|
||||
|
@ -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>();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user