Permalink
Browse files

Various updates to abstraction

This includes additions, fixes and optimizations. It also removes the final illusion of compatibility with versions prior to 1.7.10.
  • Loading branch information...
PseudoKnight committed Oct 27, 2017
1 parent 7b3d691 commit 7450f62119a36d03c12620913e4ede4728da68e1
@@ -2,6 +2,7 @@
package com.laytonsmith.abstraction;
import com.laytonsmith.abstraction.enums.MCInstrument;
import com.laytonsmith.abstraction.enums.MCParticle;
import com.laytonsmith.abstraction.enums.MCSound;
import com.laytonsmith.abstraction.enums.MCSoundCategory;
import com.laytonsmith.abstraction.enums.MCWeather;
@@ -146,6 +147,8 @@
public void stopSound(String sound, MCSoundCategory category);
void spawnParticle(MCLocation l, MCParticle pa, int count, double offsetX, double offsetY, double offsetZ, double velocity, Object data);
int getFoodLevel();
void setFoodLevel(int f);
@@ -11,6 +11,7 @@
import com.laytonsmith.abstraction.enums.MCEntityType;
import com.laytonsmith.abstraction.enums.MCGameRule;
import com.laytonsmith.abstraction.enums.MCMobs;
import com.laytonsmith.abstraction.enums.MCParticle;
import com.laytonsmith.abstraction.enums.MCSound;
import com.laytonsmith.abstraction.enums.MCSoundCategory;
import com.laytonsmith.abstraction.enums.MCTreeType;
@@ -65,6 +66,7 @@
public boolean generateTree(MCLocation l, MCTreeType treeType);
public void playEffect(MCLocation l, MCEffect mCEffect, int data, int radius);
public void spawnParticle(MCLocation l, MCParticle pa, int count, double offsetX, double offsetY, double offsetZ, double velocity, Object data);
public void playSound(MCLocation l, MCSound sound, float volume, float pitch);
public void playSound(MCLocation l, String sound, float volume, float pitch);
@@ -4,19 +4,12 @@
import com.laytonsmith.abstraction.MCMaterialData;
import com.laytonsmith.abstraction.MCMetadatable;
/**
*
*
*/
public interface MCBlockState extends MCMetadatable {
public MCMaterialData getData();
public int getTypeId();
public MCBlock getBlock();
public MCLocation getLocation();
public void update();
MCMaterialData getData();
int getTypeId();
void setTypeId(int type);
void setRawData(byte data);
MCBlock getBlock();
MCLocation getLocation();
void update();
}
@@ -54,7 +54,6 @@
import com.laytonsmith.abstraction.bukkit.events.drivers.BukkitWeatherListener;
import com.laytonsmith.abstraction.bukkit.events.drivers.BukkitWorldListener;
import com.laytonsmith.abstraction.enums.MCDyeColor;
import com.laytonsmith.abstraction.enums.MCEntityType;
import com.laytonsmith.abstraction.enums.MCPatternShape;
import com.laytonsmith.abstraction.enums.MCPotionType;
import com.laytonsmith.abstraction.enums.MCRecipeType;
@@ -94,6 +93,7 @@
import org.bukkit.entity.ComplexEntityPart;
import org.bukkit.entity.ComplexLivingEntity;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Hanging;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.LivingEntity;
@@ -110,12 +110,12 @@
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.ShapelessRecipe;
import org.bukkit.inventory.meta.*;
import org.bukkit.material.MaterialData;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.potion.PotionData;
import org.yaml.snakeyaml.Yaml;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -156,17 +156,15 @@ public Class GetServerEventMixin() {
@Override
public MCEnchantment GetEnchantmentByName(String name) {
Enchantment enchant = Enchantment.getByName(name);
if(enchant != null) {
return new BukkitMCEnchantment(enchant);
}
try {
//If they are looking it up by number, we can support that
//If they are looking it up by number, we can support that too
int i = Integer.valueOf(name);
return new BukkitMCEnchantment(Enchantment.getById(i));
} catch (NumberFormatException e) {
try {
return new BukkitMCEnchantment(Enchantment.getByName(name));
} catch (NullPointerException ee) {
return null;
}
} catch(NullPointerException e) {
} catch(NumberFormatException | NullPointerException e) {
return null;
}
}
@@ -251,8 +249,9 @@ public void Startup(CommandHelperPlugin chp) {
@Override
public int LookupItemId(String materialName) {
if (Material.matchMaterial(materialName) != null) {
return new MaterialData(Material.matchMaterial(materialName)).getItemTypeId();
Material mat = Material.matchMaterial(materialName);
if (mat != null) {
return mat.getId();
} else {
return -1;
}
@@ -424,10 +423,17 @@ public MCItemMeta GetCorrectMeta(MCItemMeta im) {
if (radius <= 0) {
radius = 1;
}
Entity tempEntity = ((BukkitMCEntity) location.getWorld().spawn(location, MCEntityType.MCVanillaEntityType.ARROW)).getHandle();
List<Entity> near = tempEntity.getNearbyEntities(radius, radius, radius);
tempEntity.remove();
List<MCEntity> entities = new ArrayList<MCEntity>();
Location l = (Location) location.getHandle();
Collection<Entity> near;
try {
near = l.getWorld().getNearbyEntities(l, radius, radius, radius);
} catch(NoSuchMethodError ex) {
// Probably before 1.8.3
Entity tempEntity = l.getWorld().spawnEntity(l, EntityType.ARROW);
near = tempEntity.getNearbyEntities(radius, radius, radius);
tempEntity.remove();
}
List<MCEntity> entities = new ArrayList<>();
for (Entity e : near) {
entities.add(BukkitGetCorrectEntity(e));
}
@@ -502,10 +508,10 @@ public MCInventory GetEntityInventory(MCEntity e) {
@Override
public MCInventory GetLocationInventory(MCLocation location) {
Block b = ((Location) (location.getHandle())).getBlock();
Block b = ((Location) location.getHandle()).getBlock();
if (b.getState() instanceof InventoryHolder) {
if (b.getState() instanceof DoubleChest) {
DoubleChest dc = (DoubleChest) (b.getState());
DoubleChest dc = (DoubleChest) b.getState();
return new BukkitMCDoubleChest(dc.getLeftSide().getInventory(), dc.getRightSide().getInventory());
} else {
return new BukkitMCInventory(((InventoryHolder) b.getState()).getInventory());
@@ -45,13 +45,7 @@ public String getName() {
@Override
public MCScore getScore(String entry) {
try {
return new BukkitMCScore(o.getScore(entry));
} catch(NoSuchMethodError ex){
// Probably 1.7.8 or prior
OfflinePlayer player = Bukkit.getOfflinePlayer(entry);
return new BukkitMCScore((Score) ReflectionUtils.invokeMethod(o, "getScore", player));
}
return new BukkitMCScore(o.getScore(entry));
}
@Override
@@ -72,16 +72,7 @@ public MCObjective getObjective(String name) {
@Override
public Set<String> getEntries() {
try {
return s.getEntries();
} catch(NoSuchMethodError ex){
// Probably 1.7.8 or prior
Set<String> ret = new HashSet<>();
for (OfflinePlayer o : (Set<OfflinePlayer>) ReflectionUtils.invokeMethod(s, "getPlayers")) {
ret.add(o.getName());
}
return ret;
}
return s.getEntries();
}
@Override
@@ -106,16 +97,8 @@ public MCTeam getPlayerTeam(String entry) {
@Override
public Set<MCScore> getScores(String entry) {
Set<MCScore> ret = new HashSet<>();
try {
for (Score o : s.getScores(entry)) {
ret.add(new BukkitMCScore(o));
}
} catch(NoSuchMethodError ex){
// Probably 1.7.8 or prior
OfflinePlayer player = Bukkit.getOfflinePlayer(entry);
for (Score o : (Set<Score>) ReflectionUtils.invokeMethod(s, "getScores", player)) {
ret.add(new BukkitMCScore(o));
}
for (Score o : s.getScores(entry)) {
ret.add(new BukkitMCScore(o));
}
return ret;
}
@@ -150,13 +133,7 @@ public MCTeam registerNewTeam(String name) {
@Override
public void resetScores(String entry) {
try {
s.resetScores(entry);
} catch(NoSuchMethodError ex){
// Probably 1.7.8 or prior
OfflinePlayer player = Bukkit.getOfflinePlayer(entry);
ReflectionUtils.invokeMethod(s, "resetScores", player);
}
s.resetScores(entry);
}
@Override
Oops, something went wrong.

0 comments on commit 7450f62

Please sign in to comment.