Skip to content

Commit

Permalink
Closes #20; adds a system for /spawn referring to a cross-server warp
Browse files Browse the repository at this point in the history
  • Loading branch information
WiIIiam278 committed Apr 14, 2021
1 parent cd34178 commit a15c8cf
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
14 changes: 14 additions & 0 deletions src/main/java/me/william278/huskhomes2/commands/SpawnCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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;
Expand All @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/me/william278/huskhomes2/config/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -180,6 +182,8 @@ public void reloadFromFile(FileConfiguration config) {
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");
Expand Down Expand Up @@ -317,6 +321,14 @@ public boolean doSpawnCommand() {
return doSpawnCommand;
}

public boolean doCrossServerSpawn() {
return doCrossServerSpawn;
}

public String getSpawnWarpName() {
return crossServerSpawnWarpName;
}

public boolean doEconomy() {
return doEconomy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,35 @@ public static void setHome(Location location, Player player, String name) {
}
}

// 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);
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/Languages/de-de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 2 additions & 1 deletion src/main/resources/Languages/en-gb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 2 additions & 1 deletion src/main/resources/Languages/it-it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 2 additions & 1 deletion src/main/resources/Languages/pl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 2 additions & 1 deletion src/main/resources/Languages/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 2 additions & 1 deletion src/main/resources/Languages/zh-tw.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 3 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ warp_command:
format: 'huskhomes.warp.'
spawn_command:
enabled: true
bungee_network_spawn:
enabled: false
warp_name: 'spawn'
position:
world:
x:
Expand Down

0 comments on commit a15c8cf

Please sign in to comment.