Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #9 from LifeMC/fix-compatibility
Browse files Browse the repository at this point in the history
Fix compatibility (fixes #7)
  • Loading branch information
Mustafa ÖNCEL authored Nov 12, 2018
2 parents 3eeeb17 + 1dd5b95 commit a4f1a9a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
47 changes: 31 additions & 16 deletions src/main/java/ch/njol/skript/expressions/ExprEntities.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,6 @@

package ch.njol.skript.expressions;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.eclipse.jdt.annotation.Nullable;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
Expand All @@ -56,6 +42,21 @@
import ch.njol.util.coll.iterator.CheckedIterator;
import ch.njol.util.coll.iterator.NonNullIterator;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.eclipse.jdt.annotation.Nullable;

/**
* @author Peter Güttinger
*/
Expand Down Expand Up @@ -169,9 +170,23 @@ public boolean isLoopOf(final String s) {
return false;
}

@SuppressWarnings("null")
private final static boolean getNearbyEntities = Skript.methodExists(World.class, "getNearbyEntities", Location.class, double.class, double.class, double.class);

@Nullable
private final static Collection<Entity> getNearbyEntities(final Location l, final double x, final double y, final double z) {
if(getNearbyEntities) {
return l.getWorld().getNearbyEntities(l, x, y, z);
} else {
// The NMS method will be included in next LifeSpigot release.
// https://www.lifemcserver.com/forum/konular/lifespigot-sueruemue-yayinlandi-lifespigot-1-7-x-1-8-x.2369/
// Return empty collection for servers not using life spigot and 1.8.
return Collections.emptyList();
}
}

@Override
@Nullable
@SuppressWarnings("null")
public Iterator<? extends Entity> iterator(final Event e) {
if (matchedPattern >= 2) {
final Location l;
Expand All @@ -191,7 +206,7 @@ public Iterator<? extends Entity> iterator(final Event e) {
if (n == null)
return null;
final double d = n.doubleValue();
final Collection<Entity> es = l.getWorld().getNearbyEntities(l, d, d, d);
final Collection<Entity> es = getNearbyEntities(l, d, d, d);
final double radiusSquared = d * d * Skript.EPSILON_MULT;
final EntityData<?>[] ts = types.getAll(e);
return new CheckedIterator<Entity>(es.iterator(), new NullableChecker<Entity>() {
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/ch/njol/skript/util/Color.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,7 @@ public final static byte getData(final DyeColor color) {
if(getWoolData) {
return color.getWoolData();
}
try {
return color.getData();
} catch(final Throwable tw) {
getWoolData = !getWoolData;
return getData(color);
}
return color.getData();
}

}

0 comments on commit a4f1a9a

Please sign in to comment.