Permalink
Browse files

Merge branch 'master' into new-html-docs

  • Loading branch information...
LadyCailin committed Aug 9, 2017
2 parents 6c1a815 + 3f68bfb commit ca3719967e2542f225cf3cb70184b371429a861c
View
@@ -176,7 +176,7 @@
<!-- GPL -->
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12-R0.1-SNAPSHOT</version>
<version>1.12.1-R0.1-SNAPSHOT</version>
</dependency>
<!-- Used for storing and retreiving Constructs in a storage transparent medium: JSONs -->
@@ -39,9 +39,8 @@
public double getLastDamage();
public MCEntity getLeashHolder();
public MCLivingEntity getTarget(Target t);
public MCBlock getTargetBlock(HashSet<Short> transparent, int maxDistance, boolean castToByte);
public MCBlock getTargetBlock(HashSet<Byte> transparent, int maxDistance);
public List<MCBlock> getLastTwoTargetBlocks(HashSet<Byte> transparent, int maxDistance);
public MCBlock getTargetBlock(HashSet<Short> transparent, int maxDistance);
public MCBlock getTargetSpace(int maxDistance);
public List<MCBlock> getLineOfSight(HashSet<Short> transparent, int maxDistance);
public boolean hasLineOfSight(MCEntity other);
public double getMaxHealth();
@@ -105,16 +105,9 @@ public double getLastDamage() {
}
@Override
public List<MCBlock> getLastTwoTargetBlocks(HashSet<Byte> transparent,
int maxDistance) {
List<Block> lst = le.getLastTwoTargetBlocks(transparent, maxDistance);
List<MCBlock> retn = new ArrayList<MCBlock>();
for (Block b : lst) {
retn.add(new BukkitMCBlock(b));
}
return retn;
public MCBlock getTargetSpace(int maxDistance) {
List<Block> lst = getLineOfSight(null, maxDistance, 2);
return new BukkitMCBlock(lst.get(0));
}
@Override
@@ -155,22 +148,7 @@ public int getRemainingAir() {
}
@Override
public MCBlock getTargetBlock(HashSet<Byte> b, int i) {
return new BukkitMCBlock(le.getTargetBlock(b, i));
}
@Override
public MCBlock getTargetBlock(HashSet<Short> b, int i, boolean castToByte) {
if (castToByte) {
if (b == null) {
return getTargetBlock(null, i);
}
HashSet<Byte> bb = new HashSet<Byte>();
for (int id : b) {
bb.add((byte) id);
}
return getTargetBlock(bb, i);
}
public MCBlock getTargetBlock(HashSet<Short> b, int i) {
return new BukkitMCBlock(getFirstTargetBlock(b, i));
}
@@ -352,7 +352,13 @@ public MCItemStack item(Construct i, Target t) {
}
MCEnchantment etype = StaticLayer.GetEnchantmentByName(setype);
if(etype == null){
throw new CREFormatException("Invalid enchantment array etype: \"" + setype + "\".", t);
if(setype.equals("SWEEPING")) {
// data from 1.11.2, changed in 1.12
etype = StaticLayer.GetEnchantmentByName("SWEEPING_EDGE");
}
if(etype == null){
throw new CREFormatException("Invalid enchantment array etype: \"" + setype + "\".", t);
}
}
enchants.put(etype, elevel);
} catch (ClassCastException e) {
@@ -1019,10 +1025,17 @@ public CArray enchants(Map<MCEnchantment, Integer> map, Target t) {
for (String key : enchantArray.stringKeySet()) {
try {
CArray ea = (CArray) enchantArray.get(key, t);
MCEnchantment etype = StaticLayer.GetConvertor().GetEnchantmentByName(ea.get("etype", t).val());
String setype = ea.get("etype", t).val();
MCEnchantment etype = StaticLayer.GetConvertor().GetEnchantmentByName(setype);
int elevel = Static.getInt32(ea.get("elevel", t), t);
if (etype == null) {
throw new CREEnchantmentException("Unknown enchantment type at " + key, t);
if(setype.equals("SWEEPING")) {
// data from 1.11.2, changed in 1.12
etype = StaticLayer.GetEnchantmentByName("SWEEPING_EDGE");
}
if(etype == null) {
throw new CREEnchantmentException("Unknown enchantment type at " + key, t);
}
}
ret.put(etype, elevel);
} catch (ClassCastException cce) {
@@ -4,6 +4,7 @@
import com.laytonsmith.PureUtilities.Common.StackTraceUtils;
import com.laytonsmith.PureUtilities.Common.StreamUtils;
import com.laytonsmith.PureUtilities.TermColors;
import com.laytonsmith.abstraction.MCCommandSender;
import com.laytonsmith.abstraction.MCPlayer;
import com.laytonsmith.abstraction.enums.MCChatColor;
import com.laytonsmith.core.CHLog;
@@ -100,6 +101,10 @@ public static Reaction GetReaction(ConfigRuntimeException e, Environment env) {
if (env.getEnv(GlobalEnv.class).GetExceptionHandler() != null) {
CClosure c = env.getEnv(GlobalEnv.class).GetExceptionHandler();
CArray ex = ObjectGenerator.GetGenerator().exception(e, env, Target.UNKNOWN);
if (e.getEnv() != null) {
MCCommandSender sender = e.getEnv().getEnv(CommandHelperEnvironment.class).GetCommandSender();
c.getEnv().getEnv(CommandHelperEnvironment.class).SetCommandSender(sender);
}
Construct ret = CNull.NULL;
try {
c.execute(new Construct[]{ex});
@@ -0,0 +1,156 @@
package com.laytonsmith.core.functions;
import com.laytonsmith.PureUtilities.Version;
import com.laytonsmith.annotations.api;
import com.laytonsmith.annotations.noboilerplate;
import com.laytonsmith.core.CHVersion;
import com.laytonsmith.core.constructs.CString;
import com.laytonsmith.core.constructs.CVoid;
import com.laytonsmith.core.constructs.Construct;
import com.laytonsmith.core.constructs.Target;
import com.laytonsmith.core.environments.Environment;
import com.laytonsmith.core.exceptions.CRE.CREFormatException;
import com.laytonsmith.core.exceptions.CRE.CREIOException;
import com.laytonsmith.core.exceptions.CRE.CREInsufficientPermissionException;
import com.laytonsmith.core.exceptions.CRE.CREThrowable;
import com.laytonsmith.core.exceptions.ConfigRuntimeException;
import java.awt.HeadlessException;
import java.awt.Toolkit;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
/**
*
* @author cailin
*/
public class Clipboard {
public static String docs() {
return "Provides functions for managing the system clipboard";
}
@SuppressWarnings("FieldMayBeFinal") // No it can't, shut up ide
private static java.awt.datatransfer.Clipboard clipboard;
static {
try {
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
} catch (HeadlessException ex) {
clipboard = null;
}
}
@api
@noboilerplate
public static class get_clipboard extends AbstractFunction {
@Override
public Class<? extends CREThrowable>[] thrown() {
return new Class[]{CREFormatException.class, CREInsufficientPermissionException.class};
}
@Override
public boolean isRestricted() {
return true;
}
@Override
public Boolean runAsync() {
return null;
}
@Override
public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException {
Cmdline.requireCmdlineMode(environment, this, t);
Transferable tr = clipboard.getContents(null);
if (tr.isDataFlavorSupported(DataFlavor.stringFlavor)) {
try {
String data = (String) tr.getTransferData(DataFlavor.stringFlavor);
return new CString(data, t);
} catch (UnsupportedFlavorException ex) {
// Can't happen
throw new RuntimeException(ex);
} catch (IOException ex) {
throw new CREIOException(ex.getMessage(), t, ex);
}
} else {
throw new CREFormatException("Clipboard value does not support parsing as text", t);
}
}
@Override
public String getName() {
return "get_clipboard";
}
@Override
public Integer[] numArgs() {
return new Integer[]{0, 1};
}
@Override
public String docs() {
return "string {[flavor]} Returns the contents of the system clipboard. Can only be used in cmdline mode. Flavor defaults to null, and is currently unused. Only strings are currently supported."
+ " If a string version of the clipboard contents cannot be parsed, a FormatException is thrown.";
}
@Override
public Version since() {
return CHVersion.V3_3_2;
}
}
@api
@noboilerplate
public static class set_clipboard extends AbstractFunction {
@Override
public Class<? extends CREThrowable>[] thrown() {
return new Class[]{CREInsufficientPermissionException.class};
}
@Override
public boolean isRestricted() {
return true;
}
@Override
public Boolean runAsync() {
return null;
}
@Override
public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException {
Cmdline.requireCmdlineMode(environment, this, t);
String data = args[0].val();
StringSelection s = new StringSelection(data);
clipboard.setContents(s, s);
return CVoid.VOID;
}
@Override
public String getName() {
return "set_clipboard";
}
@Override
public Integer[] numArgs() {
return new Integer[]{1, 2};
}
@Override
public String docs() {
return "void {value, [flavor]} Sets the contents of the system clipboard, to the given value. Can only be used in cmdline mode. Flavor defaults to null, and is currently unused. Only strings are currently supported.";
}
@Override
public Version since() {
return CHVersion.V3_3_2;
}
}
}
@@ -597,7 +597,7 @@ public Construct exec(Target t, Environment env, Construct... args) throws Cance
Static.AssertPlayerNonNull(p, t);
MCBlock b;
try {
b = p.getTargetBlock(trans, 10000, false);
b = p.getTargetBlock(trans, 512);
} catch (IllegalStateException ise) {
throw new CREPluginInternalException("The server's method of finding the target block has failed."
+ " There is nothing that can be done about this except standing somewhere else.", t);
@@ -633,7 +633,7 @@ public Boolean runAsync() {
@Override
public Class<? extends CREThrowable>[] thrown() {
return new Class[]{CREPlayerOfflineException.class};
return new Class[]{CREPlayerOfflineException.class, CRERangeException.class};
}
@Override
@@ -653,7 +653,11 @@ public Construct exec(Target t, Environment environment, Construct... args) thro
p = Static.GetPlayer(args[0], t);
}
Static.AssertPlayerNonNull(p, t);
return ObjectGenerator.GetGenerator().location(p.getLastTwoTargetBlocks(null, 10000).get(0).getLocation(), false);
MCBlock b = p.getTargetSpace(512);
if(b == null) {
throw new CRERangeException("No block in sight, or block too far", t);
}
return ObjectGenerator.GetGenerator().location(b.getLocation(), false);
}
@Override
Oops, something went wrong.

0 comments on commit ca37199

Please sign in to comment.