1
0
Fork 0

Detect glass frames being placed, with full logging.

main
Marissa Staib 6 years ago
parent bc83629876
commit ebdab500b3
  1. 124
      .idea/uiDesigner.xml
  2. 154
      .idea/workspace.xml
  3. 8
      src/main/kotlin/net/deliciousreya/minecraftportal/MinecraftPortalPlugin.kt
  4. 96
      src/main/kotlin/net/deliciousreya/minecraftportal/PortalFrame.kt
  5. 32
      src/main/kotlin/net/deliciousreya/minecraftportal/extensions/Location.kt
  6. 31
      src/main/kotlin/net/deliciousreya/minecraftportal/extensions/Vector.kt

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

@ -2,13 +2,8 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="859a87a7-9353-4bac-b28a-a1d9067ab6a4" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/.idea/minecraftportal.iml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/runConfigurations/Run_Server.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/runConfigurations/Run_Server.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/TODO" beforeDir="false" afterPath="$PROJECT_DIR$/TODO" afterDir="false" />
<change beforePath="$PROJECT_DIR$/build.gradle" beforeDir="false" afterPath="$PROJECT_DIR$/build.gradle" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/net/deliciousreya/minecraftportal/MinecraftPortalPlugin.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/net/deliciousreya/minecraftportal/MinecraftPortalPlugin.kt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/net/deliciousreya/minecraftportal/PortalFrame.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/net/deliciousreya/minecraftportal/PortalFrame.kt" afterDir="false" />
</list>
<ignored path="$PROJECT_DIR$/out/" />
<ignored path="$PROJECT_DIR$/.gradle/" />
@ -59,11 +54,47 @@
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/kotlin/net/deliciousreya/minecraftportal/MinecraftPortalPlugin.kt">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="248">
<caret line="22" column="63" lean-forward="true" selection-start-line="22" selection-start-column="63" selection-end-line="22" selection-end-column="63" />
<state relative-caret-position="116">
<caret line="8" column="6" selection-start-line="8" selection-start-column="6" selection-end-line="8" selection-end-column="6" />
<folding>
<element signature="e#43#311#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/main/kotlin/net/deliciousreya/minecraftportal/PortalFrame.kt">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="225">
<caret line="70" column="25" selection-start-line="70" selection-start-column="25" selection-end-line="70" selection-end-column="25" />
<folding>
<element signature="e#43#294#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/kotlin/net/deliciousreya/minecraftportal/extensions/Vector.kt">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="299">
<caret line="29" column="9" lean-forward="true" selection-start-line="29" selection-start-column="9" selection-end-line="29" selection-end-column="9" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/kotlin/net/deliciousreya/minecraftportal/extensions/Location.kt">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="51">
<caret line="13" selection-start-line="13" selection-end-line="13" />
<folding>
<element signature="e#54#110#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
@ -83,12 +114,14 @@
<option name="RECENT_TEMPLATES">
<list>
<option value="Kotlin Class" />
<option value="Kotlin File" />
</list>
</option>
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>1</find>
<find>.add</find>
</findStrings>
<dirStrings>
<dir>$PROJECT_DIR$</dir>
@ -106,7 +139,13 @@
<option value="$PROJECT_DIR$/.gitignore" />
<option value="$PROJECT_DIR$/build.gradle" />
<option value="$PROJECT_DIR$/TODO" />
<option value="$PROJECT_DIR$/src/main/kotlin/net/deliciousreya/minecraftportal/FrameManager.kt" />
<option value="$PROJECT_DIR$/src/main/kotlin/net/deliciousreya/minecraftportal/VectorExtensions.kt" />
<option value="$PROJECT_DIR$/src/main/kotlin/net/deliciousreya/minecraftportal/extensions/VectorExtensions.kt" />
<option value="$PROJECT_DIR$/src/main/kotlin/net/deliciousreya/minecraftportal/MinecraftPortalPlugin.kt" />
<option value="$PROJECT_DIR$/src/main/kotlin/net/deliciousreya/minecraftportal/extensions/Vector.kt" />
<option value="$PROJECT_DIR$/src/main/kotlin/net/deliciousreya/minecraftportal/extensions/Location.kt" />
<option value="$PROJECT_DIR$/src/main/kotlin/net/deliciousreya/minecraftportal/PortalFrame.kt" />
</list>
</option>
</component>
@ -141,6 +180,36 @@
<item name="minecraftportal" type="8a07ba80:GradleTreeStructureProvider$GradleModuleDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="minecraftportal" type="b2602c69:ProjectViewProjectNode" />
<item name="minecraftportal" type="8a07ba80:GradleTreeStructureProvider$GradleModuleDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="main" type="8a07ba80:GradleTreeStructureProvider$GradleModuleDirectoryNode" />
</path>
<path>
<item name="minecraftportal" type="b2602c69:ProjectViewProjectNode" />
<item name="minecraftportal" type="8a07ba80:GradleTreeStructureProvider$GradleModuleDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="main" type="8a07ba80:GradleTreeStructureProvider$GradleModuleDirectoryNode" />
<item name="kotlin" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="minecraftportal" type="b2602c69:ProjectViewProjectNode" />
<item name="minecraftportal" type="8a07ba80:GradleTreeStructureProvider$GradleModuleDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="main" type="8a07ba80:GradleTreeStructureProvider$GradleModuleDirectoryNode" />
<item name="kotlin" type="462c0819:PsiDirectoryNode" />
<item name="minecraftportal" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="minecraftportal" type="b2602c69:ProjectViewProjectNode" />
<item name="minecraftportal" type="8a07ba80:GradleTreeStructureProvider$GradleModuleDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="main" type="8a07ba80:GradleTreeStructureProvider$GradleModuleDirectoryNode" />
<item name="kotlin" type="462c0819:PsiDirectoryNode" />
<item name="minecraftportal" type="462c0819:PsiDirectoryNode" />
<item name="extensions" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
@ -165,6 +234,9 @@
<key name="MoveKotlinTopLevelDeclarationsDialog.RECENTS_KEY">
<recent name="org.deliciousreya.minecraftportal" />
</key>
<key name="MoveFile.RECENT_KEYS">
<recent name="C:\Users\serynth\IdeaProjects\minecraftportal\src\main\kotlin\net\deliciousreya\minecraftportal\extensions" />
</key>
</component>
<component name="RunDashboard">
<option name="ruleStates">
@ -215,7 +287,7 @@
<workItem from="1554828993158" duration="8169000" />
<workItem from="1554897237397" duration="4177000" />
<workItem from="1554901673860" duration="1439000" />
<workItem from="1554903259740" duration="889000" />
<workItem from="1554903259740" duration="4714000" />
</task>
<task id="LOCAL-00001" summary="Base check-in of build settings etc.">
<created>1554832667584</created>
@ -280,11 +352,25 @@
<option name="project" value="LOCAL" />
<updated>1554901123221</updated>
</task>
<option name="localTasksCounter" value="10" />
<task id="LOCAL-00010" summary="Fix glass detection">
<created>1554904174549</created>
<option name="number" value="00010" />
<option name="presentableId" value="LOCAL-00010" />
<option name="project" value="LOCAL" />
<updated>1554904174549</updated>
</task>
<task id="LOCAL-00011" summary="Detect glass frames being placed, with full logging.">
<created>1554907968725</created>
<option name="number" value="00011" />
<option name="presentableId" value="LOCAL-00011" />
<option name="project" value="LOCAL" />
<updated>1554907968725</updated>
</task>
<option name="localTasksCounter" value="12" />
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="14674000" />
<option name="totallyTimeSpent" value="18499000" />
</component>
<component name="TodoView">
<todo-panel id="selected-file">
@ -299,7 +385,7 @@
<frame x="-8" y="-8" width="1936" height="1096" extended-state="6" />
<editor active="true" />
<layout>
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.26066098" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.26066098" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Designer" order="2" />
<window_info id="Image Layers" order="3" />
@ -314,11 +400,11 @@
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" weight="0.32931727" />
<window_info anchor="bottom" id="Build" order="7" weight="0.3509865" />
<window_info anchor="bottom" id="Terminal" order="8" visible="true" weight="0.5867082" />
<window_info anchor="bottom" id="Terminal" order="8" weight="0.5867082" />
<window_info anchor="bottom" id="Docker" order="9" show_stripe_button="false" />
<window_info anchor="bottom" id="Event Log" order="10" side_tool="true" />
<window_info anchor="bottom" id="Database Changes" order="11" />
<window_info anchor="bottom" id="Version Control" order="12" weight="0.32851407" />
<window_info active="true" anchor="bottom" id="Version Control" order="12" visible="true" weight="0.3281412" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
@ -344,7 +430,9 @@
<MESSAGE value="Ignore local.properties" />
<MESSAGE value="Remove local.properties" />
<MESSAGE value="Add glass detection" />
<option name="LAST_COMMIT_MESSAGE" value="Add glass detection" />
<MESSAGE value="Fix glass detection" />
<MESSAGE value="Detect glass frames being placed, with full logging." />
<option name="LAST_COMMIT_MESSAGE" value="Detect glass frames being placed, with full logging." />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/build/resources/main/plugin.yml" />
@ -384,10 +472,40 @@
<entry file="file://$PROJECT_DIR$/TODO">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/src/main/kotlin/net/deliciousreya/minecraftportal/extensions/Location.kt">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="51">
<caret line="13" selection-start-line="13" selection-end-line="13" />
<folding>
<element signature="e#54#110#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/kotlin/net/deliciousreya/minecraftportal/MinecraftPortalPlugin.kt">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="248">
<caret line="22" column="63" lean-forward="true" selection-start-line="22" selection-start-column="63" selection-end-line="22" selection-end-column="63" />
<state relative-caret-position="116">
<caret line="8" column="6" selection-start-line="8" selection-start-column="6" selection-end-line="8" selection-end-column="6" />
<folding>
<element signature="e#43#311#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/kotlin/net/deliciousreya/minecraftportal/extensions/Vector.kt">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="299">
<caret line="29" column="9" lean-forward="true" selection-start-line="29" selection-start-column="9" selection-end-line="29" selection-end-column="9" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/kotlin/net/deliciousreya/minecraftportal/PortalFrame.kt">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="225">
<caret line="70" column="25" selection-start-line="70" selection-start-column="25" selection-end-line="70" selection-end-column="25" />
<folding>
<element signature="e#43#294#0" expanded="true" />
</folding>
</state>
</provider>
</entry>

@ -4,8 +4,6 @@ import org.bukkit.Material
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.block.BlockPlaceEvent
import org.bukkit.event.player.PlayerJoinEvent
import org.bukkit.inventory.ItemStack
import org.bukkit.plugin.java.JavaPlugin
class MinecraftPortalPlugin() : JavaPlugin(), Listener
@ -21,6 +19,12 @@ class MinecraftPortalPlugin() : JavaPlugin(), Listener
logger.info("block placed of type " + e.block.type)
if (e.block.type.equals(Material.GLASS)) {
logger.info("put down glass at " + e.block.location)
val portalScanResults = findPortalFrameConnectedTo(e.block)
if (portalScanResults.frame != null) {
logger.info("found portal frame $portalScanResults")
} else {
logger.info("no portal frame found, best scan was $portalScanResults")
}
}
}
}

@ -0,0 +1,96 @@
package net.deliciousreya.minecraftportal
import com.google.common.collect.ImmutableList
import org.bukkit.Location
import org.bukkit.Material.AIR
import org.bukkit.Material.GLASS
import org.bukkit.block.Block
import org.bukkit.util.Vector
import net.deliciousreya.minecraftportal.extensions.*
fun findPortalFrameConnectedTo(block:Block): PortalScanResults {
var bestScan:PortalScanResults? = null
if (block.type == GLASS) {
for (direction in PortalFrame.Direction.values()) {
for (vector in direction.glassOffsets) {
val scanResult = checkPortalFrameAt(block.location.subtract(vector), direction)
if (scanResult.frame != null) {
return scanResult
}
if (bestScan == null || scanResult > bestScan) {
bestScan = scanResult
}
}
}
}
if (block.type == GLASS) {
for (direction in PortalFrame.Direction.values()) {
val scanResult = checkPortalFrameAt(block.location.subtract(direction.mineralOffset), direction)
if (scanResult.frame != null) {
return scanResult
} else if (bestScan == null || scanResult > bestScan) {
bestScan = scanResult
}
}
}
if (bestScan != null) {
return bestScan
} else {
return PortalScanResults(null, ImmutableList.of(), ImmutableList.of())
}
}
/** Detects whether there is a portal frame in the given location, extending in the given direction. */
fun checkPortalFrameAt(location:Location, direction:PortalFrame.Direction): PortalScanResults {
val matches = ImmutableList.Builder<Block>()
val nonmatches = ImmutableList.Builder<Block>()
for (vector in direction.glassOffsets) {
val block = (location + vector).block
(if (block.type == GLASS) matches else nonmatches).add(block)
}
for (vector in direction.airOffsets) {
val block = (location + vector).block
(if (block.type == AIR) matches else nonmatches).add(block)
}
val block = (location + direction.mineralOffset).block
(if (block.type == GLASS) matches else nonmatches).add(block)
val nonmatchesBuilt = nonmatches.build()
return PortalScanResults(if (nonmatchesBuilt.isEmpty()) {PortalFrame(location, direction)} else {null}, matches.build(), nonmatchesBuilt)
}
data class PortalScanResults(val frame: PortalFrame?, val matchingBlocks:List<Block>, val nonMatchingBlocks:List<Block>) : Comparable<PortalScanResults> {
override fun compareTo(other:PortalScanResults): Int {
return matchingBlocks.size - other.matchingBlocks.size
}
}
/** Information about a portal frame. */
data class PortalFrame(val lowerLeftCorner: Location, val direction: Direction) {
val UP = Vector(0, 1, 0)
/** The direction along which a portal frame extends. */
enum class Direction(vector: Vector) {
X_AXIS(Vector(1, 0, 0)),
Z_AXIS(Vector(0, 0, 1));
private val rightSideVector = vector * 2
val glassOffsets: ImmutableList<Vector> = ImmutableList.of(
Vector(0, 0, 0),
Vector(0, 1, 0),
Vector(0, 2, 0),
Vector(0, 3, 0),
vector,
rightSideVector,
Vector(0, 1, 0) + rightSideVector,
Vector(0, 2, 0) + rightSideVector,
Vector(0, 3, 0) + rightSideVector
)
val mineralOffset: Vector = Vector(0, 3, 0) + vector
val airOffsets: ImmutableList<Vector> = ImmutableList.of(
Vector(0, 1, 0) + vector,
Vector(0, 2, 0) + vector
)
}
}

@ -0,0 +1,32 @@
package net.deliciousreya.minecraftportal.extensions
import org.bukkit.Location
import org.bukkit.util.Vector
operator fun Location.plus(v: Vector):Location {
return this.clone().add(v)
}
operator fun Location.plus(l: Location):Location {
return this.clone().add(l)
}
fun Location.plus(x: Double, y: Double, z: Double):Location {
return this.clone().add(x, y, z)
}
operator fun Location.minus(v:Vector):Location {
return this.clone().subtract(v)
}
operator fun Location.minus(l: Location):Location {
return this.clone().subtract(l)
}
fun Location.minus(x: Double, y: Double, z: Double):Location {
return this.clone().subtract(x, y, z)
}
operator fun Location.times(n:Double):Location {
return this.clone().multiply(n)
}

@ -0,0 +1,31 @@
package net.deliciousreya.minecraftportal.extensions
import org.bukkit.util.Vector
operator fun Vector.plus(v:Vector):Vector {
return this.clone().add(v)
}
operator fun Vector.minus(v:Vector):Vector {
return this.clone().subtract(v)
}
operator fun Vector.times(n:Int):Vector {
return this.clone().multiply(n)
}
operator fun Vector.times(n:Float):Vector {
return this.clone().multiply(n)
}
operator fun Vector.times(n:Double):Vector {
return this.clone().multiply(n)
}
operator fun Vector.times(v:Vector):Vector {
return this.clone().multiply(v)
}
operator fun Vector.div(v:Vector):Vector {
return this.clone().divide(v)
}
Loading…
Cancel
Save