MMOCore 1.1: Two big updates (+ some small features)

Block Regen has been completely reworked.
Any message in the messages.yml can now be actionbar configured.

- A default actionbar has been added.
- Added placeblock experience source
- Commands removed from the commands.yml will now be disabled
- Moved EXP holograms up a bit
This commit is contained in:
Aria 2019-10-20 00:27:56 +02:00
parent d7b251f9fe
commit bd4d889c62
8 changed files with 63 additions and 34 deletions

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>net.Indyuce</groupId> <groupId>net.Indyuce</groupId>
<artifactId>MMOCore</artifactId> <artifactId>MMOCore</artifactId>
<version>1.0.13-SNAPSHOT</version> <version>1.1-SNAPSHOT</version>
<description>Offer your players a brand new RPG experience.</description> <description>Offer your players a brand new RPG experience.</description>
<properties> <properties>

View File

@ -3,9 +3,13 @@ package net.Indyuce.mmocore;
import java.io.File; import java.io.File;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.attribute.Attribute;
import org.bukkit.command.CommandMap; import org.bukkit.command.CommandMap;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -92,6 +96,8 @@ import net.Indyuce.mmocore.manager.social.RequestManager;
import net.Indyuce.mmocore.version.ServerVersion; import net.Indyuce.mmocore.version.ServerVersion;
import net.Indyuce.mmocore.version.nms.NMSHandler; import net.Indyuce.mmocore.version.nms.NMSHandler;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
public class MMOCore extends JavaPlugin { public class MMOCore extends JavaPlugin {
public static MMOCore plugin; public static MMOCore plugin;
@ -133,6 +139,8 @@ public class MMOCore extends JavaPlugin {
public final MMOLoadManager loadManager = new MMOLoadManager(); public final MMOLoadManager loadManager = new MMOLoadManager();
public RPGUtilHandler rpgUtilHandler = new DefaultRPGUtilHandler(); public RPGUtilHandler rpgUtilHandler = new DefaultRPGUtilHandler();
private List<UUID> pausePlayers = new ArrayList<>();
public void onLoad() { public void onLoad() {
plugin = this; plugin = this;
version = new ServerVersion(Bukkit.getServer().getClass()); version = new ServerVersion(Bukkit.getServer().getClass());
@ -253,22 +261,26 @@ public class MMOCore extends JavaPlugin {
*/ */
if(getConfig().getBoolean("action-bar.enabled")) { if(getConfig().getBoolean("action-bar.enabled")) {
DecimalFormat format = new DecimalFormat(getConfig().getString("action-bar.decimal"), configManager.formatSymbols); DecimalFormat format = new DecimalFormat(getConfig().getString("action-bar.decimal"), configManager.formatSymbols);
int ticks = getConfig().getInt("action-bar.ticks-to-update");
new BukkitRunnable() { new BukkitRunnable() {
public void run() { public void run() {
//System.out.println("Tick!");
for (PlayerData data : PlayerData.getAll()) { for (PlayerData data : PlayerData.getAll()) {
if(!data.isCasting()) { if(!data.isCasting() && !pausePlayers.contains(data.getUniqueId())) {
data.displayActionBar(placeholderParser.parse(data.getPlayer(), ChatColor.translateAlternateColorCodes('&', getConfig().getString("action-bar.format") //System.out.println("Display!");
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.getStats().getStat(StatType.MAX_HEALTH))) .replace("{health}", format.format(data.getPlayer().getHealth())).replace("{max_health}", "" + StatType.MAX_HEALTH.format(data.getStats().getStat(StatType.MAX_HEALTH)))
.replace("{mana}", format.format(data.getMana())).replace("{max_mana}", "" + StatType.MAX_MANA.format(data.getStats().getStat(StatType.MAX_MANA))) .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("{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("{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.getStats().getStat(StatType.ARMOR))) .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())))); .replace("{level}", "" + data.getLevel()).replace("{name}", data.getPlayer().getDisplayName())))));
} }
} }
} }
}.runTaskTimerAsynchronously(MMOCore.plugin, 100, getConfig().getInt("action-bar.ticks-to-update")); }.runTaskTimerAsynchronously(MMOCore.plugin, 100, ticks);
} }
/* /*
@ -415,4 +427,15 @@ public class MMOCore extends JavaPlugin {
public boolean hasEconomy() { public boolean hasEconomy() {
return economy != null && economy.isValid(); 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);
}
} }

View File

@ -571,6 +571,8 @@ public class PlayerData {
} }
public void displayActionBar(String message) { public void displayActionBar(String message) {
MMOCore.plugin.pauseDefaultActionBar(uuid, 60);
lastActionbarUpdate = System.currentTimeMillis(); lastActionbarUpdate = System.currentTimeMillis();
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message)); player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));
} }
@ -581,6 +583,7 @@ public class PlayerData {
*/ */
public void displayMana() { public void displayMana() {
if (System.currentTimeMillis() > lastActionbarUpdate + 1200) 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)))); player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(getProfess().getManaDisplay().generateBar(getMana(), getStats().getStat(StatType.MAX_MANA))));
} }

View File

@ -31,6 +31,7 @@ public class BlockListener implements Listener {
if (player.getGameMode() == GameMode.CREATIVE || event.isCancelled()) if (player.getGameMode() == GameMode.CREATIVE || event.isCancelled())
return; return;
String savedData = event.getBlock().getBlockData().getAsString();
Block block = event.getBlock(); Block block = event.getBlock();
/* /*
* if custom mining enabled, check for item breaking restrictions * if custom mining enabled, check for item breaking restrictions
@ -88,7 +89,7 @@ public class BlockListener implements Listener {
trigger.apply(playerData); trigger.apply(playerData);
}); });
if(!block.hasMetadata("player_placed") && info.hasExperience() && MMOCore.plugin.hasHolograms()) if(!block.hasMetadata("player_placed") && info.hasExperience() && MMOCore.plugin.hasHolograms())
MMOCore.plugin.hologramSupport.displayIndicator(block.getLocation().add(.5, .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);
} }
/* /*
@ -105,7 +106,7 @@ public class BlockListener implements Listener {
* enable block regen. * enable block regen.
*/ */
if (info.hasRegen()) if (info.hasRegen())
MMOCore.plugin.mineManager.initialize(info.generateRegenInfo(event.getBlock())); MMOCore.plugin.mineManager.initialize(info.generateRegenInfo(Bukkit.createBlockData(savedData), block.getLocation()));
} }
} }

View File

@ -64,9 +64,7 @@ public class CustomBlockManager extends MMOManager {
* are reset and put back in place. * are reset and put back in place.
*/ */
public void resetRemainingBlocks() { public void resetRemainingBlocks() {
active.forEach(info -> { active.forEach(info -> { regen(info); });
regen(info);
});
} }
public void initialize(RegenInfo info) { public void initialize(RegenInfo info) {
@ -78,21 +76,18 @@ public class CustomBlockManager extends MMOManager {
MMOCore.plugin.nms.setSkullValue(info.getLocation().getBlock(), info.getRegen().getRegenHeadValue()); MMOCore.plugin.nms.setSkullValue(info.getLocation().getBlock(), info.getRegen().getRegenHeadValue());
} }
System.out.println("Regen Time: " + info.getRegen().getRegenTime());
new BukkitRunnable() { new BukkitRunnable() {
public void run() { public void run() { regen(info); }
regen(info);
}
}.runTaskLater(MMOCore.plugin, info.getRegen().getRegenTime()); }.runTaskLater(MMOCore.plugin, info.getRegen().getRegenTime());
} }
private void regen(RegenInfo info) { private void regen(RegenInfo info) {
System.out.println("Material: " + info.getBlockData().getMaterial());
//info.getLocation().getBlock().setType(info.getRegen().getBlock());
info.getLocation().getBlock().setBlockData(info.getBlockData()); info.getLocation().getBlock().setBlockData(info.getBlockData());
if(isPlayerSkull(info.getLocation().getBlock().getType())) if(isPlayerSkull(info.getLocation().getBlock().getType()))
MMOCore.plugin.nms.setSkullValue(info.getLocation().getBlock(), info.getRegen().getHeadValue()); MMOCore.plugin.nms.setSkullValue(info.getLocation().getBlock(), info.getRegen().getHeadValue());
active.remove(info); active.remove(info);
info.getLocation().getBlock().getState().update();
} }
public boolean isEnabled(Entity entity) { public boolean isEnabled(Entity entity) {
@ -199,8 +194,8 @@ public class CustomBlockManager extends MMOManager {
return regenHeadValue; return regenHeadValue;
} }
public RegenInfo generateRegenInfo(Block b) { public RegenInfo generateRegenInfo(BlockData data, Location loc) {
return new RegenInfo(b, this); return new RegenInfo(data, loc, this);
} }
public boolean hasExperience() { public boolean hasExperience() {
@ -221,15 +216,15 @@ public class CustomBlockManager extends MMOManager {
} }
public class RegenInfo { public class RegenInfo {
private final BlockData blockData; private final BlockData data;
private final Location loc; private final Location loc;
private final BlockInfo regen; private final BlockInfo regen;
private final long date = System.currentTimeMillis(); private final long date = System.currentTimeMillis();
public RegenInfo(Block block, BlockInfo regen) { public RegenInfo(BlockData data, Location loc, BlockInfo regen) {
this.blockData = block.getBlockData().clone(); this.data = data;
this.loc = block.getLocation(); this.loc = loc;
this.regen = regen; this.regen = regen;
} }
@ -238,7 +233,7 @@ public class CustomBlockManager extends MMOManager {
} }
public BlockData getBlockData() { public BlockData getBlockData() {
return blockData; return data;
} }
public Location getLocation() { public Location getLocation() {

View File

@ -47,6 +47,10 @@ action-bar:
# how to display the data. # how to display the data.
format: "&c❤ {health}/{max_health} &f| &9⭐ {mana}/{max_mana} &f| &7⛨ {armor}" 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: party:
# Edit party buffs here. You may # Edit party buffs here. You may

View File

@ -7,7 +7,7 @@ level-up:
- '' - ''
profession-level-up: profession-level-up:
- '&eYou are now level &6{level}&e in &6{profession}&e!' - '&eYou are now level &6{level}&e in &6{profession}&e!'
exp-notification: '&f{profession} &e{progress} &e{ratio}%' exp-notification: '%&f{profession} &e{progress} &e{ratio}%'
exp-hologram: '&e+{exp} EXP!' exp-hologram: '&e+{exp} EXP!'
class-select: '&eYou are now a &6{class}&e!' class-select: '&eYou are now a &6{class}&e!'
already-on-class: '&cYou are already a {class}.' already-on-class: '&cYou are already a {class}.'
@ -50,16 +50,16 @@ casting:
on-cooldown: '&6[{index}] &c&l{skill} &6(&c{cooldown}&6)' on-cooldown: '&6[{index}] &c&l{skill} &6(&c{cooldown}&6)'
no-mana: '&6[{index}] &9&l{skill}' no-mana: '&6[{index}] &9&l{skill}'
split: '&7 &7 - &7 ' split: '&7 &7 - &7 '
no-longer: '&cYou cancelled skill casting.' no-longer: '%&cYou cancelled skill casting.'
no-mana: '&cYou do not have enough mana!' no-mana: '&cYou do not have enough mana!'
on-cooldown: '&cThis skill is on cooldown.' on-cooldown: '&cThis skill is on cooldown.'
# Combat Log # Combat Log
now-in-combat: '&cYou are now in combat!' now-in-combat: '%&cYou are now in combat!'
leave-combat: '&aYou left combat.' leave-combat: '%&aYou left combat.'
# Waypoints # Waypoints
new-waypoint: '&eYou unlocked the &6{waypoint} &ewaypoint!' new-waypoint: '%&eYou unlocked the &6{waypoint} &ewaypoint!'
not-enough-stellium: '&cYou don''t have enough stellium: you need {more} more.' not-enough-stellium: '&cYou don''t have enough stellium: you need {more} more.'
waypoint-cooldown: '&cPlease wait {cooldown} before using a waypoint again.' waypoint-cooldown: '&cPlease wait {cooldown} before using a waypoint again.'
not-unlocked-waypoint: '&cYou have not unlocked that waypoint yet.' not-unlocked-waypoint: '&cYou have not unlocked that waypoint yet.'
@ -78,7 +78,7 @@ not-enough-money: '&cYou don''t have enough money, you need {left} more gold.'
stand-near-enderchest: '&cYou must be standing near a bank to do that.' stand-near-enderchest: '&cYou must be standing near a bank to do that.'
# Blocks # Blocks
cannot-break: '&cYou do not have the right tool in order to break that block.' cannot-break: '%&cYou do not have the right tool in order to break that block.'
# Friends # Friends
no-longer-friends: '&cYou and {unfriend} are no longer friends.' no-longer-friends: '&cYou and {unfriend} are no longer friends.'

View File

@ -9,7 +9,8 @@ experience:
per-level: 3 per-level: 3
on-mine: on-mine:
EMERALD_ORE: emerald:
material: EMERALD_ORE
drop-table: drop-table:
items: items:
- 'vanilla{type=EMERALD} 1 1-9' - 'vanilla{type=EMERALD} 1 1-9'
@ -20,7 +21,9 @@ on-mine:
triggers: triggers:
- 'exp{profession=mining;amount=32}' - 'exp{profession=mining;amount=32}'
DIAMOND_ORE: diamond:
#the material you need to mine
material: DIAMOND_ORE
# Refer to drop-tables.yml # Refer to drop-tables.yml
# The drop table used by the block. # The drop table used by the block.