diff --git a/pom.xml b/pom.xml
index 089c2902..813046d6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0
net.Indyuce
MMOCore
- 1.4.5
+ 1.4.6
MMOCore
Offer your players a brand new RPG experience.
diff --git a/src/main/java/net/Indyuce/mmocore/MMOCore.java b/src/main/java/net/Indyuce/mmocore/MMOCore.java
index 2e5b6048..91f54c40 100644
--- a/src/main/java/net/Indyuce/mmocore/MMOCore.java
+++ b/src/main/java/net/Indyuce/mmocore/MMOCore.java
@@ -107,11 +107,11 @@ public class MMOCore extends JavaPlugin {
public VaultEconomy economy;
public HologramSupport hologramSupport;
public InventoryManager inventoryManager;
- public PlayerActionBar actionBarManager;
public RegionHandler regionHandler = new DefaultRegionHandler();
public FlagPlugin flagPlugin = new DefaultFlags();
public PlaceholderParser placeholderParser = new DefaultParser();
public DataProvider dataProvider = new YAMLDataProvider();
+ public final PlayerActionBar actionBarManager = new PlayerActionBar();
public final SkillManager skillManager = new SkillManager();
public final ClassManager classManager = new ClassManager();
public final DropTableManager dropTableManager = new DropTableManager();
@@ -250,12 +250,6 @@ public class MMOCore extends JavaPlugin {
saveDefaultConfig();
reloadPlugin();
- /*
- * default action bar. only ran if the action bar is enabled
- */
- if (getConfig().getBoolean("action-bar.enabled"))
- new PlayerActionBar(getConfig().getConfigurationSection("action-bar"));
-
if (getConfig().getBoolean("vanilla-exp-redirection.enabled"))
Bukkit.getPluginManager().registerEvents(new RedirectVanillaExp(getConfig().getDouble("vanilla-exp-redirection.ratio")), this);
@@ -374,12 +368,14 @@ public class MMOCore extends JavaPlugin {
}
public void reloadPlugin() {
+ reloadConfig();
+
configManager = new ConfigManager();
skillManager.reload();
mineManager.clear();
- mineManager.reload();
+ mineManager.reload(getConfig().getBoolean("protect-custom-mine"));
fishingManager.clear();
alchemyManager.clear();
@@ -416,6 +412,9 @@ public class MMOCore extends JavaPlugin {
requestManager = new RequestManager();
configItems = new ConfigItemManager(new ConfigFile("items").getConfig());
+ if(getConfig().isConfigurationSection("action-bar"))
+ actionBarManager.reload(getConfig().getConfigurationSection("action-bar"));
+
StatType.load();
}
diff --git a/src/main/java/net/Indyuce/mmocore/api/PlayerActionBar.java b/src/main/java/net/Indyuce/mmocore/api/PlayerActionBar.java
index fbb3d3e9..136b8490 100644
--- a/src/main/java/net/Indyuce/mmocore/api/PlayerActionBar.java
+++ b/src/main/java/net/Indyuce/mmocore/api/PlayerActionBar.java
@@ -14,16 +14,23 @@ import net.md_5.bungee.api.chat.TextComponent;
import net.mmogroup.mmolib.MMOLib;
public class PlayerActionBar extends BukkitRunnable {
- private final int ticks;
- private final DecimalFormat digit;
- private final String format;
+ boolean initialized = false;
- public PlayerActionBar(ConfigurationSection config) {
- digit = new DecimalFormat(config.getString("decimal"), MMOCore.plugin.configManager.formatSymbols);
- ticks = config.getInt("ticks-to-update");
- format = config.getString("format");
-
- runTaskTimer(MMOCore.plugin, 0, ticks);
+ private ActionBarConfig config;
+ private DecimalFormat digit;
+
+ public void reload(ConfigurationSection cfg) {
+ config = new ActionBarConfig(cfg);
+ digit = new DecimalFormat(config.digit, MMOCore.plugin.configManager.formatSymbols);
+
+ if(!initialized && config.enabled) {
+ runTaskTimer(MMOCore.plugin, 0, config.ticks);
+ initialized = true;
+ }
+ }
+
+ public long getTimeOut() {
+ return config.timeout;
}
@Override
@@ -31,7 +38,7 @@ public class PlayerActionBar extends BukkitRunnable {
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(),
- MMOLib.plugin.parseColors(new String(data.getProfess().hasActionBar() ? data.getProfess().getActionBar() : format)
+ MMOLib.plugin.parseColors(new String(data.getProfess().hasActionBar() ? data.getProfess().getActionBar() : config.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_icon}", data.getProfess().getManaDisplay().getIcon())
@@ -48,4 +55,18 @@ public class PlayerActionBar extends BukkitRunnable {
.replace("{name}", data.getPlayer().getDisplayName())))));
}
}
+
+ private class ActionBarConfig {
+ private final boolean enabled;
+ private final int ticks, timeout;
+ private final String digit, format;
+
+ private ActionBarConfig(ConfigurationSection config) {
+ enabled = config.getBoolean("enabled", false);
+ timeout = config.getInt("", 60);
+ digit = config.getString("decimal", "0.#");
+ ticks = config.getInt("ticks-to-update", 5);
+ format = config.getString("format", "please format me :c");
+ }
+ }
}
diff --git a/src/main/java/net/Indyuce/mmocore/api/droptable/condition/WorldCondition.java b/src/main/java/net/Indyuce/mmocore/api/droptable/condition/WorldCondition.java
index 59c2e83d..0d99eb76 100644
--- a/src/main/java/net/Indyuce/mmocore/api/droptable/condition/WorldCondition.java
+++ b/src/main/java/net/Indyuce/mmocore/api/droptable/condition/WorldCondition.java
@@ -17,6 +17,6 @@ public class WorldCondition extends Condition {
@Override
public boolean isMet(ConditionInstance entity) {
- return names.contains(entity.getEntity().getWorld().getName());
+ return names.contains(entity.getEntity().getWorld().getName()) || names.contains("__global__");
}
}
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 28e57d9a..95046c48 100644
--- a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java
+++ b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java
@@ -577,7 +577,7 @@ public class PlayerData extends OfflinePlayerData {
}
public void displayActionBar(String message) {
- setActionBarTimeOut(60);
+ setActionBarTimeOut(MMOCore.plugin.actionBarManager.getTimeOut());
getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));
}
diff --git a/src/main/java/net/Indyuce/mmocore/api/quest/objective/MineBlockObjective.java b/src/main/java/net/Indyuce/mmocore/api/quest/objective/MineBlockObjective.java
index 86d68b32..ec2e6482 100644
--- a/src/main/java/net/Indyuce/mmocore/api/quest/objective/MineBlockObjective.java
+++ b/src/main/java/net/Indyuce/mmocore/api/quest/objective/MineBlockObjective.java
@@ -15,6 +15,7 @@ import net.mmogroup.mmolib.api.MMOLineConfig;
public class MineBlockObjective extends Objective {
private final Material block;
private final int required;
+ private final boolean playerPlaced;
public MineBlockObjective(ConfigurationSection section, MMOLineConfig config) {
super(section);
@@ -23,6 +24,7 @@ public class MineBlockObjective extends Objective {
block = Material.valueOf(config.getString("type").replace("-", "_").toUpperCase());
required = config.getInt("amount");
+ playerPlaced = config.getBoolean("player-placed", false);
}
@Override
@@ -39,6 +41,8 @@ public class MineBlockObjective extends Objective {
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void a(BlockBreakEvent event) {
+ if ((!playerPlaced) && event.getBlock().hasMetadata("player_placed"))
+ return;
if (event.getPlayer().equals(getQuestProgress().getPlayer().getPlayer()) && event.getBlock().getType() == block) {
count++;
getQuestProgress().getPlayer().getQuestData().updateBossBar();
diff --git a/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java b/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java
index 40832fa4..89cb80fe 100644
--- a/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java
+++ b/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java
@@ -36,19 +36,31 @@ public class BlockListener implements Listener {
String savedData = event.getBlock().getBlockData().getAsString();
Block block = event.getBlock();
+ final boolean regen = MMOCore.plugin.mineManager.isRegenerating(block);
+ if(regen && !MMOCore.plugin.mineManager.isBlockRegistered(block)) {
+ event.setCancelled(true);
+ return;
+ }
+
/*
* if custom mining enabled, check for item breaking restrictions
*/
boolean customMine = MMOCore.plugin.mineManager.isEnabled(player, block.getLocation());
if (!customMine)
return;
-
+
BlockInfo info = MMOCore.plugin.mineManager.getInfo(block);
- if (info == null || !info.getBlock().breakRestrictions(block)) {
+ if (info == null) {
+ if(MMOCore.plugin.mineManager.shouldProtect())
+ event.setCancelled(true);
+ return;
+ }
+
+ if(!info.getBlock().breakRestrictions(block)) {
event.setCancelled(true);
return;
}
-
+
/*
* calls the event and listen for cancel & for drops changes... also
* allows to apply tool durability & enchants to drops, etc.
@@ -109,7 +121,7 @@ public class BlockListener implements Listener {
* enable block regen.
*/
if (info.hasRegen())
- MMOCore.plugin.mineManager.initialize(info.startRegeneration(Bukkit.createBlockData(savedData), block.getLocation()));
+ MMOCore.plugin.mineManager.initialize(info.startRegeneration(Bukkit.createBlockData(savedData), block.getLocation()), !regen);
}
@EventHandler(priority = EventPriority.HIGH)
diff --git a/src/main/java/net/Indyuce/mmocore/manager/CustomBlockManager.java b/src/main/java/net/Indyuce/mmocore/manager/CustomBlockManager.java
index f4fdf6f8..8c394fec 100644
--- a/src/main/java/net/Indyuce/mmocore/manager/CustomBlockManager.java
+++ b/src/main/java/net/Indyuce/mmocore/manager/CustomBlockManager.java
@@ -49,6 +49,8 @@ public class CustomBlockManager extends MMOManager {
*/
private final List>> blockTypes = new ArrayList<>();
+ private boolean protect;
+
public CustomBlockManager() {
registerBlockType(block -> MMOCoreUtils.isPlayerHead(block.getType()) ? Optional.of(new SkullBlockType(block)) : Optional.empty());
}
@@ -61,6 +63,10 @@ public class CustomBlockManager extends MMOManager {
map.put(regen.getBlock().generateKey(), regen);
}
+ public boolean isBlockRegistered(Block block) {
+ return map.containsKey(findBlockType(block).generateKey());
+ }
+
public BlockInfo getInfo(Block block) {
return map.getOrDefault(findBlockType(block).generateKey(), null);
}
@@ -75,17 +81,19 @@ public class CustomBlockManager extends MMOManager {
return new VanillaBlockType(block);
}
- public void initialize(RegeneratingBlock info) {
- active.add(info);
+ public void initialize(RegeneratingBlock info, boolean schedule) {
+ if(schedule) {
+ active.add(info);
+ Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> regen(info, false), info.getRegeneratingBlock().getRegenerationInfo().getTime());
+ }
if (info.getRegeneratingBlock().getRegenerationInfo().hasTemporaryBlock())
info.getRegeneratingBlock().getRegenerationInfo().getTemporaryBlock().place(info.getLocation(), info);
- Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> regen(info), info.getRegeneratingBlock().getRegenerationInfo().getTime());
}
- private void regen(RegeneratingBlock info) {
+ private void regen(RegeneratingBlock info, boolean shutdown) {
info.getRegeneratingBlock().getBlock().place(info.getLocation(), info);
- active.remove(info);
info.getLocation().getBlock().getState().update();
+ if(!shutdown) active.remove(info);
}
/*
@@ -93,7 +101,18 @@ 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, true));
+ }
+
+ public boolean isRegenerating(Block block) {
+ Location loc = block.getLocation();
+ for(RegeneratingBlock info : active)
+ if(info.getLocation().getBlockX() == loc.getBlockX()
+ && info.getLocation().getBlockY() == loc.getBlockY()
+ && info.getLocation().getBlockZ() == loc.getBlockZ())
+ return true;
+
+ return false;
}
public boolean isEnabled(Entity entity) {
@@ -101,6 +120,8 @@ public class CustomBlockManager extends MMOManager {
}
public boolean isEnabled(Entity entity, Location loc) {
+ if(customMineConditions.isEmpty()) return false;
+
ConditionInstance conditionEntity = new ConditionInstance(entity, loc);
for (Condition condition : customMineConditions)
if (!condition.isMet(conditionEntity))
@@ -117,7 +138,16 @@ public class CustomBlockManager extends MMOManager {
MMOCore.log(Level.WARNING, "Could not load custom block '" + key + "': " + exception.getMessage());
}
}
+
+ public boolean shouldProtect() {
+ return protect;
+ }
+ public void reload(boolean protect) {
+ this.protect = protect;
+ reload();
+ }
+
@Override
public void reload() {
customMineConditions.clear();
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index a3b2cb47..6790f7d7 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -16,11 +16,20 @@ mysql:
flags: '?allowReconnect=true&useSSL=false'
# The list of all conditions which must be met for the
-# BLOCK REGEN and BLOCK RESTRICTIONS to apply.
-# Set to 'custom-mine-conditions: []' for no condition.
+# BLOCK REGEN and BLOCK RESTRICTIONS to apply. Set to
+# 'custom-mine-conditions: []' to disable custom mining entirely.
custom-mine-conditions:
-- 'world{name="world1,world2,world_nether,world_the_end"}'
-- 'region{name="region1,region2,__global__"}'
+- 'world{name="world,world_nether,world_the_end"}'
+- 'region{name="example_region,example_region2,__global__"}'
+#
+# custom-mine-conditions:
+# - 'world{name="__global__"}'
+#
+# ^ will enable custom mining server wide
+
+# Set to true to prevent vanilla blocks from being
+# broken when custom mining conditions are met
+protect-custom-mine: false
# Offset is the distance traveled on X and Y coordinates
# Height is the Y velocity coordinate. Lootsplosions
@@ -52,6 +61,10 @@ action-bar:
# The decimal format for stats (not including stat formats in stats.yml)
decimal: "0.#"
+ # The amount of miliseconds the bar will be faded
+ #out when displaying other action bars.
+ time-out: 60
+
# The amount of ticks before updating the info
ticks-to-update: 5