Skip to content

Commit ea9620e

Browse files
committed
rename
1 parent 7d18692 commit ea9620e

19 files changed

Lines changed: 949 additions & 58 deletions

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
![GitHub Release](https://img.shields.io/github/v/release/Cold-Development/ColdBroadcast?style=for-the-badge&logo=github&color=r0b07)
1+
![GitHub Release](https://img.shields.io/github/v/release/Cold-Development/HudActionbar?style=for-the-badge&logo=github&color=r0b07)
22

3-
## 👾 What is ColdBroadcast?
4-
**ColdBroadcast** is a Minecraft plugin that allows you to broadcast a custom message above player's action bar..<br>
3+
## 👾 What is HudActionbar?
4+
**HudActionbar** is a Minecraft plugin that allows you to broadcast a custom message above player's action bar..<br>
55
* This is a plugin based on `ColdDev` library.
66
* Multiple locales supported:
77
* `en_EN`
@@ -17,15 +17,15 @@
1717

1818
---
1919
## 🛡️ SUPPORT
20-
If you need any help with ColdBroadcast plugin, including any questions bugs or just chatting, join our [Discord server](https://discord.colddev.dev). Support is granted through Discord faster than anywhere else.
20+
If you need any help with HudActionbar plugin, including any questions bugs or just chatting, join our [Discord server](https://discord.colddev.dev). Support is granted through Discord faster than anywhere else.
2121

2222
---
2323
## 📈 Download & Installation
24-
1. Visit [GitHub release](https://github.com/Cold-Development/ColdBroadcast/releases) page.
24+
1. Visit [GitHub release](https://github.com/Cold-Development/HudActionbar/releases) page.
2525
2. Download the plugin.
2626
3. Put the `.jar` file in your `~/plugins` folder.
2727
4. Start up the server.<br>
28-
After finishing these steps, you should be able to see `~/plugins/ColdBroadcast` directory, which contains all files that may interest you.<br>
28+
After finishing these steps, you should be able to see `~/plugins/HudActionbar` directory, which contains all files that may interest you.<br>
2929

3030
---
3131
## 🤝 Dependencies

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
<modelVersion>4.0.0</modelVersion>
66
<groupId>org.padrewin</groupId>
7-
<artifactId>ColdBroadcast</artifactId>
7+
<artifactId>HudActionbar</artifactId>
88
<version>1.4</version>
99
<packaging>jar</packaging>
1010

11-
<name>ColdBroadcast</name>
11+
<name>HudActionbar</name>
1212

1313
<properties>
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -37,7 +37,7 @@
3737
<!-- Relocating dev.padrewin.coldplugin to avoid conflicts -->
3838
<relocation>
3939
<pattern>dev.padrewin.colddev</pattern>
40-
<shadedPattern>dev.padrewin.coldbroadcast.libs.coldplugin</shadedPattern>
40+
<shadedPattern>dev.padrewin.hudactionbar.libs.coldplugin</shadedPattern>
4141
</relocation>
4242
</relocations>
4343
</configuration>
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
package dev.padrewin.hudactionbar;
2+
3+
import dev.padrewin.hudactionbar.manager.CommandManager;
4+
import dev.padrewin.hudactionbar.manager.LocaleManager;
5+
import dev.padrewin.hudactionbar.setting.SettingKey;
6+
import dev.padrewin.colddev.ColdPlugin;
7+
import dev.padrewin.colddev.config.ColdSetting;
8+
import dev.padrewin.colddev.manager.Manager;
9+
import dev.padrewin.colddev.manager.PluginUpdateManager;
10+
import me.clip.placeholderapi.PlaceholderAPI;
11+
import net.md_5.bungee.api.ChatColor;
12+
import net.md_5.bungee.api.ChatMessageType;
13+
import net.md_5.bungee.api.chat.TextComponent;
14+
import org.bukkit.Bukkit;
15+
import org.bukkit.entity.Player;
16+
import org.bukkit.event.EventHandler;
17+
import org.bukkit.event.Listener;
18+
import org.bukkit.event.player.PlayerJoinEvent;
19+
import org.bukkit.scheduler.BukkitRunnable;
20+
import org.jetbrains.annotations.NotNull;
21+
22+
import java.io.File;
23+
import java.util.List;
24+
import java.util.regex.Matcher;
25+
import java.util.regex.Pattern;
26+
27+
public class HudActionbar extends ColdPlugin implements Listener {
28+
29+
/**
30+
* Console colors
31+
*/
32+
String ANSI_RESET = "\u001B[0m";
33+
String ANSI_GREEN = "\u001B[32m";
34+
String ANSI_YELLOW = "\u001B[33m";
35+
String ANSI_RED = "\u001B[31m";
36+
String ANSI_PURPLE = "\u001B[35m";
37+
String ANSI_AQUA = "\u001B[36m";
38+
39+
private static HudActionbar instance;
40+
private String actionBarMessage;
41+
42+
public HudActionbar() {
43+
super("Cold-Development", "HudActionbar", 23655, null, LocaleManager.class, null);
44+
instance = this;
45+
}
46+
47+
@Override
48+
public void enable() {
49+
instance = this;
50+
getManager(PluginUpdateManager.class);
51+
52+
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") == null) {
53+
getLogger().warning("PlaceholderAPI is not loaded. This plugin won't work properly.");
54+
getServer().getPluginManager().disablePlugin(this);
55+
return;
56+
}
57+
58+
String name = getDescription().getName();
59+
getLogger().info(ANSI_PURPLE + " ____ ___ _ ____ " + ANSI_RESET);
60+
getLogger().info(ANSI_AQUA + " / ___/ _ \\| | | _ \\ " + ANSI_RESET);
61+
getLogger().info(ANSI_PURPLE + "| | | | | | | | | | |" + ANSI_RESET);
62+
getLogger().info(ANSI_AQUA + "| |__| |_| | |___| |_| |" + ANSI_RESET);
63+
getLogger().info(ANSI_PURPLE + " \\____\\___/|_____|____/ " + ANSI_RESET);
64+
getLogger().info(" " + ANSI_GREEN + name + ANSI_RED + " v" + getDescription().getVersion() + ANSI_RESET);
65+
getLogger().info(ANSI_YELLOW + " Author(s): " + ANSI_YELLOW + getDescription().getAuthors().get(0) + ANSI_RESET);
66+
getLogger().info(ANSI_AQUA + " (c) Cold Development ❄" + ANSI_RESET);
67+
getLogger().info("");
68+
69+
File configFile = new File(getDataFolder(), "en_US.yml");
70+
if (!configFile.exists()) {
71+
saveDefaultConfig();
72+
}
73+
74+
saveDefaultConfig();
75+
loadConfig();
76+
getServer().getPluginManager().registerEvents(this, this);
77+
78+
new BukkitRunnable() {
79+
@Override
80+
public void run() {
81+
if (actionBarMessage == null) {
82+
return;
83+
}
84+
85+
for (Player player : getServer().getOnlinePlayers()) {
86+
String message = PlaceholderAPI.setPlaceholders(player, actionBarMessage);
87+
message = translateHexColorCodes(message);
88+
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));
89+
}
90+
}
91+
}.runTaskTimer(this, 0L, 20L);
92+
}
93+
94+
@Override
95+
public void disable() {
96+
getLogger().info("HudActionbar disabled.");
97+
}
98+
99+
@EventHandler
100+
public void onPlayerJoin(PlayerJoinEvent event) {
101+
Player player = event.getPlayer();
102+
103+
if (actionBarMessage == null) {
104+
return;
105+
}
106+
107+
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
108+
String message = PlaceholderAPI.setPlaceholders(player, actionBarMessage);
109+
message = translateHexColorCodes(message);
110+
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));
111+
} else {
112+
getLogger().warning("PlaceholderAPI is not loaded.");
113+
}
114+
}
115+
116+
public void loadConfig() {
117+
boolean isActionBarEnabled = getConfig().getBoolean("enableActionBarMessage", true);
118+
119+
if (isActionBarEnabled) {
120+
actionBarMessage = getConfig().getString("actionBarMessage", "&#635AA7g&#6D63ADi&#776DB3t&#8176BAh&#8B80C0u&#9589C6b&#9F92CC.&#AA9CD3c&#B4A5D9o&#BEAEDFm&#C8B8E5/&#D2C1ECC&#DCCBF2o&#E6D4F8l&#E0C9F8d&#DBBEF8-&#D5B4F8D&#D0A9F7e&#CA9EF7v&#C593F7e&#BF89F7l&#BA7EF7o&#B473F7p&#AF68F6m&#A95EF6e&#A453F6n&#9E48F6t");
121+
if (actionBarMessage != null) {
122+
actionBarMessage = translateHexColorCodes(actionBarMessage);
123+
} else {
124+
getLogger().warning("actionBarMessage is null. Please check the configuration in config.yml.");
125+
}
126+
} else {
127+
actionBarMessage = null;
128+
getLogger().info("Action bar message is disabled in the config.");
129+
}
130+
}
131+
132+
@Override
133+
protected @NotNull List<Class<? extends Manager>> getManagerLoadPriority() {
134+
return List.of(
135+
CommandManager.class
136+
);
137+
}
138+
139+
@Override
140+
protected @NotNull List<ColdSetting<?>> getColdConfigSettings() {
141+
return SettingKey.getKeys();
142+
}
143+
144+
@Override
145+
protected String[] getColdConfigHeader() {
146+
return new String[] {
147+
" ____ ___ _ ____ ",
148+
" / ___|/ _ \\ | | | _ \\ ",
149+
"| | | | | || | | | | | ",
150+
"| |___| |_| || |___ | |_| | ",
151+
" \\____|\\___/ |_____|_____/ ",
152+
" "
153+
};
154+
}
155+
156+
public static HudActionbar getInstance() {
157+
if (instance == null) {
158+
throw new IllegalStateException("HudActionbar instance is not initialized!");
159+
}
160+
return instance;
161+
}
162+
163+
private String translateHexColorCodes(String message) {
164+
Pattern hexPattern = Pattern.compile("&#([A-Fa-f0-9]{6})");
165+
Matcher matcher = hexPattern.matcher(message);
166+
StringBuffer buffer = new StringBuffer(message.length());
167+
168+
while (matcher.find()) {
169+
String hexColor = matcher.group(1);
170+
String replacement = ChatColor.of("#" + hexColor).toString();
171+
matcher.appendReplacement(buffer, replacement);
172+
}
173+
174+
matcher.appendTail(buffer);
175+
message = buffer.toString();
176+
177+
return ChatColor.translateAlternateColorCodes('&', message);
178+
}
179+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package dev.padrewin.hudactionbar.commands;
2+
3+
import java.util.Collections;
4+
import java.util.List;
5+
import dev.padrewin.hudactionbar.HudActionbar;
6+
import dev.padrewin.hudactionbar.manager.CommandManager;
7+
import org.bukkit.command.CommandSender;
8+
import org.bukkit.permissions.Permissible;
9+
10+
public abstract class BaseCommand implements NamedExecutor {
11+
12+
private final String name;
13+
private final CommandManager.CommandAliases aliases;
14+
15+
public BaseCommand(String name, CommandManager.CommandAliases aliases) {
16+
this.name = name;
17+
this.aliases = aliases;
18+
}
19+
20+
/**
21+
* Execution method for the command.
22+
*
23+
* @param plugin HudActionbar instance.
24+
* @param sender Sender of the command.
25+
* @param args Command arguments.
26+
*/
27+
public abstract void execute(HudActionbar plugin, CommandSender sender, String[] args);
28+
29+
/**
30+
* Tab completion method for the command.
31+
*
32+
* @param plugin HudActionbar instance.
33+
* @param sender Sender of the command.
34+
* @param args Command arguments.
35+
*/
36+
public abstract List<String> tabComplete(HudActionbar plugin, CommandSender sender, String[] args);
37+
38+
@Override
39+
public String getName() {
40+
return this.name;
41+
}
42+
43+
@Override
44+
public List<String> getAliases() {
45+
List<String> aliases = this.aliases.get();
46+
if (aliases.isEmpty()) {
47+
return Collections.singletonList(this.name);
48+
} else {
49+
return aliases;
50+
}
51+
}
52+
53+
@Override
54+
public boolean hasPermission(Permissible permissible) {
55+
return permissible.hasPermission("hudactionbar." + this.name);
56+
}
57+
58+
}

0 commit comments

Comments
 (0)