set
diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/HomeCommand.class.uniqueId2 b/build/tmp/compileJava/compileTransaction/stash-dir/HomeCommand.class.uniqueId2
new file mode 100644
index 0000000..540b301
Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/HomeCommand.class.uniqueId2 differ
diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/HyStuff.class.uniqueId0 b/build/tmp/compileJava/compileTransaction/stash-dir/HyStuff.class.uniqueId0
index 47fad80..dbcb087 100644
Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/HyStuff.class.uniqueId0 and b/build/tmp/compileJava/compileTransaction/stash-dir/HyStuff.class.uniqueId0 differ
diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/SetHomeCommand.class.uniqueId1 b/build/tmp/compileJava/compileTransaction/stash-dir/SetHomeCommand.class.uniqueId1
new file mode 100644
index 0000000..f617894
Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/SetHomeCommand.class.uniqueId1 differ
diff --git a/build/tmp/compileJava/previous-compilation-data.bin b/build/tmp/compileJava/previous-compilation-data.bin
index 43baa75..29c8bc2 100644
Binary files a/build/tmp/compileJava/previous-compilation-data.bin and b/build/tmp/compileJava/previous-compilation-data.bin differ
diff --git a/build/tmp/javadoc/javadoc.options b/build/tmp/javadoc/javadoc.options
index f84f3d2..24107e2 100644
--- a/build/tmp/javadoc/javadoc.options
+++ b/build/tmp/javadoc/javadoc.options
@@ -1,16 +1,16 @@
--classpath '/home/jomaa/IdeaProjects/HyStuff/build/classes/java/main:/home/jomaa/IdeaProjects/HyStuff/build/resources/main:/home/jomaa/.var/app/com.hypixel.HytaleLauncher/data/Hytale/install/release/package/game/latest/Server/HytaleServer.jar'
+-classpath '/home/jomaa/git/hystuff/build/classes/java/main:/home/jomaa/git/hystuff/build/resources/main:/home/jomaa/.var/app/com.hypixel.HytaleLauncher/data/Hytale/install/release/package/game/latest/Server/HytaleServer.jar'
-quiet
--d '/home/jomaa/IdeaProjects/HyStuff/build/docs/javadoc'
+-d '/home/jomaa/git/hystuff/build/docs/javadoc'
-windowtitle 'HyStuff 1.0.1 API'
-doctitle 'HyStuff 1.0.1 API'
-notimestamp
-Xdoclint:-missing '-quiet'
-'/home/jomaa/IdeaProjects/HyStuff/src/main/java/net/miarma/hystuff/common/LastPositionManager.java'
-'/home/jomaa/IdeaProjects/HyStuff/src/main/java/net/miarma/hystuff/common/Location.java'
-'/home/jomaa/IdeaProjects/HyStuff/src/main/java/net/miarma/hystuff/common/HomeManager.java'
-'/home/jomaa/IdeaProjects/HyStuff/src/main/java/net/miarma/hystuff/HyStuff.java'
-'/home/jomaa/IdeaProjects/HyStuff/src/main/java/net/miarma/hystuff/events/PlayerDeathListener.java'
-'/home/jomaa/IdeaProjects/HyStuff/src/main/java/net/miarma/hystuff/commands/BackCommand.java'
-'/home/jomaa/IdeaProjects/HyStuff/src/main/java/net/miarma/hystuff/commands/SetHomeCommand.java'
-'/home/jomaa/IdeaProjects/HyStuff/src/main/java/net/miarma/hystuff/commands/HomeCommand.java'
-'/home/jomaa/IdeaProjects/HyStuff/src/main/java/net/miarma/hystuff/commands/DisposalCommand.java'
+'/home/jomaa/git/hystuff/src/main/java/net/miarma/hystuff/common/LastPositionManager.java'
+'/home/jomaa/git/hystuff/src/main/java/net/miarma/hystuff/common/Location.java'
+'/home/jomaa/git/hystuff/src/main/java/net/miarma/hystuff/common/HomeManager.java'
+'/home/jomaa/git/hystuff/src/main/java/net/miarma/hystuff/HyStuff.java'
+'/home/jomaa/git/hystuff/src/main/java/net/miarma/hystuff/events/PlayerDeathListener.java'
+'/home/jomaa/git/hystuff/src/main/java/net/miarma/hystuff/commands/BackCommand.java'
+'/home/jomaa/git/hystuff/src/main/java/net/miarma/hystuff/commands/SetHomeCommand.java'
+'/home/jomaa/git/hystuff/src/main/java/net/miarma/hystuff/commands/HomeCommand.java'
+'/home/jomaa/git/hystuff/src/main/java/net/miarma/hystuff/commands/DisposalCommand.java'
diff --git a/src/main/java/net/miarma/hystuff/HyStuff.java b/src/main/java/net/miarma/hystuff/HyStuff.java
index 0558d10..24169f9 100644
--- a/src/main/java/net/miarma/hystuff/HyStuff.java
+++ b/src/main/java/net/miarma/hystuff/HyStuff.java
@@ -40,8 +40,8 @@ public class HyStuff extends JavaPlugin {
@Override
protected void setup() {
LOGGER.atInfo().log("------ HYSTUFF PLUGIN SETUP BEGIN ------");
- this.homeManager = new HomeManager(this.getDataDirectory(), LOGGER);
- this.lastPositionManager = new LastPositionManager();
+ this.homeManager = HomeManager.getInstance(this.getDataDirectory(), LOGGER);
+ this.lastPositionManager = LastPositionManager.getInstance();
this.playerDeathListener = new PlayerDeathListener(lastPositionManager, LOGGER);
LOGGER.atInfo().log("------- HYSTUFF PLUGIN SETUP END -------");
}
diff --git a/src/main/java/net/miarma/hystuff/commands/BackCommand.java b/src/main/java/net/miarma/hystuff/commands/BackCommand.java
index b1ce80d..6fa0a9d 100644
--- a/src/main/java/net/miarma/hystuff/commands/BackCommand.java
+++ b/src/main/java/net/miarma/hystuff/commands/BackCommand.java
@@ -38,19 +38,25 @@ public class BackCommand extends AbstractPlayerCommand {
UUID playerUuid = playerRef.getUuid();
Location lastPosition = this.lastPositionManager.get(playerUuid);
- final World targetWorld = Universe.get().getWorld(lastPosition.worldName()) != null ?
- Universe.get().getWorld(lastPosition.worldName()) : world;
+ if (!this.lastPositionManager.has(playerUuid)) {
+ ctx.sendMessage(Message.raw("You don't have a last position to return to."));
+ } else {
+ final World targetWorld = Universe.get().getWorld(lastPosition.worldName()) != null ?
+ Universe.get().getWorld(lastPosition.worldName()) : world;
- world.execute(() -> {
- Teleport teleport = Teleport.createForPlayer(
- targetWorld,
- lastPosition.toPosition(),
- lastPosition.toRotation()
- );
+ world.execute(() -> {
+ Teleport teleport = Teleport.createForPlayer(
+ targetWorld,
+ lastPosition.toPosition(),
+ lastPosition.toRotation()
+ );
- store.addComponent(ref, Teleport.getComponentType(), teleport);
- ctx.sendMessage(Message.raw(String.format("Teleporting to your last position at %.1f, %.1f, %.1f",
- lastPosition.x(), lastPosition.y(), lastPosition.z())));
- });
+ store.addComponent(ref, Teleport.getComponentType(), teleport);
+ ctx.sendMessage(Message.raw(String.format("Teleporting to your last position at %.1f, %.1f, %.1f",
+ lastPosition.x(), lastPosition.y(), lastPosition.z())));
+ });
+
+ this.lastPositionManager.clear(playerUuid);
+ }
}
}
diff --git a/src/main/java/net/miarma/hystuff/commands/HomeCommand.java b/src/main/java/net/miarma/hystuff/commands/HomeCommand.java
index 0315bf3..4356d01 100644
--- a/src/main/java/net/miarma/hystuff/commands/HomeCommand.java
+++ b/src/main/java/net/miarma/hystuff/commands/HomeCommand.java
@@ -2,6 +2,8 @@ package net.miarma.hystuff.commands;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.component.Store;
+import com.hypixel.hytale.math.vector.Vector3d;
+import com.hypixel.hytale.math.vector.Vector3f;
import com.hypixel.hytale.protocol.GameMode;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.CommandContext;
@@ -13,6 +15,7 @@ import com.hypixel.hytale.server.core.universe.Universe;
import com.hypixel.hytale.server.core.universe.world.World;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import net.miarma.hystuff.common.HomeManager;
+import net.miarma.hystuff.common.LastPositionManager;
import net.miarma.hystuff.common.Location;
import javax.annotation.Nonnull;
@@ -20,10 +23,12 @@ import java.util.UUID;
public class HomeCommand extends AbstractPlayerCommand {
private final HomeManager homeManager;
+ private final LastPositionManager lastPositionManager;
public HomeCommand(HomeManager homeManager) {
super("home", "Teleports you to your home");
this.homeManager = homeManager;
+ this.lastPositionManager = LastPositionManager.getInstance();
}
@Override
@@ -42,14 +47,21 @@ public class HomeCommand extends AbstractPlayerCommand {
if (home == null) {
ctx.sendMessage(Message.raw("You don't have a home set. Use /sethome first."));
} else {
+ World currentWorld = Universe.get().getWorld(playerRef.getWorldUuid());
+ Vector3d pos = playerRef.getTransform().getPosition();
+ Vector3f rotation = playerRef.getHeadRotation();
+ Location currentLocation = new Location(currentWorld.getName(), pos.getX(), pos.getY(),
+ pos.getZ(), rotation.getYaw(), rotation.getPitch());
+ this.lastPositionManager.set(playerUuid, currentLocation);
+
final World homeWorld = Universe.get().getWorld(home.worldName()) != null ?
Universe.get().getWorld(home.worldName()) : world;
world.execute(() -> {
Teleport teleport = Teleport.createForPlayer(
- homeWorld,
- home.toPosition(),
- home.toRotation()
+ homeWorld,
+ home.toPosition(),
+ home.toRotation()
);
store.addComponent(ref, Teleport.getComponentType(), teleport);
ctx.sendMessage(Message.raw(String.format("Teleporting to your home at %.1f, %.1f, %.1f",
diff --git a/src/main/java/net/miarma/hystuff/commands/SetHomeCommand.java b/src/main/java/net/miarma/hystuff/commands/SetHomeCommand.java
index e70038e..8aa20af 100644
--- a/src/main/java/net/miarma/hystuff/commands/SetHomeCommand.java
+++ b/src/main/java/net/miarma/hystuff/commands/SetHomeCommand.java
@@ -41,7 +41,7 @@ public class SetHomeCommand extends AbstractPlayerCommand {
ctx.sendMessage(Message.raw("Could not get your position."));
} else {
HeadRotation headRotation = store.getComponent(ref, HeadRotation.getComponentType());
- Vector3f rotation = headRotation != null ? headRotation.getRotation() : new Vector3f(0.0f, 0.0f, 0.0f);
+ Vector3f rotation = headRotation.getRotation();
Vector3d position = transform.getPosition();
UUID playerUuid = playerRef.getUuid();
this.homeManager.setHome(playerUuid, world, position, rotation);
diff --git a/src/main/java/net/miarma/hystuff/common/HomeManager.java b/src/main/java/net/miarma/hystuff/common/HomeManager.java
index 9175faa..0649e39 100644
--- a/src/main/java/net/miarma/hystuff/common/HomeManager.java
+++ b/src/main/java/net/miarma/hystuff/common/HomeManager.java
@@ -27,13 +27,20 @@ public class HomeManager {
private final Path dataDir;
private final HytaleLogger LOGGER;
private final Map homes = new ConcurrentHashMap<>();
+ private static HomeManager _instance;
- public HomeManager(@Nonnull Path dataDir, @Nonnull HytaleLogger logger) {
+ private HomeManager(@Nonnull Path dataDir, @Nonnull HytaleLogger logger) {
this.dataDir = dataDir;
this.LOGGER = logger;
this.load();
}
+ public static HomeManager getInstance(@Nonnull Path dataDir, @Nonnull HytaleLogger logger) {
+ if(_instance == null)
+ _instance = new HomeManager(dataDir, logger);
+ return _instance;
+ }
+
private void load() {
Path homesFile = this.dataDir.resolve(HOMES_FILE);
if(!Files.exists(homesFile)) {
diff --git a/src/main/java/net/miarma/hystuff/common/LastPositionManager.java b/src/main/java/net/miarma/hystuff/common/LastPositionManager.java
index 9068a1c..7e5aba1 100644
--- a/src/main/java/net/miarma/hystuff/common/LastPositionManager.java
+++ b/src/main/java/net/miarma/hystuff/common/LastPositionManager.java
@@ -9,6 +9,18 @@ import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public class LastPositionManager {
+ private static LastPositionManager _instance;
+
+ private LastPositionManager() {
+
+ }
+
+ public static LastPositionManager getInstance() {
+ if(_instance == null)
+ _instance = new LastPositionManager();
+ return _instance;
+ }
+
private final Map lastPositions = new ConcurrentHashMap<>();
public void set(UUID uuid, Location pos) {