Random improvments and bug fixes

This commit is contained in:
Olof Larsson 2012-01-11 22:57:55 +01:00
parent 13051a8684
commit c5b7f07456
7 changed files with 98 additions and 43 deletions

View File

@ -24,7 +24,10 @@ public class HelpCommand extends MCommand
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())
{

View File

@ -12,6 +12,7 @@ import com.massivecraft.mcore1.MCore;
import com.massivecraft.mcore1.MPlugin;
import com.massivecraft.mcore1.cmd.arg.IArgHandler;
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.Txt;
@ -77,22 +78,35 @@ public abstract class MCommand
public void setDesc(String val) { this.desc = val; }
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)
{
return pdesc;
}
return "*info unavailable*";
}
return this.desc;
return "*info unavailable*";
}
// FIELD: descPermission
// This permission node IS NOT TESTED AT ALL. It is rather used in the method above.
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; }
// FIELD: help
@ -437,7 +451,7 @@ public abstract class MCommand
T ret = handler.parse(this.arg(idx), style, this.sender, p());
if (ret == null)
{
this.msg(handler.getError());
this.msg(handler.getErrors());
return defaultNotFound;
}
return ret;

View File

@ -15,7 +15,7 @@ public abstract class AHBase<T> implements IArgHandler<T>
public abstract T parse(String str, String style, CommandSender sender, MPlugin p);
@Override
public Collection<String> getError()
public Collection<String> getErrors()
{
return this.error;
}

View File

@ -12,5 +12,5 @@ public interface IArgHandler<T>
public T parse(String str, String style, CommandSender sender, MPlugin p);
// Error here - or null.
public Collection<String> getError();
public Collection<String> getErrors();
}

View File

@ -1,4 +1,4 @@
package com.massivecraft.mcore1.persist.gson.adapter;
package com.massivecraft.mcore1.gson;
import java.lang.reflect.Type;
import java.util.ArrayList;

View File

@ -3,6 +3,7 @@ package com.massivecraft.mcore1.util;
import java.util.Collection;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import net.minecraft.server.ChunkPosition;
import net.minecraft.server.MinecraftServer;
@ -11,6 +12,8 @@ import net.minecraft.server.Packet60Explosion;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
@ -91,30 +94,47 @@ public class SmokeUtil
}
// Fake Explosion ========
public static void fakeExplosion(Location location)
{
fakeExplosion(location, 4);
}
public static void fakeExplosion(Location location, int radius)
{
if (location == null) return;
HashSet<ChunkPosition> blocks = new HashSet<ChunkPosition>();
int squRadius = radius * radius;
World world = location.getWorld();
Set<Block> blocks = new HashSet<Block>();
int r2 = radius * radius;
for(int x = -radius; x <= radius; x++)
{
for(int y = -radius; y <= radius; y++)
{
for(int z = -radius; z <= radius; z++)
{
if(x*x+y*y+z*z+x+y+z+0.75 < squRadius) // ???
{
blocks.add(new ChunkPosition(
(int)(location.getX()+x+0.5),
(int)(location.getY()+y+0.5),
(int)(location.getZ()+z+0.5)));
}
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));
if (toadd == null) continue;
if (toadd.getTypeId() != 0) continue;
blocks.add(toadd);
}
}
}
fakeExplosion(location, blocks);
}
protected static void fakeExplosion(Location location, Set<Block> blocks)
{
if (blocks == null) return;
if (blocks.size() == 0) return;
Packet60Explosion packet = new Packet60Explosion(location.getX(),location.getY(), location.getZ(), 0.1f, blocks);
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();
MinecraftServer minecraftServer = craftServer.getServer();

View File

@ -198,12 +198,12 @@ public class Txt
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();
for (int i=0; i<list.length; i++)
@ -217,38 +217,56 @@ public class Txt
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 (list.size() == 1) return list.get(0);
if (objects.size() == 0) return "";
if (objects.size() == 1) return objects.iterator().next().toString();
String lastItem = list.get(list.size()-1);
String nextToLastItem = list.get(list.size()-2);
List<Object> ourObjects = new ArrayList<Object>(objects);
String lastItem = ourObjects.get(ourObjects.size()-1).toString();
String nextToLastItem = ourObjects.get(ourObjects.size()-2).toString();
String merge = nextToLastItem+and+lastItem;
list.set(list.size()-2, merge);
list.remove(list.size()-1);
ourObjects.set(ourObjects.size()-2, merge);
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>();
int pageZeroBased = pageHumanBased - 1;
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));