Skip to content

Commit

Permalink
Merge branch 'master' of github.com:EngineHub/commandhelper
Browse files Browse the repository at this point in the history
  • Loading branch information
LadyCailin committed Nov 6, 2018
2 parents d68b63d + 60036af commit 8f7d354
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/laytonsmith/abstraction/MCEntity.java
Expand Up @@ -25,7 +25,7 @@ public interface MCEntity extends MCMetadatable {

List<MCEntity> getNearbyEntities(double x, double y, double z);

MCEntity getPassenger();
List<MCEntity> getPassengers();

MCServer getServer();

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/laytonsmith/abstraction/MCServer.java
Expand Up @@ -22,6 +22,8 @@ public interface MCServer extends AbstractionObject {

MCPluginManager getPluginManager();

MCPlayer getPlayerExact(String name);

MCPlayer getPlayer(String name);

MCPlayer getPlayer(UUID uuid);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/laytonsmith/abstraction/MCTeam.java
@@ -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;

Expand Down Expand Up @@ -29,6 +30,8 @@ public interface MCTeam {

String getSuffix();

MCChatColor getColor();

boolean hasEntry(String entry);

boolean removeEntry(String entry);
Expand All @@ -45,5 +48,7 @@ public interface MCTeam {

void setSuffix(String suffix);

void setColor(MCChatColor color);

void unregister();
}
Expand Up @@ -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
Expand Down
Expand Up @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCTeam.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
Expand Up @@ -105,12 +105,12 @@ public List<MCEntity> getNearbyEntities(double x, double y, double z) {
}

@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
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/laytonsmith/core/ObjectGenerator.java
Expand Up @@ -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;
}

Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -500,21 +501,21 @@ public Map<String, Construct> evaluate(BindableEvent event) throws EventExceptio
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);
}
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/com/laytonsmith/core/functions/ArrayHandling.java
Expand Up @@ -1180,6 +1180,7 @@ public Set<OptimizationOption> optimizationOptions() {
}

@api
@seealso({array_intersect.class})
public static class array_merge extends AbstractFunction implements Optimizable {

@Override
Expand Down Expand Up @@ -3023,6 +3024,7 @@ public ExampleScript[] examples() throws ConfigCompileException {
}

@api
@seealso({array_merge.class})
public static class array_intersect extends AbstractFunction {

@MEnum("ArrayIntersectComparisonMode")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -3195,7 +3198,13 @@ public ExampleScript[] examples() throws ConfigCompileException {
+ "\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)));")
};
}

Expand Down
43 changes: 38 additions & 5 deletions src/main/java/com/laytonsmith/core/functions/EntityManagement.java
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -1310,8 +1311,9 @@ public static class get_entity_rider extends EntityGetterFunction {
@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;
}
Expand All @@ -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
Expand All @@ -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 {

Expand Down
24 changes: 8 additions & 16 deletions src/main/java/com/laytonsmith/core/functions/PlayerManagement.java
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 8f7d354

Please sign in to comment.