Skip to content

Commit

Permalink
Merge pull request #5 from BT-Pluginz/v1.4
Browse files Browse the repository at this point in the history
V1.4
  • Loading branch information
TubYoub authored Sep 3, 2024
2 parents f10be42 + 078e993 commit 13e237f
Show file tree
Hide file tree
Showing 12 changed files with 257 additions and 34 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
![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)
![Static Badge](https://img.shields.io/badge/MC-1.21-green)
![Modrinth Downloads](https://img.shields.io/modrinth/dt/km0yAITg?logo=Modrinth&style=flat-square)


Expand Down Expand Up @@ -41,10 +42,14 @@ This is a Minecraft plugin for Spigot/Paper servers that allows players to set t
- The Plugin got Placeholders:
- `%tubsstatusplugin_status_playername%` (playname should be changed out for the real Playername, Duuuh.)
- `%tubsstatusplugin_status%`
- Groupmode
- turn on Group Mode in the Config and preconfigure set Groups for Players
- A Player will not be able to set a fully custom status but he can use one of the preconfigured Groups.

## Permissions

- `StatusPlugin.setStatus`: Allows a player to set their own status and remove it. (default: `true`)
- `StatusPlugin.group.set`: Allows players to set their status as a group status. (default: `true`)
- `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`)
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.5</version>
<version>1.4</version>
<packaging>jar</packaging>

<name>Tub's Status Plugin</name>
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/de/tubyoub/statusplugin/Listener/ChatListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.tubyoub.statusplugin.Managers.ConfigManager;
import de.tubyoub.statusplugin.Managers.StatusManager;
import de.tubyoub.statusplugin.StatusPlugin;
import de.tubyoub.utils.ColourUtils;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Bukkit;
Expand All @@ -18,15 +19,15 @@
public class ChatListener implements Listener {
private final StatusManager statusManager;
private final ConfigManager configManager;
private final StatusPlugin plugin;

/**
* Constructor for the ChatListener class.
* @param statusManager The StatusManager instance used to manage player statuses.
* @param configManager The ConfigManager instance used to manage the plugin configuration.
*/
public ChatListener(StatusManager statusManager, ConfigManager configManager) {
this.statusManager = statusManager;
this.configManager = configManager;
public ChatListener(StatusPlugin plugin) {
this.plugin = plugin;
this.statusManager = plugin.getStatusManager();
this.configManager = plugin.getConfigManager();
}

/**
Expand All @@ -45,7 +46,9 @@ public void onPlayerChat(PlayerChatEvent event) {

// Translate the player's status and add placeholders
String status = statusManager.translateColorsAndFormatting(statusManager.getStatus(player),player);
status = PlaceholderAPI.setPlaceholders(player, status);
if (plugin.isPlaceholderAPIPresent()) {
status = PlaceholderAPI.setPlaceholders(player, status);
}

// Format the broadcast message
String broadcastMessage;
Expand Down
53 changes: 42 additions & 11 deletions src/main/java/de/tubyoub/statusplugin/Managers/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class ConfigManager {
private YamlDocument config;
private int maxStatusLength;
private boolean chatFormatter;
private boolean tablistFormatter;
private boolean groupMode;
private Map<String, String> statusGroups;
private final StatusPlugin plugin;

public ConfigManager(StatusPlugin plugin) {
Expand All @@ -30,47 +34,60 @@ public void loadConfig() {
GeneralSettings.DEFAULT,
LoaderSettings.builder().setAutoUpdate(true).build(),
DumperSettings.DEFAULT,

UpdaterSettings.builder().setVersioning(new BasicVersioning("fileversion"))
.setOptionSorting(UpdaterSettings.OptionSorting.SORT_BY_DEFAULTS).build());

maxStatusLength = config.getInt("maxStatusLength", 15);
chatFormatter = config.getBoolean("chatFormatter", true);
tablistFormatter = config.getBoolean("changeTablistNames", true);
groupMode = config.getBoolean("groupMode", false);
loadStatusGroups();
} catch (IOException e) {
plugin.getLogger().severe("Could not load configuration: " + e.getMessage());
}
}

private void loadStatusGroups() {
statusGroups = new HashMap<>();
if (config.contains("statusGroups")) {
for (Object key : config.getSection("statusGroups").getKeys()) {
String groupName = key.toString();
String status = config.getString("statusGroups." + groupName + ".status");
statusGroups.put(groupName, status);
}
}
}

public void saveConfig() {
try {
config.save();
} catch (IOException e) {
plugin.getLogger().severe("Could not save configuration: " + e.getMessage());
}
}
public boolean isTablistFormatter(){

public boolean isTablistFormatter() {
return tablistFormatter;
}
public void setTablistFormatter(boolean tablistFormatter){
if (this.tablistFormatter == tablistFormatter){
return;
}else {

public void setTablistFormatter(boolean tablistFormatter) {
if (this.tablistFormatter != tablistFormatter) {
this.tablistFormatter = tablistFormatter;
config.set("changeTablistNames", tablistFormatter);
}
}
public boolean isChatFormatter(){

public boolean isChatFormatter() {
return chatFormatter;
}
public void setChatFormatter(boolean chatFormatter){
if (this.chatFormatter == chatFormatter){
return;
}else {

public void setChatFormatter(boolean chatFormatter) {
if (this.chatFormatter != chatFormatter) {
this.chatFormatter = chatFormatter;
config.set("chatFormatter", chatFormatter);
}
}

public int getMaxStatusLength() {
return maxStatusLength;
}
Expand All @@ -87,6 +104,20 @@ public void resetMaxStatusLength() {
saveConfig();
}

public boolean isGroupMode() {
return groupMode;
}

public void setGroupMode(boolean groupMode) {
this.groupMode = groupMode;
config.set("groupMode", groupMode);
saveConfig();
}

public Map<String, String> getStatusGroups() {
return statusGroups;
}

public void reloadConfig() {
loadConfig();
}
Expand Down
39 changes: 36 additions & 3 deletions src/main/java/de/tubyoub/statusplugin/Managers/StatusManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class StatusManager {
*/
public StatusManager(StatusPlugin plugin) {
this.plugin = plugin;
this.placeholderAPIPresent = Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
this.placeholderAPIPresent = plugin.isPlaceholderAPIPresent();
this.configManager = plugin.getConfigManager();
maxStatusLength = configManager.getMaxStatusLength();
this.statusFile = new File(plugin.getDataFolder(), "statuses.yml");
Expand All @@ -54,7 +54,12 @@ public StatusManager(StatusPlugin plugin) {
* @return A boolean indicating whether the status was set successfully.
*/
public boolean setStatus(Player player, String status, CommandSender sender) {
if (status.contains("&_")){
if (configManager.isGroupMode() && !sender.hasPermission("StatusPlugin.admin.setStatus")) {
sender.sendMessage(ChatColor.RED + "Group mode is enabled. Use /status group <groupname> to set your status.");
return false;
}

if (status.contains("&_")) {
status = status.replace("&_", " ");
}
String translatedStatus = translateColorsAndFormatting(status, sender);
Expand All @@ -63,7 +68,27 @@ public boolean setStatus(Player player, String status, CommandSender sender) {
return false;
}

// Store the original status, not the translated one
statusMap.put(player.getUniqueId(), status);
if (configManager.isTablistFormatter()) {
updateDisplayName(player);
}
saveStatuses();
return true;
}

public boolean setGroupStatus(Player player, String groupName) {
Map<String, String> statusGroups = configManager.getStatusGroups();
if (!statusGroups.containsKey(groupName)) {
player.sendMessage(ChatColor.RED + "Invalid group name.");
return false;
}

if (!player.hasPermission("StatusPlugin.group.set" + groupName)) {
player.sendMessage(plugin.getPluginPrefix() + ChatColor.RED + "You don't have permission to use this status group.");
return false;
}

String status = statusGroups.get(groupName);
statusMap.put(player.getUniqueId(), status);
if (configManager.isTablistFormatter()) {
updateDisplayName(player);
Expand Down Expand Up @@ -223,6 +248,14 @@ public int calculateEffectiveLength(String text) {
return withoutColorCodesAndPlaceholders.length();
}

public boolean isGroupMode() {
return configManager.isGroupMode();
}

public Map<String, String> getStatusGroups() {
return configManager.getStatusGroups();
}

/**
* Reloads the statuses from the status file into the status map.
*/
Expand Down
22 changes: 17 additions & 5 deletions src/main/java/de/tubyoub/statusplugin/StatusPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import de.tubyoub.statusplugin.Listener.PlayerJoinListener;
import de.tubyoub.statusplugin.Managers.ConfigManager;
import de.tubyoub.statusplugin.Managers.StatusManager;
import de.tubyoub.statusplugin.commands.GroupCommand;
import de.tubyoub.statusplugin.commands.StatusCommand;
import de.tubyoub.statusplugin.commands.tabCompleter.GroupTabCompleter;
import de.tubyoub.statusplugin.commands.tabCompleter.StatusTabCompleter;
import de.tubyoub.utils.VersionChecker;
import de.tubyoub.statusplugin.metrics.Metrics;
import org.bukkit.Bukkit;
Expand All @@ -13,15 +16,17 @@
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.ArrayList;

/**
* Main class for the StatusPlugin.
* This class extends JavaPlugin and represents the main entry point for the plugin.
*/
public class StatusPlugin extends JavaPlugin {
private final String version = "1.3.5";
private final String version = "1.4";
private StatusManager statusManager;
private VersionChecker versionChecker;
//private boolean placeholderAPIPresent;
private boolean placeholderAPIPresent = false;
private ConfigManager configManager;
private StatusPlaceholderExpansion placeholderExpansion;
private boolean newVersion;
Expand Down Expand Up @@ -51,12 +56,16 @@ public void onEnable() {

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

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

GroupCommand groupCommand = new GroupCommand(this);
getCommand("group").setExecutor(groupCommand);
getCommand("group").setTabCompleter(new GroupTabCompleter(this));

// Initialize the Metrics
Metrics metrics = new Metrics(this, pluginId);
Expand All @@ -65,6 +74,7 @@ public void onEnable() {
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
placeholderExpansion = new StatusPlaceholderExpansion(this);
placeholderExpansion.register();
placeholderAPIPresent = true;
getLogger().info("Tub's StatusPlugin will now use PlaceholderAPI");
} else {
getLogger().warning("Could not find PlaceholderAPI! Tub's StatusPlugin will run without it..");
Expand Down Expand Up @@ -97,7 +107,6 @@ public void sendPluginMessages(CommandSender sender, String type) {
+ ChatColor.GOLD + "-");
}
}

/**
* Method to get the plugin prefix.
* @return The plugin prefix.
Expand All @@ -122,6 +131,9 @@ public StatusManager getStatusManager(){
return statusManager;
}

public boolean isPlaceholderAPIPresent() {
return placeholderAPIPresent;
}
/**
* This method is called when the plugin is disabled.
* It saves the statuses.
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/de/tubyoub/statusplugin/commands/GroupCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package de.tubyoub.statusplugin.commands;

import de.tubyoub.statusplugin.Managers.StatusManager;
import de.tubyoub.statusplugin.StatusPlugin;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class GroupCommand implements CommandExecutor {
private final StatusManager statusManager;
private final StatusPlugin plugin;

public GroupCommand(StatusPlugin plugin) {
this.statusManager = plugin.getStatusManager();
this.plugin = plugin;
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(plugin.getPluginPrefix() + " This command can only be run by a player.");
return true;
}

Player player = (Player) sender;

if (!statusManager.isGroupMode()) {
player.sendMessage(plugin.getPluginPrefix() + ChatColor.RED + " Group mode is not enabled.");
return true;
}

if (args.length != 1) {
player.sendMessage(plugin.getPluginPrefix() + ChatColor.RED + " Usage: /" + command.getName() + " <groupname>");
return true;
}

String groupName = args[0];
if (statusManager.setGroupStatus(player, groupName)) {
player.sendMessage(plugin.getPluginPrefix() + ChatColor.GREEN + " Your status has been set to the " + groupName + " group.");
}

return true;
}
}
Loading

0 comments on commit 13e237f

Please sign in to comment.