Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many new features... #77

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@
<id>mojang</id>
<url>https://libraries.minecraft.net/</url>
</repository>
<repositories>
<repository>
<id>sonatype-oss-snapshots1</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
</repositories>
</repositories>

<dependencies>
Expand Down Expand Up @@ -168,5 +174,10 @@
<artifactId>hdb-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId>
<version>4.12.0</version>
</dependency>
</dependencies>
</project>
45 changes: 42 additions & 3 deletions src/main/java/fun/lewisdev/deluxehub/command/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ public void reload() {
commands.setInjector(new SimpleInjector(plugin));

commandRegistry.register(DeluxeHubCommand.class);


for(String[] command : config.getList("disabledCommands")){
this.unregisterCommand(command);
}

for (String command : config.getConfigurationSection("commands").getKeys(false)) {
if (!config.getBoolean("commands." + command + ".enabled")) continue;

Expand Down Expand Up @@ -99,8 +103,8 @@ private void registerCommand(String cmd, String[] aliases) {
case "LOCKCHAT":
commandRegistry.register(LockchatCommand.class, aliases);
break;
case "SETLOBBY":
commandRegistry.register(SetLobbyCommand.class, aliases);
case "SETUPLOBBY":
commandRegistry.register(SetupLobbyCommand.class, aliases);
break;
case "LOBBY":
commandRegistry.register(LobbyCommand.class, aliases);
Expand All @@ -114,4 +118,39 @@ private void registerCommand(String cmd, String[] aliases) {
public List<CustomCommand> getCustomCommands() {
return customCommands;
}


private Object getPrivateField(Object object, String field)throws SecurityException,
NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
Class<?> clazz = object.getClass();
Field objectField = clazz.getDeclaredField(field);
objectField.setAccessible(true);
Object result = objectField.get(object);
objectField.setAccessible(false);
return result;
}

private void unRegisterBukkitCommand(PluginCommand cmd) {
try {
Object result = this.getPrivateField(this.getServer().getPluginManager(), "commandMap");
SimpleCommandMap commandMap = (SimpleCommandMap) result;
Object map = this.getPrivateField(commandMap, "knownCommands");
@SuppressWarnings("unchecked")
HashMap<String, Command> knownCommands = (HashMap<String, Command>) map;
knownCommands.remove(cmd.getName());
for (String alias : cmd.getAliases()){
if(knownCommands.containsKey(alias) && knownCommands.get(alias).toString().contains(this.getName())){
knownCommands.remove(alias);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}

public void unregisterCommand(string command){
PluginCommand cmd = this.getCommand(command);
this.unRegisterBukkitCommand(cmd);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class SetLobbyCommand {
public class SetupLobbyCommand {

private final DeluxeHubPlugin plugin;

public SetLobbyCommand(DeluxeHubPlugin plugin) {
public SetupLobbyCommand(DeluxeHubPlugin plugin) {
this.plugin = plugin;
}

@Command(
aliases = {"setlobby"},
desc = "Set the lobby location"
aliases = {"setuplobby"},
desc = "Setup the lobby location"
)
public void setlobby(final CommandContext args, final CommandSender sender) throws CommandException {

Expand All @@ -41,11 +41,18 @@ public void setlobby(final CommandContext args, final CommandSender sender) thro
sender.sendMessage(TextUtil.color("&cYou cannot set the lobby location in a disabled world."));
return;
}

LobbySpawn lobbyModule = ((LobbySpawn) plugin.getModuleManager().getModule(ModuleType.LOBBY));
lobbyModule.setLocation(player.getLocation());
Messages.SET_LOBBY.send(sender);


if(args[0] == "set" || args[0] == "add"){
LobbySpawn lobbyModule = ((LobbySpawn) plugin.getModuleManager().getModule(ModuleType.LOBBY));
lobbyModule.setLocation(player.getLocation());
Messages.SET_LOBBY.send(sender);
} else if (args[0] == "remove" || args[0] == "delete") {
LobbySpawn lobbyModule = ((LobbySpawn) plugin.getModuleManager().getModule(ModuleType.LOBBY));
lobbyModule.removeLobby();
Messages.REMOVE_LOBBY.send(sender);
} else {
Messages.USAGE_LOBBY.send(sender);
}
}

}
2 changes: 2 additions & 0 deletions src/main/java/fun/lewisdev/deluxehub/config/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public enum Messages {
PLAYER_HIDER_SHOWN("PLAYER_HIDER.SHOWN"),

SET_LOBBY("LOBBY.SET_LOBBY"),
REMOVE_LOBBY("LOBBY.REMOVE_LOBBY"),
USAGE_LOBBY("LOBBY.USAGE"),

CLEARCHAT("CHAT.CLEARCHAT"),
CLEARCHAT_PLAYER("CHAT.CLEARCHAT_PLAYER"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public Location getLocation() {
public void setLocation(Location location) {
this.location = location;
}

public void removeLocation() {
this.location = null;
}

@EventHandler(priority = EventPriority.HIGH)
public void onPlayerJoin(PlayerJoinEvent event) {
Expand Down
14 changes: 12 additions & 2 deletions src/main/resources/commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,21 @@ commands:
enabled: true
aliases:
- lc
setlobby:
setuplobby:
enabled: true
lobby:
enabled: true
vanish:
enabled: true
aliases:
- v
- v

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
# | DISABLE COMMANDS |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
# Disable other plugin commands. It's recommended to restart your server.
disabledCommands:
- "version"
- "say"
- "tell"
- "disabledCommand"
4 changes: 3 additions & 1 deletion src/main/resources/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Messages:

LOBBY:
SET_LOBBY: "%prefix% &aYou have successfully set the lobby spawn point"
REMOVE_LOBBY: "%prefix% &cYou have successfully removed the lobby spawn point"
USAGE: "%prefix% &cUsage: /setuplobby <set|remove>"

CHAT:
CLEARCHAT: "&b&l* &fChat has been cleared by &e%player% &b&l*"
Expand Down Expand Up @@ -75,4 +77,4 @@ Messages:
REMOVED_LINE: "%prefix% &7Removed line &b%line%&7."

ANTI_WORLD_DOWNLOADER:
ADMIN_NOTIFY: "%prefix% &f%player% &chas joined with the World Downloader Mod, their ability to use it has been restricted by our systems."
ADMIN_NOTIFY: "%prefix% &f%player% &chas joined with the World Downloader Mod, their ability to use it has been restricted by our systems."