From 8c7d653cca9553922e11415341349ad8f41205f7 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Fri, 25 Mar 2016 13:13:15 +1100 Subject: [PATCH] Store location for teleport home --- .../src/mineplex/game/clans/tutorial/Tutorial.java | 4 ++++ .../game/clans/tutorial/TutorialSession.java | 13 +++++++++++++ .../clans/objective/goals/clan/SetHomeGoal.java | 4 ++++ .../clans/objective/goals/end/TpClanHomeGoal.java | 13 ++++++++----- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/Tutorial.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/Tutorial.java index 550ab1f11..57ce57797 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/Tutorial.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/Tutorial.java @@ -276,6 +276,10 @@ public abstract class Tutorial implements Listener, ObjectiveListener _playerSessionMap.get(player).getHolograms().add(hologram); hologram.start(); } + } + public TutorialSession getTutorialSession(Player player) + { + return _playerSessionMap.get(player); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialSession.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialSession.java index 2b4746af5..a335abaa8 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialSession.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialSession.java @@ -3,6 +3,8 @@ package mineplex.game.clans.tutorial; import java.util.ArrayList; import java.util.List; +import org.bukkit.Location; + import mineplex.core.hologram.Hologram; public class TutorialSession @@ -10,6 +12,7 @@ public class TutorialSession private int _objectiveIndex; private TutorialRegion _region; private List _hologramList = new ArrayList<>(); + private Location _homeLocation; public TutorialSession() { @@ -39,4 +42,14 @@ public class TutorialSession { _region = region; } + + public Location getHomeLocation() + { + return _homeLocation; + } + + public void setHomeLocation(Location homeLocation) + { + _homeLocation = homeLocation; + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/SetHomeGoal.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/SetHomeGoal.java index 00b528e92..2e3b8f023 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/SetHomeGoal.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/SetHomeGoal.java @@ -1,5 +1,6 @@ package mineplex.game.clans.tutorial.tutorials.clans.objective.goals.clan; +import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -34,6 +35,9 @@ public class SetHomeGoal extends ObjectiveGoal { if (getObjective().getPlugin().isIn(event.getPlayer(), ClansMainTutorial.Bounds.LAND_CLAIM)) { + // we need to save this for later when the player teleports home! + getObjective().getPlugin().getTutorialSession(event.getPlayer()).setHomeLocation(event.getPlayer().getLocation()); + finish(event.getPlayer()); } else diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/end/TpClanHomeGoal.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/end/TpClanHomeGoal.java index c64f15152..0c520377d 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/end/TpClanHomeGoal.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/end/TpClanHomeGoal.java @@ -3,13 +3,15 @@ package mineplex.game.clans.tutorial.tutorials.clans.objective.goals.end; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import mineplex.game.clans.clans.event.ClansCommandPreExecutedEvent; import mineplex.game.clans.tutorial.objective.Objective; import mineplex.game.clans.tutorial.objective.ObjectiveGoal; import mineplex.game.clans.clans.event.ClansCommandExecutedEvent; +import mineplex.game.clans.tutorial.tutorials.clans.objective.FinalObjective; -public class TpClanHomeGoal extends ObjectiveGoal +public class TpClanHomeGoal extends ObjectiveGoal { - public TpClanHomeGoal(Objective objective) + public TpClanHomeGoal(FinalObjective objective) { super(objective, "Teleport to Clan Home", "Use the /c home command to teleport to your Clan Home"); } @@ -25,9 +27,9 @@ public class TpClanHomeGoal extends ObjectiveGoal } @EventHandler - public void teleport(ClansCommandExecutedEvent event) + public void teleport(ClansCommandPreExecutedEvent event) { - if (!event.getCommand().equals("tphome")) + if (event.getArguments().length != 1 || !event.getArguments()[0].equalsIgnoreCase("home")) { return; } @@ -36,7 +38,8 @@ public class TpClanHomeGoal extends ObjectiveGoal { return; } - + + event.getPlayer().teleport(getObjective().getPlugin().getTutorialSession(event.getPlayer()).getHomeLocation()); finish(event.getPlayer()); } }