More generic database convenience methods.
This commit is contained in:
parent
d80a0f4865
commit
8f6bcf2be9
@ -1,5 +1,7 @@
|
|||||||
package com.massivecraft.massivecore.store;
|
package com.massivecraft.massivecore.store;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import com.massivecraft.massivecore.MassiveCore;
|
import com.massivecraft.massivecore.MassiveCore;
|
||||||
import com.massivecraft.massivecore.store.accessor.Accessor;
|
import com.massivecraft.massivecore.store.accessor.Accessor;
|
||||||
import com.massivecraft.massivecore.xlib.gson.Gson;
|
import com.massivecraft.massivecore.xlib.gson.Gson;
|
||||||
@ -171,7 +173,19 @@ public class Entity<E extends Entity<E>>
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// CONVENIENCE: DATABASE
|
// CONVENIENCE: DATABASE
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public <T> T convertGet(T value, T defaultValue)
|
||||||
|
{
|
||||||
|
return value != null ? value : defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T convertSet(T value, T defaultValue)
|
||||||
|
{
|
||||||
|
this.changed();
|
||||||
|
return Objects.equals(value, defaultValue) ? null : value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Boolean specific
|
||||||
public boolean convertGet(Boolean wrapper)
|
public boolean convertGet(Boolean wrapper)
|
||||||
{
|
{
|
||||||
return wrapper != null ? wrapper.booleanValue() : false;
|
return wrapper != null ? wrapper.booleanValue() : false;
|
||||||
|
@ -8,6 +8,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.google.common.base.Objects;
|
||||||
import com.massivecraft.massivecore.Named;
|
import com.massivecraft.massivecore.Named;
|
||||||
import com.massivecraft.massivecore.mixin.Mixin;
|
import com.massivecraft.massivecore.mixin.Mixin;
|
||||||
import com.massivecraft.massivecore.mson.Mson;
|
import com.massivecraft.massivecore.mson.Mson;
|
||||||
@ -64,6 +65,19 @@ public abstract class SenderEntity<E extends SenderEntity<E>> extends Entity<E>
|
|||||||
// CONVENIENCE: DATABASE
|
// CONVENIENCE: DATABASE
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public <T> T convertGet(T value, T defaultValue, String permission)
|
||||||
|
{
|
||||||
|
// Create
|
||||||
|
T ret = super.convertGet(value, defaultValue);
|
||||||
|
|
||||||
|
// Permission Requirement
|
||||||
|
if ( ! Objects.equal(value, defaultValue) && ! PermUtil.has(this.getSender(), permission)) return defaultValue;
|
||||||
|
|
||||||
|
// Return
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Boolean specific
|
||||||
public boolean convertGet(Boolean wrapper, String permission)
|
public boolean convertGet(Boolean wrapper, String permission)
|
||||||
{
|
{
|
||||||
// Create
|
// Create
|
||||||
|
Loading…
Reference in New Issue
Block a user