Random improvments and bug fixes
This commit is contained in:
parent
13051a8684
commit
c5b7f07456
@ -24,7 +24,10 @@ public class HelpCommand extends MCommand
|
|||||||
|
|
||||||
ArrayList<String> lines = new ArrayList<String>();
|
ArrayList<String> lines = new ArrayList<String>();
|
||||||
|
|
||||||
lines.addAll(Txt.parse(parentCommand.getHelp()));
|
for (String helpline : parentCommand.getHelp())
|
||||||
|
{
|
||||||
|
lines.add(Txt.parse("<a>#<i> "+helpline));
|
||||||
|
}
|
||||||
|
|
||||||
for(MCommand subCommand : parentCommand.getSubCommands())
|
for(MCommand subCommand : parentCommand.getSubCommands())
|
||||||
{
|
{
|
||||||
|
@ -12,6 +12,7 @@ import com.massivecraft.mcore1.MCore;
|
|||||||
import com.massivecraft.mcore1.MPlugin;
|
import com.massivecraft.mcore1.MPlugin;
|
||||||
import com.massivecraft.mcore1.cmd.arg.IArgHandler;
|
import com.massivecraft.mcore1.cmd.arg.IArgHandler;
|
||||||
import com.massivecraft.mcore1.cmd.req.IReq;
|
import com.massivecraft.mcore1.cmd.req.IReq;
|
||||||
|
import com.massivecraft.mcore1.cmd.req.ReqHasPerm;
|
||||||
import com.massivecraft.mcore1.util.Perm;
|
import com.massivecraft.mcore1.util.Perm;
|
||||||
import com.massivecraft.mcore1.util.Txt;
|
import com.massivecraft.mcore1.util.Txt;
|
||||||
|
|
||||||
@ -77,22 +78,35 @@ public abstract class MCommand
|
|||||||
public void setDesc(String val) { this.desc = val; }
|
public void setDesc(String val) { this.desc = val; }
|
||||||
public String getDesc()
|
public String getDesc()
|
||||||
{
|
{
|
||||||
if (this.desc == null)
|
if (this.desc != null) return this.desc;
|
||||||
|
|
||||||
|
String perm = this.getDescPermission();
|
||||||
|
if (perm != null)
|
||||||
{
|
{
|
||||||
String pdesc = Perm.getPermissionDescription(this.descPermission);
|
String pdesc = Perm.getPermissionDescription(this.getDescPermission());
|
||||||
if (pdesc != null)
|
if (pdesc != null)
|
||||||
{
|
{
|
||||||
return pdesc;
|
return pdesc;
|
||||||
}
|
}
|
||||||
return "*info unavailable*";
|
|
||||||
}
|
}
|
||||||
return this.desc;
|
|
||||||
|
return "*info unavailable*";
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIELD: descPermission
|
// FIELD: descPermission
|
||||||
// This permission node IS NOT TESTED AT ALL. It is rather used in the method above.
|
// This permission node IS NOT TESTED AT ALL. It is rather used in the method above.
|
||||||
protected String descPermission;
|
protected String descPermission;
|
||||||
public String getDescPermission() { return this.descPermission; }
|
public String getDescPermission()
|
||||||
|
{
|
||||||
|
if (this.descPermission != null) return this.descPermission;
|
||||||
|
// Otherwise we try to find one.
|
||||||
|
for (IReq req : this.requirements)
|
||||||
|
{
|
||||||
|
if ( ! (req instanceof ReqHasPerm)) continue;
|
||||||
|
return ((ReqHasPerm)req).getPerm();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
public void setDescPermission(String val) { this.descPermission = val; }
|
public void setDescPermission(String val) { this.descPermission = val; }
|
||||||
|
|
||||||
// FIELD: help
|
// FIELD: help
|
||||||
@ -437,7 +451,7 @@ public abstract class MCommand
|
|||||||
T ret = handler.parse(this.arg(idx), style, this.sender, p());
|
T ret = handler.parse(this.arg(idx), style, this.sender, p());
|
||||||
if (ret == null)
|
if (ret == null)
|
||||||
{
|
{
|
||||||
this.msg(handler.getError());
|
this.msg(handler.getErrors());
|
||||||
return defaultNotFound;
|
return defaultNotFound;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -15,7 +15,7 @@ public abstract class AHBase<T> implements IArgHandler<T>
|
|||||||
public abstract T parse(String str, String style, CommandSender sender, MPlugin p);
|
public abstract T parse(String str, String style, CommandSender sender, MPlugin p);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<String> getError()
|
public Collection<String> getErrors()
|
||||||
{
|
{
|
||||||
return this.error;
|
return this.error;
|
||||||
}
|
}
|
||||||
|
@ -12,5 +12,5 @@ public interface IArgHandler<T>
|
|||||||
public T parse(String str, String style, CommandSender sender, MPlugin p);
|
public T parse(String str, String style, CommandSender sender, MPlugin p);
|
||||||
|
|
||||||
// Error here - or null.
|
// Error here - or null.
|
||||||
public Collection<String> getError();
|
public Collection<String> getErrors();
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package com.massivecraft.mcore1.persist.gson.adapter;
|
package com.massivecraft.mcore1.gson;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
@ -3,6 +3,7 @@ package com.massivecraft.mcore1.util;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import net.minecraft.server.ChunkPosition;
|
import net.minecraft.server.ChunkPosition;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
@ -11,6 +12,8 @@ import net.minecraft.server.Packet60Explosion;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Effect;
|
import org.bukkit.Effect;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.craftbukkit.CraftServer;
|
import org.bukkit.craftbukkit.CraftServer;
|
||||||
import org.bukkit.craftbukkit.CraftWorld;
|
import org.bukkit.craftbukkit.CraftWorld;
|
||||||
|
|
||||||
@ -91,30 +94,47 @@ public class SmokeUtil
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fake Explosion ========
|
// Fake Explosion ========
|
||||||
|
public static void fakeExplosion(Location location)
|
||||||
|
{
|
||||||
|
fakeExplosion(location, 4);
|
||||||
|
}
|
||||||
|
|
||||||
public static void fakeExplosion(Location location, int radius)
|
public static void fakeExplosion(Location location, int radius)
|
||||||
{
|
{
|
||||||
if (location == null) return;
|
if (location == null) return;
|
||||||
|
World world = location.getWorld();
|
||||||
HashSet<ChunkPosition> blocks = new HashSet<ChunkPosition>();
|
Set<Block> blocks = new HashSet<Block>();
|
||||||
int squRadius = radius * radius;
|
int r2 = radius * radius;
|
||||||
for(int x = -radius; x <= radius; x++)
|
for(int x = -radius; x <= radius; x++)
|
||||||
{
|
{
|
||||||
for(int y = -radius; y <= radius; y++)
|
for(int y = -radius; y <= radius; y++)
|
||||||
{
|
{
|
||||||
for(int z = -radius; z <= radius; z++)
|
for(int z = -radius; z <= radius; z++)
|
||||||
{
|
{
|
||||||
if(x*x+y*y+z*z+x+y+z+0.75 < squRadius) // ???
|
if(x*x + y*y + z*z + x+y+z + 0.75 > r2) continue;
|
||||||
{
|
Block toadd = world.getBlockAt((int)(location.getX()+x+0.5), (int)(location.getY()+x+0.5), (int)(location.getZ()+x+0.5));
|
||||||
blocks.add(new ChunkPosition(
|
if (toadd == null) continue;
|
||||||
(int)(location.getX()+x+0.5),
|
if (toadd.getTypeId() != 0) continue;
|
||||||
(int)(location.getY()+y+0.5),
|
blocks.add(toadd);
|
||||||
(int)(location.getZ()+z+0.5)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fakeExplosion(location, blocks);
|
||||||
|
}
|
||||||
|
|
||||||
Packet60Explosion packet = new Packet60Explosion(location.getX(),location.getY(), location.getZ(), 0.1f, blocks);
|
protected static void fakeExplosion(Location location, Set<Block> blocks)
|
||||||
|
{
|
||||||
|
if (blocks == null) return;
|
||||||
|
if (blocks.size() == 0) return;
|
||||||
|
|
||||||
|
HashSet<ChunkPosition> chunkPositions = new HashSet<ChunkPosition>(blocks.size());
|
||||||
|
|
||||||
|
for (Block block : blocks)
|
||||||
|
{
|
||||||
|
chunkPositions.add(new ChunkPosition(block.getX(), block.getY(), block.getZ()));
|
||||||
|
}
|
||||||
|
|
||||||
|
Packet60Explosion packet = new Packet60Explosion(location.getX(),location.getY(), location.getZ(), 0.1f, chunkPositions);
|
||||||
CraftServer craftServer = (CraftServer) Bukkit.getServer();
|
CraftServer craftServer = (CraftServer) Bukkit.getServer();
|
||||||
MinecraftServer minecraftServer = craftServer.getServer();
|
MinecraftServer minecraftServer = craftServer.getServer();
|
||||||
|
|
||||||
|
@ -198,12 +198,12 @@ public class Txt
|
|||||||
else return string + repeat(string, times-1);
|
else return string + repeat(string, times-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String implode(List<String> list, String glue)
|
public static String implode(final List<? extends Object> list, final String glue)
|
||||||
{
|
{
|
||||||
return implode(list.toArray(new String[0]), glue);
|
return implode(list.toArray(new Object[0]), glue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String implode(Object[] list, String glue)
|
public static String implode(final Object[] list, final String glue)
|
||||||
{
|
{
|
||||||
StringBuilder ret = new StringBuilder();
|
StringBuilder ret = new StringBuilder();
|
||||||
for (int i=0; i<list.length; i++)
|
for (int i=0; i<list.length; i++)
|
||||||
@ -217,38 +217,56 @@ public class Txt
|
|||||||
return ret.toString();
|
return ret.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String implodeCommaAndDot(List<String> list, String comma, String and, String dot)
|
public static String implodeCommaAndDot(final Collection<? extends Object> objects, final String comma, final String and, final String dot)
|
||||||
{
|
{
|
||||||
if (list.size() == 0) return "";
|
if (objects.size() == 0) return "";
|
||||||
if (list.size() == 1) return list.get(0);
|
if (objects.size() == 1) return objects.iterator().next().toString();
|
||||||
|
|
||||||
String lastItem = list.get(list.size()-1);
|
List<Object> ourObjects = new ArrayList<Object>(objects);
|
||||||
String nextToLastItem = list.get(list.size()-2);
|
|
||||||
|
String lastItem = ourObjects.get(ourObjects.size()-1).toString();
|
||||||
|
String nextToLastItem = ourObjects.get(ourObjects.size()-2).toString();
|
||||||
String merge = nextToLastItem+and+lastItem;
|
String merge = nextToLastItem+and+lastItem;
|
||||||
list.set(list.size()-2, merge);
|
ourObjects.set(ourObjects.size()-2, merge);
|
||||||
list.remove(list.size()-1);
|
ourObjects.remove(ourObjects.size()-1);
|
||||||
|
|
||||||
return implode(list, comma)+dot;
|
return implode(ourObjects, comma)+dot;
|
||||||
}
|
}
|
||||||
public static String implodeCommaAnd(List<String> list, String comma, String and)
|
public static String implodeCommaAnd(final Collection<? extends Object> objects, final String comma, final String and)
|
||||||
{
|
{
|
||||||
return implodeCommaAndDot(list, comma, and, "");
|
return implodeCommaAndDot(objects, comma, and, "");
|
||||||
}
|
}
|
||||||
public static String implodeCommaAndDot(List<String> list, String color)
|
public static String implodeCommaAndDot(final Collection<? extends Object> objects, final String color)
|
||||||
{
|
{
|
||||||
return implodeCommaAndDot(list, color+", ", color+" and ", color+".");
|
return implodeCommaAndDot(objects, color+", ", color+" and ", color+".");
|
||||||
}
|
}
|
||||||
public static String implodeCommaAnd(List<String> list, String color)
|
public static String implodeCommaAnd(final Collection<? extends Object> objects, final String color)
|
||||||
{
|
{
|
||||||
return implodeCommaAndDot(list, color+", ", color+" and ", "");
|
return implodeCommaAndDot(objects, color+", ", color+" and ", "");
|
||||||
}
|
}
|
||||||
public static String implodeCommaAndDot(List<String> list)
|
public static String implodeCommaAndDot(final Collection<? extends Object> objects)
|
||||||
{
|
{
|
||||||
return implodeCommaAndDot(list, "");
|
return implodeCommaAndDot(objects, "");
|
||||||
}
|
}
|
||||||
public static String implodeCommaAnd(List<String> list)
|
public static String implodeCommaAnd(final Collection<? extends Object> objects)
|
||||||
{
|
{
|
||||||
return implodeCommaAnd(list, "");
|
return implodeCommaAnd(objects, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer indexOfFirstDigit(final String str)
|
||||||
|
{
|
||||||
|
Integer ret = null;
|
||||||
|
for (int i = 0; i < str.length(); i++)
|
||||||
|
{
|
||||||
|
char c = str.charAt(i);
|
||||||
|
boolean isDigit = (c >= '0' && c <= '9');
|
||||||
|
if (isDigit)
|
||||||
|
{
|
||||||
|
ret = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -290,7 +308,7 @@ public class Txt
|
|||||||
ArrayList<String> ret = new ArrayList<String>();
|
ArrayList<String> ret = new ArrayList<String>();
|
||||||
int pageZeroBased = pageHumanBased - 1;
|
int pageZeroBased = pageHumanBased - 1;
|
||||||
int pageheight = 9;
|
int pageheight = 9;
|
||||||
int pagecount = (lines.size() / pageheight)+1;
|
int pagecount = (int)Math.ceil(((double)lines.size()) / pageheight);
|
||||||
|
|
||||||
ret.add(titleize(title+parse("<a>")+" "+pageHumanBased+"/"+pagecount));
|
ret.add(titleize(title+parse("<a>")+" "+pageHumanBased+"/"+pagecount));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user