Violently shivering froodl.

This commit is contained in:
Olof Larsson 2013-01-28 21:14:36 +01:00
parent 8675a87aba
commit 33ab2f0e88
60 changed files with 757 additions and 322 deletions

View File

@ -1,5 +1,6 @@
package com.massivecraft.mcore5; package com.massivecraft.mcore5;
import java.io.Serializable;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -16,6 +17,10 @@ import org.bukkit.block.Block;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import com.massivecraft.mcore5.mixin.Mixin;
import com.massivecraft.mcore5.mixin.PsTeleporterException;
import com.massivecraft.mcore5.usys.Aspect;
import com.massivecraft.mcore5.usys.Multiverse;
import com.massivecraft.mcore5.util.Txt; import com.massivecraft.mcore5.util.Txt;
import com.massivecraft.mcore5.xlib.gson.annotations.SerializedName; import com.massivecraft.mcore5.xlib.gson.annotations.SerializedName;
@ -30,13 +35,15 @@ import com.massivecraft.mcore5.xlib.gson.annotations.SerializedName;
*/ */
@EqualsAndHashCode @EqualsAndHashCode
public class PS implements Cloneable public class PS implements Cloneable, Serializable
{ {
// -------------------------------------------- // // -------------------------------------------- //
// TELEPORTER // CONSTANTS
// -------------------------------------------- // // -------------------------------------------- //
public static transient PSTeleporter teleporter = PSTeleporterDefault.get(); private static final transient long serialVersionUID = 1L;
public static final transient String UNKNOWN_WORLD_NAME = "?";
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // FIELDS
@ -478,9 +485,9 @@ public class PS implements Cloneable
// WRITERS // WRITERS
//----------------------------------------------// //----------------------------------------------//
public synchronized void write(Entity entity) throws PSTeleporterException public synchronized void write(Entity entity) throws PsTeleporterException
{ {
teleporter.teleport(entity, this); Mixin.getPsTeleporterMixin().teleport(entity, this);
} }
//----------------------------------------------// //----------------------------------------------//
@ -611,5 +618,46 @@ public class PS implements Cloneable
{ {
return new PS(this); return new PS(this);
} }
//----------------------------------------------//
// STATIC COMPARISON TOOLS
//----------------------------------------------//
public static boolean inSameWorld(PS one, PS two)
{
if (one == null) return false;
if (two == null) return false;
String w1 = one.getWorldName();
String w2 = two.getWorldName();
if (w1 == null) return false;
if (w2 == null) return false;
return w1.equalsIgnoreCase(w2);
}
public static boolean inSameUniverse(PS one, PS two, Multiverse multiverse)
{
if (one == null) return false;
if (two == null) return false;
String w1 = one.getWorldName();
String w2 = two.getWorldName();
if (w1 == null) return false;
if (w2 == null) return false;
String m1 = multiverse.getUniverseForWorldName(w1);
String m2 = multiverse.getUniverseForWorldName(w2);
return m1.equalsIgnoreCase(m2);
}
public static boolean inSameUniverse(PS one, PS two, Aspect aspect)
{
return inSameUniverse(one, two, aspect.multiverse());
}
} }

View File

@ -1,12 +0,0 @@
package com.massivecraft.mcore5;
import org.bukkit.entity.Entity;
public interface PSTeleporter
{
/**
* @param entity The entity to be teleported
* @param ps The target PhysicalState
*/
public void teleport(Entity entity, PS ps) throws PSTeleporterException;
}

View File

@ -1,32 +0,0 @@
package com.massivecraft.mcore5;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.util.Vector;
import com.massivecraft.mcore5.util.Txt;
public class PSTeleporterDefault implements PSTeleporter
{
@Override
public void teleport(Entity entity, PS ps) throws PSTeleporterException
{
Location location = ps.calcLocation();
if (location == null) throw new PSTeleporterException(Txt.parse("<b>Could not calculate the location"));
entity.teleport(location);
Vector velocity = ps.getVelocity();
if (velocity == null) return;
entity.setVelocity(velocity);
}
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
protected static PSTeleporterDefault i = new PSTeleporterDefault();
public static PSTeleporterDefault get() { return i; }
}

View File

@ -1,31 +0,0 @@
package com.massivecraft.mcore5;
public class PSTeleporterException extends Exception
{
private static final long serialVersionUID = 1L;
public PSTeleporterException()
{
super();
}
public PSTeleporterException(String message)
{
super(message);
}
public PSTeleporterException(String message, Throwable cause)
{
super(message, cause);
}
public PSTeleporterException(Throwable cause)
{
super(cause);
}
protected PSTeleporterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace)
{
super(message, cause, enableSuppression, writableStackTrace);
}
}

View File

@ -0,0 +1,6 @@
package com.massivecraft.mcore5;
public interface Prioritized
{
public int getPriority();
}

View File

@ -0,0 +1,24 @@
package com.massivecraft.mcore5;
import java.util.Comparator;
public class PriorityComparator implements Comparator<Prioritized>
{
@Override
public int compare(Prioritized one, Prioritized two)
{
if (one == null && two == null) return 0;
if (two == null) return 1;
if (one == null) return -1;
return Integer.valueOf(one.getPriority()).compareTo(two.getPriority());
}
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
private static PriorityComparator i = new PriorityComparator();
public static PriorityComparator get() { return i; }
}

View File

@ -0,0 +1,24 @@
package com.massivecraft.mcore5;
import java.util.Comparator;
public class ReversePriorityComparator implements Comparator<Prioritized>
{
@Override
public int compare(Prioritized one, Prioritized two)
{
if (one == null && two == null) return 0;
if (two == null) return -1;
if (one == null) return 1;
return Integer.valueOf(two.getPriority()).compareTo(one.getPriority());
}
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
private static ReversePriorityComparator i = new ReversePriorityComparator();
public static ReversePriorityComparator get() { return i; }
}

View File

@ -2,7 +2,7 @@ package com.massivecraft.mcore5.adapter;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventoryCustom; import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventoryCustom;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;

View File

@ -4,10 +4,10 @@ import java.lang.reflect.Field;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.Map.Entry; import java.util.Map.Entry;
import net.minecraft.server.v1_4_6.NBTBase; import net.minecraft.server.v1_4_R1.NBTBase;
import net.minecraft.server.v1_4_6.NBTTagCompound; import net.minecraft.server.v1_4_R1.NBTTagCompound;
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftItemStack;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -191,11 +191,11 @@ public class ItemStackAdapterV1 implements JsonDeserializer<ItemStack>, JsonSeri
} }
} }
public static net.minecraft.server.v1_4_6.ItemStack getHandle(CraftItemStack craftItemStack) public static net.minecraft.server.v1_4_R1.ItemStack getHandle(CraftItemStack craftItemStack)
{ {
try try
{ {
return (net.minecraft.server.v1_4_6.ItemStack) fieldCraftItemStackDotHandle.get(craftItemStack); return (net.minecraft.server.v1_4_R1.ItemStack) fieldCraftItemStackDotHandle.get(craftItemStack);
} }
catch (Exception e) catch (Exception e)
{ {

View File

@ -3,7 +3,7 @@ package com.massivecraft.mcore5.adapter;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import net.minecraft.server.v1_4_6.NBTBase; import net.minecraft.server.v1_4_R1.NBTBase;
import lombok.Getter; import lombok.Getter;

View File

@ -4,19 +4,19 @@ import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map.Entry; import java.util.Map.Entry;
import net.minecraft.server.v1_4_6.NBTBase; import net.minecraft.server.v1_4_R1.NBTBase;
import net.minecraft.server.v1_4_6.NBTTagByte; import net.minecraft.server.v1_4_R1.NBTTagByte;
import net.minecraft.server.v1_4_6.NBTTagByteArray; import net.minecraft.server.v1_4_R1.NBTTagByteArray;
import net.minecraft.server.v1_4_6.NBTTagCompound; import net.minecraft.server.v1_4_R1.NBTTagCompound;
import net.minecraft.server.v1_4_6.NBTTagDouble; import net.minecraft.server.v1_4_R1.NBTTagDouble;
import net.minecraft.server.v1_4_6.NBTTagEnd; import net.minecraft.server.v1_4_R1.NBTTagEnd;
import net.minecraft.server.v1_4_6.NBTTagFloat; import net.minecraft.server.v1_4_R1.NBTTagFloat;
import net.minecraft.server.v1_4_6.NBTTagInt; import net.minecraft.server.v1_4_R1.NBTTagInt;
import net.minecraft.server.v1_4_6.NBTTagIntArray; import net.minecraft.server.v1_4_R1.NBTTagIntArray;
import net.minecraft.server.v1_4_6.NBTTagList; import net.minecraft.server.v1_4_R1.NBTTagList;
import net.minecraft.server.v1_4_6.NBTTagLong; import net.minecraft.server.v1_4_R1.NBTTagLong;
import net.minecraft.server.v1_4_6.NBTTagShort; import net.minecraft.server.v1_4_R1.NBTTagShort;
import net.minecraft.server.v1_4_6.NBTTagString; import net.minecraft.server.v1_4_R1.NBTTagString;
import com.massivecraft.mcore5.xlib.gson.JsonArray; import com.massivecraft.mcore5.xlib.gson.JsonArray;
import com.massivecraft.mcore5.xlib.gson.JsonElement; import com.massivecraft.mcore5.xlib.gson.JsonElement;

View File

@ -2,9 +2,6 @@ package com.massivecraft.mcore5.adapter;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import com.massivecraft.mcore5.util.ClassResolveUtil;
import com.massivecraft.mcore5.xlib.gson.JsonDeserializationContext; import com.massivecraft.mcore5.xlib.gson.JsonDeserializationContext;
import com.massivecraft.mcore5.xlib.gson.JsonDeserializer; import com.massivecraft.mcore5.xlib.gson.JsonDeserializer;
import com.massivecraft.mcore5.xlib.gson.JsonElement; import com.massivecraft.mcore5.xlib.gson.JsonElement;
@ -64,7 +61,7 @@ public class PolymorphicAdapter<T> implements JsonDeserializer<T>, JsonSerialize
Class<?> typeClass = null; Class<?> typeClass = null;
try try
{ {
typeClass = ClassResolveUtil.resolve(type); typeClass = Class.forName(type);
} }
catch (ClassNotFoundException e) catch (ClassNotFoundException e)
{ {

View File

@ -1,5 +1,7 @@
package com.massivecraft.mcore5.cmd; package com.massivecraft.mcore5.cmd;
import java.util.ArrayList;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -11,9 +13,9 @@ public class BukkitGlueCommand extends Command
public final MCommand mcommand; public final MCommand mcommand;
public final MPlugin mplugin; public final MPlugin mplugin;
public BukkitGlueCommand(MCommand mcommand, MPlugin mplugin) public BukkitGlueCommand(String name, MCommand mcommand, MPlugin mplugin)
{ {
super(mcommand.getAliases().get(0), mcommand.getDesc(), mcommand.getUseageTemplate(), mcommand.getAliases()); super(name, mcommand.getDesc(), mcommand.getUseageTemplate(), new ArrayList<String>());
this.mcommand = mcommand; this.mcommand = mcommand;
this.mplugin = mplugin; this.mplugin = mplugin;
} }

View File

@ -150,18 +150,29 @@ public abstract class MCommand
public boolean register(MPlugin mplugin, boolean override) public boolean register(MPlugin mplugin, boolean override)
{ {
BukkitGlueCommand bgc = new BukkitGlueCommand(this, mplugin); boolean ret = false;
SimpleCommandMap scm = BukkitCommandUtil.getBukkitCommandMap(); SimpleCommandMap scm = BukkitCommandUtil.getBukkitCommandMap();
if (override) for (String alias : this.getAliases())
{ {
// Our commands are more important than your commands :P BukkitGlueCommand bgc = new BukkitGlueCommand(alias, this, mplugin);
Map<String, Command> knownCommands = BukkitCommandUtil.getKnownCommandsFromSimpleCommandMap(scm);
String lowerLabel = bgc.getName().trim().toLowerCase(); if (override)
knownCommands.remove(lowerLabel); {
// Our commands are more important than your commands :P
Map<String, Command> knownCommands = BukkitCommandUtil.getKnownCommandsFromSimpleCommandMap(scm);
String lowerLabel = bgc.getName().trim().toLowerCase();
knownCommands.remove(lowerLabel);
}
if (scm.register(MCore.p.getDescription().getName(), bgc))
{
ret = true;
}
} }
return scm.register("mcore", bgc); return ret;
} }
// -------------------------------------------- // // -------------------------------------------- //
@ -467,7 +478,7 @@ public abstract class MCommand
{ {
String str = this.arg(idx); String str = this.arg(idx);
if (str == null) return defaultNotSet; if (str == null) return defaultNotSet;
ArgResult<T> result = argReader.read(str, this); ArgResult<T> result = argReader.read(str, this.sender);
if (result.hasErrors()) this.msg(result.getErrors()); if (result.hasErrors()) this.msg(result.getErrors());
return result.getResult(); return result.getResult();
} }

View File

@ -1,6 +1,6 @@
package com.massivecraft.mcore5.cmd.arg; package com.massivecraft.mcore5.cmd.arg;
import com.massivecraft.mcore5.cmd.MCommand; import org.bukkit.command.CommandSender;
public abstract class ARAbstractPrimitive<T> implements ArgReader<T> public abstract class ARAbstractPrimitive<T> implements ArgReader<T>
{ {
@ -8,7 +8,7 @@ public abstract class ARAbstractPrimitive<T> implements ArgReader<T>
public abstract T convert(String str) throws Exception; public abstract T convert(String str) throws Exception;
@Override @Override
public ArgResult<T> read(String str, MCommand mcommand) public ArgResult<T> read(String str, CommandSender sender)
{ {
ArgResult<T> result = new ArgResult<T>(); ArgResult<T> result = new ArgResult<T>();

View File

@ -2,27 +2,28 @@ package com.massivecraft.mcore5.cmd.arg;
import java.util.Collection; import java.util.Collection;
import com.massivecraft.mcore5.cmd.MCommand; import org.bukkit.command.CommandSender;
import com.massivecraft.mcore5.util.Txt; import com.massivecraft.mcore5.util.Txt;
public abstract class ARAbstractSelect<T> implements ArgReader<T> public abstract class ARAbstractSelect<T> implements ArgReader<T>
{ {
public abstract String typename(); public abstract String typename();
public abstract T select(String str, MCommand mcommand); public abstract T select(String str, CommandSender sender);
public abstract Collection<String> altNames(MCommand mcommand); public abstract Collection<String> altNames(CommandSender sender);
public boolean canList(MCommand mcommand) { return true; } public boolean canList(CommandSender sender) { return true; }
@Override @Override
public ArgResult<T> read(String str, MCommand mcommand) public ArgResult<T> read(String str, CommandSender sender)
{ {
ArgResult<T> result = new ArgResult<T>(this.select(str, mcommand)); ArgResult<T> result = new ArgResult<T>(this.select(str, sender));
if (!result.hasResult()) if (!result.hasResult())
{ {
result.getErrors().add("<b>No "+this.typename()+" matches \"<h>"+str+"<b>\"."); result.getErrors().add("<b>No "+this.typename()+" matches \"<h>"+str+"<b>\".");
if (this.canList(mcommand)) if (this.canList(sender))
{ {
Collection<String> names = this.altNames(mcommand); Collection<String> names = this.altNames(sender);
if (names.size() == 0) if (names.size() == 0)
{ {
result.getErrors().add("<i>Note: There is no "+this.typename()+" available."); result.getErrors().add("<i>Note: There is no "+this.typename()+" available.");

View File

@ -4,7 +4,8 @@ import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import com.massivecraft.mcore5.cmd.MCommand; import org.bukkit.command.CommandSender;
import com.massivecraft.mcore5.util.Txt; import com.massivecraft.mcore5.util.Txt;
public abstract class ARAbstractStringMatch implements ArgReader<String> public abstract class ARAbstractStringMatch implements ArgReader<String>
@ -14,7 +15,7 @@ public abstract class ARAbstractStringMatch implements ArgReader<String>
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public ArgResult<String> read(String str, MCommand mcommand) public ArgResult<String> read(String str, CommandSender sender)
{ {
ArgResult<String> result = new ArgResult<String>(); ArgResult<String> result = new ArgResult<String>();

View File

@ -2,8 +2,9 @@ package com.massivecraft.mcore5.cmd.arg;
import java.util.Collection; import java.util.Collection;
import org.bukkit.command.CommandSender;
import com.massivecraft.mcore5.Permission; import com.massivecraft.mcore5.Permission;
import com.massivecraft.mcore5.cmd.MCommand;
import com.massivecraft.mcore5.usys.Aspect; import com.massivecraft.mcore5.usys.Aspect;
import com.massivecraft.mcore5.usys.AspectColl; import com.massivecraft.mcore5.usys.AspectColl;
@ -16,19 +17,19 @@ public class ARAspect extends ARAbstractSelect<Aspect>
} }
@Override @Override
public Aspect select(String str, MCommand mcommand) public Aspect select(String str, CommandSender sender)
{ {
return AspectColl.i.get(str); return AspectColl.i.get(str);
} }
@Override @Override
public boolean canList(MCommand mcommand) public boolean canList(CommandSender sender)
{ {
return Permission.CMD_USYS_ASPECT_LIST.has(mcommand.sender, false); return Permission.CMD_USYS_ASPECT_LIST.has(sender, false);
} }
@Override @Override
public Collection<String> altNames(MCommand mcommand) public Collection<String> altNames(CommandSender sender)
{ {
return AspectColl.i.getIds(); return AspectColl.i.getIds();
} }

View File

@ -5,8 +5,7 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import com.massivecraft.mcore5.cmd.MCommand;
public class ARChatColor extends ARAbstractSelect<ChatColor> public class ARChatColor extends ARAbstractSelect<ChatColor>
{ {
@ -17,7 +16,7 @@ public class ARChatColor extends ARAbstractSelect<ChatColor>
} }
@Override @Override
public ChatColor select(String str, MCommand mcommand) public ChatColor select(String str, CommandSender sender)
{ {
ChatColor ret = null; ChatColor ret = null;
@ -37,7 +36,7 @@ public class ARChatColor extends ARAbstractSelect<ChatColor>
} }
@Override @Override
public Collection<String> altNames(MCommand mcommand) public Collection<String> altNames(CommandSender sender)
{ {
List<String> ret = new ArrayList<String>(); List<String> ret = new ArrayList<String>();

View File

@ -3,8 +3,8 @@ package com.massivecraft.mcore5.cmd.arg;
import java.util.Collection; import java.util.Collection;
import org.bukkit.Difficulty; import org.bukkit.Difficulty;
import org.bukkit.command.CommandSender;
import com.massivecraft.mcore5.cmd.MCommand;
import com.massivecraft.mcore5.util.MUtil; import com.massivecraft.mcore5.util.MUtil;
public class ARDifficulty extends ARAbstractSelect<Difficulty> public class ARDifficulty extends ARAbstractSelect<Difficulty>
@ -16,7 +16,7 @@ public class ARDifficulty extends ARAbstractSelect<Difficulty>
} }
@Override @Override
public Difficulty select(String str, MCommand mcommand) public Difficulty select(String str, CommandSender sender)
{ {
Difficulty ret = null; Difficulty ret = null;
@ -43,7 +43,7 @@ public class ARDifficulty extends ARAbstractSelect<Difficulty>
} }
@Override @Override
public Collection<String> altNames(MCommand mcommand) public Collection<String> altNames(CommandSender sender)
{ {
return MUtil.list("peaceful", "easy", "normal", "hard"); return MUtil.list("peaceful", "easy", "normal", "hard");
} }

View File

@ -3,8 +3,8 @@ package com.massivecraft.mcore5.cmd.arg;
import java.util.Collection; import java.util.Collection;
import org.bukkit.World.Environment; import org.bukkit.World.Environment;
import org.bukkit.command.CommandSender;
import com.massivecraft.mcore5.cmd.MCommand;
import com.massivecraft.mcore5.util.MUtil; import com.massivecraft.mcore5.util.MUtil;
public class AREnvironment extends ARAbstractSelect<Environment> public class AREnvironment extends ARAbstractSelect<Environment>
@ -16,7 +16,7 @@ public class AREnvironment extends ARAbstractSelect<Environment>
} }
@Override @Override
public Environment select(String str, MCommand mcommand) public Environment select(String str, CommandSender sender)
{ {
Environment ret = null; Environment ret = null;
@ -45,7 +45,7 @@ public class AREnvironment extends ARAbstractSelect<Environment>
} }
@Override @Override
public Collection<String> altNames(MCommand mcommand) public Collection<String> altNames(CommandSender sender)
{ {
return MUtil.list("normal", "end", "nether"); return MUtil.list("normal", "end", "nether");
} }

View File

@ -3,8 +3,8 @@ package com.massivecraft.mcore5.cmd.arg;
import java.util.Collection; import java.util.Collection;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.command.CommandSender;
import com.massivecraft.mcore5.cmd.MCommand;
import com.massivecraft.mcore5.util.MUtil; import com.massivecraft.mcore5.util.MUtil;
public class ARGameMode extends ARAbstractSelect<GameMode> public class ARGameMode extends ARAbstractSelect<GameMode>
@ -16,7 +16,7 @@ public class ARGameMode extends ARAbstractSelect<GameMode>
} }
@Override @Override
public GameMode select(String str, MCommand mcommand) public GameMode select(String str, CommandSender sender)
{ {
GameMode ret = null; GameMode ret = null;
@ -39,7 +39,7 @@ public class ARGameMode extends ARAbstractSelect<GameMode>
} }
@Override @Override
public Collection<String> altNames(MCommand mcommand) public Collection<String> altNames(CommandSender sender)
{ {
return MUtil.list("survival", "creative", "adventure"); return MUtil.list("survival", "creative", "adventure");
} }

View File

@ -1,13 +1,12 @@
package com.massivecraft.mcore5.cmd.arg; package com.massivecraft.mcore5.cmd.arg;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import com.massivecraft.mcore5.cmd.MCommand;
public class ARMaterial implements ArgReader<Material> public class ARMaterial implements ArgReader<Material>
{ {
@Override @Override
public ArgResult<Material> read(String str, MCommand mcommand) public ArgResult<Material> read(String str, CommandSender sender)
{ {
ArgResult<Material> result = new ArgResult<Material>(Material.matchMaterial(str)); ArgResult<Material> result = new ArgResult<Material>(Material.matchMaterial(str));
if (!result.hasResult()) if (!result.hasResult())

View File

@ -2,8 +2,9 @@ package com.massivecraft.mcore5.cmd.arg;
import java.util.Collection; import java.util.Collection;
import org.bukkit.command.CommandSender;
import com.massivecraft.mcore5.Permission; import com.massivecraft.mcore5.Permission;
import com.massivecraft.mcore5.cmd.MCommand;
import com.massivecraft.mcore5.usys.Multiverse; import com.massivecraft.mcore5.usys.Multiverse;
import com.massivecraft.mcore5.usys.MultiverseColl; import com.massivecraft.mcore5.usys.MultiverseColl;
@ -16,19 +17,19 @@ public class ARMultiverse extends ARAbstractSelect<Multiverse>
} }
@Override @Override
public Multiverse select(String str, MCommand mcommand) public Multiverse select(String str, CommandSender sender)
{ {
return MultiverseColl.i.get(str); return MultiverseColl.i.get(str);
} }
@Override @Override
public boolean canList(MCommand mcommand) public boolean canList(CommandSender sender)
{ {
return Permission.CMD_USYS_MULTIVERSE_LIST.has(mcommand.sender, false); return Permission.CMD_USYS_MULTIVERSE_LIST.has(sender, false);
} }
@Override @Override
public Collection<String> altNames(MCommand mcommand) public Collection<String> altNames(CommandSender sender)
{ {
return MultiverseColl.i.getIds(); return MultiverseColl.i.getIds();
} }

View File

@ -1,14 +1,13 @@
package com.massivecraft.mcore5.cmd.arg; package com.massivecraft.mcore5.cmd.arg;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.massivecraft.mcore5.cmd.MCommand;
public class AROnlinePlayerExact implements ArgReader<Player> public class AROnlinePlayerExact implements ArgReader<Player>
{ {
@Override @Override
public ArgResult<Player> read(String str, MCommand mcommand) public ArgResult<Player> read(String str, CommandSender sender)
{ {
ArgResult<Player> result = new ArgResult<Player>(); ArgResult<Player> result = new ArgResult<Player>();
Player player = Bukkit.getServer().getPlayerExact(str); Player player = Bukkit.getServer().getPlayerExact(str);
@ -16,7 +15,7 @@ public class AROnlinePlayerExact implements ArgReader<Player>
if (!result.hasResult()) if (!result.hasResult())
{ {
result.getErrors().add("<b>No online player with exact name \"<h>"+str+"<b\">."); result.getErrors().add("<b>No online player with exact name \"<h>"+str+"<b>\".");
} }
return result; return result;

View File

@ -4,15 +4,15 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.massivecraft.mcore5.cmd.MCommand;
import com.massivecraft.mcore5.util.Txt; import com.massivecraft.mcore5.util.Txt;
public class AROnlinePlayerMatch implements ArgReader<Player> public class AROnlinePlayerMatch implements ArgReader<Player>
{ {
@Override @Override
public ArgResult<Player> read(String str, MCommand mcommand) public ArgResult<Player> read(String str, CommandSender sender)
{ {
ArgResult<Player> result = new ArgResult<Player>(); ArgResult<Player> result = new ArgResult<Player>();
@ -33,7 +33,7 @@ public class AROnlinePlayerMatch implements ArgReader<Player>
} }
else if (players.size() == 0) else if (players.size() == 0)
{ {
result.getErrors().add("<b>No online player matching \"<h>"+str+"<b\">."); result.getErrors().add("<b>No online player matching \"<h>"+str+"<b>\".");
} }
return result; return result;

View File

@ -1,6 +1,7 @@
package com.massivecraft.mcore5.cmd.arg; package com.massivecraft.mcore5.cmd.arg;
import com.massivecraft.mcore5.cmd.MCommand; import org.bukkit.command.CommandSender;
import com.massivecraft.mcore5.store.Coll; import com.massivecraft.mcore5.store.Coll;
import com.massivecraft.mcore5.store.Entity; import com.massivecraft.mcore5.store.Entity;
@ -11,10 +12,10 @@ public class ARStringEntity<E extends Entity<E, String>> implements ArgReader<E>
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public ArgResult<E> read(String str, MCommand mcommand) public ArgResult<E> read(String str, CommandSender sender)
{ {
ArgResult<E> result = new ArgResult<E>(); ArgResult<E> result = new ArgResult<E>();
ArgResult<String> innerResult = this.stringReader().read(str, mcommand); ArgResult<String> innerResult = this.stringReader().read(str, sender);
if (innerResult.hasResult()) if (innerResult.hasResult())
{ {

View File

@ -3,7 +3,8 @@ package com.massivecraft.mcore5.cmd.arg;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import com.massivecraft.mcore5.cmd.MCommand; import org.bukkit.command.CommandSender;
import com.massivecraft.mcore5.usys.Multiverse; import com.massivecraft.mcore5.usys.Multiverse;
import com.massivecraft.mcore5.util.Txt; import com.massivecraft.mcore5.util.Txt;
@ -14,7 +15,7 @@ public class ARUniverse implements ArgReader<String>
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public ArgResult<String> read(String str, MCommand mcommand) public ArgResult<String> read(String str, CommandSender sender)
{ {
ArgResult<String> result = new ArgResult<String>(); ArgResult<String> result = new ArgResult<String>();

View File

@ -5,8 +5,7 @@ import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.CommandSender;
import com.massivecraft.mcore5.cmd.MCommand;
public class ARWorld extends ARAbstractSelect<World> public class ARWorld extends ARAbstractSelect<World>
{ {
@ -17,13 +16,13 @@ public class ARWorld extends ARAbstractSelect<World>
} }
@Override @Override
public World select(String str, MCommand mcommand) public World select(String str, CommandSender sender)
{ {
return Bukkit.getWorld(str); return Bukkit.getWorld(str);
} }
@Override @Override
public List<String> altNames(MCommand mcommand) public List<String> altNames(CommandSender sender)
{ {
List<String> ret = new ArrayList<String>(); List<String> ret = new ArrayList<String>();
for (World world : Bukkit.getWorlds()) for (World world : Bukkit.getWorlds())

View File

@ -3,8 +3,8 @@ package com.massivecraft.mcore5.cmd.arg;
import java.util.Collection; import java.util.Collection;
import org.bukkit.WorldType; import org.bukkit.WorldType;
import org.bukkit.command.CommandSender;
import com.massivecraft.mcore5.cmd.MCommand;
import com.massivecraft.mcore5.util.MUtil; import com.massivecraft.mcore5.util.MUtil;
public class ARWorldType extends ARAbstractSelect<WorldType> public class ARWorldType extends ARAbstractSelect<WorldType>
@ -16,7 +16,7 @@ public class ARWorldType extends ARAbstractSelect<WorldType>
} }
@Override @Override
public WorldType select(String str, MCommand mcommand) public WorldType select(String str, CommandSender sender)
{ {
WorldType ret = null; WorldType ret = null;
@ -55,7 +55,7 @@ public class ARWorldType extends ARAbstractSelect<WorldType>
} }
@Override @Override
public Collection<String> altNames(MCommand mcommand) public Collection<String> altNames(CommandSender sender)
{ {
return MUtil.list("normal", "flat", "1.1", "largebiomes"); return MUtil.list("normal", "flat", "1.1", "largebiomes");
} }

View File

@ -1,8 +1,8 @@
package com.massivecraft.mcore5.cmd.arg; package com.massivecraft.mcore5.cmd.arg;
import com.massivecraft.mcore5.cmd.MCommand; import org.bukkit.command.CommandSender;
public interface ArgReader<T> public interface ArgReader<T>
{ {
public ArgResult<T> read(String str, MCommand mcommand); public ArgResult<T> read(String str, CommandSender sender);
} }

View File

@ -1,5 +1,7 @@
package com.massivecraft.mcore5.integration; package com.massivecraft.mcore5.integration;
import java.util.Collection;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -43,7 +45,9 @@ public class Integration implements Listener
public void tick() public void tick()
{ {
if (pluginEnabled(this.features.getTargetPluginName())) String namelist = Txt.implodeCommaAndDot(this.features.getTargetPluginNames(), "<h>%s", "<i>, ", " <i>and ", "<i>.");
if (isPluginsEnabled(this.features.getTargetPluginNames()))
{ {
if (!this.active) if (!this.active)
{ {
@ -51,11 +55,11 @@ public class Integration implements Listener
{ {
this.features.activate(); this.features.activate();
this.active = true; this.active = true;
this.ourPlugin.log(Txt.parse("<g>Activated <i>integration with <h>%s<i>.", this.features.getTargetPluginName())); this.ourPlugin.log(Txt.parse("<g>Activated <i>integration with "+namelist));
} }
catch (Exception e) catch (Exception e)
{ {
this.ourPlugin.log(Txt.parse("<b>Failed to activate <i>integration with <h>%s<i>.", this.features.getTargetPluginName())); this.ourPlugin.log(Txt.parse("<b>Failed to activate <i>integration with "+namelist));
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -68,11 +72,11 @@ public class Integration implements Listener
{ {
this.active = false; this.active = false;
this.features.deactivate(); this.features.deactivate();
this.ourPlugin.log(Txt.parse("Deactivated integration with <h>%s<i>.", this.features.getTargetPluginName())); this.ourPlugin.log(Txt.parse("<g>Deactivated <i>integration with "+namelist));
} }
catch (Exception e) catch (Exception e)
{ {
this.ourPlugin.log(Txt.parse("<b>Failed to deactivate <i>integration with <h>%s<i>.", this.features.getTargetPluginName())); this.ourPlugin.log(Txt.parse("<b>Failed to deactivate <i>integration with "+namelist));
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -83,13 +87,22 @@ public class Integration implements Listener
// UTIL // UTIL
// -------------------------------------------- // // -------------------------------------------- //
public static boolean pluginEnabled(String pluginName) public static boolean isPluginEnabled(String pluginName)
{ {
Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName); Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName);
if (plugin == null) return false; if (plugin == null) return false;
return plugin.isEnabled(); return plugin.isEnabled();
} }
public static boolean isPluginsEnabled(Collection<String> pluginNames)
{
for (String pluginName : pluginNames)
{
if (!isPluginEnabled(pluginName)) return false;
}
return true;
}
// -------------------------------------------- // // -------------------------------------------- //
// EVENT LISTENERS // EVENT LISTENERS
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -1,8 +1,10 @@
package com.massivecraft.mcore5.integration; package com.massivecraft.mcore5.integration;
import java.util.List;
public interface IntegrationFeatures public interface IntegrationFeatures
{ {
public String getTargetPluginName(); public List<String> getTargetPluginNames();
public void activate(); public void activate();
public void deactivate(); public void deactivate();
} }

View File

@ -1,14 +1,34 @@
package com.massivecraft.mcore5.integration; package com.massivecraft.mcore5.integration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public abstract class IntegrationFeaturesAbstract implements IntegrationFeatures public abstract class IntegrationFeaturesAbstract implements IntegrationFeatures
{ {
@Override // -------------------------------------------- //
public String getTargetPluginName() // FIELDS
// -------------------------------------------- //
private List<String> targetPluginNames;
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public IntegrationFeaturesAbstract(String... targetPluginNames)
{ {
// "SpoutFeatures" --> "Spout" this.targetPluginNames = new ArrayList<String>(Arrays.asList(targetPluginNames));
String ret = this.getClass().getSimpleName(); }
ret = ret.substring(0, ret.length()-8);
return ret; // -------------------------------------------- //
// OVERRIDES
// -------------------------------------------- //
@Override
public List<String> getTargetPluginNames()
{
return this.targetPluginNames;
} }
@Override @Override
@ -22,4 +42,4 @@ public abstract class IntegrationFeaturesAbstract implements IntegrationFeatures
{ {
} }
} }

View File

@ -0,0 +1,67 @@
package com.massivecraft.mcore5.mixin;
import java.util.Map;
import java.util.TreeMap;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.massivecraft.mcore5.util.SenderUtil;
public class DefaultDisplayNameMixin implements DisplayNameMixin
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static DefaultDisplayNameMixin i = new DefaultDisplayNameMixin();
public static DefaultDisplayNameMixin get() { return i; }
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
protected Map<String, String> idToDisplayName = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public String get(String senderId)
{
if (senderId == null) return null;
String ret = this.idToDisplayName.get(senderId);
if (ret != null) return ret;
Player player = Bukkit.getPlayerExact(senderId);
if (player != null) return player.getDisplayName();
return Mixin.getSenderIdFixerMixin().tryFix(senderId);
}
@Override
public void set(String senderId, String displayName)
{
this.idToDisplayName.put(senderId, displayName);
Player player = Bukkit.getPlayerExact(senderId);
if (player == null) return;
player.setDisplayName(displayName);
}
@Override
public String get(CommandSender sender)
{
return this.get(SenderUtil.getSenderId(sender));
}
@Override
public void set(CommandSender sender, String displayName)
{
this.set(SenderUtil.getSenderId(sender), displayName);
}
}

View File

@ -0,0 +1,67 @@
package com.massivecraft.mcore5.mixin;
import java.util.Map;
import java.util.TreeMap;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.massivecraft.mcore5.util.SenderUtil;
public class DefaultListNameMixin implements ListNameMixin
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static DefaultListNameMixin i = new DefaultListNameMixin();
public static DefaultListNameMixin get() { return i; }
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
protected Map<String, String> idToListName = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public String get(String senderId)
{
if (senderId == null) return null;
String ret = this.idToListName.get(senderId);
if (ret != null) return ret;
Player player = Bukkit.getPlayerExact(senderId);
if (player != null) return player.getDisplayName();
return Mixin.getSenderIdFixerMixin().tryFix(senderId);
}
@Override
public void set(String senderId, String listName)
{
this.idToListName.put(senderId, listName);
Player player = Bukkit.getPlayerExact(senderId);
if (player == null) return;
player.setDisplayName(listName);
}
@Override
public String get(CommandSender sender)
{
return this.get(SenderUtil.getSenderId(sender));
}
@Override
public void set(CommandSender sender, String listName)
{
this.set(SenderUtil.getSenderId(sender), listName);
}
}

View File

@ -0,0 +1,37 @@
package com.massivecraft.mcore5.mixin;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.util.Vector;
import com.massivecraft.mcore5.PS;
import com.massivecraft.mcore5.util.Txt;
public class DefaultPsTeleporterMixin implements PsTeleporterMixin
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static DefaultPsTeleporterMixin i = new DefaultPsTeleporterMixin();
public static DefaultPsTeleporterMixin get() { return i; }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void teleport(Entity entity, PS ps) throws PsTeleporterException
{
Location location = ps.calcLocation();
if (location == null) throw new PsTeleporterException(Txt.parse("<b>Could not calculate the location"));
entity.teleport(location);
Vector velocity = ps.getVelocity();
if (velocity == null) return;
entity.setVelocity(velocity);
}
}

View File

@ -0,0 +1,128 @@
package com.massivecraft.mcore5.mixin;
import java.io.File;
import java.util.Map;
import java.util.TreeMap;
import net.minecraft.server.v1_4_R1.DedicatedServer;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_4_R1.CraftServer;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerLoginEvent;
import com.massivecraft.mcore5.MCore;
import com.massivecraft.mcore5.util.MUtil;
public class DefaultSenderIdFixerMixin implements SenderIdFixerMixin, Listener
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static DefaultSenderIdFixerMixin i = new DefaultSenderIdFixerMixin();
public static DefaultSenderIdFixerMixin get() { return i; }
// -------------------------------------------- //
// REGISTER & UNREGISTER
// -------------------------------------------- //
public void register()
{
Bukkit.getServer().getPluginManager().registerEvents(this, MCore.p);
}
public void unregister()
{
HandlerList.unregisterAll(this);
}
// -------------------------------------------- //
// SETUP
// -------------------------------------------- //
public void setup()
{
this.populateIdToCorrectId();
}
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
protected File playerfolder = this.getPlayerFolder();
protected Map<String, String> idToCorrectId = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public boolean canFix(String name)
{
return this.reqFix(name) != null;
}
@Override
public String tryFix(String name)
{
String ret = this.reqFix(name);
if (ret != null) return ret;
return name;
}
@Override
public String reqFix(String name)
{
if (!MUtil.isValidPlayerName(name)) return name;
return this.idToCorrectId.get(name);
}
// -------------------------------------------- //
// LISTENER
// -------------------------------------------- //
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerLogin(PlayerLoginEvent event)
{
String id = event.getPlayer().getName();
idToCorrectId.put(id, id);
}
// -------------------------------------------- //
// INTERNAL METHODS
// -------------------------------------------- //
/**
* You might ask yourself why we do this in such a low-level way.
* The reason is this info is not yet "compiled" for plugins that init early.
*/
protected File getPlayerFolder()
{
CraftServer cserver = (CraftServer)Bukkit.getServer();
DedicatedServer dserver = (DedicatedServer)cserver.getServer();
String levelName = dserver.propertyManager.getString("level-name", "world");
return new File(Bukkit.getWorldContainer(), new File(levelName, "players").getPath());
}
protected void populateIdToCorrectId()
{
// List the files in the player folder
File[] playerfiles = this.playerfolder.listFiles();
// The player file may not exist yet
if (playerfiles == null) return;
// Populate by removing .dat
for (File playerfile : playerfiles)
{
String filename = playerfile.getName();
String playername = filename.substring(0, filename.length()-4);
this.idToCorrectId.put(playername, playername);
}
}
}

View File

@ -0,0 +1,11 @@
package com.massivecraft.mcore5.mixin;
import org.bukkit.command.CommandSender;
public interface DisplayNameMixin
{
public String get(String senderId);
public void set(String senderId, String displayName);
public String get(CommandSender sender);
public void set(CommandSender sender, String displayName);
}

View File

@ -0,0 +1,11 @@
package com.massivecraft.mcore5.mixin;
import org.bukkit.command.CommandSender;
public interface ListNameMixin
{
public String get(String senderId);
public void set(String senderId, String listName);
public String get(CommandSender sender);
public void set(CommandSender sender, String listName);
}

View File

@ -0,0 +1,26 @@
package com.massivecraft.mcore5.mixin;
public class Mixin
{
private static PsTeleporterMixin psTeleporterMixin = DefaultPsTeleporterMixin.get();
public static PsTeleporterMixin getPsTeleporterMixin() { return psTeleporterMixin; }
public static void setPsTeleporterMixin(PsTeleporterMixin val) { psTeleporterMixin = val; }
private static DisplayNameMixin displayNameMixin = DefaultDisplayNameMixin.get();
public static DisplayNameMixin getDisplayNameMixin() { return displayNameMixin; }
public static void setDisplayNameMixin(DisplayNameMixin val) { displayNameMixin = val; }
private static ListNameMixin listNameMixin = DefaultListNameMixin.get();
public static ListNameMixin getListNameMixin() { return listNameMixin; }
public static void setListNameMixin(ListNameMixin val) { listNameMixin = val; }
private static SenderIdFixerMixin senderIdFixerMixin = DefaultSenderIdFixerMixin.get();
public static SenderIdFixerMixin getSenderIdFixerMixin() { return senderIdFixerMixin; }
public static void setSenderIdFixerMixin(SenderIdFixerMixin val) { senderIdFixerMixin = val; }
// Add the command sender id resolver system as a mixin?
// Nah that could possibly stay a util.
// Player last online should be added
}

View File

@ -0,0 +1,31 @@
package com.massivecraft.mcore5.mixin;
public class PsTeleporterException extends Exception
{
private static final long serialVersionUID = 1L;
public PsTeleporterException()
{
super();
}
public PsTeleporterException(String message)
{
super(message);
}
public PsTeleporterException(String message, Throwable cause)
{
super(message, cause);
}
public PsTeleporterException(Throwable cause)
{
super(cause);
}
protected PsTeleporterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace)
{
super(message, cause, enableSuppression, writableStackTrace);
}
}

View File

@ -0,0 +1,14 @@
package com.massivecraft.mcore5.mixin;
import org.bukkit.entity.Entity;
import com.massivecraft.mcore5.PS;
public interface PsTeleporterMixin
{
/**
* @param entity The entity to be teleported
* @param ps The target PhysicalState
*/
public void teleport(Entity entity, PS ps) throws PsTeleporterException;
}

View File

@ -0,0 +1,8 @@
package com.massivecraft.mcore5.mixin;
public interface SenderIdFixerMixin
{
public boolean canFix(String name);
public String tryFix(String name);
public String reqFix(String name);
}

View File

@ -5,6 +5,8 @@ import org.bukkit.Server;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.permissions.PermissibleBase; import org.bukkit.permissions.PermissibleBase;
import com.massivecraft.mcore5.util.SenderUtil;
public class BasicCommandSender extends PermissibleBase implements CommandSender public class BasicCommandSender extends PermissibleBase implements CommandSender
{ {
private final String name; private final String name;
@ -40,7 +42,7 @@ public class BasicCommandSender extends PermissibleBase implements CommandSender
@Override @Override
public void sendMessage(String message) public void sendMessage(String message)
{ {
// Per default // Nothing per default
} }
@Override @Override
@ -51,4 +53,14 @@ public class BasicCommandSender extends PermissibleBase implements CommandSender
this.sendMessage(message); this.sendMessage(message);
} }
} }
public boolean register()
{
return SenderUtil.register(this);
}
public boolean unregister()
{
return SenderUtil.unregister(this);
}
} }

View File

@ -109,10 +109,10 @@ public class Coll<E, L extends Comparable<? super L>> implements CollInterface<E
@Override public boolean containsEntity(Object entity) { return this.entity2id.containsKey(entity); }; @Override public boolean containsEntity(Object entity) { return this.entity2id.containsKey(entity); };
@Override public Collection<E> getAll() { return Collections.unmodifiableCollection(this.entity2id.keySet()); } @Override public Collection<E> getAll() { return Collections.unmodifiableCollection(this.entity2id.keySet()); }
@Override public Collection<E> getAll(Predictate<E> where) { return MStoreUtil.uglySQL(this.getAll(), where, null, null, null); } @Override public Collection<E> getAll(Predictate<? super E> where) { return MStoreUtil.uglySQL(this.getAll(), where, null, null, null); }
@Override public Collection<E> getAll(Predictate<E> where, Comparator<E> orderby) { return MStoreUtil.uglySQL(this.getAll(), where, orderby, null, null); } @Override public Collection<E> getAll(Predictate<? super E> where, Comparator<? super E> orderby) { return MStoreUtil.uglySQL(this.getAll(), where, orderby, null, null); }
@Override public Collection<E> getAll(Predictate<E> where, Comparator<E> orderby, Integer limit) { return MStoreUtil.uglySQL(this.getAll(), where, orderby, limit, null); } @Override public Collection<E> getAll(Predictate<? super E> where, Comparator<? super E> orderby, Integer limit) { return MStoreUtil.uglySQL(this.getAll(), where, orderby, limit, null); }
@Override public Collection<E> getAll(Predictate<E> where, Comparator<E> orderby, Integer limit, Integer offset) { return MStoreUtil.uglySQL(this.getAll(), where, orderby, limit, offset); } @Override public Collection<E> getAll(Predictate<? super E> where, Comparator<? super E> orderby, Integer limit, Integer offset) { return MStoreUtil.uglySQL(this.getAll(), where, orderby, limit, offset); }
@Override @Override
public L fixId(Object oid) public L fixId(Object oid)

View File

@ -45,10 +45,10 @@ public interface CollInterface<E, L extends Comparable<? super L>>
public L getId(Object entity); public L getId(Object entity);
public boolean containsEntity(Object entity); public boolean containsEntity(Object entity);
public Collection<E> getAll(); public Collection<E> getAll();
public Collection<E> getAll(Predictate<E> where); public Collection<E> getAll(Predictate<? super E> where);
public Collection<E> getAll(Predictate<E> where, Comparator<E> orderby); public Collection<E> getAll(Predictate<? super E> where, Comparator<? super E> orderby);
public Collection<E> getAll(Predictate<E> where, Comparator<E> orderby, Integer limit); public Collection<E> getAll(Predictate<? super E> where, Comparator<? super E> orderby, Integer limit);
public Collection<E> getAll(Predictate<E> where, Comparator<E> orderby, Integer limit, Integer offset); public Collection<E> getAll(Predictate<? super E> where, Comparator<? super E> orderby, Integer limit, Integer offset);
public L fixId(Object oid); public L fixId(Object oid);

View File

@ -9,7 +9,7 @@ import com.massivecraft.mcore5.Predictate;
public class MStoreUtil public class MStoreUtil
{ {
public static <T> ArrayList<T> uglySQL(Collection<T> items, Predictate<T> where, Comparator<T> orderby, Integer limit, Integer offset) public static <T> ArrayList<T> uglySQL(Collection<T> items, Predictate<? super T> where, Comparator<? super T> orderby, Integer limit, Integer offset)
{ {
ArrayList<T> ret = new ArrayList<T>(items.size()); ArrayList<T> ret = new ArrayList<T>(items.size());

View File

@ -5,12 +5,12 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.AbstractMap.SimpleEntry; import java.util.AbstractMap.SimpleEntry;
import net.minecraft.server.v1_4_6.BiomeBase; import net.minecraft.server.v1_4_R1.BiomeBase;
import net.minecraft.server.v1_4_6.Chunk; import net.minecraft.server.v1_4_R1.Chunk;
import net.minecraft.server.v1_4_6.WorldServer; import net.minecraft.server.v1_4_R1.WorldServer;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.craftbukkit.v1_4_6.CraftWorld; import org.bukkit.craftbukkit.v1_4_R1.CraftWorld;
public class BiomeUtil public class BiomeUtil
{ {

View File

@ -6,7 +6,7 @@ import java.util.Map;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.SimpleCommandMap; import org.bukkit.command.SimpleCommandMap;
import org.bukkit.craftbukkit.v1_4_6.CraftServer; import org.bukkit.craftbukkit.v1_4_R1.CraftServer;
public class BukkitCommandUtil public class BukkitCommandUtil
{ {

View File

@ -1,57 +0,0 @@
package com.massivecraft.mcore5.util;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.Map;
import java.util.regex.Pattern;
import org.bukkit.Bukkit;
import org.bukkit.plugin.SimplePluginManager;
import org.bukkit.plugin.java.JavaPluginLoader;
@SuppressWarnings("unchecked")
public class ClassResolveUtil
{
protected static Collection<JavaPluginLoader> javaPluginLoaders;
static
{
try
{
SimplePluginManager pluginManager = (SimplePluginManager)Bukkit.getPluginManager();
Field field = SimplePluginManager.class.getDeclaredField("fileAssociations");
field.setAccessible(true);
Map<Pattern, JavaPluginLoader> fileAssociations = (Map<Pattern, JavaPluginLoader>)field.get(pluginManager);
javaPluginLoaders = fileAssociations.values(); // Does this one autoupdate?
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static Class<?> resolve(String className) throws ClassNotFoundException
{
//System.out.println("resolve..."+this.javaPluginLoaders.toString());
Class<?> ret = null;
for (JavaPluginLoader javaPluginLoader : javaPluginLoaders)
{
ret = javaPluginLoader.getClassByName(className);
if (ret != null)
{
return ret;
}
}
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
try
{
return classLoader.loadClass(className);
}
catch (ClassNotFoundException e)
{
return Class.forName(className, false, classLoader);
}
}
}

View File

@ -1,6 +1,6 @@
package com.massivecraft.mcore5.util; package com.massivecraft.mcore5.util;
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventoryCustom; import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventoryCustom;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;

View File

@ -1,10 +1,10 @@
package com.massivecraft.mcore5.util; package com.massivecraft.mcore5.util;
import net.minecraft.server.v1_4_6.WorldServer; import net.minecraft.server.v1_4_R1.WorldServer;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_4_6.CraftWorld; import org.bukkit.craftbukkit.v1_4_R1.CraftWorld;
public class LightUtil public class LightUtil
{ {

View File

@ -12,6 +12,7 @@ import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.regex.Pattern;
import java.util.Set; import java.util.Set;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.TreeSet; import java.util.TreeSet;
@ -45,6 +46,19 @@ import com.massivecraft.mcore5.util.extractor.ExtractorWorldName;
public class MUtil public class MUtil
{ {
// -------------------------------------------- //
// IS PLAYER ID
// -------------------------------------------- //
// Player id pattern, the regex for a valid minecraft username.
public final static Pattern playerNamePattern = Pattern.compile("^[a-zA-Z0-9_]{2,16}$");
public static boolean isValidPlayerName(Object o)
{
if (!(o instanceof String)) return false;
return playerNamePattern.matcher((String) o).matches();
}
// -------------------------------------------- // // -------------------------------------------- //
// MATERIAL FACTS // MATERIAL FACTS
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -5,7 +5,6 @@ import java.util.Map.Entry;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permissible; import org.bukkit.permissions.Permissible;
import org.bukkit.permissions.Permission; import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault; import org.bukkit.permissions.PermissionDefault;
@ -96,21 +95,21 @@ public class PermUtil
// ENSURE HAS // ENSURE HAS
// -------------------------------------------- // // -------------------------------------------- //
public static void ensureHas(Player player, String permissionName) public static void ensureHas(Permissible permissible, String permissionName)
{ {
if (player.hasPermission(permissionName)) if (permissible.hasPermission(permissionName))
{ {
return; return;
} }
else else
{ {
player.addAttachment(MCore.p, permissionName, true); permissible.addAttachment(MCore.p, permissionName, true);
} }
} }
public static void ensureHas(Player player, Permission permission) public static void ensureHas(Permissible permissible, Permission permission)
{ {
ensureHas(player, permission.getName()); ensureHas(permissible, permission.getName());
} }
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -6,15 +6,14 @@ import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.ConcurrentSkipListMap;
import java.util.regex.Pattern;
import net.minecraft.server.v1_4_6.DedicatedServer; import net.minecraft.server.v1_4_R1.DedicatedServer;
import net.minecraft.server.v1_4_6.EntityPlayer; import net.minecraft.server.v1_4_R1.EntityPlayer;
import net.minecraft.server.v1_4_6.Packet8UpdateHealth; import net.minecraft.server.v1_4_R1.Packet8UpdateHealth;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_4_6.CraftServer; import org.bukkit.craftbukkit.v1_4_R1.CraftServer;
import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
@ -85,7 +84,7 @@ public class PlayerUtil implements Listener
*/ */
public static boolean isValidPlayerName(final String playerName) public static boolean isValidPlayerName(final String playerName)
{ {
return Pattern.matches("^[a-zA-Z0-9_]{2,16}$", playerName); return MUtil.isValidPlayerName(playerName);
} }
public static Set<String> getAllVisitorNames() public static Set<String> getAllVisitorNames()

View File

@ -1,9 +1,9 @@
package com.massivecraft.mcore5.util; package com.massivecraft.mcore5.util;
import net.minecraft.server.v1_4_6.Packet41MobEffect; import net.minecraft.server.v1_4_R1.Packet41MobEffect;
import net.minecraft.server.v1_4_6.Packet42RemoveMobEffect; import net.minecraft.server.v1_4_R1.Packet42RemoveMobEffect;
import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;

View File

@ -1,12 +1,15 @@
package com.massivecraft.mcore5.util; package com.massivecraft.mcore5.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.regex.Pattern;
import net.minecraft.server.v1_4_6.MinecraftServer; import net.minecraft.server.v1_4_R1.MinecraftServer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -16,9 +19,10 @@ import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.command.RemoteConsoleCommandSender; import org.bukkit.command.RemoteConsoleCommandSender;
import org.bukkit.craftbukkit.v1_4_6.CraftServer; import org.bukkit.craftbukkit.v1_4_R1.CraftServer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.massivecraft.mcore5.mixin.Mixin;
import com.massivecraft.mcore5.sender.FakeBlockCommandSender; import com.massivecraft.mcore5.sender.FakeBlockCommandSender;
import com.massivecraft.mcore5.store.SenderColl; import com.massivecraft.mcore5.store.SenderColl;
@ -65,15 +69,11 @@ public class SenderUtil
public final static String VANILLA_RCON_NAME = "Rcon"; public final static String VANILLA_RCON_NAME = "Rcon";
public final static String VANILLA_BLOCK_NAME = "@"; public final static String VANILLA_BLOCK_NAME = "@";
// Player id pattern, the regex for a valid minecraft username.
public final static Pattern playerNamePattern = Pattern.compile("^[a-zA-Z0-9_]{2,16}$");
// -------------------------------------------- // // -------------------------------------------- //
// REGISTRY // REGISTRY
// -------------------------------------------- // // -------------------------------------------- //
protected static Map<String, CommandSender> idToSender = new TreeMap<String, CommandSender>(String.CASE_INSENSITIVE_ORDER); protected static Map<String, CommandSender> idToSender = new TreeMap<String, CommandSender>(String.CASE_INSENSITIVE_ORDER);
protected static Map<String, String> idToDisplayName = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
protected static Map<String, String> idToListName = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER); protected static Map<String, String> idToListName = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
public static synchronized boolean register(CommandSender sender) public static synchronized boolean register(CommandSender sender)
@ -87,6 +87,11 @@ public class SenderUtil
return true; return true;
} }
public static synchronized boolean unregister(CommandSender sender)
{
return idToSender.remove(getSenderId(sender)) != null;
}
public static Map<String, CommandSender> getIdToSender() public static Map<String, CommandSender> getIdToSender()
{ {
return Collections.unmodifiableMap(idToSender); return Collections.unmodifiableMap(idToSender);
@ -121,8 +126,7 @@ public class SenderUtil
public static boolean isPlayerId(Object o) public static boolean isPlayerId(Object o)
{ {
if (!isSenderId(o)) return false; return MUtil.isValidPlayerName(o);
return playerNamePattern.matcher((String) o).matches();
} }
public static boolean isConsoleId(Object o) public static boolean isConsoleId(Object o)
@ -365,10 +369,22 @@ public class SenderUtil
return isOffline(getSenderId(sender)); return isOffline(getSenderId(sender));
} }
/*public static LinkedHashSet<String> getOnlineIds(String senderId) // -------------------------------------------- //
// GET ALL ONLINE
// -------------------------------------------- //
public static List<CommandSender> getOnlineSenders()
{ {
return false; List<CommandSender> ret = new ArrayList<CommandSender>(Arrays.asList(Bukkit.getOnlinePlayers()));
}*/ for (Entry<String, CommandSender> entry : idToSender.entrySet())
{
String id = entry.getKey();
CommandSender sender = entry.getValue();
if (isPlayerId(id)) continue;
ret.add(sender);
}
return ret;
}
// -------------------------------------------- // // -------------------------------------------- //
// DISPLAY NAME // DISPLAY NAME
@ -376,33 +392,22 @@ public class SenderUtil
public static String getDisplayName(String senderId) public static String getDisplayName(String senderId)
{ {
String ret = idToDisplayName.get(senderId); return Mixin.getDisplayNameMixin().get(senderId);
if (ret != null) return ret;
Player player = Bukkit.getPlayer(senderId);
if (player == null) return senderId;
return player.getDisplayName();
} }
public static void setDisplayName(String senderId, String displayName) public static void setDisplayName(String senderId, String displayName)
{ {
idToDisplayName.put(senderId, displayName); Mixin.getDisplayNameMixin().set(senderId, displayName);
Player player = Bukkit.getPlayer(senderId);
if (player == null) return;
player.setDisplayName(displayName);
} }
public static String getDisplayName(CommandSender sender) public static String getDisplayName(CommandSender sender)
{ {
return getDisplayName(getSenderId(sender)); return Mixin.getDisplayNameMixin().get(sender);
} }
public static void setDisplayName(CommandSender sender, String displayName) public static void setDisplayName(CommandSender sender, String displayName)
{ {
setDisplayName(getSenderId(sender), displayName); Mixin.getDisplayNameMixin().set(sender, displayName);
} }
// -------------------------------------------- // // -------------------------------------------- //
@ -411,33 +416,22 @@ public class SenderUtil
public static String getListName(String senderId) public static String getListName(String senderId)
{ {
String ret = idToListName.get(senderId); return Mixin.getListNameMixin().get(senderId);
if (ret != null) return ret;
Player player = Bukkit.getPlayer(senderId);
if (player == null) return senderId;
return player.getPlayerListName();
} }
public static void setListName(String senderId, String displayName) public static void setListName(String senderId, String displayName)
{ {
idToListName.put(senderId, displayName); Mixin.getListNameMixin().set(senderId, displayName);
Player player = Bukkit.getPlayer(senderId);
if (player == null) return;
player.setPlayerListName(displayName);
} }
public static String getListName(CommandSender sender) public static String getListName(CommandSender sender)
{ {
return getListName(getSenderId(sender)); return Mixin.getListNameMixin().get(sender);
} }
public static void setListName(CommandSender sender, String displayName) public static void setListName(CommandSender sender, String displayName)
{ {
setListName(getSenderId(sender), displayName); Mixin.getListNameMixin().set(sender, displayName);
} }
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -25,7 +25,7 @@ public class TextWrapper
private static final char COLOR_CHAR = '\u00A7'; private static final char COLOR_CHAR = '\u00A7';
private static final int CHAT_WINDOW_WIDTH = 320; private static final int CHAT_WINDOW_WIDTH = 320;
private static final int CHAT_STRING_LENGTH = 119; private static final int CHAT_STRING_LENGTH = 119;
private static final String allowedChars = net.minecraft.server.v1_4_6.SharedConstants.allowedCharacters; private static final String allowedChars = net.minecraft.server.v1_4_R1.SharedConstants.allowedCharacters;
public static int getCharPixelWidth(char ch) public static int getCharPixelWidth(char ch)
{ {

View File

@ -1,6 +1,6 @@
package com.massivecraft.mcore5.util; package com.massivecraft.mcore5.util;
import org.bukkit.craftbukkit.v1_4_6.entity.CraftThrownPotion; import org.bukkit.craftbukkit.v1_4_R1.entity.CraftThrownPotion;
import org.bukkit.entity.ThrownPotion; import org.bukkit.entity.ThrownPotion;
// PR to add this feature to the API: // PR to add this feature to the API: