Skip to content

Commit

Permalink
update UserBlockTracker API
Browse files Browse the repository at this point in the history
  • Loading branch information
nossr50 committed May 19, 2024
1 parent c2054a5 commit 8b82163
Show file tree
Hide file tree
Showing 26 changed files with 700 additions and 460 deletions.
8 changes: 8 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Version 2.2.013
(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

NOTES:
Not planning to delete the deprecated methods in UserBlockTracker anytime soon, as nothing has really changed other than the names

Version 2.2.012
Fixed a bug where Daze would cause an exception in older game versions (1.20.4 and older)

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.nossr50.mcMMO</groupId>
<artifactId>mcMMO</artifactId>
<version>2.2.012</version>
<version>2.2.013-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 @@ -4,7 +4,6 @@
import com.gmail.nossr50.datatypes.skills.alchemy.AlchemyPotion;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.ItemUtils;
import com.gmail.nossr50.util.PotionUtil;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.Material;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.gmail.nossr50.datatypes.skills.alchemy;

import com.gmail.nossr50.util.PotionUtil;
import org.bukkit.Bukkit;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionEffect;

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/gmail/nossr50/listeners/BlockListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public void onBlockGrow(BlockGrowEvent event) {

// 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().setFalse(block);
mcMMO.getPlaceStore().setEligible(block);
}
}

Expand Down Expand Up @@ -400,14 +400,14 @@ public void onBlockBreak(BlockBreakEvent event) {
else if (BlockUtils.affectedBySuperBreaker(blockState)
&& (ItemUtils.isPickaxe(heldItem) || ItemUtils.isHoe(heldItem))
&& mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.MINING)
&& !mcMMO.getPlaceStore().isTrue(blockState)) {
&& !mcMMO.getPlaceStore().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().isTrue(blockState)) {
&& mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.WOODCUTTING) && !mcMMO.getPlaceStore().isIneligible(blockState)) {
WoodcuttingManager woodcuttingManager = mcMMOPlayer.getWoodcuttingManager();
if (woodcuttingManager.canUseTreeFeller(heldItem)) {
woodcuttingManager.processTreeFeller(blockState);
Expand All @@ -422,7 +422,7 @@ else if (BlockUtils.hasWoodcuttingXP(blockState) && ItemUtils.isAxe(heldItem)
}

/* EXCAVATION */
else if (BlockUtils.affectedByGigaDrillBreaker(blockState) && ItemUtils.isShovel(heldItem) && mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.EXCAVATION) && !mcMMO.getPlaceStore().isTrue(blockState)) {
else if (BlockUtils.affectedByGigaDrillBreaker(blockState) && ItemUtils.isShovel(heldItem) && mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.EXCAVATION) && !mcMMO.getPlaceStore().isIneligible(blockState)) {
ExcavationManager excavationManager = mcMMOPlayer.getExcavationManager();
excavationManager.excavationBlockCheck(blockState);

Expand Down Expand Up @@ -687,7 +687,7 @@ private void debugStickDump(Player player, BlockState blockState) {

if (UserManager.getPlayer(player).isDebugMode())
{
if (mcMMO.getPlaceStore().isTrue(blockState))
if (mcMMO.getPlaceStore().isIneligible(blockState))
player.sendMessage("[mcMMO DEBUG] This block is not natural and does not reward treasures/XP");
else
{
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/com/gmail/nossr50/listeners/EntityListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.projectiles.ProjectileSource;
import org.jetbrains.annotations.NotNull;

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

Expand Down Expand Up @@ -207,8 +206,8 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) {
if (entity instanceof FallingBlock || entity instanceof Enderman) {
boolean isTracked = entity.hasMetadata(MetadataConstants.METADATA_KEY_TRAVELING_BLOCK);

if (mcMMO.getPlaceStore().isTrue(block) && !isTracked) {
mcMMO.getPlaceStore().setFalse(block);
if (mcMMO.getPlaceStore().isIneligible(block) && !isTracked) {
mcMMO.getPlaceStore().setEligible(block);

entity.setMetadata(MetadataConstants.METADATA_KEY_TRAVELING_BLOCK, MetadataConstants.MCMMO_METADATA_VALUE);
TravelingBlockMetaCleanup metaCleanupTask = new TravelingBlockMetaCleanup(entity, pluginRef);
Expand All @@ -222,8 +221,8 @@ else if (isTracked) {
//Redstone ore fire this event and should be ignored
}
else {
if (mcMMO.getPlaceStore().isTrue(block)) {
mcMMO.getPlaceStore().setFalse(block);
if (mcMMO.getPlaceStore().isIneligible(block)) {
mcMMO.getPlaceStore().setEligible(block);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ public void onPlayerInteractMonitor(PlayerInteractEvent event) {
case "NETHER_WART_BLOCK":
case "POTATO":
case "MANGROVE_PROPAGULE":
mcMMO.getPlaceStore().setFalse(blockState);
mcMMO.getPlaceStore().setEligible(blockState);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void onStructureGrow(StructureGrowEvent event) {
// 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().setFalse(blockState);
mcMMO.getPlaceStore().setEligible(blockState);
}
}, 1);
}
Expand Down
47 changes: 0 additions & 47 deletions src/main/java/com/gmail/nossr50/runnables/PistonTrackerTask.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public StickyPistonTrackerTask(BlockFace direction, Block block, Block movedBloc

@Override
public void run() {
if (!mcMMO.getPlaceStore().isTrue(movedBlock.getRelative(direction))) {
if (!mcMMO.getPlaceStore().isIneligible(movedBlock.getRelative(direction))) {
return;
}

Expand All @@ -29,7 +29,7 @@ public void run() {
}

// The sticky piston actually pulled the block so move the PlaceStore data
mcMMO.getPlaceStore().setFalse(movedBlock.getRelative(direction));
mcMMO.getPlaceStore().setEligible(movedBlock.getRelative(direction));
BlockUtils.setUnnaturalBlock(movedBlock);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.skills.alchemy.Alchemy;
import com.gmail.nossr50.skills.alchemy.AlchemyPotionBrewer;
import com.gmail.nossr50.util.CancellableRunnable;
import com.gmail.nossr50.util.ContainerMetadataUtils;
import com.gmail.nossr50.util.player.UserManager;
Expand All @@ -17,7 +16,6 @@
import java.util.Arrays;

import static com.gmail.nossr50.skills.alchemy.AlchemyPotionBrewer.isValidBrew;
import static com.gmail.nossr50.util.EventUtils.getMcMMOPlayer;

public class AlchemyBrewCheckTask extends CancellableRunnable {
private final BrewingStand brewingStand;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ private void processHerbalismOnBlocksBroken(BlockBreakEvent blockBreakEvent, Has
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().isTrue(originalBreak)) {
if (!mcMMO.getPlaceStore().isIneligible(originalBreak)) {
//Even if its a chorus block, the original break will be moved to nonChorusBlocks for immediate XP rewards
noDelayPlantBlocks.add(brokenPlant);
} else {
Expand Down Expand Up @@ -335,7 +335,7 @@ public void checkDoubleDropsOnBrokenPlants(Player player, Collection<Block> brok
BlockData plantData = brokenPlantState.getBlockData();

//Check for double drops
if (!mcMMO.getPlaceStore().isTrue(brokenPlant)) {
if (!mcMMO.getPlaceStore().isIneligible(brokenPlant)) {

/*
*
Expand Down Expand Up @@ -413,7 +413,7 @@ public void awardXPForPlantBlocks(HashSet<Block> brokenPlants) {
BlockState brokenBlockNewState = brokenPlantBlock.getState();
BlockData plantData = brokenBlockNewState.getBlockData();

if (mcMMO.getPlaceStore().isTrue(brokenBlockNewState)) {
if (mcMMO.getPlaceStore().isIneligible(brokenBlockNewState)) {
/*
*
* Unnatural Blocks
Expand All @@ -427,7 +427,7 @@ public void awardXPForPlantBlocks(HashSet<Block> brokenPlants) {
}

//Mark it as natural again as it is being broken
mcMMO.getPlaceStore().setFalse(brokenBlockNewState);
mcMMO.getPlaceStore().setEligible(brokenBlockNewState);
} else {
/*
*
Expand Down Expand Up @@ -489,9 +489,9 @@ public void awardXPForBlockSnapshots(ArrayList<BlockSnapshot> brokenPlants) {
continue;
}

if (mcMMO.getPlaceStore().isTrue(brokenBlockNewState)) {
if (mcMMO.getPlaceStore().isIneligible(brokenBlockNewState)) {
//Mark it as natural again as it is being broken
mcMMO.getPlaceStore().setFalse(brokenBlockNewState);
mcMMO.getPlaceStore().setEligible(brokenBlockNewState);
} else {
//TODO: Do we care about chorus flower age?
//Calculate XP for the old type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public void blastMiningDropProcessing(float yield, EntityExplodeEvent event) {
//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().isTrue(targetBlock)) {
&& !mcMMO.getPlaceStore().isIneligible(targetBlock)) {
if (BlockUtils.isOre(blockState)) {
ores.add(blockState);
} else {
Expand Down Expand Up @@ -216,7 +216,7 @@ public void blastMiningDropProcessing(float yield, EntityExplodeEvent event) {

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().isTrue(blockState)) {
if (mcMMO.p.getAdvancedConfig().isBlastMiningBonusDropsEnabled() && !mcMMO.getPlaceStore().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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void processBonusDropCheck(@NotNull BlockState blockState) {
}

public void processWoodcuttingBlockXP(@NotNull BlockState blockState) {
if (mcMMO.getPlaceStore().isTrue(blockState))
if (mcMMO.getPlaceStore().isIneligible(blockState))
return;

int xp = getExperienceFromLog(blockState);
Expand Down Expand Up @@ -269,7 +269,7 @@ private static boolean handleDurabilityLoss(@NotNull Set<BlockState> treeFellerB
* in treeFellerBlocks.
*/
private boolean processTreeFellerTargetBlock(@NotNull BlockState blockState, @NotNull List<BlockState> futureCenterBlocks, @NotNull Set<BlockState> treeFellerBlocks) {
if (treeFellerBlocks.contains(blockState) || mcMMO.getPlaceStore().isTrue(blockState)) {
if (treeFellerBlocks.contains(blockState) || mcMMO.getPlaceStore().isIneligible(blockState)) {
return false;
}

Expand Down Expand Up @@ -373,7 +373,7 @@ private int updateProcessedLogCount(int xp, int processedLogCount, int beforeXP)
* @return Amount of experience
*/
private static int processTreeFellerXPGains(BlockState blockState, int woodCount) {
if (mcMMO.getPlaceStore().isTrue(blockState))
if (mcMMO.getPlaceStore().isIneligible(blockState))
return 0;

int rawXP = ExperienceConfig.getInstance().getXp(PrimarySkillType.WOODCUTTING, blockState.getType());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/gmail/nossr50/util/BlockUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static Material getShortGrass() {
* @param block target block
*/
public static void setUnnaturalBlock(@NotNull Block block) {
mcMMO.getPlaceStore().setTrue(block);
mcMMO.getPlaceStore().setIneligible(block);

// Failsafe against lingering metadata
if (block.hasMetadata(MetadataConstants.METADATA_KEY_BONUS_DROPS))
Expand All @@ -82,7 +82,7 @@ public static void cleanupBlockMetadata(Block block) {
block.removeMetadata(MetadataConstants.METADATA_KEY_REPLANT, mcMMO.p);
}

mcMMO.getPlaceStore().setFalse(block);
mcMMO.getPlaceStore().setEligible(block);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.gmail.nossr50.util;

import com.gmail.nossr50.datatypes.skills.subskills.taming.CallOfTheWildType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.skills.taming.TrackedTamingEntity;
import com.gmail.nossr50.util.player.NotificationManager;
import com.gmail.nossr50.util.skills.ParticleEffectUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public synchronized void unloadWorld(@NotNull World world) {
}
}

private synchronized boolean isTrue(int x, int y, int z, @NotNull World world) {
private synchronized boolean isIneligible(int x, int y, int z, @NotNull World world) {
CoordinateKey chunkKey = blockCoordinateToChunkKey(world.getUID(), x, y, z);

// Get chunk, load from file if necessary
Expand All @@ -178,32 +178,42 @@ private synchronized boolean isTrue(int x, int y, int z, @NotNull World world) {
}

@Override
public synchronized boolean isTrue(@NotNull Block block) {
return isTrue(block.getX(), block.getY(), block.getZ(), block.getWorld());
public synchronized boolean isIneligible(@NotNull Block block) {
return isIneligible(block.getX(), block.getY(), block.getZ(), block.getWorld());
}

@Override
public synchronized boolean isTrue(@NotNull BlockState blockState) {
return isTrue(blockState.getX(), blockState.getY(), blockState.getZ(), blockState.getWorld());
public synchronized boolean isIneligible(@NotNull BlockState blockState) {
return isIneligible(blockState.getX(), blockState.getY(), blockState.getZ(), blockState.getWorld());
}

@Override
public synchronized void setTrue(@NotNull Block block) {
public synchronized boolean isEligible(@NotNull Block block) {
return !isIneligible(block);
}

@Override
public synchronized boolean isEligible(@NotNull BlockState blockState) {
return !isIneligible(blockState);
}

@Override
public synchronized void setIneligible(@NotNull Block block) {
set(block.getX(), block.getY(), block.getZ(), block.getWorld(), true);
}

@Override
public synchronized void setTrue(@NotNull BlockState blockState) {
public synchronized void setIneligible(@NotNull BlockState blockState) {
set(blockState.getX(), blockState.getY(), blockState.getZ(), blockState.getWorld(), true);
}

@Override
public synchronized void setFalse(@NotNull Block block) {
public synchronized void setEligible(@NotNull Block block) {
set(block.getX(), block.getY(), block.getZ(), block.getWorld(), false);
}

@Override
public synchronized void setFalse(@NotNull BlockState blockState) {
public synchronized void setEligible(@NotNull BlockState blockState) {
set(blockState.getX(), blockState.getY(), blockState.getZ(), blockState.getWorld(), false);
}

Expand Down
Loading

0 comments on commit 8b82163

Please sign in to comment.