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

Fix compatibility (fixes #7) #9

Merged
merged 1 commit into from
Nov 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}

}