This commit is contained in:
Indyuce 2020-09-27 00:14:42 +02:00
commit 844a7ca675
12 changed files with 117 additions and 38 deletions

View File

@ -4,7 +4,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.4.5</version> <version>1.4.6</version>
<name>MMOCore</name> <name>MMOCore</name>
<description>Offer your players a brand new RPG experience.</description> <description>Offer your players a brand new RPG experience.</description>

View File

@ -107,11 +107,11 @@ public class MMOCore extends JavaPlugin {
public VaultEconomy economy; public VaultEconomy economy;
public HologramSupport hologramSupport; public HologramSupport hologramSupport;
public InventoryManager inventoryManager; public InventoryManager inventoryManager;
public PlayerActionBar actionBarManager;
public RegionHandler regionHandler = new DefaultRegionHandler(); public RegionHandler regionHandler = new DefaultRegionHandler();
public FlagPlugin flagPlugin = new DefaultFlags(); public FlagPlugin flagPlugin = new DefaultFlags();
public PlaceholderParser placeholderParser = new DefaultParser(); public PlaceholderParser placeholderParser = new DefaultParser();
public DataProvider dataProvider = new YAMLDataProvider(); public DataProvider dataProvider = new YAMLDataProvider();
public final PlayerActionBar actionBarManager = new PlayerActionBar();
public final SkillManager skillManager = new SkillManager(); public final SkillManager skillManager = new SkillManager();
public final ClassManager classManager = new ClassManager(); public final ClassManager classManager = new ClassManager();
public final DropTableManager dropTableManager = new DropTableManager(); public final DropTableManager dropTableManager = new DropTableManager();
@ -250,12 +250,6 @@ public class MMOCore extends JavaPlugin {
saveDefaultConfig(); saveDefaultConfig();
reloadPlugin(); 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")) if (getConfig().getBoolean("vanilla-exp-redirection.enabled"))
Bukkit.getPluginManager().registerEvents(new RedirectVanillaExp(getConfig().getDouble("vanilla-exp-redirection.ratio")), this); Bukkit.getPluginManager().registerEvents(new RedirectVanillaExp(getConfig().getDouble("vanilla-exp-redirection.ratio")), this);
@ -374,12 +368,14 @@ public class MMOCore extends JavaPlugin {
} }
public void reloadPlugin() { public void reloadPlugin() {
reloadConfig();
configManager = new ConfigManager(); configManager = new ConfigManager();
skillManager.reload(); skillManager.reload();
mineManager.clear(); mineManager.clear();
mineManager.reload(); mineManager.reload(getConfig().getBoolean("protect-custom-mine"));
fishingManager.clear(); fishingManager.clear();
alchemyManager.clear(); alchemyManager.clear();
@ -416,6 +412,9 @@ public class MMOCore extends JavaPlugin {
requestManager = new RequestManager(); requestManager = new RequestManager();
configItems = new ConfigItemManager(new ConfigFile("items").getConfig()); configItems = new ConfigItemManager(new ConfigFile("items").getConfig());
if(getConfig().isConfigurationSection("action-bar"))
actionBarManager.reload(getConfig().getConfigurationSection("action-bar"));
StatType.load(); StatType.load();
} }

View File

@ -14,16 +14,23 @@ import net.md_5.bungee.api.chat.TextComponent;
import net.mmogroup.mmolib.MMOLib; import net.mmogroup.mmolib.MMOLib;
public class PlayerActionBar extends BukkitRunnable { public class PlayerActionBar extends BukkitRunnable {
private final int ticks; boolean initialized = false;
private final DecimalFormat digit;
private final String format;
public PlayerActionBar(ConfigurationSection config) { private ActionBarConfig config;
digit = new DecimalFormat(config.getString("decimal"), MMOCore.plugin.configManager.formatSymbols); private DecimalFormat digit;
ticks = config.getInt("ticks-to-update");
format = config.getString("format");
runTaskTimer(MMOCore.plugin, 0, ticks); 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 @Override
@ -31,7 +38,7 @@ public class PlayerActionBar extends BukkitRunnable {
for (PlayerData data : PlayerData.getAll()) for (PlayerData data : PlayerData.getAll())
if (data.isOnline() && !data.getPlayer().isDead() && !data.isCasting() && data.canSeeActionBar()) { 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(), 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("{health}", digit.format(data.getPlayer().getHealth()))
.replace("{max_health}", "" + StatType.MAX_HEALTH.format(data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue())) .replace("{max_health}", "" + StatType.MAX_HEALTH.format(data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()))
.replace("{mana_icon}", data.getProfess().getManaDisplay().getIcon()) .replace("{mana_icon}", data.getProfess().getManaDisplay().getIcon())
@ -48,4 +55,18 @@ public class PlayerActionBar extends BukkitRunnable {
.replace("{name}", data.getPlayer().getDisplayName()))))); .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");
}
}
} }

View File

@ -17,6 +17,6 @@ public class WorldCondition extends Condition {
@Override @Override
public boolean isMet(ConditionInstance entity) { public boolean isMet(ConditionInstance entity) {
return names.contains(entity.getEntity().getWorld().getName()); return names.contains(entity.getEntity().getWorld().getName()) || names.contains("__global__");
} }
} }

View File

@ -577,7 +577,7 @@ public class PlayerData extends OfflinePlayerData {
} }
public void displayActionBar(String message) { public void displayActionBar(String message) {
setActionBarTimeOut(60); setActionBarTimeOut(MMOCore.plugin.actionBarManager.getTimeOut());
getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message)); getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));
} }

View File

@ -65,7 +65,7 @@ public class PlayerClass extends PostLoadObject {
this.id = id.toUpperCase().replace("-", "_").replace(" ", "_"); this.id = id.toUpperCase().replace("-", "_").replace(" ", "_");
name = MMOLib.plugin.parseColors(config.getString("display.name")); name = MMOLib.plugin.parseColors(config.getString("display.name", "INVALID DISPLAY NAME"));
icon = MMOCoreUtils.readIcon(config.getString("display.item", "BARRIER")); icon = MMOCoreUtils.readIcon(config.getString("display.item", "BARRIER"));
if (config.contains("display.texture") && icon.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) if (config.contains("display.texture") && icon.getType() == VersionMaterial.PLAYER_HEAD.toMaterial())

View File

@ -15,6 +15,7 @@ import net.mmogroup.mmolib.api.MMOLineConfig;
public class MineBlockObjective extends Objective { public class MineBlockObjective extends Objective {
private final Material block; private final Material block;
private final int required; private final int required;
private final boolean playerPlaced;
public MineBlockObjective(ConfigurationSection section, MMOLineConfig config) { public MineBlockObjective(ConfigurationSection section, MMOLineConfig config) {
super(section); super(section);
@ -23,6 +24,7 @@ public class MineBlockObjective extends Objective {
block = Material.valueOf(config.getString("type").replace("-", "_").toUpperCase()); block = Material.valueOf(config.getString("type").replace("-", "_").toUpperCase());
required = config.getInt("amount"); required = config.getInt("amount");
playerPlaced = config.getBoolean("player-placed", false);
} }
@Override @Override
@ -39,6 +41,8 @@ public class MineBlockObjective extends Objective {
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void a(BlockBreakEvent event) { public void a(BlockBreakEvent event) {
if ((!playerPlaced) && event.getBlock().hasMetadata("player_placed"))
return;
if (event.getPlayer().equals(getQuestProgress().getPlayer().getPlayer()) && event.getBlock().getType() == block) { if (event.getPlayer().equals(getQuestProgress().getPlayer().getPlayer()) && event.getBlock().getType() == block) {
count++; count++;
getQuestProgress().getPlayer().getQuestData().updateBossBar(); getQuestProgress().getPlayer().getQuestData().updateBossBar();

View File

@ -39,6 +39,7 @@ public class GetItemObjective extends Objective {
@EventHandler @EventHandler
public void a(CitizenInteractEvent event) { public void a(CitizenInteractEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if(!getQuestProgress().getPlayer().isOnline()) return;
if (player.equals(getQuestProgress().getPlayer().getPlayer()) && event.getNPC().getId() == npcId && player.getInventory().getItemInMainHand() != null) { if (player.equals(getQuestProgress().getPlayer().getPlayer()) && event.getNPC().getId() == npcId && player.getInventory().getItemInMainHand() != null) {
ItemStack item = player.getInventory().getItemInMainHand(); ItemStack item = player.getInventory().getItemInMainHand();
if (item.getType() == material && item.getAmount() >= required) { if (item.getType() == material && item.getAmount() >= required) {

View File

@ -36,6 +36,12 @@ public class BlockListener implements Listener {
String savedData = event.getBlock().getBlockData().getAsString(); String savedData = event.getBlock().getBlockData().getAsString();
Block block = event.getBlock(); 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 * if custom mining enabled, check for item breaking restrictions
*/ */
@ -44,7 +50,13 @@ public class BlockListener implements Listener {
return; return;
BlockInfo info = MMOCore.plugin.mineManager.getInfo(block); 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); event.setCancelled(true);
return; return;
} }
@ -109,7 +121,7 @@ public class BlockListener implements Listener {
* enable block regen. * enable block regen.
*/ */
if (info.hasRegen()) 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) @EventHandler(priority = EventPriority.HIGH)

View File

@ -49,6 +49,8 @@ public class CustomBlockManager extends MMOManager {
*/ */
private final List<Function<Block, Optional<BlockType>>> blockTypes = new ArrayList<>(); private final List<Function<Block, Optional<BlockType>>> blockTypes = new ArrayList<>();
private boolean protect;
public CustomBlockManager() { public CustomBlockManager() {
registerBlockType(block -> MMOCoreUtils.isPlayerHead(block.getType()) ? Optional.of(new SkullBlockType(block)) : Optional.empty()); 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); map.put(regen.getBlock().generateKey(), regen);
} }
public boolean isBlockRegistered(Block block) {
return map.containsKey(findBlockType(block).generateKey());
}
public BlockInfo getInfo(Block block) { public BlockInfo getInfo(Block block) {
return map.getOrDefault(findBlockType(block).generateKey(), null); return map.getOrDefault(findBlockType(block).generateKey(), null);
} }
@ -75,17 +81,19 @@ public class CustomBlockManager extends MMOManager {
return new VanillaBlockType(block); return new VanillaBlockType(block);
} }
public void initialize(RegeneratingBlock info) { public void initialize(RegeneratingBlock info, boolean schedule) {
active.add(info); if(schedule) {
active.add(info);
Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> regen(info, false), info.getRegeneratingBlock().getRegenerationInfo().getTime());
}
if (info.getRegeneratingBlock().getRegenerationInfo().hasTemporaryBlock()) if (info.getRegeneratingBlock().getRegenerationInfo().hasTemporaryBlock())
info.getRegeneratingBlock().getRegenerationInfo().getTemporaryBlock().place(info.getLocation(), info); 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); info.getRegeneratingBlock().getBlock().place(info.getLocation(), info);
active.remove(info);
info.getLocation().getBlock().getState().update(); 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. * are reset and put back in place.
*/ */
public void resetRemainingBlocks() { 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) { public boolean isEnabled(Entity entity) {
@ -101,6 +120,8 @@ public class CustomBlockManager extends MMOManager {
} }
public boolean isEnabled(Entity entity, Location loc) { public boolean isEnabled(Entity entity, Location loc) {
if(customMineConditions.isEmpty()) return false;
ConditionInstance conditionEntity = new ConditionInstance(entity, loc); ConditionInstance conditionEntity = new ConditionInstance(entity, loc);
for (Condition condition : customMineConditions) for (Condition condition : customMineConditions)
if (!condition.isMet(conditionEntity)) if (!condition.isMet(conditionEntity))
@ -118,6 +139,15 @@ public class CustomBlockManager extends MMOManager {
} }
} }
public boolean shouldProtect() {
return protect;
}
public void reload(boolean protect) {
this.protect = protect;
reload();
}
@Override @Override
public void reload() { public void reload() {
customMineConditions.clear(); customMineConditions.clear();

View File

@ -29,9 +29,8 @@ public class MySQLDataProvider implements DataProvider {
private void initialize() { private void initialize() {
try { try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(config.getConnectionString(), config.getUser(), config.getPassword()); connection = DriverManager.getConnection(config.getConnectionString(), config.getUser(), config.getPassword());
} catch (ClassNotFoundException | SQLException exception) { } catch (SQLException exception) {
throw new IllegalArgumentException("Could not initialize MySQL support: " + exception.getMessage()); throw new IllegalArgumentException("Could not initialize MySQL support: " + exception.getMessage());
} }
} }

View File

@ -16,11 +16,20 @@ mysql:
flags: '?allowReconnect=true&useSSL=false' flags: '?allowReconnect=true&useSSL=false'
# The list of all conditions which must be met for the # The list of all conditions which must be met for the
# BLOCK REGEN and BLOCK RESTRICTIONS to apply. # BLOCK REGEN and BLOCK RESTRICTIONS to apply. Set to
# Set to 'custom-mine-conditions: []' for no condition. # 'custom-mine-conditions: []' to disable custom mining entirely.
custom-mine-conditions: custom-mine-conditions:
- 'world{name="world1,world2,world_nether,world_the_end"}' - 'world{name="world,world_nether,world_the_end"}'
- 'region{name="region1,region2,__global__"}' - '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 # Offset is the distance traveled on X and Y coordinates
# Height is the Y velocity coordinate. Lootsplosions # 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) # The decimal format for stats (not including stat formats in stats.yml)
decimal: "0.#" 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 # The amount of ticks before updating the info
ticks-to-update: 5 ticks-to-update: 5