Added a few utils and fixed a few warnings
This commit is contained in:
parent
ecaa3759dc
commit
411f597cad
11
src/com/massivecraft/core/Lang.java
Executable file
11
src/com/massivecraft/core/Lang.java
Executable file
@ -0,0 +1,11 @@
|
|||||||
|
package com.massivecraft.core;
|
||||||
|
|
||||||
|
public class Lang
|
||||||
|
{
|
||||||
|
public static final String permForbidden = "<b>You don't have permission to %s.";
|
||||||
|
public static final String permDoThat = "do that";
|
||||||
|
|
||||||
|
public static final String commandSenderMustBePlayer = "<b>This command can only be used by ingame players.";
|
||||||
|
public static final String commandToFewArgs = "<b>To few arguments. <i>Use like this:";
|
||||||
|
public static final String commandToManyArgs = "<b>Strange argument \"<p>%s<b>\". <i>Use the command like this:";
|
||||||
|
}
|
@ -400,7 +400,7 @@ public final class Gson {
|
|||||||
* @return Json representation of {@code src}
|
* @return Json representation of {@code src}
|
||||||
* @since 1.4
|
* @since 1.4
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"unchecked", "rawtypes"}) // the caller is required to make src and typeOfSrc consistent
|
// the caller is required to make src and typeOfSrc consistent
|
||||||
public JsonElement toJsonTree(Object src, Type typeOfSrc) {
|
public JsonElement toJsonTree(Object src, Type typeOfSrc) {
|
||||||
JsonElementWriter writer = new JsonElementWriter();
|
JsonElementWriter writer = new JsonElementWriter();
|
||||||
toJson(src, typeOfSrc, writer);
|
toJson(src, typeOfSrc, writer);
|
||||||
@ -682,7 +682,8 @@ public final class Gson {
|
|||||||
* @throws JsonSyntaxException if json is not a valid representation for an object of type
|
* @throws JsonSyntaxException if json is not a valid representation for an object of type
|
||||||
* @since 1.2
|
* @since 1.2
|
||||||
*/
|
*/
|
||||||
public <T> T fromJson(Reader json, Type typeOfT) throws JsonIOException, JsonSyntaxException {
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T> T fromJson(Reader json, Type typeOfT) throws JsonIOException, JsonSyntaxException {
|
||||||
JsonReader jsonReader = new JsonReader(json);
|
JsonReader jsonReader = new JsonReader(json);
|
||||||
T object = (T) fromJson(jsonReader, typeOfT);
|
T object = (T) fromJson(jsonReader, typeOfT);
|
||||||
assertFullConsumption(object, jsonReader);
|
assertFullConsumption(object, jsonReader);
|
||||||
@ -777,7 +778,8 @@ public final class Gson {
|
|||||||
* @throws JsonSyntaxException if json is not a valid representation for an object of type typeOfT
|
* @throws JsonSyntaxException if json is not a valid representation for an object of type typeOfT
|
||||||
* @since 1.3
|
* @since 1.3
|
||||||
*/
|
*/
|
||||||
public <T> T fromJson(JsonElement json, Type typeOfT) throws JsonSyntaxException {
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T> T fromJson(JsonElement json, Type typeOfT) throws JsonSyntaxException {
|
||||||
if (json == null) {
|
if (json == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,8 @@ final class GsonToMiniGsonTypeAdapterFactory implements TypeAdapter.Factory {
|
|||||||
this.deserializers = deserializers;
|
this.deserializers = deserializers;
|
||||||
|
|
||||||
this.deserializationContext = new JsonDeserializationContext() {
|
this.deserializationContext = new JsonDeserializationContext() {
|
||||||
public <T> T deserialize(JsonElement json, Type typeOfT) throws JsonParseException {
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T> T deserialize(JsonElement json, Type typeOfT) throws JsonParseException {
|
||||||
return (T) gson.fromJson(json, typeOfT);
|
return (T) gson.fromJson(json, typeOfT);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
50
src/com/massivecraft/core/util/ClassLoadHack.java
Executable file
50
src/com/massivecraft/core/util/ClassLoadHack.java
Executable file
@ -0,0 +1,50 @@
|
|||||||
|
package com.massivecraft.core.util;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
|
||||||
|
public class ClassLoadHack
|
||||||
|
{
|
||||||
|
private static URLClassLoader sysloader = (URLClassLoader)ClassLoader.getSystemClassLoader();
|
||||||
|
|
||||||
|
public static boolean load(String filename)
|
||||||
|
{
|
||||||
|
return load(new File(filename));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean load(File file)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return load(file.toURI().toURL());
|
||||||
|
}
|
||||||
|
catch (MalformedURLException e)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean load(URL url)
|
||||||
|
{
|
||||||
|
// If the file already is loaded we can skip it
|
||||||
|
for (URL otherUrl : sysloader.getURLs())
|
||||||
|
{
|
||||||
|
if (otherUrl.sameFile(url)) return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Method addURLMethod = URLClassLoader.class.getDeclaredMethod("addURL", new Class[]{ URL.class });
|
||||||
|
addURLMethod.setAccessible(true);
|
||||||
|
addURLMethod.invoke(sysloader, new Object[]{ url });
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
68
src/com/massivecraft/core/util/PermUtil.java
Executable file
68
src/com/massivecraft/core/util/PermUtil.java
Executable file
@ -0,0 +1,68 @@
|
|||||||
|
package com.massivecraft.core.util;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.permissions.Permission;
|
||||||
|
|
||||||
|
import com.massivecraft.core.Lang;
|
||||||
|
|
||||||
|
public class PermUtil
|
||||||
|
{
|
||||||
|
public static String getPermissionDescription (String perm)
|
||||||
|
{
|
||||||
|
if (perm == null) return Lang.permDoThat;
|
||||||
|
Permission permission = Bukkit.getPluginManager().getPermission(perm);
|
||||||
|
return getPermissionDescription(permission);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getPermissionDescription (Permission perm)
|
||||||
|
{
|
||||||
|
if (perm == null) return Lang.permDoThat;
|
||||||
|
String desc = perm.getDescription();
|
||||||
|
if (desc == null || desc.length() == 0) return Lang.permDoThat;
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getForbiddenMessage(String perm)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
// TODO: Decouple the text util.
|
||||||
|
//return p.txt.parse(Lang.permForbidden, getPermissionDescription(perm));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean has (CommandSender me, String perm)
|
||||||
|
{
|
||||||
|
if (me == null) return false;
|
||||||
|
return me.hasPermission(perm);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean has (CommandSender me, String perm, boolean verbose)
|
||||||
|
{
|
||||||
|
if (has(me, perm))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (verbose && me != null)
|
||||||
|
{
|
||||||
|
me.sendMessage(this.getForbiddenMessage(perm));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T pickFirstVal(CommandSender me, Map<String, T> perm2val)
|
||||||
|
{
|
||||||
|
if (perm2val == null) return null;
|
||||||
|
T ret = null;
|
||||||
|
|
||||||
|
for ( Entry<String, T> entry : perm2val.entrySet())
|
||||||
|
{
|
||||||
|
ret = entry.getValue();
|
||||||
|
if (has(me, entry.getKey())) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
91
src/com/massivecraft/core/util/SmokeUtil.java
Executable file
91
src/com/massivecraft/core/util/SmokeUtil.java
Executable file
@ -0,0 +1,91 @@
|
|||||||
|
package com.massivecraft.core.util;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import org.bukkit.Effect;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
// http://mc.kev009.com/Protocol
|
||||||
|
// -----------------------------
|
||||||
|
// Smoke Directions
|
||||||
|
// -----------------------------
|
||||||
|
// Direction ID Direction
|
||||||
|
// 0 South - East
|
||||||
|
// 1 South
|
||||||
|
// 2 South - West
|
||||||
|
// 3 East
|
||||||
|
// 4 (Up or middle ?)
|
||||||
|
// 5 West
|
||||||
|
// 6 North - East
|
||||||
|
// 7 North
|
||||||
|
// 8 North - West
|
||||||
|
//-----------------------------
|
||||||
|
|
||||||
|
public class SmokeUtil
|
||||||
|
{
|
||||||
|
public static Random random = new Random();
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// Spawn once
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
// Single ========
|
||||||
|
public static void spawnSingle(Location location, int direction)
|
||||||
|
{
|
||||||
|
if (location == null) return;
|
||||||
|
location.getWorld().playEffect(location, Effect.SMOKE, direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void spawnSingle(Location location)
|
||||||
|
{
|
||||||
|
spawnSingle(location, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void spawnSingleRandom(Location location)
|
||||||
|
{
|
||||||
|
spawnSingle(location, random.nextInt(9));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simple Cloud ========
|
||||||
|
public static void spawnCloudSimple(Location location)
|
||||||
|
{
|
||||||
|
for (int i = 0; i <= 8; i++)
|
||||||
|
{
|
||||||
|
spawnSingle(location, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void spawnCloudSimple(Collection<Location> locations)
|
||||||
|
{
|
||||||
|
for (Location location : locations)
|
||||||
|
{
|
||||||
|
spawnCloudSimple(location);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Random Cloud ========
|
||||||
|
public static void spawnCloudRandom(Location location, float thickness)
|
||||||
|
{
|
||||||
|
int singles = (int) Math.floor(thickness*9);
|
||||||
|
for (int i = 0; i < singles; i++)
|
||||||
|
{
|
||||||
|
spawnSingleRandom(location);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void spawnCloudRandom(Collection<Location> locations, float thickness)
|
||||||
|
{
|
||||||
|
for (Location location : locations)
|
||||||
|
{
|
||||||
|
spawnCloudRandom(location, thickness);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// Attach continuous effects to or locations
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user