Updated to 3.8.0 and eco 5.7.0

This commit is contained in:
Auxilor
2021-07-05 18:36:55 +02:00
parent c6b4311a4c
commit 2a8d283a42
10 changed files with 262 additions and 270 deletions

View File

@@ -46,7 +46,7 @@ allprojects {
}
dependencies {
compileOnly 'com.willfp:eco:5.6.0'
compileOnly 'com.willfp:eco:5.7.0'
compileOnly 'org.jetbrains:annotations:19.0.0'

View File

@@ -2,12 +2,12 @@ package com.willfp.talismans;
import com.willfp.eco.core.AbstractPacketAdapter;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.command.AbstractCommand;
import com.willfp.eco.core.command.impl.PluginCommand;
import com.willfp.eco.core.display.DisplayModule;
import com.willfp.eco.core.integrations.IntegrationLoader;
import com.willfp.talismans.commands.CommandTalgive;
import com.willfp.talismans.commands.CommandTalreload;
import com.willfp.talismans.commands.TabcompleterTalgive;
import com.willfp.talismans.command.CommandGive;
import com.willfp.talismans.command.CommandReload;
import com.willfp.talismans.command.CommandTalismans;
import com.willfp.talismans.display.TalismanDisplay;
import com.willfp.talismans.talismans.Talismans;
import com.willfp.talismans.talismans.util.BlockPlaceListener;
@@ -38,7 +38,7 @@ public class TalismansPlugin extends EcoPlugin {
* Internal constructor called by bukkit on plugin load.
*/
public TalismansPlugin() {
super(87377, 9865, "com.willfp.talismans.proxy", "&6");
super(87377, 9865, "&6");
instance = this;
}
@@ -110,16 +110,10 @@ public class TalismansPlugin extends EcoPlugin {
return new ArrayList<>();
}
/**
* Talismans-specific commands.
*
* @return A list of all commands.
*/
@Override
public List<AbstractCommand> getCommands() {
public List<PluginCommand> getPluginCommands() {
return Arrays.asList(
new CommandTalreload(this),
new CommandTalgive(this)
new CommandTalismans(this)
);
}
@@ -154,7 +148,7 @@ public class TalismansPlugin extends EcoPlugin {
return Arrays.asList(
TalismanChecks.class,
Talismans.class,
TabcompleterTalgive.class
CommandGive.class
);
}
@@ -163,4 +157,9 @@ public class TalismansPlugin extends EcoPlugin {
protected DisplayModule createDisplayModule() {
return new TalismanDisplay(this);
}
@Override
protected String getMinimumEcoVersion() {
return "5.7.0";
}
}

View File

@@ -0,0 +1,182 @@
package com.willfp.talismans.command;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.command.CommandHandler;
import com.willfp.eco.core.command.TabCompleteHandler;
import com.willfp.eco.core.command.impl.Subcommand;
import com.willfp.eco.core.config.ConfigUpdater;
import com.willfp.talismans.TalismansPlugin;
import com.willfp.talismans.talismans.Talisman;
import com.willfp.talismans.talismans.TalismanLevel;
import com.willfp.talismans.talismans.Talismans;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
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 CommandGive extends Subcommand {
/**
* The cached enchantment names.
*/
private static final List<String> TALISMAN_NAMES = new ArrayList<>();
/**
* The cached numbers.
*/
private static final List<String> NUMBERS = Arrays.asList(
"1",
"2",
"3",
"4",
"5",
"10",
"32",
"64"
);
/**
* Instantiate a new command handler.
*
* @param plugin The plugin for the commands to listen for.
*/
public CommandGive(@NotNull final EcoPlugin plugin) {
super(plugin, "give", "talismans.command.give", false);
}
/**
* Called on reload.
*/
@ConfigUpdater
public static void reload() {
TALISMAN_NAMES.clear();
TALISMAN_NAMES.addAll(Talismans.values().stream().filter(Talisman::isEnabled).map(talisman -> talisman.getKey().getKey()).collect(Collectors.toList()));
}
@Override
public CommandHandler getHandler() {
return (sender, args) -> {
if (args.isEmpty()) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("needs-player"));
return;
}
if (args.size() == 1) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("needs-talisman"));
return;
}
int level = 1;
if (args.size() > 2) {
try {
level = Integer.parseInt(args.get(2));
} catch (NumberFormatException ignored) {
// do nothing
}
}
int amount = 1;
if (args.size() > 3) {
try {
amount = Integer.parseInt(args.get(3));
} catch (NumberFormatException ignored) {
// do nothing
}
}
String recieverName = args.get(0);
Player reciever = Bukkit.getPlayer(recieverName);
if (reciever == null) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-player"));
return;
}
String talismanName = args.get(1);
Talisman talisman = Talismans.getByKey(this.getPlugin().getNamespacedKeyFactory().create(talismanName));
if (talisman == null || !talisman.isEnabled()) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-talisman"));
return;
}
TalismanLevel talismanLevel = talisman.getLevel(level);
if (talismanLevel == null) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-level"));
return;
}
String message = this.getPlugin().getLangYml().getMessage("give-success");
message = message.replace("%talisman%", talismanLevel.getName()).replace("%recipient%", reciever.getName());
sender.sendMessage(message);
ItemStack itemStack = talismanLevel.getItemStack();
itemStack.setAmount(amount);
reciever.getInventory().addItem(itemStack);
};
}
@Override
public TabCompleteHandler getTabCompleter() {
return (sender, args) -> {
List<String> completions = new ArrayList<>();
if (args.isEmpty()) {
// Currently, this case is not ever reached
return TALISMAN_NAMES;
}
if (args.size() == 1) {
StringUtil.copyPartialMatches(args.get(0), Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()), completions);
return completions;
}
if (args.size() == 2) {
StringUtil.copyPartialMatches(args.get(1), TALISMAN_NAMES, completions);
Collections.sort(completions);
return completions;
}
if (args.size() == 3) {
Talisman talisman = Talismans.getByKey(TalismansPlugin.getInstance().getNamespacedKeyFactory().create(args.get(1).toLowerCase()));
if (talisman == null) {
return new ArrayList<>();
}
List<String> levels = talisman.getLevels().stream().map(TalismanLevel::getLevel).map(String::valueOf).collect(Collectors.toList());
StringUtil.copyPartialMatches(args.get(2), levels, completions);
completions.sort((s1, s2) -> {
int t1 = Integer.parseInt(s1);
int t2 = Integer.parseInt(s2);
return t1 - t2;
});
return completions;
}
if (args.size() == 4) {
StringUtil.copyPartialMatches(args.get(3), NUMBERS, completions);
completions.sort((s1, s2) -> {
int t1 = Integer.parseInt(s1);
int t2 = Integer.parseInt(s2);
return t1 - t2;
});
return completions;
}
return new ArrayList<>(0);
};
}
}

View File

@@ -0,0 +1,26 @@
package com.willfp.talismans.command;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.command.CommandHandler;
import com.willfp.eco.core.command.impl.Subcommand;
import org.jetbrains.annotations.NotNull;
public class CommandReload extends Subcommand {
/**
* Instantiate a new command handler.
*
* @param plugin The plugin for the commands to listen for.
*/
public CommandReload(@NotNull final EcoPlugin plugin) {
super(plugin, "reload", "talismans.commands.reload", false);
}
@Override
public CommandHandler getHandler() {
return (sender, args) -> {
this.getPlugin().reload();
this.getPlugin().reload(); // Aids
sender.sendMessage(this.getPlugin().getLangYml().getMessage("reloaded"));
};
}
}

View File

@@ -0,0 +1,27 @@
package com.willfp.talismans.command;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.command.CommandHandler;
import com.willfp.eco.core.command.impl.PluginCommand;
import org.jetbrains.annotations.NotNull;
public class CommandTalismans extends PluginCommand {
/**
* Instantiate a new command handler.
*
* @param plugin The plugin for the commands to listen for.
*/
public CommandTalismans(@NotNull final EcoPlugin plugin) {
super(plugin, "talismans", "talismans.command.talismans", false);
this.addSubcommand(new CommandReload(plugin))
.addSubcommand(new CommandGive(plugin));
}
@Override
public CommandHandler getHandler() {
return (sender, args) -> {
};
}
}

View File

@@ -1,95 +0,0 @@
package com.willfp.talismans.commands;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.command.AbstractCommand;
import com.willfp.eco.core.command.AbstractTabCompleter;
import com.willfp.talismans.talismans.Talisman;
import com.willfp.talismans.talismans.TalismanLevel;
import com.willfp.talismans.talismans.Talismans;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class CommandTalgive extends AbstractCommand {
/**
* Instantiate a new /talgive command handler.
*
* @param plugin The plugin for the commands to listen for.
*/
public CommandTalgive(@NotNull final EcoPlugin plugin) {
super(plugin, "talgive", "talismans.give", false);
}
@Override
public @Nullable AbstractTabCompleter getTab() {
return new TabcompleterTalgive(this);
}
@Override
public void onExecute(@NotNull final CommandSender sender,
@NotNull final List<String> args) {
if (args.isEmpty()) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("needs-player"));
return;
}
if (args.size() == 1) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("needs-talisman"));
return;
}
int level = 1;
if (args.size() > 2) {
try {
level = Integer.parseInt(args.get(2));
} catch (NumberFormatException ignored) {
// do nothing
}
}
int amount = 1;
if (args.size() > 3) {
try {
amount = Integer.parseInt(args.get(3));
} catch (NumberFormatException ignored) {
// do nothing
}
}
String recieverName = args.get(0);
Player reciever = Bukkit.getPlayer(recieverName);
if (reciever == null) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-player"));
return;
}
String talismanName = args.get(1);
Talisman talisman = Talismans.getByKey(this.getPlugin().getNamespacedKeyFactory().create(talismanName));
if (talisman == null || !talisman.isEnabled()) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-talisman"));
return;
}
TalismanLevel talismanLevel = talisman.getLevel(level);
if (talismanLevel == null) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-level"));
return;
}
String message = this.getPlugin().getLangYml().getMessage("give-success");
message = message.replace("%talisman%", talismanLevel.getName()).replace("%recipient%", reciever.getName());
sender.sendMessage(message);
ItemStack itemStack = talismanLevel.getItemStack();
itemStack.setAmount(amount);
reciever.getInventory().addItem(itemStack);
}
}

View File

@@ -1,27 +0,0 @@
package com.willfp.talismans.commands;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.command.AbstractCommand;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class CommandTalreload extends AbstractCommand {
/**
* Instantiate a new /talreload command handler.
*
* @param plugin The plugin for the commands to listen for.
*/
public CommandTalreload(@NotNull final EcoPlugin plugin) {
super(plugin, "talreload", "talismans.reload", false);
}
@Override
public void onExecute(@NotNull final CommandSender sender,
@NotNull final List<String> args) {
this.getPlugin().reload();
this.getPlugin().reload(); // Aids
sender.sendMessage(this.getPlugin().getLangYml().getMessage("reloaded"));
}
}

View File

@@ -1,121 +0,0 @@
package com.willfp.talismans.commands;
import com.willfp.eco.core.command.AbstractTabCompleter;
import com.willfp.eco.core.config.ConfigUpdater;
import com.willfp.talismans.TalismansPlugin;
import com.willfp.talismans.talismans.Talisman;
import com.willfp.talismans.talismans.TalismanLevel;
import com.willfp.talismans.talismans.Talismans;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
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 TabcompleterTalgive extends AbstractTabCompleter {
/**
* The cached enchantment names.
*/
private static final List<String> TALISMAN_NAMES = new ArrayList<>();
/**
* The cached numbers.
*/
private static final List<String> NUMBERS = Arrays.asList(
"1",
"2",
"3",
"4",
"5",
"10",
"32",
"64"
);
/**
* Instantiate a new tab-completer for /talgive.
*
* @param command Instance of /talgive.
*/
public TabcompleterTalgive(@NotNull final CommandTalgive command) {
super(command);
}
/**
* Called on /ecoreload.
*/
@ConfigUpdater
public static void reload() {
TALISMAN_NAMES.clear();
TALISMAN_NAMES.addAll(Talismans.values().stream().filter(Talisman::isEnabled).map(talisman -> talisman.getKey().getKey()).collect(Collectors.toList()));
}
/**
* The execution of the tabcompleter.
*
* @param sender The sender of the command.
* @param args The arguments of the command.
* @return A list of tab-completions.
*/
@Override
public List<String> onTab(@NotNull final CommandSender sender,
@NotNull final List<String> args) {
List<String> completions = new ArrayList<>();
if (args.isEmpty()) {
// Currently, this case is not ever reached
return TALISMAN_NAMES;
}
if (args.size() == 1) {
StringUtil.copyPartialMatches(args.get(0), Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()), completions);
return completions;
}
if (args.size() == 2) {
StringUtil.copyPartialMatches(args.get(1), TALISMAN_NAMES, completions);
Collections.sort(completions);
return completions;
}
if (args.size() == 3) {
Talisman talisman = Talismans.getByKey(TalismansPlugin.getInstance().getNamespacedKeyFactory().create(args.get(1).toLowerCase()));
if (talisman == null) {
return new ArrayList<>();
}
List<String> levels = talisman.getLevels().stream().map(TalismanLevel::getLevel).map(String::valueOf).collect(Collectors.toList());
StringUtil.copyPartialMatches(args.get(2), levels, completions);
completions.sort((s1, s2) -> {
int t1 = Integer.parseInt(s1);
int t2 = Integer.parseInt(s2);
return t1 - t2;
});
return completions;
}
if (args.size() == 4) {
StringUtil.copyPartialMatches(args.get(3), NUMBERS, completions);
completions.sort((s1, s2) -> {
int t1 = Integer.parseInt(s1);
int t2 = Integer.parseInt(s2);
return t1 - t2;
});
return completions;
}
return new ArrayList<>(0);
}
}

View File

@@ -23,28 +23,29 @@ softdepend:
- mcMMO
commands:
talreload:
description: Reloads config
permission: talismans.reload
talgive:
description: Give a player a talisman
permission: talismans.give
talismans:
description: Parent command.
permission: talismans.command.talismans
permissions:
talismans.*:
description: All talismans permissions
default: op
children:
talismans.reload: true
talismans.give: true
talismans.command.talismans: true
talismans.command.give: true
talismans.command.reload: true
talismans.fromtable.*: true
talismans.reload:
talismans.command.reload:
description: Allows reloading the config
default: op
talismans.give:
description: Allows the use of /talgive.
talismans.command.give:
description: Allows the use of /talismans give.
default: op
talismans.command.talismans:
description: Allows the use of /talismans
default: true
talismans.fromtable.*:
description: Allows crafting all talismans
default: true

View File

@@ -1,2 +1,2 @@
version = 3.7.0
version = 3.8.0
plugin-name = Talismans