Skip to content

Commit

Permalink
#2 Add Mythic Mobs support
Browse files Browse the repository at this point in the history
  • Loading branch information
CJCrafter committed Jul 21, 2022
1 parent 674d252 commit 3146806
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 1 deletion.
7 changes: 7 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,19 @@ repositories {
password = "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" // this is a public token created in CJCrafter's name which will never expire
}
}

maven {
name = "lumine-repo"
url = uri("http://mvn.lumine.io/repository/maven-public/")
isAllowInsecureProtocol = true
}
}

dependencies {
compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT")
compileOnly("me.deecaad:mechanicscore:1.3.3-BETA")
compileOnly("me.deecaad:weaponmechanics:1.8.3-BETA")
implementation("io.lumine:Mythic-Dist:5.0.1-SNAPSHOT")
implementation("org.bstats:bstats-bukkit:3.0.0")
}

Expand Down
13 changes: 12 additions & 1 deletion src/main/java/me/cjcrafter/armormechanics/ArmorMechanics.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import me.deecaad.core.file.SerializerException;
import me.deecaad.core.utils.Debugger;
import me.deecaad.core.utils.FileUtil;
import me.deecaad.core.utils.LogLevel;
import me.deecaad.core.utils.ReflectionUtil;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie;
Expand All @@ -24,7 +25,7 @@ public class ArmorMechanics extends JavaPlugin {

public static ArmorMechanics INSTANCE;

Debugger debug;
public Debugger debug;
private Metrics metrics;

public final Map<String, BonusEffect> effects = new HashMap<>();
Expand Down Expand Up @@ -62,6 +63,16 @@ public void onEnable() {
pm.registerEvents(new PreventRemoveListener(), this);
pm.registerEvents(new WeaponMechanicsDamageListener(), this);

// Try to hook into MythicMobs, an error will be thrown if the user is
// using any version below v5.0.0
if (pm.getPlugin("MythicMobs") != null) {
try {
pm.registerEvents(new MythicMobsListener(), this);
} catch (Throwable e) {
debug.log(LogLevel.ERROR, "Could not hook into MythicMobs", e);
}
}

Command.register();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package me.cjcrafter.armormechanics.lib;

import io.lumine.mythic.api.adapters.AbstractItemStack;
import io.lumine.mythic.api.config.MythicLineConfig;
import io.lumine.mythic.api.drops.DropMetadata;
import io.lumine.mythic.api.drops.IItemDrop;
import io.lumine.mythic.bukkit.adapters.BukkitItemStack;
import me.cjcrafter.armormechanics.ArmorMechanics;
import me.deecaad.core.utils.StringUtil;
import org.bukkit.inventory.ItemStack;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Set;

public class MythicMobsArmorDrop implements IItemDrop {

private final String armorTitle;

public MythicMobsArmorDrop(MythicLineConfig config, String argument) {
String title = config.getString(new String[]{ "armorTitle", "armor" }, "", "");

// Since we want to ignore spelling/capitalization errors, we should
// make sure the given 'title' matches to an actual armor-title.
List<String> startsWith = new ArrayList<>();
Set<String> options = ArmorMechanics.INSTANCE.armors.keySet();
for (String temp : options) {
if (temp.toLowerCase(Locale.ROOT).startsWith(title.toLowerCase(Locale.ROOT)))
startsWith.add(title);
}

armorTitle = StringUtil.didYouMean(title, startsWith.isEmpty() ? options : startsWith);
}

@Override
public AbstractItemStack getDrop(DropMetadata dropMetadata, double v) {
ItemStack item = ArmorMechanics.INSTANCE.armors.get(armorTitle);

// Just in case MythicMobs edits this item, we want to use a clone
// to avoid possible modification.
return new BukkitItemStack(item.clone());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package me.cjcrafter.armormechanics.listeners;

import io.lumine.mythic.bukkit.events.MythicDropLoadEvent;
import me.cjcrafter.armormechanics.ArmorMechanics;
import me.cjcrafter.armormechanics.lib.MythicMobsArmorDrop;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

public class MythicMobsListener implements Listener {

public MythicMobsListener() {
ArmorMechanics.INSTANCE.debug.info("Hooking into MythicMobs");
}

@EventHandler
public void onMythicDropLoad(MythicDropLoadEvent event) {
if (event.getDropName().equalsIgnoreCase("armorMechanicsArmor")) {
event.register(new MythicMobsArmorDrop(event.getConfig(), event.getArgument()));
}
}
}

0 comments on commit 3146806

Please # to comment.