Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
Updated CommandAPI
Deprecated Plugin Command because of fear of usage from users that don't understand how plugin loading and unloading works
Deprecated auto saving because bukkit already has that
Removed speed command
  • Loading branch information
Timongcraft committed Nov 2, 2023
1 parent b156131 commit 1d371d7
Show file tree
Hide file tree
Showing 42 changed files with 578 additions and 724 deletions.
10 changes: 10 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

97 changes: 82 additions & 15 deletions .idea/workspace.xml

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@
- A maintenance system
- A hopper sorting system
- A coordinate save system
- A auto save system
- A team chat
- A resource pack system
- A alert/broadcast command
- A speed, walkspeed and flyspeed command
- A walkspeed and flyspeed command
- A reboot command that reboots server after a specified amount of minutes with a reason
- A plugin command to disable plugins
- Time in chat messages with formatting
- A configs reload command for the plugin
- Block commands & prefixes
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<dependency>
<groupId>dev.jorel</groupId>
<artifactId>commandapi-bukkit-core</artifactId>
<version>9.0.3</version>
<version>9.2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
41 changes: 16 additions & 25 deletions src/main/java/timongcraft/system/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import timongcraft.system.commands.*;
import timongcraft.system.listeners.*;
import timongcraft.system.listeners.BlockCommandsListeners;
import timongcraft.system.listeners.ConnectionListeners;
import timongcraft.system.listeners.OtherListeners;
import timongcraft.system.listeners.SpawnElytraListeners;
import timongcraft.system.util.*;

import java.io.File;

public class Main extends JavaPlugin {

private static Main instance;
private final String prefix = getConfig().getString("prefix.pluginPrefix");
private DataConfigHandler dataConfigHandler;
Expand All @@ -25,15 +29,11 @@ public void onLoad() {

if (noLoad || Main.get().getConfig().getBoolean("CommandAPI.autoDownload")) {
try {
CommandAPILoader.load("9.0.3", noLoad);
CommandAPILoader.load("9.2.0", noLoad);
} catch (Exception e) {
throw new RuntimeException(e);
}
}

if (noLoad) return;

//CommandAPI.onLoad(new CommandAPIBukkitConfig(this).silentLogs(true).missingExecutorImplementationMessage("This command can't be executed with the %s"));
}

@Override
Expand All @@ -46,11 +46,8 @@ public void onEnable() {

PluginCommand.disablePluginsOnBoot();

if (getConfig().getBoolean("newUpdateNotifications.console")) {
if (getConfig().getBoolean("newUpdateNotifications.console"))
UpdateCheckHandler.checkForUpdate(Double.parseDouble(getDescription().getVersion()));
}

//CommandAPI.onEnable();

registerCommandsInOnEnable();

Expand All @@ -63,6 +60,7 @@ public void onEnable() {
public void onDisable() {
if (noLoad) return;

if (dataConfigHandler != null) dataConfigHandler.save();
if (getConfig().getBoolean("autoSave.enabled")) autoSaveHandler.cancel();
}

Expand All @@ -80,31 +78,26 @@ private void configVersionCheck() {
private void registerCommandsInOnEnable() {
AlertCommand.register();
ColorCodesCommand.register();
if (Main.get().getConfig().getBoolean("coordsSaver.enabled")) {
if (Main.get().getConfig().getBoolean("coordsSaver.enabled"))
CoordinatesCommand.register();
}
FlySpeedCommand.register();
if (getConfig().getBoolean("hopperFilters.enabled")) {
if (getConfig().getBoolean("hopperFilters.enabled"))
HopperFiltersCommand.register();
}
if (Main.get().getConfig().getBoolean("chatSystem.enabled")) {
MsgCommand.register();
ReplyCommand.register();
MeCommand.register();
SayCommand.register();
}
MaintenanceCommand.register();
if (Main.get().getConfig().getBoolean("permissionSystem.enabled")) {
if (Main.get().getConfig().getBoolean("permissionSystem.enabled"))
PermissionManagerCommand.register();
}
PluginCommand.register();
RebootCommand.register();
ReloadConfigsCommand.register();
ResourcePackCommand.register();
SpeedCommand.register();
if (Main.get().getConfig().getBoolean("statuses.enabled")) {
if (Main.get().getConfig().getBoolean("statuses.enabled"))
StatusCommand.register();
}
TeamMsgCommand.register();
WalkSpeedCommand.register();
}
Expand All @@ -115,15 +108,12 @@ private void registerEvents() {
pluginManager.registerEvents(new ConnectionListeners(), this);
pluginManager.registerEvents(new OtherListeners(), this);
pluginManager.registerEvents(new HopperFilterHandler(), this);
if (!getConfig().getStringList("blockedCommands").isEmpty() || !getConfig().getStringList("blockedPrefix").isEmpty()) {
if (!getConfig().getStringList("blockedCommands").isEmpty() || !getConfig().getStringList("blockedPrefix").isEmpty())
pluginManager.registerEvents(new BlockCommandsListeners(), this);
}
if (getConfig().getBoolean("spawnElytra.enabled")) {
if (getConfig().getBoolean("spawnElytra.enabled"))
pluginManager.registerEvents(new SpawnElytraListeners(), this);
}
if (getConfig().getBoolean("hopperFilters.enabled")) {
if (getConfig().getBoolean("hopperFilters.enabled"))
pluginManager.registerEvents(new HopperFilterHandler(), this);
}
}

private void enableAutoSave() {
Expand Down Expand Up @@ -156,4 +146,5 @@ public String getPrefix() {
public DataConfigHandler getDataConfig() {
return dataConfigHandler;
}

}
11 changes: 6 additions & 5 deletions src/main/java/timongcraft/system/commands/AlertCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import timongcraft.system.Main;

public class AlertCommand {

public static void register() {
new CommandTree("alert")
.withShortDescription("Sends an alert to all players")
Expand All @@ -21,13 +22,13 @@ public static void register() {
.register();
}

private static int alertManager(CommandSender sender, CommandArguments args) {
private static void alertManager(CommandSender sender, CommandArguments args) {
String message = (String) args.get("message");

for (Player player : Bukkit.getOnlinePlayers()) {
player.sendMessage(Main.get().getConfig().getString("prefix.alertPrefix") + message.replaceAll("&", "§"));
Bukkit.broadcastMessage(Main.get().getConfig().getString("prefix.alertPrefix") + message.replaceAll("&", "§"));

for (Player player : Bukkit.getOnlinePlayers())
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 1.0F, .5F);
}
return 1;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.bukkit.command.CommandSender;

public class ColorCodesCommand {

public static void register() {
new CommandTree("colorcodes")
.withShortDescription("Get all color codes as well as the format codes")
Expand All @@ -15,7 +16,7 @@ public static void register() {
.register();
}

private static int colorCodesManager(CommandSender sender, CommandArguments args) {
private static void colorCodesManager(CommandSender sender, CommandArguments args) {
sender.sendMessage(ChatColor.GOLD + "======== Color Codes ========");
sender.sendMessage("&0 = " + ChatColor.BLACK + "Black" + " " + ChatColor.WHITE + "&1 = " + ChatColor.DARK_BLUE + "Dark Blue");
sender.sendMessage("&2 = " + ChatColor.DARK_GREEN + "Dark Green" + " " + ChatColor.WHITE + "&3 = " + ChatColor.DARK_AQUA + "Dark Aqua");
Expand All @@ -30,6 +31,6 @@ private static int colorCodesManager(CommandSender sender, CommandArguments args
sender.sendMessage("&k = " + ChatColor.MAGIC + "Magic" + ChatColor.WHITE + " " + "&l = " + ChatColor.BOLD + "Bold");
sender.sendMessage("&m = " + ChatColor.STRIKETHROUGH + "Strikethrough" + ChatColor.WHITE + " " + "&n = " + ChatColor.UNDERLINE + "Underline");
sender.sendMessage("&o = " + ChatColor.ITALIC + "Italic" + ChatColor.WHITE + " " + "&r = " + ChatColor.RESET + "Reset");
return 1;
}

}
30 changes: 14 additions & 16 deletions src/main/java/timongcraft/system/commands/CoordinatesCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import timongcraft.system.Main;
import timongcraft.system.util.PlayerUtils;
import timongcraft.system.util.MessageUtils;

import java.util.List;

public class CoordinatesCommand {

public static void register() {
new CommandTree("coordinates")
.withShortDescription("A more vanilla like alternative to waypoints")
Expand Down Expand Up @@ -59,9 +60,8 @@ private static String[] getCoordinates(Player sender) {
String[] coordinateNames = new String[coordinatesList.size()];
int index = 0;

for (String coordinateNamesName : coordinatesList) {
for (String coordinateNamesName : coordinatesList)
coordinateNames[index++] = (coordinateNamesName.split(":")[0]);
}

return coordinateNames;
}
Expand All @@ -71,7 +71,7 @@ private static int coordsList(Player sender, CommandArguments args) {

if (coordinatesList.isEmpty()) {
sender.sendMessage(Main.get().getPrefix() + "§cYou haven't any saved coordinates");
return 1;
return 0;
}

sender.sendMessage("Saved Coordinates:\n");
Expand Down Expand Up @@ -100,7 +100,7 @@ private static int coordsListOther(CommandSender sender, CommandArguments args)

if (coordinatesList.isEmpty()) {
sender.sendMessage(Main.get().getPrefix() + "§c" + target.getName() + " hasn't saved any coordinates");
return 1;
return 0;
}

sender.sendMessage(Main.get().getPrefix() + target.getName() + "s Saved Coordinates:\n");
Expand Down Expand Up @@ -133,7 +133,7 @@ private static int coordsAdder(Player sender, CommandArguments args) {

if (coordinatesLimit != -1 && coordinatesList.size() >= coordinatesLimit) {
sender.sendMessage(Main.get().getPrefix() + "§cYou succeeded the limit of " + coordinatesLimit + " coordinates");
return 1;
return 0;
}

coordinatesList.removeIf(searchedCoordinate -> searchedCoordinate.startsWith(coordinateName + ":"));
Expand All @@ -151,8 +151,7 @@ private static int coordsAdder(Player sender, CommandArguments args) {
coordinateCoordinatesComponent.setClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, coordinateClean));
coordinateCoordinatesComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("§6Click to copy coordinates.")));

sender.spigot().sendMessage(new TextComponent(Main.get().getPrefix() + "Added coordinate: "), coordinateNameComponent, coordinateCoordinatesComponent);
PlayerUtils.sendToTeam(sender.getName(), null, "Added coordinate: " + coordinateName + " (" + coordinateClean + ")");
MessageUtils.sendAdminMessage(sender, new TextComponent("Added coordinate: " + coordinateName + " (" + coordinateClean + ")"));
return 1;
}

Expand All @@ -162,7 +161,7 @@ private static int coordsRemover(Player sender, CommandArguments args) {

if (coordinatesList.isEmpty()) {
sender.sendMessage(Main.get().getPrefix() + "§cThere aren't any saved coordinates");
return 1;
return 0;
}

for (String coordinate : coordinatesList) {
Expand All @@ -171,14 +170,13 @@ private static int coordsRemover(Player sender, CommandArguments args) {
Main.get().getDataConfig().set("players." + sender.getUniqueId() + ".coords", coordinatesList);
Main.get().getDataConfig().save();

sender.sendMessage(Main.get().getPrefix() + "Removed coordinate: " + coordinateName);
PlayerUtils.sendToTeam(sender.getName(), null, "Removed coordinate: " + coordinateName);
MessageUtils.sendAdminMessage(sender, new TextComponent("Removed coordinate: " + coordinateName));
return 1;
}
}

sender.sendMessage(Main.get().getPrefix() + "§cNo coordinate with the name: " + coordinateName + "could be found");
return 1;
return 0;
}

private static int coordsGrabber(Player sender, CommandArguments args) {
Expand All @@ -187,7 +185,7 @@ private static int coordsGrabber(Player sender, CommandArguments args) {

if (coordinatesList.isEmpty()) {
sender.sendMessage(Main.get().getPrefix() + "§cThere aren't any saved coordinates");
return 1;
return 0;
}

for (String coordinate : coordinatesList) {
Expand All @@ -209,10 +207,10 @@ private static int coordsGrabber(Player sender, CommandArguments args) {
}

sender.sendMessage(Main.get().getPrefix() + "§cNo coordinate with the name: " + coordinateName + "could be found");
return 1;
return 0;
}

private static int coordsSaver(Player sender, CommandArguments args) {
private static void coordsSaver(Player sender, CommandArguments args) {
String coords = (String) args.get("coords");
String coordsName = coords.split(":")[0];
ChatColor color = getEnvironmentColor(coords.split(":")[2]);
Expand All @@ -224,7 +222,6 @@ private static int coordsSaver(Player sender, CommandArguments args) {
Main.get().getDataConfig().save();

sender.sendMessage(Main.get().getPrefix() + "Added " + color + coordsName + "§r to your coords list");
return 1;
}

public static ChatColor getEnvironmentColor(String environment) {
Expand All @@ -237,4 +234,5 @@ public static ChatColor getEnvironmentColor(String environment) {
};

}

}
Loading

0 comments on commit 1d371d7

Please sign in to comment.