<commit_before>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.laytonsmith.aliasengine.functions;

import com.laytonsmith.aliasengine.Constructs.CArray;
import com.laytonsmith.aliasengine.Constructs.CInt;
import com.laytonsmith.aliasengine.Constructs.CString;
import com.laytonsmith.aliasengine.Constructs.CVoid;
import com.laytonsmith.aliasengine.functions.exceptions.CancelCommandException;
import com.laytonsmith.aliasengine.functions.exceptions.ConfigRuntimeException;
import com.laytonsmith.aliasengine.Constructs.Construct;
import com.laytonsmith.aliasengine.Static;
import com.laytonsmith.aliasengine.functions.Exceptions.ExceptionType;
import java.io.File;

import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
import com.sk89q.worldedit.bukkit.selections.Selection;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

/**
 *
 * @author Layton
 */
public class WorldEdit_ {

    public static String docs() {
        return "Provides various methods for programmatically hooking into WorldEdit";
    }

    @api public static class sk_pos1 extends SKFunction {

        public String getName() {
            return "sk_pos1";
        }

        public Integer[] numArgs() {
            return new Integer[]{0, 1, 2};
        }

        public ExceptionType[] thrown() {
            return new ExceptionType[]{ExceptionType.PlayerOfflineException, ExceptionType.CastException};
        }

        public String docs() {
            return "mixed {[player], locationArray | [player]} Sets the player's point 1, or returns it if the array to set isn't specified. If"
                    + " the location is returned, it is returned as a 4 index array:(x, y, z, world)";
        }

        public Construct exec(int line_num, File f, CommandSender p, Construct... args) throws CancelCommandException, ConfigRuntimeException {
            Player m = null;
            Location l = null;
            boolean setter = false;
            Static.checkPlugin("WorldEdit", line_num, f);
            
            if(p instanceof Player){
                m = (Player)p;
            }
            if(args.length == 2){
                m = Static.GetPlayer(args[0].val(), line_num, f);
                l = Static.GetLocation(args[1], m.getWorld(), line_num, f);
                setter = true;
            } else if(args.length == 1){
                if(args[0] instanceof CArray){
                    l = Static.GetLocation(args[0], (m==null?null:m.getWorld()), line_num, f);
                    setter = true;
                } else {
                    m = Static.GetPlayer(args[0].val(), line_num, f);
                }
            }

            if (m == null) {
                throw new ConfigRuntimeException(this.getName() + " needs a player", ExceptionType.PlayerOfflineException, line_num, f);
            }

            if(setter){
                Region sel = Static.getWorldEditPlugin().getSession(m).getRegionSelector(BukkitUtil.getLocalWorld(l.getWorld())).getIncompleteRegion();
                if (!(sel instanceof CuboidRegion)) {
                    throw new ConfigRuntimeException("Only cuboid regions are supported with " + this.getName(), ExceptionType.PluginInternalException, line_num, f);
                }
                ((CuboidRegion) sel).setPos1(BukkitUtil.toVector(l));
                return new CVoid(line_num, f);
            } else {
                Region sel = Static.getWorldEditPlugin().getSession(m).getRegionSelector(BukkitUtil.getLocalWorld(m.getWorld())).getIncompleteRegion();
                if (!(sel instanceof CuboidRegion)) {
                    throw new ConfigRuntimeException("Only cuboid regions are supported with " + this.getName(), ExceptionType.PluginInternalException, line_num, f);
                }
                Vector pt = ((CuboidRegion) sel).getPos1();
                if (pt == null) throw new ConfigRuntimeException("Point in " + this.getName() +  "undefined", line_num, f);
                return new CArray(line_num, f,
                        new CInt(pt.getBlockX(), line_num, f),
                        new CInt(pt.getBlockY(), line_num, f),
                        new CInt(pt.getBlockZ(), line_num, f),
                        new CString(m.getWorld().getName(), line_num, f));
            }
        }
    }

    @api public static class sk_pos2 extends SKFunction {

        public String getName() {
            return "sk_pos2";
        }

        public Integer[] numArgs() {
            return new Integer[]{0, 1, 2};
        }

        public String docs() {
            return "mixed {[player], array | [player]} Sets the player's point 2, or returns it if the array to set isn't specified";
        }

        public ExceptionType[] thrown() {
            return new ExceptionType[]{ExceptionType.PlayerOfflineException, ExceptionType.CastException};
        }

        public Construct exec(int line_num, File f, CommandSender p, Construct... args) throws CancelCommandException, ConfigRuntimeException {
            Player m = null;
            Location l = null;
            boolean setter = false;
            Static.checkPlugin("WorldEdit", line_num, f);

            if (p instanceof Player) {
                m = (Player)p;
            }
            if (args.length == 2){
                m = Static.GetPlayer(args[0].val(), line_num, f);
                l = Static.GetLocation(args[1], m.getWorld(), line_num, f);
                setter = true;
            } else if (args.length == 1){
                if (args[0] instanceof CArray) {
                    l = Static.GetLocation(args[0], (m==null?null:m.getWorld()), line_num, f);
                    setter = true;
                } else {
                    m = Static.GetPlayer(args[0].val(), line_num, f);
                }
            }

            if (m == null) {
                throw new ConfigRuntimeException(this.getName() + " needs a player", ExceptionType.PlayerOfflineException, line_num, f);
            }

            if(setter){
                Region sel = Static.getWorldEditPlugin().getSession(m).getRegionSelector(BukkitUtil.getLocalWorld(l.getWorld())).getIncompleteRegion();
                if (!(sel instanceof CuboidRegion)) {
                    throw new ConfigRuntimeException("Only cuboid regions are supported with " + this.getName(), ExceptionType.PluginInternalException, line_num, f);
                }
                ((CuboidRegion) sel).setPos2(BukkitUtil.toVector(l));
                return new CVoid(line_num, f);
            } else {
                Region sel = Static.getWorldEditPlugin().getSession(m).getRegionSelector(BukkitUtil.getLocalWorld(m.getWorld())).getIncompleteRegion();
                if (!(sel instanceof CuboidSelection)) {
                    throw new ConfigRuntimeException("Only cuboid regions are supported with " + this.getName(), ExceptionType.PluginInternalException, line_num, f);
                }
                Vector pt = ((CuboidRegion)sel).getPos2();
                if (pt == null) throw new ConfigRuntimeException("Point in " + this.getName() +  "undefined", line_num, f);
                return new CArray(line_num, f,
                        new CInt(pt.getBlockX(), line_num, f),
                        new CInt(pt.getBlockY(), line_num, f),
                        new CInt(pt.getBlockZ(), line_num, f),
                        new CString(m.getWorld().getName(), line_num, f));
            }
        }
    }

    public static class sk_points extends SKFunction {

        public String getName() {
            return "sk_points";<commit_msg>Probably fixed WE functions for real this time<commit_after>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.laytonsmith.aliasengine.functions;

import com.laytonsmith.aliasengine.Constructs.CArray;
import com.laytonsmith.aliasengine.Constructs.CInt;
import com.laytonsmith.aliasengine.Constructs.CString;
import com.laytonsmith.aliasengine.Constructs.CVoid;
import com.laytonsmith.aliasengine.functions.exceptions.CancelCommandException;
import com.laytonsmith.aliasengine.functions.exceptions.ConfigRuntimeException;
import com.laytonsmith.aliasengine.Constructs.Construct;
import com.laytonsmith.aliasengine.Static;
import com.laytonsmith.aliasengine.functions.Exceptions.ExceptionType;
import java.io.File;

import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.CuboidRegionSelector;
import com.sk89q.worldedit.regions.RegionSelector;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

/**
 *
 * @author Layton
 */
public class WorldEdit_ {

    public static String docs() {
        return "Provides various methods for programmatically hooking into WorldEdit";
    }

    @api public static class sk_pos1 extends SKFunction {

        public String getName() {
            return "sk_pos1";
        }

        public Integer[] numArgs() {
            return new Integer[]{0, 1, 2};
        }

        public ExceptionType[] thrown() {
            return new ExceptionType[]{ExceptionType.PlayerOfflineException, ExceptionType.CastException};
        }

        public String docs() {
            return "mixed {[player], locationArray | [player]} Sets the player's point 1, or returns it if the array to set isn't specified. If"
                    + " the location is returned, it is returned as a 4 index array:(x, y, z, world)";
        }

        public Construct exec(int line_num, File f, CommandSender p, Construct... args) throws CancelCommandException, ConfigRuntimeException {
            Player m = null;
            Location l = null;
            boolean setter = false;
            Static.checkPlugin("WorldEdit", line_num, f);
            
            if(p instanceof Player){
                m = (Player)p;
            }
            if(args.length == 2){
                m = Static.GetPlayer(args[0].val(), line_num, f);
                l = Static.GetLocation(args[1], m.getWorld(), line_num, f);
                setter = true;
            } else if(args.length == 1){
                if(args[0] instanceof CArray){
                    l = Static.GetLocation(args[0], (m==null?null:m.getWorld()), line_num, f);
                    setter = true;
                } else {
                    m = Static.GetPlayer(args[0].val(), line_num, f);
                }
            }

            if (m == null) {
                throw new ConfigRuntimeException(this.getName() + " needs a player", ExceptionType.PlayerOfflineException, line_num, f);
            }

            RegionSelector sel = Static.getWorldEditPlugin().getSession(m).getRegionSelector(BukkitUtil.getLocalWorld(l.getWorld()));
            if (!(sel instanceof CuboidRegionSelector)) {
                throw new ConfigRuntimeException("Only cuboid regions are supported with " + this.getName(), ExceptionType.PluginInternalException, line_num, f);
            }
            if(setter){
                sel.selectPrimary(BukkitUtil.toVector(l));
                return new CVoid(line_num, f);
            } else {
                Vector pt = ((CuboidRegion) sel.getIncompleteRegion()).getPos1();
                if (pt == null) throw new ConfigRuntimeException("Point in " + this.getName() +  "undefined", line_num, f);
                return new CArray(line_num, f,
                        new CInt(pt.getBlockX(), line_num, f),
                        new CInt(pt.getBlockY(), line_num, f),
                        new CInt(pt.getBlockZ(), line_num, f),
                        new CString(m.getWorld().getName(), line_num, f));
            }
        }
    }

    @api public static class sk_pos2 extends SKFunction {

        public String getName() {
            return "sk_pos2";
        }

        public Integer[] numArgs() {
            return new Integer[]{0, 1, 2};
        }

        public String docs() {
            return "mixed {[player], array | [player]} Sets the player's point 2, or returns it if the array to set isn't specified";
        }

        public ExceptionType[] thrown() {
            return new ExceptionType[]{ExceptionType.PlayerOfflineException, ExceptionType.CastException};
        }

        public Construct exec(int line_num, File f, CommandSender p, Construct... args) throws CancelCommandException, ConfigRuntimeException {
            Player m = null;
            Location l = null;
            boolean setter = false;
            Static.checkPlugin("WorldEdit", line_num, f);

            if (p instanceof Player) {
                m = (Player)p;
            }
            if (args.length == 2){
                m = Static.GetPlayer(args[0].val(), line_num, f);
                l = Static.GetLocation(args[1], m.getWorld(), line_num, f);
                setter = true;
            } else if (args.length == 1){
                if (args[0] instanceof CArray) {
                    l = Static.GetLocation(args[0], (m==null?null:m.getWorld()), line_num, f);
                    setter = true;
                } else {
                    m = Static.GetPlayer(args[0].val(), line_num, f);
                }
            }

            if (m == null) {
                throw new ConfigRuntimeException(this.getName() + " needs a player", ExceptionType.PlayerOfflineException, line_num, f);
            }

            RegionSelector sel = Static.getWorldEditPlugin().getSession(m).getRegionSelector(BukkitUtil.getLocalWorld(l.getWorld()));
            if (!(sel instanceof CuboidRegionSelector)) {
                throw new ConfigRuntimeException("Only cuboid regions are supported with " + this.getName(), ExceptionType.PluginInternalException, line_num, f);
            }

            if(setter){
                sel.selectSecondary(BukkitUtil.toVector(l));
                return new CVoid(line_num, f);
            } else {
                Vector pt = ((CuboidRegion)sel.getIncompleteRegion()).getPos2();
                if (pt == null) throw new ConfigRuntimeException("Point in " + this.getName() +  "undefined", line_num, f);
                return new CArray(line_num, f,
                        new CInt(pt.getBlockX(), line_num, f),
                        new CInt(pt.getBlockY(), line_num, f),
                        new CInt(pt.getBlockZ(), line_num, f),
                        new CString(m.getWorld().getName(), line_num, f));
            }
        }
    }

    public static class sk_points extends SKFunction {

        public String getName() {
            return "sk_points";
{'fraction_non_alphanumeric': 0.1081026875250702, 'fraction_numerical': 0.005615724027276374, 'mean_word_length': 2.1151603498542273, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5936772', 'n_tokens_mistral': 4181, 'n_tokens_neox': 3920, 'n_words': 988}