Permalink
Browse files

Merge branch 'master' of github.com:EngineHub/commandhelper

  • Loading branch information...
LadyCailin committed Nov 6, 2018
2 parents d68b63d + 60036af commit 8f7d354dd41d19e48c8bd8f85b2cb8ce6ad8fd13
@@ -25,7 +25,7 @@
List<MCEntity> getNearbyEntities(double x, double y, double z);
MCEntity getPassenger();
List<MCEntity> getPassengers();
MCServer getServer();
@@ -22,6 +22,8 @@
MCPluginManager getPluginManager();
MCPlayer getPlayerExact(String name);
MCPlayer getPlayer(String name);
MCPlayer getPlayer(UUID uuid);
@@ -1,5 +1,6 @@
package com.laytonsmith.abstraction;
import com.laytonsmith.abstraction.enums.MCChatColor;
import com.laytonsmith.abstraction.enums.MCOption;
import com.laytonsmith.abstraction.enums.MCOptionStatus;
@@ -29,6 +30,8 @@
String getSuffix();
MCChatColor getColor();
boolean hasEntry(String entry);
boolean removeEntry(String entry);
@@ -45,5 +48,7 @@
void setSuffix(String suffix);
void setColor(MCChatColor color);
void unregister();
}
@@ -44,7 +44,7 @@ public MCItemStack getInput() {
@Override
public void setInput(MCItemStack input) {
fr.setInput(((ItemStack) input.getHandle()).getData());
fr.setInput(((ItemStack) input.getHandle()).getType());
}
@Override
@@ -172,6 +172,16 @@ public MCPluginManager getPluginManager() {
return new BukkitMCPluginManager(s.getPluginManager());
}
@Override
@SuppressWarnings("deprecation")
public MCPlayer getPlayerExact(String name) {
Player p = s.getPlayerExact(name);
if(p == null) {
return null;
}
return new BukkitMCPlayer(p);
}
@Override
@SuppressWarnings("deprecation")
public MCPlayer getPlayer(String name) {
@@ -2,8 +2,10 @@
import com.laytonsmith.abstraction.MCScoreboard;
import com.laytonsmith.abstraction.MCTeam;
import com.laytonsmith.abstraction.enums.MCChatColor;
import com.laytonsmith.abstraction.enums.MCOption;
import com.laytonsmith.abstraction.enums.MCOptionStatus;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCChatColor;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCOption;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCOptionStatus;
import org.bukkit.scoreboard.Team;
@@ -78,6 +80,11 @@ public String getSuffix() {
return t.getSuffix();
}
@Override
public MCChatColor getColor() {
return BukkitMCChatColor.getConvertor().getAbstractedEnum(t.getColor());
}
@Override
public boolean hasEntry(String entry) {
return t.hasEntry(entry);
@@ -118,6 +125,11 @@ public void setSuffix(String suffix) {
t.setSuffix(suffix);
}
@Override
public void setColor(MCChatColor color) {
t.setColor(BukkitMCChatColor.getConvertor().getConcreteEnum(color));
}
@Override
public void unregister() {
t.unregister();
@@ -105,12 +105,12 @@ public int getMaxFireTicks() {
}
@Override
public MCEntity getPassenger() {
List<Entity> passengers = e.getPassengers();
if(passengers.isEmpty()) {
return null;
public List<MCEntity> getPassengers() {
List<MCEntity> passengers = new ArrayList<>();
for(Entity passenger : e.getPassengers()) {
passengers.add(BukkitConvertor.BukkitGetCorrectEntity(passenger));
}
return BukkitConvertor.BukkitGetCorrectEntity(passengers.get(0));
return passengers;
}
@Override
@@ -225,7 +225,7 @@ public MCLocation location(Construct c, MCWorld w, Target t) {
* @return An item array or CNull
*/
public Construct item(MCItemStack is, Target t) {
if(is.isEmpty()) {
if(is == null || is.isEmpty()) {
return CNull.NULL;
}
@@ -45,6 +45,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
@@ -465,9 +466,9 @@ public boolean matches(Map<String, Construct> prefilter, BindableEvent e) throws
}
Prefilters.match(prefilter, "vehicletype", event.getVehicle().getType().name(), PrefilterType.MACRO);
MCEntity passenger = event.getVehicle().getPassenger();
if(passenger != null) {
Prefilters.match(prefilter, "passengertype", passenger.getType().name(), PrefilterType.MACRO);
List<MCEntity> passengers = event.getVehicle().getPassengers();
if(!passengers.isEmpty()) {
Prefilters.match(prefilter, "passengertype", passengers.get(0).getType().name(), PrefilterType.MACRO);
}
return true;
@@ -500,21 +501,21 @@ public BindableEvent convert(CArray manualObject, Target t) {
ret.put("vehicletype", new CString(e.getVehicle().getType().name(), t));
ret.put("id", new CString(e.getVehicle().getUniqueId().toString(), t));
MCEntity passenger = e.getVehicle().getPassenger();
List<MCEntity> passengers = e.getVehicle().getPassengers();
if(passenger == null) {
if(passengers.isEmpty()) {
ret.put("passenger", CNull.NULL);
ret.put("passengertype", CNull.NULL);
ret.put("player", CNull.NULL);
} else {
MCEntityType<?> passengertype = e.getVehicle().getPassenger().getType();
MCEntity passenger = passengers.get(0);
MCEntityType<?> passengertype = passenger.getType();
ret.put("passengertype", new CString(passengertype.name(), t));
ret.put("passenger", new CString(passenger.getUniqueId().toString(), t));
if(passengertype.getAbstracted() == MCEntityType.MCVanillaEntityType.PLAYER) {
ret.put("player", new CString(((MCPlayer) e.getVehicle().getPassenger()).getName(), t));
ret.put("player", new CString(((MCPlayer) passenger).getName(), t));
} else {
ret.put("player", CNull.NULL);
}
@@ -1180,6 +1180,7 @@ public Construct exec(Target t, Environment env, Construct... args) throws Confi
}
@api
@seealso({array_intersect.class})
public static class array_merge extends AbstractFunction implements Optimizable {
@Override
@@ -3023,6 +3024,7 @@ public Version since() {
}
@api
@seealso({array_merge.class})
public static class array_intersect extends AbstractFunction {
@MEnum("ArrayIntersectComparisonMode")
@@ -3160,7 +3162,8 @@ public String docs() {
+ " be different, and so in that case using STRICT_EQUALS has a lower performance for no gain,"
+ " but there may be some cases where using"
+ " the hash code is not desirable. EQUALS is necessary if you wish to disregard typing, so that"
+ " array(1, 2, 3) and array('1', '2', '3') are considered equal.";
+ " array(1, 2, 3) and array('1', '2', '3') are considered equal. Duplicate values in the left"
+ " array are duplicated, but duplicates in the right are not.";
}
@Override
@@ -3195,7 +3198,13 @@ public Version since() {
+ "\tarray(array(id: 1, pos: 'right')),\n"
+ "\tclosure(@a, @b) {\n"
+ "\t\treturn(@a['id'] == @b['id']);\n"
+ "})")
+ "})"),
new ExampleScript("Demonstrates behavior with duplicate values", "msg(array_intersect(\n"
+ "\tarray(1, 1, 1, 2, 3),\n"
+ "\tarray(1, 2)));\n"
+ "msg(array_intersect(\n"
+ "\tarray(1, 2, 3),\n"
+ "\tarray(1, 1, 1)));")
};
}
@@ -1267,7 +1267,7 @@ public Construct exec(Target t, Environment environment, Construct... args) thro
} else {
rider = Static.getEntity(args[1], t);
}
if((horse == null && rider == null) || horse == rider) {
if((horse == null && rider == null) || args[0].val().equals(args[1].val())) {
throw new CREFormatException("Horse and rider cannot be the same entity", t);
} else if(horse == null) {
success = rider.leaveVehicle();
@@ -1295,7 +1295,8 @@ public String docs() {
+ " If rider is null, horse will eject its current rider, if it has one. If horse is null,"
+ " rider will leave whatever it is riding. If horse and rider are both valid entities,"
+ " rider will ride horse. The function returns the success of whatever operation is done."
+ " If horse and rider are both null, or otherwise the same, a FormatException is thrown.";
+ " If horse and rider are both null, or otherwise the same, a FormatException is thrown."
+ " If a horse already has a rider, this will add the new rider without ejecting the existing one.";
}
@Override
@@ -1310,8 +1311,9 @@ public CHVersion since() {
@Override
public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException {
MCEntity ent = Static.getEntity(args[0], t);
if(ent.getPassenger() != null) {
return new CString(ent.getPassenger().getUniqueId().toString(), t);
List<MCEntity> passengers = ent.getPassengers();
if(!passengers.isEmpty()) {
return new CString(passengers.get(0).getUniqueId().toString(), t);
}
return CNull.NULL;
}
@@ -1323,7 +1325,8 @@ public String getName() {
@Override
public String docs() {
return "string {entityUUID} Returns the UUID of the given entity's rider, or null if it doesn't have one.";
return "string {entityUUID} Returns the UUID of the given entity's rider, or null if it doesn't have one."
+ " If there are multiple riders, only the first is returned.";
}
@Override
@@ -1332,6 +1335,36 @@ public CHVersion since() {
}
}
@api
public static class get_entity_riders extends EntityGetterFunction {
@Override
public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException {
MCEntity ent = Static.getEntity(args[0], t);
List<MCEntity> riders = ent.getPassengers();
CArray ret = new CArray(t);
for(MCEntity rider : riders) {
ret.push(new CString(rider.getUniqueId().toString(), t), t);
}
return ret;
}
@Override
public String getName() {
return "get_entity_riders";
}
@Override
public String docs() {
return "array {entityUUID} Returns an array of UUIDs for the given entity's riders.";
}
@Override
public CHVersion since() {
return CHVersion.V3_3_3;
}
}
@api
public static class get_entity_vehicle extends EntityGetterFunction {
@@ -2558,25 +2558,17 @@ public Boolean runAsync() {
@Override
public Construct exec(Target t, Environment env, Construct... args) throws ConfigRuntimeException {
//We have to use this method here, because we might be in the midst
//of an event, in which the player is offline, but not really. It will
//throw an exception if the player doesn't exist
MCPlayer p = null;
try {
p = Static.GetPlayer(args[0], t);
//Static.GetPlayer() autocompletes names, which we don't want in this function,
//however we have to check if this is an injected player first.
MCPlayer p = Static.GetPlayer(args[0], t);
//Now we must check if the name was exact. Skip this if the argument is a UUID.
if(args[0].val().length() <= 16 && !p.getName().equalsIgnoreCase(args[0].val())) {
p = Static.getServer().getPlayerExact(args[0].val());
}
return CBoolean.get(p != null);
} catch (ConfigRuntimeException e) {
//They aren't in the player list
}
//If the player we grabbed doesn't match exactly, we're referring to another player
//However, we had to check with Static.GetPlayer first, in case this is an injected player.
//Otherwise, we need to use the player returned from Static.GetPlayer, not the one returned
//from the server directly
if(p != null && !p.getName().equals(args[0].val())) {
MCOfflinePlayer player = Static.getServer().getOfflinePlayer(args[0].val());
return CBoolean.get(player.isOnline());
} else if(p != null) {
return CBoolean.get(p.isOnline());
} else {
return CBoolean.FALSE;
}
}
Oops, something went wrong.

0 comments on commit 8f7d354

Please sign in to comment.