-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
Showing
13 changed files
with
739 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 43 additions & 14 deletions
57
src/main/java/de/tubyoub/statusplugin/Listener/ChatListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/main/java/de/tubyoub/statusplugin/Managers/ConfigManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.