Adjusted Command Processing

Completion annotations have been moved to top level, from per method, for a much clearer understanding of how the annotation should be used.
This commit is contained in:
Paul Reilly
2023-07-23 02:15:12 -05:00
parent 2b12f4eebb
commit 6842cb2792
16 changed files with 71 additions and 66 deletions

View File

@ -1,5 +1,9 @@
package me.totalfreedom.audience;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Predicate;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.bossbar.BossBar;
import net.kyori.adventure.chat.ChatType;
@ -13,13 +17,8 @@ import net.kyori.adventure.title.Title;
import net.kyori.adventure.title.TitlePart;
import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Predicate;
/**
* A replacement for {@link net.kyori.adventure.audience.ForwardingAudience} that allows for audiences to be removed &
* A replacement for {@link net.kyori.adventure.audience.ForwardingAudience} that allows for audiences to be removed and
* added at will. Not thread safe.
* <p>
* This is intended for use in toggleable logging systems, for example, potion spy.

View File

@ -1,5 +1,9 @@
package me.totalfreedom.command;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import me.totalfreedom.command.annotation.Completion;
import me.totalfreedom.command.annotation.Subcommand;
import me.totalfreedom.provider.ContextProvider;
@ -10,24 +14,18 @@ import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.command.PluginIdentifiableCommand;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
/**
* This class is acts as a delegate between our custom command implementation and the Bukkit API.
* <br>
* This class is not meant to be used directly, and is only public to allow for the Bukkit API to access it. As a
* result, this file will remain undocumented.
* <span color=#ff0000>
* <br>
* <br>
* This class is not thread-safe.
* <br>
@ -36,7 +34,6 @@ import java.util.Set;
* This class is not meant to be instantiated.
* <br>
* This class is not meant to be used outside Patchwork.
* </span>
*/
public final class BukkitDelegate extends Command implements PluginIdentifiableCommand
{
@ -101,14 +98,18 @@ public final class BukkitDelegate extends Command implements PluginIdentifiableC
{
try
{
if (noConsole) {
if (noConsole)
{
command.getBaseMethod()
.invoke(command, (Player)sender);
} else {
.invoke(command, (Player) sender);
}
else
{
command.getBaseMethod()
.invoke(command, sender);
}
} catch (Exception ex)
}
catch (Exception ex)
{
FreedomLogger.getLogger("Patchwork")
.error(ex);
@ -142,37 +143,45 @@ public final class BukkitDelegate extends Command implements PluginIdentifiableC
final String[] reasonArgs = Arrays.copyOfRange(args, i, args.length - 1);
final String reason = String.join(" ", reasonArgs);
objects[i] = reason;
} else
}
else
{
continue;
}
}
if (argType.equals(Location.class)) {
if (argType.equals(Location.class))
{
final String[] locationArgs = Arrays.copyOfRange(args, i, i + 3);
final String location = String.join(" ", locationArgs);
objects[i] = location;
}
final Object obj = provider.fromString(arg, argType);
if (obj == null) {
FreedomLogger.getLogger("Datura").error("Failed to parse argument " + arg + " for type " + argType.getName());
if (obj == null)
{
FreedomLogger.getLogger("Datura")
.error("Failed to parse argument " + arg + " for type " + argType.getName());
return;
}
objects[i] = obj;
}
try
{
if (noConsole) {
if (noConsole)
{
command.getSubcommands()
.get(node)
.invoke(command, (Player)sender, objects);
} else {
.invoke(command, (Player) sender, objects);
}
else
{
command.getSubcommands()
.get(node)
.invoke(command, sender, objects);
}
} catch (Exception ex)
}
catch (Exception ex)
{
FreedomLogger.getLogger("Patchwork")
.error(ex);
@ -204,16 +213,16 @@ public final class BukkitDelegate extends Command implements PluginIdentifiableC
.map(World::getName)
.toList());
case "%number%" -> results.addAll(List.of(
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"));
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"));
case "%location%" -> results.add("world x y z");
default -> results.add(p);
}

View File

@ -12,7 +12,7 @@ import java.lang.annotation.Target;
* This will register at class level, and does not retain method information. As a result, you only need to register the
* arguments a single time, and it will always be used in tab completions.
*/
@Target(ElementType.METHOD)
@Target(ElementType.TYPE)
@Repeatable(Completions.class)
@Retention(RetentionPolicy.RUNTIME)
public @interface Completion

View File

@ -8,10 +8,10 @@ import java.lang.annotation.Target;
/**
* A marker interface which represents a holder for multiple {@link Completion} annotations.
* <br>
* <u>This interface is <span color=#ff0000><b>NOT</b></span> intended for implementation and should
* <span color=#ff0000><b>NOT</b></span> be used.</u>
* <u>This interface is <b>NOT</b> intended for implementation and should
* <b>NOT</b> be used.</u>
*/
@Target(ElementType.METHOD)
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Completions
{

View File

@ -284,7 +284,7 @@ public class ServiceTaskRegistry
* <br>
* <i>The service should have been registered previously as a <b>ServiceSubscription</b></i>.
*
* @param service The service you are trying to unregister.
* @param clazz The service you are trying to unregister.
* @see #registerService(ServiceSubscription)
* @see ServiceSubscription
*/

View File

@ -78,6 +78,7 @@ public class DisplayableView extends InventoryView
}
@Override
@Deprecated(forRemoval = true, since = "1.16")
public @NotNull String getTitle()
{
return title;

View File

@ -56,7 +56,7 @@ public interface Trail
*
* @return The color of the trail, or null if the trail is a gradient or non-colorable.
* @see Particle
* @see #getColors();
* @see #getColors()
*/
@Nullable
Color getColor();

View File

@ -1,9 +1,7 @@
package me.totalfreedom.shop;
import me.totalfreedom.display.BossBarDisplay;
import net.kyori.adventure.text.Component;
import java.time.Duration;
import net.kyori.adventure.text.Component;
/**
* Represents a chat reaction that can be performed by a player.
@ -59,10 +57,4 @@ public abstract class Reaction implements Reactable
{
return reactionType;
}
@Override
public BossBarDisplay getBossBarDisplay()
{
}
}