Experimental: MMOItems Custom Block Regen Support, The Update

This commit is contained in:
Aria 2019-12-11 05:09:25 +01:00
parent bbb0b08c0a
commit cc68187d69
6 changed files with 61 additions and 16 deletions

Binary file not shown.

View File

@ -136,6 +136,7 @@ public class MMOCore extends JavaPlugin {
public final MMOLoadManager loadManager = new MMOLoadManager(); public final MMOLoadManager loadManager = new MMOLoadManager();
public RPGUtilHandler rpgUtilHandler = new DefaultRPGUtilHandler(); public RPGUtilHandler rpgUtilHandler = new DefaultRPGUtilHandler();
private boolean miLoaded;
public void onLoad() { public void onLoad() {
plugin = this; plugin = this;
@ -354,6 +355,8 @@ public class MMOCore extends JavaPlugin {
} }
}.runTaskTimerAsynchronously(MMOCore.plugin, autosave, autosave); }.runTaskTimerAsynchronously(MMOCore.plugin, autosave, autosave);
} }
miLoaded = Bukkit.getPluginManager().isPluginEnabled("MMOItems");
} }
public void onDisable() { public void onDisable() {
@ -431,4 +434,8 @@ public class MMOCore extends JavaPlugin {
public boolean hasEconomy() { public boolean hasEconomy() {
return economy != null && economy.isValid(); return economy != null && economy.isValid();
} }
public boolean isMILoaded() {
return miLoaded;
}
} }

View File

@ -20,6 +20,8 @@ import net.Indyuce.mmocore.api.event.CustomBlockMineEvent;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.manager.CustomBlockManager.BlockInfo; import net.Indyuce.mmocore.manager.CustomBlockManager.BlockInfo;
import net.Indyuce.mmocore.manager.RestrictionManager.BlockPermissions; import net.Indyuce.mmocore.manager.RestrictionManager.BlockPermissions;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.CustomBlock;
public class BlockListener implements Listener { public class BlockListener implements Listener {
private static final BlockFace[] order = { BlockFace.UP, BlockFace.DOWN, BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH }; 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; return;
} }
if (!perms.canMine(block.getType())) { if (!perms.canMine(getBlockName(block))) {
MMOCore.plugin.configManager.getSimpleMessage("cannot-break").send(player); MMOCore.plugin.configManager.getSimpleMessage("cannot-break").send(player);
event.setCancelled(true); event.setCancelled(true);
return; 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) @EventHandler(priority = EventPriority.HIGH)
public void b(BlockPlaceEvent event) { public void b(BlockPlaceEvent event) {
event.getBlock().setMetadata("player_placed", new FixedMetadataValue(MMOCore.plugin, true)); event.getBlock().setMetadata("player_placed", new FixedMetadataValue(MMOCore.plugin, true));

View File

@ -1,7 +1,6 @@
package net.Indyuce.mmocore.listener; package net.Indyuce.mmocore.listener;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile; import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -15,6 +14,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
import com.codingforcookies.armorequip.ArmorEquipEvent; import com.codingforcookies.armorequip.ArmorEquipEvent;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.event.PlayerAttackEvent; import net.Indyuce.mmocore.api.event.PlayerAttackEvent;
import net.Indyuce.mmocore.api.event.PlayerCombatEvent; import net.Indyuce.mmocore.api.event.PlayerCombatEvent;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
@ -102,7 +102,7 @@ public class PlayerListener implements Listener {
double damage = event.getDamage(); double damage = event.getDamage();
double d = 1, s = 1; double d = 1, s = 1;
if(Bukkit.getPluginManager().isPluginEnabled("MMOItems")) if(MMOCore.plugin.isMILoaded())
for (DamageType type : event.getDamageInfo().getTypes()) for (DamageType type : event.getDamageInfo().getTypes())
s += (net.Indyuce.mmoitems.api.player.PlayerData.get(event.getPlayer()).getStats() s += (net.Indyuce.mmoitems.api.player.PlayerData.get(event.getPlayer()).getStats()
.getStat(AttackResult.DamageType.valueOf(type.name()).getStat()) / 100); .getStat(AttackResult.DamageType.valueOf(type.name()).getStat()) / 100);

View File

@ -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.ExperienceTrigger;
import net.Indyuce.mmocore.api.quest.trigger.Trigger; import net.Indyuce.mmocore.api.quest.trigger.Trigger;
import net.Indyuce.mmocore.version.VersionMaterial; import net.Indyuce.mmocore.version.VersionMaterial;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.CustomBlock;
public class CustomBlockManager extends MMOManager { public class CustomBlockManager extends MMOManager {
private final Map<String, BlockInfo> map = new HashMap<>(); private final Map<String, BlockInfo> map = new HashMap<>();
@ -40,7 +42,7 @@ public class CustomBlockManager extends MMOManager {
for (String key : config.getKeys(false)) for (String key : config.getKeys(false))
try { try {
BlockInfo info = new BlockInfo(config.getConfigurationSection(key)); 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) { } catch (IllegalArgumentException exception) {
MMOCore.log(Level.WARNING, "Could not load custom block '" + key + "': " + exception.getMessage()); MMOCore.log(Level.WARNING, "Could not load custom block '" + key + "': " + exception.getMessage());
} }
@ -55,7 +57,13 @@ public class CustomBlockManager extends MMOManager {
String skullValue = MMOCore.plugin.nms.getSkullValue(block); String skullValue = MMOCore.plugin.nms.getSkullValue(block);
return map.getOrDefault(skullValue, map.getOrDefault(block.getType().name(), null)); 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); return map.getOrDefault(block.getType().name(), null);
} }
@ -70,7 +78,12 @@ public class CustomBlockManager extends MMOManager {
public void initialize(RegenInfo info) { public void initialize(RegenInfo info) {
active.add(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.getLocation().getBlock().getType())) {
if(isPlayerSkull(info.getRegen().getBlock())) info.getLocation().getBlock().setBlockData(info.getBlockData()); if(isPlayerSkull(info.getRegen().getBlock())) info.getLocation().getBlock().setBlockData(info.getBlockData());
MMOCore.plugin.nms.setSkullValue(info.getLocation().getBlock(), info.getRegen().getRegenHeadValue()); 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 List<Trigger> triggers = new ArrayList<>();
private final ExperienceTrigger experience; private final ExperienceTrigger experience;
private final int customBlockId;
/* /*
* options for block regen. * options for block regen.
*/ */
private Material temporary; private Material temporary;
private int regenTime = -1; private int regenTime = -1;
private int regenCustomBlockId;
private String regenHeadValue; private String regenHeadValue;
public BlockInfo(ConfigurationSection config) { public BlockInfo(ConfigurationSection config) {
Validate.notNull(config, "Could not load config"); Validate.notNull(config, "Could not load config");
block = Material.valueOf(config.getString("material", "BOOKSHELF").toUpperCase().replace("-", "_").replace(" ", "_")); block = Material.valueOf(config.getString("material", "BOOKSHELF").toUpperCase().replace("-", "_").replace(" ", "_"));
customBlockId = config.getInt("mi-custom-block", 0);
headValue = config.getString("head-value", ""); headValue = config.getString("head-value", "");
table = config.contains("drop-table") ? MMOCore.plugin.dropTableManager.loadDropTable(config.get("drop-table")) : null; table = config.contains("drop-table") ? MMOCore.plugin.dropTableManager.loadDropTable(config.get("drop-table")) : null;
vanillaDrops = config.getBoolean("vanilla-drops", true); vanillaDrops = config.getBoolean("vanilla-drops", true);
if (config.contains("regen")) { if (config.contains("regen")) {
temporary = Material.valueOf(config.getString("regen.temp-block", "BOOKSHELF").toUpperCase().replace("-", "_").replace(" ", "_")); 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", ""); regenHeadValue = config.getString("regen.head-value", "");
regenTime = config.getInt("regen.time"); regenTime = config.getInt("regen.time");
@ -197,6 +214,14 @@ public class CustomBlockManager extends MMOManager {
public RegenInfo generateRegenInfo(BlockData data, Location loc) { public RegenInfo generateRegenInfo(BlockData data, Location loc) {
return new RegenInfo(data, loc, this); return new RegenInfo(data, loc, this);
} }
public int getCustomBlockID() {
return customBlockId;
}
public int getCustomRegenBlockID() {
return regenCustomBlockId;
}
public boolean hasExperience() { public boolean hasExperience() {
return experience != null; return experience != null;

View File

@ -14,7 +14,7 @@ import org.bukkit.configuration.file.FileConfiguration;
import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.MMOCore;
public class RestrictionManager { public class RestrictionManager {
private Set<Material> breakBlackList = new HashSet<>(); private Set<String> breakBlackList = new HashSet<>();
private Map<Material, BlockPermissions> map = new HashMap<>(); private Map<Material, BlockPermissions> map = new HashMap<>();
public RestrictionManager(FileConfiguration config) { public RestrictionManager(FileConfiguration config) {
@ -41,8 +41,8 @@ public class RestrictionManager {
} }
} }
public boolean isBlackListed(Material material) { public boolean isBlackListed(String s) {
return breakBlackList.contains(material); return breakBlackList.contains(s);
} }
public BlockPermissions getPermissions(Material tool) { public BlockPermissions getPermissions(Material tool) {
@ -50,7 +50,7 @@ public class RestrictionManager {
} }
public class BlockPermissions { public class BlockPermissions {
private final Set<Material> canMine = new HashSet<>(); private final Set<String> canMine = new HashSet<>();
private final Material tool; private final Material tool;
private BlockPermissions parent; private BlockPermissions parent;
@ -80,7 +80,7 @@ public class RestrictionManager {
} }
for (String key : loaded.getStringList("can-mine")) for (String key : loaded.getStringList("can-mine"))
canMine.add(Material.valueOf(key.toUpperCase().replace("-", "_"))); canMine.add(key.toUpperCase().replace("-", "_"));
loaded = null; loaded = null;
} }
@ -89,17 +89,17 @@ public class RestrictionManager {
this.parent = parent; this.parent = parent;
} }
public void addPermission(Material material) { public void addPermission(String s) {
canMine.add(material); canMine.add(s);
} }
// recursive function to check for parent permissions // 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)); return canMine.contains(material) || (parent != null && parent.canMine(material));
} }
public Set<Material> getMinable() { public Set<String> getMinable() {
Set<Material> total = new HashSet<>(canMine); Set<String> total = new HashSet<>(canMine);
if (parent != null) if (parent != null)
total.addAll(parent.getMinable()); total.addAll(parent.getMinable());
return total; return total;