Save their previous GameMode if it is enabled in the config.

Need to update the wiki with the new config option.
This commit is contained in:
graywolf336 2013-12-25 22:57:09 -06:00
parent 6423e8d2e5
commit aaa286fbdd
6 changed files with 33 additions and 0 deletions

View File

@ -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)
====

View File

@ -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);
}
}

View File

@ -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());
}
}
}

View File

@ -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);
}
}

View File

@ -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;

View File

@ -28,4 +28,5 @@ jailing:
release:
backToPreviousPosition: false
commands: []
restorePreviousGameMode: false
teleport: true