mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 14:38:53 +00:00
Tweak command registration, make global respawn default to global spawn
This commit is contained in:
3 files changed
+28
-12
No files matched your search
@@ -144,7 +144,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
|||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
new BukkitCommand(command, this).register();
|
new BukkitCommand(command, this).register();
|
||||||
return type.getCommand();
|
return command;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
|
|||||||
@@ -48,15 +48,9 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
|
|||||||
|
|
||||||
public void register() {
|
public void register() {
|
||||||
// Register with bukkit
|
// Register with bukkit
|
||||||
final PluginCommand pluginCommand = Objects.requireNonNull(plugin.getCommand(command.getName()));
|
final PluginCommand pluginCommand = plugin.getCommand(command.getName());
|
||||||
pluginCommand.setExecutor(this);
|
if (pluginCommand == null) {
|
||||||
pluginCommand.setTabCompleter(this);
|
throw new IllegalStateException("Command " + command.getName() + " not found in plugin.yml");
|
||||||
pluginCommand.setDescription(command.getDescription());
|
|
||||||
pluginCommand.setPermission(command.getPermission());
|
|
||||||
|
|
||||||
// Register commodore TAB completion
|
|
||||||
if (CommodoreProvider.isSupported() && plugin.getSettings().doBrigadierTabCompletion()) {
|
|
||||||
BrigadierUtil.registerCommodore(plugin, pluginCommand, command);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register permissions
|
// Register permissions
|
||||||
@@ -66,10 +60,23 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
|
|||||||
.map((entry) -> addPermission(entry.getKey(), "", getPermissionDefault(entry.getValue())))
|
.map((entry) -> addPermission(entry.getKey(), "", getPermissionDefault(entry.getValue())))
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.toList();
|
.toList();
|
||||||
|
if (!childNodes.isEmpty()) {
|
||||||
addPermission(command.getPermission("*"), command.getUsage(), PermissionDefault.FALSE,
|
addPermission(command.getPermission("*"), command.getUsage(), PermissionDefault.FALSE,
|
||||||
childNodes.toArray(new Permission[0]));
|
childNodes.toArray(new Permission[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set command parameters
|
||||||
|
pluginCommand.setExecutor(this);
|
||||||
|
pluginCommand.setTabCompleter(this);
|
||||||
|
pluginCommand.setDescription(command.getDescription());
|
||||||
|
pluginCommand.setPermission(command.getPermission());
|
||||||
|
|
||||||
|
// Register commodore TAB completion
|
||||||
|
if (CommodoreProvider.isSupported() && plugin.getSettings().doBrigadierTabCompletion()) {
|
||||||
|
BrigadierUtil.registerCommodore(plugin, pluginCommand, command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private Permission addPermission(@NotNull String node, @NotNull String description, @NotNull PermissionDefault permissionDefault, @NotNull Permission... children) {
|
private Permission addPermission(@NotNull String node, @NotNull String description, @NotNull PermissionDefault permissionDefault, @NotNull Permission... children) {
|
||||||
final Map<String, Boolean> childNodes = Arrays.stream(children)
|
final Map<String, Boolean> childNodes = Arrays.stream(children)
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ public class EventListener {
|
|||||||
|
|
||||||
// Respawn the player cross-server if needed
|
// Respawn the player cross-server if needed
|
||||||
if (plugin.getSettings().doCrossServer() && plugin.getSettings().isGlobalRespawning()) {
|
if (plugin.getSettings().doCrossServer() && plugin.getSettings().isGlobalRespawning()) {
|
||||||
plugin.getDatabase().getRespawnPosition(onlineUser).ifPresent(respawnPosition -> {
|
plugin.getDatabase().getRespawnPosition(onlineUser).ifPresentOrElse(respawnPosition -> {
|
||||||
if (!respawnPosition.getServer().equals(plugin.getServerName())) {
|
if (!respawnPosition.getServer().equals(plugin.getServerName())) {
|
||||||
Teleport.builder(plugin)
|
Teleport.builder(plugin)
|
||||||
.teleporter(onlineUser)
|
.teleporter(onlineUser)
|
||||||
@@ -204,7 +204,16 @@ public class EventListener {
|
|||||||
.toTeleport()
|
.toTeleport()
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
});
|
}, () -> plugin.getSpawn().ifPresent(spawn -> {
|
||||||
|
if (!spawn.getServer().equals(plugin.getServerName())) {
|
||||||
|
Teleport.builder(plugin)
|
||||||
|
.teleporter(onlineUser)
|
||||||
|
.type(Teleport.Type.RESPAWN)
|
||||||
|
.target(spawn)
|
||||||
|
.toTeleport()
|
||||||
|
.execute();
|
||||||
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user