Implemented a mstore mcore config with custom permission denied formats.
This commit is contained in:
parent
d274874092
commit
edabc02555
@ -25,13 +25,13 @@ public class ConfServer extends SimpleConfig
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public static String dburi = "gson://./mstore";
|
public static String dburi = "gson://./mstore";
|
||||||
|
|
||||||
public static String serverid = UUID.randomUUID().toString();
|
public static String serverid = UUID.randomUUID().toString();
|
||||||
|
|
||||||
public static Map<String, List<String>> cmdaliases = MUtil.map(
|
public static Map<String, List<String>> cmdaliases = MUtil.map(
|
||||||
CmdUsys.USYS, MUtil.list(CmdUsys.USYS),
|
CmdUsys.USYS, MUtil.list(CmdUsys.USYS),
|
||||||
CmdMcore.MCORE, MUtil.list(CmdMcore.MCORE)
|
CmdMcore.MCORE, MUtil.list(CmdMcore.MCORE)
|
||||||
);
|
);
|
||||||
public static int tpdelay = 10;
|
|
||||||
|
|
||||||
public static List<String> getCmdAliases(String name)
|
public static List<String> getCmdAliases(String name)
|
||||||
{
|
{
|
||||||
List<String> ret = cmdaliases.get(name);
|
List<String> ret = cmdaliases.get(name);
|
||||||
@ -44,6 +44,7 @@ public class ConfServer extends SimpleConfig
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int tpdelay = 10;
|
||||||
public static int getTpdelay(Permissible permissible)
|
public static int getTpdelay(Permissible permissible)
|
||||||
{
|
{
|
||||||
if (Perm.NOTPDELAY.has(permissible, false)) return 0;
|
if (Perm.NOTPDELAY.has(permissible, false)) return 0;
|
||||||
|
@ -23,6 +23,7 @@ import org.bukkit.event.player.PlayerTeleportEvent;
|
|||||||
|
|
||||||
import com.massivecraft.mcore.event.MCoreAfterPlayerRespawnEvent;
|
import com.massivecraft.mcore.event.MCoreAfterPlayerRespawnEvent;
|
||||||
import com.massivecraft.mcore.event.MCoreAfterPlayerTeleportEvent;
|
import com.massivecraft.mcore.event.MCoreAfterPlayerTeleportEvent;
|
||||||
|
import com.massivecraft.mcore.event.MCorePermissionDeniedFormatEvent;
|
||||||
import com.massivecraft.mcore.event.MCorePlayerLeaveEvent;
|
import com.massivecraft.mcore.event.MCorePlayerLeaveEvent;
|
||||||
import com.massivecraft.mcore.event.MCoreSenderRegisterEvent;
|
import com.massivecraft.mcore.event.MCoreSenderRegisterEvent;
|
||||||
import com.massivecraft.mcore.event.MCoreSenderUnregisterEvent;
|
import com.massivecraft.mcore.event.MCoreSenderUnregisterEvent;
|
||||||
@ -51,6 +52,24 @@ public class InternalListener implements Listener
|
|||||||
Bukkit.getPluginManager().registerEvents(this, MCore.get());
|
Bukkit.getPluginManager().registerEvents(this, MCore.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// PERMISSION DENIED FORMAT
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
|
public void permissionDeniedFormat(MCorePermissionDeniedFormatEvent event)
|
||||||
|
{
|
||||||
|
// If noone set a format already ...
|
||||||
|
if (event.hasFormat()) return;
|
||||||
|
|
||||||
|
// ... and we have a custom format in the config ...
|
||||||
|
String customFormat = MCoreConf.get().getPermissionDeniedFormat(event.getPermissionName());
|
||||||
|
if (customFormat == null) return;
|
||||||
|
|
||||||
|
// ... then make use of that format.
|
||||||
|
event.setFormat(customFormat);
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// CHAT TAB COMPLETE
|
// CHAT TAB COMPLETE
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
@ -109,6 +109,7 @@ public class MCore extends MPlugin
|
|||||||
|
|
||||||
if ( ! preEnable()) return;
|
if ( ! preEnable()) return;
|
||||||
|
|
||||||
|
// Load Server Config
|
||||||
ConfServer.get().load();
|
ConfServer.get().load();
|
||||||
|
|
||||||
// Setup the default database
|
// Setup the default database
|
||||||
@ -127,9 +128,10 @@ public class MCore extends MPlugin
|
|||||||
// Schedule the collection ticker.
|
// Schedule the collection ticker.
|
||||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this.collTickTask, 1, 1);
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this.collTickTask, 1, 1);
|
||||||
|
|
||||||
// Init internal collections
|
// Initialize Internal Collections
|
||||||
MultiverseColl.get().init();
|
MultiverseColl.get().init();
|
||||||
AspectColl.get().init();
|
AspectColl.get().init();
|
||||||
|
MCoreConfColl.get().init();
|
||||||
|
|
||||||
// Register commands
|
// Register commands
|
||||||
this.cmdUsys = new CmdUsys();
|
this.cmdUsys = new CmdUsys();
|
||||||
|
71
src/com/massivecraft/mcore/MCoreConf.java
Normal file
71
src/com/massivecraft/mcore/MCoreConf.java
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
package com.massivecraft.mcore;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.massivecraft.mcore.MCore;
|
||||||
|
import com.massivecraft.mcore.store.Entity;
|
||||||
|
import com.massivecraft.mcore.util.MUtil;
|
||||||
|
|
||||||
|
public class MCoreConf extends Entity<MCoreConf, String>
|
||||||
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// META
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static MCoreConf get()
|
||||||
|
{
|
||||||
|
return MCoreConfColl.get().get(MCore.INSTANCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// OVERRIDE
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MCoreConf load(MCoreConf that)
|
||||||
|
{
|
||||||
|
this.permissionDeniedFormats = that.permissionDeniedFormats;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// FIELDS
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// These getters and setters are obnoxious, defensive copying, NPE avoiding and probably thread safe.
|
||||||
|
|
||||||
|
private Map<String, String> permissionDeniedFormats = MUtil.map(
|
||||||
|
"some.awesome.permission.node", "<b>You must be awesome to %s<b>.",
|
||||||
|
"some.derp.permission.node", "<b>Only derp people can %s<b>.\n<i>Ask a moderator to become derp."
|
||||||
|
);
|
||||||
|
public Map<String, String> getPermissionDeniedFormats() { return this.permissionDeniedFormats == null ? new LinkedHashMap<String, String>() : new LinkedHashMap<String, String>(this.permissionDeniedFormats); }
|
||||||
|
public void setPermissionDeniedFormats(Map<String, String> permissionDeniedFormats) { this.permissionDeniedFormats = permissionDeniedFormats == null ? new LinkedHashMap<String, String>() : new LinkedHashMap<String, String>(permissionDeniedFormats); this.changed(); }
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// HELP ACCESS
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public String setPermissionDeniedFormat(String permissionName, String permissionDeniedFormat)
|
||||||
|
{
|
||||||
|
Map<String, String> temp = this.getPermissionDeniedFormats();
|
||||||
|
String ret = temp.put(permissionName, permissionDeniedFormat);
|
||||||
|
this.setPermissionDeniedFormats(temp);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String removePermissionDeniedFormat(String permissionName)
|
||||||
|
{
|
||||||
|
Map<String, String> temp = this.getPermissionDeniedFormats();
|
||||||
|
String ret = temp.remove(permissionName);
|
||||||
|
this.setPermissionDeniedFormats(temp);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPermissionDeniedFormat(String permissionName)
|
||||||
|
{
|
||||||
|
return this.getPermissionDeniedFormats().get(permissionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
38
src/com/massivecraft/mcore/MCoreConfColl.java
Normal file
38
src/com/massivecraft/mcore/MCoreConfColl.java
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package com.massivecraft.mcore;
|
||||||
|
|
||||||
|
import com.massivecraft.mcore.MCore;
|
||||||
|
import com.massivecraft.mcore.store.Coll;
|
||||||
|
import com.massivecraft.mcore.store.MStore;
|
||||||
|
|
||||||
|
public class MCoreConfColl extends Coll<MCoreConf, String>
|
||||||
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// INSTANCE & CONSTRUCT
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
private static MCoreConfColl i = new MCoreConfColl();
|
||||||
|
public static MCoreConfColl get() { return i; }
|
||||||
|
private MCoreConfColl()
|
||||||
|
{
|
||||||
|
super(MStore.getDb(ConfServer.dburi), MCore.get(), "ai", "mcore_conf", MCoreConf.class, String.class, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// OVERRIDE
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init()
|
||||||
|
{
|
||||||
|
super.init();
|
||||||
|
this.get(MCore.INSTANCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void loadFromRemote(Object oid)
|
||||||
|
{
|
||||||
|
super.loadFromRemote(oid);
|
||||||
|
if ( ! this.inited()) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -22,6 +22,7 @@ public class MCorePermissionDeniedFormatEvent extends MCoreEvent
|
|||||||
private String format;
|
private String format;
|
||||||
public String getFormat() { return this.format; }
|
public String getFormat() { return this.format; }
|
||||||
public void setFormat(String format) { this.format = format; }
|
public void setFormat(String format) { this.format = format; }
|
||||||
|
public boolean hasFormat() { return this.format != null; }
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// CONSTRUCT
|
// CONSTRUCT
|
||||||
|
Loading…
Reference in New Issue
Block a user