Skip to content

Commit

Permalink
Version 1.3.3
Browse files Browse the repository at this point in the history
[bugfix]
- Config file got changed back after reloading the plugin with `/status reload`

[changes]
- Plugin messages will now have a `[TSP]` prefix at the start.
- Discord link added to the `/status info` command.
- ConfigManager got a new config
- config.yml is now at Version 1

[addition]
PlaceholderAPI:
- added a placeholder `%tubsstatusplugin_status_playername%`
Plugin:
- Chat Formatter can now be disabled in the config, so you can use custom Chat Plugins.
- Added version control for the config.yml
- Java Docs

PS: Report any Problems

Took 7 hours 45 minutes
  • Loading branch information
TubYoub committed Apr 13, 2024
1 parent f758ae0 commit 6e6c2c4
Show file tree
Hide file tree
Showing 13 changed files with 739 additions and 243 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This is a Minecraft plugin for Spigot/Paper servers that allows players to set t

- Set your own status with `/status <status>`
- Remove your status with `/status remove`
- Set status with formatting codes (for example to color them) with `/status &3<status>`
- Set status with formatting codes (for example to color them) with `/status &3<status> (/status help colorcodes)`
- 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` (requires `StatusPlugin.admin.reload` permission) (Can be executed by console)
Expand Down
15 changes: 8 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.2</version>
<version>1.3.3</version>
<packaging>jar</packaging>

<name>Tub's Status Plugin</name>
Expand Down Expand Up @@ -40,11 +40,11 @@
</excludes>
</filter>
</filters>
<createDependencyReducedPom>true</createDependencyReducedPom>
<createDependencyReducedPom>false</createDependencyReducedPom>
<outputFile>D:\papermc\plugins\TubsStatusPlugin-v${project.version}.jar</outputFile>
<outputFile>target\TubsStatusPlugin-v${project.version}.jar</outputFile>
</configuration>
<executions>
<executions>
<execution>
<phase>package</phase>
<goals>
Expand All @@ -59,10 +59,6 @@
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>${project.basedir}/src/main/java</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>

Expand Down Expand Up @@ -99,5 +95,10 @@
<version>2.11.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>dev.dejvokep</groupId>
<artifactId>boosted-yaml</artifactId>
<version>1.3.1</version>
</dependency>
</dependencies>
</project>
57 changes: 43 additions & 14 deletions src/main/java/de/tubyoub/statusplugin/Listener/ChatListener.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,63 @@
package de.tubyoub.statusplugin.Listener;

import de.tubyoub.statusplugin.Managers.ConfigManager;
import de.tubyoub.statusplugin.Managers.StatusManager;
import de.tubyoub.utils.ColourUtils;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChatEvent;

/**
* Class implementing the Listener interface to handle player chat events.
* When a player sends a chat message, the message is formatted based on the player's status.
*/
public class ChatListener implements Listener {
private final StatusManager statusManager;
public ChatListener(StatusManager statusManager) {
private final ConfigManager configManager;

/**
* 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;
}

/**
* Event handler for player chat events.
* When a player sends a chat message, the message is formatted based on the player's status.
* If the player has a status, it is added to the beginning of the message.
* If the player does not have a status, the message is sent as is.
* @param event The PlayerChatEvent to be handled.
*/
@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 (configManager.isChatFormatter()) {
// Get the player and message
Player player = event.getPlayer();
String message = event.getMessage();

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

// Format the broadcast message
String broadcastMessage;
if (status == null) {
broadcastMessage = player.getName() + ": " + message;
} else {
broadcastMessage = "[" + ColourUtils.format(status) + ChatColor.RESET + "] " + player.getName() + ": " + message;
}

if (status == null) {
broadcastMessage = player.getName() + ": " + message;
} else {
broadcastMessage = "[" + ColourUtils.format(status) + ChatColor.RESET + "] " + player.getName() + ": " + message;
// Broadcast the message and cancel the original event
Bukkit.broadcastMessage(broadcastMessage);
event.setCancelled(true);
}
Bukkit.broadcastMessage(broadcastMessage);
// Cancel the original event
event.setCancelled(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,29 @@
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;

/**
* Class implementing the Listener interface to handle player join events.
* When a player joins, their display name is updated based on their status.
*/
public class PlayerJoinListener implements Listener {
private final StatusManager statusManager;

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

@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
statusManager.updateDisplayName(player);
}

/**
* Event handler for player join events.
* When a player joins, their display name is updated based on their status.
* @param event The PlayerJoinEvent to be handled.
*/
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
statusManager.updateDisplayName(player);
}
}
82 changes: 82 additions & 0 deletions src/main/java/de/tubyoub/statusplugin/Managers/ConfigManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package de.tubyoub.statusplugin.Managers;

import de.tubyoub.statusplugin.StatusPlugin;
import dev.dejvokep.boostedyaml.YamlDocument;
import dev.dejvokep.boostedyaml.dvs.versioning.BasicVersioning;
import dev.dejvokep.boostedyaml.settings.dumper.DumperSettings;
import dev.dejvokep.boostedyaml.settings.general.GeneralSettings;
import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings;
import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings;

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

public class ConfigManager {
private YamlDocument config;
private int maxStatusLength;
private boolean chatFormatter;
private boolean changeTabListNames;
private final StatusPlugin plugin;

public ConfigManager(StatusPlugin plugin) {
this.plugin = plugin;
}

public void loadConfig() {
try {
config = YamlDocument.create(new File(plugin.getDataFolder(), "config.yml"),
Objects.requireNonNull(getClass().getResourceAsStream("/config.yml")),
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);
} catch (IOException e) {
plugin.getLogger().severe("Could not load configuration: " + e.getMessage());
}
}

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

public boolean isChatFormatter(){
return chatFormatter;
}
public void setChatFormatter(boolean chatFormatter){
if (this.chatFormatter == chatFormatter){
return;
}else {
this.chatFormatter = chatFormatter;
config.set("chatFormatter", chatFormatter);
}
}
public int getMaxStatusLength() {
return maxStatusLength;
}

public void setMaxStatusLength(int maxLength) {
this.maxStatusLength = maxLength;
config.set("maxStatusLength", maxLength);
saveConfig();
}

public void resetMaxStatusLength() {
this.maxStatusLength = 15;
config.set("maxStatusLength", 15);
saveConfig();
}

public void reloadConfig() {
loadConfig();
}
}
Loading

0 comments on commit 6e6c2c4

Please sign in to comment.