From adb5239d36c828ae2eac3e93984154b5e319d7e4 Mon Sep 17 00:00:00 2001 From: Indyuce Date: Sun, 3 Nov 2019 17:44:25 +0100 Subject: [PATCH 1/3] !Fixed default mining config --- src/main/resources/default/professions/mining.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/default/professions/mining.yml b/src/main/resources/default/professions/mining.yml index e934564b..a107b347 100644 --- a/src/main/resources/default/professions/mining.yml +++ b/src/main/resources/default/professions/mining.yml @@ -22,7 +22,7 @@ on-mine: - 'exp{profession=mining;amount=32}' diamond: - #the material you need to mine + # The material you need to mine material: DIAMOND_ORE # Refer to drop-tables.yml From 64db110f3c266f59d858d91bdef5a59b1bf96ed1 Mon Sep 17 00:00:00 2001 From: Indyuce Date: Sun, 3 Nov 2019 17:44:43 +0100 Subject: [PATCH 2/3] !Improved block trigger calculation --- .../Indyuce/mmocore/api/quest/trigger/Trigger.java | 5 ++--- .../net/Indyuce/mmocore/listener/BlockListener.java | 11 +++-------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/api/quest/trigger/Trigger.java b/src/main/java/net/Indyuce/mmocore/api/quest/trigger/Trigger.java index f95984d8..b284252e 100644 --- a/src/main/java/net/Indyuce/mmocore/api/quest/trigger/Trigger.java +++ b/src/main/java/net/Indyuce/mmocore/api/quest/trigger/Trigger.java @@ -7,11 +7,10 @@ import net.Indyuce.mmocore.api.load.MMOLineConfig; import net.Indyuce.mmocore.api.player.PlayerData; public abstract class Trigger { - private long delay; + private final long delay; public Trigger(MMOLineConfig config) { - if (config.contains("delay")) - delay = (long) (config.getDouble("delay") * 20); + delay = config.contains("delay") ? (long) (config.getDouble("delay") * 20) : 0; } public boolean hasDelay() { diff --git a/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java b/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java index 4f284a21..3b85a65e 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java +++ b/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java @@ -18,7 +18,6 @@ import org.bukkit.metadata.FixedMetadataValue; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.event.CustomBlockMineEvent; import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.api.quest.trigger.ExperienceTrigger; import net.Indyuce.mmocore.manager.CustomBlockManager.BlockInfo; import net.Indyuce.mmocore.manager.RestrictionManager.BlockPermissions; @@ -81,15 +80,11 @@ public class BlockListener implements Listener { * apply triggers, add experience info to the event so the other * events can give exp to other TOOLS and display HOLOGRAMS */ - if (info.hasTriggers()) { + if (info.hasTriggers() && !block.hasMetadata("player_placed")) { PlayerData playerData = PlayerData.get(player); - info.getTriggers().forEach(trigger -> { - if (!block.hasMetadata("player_placed") && trigger instanceof ExperienceTrigger) - trigger.apply(playerData); - }); + info.getTriggers().forEach(trigger -> trigger.apply(playerData)); if (!block.hasMetadata("player_placed") && info.hasExperience() && MMOCore.plugin.hasHolograms()) - MMOCore.plugin.hologramSupport.displayIndicator(block.getLocation().add(.5, 1.5, .5), - MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + called.getGainedExperience().getValue()).message(), player); + MMOCore.plugin.hologramSupport.displayIndicator(block.getLocation().add(.5, 1.5, .5), MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + called.getGainedExperience().getValue()).message(), player); } /* From ad392038ddb051a658ba5fe5f5922fd791fdc938 Mon Sep 17 00:00:00 2001 From: Indyuce Date: Mon, 11 Nov 2019 00:16:40 +0100 Subject: [PATCH 3/3] !Moved action bar to another class --- .../java/net/Indyuce/mmocore/MMOCore.java | 46 ++--------------- .../Indyuce/mmocore/api/PlayerActionBar.java | 50 +++++++++++++++++++ .../mmocore/api/player/PlayerData.java | 38 +++++++------- .../player/profess/SavedClassInformation.java | 2 +- .../rpg/admin/HideActionBarCommandMap.java | 6 +-- src/main/resources/config.yml | 10 ++-- 6 files changed, 79 insertions(+), 73 deletions(-) create mode 100644 src/main/java/net/Indyuce/mmocore/api/PlayerActionBar.java diff --git a/src/main/java/net/Indyuce/mmocore/MMOCore.java b/src/main/java/net/Indyuce/mmocore/MMOCore.java index 7aba11d8..3f3b2832 100644 --- a/src/main/java/net/Indyuce/mmocore/MMOCore.java +++ b/src/main/java/net/Indyuce/mmocore/MMOCore.java @@ -2,15 +2,10 @@ package net.Indyuce.mmocore; import java.io.File; import java.lang.reflect.Field; -import java.text.DecimalFormat; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; import java.util.logging.Level; import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import org.bukkit.attribute.Attribute; import org.bukkit.command.CommandMap; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.java.JavaPlugin; @@ -19,6 +14,7 @@ import org.bukkit.scheduler.BukkitRunnable; import com.codingforcookies.armorequip.ArmorListener; import net.Indyuce.mmocore.api.ConfigFile; +import net.Indyuce.mmocore.api.PlayerActionBar; import net.Indyuce.mmocore.api.debug.DebugMode; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource; @@ -96,8 +92,6 @@ import net.Indyuce.mmocore.manager.social.PartyManager; import net.Indyuce.mmocore.manager.social.RequestManager; import net.Indyuce.mmocore.version.ServerVersion; import net.Indyuce.mmocore.version.nms.NMSHandler; -import net.md_5.bungee.api.ChatMessageType; -import net.md_5.bungee.api.chat.TextComponent; public class MMOCore extends JavaPlugin { public static MMOCore plugin; @@ -127,6 +121,7 @@ public class MMOCore extends JavaPlugin { public ServerVersion version; public InventoryManager inventoryManager; public RegionHandler regionHandler; + public PlayerActionBar actionBarManager ; /* * professions @@ -139,7 +134,6 @@ public class MMOCore extends JavaPlugin { public final MMOLoadManager loadManager = new MMOLoadManager(); public RPGUtilHandler rpgUtilHandler = new DefaultRPGUtilHandler(); - private List pausePlayers = new ArrayList<>(); public void onLoad() { plugin = this; @@ -260,29 +254,8 @@ public class MMOCore extends JavaPlugin { /* * default action bar. only ran if the action bar is enabled */ - if (getConfig().getBoolean("action-bar.enabled")) { - DecimalFormat format = new DecimalFormat(getConfig().getString("action-bar.decimal"), configManager.formatSymbols); - int ticks = getConfig().getInt("action-bar.ticks-to-update"); - - new BukkitRunnable() { - public void run() { - for (PlayerData data : PlayerData.getAll()) { - if (data.isOnline() && !data.getPlayer().isDead() && !data.isCasting() && !pausePlayers.contains(data.getUniqueId())) { - data.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(placeholderParser.parse(data.getPlayer(), - ChatColor.translateAlternateColorCodes('&', getConfig().getString("action-bar.format").replace("{health}", format.format(data.getPlayer().getHealth())) - .replace("{max_health}", "" + StatType.MAX_HEALTH.format(data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue())).replace("{mana}", format.format(data.getMana())) - .replace("{max_mana}", "" + StatType.MAX_MANA.format(data.getStats().getStat(StatType.MAX_MANA))).replace("{stamina}", format.format(data.getStamina())) - .replace("{max_stamina}", "" + StatType.MAX_STAMINA.format(data.getStats().getStat(StatType.MAX_STAMINA))) - .replace("{stellium}", format.format(data.getStellium())) - .replace("{max_stellium}", "" + StatType.MAX_STELLIUM.format(data.getStats().getStat(StatType.MAX_STELLIUM))) - .replace("{class}", data.getProfess().getName()).replace("{xp}", "" + data.getExperience()) - .replace("{armor}", "" + StatType.ARMOR.format(data.getPlayer().getAttribute(Attribute.GENERIC_ARMOR).getValue())).replace("{level}", "" + data.getLevel()) - .replace("{name}", data.getPlayer().getDisplayName()))))); - } - } - } - }.runTaskTimerAsynchronously(MMOCore.plugin, 100, ticks); - } + if (getConfig().getBoolean("action-bar.enabled")) + new PlayerActionBar(getConfig().getConfigurationSection("action-bar")); /* * enable debug mode for extra debug tools. @@ -438,15 +411,4 @@ public class MMOCore extends JavaPlugin { public boolean hasEconomy() { return economy != null && economy.isValid(); } - - public void pauseDefaultActionBar(UUID uuid, int ticks) { - pausePlayers.add(uuid); - - new BukkitRunnable() { - @Override - public void run() { - pausePlayers.remove(uuid); - } - }.runTaskLater(MMOCore.plugin, ticks); - } } diff --git a/src/main/java/net/Indyuce/mmocore/api/PlayerActionBar.java b/src/main/java/net/Indyuce/mmocore/api/PlayerActionBar.java new file mode 100644 index 00000000..ee97866a --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/api/PlayerActionBar.java @@ -0,0 +1,50 @@ +package net.Indyuce.mmocore.api; + +import java.text.DecimalFormat; + +import org.bukkit.ChatColor; +import org.bukkit.attribute.Attribute; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.scheduler.BukkitRunnable; + +import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.api.player.stats.StatType; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.TextComponent; + +public class PlayerActionBar extends BukkitRunnable { +private final int ticks; + private final DecimalFormat digit; + private final String format; + + public PlayerActionBar(ConfigurationSection config) { + digit = new DecimalFormat(config.getString("decimal"), MMOCore.plugin.configManager.formatSymbols); + ticks = config.getInt("ticks-to-update"); + format = config.getString("format"); + + runTaskTimerAsynchronously(MMOCore.plugin, 0, ticks); + } + + @Override + public void run() { + for (PlayerData data : PlayerData.getAll()) + if (data.isOnline() && !data.getPlayer().isDead() && !data.isCasting() && data.canSeeActionBar()) { + data.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(MMOCore.plugin.placeholderParser.parse(data.getPlayer(), + ChatColor.translateAlternateColorCodes('&', new String(format) + .replace("{health}", digit.format(data.getPlayer().getHealth())) + .replace("{max_health}", "" + StatType.MAX_HEALTH.format(data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue())) + .replace("{mana}", digit.format(data.getMana())) + .replace("{max_mana}", "" + StatType.MAX_MANA.format(data.getStats().getStat(StatType.MAX_MANA))) + .replace("{stamina}", digit.format(data.getStamina())) + .replace("{max_stamina}", "" + StatType.MAX_STAMINA.format(data.getStats().getStat(StatType.MAX_STAMINA))) + .replace("{stellium}", digit.format(data.getStellium())) + .replace("{max_stellium}", "" + StatType.MAX_STELLIUM.format(data.getStats().getStat(StatType.MAX_STELLIUM))) + .replace("{class}", data.getProfess().getName()) + .replace("{xp}", "" + data.getExperience()) + .replace("{armor}", "" + StatType.ARMOR.format(data.getPlayer().getAttribute(Attribute.GENERIC_ARMOR).getValue())) + .replace("{level}", "" + data.getLevel()) + .replace("{name}", data.getPlayer().getDisplayName()))))); + } + } +} diff --git a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index 85d5a916..a47718f6 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -77,7 +77,7 @@ public class PlayerData { private final PlayerAttributes attributes = new PlayerAttributes(this); private final PlayerStats playerStats = new PlayerStats(this); - private long lastWaypoint, lastLogin, lastFriendRequest, lastActionbarUpdate; + private long lastWaypoint, lastLogin, lastFriendRequest, actionBarTimeOut; private final Map skills = new HashMap<>(); private final PlayerSkillData skillData = new PlayerSkillData(this); @@ -519,9 +519,7 @@ public class PlayerData { } public void giveMana(double amount) { - if (mana != (mana = Math.max(0, Math.min(getStats().getStat(StatType.MAX_MANA), mana + amount)))) - if (MMOCore.plugin.getConfig().getBoolean("display.mana")) - displayMana(); + mana = Math.max(0, Math.min(getStats().getStat(StatType.MAX_MANA), mana + amount)); } public void giveStamina(double amount) { @@ -576,28 +574,28 @@ public class PlayerData { return skillCasting != null; } - public void displayActionBar(String message) { - MMOCore.plugin.pauseDefaultActionBar(uuid, 60); + /* + * returns if the action bar is not being used to display anything else and + * if the general info action bar can be displayed + */ + public boolean canSeeActionBar() { + return actionBarTimeOut + 100 < System.currentTimeMillis(); + } + + public void setActionBarTimeOut(long actionBarTimeOut) { + this.actionBarTimeOut = actionBarTimeOut; + } - lastActionbarUpdate = System.currentTimeMillis(); + public void displayActionBar(String message) { + actionBarTimeOut = System.currentTimeMillis(); player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message)); } - /* - * 200ms timeout to prevent action bar displayed gitches when casting spells - * and when using a waypoint. - */ - public void displayMana() { - if (System.currentTimeMillis() > lastActionbarUpdate + 1200) - MMOCore.plugin.pauseDefaultActionBar(uuid, 60); - player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(getProfess().getManaDisplay().generateBar(getMana(), getStats().getStat(StatType.MAX_MANA)))); + public void setAttribute(PlayerAttribute attribute, int value) { + setAttribute(attribute.getId(), value); } - public void setAttributes(PlayerAttribute attribute, int value) { - setAttributes(attribute.getId(), value); - } - - public void setAttributes(String id, int value) { + public void setAttribute(String id, int value) { attributes.setBaseAttribute(id, value); } diff --git a/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java b/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java index cb66aaa1..81ca09b4 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java @@ -140,7 +140,7 @@ public class SavedClassInformation { player.setAttributePoints(attributePoints); player.setAttributeReallocationPoints(attributeReallocationPoints); skills.keySet().forEach(id -> player.setSkillLevel(id, skills.get(id))); - attributes.keySet().forEach(id -> player.setAttributes(id, attributes.get(id))); + attributes.keySet().forEach(id -> player.setAttribute(id, attributes.get(id))); /* * unload current class information and set the new profess once diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/HideActionBarCommandMap.java b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/HideActionBarCommandMap.java index a7297d4f..1cf763b6 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/HideActionBarCommandMap.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/HideActionBarCommandMap.java @@ -5,7 +5,7 @@ import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.command.api.CommandEnd; import net.Indyuce.mmocore.command.api.CommandMap; import net.Indyuce.mmocore.command.api.Parameter; @@ -36,8 +36,8 @@ public class HideActionBarCommandMap extends CommandEnd { sender.sendMessage(ChatColor.RED + args[3] + " is not a valid number."); return CommandResult.FAILURE; } - - MMOCore.plugin.pauseDefaultActionBar(player.getUniqueId(), amount); + + PlayerData.get(player).setActionBarTimeOut(System.currentTimeMillis() - 100 + amount * 50); return CommandResult.SUCCESS; } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 591a1d31..59bce6fa 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -36,21 +36,17 @@ lootsplosion: offset: .2 height: .6 -# settings for the default action bar +# Settings for the default action bar action-bar: # Whether or not to use the default action bar. (This doesn't change any other action bars provided by MMOCore.) enabled: true - # the decimal format for stats (not including stat formats in stats.yml) + # The decimal format for stats (not including stat formats in stats.yml) decimal: "0.#" # The amount of ticks before updating the info ticks-to-update: 5 - # how to display the data. + # How to display the data. format: "&c❤ {health}/{max_health} &f| &9⭐ {mana}/{max_mana} &f| &7⛨ {armor}" -# Whether or not to display the mana bar when regenerating mana -display: - mana: true - party: # Edit party buffs here. You may