mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-27 00:45:40 +01:00
Experimental: MMOItems Custom Block Regen Support, The Update
This commit is contained in:
parent
bbb0b08c0a
commit
cc68187d69
Binary file not shown.
@ -136,6 +136,7 @@ public class MMOCore extends JavaPlugin {
|
||||
public final MMOLoadManager loadManager = new MMOLoadManager();
|
||||
public RPGUtilHandler rpgUtilHandler = new DefaultRPGUtilHandler();
|
||||
|
||||
private boolean miLoaded;
|
||||
|
||||
public void onLoad() {
|
||||
plugin = this;
|
||||
@ -354,6 +355,8 @@ public class MMOCore extends JavaPlugin {
|
||||
}
|
||||
}.runTaskTimerAsynchronously(MMOCore.plugin, autosave, autosave);
|
||||
}
|
||||
|
||||
miLoaded = Bukkit.getPluginManager().isPluginEnabled("MMOItems");
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
@ -431,4 +434,8 @@ public class MMOCore extends JavaPlugin {
|
||||
public boolean hasEconomy() {
|
||||
return economy != null && economy.isValid();
|
||||
}
|
||||
|
||||
public boolean isMILoaded() {
|
||||
return miLoaded;
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,8 @@ import net.Indyuce.mmocore.api.event.CustomBlockMineEvent;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.manager.CustomBlockManager.BlockInfo;
|
||||
import net.Indyuce.mmocore.manager.RestrictionManager.BlockPermissions;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.CustomBlock;
|
||||
|
||||
public class BlockListener implements Listener {
|
||||
private static final BlockFace[] order = { BlockFace.UP, BlockFace.DOWN, BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH };
|
||||
@ -62,7 +64,7 @@ public class BlockListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!perms.canMine(block.getType())) {
|
||||
if (!perms.canMine(getBlockName(block))) {
|
||||
MMOCore.plugin.configManager.getSimpleMessage("cannot-break").send(player);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@ -105,6 +107,17 @@ public class BlockListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private String getBlockName(Block block) {
|
||||
if(MMOCore.plugin.isMILoaded())
|
||||
if(MMOItems.plugin.getCustomBlocks().isMushroomBlock(block.getType())) {
|
||||
CustomBlock cblock = CustomBlock.getFromData(block.getBlockData());
|
||||
if(cblock != null)
|
||||
return "MICUSTOM_" + cblock.getId();
|
||||
}
|
||||
|
||||
return block.getType().toString();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void b(BlockPlaceEvent event) {
|
||||
event.getBlock().setMetadata("player_placed", new FixedMetadataValue(MMOCore.plugin, true));
|
||||
|
@ -1,7 +1,6 @@
|
||||
|
||||
package net.Indyuce.mmocore.listener;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -15,6 +14,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import com.codingforcookies.armorequip.ArmorEquipEvent;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.event.PlayerAttackEvent;
|
||||
import net.Indyuce.mmocore.api.event.PlayerCombatEvent;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
@ -102,7 +102,7 @@ public class PlayerListener implements Listener {
|
||||
double damage = event.getDamage();
|
||||
double d = 1, s = 1;
|
||||
|
||||
if(Bukkit.getPluginManager().isPluginEnabled("MMOItems"))
|
||||
if(MMOCore.plugin.isMILoaded())
|
||||
for (DamageType type : event.getDamageInfo().getTypes())
|
||||
s += (net.Indyuce.mmoitems.api.player.PlayerData.get(event.getPlayer()).getStats()
|
||||
.getStat(AttackResult.DamageType.valueOf(type.name()).getStat()) / 100);
|
||||
|
@ -28,6 +28,8 @@ import net.Indyuce.mmocore.api.load.MMOLoadException;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.ExperienceTrigger;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
|
||||
import net.Indyuce.mmocore.version.VersionMaterial;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.CustomBlock;
|
||||
|
||||
public class CustomBlockManager extends MMOManager {
|
||||
private final Map<String, BlockInfo> map = new HashMap<>();
|
||||
@ -40,7 +42,7 @@ public class CustomBlockManager extends MMOManager {
|
||||
for (String key : config.getKeys(false))
|
||||
try {
|
||||
BlockInfo info = new BlockInfo(config.getConfigurationSection(key));
|
||||
register(info.getHeadValue().isEmpty() ? info.getBlock().name() : info.getHeadValue(), info);
|
||||
register(info.getHeadValue().isEmpty() ? info.getCustomBlockID() > 0 ? "mi-custom-" + info.getCustomBlockID() : info.getBlock().name() : info.getHeadValue(), info);
|
||||
} catch (IllegalArgumentException exception) {
|
||||
MMOCore.log(Level.WARNING, "Could not load custom block '" + key + "': " + exception.getMessage());
|
||||
}
|
||||
@ -55,6 +57,12 @@ public class CustomBlockManager extends MMOManager {
|
||||
String skullValue = MMOCore.plugin.nms.getSkullValue(block);
|
||||
return map.getOrDefault(skullValue, map.getOrDefault(block.getType().name(), null));
|
||||
}
|
||||
if(MMOCore.plugin.isMILoaded())
|
||||
if(MMOItems.plugin.getCustomBlocks().isMushroomBlock(block.getType())) {
|
||||
CustomBlock cblock = CustomBlock.getFromData(block.getBlockData());
|
||||
if(block != null)
|
||||
return map.getOrDefault("mi-custom-" + cblock.getId(), map.getOrDefault(block.getType().name(), null));
|
||||
}
|
||||
|
||||
return map.getOrDefault(block.getType().name(), null);
|
||||
}
|
||||
@ -70,7 +78,12 @@ public class CustomBlockManager extends MMOManager {
|
||||
public void initialize(RegenInfo info) {
|
||||
active.add(info);
|
||||
|
||||
info.getLocation().getBlock().setType(info.getRegen().getTemporaryBlock());
|
||||
if(MMOCore.plugin.isMILoaded() && info.getRegen().getCustomRegenBlockID() != 0) {
|
||||
CustomBlock block = MMOItems.plugin.getCustomBlocks().getBlock(info.getRegen().getCustomRegenBlockID());
|
||||
info.getLocation().getBlock().setType(block.getType());
|
||||
info.getLocation().getBlock().setBlockData(block.getBlockData());
|
||||
}
|
||||
else info.getLocation().getBlock().setType(info.getRegen().getTemporaryBlock());
|
||||
if(isPlayerSkull(info.getLocation().getBlock().getType())) {
|
||||
if(isPlayerSkull(info.getRegen().getBlock())) info.getLocation().getBlock().setBlockData(info.getBlockData());
|
||||
MMOCore.plugin.nms.setSkullValue(info.getLocation().getBlock(), info.getRegen().getRegenHeadValue());
|
||||
@ -116,23 +129,27 @@ public class CustomBlockManager extends MMOManager {
|
||||
|
||||
private final List<Trigger> triggers = new ArrayList<>();
|
||||
private final ExperienceTrigger experience;
|
||||
private final int customBlockId;
|
||||
|
||||
/*
|
||||
* options for block regen.
|
||||
*/
|
||||
private Material temporary;
|
||||
private int regenTime = -1;
|
||||
private int regenCustomBlockId;
|
||||
private String regenHeadValue;
|
||||
|
||||
public BlockInfo(ConfigurationSection config) {
|
||||
Validate.notNull(config, "Could not load config");
|
||||
block = Material.valueOf(config.getString("material", "BOOKSHELF").toUpperCase().replace("-", "_").replace(" ", "_"));
|
||||
customBlockId = config.getInt("mi-custom-block", 0);
|
||||
headValue = config.getString("head-value", "");
|
||||
table = config.contains("drop-table") ? MMOCore.plugin.dropTableManager.loadDropTable(config.get("drop-table")) : null;
|
||||
vanillaDrops = config.getBoolean("vanilla-drops", true);
|
||||
|
||||
if (config.contains("regen")) {
|
||||
temporary = Material.valueOf(config.getString("regen.temp-block", "BOOKSHELF").toUpperCase().replace("-", "_").replace(" ", "_"));
|
||||
regenCustomBlockId = config.getInt("regen.mi-custom-block", 0);
|
||||
regenHeadValue = config.getString("regen.head-value", "");
|
||||
|
||||
regenTime = config.getInt("regen.time");
|
||||
@ -198,6 +215,14 @@ public class CustomBlockManager extends MMOManager {
|
||||
return new RegenInfo(data, loc, this);
|
||||
}
|
||||
|
||||
public int getCustomBlockID() {
|
||||
return customBlockId;
|
||||
}
|
||||
|
||||
public int getCustomRegenBlockID() {
|
||||
return regenCustomBlockId;
|
||||
}
|
||||
|
||||
public boolean hasExperience() {
|
||||
return experience != null;
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
|
||||
public class RestrictionManager {
|
||||
private Set<Material> breakBlackList = new HashSet<>();
|
||||
private Set<String> breakBlackList = new HashSet<>();
|
||||
private Map<Material, BlockPermissions> map = new HashMap<>();
|
||||
|
||||
public RestrictionManager(FileConfiguration config) {
|
||||
@ -41,8 +41,8 @@ public class RestrictionManager {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isBlackListed(Material material) {
|
||||
return breakBlackList.contains(material);
|
||||
public boolean isBlackListed(String s) {
|
||||
return breakBlackList.contains(s);
|
||||
}
|
||||
|
||||
public BlockPermissions getPermissions(Material tool) {
|
||||
@ -50,7 +50,7 @@ public class RestrictionManager {
|
||||
}
|
||||
|
||||
public class BlockPermissions {
|
||||
private final Set<Material> canMine = new HashSet<>();
|
||||
private final Set<String> canMine = new HashSet<>();
|
||||
private final Material tool;
|
||||
|
||||
private BlockPermissions parent;
|
||||
@ -80,7 +80,7 @@ public class RestrictionManager {
|
||||
}
|
||||
|
||||
for (String key : loaded.getStringList("can-mine"))
|
||||
canMine.add(Material.valueOf(key.toUpperCase().replace("-", "_")));
|
||||
canMine.add(key.toUpperCase().replace("-", "_"));
|
||||
|
||||
loaded = null;
|
||||
}
|
||||
@ -89,17 +89,17 @@ public class RestrictionManager {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public void addPermission(Material material) {
|
||||
canMine.add(material);
|
||||
public void addPermission(String s) {
|
||||
canMine.add(s);
|
||||
}
|
||||
|
||||
// recursive function to check for parent permissions
|
||||
public boolean canMine(Material material) {
|
||||
public boolean canMine(String material) {
|
||||
return canMine.contains(material) || (parent != null && parent.canMine(material));
|
||||
}
|
||||
|
||||
public Set<Material> getMinable() {
|
||||
Set<Material> total = new HashSet<>(canMine);
|
||||
public Set<String> getMinable() {
|
||||
Set<String> total = new HashSet<>(canMine);
|
||||
if (parent != null)
|
||||
total.addAll(parent.getMinable());
|
||||
return total;
|
||||
|
Loading…
Reference in New Issue
Block a user