added givepixelblock command
This commit is contained in:
parent
e45bbfc07b
commit
8851f3c032
@ -5,6 +5,7 @@ import co.aikar.taskchain.TaskChain;
|
||||
import co.aikar.taskchain.TaskChainFactory;
|
||||
import eu.mhsl.minecraft.pixelblocks.commands.CreatePixelBlockCommand;
|
||||
import eu.mhsl.minecraft.pixelblocks.commands.ExitWorldCommand;
|
||||
import eu.mhsl.minecraft.pixelblocks.commands.GivePixelBlockCommand;
|
||||
import eu.mhsl.minecraft.pixelblocks.listeners.*;
|
||||
import eu.mhsl.minecraft.pixelblocks.pixelblock.PixelBlock;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -82,6 +83,7 @@ public final class Main extends JavaPlugin {
|
||||
}
|
||||
|
||||
Objects.requireNonNull(getCommand("createpixelblock")).setExecutor(new CreatePixelBlockCommand());
|
||||
Objects.requireNonNull(getCommand("givepixelblock")).setExecutor(new GivePixelBlockCommand());
|
||||
Objects.requireNonNull(getCommand("exitworld")).setExecutor(new ExitWorldCommand());
|
||||
|
||||
Bukkit.addRecipe(PixelBlockItem.getRecipe());
|
||||
|
@ -0,0 +1,40 @@
|
||||
package eu.mhsl.minecraft.pixelblocks.commands;
|
||||
|
||||
import eu.mhsl.minecraft.pixelblocks.PixelBlockItem;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
import static eu.mhsl.minecraft.pixelblocks.PixelBlockItem.getEmptyPixelBlock;
|
||||
|
||||
public class GivePixelBlockCommand implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if(sender instanceof Player p) {
|
||||
ItemStack result = getEmptyPixelBlock();
|
||||
ItemMeta itemMeta = result.getItemMeta();
|
||||
PersistentDataContainer dataContainer = itemMeta.getPersistentDataContainer();
|
||||
if(!dataContainer.has(PixelBlockItem.idProperty)) return false;
|
||||
String currentId = dataContainer.get(PixelBlockItem.idProperty, PersistentDataType.STRING);
|
||||
Objects.requireNonNull(currentId);
|
||||
if(!UUID.fromString(currentId).equals(PixelBlockItem.emptyBlockUUID)) return false;
|
||||
|
||||
dataContainer.set(PixelBlockItem.idProperty, PersistentDataType.STRING, args[0]);
|
||||
|
||||
result.setItemMeta(itemMeta);
|
||||
|
||||
|
||||
p.getInventory().addItem(result);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -5,3 +5,4 @@ api-version: '1.21'
|
||||
commands:
|
||||
createpixelblock:
|
||||
exitworld:
|
||||
givepixelblock:
|
Loading…
x
Reference in New Issue
Block a user