Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Respawn Location commands
Browse files Browse the repository at this point in the history
Still not implemented in Sponge, but should work fine once they are. Also updated a deprecated Key creating method, and improved ban command to accept players as entity tag input.
  • Loading branch information
Xenmai committed Jun 15, 2018
1 parent fd949e5 commit fa87fc4
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 13 deletions.
Expand Up @@ -171,6 +171,8 @@ public void onServerStart(GamePreInitializationEvent event) {
Denizen2Core.register(new NarrateCommand());
Denizen2Core.register(new PardonCommand());
Denizen2Core.register(new RemoveBossBarCommand());
Denizen2Core.register(new RemoveRespawnCommand());
Denizen2Core.register(new SetRespawnCommand());
Denizen2Core.register(new TabListCommand());
Denizen2Core.register(new TakeCommand());
Denizen2Core.register(new TellCommand());
Expand Down
Expand Up @@ -25,7 +25,7 @@ public class AbsorptionCommand extends AbstractCommand {
// Changes the absorption points of an entity. You can specify whether
// the command will 'add' or 'set' the points. Defaults to 'add'.
// @Example
// # This example increased the player's absorption points by 10 (5 golden hearts).
// # This example increases the player's absorption points by 10 (5 golden hearts).
// - absorption <player> 10
// -->

Expand Down
Expand Up @@ -7,6 +7,7 @@
import com.denizenscript.denizen2core.tags.objects.DurationTag;
import com.denizenscript.denizen2core.utilities.debugging.ColorSet;
import com.denizenscript.denizen2sponge.Denizen2Sponge;
import com.denizenscript.denizen2sponge.tags.objects.EntityTag;
import com.denizenscript.denizen2sponge.tags.objects.FormattedTextTag;
import com.denizenscript.denizen2sponge.tags.objects.PlayerTag;
import org.spongepowered.api.Sponge;
Expand Down Expand Up @@ -91,8 +92,8 @@ public void execute(CommandQueue queue, CommandEntry entry) {
}
}
AbstractTagObject target = entry.getArgumentObject(queue, 0);
if (target instanceof PlayerTag) {
GameProfile profile = ((PlayerTag) target).getInternal().getProfile();
if (target instanceof PlayerTag || target instanceof EntityTag) {
GameProfile profile = PlayerTag.getFor(queue.error, target).getInternal().getProfile();
build.type(BanTypes.PROFILE).profile(profile);
if (queue.shouldShowGood()) {
queue.outGood("Banning player " + ColorSet.emphasis + profile.getName().get() +
Expand Down
@@ -0,0 +1,70 @@
package com.denizenscript.denizen2sponge.commands.player;

import com.denizenscript.denizen2core.commands.AbstractCommand;
import com.denizenscript.denizen2core.commands.CommandEntry;
import com.denizenscript.denizen2core.commands.CommandQueue;
import com.denizenscript.denizen2core.utilities.debugging.ColorSet;
import com.denizenscript.denizen2sponge.tags.objects.PlayerTag;
import com.denizenscript.denizen2sponge.tags.objects.WorldTag;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.util.RespawnLocation;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class RemoveRespawnCommand extends AbstractCommand {

// <--[command]
// @Since 0.4.0
// @Name removerespawn
// @Arguments <player> <world>
// @Short removes a respawn location for the player.
// @Updated 2018/02/22
// @Group Player
// @Warning This command doesn't work due to not being implemented in Sponge yet.
// @Minimum 2
// @Maximum 2
// @Description
// Removes the respawn location for the player in the specified world.
// Related commands: <@link command setrespawn>setrespawn<@/link>.
// @Example
// # This example removes the player's respawn point in their current world.
// - removerespawn <player> <player.location.world>
// -->

@Override
public String getName() {
return "removerespawn";
}

@Override
public String getArguments() {
return "<player> <world>";
}

@Override
public int getMinimumArguments() {
return 2;
}

@Override
public int getMaximumArguments() {
return 2;
}

@Override
public void execute(CommandQueue queue, CommandEntry entry) {
PlayerTag playerTag = PlayerTag.getFor(queue.error, entry.getArgumentObject(queue, 0));
Player player = playerTag.getOnline(queue.error);
WorldTag world = WorldTag.getFor(queue.error, entry.getArgumentObject(queue, 1));
Map<UUID, RespawnLocation> map = player.get(Keys.RESPAWN_LOCATIONS).orElse(new HashMap<>());
map.remove(world.getInternal().getUniqueId());
player.offer(Keys.RESPAWN_LOCATIONS, map);
if (queue.shouldShowGood()) {
queue.outGood("Removing respawn location for player '" + ColorSet.emphasis + playerTag.debug()
+ ColorSet.good + "' in world '" + ColorSet.emphasis + world.debug() + ColorSet.good + "'!");
}
}
}
@@ -0,0 +1,80 @@
package com.denizenscript.denizen2sponge.commands.player;

import com.denizenscript.denizen2core.commands.AbstractCommand;
import com.denizenscript.denizen2core.commands.CommandEntry;
import com.denizenscript.denizen2core.commands.CommandQueue;
import com.denizenscript.denizen2core.tags.objects.BooleanTag;
import com.denizenscript.denizen2core.utilities.debugging.ColorSet;
import com.denizenscript.denizen2sponge.tags.objects.LocationTag;
import com.denizenscript.denizen2sponge.tags.objects.PlayerTag;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.util.RespawnLocation;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class SetRespawnCommand extends AbstractCommand {

// <--[command]
// @Since 0.4.0
// @Name setrespawn
// @Arguments <player> <location>
// @Short sets a respawn location for the player.
// @Updated 2018/02/22
// @Group Player
// @Warning This command doesn't work due to not being implemented in Sponge yet.
// @Minimum 2
// @Maximum 2
// @Named force (BooleanTag) Sets whether this respawn position is forced.
// @Description
// Sets a respawn location for the player. A player can only have one respawn location
// per world. You can also specify if the position to respawn at is forced or can
// be varied for safety.
// Related commands: <@link command removerespawn>removerespawn<@/link>.
// @Example
// # This example sets the player's respawn point in their current world to their current location.
// - setrespawn <player> <player.location>
// -->

@Override
public String getName() {
return "setrespawn";
}

@Override
public String getArguments() {
return "<player> <location>";
}

@Override
public int getMinimumArguments() {
return 2;
}

@Override
public int getMaximumArguments() {
return 2;
}

@Override
public void execute(CommandQueue queue, CommandEntry entry) {
PlayerTag playerTag = PlayerTag.getFor(queue.error, entry.getArgumentObject(queue, 0));
Player player = playerTag.getOnline(queue.error);
LocationTag location = LocationTag.getFor(queue.error, entry.getArgumentObject(queue, 1));
RespawnLocation.Builder builder = RespawnLocation.builder().location(location.getInternal().toLocation());
if (entry.namedArgs.containsKey("force")) {
BooleanTag force = BooleanTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "force"));
builder.forceSpawn(force.getInternal());
}
Map<UUID, RespawnLocation> map = player.get(Keys.RESPAWN_LOCATIONS).orElse(new HashMap<>());
map.put(location.getInternal().world.getUniqueId(), builder.build());
player.offer(Keys.RESPAWN_LOCATIONS, map);
queue.outInfo(player.get(Keys.RESPAWN_LOCATIONS).orElse(new HashMap<>()).toString());
if (queue.shouldShowGood()) {
queue.outGood("Setting respawn location for player '" + ColorSet.emphasis + playerTag.debug()
+ ColorSet.good + "' to '" + ColorSet.emphasis + location.debug() + ColorSet.good + "'!");
}
}
}
Expand Up @@ -17,6 +17,8 @@
import org.spongepowered.api.statistic.Statistic;
import org.spongepowered.api.statistic.StatisticType;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.util.RespawnLocation;
import org.spongepowered.api.world.World;

import java.util.HashMap;
import java.util.Optional;
Expand Down Expand Up @@ -382,6 +384,29 @@ else if (map.getInternal().containsKey("item")) {
}
return new FormattedTextTag(pl.getTabList().getFooter().orElse(Text.of("")));
});
// <--[tag]
// @Since 0.4.0
// @Name PlayerTag.respawn_location[<WorldTag>]
// @Updated 2018/02/22
// @Group Properties
// @ReturnType LocationTag
// @Returns whether the player's respawn location in the specified world. ONLINE-PLAYERS-ONLY.
// -->
handlers.put("respawn_location", (dat, obj) -> {
Player pl = ((PlayerTag) obj).getOnline(dat);
if (pl == null) {
return new NullTag();
}
World world = WorldTag.getFor(dat.error, dat.getNextModifier()).getInternal();
RespawnLocation loc = pl.get(Keys.RESPAWN_LOCATIONS).orElse(new HashMap<>()).get(world.getUniqueId());
if (loc == null) {
if (!dat.hasFallback()) {
dat.error.run("The player has no defined respawn location in the specified world!");
}
return new NullTag();
}
return new LocationTag(loc.asLocation().get());
});
}

public static PlayerTag getFor(Action<String> error, String text) {
Expand Down
Expand Up @@ -10,19 +10,15 @@

public class FlagHelper {

public static final TypeToken<FlagMap> FLAGMAP_TOKEN = new TypeToken<FlagMap>() {
};

public static final TypeToken<Value<FlagMap>> FLAGMAP_VALUE_TOKEN = new TypeToken<Value<FlagMap>>() {
};

public static Key<Value<FlagMap>> FLAGMAP = KeyFactory.makeSingleKey(
FLAGMAP_TOKEN,
FLAGMAP_VALUE_TOKEN,
DataQuery.of("flagmap"),
"denizen2sponge:flagmap",
"DenizenFlagMap"
);
public static Key<Value<FlagMap>> FLAGMAP = Key.builder()
.type(FLAGMAP_VALUE_TOKEN)
.query(DataQuery.of("flagmap"))
.id("flagmap")
.name("DenizenFlagMap")
.build();

public static FlagMapDataBuilder FMDB;

Expand Down

0 comments on commit fa87fc4

Please sign in to comment.