Skip to content

Commit

Permalink
Add logic for spawn and setspawn
Browse files Browse the repository at this point in the history
  • Loading branch information
zax71 committed Mar 8, 2024
1 parent 631ed29 commit 1a508a5
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package org.mvplugins.multiverse.core.commands;

import co.aikar.commands.BukkitCommandIssuer;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandCompletion;
import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Description;
import co.aikar.commands.annotation.Flags;
import co.aikar.commands.annotation.Optional;
import co.aikar.commands.annotation.Subcommand;
import co.aikar.commands.annotation.Syntax;
import jakarta.inject.Inject;
import org.bukkit.Location;
import org.jetbrains.annotations.NotNull;
import org.jvnet.hk2.annotations.Service;
import org.mvplugins.multiverse.core.api.BlockSafety;
import org.mvplugins.multiverse.core.commandtools.MVCommandManager;
import org.mvplugins.multiverse.core.commandtools.MultiverseCommand;
import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld;
import org.mvplugins.multiverse.core.world.WorldManager;

@Service
@CommandAlias("mv")
public class SetSpawnCommand extends MultiverseCommand {

@Inject
SetSpawnCommand(@NotNull MVCommandManager commandManager) {
super(commandManager);
}

@Subcommand("setspawn")
@CommandPermission("multiverse.core.setspawn")
@CommandCompletion("@nothing @mvworlds:scope=loaded ") // TODO: Use Brigadier to show <position> above in chat like the vanilla TP command
@Syntax("[location] [world]")
@Description("{@@mv-core.setspawn.description}")
void onSetSpawnCommand(
BukkitCommandIssuer issuer,

@Optional
@Flags("resolve=issuerAware")
@Syntax("<location>")
@Description("{@@mv-core.setspawn.location.description}")
Location location,

@Optional
@Flags("resolve=issuerAware")
@Syntax("<world>")
@Description("{@@mv-core.setspawn.world.description}")
LoadedMultiverseWorld world
) {

// TODO: Use a flag to do this, no clue how to edit an inbuilt ACF flag though
// Get the Location
if (location == null) {
if (issuer.isPlayer()) {
location = issuer.getPlayer().getLocation();
} else {
issuer.sendMessage("The console must specify a location");
return;
}
}

issuer.sendMessage("Setting spawn in " + world.getName() + " to " + prettyLocation(location));

world.setSpawnLocation(location);
}

private String prettyLocation(Location location) {
return location.getX() + ", " + location.getY() + ", " + location.getZ();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import co.aikar.commands.annotation.Flags;
import co.aikar.commands.annotation.Subcommand;
import co.aikar.commands.annotation.Syntax;
import com.dumptruckman.minecraft.util.Logging;
import jakarta.inject.Inject;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
Expand All @@ -23,55 +24,56 @@
@Service
@CommandAlias("mv")
class SpawnCommand extends MultiverseCommand {

private final WorldManager worldManager;
private final AsyncSafetyTeleporter safetyTeleporter;

@Inject
SpawnCommand(@NotNull MVCommandManager commandManager,
WorldManager worldManager,
@NotNull WorldManager worldManager,

Check warning on line 32 in src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 '@' has incorrect indentation level 17, expected level should be 12. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java:32:18: warning: '@' has incorrect indentation level 17, expected level should be 12. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)
@NotNull AsyncSafetyTeleporter safetyTeleporter) {

Check warning on line 33 in src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 '@' has incorrect indentation level 17, expected level should be 12. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java:33:18: warning: '@' has incorrect indentation level 17, expected level should be 12. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)
super(commandManager);
this.worldManager = worldManager;
this.safetyTeleporter = safetyTeleporter;
}

@Subcommand("spawn tp")
@Subcommand("spawn")
@CommandPermission("multiverse.core.spawn")
@CommandCompletion("@players")
@Syntax("[player]")
@Description("{@@mv-core.spawn.tp.description}")
@Description("{@@mv-core.spawn.description}")
void onSpawnTpCommand(
BukkitCommandIssuer issuer,

@Flags("resolve=issuerAware")
@Syntax("[player]")
@Description("{@@mv-core.spawn.tp.player.description}")
@Description("{@@mv-core.spawn.player.description}")
Player player
) {

Check warning on line 51 in src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 'method def rparen' has incorrect indentation level 11, expected level should be 4. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java:51:12: warning: 'method def rparen' has incorrect indentation level 11, expected level should be 4. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)

Check warning on line 51 in src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 ')' should be on the previous line. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java:51:12: warning: ')' should be on the previous line. (SeparatorWrapEol)
// The player is in the world, so it must be loaded
LoadedMultiverseWorld world = worldManager.getLoadedWorld(player.getWorld().getName()).getOrNull();

// TODO: Log when the player cannot be teleported there. No clue how to detect that

Check warning on line 55 in src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Comment matches to-do format 'TODO'. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java:55:11: info: Comment matches to-do format 'TODO'. (com.puppycrawl.tools.checkstyle.checks.TodoCommentCheck)
// Teleport the player
safetyTeleporter.teleportSafely(issuer.getIssuer(), player, world.getSpawnLocation());

// Make the conformation message make sense
String teleporterName;
if (issuer.getIssuer().getName().equals("CONSOLE")) {
teleporterName = commandManager.formatMessage(issuer, MessageType.INFO, MVCorei18n.SPAWN_TP_CONSOLENAME);
} else if (issuer.getIssuer().getName().equals(player.getName())) {
teleporterName = commandManager.formatMessage(issuer, MessageType.INFO, MVCorei18n.SPAWN_TP_YOU);
} else {
teleporterName = issuer.getIssuer().getName();
}

// Send the conformation message
player.sendMessage(commandManager.formatMessage(
issuer,
MessageType.INFO,
MVCorei18n.SPAWN_TP_MESSAGE,
MVCorei18n.SPAWN_MESSAGE,
"{teleporter}",
teleporterName
getTeleporterName(issuer, player)
));

Check warning on line 65 in src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 ')' should be on the previous line. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java:65:9: warning: ')' should be on the previous line. (SeparatorWrapEol)

Logging.fine("Teleported " + player.getName() + " to " + world.getSpawnLocation().getX() + ", " + world.getSpawnLocation().getY() + ", " + world.getSpawnLocation().getZ());

Check warning on line 67 in src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Line is longer than 120 characters (found 180). Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java:67:0: warning: Line is longer than 120 characters (found 180). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)

Check warning on line 67 in src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 The String ", " appears 2 times in the file. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java:67:100: warning: The String ", " appears 2 times in the file. (com.puppycrawl.tools.checkstyle.checks.coding.MultipleStringLiteralsCheck)
}

private String getTeleporterName(BukkitCommandIssuer issuer, Player teleportTo) {

Check warning on line 70 in src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Return count is 3 (max allowed for non-void methods/lambdas is 2). Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java:70:5: info: Return count is 3 (max allowed for non-void methods/lambdas is 2). (com.puppycrawl.tools.checkstyle.checks.coding.ReturnCountCheck)
if (issuer.getIssuer().getName().equals("CONSOLE")) {
return commandManager.formatMessage(issuer, MessageType.INFO, MVCorei18n.SPAWN_CONSOLENAME);
}
if (issuer.getIssuer().getName().equals(teleportTo.getName())) {
return commandManager.formatMessage(issuer, MessageType.INFO, MVCorei18n.SPAWN_YOU);
}
return issuer.getIssuer().getName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ public enum MVCorei18n implements MessageKeyProvider {
ROOT_HELP,

// spawn tp command
SPAWN_TP_DESCRIPTION,
SPAWN_TP_PLAYER_DESCRIPTION,
SPAWN_TP_MESSAGE,
SPAWN_TP_CONSOLENAME,
SPAWN_TP_YOU,
SPAWN_DESCRIPTION,
SPAWN_PLAYER_DESCRIPTION,
SPAWN_MESSAGE,
SPAWN_CONSOLENAME,
SPAWN_YOU,

// teleport command
TELEPORT_SUCCESS,
Expand Down
12 changes: 6 additions & 6 deletions src/main/resources/multiverse-core_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ mv-core.remove.success=&aWorld '{world}' removed!
mv-core.root.title=&a{name} version {version}
mv-core.root.help=&aSee &f/mv help&a for commands available.

# /mv spawn tp
mv-core.spawn.tp.description=Teleports the specified player to the spawn of the world they are in
mv-core.spawn.tp.player.description=The player
mv-core.spawn.tp.message={teleporter} just sent you to spawn!
mv-core.spawn.tp.consolename=The console
mv-core.spawn.tp.you=You
# /mv spawn
mv-core.spawn.description=Teleports the specified player to the spawn of the world they are in
mv-core.spawn.player.description=The player
mv-core.spawn.message={teleporter} just sent you to spawn!
mv-core.spawn.consolename=The console
mv-core.spawn.you=You

# /mv tp
mv-core.teleport.description=Allows you to teleport to a location on your server!
Expand Down

0 comments on commit 1a508a5

Please sign in to comment.