Skip to content

Commit

Permalink
Merge branch 'mcMMO-Dev:master' into update
Browse files Browse the repository at this point in the history
  • Loading branch information
SrBedrock authored Nov 10, 2024
2 parents 865115b + 04eefae commit d1c1ed8
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 257 deletions.
7 changes: 6 additions & 1 deletion Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Version 2.2.027
Fixed Ricocheted arrows losing some data after a ricochet
Fixed concurrency issue with Folia regarding locale strings
Fixed concurrency issue with Folia regarding COTW summons

Version 2.2.026
Fixed NPE on ChunkUnloadEvent
Fixed NullPointerException on ChunkUnloadEvent

Version 2.2.025
Fixed NullPointerException spam when processing XP for child skills
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.nossr50.mcMMO</groupId>
<artifactId>mcMMO</artifactId>
<version>2.2.026</version>
<version>2.2.027-SNAPSHOT</version>
<name>mcMMO</name>
<url>https://github.com/mcMMO-Dev/mcMMO</url>
<scm>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ public void onEntityDeathLowest(final EntityDeathEvent event) {
public void onEntityDeath(final EntityDeathEvent event) {
final LivingEntity entity = event.getEntity();

if (mcMMO.getTransientEntityTracker().isTransientSummon(entity)) {
if (mcMMO.getTransientEntityTracker().isTransient(entity)) {
mcMMO.getTransientEntityTracker().removeSummon(entity, null, false);
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/gmail/nossr50/locale/LocaleLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public final class LocaleLoader {
private static final String BUNDLE_ROOT = "com.gmail.nossr50.locale.locale";
private static final String OVERRIDE_FILE_NAME = "locale_override.properties";
private static Map<String, String> bundleCache = new HashMap<>();
// Must be concurrent to accomodate Folia
private static Map<String, String> bundleCache = new ConcurrentHashMap<>();
private static ResourceBundle bundle = null;
private static ResourceBundle filesystemBundle = null;
private static ResourceBundle enBundle = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,17 @@ private void spawnReflectedArrow(@NotNull Plugin pluginRef, @NotNull Arrow origi

// Spawn new arrow with the reflected direction
Arrow spawnedArrow = originalArrow.getWorld().spawnArrow(origin, reflectedDirection, 1, 1);
// copy some properties from the old arrow
spawnedArrow.setShooter(originalArrowShooter);
spawnedArrow.setCritical(originalArrow.isCritical());
spawnedArrow.setPierceLevel(originalArrow.getPierceLevel());
spawnedArrow.setPickupStatus(originalArrow.getPickupStatus());
spawnedArrow.setKnockbackStrength(originalArrow.getKnockbackStrength());

// copy metadata from old arrow
ProjectileUtils.copyArrowMetadata(pluginRef, originalArrow, spawnedArrow);
originalArrow.remove();
// copy metadata from old arrow
spawnedArrow.setShooter(originalArrowShooter);
// add important metadata to new arrow
spawnedArrow.setMetadata(MetadataConstants.METADATA_KEY_BOUNCE_COUNT,
new FixedMetadataValue(pluginRef, bounceCount + 1));
spawnedArrow.setMetadata(MetadataConstants.METADATA_KEY_SPAWNED_ARROW,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,12 @@ public boolean isCOTWItem(@NotNull ItemStack itemStack) {
}

private int getAmountCurrentlySummoned(@NotNull CallOfTheWildType callOfTheWildType) {
return mcMMO.getTransientEntityTracker().getAmountCurrentlySummoned(getPlayer().getUniqueId(), callOfTheWildType);
return mcMMO.getTransientEntityTracker().summonCountForPlayerOfType(getPlayer().getUniqueId(), callOfTheWildType);
}

private void addToTracker(@NotNull LivingEntity livingEntity, @NotNull CallOfTheWildType callOfTheWildType) {
mcMMO.getTransientEntityTracker().registerEntity(getPlayer().getUniqueId(), new TrackedTamingEntity(livingEntity, callOfTheWildType, getPlayer()));
mcMMO.getTransientEntityTracker().addSummon(getPlayer().getUniqueId(),
new TrackedTamingEntity(livingEntity, callOfTheWildType, getPlayer()));
}

/**
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/com/gmail/nossr50/util/MobMetadataUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.gmail.nossr50.api.exceptions.IncompleteNamespacedKeyRegister;
import com.gmail.nossr50.config.PersistentDataConfig;
import com.gmail.nossr50.metadata.MobMetaFlagType;
import com.google.common.collect.MapMaker;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
Expand All @@ -12,13 +13,13 @@

import java.util.EnumMap;
import java.util.HashSet;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentMap;

import static com.gmail.nossr50.util.MetadataService.*;

//TODO: Use SpawnReason where appropriate instead of MobMetaFlagType
public final class MobMetadataUtils {
private static final @NotNull WeakHashMap<Entity, HashSet<MobMetaFlagType>> mobRegistry; //transient data
private static final @NotNull ConcurrentMap<Entity, HashSet<MobMetaFlagType>> mobRegistry; //transient data
private static final @NotNull EnumMap<MobMetaFlagType, NamespacedKey> mobFlagKeyMap; //used for persistent data
private static boolean isUsingPersistentData = false;

Expand All @@ -28,7 +29,14 @@ private MobMetadataUtils() {

static {
mobFlagKeyMap = new EnumMap<>(MobMetaFlagType.class);
mobRegistry = new WeakHashMap<>();
// Using Guava for a concurrent weak hash map
// IMPORTANT: This type of map uses == for comparison over .equals(),
// which is a violation of map contract
mobRegistry = new MapMaker()
.weakKeys()
.concurrencyLevel(4)
.makeMap();

initMobFlagKeyMap();

for (MobMetaFlagType metaFlagType : MobMetaFlagType.values()) {
Expand Down Expand Up @@ -92,7 +100,7 @@ public static boolean hasMobFlags(@NotNull LivingEntity livingEntity) {

return false;
} else {
return mobRegistry.containsKey(livingEntity) && mobRegistry.get(livingEntity).size() > 0;
return mobRegistry.containsKey(livingEntity) && !mobRegistry.get(livingEntity).isEmpty();
}
}

Expand Down
Loading

0 comments on commit d1c1ed8

Please sign in to comment.