Skip to content

Commit

Permalink
Started removable of AText
Browse files Browse the repository at this point in the history
  • Loading branch information
mosemister committed Oct 16, 2023
1 parent 3f90477 commit a3d9df2
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 35 deletions.
13 changes: 12 additions & 1 deletion src/main/java/org/core/adventureText/AText.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.core.adventureText;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
import org.core.adventureText.adventure.AdventureText;
import org.core.adventureText.format.TextColour;
import org.core.adventureText.legacy.LegacyText;
import org.core.utils.ComponentUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -20,12 +23,20 @@
* @deprecated Removed as component is now supported by all platforms (except spigot). Using Component
*/
@Deprecated(forRemoval = true)
public interface AText {
public interface AText extends ComponentLike {

String COMPONENT_CLASS_PATH = "net.kyori.adventure.text.Component";
String PLAIN_COMPONENT_CLASS_PATH = "net.kyori.adventure.text.serializer.plain.PlainComponentSerializer";
String LEGACY_COMPONENT_CLASS_PATH = "net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer";

@Override
default @NotNull Component asComponent() {
if (this instanceof AdventureText adventureText) {
return adventureText.getComponent();
}
return ComponentUtils.fromLegacy(this.toLegacy());
}

/**
* Adds the provided text to the end of this text
*
Expand Down
51 changes: 23 additions & 28 deletions src/main/java/org/core/command/ArgumentLauncher.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.core.command;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor;
import org.core.adventureText.AText;
import org.core.adventureText.format.NamedTextColours;
import org.core.command.argument.ArgumentCommand;
Expand Down Expand Up @@ -28,38 +30,31 @@ public interface ArgumentLauncher extends BaseCommandLauncher {
default boolean run(CommandSource source, String... args) throws NotEnoughArguments {
CommandContext commandContext = new CommandContext(source, this.getCommands(), args);
Optional<ArgumentCommand> opCommand = commandContext.getCompleteCommand();
if (!opCommand.isPresent()) {
if (source instanceof CommandViewer) {
CommandViewer viewer = (CommandViewer) source;
Set<ErrorContext> errors = commandContext.getErrors();
if (!errors.isEmpty()) {
ErrorContext error = errors.iterator().next();
viewer.sendMessage(AText.ofPlain(error.getError()).withColour(NamedTextColours.RED));
if (errors.size() > 8) {
return false;
}

errors
.parallelStream()
.map(e -> e.getArgument().getUsage())
.collect(Collectors.toSet())
.forEach(e -> viewer.sendMessage(AText.ofPlain(e).withColour(NamedTextColours.RED)));
} else {
viewer.sendMessage(AText.ofPlain("Unknown error").withColour(NamedTextColours.RED));
}
if (opCommand.isEmpty()) {
Set<ErrorContext> errors = commandContext.getErrors();
if (errors.isEmpty()) {
source.sendMessage(Component.text("Unknown error").color(TextColor.color(255, 0, 0)));
return true;
}
return false;
ErrorContext error = errors.iterator().next();
source.sendMessage(Component.text(error.getError()).color(TextColor.color(255, 0, 0)));
if (errors.size() > 8) {
return false;
}
errors
.parallelStream()
.map(e -> e.getArgument().getUsage())
.collect(Collectors.toSet())
.forEach(e -> source.sendMessage(Component.text(e).color(TextColor.color(255, 0, 0))));
return true;
}
if (!opCommand.get().hasPermission(source)) {
if (source instanceof CommandViewer) {
((CommandViewer) source).sendMessage(AText
.ofPlain("You do not have permission for that command. You require " +
opCommand.get().getPermissionNode())
.withColour(NamedTextColours.RED));
return true;
}
return false;
source.sendMessage(AText
.ofPlain("You do not have permission for that command. You require " + opCommand
.get()
.getPermissionNode())
.withColour(NamedTextColours.RED));
return true;
}
return opCommand.get().run(commandContext, args);
}
Expand Down
55 changes: 49 additions & 6 deletions src/main/java/org/core/world/boss/ServerBossBar.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,68 @@
package org.core.world.boss;

import net.kyori.adventure.bossbar.BossBar;
import org.core.adventureText.AText;
import org.core.adventureText.adventure.AdventureText;
import org.core.entity.living.human.player.LivePlayer;
import org.core.world.boss.colour.BossColour;
import org.core.world.boss.colour.BossColours;

import java.util.Set;

@Deprecated(forRemoval = true)
public interface ServerBossBar {

AText getTitle();
BossBar bossBar();

ServerBossBar setTitle(AText text);
default AText getTitle() {
return new AdventureText(bossBar().name());
}

BossColour getColour();
default ServerBossBar setTitle(AText text) {
bossBar().name(text);
return this;
}

ServerBossBar setColour(BossColour colour);
default BossColour getColour() {
switch (bossBar().color()) {
case PINK -> {
return BossColours.PINK.get();
}
case BLUE -> {
return BossColours.BLUE.get();
}
case RED -> {
return BossColours.RED.get();
}
case GREEN -> {
return BossColours.GREEN.get();
}
case YELLOW -> {
return BossColours.YELLOW.get();
}
case PURPLE -> {
return BossColours.PURPLE.get();
}
case WHITE -> {
return BossColours.WHITE.get();
}
}
throw new RuntimeException("legacy colour not accepted");
}

int getValue();
default ServerBossBar setColour(BossColour colour) {
BossBar.Color.valueOf(colour.getName().toUpperCase());
return this;
}

ServerBossBar setValue(int value);
default int getValue() {
return (int) (this.bossBar().progress() * 100);
}

default ServerBossBar setValue(int value) {
this.bossBar().progress(value / 100);
return this;
}

Set<LivePlayer> getPlayers();

Expand Down

0 comments on commit a3d9df2

Please sign in to comment.