From b7c57859da0ec91d75e63a9fa79b369f3c32af4b Mon Sep 17 00:00:00 2001
From: MidasSword <72667836+MidasSword@users.noreply.github.com>
Date: Sat, 10 Oct 2020 12:48:18 -0700
Subject: [PATCH 1/3] add github actions
---
.github/workflows/compile.yml | 38 +++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
create mode 100644 .github/workflows/compile.yml
diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml
new file mode 100644
index 00000000..e6a5f26a
--- /dev/null
+++ b/.github/workflows/compile.yml
@@ -0,0 +1,38 @@
+name: Test EcoEnchants
+
+on:
+ push:
+ branches:
+ - master
+ pull_request:
+ branches:
+ - master
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ name: Build Maven project
+ steps:
+ - uses: actions/checkout@v1
+ - uses: actions/cache@v2
+ with:
+ path: ~/.m2/repository
+ key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
+ restore-keys: |
+ ${{ runner.os }}-maven-
+ # - name: Build Spigot
+ # # Takes 3 minutes
+ # # We only build 1.15 because it is the only Spigot version that is not
+ # # available on their Maven repo
+ # run: |
+ # cd ..
+ # wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar
+ # java -jar BuildTools.jar --rev 1.15
+ - name: Set up JDK 8
+ uses: actions/setup-java@v1
+ with:
+ java-version: 8
+ - name: Build EcoEnchants
+ run: |
+ mvn initialize --batch-mode
+ mvn package install --batch-mode
\ No newline at end of file
From dfdf6e997f80dba9e85569c487b449974435522d Mon Sep 17 00:00:00 2001
From: MidasSword <72667836+MidasSword@users.noreply.github.com>
Date: Sat, 10 Oct 2020 13:00:17 -0700
Subject: [PATCH 2/3] Change 1.15 to 1.15.2
---
API/pom.xml | 2 +-
NMS/v1_15_R1/pom.xml | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/API/pom.xml b/API/pom.xml
index 8eb7ba05..bb7185bc 100644
--- a/API/pom.xml
+++ b/API/pom.xml
@@ -16,7 +16,7 @@
org.spigotmc
spigot-api
- 1.15-R0.1-SNAPSHOT
+ 1.15.2-R0.1-SNAPSHOT
provided
diff --git a/NMS/v1_15_R1/pom.xml b/NMS/v1_15_R1/pom.xml
index aba4bf05..eee2914d 100644
--- a/NMS/v1_15_R1/pom.xml
+++ b/NMS/v1_15_R1/pom.xml
@@ -22,7 +22,7 @@
org.spigotmc
spigot
- 1.15-R0.1-SNAPSHOT
+ 1.15.2-R0.1-SNAPSHOT
provided
From af271b07a0d8fef1a18694067755e6206ecb4998 Mon Sep 17 00:00:00 2001
From: MidasSword <72667836+MidasSword@users.noreply.github.com>
Date: Sun, 11 Oct 2020 17:39:55 -0700
Subject: [PATCH 3/3] implement autocomplete for /enchantinfo
---
.../ecoenchants/command/AbstractCommand.java | 5 +-
.../command/EcoEnchantsTabCompleter.java | 60 +++++++++++++++++++
.../command/commands/CommandEnchantinfo.java | 1 -
.../com/willfp/ecoenchants/loader/Loader.java | 1 +
4 files changed, 65 insertions(+), 2 deletions(-)
create mode 100644 Plugin/src/main/java/com/willfp/ecoenchants/command/EcoEnchantsTabCompleter.java
diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/command/AbstractCommand.java b/Plugin/src/main/java/com/willfp/ecoenchants/command/AbstractCommand.java
index 435ff991..e6a64a53 100644
--- a/Plugin/src/main/java/com/willfp/ecoenchants/command/AbstractCommand.java
+++ b/Plugin/src/main/java/com/willfp/ecoenchants/command/AbstractCommand.java
@@ -6,6 +6,7 @@ import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
+import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player;
import java.util.Arrays;
@@ -43,7 +44,9 @@ public abstract class AbstractCommand implements CommandExecutor, Registerable {
@Override
public final void register() {
- Bukkit.getPluginCommand(name).setExecutor(this);
+ PluginCommand pluginCommand = Bukkit.getPluginCommand(name);
+ pluginCommand.setExecutor(this);
+ pluginCommand.setTabCompleter(new EcoEnchantsTabCompleter());
}
public abstract void onExecute(CommandSender sender, List args);
diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/command/EcoEnchantsTabCompleter.java b/Plugin/src/main/java/com/willfp/ecoenchants/command/EcoEnchantsTabCompleter.java
new file mode 100644
index 00000000..5791defd
--- /dev/null
+++ b/Plugin/src/main/java/com/willfp/ecoenchants/command/EcoEnchantsTabCompleter.java
@@ -0,0 +1,60 @@
+package com.willfp.ecoenchants.command;
+
+import com.willfp.ecoenchants.enchantments.EcoEnchant;
+import com.willfp.ecoenchants.enchantments.EcoEnchants;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.TabCompleter;
+import org.bukkit.util.StringUtil;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+
+
+public class EcoEnchantsTabCompleter implements TabCompleter {
+ private final List enchantsNames;
+
+ public EcoEnchantsTabCompleter() {
+ // Fetching the list of all enchants takes longer than anything inside onTabComplete, so caching is effective
+ enchantsNames = EcoEnchants.getAll().stream().map(EcoEnchant::getName).collect(Collectors.toList());
+ }
+
+ private static String removePrefix(String s, String prefix) {
+ if (s != null && prefix != null && s.startsWith(prefix)) {
+ return s.substring(prefix.length());
+ }
+ return s;
+ }
+
+ @Override
+ public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
+ try {
+ if (command.getLabel().equalsIgnoreCase("enchantinfo") && (sender.isOp() || sender.hasPermission("ecoenchants.enchantinfo"))) {
+ List completions = new ArrayList<>();
+
+ if (args.length == 0) {
+ // Currently, this case is not ever reached
+ return enchantsNames;
+ }
+
+ StringUtil.copyPartialMatches(String.join(" ", args), enchantsNames, completions);
+
+ if (args.length > 1) { // Remove all previous words from the candidate of completions
+ ArrayList finishedArgs = new ArrayList<>(Arrays.asList(args));
+ finishedArgs.remove(args.length - 1);
+
+ String prefix = String.join(" ", finishedArgs);
+ completions = completions.stream().map(enchantName -> removePrefix(enchantName, prefix).trim()).collect(Collectors.toList());
+ }
+
+ Collections.sort(completions);
+ return completions;
+ }
+ } catch (Exception ignored) {}
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEnchantinfo.java b/Plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEnchantinfo.java
index 277438ed..c1fd0694 100644
--- a/Plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEnchantinfo.java
+++ b/Plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEnchantinfo.java
@@ -126,7 +126,6 @@ public final class CommandEnchantinfo extends AbstractCommand {
final String finalTargets = allTargets;
final String finalConflicts = allConflicts;
final String finalMaxLevel = maxLevel;
-
Arrays.asList(ConfigManager.getLang().getMessage("enchantinfo").split("\\r?\\n")).forEach((string -> {
string = string.replaceAll("%name%", finalName)
.replaceAll("%description%", finalDescription)
diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/loader/Loader.java b/Plugin/src/main/java/com/willfp/ecoenchants/loader/Loader.java
index 1526bbfb..cd15a967 100644
--- a/Plugin/src/main/java/com/willfp/ecoenchants/loader/Loader.java
+++ b/Plugin/src/main/java/com/willfp/ecoenchants/loader/Loader.java
@@ -5,6 +5,7 @@ import com.willfp.ecoenchants.EcoEnchantsPlugin;
import com.willfp.ecoenchants.command.commands.CommandEcodebug;
import com.willfp.ecoenchants.command.commands.CommandEcoreload;
import com.willfp.ecoenchants.command.commands.CommandEnchantinfo;
+import com.willfp.ecoenchants.command.EcoEnchantsTabCompleter;
import com.willfp.ecoenchants.config.ConfigManager;
import com.willfp.ecoenchants.display.EnchantDisplay;
import com.willfp.ecoenchants.display.packets.PacketOpenWindowMerchant;