From aaa286fbddd560f514a9b8664097d4358c4e667d Mon Sep 17 00:00:00 2001 From: graywolf336 Date: Wed, 25 Dec 2013 22:57:09 -0600 Subject: [PATCH] Save their previous GameMode if it is enabled in the config. Need to update the wiki with the new config option. --- README.md | 1 + .../java/com/graywolf336/jail/JailIO.java | 4 ++++ .../com/graywolf336/jail/PrisonerManager.java | 6 ++++++ .../com/graywolf336/jail/beans/Prisoner.java | 20 +++++++++++++++++++ .../com/graywolf336/jail/enums/Settings.java | 1 + src/main/resources/config.yml | 1 + 6 files changed, 33 insertions(+) diff --git a/README.md b/README.md index a3ff32c..f1ddad2 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ Done * Config value ``jailing.jail.logToConsole`` is now used * Config value ``jailing.jail.deleteInventory`` is now used * Config value ``jailing.release.backToPreviousPosition`` is now used +* Config value ``jailing.release.restorePreviousGameMode`` is now used [Jail 3.0 JavaDoc](http://ci.graywolf336.com/job/Jail/javadoc) ==== \ No newline at end of file diff --git a/src/main/java/com/graywolf336/jail/JailIO.java b/src/main/java/com/graywolf336/jail/JailIO.java index 6dadd09..a58bb71 100644 --- a/src/main/java/com/graywolf336/jail/JailIO.java +++ b/src/main/java/com/graywolf336/jail/JailIO.java @@ -219,6 +219,7 @@ public class JailIO { flat.set(cNode + "prisoner.offlinePending", p.isOfflinePending()); flat.set(cNode + "prisoner.reason", p.getReason()); flat.set(cNode + "prisoner.previousLocation", p.getPreviousLocationString()); + flat.set(cNode + "prisoner.previousGameMode", p.getPreviousGameMode().toString()); } } @@ -229,6 +230,7 @@ public class JailIO { flat.set(pNode + "offlinePending", p.isOfflinePending()); flat.set(pNode + "reason", p.getReason()); flat.set(pNode + "previousLocation", p.getPreviousLocationString()); + flat.set(pNode + "previousGameMode", p.getPreviousGameMode().toString()); } try { @@ -308,6 +310,7 @@ public class JailIO { flat.getString(cellNode + "prisoner.reason")); p.setOfflinePending(flat.getBoolean(cellNode + "prisoner.offlinePending")); p.setPreviousPosition(flat.getString(cellNode + "prisoner.previousLocation")); + p.setPreviousGameMode(flat.getString(cellNode + "prisoner.previousGameMode")); c.setPrisoner(p); } @@ -324,6 +327,7 @@ public class JailIO { Prisoner pris = new Prisoner(prisoner, flat.getBoolean(pNode + "muted"), flat.getLong(pNode + "time"), flat.getString(pNode + "reason")); pris.setOfflinePending(flat.getBoolean(pNode + "offlinePending")); pris.setPreviousPosition(flat.getString(pNode + "previousLocation")); + pris.setPreviousGameMode(flat.getString(pNode + "previousGameMode")); j.addPrisoner(pris); } } diff --git a/src/main/java/com/graywolf336/jail/PrisonerManager.java b/src/main/java/com/graywolf336/jail/PrisonerManager.java index 0baf692..f540b14 100644 --- a/src/main/java/com/graywolf336/jail/PrisonerManager.java +++ b/src/main/java/com/graywolf336/jail/PrisonerManager.java @@ -116,5 +116,11 @@ public class PrisonerManager { if(pl.getConfig().getBoolean(Settings.RELEASETOPREVIOUSPOSITION.getPath(), false)) { prisoner.setPreviousPosition(player.getLocation()); } + + //If the config has restoring their previous gamemode enabled, + //then let's set it in their prisoner data. + if(pl.getConfig().getBoolean(Settings.RESTOREPREVIOUSGAMEMODE.getPath(), false)) { + prisoner.setPreviousGameMode(player.getGameMode()); + } } } diff --git a/src/main/java/com/graywolf336/jail/beans/Prisoner.java b/src/main/java/com/graywolf336/jail/beans/Prisoner.java index 7cad3f5..23061df 100644 --- a/src/main/java/com/graywolf336/jail/beans/Prisoner.java +++ b/src/main/java/com/graywolf336/jail/beans/Prisoner.java @@ -3,6 +3,7 @@ package com.graywolf336.jail.beans; import java.util.concurrent.TimeUnit; import org.bukkit.Bukkit; +import org.bukkit.GameMode; import org.bukkit.Location; /** @@ -17,6 +18,7 @@ public class Prisoner { private boolean muted, offlinePending, teleporting; private long time; private Location previousPosition; + private GameMode previousGameMode; /** * Creates a new prisoner with a name and whether they are muted or not. @@ -33,6 +35,7 @@ public class Prisoner { this.offlinePending = false; this.teleporting = false; this.previousPosition = null; + this.previousGameMode = null; } /** Gets the name of this player. */ @@ -133,4 +136,21 @@ public class Prisoner { Float.valueOf(s[4]), Float.valueOf(s[5])); } + + /** Gets the previous gamemode of this player. */ + public GameMode getPreviousGameMode() { + return this.previousGameMode; + } + + /** Sets the previous gamemode of this player. */ + public void setPreviousGameMode(GameMode previous) { + this.previousGameMode = previous; + } + + /** Sets the previous gamemode of this player based upon the provided string. */ + public void setPreviousGameMode(String previous) { + if(previous == null) return; + else if(previous.isEmpty()) return; + else this.previousGameMode = GameMode.valueOf(previous); + } } diff --git a/src/main/java/com/graywolf336/jail/enums/Settings.java b/src/main/java/com/graywolf336/jail/enums/Settings.java index efbf3a1..ff8091b 100644 --- a/src/main/java/com/graywolf336/jail/enums/Settings.java +++ b/src/main/java/com/graywolf336/jail/enums/Settings.java @@ -8,6 +8,7 @@ public enum Settings { JAILDEFAULTTIME("jailing.jail.defaultTime"), LOGJAILING("jailing.jail.logToConsole"), RELEASETOPREVIOUSPOSITION("jailing.release.backToPreviousPosition"), + RESTOREPREVIOUSGAMEMODE("jailing.release.restorePreviousGameMode"), UPDATENOTIFICATIONS("system.updateNotifications"); private String path; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 4ecc4cc..dc48f71 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -28,4 +28,5 @@ jailing: release: backToPreviousPosition: false commands: [] + restorePreviousGameMode: false teleport: true \ No newline at end of file