Skip to content

Commit

Permalink
Merge pull request #4 from TubYoub/dev
Browse files Browse the repository at this point in the history
Version 1.3.5
  • Loading branch information
TubYoub authored Apr 21, 2024
2 parents 7448bb5 + 4ffac14 commit f10be42
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 35 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,18 @@
![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)
![Modrinth Downloads](https://img.shields.io/modrinth/dt/km0yAITg?logo=Modrinth&style=flat-square)

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

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

<p align="center">
<a href="https://discord.tubyoub.de">
<img src="https://i.imgur.com/JgDt1Fl.png" width="300">
</a>
<br/>
<i>Please join the Discord if you have questions!</i>
</p>


This is a Minecraft plugin for Spigot/Paper servers that allows players to set their own status, which is displayed in the tab list and above their heads in-game.
Expand All @@ -28,7 +38,9 @@ This is a Minecraft plugin for Spigot/Paper servers that allows players to set t
- 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.
- The Plugin now got a Placeholder`%tubsstatusplugin_status_playername%` (playname should be changed out for the real Playername, Duuuh.)
- The Plugin got Placeholders:
- `%tubsstatusplugin_status_playername%` (playname should be changed out for the real Playername, Duuuh.)
- `%tubsstatusplugin_status%`

## Permissions

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>de.tubyoub</groupId>
<artifactId>StatusPlugin</artifactId>
<version>1.3.3</version>
<version>1.3.5</version>
<packaging>jar</packaging>

<name>Tub's Status Plugin</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.tubyoub.statusplugin.Listener;

import de.tubyoub.statusplugin.Managers.StatusManager;
import de.tubyoub.statusplugin.StatusPlugin;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand All @@ -12,13 +13,14 @@
*/
public class PlayerJoinListener implements Listener {
private final StatusManager statusManager;

private final StatusPlugin plugin;
/**
* Constructor for the PlayerJoinListener class.
* @param statusManager The StatusManager instance used to manage player statuses.
*/
public PlayerJoinListener(StatusManager statusManager) {
public PlayerJoinListener(StatusPlugin plugin, StatusManager statusManager) {
this.statusManager = statusManager;
this.plugin = plugin;
}

/**
Expand All @@ -28,7 +30,9 @@ public PlayerJoinListener(StatusManager statusManager) {
*/
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
statusManager.updateDisplayName(player);
if (plugin.getConfigManager().isTablistFormatter()) {
Player player = event.getPlayer();
statusManager.updateDisplayName(player);
}
}
}
15 changes: 13 additions & 2 deletions src/main/java/de/tubyoub/statusplugin/Managers/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ConfigManager {
private YamlDocument config;
private int maxStatusLength;
private boolean chatFormatter;
private boolean changeTabListNames;
private boolean tablistFormatter;
private final StatusPlugin plugin;

public ConfigManager(StatusPlugin plugin) {
Expand All @@ -36,6 +36,7 @@ public void loadConfig() {

maxStatusLength = config.getInt("maxStatusLength", 15);
chatFormatter = config.getBoolean("chatFormatter", true);
tablistFormatter = config.getBoolean("changeTablistNames", true);
} catch (IOException e) {
plugin.getLogger().severe("Could not load configuration: " + e.getMessage());
}
Expand All @@ -48,7 +49,17 @@ public void saveConfig() {
plugin.getLogger().severe("Could not save configuration: " + e.getMessage());
}
}

public boolean isTablistFormatter(){
return tablistFormatter;
}
public void setTablistFormatter(boolean tablistFormatter){
if (this.tablistFormatter == tablistFormatter){
return;
}else {
this.tablistFormatter = tablistFormatter;
config.set("changeTablistNames", tablistFormatter);
}
}
public boolean isChatFormatter(){
return chatFormatter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ public boolean setStatus(Player player, String status, CommandSender sender) {

// Store the original status, not the translated one
statusMap.put(player.getUniqueId(), status);
updateDisplayName(player);
if (configManager.isTablistFormatter()) {
updateDisplayName(player);
}
saveStatuses();
return true;
}
Expand All @@ -76,7 +78,10 @@ public boolean setStatus(Player player, String status, CommandSender sender) {
* @return The status of the player.
*/
public String getStatus(Player player) {
return statusMap.get(player.getUniqueId());
if (statusMap.containsKey(player.getUniqueId())){
return statusMap.get(player.getUniqueId());
}
return "";
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import java.util.Objects;

/**
* This class extends PlaceholderExpansion from the PlaceholderAPI.
* It provides a way to register and use placeholders related to the StatusPlugin.
Expand Down Expand Up @@ -73,10 +75,12 @@ public String getVersion(){
*/
@Override
public String onPlaceholderRequest(Player player, String identifier){

if(player == null){
return "";
}
if (Objects.equals(identifier, "status")){
return plugin.getStatusManager().getStatus(player);
}

// %tubsstatusplugin_status_playername%
String[] parts = identifier.split("_");
Expand Down
23 changes: 13 additions & 10 deletions src/main/java/de/tubyoub/statusplugin/StatusPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import de.tubyoub.statusplugin.Managers.ConfigManager;
import de.tubyoub.statusplugin.Managers.StatusManager;
import de.tubyoub.statusplugin.commands.StatusCommand;
import de.tubyoub.statusplugin.commands.VersionChecker;
import de.tubyoub.utils.VersionChecker;
import de.tubyoub.statusplugin.metrics.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
Expand All @@ -18,12 +18,13 @@
* This class extends JavaPlugin and represents the main entry point for the plugin.
*/
public class StatusPlugin extends JavaPlugin {
private final String version = "1.3.3";
private final String version = "1.3.5";
private StatusManager statusManager;
private VersionChecker versionChecker;
//private boolean placeholderAPIPresent;
private ConfigManager configManager;
private StatusPlaceholderExpansion placeholderExpansion;
private boolean newVersion;
private int pluginId = 20463;

/**
Expand All @@ -46,13 +47,14 @@ public void onEnable() {
// Initialize the StatusManager and VersionChecker
this.statusManager = new StatusManager(this);
this.versionChecker = new VersionChecker();
newVersion = VersionChecker.isNewVersionAvailable(version);

// Register the PlayerJoinListener and ChatListener
getServer().getPluginManager().registerEvents(new PlayerJoinListener(this.statusManager), this);
getServer().getPluginManager().registerEvents(new PlayerJoinListener(this ,this.statusManager), this);
getServer().getPluginManager().registerEvents(new ChatListener(this.statusManager, configManager), this);

// Set the executor and tab completer for the "status" command
StatusCommand statusCommand = new StatusCommand(statusManager,versionChecker,version);
StatusCommand statusCommand = new StatusCommand(statusManager,newVersion,version);
getCommand("status").setExecutor(statusCommand);
getCommand("status").setTabCompleter(new StatusTabCompleter());

Expand All @@ -69,12 +71,13 @@ public void onEnable() {
}

// Schedule a task to update the display name of online players every 30 seconds
Bukkit.getScheduler().runTaskTimer(this, () -> {
for (Player player : Bukkit.getOnlinePlayers()) {
statusManager.updateDisplayName(player);
}
}, 0L, 600L); // 600 ticks = 30 seconds

if (configManager.isTablistFormatter()) {
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");
getLogger().warning(String.valueOf(this.getConfig()));
}
Expand Down
35 changes: 28 additions & 7 deletions src/main/java/de/tubyoub/statusplugin/commands/StatusCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import de.tubyoub.statusplugin.Managers.StatusManager;
import de.tubyoub.statusplugin.StatusPlugin;
import de.tubyoub.utils.ColourUtils;
import de.tubyoub.utils.VersionChecker;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
Expand All @@ -21,19 +22,19 @@
public class StatusCommand implements CommandExecutor {
String version;
private final StatusManager statusManager;
private final VersionChecker versionChecker;
private final boolean newVersion;
private StatusPlugin plugin;

/**
* Constructor for the StatusCommand class.
*
* @param statusManager The StatusManager instance used to manage player statuses.
* @param versionChecker The VersionChecker instance used to check for new versions.
* @param newVersion If the plugin has a new Version..
* @param version The current version of the plugin.
*/
public StatusCommand(StatusManager statusManager, VersionChecker versionChecker, String version) {
public StatusCommand(StatusManager statusManager, boolean newVersion, String version) {
this.statusManager = statusManager;
this.versionChecker = versionChecker;
this.newVersion = newVersion;
this.version = version;
}

Expand Down Expand Up @@ -171,9 +172,29 @@ private void helpCommand(Player sender, StatusPlugin plugin, String[] args) {
} else {
plugin.sendPluginMessages(sender, "title");
sender.sendMessage("Here you can see all available commands:");
// The rest of the code is self-explanatory and does not need documentation.
plugin.sendPluginMessages(sender, "title");
sender.sendMessage("Here you can see all available commands:");
sender.sendMessage("/status <status> - Set your own status.");
sender.sendMessage("/status remove - Remove your Status.");
sender.sendMessage("/status help colorcodes - Get all colorcodes to use in your status.");
if (sender.hasPermission("StatusPlugin.admin.setStatus")) {
sender.sendMessage("/status remove <player> - Remove a player's status. (Admin)");
sender.sendMessage("/status <player> <status> - Set a player's status. (Admin)");
}
sender.sendMessage("/status help colors - Show a list of color codes.");
if (sender.hasPermission("StatusPlugin.admin.reload")) {
sender.sendMessage("/status reload - Reload all statuses. (Admin)");
}
if (sender.hasPermission("StatusPlugin.admin.setMaxlength")) {
sender.sendMessage("/status setmaxlength <length> - Set the max length of status. (Admin)");
}
if (sender.hasPermission("StatusPlugin.admin.resetMaxlength")) {
sender.sendMessage("/status resetmaxlength - Reset the max length of status to default. (Admin)");
}
sender.sendMessage("/status info - Show info about the plugin.");
plugin.sendPluginMessages(sender, "line");
}
}
}

/**
* Displays the available color and formatting codes to the sender.
Expand Down Expand Up @@ -248,7 +269,7 @@ public void infoCommand(Player sender, StatusPlugin plugin) {
sender.sendMessage(ChatColor.GREEN + "Author: TubYoub");
sender.sendMessage(ChatColor.GREEN + "Version: " + version);

if (VersionChecker.isNewVersionAvailable(version)) {
if (newVersion) {
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!");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package de.tubyoub.statusplugin.commands;
package de.tubyoub.utils;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import com.google.gson.JsonParser;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
Expand All @@ -10,8 +12,6 @@
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.core.type.TypeReference;

/**
* Class responsible for checking if a new version of the plugin is available.
Expand Down
7 changes: 5 additions & 2 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
# by TubYoub #
################################
# Don't change this value, it's changed by the plugin if needed
fileversion: 1
fileversion: 2

# maximum Character length a Status should be allowed to have.
# default: 15
maxStatusLength: 15
# If the Chat formatter should be enabled (so the Plugin sends Messages with the Status in front of the Player name and formats colors).
# default: true
chatFormatter: true
chatFormatter: true
# If the Tablist name should be changed by the plugin or not. (restart your server so the changes will work correctly)
# default: true
changeTablistNames: true

0 comments on commit f10be42

Please sign in to comment.