Skip to content

Commit

Permalink
Added get_art_at for testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
LadyCailin committed Jul 16, 2013
1 parent 8e87f63 commit 39388cc
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/java/com/laytonsmith/abstraction/Convertor.java
Expand Up @@ -5,6 +5,7 @@
import com.laytonsmith.abstraction.blocks.MCMaterial;
import com.laytonsmith.abstraction.enums.MCTone;
import com.laytonsmith.commandhelper.CommandHelperPlugin;
import java.util.List;
import java.util.concurrent.Callable;

/**
Expand Down Expand Up @@ -63,6 +64,14 @@ public interface Convertor {

public MCItemMeta GetCorrectMeta(MCItemMeta im);

/**
* Returns the entities at the specified location, or null
* if no entities are in this location.
* @param loc
* @return
*/
public List<MCEntity> GetEntitiesAt(MCLocation loc, double radius);

/**
* Gets the inventory of the specified entity, or null if the entity id
* is invalid
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/laytonsmith/abstraction/MCPainting.java
@@ -0,0 +1,12 @@
package com.laytonsmith.abstraction;

import com.laytonsmith.abstraction.enums.MCArt;

/**
*
*/
public interface MCPainting extends MCHanging {
MCArt getArt();
boolean setArt(MCArt art);
boolean setArt(MCArt art, boolean force);
}
Expand Up @@ -10,10 +10,14 @@
import com.laytonsmith.abstraction.bukkit.entities.*;
import com.laytonsmith.abstraction.bukkit.events.BukkitAbstractEventMixin;
import com.laytonsmith.abstraction.bukkit.events.drivers.*;
import com.laytonsmith.abstraction.enums.MCEntityType;
import com.laytonsmith.abstraction.enums.MCTone;
import com.laytonsmith.annotations.convert;
import com.laytonsmith.commandhelper.CommandHelperPlugin;
import com.laytonsmith.core.Static;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.Callable;
Expand Down Expand Up @@ -217,6 +221,10 @@ public static MCEntity BukkitGetCorrectEntity(Entity be){
return new BukkitMCProjectile((Projectile)be);
}

if(be instanceof Painting){
return new BukkitMCPainting((Painting)be);
}

if(be instanceof Hanging){
return new BukkitMCHanging(be);
}
Expand Down Expand Up @@ -284,6 +292,23 @@ public MCItemMeta GetCorrectMeta(MCItemMeta im) {
return BukkitConvertor.BukkitGetCorrectMeta(bim);
}

public List<MCEntity> GetEntitiesAt(MCLocation location, double radius) {
if(location == null){
return Collections.EMPTY_LIST;
}
if(radius <= 0){
radius = 1;
}
Entity tempEntity = ((BukkitMCEntity)location.getWorld().spawn(location, MCEntityType.ARROW)).asEntity();
List<Entity> near = tempEntity.getNearbyEntities(radius, radius, radius);
tempEntity.remove();
List<MCEntity> entities = new ArrayList<MCEntity>();
for(Entity e : near){
entities.add(BukkitGetCorrectEntity(e));
}
return entities;
}

public static MCItemMeta BukkitGetCorrectMeta(ItemMeta im) {
if (im instanceof BookMeta) {
return new BukkitMCBookMeta((BookMeta) im);
Expand Down
@@ -0,0 +1,32 @@
package com.laytonsmith.abstraction.bukkit;

import com.laytonsmith.abstraction.MCPainting;
import com.laytonsmith.abstraction.enums.MCArt;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCArt;
import org.bukkit.entity.Painting;

/**
*
*/
public class BukkitMCPainting extends BukkitMCHanging implements MCPainting {

Painting p;

public BukkitMCPainting(Painting painting){
super(painting);
this.p = painting;
}

public MCArt getArt() {
return BukkitMCArt.getConvertor().getAbstractedEnum(p.getArt());
}

public boolean setArt(MCArt art) {
return setArt(art, false);
}

public boolean setArt(MCArt art, boolean force) {
return p.setArt(BukkitMCArt.getConvertor().getConcreteEnum(art), force);
}

}
33 changes: 33 additions & 0 deletions src/main/java/com/laytonsmith/abstraction/enums/MCArt.java
@@ -0,0 +1,33 @@
package com.laytonsmith.abstraction.enums;

/**
*
*/
public enum MCArt {
KEBAB,
AZTEC,
ALBAN,
AZTEC2,
BOMB,
PLANT,
WASTELAND,
POOL,
COURBET,
SEA,
SUNSET,
CREEBET,
WANDERER,
GRAHAM,
MATCH,
BUST,
STAGE,
VOID,
SKULL_AND_ROSES,
WITHER,
FIGHTERS,
POINTER,
PIGSCENE,
BURNINGSKULL,
SKELETON,
DONKEYKONG;
}
@@ -0,0 +1,25 @@
package com.laytonsmith.abstraction.enums.bukkit;

import com.laytonsmith.abstraction.Implementation;
import com.laytonsmith.abstraction.enums.EnumConvertor;
import com.laytonsmith.abstraction.enums.MCArt;
import com.laytonsmith.annotations.abstractionenum;
import org.bukkit.Art;

@abstractionenum(
implementation = Implementation.Type.BUKKIT,
forAbstractEnum = MCArt.class,
forConcreteEnum = Art.class)
public class BukkitMCArt extends EnumConvertor<MCArt, Art> {

private static com.laytonsmith.abstraction.enums.bukkit.BukkitMCArt instance;

public static com.laytonsmith.abstraction.enums.bukkit.BukkitMCArt getConvertor() {
if (instance == null) {
instance = new com.laytonsmith.abstraction.enums.bukkit.BukkitMCArt();
}
return instance;
}


}
88 changes: 88 additions & 0 deletions src/main/java/com/laytonsmith/core/functions/EntityManagement.java
@@ -1,10 +1,12 @@
package com.laytonsmith.core.functions;

import com.laytonsmith.PureUtilities.StringUtils;
import com.laytonsmith.PureUtilities.Version;
import com.laytonsmith.abstraction.*;
import com.laytonsmith.abstraction.blocks.MCBlockFace;
import com.laytonsmith.abstraction.entities.MCBoat;
import com.laytonsmith.abstraction.entities.MCMinecart;
import com.laytonsmith.abstraction.enums.MCArt;
import com.laytonsmith.abstraction.enums.MCEntityEffect;
import com.laytonsmith.abstraction.enums.MCEntityType;
import com.laytonsmith.abstraction.enums.MCEquipmentSlot;
Expand Down Expand Up @@ -1383,4 +1385,90 @@ public String docs() {
return "void {entityID, boolean} Sets a living entity's ability to pick up items.";
}
}

@api public static class get_art_at extends AbstractFunction {

public ExceptionType[] thrown() {
return new ExceptionType[]{ExceptionType.BadEntityException};
}

public boolean isRestricted() {
return true;
}

public Boolean runAsync() {
return false;
}

public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException {
MCWorld w = null;
if(environment.getEnv(CommandHelperEnvironment.class).GetPlayer() != null){
w = environment.getEnv(CommandHelperEnvironment.class).GetPlayer().getWorld();
}
List<MCEntity> es = StaticLayer.GetConvertor().GetEntitiesAt(ObjectGenerator.GetGenerator().location(args[0], w, t), 1);
for(MCEntity e : es){
if(e instanceof MCPainting){
return new CString(((MCPainting)e).getArt().name(), t);
}
}
throw new ConfigRuntimeException("There is no painting at the specified location", ExceptionType.BadEntityException, t);
}

public String getName() {
return "get_art_at";
}

public Integer[] numArgs() {
return new Integer[]{1};
}

public String docs() {
return "string {locationArray} Gets the specified art at the given location. If the item"
+ " at the specified location isn't a painting, an ----"
+ " Will be one of the following: " + StringUtils.Join(MCArt.values(), ", ") + ".";
}

public Version since() {
return CHVersion.V3_3_1;
}

}

// @api public static class set_art_at extends AbstractFunction {
//
// public ExceptionType[] thrown() {
// return new ExceptionType[]{};
// }
//
// public boolean isRestricted() {
// return true;
// }
//
// public Boolean runAsync() {
// return false;
// }
//
// public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException {
//
// }
//
// public String getName() {
// return "set_art_at";
// }
//
// public Integer[] numArgs() {
// return new Integer[]{2, 3};
// }
//
// public String docs() {
// return "boolean {locationArray, art} Sets the art at the specified location. If the art"
// + " doesn't fit, nothing happens, and false is returned. Otherwise, true is returned."
// + " ---- Art may be one of the following: " + StringUtils.Join(MCArt.values(), ", ");
// }
//
// public Version since() {
// return CHVersion.V3_3_1;
// }
//
// }
}
4 changes: 4 additions & 0 deletions src/test/java/com/laytonsmith/testing/StaticTest.java
Expand Up @@ -699,6 +699,10 @@ public MCMaterial getMaterial(int id) {
public MCItemMeta GetCorrectMeta(MCItemMeta im) {
throw new UnsupportedOperationException("Not supported yet.");
}

public List<MCEntity> GetEntitiesAt(MCLocation loc, double radius) {
throw new UnsupportedOperationException("Not supported yet.");
}

}

Expand Down

0 comments on commit 39388cc

Please sign in to comment.