Added two new placeholders:

%mmocore_profession_experience_<profession>%
%mmocore_profession_next_level_<profession>%
(more information on the wiki)

API Changes:
CustomBlockMineEvent now has a new method to check if the block was actually broken or not.
This commit is contained in:
ASangarin 2020-11-29 00:58:56 +01:00
parent c0bdf1ee12
commit 8812e63b3e
4 changed files with 49 additions and 30 deletions

View File

@ -22,9 +22,10 @@ public class CustomBlockMineEvent extends PlayerDataEvent implements Cancellable
private final List<ItemStack> drops;
private final ExperienceInfo experience;
private boolean canBreak;
private boolean cancelled = false;
public CustomBlockMineEvent(PlayerData player, Block block, BlockInfo info) {
public CustomBlockMineEvent(PlayerData player, Block block, BlockInfo info, boolean canBreak) {
super(player);
this.block = block;
@ -33,6 +34,7 @@ public class CustomBlockMineEvent extends PlayerDataEvent implements Cancellable
&& info.getDropTable().areConditionsMet(new ConditionInstance(player.getPlayer())))
? info.collectDrops(new LootBuilder(player, 0)) : new ArrayList<>();
this.experience = info.hasExperience() ? info.getExperience().newInfo() : null;
this.canBreak = canBreak;
}
public Block getBlock() {
@ -55,6 +57,14 @@ public class CustomBlockMineEvent extends PlayerDataEvent implements Cancellable
return experience;
}
public boolean canBreak() {
return canBreak;
}
public void setCanBreak(boolean value) {
canBreak = value;
}
@Override
public boolean isCancelled() {
return cancelled;

View File

@ -76,7 +76,7 @@ public class PlayerProfessions {
}
public int getLevel(String profession) {
return Math.max(1, level.containsKey(profession) ? level.get(profession) : 1);
return Math.max(1, level.getOrDefault(profession, 1));
}
public int getLevel(Profession profession) {
@ -84,7 +84,7 @@ public class PlayerProfessions {
}
public int getExperience(String id) {
return exp.containsKey(id) ? exp.get(id) : 0;
return exp.getOrDefault(id, 0);
}
public int getExperience(Profession profession) {
@ -95,6 +95,11 @@ public class PlayerProfessions {
return profession.getExpCurve().getExperience(getLevel(profession) + 1);
}
public int getLevelUpExperience(String id) {
if(!MMOCore.plugin.professionManager.has(id)) return 0;
return MMOCore.plugin.professionManager.get(id).getExpCurve().getExperience(getLevel(id) + 1);
}
public void setLevel(Profession profession, int value) {
level.put(profession.getId(), value);
}

View File

@ -1,12 +1,5 @@
package net.Indyuce.mmocore.comp.placeholder;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.attribute.Attribute;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.experience.PlayerProfessions;
@ -15,6 +8,12 @@ import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.stats.StatType;
import net.Indyuce.mmocore.api.quest.PlayerQuests;
import net.mmogroup.mmolib.api.util.AltChar;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.attribute.Attribute;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class RPGPlaceholders extends PlaceholderExpansion {
@Override
@ -74,9 +73,7 @@ public class RPGPlaceholders extends PlaceholderExpansion {
double ratio = 20 * player.getPlayer().getHealth()
/ player.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
for (double j = 1; j < 20; j++)
format.append((ratio >= j ? ChatColor.RED
: ratio >= j - .5 ? ChatColor.DARK_RED : ChatColor.DARK_GRAY)
+ AltChar.listSquare);
format.append(ratio >= j ? ChatColor.RED : ratio >= j - .5 ? ChatColor.DARK_RED : ChatColor.DARK_GRAY).append(AltChar.listSquare);
return format.toString();
}
@ -98,6 +95,14 @@ public class RPGPlaceholders extends PlaceholderExpansion {
: MMOCore.plugin.configManager.noSkillBoundPlaceholder;
}
else if (identifier.startsWith("profession_experience_"))
return "" + PlayerData.get(player).getCollectionSkills()
.getExperience(identifier.substring(22).replace(" ", "-").replace("_", "-").toLowerCase());
else if (identifier.startsWith("profession_next_level_"))
return "" + PlayerData.get(player).getCollectionSkills()
.getLevelUpExperience(identifier.substring(21).replace(" ", "-").replace("_", "-").toLowerCase());
else if (identifier.startsWith("profession_"))
return "" + PlayerData.get(player).getCollectionSkills()
.getLevel(identifier.substring(11).replace(" ", "-").replace("_", "-").toLowerCase());
@ -148,14 +153,12 @@ public class RPGPlaceholders extends PlaceholderExpansion {
return MMOCore.plugin.configManager.decimal.format(PlayerData.get(player).getStamina());
else if (identifier.equals("stamina_bar")) {
String format = "";
StringBuilder format = new StringBuilder();
PlayerData data = PlayerData.get(player);
double ratio = 20 * data.getStamina() / data.getStats().getStat(StatType.MAX_STAMINA);
for (double j = 1; j < 20; j++)
format += (ratio >= j ? MMOCore.plugin.configManager.staminaFull
: ratio >= j - .5 ? MMOCore.plugin.configManager.staminaHalf : MMOCore.plugin.configManager.staminaEmpty)
+ AltChar.listSquare;
return format;
format.append(ratio >= j ? MMOCore.plugin.configManager.staminaFull : ratio >= j - .5 ? MMOCore.plugin.configManager.staminaHalf : MMOCore.plugin.configManager.staminaEmpty).append(AltChar.listSquare);
return format.toString();
}
else if (identifier.startsWith("stat_")) {
@ -167,12 +170,12 @@ public class RPGPlaceholders extends PlaceholderExpansion {
return MMOCore.plugin.configManager.decimal.format(PlayerData.get(player).getStellium());
else if (identifier.equals("stellium_bar")) {
String format = "";
StringBuilder format = new StringBuilder();
PlayerData data = PlayerData.get(player);
double ratio = 20 * data.getStellium() / data.getStats().getStat(StatType.MAX_STELLIUM);
for (double j = 1; j < 20; j++)
format += (ratio >= j ? ChatColor.BLUE : ratio >= j - .5 ? ChatColor.AQUA : ChatColor.WHITE) + AltChar.listSquare;
return format;
format.append(ratio >= j ? ChatColor.BLUE : ratio >= j - .5 ? ChatColor.AQUA : ChatColor.WHITE).append(AltChar.listSquare);
return format.toString();
}
else if (identifier.equals("quest")) {

View File

@ -76,20 +76,21 @@ public class BlockListener implements Listener {
return;
}
boolean canBreak = true;
ItemStack item = player.getInventory().getItemInMainHand();
if (!MMOCore.plugin.restrictionManager.checkPermissions(item, info.getBlock())) {
MMOCore.plugin.configManager.getSimpleMessage("cannot-break").send(player);
canBreak = false;
}
/*
* Calls the event and listen for cancel & for drops changes... also
* allows to apply tool durability & enchants to drops, etc.
*/
CustomBlockMineEvent called = new CustomBlockMineEvent(PlayerData.get(player), block, info);
CustomBlockMineEvent called = new CustomBlockMineEvent(PlayerData.get(player), block, info, canBreak);
Bukkit.getPluginManager().callEvent(called);
if (called.isCancelled()) {
event.setCancelled(true);
return;
}
ItemStack item = player.getInventory().getItemInMainHand();
if (!MMOCore.plugin.restrictionManager.checkPermissions(item, info.getBlock())) {
MMOCore.plugin.configManager.getSimpleMessage("cannot-break").send(player);
if(called.isCancelled() || !called.canBreak()) {
event.setCancelled(true);
return;
}
@ -141,7 +142,7 @@ public class BlockListener implements Listener {
if (!movedBlock.hasMetadata("player_placed"))
return;
BlockFace direction = event.getDirection();
movedBlock = movedBlock.getRelative(direction, 2);
//movedBlock = movedBlock.getRelative(direction, 2);
for (Block b : event.getBlocks())
if (b.hasMetadata("player_placed")) {