Add a removeByIndex utility method and a new arg reader.
This commit is contained in:
		
							parent
							
								
									af539e1a51
								
							
						
					
					
						commit
						23ddea0772
					
				
							
								
								
									
										48
									
								
								src/com/massivecraft/mcore/cmd/arg/AREntityType.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								src/com/massivecraft/mcore/cmd/arg/AREntityType.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,48 @@ | ||||
| package com.massivecraft.mcore.cmd.arg; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.Collection; | ||||
| import java.util.List; | ||||
| 
 | ||||
| import org.bukkit.command.CommandSender; | ||||
| import org.bukkit.entity.EntityType; | ||||
| 
 | ||||
| public class AREntityType extends ARAbstractSelect<EntityType> | ||||
| { | ||||
| 	// -------------------------------------------- // | ||||
| 	// INSTANCE & CONSTRUCT | ||||
| 	// -------------------------------------------- // | ||||
| 	 | ||||
| 	private static AREntityType i = new AREntityType(); | ||||
| 	public static AREntityType get() { return i; } | ||||
| 	 | ||||
| 	// -------------------------------------------- // | ||||
| 	// OVERRIDE | ||||
| 	// -------------------------------------------- // | ||||
| 	 | ||||
| 	@Override | ||||
| 	public String typename() | ||||
| 	{ | ||||
| 		return "entity type"; | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("deprecation") | ||||
| 	@Override | ||||
| 	public EntityType select(String arg, CommandSender sender) | ||||
| 	{ | ||||
| 		return EntityType.fromName(arg); | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("deprecation") | ||||
| 	@Override | ||||
| 	public Collection<String> altNames(CommandSender sender) | ||||
| 	{ | ||||
| 		List<String> ret = new ArrayList<String>(); | ||||
| 		for (EntityType entityType : EntityType.values()) | ||||
| 		{ | ||||
| 			ret.add(entityType.getName()); | ||||
| 		} | ||||
| 		return ret; | ||||
| 	} | ||||
| 	 | ||||
| } | ||||
| @ -449,6 +449,36 @@ public class MUtil | ||||
| 		return ret; | ||||
| 	} | ||||
| 	 | ||||
| 	// -------------------------------------------- // | ||||
| 	// COLLECTION MANIPULATION | ||||
| 	// -------------------------------------------- // | ||||
| 	 | ||||
| 	public static <T> T removeByIndex(Collection<T> coll, int index) | ||||
| 	{ | ||||
| 		if (coll == null) throw new NullPointerException("coll"); | ||||
| 		 | ||||
| 		if (coll instanceof List<?>) | ||||
| 		{ | ||||
| 			return ((List<T>)coll).remove(index); | ||||
| 		} | ||||
| 		 | ||||
| 		if (index < 0) throw new IndexOutOfBoundsException("index < 0"); | ||||
| 		if (index >= coll.size()) throw new IndexOutOfBoundsException("index > collection size"); | ||||
| 		 | ||||
| 		int i = -1; | ||||
| 		Iterator<T> iter = coll.iterator(); | ||||
| 		while (iter.hasNext()) | ||||
| 		{ | ||||
| 			i++; | ||||
| 			T ret = iter.next(); | ||||
| 			if (i != index) continue; | ||||
| 			iter.remove(); | ||||
| 			return ret; | ||||
| 		} | ||||
| 		 | ||||
| 		return null; | ||||
| 	} | ||||
| 	 | ||||
| 	// -------------------------------------------- // | ||||
| 	// LE NICE RANDOM | ||||
| 	// -------------------------------------------- // | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user