Skip to content

Commit

Permalink
v1.1 - Configuration Update!
Browse files Browse the repository at this point in the history
Added config.yml and a ingame way to reload it (/niceformat).
  • Loading branch information
Lukiiy committed Apr 3, 2024
1 parent 15c112b commit 00e78bf
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/main/java/me/lukiiy/niceformat/Chat.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import org.bukkit.event.player.PlayerListener;

public class Chat extends PlayerListener {

public void onPlayerChat(PlayerChatEvent e) {
e.setMessage(e.getMessage().replace('&', '§')); // Chat Colr
e.setFormat("%1$s: %2$s"); // Format
if (main.Color) e.setMessage(e.getMessage().replace('&', '§'));
e.setFormat(main.Format);
}
}
14 changes: 14 additions & 0 deletions src/main/java/me/lukiiy/niceformat/ReloadCMD.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package me.lukiiy.niceformat;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;

public class ReloadCMD implements CommandExecutor {
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
main.Plugin.config();
commandSender.sendMessage("§aNiceFormat Reload complete.");
return true;
}
}
20 changes: 19 additions & 1 deletion src/main/java/me/lukiiy/niceformat/main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,27 @@
import org.bukkit.plugin.java.JavaPlugin;

public class main extends JavaPlugin {
public static main Plugin;
public static boolean Color = true;
public static String Format = "%1$s: %2$s";

@Override
public void onEnable() {getServer().getPluginManager().registerEvent(Event.Type.PLAYER_CHAT, new Chat(), Event.Priority.Lowest, this);}
public void onEnable() {
Plugin = this;
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_CHAT, new Chat(), Event.Priority.Lowest, this);
getCommand("niceformat").setExecutor(new ReloadCMD());
config();
}

@Override
public void onDisable() {}

public void config() {
getConfiguration().load();
Color = getConfiguration().getBoolean("color", Color);
Format = getConfiguration().getString("format", Format)
.replace("(p)", "%1$s")
.replace("(msg)", "%2$s");
getConfiguration().save();
}
}
6 changes: 5 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
name: NiceFormat
version: '${project.version}'
main: me.lukiiy.niceformat.main
author: Lukiiy
author: Lukiiy
commands:
niceformat:
description: "Reloads the plugin"
permission: niceformat.reload

0 comments on commit 00e78bf

Please sign in to comment.