Skip to content

Commit

Permalink
fix: refill missing method
Browse files Browse the repository at this point in the history
  • Loading branch information
StarWishsama committed Sep 15, 2024
1 parent 762a6e0 commit 2624b45
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,6 @@ private void onPluginStart() {
cfgManager.load();
registry.load(this);

// Inject downstream extra staff
SlimefunExtended.register(this);

logger.log(Level.INFO, "正在加载数据库...");
if (PlayerProfileMigrator.getInstance().hasOldData()
|| BlockStorageMigrator.getInstance().hasOldData()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -410,6 +411,36 @@ public void enableTicker(@Nonnull Location l) {
}
}

/**
* This enables the ticker at the given {@link Location} and adds it to our "queue".
*
* @param uuid
* The {@link UUID} to activate
*/
public void enableTicker(@Nonnull UUID uuid, @Nonnull Location l) {
Validate.notNull(uuid, "UUID cannot be null!");
Validate.notNull(l, "Location cannot be null!");

synchronized (tickingUniversalLocations) {
ChunkPosition chunk = new ChunkPosition(l.getWorld(), l.getBlockX() >> 4, l.getBlockZ() >> 4);

/*
Note that all the values in #tickingLocations must be thread-safe.
Thus, the choice is between the CHM KeySet or a synchronized set.
The CHM KeySet was chosen since it at least permits multiple concurrent
reads without blocking.
*/
Map<Location, UUID> newValue = new ConcurrentHashMap<>();
Map<Location, UUID> oldValue = tickingUniversalLocations.putIfAbsent(chunk, newValue);

/**
* This is faster than doing computeIfAbsent(...)
* on a ConcurrentHashMap because it won't block the Thread for too long
*/
Objects.requireNonNullElse(oldValue, newValue).put(l, uuid);
}
}

/**
* This method disables the ticker at the given {@link Location} and removes it from our internal
* "queue".
Expand Down

0 comments on commit 2624b45

Please sign in to comment.