Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite how mob/item/block metadata is tracked/retrieved
Fixes #4720
- Loading branch information
Showing
19 changed files
with
477 additions
and
600 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/com/gmail/nossr50/config/PersistentDataConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/com/gmail/nossr50/metadata/BlockMetadataService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.gmail.nossr50.metadata; | ||
|
||
import com.gmail.nossr50.mcMMO; | ||
import org.bukkit.block.Furnace; | ||
import org.bukkit.persistence.PersistentDataContainer; | ||
import org.bukkit.persistence.PersistentDataHolder; | ||
import org.bukkit.persistence.PersistentDataType; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.UUID; | ||
|
||
import static com.gmail.nossr50.metadata.MetadataService.NSK_FURNACE_UUID_LEAST_SIG; | ||
import static com.gmail.nossr50.metadata.MetadataService.NSK_FURNACE_UUID_MOST_SIG; | ||
|
||
public class BlockMetadataService { | ||
|
||
private final @NotNull mcMMO pluginRef; | ||
|
||
public BlockMetadataService(@NotNull mcMMO pluginRef) { | ||
this.pluginRef = pluginRef; | ||
} | ||
|
||
public @Nullable UUID getFurnaceOwner(@NotNull Furnace furnace) { | ||
//Get container from entity | ||
PersistentDataContainer dataContainer = ((PersistentDataHolder) furnace).getPersistentDataContainer(); | ||
|
||
//Too lazy to make a custom data type for this stuff | ||
Long mostSigBits = dataContainer.get(NSK_FURNACE_UUID_MOST_SIG, PersistentDataType.LONG); | ||
Long leastSigBits = dataContainer.get(NSK_FURNACE_UUID_LEAST_SIG, PersistentDataType.LONG); | ||
|
||
if (mostSigBits != null && leastSigBits != null) { | ||
return new UUID(mostSigBits, leastSigBits); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
public void setFurnaceOwner(@NotNull Furnace furnace, @NotNull UUID uuid) { | ||
PersistentDataContainer dataContainer = ((PersistentDataHolder) furnace).getPersistentDataContainer(); | ||
|
||
dataContainer.set(NSK_FURNACE_UUID_MOST_SIG, PersistentDataType.LONG, uuid.getMostSignificantBits()); | ||
dataContainer.set(NSK_FURNACE_UUID_LEAST_SIG, PersistentDataType.LONG, uuid.getLeastSignificantBits()); | ||
|
||
furnace.update(); | ||
} | ||
|
||
|
||
} |
110 changes: 110 additions & 0 deletions
110
src/main/java/com/gmail/nossr50/metadata/ItemMetadataService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package com.gmail.nossr50.metadata; | ||
|
||
import com.gmail.nossr50.mcMMO; | ||
import org.bukkit.enchantments.Enchantment; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.meta.ItemMeta; | ||
import org.bukkit.persistence.PersistentDataContainer; | ||
import org.bukkit.persistence.PersistentDataType; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.List; | ||
|
||
import static com.gmail.nossr50.metadata.MetadataService.NSK_SUPER_ABILITY_BOOSTED_ITEM; | ||
|
||
public class ItemMetadataService { | ||
|
||
public final @NotNull String LEGACY_ABILITY_TOOL_LORE = "mcMMO Ability Tool"; | ||
public final @NotNull mcMMO pluginRef; | ||
|
||
public ItemMetadataService(@NotNull mcMMO pluginRef) { | ||
this.pluginRef = pluginRef; | ||
} | ||
|
||
public void setSuperAbilityBoostedItem(@NotNull ItemStack itemStack, int originalDigSpeed) { | ||
if (itemStack.getItemMeta() == null) { | ||
mcMMO.p.getLogger().severe("Can not assign persistent data to an item with null item metadata"); | ||
return; | ||
} | ||
|
||
ItemMeta itemMeta = itemStack.getItemMeta(); | ||
PersistentDataContainer dataContainer = itemMeta.getPersistentDataContainer(); | ||
|
||
dataContainer.set(NSK_SUPER_ABILITY_BOOSTED_ITEM, PersistentDataType.INTEGER, originalDigSpeed); | ||
|
||
itemStack.setItemMeta(itemMeta); | ||
} | ||
|
||
public boolean isSuperAbilityBoosted(@NotNull ItemStack itemStack) { | ||
if (itemStack.getItemMeta() == null) | ||
return false; | ||
|
||
ItemMeta itemMeta = itemStack.getItemMeta(); | ||
//Get container from entity | ||
PersistentDataContainer dataContainer = itemMeta.getPersistentDataContainer(); | ||
|
||
//If this value isn't null, then the tool can be considered dig speed boosted | ||
Integer boostValue = dataContainer.get(NSK_SUPER_ABILITY_BOOSTED_ITEM, PersistentDataType.INTEGER); | ||
|
||
return boostValue != null; | ||
} | ||
|
||
public int getSuperAbilityToolOriginalDigSpeed(@NotNull ItemStack itemStack) { | ||
//Get container from entity | ||
ItemMeta itemMeta = itemStack.getItemMeta(); | ||
|
||
if (itemMeta == null) | ||
return 0; | ||
|
||
PersistentDataContainer dataContainer = itemMeta.getPersistentDataContainer(); | ||
|
||
if (dataContainer.get(NSK_SUPER_ABILITY_BOOSTED_ITEM, PersistentDataType.INTEGER) == null) { | ||
mcMMO.p.getLogger().severe("Value should never be null for a boosted item"); | ||
return 0; | ||
} else { | ||
//Too lazy to make a custom data type for this stuff | ||
Integer boostValue = dataContainer.get(NSK_SUPER_ABILITY_BOOSTED_ITEM, PersistentDataType.INTEGER); | ||
return Math.max(boostValue, 0); | ||
} | ||
} | ||
|
||
public void removeBonusDigSpeedOnSuperAbilityTool(@NotNull ItemStack itemStack) { | ||
int originalSpeed = getSuperAbilityToolOriginalDigSpeed(itemStack); | ||
ItemMeta itemMeta = itemStack.getItemMeta(); | ||
|
||
if(itemMeta != null) { | ||
//TODO: can be optimized | ||
if (itemMeta.hasEnchant(Enchantment.DIG_SPEED)) { | ||
itemMeta.removeEnchant(Enchantment.DIG_SPEED); | ||
} | ||
|
||
if (originalSpeed > 0) { | ||
itemMeta.addEnchant(Enchantment.DIG_SPEED, originalSpeed, true); | ||
} | ||
|
||
PersistentDataContainer dataContainer = itemMeta.getPersistentDataContainer(); | ||
dataContainer.remove(NSK_SUPER_ABILITY_BOOSTED_ITEM); //Remove persistent data | ||
|
||
//TODO: needed? | ||
itemStack.setItemMeta(itemMeta); | ||
} | ||
} | ||
|
||
public boolean isLegacyAbilityTool(@NotNull ItemStack itemStack) { | ||
ItemMeta itemMeta = itemStack.getItemMeta(); | ||
|
||
if (itemMeta == null) | ||
return false; | ||
|
||
List<String> lore = itemMeta.getLore(); | ||
|
||
if (lore == null || lore.isEmpty()) | ||
return false; | ||
|
||
return lore.contains(LEGACY_ABILITY_TOOL_LORE); | ||
} | ||
|
||
public @NotNull String getLegacyAbilityToolLore() { | ||
return LEGACY_ABILITY_TOOL_LORE; | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/main/java/com/gmail/nossr50/metadata/MetadataService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.gmail.nossr50.metadata; | ||
|
||
import com.gmail.nossr50.mcMMO; | ||
import com.gmail.nossr50.util.MetadataConstants; | ||
import org.bukkit.NamespacedKey; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class MetadataService { | ||
private final @NotNull mcMMO pluginRef; | ||
|
||
protected static final @NotNull NamespacedKey NSK_SUPER_ABILITY_BOOSTED_ITEM; | ||
protected static final @NotNull NamespacedKey NSK_MOB_SPAWNER_MOB; | ||
protected static final @NotNull NamespacedKey NSK_EGG_MOB; | ||
protected static final @NotNull NamespacedKey NSK_NETHER_GATE_MOB; | ||
protected static final @NotNull NamespacedKey NSK_COTW_SUMMONED_MOB; | ||
protected static final @NotNull NamespacedKey NSK_PLAYER_BRED_MOB; | ||
protected static final @NotNull NamespacedKey NSK_PLAYER_TAMED_MOB; | ||
protected static final @NotNull NamespacedKey NSK_VILLAGER_TRADE_ORIGIN_ITEM; | ||
protected static final @NotNull NamespacedKey NSK_EXPLOITED_ENDERMEN; | ||
protected static final @NotNull NamespacedKey NSK_FURNACE_UUID_MOST_SIG; | ||
protected static final @NotNull NamespacedKey NSK_FURNACE_UUID_LEAST_SIG; | ||
|
||
static { | ||
NSK_SUPER_ABILITY_BOOSTED_ITEM = getNamespacedKey(MetadataConstants.METADATA_KEY_SUPER_ABILITY_BOOSTED_ITEM); | ||
NSK_MOB_SPAWNER_MOB = getNamespacedKey(MetadataConstants.METADATA_KEY_MOB_SPAWNER_MOB); | ||
NSK_EGG_MOB = getNamespacedKey(MetadataConstants.METADATA_KEY_EGG_MOB); | ||
NSK_NETHER_GATE_MOB = getNamespacedKey(MetadataConstants.METADATA_KEY_NETHER_PORTAL_MOB); | ||
NSK_COTW_SUMMONED_MOB = getNamespacedKey(MetadataConstants.METADATA_KEY_COTW_SUMMONED_MOB); | ||
NSK_PLAYER_BRED_MOB = getNamespacedKey(MetadataConstants.METADATA_KEY_PLAYER_BRED_MOB); | ||
NSK_PLAYER_TAMED_MOB = getNamespacedKey(MetadataConstants.METADATA_KEY_PLAYER_TAMED_MOB); | ||
NSK_VILLAGER_TRADE_ORIGIN_ITEM = getNamespacedKey(MetadataConstants.METADATA_KEY_VILLAGER_TRADE_ORIGIN_ITEM); | ||
NSK_EXPLOITED_ENDERMEN = getNamespacedKey(MetadataConstants.METADATA_KEY_EXPLOITED_ENDERMEN); | ||
NSK_FURNACE_UUID_MOST_SIG = getNamespacedKey(MetadataConstants.METADATA_KEY_FURNACE_UUID_MOST_SIG); | ||
NSK_FURNACE_UUID_LEAST_SIG = getNamespacedKey(MetadataConstants.METADATA_KEY_FURNACE_UUID_LEAST_SIG); | ||
} | ||
|
||
private final @NotNull ItemMetadataService itemMetadataService; | ||
private final @NotNull MobMetadataService mobMetadataService; | ||
private final @NotNull BlockMetadataService blockMetadataService; | ||
|
||
public MetadataService(@NotNull mcMMO pluginRef) { | ||
this.pluginRef = pluginRef; | ||
|
||
blockMetadataService = new BlockMetadataService(pluginRef); | ||
mobMetadataService = new MobMetadataService(pluginRef); | ||
itemMetadataService = new ItemMetadataService(pluginRef); | ||
} | ||
|
||
/** | ||
* Helper method to simplify generating namespaced keys | ||
* | ||
* @param key the {@link String} value of the key | ||
* | ||
* @return the generated {@link NamespacedKey} | ||
*/ | ||
public static @NotNull NamespacedKey getNamespacedKey(@NotNull String key) { | ||
return new NamespacedKey(mcMMO.p, key); | ||
} | ||
|
||
public @NotNull ItemMetadataService getItemMetadataService() { | ||
return itemMetadataService; | ||
} | ||
|
||
public @NotNull MobMetadataService getMobMetadataService() { | ||
return mobMetadataService; | ||
} | ||
|
||
public @NotNull BlockMetadataService getBlockMetadataService() { | ||
return blockMetadataService; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ayers/persistentdata/MobMetaFlagType.java → ...ail/nossr50/metadata/MobMetaFlagType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
3be15d3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is causing some lag issues, compared to old mcmmo mcMMO::Event: c.g.n.l.WorldListener (ChunkUnloadEvent) is going crazy now...
Minecraft::Full Server Tick
count(1716) total(100.00% 216.13s, 251.90% of tick)
avg(125.95ms per - 125.95ms/1.00 per tick)
Minecraft::world - doTick
count(1664) total(92.66% 200.261s, 233.40% of tick)
avg(120.35ms per - 116.70ms/0.97 per tick)
Minecraft::world - Chunk provider tick
count(1664) total(63.99% 138.305s, 161.19% of tick)
avg(83.12ms per - 80.60ms/0.97 per tick)
Minecraft::Plugins
count(22209364) total(59.41% 128.394s, 149.64% of tick)
avg(0.01ms per - 74.82ms/12,942.52 per tick)
Minecraft::Distance Manager Tick
count(3026531) total(54.83% 118.511s, 138.12% of tick)
avg(0.04ms per - 69.06ms/1,763.71 per tick)
Minecraft::world - doChunkMap
count(1664) total(54.64% 118.087s, 137.63% of tick)
avg(70.97ms per - 68.82ms/0.97 per tick)
mcMMO::Combined Total
count(343859) total(54.59% 117.991s, 137.52% of tick)
avg(0.34ms per - 68.76ms/200.38 per tick)
mcMMO::Event: c.g.n.l.WorldListener (ChunkUnloadEvent)
count(6090) total(54.17% 117.072s, 136.45% of tick)
avg(19.22ms per - 68.22ms/3.55 per tick)
Minecraft::world - tickEntities
count(1664) total(18.66% 40.329s, 47.00% of tick)
avg(24.24ms per - 23.50ms/0.97 per tick)
Minecraft::world - entityTick
count(1664) total(18.52% 40.028s, 46.65% of tick)
avg(24.06ms per - 23.33ms/0.97 per tick)
Minecraft::tickEntity
count(6318086) total(16.37% 35.387s, 41.24% of tick)
avg(0.01ms per - 20.62ms/3,681.87 per tick)
Minecraft::world - Chunks
count(1664) total(9.32% 20.149s, 23.48% of tick)
avg(12.11ms per - 11.74ms/0.97 per tick)
Minecraft::world - tileEntityTick
count(1664) total(7.23% 15.618s, 18.20% of tick)
avg(9.39ms per - 9.10ms/0.97 per tick)
Minecraft::tickTileEntity
count(15520002) total(5.48% 11.841s, 13.80% of tick)
avg(0.00ms per - 6.90ms/9,044.29 per tick)
Minecraft::world - Chunk Ticks
count(1664) total(5.22% 11.286s, 13.15% of tick)
avg(6.78ms per - 6.58ms/0.97 per tick)
Minecraft::tickTileEntity - net.minecraft.world.level.block.entity.TileEntityHopper
count(7995442) total(3.40% 7.347s, 8.56% of tick)
avg(0.00ms per - 4.28ms/4,659.35 per tick)
Minecraft::tickEntity - villager - tick
count(178564) total(3.38% 7.298s, 8.51% of tick)
avg(0.04ms per - 4.25ms/104.06 per tick)
Minecraft::tickEntity - cow - tick
count(248399) total(2.45% 5.295s, 6.17% of tick)
avg(0.02ms per - 3.09ms/144.75 per tick)
Minecraft::world - Chunk Ticks - Blocks
count(5046077) total(2.18% 4.706s, 5.48% of tick)
avg(0.00ms per - 2.74ms/2,940.60 per tick)
Minecraft::world - tracker stage 2
count(1664) total(2.02% 4.364s, 5.09% of tick)
avg(2.62ms per - 2.54ms/0.97 per tick)
Minecraft::world - Scheduled Blocks
count(1664) total(1.96% 4.228s, 4.93% of tick)
avg(2.54ms per - 2.46ms/0.97 per tick)
Minecraft::Server Oversleep
count(1664) total(1.87% 4.049s, 4.72% of tick)
avg(2.43ms per - 2.36ms/0.97 per tick)
Minecraft::world - Scheduled Blocks - Ticking
3be15d3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also saw some chatter about mobs from spawners giving mcmmo XP tho I didn't test that.
3be15d3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a same problem
https://i.imgur.com/5Un9rzC.png
3be15d3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@L4BORG @WolverStones Could you provide a Spark dump? I'm not seeing any changes related to our ChunkUnlodEvent listener in WorldListener so I'm not sure why you would have a performance degradation. It would also be appreciated if you tagged me on Discord or made a new issue thread if you're having this problem with the latest build.
3be15d3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After updating to latest mcMMO it's not an issue anymore. At least I can't replicate.