Skip to content

Commit d19e51a

Browse files
Pushed version to 1.1.3
Recoded backend command framework Recoded backend listener framework Recoded existing commands to new framework Fixed issue with console messages not always matching Fixed issue with HEX colors not being applied. Use like <#Hex> Fixed issue with version check and glow Cleared old code.
1 parent 244f911 commit d19e51a

21 files changed

+157
-726
lines changed

pom.xml

+13-3
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,29 @@
7575
<id>localrepository</id>
7676
<url>file://${project.basedir}/lib</url>
7777
</repository>
78+
<repository>
79+
<id>aikar</id>
80+
<url>https://repo.aikar.co/content/groups/aikar/</url>
81+
</repository>
7882
</repositories>
7983

8084
<dependencies>
8185
<dependency>
8286
<groupId>org.spigotmc</groupId>
8387
<artifactId>spigot-api</artifactId>
84-
<version>1.14.2-R0.1-SNAPSHOT</version>
88+
<version>1.18.2-R0.1-SNAPSHOT</version>
8589
<scope>provided</scope>
8690
</dependency>
8791
<dependency>
88-
<groupId>me.arcaniax</groupId>
92+
<groupId>co.aikar</groupId>
93+
<artifactId>acf-paper</artifactId>
94+
<version>0.5.1-SNAPSHOT</version>
95+
<scope>compile</scope>
96+
</dependency>
97+
<dependency>
98+
<groupId>com.arcaniax</groupId>
8999
<artifactId>HeadDatabase-API</artifactId>
90-
<version>1.1.0</version>
100+
<version>1.3.1</version>
91101
<scope>provided</scope>
92102
</dependency>
93103
<dependency>

src/main/java/net/bghddevelopment/punishmentgui/PunishGUI.java

+32-15
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
package net.bghddevelopment.punishmentgui;
22

3+
import co.aikar.commands.BukkitCommandIssuer;
4+
import co.aikar.commands.BukkitCommandManager;
5+
import co.aikar.commands.ConditionFailedException;
36
import com.google.gson.JsonObject;
47
import com.google.gson.JsonParser;
58
import lombok.Getter;
9+
import net.bghddevelopment.punishmentgui.commands.PunishmentCommand;
10+
import net.bghddevelopment.punishmentgui.commands.PunishmentGUIReloadCommand;
611
import net.bghddevelopment.punishmentgui.language.Language;
12+
import net.bghddevelopment.punishmentgui.listeners.InventoryListener;
713
import net.bghddevelopment.punishmentgui.menu.MenuManager;
814
import net.bghddevelopment.punishmentgui.menu.handler.CoreHandler;
915
import net.bghddevelopment.punishmentgui.menu.menu.AquaMenu;
1016
import net.bghddevelopment.punishmentgui.utils.*;
11-
import net.bghddevelopment.punishmentgui.utils.command.CommandFramework;
1217
import net.bghddevelopment.punishmentgui.utils.glow.Glow;
13-
import net.bghddevelopment.punishmentgui.utils.registration.RegisterHandler;
1418
import org.bukkit.Bukkit;
1519
import org.bukkit.NamespacedKey;
1620
import org.bukkit.command.CommandSender;
1721
import org.bukkit.event.Listener;
18-
import org.bukkit.plugin.PluginDescriptionFile;
1922
import org.bukkit.plugin.java.JavaPlugin;
2023

2124
import java.io.BufferedReader;
@@ -32,7 +35,6 @@ public final class PunishGUI extends JavaPlugin {
3235
@Getter
3336
public static PunishGUI instance;
3437
private ConfigFile settingsFile, languageFile;
35-
private CommandFramework framework;
3638
private CoreHandler coreHandler;
3739
private MenuManager menuManager;
3840
private List<Listener> listeners = new ArrayList<>();
@@ -47,33 +49,48 @@ public static PunishGUI getInstance() {
4749
@Override
4850
public void onEnable() {
4951
instance = this;
50-
this.framework = new CommandFramework(this);
5152
this.settingsFile = new ConfigFile(this, "settings.yml");
5253
this.languageFile = new ConfigFile(this, "language.yml");
5354
Language.setConfig(this.languageFile);
5455
loadLanguage();
55-
Bukkit.getConsoleSender().sendMessage(Color.translate("&eLoaded config files!"));
56-
RegisterHandler.loadCommandsFromPackage(this, "net.bghddevelopment.punishmentgui.commands");
57-
RegisterHandler.loadListenersFromPackage(this, "net.bghddevelopment.punishmentgui.listeners");
58-
Bukkit.getConsoleSender().sendMessage(Color.translate("&eLoaded commands and permissions!"));
56+
Utilities.log("&aLoaded config files!");
57+
loadCommands();
58+
loadListeners();
5959
loadHandlers();
60-
this.framework.loadCommandsInFile();
6160
this.coreHandler.setupCustomMenuData();
62-
if(Bukkit.getVersion().contains("1.13") || Bukkit.getVersion().contains("1.14") || Bukkit.getVersion().contains("1.15") || Bukkit.getVersion().contains("1.16") || Bukkit.getVersion().contains("1.17") || Bukkit.getVersion().contains("1.18")) {
61+
if(VersionCheck.isOnePointThirteenPlus()) {
6362
this.glow = new Glow(NamespacedKey.minecraft("glow"));
6463
this.glow.register();
65-
Utilities.log("&eEnabled glow for Spigot 1.13+");
64+
Utilities.log("&aEnabled glow for Spigot 1.13+");
6665
}
67-
Bukkit.getConsoleSender().sendMessage(Color.translate("&eLoaded menus!"));
66+
Utilities.log("&aLoaded menus!");
6867
new Metrics(this, 5694);
69-
Bukkit.getConsoleSender().sendMessage(Color.translate("&eLoaded metrics!"));
68+
Utilities.log("&aLoaded metrics!");
7069
if (getSettingsFile().getBoolean("CheckForUpdates")) {
70+
Utilities.log("&aChecking for updates!");
7171
updateCheck(Bukkit.getConsoleSender(), true);
7272
}
73-
Bukkit.getConsoleSender().sendMessage(Color.translate("&aPunishmentGUI Loaded!"));
73+
Utilities.log("&aPunishmentGUI Loaded!");
7474
Bukkit.getScheduler().runTaskTimerAsynchronously(this, new MenuUpdate(), 20L, 20L);
7575
}
7676

77+
public void loadCommands() {
78+
BukkitCommandManager manager = new BukkitCommandManager(this);
79+
manager.getCommandConditions().addCondition("noconsole", (context) -> {
80+
BukkitCommandIssuer issuer = context.getIssuer();
81+
if (!issuer.isPlayer()) {
82+
throw new ConditionFailedException(Language.CONSOLE_ERROR.toString());
83+
}
84+
return;
85+
});
86+
manager.registerCommand(new PunishmentCommand());
87+
manager.registerCommand(new PunishmentGUIReloadCommand());
88+
}
89+
90+
private void loadListeners() {
91+
getServer().getPluginManager().registerEvents(new InventoryListener(this), this);
92+
}
93+
7794
@Override
7895
public void onDisable() {
7996
getBannedManager().clear();

src/main/java/net/bghddevelopment/punishmentgui/commands/PunishReloadCommand.java

-30
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
11
package net.bghddevelopment.punishmentgui.commands;
22

3+
import co.aikar.commands.BaseCommand;
4+
import co.aikar.commands.annotation.*;
5+
import net.bghddevelopment.punishmentgui.PunishGUI;
36
import net.bghddevelopment.punishmentgui.language.Language;
47
import net.bghddevelopment.punishmentgui.menu.handler.CustomMenu;
5-
import net.bghddevelopment.punishmentgui.utils.Color;
68
import net.bghddevelopment.punishmentgui.utils.Tasks;
79
import net.bghddevelopment.punishmentgui.utils.Utilities;
8-
import net.bghddevelopment.punishmentgui.utils.command.BaseCommand;
9-
import net.bghddevelopment.punishmentgui.utils.command.Command;
10-
import net.bghddevelopment.punishmentgui.utils.command.CommandArgs;
11-
import org.bukkit.Bukkit;
12-
import org.bukkit.ChatColor;
10+
import org.bukkit.command.CommandSender;
1311
import org.bukkit.entity.Player;
1412

15-
public class PunishCommand extends BaseCommand {
13+
@CommandAlias("punish|punishment")
14+
@CommandPermission("punish.use")
15+
@Description("Opens the punish menu for specified player.")
16+
@Conditions("noconsole")
17+
public class PunishmentCommand extends BaseCommand {
1618

19+
@Dependency
20+
private PunishGUI plugin;
1721

18-
@Command(name = "punish", aliases = "p", permission = "punish.use")
19-
public void onCommand(CommandArgs command) {
20-
Player player = command.getPlayer();
21-
String[] args = command.getArgs();
22-
if (!(command.getSender() instanceof Player)) {
23-
command.getSender().sendMessage(Color.translate("This can only be used in-game!"));
24-
return;
25-
}
26-
if (!player.hasPermission("punish.use")) {
27-
return;
28-
}
22+
@Default
23+
public void onDefault(CommandSender sender, String[] args) {
24+
Player player = (Player) sender;
2925
if (args.length == 0 || args.length > 2) {
3026
player.sendMessage(plugin.getPlaceholderAPI().translate(player, Language.PUNISH_USAGE.toString()));
3127
return;
@@ -46,9 +42,9 @@ public void onCommand(CommandArgs command) {
4642
return;
4743
});
4844
} else {
49-
Utilities.log("&c[MenuLog-1] &eThere is no menu with name &e&n" + plugin.getSettingsFile().getString("Command") + "&b &eto open for &b" + player.getName() + "&e. &c&oPlease check your configurations.");
45+
Utilities.log("&cThere is no menu with name &e&n" + plugin.getSettingsFile().getString("Command") + "&b &eto open for &b" + player.getName() + "&e. &c&oPlease check your configurations.");
5046
return;
5147
}
5248
player.updateInventory();
5349
}
54-
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package net.bghddevelopment.punishmentgui.commands;
2+
3+
import co.aikar.commands.BaseCommand;
4+
import co.aikar.commands.annotation.*;
5+
import net.bghddevelopment.punishmentgui.PunishGUI;
6+
import net.bghddevelopment.punishmentgui.language.Language;
7+
import net.bghddevelopment.punishmentgui.menu.handler.CustomMenu;
8+
import net.bghddevelopment.punishmentgui.utils.Color;
9+
import net.bghddevelopment.punishmentgui.utils.Tasks;
10+
import net.bghddevelopment.punishmentgui.utils.Utilities;
11+
import org.bukkit.command.CommandSender;
12+
import org.bukkit.entity.Player;
13+
14+
@CommandAlias("punishreload|reloadpunish")
15+
@CommandPermission("punish.admin")
16+
@Description("Reloads the PunishGUI menu.")
17+
public class PunishmentGUIReloadCommand extends BaseCommand {
18+
19+
@Dependency
20+
private PunishGUI plugin;
21+
22+
@Default
23+
public void onDefault(CommandSender sender, String[] args) {
24+
plugin.getSettingsFile().load();
25+
plugin.getLanguageFile().load();
26+
plugin.getCoreHandler().setupCustomMenuData();
27+
sender.sendMessage(Color.translate(Language.RELOADED.toString()));
28+
}
29+
}

src/main/java/net/bghddevelopment/punishmentgui/language/Language.java

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public enum Language {
1111

1212
PUNISH_USAGE("PUNISH.USAGE", "&cUse Like: /punish <target>"),
1313
PUNISH_NAME_ERROR("PUNISH.NAME-ERROR", "&cThat player name is invalid!"),
14+
CONSOLE_ERROR("PUNISH.COMMAND-CONSOLE", "&cConsole cannot use this command!"),
15+
RELOADED("PUNISH.RELOAD", "&aPlugin files have been reloaded!"),
1416

1517
END("", "");
1618

src/main/java/net/bghddevelopment/punishmentgui/listeners/InventoryListener.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,21 @@
88
import net.bghddevelopment.punishmentgui.PunishGUI;
99
import net.bghddevelopment.punishmentgui.menu.menu.AquaMenu;
1010
import net.bghddevelopment.punishmentgui.menu.slots.Slot;
11+
import net.bghddevelopment.punishmentgui.utils.Manager;
1112
import org.bukkit.entity.Player;
1213
import org.bukkit.event.EventHandler;
1314
import org.bukkit.event.EventPriority;
1415
import org.bukkit.event.Listener;
1516
import org.bukkit.event.inventory.*;
1617

17-
public class InventoryListener implements Listener {
18+
public class InventoryListener extends Manager implements Listener {
1819

1920
private PunishGUI plugin = PunishGUI.getInstance();
2021

22+
public InventoryListener(PunishGUI plugin) {
23+
super(plugin);
24+
}
25+
2126
@EventHandler(priority = EventPriority.HIGHEST)
2227
public void handleInventories(InventoryClickEvent event) {
2328
Player player = (Player) event.getWhoClicked();

src/main/java/net/bghddevelopment/punishmentgui/menu/handler/CustomMenu.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public void onClick(Player player, int slot, ClickType clickType) {
8686
if (customMenu != null) {
8787
Tasks.run(plugin, () -> customMenu.getMenu().open(player));
8888
} else {
89-
Utilities.log("&c[MenuLog-2] &eThere is no menu with name &e&n" + menu + "&b &eto open for &b" + player.getName() + "&e. &c&oPlease check your configurations.");
89+
Utilities.log("&cThere is no menu with name &e&n" + menu + "&b &eto open for &b" + player.getName() + "&e. &c&oPlease check your configurations.");
9090
}
9191
}
9292

src/main/java/net/bghddevelopment/punishmentgui/utils/Color.java

+15-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,24 @@
44
import org.bukkit.ChatColor;
55

66
import java.util.List;
7+
import java.util.regex.Matcher;
8+
import java.util.regex.Pattern;
79
import java.util.stream.Collectors;
810

911
public class Color {
10-
public static String translate(String source) {
11-
return ChatColor.translateAlternateColorCodes('&', source);
12+
public static String translate(String message) {
13+
if (VersionCheck.isOnePointSixteenPlus()) {
14+
Pattern pattern = Pattern.compile("#[a-fA-F0-9]{6}");
15+
Matcher matcher = pattern.matcher(message);
16+
17+
while (matcher.find()) {
18+
String color = message.substring(matcher.start(), matcher.end());
19+
message = message.replace(color, net.md_5.bungee.api.ChatColor.of(color) + "");
20+
matcher = pattern.matcher(message);
21+
}
22+
}
23+
24+
return ChatColor.translateAlternateColorCodes('&', message);
1225
}
1326

1427
public static List<String> translate(List<String> source) {

src/main/java/net/bghddevelopment/punishmentgui/utils/Utilities.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static List<Player> getOnlinePlayers() {
2323
}
2424

2525
public static void log(String message) {
26-
Bukkit.getConsoleSender().sendMessage(net.bghddevelopment.punishmentgui.utils.Color.translate(message));
26+
Bukkit.getConsoleSender().sendMessage(net.bghddevelopment.punishmentgui.utils.Color.translate("[PunishGUI] " + message));
2727
}
2828

2929
public static Material getMaterial(String source) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package net.bghddevelopment.punishmentgui.utils;
2+
3+
import org.bukkit.Bukkit;
4+
5+
public class VersionCheck {
6+
7+
public static boolean isOnePointEightPlus() {
8+
if (Bukkit.getVersion().contains("1.8") || Bukkit.getVersion().contains("1.9") || Bukkit.getVersion().contains("1.10") || Bukkit.getVersion().contains("1.11") || Bukkit.getVersion().contains("1.12") || Bukkit.getVersion().contains("1.13") || Bukkit.getVersion().contains("1.14") || Bukkit.getVersion().contains("1.15") || Bukkit.getVersion().contains("1.16") || Bukkit.getVersion().contains("1.17") || Bukkit.getVersion().contains("1.18")) {
9+
return true;
10+
}
11+
return false;
12+
}
13+
14+
public static boolean isOnePointNinePlus() {
15+
if (Bukkit.getVersion().contains("1.9") || Bukkit.getVersion().contains("1.10") || Bukkit.getVersion().contains("1.11") || Bukkit.getVersion().contains("1.12") || Bukkit.getVersion().contains("1.13") || Bukkit.getVersion().contains("1.14") || Bukkit.getVersion().contains("1.15") || Bukkit.getVersion().contains("1.16") || Bukkit.getVersion().contains("1.17") || Bukkit.getVersion().contains("1.18")) {
16+
return true;
17+
}
18+
return false;
19+
}
20+
21+
public static boolean isOnePointThirteenPlus() {
22+
if (Bukkit.getVersion().contains("1.13") || Bukkit.getVersion().contains("1.14") || Bukkit.getVersion().contains("1.15") || Bukkit.getVersion().contains("1.16") || Bukkit.getVersion().contains("1.17") || Bukkit.getVersion().contains("1.18")) {
23+
return true;
24+
}
25+
return false;
26+
}
27+
28+
public static boolean isOnePointFourteenPlus() {
29+
if (Bukkit.getVersion().contains("1.14") || Bukkit.getVersion().contains("1.15") || Bukkit.getVersion().contains("1.16") || Bukkit.getVersion().contains("1.17") || Bukkit.getVersion().contains("1.18")) {
30+
return true;
31+
}
32+
return false;
33+
}
34+
35+
public static boolean isOnePointSixteenPlus() {
36+
if (Bukkit.getVersion().contains("1.16") || Bukkit.getVersion().contains("1.17") || Bukkit.getVersion().contains("1.18")) {
37+
return true;
38+
}
39+
return false;
40+
}
41+
}

src/main/java/net/bghddevelopment/punishmentgui/utils/command/BaseCommand.java

-23
This file was deleted.

0 commit comments

Comments
 (0)