Custom HCF CORE (3/3 Vouch copies left)

Status
This thread has been locked.

CryptonicMC

Banned
Feedback score
4
Posts
90
Reactions
63
Resources
0
Hello, so for the past month i've been working on creating a HCF Core. I understand that i have no rep. But i'd like to start getting repution around on MCM. So to start off i'm giving away 3 vouch copies of the core then i'm going to start selling the core after the vouch copies are gone. So pm me if your interested!
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Albert14

Feedback score
-1
Posts
183
Reactions
14
Resources
0
I'm interested
 

madk0ur

Music Producer
Premium
Feedback score
2
Posts
142
Reactions
26
Resources
0
Hello, so for the past month i've been working on creating a HCF Core. I understand that i have no rep. But i'd like to start getting repution around on MCM. So to start off i'm giving away 3 vouch copies of the core then i'm going to start selling the core after the vouch copies are gone. So pm me if your interested!
Useless post.. If you're interested send him a PM.
I'm interested
._.[DOUBLEPOST=1507908415][/DOUBLEPOST]Is the Core already finished ? Or you’re gona start ;-;
 
Last edited:

zt

Alfie
Supreme
Feedback score
14
Posts
536
Reactions
172
Resources
0
Hey. I may be interested do you have a test server?
 

Ambrosia

Premium
Feedback score
22
Posts
2,340
Reactions
1,384
Resources
0
Just looking for it for free

no rep, make sure to give it to reputable devs like Mat Eric Sniper
There are way more developers that are competent than that, and I wouldn't give a vouch copy to a developer that doesn't have experience in HCF (like Mat), honestly I would say Eric or subbotted are semi-reputable and that's the person to give it to, because they are both competent and can help you out a lot.
 

subbotted

Contact on Discord, subbotted#5560
Supreme
Feedback score
17
Posts
524
Reactions
407
Resources
0
I've made 10s of cores for clients from scratch since the start of 2015 / late 2014, prior to when HCF was even at the level of popularity it is now, I just am not up to date with all the latest leaks because the community is a shithole, hence why I will not be bothering to review the code, only did it a couple of times for some people who weere very serious about their hard work, I love a good HCF core made from scratch.

On the topic of code review, I feel like I've slowly watched subbotted progress into a better developer from when he first joined, and at the start of his time here at MCM I was giving him a fairly hard time as he was essentially clueless, but has definitely improved over time, I can't comment on his ability now however, but I am 100% sure that his core is not his 100% work from scratch though, not many people on this site have the mathmatical ability to efficiently create grids etc over the map to effectively manage territory, not to mention the effective scoreboard handling, HCF cores are a lot of work. If I have wrongly called you out subbotted then feel free to give snippets of code for your scoreboard and your factions system (and don't tell me you used that bloody cuboid library, it's basic maths and just some dimention checks)

Eric is probably the most qualified, he's worked with any other forked HCF core out there and can probably give you a good idea as to if it's skidded or not, I can also vouch for his skill in java.

Just thought I'd make a point Ambrosia, no hostility, it's just that I was making HCF cores before the community even blew up, I was making full faction system with all the trimmings etc for $200 back in the day, now it's going to set you back minimum £1,500 from me, usually around £2k -£5k depending on features.

Plus the community is the worst I have ever experienced, there is one user I will do HCF work for and that is it, good luck with your thing OP, but I'm not reviewing it.

Code snippets from what? Neon? Its not even released yet lol.

But anyway, heres a few classes from my latest version:

FactionManager
Code:
package com.roguehcf.faction;

import java.util.HashMap;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection;

import com.roguehcf.Neon;
import com.roguehcf.configuration.Config;
import com.roguehcf.faction.struct.Role;
import com.roguehcf.faction.type.ClaimableFaction;
import com.roguehcf.faction.type.Faction;
import com.roguehcf.faction.type.FactionType;
import com.roguehcf.faction.type.PlayerFaction;
import com.roguehcf.faction.type.SystemFaction;
import com.roguehcf.profile.Profile;

import lombok.Getter;
public class FactionManager {

    @Getter private HashMap<String, Faction> factions = new HashMap<>();
    @Getter private Faction warzone, wilderness;
    @Getter private Config config;
 
    public FactionManager() {
        config = new Config(Neon.getInstance(), "factions");
     
        ConfigurationSection section = getConfig().getConfigurationSection("faction");
     
        if(section != null) {
            for(String faction : section.getKeys(false)) {
                FactionType type = FactionType.valueOf(section.getString(faction + ".type"));
                loadFaction(type, faction);
            }
        }
    }
 
    public void loadFaction(FactionType type, String factionName) {
        switch(type) {
        case PLAYER: {
            PlayerFaction faction = new PlayerFaction(factionName);
            faction.load();
            factions.put(factionName, faction);
            Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&fLoaded faction &a" + faction.getName()));
            break;
        }
        case SYSTEM: {
            SystemFaction faction = new SystemFaction(factionName);
            faction.load();
            factions.put(factionName, faction);
            Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&fLoaded faction &a" + faction.getName()));
            break;
        }
        default: {
            Faction faction = new Faction(factionName);
            faction.load();
            factions.put(factionName, faction);
            Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&fLoaded faction &a" + faction.getName()));
            break;
        }
        }
    }
     
    public Faction getFactionByName(String name) {
        return factions.get(name);
    }
 
    public Faction getFactionByProfile(Profile profile) {
        for(Faction faction : getFactions().values()) {
            if(faction instanceof PlayerFaction) {
                if(((PlayerFaction) faction).getMembers().contains(profile)) {
                    return faction;
                }
            }
        }
        return null;
    }
 
    public Faction getFactionByUserName(String name) {
        for(Faction faction : getFactions().values()) {
            if(faction instanceof PlayerFaction) {
                PlayerFaction playerFaction = (PlayerFaction) faction;
                for(Profile profile : playerFaction.getMembers()) {
                    if(profile.getName().equalsIgnoreCase(name)) {
                        return faction;
                    }
                }
            }
        }
        return null;
    }
 
    public Faction getFactionAtLocation(Location location) {
        for(Faction faction : factions.values()) {
            if(faction instanceof ClaimableFaction) {
                ClaimableFaction fac = (ClaimableFaction) faction;
                if(fac.getClaimAtLocation(location) != null) {
                    return faction;
                }
            }
        }
        return null;
    }
 
    public void saveFactions() {
        for(Faction faction : factions.values()) {
            faction.save();
        }
    }
 
    public void createFaction(String factionName, Profile leader) {
        PlayerFaction playerFaction = new PlayerFaction(factionName);
        playerFaction.addMember(leader);
        leader.setRole(Role.LEADER);
        factions.put(factionName, playerFaction);
        playerFaction.save();
    }
 
}
The scoreboard is Deathstreams first version of ScoreboardWrapper, I'd never take credit for it.

The claims and that are done with the Cuboids API, as you guessed.

Saving of factions
Code:
    @Override
    public void save() {
        getClaims().add(new Claim(new Location(Bukkit.getServer().getWorld("world"), 0, 100, 0), new Location(Bukkit.getServer().getWorld("world"), 0, 100, 0)));
        Neon.getInstance().getFactionManager().getConfig().set("faction." + getName() + ".members", Neon.getInstance().getProfileManager().profilesToUUIDStrings(members));
        Neon.getInstance().getFactionManager().getConfig().set("faction." + getName() + ".invited", Neon.getInstance().getProfileManager().profilesToUUIDStrings(invited));
        Neon.getInstance().getFactionManager().getConfig().set("faction." + getName() + ".dtr", getDtr());
        Neon.getInstance().getFactionManager().getConfig().set("faction." + getName() + ".type", getType().toString());
        Neon.getInstance().getFactionManager().getConfig().set("faction." + getName() + ".open", isOpen());
        Neon.getInstance().getFactionManager().getConfig().set("faction." + getName() + ".regenerationMillis", getRegenerationMillis());
        Neon.getInstance().getFactionManager().getConfig().set("faction." + getName() + ".claims", getClaims());
        Neon.getInstance().getFactionManager().getConfig().save();
        Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "Saved");
    }

The code might not be the most efficient and thats all I'm willing to share publicly right now, but it is all mine apart from the Cuboid/Scoreboard systems and I can prove that. Custom factions is easy as fuck, its just a teams plugin with claims and locations.

Also as you may notice I am saving a predefined claim just as a test for the serialisation, which I got working. I haven't even finished claims yet, I've recoded Neon since the first inefficient version (before I had cleaned up the code etc) got leaked by Mason on github, just search for Neon-Core on GitHub if you want to see the leaked version.[DOUBLEPOST=1507986088][/DOUBLEPOST]
Code:
package com.roguehcf.faction.claim;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
/**
* This class is a region/cuboid from one location to another. It can be used for blocks protection and things like WorldEdit.
* @author desht (Original code), KingFaris10 (Editor of code)
*/
public class Claim implements Iterable<Block>, Cloneable, ConfigurationSerializable {
        protected final String worldName;
        protected final int x1, y1, z1;
        protected final int x2, y2, z2;
        /**
         * Construct a Cuboid given two Location objects which represent any two corners of the Cuboid.
         * Note: The 2 locations must be on the same world.
         *
         * @param l1 - One of the corners
         * @param l2 - The other corner
         */
        public Claim(Location l1, Location l2) {
                if (!l1.getWorld().equals(l2.getWorld())) throw new IllegalArgumentException("Locations must be on the same world");
                this.worldName = l1.getWorld().getName();
                this.x1 = Math.min(l1.getBlockX(), l2.getBlockX());
                this.y1 = Math.min(l1.getBlockY(), l2.getBlockY());
                this.z1 = Math.min(l1.getBlockZ(), l2.getBlockZ());
                this.x2 = Math.max(l1.getBlockX(), l2.getBlockX());
                this.y2 = Math.max(l1.getBlockY(), l2.getBlockY());
                this.z2 = Math.max(l1.getBlockZ(), l2.getBlockZ());
        }
        /**
         * Construct a one-block Cuboid at the given Location of the Cuboid.
         *
         * @param l1 location of the Cuboid
         */
        public Claim(Location l1) {
                this(l1, l1);
        }
        /**
         * Copy constructor.
         *
         * @param other - The Cuboid to copy
         */
        public Claim(Claim other) {
                this(other.getWorld().getName(), other.x1, other.y1, other.z1, other.x2, other.y2, other.z2);
        }
        /**
         * Construct a Cuboid in the given World and xyz co-ordinates
         *
         * @param world - The Cuboid's world
         * @param x1 - X co-ordinate of corner 1
         * @param y1 - Y co-ordinate of corner 1
         * @param z1 - Z co-ordinate of corner 1
         * @param x2 - X co-ordinate of corner 2
         * @param y2 - Y co-ordinate of corner 2
         * @param z2 - Z co-ordinate of corner 2
         */
        public Claim(World world, int x1, int y1, int z1, int x2, int y2, int z2) {
                this.worldName = world.getName();
                this.x1 = Math.min(x1, x2);
                this.x2 = Math.max(x1, x2);
                this.y1 = Math.min(y1, y2);
                this.y2 = Math.max(y1, y2);
                this.z1 = Math.min(z1, z2);
                this.z2 = Math.max(z1, z2);
        }
        /**
         * Construct a Cuboid in the given world name and xyz co-ordinates.
         *
         * @param worldName - The Cuboid's world name
         * @param x1 - X co-ordinate of corner 1
         * @param y1 - Y co-ordinate of corner 1
         * @param z1 - Z co-ordinate of corner 1
         * @param x2 - X co-ordinate of corner 2
         * @param y2 - Y co-ordinate of corner 2
         * @param z2 - Z co-ordinate of corner 2
         */
        private Claim(String worldName, int x1, int y1, int z1, int x2, int y2, int z2) {
                this.worldName = worldName;
                this.x1 = Math.min(x1, x2);
                this.x2 = Math.max(x1, x2);
                this.y1 = Math.min(y1, y2);
                this.y2 = Math.max(y1, y2);
                this.z1 = Math.min(z1, z2);
                this.z2 = Math.max(z1, z2);
        }
        /**
         * Construct a Cuboid using a map with the following keys: worldName, x1, x2, y1, y2, z1, z2
         * @param map - The map of keys.
         */
        public Claim(Map<String, Object> map) {
                this.worldName = (String) map.get("worldName");
                this.x1 = (Integer) map.get("x1");
                this.x2 = (Integer) map.get("x2");
                this.y1 = (Integer) map.get("y1");
                this.y2 = (Integer) map.get("y2");
                this.z1 = (Integer) map.get("z1");
                this.z2 = (Integer) map.get("z2");
        }
        @Override
        public Map<String, Object> serialize() {
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("worldName", this.worldName);
                map.put("x1", this.x1);
                map.put("y1", this.y1);
                map.put("z1", this.z1);
                map.put("x2", this.x2);
                map.put("y2", this.y2);
                map.put("z2", this.z2);
                return map;
        }
        /**
         * Get the Location of the lower northeast corner of the Cuboid (minimum XYZ co-ordinates).
         *
         * @return Location of the lower northeast corner
         */
        public Location getLowerNE() {
                return new Location(this.getWorld(), this.x1, this.y1, this.z1);
        }
        /**
         * Get the Location of the upper southwest corner of the Cuboid (maximum XYZ co-ordinates).
         *
         * @return Location of the upper southwest corner
         */
        public Location getUpperSW() {
                return new Location(this.getWorld(), this.x2, this.y2, this.z2);
        }
        /**
         * Get the blocks in the Cuboid.
         *
         * @return The blocks in the Cuboid
         */
        public List<Block> getBlocks() {
                Iterator<Block> blockI = this.iterator();
                List<Block> copy = new ArrayList<Block>();
                while (blockI.hasNext())
                        copy.add(blockI.next());
                return copy;
        }
        /**
         * Get the the centre of the Cuboid.
         *
         * @return Location at the centre of the Cuboid
         */
        public Location getCenter() {
                int x1 = this.getUpperX() + 1;
                int y1 = this.getUpperY() + 1;
                int z1 = this.getUpperZ() + 1;
                return new Location(this.getWorld(), this.getLowerX() + (x1 - this.getLowerX()) / 2.0, this.getLowerY() + (y1 - this.getLowerY()) / 2.0, this.getLowerZ() + (z1 - this.getLowerZ()) / 2.0);
        }
        /**
         * Get the Cuboid's world.
         *
         * @return The World object representing this Cuboid's world
         * @throws IllegalStateException if the world is not loaded
         */
        public World getWorld() {
                World world = Bukkit.getWorld(this.worldName);
                if (world == null) throw new IllegalStateException("World '" + this.worldName + "' is not loaded");
                return world;
        }
        /**
         * Get the size of this Cuboid along the X axis
         *
         * @return      Size of Cuboid along the X axis
         */
        public int getSizeX() {
                return (this.x2 - this.x1) + 1;
        }
        /**
         * Get the size of this Cuboid along the Y axis
         *
         * @return      Size of Cuboid along the Y axis
         */
        public int getSizeY() {
                return (this.y2 - this.y1) + 1;
        }
        /**
         * Get the size of this Cuboid along the Z axis
         *
         * @return      Size of Cuboid along the Z axis
         */
        public int getSizeZ() {
                return (this.z2 - this.z1) + 1;
        }
        /**
         * Get the minimum X co-ordinate of this Cuboid
         *
         * @return      the minimum X co-ordinate
         */
        public int getLowerX() {
                return this.x1;
        }
        /**
         * Get the minimum Y co-ordinate of this Cuboid
         *
         * @return      the minimum Y co-ordinate
         */
        public int getLowerY() {
                return this.y1;
        }
        /**
         * Get the minimum Z co-ordinate of this Cuboid
         *
         * @return      the minimum Z co-ordinate
         */
        public int getLowerZ() {
                return this.z1;
        }
        /**
         * Get the maximum X co-ordinate of this Cuboid
         *
         * @return      the maximum X co-ordinate
         */
        public int getUpperX() {
                return this.x2;
        }
        /**
         * Get the maximum Y co-ordinate of this Cuboid
         *
         * @return      the maximum Y co-ordinate
         */
        public int getUpperY() {
                return this.y2;
        }
        /**
         * Get the maximum Z co-ordinate of this Cuboid
         *
         * @return      the maximum Z co-ordinate
         */
        public int getUpperZ() {
                return this.z2;
        }
        /**
         * Get the Blocks at the eight corners of the Cuboid.
         *
         * @return array of Block objects representing the Cuboid corners
         */
        public Block[] corners() {
                Block[] res = new Block[8];
                World w = this.getWorld();
                res[0] = w.getBlockAt(this.x1, this.y1, this.z1);
                res[1] = w.getBlockAt(this.x1, this.y1, this.z2);
                res[2] = w.getBlockAt(this.x1, this.y2, this.z1);
                res[3] = w.getBlockAt(this.x1, this.y2, this.z2);
                res[4] = w.getBlockAt(this.x2, this.y1, this.z1);
                res[5] = w.getBlockAt(this.x2, this.y1, this.z2);
                res[6] = w.getBlockAt(this.x2, this.y2, this.z1);
                res[7] = w.getBlockAt(this.x2, this.y2, this.z2);
                return res;
        }
        /**
         * Expand the Cuboid in the given direction by the given amount.  Negative amounts will shrink the Cuboid in the given direction.  Shrinking a cuboid's face past the opposite face is not an error and will return a valid Cuboid.
         *
         * @param dir - The direction in which to expand
         * @param amount - The number of blocks by which to expand
         * @return A new Cuboid expanded by the given direction and amount
         */
        public Claim expand(CuboidDirection dir, int amount) {
                switch (dir) {
                case North:
                        return new Claim(this.worldName, this.x1 - amount, this.y1, this.z1, this.x2, this.y2, this.z2);
                case South:
                        return new Claim(this.worldName, this.x1, this.y1, this.z1, this.x2 + amount, this.y2, this.z2);
                case East:
                        return new Claim(this.worldName, this.x1, this.y1, this.z1 - amount, this.x2, this.y2, this.z2);
                case West:
                        return new Claim(this.worldName, this.x1, this.y1, this.z1, this.x2, this.y2, this.z2 + amount);
                case Down:
                        return new Claim(this.worldName, this.x1, this.y1 - amount, this.z1, this.x2, this.y2, this.z2);
                case Up:
                        return new Claim(this.worldName, this.x1, this.y1, this.z1, this.x2, this.y2 + amount, this.z2);
                default:
                        throw new IllegalArgumentException("Invalid direction " + dir);
                }
        }
        /**
         * Shift the Cuboid in the given direction by the given amount.
         *
         * @param dir - The direction in which to shift
         * @param amount - The number of blocks by which to shift
         * @return A new Cuboid shifted by the given direction and amount
         */
        public Claim shift(CuboidDirection dir, int amount) {
                return expand(dir, amount).expand(dir.opposite(), -amount);
        }
        /**
         * Outset (grow) the Cuboid in the given direction by the given amount.
         *
         * @param dir - The direction in which to outset (must be Horizontal, Vertical, or Both)
         * @param amount - The number of blocks by which to outset
         * @return A new Cuboid outset by the given direction and amount
         */
        public Claim outset(CuboidDirection dir, int amount) {
                Claim c;
                switch (dir) {
                case Horizontal:
                        c = expand(CuboidDirection.North, amount).expand(CuboidDirection.South, amount).expand(CuboidDirection.East, amount).expand(CuboidDirection.West, amount);
                        break;
                case Vertical:
                        c = expand(CuboidDirection.Down, amount).expand(CuboidDirection.Up, amount);
                        break;
                case Both:
                        c = outset(CuboidDirection.Horizontal, amount).outset(CuboidDirection.Vertical, amount);
                        break;
                default:
                        throw new IllegalArgumentException("Invalid direction " + dir);
                }
                return c;
        }
        /**
         * Inset (shrink) the Cuboid in the given direction by the given amount.  Equivalent
         * to calling outset() with a negative amount.
         *
         * @param dir - The direction in which to inset (must be Horizontal, Vertical, or Both)
         * @param amount - The number of blocks by which to inset
         * @return A new Cuboid inset by the given direction and amount
         */
        public Claim inset(CuboidDirection dir, int amount) {
                return this.outset(dir, -amount);
        }
        /**
         * Return true if the point at (x,y,z) is contained within this Cuboid.
         *
         * @param x     - The X co-ordinate
         * @param y     - The Y co-ordinate
         * @param z     - The Z co-ordinate
         * @return true if the given point is within this Cuboid, false otherwise
         */
        public boolean contains(int x, int y, int z) {
                return x >= this.x1 && x <= this.x2 && y >= this.y1 && y <= this.y2 && z >= this.z1 && z <= this.z2;
        }
        /**
         * Check if the given Block is contained within this Cuboid.
         *
         * @param b     - The Block to check for
         * @return true if the Block is within this Cuboid, false otherwise
         */
        public boolean contains(Block b) {
                return this.contains(b.getLocation());
        }
        /**
         * Check if the given Location is contained within this Cuboid.
         *
         * @param l     - The Location to check for
         * @return true if the Location is within this Cuboid, false otherwise
         */
        public boolean contains(Location l) {
                if (!this.worldName.equals(l.getWorld().getName())) return false;
                return this.contains(l.getBlockX(), l.getBlockY(), l.getBlockZ());
        }
        /**
         * Get the volume of this Cuboid.
         *
         * @return The Cuboid volume, in blocks
         */
        public int getVolume() {
                return this.getSizeX() * this.getSizeY() * this.getSizeZ();
        }
        /**
         * Get the average light level of all empty (air) blocks in the Cuboid.  Returns 0 if there are no empty blocks.
         *
         * @return The average light level of this Cuboid
         */
        public byte getAverageLightLevel() {
                long total = 0;
                int n = 0;
                for (Block b : this) {
                        if (b.isEmpty()) {
                                total += b.getLightLevel();
                                ++n;
                        }
                }
                return n > 0 ? (byte) (total / n) : 0;
        }
        /**
         * Contract the Cuboid, returning a Cuboid with any air around the edges removed, just large enough to include all non-air blocks.
         *
         * @return A new Cuboid with no external air blocks
         */
        public Claim contract() {
                return this.contract(CuboidDirection.Down).contract(CuboidDirection.South).contract(CuboidDirection.East).contract(CuboidDirection.Up).contract(CuboidDirection.North).contract(CuboidDirection.West);
        }
        /**
         * Contract the Cuboid in the given direction, returning a new Cuboid which has no exterior empty space.
         * E.g. A direction of Down will push the top face downwards as much as possible.
         *
         * @param dir - The direction in which to contract
         * @return A new Cuboid contracted in the given direction
         */
        public Claim contract(CuboidDirection dir) {
                Claim face = getFace(dir.opposite());
                switch (dir) {
                case Down:
                        while (face.containsOnly(0) && face.getLowerY() > this.getLowerY()) {
                                face = face.shift(CuboidDirection.Down, 1);
                        }
                        return new Claim(this.worldName, this.x1, this.y1, this.z1, this.x2, face.getUpperY(), this.z2);
                case Up:
                        while (face.containsOnly(0) && face.getUpperY() < this.getUpperY()) {
                                face = face.shift(CuboidDirection.Up, 1);
                        }
                        return new Claim(this.worldName, this.x1, face.getLowerY(), this.z1, this.x2, this.y2, this.z2);
                case North:
                        while (face.containsOnly(0) && face.getLowerX() > this.getLowerX()) {
                                face = face.shift(CuboidDirection.North, 1);
                        }
                        return new Claim(this.worldName, this.x1, this.y1, this.z1, face.getUpperX(), this.y2, this.z2);
                case South:
                        while (face.containsOnly(0) && face.getUpperX() < this.getUpperX()) {
                                face = face.shift(CuboidDirection.South, 1);
                        }
                        return new Claim(this.worldName, face.getLowerX(), this.y1, this.z1, this.x2, this.y2, this.z2);
                case East:
                        while (face.containsOnly(0) && face.getLowerZ() > this.getLowerZ()) {
                                face = face.shift(CuboidDirection.East, 1);
                        }
                        return new Claim(this.worldName, this.x1, this.y1, this.z1, this.x2, this.y2, face.getUpperZ());
                case West:
                        while (face.containsOnly(0) && face.getUpperZ() < this.getUpperZ()) {
                                face = face.shift(CuboidDirection.West, 1);
                        }
                        return new Claim(this.worldName, this.x1, this.y1, face.getLowerZ(), this.x2, this.y2, this.z2);
                default:
                        throw new IllegalArgumentException("Invalid direction " + dir);
                }
        }
        /**
         * Get the Cuboid representing the face of this Cuboid.  The resulting Cuboid will be one block thick in the axis perpendicular to the requested face.
         *
         * @param dir - which face of the Cuboid to get
         * @return The Cuboid representing this Cuboid's requested face
         */
        public Claim getFace(CuboidDirection dir) {
                switch (dir) {
                case Down:
                        return new Claim(this.worldName, this.x1, this.y1, this.z1, this.x2, this.y1, this.z2);
                case Up:
                        return new Claim(this.worldName, this.x1, this.y2, this.z1, this.x2, this.y2, this.z2);
                case North:
                        return new Claim(this.worldName, this.x1, this.y1, this.z1, this.x1, this.y2, this.z2);
                case South:
                        return new Claim(this.worldName, this.x2, this.y1, this.z1, this.x2, this.y2, this.z2);
                case East:
                        return new Claim(this.worldName, this.x1, this.y1, this.z1, this.x2, this.y2, this.z1);
                case West:
                        return new Claim(this.worldName, this.x1, this.y1, this.z2, this.x2, this.y2, this.z2);
                default:
                        throw new IllegalArgumentException("Invalid direction " + dir);
                }
        }
        /**
         * Check if the Cuboid contains only blocks of the given type
         *
         * @param blockId - The block ID to check for
         * @return true if this Cuboid contains only blocks of the given type
         */
        @SuppressWarnings("deprecation")
        public boolean containsOnly(int blockId) {
                for (Block b : this) {
                        if (b.getTypeId() != blockId) return false;
                }
                return true;
        }
        /**
         * Get the Cuboid big enough to hold both this Cuboid and the given one.
         *
         * @param other - The other cuboid.
         * @return A new Cuboid large enough to hold this Cuboid and the given Cuboid
         */
        public Claim getBoundingCuboid(Claim other) {
                if (other == null) return this;
                int xMin = Math.min(this.getLowerX(), other.getLowerX());
                int yMin = Math.min(this.getLowerY(), other.getLowerY());
                int zMin = Math.min(this.getLowerZ(), other.getLowerZ());
                int xMax = Math.max(this.getUpperX(), other.getUpperX());
                int yMax = Math.max(this.getUpperY(), other.getUpperY());
                int zMax = Math.max(this.getUpperZ(), other.getUpperZ());
                return new Claim(this.worldName, xMin, yMin, zMin, xMax, yMax, zMax);
        }
       
        public int getArea() {
            Location min = this.getLowerNE();
            Location max = this.getUpperSW();
            return (max.getBlockX() - min.getBlockX() + 1) * (max.getBlockZ() - min.getBlockZ() + 1);
        }
       
        /**
         * Get a block relative to the lower NE point of the Cuboid.
         *
         * @param x     - The X co-ordinate
         * @param y     - The Y co-ordinate
         * @param z     - The Z co-ordinate
         * @return The block at the given position
         */
        public Block getRelativeBlock(int x, int y, int z) {
                return this.getWorld().getBlockAt(this.x1 + x, this.y1 + y, this.z1 + z);
        }
        /**
         * Get a block relative to the lower NE point of the Cuboid in the given World.  This
         * version of getRelativeBlock() should be used if being called many times, to avoid
         * excessive calls to getWorld().
         *
         * @param w     - The world
         * @param x     - The X co-ordinate   
         * @param y     - The Y co-ordinate   
         * @param z     - The Z co-ordinate   
         * @return The block at the given position
         */
        public Block getRelativeBlock(World w, int x, int y, int z) {
                return w.getBlockAt(this.x1 + x, y1 + y, this.z1 + z);
        }
        /**
         * Get a list of the chunks which are fully or partially contained in this cuboid.
         *
         * @return A list of Chunk objects
         */
        public List<Chunk> getChunks() {
                List<Chunk> res = new ArrayList<Chunk>();
                World w = this.getWorld();
                int x1 = this.getLowerX() & ~0xf;
                int x2 = this.getUpperX() & ~0xf;
                int z1 = this.getLowerZ() & ~0xf;
                int z2 = this.getUpperZ() & ~0xf;
                for (int x = x1; x <= x2; x += 16) {
                        for (int z = z1; z <= z2; z += 16) {
                                res.add(w.getChunkAt(x >> 4, z >> 4));
                        }
                }
                return res;
        }
        public Iterator<Block> iterator() {
                return new CuboidIterator(this.getWorld(), this.x1, this.y1, this.z1, this.x2, this.y2, this.z2);
        }
        @Override
        public Claim clone() {
                return new Claim(this);
        }
        @Override
        public String toString() {
                return new String("Cuboid: " + this.worldName + "," + this.x1 + "," + this.y1 + "," + this.z1 + "=>" + this.x2 + "," + this.y2 + "," + this.z2);
        }
        public class CuboidIterator implements Iterator<Block> {
                private World w;
                private int baseX, baseY, baseZ;
                private int x, y, z;
                private int sizeX, sizeY, sizeZ;
                public CuboidIterator(World w, int x1, int y1, int z1, int x2, int y2, int z2) {
                        this.w = w;
                        this.baseX = x1;
                        this.baseY = y1;
                        this.baseZ = z1;
                        this.sizeX = Math.abs(x2 - x1) + 1;
                        this.sizeY = Math.abs(y2 - y1) + 1;
                        this.sizeZ = Math.abs(z2 - z1) + 1;
                        this.x = this.y = this.z = 0;
                }
                public boolean hasNext() {
                        return this.x < this.sizeX && this.y < this.sizeY && this.z < this.sizeZ;
                }
                public Block next() {
                        Block b = this.w.getBlockAt(this.baseX + this.x, this.baseY + this.y, this.baseZ + this.z);
                        if (++x >= this.sizeX) {
                                this.x = 0;
                                if (++this.y >= this.sizeY) {
                                        this.y = 0;
                                        ++this.z;
                                }
                        }
                        return b;
                }
                public void remove() {
                }
        }
        public enum CuboidDirection {
                North, East, South, West, Up, Down, Horizontal, Vertical, Both, Unknown;
                public CuboidDirection opposite() {
                        switch (this) {
                        case North:
                                return South;
                        case East:
                                return West;
                        case South:
                                return North;
                        case West:
                                return East;
                        case Horizontal:
                                return Vertical;
                        case Vertical:
                                return Horizontal;
                        case Up:
                                return Down;
                        case Down:
                                return Up;
                        case Both:
                                return Both;
                        default:
                                return Unknown;
                        }
                }
        }
}
 
Last edited:
Status
This thread has been locked.
Top