Skip to content

Commit

Permalink
Added title and action bar message options
Browse files Browse the repository at this point in the history
- Added title and action bar message options #40
- Fixed message command type
  • Loading branch information
Smudgge committed Aug 1, 2023
1 parent c3b1bf1 commit cda2b31
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 10 deletions.
2 changes: 1 addition & 1 deletion dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.github.smuddgge</groupId>
<artifactId>Leaf</artifactId>
<name>Leaf</name>
<version>3.2.1</version>
<version>3.3.0</version>
<description>A velocity utility plugin</description>
<build>
<resources>
Expand Down
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>com.github.smuddgge</groupId>
<artifactId>Leaf</artifactId>
<version>3.2.1</version>
<version>3.3.0</version>
<packaging>jar</packaging>

<name>Leaf</name>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/smuddgge/leaf/Leaf.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
@Plugin(
id = "leaf",
name = "Leaf",
version = "3.0.2",
version = "3.3.0",
description = "A velocity utility plugin",
authors = {"Smudge"}
)
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/github/smuddgge/leaf/MessageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.velocitypowered.api.proxy.Player;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ public CommandStatus onPlayerRun(ConfigurationSection section, String[] argument

// Get message as list.
// If the message is not a list it will return null.
List<String> message = section.getListString("message");
List<String> message = section.getListString("message", new ArrayList<>());

// If null assume it's a string.
if (message == null) {
if (message == null || message.isEmpty()) {
String messageString = section.getString("message", "null");
user.sendMessage(messageString);
return new CommandStatus();
Expand Down
40 changes: 35 additions & 5 deletions src/main/java/com/github/smuddgge/leaf/datatype/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ServerConnection;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.title.TitlePart;

import java.time.Duration;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.CompletableFuture;

/**
Expand Down Expand Up @@ -236,12 +235,43 @@ public boolean isIgnoring(UUID uuid) {
/**
* Used to send a user a message.
* This will also convert the messages placeholders and colours.
* <li>Title example: "::title =string::"</li>
* <li>Subtitle example: "::subtitle =string>::"</li>
* <li>Action bar example: "::actionbar =string::"</li>
*
* @param message The message to send.
*/
public void sendMessage(String message) {
if (this.player == null) return;
this.player.sendMessage(MessageManager.convert(message, this));
String[] parts = message.split("::");

// Loop though parts.
for (String part : parts) {
if (part.equals("")) continue;

// Check if it's a title part.
if (part.startsWith("title =")) {
String titleMessage = part.split("=")[1];
this.player.sendTitlePart(TitlePart.TITLE, MessageManager.convert(titleMessage));
continue;
}

// Check if it's a subtitle part.
if (part.startsWith("subtitle =")) {
String subtitleMessage = part.split("=")[1];
this.player.sendTitlePart(TitlePart.SUBTITLE, MessageManager.convert(subtitleMessage));
continue;
}

// Check if it's an actionbar part.
if (part.startsWith("actionbar =")) {
String actionbarMessage = part.split("=")[1];
this.player.sendActionBar(MessageManager.convert(actionbarMessage));
continue;
}

this.player.sendMessage(MessageManager.convert(part));
}
}

/**
Expand Down

0 comments on commit cda2b31

Please sign in to comment.