mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-24 06:06:45 +01:00
Small Optimizations
This commit is contained in:
parent
133a60c4bf
commit
1c307d4f4c
14
pom.xml
14
pom.xml
@ -154,6 +154,7 @@
|
|||||||
<include>net.kyori:adventure-text-serializer-craftbukkit</include>
|
<include>net.kyori:adventure-text-serializer-craftbukkit</include>
|
||||||
<include>net.kyori:adventure-text-serializer-gson-legacy-impl</include>
|
<include>net.kyori:adventure-text-serializer-gson-legacy-impl</include>
|
||||||
<include>co.aikar:acf-bukkit</include>
|
<include>co.aikar:acf-bukkit</include>
|
||||||
|
<include>io.papermc:paperlib</include>
|
||||||
</includes>
|
</includes>
|
||||||
</artifactSet>
|
</artifactSet>
|
||||||
<relocations>
|
<relocations>
|
||||||
@ -189,6 +190,10 @@
|
|||||||
<pattern>org.bstats</pattern>
|
<pattern>org.bstats</pattern>
|
||||||
<shadedPattern>com.gmail.nossr50.mcmmo.metrics.bstats</shadedPattern>
|
<shadedPattern>com.gmail.nossr50.mcmmo.metrics.bstats</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>io.papermc.lib</pattern>
|
||||||
|
<shadedPattern>com.gmail.nossr50.mcmmo.paperlib</shadedPattern>
|
||||||
|
</relocation>
|
||||||
</relocations>
|
</relocations>
|
||||||
</configuration>
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
@ -241,6 +246,10 @@
|
|||||||
<id>sonatype-oss-snapshots1</id>
|
<id>sonatype-oss-snapshots1</id>
|
||||||
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
|
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>papermc</id>
|
||||||
|
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
<!-- ... -->
|
<!-- ... -->
|
||||||
<!-- ... -->
|
<!-- ... -->
|
||||||
</repositories>
|
</repositories>
|
||||||
@ -362,5 +371,10 @@
|
|||||||
<version>31.1-jre</version> <!-- At this time Spigot is including 29.0 Guava classes that we are using -->
|
<version>31.1-jre</version> <!-- At this time Spigot is including 29.0 Guava classes that we are using -->
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.papermc</groupId>
|
||||||
|
<artifactId>paperlib</artifactId>
|
||||||
|
<version>1.0.8</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@ -13,6 +13,7 @@ import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
|
|||||||
import com.gmail.nossr50.events.fake.FakeBlockDamageEvent;
|
import com.gmail.nossr50.events.fake.FakeBlockDamageEvent;
|
||||||
import com.gmail.nossr50.events.fake.FakeEvent;
|
import com.gmail.nossr50.events.fake.FakeEvent;
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
|
import com.gmail.nossr50.runnables.skills.AlchemyBrewTask;
|
||||||
import com.gmail.nossr50.skills.alchemy.Alchemy;
|
import com.gmail.nossr50.skills.alchemy.Alchemy;
|
||||||
import com.gmail.nossr50.skills.excavation.ExcavationManager;
|
import com.gmail.nossr50.skills.excavation.ExcavationManager;
|
||||||
import com.gmail.nossr50.skills.herbalism.HerbalismManager;
|
import com.gmail.nossr50.skills.herbalism.HerbalismManager;
|
||||||
@ -27,6 +28,7 @@ import com.gmail.nossr50.util.sounds.SoundManager;
|
|||||||
import com.gmail.nossr50.util.sounds.SoundType;
|
import com.gmail.nossr50.util.sounds.SoundType;
|
||||||
import com.gmail.nossr50.worldguard.WorldGuardManager;
|
import com.gmail.nossr50.worldguard.WorldGuardManager;
|
||||||
import com.gmail.nossr50.worldguard.WorldGuardUtils;
|
import com.gmail.nossr50.worldguard.WorldGuardUtils;
|
||||||
|
import io.papermc.lib.PaperLib;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.block.*;
|
import org.bukkit.block.*;
|
||||||
import org.bukkit.entity.Item;
|
import org.bukkit.entity.Item;
|
||||||
@ -36,8 +38,10 @@ import org.bukkit.event.EventPriority;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.*;
|
import org.bukkit.event.block.*;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.metadata.MetadataValue;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class BlockListener implements Listener {
|
public class BlockListener implements Listener {
|
||||||
private final mcMMO plugin;
|
private final mcMMO plugin;
|
||||||
@ -104,8 +108,9 @@ public class BlockListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.getBlock().getMetadata(MetadataConstants.METADATA_KEY_BONUS_DROPS).size() > 0) {
|
List<MetadataValue> metadata = event.getBlock().getMetadata(MetadataConstants.METADATA_KEY_BONUS_DROPS);
|
||||||
BonusDropMeta bonusDropMeta = (BonusDropMeta) event.getBlock().getMetadata(MetadataConstants.METADATA_KEY_BONUS_DROPS).get(0);
|
if (metadata.size() > 0) {
|
||||||
|
BonusDropMeta bonusDropMeta = (BonusDropMeta) metadata.get(0);
|
||||||
int bonusCount = bonusDropMeta.asInt();
|
int bonusCount = bonusDropMeta.asInt();
|
||||||
|
|
||||||
for (int i = 0; i < bonusCount; i++) {
|
for (int i = 0; i < bonusCount; i++) {
|
||||||
@ -115,8 +120,7 @@ public class BlockListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(event.getBlock().hasMetadata(MetadataConstants.METADATA_KEY_BONUS_DROPS))
|
event.getBlock().removeMetadata(MetadataConstants.METADATA_KEY_BONUS_DROPS, plugin);
|
||||||
event.getBlock().removeMetadata(MetadataConstants.METADATA_KEY_BONUS_DROPS, plugin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -339,7 +343,7 @@ public class BlockListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockState blockState = block.getState();
|
BlockState blockState = PaperLib.getBlockState(block, false).getState();
|
||||||
Location location = blockState.getLocation();
|
Location location = blockState.getLocation();
|
||||||
|
|
||||||
// if (!BlockUtils.shouldBeWatched(blockState)) {
|
// if (!BlockUtils.shouldBeWatched(blockState)) {
|
||||||
@ -347,8 +351,10 @@ public class BlockListener implements Listener {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
/* ALCHEMY - Cancel any brew in progress for that BrewingStand */
|
/* ALCHEMY - Cancel any brew in progress for that BrewingStand */
|
||||||
if (blockState instanceof BrewingStand && Alchemy.brewingStandMap.containsKey(location)) {
|
if (blockState instanceof BrewingStand) {
|
||||||
Alchemy.brewingStandMap.get(location).cancelBrew();
|
AlchemyBrewTask task = Alchemy.brewingStandMap.get(location);
|
||||||
|
if (task != null)
|
||||||
|
task.cancelBrew();
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
@ -605,17 +611,11 @@ public class BlockListener implements Listener {
|
|||||||
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
if (!UserManager.hasPlayerDataKey(player)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
|
||||||
//Profile not loaded
|
//Profile not loaded
|
||||||
if(UserManager.getPlayer(player) == null)
|
if (mcMMOPlayer == null)
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
ItemStack heldItem = player.getInventory().getItemInMainHand();
|
ItemStack heldItem = player.getInventory().getItemInMainHand();
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
@ -659,37 +659,30 @@ public class BlockListener implements Listener {
|
|||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
|
||||||
//Profile not loaded
|
//Profile not loaded
|
||||||
if(UserManager.getPlayer(player) == null)
|
if (mcMMOPlayer == null)
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
BlockState blockState = event.getBlock().getState();
|
BlockState blockState = PaperLib.getBlockState(event.getBlock(), false).getState();
|
||||||
|
|
||||||
ItemStack heldItem = player.getInventory().getItemInMainHand();
|
ItemStack heldItem = player.getInventory().getItemInMainHand();
|
||||||
|
|
||||||
cleanupAbilityTools(player, mcMMOPlayer, blockState, heldItem);
|
cleanupAbilityTools(player, mcMMOPlayer, blockState, heldItem);
|
||||||
|
|
||||||
debugStickDump(player, blockState);
|
debugStickDump(player, mcMMOPlayer, blockState);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Rewrite this
|
//TODO: Rewrite this
|
||||||
//TODO: Convert into locale strings
|
//TODO: Convert into locale strings
|
||||||
private void debugStickDump(Player player, BlockState blockState) {
|
private void debugStickDump(Player player, McMMOPlayer mcmmoPlayer, BlockState blockState) {
|
||||||
//Profile not loaded
|
|
||||||
if(UserManager.getPlayer(player) == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(UserManager.getPlayer(player).isDebugMode())
|
if(mcmmoPlayer.isDebugMode())
|
||||||
{
|
{
|
||||||
if(mcMMO.getPlaceStore().isTrue(blockState))
|
if(mcMMO.getPlaceStore().isTrue(blockState))
|
||||||
player.sendMessage("[mcMMO DEBUG] This block is not natural and does not reward treasures/XP");
|
player.sendMessage("[mcMMO DEBUG] This block is not natural and does not reward treasures/XP");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
player.sendMessage("[mcMMO DEBUG] This block is considered natural by mcMMO");
|
player.sendMessage("[mcMMO DEBUG] This block is considered natural by mcMMO");
|
||||||
UserManager.getPlayer(player).getExcavationManager().printExcavationDebug(player, blockState);
|
mcmmoPlayer.getExcavationManager().printExcavationDebug(player, blockState);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(WorldGuardUtils.isWorldGuardLoaded())
|
if(WorldGuardUtils.isWorldGuardLoaded())
|
||||||
|
@ -7,6 +7,7 @@ import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
|||||||
import com.gmail.nossr50.events.fake.FakeBrewEvent;
|
import com.gmail.nossr50.events.fake.FakeBrewEvent;
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.runnables.player.PlayerUpdateInventoryTask;
|
import com.gmail.nossr50.runnables.player.PlayerUpdateInventoryTask;
|
||||||
|
import com.gmail.nossr50.runnables.skills.AlchemyBrewTask;
|
||||||
import com.gmail.nossr50.skills.alchemy.Alchemy;
|
import com.gmail.nossr50.skills.alchemy.Alchemy;
|
||||||
import com.gmail.nossr50.skills.alchemy.AlchemyPotionBrewer;
|
import com.gmail.nossr50.skills.alchemy.AlchemyPotionBrewer;
|
||||||
import com.gmail.nossr50.util.ItemUtils;
|
import com.gmail.nossr50.util.ItemUtils;
|
||||||
@ -16,6 +17,7 @@ import com.gmail.nossr50.util.player.UserManager;
|
|||||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
import com.gmail.nossr50.util.skills.SkillUtils;
|
||||||
import com.gmail.nossr50.worldguard.WorldGuardManager;
|
import com.gmail.nossr50.worldguard.WorldGuardManager;
|
||||||
import com.gmail.nossr50.worldguard.WorldGuardUtils;
|
import com.gmail.nossr50.worldguard.WorldGuardUtils;
|
||||||
|
import io.papermc.lib.PaperLib;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
@ -54,11 +56,8 @@ public class InventoryListener implements Listener {
|
|||||||
|
|
||||||
Furnace furnace = (Furnace) furnaceState;
|
Furnace furnace = (Furnace) furnaceState;
|
||||||
OfflinePlayer offlinePlayer = mcMMO.getSmeltingTracker().getFurnaceOwner(furnace);
|
OfflinePlayer offlinePlayer = mcMMO.getSmeltingTracker().getFurnaceOwner(furnace);
|
||||||
Player player;
|
|
||||||
|
|
||||||
if(offlinePlayer != null && offlinePlayer.isOnline() && offlinePlayer instanceof Player) {
|
|
||||||
player = (Player) offlinePlayer;
|
|
||||||
|
|
||||||
|
if(offlinePlayer != null && offlinePlayer.isOnline() && offlinePlayer instanceof Player player) {
|
||||||
if (!Permissions.isSubSkillEnabled(player, SubSkillType.SMELTING_FUEL_EFFICIENCY)) {
|
if (!Permissions.isSubSkillEnabled(player, SubSkillType.SMELTING_FUEL_EFFICIENCY)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -91,7 +90,7 @@ public class InventoryListener implements Listener {
|
|||||||
if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld()))
|
if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
BlockState blockState = event.getBlock().getState(); //Furnaces can only be cast from a BlockState not a Block
|
BlockState blockState = PaperLib.getBlockState(event.getBlock(), false).getState(); //Furnaces can only be cast from a BlockState not a Block
|
||||||
ItemStack smelting = event.getSource();
|
ItemStack smelting = event.getSource();
|
||||||
|
|
||||||
if (!ItemUtils.isSmeltable(smelting)) {
|
if (!ItemUtils.isSmeltable(smelting)) {
|
||||||
@ -120,12 +119,12 @@ public class InventoryListener implements Listener {
|
|||||||
if(WorldBlacklist.isWorldBlacklisted(event.getPlayer().getWorld()))
|
if(WorldBlacklist.isWorldBlacklisted(event.getPlayer().getWorld()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
BlockState furnaceBlock = event.getBlock().getState();
|
|
||||||
|
|
||||||
if (!ItemUtils.isSmelted(new ItemStack(event.getItemType(), event.getItemAmount()))) {
|
if (!ItemUtils.isSmelted(new ItemStack(event.getItemType(), event.getItemAmount()))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BlockState furnaceBlock = PaperLib.getBlockState(event.getBlock(), false).getState();
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
if(furnaceBlock instanceof Furnace) {
|
if(furnaceBlock instanceof Furnace) {
|
||||||
@ -136,18 +135,14 @@ public class InventoryListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!UserManager.hasPlayerDataKey(player) || !Permissions.vanillaXpBoost(player, PrimarySkillType.SMELTING)) {
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Profile not loaded
|
if (mcMMOPlayer == null || !Permissions.vanillaXpBoost(player, PrimarySkillType.SMELTING)) {
|
||||||
if(UserManager.getPlayer(player) == null)
|
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int xpToDrop = event.getExpToDrop();
|
int xpToDrop = event.getExpToDrop();
|
||||||
int exp = UserManager.getPlayer(player).getSmeltingManager().vanillaXPBoost(xpToDrop);
|
int exp = mcMMOPlayer.getSmeltingManager().vanillaXPBoost(xpToDrop);
|
||||||
event.setExpToDrop(exp);
|
event.setExpToDrop(exp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -164,7 +159,7 @@ public class InventoryListener implements Listener {
|
|||||||
|
|
||||||
Inventory inventory = event.getInventory();
|
Inventory inventory = event.getInventory();
|
||||||
|
|
||||||
Player player = ((Player) event.getWhoClicked()).getPlayer();
|
Player player = ((Player) event.getWhoClicked());
|
||||||
|
|
||||||
if(event.getInventory() instanceof FurnaceInventory)
|
if(event.getInventory() instanceof FurnaceInventory)
|
||||||
{
|
{
|
||||||
@ -181,7 +176,7 @@ public class InventoryListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
InventoryHolder holder = inventory.getHolder();
|
InventoryHolder holder = PaperLib.getHolder(inventory, false).getHolder();
|
||||||
|
|
||||||
if (!(holder instanceof BrewingStand stand)) {
|
if (!(holder instanceof BrewingStand stand)) {
|
||||||
return;
|
return;
|
||||||
@ -287,13 +282,17 @@ public class InventoryListener implements Listener {
|
|||||||
if(WorldBlacklist.isWorldBlacklisted(event.getWhoClicked().getWorld()))
|
if(WorldBlacklist.isWorldBlacklisted(event.getWhoClicked().getWorld()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Inventory inventory = event.getInventory();
|
if (!event.getInventorySlots().contains(Alchemy.INGREDIENT_SLOT)) {
|
||||||
|
|
||||||
if (!(inventory instanceof BrewerInventory)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
InventoryHolder holder = inventory.getHolder();
|
Inventory inventory = event.getInventory();
|
||||||
|
|
||||||
|
if (!(inventory instanceof BrewerInventory brewerInventory)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
InventoryHolder holder = PaperLib.getHolder(inventory, false).getHolder();
|
||||||
|
|
||||||
if (!(holder instanceof BrewingStand)) {
|
if (!(holder instanceof BrewingStand)) {
|
||||||
return;
|
return;
|
||||||
@ -305,12 +304,8 @@ public class InventoryListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!event.getInventorySlots().contains(Alchemy.INGREDIENT_SLOT)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemStack cursor = event.getCursor();
|
ItemStack cursor = event.getCursor();
|
||||||
ItemStack ingredient = ((BrewerInventory) inventory).getIngredient();
|
ItemStack ingredient = brewerInventory.getIngredient();
|
||||||
|
|
||||||
if (AlchemyPotionBrewer.isEmpty(ingredient) || ingredient.isSimilar(cursor)) {
|
if (AlchemyPotionBrewer.isEmpty(ingredient) || ingredient.isSimilar(cursor)) {
|
||||||
Player player = (Player) whoClicked;
|
Player player = (Player) whoClicked;
|
||||||
@ -344,8 +339,9 @@ public class InventoryListener implements Listener {
|
|||||||
if (event instanceof FakeBrewEvent)
|
if (event instanceof FakeBrewEvent)
|
||||||
return;
|
return;
|
||||||
Location location = event.getBlock().getLocation();
|
Location location = event.getBlock().getLocation();
|
||||||
if (Alchemy.brewingStandMap.containsKey(location)) {
|
AlchemyBrewTask task = Alchemy.brewingStandMap.get(location);
|
||||||
Alchemy.brewingStandMap.get(location).finishImmediately();
|
if (task != null) {
|
||||||
|
task.finishImmediately();
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -364,7 +360,7 @@ public class InventoryListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
InventoryHolder holder = inventory.getHolder();
|
InventoryHolder holder = PaperLib.getHolder(inventory, false).getHolder();
|
||||||
|
|
||||||
if (!(holder instanceof BrewingStand)) {
|
if (!(holder instanceof BrewingStand)) {
|
||||||
return;
|
return;
|
||||||
|
@ -103,8 +103,7 @@ public final class LocaleLoader {
|
|||||||
|
|
||||||
public static String formatString(String string, Object... messageArguments) {
|
public static String formatString(String string, Object... messageArguments) {
|
||||||
if (messageArguments != null) {
|
if (messageArguments != null) {
|
||||||
MessageFormat formatter = new MessageFormat("");
|
MessageFormat formatter = new MessageFormat(string.replace("'", "''"));
|
||||||
formatter.applyPattern(string.replace("'", "''"));
|
|
||||||
string = formatter.format(messageArguments);
|
string = formatter.format(messageArguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,8 +114,7 @@ public final class LocaleLoader {
|
|||||||
|
|
||||||
public static @NotNull TextComponent formatComponent(@NotNull String string, Object... messageArguments) {
|
public static @NotNull TextComponent formatComponent(@NotNull String string, Object... messageArguments) {
|
||||||
if (messageArguments != null) {
|
if (messageArguments != null) {
|
||||||
MessageFormat formatter = new MessageFormat("");
|
MessageFormat formatter = new MessageFormat(string.replace("'", "''"));
|
||||||
formatter.applyPattern(string.replace("'", "''"));
|
|
||||||
string = formatter.format(messageArguments);
|
string = formatter.format(messageArguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,19 +73,15 @@ public class ItemMetadataService {
|
|||||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||||
|
|
||||||
if(itemMeta != null) {
|
if(itemMeta != null) {
|
||||||
//TODO: can be optimized
|
|
||||||
if (itemMeta.hasEnchant(Enchantment.DIG_SPEED)) {
|
|
||||||
itemMeta.removeEnchant(Enchantment.DIG_SPEED);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (originalSpeed > 0) {
|
if (originalSpeed > 0) {
|
||||||
itemMeta.addEnchant(Enchantment.DIG_SPEED, originalSpeed, true);
|
itemMeta.addEnchant(Enchantment.DIG_SPEED, originalSpeed, true);
|
||||||
|
} else {
|
||||||
|
itemMeta.removeEnchant(Enchantment.DIG_SPEED);
|
||||||
}
|
}
|
||||||
|
|
||||||
PersistentDataContainer dataContainer = itemMeta.getPersistentDataContainer();
|
PersistentDataContainer dataContainer = itemMeta.getPersistentDataContainer();
|
||||||
dataContainer.remove(NSK_SUPER_ABILITY_BOOSTED_ITEM); //Remove persistent data
|
dataContainer.remove(NSK_SUPER_ABILITY_BOOSTED_ITEM); //Remove persistent data
|
||||||
|
|
||||||
//TODO: needed?
|
|
||||||
itemStack.setItemMeta(itemMeta);
|
itemStack.setItemMeta(itemMeta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.gmail.nossr50.runnables.skills;
|
package com.gmail.nossr50.runnables.skills;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||||
import com.gmail.nossr50.events.skills.alchemy.McMMOPlayerBrewEvent;
|
import com.gmail.nossr50.events.skills.alchemy.McMMOPlayerBrewEvent;
|
||||||
@ -12,7 +13,6 @@ import com.gmail.nossr50.util.Permissions;
|
|||||||
import com.gmail.nossr50.util.player.UserManager;
|
import com.gmail.nossr50.util.player.UserManager;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.block.BrewingStand;
|
import org.bukkit.block.BrewingStand;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
@ -21,7 +21,7 @@ public class AlchemyBrewTask extends BukkitRunnable {
|
|||||||
private static final double DEFAULT_BREW_SPEED = 1.0;
|
private static final double DEFAULT_BREW_SPEED = 1.0;
|
||||||
private static final int DEFAULT_BREW_TICKS = 400;
|
private static final int DEFAULT_BREW_TICKS = 400;
|
||||||
|
|
||||||
private final BlockState brewingStand;
|
private final BrewingStand brewingStand;
|
||||||
private final Location location;
|
private final Location location;
|
||||||
private double brewSpeed;
|
private double brewSpeed;
|
||||||
private double brewTimer;
|
private double brewTimer;
|
||||||
@ -29,7 +29,7 @@ public class AlchemyBrewTask extends BukkitRunnable {
|
|||||||
private int fuel;
|
private int fuel;
|
||||||
private boolean firstRun = true;
|
private boolean firstRun = true;
|
||||||
|
|
||||||
public AlchemyBrewTask(BlockState brewingStand, Player player) {
|
public AlchemyBrewTask(BrewingStand brewingStand, Player player) {
|
||||||
this.brewingStand = brewingStand;
|
this.brewingStand = brewingStand;
|
||||||
this.location = brewingStand.getLocation();
|
this.location = brewingStand.getLocation();
|
||||||
this.player = player;
|
this.player = player;
|
||||||
@ -37,12 +37,14 @@ public class AlchemyBrewTask extends BukkitRunnable {
|
|||||||
brewSpeed = DEFAULT_BREW_SPEED;
|
brewSpeed = DEFAULT_BREW_SPEED;
|
||||||
brewTimer = DEFAULT_BREW_TICKS;
|
brewTimer = DEFAULT_BREW_TICKS;
|
||||||
|
|
||||||
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
|
||||||
if (player != null
|
if (player != null
|
||||||
&& !Misc.isNPCEntityExcludingVillagers(player)
|
&& !Misc.isNPCEntityExcludingVillagers(player)
|
||||||
&& Permissions.isSubSkillEnabled(player, SubSkillType.ALCHEMY_CATALYSIS)
|
&& Permissions.isSubSkillEnabled(player, SubSkillType.ALCHEMY_CATALYSIS)
|
||||||
&& UserManager.getPlayer(player) != null) {
|
&& mcMMOPlayer != null) {
|
||||||
|
|
||||||
double catalysis = UserManager.getPlayer(player).getAlchemyManager().calculateBrewSpeed(Permissions.lucky(player, PrimarySkillType.ALCHEMY));
|
double catalysis = mcMMOPlayer.getAlchemyManager().calculateBrewSpeed(Permissions.lucky(player, PrimarySkillType.ALCHEMY));
|
||||||
|
|
||||||
McMMOPlayerCatalysisEvent event = new McMMOPlayerCatalysisEvent(player, catalysis);
|
McMMOPlayerCatalysisEvent event = new McMMOPlayerCatalysisEvent(player, catalysis);
|
||||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||||
@ -52,13 +54,14 @@ public class AlchemyBrewTask extends BukkitRunnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Alchemy.brewingStandMap.containsKey(location)) {
|
AlchemyBrewTask existing = Alchemy.brewingStandMap.get(location);
|
||||||
Alchemy.brewingStandMap.get(location).cancel();
|
if (existing != null) {
|
||||||
|
existing.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
fuel = ((BrewingStand) brewingStand).getFuelLevel();
|
fuel = brewingStand.getFuelLevel();
|
||||||
|
|
||||||
if (((BrewingStand) brewingStand).getBrewingTime() == -1) // Only decrement on our end if it isn't a vanilla ingredient.
|
if (brewingStand.getBrewingTime() == -1) // Only decrement on our end if it isn't a vanilla ingredient.
|
||||||
fuel--;
|
fuel--;
|
||||||
|
|
||||||
Alchemy.brewingStandMap.put(location, this);
|
Alchemy.brewingStandMap.put(location, this);
|
||||||
@ -67,10 +70,8 @@ public class AlchemyBrewTask extends BukkitRunnable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (player == null || !player.isValid() || brewingStand == null || brewingStand.getType() != Material.BREWING_STAND || !AlchemyPotionBrewer.isValidIngredient(player, ((BrewingStand) brewingStand).getInventory().getContents()[Alchemy.INGREDIENT_SLOT])) {
|
if (player == null || !player.isValid() || location.getBlock().getType() != Material.BREWING_STAND || !AlchemyPotionBrewer.isValidIngredient(player, brewingStand.getInventory().getContents()[Alchemy.INGREDIENT_SLOT])) {
|
||||||
if (Alchemy.brewingStandMap.containsKey(location)) {
|
Alchemy.brewingStandMap.remove(location);
|
||||||
Alchemy.brewingStandMap.remove(location);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.cancel();
|
this.cancel();
|
||||||
|
|
||||||
@ -79,7 +80,7 @@ public class AlchemyBrewTask extends BukkitRunnable {
|
|||||||
|
|
||||||
if (firstRun) {
|
if (firstRun) {
|
||||||
firstRun = false;
|
firstRun = false;
|
||||||
((BrewingStand) brewingStand).setFuelLevel(fuel);
|
brewingStand.setFuelLevel(fuel);
|
||||||
}
|
}
|
||||||
|
|
||||||
brewTimer -= brewSpeed;
|
brewTimer -= brewSpeed;
|
||||||
@ -90,7 +91,7 @@ public class AlchemyBrewTask extends BukkitRunnable {
|
|||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
((BrewingStand) brewingStand).setBrewingTime((int) brewTimer);
|
brewingStand.setBrewingTime((int) brewTimer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,24 +50,19 @@ public class ExperienceBarManager {
|
|||||||
|| !ExperienceConfig.getInstance().isExperienceBarEnabled(primarySkillType))
|
|| !ExperienceConfig.getInstance().isExperienceBarEnabled(primarySkillType))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//Init Bar
|
// Init or get the bar
|
||||||
if(experienceBars.get(primarySkillType) == null)
|
ExperienceBarWrapper bar = experienceBars.computeIfAbsent(primarySkillType, k -> new ExperienceBarWrapper(primarySkillType, mcMMOPlayer));
|
||||||
experienceBars.put(primarySkillType, new ExperienceBarWrapper(primarySkillType, mcMMOPlayer));
|
|
||||||
|
|
||||||
//Get Bar
|
|
||||||
ExperienceBarWrapper experienceBarWrapper = experienceBars.get(primarySkillType);
|
|
||||||
|
|
||||||
//Update Progress
|
//Update Progress
|
||||||
experienceBarWrapper.setProgress(mcMMOPlayer.getProgressInCurrentSkillLevel(primarySkillType));
|
bar.setProgress(mcMMOPlayer.getProgressInCurrentSkillLevel(primarySkillType));
|
||||||
|
|
||||||
//Show Bar
|
//Show Bar
|
||||||
experienceBarWrapper.showExperienceBar();
|
bar.showExperienceBar();
|
||||||
|
|
||||||
//Setup Hide Bar Task
|
//Setup Hide Bar Task
|
||||||
if(experienceBarHideTaskHashMap.get(primarySkillType) != null)
|
ExperienceBarHideTask task = experienceBarHideTaskHashMap.get(primarySkillType);
|
||||||
{
|
if (task != null)
|
||||||
experienceBarHideTaskHashMap.get(primarySkillType).cancel();
|
task.cancel();
|
||||||
}
|
|
||||||
|
|
||||||
scheduleHideTask(primarySkillType, plugin);
|
scheduleHideTask(primarySkillType, plugin);
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,14 @@ import org.bukkit.OfflinePlayer;
|
|||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.metadata.FixedMetadataValue;
|
import org.bukkit.metadata.FixedMetadataValue;
|
||||||
|
import org.bukkit.metadata.MetadataValue;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public final class UserManager {
|
public final class UserManager {
|
||||||
|
|
||||||
@ -137,9 +139,13 @@ public final class UserManager {
|
|||||||
* @return McMMOPlayer object for this player, null if Player has not been loaded
|
* @return McMMOPlayer object for this player, null if Player has not been loaded
|
||||||
*/
|
*/
|
||||||
public static @Nullable McMMOPlayer getPlayer(@Nullable Player player) {
|
public static @Nullable McMMOPlayer getPlayer(@Nullable Player player) {
|
||||||
|
if (player == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
List<MetadataValue> metadata = player.getMetadata(MetadataConstants.METADATA_KEY_PLAYER_DATA);
|
||||||
//Avoid Array Index out of bounds
|
//Avoid Array Index out of bounds
|
||||||
if(player != null && player.hasMetadata(MetadataConstants.METADATA_KEY_PLAYER_DATA))
|
if (!metadata.isEmpty())
|
||||||
return (McMMOPlayer) player.getMetadata(MetadataConstants.METADATA_KEY_PLAYER_DATA).get(0).value();
|
return (McMMOPlayer) metadata.get(0).value();
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
|||||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.util.player.UserManager;
|
import com.gmail.nossr50.util.player.UserManager;
|
||||||
|
import io.papermc.lib.PaperLib;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
@ -80,7 +81,7 @@ public class SmeltingTracker {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (Furnace) inventory.getHolder();
|
return (Furnace) PaperLib.getHolder(inventory, false).getHolder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFurnaceOwned(Furnace furnace) {
|
public boolean isFurnaceOwned(Furnace furnace) {
|
||||||
@ -92,8 +93,9 @@ public class SmeltingTracker {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
//Don't swap ownership if its the same player
|
//Don't swap ownership if its the same player
|
||||||
if(getFurnaceOwner(furnace) != null) {
|
OfflinePlayer owner = getFurnaceOwner(furnace);
|
||||||
if(getFurnaceOwner(furnace).getUniqueId().equals(player.getUniqueId()))
|
if(owner != null) {
|
||||||
|
if(owner.getUniqueId().equals(player.getUniqueId()))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user