mirror of
https://github.com/tanyaofei/minecraft-fakeplayer.git
synced 2025-07-13 12:52:23 +08:00
Supports OpenInv as invsee implementation
This commit is contained in:
parent
640ef370b3
commit
a1d4315486
@ -77,6 +77,14 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.jikoo</groupId>
|
||||
<artifactId>OpenInv</artifactId>
|
||||
<version>5.1.1</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/../lib/OpenInv.jar</systemPath>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -8,13 +8,18 @@ import io.github.hello09x.fakeplayer.core.manager.FakeplayerList;
|
||||
import io.github.hello09x.fakeplayer.core.manager.FakeplayerManager;
|
||||
import io.github.hello09x.fakeplayer.core.manager.invsee.DefaultInvseeManagerImpl;
|
||||
import io.github.hello09x.fakeplayer.core.manager.invsee.InvseeManager;
|
||||
import io.github.hello09x.fakeplayer.core.manager.invsee.OpenInvInvseeManagerImpl;
|
||||
import io.github.hello09x.fakeplayer.core.util.ClassUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class FakeplayerModule extends AbstractModule {
|
||||
|
||||
private final static Logger log = Main.getInstance().getLogger();
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
super.bind(Plugin.class).toInstance(Main.getInstance());
|
||||
@ -23,6 +28,12 @@ public class FakeplayerModule extends AbstractModule {
|
||||
@Provides
|
||||
@Singleton
|
||||
public InvseeManager invseeManager(FakeplayerManager fakeplayerManager, FakeplayerList fakeplayerList) {
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("OpenInv") && ClassUtils.isClassExists("com.lishid.openinv.IOpenInv")) {
|
||||
log.info("Using OpenInv as invsee implementation");
|
||||
return new OpenInvInvseeManagerImpl(fakeplayerManager, fakeplayerList);
|
||||
}
|
||||
|
||||
log.info("Using default invsee implementation");
|
||||
return new DefaultInvseeManagerImpl(fakeplayerManager, fakeplayerList);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,38 @@
|
||||
package io.github.hello09x.fakeplayer.core.manager.invsee;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.lishid.openinv.IOpenInv;
|
||||
import io.github.hello09x.fakeplayer.core.Main;
|
||||
import io.github.hello09x.fakeplayer.core.manager.FakeplayerList;
|
||||
import io.github.hello09x.fakeplayer.core.manager.FakeplayerManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author tanyaofei
|
||||
* @since 2024/8/12
|
||||
**/
|
||||
public class OpenInvInvseeManagerImpl extends AbstractInvseeManager {
|
||||
|
||||
private final static Logger log = Main.getInstance().getLogger();
|
||||
private final IOpenInv openInv;
|
||||
|
||||
public OpenInvInvseeManagerImpl(FakeplayerManager manager, FakeplayerList fakeplayerList) {
|
||||
super(manager, fakeplayerList);
|
||||
this.openInv = (IOpenInv) Bukkit.getPluginManager().getPlugin("OpenInv");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InventoryView openInventory(@NotNull Player viewer, @NotNull Player whom) {
|
||||
try {
|
||||
return openInv.openInventory(viewer, openInv.getSpecialInventory(whom, true));
|
||||
} catch (InstantiationException e) {
|
||||
log.warning("Failed to %s's open inventory for %s\n%s".formatted(whom.getName(), viewer.getName(), Throwables.getStackTraceAsString(e)));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package io.github.hello09x.fakeplayer.core.util;
|
||||
|
||||
/**
|
||||
* @author tanyaofei
|
||||
* @since 2024/8/12
|
||||
**/
|
||||
public class ClassUtils {
|
||||
|
||||
public static boolean isClassExists(String className) {
|
||||
try {
|
||||
Class.forName(className);
|
||||
return true;
|
||||
} catch (ClassNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -7,6 +7,9 @@ website: 'https://github.com/tanyaofei/minecraft-fakeplayer'
|
||||
depend:
|
||||
- CommandAPI
|
||||
|
||||
softdepend:
|
||||
- OpenInv
|
||||
|
||||
permissions:
|
||||
fakeplayer.command.spawn:
|
||||
description: 'Allow player to run /fp spawn'
|
||||
|
Loading…
Reference in New Issue
Block a user