-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CommandBuilder, new main command, view all commands in-game via GUI, …
…Paginated menu System. Added menu system. View all commands with their actions in-game. ItemBuilder, CommandBuilder, Menu builder. new commands.
- Loading branch information
Showing
24 changed files
with
832 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
/.idea/ | ||
/out | ||
/Project Links.iml | ||
/.gitattributes | ||
/.gitattributes | ||
/pom.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?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.sean0402</groupId> | ||
<artifactId>ProjectLinks</artifactId> | ||
<version>1.0.0-Beta</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>Project Links</name> | ||
|
||
<properties> | ||
<java.version>1.8</java.version> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<build> | ||
<defaultGoal>clean package</defaultGoal> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.7.0</version> | ||
<configuration> | ||
<source>${java.version}</source> | ||
<target>${java.version}</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>3.2.2</version> | ||
<executions> | ||
<execution> | ||
<id>shade</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<relocations> | ||
<relocation> | ||
<pattern>de.tr7zw.changeme.nbtapi</pattern> | ||
</relocation> | ||
</relocations> | ||
<createDependencyReducedPom>false</createDependencyReducedPom> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.0.2</version> | ||
<configuration> | ||
<outputDirectory>C:\Users\Sean\Desktop\server\plugins</outputDirectory> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
<resources> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<filtering>true</filtering> | ||
</resource> | ||
</resources> | ||
</build> | ||
|
||
<repositories> | ||
<repository> | ||
<id>jitpack.io</id> | ||
<url>https://jitpack.io</url> | ||
</repository> | ||
<repository> | ||
<id>spigotmc-repo</id> | ||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> | ||
</repository> | ||
<repository> | ||
<id>codemc-repo</id> | ||
<url>https://repo.codemc.org/repository/maven-public/</url> | ||
<layout>default</layout> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.spigotmc</groupId> | ||
<artifactId>spigot-api</artifactId> | ||
<version>1.15.2-R0.1-SNAPSHOT</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.MilkBowl</groupId> | ||
<artifactId>VaultAPI</artifactId> | ||
<version>1.7</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.12</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>de.tr7zw</groupId> | ||
<artifactId>item-nbt-api</artifactId> | ||
<version>2.5.0</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
74 changes: 74 additions & 0 deletions
74
src/main/java/me/sean0402/projectlinks/CommandBuilder/Command.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package me.sean0402.projectlinks.CommandBuilder; | ||
|
||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.Plugin; | ||
import org.bukkit.scheduler.BukkitRunnable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
/* | ||
Created on 02/09/2020 at 02:10 | ||
Author - Sean | ||
*/ | ||
public abstract class Command { | ||
|
||
public void setup() { | ||
} | ||
|
||
public void execute(org.bukkit.command.CommandSender sender, String... args) { | ||
|
||
} | ||
|
||
public BukkitRunnable executeAsync(org.bukkit.command.CommandSender sender, String... args) { | ||
return new BukkitRunnable() { | ||
@Override | ||
public void run() { | ||
} | ||
}; | ||
} | ||
|
||
public ArrayList<String> tabComplete(org.bukkit.command.CommandSender sender, String alias, String... args) { | ||
if (args.length <= 1 && !this.subCommands.isEmpty()) { | ||
if (args[0].isEmpty()) { | ||
return this.tabSubCommands(); | ||
} else { | ||
return (this.tabSubCommands() | ||
.stream() | ||
.filter(item -> item.toLowerCase().startsWith(args[0])) | ||
.collect(Collectors.toCollection(ArrayList::new)) | ||
); | ||
} | ||
} else if (args.length > 1) { | ||
String command = args[0]; | ||
|
||
if (this.containsSub(command)) { | ||
String[] lessArgs = Arrays.copyOfRange(args, 1, args.length); | ||
return this.subCommands.get(command).tabComplete(sender, alias, lessArgs); | ||
} | ||
} | ||
|
||
return new ArrayList<>(); | ||
} | ||
|
||
private Map<String, Command> subCommands = new HashMap<>(); | ||
|
||
public void sub(String name, Command command) { | ||
this.subCommands.put(name.toLowerCase(), command); | ||
} | ||
|
||
public boolean containsSub(String name) { | ||
return this.subCommands.containsKey(name); | ||
} | ||
|
||
public void processSubCommands(Player player, String[] args, Command help, Plugin instance) { | ||
|
||
} | ||
|
||
public ArrayList<String> tabSubCommands() { | ||
return new ArrayList<>(this.subCommands.keySet()); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/me/sean0402/projectlinks/CommandBuilder/CommandLib.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package me.sean0402.projectlinks.CommandBuilder; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import me.sean0402.projectlinks.CommandBuilder.register.BukkitRegister; | ||
import me.sean0402.projectlinks.CommandBuilder.register.RegisterBase; | ||
|
||
/* | ||
Created on 02/09/2020 at 01:53 | ||
Author - Sean | ||
*/ | ||
@NoArgsConstructor | ||
public class CommandLib { | ||
|
||
@Getter | ||
private org.bukkit.plugin.Plugin bukkitPlugin; | ||
private RegisterBase platform; | ||
|
||
public CommandLib setupBukkit(org.bukkit.plugin.Plugin bukkitPlugin) { | ||
this.bukkitPlugin = bukkitPlugin; | ||
this.platform = new BukkitRegister(this); | ||
this.platform.setup(); | ||
return this; | ||
} | ||
|
||
public CommandLib register(Command command) { | ||
command.setup(); | ||
if (this.bukkitPlugin != null) | ||
this.platform.registerCommand(command, this.bukkitPlugin); | ||
return this; | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/me/sean0402/projectlinks/CommandBuilder/DynamicCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package me.sean0402.projectlinks.CommandBuilder; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(value = ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface DynamicCommand { | ||
|
||
String name(); | ||
|
||
String description() default ""; | ||
|
||
String usage() default ""; | ||
|
||
boolean console() default false; | ||
|
||
String[] aliases() default {}; | ||
} |
85 changes: 85 additions & 0 deletions
85
src/main/java/me/sean0402/projectlinks/CommandBuilder/register/BukkitRegister.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package me.sean0402.projectlinks.CommandBuilder.register; | ||
|
||
import me.sean0402.projectlinks.CommandBuilder.Command; | ||
import me.sean0402.projectlinks.CommandBuilder.CommandLib; | ||
import me.sean0402.projectlinks.CommandBuilder.DynamicCommand; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.command.CommandMap; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.Plugin; | ||
import org.bukkit.plugin.SimplePluginManager; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Field; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
/* | ||
Created on 02/09/2020 at 02:10 | ||
Author - Sean | ||
*/ | ||
public class BukkitRegister extends RegisterBase { | ||
|
||
private CommandMap commandMap; | ||
|
||
public BukkitRegister(CommandLib commandLib) { | ||
super(commandLib); | ||
} | ||
|
||
@Override | ||
public void setup() { | ||
try { | ||
Field commandMap = SimplePluginManager.class.getDeclaredField("commandMap"); | ||
commandMap.setAccessible(true); | ||
this.commandMap = (CommandMap) commandMap.get(Bukkit.getPluginManager()); | ||
} catch (NoSuchFieldException | IllegalAccessException exception) { | ||
exception.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public CommandLib registerCommand(Command command, Plugin plugin) { | ||
CommandLib commandLib = super.getCommandLib(); | ||
|
||
for (Annotation annotation : command.getClass().getAnnotations()) { | ||
if (!DynamicCommand.class.isAssignableFrom(annotation.annotationType())) continue; | ||
|
||
WrappedCommand wrappedCommand = new WrappedCommand(command, (DynamicCommand) annotation); | ||
|
||
this.commandMap.register(plugin.getName(), wrappedCommand); | ||
} | ||
return commandLib; | ||
} | ||
|
||
private class WrappedCommand extends org.bukkit.command.Command { | ||
|
||
private Command command; | ||
private DynamicCommand dynamicCommand; | ||
|
||
WrappedCommand(Command command, DynamicCommand dynamicCommand) { | ||
super(dynamicCommand.name(), dynamicCommand.description(), | ||
dynamicCommand.usage(), Arrays.asList(dynamicCommand.aliases())); | ||
|
||
this.command = command; | ||
this.dynamicCommand = dynamicCommand; | ||
} | ||
|
||
@Override | ||
public boolean execute(CommandSender sender, String label, String[] args) { | ||
if (!(sender instanceof Player) && !this.dynamicCommand.console()) return true; | ||
|
||
this.command.execute(sender, args); | ||
|
||
Plugin instance = BukkitRegister.super.commandLib.getBukkitPlugin(); | ||
this.command.executeAsync(sender, args).runTaskAsynchronously(instance); | ||
return true; | ||
} | ||
|
||
@Override | ||
public List<String> tabComplete(CommandSender sender, String alias, String... args) | ||
throws IllegalArgumentException { | ||
return this.command.tabComplete(sender, alias, args); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/me/sean0402/projectlinks/CommandBuilder/register/RegisterBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package me.sean0402.projectlinks.CommandBuilder.register; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import me.sean0402.projectlinks.CommandBuilder.Command; | ||
import me.sean0402.projectlinks.CommandBuilder.CommandLib; | ||
|
||
/* | ||
Created on 02/09/2020 at 02:10 | ||
Author - Sean | ||
*/ | ||
@AllArgsConstructor | ||
public abstract class RegisterBase { | ||
|
||
@Getter | ||
protected CommandLib commandLib; | ||
|
||
public abstract void setup(); | ||
|
||
public CommandLib registerCommand(Command command, org.bukkit.plugin.Plugin plugin) { | ||
return this.commandLib; | ||
} | ||
} |
Oops, something went wrong.