mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-09-30 04:37:52 +02:00
Faster Bukkit world lookup using an IdentityHashMap and computeIfAbsent
This commit is contained in:
parent
c239908aa3
commit
75d983fea3
@ -18,16 +18,16 @@
|
|||||||
*/
|
*/
|
||||||
package com.plotsquared.bukkit.util;
|
package com.plotsquared.bukkit.util;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
|
||||||
import com.plotsquared.core.location.World;
|
import com.plotsquared.core.location.World;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
|
import java.util.IdentityHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class BukkitWorld implements World<org.bukkit.World> {
|
public class BukkitWorld implements World<org.bukkit.World> {
|
||||||
|
|
||||||
private static final Map<String, BukkitWorld> worldMap = Maps.newHashMap();
|
private static final Map<org.bukkit.World, BukkitWorld> worldMap = new IdentityHashMap<>();
|
||||||
private static final boolean HAS_MIN_Y;
|
private static final boolean HAS_MIN_Y;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@ -68,13 +68,7 @@ public class BukkitWorld implements World<org.bukkit.World> {
|
|||||||
* @return World instance
|
* @return World instance
|
||||||
*/
|
*/
|
||||||
public static @NonNull BukkitWorld of(final org.bukkit.World world) {
|
public static @NonNull BukkitWorld of(final org.bukkit.World world) {
|
||||||
BukkitWorld bukkitWorld = worldMap.get(world.getName());
|
return worldMap.computeIfAbsent(world, BukkitWorld::new);
|
||||||
if (bukkitWorld != null && bukkitWorld.getPlatformWorld().equals(world)) {
|
|
||||||
return bukkitWorld;
|
|
||||||
}
|
|
||||||
bukkitWorld = new BukkitWorld(world);
|
|
||||||
worldMap.put(world.getName(), bukkitWorld);
|
|
||||||
return bukkitWorld;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user