Skip to content

Commit

Permalink
Version 1.3.2
Browse files Browse the repository at this point in the history
[bugfix]
/
[changes]
- Changed the Package from StatusManager.java to Managers.StatusManager.
- Every Status gets reloaded every 30 Seconds
- Player statuses will be saved untranslated to accemendate the the Placeholders
[addition]
- Placeholder v2.11.5 is now supported

PS: Report any Problems
PPS: Thanks Rob for the Feature request
  • Loading branch information
TubYoub committed Apr 1, 2024
1 parent e56da6b commit f758ae0
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 57 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ This is a Minecraft plugin for Spigot/Paper servers that allows players to set t
- Reset the maximum length of statuses to default (`15`) with `/status resetmaxlength` (requires StatusPlugin.admin.resetMaxlength permission)
(Color codes in statuses are not counted towards the character limit)
- The status of every player is saved to a file, so they will keep their status when they rejoin the server.
- The Plugin supports `PlaceholderAPI v2.11.5`
- The Plugin reloads statuses every 600 Game Ticks (30seconds) so the Placeholders can update themselves.

## Permissions

Expand Down Expand Up @@ -57,6 +59,6 @@ I currently have no plans to get co-contributer's on this project, but if you ha

## License

This project is licensed under the [Unlicense](LICENSE).
This project is licensed under the [MIT License](LICENSE).

[![forthebadge](https://forthebadge.com/images/badges/powered-by-black-magic.svg)](https://forthebadge.com)
37 changes: 30 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>de.tubyoub</groupId>
<artifactId>StatusPlugin</artifactId>
<version>1.3.1</version>
<version>1.3.2</version>
<packaging>jar</packaging>

<name>Tub's Status Plugin</name>
Expand All @@ -30,24 +30,37 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<version>3.4.1</version>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.MF</exclude>
</excludes>
</filter>
</filters>
<createDependencyReducedPom>true</createDependencyReducedPom>
<outputFile>D:\papermc\plugins\TubsStatusPlugin-v${project.version}.jar</outputFile>
<outputFile>target\TubsStatusPlugin-v${project.version}.jar</outputFile>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<outputFile>D:\papermc\plugins\TubsStatusPlugin-v${project.version}.jar</outputFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>${project.basedir}/src/main/java</directory>
<filtering>true</filtering>
</resource>
</resources>
Expand All @@ -62,6 +75,10 @@
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -76,5 +93,11 @@
<artifactId>jackson-databind</artifactId>
<version>2.16.0</version>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.5</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.tubyoub.statusplugin.Listener;

import de.tubyoub.statusplugin.StatusManager;
import de.tubyoub.statusplugin.Managers.StatusManager;
import de.tubyoub.utils.ColourUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.tubyoub.statusplugin.Listener;

import de.tubyoub.statusplugin.StatusManager;
import de.tubyoub.statusplugin.Managers.StatusManager;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package de.tubyoub.statusplugin;
package de.tubyoub.statusplugin.Managers;

import de.tubyoub.statusplugin.StatusPlugin;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
Expand All @@ -25,9 +28,11 @@ public class StatusManager {
private int maxStatusLength = DEFAULT_MAX_LENGTH;
private final StatusPlugin plugin;
private ColourUtils chatColour;
private final boolean placeholderAPIPresent;

public StatusManager(StatusPlugin plugin) {
this.plugin = plugin;
this.placeholderAPIPresent = Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
this.maxStatusLength = plugin.getConfig().getInt("maxStatusLength", DEFAULT_MAX_LENGTH);
this.statusFile = new File(plugin.getDataFolder(), "statuses.yml");
loadStatuses();
Expand All @@ -39,30 +44,35 @@ public boolean setStatus(Player player, String status, CommandSender sender) {
sender.sendMessage(ChatColor.RED + "Status is too long. Max length is " + maxStatusLength + " characters.");
return false;
}
statusMap.put(player.getUniqueId(), translatedStatus);

// Store the original status, not the translated one
statusMap.put(player.getUniqueId(), status);
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();
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());
String status = getStatus(player);
if (status != null) {
// Translate the status here
String translatedStatus = translateColorsAndFormatting(status, player);
if (placeholderAPIPresent && player.hasPermission("StatusPlugin.placeholders")) {
translatedStatus = PlaceholderAPI.setPlaceholders(player, translatedStatus);
}
String displayName = "[" + translatedStatus + ChatColor.RESET + "] " + ChatColor.WHITE + player.getName();
displayName = ColourUtils.format(displayName); // Assign the result back to displayName
player.setDisplayName(displayName);
player.setPlayerListName(displayName);
} else {
player.setDisplayName(player.getName());
player.setPlayerListName(player.getName());
}
}
}
public int getMaxStatusLength() {
return maxStatusLength;
}
Expand Down Expand Up @@ -132,11 +142,11 @@ public void removeStatus(Player player) {
player.setPlayerListName(player.getName());
saveStatuses();
}
public int calculateEffectiveLength(String text) {
Pattern pattern = Pattern.compile("&[0-9a-fk-or]");
public int calculateEffectiveLength(String text) {
Pattern pattern = Pattern.compile("&[0-9a-fk-or]|%[^%]+%");
Matcher matcher = pattern.matcher(text);
String withoutColorCodes = matcher.replaceAll("");
return withoutColorCodes.length();
String withoutColorCodesAndPlaceholders = matcher.replaceAll("");
return withoutColorCodesAndPlaceholders.length();
}
public void reloadStatuses() {
statusMap.clear();
Expand Down
33 changes: 31 additions & 2 deletions src/main/java/de/tubyoub/statusplugin/StatusPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,61 @@

import de.tubyoub.statusplugin.Listener.ChatListener;
import de.tubyoub.statusplugin.Listener.PlayerJoinListener;
import de.tubyoub.statusplugin.Managers.StatusManager;
import de.tubyoub.statusplugin.commands.StatusCommand;
import de.tubyoub.statusplugin.commands.VersionChecker;
import de.tubyoub.statusplugin.metrics.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

public class StatusPlugin extends JavaPlugin {
private final String version = "1.3.2";
private StatusManager statusManager;
private VersionChecker versionChecker;
//private boolean placeholderAPIPresent;
private int pluginId = 20463;

@Override
public void onEnable() {
getLogger().info( "______________________________");
getLogger().info("\\__ ___/ _____/\\______ \\");
getLogger().info( " | | \\_____ \\ | ___/");
getLogger().info( " | | / \\ | |");
getLogger().info( " |____| /_______ / |____|" + " TubsStatusPlugin v"+ version);
getLogger().info( " \\/ "+ " Running on " + Bukkit.getServer().getName() + " using Blackmagic");
this.statusManager = new StatusManager(this);
this.saveDefaultConfig();
this.versionChecker = new VersionChecker();
getServer().getPluginManager().registerEvents(new PlayerJoinListener(this.statusManager), this);
getServer().getPluginManager().registerEvents(new ChatListener(this.statusManager), this);
StatusCommand statusCommand = new StatusCommand(statusManager,versionChecker);
getCommand("status").setExecutor(new StatusCommand(this.statusManager,versionChecker));
StatusCommand statusCommand = new StatusCommand(statusManager,versionChecker,version);
//getCommand("status").setExecutor(new StatusCommand(this.statusManager,versionChecker));
getCommand("status").setExecutor(statusCommand);
getCommand("status").setTabCompleter(new StatusTabCompleter());

Metrics metrics = new Metrics(this, pluginId);

if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
// new StatusPlaceholderExpansion(this).register();
//this.placeholderAPIPresent = Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
getLogger().info("Tub's StatusPlugin will now use PlaceholderAPI");
} else {
getLogger().warning("Could not find PlaceholderAPI! Tub's StatusPlugin will run without it..");
}


Bukkit.getScheduler().runTaskTimer(this, () -> {
for (Player player : Bukkit.getOnlinePlayers()) {
statusManager.updateDisplayName(player);
}
}, 0L, 600L); // 600 ticks = 30 seconds
getLogger().info("Tub's StatusPlugin successfully loaded");
}

public void sendPluginMessages(CommandSender sender, String type) {
if ("title".equals(type)) {
sender.sendMessage(ChatColor.GOLD + "◢◤" + ChatColor.YELLOW + "Tu" + ChatColor.DARK_GREEN + "b's" + ChatColor.DARK_AQUA + " Status" + ChatColor.GOLD + " Plugin" + ChatColor.YELLOW + "◥◣");
Expand Down
53 changes: 27 additions & 26 deletions src/main/java/de/tubyoub/statusplugin/commands/StatusCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.tubyoub.statusplugin.commands;

import de.tubyoub.statusplugin.StatusManager;
import de.tubyoub.statusplugin.Managers.StatusManager;
import de.tubyoub.statusplugin.StatusPlugin;
import de.tubyoub.utils.ColourUtils;
import net.md_5.bungee.api.chat.ClickEvent;
Expand All @@ -17,39 +17,40 @@



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

private final VersionChecker versionChecker;
private StatusPlugin plugin;
private final VersionChecker versionChecker;
private StatusPlugin plugin;

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

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
this.plugin = (StatusPlugin) Bukkit.getPluginManager().getPlugin("TubsStatusPlugin");

if (!(sender instanceof Player)) {
// Handle console commands here
if (args.length > 0 && "reload".equals(args[0])) {
statusManager.reloadStatuses();
sender.sendMessage("Statuses have been reloaded.");
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
this.plugin = (StatusPlugin) Bukkit.getPluginManager().getPlugin("TubsStatusPlugin");

if (!(sender instanceof Player)) {
// Handle console commands here
if (args.length > 0 && "reload".equals(args[0])) {
statusManager.reloadStatuses();
sender.sendMessage("Statuses have been reloaded.");
return true;
}
sender.sendMessage("This command can only be run by a player.");
return true;
}
sender.sendMessage("This command can only be run by a player.");
return true;
}

Player player = (Player) sender;
Player player = (Player) sender;

if (args.length == 0) {
player.sendMessage("Try using /status help");
return true;
}
if (args.length == 0) {
player.sendMessage("Try using /status help");
return true;
}

switch (args[0].toLowerCase()) {
case "reload":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
import com.fasterxml.jackson.core.type.TypeReference;

public class VersionChecker {
private static final String project = "km0yAITg";

public static boolean isNewVersionAvailable(String version) {
try {
URL url = new URL("https://api.modrinth.com/v2/project/km0yAITg/version");
URL url = new URL("https://api.modrinth.com/v2/project/" + project + "/version");

HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version: '${project.version}'
main: de.tubyoub.statusplugin.StatusPlugin
api-version: 1.13
author: TubYoub
softdepend: [PlaceholderAPI]
commands:
status:
description: Set a player's status, get info, get help, reload the plugin, set/reset max length
Expand Down Expand Up @@ -39,4 +40,7 @@ permissions:
default: op
StatusPlugin.formatting.italic:
description: Allows to use italic formatting in statuses
default: op
StatusPlugin.placeholders:
description: Allows players to use Placeholders from PlaceholderAPI
default: op

0 comments on commit f758ae0

Please sign in to comment.