stuff
This commit is contained in:
parent
e6ae54fc9b
commit
a00c59679e
6 changed files with 171 additions and 3 deletions
17
pom.xml
17
pom.xml
|
|
@ -12,12 +12,13 @@
|
||||||
<name>Letterbox</name>
|
<name>Letterbox</name>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>1.8</java.version>
|
<java.version>21</java.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<finalName>${project.name}</finalName>
|
||||||
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
|
@ -58,13 +59,23 @@
|
||||||
<id>sonatype</id>
|
<id>sonatype</id>
|
||||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>brokkonaut</id>
|
||||||
|
<url>https://www.iani.de/nexus/content/groups/public</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.papermc.paper</groupId>
|
<groupId>io.papermc.paper</groupId>
|
||||||
<artifactId>paper-api</artifactId>
|
<artifactId>paper-api</artifactId>
|
||||||
<version>1.20.4-R0.1-SNAPSHOT</version>
|
<version>1.20.6-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>de.lunarakai</groupId>
|
||||||
|
<artifactId>LunarUtils</artifactId>
|
||||||
|
<version>0.0.2</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package de.lunarakai.letterbox;
|
package de.lunarakai.letterbox;
|
||||||
|
|
||||||
|
import de.iani.cubesideutils.bukkit.commands.CommandRouter;
|
||||||
|
import de.lunarakai.letterbox.commands.LetterboxGiveCommand;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public final class Letterbox extends JavaPlugin {
|
public final class Letterbox extends JavaPlugin {
|
||||||
|
|
@ -7,6 +9,10 @@ public final class Letterbox extends JavaPlugin {
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
// Plugin startup logic
|
// Plugin startup logic
|
||||||
|
getServer().getPluginManager().registerEvents(new LetterboxListener(this), this);
|
||||||
|
|
||||||
|
CommandRouter commandRouter = new CommandRouter(getCommand("letterbox"));
|
||||||
|
commandRouter.addCommandMapping(new LetterboxGiveCommand(this), "give");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
81
src/main/java/de/lunarakai/letterbox/LetterboxItem.java
Normal file
81
src/main/java/de/lunarakai/letterbox/LetterboxItem.java
Normal file
|
|
@ -0,0 +1,81 @@
|
||||||
|
package de.lunarakai.letterbox;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.block.Skull;
|
||||||
|
import org.bukkit.block.data.BlockData;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.inventory.meta.SkullMeta;
|
||||||
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
|
public class LetterboxItem {
|
||||||
|
private Letterbox plugin;
|
||||||
|
|
||||||
|
private boolean isLetterbox;
|
||||||
|
private UUID owner;
|
||||||
|
|
||||||
|
private final NamespacedKey isLetterboxKey;
|
||||||
|
private final NamespacedKey ownerKey;
|
||||||
|
|
||||||
|
public LetterboxItem(Letterbox plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
|
||||||
|
isLetterboxKey = new NamespacedKey(plugin, "isLetterbox");
|
||||||
|
ownerKey = new NamespacedKey(plugin, "ownerPlayer");
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack createLetterboxItem(UUID owner) {
|
||||||
|
|
||||||
|
ItemStack letterboxItem = new ItemStack(Material.PLAYER_HEAD);
|
||||||
|
SkullMeta skullMeta = (SkullMeta) letterboxItem.getItemMeta();
|
||||||
|
ItemMeta meta = letterboxItem.getItemMeta();
|
||||||
|
|
||||||
|
PersistentDataContainer dataContainer = meta.getPersistentDataContainer();
|
||||||
|
dataContainer.set(getIsLetterboxKey(), PersistentDataType.BOOLEAN, true);
|
||||||
|
dataContainer.set(getOwnerKey(), PersistentDataType.STRING, owner.toString());
|
||||||
|
|
||||||
|
letterboxItem.setItemMeta(skullMeta);
|
||||||
|
|
||||||
|
return letterboxItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NamespacedKey getIsLetterboxKey() {
|
||||||
|
return isLetterboxKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NamespacedKey getOwnerKey() {
|
||||||
|
return ownerKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLetterbox(BlockData blockData) {
|
||||||
|
boolean isLetterbox = false;
|
||||||
|
if(!(blockData instanceof Skull)) return false;
|
||||||
|
SkullMeta skullMeta = (SkullMeta) blockData;
|
||||||
|
try {
|
||||||
|
isLetterbox = Boolean.TRUE.equals(skullMeta.getPersistentDataContainer().get(getIsLetterboxKey(), PersistentDataType.BOOLEAN));
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
plugin.getLogger().log(Level.SEVERE, "Could not get isLetterbox item", e);
|
||||||
|
}
|
||||||
|
return isLetterbox;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getOwnerUUID(ItemStack letterboxItem) {
|
||||||
|
String uuidString = letterboxItem.getItemMeta().getPersistentDataContainer().get(getOwnerKey(), PersistentDataType.STRING);
|
||||||
|
UUID uuid = null;
|
||||||
|
if(uuidString != null) {
|
||||||
|
try {
|
||||||
|
uuid = UUID.fromString(uuidString);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
plugin.getLogger().log(Level.SEVERE, "Could not convert UUIDString to UUID", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
30
src/main/java/de/lunarakai/letterbox/LetterboxListener.java
Normal file
30
src/main/java/de/lunarakai/letterbox/LetterboxListener.java
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
package de.lunarakai.letterbox;
|
||||||
|
|
||||||
|
import org.bukkit.block.data.BlockData;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
|
public class LetterboxListener implements Listener {
|
||||||
|
protected Letterbox plugin;
|
||||||
|
|
||||||
|
public LetterboxListener(Letterbox plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
|
if(event.getClickedBlock() == null) return;
|
||||||
|
if (!event.getAction().isRightClick()) return;
|
||||||
|
if(event.getClickedBlock() == null) return;
|
||||||
|
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
|
LetterboxItem letterbox = new LetterboxItem(plugin);
|
||||||
|
BlockData data = event.getClickedBlock().getBlockData();
|
||||||
|
if(!letterbox.isLetterbox(data)) return;
|
||||||
|
|
||||||
|
player.sendMessage("Item is a Letterbox :3");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
package de.lunarakai.letterbox.commands;
|
||||||
|
|
||||||
|
import de.iani.cubesideutils.bukkit.commands.SubCommand;
|
||||||
|
import de.iani.cubesideutils.bukkit.commands.exceptions.DisallowsCommandBlockException;
|
||||||
|
import de.iani.cubesideutils.bukkit.commands.exceptions.IllegalSyntaxException;
|
||||||
|
import de.iani.cubesideutils.bukkit.commands.exceptions.InternalCommandException;
|
||||||
|
import de.iani.cubesideutils.bukkit.commands.exceptions.NoPermissionException;
|
||||||
|
import de.iani.cubesideutils.bukkit.commands.exceptions.RequiresPlayerException;
|
||||||
|
import de.iani.cubesideutils.commands.ArgsParser;
|
||||||
|
import de.lunarakai.letterbox.Letterbox;
|
||||||
|
import de.lunarakai.letterbox.LetterboxItem;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class LetterboxGiveCommand extends SubCommand {
|
||||||
|
private Letterbox plugin;
|
||||||
|
|
||||||
|
public LetterboxGiveCommand(Letterbox plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean requiresPlayer() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender commandSender, Command command, String s, String s1, ArgsParser argsParser) throws DisallowsCommandBlockException, RequiresPlayerException, NoPermissionException, IllegalSyntaxException, InternalCommandException {
|
||||||
|
Player player = (Player) commandSender;
|
||||||
|
LetterboxItem letterboxItem = new LetterboxItem(plugin);
|
||||||
|
ItemStack itemStack = letterboxItem.createLetterboxItem(player.getUniqueId());
|
||||||
|
player.getInventory().addItem(itemStack);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,3 +2,6 @@ name: Letterbox
|
||||||
version: '${project.version}'
|
version: '${project.version}'
|
||||||
main: de.lunarakai.letterbox.Letterbox
|
main: de.lunarakai.letterbox.Letterbox
|
||||||
api-version: '1.20'
|
api-version: '1.20'
|
||||||
|
commands:
|
||||||
|
letterbox:
|
||||||
|
description: Letterbox main command
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue