From 9420b8c5ef71dee01d7e19160992c34d5feef154 Mon Sep 17 00:00:00 2001 From: Leonard Kugis Date: Mon, 25 Apr 2022 18:40:22 +0200 Subject: . --- .../java/com/encrox/instanceddungeons/Section.java | 499 +++++++++++++++++++++ 1 file changed, 499 insertions(+) create mode 100644 src/main/java/com/encrox/instanceddungeons/Section.java (limited to 'src/main/java/com/encrox/instanceddungeons/Section.java') diff --git a/src/main/java/com/encrox/instanceddungeons/Section.java b/src/main/java/com/encrox/instanceddungeons/Section.java new file mode 100644 index 0000000..282a554 --- /dev/null +++ b/src/main/java/com/encrox/instanceddungeons/Section.java @@ -0,0 +1,499 @@ +package com.encrox.instanceddungeons; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.plugin.Plugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.encrox.instancedregions.InstancedProtectedCuboidRegion; +import com.sk89q.worldedit.BlockVector; +import com.sk89q.worldedit.CuboidClipboard; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.MaxChangedBlocksException; +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.bukkit.BukkitWorld; +import com.sk89q.worldedit.data.DataException; +import com.sk89q.worldedit.schematic.MCEditSchematicFormat; + +public class Section { + + private Schematic schematic; + private String schematicFileName; + private Map exitMap; + private ArrayList players; + private BlockVector[] exits; + private BlockVector size, nearestPositiveX, nearestNegativeX, nearestPositiveY, nearestNegativeY, nearestPositiveZ, nearestNegativeZ; + private int index, depth; + private InstancedProtectedCuboidRegion region; + private Listener trigger; + private volatile boolean justEntered, portal = false; + private JSONObject descriptor; + + public Section(JSONObject descriptor, int index, int depth) { + this.index = index; + this.depth = depth; + players = new ArrayList(); + exitMap = new HashMap(); + schematicFileName = descriptor.getString("file"); + JSONArray size = descriptor.getJSONArray("size"); + this.size = new BlockVector(size.getInt(0), size.getInt(1), size.getInt(2)); + JSONArray exits = descriptor.getJSONArray("exits"); + this.exits = new BlockVector[exits.length()]; + for(int i = 0; i usable = new ArrayList(); + if(exits[i].getBlockX() == 0.0 || exits[i].getBlockX() == size.getBlockX()-1 || exits[i].getBlockZ() == 0.0 || exits[i].getBlockZ() == size.getBlockZ()-1) { + if(index == depth) { + for(int c = 0, length = InstancedDungeons.endDescriptors.length(); c getSideExits() { + ArrayList out = new ArrayList(); + for(int i = 0; i getTopExits() { + ArrayList out = new ArrayList(); + for(int i = 0; i getBottomExits() { + ArrayList out = new ArrayList(); + for(int i = 0; i dist) { + dist = current; + nearest = exits[i]; + } + } + } + return nearest; + } + + public BlockVector getNearestExitNegativeX(org.bukkit.util.Vector relative) { + BlockVector nearest = null; + double dist = 0.0, current; + for(int i = 0; i dist) { + dist = current; + nearest = exits[i]; + } + } + } + return nearest; + } + + public BlockVector getNearestExitPositiveY(org.bukkit.util.Vector relative) { + BlockVector nearest = null; + double dist = 0.0, current; + for(int i = 0; i dist) { + dist = current; + nearest = exits[i]; + } + } + } + return nearest; + } + + public BlockVector getNearestExitNegativeY(org.bukkit.util.Vector relative) { + BlockVector nearest = null; + double dist = 0.0, current; + for(int i = 0; i dist) { + dist = current; + nearest = exits[i]; + } + } + } + return nearest; + } + + public BlockVector getNearestExitPositiveZ(org.bukkit.util.Vector relative) { + BlockVector nearest = null; + double dist = 0.0, current; + for(int i = 0; i dist) { + dist = current; + nearest = exits[i]; + } + } + } + return nearest; + } + + public BlockVector getNearestExitNegativeZ(org.bukkit.util.Vector relative) { + BlockVector nearest = null; + double dist = 0.0, current; + for(int i = 0; i dist) { + dist = current; + nearest = exits[i]; + } + } + } + return nearest; + } + + public void instantiate() { + InstancedDungeons.logger.info("Instantiating section (file: " + descriptor.getString("file") + ", index: " + index + ", depth: " + depth + ")"); + justEntered = true; + portal = false; + region = InstancedDungeons.dungeonWorld.allocate(size.getBlockX(), size.getBlockZ()); + Iterator iter = players.iterator(); + while(iter.hasNext()) + region.addPlayer(iter.next()); + //write schematic to map + final BlockVector min = region.getMinimumPoint(); + + for(int i = 0; i exits = exitMap.values().iterator(); + while(exits.hasNext()) + exits.next().getSection().addPlayer(player); + } + } + + public void removePlayer(Player player) { + players.add(player); + if(region != null) + region.removePlayer(player); + if(exitMap != null) { + Iterator exits = exitMap.values().iterator(); + while(exits.hasNext()) + exits.next().getSection().removePlayer(player); + } + } + +} -- cgit v1.2.1