Item Send function
This commit is contained in:
+39
@@ -0,0 +1,39 @@
|
|||||||
|
target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
!**/src/main/**/target/
|
||||||
|
!**/src/test/**/target/
|
||||||
|
.kotlin
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea/modules.xml
|
||||||
|
.idea/jarRepositories.xml
|
||||||
|
.idea/compiler.xml
|
||||||
|
.idea/libraries/
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
### Eclipse ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
build/
|
||||||
|
!**/src/main/**/build/
|
||||||
|
!**/src/test/**/build/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
### Mac OS ###
|
||||||
|
.DS_Store
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>de.oryfox.plugins</groupId>
|
||||||
|
<artifactId>inventory-tools</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>25</maven.compiler.source>
|
||||||
|
<maven.compiler.target>25</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>papermc</id>
|
||||||
|
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.papermc.paper</groupId>
|
||||||
|
<artifactId>paper-api</artifactId>
|
||||||
|
<version>1.21.11-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>dev.triumphteam</groupId>
|
||||||
|
<artifactId>triumph-gui</artifactId>
|
||||||
|
<version>3.1.13</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.5.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
<finalName>${project.artifactId}</finalName>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package de.oryfox.plugins;
|
||||||
|
|
||||||
|
import de.oryfox.plugins.event.SendItemCommandEvent;
|
||||||
|
import io.papermc.paper.command.brigadier.Commands;
|
||||||
|
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
public class InventoryTools extends JavaPlugin {
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
super.onEnable();
|
||||||
|
this.getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, commands -> {
|
||||||
|
commands.registrar().register(
|
||||||
|
Commands
|
||||||
|
.literal("sendItem")
|
||||||
|
.executes(SendItemCommandEvent::openPlayerSelectionMenu)
|
||||||
|
.build());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
package de.oryfox.plugins.event;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import de.oryfox.plugins.helpers.HeadItem;
|
||||||
|
import dev.triumphteam.gui.builder.item.ItemBuilder;
|
||||||
|
import dev.triumphteam.gui.guis.Gui;
|
||||||
|
import dev.triumphteam.gui.guis.GuiItem;
|
||||||
|
import dev.triumphteam.gui.guis.ScrollingGui;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class SendItemCommandEvent {
|
||||||
|
public static int openPlayerSelectionMenu(CommandContext<CommandSourceStack> ctx) {
|
||||||
|
if (ctx.getSource().getExecutor() == null) {
|
||||||
|
throw new IllegalStateException("Command can only be executed by a player");
|
||||||
|
}
|
||||||
|
if (Bukkit.getOnlinePlayers().size() <= 1) {
|
||||||
|
ctx.getSource().getSender().sendMessage(Component.text("No other players online"));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (ctx.getSource().getExecutor() instanceof Player player) {
|
||||||
|
ScrollingGui gui = Gui.scrolling()
|
||||||
|
.title(Component.text("Select recipient!"))
|
||||||
|
.rows(3)
|
||||||
|
.pageSize(18)
|
||||||
|
.create();
|
||||||
|
|
||||||
|
Bukkit.getOnlinePlayers()
|
||||||
|
.stream()
|
||||||
|
.filter(p -> !p.getUniqueId().equals(player.getUniqueId()))
|
||||||
|
.forEach(p -> gui.addItem(new HeadItem(p.getPlayerProfile(), event -> {
|
||||||
|
event.getClickedInventory().close();
|
||||||
|
openItemSelectionMenu(player, p);
|
||||||
|
})));
|
||||||
|
|
||||||
|
gui.setDefaultClickAction(event -> event.setCancelled(true));
|
||||||
|
gui.setItem(3, 3, new HeadItem(HeadItem.ARROW_UP, _ -> gui.previous()));
|
||||||
|
gui.setItem(3, 7, new HeadItem(HeadItem.ARROW_DOWN, _ -> gui.next()));
|
||||||
|
gui.getFiller().fillBottom(ItemBuilder.from(Material.BLACK_STAINED_GLASS_PANE).asGuiItem());
|
||||||
|
|
||||||
|
gui.open(player);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
throw new IllegalStateException("Command can only be executed by a player");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void openItemSelectionMenu(Player player, Player recipient) {
|
||||||
|
Gui gui = Gui.gui()
|
||||||
|
.title(Component.text("Select items to send to " + recipient.getName()))
|
||||||
|
.rows(6)
|
||||||
|
.create();
|
||||||
|
|
||||||
|
gui.setItem(6, 1, ItemBuilder.from(Material.RED_STAINED_GLASS_PANE).name(Component.text("Cancel")).asGuiItem(event -> cancelSend(event, gui, player)));
|
||||||
|
gui.setItem(6, 9, ItemBuilder.from(Material.GREEN_STAINED_GLASS_PANE).name(Component.text("Send Items")).asGuiItem(event -> sendItems(event, gui, player, recipient)));
|
||||||
|
gui.getFiller().fillBottom(new GuiItem(Material.BLACK_STAINED_GLASS_PANE));
|
||||||
|
|
||||||
|
gui.open(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendItems(InventoryClickEvent event, Gui gui, Player player, Player recipient) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
gui.close(player);
|
||||||
|
if (recipient.isOnline()) {
|
||||||
|
dropAtPlayer(recipient, gui.getInventory().getStorageContents());
|
||||||
|
player.sendMessage(Component.text("Sent items to " + recipient.getName()));
|
||||||
|
} else {
|
||||||
|
dropAtPlayer(player, gui.getInventory().getStorageContents());
|
||||||
|
player.sendMessage(Component.text("Recipient is no longer online, so we dropped your items at your location"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void dropAtPlayer(Player player, ItemStack[] stacks) {
|
||||||
|
var location = player.getLocation();
|
||||||
|
for (ItemStack stack : stacks) {
|
||||||
|
location.getWorld().dropItem(location, stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void cancelSend(InventoryClickEvent event, Gui gui, Player player) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
gui.close(player);
|
||||||
|
dropAtPlayer(player, gui.getInventory().getStorageContents());
|
||||||
|
player.sendPlainMessage("Cancelled sending items to " + player.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package de.oryfox.plugins.helpers;
|
||||||
|
|
||||||
|
import com.destroystokyo.paper.profile.PlayerProfile;
|
||||||
|
import dev.triumphteam.gui.components.GuiAction;
|
||||||
|
import dev.triumphteam.gui.guis.GuiItem;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.SkullMeta;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class HeadItem extends GuiItem {
|
||||||
|
|
||||||
|
public static final PlayerProfile ARROW_UP = profile("https://textures.minecraft.net/texture/ac5c7e53695d88f4d31f52f43fac609ad9e62bc97d49fc504174dfdb84150c39", "Previous");
|
||||||
|
public static final PlayerProfile ARROW_DOWN = profile("https://textures.minecraft.net/texture/8c89aa29cb50359c9ac573e86c8eb0721197796cfab43ff5ce173385b9df2ed1", "Next");
|
||||||
|
|
||||||
|
public static PlayerProfile profile(String url, String displayName) {
|
||||||
|
var profile = Bukkit.createProfile(UUID.randomUUID(), displayName);
|
||||||
|
var textures = profile.getTextures();
|
||||||
|
try {
|
||||||
|
textures.setSkin(URI.create(url).toURL());
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
profile.setTextures(textures);
|
||||||
|
return profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HeadItem(PlayerProfile profile, GuiAction<InventoryClickEvent> action) {
|
||||||
|
var itemStack = new ItemStack(Material.PLAYER_HEAD);
|
||||||
|
itemStack.editMeta((meta) -> {
|
||||||
|
if (meta instanceof SkullMeta skullMeta) {
|
||||||
|
skullMeta.setPlayerProfile(profile);
|
||||||
|
skullMeta.displayName(Component.text(NullHelper.or(profile.getName(), "Unknown Player")));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
super(itemStack);
|
||||||
|
setAction(action);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package de.oryfox.plugins.helpers;
|
||||||
|
|
||||||
|
public class NullHelper {
|
||||||
|
public static String or(String value, String defaultValue) {
|
||||||
|
return value == null ? defaultValue : value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package de.oryfox.plugins.menu;
|
||||||
|
|
||||||
|
public class PlayerSelectMenu {
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
name: Inventory-Tools
|
||||||
|
version: 1.0.0
|
||||||
|
main: de.oryfox.plugins.InventoryTools
|
||||||
|
api-version: '1.21'
|
||||||
Reference in New Issue
Block a user