mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-12-28 05:37:44 +01:00
Merge branch 'master' of https://git.lumine.io/mythiccraft/mmocore
This commit is contained in:
commit
844a7ca675
2
pom.xml
2
pom.xml
@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>net.Indyuce</groupId>
|
||||
<artifactId>MMOCore</artifactId>
|
||||
<version>1.4.5</version>
|
||||
<version>1.4.6</version>
|
||||
<name>MMOCore</name>
|
||||
<description>Offer your players a brand new RPG experience.</description>
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
private ActionBarConfig config;
|
||||
private DecimalFormat digit;
|
||||
|
||||
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
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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__");
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ public class PlayerClass extends PostLoadObject {
|
||||
|
||||
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"));
|
||||
|
||||
if (config.contains("display.texture") && icon.getType() == VersionMaterial.PLAYER_HEAD.toMaterial())
|
||||
|
@ -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();
|
||||
|
@ -39,6 +39,7 @@ public class GetItemObjective extends Objective {
|
||||
@EventHandler
|
||||
public void a(CitizenInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if(!getQuestProgress().getPlayer().isOnline()) return;
|
||||
if (player.equals(getQuestProgress().getPlayer().getPlayer()) && event.getNPC().getId() == npcId && player.getInventory().getItemInMainHand() != null) {
|
||||
ItemStack item = player.getInventory().getItemInMainHand();
|
||||
if (item.getType() == material && item.getAmount() >= required) {
|
||||
|
@ -36,6 +36,12 @@ 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
|
||||
*/
|
||||
@ -44,7 +50,13 @@ public class BlockListener implements Listener {
|
||||
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;
|
||||
}
|
||||
@ -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)
|
||||
|
@ -49,6 +49,8 @@ public class CustomBlockManager extends MMOManager {
|
||||
*/
|
||||
private final List<Function<Block, Optional<BlockType>>> 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) {
|
||||
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))
|
||||
@ -118,6 +139,15 @@ public class CustomBlockManager extends MMOManager {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean shouldProtect() {
|
||||
return protect;
|
||||
}
|
||||
|
||||
public void reload(boolean protect) {
|
||||
this.protect = protect;
|
||||
reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
customMineConditions.clear();
|
||||
|
@ -29,9 +29,8 @@ public class MySQLDataProvider implements DataProvider {
|
||||
|
||||
private void initialize() {
|
||||
try {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user