Skip to content

Commit

Permalink
v2.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildTools committed May 8, 2024
1 parent 979705c commit abda0e1
Show file tree
Hide file tree
Showing 83 changed files with 2,774 additions and 374 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>su.nightexpress.nightcore</groupId>
<artifactId>nightcore</artifactId>
<version>2.5.2.1</version>
<version>2.6.1</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
Expand Down
51 changes: 35 additions & 16 deletions src/main/java/su/nightexpress/nightcore/NightCore.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package su.nightexpress.nightcore;

import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import su.nightexpress.nightcore.command.base.ReloadSubCommand;
import su.nightexpress.nightcore.command.experimental.ImprovedCommands;
import su.nightexpress.nightcore.command.experimental.impl.ReloadCommand;
import su.nightexpress.nightcore.command.experimental.node.ChainedNode;
import su.nightexpress.nightcore.config.PluginDetails;
import su.nightexpress.nightcore.core.CoreConfig;
import su.nightexpress.nightcore.core.CoreLang;
Expand All @@ -13,16 +16,13 @@
import su.nightexpress.nightcore.dialog.Dialog;
import su.nightexpress.nightcore.integration.VaultHook;
import su.nightexpress.nightcore.language.LangAssets;
import su.nightexpress.nightcore.util.EntityUtil;
import su.nightexpress.nightcore.util.ItemUtil;
import su.nightexpress.nightcore.util.Plugins;
import su.nightexpress.nightcore.util.Version;
import su.nightexpress.nightcore.util.*;
import su.nightexpress.nightcore.util.blocktracker.PlayerBlockTracker;

import java.util.HashSet;
import java.util.Set;

public class NightCore extends NightPlugin {
public class NightCore extends NightPlugin implements ImprovedCommands {

private final Set<NightCorePlugin> childrens;
private final CoreManager coreManager;
Expand All @@ -36,11 +36,13 @@ public NightCore() {
public void enable() {
LangAssets.load();

ChainedNode rootNode = this.getRootNode();

if (Plugins.hasVault()) {
VaultHook.setup();
this.getBaseCommand().addChildren(new CheckPermCommand(this));
CheckPermCommand.inject(this, rootNode);
}
this.getBaseCommand().addChildren(new ReloadSubCommand(this, CorePerms.COMMAND_RELOAD));
ReloadCommand.inject(this, rootNode, CorePerms.COMMAND_RELOAD);

this.testMethods();
this.coreManager.setup();
Expand Down Expand Up @@ -78,18 +80,35 @@ public Set<NightCorePlugin> getChildrens() {

private void testMethods() {
if (Version.getCurrent() == Version.UNKNOWN) {
this.warn("Server Version: UNSUPPORTED (!)");
this.warn("Server Version: UNSUPPORTED ");
}
else this.info("Server Version: " + Version.getCurrent().getLocalized() + " (OK)");
else this.info("Server Version: " + Version.getCurrent().getLocalized() + " ");

if (EntityUtil.ENTITY_COUNTER == null) {
this.warn("Entity Id Counter: NULL!");
if (EntityUtil.setupEntityCounter(this)) {
this.info("Entity Id Counter: OK ✔");
}
else this.info("Entity Id Counter: OK.");
else this.error("Entity Id Counter: FAIL ✘");

if (ItemUtil.compress(new ItemStack(Material.DIAMOND_SWORD)) == null) {
this.warn("Item NBT Compress: FAILED!");
if (this.testItemNbt()) {
this.info("Item NBT Compress: OK ✔");
}
else this.info("Item NBT Compress: OK.");
else this.error("Item NBT Compress: FAIL ✘");
}

private boolean testItemNbt() {
if (!ItemNbt.setup(this)) return false;

ItemStack testItem = new ItemStack(Material.DIAMOND_SWORD);
ItemUtil.editMeta(testItem, meta -> {
meta.setDisplayName("Test Item");
meta.setLore(Lists.newList("Test Lore 1", "Test Lore 2", "Test Lore 3"));
meta.addEnchant(Enchantment.FIRE_ASPECT, 10, true);
});

String nbt = ItemNbt.compress(testItem);
if (nbt == null) return false;

ItemStack decompressed = ItemNbt.decompress(nbt);
return decompressed != null && decompressed.getType() == testItem.getType();
}
}
4 changes: 2 additions & 2 deletions src/main/java/su/nightexpress/nightcore/NightCorePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.NotNull;
import su.nightexpress.nightcore.command.CommandManager;
import su.nightexpress.nightcore.command.api.NightPluginCommand;
import su.nightexpress.nightcore.config.FileConfig;
import su.nightexpress.nightcore.command.CommandManager;
import su.nightexpress.nightcore.config.PluginDetails;
import su.nightexpress.nightcore.language.LangManager;
import su.nightexpress.nightcore.util.wrapper.UniTask;
Expand All @@ -24,7 +24,7 @@ public interface NightCorePlugin extends Plugin {

void reload();

@NotNull NightPluginCommand getBaseCommand();
NightPluginCommand getBaseCommand();

@Override
@NotNull FileConfig getConfig();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/su/nightexpress/nightcore/NightPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void onEnable() {
this.warn("=".repeat(35));
this.warn("WARNING: You're running an unsupported server version!");
this.warn("Expect bugs and broken features.");
this.warn("! NO DISCORD SUPPORT WILL BE GIVEN !");
this.warn("=".repeat(35));
}
else if (version.isDeprecated()) {
Expand Down Expand Up @@ -157,7 +158,7 @@ protected void unloadManagers() {

this.disable();

AbstractMenu.closeAll(this); // Close all GUIs.
AbstractMenu.clearAll(this); // Close all GUIs.
HandlerList.unregisterAll(this); // Unregister all plugin listeners.

this.getCommandManager().shutdown();
Expand Down
76 changes: 66 additions & 10 deletions src/main/java/su/nightexpress/nightcore/command/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,33 @@

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nightexpress.nightcore.NightCorePlugin;
import su.nightexpress.nightcore.NightPlugin;
import su.nightexpress.nightcore.command.api.NightPluginCommand;
import su.nightexpress.nightcore.manager.SimpleManager;
import su.nightexpress.nightcore.command.base.HelpSubCommand;
import su.nightexpress.nightcore.command.experimental.ImprovedCommands;
import su.nightexpress.nightcore.command.experimental.RootCommand;
import su.nightexpress.nightcore.command.experimental.ServerCommand;
import su.nightexpress.nightcore.command.experimental.node.ChainedNode;
import su.nightexpress.nightcore.command.impl.BaseCommand;
import su.nightexpress.nightcore.manager.SimpleManager;
import su.nightexpress.nightcore.util.CommandUtil;
import su.nightexpress.nightcore.util.Lists;

import java.util.HashSet;
import java.util.Set;

public class CommandManager extends SimpleManager<NightCorePlugin> {
public class CommandManager extends SimpleManager<NightPlugin> {

private final Set<NightPluginCommand> commands;
private final Set<ServerCommand> serverCommands;

private BaseCommand mainCommand;
private BaseCommand mainCommand;
private RootCommand<NightPlugin, ChainedNode> rootCommand;

public CommandManager(@NotNull NightCorePlugin plugin) {
public CommandManager(@NotNull NightPlugin plugin) {
super(plugin);
this.commands = new HashSet<>();
this.serverCommands = new HashSet<>();
}

@Override
Expand All @@ -32,16 +39,28 @@ public void onLoad() {
return;
}

// Create main plugin command and attach help sub-command as a default executor.
this.mainCommand = new BaseCommand(this.plugin);
this.mainCommand.addDefaultCommand(new HelpSubCommand(this.plugin));
if (this.plugin instanceof ImprovedCommands) {
this.rootCommand = RootCommand.chained(this.plugin, aliases, builder -> builder
// TODO Permission?
.localized(this.plugin.getNameLocalized())
);
this.registerCommand(this.rootCommand);
}
else {
// Create main plugin command and attach help sub-command as a default executor.
this.mainCommand = new BaseCommand(this.plugin);
this.mainCommand.addDefaultCommand(new HelpSubCommand(this.plugin));

// Register main command as a bukkit command.
this.registerCommand(this.mainCommand);
// Register main command as a bukkit command.
this.registerCommand(this.mainCommand);
}
}

@Override
public void onShutdown() {
this.serverCommands.forEach(ServerCommand::unregister);
this.serverCommands.clear();

for (NightPluginCommand command : new HashSet<>(this.getCommands())) {
this.unregisterCommand(command);
command.getChildrens().clear();
Expand All @@ -54,18 +73,35 @@ public Set<NightPluginCommand> getCommands() {
return this.commands;
}

@NotNull
public Set<ServerCommand> getServerCommands() {
return serverCommands;
}

@NotNull
public BaseCommand getMainCommand() {
return this.mainCommand;
}

@NotNull
public RootCommand<NightPlugin, ChainedNode> getRootCommand() {
return rootCommand;
}

@Nullable
public NightPluginCommand getCommand(@NotNull String alias) {
return this.getCommands().stream()
.filter(command -> Lists.contains(command.getAliases(), alias))
.findFirst().orElse(null);
}

@Nullable
public ServerCommand getServerCommand(@NotNull String alias) {
return this.serverCommands.stream()
.filter(command -> command.getNode().getName().equalsIgnoreCase(alias) || Lists.contains(command.getNode().getAliases(), alias))
.findFirst().orElse(null);
}

public void registerCommand(@NotNull NightPluginCommand command) {
if (this.commands.add(command)) {
CommandUtil.register(this.plugin, command);
Expand All @@ -86,4 +122,24 @@ public boolean unregisterCommand(@NotNull NightPluginCommand command) {
}
return false;
}

public void registerCommand(@NotNull ServerCommand command) {
if (!this.serverCommands.contains(command)) {
if (command.register()) {
this.serverCommands.add(command);
}
}
}

public boolean unregisterServerCommand(@NotNull String alias) {
ServerCommand command = this.getServerCommand(alias);
if (command != null) {
return this.unregisterCommand(command);
}
return false;
}

public boolean unregisterCommand(@NotNull ServerCommand command) {
return this.serverCommands.remove(command) && command.unregister();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package su.nightexpress.nightcore.command.experimental;

import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nightexpress.nightcore.NightCorePlugin;
import su.nightexpress.nightcore.core.CoreLang;
import su.nightexpress.nightcore.language.message.LangMessage;

public class CommandContext {

private final NightCorePlugin plugin;
private final CommandSender sender;
private final Player executor;
private final String label;
private final String[] args;

private int argumentIndex;

public CommandContext(@NotNull NightCorePlugin plugin, @NotNull CommandSender sender, @NotNull String label, String[] args) {
this.plugin = plugin;
this.sender = sender;
this.executor = sender instanceof Player player ? player : null;
this.label = label;
this.args = args;
this.argumentIndex = 0;
}

public void send(@NotNull String string) {
this.sender.sendMessage(string);
}

public boolean sendSuccess(@NotNull String string) {
this.send(string);
return true;
}

public boolean sendFailure(@NotNull String string) {
this.send(string);
return false;
}

public void send(@NotNull LangMessage message) {
message.send(this.sender);
}

public boolean sendSuccess(@NotNull LangMessage message) {
this.send(message);
return true;
}

public boolean sendFailure(@NotNull LangMessage message) {
this.send(message);
return false;
}

public boolean checkPermission(@NotNull Permission permission) {
return this.sender.hasPermission(permission);
}

public boolean checkPermission(@NotNull String permission) {
return this.sender.hasPermission(permission);
}

public boolean isPlayer() {
return this.executor != null;
}

public int getArgumentIndex() {
return argumentIndex;
}

public void setArgumentIndex(int argumentIndex) {
this.argumentIndex = argumentIndex;
}

@NotNull
public CommandSender getSender() {
return sender;
}

@Nullable
public Player getExecutor() {
return executor;
}

public int length() {
return this.args.length;
}

@NotNull
public String getLabel() {
return label;
}

public String[] getArgs() {
return args;
}

public void errorPermission() {
this.send(CoreLang.ERROR_NO_PERMISSION.getMessage(plugin));
}

public void errorBadPlayer() {
this.send(CoreLang.ERROR_INVALID_PLAYER.getMessage(plugin));
}

public void errorPlayerOnly() {
this.send(CoreLang.ERROR_COMMAND_PLAYER_ONLY.getMessage(plugin));
}
}
Loading

0 comments on commit abda0e1

Please sign in to comment.