Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add spawn module #1

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions src/main/java/com/skcraft/plume/module/Spawn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.skcraft.plume.module;

import com.sk89q.intake.Command;
import com.sk89q.intake.Require;
import com.skcraft.plume.command.Sender;
import com.skcraft.plume.common.util.config.Config;
import com.skcraft.plume.common.util.config.InjectConfig;
import com.skcraft.plume.common.util.module.Module;
import com.skcraft.plume.util.Messages;
import com.skcraft.plume.util.TeleportHelper;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import ninja.leaping.configurate.objectmapping.Setting;

import static com.skcraft.plume.common.util.SharedLocale.tr;

@Module(name = "spawn", desc = "Set a server spawn for players to teleport to")
public class Spawn {

@InjectConfig("spawn") private Config<SpawnConfig> config;

@Command(aliases = "spawn", desc = "Teleport to the server spawn")
@Require("plume.spawn")
public void spawn(@Sender EntityPlayerMP player) {
TeleportHelper.teleport(player, config.get().x, config.get().y, config.get().z, config.get().dimension, config.get().yaw, config.get().pitch);
player.addChatMessage(Messages.info(tr("spawn.success")));
}

@Command(aliases = "setspawn", desc = "Set the server spawn")
@Require("plume.spawn.set")
public void setspawn(@Sender EntityPlayerMP player) {
config.get().dimension = player.dimension;
config.get().x = player.posX;
config.get().y = player.posY;
config.get().z = player.posZ;
config.get().yaw = player.rotationYaw;
config.get().pitch = player.rotationPitch;
config.save();

player.addChatMessage(Messages.info(tr("spawn.set")));
}

@SubscribeEvent
public void playerRespawn(PlayerEvent.PlayerRespawnEvent event) {
EntityPlayerMP player = (EntityPlayerMP) event.player;
player.playerNetServerHandler.playerEntity = player;
TeleportHelper.teleport(player, config.get().x, config.get().y, config.get().z, config.get().dimension, config.get().yaw, config.get().pitch);
}

private static class SpawnConfig {
@Setting(comment = "Dimension ID")
public int dimension = 0;

@Setting(comment = "X coordinate")
public double x = 0;

@Setting(comment = "Y coordinate")
public double y = 80;

@Setting(comment = "Z coordinate")
public double z = 0;

@Setting(comment = "Yaw")
public float yaw = 0;

@Setting(comment = "Pitch")
public float pitch = 0;
}
}
8 changes: 6 additions & 2 deletions src/main/java/com/skcraft/plume/util/TeleportHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ public static void teleport(EntityPlayerMP player, EntityPlayerMP target) {
}

public static void teleport(EntityPlayerMP player, double x, double y, double z, int dimension) {
teleport(player, x, y, z, dimension, player.rotationYaw, player.rotationPitch);
}

public static void teleport(EntityPlayerMP player, double x, double y, double z, int dimension, float yaw, float pitch) {
if(player.dimension != dimension) {
MinecraftServer.getServer().getConfigurationManager().transferPlayerToDimension(player, dimension, new BasicTeleporter(DimensionManager.getWorld(dimension)));
}
//TODO: allow pitch and yaw to be set
player.playerNetServerHandler.setPlayerLocation(x, y, z, player.rotationYaw, player.rotationPitch);

player.playerNetServerHandler.setPlayerLocation(x, y, z, yaw, pitch);
}

public static class BasicTeleporter extends Teleporter {
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/com/skcraft/plume/lang/Plume.properties
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,6 @@ logger.details.location=
logger.details.time=�eTime\: �b{0}
logger.items.noItems=The specified record has no items to give.
logger.items.inventoryName=Logged Items

spawn.set=Spawn has been set to your current position.
spawn.success=You have been sent to spawn.