Skip to content

Commit

Permalink
Version 1.3
Browse files Browse the repository at this point in the history
[Bugfix]
- Colors finaly work
[changes]
- reworked translateColorsAndFormatting() so it now supports the newly added formatting  permissions
- When u send a message the default brackets <> won't whow up anymore
- updated README.md
[added]
- Multi Version Support (1.13-1.20.*)
- added for color formatting ColorUtils.java
- added ChatListener.java
- added Version Checker (/info now checks if there is a new Version of the Plugin)
- added basic bStats functionality
- added permissions for using colors and every other type to write (bold, italic,...)

Tested-by:
Me on a localserver

PS: hopefullly this works

Took 3 hours 37 minutes
  • Loading branch information
BuildTools committed Dec 7, 2023
1 parent 0d9587d commit 71713da
Show file tree
Hide file tree
Showing 11 changed files with 1,164 additions and 51 deletions.
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Tub's Status Plugin
![Static Badge](https://img.shields.io/badge/MC-1.20.1-green)
![Static Badge](https://img.shields.io/badge/MC-1.13-green)
![Static Badge](https://img.shields.io/badge/MC-1.14-green)
![Static Badge](https://img.shields.io/badge/MC-1.15-green)
![Static Badge](https://img.shields.io/badge/MC-1.16-green)
![Static Badge](https://img.shields.io/badge/MC-1.17-green)
![Static Badge](https://img.shields.io/badge/MC-1.18-green)
![Static Badge](https://img.shields.io/badge/MC-1.19-green)
![Static Badge](https://img.shields.io/badge/MC-1.20-green)

[![forthebadge](https://forthebadge.com/images/badges/works-on-my-machine.svg)](https://forthebadge.com)


Expand All @@ -11,7 +19,7 @@ This is a Minecraft plugin for Spigot/Paper servers that allows players to set t
- Set status with formatting codes (for example to color them) with `/status &3<status>`
- Set other players' statuses with `/status <player> <status>` (requires `StatusPlugin.admin.setStatus` permission)
- Remove other players' statuses with `/status remove <player>` (requires `StatusPlugin.admin.setStatus` permission)
- Reload all statuses from file with `/status reload`
- Reload all statuses from file with `/status reload` (requires `StatusPlugin.admin.reload` permission) (Can be executed by console)
- View a list of all available color codes with `/status help colors`
- View info about the plugin with `/status info`
- Set a maximum length for statuses with `/status setmaxlength <length>` (requires StatusPlugin.admin.setMaxlength permission)
Expand All @@ -22,11 +30,16 @@ This is a Minecraft plugin for Spigot/Paper servers that allows players to set t
## Permissions

- `StatusPlugin.setStatus`: Allows a player to set their own status and remove it. (default: `true`)
- `StatusPlugin.formatting:`: Allows a player to use formatting codes in their status (for example to color them). (default: `false`)
- `StatusPlugin.admin.setStatus`: Allows a player to set and remove other players' statuses. (default: `false`)
- `StatusPlugin.admin.reload`: Allows a player to reload all statuses.(default: `false`)
- `StatusPlugin.admin.setMaxlength:` Allows a player to set the maximum length of statuses. (default: false)
- `StatusPlugin.admin.resetMaxlength:` Allows a player to reset the maximum length of statuses to default. (default: false)
- `StatusPlugin.admin.setMaxlength:` Allows a player to set the maximum length of statuses. (default: `false`)
- `StatusPlugin.admin.resetMaxlength:` Allows a player to reset the maximum length of statuses to default. (default: `false`)
- `StatusPlugin.formatting.color`: Allows a player to use color codes in their status. (default: `false`)
- `StatusPlugin.formatting.bold`: Allows a player to use bold formatting in their status. (default: `false`)
- `StatusPlugin.formatting.italic`: Allows a player to use italic formatting in their status. (default: `false`)
- `StatusPlugin.formatting.underlined`: Allows a player to use underlined formatting in their status. (default: `false`)
- `StatusPlugin.formatting.strikethrough`: Allows a player to use strikethrough formatting in their status. (default: `false`)
- `StatusPlugin.formatting.magic`: Allows a player to use obfuscated formatting in their status. (default: `false`)

## Installation

Expand Down
13 changes: 9 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

<groupId>de.tubyoub</groupId>
<artifactId>StatusPlugin</artifactId>
<version>1.2</version>
<version>1.3</version>
<packaging>jar</packaging>

<name>Tub's Status Plugin</name>

<properties>
<java.version>17</java.version>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand All @@ -39,7 +39,7 @@
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<outputFile>C:\Users\jornw\OneDrive\Desktop\Server\plugins\TubsStatusPlugin-1.2.jar</outputFile>
<outputFile>D:\papermc\plugins\TubsStatusPlugin-${project.version}.jar</outputFile>
</configuration>
</execution>
</executions>
Expand Down Expand Up @@ -68,8 +68,13 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.20.1-R0.1-SNAPSHOT</version>
<version>1.13-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.16.0</version>
</dependency>
</dependencies>
</project>
32 changes: 32 additions & 0 deletions src/main/java/de/tubyoub/statusplugin/Listener/ChatListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package de.tubyoub.statusplugin.Listener;

import de.tubyoub.statusplugin.StatusManager;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChatEvent;

public class ChatListener implements Listener {
private final StatusManager statusManager;
public ChatListener(StatusManager statusManager) {
this.statusManager = statusManager;
}
@EventHandler
public void onPlayerChat(PlayerChatEvent event) {
// Get the player and message
Player player = event.getPlayer();
String message = event.getMessage();
String status = statusManager.getStatus(player);
String broadcastMessage;

if (status == null) {
broadcastMessage = player.getName() + ": " + message;
} else {
broadcastMessage = "[" + status + "] " + player.getName() + ": " + message;
}
Bukkit.broadcastMessage(broadcastMessage);
// Cancel the original event
event.setCancelled(true);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.tubyoub.statusplugin;
package de.tubyoub.statusplugin.Listener;

import org.bukkit.ChatColor;
import de.tubyoub.statusplugin.StatusManager;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand Down
74 changes: 48 additions & 26 deletions src/main/java/de/tubyoub/statusplugin/StatusManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
import java.util.UUID;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import de.tubyoub.utils.ColourUtils;


import static org.bukkit.Bukkit.getConsoleSender;
import static org.bukkit.Bukkit.getLogger;

public class StatusManager {
Expand All @@ -23,6 +24,7 @@ public class StatusManager {
private static final int DEFAULT_MAX_LENGTH = 15;
private int maxStatusLength = DEFAULT_MAX_LENGTH;
private final StatusPlugin plugin;
private ColourUtils chatColour;

public StatusManager(StatusPlugin plugin) {
this.plugin = plugin;
Expand All @@ -31,40 +33,41 @@ public StatusManager(StatusPlugin plugin) {
loadStatuses();
}

public boolean setStatus(Player player, String status, CommandSender sender) {
String translatedStatus = translateColorsAndFormatting(status, sender);
if (calculateEffectiveLength(translatedStatus) > maxStatusLength) {
sender.sendMessage(ChatColor.RED + "Status is too long. Max length is " + maxStatusLength + " characters.");
return false;
public boolean setStatus(Player player, String status, CommandSender sender) {
String translatedStatus = translateColorsAndFormatting(status, sender);
if (calculateEffectiveLength(translatedStatus) > maxStatusLength) {
sender.sendMessage(ChatColor.RED + "Status is too long. Max length is " + maxStatusLength + " characters.");
return false;
}
statusMap.put(player.getUniqueId(), translatedStatus);
updateDisplayName(player);
saveStatuses();
return true;
}
statusMap.put(player.getUniqueId(), translatedStatus);
updateDisplayName(player);
saveStatuses();
return true;
}


public String getStatus(Player player) {
return statusMap.get(player.getUniqueId());
}

public void updateDisplayName(Player player) {
String status = getStatus(player);
if (status != null) {
String displayName = "[" + status + ChatColor.RESET + "] " + ChatColor.WHITE + player.getName();
ChatColor.translateAlternateColorCodes('&', displayName);
player.setDisplayName(displayName);
player.setPlayerListName(displayName);
} else {
player.setDisplayName(player.getName());
player.setPlayerListName(player.getName());
}
String status = getStatus(player);
if (status != null) {
String displayName = "[" + status + ChatColor.RESET + "] " + ChatColor.WHITE + player.getName();
displayName = ColourUtils.format(displayName); // Assign the result back to displayName
getConsoleSender().sendMessage(displayName);
player.setDisplayName(displayName);
player.setPlayerListName(displayName);
} else {
player.setDisplayName(player.getName());
player.setPlayerListName(player.getName());
}
}
public int getMaxStatusLength() {
return maxStatusLength;
}

public void setMaxStatusLength(int maxLength) {
public void setMaxStatusLength(int maxLength) {
this.maxStatusLength = maxLength;
plugin.getConfig().set("maxStatusLength", maxLength);
plugin.saveConfig();
Expand Down Expand Up @@ -97,11 +100,30 @@ public void saveStatuses() {
}

public String translateColorsAndFormatting(String status, CommandSender sender) {
if (sender.hasPermission("StatusPlugin.formatting")) {
return ChatColor.translateAlternateColorCodes('&', status);
} else {
return ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', status));
String[] codes = {"&l", "&k", "&n", "&m", "&o"};
String[] permissions = {
"StatusPlugin.formatting.bold",
"StatusPlugin.formatting.magic",
"StatusPlugin.formatting.underline",
"StatusPlugin.formatting.strikethrough",
"StatusPlugin.formatting.italic"
};

if (!sender.hasPermission("StatusPlugin.formatting.color")) {
status = removeColorCodes(status);
}
for (int i = 0; i < codes.length; i++) {
if (status.contains(codes[i]) && !sender.hasPermission(permissions[i])) {
status = status.replace(codes[i], "");
}
}
return ChatColor.translateAlternateColorCodes('§', status);
}

private String removeColorCodes(String status) {
Pattern pattern = Pattern.compile("&[0-9a-fk-or]");
Matcher matcher = pattern.matcher(status);
return matcher.replaceAll("");
}

public void removeStatus(Player player) {
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/de/tubyoub/statusplugin/StatusPlugin.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
package de.tubyoub.statusplugin;

import de.tubyoub.statusplugin.Listener.ChatListener;
import de.tubyoub.statusplugin.Listener.PlayerJoinListener;
import de.tubyoub.statusplugin.commands.StatusCommand;
import de.tubyoub.statusplugin.commands.VersionChecker;
import de.tubyoub.statusplugin.metrics.Metrics;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;

public class StatusPlugin extends JavaPlugin {
private StatusManager statusManager;
private VersionChecker versionChecker;
private int pluginId = 20463;

@Override
public void onEnable() {
this.statusManager = new StatusManager(this);
this.saveDefaultConfig();
this.statusManager = new StatusManager(this);
StatusCommand statusCommand = new StatusCommand(statusManager);
getCommand("status").setExecutor(new StatusCommand(this.statusManager));
this.versionChecker = new VersionChecker();
StatusCommand statusCommand = new StatusCommand(statusManager,versionChecker);
getCommand("status").setExecutor(new StatusCommand(this.statusManager,versionChecker));
getServer().getPluginManager().registerEvents(new PlayerJoinListener(this.statusManager), this);
getServer().getPluginManager().registerEvents(new ChatListener(this.statusManager), this);
getCommand("status").setExecutor(statusCommand);
getCommand("status").setTabCompleter(new StatusTabCompleter());

Metrics metrics = new Metrics(this, pluginId);
}
public void sendPluginMessages(CommandSender sender, String type) {
if ("title".equals(type)) {
Expand Down
39 changes: 32 additions & 7 deletions src/main/java/de/tubyoub/statusplugin/commands/StatusCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.tubyoub.statusplugin.StatusManager;
import de.tubyoub.statusplugin.StatusPlugin;
import de.tubyoub.utils.ColourUtils;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
Expand All @@ -14,11 +15,17 @@
import java.util.Arrays;
import java.util.stream.Collectors;



public class StatusCommand implements CommandExecutor {
String version = "1.3";
private final StatusManager statusManager;

public StatusCommand(StatusManager statusManager) {
private final VersionChecker versionChecker;

public StatusCommand(StatusManager statusManager, VersionChecker versionChecker) {
this.statusManager = statusManager;
this.versionChecker = versionChecker;
}

@Override
Expand Down Expand Up @@ -84,7 +91,7 @@ private void handleDefaultCommand(Player player, String[] args) {
}
String status = Arrays.stream(args, 1, args.length).collect(Collectors.joining(" "));
if (statusManager.setStatus(target, status, player)) {
player.sendMessage("Set " + target.getName() + "'s status to: " + ChatColor.translateAlternateColorCodes('&', status));
player.sendMessage("Set " + target.getName() + "'s status to: " + ColourUtils.format(status));
}
return;
}
Expand All @@ -97,13 +104,14 @@ private void handleDefaultCommand(Player player, String[] args) {
}
String status = String.join(" ", args);
if (statusManager.setStatus(player, status, player)) {
player.sendMessage("Your status has been set to: " + "[" + status + "]");
player.sendMessage("Your status has been set to: " + "[" + ColourUtils.format(statusManager.getStatus(player)) + ChatColor.RESET + "]");
}

}
private void reloadPlugin(Player sender) {
if (!sender.hasPermission("StatusPlugin.admin.reload")) {
sender.sendMessage(ChatColor.RED + "You don't have permission to reload statuses.");
return;
}
statusManager.reloadStatuses();
sender.sendMessage("Statuses have been reloaded.");
Expand Down Expand Up @@ -148,6 +156,7 @@ private void displayColorCodes(CommandSender sender, StatusPlugin plugin) {
private void setmaxlenghtCommand(Player sender, String[] args) {
if (!sender.hasPermission("StatusPlugin.admin.setMaxlength")) {
sender.sendMessage(ChatColor.RED + "You don't have permission to set the maximum status length.");
return;
}
if (args.length == 2) {
try {
Expand All @@ -164,24 +173,40 @@ private void setmaxlenghtCommand(Player sender, String[] args) {
private void resetmaxlenghtCommand(Player sender) {
if (!sender.hasPermission("StatusPlugin.admin.resetMaxlength")) {
sender.sendMessage(ChatColor.RED + "You don't have permission to reset the maximum status length.");
return;
}
statusManager.resetMaxStatusLength();
sender.sendMessage(ChatColor.GREEN + "Max status length reset to default.");
}
public void infoCommand(Player sender, StatusPlugin plugin){
plugin.sendPluginMessages(sender, "title");
if(!(plugin == null)) {
plugin.sendPluginMessages(sender, "title");
}else {
sender.sendMessage(ChatColor.GOLD + "◢◤" + ChatColor.YELLOW + "Tu" + ChatColor.DARK_GREEN + "b's" + ChatColor.DARK_AQUA + " Status" + ChatColor.GOLD + " Plugin" + ChatColor.YELLOW + "◥◣");
}
sender.sendMessage(ChatColor.GREEN + "Author: TubYoub");
sender.sendMessage(ChatColor.GREEN + "Version: 1.2");
sender.sendMessage(ChatColor.GREEN + "Version: " + version);

if (VersionChecker.isNewVersionAvailable(version)) {
sender.sendMessage(ChatColor.YELLOW + "A new version is available! Update at: " + ChatColor.UNDERLINE + "https://modrinth.com/plugin/tubs-status-plugin/version/latest");
}else{
sender.sendMessage(ChatColor.GREEN + "You are using the latest version!");
}
TextComponent githubLink = new TextComponent(ChatColor.DARK_GRAY + "" + ChatColor.UNDERLINE + "GitHub");
githubLink.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://github.com/TubYoub/StatusPlugin"));
githubLink.setUnderlined(true);
sender.spigot().sendMessage(githubLink);

sender.sendMessage(ChatColor.BLUE + "" + ChatColor.UNDERLINE + "Discord" + ChatColor.RESET + " is coming soon! (Maybe)");
sender.sendMessage("If you have any issues please report them on GitHub.");

plugin.sendPluginMessages(sender, "line");
if (!(plugin == null)) {
plugin.sendPluginMessages(sender, "line");
}else {
sender.sendMessage(ChatColor.GOLD + "-" + ChatColor.YELLOW + "-" + ChatColor.GREEN + "-" + ChatColor.DARK_GREEN + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_AQUA + "-"
+ ChatColor.GOLD + "-" + ChatColor.YELLOW + "-" + ChatColor.GREEN + "-" + ChatColor.DARK_GREEN + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_AQUA + "-"
+ ChatColor.GOLD + "-" + ChatColor.YELLOW + "-" + ChatColor.GREEN + "-" + ChatColor.DARK_GREEN + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_AQUA + "-"
+ ChatColor.GOLD + "-");
}
}
private void removeOwnStatus(Player player) {
if (!player.hasPermission("StatusPlugin.setStatus")) {
Expand Down
Loading

0 comments on commit 71713da

Please sign in to comment.