Skip to content
Permalink
Browse files
Add compass item meta
  • Loading branch information
PseudoKnight committed Jul 2, 2020
1 parent eba81c0 commit 52b1b1c8bbd91f928ff173185dd081f4e77b0c47
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 2 deletions.
@@ -0,0 +1,12 @@
package com.laytonsmith.abstraction;

public interface MCCompassMeta extends MCItemMeta {

MCLocation getTargetLocation();

void setTargetLocation(MCLocation location);

boolean isLodestoneTracked();

void setLodestoneTracked(boolean tracked);
}
@@ -143,6 +143,7 @@
import org.bukkit.inventory.meta.BannerMeta;
import org.bukkit.inventory.meta.BlockStateMeta;
import org.bukkit.inventory.meta.BookMeta;
import org.bukkit.inventory.meta.CompassMeta;
import org.bukkit.inventory.meta.CrossbowMeta;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.FireworkEffectMeta;
@@ -568,8 +569,13 @@ public static MCItemMeta BukkitGetCorrectMeta(ItemMeta im) {
if(im instanceof TropicalFishBucketMeta) {
return new BukkitMCTropicalFishBucketMeta((TropicalFishBucketMeta) im);
}
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_14) && im instanceof CrossbowMeta) {
return new BukkitMCCrossbowMeta((CrossbowMeta) im);
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_14)) {
if(im instanceof CrossbowMeta) {
return new BukkitMCCrossbowMeta((CrossbowMeta) im);
}
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_16) && im instanceof CompassMeta) {
return new BukkitMCCompassMeta((CompassMeta) im);
}
}
return new BukkitMCItemMeta(im);
}
@@ -0,0 +1,44 @@
package com.laytonsmith.abstraction.bukkit;

import com.laytonsmith.abstraction.MCCompassMeta;
import com.laytonsmith.abstraction.MCLocation;
import org.bukkit.Location;
import org.bukkit.inventory.meta.CompassMeta;

public class BukkitMCCompassMeta extends BukkitMCItemMeta implements MCCompassMeta {

CompassMeta cm;

public BukkitMCCompassMeta(CompassMeta im) {
super(im);
this.cm = im;
}

@Override
public MCLocation getTargetLocation() {
Location l = cm.getLodestone();
if(l == null) {
return null;
}
return new BukkitMCLocation(l);
}

@Override
public void setTargetLocation(MCLocation location) {
if(location == null) {
cm.setLodestone(null);
} else {
cm.setLodestone((Location) location.getHandle());
}
}

@Override
public boolean isLodestoneTracked() {
return cm.isLodestoneTracked();
}

@Override
public void setLodestoneTracked(boolean tracked) {
cm.setLodestoneTracked(tracked);
}
}
@@ -7,6 +7,7 @@
import com.laytonsmith.abstraction.MCBookMeta;
import com.laytonsmith.abstraction.MCBrewerInventory;
import com.laytonsmith.abstraction.MCColor;
import com.laytonsmith.abstraction.MCCompassMeta;
import com.laytonsmith.abstraction.MCCreatureSpawner;
import com.laytonsmith.abstraction.MCCrossbowMeta;
import com.laytonsmith.abstraction.MCEnchantment;
@@ -656,6 +657,14 @@ public Construct itemMeta(MCItemStack is, Target t) {
} else {
ma.set("projectiles", CNull.NULL, t);
}
} else if(meta instanceof MCCompassMeta) {
MCCompassMeta cm = (MCCompassMeta) meta;
if(cm.getTargetLocation() == null) {
ma.set("target", CNull.NULL, t);
} else {
ma.set("target", location(cm.getTargetLocation(), false), t);
}
ma.set("lodestone", CBoolean.get(cm.isLodestoneTracked()), t);
}
return ma;
}
@@ -1099,6 +1108,17 @@ public MCItemMeta itemMeta(Mixed c, MCMaterial mat, Target t) throws ConfigRunti
((MCCrossbowMeta) meta).setChargedProjectiles(projectiles);
}
}
} else if(meta instanceof MCCompassMeta) {
if(ma.containsKey("target")) {
Mixed loc = ma.get("target", t);
if(!(loc instanceof CNull)) {
((MCCompassMeta) meta).setTargetLocation(location(loc, null, t));
}
}
if(ma.containsKey("lodestone")) {
((MCCompassMeta) meta).setLodestoneTracked(
ArgumentValidation.getBooleanObject(ma.get("lodestone", t), t));
}
}
} catch (Exception ex) {
throw new CREFormatException(ex.getMessage(), t, ex);
@@ -101,4 +101,9 @@ Below are the available fields in the item meta array. Fields can be null when t
| Beehive
|
* '''flowerlocation''' : (array) The location of a flower for bees to target, or null if there is none.
|-
| Compass
|
* '''target''' : (array) The location this compass will point to, or null to use normal compass target.
* '''lodestone''' : (boolean) If the target location is a tracked lodestone. If true, compass spins if no lodestone exists there.
|}

0 comments on commit 52b1b1c

Please sign in to comment.