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>
<groupId>net.Indyuce</groupId>
<artifactId>MMOCore</artifactId>
<version>1.0.13-SNAPSHOT</version>
<version>1.1-SNAPSHOT</version>
<description>Offer your players a brand new RPG experience.</description>
<properties>

View File

@ -3,9 +3,13 @@ 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.attribute.Attribute;
import org.bukkit.command.CommandMap;
import org.bukkit.configuration.file.FileConfiguration;
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.nms.NMSHandler;
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 static MMOCore plugin;
@ -133,6 +139,8 @@ public class MMOCore extends JavaPlugin {
public final MMOLoadManager loadManager = new MMOLoadManager();
public RPGUtilHandler rpgUtilHandler = new DefaultRPGUtilHandler();
private List<UUID> pausePlayers = new ArrayList<>();
public void onLoad() {
plugin = this;
version = new ServerVersion(Bukkit.getServer().getClass());
@ -253,22 +261,26 @@ public class MMOCore extends JavaPlugin {
*/
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() {
//System.out.println("Tick!");
for (PlayerData data : PlayerData.getAll()) {
if(!data.isCasting()) {
data.displayActionBar(placeholderParser.parse(data.getPlayer(), ChatColor.translateAlternateColorCodes('&', getConfig().getString("action-bar.format")
if(!data.isCasting() && !pausePlayers.contains(data.getUniqueId())) {
//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("{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.getStats().getStat(StatType.ARMOR)))
.replace("{level}", "" + data.getLevel()).replace("{name}", data.getPlayer().getDisplayName()))));
.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, getConfig().getInt("action-bar.ticks-to-update"));
}.runTaskTimerAsynchronously(MMOCore.plugin, 100, ticks);
}
/*
@ -415,4 +427,15 @@ 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);
}
}

View File

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

View File

@ -31,6 +31,7 @@ public class BlockListener implements Listener {
if (player.getGameMode() == GameMode.CREATIVE || event.isCancelled())
return;
String savedData = event.getBlock().getBlockData().getAsString();
Block block = event.getBlock();
/*
* if custom mining enabled, check for item breaking restrictions
@ -88,7 +89,7 @@ public class BlockListener implements Listener {
trigger.apply(playerData);
});
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);
}
/*
@ -100,12 +101,12 @@ public class BlockListener implements Listener {
if (drop.getType() != Material.AIR && drop.getAmount() > 0)
block.getWorld().dropItemNaturally(dropLocation, drop);
}
/*
* enable block regen.
*/
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.
*/
public void resetRemainingBlocks() {
active.forEach(info -> {
regen(info);
});
active.forEach(info -> { regen(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());
}
System.out.println("Regen Time: " + info.getRegen().getRegenTime());
new BukkitRunnable() {
public void run() {
regen(info);
}
public void run() { regen(info); }
}.runTaskLater(MMOCore.plugin, info.getRegen().getRegenTime());
}
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());
if(isPlayerSkull(info.getLocation().getBlock().getType()))
MMOCore.plugin.nms.setSkullValue(info.getLocation().getBlock(), info.getRegen().getHeadValue());
active.remove(info);
info.getLocation().getBlock().getState().update();
}
public boolean isEnabled(Entity entity) {
@ -199,8 +194,8 @@ public class CustomBlockManager extends MMOManager {
return regenHeadValue;
}
public RegenInfo generateRegenInfo(Block b) {
return new RegenInfo(b, this);
public RegenInfo generateRegenInfo(BlockData data, Location loc) {
return new RegenInfo(data, loc, this);
}
public boolean hasExperience() {
@ -221,24 +216,24 @@ public class CustomBlockManager extends MMOManager {
}
public class RegenInfo {
private final BlockData blockData;
private final BlockData data;
private final Location loc;
private final BlockInfo regen;
private final long date = System.currentTimeMillis();
public RegenInfo(Block block, BlockInfo regen) {
this.blockData = block.getBlockData().clone();
this.loc = block.getLocation();
public RegenInfo(BlockData data, Location loc, BlockInfo regen) {
this.data = data;
this.loc = loc;
this.regen = regen;
}
public boolean isTimedOut() {
return date + regen.getRegenTime() * 50 < System.currentTimeMillis();
}
public BlockData getBlockData() {
return blockData;
return data;
}
public Location getLocation() {

View File

@ -47,6 +47,10 @@ action-bar:
# 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

View File

@ -7,7 +7,7 @@ level-up:
- ''
profession-level-up:
- '&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!'
class-select: '&eYou are now a &6{class}&e!'
already-on-class: '&cYou are already a {class}.'
@ -50,16 +50,16 @@ casting:
on-cooldown: '&6[{index}] &c&l{skill} &6(&c{cooldown}&6)'
no-mana: '&6[{index}] &9&l{skill}'
split: '&7 &7 - &7 '
no-longer: '&cYou cancelled skill casting.'
no-longer: '%&cYou cancelled skill casting.'
no-mana: '&cYou do not have enough mana!'
on-cooldown: '&cThis skill is on cooldown.'
# Combat Log
now-in-combat: '&cYou are now in combat!'
leave-combat: '&aYou left combat.'
now-in-combat: '%&cYou are now in combat!'
leave-combat: '%&aYou left combat.'
# 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.'
waypoint-cooldown: '&cPlease wait {cooldown} before using a waypoint again.'
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.'
# 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
no-longer-friends: '&cYou and {unfriend} are no longer friends.'

View File

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