Player messages, support for more errorMessages, new color codes and some private to protected.
This commit is contained in:
parent
155344a7ad
commit
13051a8684
@ -6,6 +6,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -13,6 +14,7 @@ import com.massivecraft.mcore1.cmd.arg.AHBoolean;
|
||||
import com.massivecraft.mcore1.cmd.arg.AHDouble;
|
||||
import com.massivecraft.mcore1.cmd.arg.AHFloat;
|
||||
import com.massivecraft.mcore1.cmd.arg.AHInteger;
|
||||
import com.massivecraft.mcore1.cmd.arg.AHMaterial;
|
||||
import com.massivecraft.mcore1.cmd.arg.AHPlayer;
|
||||
import com.massivecraft.mcore1.cmd.arg.IArgHandler;
|
||||
|
||||
@ -48,9 +50,10 @@ public class Cmd
|
||||
public Cmd()
|
||||
{
|
||||
this.setArgHandler(Boolean.class, new AHBoolean());
|
||||
this.setArgHandler(Integer.class, new AHInteger());
|
||||
this.setArgHandler(Float.class, new AHFloat());
|
||||
this.setArgHandler(Double.class, new AHDouble());
|
||||
this.setArgHandler(Float.class, new AHFloat());
|
||||
this.setArgHandler(Integer.class, new AHInteger());
|
||||
this.setArgHandler(Material.class, new AHMaterial());
|
||||
this.setArgHandler(Player.class, new AHPlayer());
|
||||
}
|
||||
}
|
||||
|
@ -381,12 +381,20 @@ public abstract class MCommand
|
||||
sender.sendMessage(Txt.parse(str));
|
||||
}
|
||||
|
||||
public void msg(Collection<String> msgs)
|
||||
{
|
||||
for(String msg : msgs)
|
||||
{
|
||||
this.msg(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMessage(String msg)
|
||||
{
|
||||
sender.sendMessage(msg);
|
||||
}
|
||||
|
||||
public void sendMessage(List<String> msgs)
|
||||
public void sendMessage(Collection<String> msgs)
|
||||
{
|
||||
for(String msg : msgs)
|
||||
{
|
||||
|
@ -1,18 +1,21 @@
|
||||
package com.massivecraft.mcore1.cmd.arg;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.mcore1.MPlugin;
|
||||
|
||||
public abstract class AHBase<T> implements IArgHandler<T>
|
||||
{
|
||||
protected String error = null;
|
||||
protected Collection<String> error = new ArrayList<String>();
|
||||
|
||||
@Override
|
||||
public abstract T parse(String str, String style, CommandSender sender, MPlugin p);
|
||||
|
||||
@Override
|
||||
public String getError()
|
||||
public Collection<String> getError()
|
||||
{
|
||||
return this.error;
|
||||
}
|
||||
|
24
src/com/massivecraft/mcore1/cmd/arg/AHMaterial.java
Normal file
24
src/com/massivecraft/mcore1/cmd/arg/AHMaterial.java
Normal file
@ -0,0 +1,24 @@
|
||||
package com.massivecraft.mcore1.cmd.arg;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.mcore1.MPlugin;
|
||||
|
||||
public class AHMaterial extends AHBase<Material>
|
||||
{
|
||||
@Override
|
||||
public Material parse(String str, String style, CommandSender sender, MPlugin p)
|
||||
{
|
||||
this.error.clear();
|
||||
Material ret = Material.matchMaterial(str);
|
||||
|
||||
if (ret == null)
|
||||
{
|
||||
this.error.add("<b>No material matching \"<p>"+str+"<b>\".");
|
||||
this.error.add("<i>Suggestion: <aqua>http://www.minecraftwiki.net/wiki/Data_values");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@ public class AHPlayer extends AHBase<Player>
|
||||
@Override
|
||||
public Player parse(String str, String style, CommandSender sender, MPlugin p)
|
||||
{
|
||||
this.error = null;
|
||||
this.error.clear();
|
||||
if (str == null) return null;
|
||||
|
||||
if (style != null && style.equals("match"))
|
||||
@ -23,7 +23,7 @@ public class AHPlayer extends AHBase<Player>
|
||||
{
|
||||
return players.get(0);
|
||||
}
|
||||
this.error = "<b>No online player's name begins with \"<p>"+str+"<b>\".";
|
||||
this.error.add("<b>No online player's name begins with \"<p>"+str+"<b>\".");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -32,7 +32,7 @@ public class AHPlayer extends AHBase<Player>
|
||||
{
|
||||
return player;
|
||||
}
|
||||
this.error = "<b>No player online with the exact name \"<p>"+str+"<b>\".";
|
||||
this.error.add("<b>No player online with the exact name \"<p>"+str+"<b>\".");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ public abstract class AHPlayerWrapper<T> extends AHBase<T>
|
||||
@Override
|
||||
public T parse(String str, String style, CommandSender sender, MPlugin p)
|
||||
{
|
||||
this.error = null;
|
||||
this.error.clear();
|
||||
if (str == null) return null;
|
||||
|
||||
IClassManager<T> manager = this.getManager(p);
|
||||
@ -32,7 +32,7 @@ public abstract class AHPlayerWrapper<T> extends AHBase<T>
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
this.error = "<b>No player name begins with \"<p>"+str+"<b>\".";
|
||||
this.error.add("<b>No player name begins with \"<p>"+str+"<b>\".");
|
||||
}
|
||||
else if (style != null && style.equalsIgnoreCase("matchany"))
|
||||
{
|
||||
@ -41,7 +41,7 @@ public abstract class AHPlayerWrapper<T> extends AHBase<T>
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
this.error = "<b>No player name begins with \"<p>"+str+"<b>\".";
|
||||
this.error.add("<b>No player name begins with \"<p>"+str+"<b>\".");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -51,7 +51,7 @@ public abstract class AHPlayerWrapper<T> extends AHBase<T>
|
||||
return ret;
|
||||
|
||||
}
|
||||
this.error = "<b>No player with the exact name \"<p>"+str+"<b>\".";
|
||||
this.error.add("<b>No player with the exact name \"<p>"+str+"<b>\".");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public abstract class AHPrimitive<T> extends AHBase<T>
|
||||
@Override
|
||||
public T parse(String str, String style, CommandSender sender, MPlugin p)
|
||||
{
|
||||
this.error = null;
|
||||
this.error.clear();
|
||||
if (str == null) return null;
|
||||
try
|
||||
{
|
||||
@ -22,7 +22,7 @@ public abstract class AHPrimitive<T> extends AHBase<T>
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.error = "<b>\"<p>"+str+"<b>\" is not a valid "+this.getPrimitiveName()+".";
|
||||
this.error.add("<b>\"<p>"+str+"<b>\" is not a valid "+this.getPrimitiveName()+".");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.massivecraft.mcore1.cmd.arg;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.mcore1.MPlugin;
|
||||
@ -10,5 +12,5 @@ public interface IArgHandler<T>
|
||||
public T parse(String str, String style, CommandSender sender, MPlugin p);
|
||||
|
||||
// Error here - or null.
|
||||
public String getError();
|
||||
public Collection<String> getError();
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
package com.massivecraft.mcore1.persist;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.massivecraft.mcore1.util.Txt;
|
||||
|
||||
|
||||
public abstract class PlayerEntity<T extends PlayerEntity<T>> extends Entity<T>
|
||||
{
|
||||
@ -34,7 +36,7 @@ public abstract class PlayerEntity<T extends PlayerEntity<T>> extends Entity<T>
|
||||
player.sendMessage(msg);
|
||||
}
|
||||
|
||||
public void sendMessage(List<String> msgs)
|
||||
public void sendMessage(Collection<String> msgs)
|
||||
{
|
||||
Player player = this.getPlayer();
|
||||
if (player == null) return;
|
||||
@ -43,4 +45,24 @@ public abstract class PlayerEntity<T extends PlayerEntity<T>> extends Entity<T>
|
||||
player.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public void msg(String msg)
|
||||
{
|
||||
this.sendMessage(Txt.parse(msg));
|
||||
}
|
||||
|
||||
public void msg(String msg, Object... args)
|
||||
{
|
||||
this.sendMessage(Txt.parse(msg, args));
|
||||
}
|
||||
|
||||
public void msg(Collection<String> msgs)
|
||||
{
|
||||
Player player = this.getPlayer();
|
||||
if (player == null) return;
|
||||
for(String msg : msgs)
|
||||
{
|
||||
player.sendMessage(Txt.parse(msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,29 +21,29 @@ public abstract class GsonClassManager<T> implements IClassManager<T>
|
||||
// -------------------------------------------- //
|
||||
// NON INTERFACE
|
||||
// -------------------------------------------- //
|
||||
private final static String DOTJSON = ".json";
|
||||
private Set<String> ids;
|
||||
private Set<T> entities;
|
||||
private Map<String, T> id2entity;
|
||||
private Map<T, String> entity2id;
|
||||
private long idCurrent = 1;
|
||||
protected final static String DOTJSON = ".json";
|
||||
protected Set<String> ids;
|
||||
protected Set<T> entities;
|
||||
protected Map<String, T> id2entity;
|
||||
protected Map<T, String> entity2id;
|
||||
protected long idCurrent = 1;
|
||||
|
||||
private Gson gson;
|
||||
protected Gson gson;
|
||||
public Gson getGson() { return gson; }
|
||||
public void setGson(Gson gson) { this.gson = gson; }
|
||||
|
||||
private File folder;
|
||||
protected File folder;
|
||||
public File getFolder() { return folder; }
|
||||
public void setFolder(File val) { this.folder = val; this.folder.mkdirs(); }
|
||||
|
||||
private boolean creative;
|
||||
protected boolean creative;
|
||||
@Override
|
||||
public boolean getIsCreative() { return this.creative; }
|
||||
@Override
|
||||
public void setIsCreative(boolean val) { this.creative = val; }
|
||||
|
||||
private boolean didLoadAll = false;
|
||||
private void loadIds()
|
||||
protected boolean didLoadAll = false;
|
||||
protected void loadIds()
|
||||
{
|
||||
for(File file : this.getFolder().listFiles(JsonFileFilter.getInstance()))
|
||||
{
|
||||
@ -51,14 +51,14 @@ public abstract class GsonClassManager<T> implements IClassManager<T>
|
||||
}
|
||||
}
|
||||
|
||||
private String idFromFile(File file)
|
||||
protected String idFromFile(File file)
|
||||
{
|
||||
if (file == null) return null;
|
||||
String name = file.getName();
|
||||
return name.substring(0, name.length()-5);
|
||||
}
|
||||
|
||||
private File fileFromId(Object oid)
|
||||
protected File fileFromId(Object oid)
|
||||
{
|
||||
String id = this.idFix(oid);
|
||||
if (id == null) return null;
|
||||
@ -148,7 +148,7 @@ public abstract class GsonClassManager<T> implements IClassManager<T>
|
||||
return this.attach(entity, oid, false);
|
||||
}
|
||||
|
||||
private synchronized String attach(T entity, Object oid, boolean allowExistingIdUsage)
|
||||
protected synchronized String attach(T entity, Object oid, boolean allowExistingIdUsage)
|
||||
{
|
||||
// Check entity
|
||||
if (entity == null) return null;
|
||||
@ -197,7 +197,7 @@ public abstract class GsonClassManager<T> implements IClassManager<T>
|
||||
}
|
||||
|
||||
// Assumes the id is correct! For internal use only!
|
||||
private synchronized void detach(T entity, String id)
|
||||
protected synchronized void detach(T entity, String id)
|
||||
{
|
||||
if (id != null)
|
||||
{
|
||||
@ -213,7 +213,7 @@ public abstract class GsonClassManager<T> implements IClassManager<T>
|
||||
}
|
||||
}
|
||||
|
||||
private void removeFile(String id)
|
||||
protected void removeFile(String id)
|
||||
{
|
||||
File file = this.fileFromId(id);
|
||||
if (file.exists())
|
||||
@ -251,7 +251,7 @@ public abstract class GsonClassManager<T> implements IClassManager<T>
|
||||
return this.save(id, entity);
|
||||
}
|
||||
|
||||
private boolean save(String id, T entity)
|
||||
protected boolean save(String id, T entity)
|
||||
{
|
||||
if (id == null) return false;
|
||||
if (entity == null) return false;
|
||||
|
@ -1,10 +1,18 @@
|
||||
package com.massivecraft.mcore1.util;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.server.ChunkPosition;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.Packet60Explosion;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
|
||||
// http://mc.kev009.com/Protocol
|
||||
// -----------------------------
|
||||
@ -82,6 +90,38 @@ public class SmokeUtil
|
||||
}
|
||||
}
|
||||
|
||||
// Fake Explosion ========
|
||||
public static void fakeExplosion(Location location, int radius)
|
||||
{
|
||||
if (location == null) return;
|
||||
|
||||
HashSet<ChunkPosition> blocks = new HashSet<ChunkPosition>();
|
||||
int squRadius = 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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Packet60Explosion packet = new Packet60Explosion(location.getX(),location.getY(), location.getZ(), 0.1f, blocks);
|
||||
CraftServer craftServer = (CraftServer) Bukkit.getServer();
|
||||
MinecraftServer minecraftServer = craftServer.getServer();
|
||||
|
||||
minecraftServer.serverConfigurationManager.sendPacketNearby(location.getX(), location.getY(), location.getZ(), 64, ((CraftWorld)location.getWorld()).getHandle().dimension, packet);
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------- //
|
||||
// Attach continuous effects to or locations
|
||||
// -------------------------------------------- //
|
||||
|
@ -74,8 +74,15 @@ public class Txt
|
||||
parseReplacements.put("<good>", "\u00A7a");
|
||||
parseReplacements.put("<b>", "\u00A7c");
|
||||
parseReplacements.put("<bad>", "\u00A7c");
|
||||
|
||||
parseReplacements.put("<k>", "\u00A7b");
|
||||
parseReplacements.put("<key>", "\u00A7b");
|
||||
|
||||
parseReplacements.put("<v>", "\u00A7d");
|
||||
parseReplacements.put("<value>", "\u00A7d");
|
||||
parseReplacements.put("<h>", "\u00A7d");
|
||||
parseReplacements.put("<highlight>", "\u00A7d");
|
||||
|
||||
parseReplacements.put("<c>", "\u00A7b");
|
||||
parseReplacements.put("<command>", "\u00A7b");
|
||||
parseReplacements.put("<p>", "\u00A73");
|
||||
@ -285,7 +292,7 @@ public class Txt
|
||||
int pageheight = 9;
|
||||
int pagecount = (lines.size() / pageheight)+1;
|
||||
|
||||
ret.add(titleize(title+" "+pageHumanBased+"/"+pagecount));
|
||||
ret.add(titleize(title+parse("<a>")+" "+pageHumanBased+"/"+pagecount));
|
||||
|
||||
if (pagecount == 0)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user