mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-27 02:49:17 +00:00
fix mcmmo
This commit is contained in:
@@ -104,7 +104,7 @@ public class IntegrationManagerImpl implements IntegrationManager {
|
||||
}
|
||||
if (plugin.isHookedPluginEnabled("mcMMO")) {
|
||||
try {
|
||||
plugin.getItemManager().registerCustomItem("item", "mcmmo", new McMMOBuildableItem());
|
||||
plugin.getItemManager().registerItemLibrary(new McMMOTreasureImpl());
|
||||
} catch (ClassNotFoundException | NoSuchMethodException e) {
|
||||
LogUtils.warn("Failed to initialize mcMMO Treasure");
|
||||
}
|
||||
|
||||
@@ -17,36 +17,44 @@
|
||||
|
||||
package net.momirealms.customfishing.compatibility.item;
|
||||
|
||||
import net.momirealms.customfishing.api.mechanic.item.BuildableItem;
|
||||
import net.momirealms.customfishing.api.mechanic.item.ItemLibrary;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
public class McMMOBuildableItem implements BuildableItem {
|
||||
public class McMMOTreasureImpl implements ItemLibrary {
|
||||
|
||||
private final Method getMcMMOPlayerMethod;
|
||||
private final Method getFishingManagerMethod;
|
||||
private final Method getFishingTreasureMethod;
|
||||
private final Method getItemStackMethod;
|
||||
|
||||
public McMMOBuildableItem() throws ClassNotFoundException, NoSuchMethodException {
|
||||
public McMMOTreasureImpl() throws ClassNotFoundException, NoSuchMethodException {
|
||||
Class<?> userClass = Class.forName("com.gmail.nossr50.util.player.UserManager");
|
||||
getMcMMOPlayerMethod = userClass.getMethod("getPlayer", Player.class);
|
||||
Class<?> mcMMOPlayerClass = Class.forName("com.gmail.nossr50.datatypes.player.McMMOPlayer");
|
||||
getFishingManagerMethod = mcMMOPlayerClass.getMethod("getFishingManager");
|
||||
Class<?> fishingManagerClass = Class.forName("com.gmail.nossr50.skills.fishing.FishingManager");
|
||||
getFishingTreasureMethod = fishingManagerClass.getDeclaredMethod("getFishingTreasure");
|
||||
getFishingTreasureMethod.setAccessible(true);
|
||||
Class<?> treasureClass = Class.forName("com.gmail.nossr50.datatypes.treasure.Treasure");
|
||||
getItemStackMethod = treasureClass.getMethod("getDrop");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack build(Player player, Map<String, String> placeholders) {
|
||||
public String identification() {
|
||||
return "mcMMO";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack buildItem(Player player, String id) {
|
||||
if (!id.equals("treasure")) return new ItemStack(Material.AIR);
|
||||
ItemStack itemStack = null;
|
||||
while (itemStack == null) {
|
||||
int times = 0;
|
||||
while (itemStack == null && times < 5) {
|
||||
try {
|
||||
Object mcMMOPlayer = getMcMMOPlayerMethod.invoke(null, player);
|
||||
Object fishingManager = getFishingManagerMethod.invoke(mcMMOPlayer);
|
||||
@@ -56,13 +64,15 @@ public class McMMOBuildableItem implements BuildableItem {
|
||||
}
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
times++;
|
||||
}
|
||||
}
|
||||
return itemStack;
|
||||
return itemStack == null ? new ItemStack(Material.COD) : itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean persist() {
|
||||
return true;
|
||||
public String getItemID(ItemStack itemStack) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ import java.util.HashSet;
|
||||
public class BetonQuestHook {
|
||||
|
||||
public static void register() {
|
||||
BetonQuest.getInstance().registerObjectives("customfishing_id", IDObjective.class);
|
||||
BetonQuest.getInstance().registerObjectives("customfishing_loot", IDObjective.class);
|
||||
BetonQuest.getInstance().registerObjectives("customfishing_group", GroupObjective.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -554,7 +554,7 @@ public class FishingManagerImpl implements Listener, FishingManager {
|
||||
if (loot.getID().equals("vanilla")) {
|
||||
ItemStack itemStack = vanillaLootMap.remove(player.getUniqueId());
|
||||
if (itemStack != null) {
|
||||
fishingPreparation.insertArg("{loot}", "<lang:item.minecraft." + itemStack.getType().toString().toLowerCase() + ">");
|
||||
fishingPreparation.insertArg("{nick}", "<lang:item.minecraft." + itemStack.getType().toString().toLowerCase() + ">");
|
||||
for (int i = 0; i < amount; i++) {
|
||||
plugin.getItemManager().dropItem(hook.getLocation(), player.getLocation(), itemStack.clone());
|
||||
doSuccessActions(loot, effect, fishingPreparation, player);
|
||||
|
||||
@@ -38,9 +38,9 @@ mechanics:
|
||||
- '<green>GG!</green>'
|
||||
- '<green>Good Job!</green>'
|
||||
subtitles:
|
||||
- 'You caught a {loot}'
|
||||
- 'You caught a {nick}'
|
||||
- 'Whoa! Nice catch!'
|
||||
- 'Oh {loot} here we go!'
|
||||
- 'Oh {nick} here we go!'
|
||||
- 'Let''s see what it is!'
|
||||
fade-in: 20
|
||||
stay: 30
|
||||
|
||||
@@ -27,7 +27,6 @@ softdepend:
|
||||
- BattlePass
|
||||
- ClueScrolls
|
||||
- BetonQuest
|
||||
- Quests
|
||||
|
||||
- AdvancedEnchantments
|
||||
- EcoEnchants
|
||||
|
||||
Reference in New Issue
Block a user