This commit is contained in:
femsci 2023-04-21 22:56:48 +02:00
commit 56d69abdc0
Signed by: femsci
GPG key ID: 08F7911F0E650C67
203 changed files with 15543 additions and 0 deletions

41
CommandItems/pom.xml Executable file
View file

@ -0,0 +1,41 @@
<?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>me.yuri</groupId>
<artifactId>CommandItems</artifactId>
<version>1.0-A</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>me.yuri</groupId>
<artifactId>YuriAPI</artifactId>
<version>1.2.3</version>
<scope>system</scope>
<systemPath>/mnt/B65CCF2D5CCEE6E9/Projects/IdeaProjects/YAPI/YuriAPI.jar</systemPath>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.14.4-R0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,37 @@
package me.yuri.cmditems;
import me.yuri.yuriapi.api.command.CommandManager;
import org.bukkit.NamespacedKey;
import org.bukkit.plugin.java.JavaPlugin;
public class C extends JavaPlugin {
private static C instance;
protected static NamespacedKey nsk;
protected static NamespacedKey nsc;
//Cannot instantiate NamespacedKey before onEnable()...
public static C getMainClass() {
return instance;
}
@Override
public void onLoad() {
instance = this;
}
@Override
public void onDisable() {
}
@Override
public void onEnable() {
new CommandManager(this).registerCommand(new Commands());
this.getServer().getPluginManager().registerEvents(new Listeners(), this);
nsc = new NamespacedKey(C.getMainClass(), "command");
nsk = new NamespacedKey(C.getMainClass(), "events");
}
}

View file

@ -0,0 +1,82 @@
package me.yuri.cmditems;
import me.yuri.yuriapi.api.command.Cmd;
import me.yuri.yuriapi.api.command.CommandEvent;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import java.util.ArrayList;
import java.util.List;
public class Commands {
@Cmd(command = "addcommand", aliases = "addcmd", consoleSide = false, permissions = "commanditems.addcommand")
public void addCommand(CommandEvent e){
Player s = (Player) e.getSender();
ItemStack is = s.getInventory().getItemInMainHand();
if(is.getType() == Material.AIR){
e.reply("§cYou need to hold an item in order to apply a command to it!");
return;
}
if(e.getArgs().length < 2){
e.reply("§cYou need to specify the event and command!");
return;
}
String event = e.getArgs()[0];
String[] event2 = event.split(",");
String command = e.getArgsString().substring(e.getArgs()[0].length()+1).trim();
List<EventType> events;
try {
events = parse(event2);
} catch (IllegalArgumentException a){
e.reply("§cUknown event type: §6"+a.getMessage()+"§c!");
return;
}
int[] a = {0};
if(!events.contains(EventType.ALL)){
a = new int[events.size()];
int cnt = 0;
for(EventType aa : events){
a[cnt] = aa.ordinal();
cnt++;
}
}
ItemMeta im = is.getItemMeta();
assert im != null;
im.getPersistentDataContainer().set(C.nsk, PersistentDataType.INTEGER_ARRAY, a);
im.getPersistentDataContainer().set(C.nsc, PersistentDataType.STRING, command);
//im.setDisplayName("§4§lMETA");
is.setItemMeta(im);
e.reply("§aCommand set!");
}
private static List<EventType> parse(String... a){
List<EventType> e = new ArrayList<>();
for(String b : a){
try {
if(!e.contains(EventType.valueOf(b.toUpperCase())))
e.add(EventType.valueOf(b.toUpperCase()));
} catch (IllegalArgumentException ignored){
throw new IllegalArgumentException(b);
}
}
return e;
}
}

View file

@ -0,0 +1,5 @@
package me.yuri.cmditems;
public enum EventType {
ALL, DAMAGE_IMPOSED, DAMAGE_RECEIVED, ITEM_USE, ITEM_USE_BLOCK, ITEM_USE_AIR, BLOCK_BREAK, DROPPED, PICKED_UP
}

View file

@ -0,0 +1,32 @@
package me.yuri.cmditems;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
public class Listeners implements Listener {
@EventHandler
public void onUse(PlayerInteractEvent e){
ItemStack is = e.getPlayer().getInventory().getItemInMainHand();
if(is.getType() != Material.AIR){
if(is.getItemMeta() == null) return;
PersistentDataContainer dc = is.getItemMeta().getPersistentDataContainer();
if(dc.has(C.nsk, PersistentDataType.INTEGER_ARRAY)){
int[] i = dc.get(C.nsk, PersistentDataType.INTEGER_ARRAY);
String cmd = dc.get(C.nsc, PersistentDataType.STRING);
if(i == null || cmd == null) return;
if(i[0] == 0){
e.getPlayer().performCommand(cmd);
}
}
}
}
}

View file

@ -0,0 +1,11 @@
name: CommandItems
version: 1.0E
main: me.yuri.cmditems.C
author: yuri
depend:
- YuriAPI
commands:
addcommand:
aliases: addcmd
description: Assigns a command to an item
permission: commanditems.addcmd