-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/me/cjcrafter/armormechanics/lib/MythicMobsArmorDrop.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/me/cjcrafter/armormechanics/listeners/MythicMobsListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | ||
} | ||
} | ||
} |