From 7ee77cbe6fd400f95469953c6779b3ecbce0cec3 Mon Sep 17 00:00:00 2001 From: Nentify Date: Sun, 30 Aug 2015 18:00:47 +0100 Subject: [PATCH 1/7] Add spawn module --- .../java/com/skcraft/plume/module/Spawn.java | 59 +++++++++++++++++++ .../com/skcraft/plume/lang/Plume.properties | 3 + 2 files changed, 62 insertions(+) create mode 100644 src/main/java/com/skcraft/plume/module/Spawn.java diff --git a/src/main/java/com/skcraft/plume/module/Spawn.java b/src/main/java/com/skcraft/plume/module/Spawn.java new file mode 100644 index 0000000..d0df26f --- /dev/null +++ b/src/main/java/com/skcraft/plume/module/Spawn.java @@ -0,0 +1,59 @@ +package com.skcraft.plume.module; + +import com.sk89q.intake.Command; +import com.skcraft.plume.command.Sender; +import com.skcraft.plume.common.util.SharedLocale; +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 net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.util.ChatComponentText; +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 config; + + @Command(aliases = "spawn", desc = "Go to the server spawn") + public void spawn(@Sender ICommandSender sender) { + if (sender instanceof EntityPlayerMP) { + TeleportHelper.teleport((EntityPlayerMP) sender, config.get().x, config.get().y, config.get().z, config.get().dimension); + sender.addChatMessage(Messages.info(tr("spawn.success"))); + } + } + + @Command(aliases = "setspawn", desc = "Set the server spawn") + public void setspawn(@Sender ICommandSender sender) { + if (sender instanceof EntityPlayerMP) { + EntityPlayerMP player = (EntityPlayerMP) sender; + + config.get().dimension = player.dimension; + config.get().x = player.posX; + config.get().y = player.posY; + config.get().z = player.posZ; + config.save(); + + sender.addChatMessage(Messages.info(tr("spawn.set"))); + } + } + + 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; + } +} diff --git a/src/main/resources/com/skcraft/plume/lang/Plume.properties b/src/main/resources/com/skcraft/plume/lang/Plume.properties index bc5991e..48a4dcc 100755 --- a/src/main/resources/com/skcraft/plume/lang/Plume.properties +++ b/src/main/resources/com/skcraft/plume/lang/Plume.properties @@ -127,3 +127,6 @@ commandFilter.blocked=Sorry, you can't use this command. commandFilter.consoleOnly=Sorry, you can only use this command from the server console. motd.notConfigured=No MOTD is configured. + +spawn.set=Spawn has been set to your current position. +spawn.success=You have been sent to spawn. From 35ccbf407c3a757545b83144d88e8922f63152dd Mon Sep 17 00:00:00 2001 From: Nentify Date: Sun, 30 Aug 2015 18:22:11 +0100 Subject: [PATCH 2/7] Add permissions for spawn commands --- src/main/java/com/skcraft/plume/module/Spawn.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/skcraft/plume/module/Spawn.java b/src/main/java/com/skcraft/plume/module/Spawn.java index d0df26f..4e984f5 100644 --- a/src/main/java/com/skcraft/plume/module/Spawn.java +++ b/src/main/java/com/skcraft/plume/module/Spawn.java @@ -1,6 +1,7 @@ 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.SharedLocale; import com.skcraft.plume.common.util.config.Config; @@ -21,6 +22,7 @@ public class Spawn { @InjectConfig("spawn") private Config config; @Command(aliases = "spawn", desc = "Go to the server spawn") + @Require("plume.spawn") public void spawn(@Sender ICommandSender sender) { if (sender instanceof EntityPlayerMP) { TeleportHelper.teleport((EntityPlayerMP) sender, config.get().x, config.get().y, config.get().z, config.get().dimension); @@ -29,6 +31,7 @@ public void spawn(@Sender ICommandSender sender) { } @Command(aliases = "setspawn", desc = "Set the server spawn") + @Require("plum.spawn.set") public void setspawn(@Sender ICommandSender sender) { if (sender instanceof EntityPlayerMP) { EntityPlayerMP player = (EntityPlayerMP) sender; From 92c40bcfb8a96957ef8c179caf4e6da87610134a Mon Sep 17 00:00:00 2001 From: Nentify Date: Sun, 30 Aug 2015 20:36:05 +0100 Subject: [PATCH 3/7] Change sender to EntityPlayer --- .../java/com/skcraft/plume/module/Spawn.java | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/skcraft/plume/module/Spawn.java b/src/main/java/com/skcraft/plume/module/Spawn.java index 4e984f5..6667036 100644 --- a/src/main/java/com/skcraft/plume/module/Spawn.java +++ b/src/main/java/com/skcraft/plume/module/Spawn.java @@ -3,15 +3,13 @@ import com.sk89q.intake.Command; import com.sk89q.intake.Require; import com.skcraft.plume.command.Sender; -import com.skcraft.plume.common.util.SharedLocale; 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 net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.util.ChatComponentText; import ninja.leaping.configurate.objectmapping.Setting; import static com.skcraft.plume.common.util.SharedLocale.tr; @@ -23,27 +21,22 @@ public class Spawn { @Command(aliases = "spawn", desc = "Go to the server spawn") @Require("plume.spawn") - public void spawn(@Sender ICommandSender sender) { - if (sender instanceof EntityPlayerMP) { - TeleportHelper.teleport((EntityPlayerMP) sender, config.get().x, config.get().y, config.get().z, config.get().dimension); - sender.addChatMessage(Messages.info(tr("spawn.success"))); - } + public void spawn(@Sender EntityPlayer sender) { + // TODO: Set yaw & pitch when supported + TeleportHelper.teleport((EntityPlayerMP) sender, config.get().x, config.get().y, config.get().z, config.get().dimension); + sender.addChatMessage(Messages.info(tr("spawn.success"))); } @Command(aliases = "setspawn", desc = "Set the server spawn") @Require("plum.spawn.set") - public void setspawn(@Sender ICommandSender sender) { - if (sender instanceof EntityPlayerMP) { - EntityPlayerMP player = (EntityPlayerMP) sender; - - config.get().dimension = player.dimension; - config.get().x = player.posX; - config.get().y = player.posY; - config.get().z = player.posZ; - config.save(); - - sender.addChatMessage(Messages.info(tr("spawn.set"))); - } + public void setspawn(@Sender EntityPlayer sender) { + config.get().dimension = sender.dimension; + config.get().x = sender.posX; + config.get().y = sender.posY; + config.get().z = sender.posZ; + config.save(); + + sender.addChatMessage(Messages.info(tr("spawn.set"))); } private static class SpawnConfig { From 70684e1e8e200059b13c92c382e0a3f47a8ea1a1 Mon Sep 17 00:00:00 2001 From: Nentify Date: Sun, 30 Aug 2015 20:41:04 +0100 Subject: [PATCH 4/7] Fix typo & change wording --- src/main/java/com/skcraft/plume/module/Spawn.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/skcraft/plume/module/Spawn.java b/src/main/java/com/skcraft/plume/module/Spawn.java index 6667036..73e7458 100644 --- a/src/main/java/com/skcraft/plume/module/Spawn.java +++ b/src/main/java/com/skcraft/plume/module/Spawn.java @@ -28,7 +28,7 @@ public void spawn(@Sender EntityPlayer sender) { } @Command(aliases = "setspawn", desc = "Set the server spawn") - @Require("plum.spawn.set") + @Require("plume.spawn.set") public void setspawn(@Sender EntityPlayer sender) { config.get().dimension = sender.dimension; config.get().x = sender.posX; From ba0b818f093573c6edf7aa26f8a30b3d3d030194 Mon Sep 17 00:00:00 2001 From: Nentify Date: Sun, 30 Aug 2015 20:42:06 +0100 Subject: [PATCH 5/7] Didn't catch the re-wording in last commit, whoops - Sorry --- src/main/java/com/skcraft/plume/module/Spawn.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/skcraft/plume/module/Spawn.java b/src/main/java/com/skcraft/plume/module/Spawn.java index 73e7458..a48b0ee 100644 --- a/src/main/java/com/skcraft/plume/module/Spawn.java +++ b/src/main/java/com/skcraft/plume/module/Spawn.java @@ -19,7 +19,7 @@ public class Spawn { @InjectConfig("spawn") private Config config; - @Command(aliases = "spawn", desc = "Go to the server spawn") + @Command(aliases = "spawn", desc = "Teleport to the server spawn") @Require("plume.spawn") public void spawn(@Sender EntityPlayer sender) { // TODO: Set yaw & pitch when supported From c1f1654a9138e853e7512936c01672bb3f1f4bf9 Mon Sep 17 00:00:00 2001 From: Nentify Date: Mon, 31 Aug 2015 16:22:48 +0100 Subject: [PATCH 6/7] Add support for setting yaw and pitch in TeleportHelper and include yaw and pitch when setting spawn --- src/main/java/com/skcraft/plume/module/Spawn.java | 11 +++++++++-- .../java/com/skcraft/plume/util/TeleportHelper.java | 8 ++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/skcraft/plume/module/Spawn.java b/src/main/java/com/skcraft/plume/module/Spawn.java index a48b0ee..4aef123 100644 --- a/src/main/java/com/skcraft/plume/module/Spawn.java +++ b/src/main/java/com/skcraft/plume/module/Spawn.java @@ -22,8 +22,7 @@ public class Spawn { @Command(aliases = "spawn", desc = "Teleport to the server spawn") @Require("plume.spawn") public void spawn(@Sender EntityPlayer sender) { - // TODO: Set yaw & pitch when supported - TeleportHelper.teleport((EntityPlayerMP) sender, config.get().x, config.get().y, config.get().z, config.get().dimension); + TeleportHelper.teleport((EntityPlayerMP) sender, config.get().x, config.get().y, config.get().z, config.get().dimension, config.get().yaw, config.get().pitch); sender.addChatMessage(Messages.info(tr("spawn.success"))); } @@ -34,6 +33,8 @@ public void setspawn(@Sender EntityPlayer sender) { config.get().x = sender.posX; config.get().y = sender.posY; config.get().z = sender.posZ; + config.get().yaw = sender.rotationYaw; + config.get().pitch = sender.rotationPitch; config.save(); sender.addChatMessage(Messages.info(tr("spawn.set"))); @@ -51,5 +52,11 @@ private static class SpawnConfig { @Setting(comment = "Z coordinate") public double z = 0; + + @Setting(comment = "Yaw") + public float yaw = 0; + + @Setting(comment = "Pitch") + public float pitch = 0; } } diff --git a/src/main/java/com/skcraft/plume/util/TeleportHelper.java b/src/main/java/com/skcraft/plume/util/TeleportHelper.java index 5d547ed..4d390c8 100644 --- a/src/main/java/com/skcraft/plume/util/TeleportHelper.java +++ b/src/main/java/com/skcraft/plume/util/TeleportHelper.java @@ -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 { From e44c30dcd3592464bfcaccb9e5032a71fb4441ea Mon Sep 17 00:00:00 2001 From: Nentify Date: Tue, 1 Sep 2015 20:03:49 +0100 Subject: [PATCH 7/7] Use EntityPlayerMP and make player respawn at spawn --- .../java/com/skcraft/plume/module/Spawn.java | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/skcraft/plume/module/Spawn.java b/src/main/java/com/skcraft/plume/module/Spawn.java index 4aef123..a9dc10a 100644 --- a/src/main/java/com/skcraft/plume/module/Spawn.java +++ b/src/main/java/com/skcraft/plume/module/Spawn.java @@ -8,6 +8,8 @@ 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; @@ -21,23 +23,30 @@ public class Spawn { @Command(aliases = "spawn", desc = "Teleport to the server spawn") @Require("plume.spawn") - public void spawn(@Sender EntityPlayer sender) { - TeleportHelper.teleport((EntityPlayerMP) sender, config.get().x, config.get().y, config.get().z, config.get().dimension, config.get().yaw, config.get().pitch); - sender.addChatMessage(Messages.info(tr("spawn.success"))); + 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 EntityPlayer sender) { - config.get().dimension = sender.dimension; - config.get().x = sender.posX; - config.get().y = sender.posY; - config.get().z = sender.posZ; - config.get().yaw = sender.rotationYaw; - config.get().pitch = sender.rotationPitch; + 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(); - sender.addChatMessage(Messages.info(tr("spawn.set"))); + 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 {