Closes #20; adds a system for /spawn referring to a cross-server warp

This commit is contained in:
William278 committed 2021-04-14 13:23:11 +01:00
1 parent cd341785c8
commit a15c8cf2ab
11 files changed
+84 -9

No files matched your search

@@ -11,11 +11,22 @@ public class SetspawnCommand extends CommandBase {
@Override
protected void onCommand(Player p, Command command, String label, String[] args) {
if (HuskHomes.getSettings().doSpawnCommand()) {
SettingHandler.setSpawnLocation(p.getLocation());
p.getLocation().getWorld().setSpawnLocation(p.getLocation());
MessageManager.sendMessage(p, "set_spawn_success");
if (HuskHomes.getSettings().doCrossServerSpawn()) {
if (SettingHandler.setCrossServerSpawnWarp(p.getLocation(), p)) {
updateSpawnLocation(p);
}
return;
}
updateSpawnLocation(p);
} else {
MessageManager.sendMessage(p, "error_command_disabled");
}
}
// Set the spawn position on the world to the player's location
private void updateSpawnLocation(Player p) {
SettingHandler.setSpawnLocation(p.getLocation());
p.getLocation().getWorld().setSpawnLocation(p.getLocation());
MessageManager.sendMessage(p, "set_spawn_success");
}
}
@@ -2,6 +2,7 @@ package me.william278.huskhomes2.commands;
import me.william278.huskhomes2.HuskHomes;
import me.william278.huskhomes2.MessageManager;
import me.william278.huskhomes2.data.DataManager;
import me.william278.huskhomes2.teleport.TeleportManager;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
@@ -11,6 +12,19 @@ public class SpawnCommand extends CommandBase {
@Override
protected void onCommand(Player p, Command command, String label, String[] args) {
if (HuskHomes.getSettings().doSpawnCommand()) {
String spawnWarpName = HuskHomes.getSettings().getSpawnWarpName();
// Cross server spawn teleport
if (HuskHomes.getSettings().doCrossServerSpawn()) {
if (DataManager.warpExists(spawnWarpName)) {
TeleportManager.queueTimedTeleport(p, DataManager.getWarp(spawnWarpName));
} else {
MessageManager.sendMessage(p, "error_spawn_undefined");
}
return;
}
// Server-based spawn teleport
if (TeleportManager.getSpawnLocation() != null) {
TeleportManager.queueTimedTeleport(p, TeleportManager.getSpawnLocation());
} else {
@@ -80,6 +80,8 @@ public class Settings {
// Spawn command settings
private boolean doSpawnCommand;
private boolean doCrossServerSpawn;
private String crossServerSpawnWarpName;
// Warp command settings
private boolean doWarpCommand;
@@ -180,6 +182,8 @@ public class Settings {
this.checkVanishedPlayers = config.getBoolean("handle_vanished_players");
this.doSpawnCommand = config.getBoolean("spawn_command.enabled");
this.doCrossServerSpawn = config.getBoolean("spawn_command.bungee_network_spawn.enabled");
this.crossServerSpawnWarpName = config.getString("spawn_command.bungee_network_spawn.warp_name");
this.doWarpCommand = config.getBoolean("warp_command.enabled");
this.doPermissionRestrictedWarps = config.getBoolean("warp_command.permission_restrictions.require_permission");
@@ -317,6 +321,14 @@ public class Settings {
return doSpawnCommand;
}
public boolean doCrossServerSpawn() {
return doCrossServerSpawn;
}
public String getSpawnWarpName() {
return crossServerSpawnWarpName;
}
public boolean doEconomy() {
return doEconomy;
}
@@ -57,6 +57,35 @@ public class SettingHandler {
}
}
// Set a new server spawn (override existing one if exists)
public static boolean setCrossServerSpawnWarp(Location location, Player player) {
String spawnWarpName = HuskHomes.getSettings().getSpawnWarpName();
// Delete the old spawn warp
if (DataManager.warpExists(spawnWarpName)) {
DataManager.deleteWarp(spawnWarpName);
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
DynMapIntegration.removeDynamicMapMarker(spawnWarpName);
}
}
// Set a new warp for the spawn position
SetWarpConditions setWarpConditions = new SetWarpConditions(spawnWarpName);
if (setWarpConditions.areConditionsMet()) {
Warp spawnWarp = new Warp(location, HuskHomes.getSettings().getServerID(), spawnWarpName);
spawnWarp.setDescription(MessageManager.getRawMessage("spawn_warp_default_description"));
DataManager.addWarp(spawnWarp);
if (HuskHomes.getSettings().doDynmap() && HuskHomes.getSettings().showWarpsOnDynmap()) {
DynMapIntegration.addDynamicMapMarker(spawnWarp);
}
WarpCommand.Tab.updateWarpsTabCache();
} else {
MessageManager.sendMessage(player, setWarpConditions.getConditionsNotMetReason());
return false;
}
return true;
}
// Set a warp at the specified position
public static void setWarp(Location location, Player player, String name) {
SetWarpConditions setWarpConditions = new SetWarpConditions(name);
+2 -1
View File
@@ -125,4 +125,5 @@ delete_confirmation_button: '&4[Confirm]'
delete_all_homes_success: '&aSuccessfully deleted your &l%1%&r&a home(s).'
delete_all_warps_success: '&aSuccessfully deleted all &l%1%&r&a server warp(s).'
error_permission_restricted_warp: '&4Error: &cYou do not have permission to warp to %1%!'
teleporting_complete_console: '&7(Console teleported you to %1%)'
teleporting_complete_console: '&7(Console teleported you to %1%)'
spawn_warp_default_description: 'The /spawn position of the server'
+2 -1
View File
@@ -125,4 +125,5 @@ delete_confirmation_button: '&4[Confirm]'
delete_all_homes_success: '&aSuccessfully deleted your &l%1%&r&a home(s).'
delete_all_warps_success: '&aSuccessfully deleted all &l%1%&r&a server warp(s).'
error_permission_restricted_warp: '&4Error: &cYou do not have permission to warp to %1%!'
teleporting_complete_console: '&7(Console teleported you to %1%)'
teleporting_complete_console: '&7(Console teleported you to %1%)'
spawn_warp_default_description: 'The /spawn position of the server'
+2 -1
View File
@@ -125,4 +125,5 @@ delete_confirmation_button: '&4[Confirm]'
delete_all_homes_success: '&aSuccessfully deleted your &l%1%&r&a home(s).'
delete_all_warps_success: '&aSuccessfully deleted all &l%1%&r&a server warp(s).'
error_permission_restricted_warp: '&4Error: &cYou do not have permission to warp to %1%!'
teleporting_complete_console: '&7(Console teleported you to %1%)'
teleporting_complete_console: '&7(Console teleported you to %1%)'
spawn_warp_default_description: 'The /spawn position of the server'
+2 -1
View File
@@ -125,4 +125,5 @@ delete_confirmation_button: '&4[Confirm]'
delete_all_homes_success: '&aSuccessfully deleted your &l%1%&r&a home(s).'
delete_all_warps_success: '&aSuccessfully deleted all &l%1%&r&a server warp(s).'
error_permission_restricted_warp: '&4Error: &cYou do not have permission to warp to %1%!'
teleporting_complete_console: '&7(Console teleported you to %1%)'
teleporting_complete_console: '&7(Console teleported you to %1%)'
spawn_warp_default_description: 'The /spawn position of the server'
+2 -1
View File
@@ -125,4 +125,5 @@ delete_confirmation_button: '&4[Confirm]'
delete_all_homes_success: '&aSuccessfully deleted your &l%1%&r&a home(s).'
delete_all_warps_success: '&aSuccessfully deleted all &l%1%&r&a server warp(s).'
error_permission_restricted_warp: '&4Error: &cYou do not have permission to warp to %1%!'
teleporting_complete_console: '&7(Console teleported you to %1%)'
teleporting_complete_console: '&7(Console teleported you to %1%)'
spawn_warp_default_description: 'The /spawn position of the server'
+2 -1
View File
@@ -125,4 +125,5 @@ delete_confirmation_button: '&4[Confirm]'
delete_all_homes_success: '&aSuccessfully deleted your &l%1%&r&a home(s).'
delete_all_warps_success: '&aSuccessfully deleted all &l%1%&r&a server warp(s).'
error_permission_restricted_warp: '&4Error: &cYou do not have permission to warp to %1%!'
teleporting_complete_console: '&7(Console teleported you to %1%)'
teleporting_complete_console: '&7(Console teleported you to %1%)'
spawn_warp_default_description: 'The /spawn position of the server'
+3
View File
@@ -45,6 +45,9 @@ warp_command:
format: 'huskhomes.warp.'
spawn_command:
enabled: true
bungee_network_spawn:
enabled: false
warp_name: 'spawn'
position:
world:
x: