add more sensibly named API for grabbing the UserBlockTracker

This commit is contained in:
nossr50 2024-05-19 12:58:13 -07:00
parent 8b82163e3d
commit 9b09f06ad8
14 changed files with 58 additions and 31 deletions

View File

@ -1,4 +1,7 @@
Version 2.2.013
(API) Deprecated com.gmail.nossr50.mcMMO.getPlaceStore
(API) Added com.gmail.nossr50.mcMMO.getUserBlockTracker
(API) Added com.gmail.nossr50.mcMMO.getChunkManager
(API) Added new methods to com.gmail.nossr50.util.blockmeta.UserBlockTracker for easier readability
(API) Deprecated the old poorly named methods in UserBlockTracker
(Codebase) Cleaned up and organized unit tests relating to UserBlockTracker

View File

@ -310,7 +310,7 @@ public class BlockListener implements Listener {
// Minecraft is dumb, the events still throw when a plant "grows" higher than the max block height. Even though no new block is created
if (BlockUtils.isWithinWorldBounds(block)) {
mcMMO.getPlaceStore().setEligible(block);
mcMMO.getUserBlockTracker().setEligible(block);
}
}
@ -400,14 +400,14 @@ public class BlockListener implements Listener {
else if (BlockUtils.affectedBySuperBreaker(blockState)
&& (ItemUtils.isPickaxe(heldItem) || ItemUtils.isHoe(heldItem))
&& mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.MINING)
&& !mcMMO.getPlaceStore().isIneligible(blockState)) {
&& !mcMMO.getUserBlockTracker().isIneligible(blockState)) {
MiningManager miningManager = mcMMOPlayer.getMiningManager();
miningManager.miningBlockCheck(blockState);
}
/* WOOD CUTTING */
else if (BlockUtils.hasWoodcuttingXP(blockState) && ItemUtils.isAxe(heldItem)
&& mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.WOODCUTTING) && !mcMMO.getPlaceStore().isIneligible(blockState)) {
&& mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.WOODCUTTING) && !mcMMO.getUserBlockTracker().isIneligible(blockState)) {
WoodcuttingManager woodcuttingManager = mcMMOPlayer.getWoodcuttingManager();
if (woodcuttingManager.canUseTreeFeller(heldItem)) {
woodcuttingManager.processTreeFeller(blockState);
@ -422,7 +422,7 @@ public class BlockListener implements Listener {
}
/* EXCAVATION */
else if (BlockUtils.affectedByGigaDrillBreaker(blockState) && ItemUtils.isShovel(heldItem) && mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.EXCAVATION) && !mcMMO.getPlaceStore().isIneligible(blockState)) {
else if (BlockUtils.affectedByGigaDrillBreaker(blockState) && ItemUtils.isShovel(heldItem) && mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.EXCAVATION) && !mcMMO.getUserBlockTracker().isIneligible(blockState)) {
ExcavationManager excavationManager = mcMMOPlayer.getExcavationManager();
excavationManager.excavationBlockCheck(blockState);
@ -687,7 +687,7 @@ public class BlockListener implements Listener {
if (UserManager.getPlayer(player).isDebugMode())
{
if (mcMMO.getPlaceStore().isIneligible(blockState))
if (mcMMO.getUserBlockTracker().isIneligible(blockState))
player.sendMessage("[mcMMO DEBUG] This block is not natural and does not reward treasures/XP");
else
{

View File

@ -12,7 +12,8 @@ public class ChunkListener implements Listener {
@EventHandler(ignoreCancelled = true)
public void onChunkUnload(ChunkUnloadEvent event) {
List<LivingEntity> matchingEntities = mcMMO.getTransientEntityTracker().getAllTransientEntitiesInChunk(event.getChunk());
List<LivingEntity> matchingEntities
= mcMMO.getTransientEntityTracker().getAllTransientEntitiesInChunk(event.getChunk());
for(LivingEntity livingEntity : matchingEntities) {
mcMMO.getTransientEntityTracker().removeSummon(livingEntity, null, false);
}

View File

@ -206,8 +206,8 @@ public class EntityListener implements Listener {
if (entity instanceof FallingBlock || entity instanceof Enderman) {
boolean isTracked = entity.hasMetadata(MetadataConstants.METADATA_KEY_TRAVELING_BLOCK);
if (mcMMO.getPlaceStore().isIneligible(block) && !isTracked) {
mcMMO.getPlaceStore().setEligible(block);
if (mcMMO.getUserBlockTracker().isIneligible(block) && !isTracked) {
mcMMO.getUserBlockTracker().setEligible(block);
entity.setMetadata(MetadataConstants.METADATA_KEY_TRAVELING_BLOCK, MetadataConstants.MCMMO_METADATA_VALUE);
TravelingBlockMetaCleanup metaCleanupTask = new TravelingBlockMetaCleanup(entity, pluginRef);
@ -221,8 +221,8 @@ public class EntityListener implements Listener {
//Redstone ore fire this event and should be ignored
}
else {
if (mcMMO.getPlaceStore().isIneligible(block)) {
mcMMO.getPlaceStore().setEligible(block);
if (mcMMO.getUserBlockTracker().isIneligible(block)) {
mcMMO.getUserBlockTracker().setEligible(block);
}
}
}

View File

@ -852,7 +852,7 @@ public class PlayerListener implements Listener {
case "NETHER_WART_BLOCK":
case "POTATO":
case "MANGROVE_PROPAGULE":
mcMMO.getPlaceStore().setEligible(blockState);
mcMMO.getUserBlockTracker().setEligible(blockState);
break;
}
}

View File

@ -32,7 +32,7 @@ public class WorldListener implements Listener {
// Using 50 ms later as I do not know of a way to run one tick later (safely)
plugin.getFoliaLib().getImpl().runLater(() -> {
for (BlockState blockState : event.getBlocks()) {
mcMMO.getPlaceStore().setEligible(blockState);
mcMMO.getUserBlockTracker().setEligible(blockState);
}
}, 1);
}
@ -48,7 +48,7 @@ public class WorldListener implements Listener {
if (WorldBlacklist.isWorldBlacklisted(event.getWorld()))
return;
mcMMO.getPlaceStore().unloadWorld(event.getWorld());
mcMMO.getChunkManager().unloadWorld(event.getWorld());
}
/**
@ -64,6 +64,6 @@ public class WorldListener implements Listener {
Chunk chunk = event.getChunk();
mcMMO.getPlaceStore().chunkUnloaded(chunk.getX(), chunk.getZ(), event.getWorld());
mcMMO.getChunkManager().chunkUnloaded(chunk.getX(), chunk.getZ(), event.getWorld());
}
}

View File

@ -39,6 +39,7 @@ import com.gmail.nossr50.skills.salvage.salvageables.SimpleSalvageableManager;
import com.gmail.nossr50.util.*;
import com.gmail.nossr50.util.blockmeta.ChunkManager;
import com.gmail.nossr50.util.blockmeta.ChunkManagerFactory;
import com.gmail.nossr50.util.blockmeta.UserBlockTracker;
import com.gmail.nossr50.util.commands.CommandRegistrationManager;
import com.gmail.nossr50.util.compat.CompatibilityManager;
import com.gmail.nossr50.util.experience.FormulaManager;
@ -443,6 +444,28 @@ public class mcMMO extends JavaPlugin {
return formulaManager;
}
/**
* Get the {@link UserBlockTracker}.
* @return the {@link UserBlockTracker}
*/
public static UserBlockTracker getUserBlockTracker() {
return placeStore;
}
/**
* Get the chunk manager.
* @return the chunk manager
*/
public static ChunkManager getChunkManager() {
return placeStore;
}
/**
* Get the chunk manager.
* @deprecated Use {@link #getChunkManager()} or {@link #getUserBlockTracker()} instead.
* @return the chunk manager
*/
@Deprecated(since = "2.2.013", forRemoval = true)
public static ChunkManager getPlaceStore() {
return placeStore;
}

View File

@ -19,7 +19,7 @@ public class StickyPistonTrackerTask extends CancellableRunnable {
@Override
public void run() {
if (!mcMMO.getPlaceStore().isIneligible(movedBlock.getRelative(direction))) {
if (!mcMMO.getUserBlockTracker().isIneligible(movedBlock.getRelative(direction))) {
return;
}
@ -29,7 +29,7 @@ public class StickyPistonTrackerTask extends CancellableRunnable {
}
// The sticky piston actually pulled the block so move the PlaceStore data
mcMMO.getPlaceStore().setEligible(movedBlock.getRelative(direction));
mcMMO.getUserBlockTracker().setEligible(movedBlock.getRelative(direction));
BlockUtils.setUnnaturalBlock(movedBlock);
}
}

View File

@ -282,7 +282,7 @@ public class HerbalismManager extends SkillManager {
if (brokenPlant.getLocation().equals(originalBreak.getBlock().getLocation())) {
//If its the same block as the original, we are going to directly check it for being a valid XP gain and add it to the nonChorusBlocks list even if its a chorus block
//This stops a delay from happening when bringing up the XP bar for chorus trees
if (!mcMMO.getPlaceStore().isIneligible(originalBreak)) {
if (!mcMMO.getUserBlockTracker().isIneligible(originalBreak)) {
//Even if its a chorus block, the original break will be moved to nonChorusBlocks for immediate XP rewards
noDelayPlantBlocks.add(brokenPlant);
} else {
@ -335,7 +335,7 @@ public class HerbalismManager extends SkillManager {
BlockData plantData = brokenPlantState.getBlockData();
//Check for double drops
if (!mcMMO.getPlaceStore().isIneligible(brokenPlant)) {
if (!mcMMO.getUserBlockTracker().isIneligible(brokenPlant)) {
/*
*
@ -413,7 +413,7 @@ public class HerbalismManager extends SkillManager {
BlockState brokenBlockNewState = brokenPlantBlock.getState();
BlockData plantData = brokenBlockNewState.getBlockData();
if (mcMMO.getPlaceStore().isIneligible(brokenBlockNewState)) {
if (mcMMO.getUserBlockTracker().isIneligible(brokenBlockNewState)) {
/*
*
* Unnatural Blocks
@ -427,7 +427,7 @@ public class HerbalismManager extends SkillManager {
}
//Mark it as natural again as it is being broken
mcMMO.getPlaceStore().setEligible(brokenBlockNewState);
mcMMO.getUserBlockTracker().setEligible(brokenBlockNewState);
} else {
/*
*
@ -489,9 +489,9 @@ public class HerbalismManager extends SkillManager {
continue;
}
if (mcMMO.getPlaceStore().isIneligible(brokenBlockNewState)) {
if (mcMMO.getUserBlockTracker().isIneligible(brokenBlockNewState)) {
//Mark it as natural again as it is being broken
mcMMO.getPlaceStore().setEligible(brokenBlockNewState);
mcMMO.getUserBlockTracker().setEligible(brokenBlockNewState);
} else {
//TODO: Do we care about chorus flower age?
//Calculate XP for the old type

View File

@ -181,7 +181,7 @@ public class MiningManager extends SkillManager {
//Containers usually have 0 XP unless someone edited their config in a very strange way
if (ExperienceConfig.getInstance().getXp(PrimarySkillType.MINING, targetBlock) != 0
&& !(targetBlock instanceof Container)
&& !mcMMO.getPlaceStore().isIneligible(targetBlock)) {
&& !mcMMO.getUserBlockTracker().isIneligible(targetBlock)) {
if (BlockUtils.isOre(blockState)) {
ores.add(blockState);
} else {
@ -216,7 +216,7 @@ public class MiningManager extends SkillManager {
Misc.spawnItem(getPlayer(), Misc.getBlockCenter(blockState), new ItemStack(blockState.getType()), ItemSpawnReason.BLAST_MINING_ORES); // Initial block that would have been dropped
if (mcMMO.p.getAdvancedConfig().isBlastMiningBonusDropsEnabled() && !mcMMO.getPlaceStore().isIneligible(blockState)) {
if (mcMMO.p.getAdvancedConfig().isBlastMiningBonusDropsEnabled() && !mcMMO.getUserBlockTracker().isIneligible(blockState)) {
for (int i = 1; i < dropMultiplier; i++) {
// Bukkit.broadcastMessage("Bonus Drop on Ore: "+blockState.getType().toString());
Misc.spawnItem(getPlayer(), Misc.getBlockCenter(blockState), new ItemStack(blockState.getType()), ItemSpawnReason.BLAST_MINING_ORES_BONUS_DROP); // Initial block that would have been dropped

View File

@ -113,7 +113,7 @@ public class WoodcuttingManager extends SkillManager {
}
public void processWoodcuttingBlockXP(@NotNull BlockState blockState) {
if (mcMMO.getPlaceStore().isIneligible(blockState))
if (mcMMO.getUserBlockTracker().isIneligible(blockState))
return;
int xp = getExperienceFromLog(blockState);
@ -269,7 +269,7 @@ public class WoodcuttingManager extends SkillManager {
* in treeFellerBlocks.
*/
private boolean processTreeFellerTargetBlock(@NotNull BlockState blockState, @NotNull List<BlockState> futureCenterBlocks, @NotNull Set<BlockState> treeFellerBlocks) {
if (treeFellerBlocks.contains(blockState) || mcMMO.getPlaceStore().isIneligible(blockState)) {
if (treeFellerBlocks.contains(blockState) || mcMMO.getUserBlockTracker().isIneligible(blockState)) {
return false;
}
@ -373,7 +373,7 @@ public class WoodcuttingManager extends SkillManager {
* @return Amount of experience
*/
private static int processTreeFellerXPGains(BlockState blockState, int woodCount) {
if (mcMMO.getPlaceStore().isIneligible(blockState))
if (mcMMO.getUserBlockTracker().isIneligible(blockState))
return 0;
int rawXP = ExperienceConfig.getInstance().getXp(PrimarySkillType.WOODCUTTING, blockState.getType());

View File

@ -65,7 +65,7 @@ public final class BlockUtils {
* @param block target block
*/
public static void setUnnaturalBlock(@NotNull Block block) {
mcMMO.getPlaceStore().setIneligible(block);
mcMMO.getUserBlockTracker().setIneligible(block);
// Failsafe against lingering metadata
if (block.hasMetadata(MetadataConstants.METADATA_KEY_BONUS_DROPS))
@ -82,7 +82,7 @@ public final class BlockUtils {
block.removeMetadata(MetadataConstants.METADATA_KEY_REPLANT, mcMMO.p);
}
mcMMO.getPlaceStore().setEligible(block);
mcMMO.getUserBlockTracker().setEligible(block);
}
/**

View File

@ -7,7 +7,7 @@ import org.jetbrains.annotations.NotNull;
/**
* Contains blockstore methods that are safe for external plugins to access.
* An instance can be retrieved via {@link mcMMO#getPlaceStore() mcMMO.getPlaceStore()}
* An instance can be retrieved via {@link mcMMO#getUserBlockTracker() mcMMO.getPlaceStore()}
*/
public interface UserBlockTracker {
/**

View File

@ -74,7 +74,7 @@ public abstract class MMOTestEnvironment {
// place store
chunkManager = mock(ChunkManager.class);
when(mcMMO.getPlaceStore()).thenReturn(chunkManager);
when(mcMMO.getUserBlockTracker()).thenReturn(chunkManager);
// shut off mod manager for woodcutting
when(mcMMO.getModManager()).thenReturn(mock(ModManager.class));