diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
new file mode 100644
index 00000000..dd84ea78
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -0,0 +1,38 @@
+---
+name: Bug report
+about: Create a report to help us improve
+title: ''
+labels: ''
+assignees: ''
+
+---
+
+**Describe the bug**
+A clear and concise description of what the bug is.
+
+**To Reproduce**
+Steps to reproduce the behavior:
+1. Go to '...'
+2. Click on '....'
+3. Scroll down to '....'
+4. See error
+
+**Expected behavior**
+A clear and concise description of what you expected to happen.
+
+**Screenshots**
+If applicable, add screenshots to help explain your problem.
+
+**Desktop (please complete the following information):**
+ - OS: [e.g. iOS]
+ - Browser [e.g. chrome, safari]
+ - Version [e.g. 22]
+
+**Smartphone (please complete the following information):**
+ - Device: [e.g. iPhone6]
+ - OS: [e.g. iOS8.1]
+ - Browser [e.g. stock browser, safari]
+ - Version [e.g. 22]
+
+**Additional context**
+Add any other context about the problem here.
diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml
new file mode 100644
index 00000000..38fa5ed1
--- /dev/null
+++ b/.github/workflows/create_release.yml
@@ -0,0 +1,45 @@
+# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
+# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
+
+# This workflow uses actions that are not certified by GitHub.
+# They are provided by a third-party and are governed by
+# separate terms of service, privacy policy, and support
+# documentation.
+
+name: Create release
+
+on:
+ workflow_dispatch:
+
+env:
+ MINECRAFT_VERSION: 1.20.4
+
+jobs:
+ build:
+ permissions:
+ contents: write
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v3
+ - name: Set up Java 17
+ uses: actions/setup-java@v3
+ with:
+ java-version: '17'
+ distribution: 'temurin'
+ cache: maven
+ - uses: SpraxDev/Action-SpigotMC@v4
+ with:
+ versions: ${{ env.MINECRAFT_VERSION }},
+ remapped: true
+ - name: Build with Maven
+ run: mvn '-Dproject.artifactOutput=.' -B package --file pom.xml
+ - name: Create Release
+ uses: ncipollo/release-action@v1.14.0
+ with:
+ artifacts: jrides.jar
+ name: jrides ${{ env.MINECRAFT_VERSION }}-${{ github.run_number }}
+ makeLatest: true
+ commit: master
+ tag: release-${{ github.run_number }}
diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
new file mode 100644
index 00000000..531f25ea
--- /dev/null
+++ b/.github/workflows/maven.yml
@@ -0,0 +1,43 @@
+# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
+# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
+
+# This workflow uses actions that are not certified by GitHub.
+# They are provided by a third-party and are governed by
+# separate terms of service, privacy policy, and support
+# documentation.
+
+name: Maven build
+
+on:
+ push:
+ branches: [ "master" ]
+ pull_request:
+ branches: [ "master" ]
+
+env:
+ MINECRAFT_VERSION: 1.20.4
+
+jobs:
+ build:
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v3
+ - name: Set up Java 17
+ uses: actions/setup-java@v3
+ with:
+ java-version: '17'
+ distribution: 'temurin'
+ cache: maven
+ - uses: SpraxDev/Action-SpigotMC@v4
+ with:
+ versions: ${{ env.MINECRAFT_VERSION }},
+ remapped: true
+ - name: Build with Maven
+ run: mvn '-Dproject.artifactOutput=.' '-DartifactFileNameSuffix=_devbuild_${{ github.run_number }}' -B package --file pom.xml
+ - name: Upload Artifact
+ uses: actions/upload-artifact@v4
+ with:
+ name: jrides ${{ env.MINECRAFT_VERSION }} nr.${{ github.run_number }} Development Build
+ path: jrides_devbuild_${{ github.run_number }}.jar
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..97f75fb6
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,177 @@
+# Created by https://www.toptal.com/developers/gitignore/api/java
+# Edit at https://www.toptal.com/developers/gitignore?templates=java
+
+### Java ###
+# Compiled class file
+*.class
+
+# Log file
+*.log
+
+# BlueJ files
+*.ctxt
+
+# Mobile Tools for Java (J2ME)
+.mtj.tmp/
+
+# Package Files #
+*.jar
+*.war
+*.nar
+*.ear
+*.zip
+*.tar.gz
+*.rar
+
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
+hs_err_pid*
+replay_pid*
+
+# End of https://www.toptal.com/developers/gitignore/api/java
+
+# Created by https://www.toptal.com/developers/gitignore/api/maven
+# Edit at https://www.toptal.com/developers/gitignore?templates=maven
+
+### Maven ###
+target/
+pom.xml.tag
+pom.xml.releaseBackup
+pom.xml.versionsBackup
+pom.xml.next
+release.properties
+dependency-reduced-pom.xml
+buildNumber.properties
+.mvn/timing.properties
+# https://github.com/takari/maven-wrapper#usage-without-binary-jar
+.mvn/wrapper/maven-wrapper.jar
+
+# Eclipse m2e generated files
+# Eclipse Core
+.project
+# JDT-specific (Eclipse Java Development Tools)
+.classpath
+
+# End of https://www.toptal.com/developers/gitignore/api/maven
+
+# Created by https://www.toptal.com/developers/gitignore/api/intellij
+# Edit at https://www.toptal.com/developers/gitignore?templates=intellij
+
+### Intellij ###
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
+
+# User-specific stuff
+.idea/**/workspace.xml
+.idea/**/tasks.xml
+.idea/**/usage.statistics.xml
+.idea/**/dictionaries
+.idea/**/shelf
+
+# AWS User-specific
+.idea/**/aws.xml
+
+# Generated files
+.idea/**/contentModel.xml
+
+# Sensitive or high-churn files
+.idea/**/dataSources/
+.idea/**/dataSources.ids
+.idea/**/dataSources.local.xml
+.idea/**/sqlDataSources.xml
+.idea/**/dynamic.xml
+.idea/**/uiDesigner.xml
+.idea/**/dbnavigator.xml
+
+# Gradle
+.idea/**/gradle.xml
+.idea/**/libraries
+
+# Gradle and Maven with auto-import
+# When using Gradle or Maven with auto-import, you should exclude module files,
+# since they will be recreated, and may cause churn. Uncomment if using
+# auto-import.
+.idea/artifacts
+.idea/compiler.xml
+.idea/jarRepositories.xml
+.idea/modules.xml
+.idea/*.iml
+.idea/modules
+*.iml
+*.ipr
+
+# CMake
+cmake-build-*/
+
+# Mongo Explorer plugin
+.idea/**/mongoSettings.xml
+
+# File-based project format
+*.iws
+
+# IntelliJ
+out/
+.idea
+jrides.iml
+
+# VS Code
+.vscode/
+
+# mpeltonen/sbt-idea plugin
+.idea_modules/
+
+# JIRA plugin
+atlassian-ide-plugin.xml
+
+# Cursive Clojure plugin
+.idea/replstate.xml
+
+# SonarLint plugin
+.idea/sonarlint/
+
+# Crashlytics plugin (for Android Studio and IntelliJ)
+com_crashlytics_export_strings.xml
+crashlytics.properties
+crashlytics-build.properties
+fabric.properties
+
+# Editor-based Rest Client
+.idea/httpRequests
+
+# Android studio 3.1+ serialized cache file
+.idea/caches/build_file_checksums.ser
+
+### Intellij Patch ###
+# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
+
+# *.iml
+# modules.xml
+# .idea/misc.xml
+# *.ipr
+
+# Sonarlint plugin
+# https://plugins.jetbrains.com/plugin/7973-sonarlint
+.idea/**/sonarlint/
+
+# SonarQube Plugin
+# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
+.idea/**/sonarIssues.xml
+
+# Markdown Navigator plugin
+# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
+.idea/**/markdown-navigator.xml
+.idea/**/markdown-navigator-enh.xml
+.idea/**/markdown-navigator/
+
+# Cache file creation bug
+# See https://youtrack.jetbrains.com/issue/JBR-2257
+.idea/$CACHE_FILE$
+
+# CodeStream plugin
+# https://plugins.jetbrains.com/plugin/12206-codestream
+.idea/codestream.xml
+
+# Azure Toolkit for IntelliJ plugin
+# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
+.idea/**/azureSettings.xml
+
+# End of https://www.toptal.com/developers/gitignore/api/intellij
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 00000000..e72bfdda
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+
+ Copyright (C)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ Copyright (C)
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+ .
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+.
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 00000000..38c8ed32
--- /dev/null
+++ b/README.md
@@ -0,0 +1,77 @@
+![](assets/banner-1.gif)
+
+# **jrides** - Bring coasters to your Minecraft server!
+![Maven build](https://github.com/JVerbruggen/jrides/workflows/Maven%20build/badge.svg)
+
+
+'jrides' is an open-source rollercoaster animator for Minecraft Spigot. Super-smoothly animated coasters within the snap of a finger.
+
+✨ **No mods required!** ✨
+
+## 🎢 *Ride - go inside your own rides*
+* With jrides, you can enter any ride you create. Whether it is a launched, inverted or water coaster.
+
+![](assets/banner-2.gif)
+
+
+
+## 🎛️ *Control - send your friends onto the lift-hill*
+* Be the person behind the buttons! You decide whether the ride is safe for dispatch or not.
+* Not interested in being behind the controls, or no player online to control the ride? No problem! Put the ride in automatic mode!
+
+**And with the advanced ride monitoring system, you know where all trains are, without even seeing them!**
+
+![](assets/banner-3.gif)
+
+
+## 🚠 *Go sideways - hyper-mobile transfers*
+* Besides going forward, your coaster can go sideways, if you want! Use transfers to push a train sideways, upwards, or even roll it on its side.
+
+![](assets/banner-4.gif)
+
+## 😵💫 *SmoothCoasters - upside down POV camera*
+With built-in support for the [smooth-coasters client](https://www.curseforge.com/minecraft/mc-mods/smoothcoasters), you can go upside down!
+
+## ✨ And so much more!
+* Custom **Flat rides** - i.e. TeaCups, Caroussels, Ferris Wheels, anything that rotates!
+* Flat ride passenger control
+* Navigation menu
+* Ride counters
+* Double stations
+* Multi-track support, redirect your trains left or right
+* Player teleportation system
+
+
+---
+
+## Download
+
+Click one of the versions below to start your download! Thank you and enjoy!
+
+| Version | Link |
+|---------|-----|
+| 1.19.2 | tbd |
+| 1.20.1 | tbd |
+
+### Warning - jrides is currently in beta. Please report any issues in GitHub.
+
+
+
+## Configuration
+Refer to [docs/config.md](./docs/config.md) for configuration.
+
+
+---
+
+## 🎡 **Visit our live demo!** server.greekcraft.nl
+Try it out for yourself! Join our demo server at [server.greekcraft.nl](https://greekcraft.nl).
+
+
+
+**Trailer video**
+
+[![GreekCraft trailer](https://img.youtube.com/vi/pJAwFTujA9M/0.jpg)](https://www.youtube.com/watch?v=pJAwFTujA9M)
+
+---
+
+*jrides - created by [MeneerPinguin](https://github.com/JVerbruggen)*
diff --git a/assets/banner-1.gif b/assets/banner-1.gif
new file mode 100644
index 00000000..bcf521cf
Binary files /dev/null and b/assets/banner-1.gif differ
diff --git a/assets/banner-2.gif b/assets/banner-2.gif
new file mode 100644
index 00000000..cc3e8b39
Binary files /dev/null and b/assets/banner-2.gif differ
diff --git a/assets/banner-3.gif b/assets/banner-3.gif
new file mode 100644
index 00000000..6764ad9c
Binary files /dev/null and b/assets/banner-3.gif differ
diff --git a/assets/banner-4.gif b/assets/banner-4.gif
new file mode 100644
index 00000000..9812d074
Binary files /dev/null and b/assets/banner-4.gif differ
diff --git a/docs/assets/coaster-creation-flow.drawio.png b/docs/assets/coaster-creation-flow.drawio.png
new file mode 100644
index 00000000..80e315e7
Binary files /dev/null and b/docs/assets/coaster-creation-flow.drawio.png differ
diff --git a/docs/assets/source/coaster-creation-flow.drawio b/docs/assets/source/coaster-creation-flow.drawio
new file mode 100644
index 00000000..124cd4fa
--- /dev/null
+++ b/docs/assets/source/coaster-creation-flow.drawio
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/docs/coaster_yml.md b/docs/coaster_yml.md
new file mode 100644
index 00000000..e9c13940
--- /dev/null
+++ b/docs/coaster_yml.md
@@ -0,0 +1 @@
+# Coaster.yml
diff --git a/docs/config.md b/docs/config.md
new file mode 100644
index 00000000..f287c16e
--- /dev/null
+++ b/docs/config.md
@@ -0,0 +1,47 @@
+# Configuration
+
+## Folder structure
+
+Default data folder
+* `plugins/jrides`
+
+## rides.yml
+* This file contains all active coasters that should be loaded on startup.
+* Location: `plugins/jrides/rides.yml`
+
+Example configuration:
+```yml
+config:
+ silverstar:
+ identifier: silverstar
+ type: coaster
+ wodan:
+ identifier: wodan
+ type: coaster
+```
+
+## language.yml
+* Change all feedback that is visible to players.
+* Location: `plugins/jrides/language.yml`
+
+Example configuration:
+```yml
+language:
+ NOTIFICATION_RIDE_COUNTER_UPDATE: "&4-------\n \n&6You have been %RIDE_COUNT% times in %RIDE_DISPLAY_NAME%!\n \n&4-------"
+ NOTIFICATION_CANNOT_ENTER_RIDE: "&7This ride is temporarily unavailable."
+```
+
+For all available language overrides, see [docs/language.md](./language.md)
+
+
+## coaster.yml
+* Coaster configuration
+* Location: `plugins/jrides/coasters//.coaster.yml`
+* * Example: `plugins/jrides/coasters/silverstar/silverstar.coaster.yml`
+
+The exact structure of this file can be found in [docs/coaster_yml.md](./coaster_yml.md)
+
+## trigger.yml
+* Add triggers to coaster tracks, to run effects, commands or animate entities.
+
+For more information, see [docs/triggers.md](./triggers.md)
\ No newline at end of file
diff --git a/docs/item.md b/docs/item.md
new file mode 100644
index 00000000..8f7aaa16
--- /dev/null
+++ b/docs/item.md
@@ -0,0 +1,2 @@
+# Item configuration
+
diff --git a/docs/language.md b/docs/language.md
new file mode 100644
index 00000000..79efc9b3
--- /dev/null
+++ b/docs/language.md
@@ -0,0 +1,69 @@
+
+# Language
+
+Also see: [docs/config.md](./config.md)
+
+Example language file (plugins/jrides/language.yml):
+```yaml
+language:
+ NOTIFICATION_RIDE_COUNTER_UPDATE: "&4-------\n \n&6You have been %RIDE_COUNT% times in %RIDE_DISPLAY_NAME%!\n \n&4-------"
+ NOTIFICATION_CANNOT_ENTER_RIDE: "&7This ride is temporarily unavailable."
+```
+
+Key | Default value
+--- | ---
+CHAT_FEEDBACK_PREFIX | "[jrides] "
+CHAT_FEEDBACK_INFO_COLOR | "&7"
+CHAT_FEEDBACK_WARNING_COLOR | "&e"
+CHAT_FEEDBACK_SEVERE_COLOR | "&c"
+COMMAND_RIDE_DISPATCHED_MESSAGE | "Ride %RIDE_DISPLAY_NAME% was dispatched!"
+COMMAND_VISUALIZE_ADDED_VIEWER | "You are now viewing %RIDE_IDENTIFIER% in visualize mode"
+COMMAND_VISUALIZE_REMOVED_VIEWER | "You are no longer viewing %RIDE_IDENTIFIER% in visualize mode"
+NOTIFICATION_PLUGIN_STILL_LOADING | "Please try again later when jrides is loaded"
+NOTIFICATION_RIDE_CONTROL_ACTIVE | "You are now controlling %RIDE_DISPLAY_NAME%"
+NOTIFICATION_RIDE_CONTROL_INACTIVE | "You are no longer controlling %RIDE_DISPLAY_NAME%"
+NOTIFICATION_RIDE_DISPATCH_PROBLEMS | "Cannot dispatch due to the following problems:"
+NOTIFICATION_RIDE_NO_TRAIN_PRESENT | "No train present in station"
+NOTIFICATION_RIDE_NEXT_BLOCK_OCCUPIED | "Next block section is occupied"
+NOTIFICATION_RIDE_WAITING_TIME | "Waiting time has not passed yet"
+NOTIFICATION_RIDE_RESTRAINTS_NOT_CLOSED | "Not all restraints are closed"
+NOTIFICATION_RIDE_GATES_NOT_CLOSED | "Not all gates are closed"
+NOTIFICATION_RIDE_GATE_NOT_CLOSED | "Gate %NAME% is not closed"
+NOTIFICATION_RIDE_COUNTER_UPDATE | "\nYou've ridden %RIDE_DISPLAY_NAME% %RIDE_COUNT% times now\n"
+NOTIFICATION_RIDE_STATE_OPEN | "%RIDE_DISPLAY_NAME% is now open"
+NOTIFICATION_RIDE_STATE_CLOSED | "%RIDE_DISPLAY_NAME% is now closed"
+NOTIFICATION_SHIFT_EXIT_CONFIRMATION | "Press shift again within 2 seconds to confirm exiting the ride"
+NOTIFICATION_SHIFT_EXIT_CONFIRMED | "You just exited the ride while the restraints were closed"
+NOTIFICATION_DISPATCH_WAIT_GENERIC | "Please wait until the ride is dispatched"
+NOTIFICATION_DISPATCH_WAIT_SPECIFIC | "Waiting time: %TIME% seconds"
+NOTIFICATION_RESTRAINT_ON_EXIT_ATTEMPT | "The restraints are closed"
+NOTIFICATION_RESTRAINT_ON_ENTER_ATTEMPT | "The restraints are closed"
+NOTIFICATION_RESTRAINT_ENTER_OVERRIDE | "You just entered the ride while the restraints were closed"
+NOTIFICATION_CANNOT_ENTER_RIDE | "You currently cannot enter this ride, try again later"
+NOTIFICATION_CANNOT_ENTER_RIDE_CLOSED | "This ride is currently closed"
+NOTIFICATION_OPERATOR_IDLE_TOO_LONG | "You were idle for too long while operating %RIDE_DISPLAY_NAME%"
+NOTIFICATION_WARPED | ""
+ELEVATED_OPERATOR_OVERRIDE_VICTIM_MESSAGE | "Player %PLAYER% took over control of the operating cabin"
+ERROR_SMOOTH_COASTERS_DISABLED | "Smoother ride experience is disabled, please install SmoothCoasters"
+ERROR_GENERAL_NO_PERMISSION_MESSAGE | "You do not have permissions to execute this action"
+ERROR_PLAYER_COMMAND_ONLY_MESSAGE | "Only players can execute this command"
+ERROR_UNKNOWN_COMMAND_MESSAGE | "Unknown jrides command. Type '/jrides help' for help"
+ERROR_OPERATING_CABIN_OCCUPIED | "You can not take this operating cabin since it is already in use by another operator"
+ERROR_OPERATING_NO_PERMISSION | "You are not allowed to operate this ride"
+ERROR_RIDE_CONTROL_MENU_NOT_FOUND | "Ride control menu was not found"
+ERROR_RIDE_OVERVIEW_MAP_NOT_FOUND | "Could not retrieve map for ride %RIDE_IDENTIFIER%, was the map id configured?"
+MENU_RIDE_OVERVIEW_TITLE | "Ride overview menu"
+MENU_RIDE_OVERVIEW_STATUS_OPEN | "This ride is currently opened"
+MENU_RIDE_OVERVIEW_STATUS_CLOSED | "This ride is currently closed"
+MENU_RIDE_OVERVIEW_STATUS_MAINTENANCE | "This ride is in maintenance"
+MENU_RIDE_CONTROL_TITLE | "Ride control menu"
+MENU_ADMIN_RIDE_CONTROL_TITLE | "Admin ride control menu"
+BUTTON_CLAIM_CABIN | "Claim operating cabin"
+BUTTON_CABIN_CLAIMED | "Claim operating cabin"
+BUTTON_DISPATCH_STATE | "Dispatch"
+BUTTON_DISPATCH_PROBLEM_STATE | "Not allowed"
+BUTTON_PROBLEMS_STATE | "Problems"
+BUTTON_GATES_OPEN_STATE | "Gates are open"
+BUTTON_GATES_CLOSED_STATE | "Gates are closed"
+BUTTON_RESTRAINTS_OPEN_STATE | "Restraints are open"
+BUTTON_RESTRAINTS_CLOSED_STATE | "Restraints are closed"
diff --git a/docs/permissions.md b/docs/permissions.md
new file mode 100644
index 00000000..7df2977c
--- /dev/null
+++ b/docs/permissions.md
@@ -0,0 +1,39 @@
+# Permissions
+
+## Default
+
+Permission | Description
+--- | ---
+jrides.default.ride_enter | Allow entering a ride
+jrides.default.warp | Allow warping (through menu)
+jrides.command.default.warp | Allow warping (through command)
+
+## Operator
+
+Permission | Description
+--- | ---
+jrides.operator.cabin_operate | Allow to operate in a ride cabin
+jrides.command.operator | Allow '/jrides control' command
+jrides.command.operator.dispatch | Allow '/jrides control dispatch' command
+jrides.command.operator.menu | Allow '/jrides control menu' command
+
+## Elevated (admin)
+
+Permission | Description
+--- | ---
+jrides.elevated.restraint_override | Allow to override restraint lock
+jrides.elevated.operator_override | Allow to take over an operator in a cabin
+jrides.elevated.closed_ride_enter_override | Allow to override closed ride entering
+jrides.elevated.open_state_change | Allow to open or close a ride
+jrides.command.elevated | Base for elevated commands (for admins)
+jrides.command.elevated.admin_menu | Allow to open ride admin menu
+jrides.command.elevated.ride_overview | Allow for generating a ride overview map
+jrides.command.elevated.block_section | Allow for getting block section occupation message (debug)
+jrides.command.elevated.visualize | Allow to visualize a coaster spline (debug)
+
+## Debug
+
+Permission | Description
+--- | ---
+jrides.elevated.status_inspection | Allow to inspect coaster frames (debug)
+
diff --git a/docs/plugin_update.md b/docs/plugin_update.md
new file mode 100644
index 00000000..70271d23
--- /dev/null
+++ b/docs/plugin_update.md
@@ -0,0 +1,43 @@
+# Plugin update
+
+To manually build jrides on a new spigot version, follow this guide.
+
+## 1. Run build tools
+
+Go to:
+https://www.spigotmc.org/wiki/buildtools/
+
+and download the latest BuildTools.
+
+Run BuildTools with the '--remapped' option, or in the gui with 'Remapped Jars'.
+
+## 2. Add new build profile to pom.xml
+```xml
+
+ jrides-1.20.1
+
+ true
+
+
+ 1.20.1
+ 1.20
+ 1.20
+
+
+```
+
+Make sure to select the new profile in your Maven configuration.
+
+## 3. Check dependency versioning
+ProtocolLib usually has a new version for the new minecraft version. Update all dependencies in maven and on your test server.
+
+## 4. Create a new PacketSender instance
+In the jrides repository, go to `com.jverbruggen.jrides.packets.impl` and create a new implementation for your new Minecraft version.
+
+Also make sure to register this implementation in the PacketSenderFactory.
+
+## 5. Update the maven workflow
+In jrides repository, go to .github/workflows and edit the maven.yml. Update the Action-SpigotMC version to the new latest version.
+
+## 6. Build with Maven
+Finally, run a jrides build with Maven.
\ No newline at end of file
diff --git a/docs/triggers.md b/docs/triggers.md
new file mode 100644
index 00000000..2d9813ae
--- /dev/null
+++ b/docs/triggers.md
@@ -0,0 +1,219 @@
+# Triggers
+
+Triggers are tools that are used for creating all sorts of effects alongside the rides themselves.
+'jrides' has various types of triggers, each of them listed below.
+
+## Adding triggers to a track
+
+### Summary
+
+Triggers can only exist when defined. Definitions can be found in multiple places.
+
+1. In the `.default.trigger.yml` file, used for placing triggers alongside the default track.
+2. In the `.coaster.yml` file ([link](./coaster_yml.md)), used for section types that support triggers, such as the `type: station` section type.
+3. In another track's trigger file, other than the default track. Just like the `.default.trigger.yml` file, each registered track can have its own trigger file. The trigger file name should be called `..trigger.yml`.
+
+### File structure
+
+As said, the file name of the general trigger.yml file is as follows: `..trigger.yml`. The contents of this file is defined here.
+
+```yml
+triggers:
+ :
+ frame:
+ :
+ frame:
+ ...
+```
+
+for example:
+
+```yml
+triggers:
+ start-chain-hook-sound:
+ frame: 500
+ stop-chain-hook-sound:
+ frame: 2300
+ people-scream-sound:
+ frame: 3100
+```
+
+Add as many triggers as you'd like.
+
+## Defining trigger behaviour
+
+### Summary
+
+Every trigger identifier has it's own configuration file as of what it does. These files can be found in the `coasters//triggers` folder.
+
+Each trigger that is defined in the general trigger.yml, needs a corresponding file in the triggers folder. The name of this file is equal to `.yml`
+
+For example, when using a trigger named `start-chain-hook-sound` that triggers at frame 500, a file with name `start-chain-hook-sound.yml` needs to be created in the triggers folder.
+
+### File structure
+
+Since jrides has multiple types of triggers, the structure of this file changes depending on which trigger is used. For every trigger, the following base structure is the same:
+
+```yml
+trigger:
+ type:
+```
+
+The `trigger_type` can be either one of the following values:
+
+* [type: multi-entity-movement](#type-multi-entity-movement)
+* [type: command](#type-command)
+* [type: eject](#type-eject)
+* [type: command-for-player](#type-command-for-player)
+* [type: command-as-player](#type-command-as-player)
+* [type: external](#type-external-for-developers)
+
+
+
+## Trigger specifications
+
+### type: multi-entity-movement
+
+The `multi-entity-movement` trigger can move several entities at once. Each entity has its own unique name under the `entities` attribute.
+
+An entity can have either an item that is displayed, or it can be a minecraft entity, such as a chicken or a horse. To see all item configuration options, check out [item.md](item.md).
+
+Motions can be defined in two distinct ways.
+1. From position -> To position (using the `locationFrom`, `locationTo`, `rotationFrom` and `rotationTo` keys)
+2. Initial position -> Continuous motion (until animation time ticks is reached)
+
+
+
+**From -> to animation**
+
+The from -> to animation type uses keys `locationFrom`, `locationTo`, `rotationFrom` and `rotationTo`, to create a linear path between two points.
+
+```yml
+trigger:
+ type: multi-entity-movement
+ entities:
+ :
+ item:
+ material: APPLE
+ entity: # item: and entity: cannot be used simultaneously
+ type: HORSE
+ animation:
+ 1:
+ locationFrom: [50.0, 10.0, 50.0] # [x, y, z]
+ locationTo: [50.0, 14.0, 50.0]
+ rotationFrom: [0.0, 0.0, 0.0] # [pitch, yaw, roll]
+ rotationTo: [0.0, 90.0, 0.0]
+ animationTimeTicks: 60 # Duration of animation in ticks
+ delayTicks: 0 # Duration of delay in ticks until the animation starts
+ 2:
+ locationFrom: [50, 14, 50]
+ locationTo: [50, 12, 50]
+ animationTimeTicks: 20
+```
+
+**Initial position -> Continuous motion**
+
+the initial -> Continuous motion type uses keys `initialLocation`, `initialRotation`, `locationDelta` and `rotationDeta` to create a continuous path after an initial location. Each tick, the delta location and rotation is added to the initials, creating a continuous motion. This can be useful for example for turning wheels.
+
+```yml
+trigger:
+ type: multi-entity-movement
+ entities:
+ :
+ item:
+ material: APPLE
+ animation:
+ 1:
+ initialLocation: [50.0, 10.0, 50.0] # [x, y, z]
+ initialRotation: [0, 0, 0] # [pitch, yaw, roll]
+ locationDelta: [0.0, 0.1, 0.0]
+ rotationDelta: [0.0, 1.0, 0.0]
+ resetOnStart: false # whether to set the entity back to its initial position every time
+ animationTimeTicks: 60 # Duration of animation in ticks
+ delayTicks: 0 # Duration of delay in ticks until the animation starts
+```
+
+
+---
+
+### type: eject
+The `eject` trigger allows to eject players early in a coaster. This is helpful (for example) when you want to eject players before the station was reached.
+
+```yml
+trigger:
+ type: eject
+ asFinished: true # Process the ejection as if the ride was finished. Default = true
+```
+---
+
+### type: command
+
+The `command` trigger allows for flexible linkage of jrides triggers to your plugins or minecraft commands. The command defined in this trigger is ran by the console, so be careful about what is filled in here.
+
+**! Be aware !** Using commands is usually not a 'best-practice' in most cases, and should only be used when the [external](#type-external-for-developers) trigger type is not a viable solution.
+
+```yml
+trigger:
+ type: command
+ command:
+```
+
+For example, if you want the server to run the command `/time set day`, the config would look as follows:
+
+```yml
+trigger:
+ type: command
+ command: time set day
+```
+
+If you want a command to be executed that is bound to a player, you should use the `command-for-player` type.
+
+---
+
+### type: command-for-player
+
+Just like the [command](#type-command) type, the `command-for-player` type is executed by the server. The main difference is that the command is executed for all passengers of the train that is passing the trigger. This means that for i.e. 6 passengers, the command is executed 6 times.
+
+```yml
+trigger:
+ type: command-for-player
+ command:
+```
+
+Use the `%PLAYER%` tag in your command to replace that bit of the command with the player's name.
+
+```yml
+trigger:
+ type: command-for-player
+ command: tell %PLAYER% Please stay seated!
+```
+
+If you'd like a command to be executed as if the player ran it themselves, you should use the `command-as-player` type.
+
+---
+
+### type: command-as-player
+
+In contrast to the [command](#type-command) type, the `command-as-player` type is executed by the player.
+
+```yml
+trigger:
+ type: command-as-player
+ command:
+```
+
+---
+
+### type: external (for developers)
+
+The external trigger allows you to listen for a bukkit event, that is dispatched by jrides. The event that is dispatched can be found in [ExternalTriggerEvent.java](../src/main/java/com/jverbruggen/jrides/event/ride/ExternalTriggerEvent.java).
+
+The trigger config file has a `data` attribute, where you can store any key and value as strings. Be aware not to use anything other than strings as values to this data attribute.
+
+```yml
+trigger:
+ type: external
+ data:
+ :
+ :
+```
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 00000000..ee3a186d
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,313 @@
+
+
+ 4.0.0
+
+ com.jverbruggen.jrides
+ jrides
+ 1.0_${minecraft.version.short}
+
+ jrides
+ Bring coasters to your Minecraft server!
+ https://github.com/JVerbruggen/jrides
+
+ 2023
+
+
+
+ J Verbruggen
+ JVerbruggen
+
+ Lead Developer
+
+
+
+
+
+
+ GPL-3.0
+ https://www.gnu.org/licenses/gpl-3.0.html
+
+
+
+
+ GitHub
+ https://github.com/JVerbruggen/jrides/issues
+
+
+
+ UTF-8
+ 17.0.5
+ 17
+ 17.0.5
+ 17.0.5
+
+
+ ${minecraft.version.short}
+
+ ${minecraft.version.short}-R0.1-SNAPSHOT
+ ${minecraft.version.short.spigot}-R0.1-SNAPSHOT
+
+ ${testServer.location}/plugins
+ jrides-api
+ /api
+
+ ${project.artifactId}${artifactFileNameSuffix}
+
+ ../jrides_testserver/${minecraft.version.short}
+
+
+
+
+ org.junit.jupiter
+ junit-jupiter
+ 5.10.2
+ test
+
+
+ org.spigotmc
+ spigot-api
+ ${minecraft.version}
+ provided
+
+
+ org.spigotmc
+ spigot
+ ${minecraft.version.spigot}
+ remapped-mojang
+ provided
+
+
+ me.m56738
+ SmoothCoastersAPI
+ 1.10
+ compile
+
+
+ de.tr7zw
+ item-nbt-api-plugin
+ 2.12.3
+
+
+ com.comphenix.protocol
+ ProtocolLib
+ 5.1.0
+ provided
+
+
+ com.sk89q.worldguard
+ worldguard-bukkit
+ 7.0.9
+ provided
+
+
+ com.google.code.gson
+ gson
+ 2.10.1
+
+
+
+ dev.cerus.maps
+ common
+ 3.8.3
+ compile
+
+
+ dev.cerus.maps
+ plugin
+ 3.8.3
+ compile
+
+
+ junit
+ junit
+ RELEASE
+ test
+
+
+ com.github.shynixn.structureblocklib
+ structureblocklib-bukkit-api
+ 2.13.0
+ provided
+
+
+
+
+
+
+ src/main/resources
+
+ plugin.yml
+
+ true
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.7.0
+
+ true
+ 512m
+ 2048m
+ ${java.versioneasy}
+ ${java.versioneasy}
+
+
+
+ net.md-5
+ specialsource-maven-plugin
+ 1.2.4
+
+
+ package
+
+ remap
+
+ remap-obf
+
+ org.spigotmc:minecraft-server:${minecraft.version.spigot}:txt:maps-mojang
+ true
+ org.spigotmc:spigot:${minecraft.version.spigot}:jar:remapped-mojang
+ true
+ remapped-obf
+
+
+
+ package
+
+ remap
+
+ remap-spigot
+
+ ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar
+ org.spigotmc:minecraft-server:${minecraft.version.spigot}:csrg:maps-spigot
+ org.spigotmc:spigot:${minecraft.version.spigot}:jar:remapped-obf
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 3.2.0
+
+
+ jrides-api
+ package
+
+ jar
+
+
+ api
+
+ com/jverbruggen/jrides/api/**/*.class
+ com/jverbruggen/jrides/event/**/*.class
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ 3.3.0
+
+
+
+ de.tr7zw.changeme.nbtapi
+ com.jverbruggen.jrides.nbtapi
+
+
+ com.google.code.gson
+ com.jverbruggen.jrides.gson
+
+
+
+
+
+ package
+
+ shade
+
+
+ ${artifactFileName}
+ ${project.artifactOutput}/${artifactFileName}.jar
+ ${project.artifactOutput}
+
+
+
+
+
+
+
+
+
+ spigot-repo
+ https://hub.spigotmc.org/nexus/content/repositories/snapshots/
+
+
+ sonatype
+ https://oss.sonatype.org/content/groups/public/
+
+
+
+ dmulloy2-repo
+ https://repo.dmulloy2.net/repository/public/
+
+
+ codemc-repo
+ https://repo.codemc.org/repository/maven-public/
+ default
+
+
+ sk89q-repo
+ https://maven.enginehub.org/repo/
+
+
+
+ mgdev-repo
+ https://ci.mg-dev.eu/plugin/repository/everything/
+
+
+
+
+
+ jrides-1.19.2
+
+ 1.19.2
+ 1.19.2
+ 1.19
+
+
+
+ jrides-1.20.1
+
+ 1.20.1
+ 1.20.1
+ 1.20
+
+
+
+ jrides-1.20.4
+
+ true
+
+
+ 1.20.4
+ 1.20.4
+ 1.20
+
+
+
+
+
+
+ maven-snapshots
+ https://repository.apache.org/content/repositories/snapshots/
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/com/jverbruggen/jrides/JRidesPlugin.java b/src/main/java/com/jverbruggen/jrides/JRidesPlugin.java
new file mode 100644
index 00000000..43cb7f0c
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/JRidesPlugin.java
@@ -0,0 +1,90 @@
+package com.jverbruggen.jrides;
+
+import com.jverbruggen.jrides.animator.smoothanimation.SmoothAnimation;
+import com.jverbruggen.jrides.language.LanguageFile;
+import com.jverbruggen.jrides.logging.JRidesLogger;
+import com.jverbruggen.jrides.logging.LogType;
+import com.jverbruggen.jrides.models.entity.BroadcastMessageReceiver;
+import com.jverbruggen.jrides.models.entity.MessageReceiver;
+import com.jverbruggen.jrides.packets.PacketSender;
+import com.jverbruggen.jrides.serviceprovider.ServiceProvider;
+import org.bukkit.Bukkit;
+import org.bukkit.World;
+import org.bukkit.plugin.java.JavaPlugin;
+
+import java.util.logging.Logger;
+
+public class JRidesPlugin {
+ private static JRidesLogger logger = null;
+ private static JavaPlugin plugin;
+ private static PacketSender packetSender;
+ private static SmoothAnimation smoothAnimation;
+ private static LanguageFile languageFile;
+ private static World world;
+ private static MessageReceiver broadcastMessageReceiver;
+
+ public static ServiceProvider getServiceProvider(){
+ return ServiceProvider.instance;
+ }
+
+ public static JavaPlugin getBukkitPlugin(){
+ if(plugin == null){
+ throw new RuntimeException("JRidesPlugin not defined since it is not yet enabled");
+ }
+
+ return plugin;
+ }
+
+ public static void setBukkitPluginHost(JavaPlugin plugin){
+ JRidesPlugin.plugin = plugin;
+ }
+
+ public static void initOtherStatics(){
+ packetSender = ServiceProvider.getSingleton(PacketSender.class);
+ smoothAnimation = ServiceProvider.getSingleton(SmoothAnimation.class);
+ logger = ServiceProvider.getSingleton(JRidesLogger.class);
+ languageFile = ServiceProvider.getSingleton(LanguageFile.class);
+ broadcastMessageReceiver = new BroadcastMessageReceiver();
+
+// logger.enableLogType(LogType.SECTIONS);
+ }
+
+ public static PacketSender getPacketSender() {
+ return packetSender;
+ }
+
+ public static SmoothAnimation getSmoothAnimation() {
+ return smoothAnimation;
+ }
+
+ public static JRidesLogger getLogger() {
+ if(logger == null){ // Only occurs when not running as plugin
+ logger = new JRidesLogger(Logger.getGlobal(), false, false);
+ }
+ return logger;
+ }
+
+ public static LanguageFile getLanguageFile() {
+ return languageFile;
+ }
+
+ public static void setWorld(World world) {
+ JRidesPlugin.world = world;
+ }
+
+ public static World getWorld() {
+ return world;
+ }
+
+ private static String getBukkitVersion(){
+ return Bukkit.getServer().getBukkitVersion().split("-")[0];
+ }
+
+ public static String getVersion() {
+ return getBukkitVersion() + "-j0.0";
+ }
+
+ public static MessageReceiver getBroadcastReceiver(){
+ return broadcastMessageReceiver;
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/Main.java b/src/main/java/com/jverbruggen/jrides/Main.java
new file mode 100644
index 00000000..e8abf2a4
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/Main.java
@@ -0,0 +1,114 @@
+package com.jverbruggen.jrides;
+
+import com.comphenix.protocol.ProtocolManager;
+import com.jverbruggen.jrides.command.MainCommandExecutor;
+import com.jverbruggen.jrides.common.MenuSessionManager;
+import com.jverbruggen.jrides.common.startup.StartMessage;
+import com.jverbruggen.jrides.config.ride.RideState;
+import com.jverbruggen.jrides.control.uiinterface.menu.button.event.ButtonClickEventListener;
+import com.jverbruggen.jrides.control.uiinterface.menu.open.SignMenuListener;
+import com.jverbruggen.jrides.listener.PlayerTeleportToRideListener;
+import com.jverbruggen.jrides.models.map.ridecounter.RideCounterMapListener;
+import com.jverbruggen.jrides.models.entity.listener.PassengerListener;
+import com.jverbruggen.jrides.models.ride.count.RideCounterRecordRideCollection;
+import com.jverbruggen.jrides.state.player.BukkitPlayerJoinEventListener;
+import com.jverbruggen.jrides.models.entity.Player;
+import com.jverbruggen.jrides.models.entity.agent.MessageAgentManagerListener;
+import com.jverbruggen.jrides.models.map.rideoverview.RideOverviewMapListener;
+import com.jverbruggen.jrides.models.ride.count.RideCounterListener;
+import com.jverbruggen.jrides.models.ride.count.RideCounterRecord;
+import com.jverbruggen.jrides.models.ride.count.RideCounterRecordCollection;
+import com.jverbruggen.jrides.packets.listener.VirtualEntityPacketListener;
+import com.jverbruggen.jrides.serviceprovider.ServiceProvider;
+import com.jverbruggen.jrides.serviceprovider.configuration.ServiceProviderConfigurator;
+import com.jverbruggen.jrides.state.player.PlayerManager;
+import com.jverbruggen.jrides.state.player.PlayerManagerListener;
+import com.jverbruggen.jrides.state.ride.RideCounterManager;
+import com.jverbruggen.jrides.state.ride.RideManager;
+import com.jverbruggen.jrides.state.ride.SoftEjector;
+import com.jverbruggen.jrides.state.ride.menu.RideMenuLoader;
+import com.jverbruggen.jrides.state.viewport.ViewportListener;
+import com.jverbruggen.jrides.state.viewport.ViewportManager;
+import org.bukkit.Bukkit;
+import org.bukkit.World;
+import org.bukkit.configuration.serialization.ConfigurationSerialization;
+import org.bukkit.plugin.PluginManager;
+import org.bukkit.plugin.java.JavaPlugin;
+
+public class Main extends JavaPlugin {
+ @Override
+ public void onEnable() {
+ World world = Bukkit.getWorld("Lobby");
+ JRidesPlugin.setWorld(world);
+
+ JRidesPlugin.setBukkitPluginHost(this);
+ ServiceProviderConfigurator.configure(this);
+ JRidesPlugin.initOtherStatics();
+
+ PlayerManager playerManager = ServiceProvider.getSingleton(PlayerManager.class);
+
+ PluginManager pluginManager = getServer().getPluginManager();
+ pluginManager.registerEvents(new BukkitPlayerJoinEventListener(), this);
+ pluginManager.registerEvents(new PlayerManagerListener(playerManager), this);
+ pluginManager.registerEvents(new ViewportListener(
+ ServiceProvider.getSingleton(ViewportManager.class),
+ playerManager), this);
+ pluginManager.registerEvents(new ButtonClickEventListener(), this);
+ pluginManager.registerEvents(new SignMenuListener("Control panel"), this);
+ pluginManager.registerEvents(new RideCounterListener(), this);
+ pluginManager.registerEvents(new RideOverviewMapListener(), this);
+ pluginManager.registerEvents(new RideCounterMapListener(), this);
+ pluginManager.registerEvents(new MessageAgentManagerListener(), this);
+ pluginManager.registerEvents(new PlayerTeleportToRideListener(), this);
+ pluginManager.registerEvents(new RideMenuLoader(), this);
+ pluginManager.registerEvents(new PassengerListener(), this);
+
+ ConfigurationSerialization.registerClass(RideCounterRecord.class);
+ ConfigurationSerialization.registerClass(RideCounterRecordCollection.class);
+ ConfigurationSerialization.registerClass(RideCounterRecordRideCollection.class);
+ ConfigurationSerialization.registerClass(RideState.class);
+
+ MainCommandExecutor commandExecutor = new MainCommandExecutor();
+ getServer().getPluginCommand("jrides").setTabCompleter(commandExecutor);
+ getServer().getPluginCommand("jrides").setExecutor(commandExecutor);
+
+ RideManager rideManager = ServiceProvider.getSingleton(RideManager.class);
+ rideManager.initAllRides(world);
+
+ ViewportManager viewportManager = ServiceProvider.getSingleton(ViewportManager.class);
+
+ for(org.bukkit.entity.Player bukkitPlayer : world.getPlayers()){
+ Player player = playerManager.getPlayer(bukkitPlayer);
+ getLogger().info("Initialising jrides for player " + bukkitPlayer.getName());
+ viewportManager.updateVisuals(player);
+ }
+
+ VirtualEntityPacketListener packetListener = ServiceProvider.getSingleton(VirtualEntityPacketListener.class);
+ ProtocolManager protocolManager = ServiceProvider.getSingleton(ProtocolManager.class);
+ protocolManager.addPacketListener(packetListener);
+
+ SoftEjector.startClock(this);
+
+ StartMessage.sendEnabledMessage();
+ }
+
+ @Override
+ public void onDisable() {
+ PlayerManager playerManager = ServiceProvider.getSingleton(PlayerManager.class);
+ ViewportManager viewportManager = ServiceProvider.getSingleton(ViewportManager.class);
+ RideManager rideManager = ServiceProvider.getSingleton(RideManager.class);
+ RideCounterManager rideCounterManager = ServiceProvider.getSingleton(RideCounterManager.class);
+ MenuSessionManager menuSessionManager = ServiceProvider.getSingleton(MenuSessionManager.class);
+
+ for(Player player : playerManager.getPlayers()){
+ player.clearSmoothAnimationRotation();
+ }
+
+ menuSessionManager.closeAllOpenMenus();
+ rideManager.unloadAllRides();
+ viewportManager.despawnAll();
+ rideCounterManager.saveAndUnloadAll();
+
+ StartMessage.sendDisabledMessage();
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/AbstractRideHandle.java b/src/main/java/com/jverbruggen/jrides/animator/AbstractRideHandle.java
new file mode 100644
index 00000000..dc9e9378
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/AbstractRideHandle.java
@@ -0,0 +1,199 @@
+package com.jverbruggen.jrides.animator;
+
+import com.jverbruggen.jrides.JRidesPlugin;
+import com.jverbruggen.jrides.common.permissions.Permissions;
+import com.jverbruggen.jrides.config.coaster.objects.SoundsConfig;
+import com.jverbruggen.jrides.config.ride.RideCounterMapConfigs;
+import com.jverbruggen.jrides.config.ride.RideState;
+import com.jverbruggen.jrides.control.controller.RideController;
+import com.jverbruggen.jrides.event.ride.RideStateUpdatedEvent;
+import com.jverbruggen.jrides.language.LanguageFileField;
+import com.jverbruggen.jrides.language.LanguageFileTag;
+import com.jverbruggen.jrides.models.entity.Player;
+import com.jverbruggen.jrides.models.menu.Menu;
+import com.jverbruggen.jrides.models.properties.PlayerLocation;
+import com.jverbruggen.jrides.models.ride.Ride;
+import com.jverbruggen.jrides.models.ride.count.RideCounterRecord;
+import org.bukkit.Sound;
+import org.bukkit.World;
+
+import javax.annotation.Nullable;
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class AbstractRideHandle implements RideHandle{
+ private World world;
+ private Ride ride;
+ private RideState rideState;
+ private boolean loaded;
+ private Menu rideControlMenu;
+ private RideController rideController;
+ private final SoundsConfig sounds;
+ private final PlayerLocation customEjectLocation;
+
+ private List topRideCounters;
+ private RideCounterMapConfigs rideCounterMapConfigs;
+
+ public AbstractRideHandle(World world, Ride ride, RideState rideState, boolean loaded, SoundsConfig sounds, PlayerLocation customEjectLocation, RideCounterMapConfigs rideCounterMapConfigs) {
+ this.world = world;
+ this.ride = ride;
+ this.rideState = rideState;
+ this.loaded = loaded;
+ this.customEjectLocation = customEjectLocation;
+ this.rideController = null;
+ this.topRideCounters = new ArrayList<>();
+
+ this.sounds = sounds;
+ this.rideCounterMapConfigs = rideCounterMapConfigs;
+ }
+
+ public World getWorld() {
+ return world;
+ }
+
+ @Override
+ public Ride getRide() {
+ return ride;
+ }
+
+ @Override
+ public RideState getState() {
+ return rideState;
+ }
+
+ @Override
+ public PlayerLocation getCustomEjectLocation() {
+ return customEjectLocation;
+ }
+
+ @Override
+ public void setState(RideState state) {
+ assert state != null;
+
+ this.rideState = state;
+ RideStateUpdatedEvent.send(ride, rideState);
+ }
+
+ @Override
+ public void unload(boolean save) {
+ if(!loaded) return;
+ if(save) rideState.save();
+ loaded = false;
+ JRidesPlugin.getLogger().info("Unloaded ride " + getRide().getDisplayName());
+ }
+
+ @Override
+ public boolean isLoaded() {
+ return loaded;
+ }
+
+
+ @Override
+ public void broadcastRideOpen() {
+ JRidesPlugin.getLanguageFile().sendMessage(
+ JRidesPlugin.getBroadcastReceiver(),
+ LanguageFileField.NOTIFICATION_RIDE_STATE_OPEN,
+ b -> b.add(LanguageFileTag.rideDisplayName, getRide().getDisplayName()));
+ }
+
+ @Override
+ public void broadcastRideClose() {
+ JRidesPlugin.getLanguageFile().sendMessage(
+ JRidesPlugin.getBroadcastReceiver(),
+ LanguageFileField.NOTIFICATION_RIDE_STATE_CLOSED,
+ b -> b.add(LanguageFileTag.rideDisplayName, getRide().getDisplayName()));
+ }
+
+ @Override
+ public void open(Player authority) {
+ if(!authority.hasPermission(Permissions.ELEVATED_RIDE_OPEN_STATE_CHANGE)){
+ JRidesPlugin.getLanguageFile().sendMessage(authority, LanguageFileField.ERROR_GENERAL_NO_PERMISSION_MESSAGE);
+ return;
+ }
+
+ boolean opened = getState().setStateOpened(this);
+ if(opened) authority.playSound(Sound.BLOCK_FENCE_GATE_OPEN);
+ else authority.playSound(Sound.UI_BUTTON_CLICK);
+ }
+
+ @Override
+ public void close(Player authority) {
+ if(!authority.hasPermission(Permissions.ELEVATED_RIDE_OPEN_STATE_CHANGE)){
+ JRidesPlugin.getLanguageFile().sendMessage(authority, LanguageFileField.ERROR_GENERAL_NO_PERMISSION_MESSAGE);
+ return;
+ }
+
+ attemptClose(authority);
+ }
+
+ private boolean attemptClose(@Nullable Player authority){
+ if(authority != null && !authority.hasPermission(Permissions.ELEVATED_RIDE_OPEN_STATE_CHANGE)){
+ JRidesPlugin.getLanguageFile().sendMessage(authority, LanguageFileField.ERROR_GENERAL_NO_PERMISSION_MESSAGE);
+ return false;
+ }
+
+ if(getState().getOpenState().isOpen()){
+ boolean closed = getState().setStateClosed(this);
+
+ if(authority != null){
+ if(!closed){
+ authority.playSound(Sound.UI_BUTTON_CLICK);
+ }else{
+ authority.playSound(Sound.BLOCK_FENCE_GATE_CLOSE);
+ }
+ }
+ }
+
+ Player currentOperator = getRideController().getOperator();
+ if(currentOperator != null) currentOperator.setOperating(null);
+ getRideControlMenu().sendUpdate();
+
+ if(getState().getOpenState().isClosing()){
+ if(canFullyClose()){
+ getState().setStateFullyClosed();
+ }else return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public RideController getRideController() {
+ return rideController;
+ }
+
+ @Override
+ public void setRideController(RideController rideController, Menu rideControlMenu) {
+ this.rideController = rideController;
+ this.rideControlMenu = rideControlMenu;
+ }
+
+ @Override
+ public Menu getRideControlMenu() {
+ return rideControlMenu;
+ }
+
+ @Override
+ public List getTopRideCounters() {
+ return topRideCounters;
+ }
+
+ public SoundsConfig getSounds() {
+ return sounds;
+ }
+
+
+ @Override
+ public boolean isOpen() {
+ return isLoaded() && getState().getOpenState().isOpen();
+ }
+
+ @Override
+ public boolean canFullyClose() {
+ return getPassengers().isEmpty();
+ }
+
+ public RideCounterMapConfigs getRideCounterMapConfigs() {
+ return rideCounterMapConfigs;
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/RideHandle.java b/src/main/java/com/jverbruggen/jrides/animator/RideHandle.java
new file mode 100644
index 00000000..f9719f84
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/RideHandle.java
@@ -0,0 +1,51 @@
+package com.jverbruggen.jrides.animator;
+
+import com.jverbruggen.jrides.config.coaster.objects.SoundsConfig;
+import com.jverbruggen.jrides.config.ride.RideState;
+import com.jverbruggen.jrides.control.controller.RideController;
+import com.jverbruggen.jrides.control.trigger.DispatchTrigger;
+import com.jverbruggen.jrides.control.trigger.TriggerContext;
+import com.jverbruggen.jrides.models.entity.Player;
+import com.jverbruggen.jrides.models.menu.Menu;
+import com.jverbruggen.jrides.models.properties.PlayerLocation;
+import com.jverbruggen.jrides.models.ride.Ride;
+import com.jverbruggen.jrides.models.ride.StationHandle;
+import com.jverbruggen.jrides.models.ride.count.RideCounterRecord;
+
+import javax.annotation.Nonnull;
+import java.util.List;
+
+public interface RideHandle {
+ void tick();
+ Ride getRide();
+ RideController getRideController();
+ Menu getRideControlMenu();
+ PlayerLocation getCustomEjectLocation();
+
+ void setRideController(RideController rideController, Menu rideControlMenu);
+ DispatchTrigger getDispatchTrigger();
+ TriggerContext getTriggerContext(@Nonnull String contextOwner);
+ TriggerContext getFirstTriggerContext();
+
+ PlayerLocation getEjectLocation();
+ List getStationHandles();
+
+ List getTopRideCounters();
+ List getPassengers();
+
+ void setState(RideState state);
+ RideState getState();
+ boolean isOpen();
+
+ void open(Player authority);
+ void close(Player authority);
+ boolean canFullyClose();
+
+ void broadcastRideOpen();
+ void broadcastRideClose();
+
+ void unload(boolean save);
+ boolean isLoaded();
+
+ SoundsConfig getSounds();
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/animatedjava/AnimatedJavaExecutor.java b/src/main/java/com/jverbruggen/jrides/animator/animatedjava/AnimatedJavaExecutor.java
new file mode 100644
index 00000000..b5263c5f
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/animatedjava/AnimatedJavaExecutor.java
@@ -0,0 +1,79 @@
+package com.jverbruggen.jrides.animator.animatedjava;
+
+import com.jverbruggen.jrides.models.math.Vector3;
+import org.bukkit.Bukkit;
+
+public class AnimatedJavaExecutor {
+ private final String rootEntityTag;
+ private final String rigName;
+ private final Vector3 location;
+ private boolean isSpawned;
+
+ public AnimatedJavaExecutor(String rootEntityTag, String rigName, Vector3 location) {
+ this.rootEntityTag = rootEntityTag;
+ this.rigName = rigName;
+ this.location = location;
+ this.isSpawned = false;
+ }
+
+ public boolean isSpawned(){
+ return isSpawned;
+ }
+
+ public void spawnRig(){
+ executeCommand(getSpawnRigCommand());
+ isSpawned = true;
+ }
+
+ public void playAnimation(String animationName){
+ if(!isSpawned) throw new RuntimeException("Rig was not spawned");
+ executeCommand(getPlayAnimationCommand(animationName));
+ }
+
+ public void removeRig(){
+ executeCommand(getRemoveRigCommand());
+ isSpawned = false;
+ }
+
+ public void removeAllRigs(){
+ executeCommand(getRemoveAllRigsCommand());
+ isSpawned = false;
+ }
+
+ private void executeCommand(String command){
+ Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
+ }
+
+ private String getSpawnRigCommand(){
+ return getRunFunctionBaseCommand() + "animated_java:" + rigName + "/summon";
+ }
+
+ private String getRemoveRigCommand(){
+ return getRunFunctionAsEntityBaseCommand() + "animated_java:" + rigName + "/remove/this";
+ }
+
+ private String getRemoveAllRigsCommand(){
+ return getRunFunctionBaseCommand() + "animated_java:" + rigName + "/remove/all";
+ }
+
+ private String getPlayAnimationCommand(String animationName){
+ return getRunFunctionAsEntityBaseCommand() + "animated_java:" + rigName + "/animations/" + animationName + "/play";
+ }
+
+ private String getRunFunctionAsEntityBaseCommand(){
+ return "execute " +
+ "positioned " + getLocationString() + " " +
+ "as @e[type=minecraft:item_display,tag=" + rootEntityTag + ",limit=1] " +
+ "run function ";
+ }
+
+ private String getRunFunctionBaseCommand(){
+ return "execute " +
+ "positioned " + getLocationString() + " " +
+ "run function ";
+ }
+
+ private String getLocationString(){
+ return location.getX() + " " + location.getY() + " " + location.getZ();
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/coaster/CoasterHandle.java b/src/main/java/com/jverbruggen/jrides/animator/coaster/CoasterHandle.java
new file mode 100644
index 00000000..887c5cca
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/coaster/CoasterHandle.java
@@ -0,0 +1,220 @@
+package com.jverbruggen.jrides.animator.coaster;
+
+import com.jverbruggen.jrides.JRidesPlugin;
+import com.jverbruggen.jrides.animator.AbstractRideHandle;
+import com.jverbruggen.jrides.animator.coaster.tool.ParticleTrackVisualisationTool;
+import com.jverbruggen.jrides.config.coaster.objects.SoundsConfig;
+import com.jverbruggen.jrides.config.ride.RideCounterMapConfigs;
+import com.jverbruggen.jrides.control.controller.RideController;
+import com.jverbruggen.jrides.control.trigger.DispatchTrigger;
+import com.jverbruggen.jrides.control.trigger.TriggerContext;
+import com.jverbruggen.jrides.effect.EffectTriggerCollection;
+import com.jverbruggen.jrides.effect.handle.cart.CartEffectTriggerHandle;
+import com.jverbruggen.jrides.effect.handle.train.TrainEffectTriggerHandle;
+import com.jverbruggen.jrides.models.entity.Player;
+import com.jverbruggen.jrides.models.properties.PlayerLocation;
+import com.jverbruggen.jrides.models.ride.CoasterStationHandle;
+import com.jverbruggen.jrides.models.ride.Ride;
+import com.jverbruggen.jrides.models.ride.StationHandle;
+import com.jverbruggen.jrides.models.ride.coaster.transfer.Transfer;
+import com.jverbruggen.jrides.models.ride.coaster.track.Track;
+import com.jverbruggen.jrides.models.ride.section.Unlockable;
+import org.bukkit.World;
+
+import javax.annotation.Nonnull;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class CoasterHandle extends AbstractRideHandle {
+ private Track track;
+ private ParticleTrackVisualisationTool visualisationTool;
+ private List stationHandles;
+ private List trains;
+ private final List transfers;
+ private final Map unlockables;
+ private EffectTriggerCollection trainEffectTriggerCollection;
+ private EffectTriggerCollection cartEffectTriggerCollection;
+
+ private final double dragConstant;
+ private final double gravityConstant;
+ private int rideOverviewMapId;
+ private final RideCounterMapConfigs rideCounterMapConfigs;
+
+ public CoasterHandle(Ride ride, World world, SoundsConfig sounds, PlayerLocation customEjectLocation, int rideOverviewMapId, boolean loaded, double dragConstant, double gravityConstant, RideCounterMapConfigs rideCounterMapConfigs) {
+ super(world, ride, null, loaded, sounds, customEjectLocation, rideCounterMapConfigs);
+ this.dragConstant = dragConstant;
+ this.gravityConstant = gravityConstant;
+
+ this.trains = new ArrayList<>();
+ this.stationHandles = new ArrayList<>();
+ this.transfers = new ArrayList<>();
+ this.unlockables = new HashMap<>();
+ this.visualisationTool = null;
+ this.track = null;
+ this.trainEffectTriggerCollection = null;
+ this.rideOverviewMapId = rideOverviewMapId;
+ this.rideCounterMapConfigs = rideCounterMapConfigs;
+ }
+
+ public double getDragConstant() {
+ return dragConstant;
+ }
+
+ public double getGravityConstant() {
+ return gravityConstant;
+ }
+
+ public int getRideOverviewMapId(){
+ return this.rideOverviewMapId;
+ }
+
+ public void setRideOverviewMapId(int rideOverviewMapId) {
+ if(rideOverviewMapId<0) throw new RuntimeException("Cannot set ride overview map id to a negative value");
+ this.rideOverviewMapId = rideOverviewMapId;
+ }
+
+ public void setTrains(List trains) {
+ this.trains = trains;
+ trains.forEach(t -> t.setCoasterHandle(this));
+ this.visualisationTool = ParticleTrackVisualisationTool.fromTrack(getWorld(), track, 20, trains);
+ }
+
+ public List getTrains() {
+ return trains;
+ }
+
+ public void setTrack(Track track) {
+ this.track = track;
+ }
+
+ public ParticleTrackVisualisationTool getVisualisationTool() {
+ return visualisationTool;
+ }
+
+ @Override
+ public DispatchTrigger getDispatchTrigger() {
+ return getStationHandle(null).getTriggerContext().getDispatchTrigger();
+ }
+
+ @Override
+ public TriggerContext getTriggerContext(@Nonnull String contextOwner) {
+ CoasterStationHandle stationHandle = getStationHandle(contextOwner);
+ if(stationHandle == null) return null;
+ return stationHandle.getTriggerContext();
+ }
+
+ @Override
+ public TriggerContext getFirstTriggerContext() {
+ return getStationHandles().get(0).getTriggerContext();
+ }
+
+ @Override
+ public PlayerLocation getEjectLocation() {
+ PlayerLocation customEjectLocation = getCustomEjectLocation();
+ if(customEjectLocation != null) return customEjectLocation;
+
+ return stationHandles.stream()
+ .filter(s -> s.getEjectLocation() != null)
+ .map(StationHandle::getEjectLocation)
+ .findFirst().orElse(null);
+ }
+
+ @Override
+ public List getStationHandles() {
+ return stationHandles.stream().map(h->(StationHandle)h).collect(Collectors.toList());
+ }
+
+ public void addStationHandle(CoasterStationHandle stationHandle) {
+ stationHandles.add(stationHandle);
+ }
+
+ public List getCoasterStationHandles() {
+ return stationHandles;
+ }
+
+ public CoasterStationHandle getStationHandle(String shortName){
+ if(getStationHandles().size() == 0){
+ JRidesPlugin.getLogger().severe("Looked for station with short name " + shortName + " but size was 0");
+ return null;
+ }
+
+ return stationHandles.stream()
+ .filter(s -> s.getShortName().equalsIgnoreCase(shortName))
+ .findFirst()
+ .orElseThrow(() -> {
+ String options = stationHandles.stream().map(StationHandle::getShortName).collect(Collectors.joining(", "));
+ return new RuntimeException("Station short name " + shortName + " did not exist. Existing stations: " + options);
+ });
+ }
+
+ public CoasterStationHandle getStationHandle(int index){
+ if(getStationHandles().size() <= index) return null;
+ return getCoasterStationHandles().get(index);
+ }
+
+ public boolean hasStation(){
+ return getStationHandles().size() > 0;
+ }
+
+ public void tick(){
+ if(!isLoaded()) return;
+
+ RideController rideController = getRideController();
+ if(rideController.isActive())
+ rideController.getControlMode().tick();
+
+ for(TrainHandle trainHandle : trains){
+ trainHandle.tick();
+ }
+ for(Transfer transfer : transfers){
+ transfer.tick();
+ }
+ }
+
+ public EffectTriggerCollection getTrainEffectTriggerCollection() {
+ return trainEffectTriggerCollection;
+ }
+
+ public void setTrainEffectTriggerCollection(EffectTriggerCollection trainEffectTriggerCollection) {
+ this.trainEffectTriggerCollection = trainEffectTriggerCollection;
+ }
+
+ public EffectTriggerCollection getCartEffectTriggerCollection() {
+ return cartEffectTriggerCollection;
+ }
+
+ public void setCartEffectTriggerCollection(EffectTriggerCollection cartEffectTriggerCollection) {
+ this.cartEffectTriggerCollection = cartEffectTriggerCollection;
+ }
+
+ public void addTransfer(Transfer transfer){
+ transfers.add(transfer);
+ }
+
+ public List getTransfers() {
+ return transfers;
+ }
+
+ public void addUnlockable(String identifier, Unlockable unlockable){
+ unlockables.put(identifier, unlockable);
+ }
+
+ public Unlockable getUnlockable(String identifier){
+ return unlockables.get(identifier);
+ }
+
+ public Track getTrack(){
+ return track;
+ }
+
+ @Override
+ public List getPassengers() {
+ return getTrains().stream()
+ .flatMap(trainHandle -> trainHandle.getTrain().getPassengers().stream())
+ .toList();
+ }
+
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/coaster/EffectHandler.java b/src/main/java/com/jverbruggen/jrides/animator/coaster/EffectHandler.java
new file mode 100644
index 00000000..d723e262
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/coaster/EffectHandler.java
@@ -0,0 +1,137 @@
+package com.jverbruggen.jrides.animator.coaster;
+
+import com.jverbruggen.jrides.effect.EffectTriggerCollection;
+import com.jverbruggen.jrides.effect.handle.EffectTriggerHandle;
+import com.jverbruggen.jrides.effect.handle.cart.CartEffectTriggerHandle;
+import com.jverbruggen.jrides.effect.handle.train.TrainEffectTriggerHandle;
+import com.jverbruggen.jrides.models.properties.frame.Frame;
+import com.jverbruggen.jrides.models.ride.coaster.train.CoasterCart;
+import com.jverbruggen.jrides.models.ride.coaster.train.Train;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Map;
+
+public class EffectHandler {
+ private final Train train;
+ private CoasterHandle coasterHandle;
+
+ private boolean hasEffects;
+ private TrainEffectTriggerHandle nextEffect;
+
+ private boolean hasCartEffects;
+ private final Map nextCartEffects;
+
+ public EffectHandler(Train train, Map nextCartEffects) {
+ this.train = train;
+ this.coasterHandle = null;
+ this.hasEffects = false;
+ this.nextEffect = null;
+ this.hasCartEffects = false;
+ this.nextCartEffects = nextCartEffects;
+ }
+
+ public void setCoasterHandle(CoasterHandle coasterHandle){
+ this.coasterHandle = coasterHandle;
+
+ EffectTriggerCollection trainEffectTriggerCollection = coasterHandle.getTrainEffectTriggerCollection();
+ if(trainEffectTriggerCollection != null && trainEffectTriggerCollection.size() > 0){
+ hasEffects = true;
+ }
+
+ EffectTriggerCollection cartEffectTriggerCollection = coasterHandle.getCartEffectTriggerCollection();
+ if(cartEffectTriggerCollection != null && cartEffectTriggerCollection.size() > 0){
+ hasCartEffects = true;
+ }
+
+ if(hasEffects || hasCartEffects)
+ resetEffectsRandomPos();
+ }
+
+ private void resetEffectsRandomPos(){
+ if(hasEffects){
+ nextEffect = EffectTriggerHandle.FindNearestNextEffect(
+ TrainEffectTriggerHandle.class,
+ coasterHandle.getTrainEffectTriggerCollection().getLinkedList(),
+ train.getHeadOfTrainFrame());
+
+// Bukkit.broadcastMessage("Next train effect: " + nextEffect.getFrame());
+ }
+
+ if(hasCartEffects){
+ LinkedList cartEffectLinkedList = coasterHandle.getCartEffectTriggerCollection().getLinkedList();
+
+ for(CoasterCart cart : train.getCarts()){
+ CartEffectTriggerHandle nextCartEffect = EffectTriggerHandle.FindNearestNextEffect(
+ CartEffectTriggerHandle.class,
+ cartEffectLinkedList,
+ cart.getFrame()
+ );
+ nextCartEffects.put(cart, nextCartEffect);
+
+// Bukkit.broadcastMessage("Next cart effect: " + nextCartEffect.getFrame());
+ }
+ }
+ }
+
+ public void resetEffects(){
+ if(hasEffects){
+ nextEffect = coasterHandle.getTrainEffectTriggerCollection().first();
+ }
+
+ if(hasCartEffects){
+ LinkedList cartEffectLinkedList = coasterHandle.getCartEffectTriggerCollection().getLinkedList();
+
+ for(CoasterCart cart : train.getCarts()){
+ CartEffectTriggerHandle nextCartEffect = cartEffectLinkedList.get(0);
+ nextCartEffects.put(cart, nextCartEffect);
+ }
+ }
+ }
+
+ private boolean shouldTrainEffect(TrainEffectTriggerHandle trainEffectTriggerHandle, Frame currentFrame){
+ return trainEffectTriggerHandle.shouldPlay(currentFrame);
+ }
+
+ public void playTrainEffects(Frame currentFrame){
+ while(nextEffect != null){
+ if(!shouldTrainEffect(nextEffect, currentFrame)) break;
+ boolean processNext = nextEffect.executeForTrain(train);
+ if(!processNext) break;
+
+ nextEffect = nextEffect.next();
+ }
+ }
+
+ private boolean shouldCartEffectPlay(CartEffectTriggerHandle cartEffectTriggerHandle, Frame currentFrame){
+ return cartEffectTriggerHandle.shouldPlay(currentFrame);
+ }
+
+ public void playCartEffects(CoasterCart cart){
+ Frame currentCartFrame = cart.getFrame();
+ CartEffectTriggerHandle nextCartEffect = nextCartEffects.get(cart);
+ while(nextCartEffect != null){
+ if(!shouldCartEffectPlay(nextCartEffect, currentCartFrame)) break;
+ boolean processNext = nextCartEffect.executeForCart(cart);
+ if(!processNext) break;
+
+ CartEffectTriggerHandle newNextEffect = nextCartEffect.next();
+ nextCartEffects.put(cart, newNextEffect);
+ nextCartEffect = newNextEffect;
+ }
+ }
+
+ public static EffectHandler createForTrain(Train train){
+ Map nextCartEffects = new HashMap<>();
+
+ for(CoasterCart cart : train.getCarts()){
+ nextCartEffects.put(cart, null);
+ }
+
+ return new EffectHandler(train, nextCartEffects);
+ }
+
+ public boolean hasCartEffects() {
+ return hasCartEffects;
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/coaster/NoLimitsExportPositionRecord.java b/src/main/java/com/jverbruggen/jrides/animator/coaster/NoLimitsExportPositionRecord.java
new file mode 100644
index 00000000..56d221a0
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/coaster/NoLimitsExportPositionRecord.java
@@ -0,0 +1,120 @@
+package com.jverbruggen.jrides.animator.coaster;
+
+import com.jverbruggen.jrides.models.math.Quaternion;
+import com.jverbruggen.jrides.models.math.Vector3;
+import org.bukkit.util.Vector;
+
+public class NoLimitsExportPositionRecord {
+ private final int index;
+ private final float posX;
+ private final float posY;
+ private final float posZ;
+ private final float frontX;
+ private final float frontY;
+ private final float frontZ;
+ private final float leftX;
+ private final float leftY;
+ private final float leftZ;
+ private final float upX;
+ private final float upY;
+ private final float upZ;
+ private final Quaternion orientation;
+
+ public NoLimitsExportPositionRecord(int index, float posX, float posY, float posZ, float frontX, float frontY, float frontZ, float leftX, float leftY, float leftZ, float upX, float upY, float upZ) {
+ this.index = index;
+ this.posX = posX;
+ this.posY = posY;
+ this.posZ = posZ;
+ this.frontX = frontX;
+ this.frontY = frontY;
+ this.frontZ = frontZ;
+ this.leftX = leftX;
+ this.leftY = leftY;
+ this.leftZ = leftZ;
+ this.upX = upX;
+ this.upY = upY;
+ this.upZ = upZ;
+
+ Vector dirVector = new Vector(leftX, leftY, leftZ).multiply(-1);
+ Vector upVector = new Vector(upX, upY, upZ);
+ this.orientation = Quaternion.fromLookDirection(dirVector, upVector);
+ }
+
+ public int getIndex() {
+ return index;
+ }
+
+ public float getPosX() {
+ return posX;
+ }
+
+ public float getPosY() {
+ return posY;
+ }
+
+ public float getPosZ() {
+ return posZ;
+ }
+
+ public float getFrontX() {
+ return frontX;
+ }
+
+ public float getFrontY() {
+ return frontY;
+ }
+
+ public float getFrontZ() {
+ return frontZ;
+ }
+
+ public float getLeftX() {
+ return leftX;
+ }
+
+ public float getLeftY() {
+ return leftY;
+ }
+
+ public float getLeftZ() {
+ return leftZ;
+ }
+
+ public float getUpX() {
+ return upX;
+ }
+
+ public float getUpY() {
+ return upY;
+ }
+
+ public float getUpZ() {
+ return upZ;
+ }
+
+ public Quaternion getOrientation() {
+ return orientation;
+ }
+
+ public Vector3 toVector3(){
+ return new Vector3(posX, posY, posZ);
+ }
+
+ public static NoLimitsExportPositionRecord createFromCSVAttributes(String[] attributes, int index,float offsetX, float offsetY, float offsetZ){
+ return new NoLimitsExportPositionRecord(
+ index,
+ Float.parseFloat(attributes[1]) + offsetX,
+ Float.parseFloat(attributes[2]) + offsetY,
+ Float.parseFloat(attributes[3]) + offsetZ,
+ Float.parseFloat(attributes[4]),
+ Float.parseFloat(attributes[5]),
+ Float.parseFloat(attributes[6]),
+ Float.parseFloat(attributes[7]),
+ Float.parseFloat(attributes[8]),
+ Float.parseFloat(attributes[9]),
+ Float.parseFloat(attributes[10]),
+ Float.parseFloat(attributes[11]),
+ Float.parseFloat(attributes[12])
+ );
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/coaster/TrainHandle.java b/src/main/java/com/jverbruggen/jrides/animator/coaster/TrainHandle.java
new file mode 100644
index 00000000..8a33f32e
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/coaster/TrainHandle.java
@@ -0,0 +1,158 @@
+package com.jverbruggen.jrides.animator.coaster;
+
+import com.jverbruggen.jrides.JRidesPlugin;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.TrackBehaviour;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.result.CartMovement;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.result.CartMovementFactory;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.result.TrainMovement;
+import com.jverbruggen.jrides.logging.LogType;
+import com.jverbruggen.jrides.models.entity.Player;
+import com.jverbruggen.jrides.models.math.Vector3;
+import com.jverbruggen.jrides.models.properties.frame.Frame;
+import com.jverbruggen.jrides.models.properties.Speed;
+import com.jverbruggen.jrides.models.properties.TrainEnd;
+import com.jverbruggen.jrides.models.ride.coaster.train.CoasterCart;
+import com.jverbruggen.jrides.models.ride.coaster.track.Track;
+import com.jverbruggen.jrides.models.ride.coaster.train.Train;
+import com.jverbruggen.jrides.models.ride.section.provider.SectionProvider;
+import com.jverbruggen.jrides.serviceprovider.ServiceProvider;
+import org.bukkit.SoundCategory;
+
+import java.util.Map;
+import java.util.Set;
+
+public class TrainHandle {
+ private final Train train;
+ private final Track track;
+ private final Speed speedBPS;
+ private TrackBehaviour trackBehaviour;
+ private final SectionProvider sectionProvider;
+ private final CartMovementFactory cartMovementFactory;
+ private CoasterHandle coasterHandle;
+
+ private final EffectHandler effectHandler;
+
+ private final int windSoundInterval;
+ private int windSoundState;
+
+ public TrainHandle(SectionProvider sectionProvider, Train train, Track track) {
+ this.sectionProvider = sectionProvider;
+ this.cartMovementFactory = ServiceProvider.getSingleton(CartMovementFactory.class);
+ this.train = train;
+ this.track = track;
+ this.trackBehaviour = train.getHeadSection().getTrackBehaviour();
+ this.speedBPS = new Speed(0);
+ this.coasterHandle = null;
+ this.effectHandler = EffectHandler.createForTrain(train);
+
+ this.train.setHandle(this);
+
+ this.windSoundInterval = 4;
+ this.windSoundState = 0;
+ }
+
+ public void tick(){
+ if(train.isCrashed()) return;
+
+ // --- Calculate movement that should be applied to the train
+ TrainMovement result = trackBehaviour.move(speedBPS, this, train.getHeadSection());
+ if(result == null) return;
+
+ // --- Apply movement: new head frame and speed
+ speedBPS.setSpeed(result.getNewSpeed().getSpeedPerTick());
+
+ // --- Move carts according to instructions
+ Set> cartMovements = cartMovementFactory.createOnTrackCartMovement(train.getHandle(), train.getCarts(), result.getNewSpeed().getFrameIncrement(), null).entrySet();
+ if(cartMovements != null){
+ for(Map.Entry cartMovement : cartMovements){
+ CoasterCart cart = cartMovement.getKey();
+ CartMovement movement = cartMovement.getValue();
+ cart.setPosition(movement);
+ cart.playEffects();
+ }
+ }
+
+ Frame trainHeadOfTrainFrame = train.getHeadOfTrainFrame();
+ Frame trainMiddleOfTrainFrame = train.getMiddleOfTrainFrame();
+ Frame trainTailOfTrainFrame = train.getTailOfTrainFrame();
+
+ boolean headAppliesBehaviour = speedBPS.isGoingForwards();
+ boolean tailAppliesBehaviour = !headAppliesBehaviour;
+
+ // Both Head and Tail update section occupations: if going forwards: head locks next and tail unlocks previous
+ sectionProvider.addFramesWithSectionLogic(this, trainHeadOfTrainFrame, result.getNewHeadOfTrainFrame().getValue(),
+ true, TrainEnd.HEAD, "HEAD", headAppliesBehaviour);
+ sectionProvider.addFramesWithSectionLogic(this, trainMiddleOfTrainFrame, result.getNewMiddleOfTrainFrame().getValue());
+ sectionProvider.addFramesWithSectionLogic(this, trainTailOfTrainFrame, result.getNewTailOfTrainFrame().getValue(),
+ true, TrainEnd.TAIL, "TAIL", tailAppliesBehaviour);
+
+ JRidesPlugin.getLogger().info(LogType.SECTIONS_DETAIL, trainHeadOfTrainFrame + " -= "
+ + trainMiddleOfTrainFrame + " =- " + trainTailOfTrainFrame);
+
+ // --- Set new train location according to new frames
+ Vector3 headLocation = track.getLocationFor(trainHeadOfTrainFrame);
+ Vector3 middleLocation = track.getLocationFor(trainMiddleOfTrainFrame);
+ Vector3 tailLocation = track.getLocationFor(trainTailOfTrainFrame);
+ train.setCurrentLocation(headLocation, middleLocation, tailLocation);
+
+ sendPositionUpdatesToListeners("HEAD", trainHeadOfTrainFrame);
+ sendPositionUpdatesToListeners("MIDD", trainMiddleOfTrainFrame);
+ sendPositionUpdatesToListeners("TAIL", trainTailOfTrainFrame);
+ train.sendPositionMessage("SPEED: " + speedBPS);
+
+ effectHandler.playTrainEffects(trainHeadOfTrainFrame);
+ if(effectHandler.hasCartEffects()){
+ for(CoasterCart cart : train.getCarts()){
+ effectHandler.playCartEffects(cart);
+ }
+ }
+ playWindSounds();
+ }
+
+ private void sendPositionUpdatesToListeners(String identifier, Frame currentFrame) {
+ train.sendPositionMessage(identifier + ": " + currentFrame.toString());
+ }
+
+
+ private void playWindSounds(){
+ String sound = coasterHandle.getSounds().getOnrideWind();
+ if(sound == null) return;
+ if(windSoundState < windSoundInterval)
+ windSoundState++;
+ else{
+ for(Player player : train.getPassengers()){
+ float pitch = (float)Math.abs(speedBPS.getSpeedPerTick() / 10) + 0.4f;
+ float volume = Math.abs((pitch - 0.3f) / 5) - 0.05f;
+ player.getBukkitPlayer().playSound(player.getBukkitPlayer().getLocation(),
+ sound, SoundCategory.MASTER, volume, pitch);
+ }
+ windSoundState = 0;
+ }
+ }
+
+ public Train getTrain() {
+ return train;
+ }
+
+ public void setCoasterHandle(CoasterHandle coasterHandle) {
+ this.coasterHandle = coasterHandle;
+
+ this.effectHandler.setCoasterHandle(coasterHandle);
+ }
+
+ public CoasterHandle getCoasterHandle() {
+ return coasterHandle;
+ }
+
+ public Speed getSpeed() {
+ return speedBPS;
+ }
+
+ public void setTrackBehaviour(TrackBehaviour trackBehaviour) {
+ this.trackBehaviour = trackBehaviour;
+ }
+
+ public void resetEffects() {
+ effectHandler.resetEffects();
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/coaster/tool/ParticleTrackVisualisationTool.java b/src/main/java/com/jverbruggen/jrides/animator/coaster/tool/ParticleTrackVisualisationTool.java
new file mode 100644
index 00000000..6f1b58a4
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/coaster/tool/ParticleTrackVisualisationTool.java
@@ -0,0 +1,69 @@
+package com.jverbruggen.jrides.animator.coaster.tool;
+
+import com.jverbruggen.jrides.animator.coaster.TrainHandle;
+import com.jverbruggen.jrides.models.entity.Player;
+import com.jverbruggen.jrides.models.math.Vector3;
+import com.jverbruggen.jrides.models.ride.coaster.track.Track;
+import com.jverbruggen.jrides.models.ride.coaster.train.CoasterCart;
+import org.bukkit.Location;
+import org.bukkit.Particle;
+import org.bukkit.World;
+
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+public class ParticleTrackVisualisationTool extends ParticleVisualisationTool {
+ private List locations;
+ private World world;
+ private List sectionSplitLocations;
+ private List trains;
+
+ public ParticleTrackVisualisationTool(World world, List locations, List sectionSplitLocations, List trains){
+ super(5);
+ this.world = world;
+ this.locations = locations;
+ this.sectionSplitLocations = sectionSplitLocations;
+ this.trains = trains;
+ }
+
+ public static ParticleTrackVisualisationTool fromTrack(World world, Track track, int takeOneInX, List trains){
+ List positions = track.getAllPositions();
+
+ List sectionSplitLocations = track.getSections().stream()
+ .map(s -> s.getParentTrack().getLocationFor(s.getEndFrame()).toBukkitLocation(world))
+ .collect(Collectors.toList());
+
+ List locations = IntStream
+ .range(0, positions.size())
+ .filter(i -> i % takeOneInX == 0)
+ .mapToObj(i -> positions.get(i).toBukkitLocation(world))
+ .collect(Collectors.toList());
+
+ return new ParticleTrackVisualisationTool(world, locations, sectionSplitLocations, trains);
+ }
+
+ @Override
+ public void tick(){
+ for(Player viewer : getViewers()){
+ spawnVisualisationParticles(viewer);
+ }
+ }
+
+ public void spawnVisualisationParticles(Player player){
+ org.bukkit.entity.Player bukkitPlayer = player.getBukkitPlayer();
+ for(Location location : locations){
+ bukkitPlayer.spawnParticle(Particle.VILLAGER_HAPPY, location, 1, 0.01, 0.01, 0.01, 0);
+ }
+ for(Location splitSectionLocation : sectionSplitLocations){
+ bukkitPlayer.spawnParticle(Particle.CRIT_MAGIC, splitSectionLocation, 5, 0.01, 1, 0.01, 0);
+ }
+ for(TrainHandle train : trains){
+ bukkitPlayer.spawnParticle(Particle.DRIP_WATER, train.getTrain().getCurrentHeadLocation().toBukkitLocation(world), 5, 0.01, 1, 0.01, 0);
+ for(CoasterCart cart : train.getTrain().getCarts()){
+ bukkitPlayer.spawnParticle(Particle.VILLAGER_HAPPY, cart.getPosition().toBukkitLocation(world), 5, 0.01, 1, 0.01, 0);
+ }
+ bukkitPlayer.spawnParticle(Particle.DRIP_LAVA, train.getTrain().getCurrentTailLocation().toBukkitLocation(world), 5, 0.01, 1, 0.01, 0);
+ }
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/coaster/tool/ParticleTrainVisualisationTool.java b/src/main/java/com/jverbruggen/jrides/animator/coaster/tool/ParticleTrainVisualisationTool.java
new file mode 100644
index 00000000..da10502b
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/coaster/tool/ParticleTrainVisualisationTool.java
@@ -0,0 +1,29 @@
+package com.jverbruggen.jrides.animator.coaster.tool;
+
+import com.jverbruggen.jrides.models.entity.Player;
+import com.jverbruggen.jrides.models.ride.coaster.train.Train;
+import org.bukkit.Particle;
+import org.bukkit.World;
+
+public class ParticleTrainVisualisationTool extends ParticleVisualisationTool {
+ private World world;
+ private Train train;
+
+ public ParticleTrainVisualisationTool(World world, Train train){
+ super(5);
+ this.world = world;
+ this.train = train;
+ }
+
+ @Override
+ public void tick(){
+ for(Player viewer : getViewers()){
+ spawnVisualisationParticles(viewer);
+ }
+ }
+
+ public void spawnVisualisationParticles(Player player){
+ org.bukkit.entity.Player bukkitPlayer = player.getBukkitPlayer();
+ bukkitPlayer.spawnParticle(Particle.VILLAGER_HAPPY, train.getCurrentHeadLocation().toBukkitLocation(world), 1, 0.01, 0.01, 0.01, 0);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/coaster/tool/ParticleVisualisationTool.java b/src/main/java/com/jverbruggen/jrides/animator/coaster/tool/ParticleVisualisationTool.java
new file mode 100644
index 00000000..f79fa6a2
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/coaster/tool/ParticleVisualisationTool.java
@@ -0,0 +1,56 @@
+package com.jverbruggen.jrides.animator.coaster.tool;
+
+import com.jverbruggen.jrides.JRidesPlugin;
+import com.jverbruggen.jrides.models.entity.Player;
+import org.bukkit.Bukkit;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class ParticleVisualisationTool {
+ private List viewers;
+ private int taskId;
+ private int interval;
+
+ public abstract void tick();
+
+ public ParticleVisualisationTool(int interval) {
+ this.viewers = new ArrayList<>();
+ this.taskId = -1;
+ this.interval = interval;
+ }
+
+ public List getViewers() {
+ return viewers;
+ }
+
+ public void addViewer(Player player){
+ viewers.add(player);
+
+ if(taskId == -1) runNewTask();
+ }
+
+ public void removeViewer(Player player){
+ viewers.remove(player);
+
+ if(viewers.size() == 0) cancelTask();
+ }
+
+ public boolean isViewer(Player player){
+ return viewers.contains(player);
+ }
+
+ private void runNewTask(){
+ if(taskId == -1){
+ taskId = Bukkit.getScheduler().runTaskTimer(JRidesPlugin.getBukkitPlugin(), this::tick, interval, interval).getTaskId();
+ }else throw new RuntimeException("Task set moment unexpected");
+ }
+
+ private void cancelTask(){
+ if(taskId != -1){
+ Bukkit.getScheduler().cancelTask(taskId);
+ taskId = -1;
+ }else throw new RuntimeException("Task cancel moment unexpected");
+ }
+
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/BaseTrackBehaviour.java b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/BaseTrackBehaviour.java
new file mode 100644
index 00000000..bff22a11
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/BaseTrackBehaviour.java
@@ -0,0 +1,158 @@
+package com.jverbruggen.jrides.animator.coaster.trackbehaviour;
+
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.result.CartMovementFactory;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.result.TrainMovement;
+import com.jverbruggen.jrides.models.math.Quaternion;
+import com.jverbruggen.jrides.models.math.Vector3;
+import com.jverbruggen.jrides.models.properties.frame.Frame;
+import com.jverbruggen.jrides.models.properties.Speed;
+import com.jverbruggen.jrides.models.ride.coaster.track.Track;
+import com.jverbruggen.jrides.models.ride.coaster.train.Train;
+import com.jverbruggen.jrides.models.ride.section.Section;
+import com.jverbruggen.jrides.models.ride.section.reference.SectionReference;
+import com.jverbruggen.jrides.models.ride.section.result.BlockSectionSafetyResult;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+public abstract class BaseTrackBehaviour implements TrackBehaviour {
+ protected final CartMovementFactory cartMovementFactory;
+ protected Track parentTrack;
+
+ protected BaseTrackBehaviour(CartMovementFactory cartMovementFactory) {
+ this.cartMovementFactory = cartMovementFactory;
+ this.parentTrack = null;
+ }
+
+ protected BlockSectionSafetyResult getNextSectionSafety(Train train){
+ Section nextSection = train.getNextSection();
+ if(nextSection == null) return new BlockSectionSafetyResult(false, train, "No next section present");
+ return nextSection.getBlockSectionSafety(train);
+ }
+
+ protected boolean shouldReserveNextSection(Train train){
+ Section nextSection = train.getNextSection();
+ if(nextSection == null) return false;
+ return nextSection.getReservedBy() != train;
+ }
+
+ protected TrainMovement calculateTrainMovement(Train train, Section section, Speed speed){
+ if(speed.isZero()){
+ return new TrainMovement(speed, train.getHeadOfTrainFrame(), train.getMiddleOfTrainFrame(), train.getTailOfTrainFrame(), train.getCurrentLocation(), null);
+ }
+
+ int speedFrameIncrement = speed.getFrameIncrement();
+
+ Frame newHeadOfTrainFrame = train.getHeadOfTrainFrame().clone().add(speedFrameIncrement);
+ Frame newMiddleOfTrainFrame = train.getMiddleOfTrainFrame().clone().add(speedFrameIncrement);
+ Frame newTailOfTrainFrame = train.getTailOfTrainFrame().clone().add(speedFrameIncrement);
+
+ Vector3 newTrainLocation = newMiddleOfTrainFrame.getSection().getLocationFor(newMiddleOfTrainFrame);
+
+
+ return new TrainMovement(speed, newHeadOfTrainFrame, newMiddleOfTrainFrame, newTailOfTrainFrame, newTrainLocation, null);
+ }
+
+ protected abstract void setParentTrackOnFrames(Track parentTrack);
+
+ @Override
+ public void setParentTrack(Track parentTrack) {
+ this.parentTrack = parentTrack;
+ setParentTrackOnFrames(parentTrack);
+ }
+
+ @Override
+ public Track getParentTrack() {
+ return parentTrack;
+ }
+
+ @Override
+ public Section getSectionAtEnd(Train train, boolean process) {
+ return null;
+ }
+
+ @Override
+ public Section getSectionAtStart(Train train, boolean process) {
+ return null;
+ }
+
+ @Override
+ public void trainPassed(Train train) {
+
+ }
+
+ @Override
+ public boolean definesNextSection() {
+ return false;
+ }
+
+ @Override
+ public Vector3 getBehaviourDefinedPosition(Vector3 originalPosition) {
+ return originalPosition;
+ }
+
+ @Override
+ public Quaternion getBehaviourDefinedOrientation(Quaternion originalOrientation) {
+ return originalOrientation;
+ }
+
+ @Override
+ public boolean accepts(Train train) {
+ return true;
+ }
+
+ @Override
+ public Section getSectionNext(Train train, boolean process) {
+ return getSectionAtEnd(train, process);
+ }
+
+ @Override
+ public Section getSectionPrevious(Train train, boolean process) {
+ return getSectionAtStart(train, process);
+ }
+
+ @Override
+ public Collection getAllNextSections(Train train) {
+ return List.of(getSectionNext(train, false));
+ }
+
+ @Override
+ public Collection getAllPreviousSections(Train train) {
+ return List.of(getSectionPrevious(train, false));
+ }
+
+ @Override
+ public void populateSectionReferences(Map sectionMap) {
+ }
+
+ @Override
+ public boolean definesNextAccepting() {
+ return false;
+ }
+
+ @Override
+ public Section acceptAsNext(Train train, boolean canProcessPassed) {
+ return null;
+ }
+
+ @Override
+ public boolean canHandleBlockSectionSafety() {
+ return false;
+ }
+
+ @Override
+ public boolean canHandleConnections() {
+ return false;
+ }
+
+ @Override
+ public boolean nextConnectsToStart() {
+ return true;
+ }
+
+ @Override
+ public boolean previousConnectsToStart() {
+ return false;
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/FreeMovementTrackBehaviour.java b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/FreeMovementTrackBehaviour.java
new file mode 100644
index 00000000..ecfcd7a6
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/FreeMovementTrackBehaviour.java
@@ -0,0 +1,99 @@
+package com.jverbruggen.jrides.animator.coaster.trackbehaviour;
+
+import com.jverbruggen.jrides.animator.coaster.TrainHandle;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.result.CartMovementFactory;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.result.TrainMovement;
+import com.jverbruggen.jrides.models.math.Quaternion;
+import com.jverbruggen.jrides.models.math.Vector3;
+import com.jverbruggen.jrides.models.properties.frame.Frame;
+import com.jverbruggen.jrides.models.properties.Speed;
+import com.jverbruggen.jrides.models.ride.coaster.track.Track;
+import com.jverbruggen.jrides.models.ride.coaster.train.Train;
+import com.jverbruggen.jrides.models.ride.section.Section;
+
+import javax.annotation.Nullable;
+
+public class FreeMovementTrackBehaviour extends BaseTrackBehaviour {
+ private final double gravityConstant;
+ private final double dragConstant;
+
+ public FreeMovementTrackBehaviour(CartMovementFactory cartMovementFactory, double gravityConstant, double dragConstant) {
+ super(cartMovementFactory);
+
+ this.gravityConstant = gravityConstant;
+ this.dragConstant = dragConstant;
+ }
+
+ public TrainMovement move(Speed currentSpeed, TrainHandle trainHandle, Section section) {
+ Train train = trainHandle.getTrain();
+ Speed newSpeed = calculateGravityActedSpeed(trainHandle, section, currentSpeed, gravityConstant, dragConstant);
+
+ return calculateTrainMovement(train, section, newSpeed);
+ }
+
+ @Override
+ public void trainExitedAtStart(@Nullable Train train, @Nullable Section section) {
+
+ }
+
+ @Override
+ public void trainExitedAtEnd(@Nullable Train train, @Nullable Section section) {
+
+ }
+
+ @Override
+ public String getName() {
+ return "FreeMovement";
+ }
+
+ @Override
+ public boolean canBlock() {
+ return false;
+ }
+
+ @Override
+ public boolean canSpawnOn() {
+ return false;
+ }
+
+ @Override
+ public Frame getSpawnFrame() {
+ return null;
+ }
+
+ @Override
+ protected void setParentTrackOnFrames(Track parentTrack) {
+
+ }
+
+ private static double getGravityPitch(Train train, Vector3 newHeadOfTrainLocation, Vector3 newTailOfTrainLocation){
+ if(train.getCarts().size() == 1){
+ int forwardsMulti = -1;
+ if(!train.isFacingForwards())
+ forwardsMulti = 1;
+ return forwardsMulti * train.getCarts().get(0).getOrientation().getRoll();
+ }else{
+ Vector3 headTailDifference = Vector3.subtract(newHeadOfTrainLocation, newTailOfTrainLocation);
+ return Quaternion.fromLookDirection(headTailDifference.toBukkitVector()).getPitch();
+ }
+ }
+
+ public static Speed calculateGravityActedSpeed(TrainHandle trainHandle, Section section, Speed currentSpeed, double gravityConstant, double dragConstant){
+ // --- New mass middle calculation
+ Train train = trainHandle.getTrain();
+ Section backFacingSection = train.getBackFacingTrainFrame().getSection();
+ Vector3 newForwardsFacingFrameLocation = section.getLocationFor(train.getFrontFacingTrainFrame());
+ Vector3 newBackwardsFacingFrameLocation = backFacingSection.getLocationFor(train.getBackFacingTrainFrame());
+
+ // --- Gravity speed calculation
+ Speed newSpeed = currentSpeed.clone();
+ double pitch = getGravityPitch(train, newForwardsFacingFrameLocation, newBackwardsFacingFrameLocation);
+
+ double dy = Math.sin(pitch/180*3.141592);
+
+ newSpeed.add(dy * gravityConstant);
+ newSpeed.multiply(dragConstant);
+
+ return newSpeed;
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/LaunchTrackBehaviour.java b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/LaunchTrackBehaviour.java
new file mode 100644
index 00000000..67a753a0
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/LaunchTrackBehaviour.java
@@ -0,0 +1,169 @@
+package com.jverbruggen.jrides.animator.coaster.trackbehaviour;
+
+import com.jverbruggen.jrides.animator.coaster.TrainHandle;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.result.CartMovementFactory;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.result.TrainMovement;
+import com.jverbruggen.jrides.effect.handle.train.TrainEffectTriggerHandle;
+import com.jverbruggen.jrides.models.properties.frame.Frame;
+import com.jverbruggen.jrides.models.properties.Speed;
+import com.jverbruggen.jrides.models.ride.coaster.track.Track;
+import com.jverbruggen.jrides.models.ride.coaster.train.Train;
+import com.jverbruggen.jrides.models.ride.section.Section;
+
+import javax.annotation.Nullable;
+import java.util.List;
+
+public class LaunchTrackBehaviour extends BaseTrackBehaviour {
+ private final boolean canSpawn;
+ private final double deceleration;
+ private final double acceleration;
+ private final double driveSpeed;
+ private final boolean forwardsLaunch;
+
+ private final int waitTicks;
+ private final Frame engageFrame;
+ private final double launchAcceleration;
+ private final double launchSpeed;
+ private final double launchSpeedBackward;
+ private final List launchEffectTriggers;
+
+ private int waitTicksState;
+ private LaunchPhase phase;
+
+ public LaunchTrackBehaviour(CartMovementFactory cartMovementFactory, boolean canSpawn, double driveSpeed, double deceleration, double acceleration, boolean forwardsLaunch, int waitTicks, Frame engageFrame, double launchAcceleration, double launchSpeed, double launchSpeedBackward, List launchEffectTriggers) {
+ super(cartMovementFactory);
+ this.canSpawn = canSpawn;
+ this.deceleration = deceleration;
+ this.acceleration = acceleration;
+ this.driveSpeed = driveSpeed;
+ this.forwardsLaunch = forwardsLaunch;
+ this.waitTicks = waitTicks;
+ this.engageFrame = engageFrame;
+ this.launchSpeed = launchSpeed;
+ this.launchAcceleration = launchAcceleration;
+ this.launchSpeedBackward = launchSpeedBackward;
+ this.launchEffectTriggers = launchEffectTriggers;
+
+ this.phase = LaunchPhase.IDLE;
+ this.waitTicksState = 0;
+ }
+
+ @Override
+ public TrainMovement move(Speed currentSpeed, TrainHandle trainHandle, Section section) {
+ Speed newSpeed = currentSpeed.clone();
+ Train train = trainHandle.getTrain();
+
+ boolean goIntoSwitch = true;
+ while(goIntoSwitch) {
+ goIntoSwitch = false;
+ switch (this.phase) {
+ case IDLE:
+ if(waitTicks < 0 && getNextSectionSafety(train).safe()){
+ train.getNextSection().setEntireBlockReservation(train);
+ this.phase = LaunchPhase.LAUNCHING;
+ }else{
+ this.phase = LaunchPhase.DRIVING;
+ }
+
+ goIntoSwitch = true;
+ break;
+ case DRIVING:
+ if (train.getHeadSection().hasPassed(engageFrame, train.getHeadOfTrainFrame())) {
+ this.phase = LaunchPhase.STOPPING;
+ goIntoSwitch = true;
+ }else{
+ newSpeed.approach(acceleration, deceleration, driveSpeed);
+ }
+ break;
+ case STOPPING:
+ if(newSpeed.isZero()){
+ phase = LaunchPhase.WAITING;
+ goIntoSwitch = true;
+ }
+ newSpeed.minus(deceleration, 0);
+ break;
+ case WAITING:
+ if(getNextSectionSafety(train).safe() && doneWaiting()){
+ phase = LaunchPhase.LAUNCHING_FROM_STANDSTILL;
+ train.getNextSection().setEntireBlockReservation(train);
+ goIntoSwitch = true;
+ playLaunchEffects(train);
+ }
+ break;
+ case LAUNCHING_FROM_STANDSTILL:
+ if(forwardsLaunch){
+ newSpeed.approach(launchAcceleration, launchAcceleration, launchSpeed);
+ }else{
+ newSpeed.approach(launchAcceleration, launchAcceleration, -launchSpeedBackward);
+ }
+ break;
+ case LAUNCHING:
+ newSpeed.approach(launchAcceleration, launchAcceleration, launchSpeed);
+ break;
+ }
+ }
+
+ return calculateTrainMovement(train, section, newSpeed);
+ }
+
+ private void playLaunchEffects(Train train){
+ if(launchEffectTriggers == null) return;
+ launchEffectTriggers.forEach(e -> e.executeForTrain(train));
+ }
+
+ private void reset(){
+ waitTicksState = 0;
+ phase = LaunchPhase.IDLE;
+ }
+
+ private boolean doneWaiting(){
+ if(waitTicksState >= waitTicks)
+ return true;
+ waitTicksState++;
+ return false;
+ }
+
+ @Override
+ public void trainExitedAtStart(@Nullable Train train, @Nullable Section section) {
+ reset();
+ }
+
+ @Override
+ public void trainExitedAtEnd(@Nullable Train train, @Nullable Section section){
+ reset();
+ }
+
+ @Override
+ public String getName() {
+ return "Launch";
+ }
+
+ @Override
+ public boolean canBlock() {
+ return true;
+ }
+
+ @Override
+ public boolean canSpawnOn() {
+ return canSpawn;
+ }
+
+ @Override
+ public Frame getSpawnFrame() {
+ return engageFrame;
+ }
+
+ @Override
+ protected void setParentTrackOnFrames(Track parentTrack) {
+ engageFrame.setTrack(parentTrack);
+ }
+}
+
+enum LaunchPhase{
+ IDLE,
+ DRIVING,
+ STOPPING,
+ WAITING,
+ LAUNCHING_FROM_STANDSTILL,
+ LAUNCHING
+}
\ No newline at end of file
diff --git a/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/ProximityUtils.java b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/ProximityUtils.java
new file mode 100644
index 00000000..70c6bd4a
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/ProximityUtils.java
@@ -0,0 +1,26 @@
+package com.jverbruggen.jrides.animator.coaster.trackbehaviour;
+
+import com.jverbruggen.jrides.models.ride.coaster.train.Train;
+
+import java.util.List;
+
+public class ProximityUtils {
+ public static boolean isTooCloseToOtherTrains(Train train, List otherTrains, double minTrainDistance){
+ boolean tooCloseToOther = false;
+ int trainFrameValue = train.getMiddleOfTrainFrame().getValue();
+
+ for(Train otherTrain : otherTrains){
+ if(otherTrain == train) continue;
+
+ int otherTrainFrameValue = otherTrain.getMiddleOfTrainFrame().getValue();
+ if(otherTrainFrameValue < trainFrameValue)
+ break; // Do not care about trains behind us
+
+ int distanceFrom = otherTrainFrameValue - trainFrameValue;
+ if(distanceFrom < minTrainDistance){
+ tooCloseToOther = true;
+ }
+ }
+ return tooCloseToOther;
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/TrackBehaviour.java b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/TrackBehaviour.java
new file mode 100644
index 00000000..630548e7
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/TrackBehaviour.java
@@ -0,0 +1,55 @@
+package com.jverbruggen.jrides.animator.coaster.trackbehaviour;
+
+import com.jverbruggen.jrides.animator.coaster.TrainHandle;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.result.TrainMovement;
+import com.jverbruggen.jrides.models.math.Quaternion;
+import com.jverbruggen.jrides.models.math.Vector3;
+import com.jverbruggen.jrides.models.properties.frame.Frame;
+import com.jverbruggen.jrides.models.properties.Speed;
+import com.jverbruggen.jrides.models.ride.coaster.track.Track;
+import com.jverbruggen.jrides.models.ride.coaster.train.Train;
+import com.jverbruggen.jrides.models.ride.section.Section;
+import com.jverbruggen.jrides.models.ride.section.reference.SectionReference;
+
+import javax.annotation.Nullable;
+import java.util.Collection;
+import java.util.Map;
+
+public interface TrackBehaviour {
+ TrainMovement move(Speed currentSpeed, TrainHandle trainHandle, Section section);
+ void trainExitedAtStart(@Nullable Train train, @Nullable Section section);
+ void trainExitedAtEnd(@Nullable Train train, @Nullable Section section);
+ void trainPassed(Train train);
+
+ String getName();
+ boolean canBlock();
+ boolean canSpawnOn();
+ Frame getSpawnFrame();
+
+ void setParentTrack(Track parentTrack);
+ Track getParentTrack();
+
+ Section getSectionNext(Train train, boolean process);
+ Section getSectionPrevious(Train train, boolean process);
+ Section getSectionAtStart(Train train, boolean process);
+ Section getSectionAtEnd(Train train, boolean process);
+ boolean accepts(Train train);
+
+ Collection getAllNextSections(Train train);
+ Collection getAllPreviousSections(Train train);
+
+ boolean definesNextSection();
+ Vector3 getBehaviourDefinedPosition(Vector3 originalPosition);
+ Quaternion getBehaviourDefinedOrientation(Quaternion originalOrientation);
+
+ void populateSectionReferences(Map sectionMap);
+
+ boolean definesNextAccepting();
+ Section acceptAsNext(Train train, boolean canProcessPassed);
+
+ boolean canHandleBlockSectionSafety();
+
+ boolean canHandleConnections();
+ boolean previousConnectsToStart();
+ boolean nextConnectsToStart();
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/drive/BlockBrakeTrackBehaviour.java b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/drive/BlockBrakeTrackBehaviour.java
new file mode 100644
index 00000000..dd01b120
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/drive/BlockBrakeTrackBehaviour.java
@@ -0,0 +1,155 @@
+package com.jverbruggen.jrides.animator.coaster.trackbehaviour.drive;
+
+import com.jverbruggen.jrides.animator.coaster.TrainHandle;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.BaseTrackBehaviour;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.result.CartMovementFactory;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.result.TrainMovement;
+import com.jverbruggen.jrides.models.properties.Speed;
+import com.jverbruggen.jrides.models.properties.frame.Frame;
+import com.jverbruggen.jrides.models.ride.coaster.track.Track;
+import com.jverbruggen.jrides.models.ride.coaster.train.Train;
+import com.jverbruggen.jrides.models.ride.section.Section;
+import com.jverbruggen.jrides.models.ride.section.result.BlockSectionSafetyResult;
+
+import javax.annotation.Nullable;
+
+public class BlockBrakeTrackBehaviour extends BaseTrackBehaviour {
+ private final double deceleration;
+ private final double acceleration;
+ private final double driveSpeed;
+
+ private BlockBrakePhase phase;
+ private final Frame stopFrame;
+ private final boolean canSpawn;
+
+ private final int minWaitTicks;
+ private int minWaitTicksState;
+
+ public BlockBrakeTrackBehaviour(CartMovementFactory cartMovementFactory, Frame stopFrame, boolean canSpawn, double driveSpeed, double deceleration, double acceleration, int minWaitTicks) {
+ super(cartMovementFactory);
+ this.deceleration = deceleration;
+ this.acceleration = acceleration;
+ this.driveSpeed = driveSpeed;
+ this.phase = BlockBrakePhase.IDLE;
+ this.stopFrame = stopFrame;
+ this.canSpawn = canSpawn;
+
+ this.minWaitTicks = minWaitTicks;
+ this.minWaitTicksState = 0;
+
+ trainExitedAtEnd(null, null);
+ }
+
+ @Override
+ public TrainMovement move(Speed currentSpeed, TrainHandle trainHandle, Section section) {
+ Speed newSpeed = currentSpeed.clone();
+ Train train = trainHandle.getTrain();
+
+ boolean goIntoSwitch = true;
+ while(goIntoSwitch){
+ goIntoSwitch = false;
+ switch (phase){
+ case IDLE:
+ train.setStatusMessage("Idle");
+ if(getNextSectionSafety(train).safe() && minWaitTicks <= 0){
+ phase = BlockBrakePhase.DRIVING;
+ train.getNextSection().setEntireBlockReservation(train);
+ } else
+ phase = BlockBrakePhase.DRIVING_UNTIL_STOP;
+ goIntoSwitch = true;
+ break;
+ case DRIVING_UNTIL_STOP:
+ train.setStatusMessage("Driving until stop");
+ if(train.getHeadSection().hasPassed(stopFrame, train.getHeadOfTrainFrame())){
+ if(getNextSectionSafety(train).safe() && minWaitTicks <= 0){
+ phase = BlockBrakePhase.DRIVING;
+ train.getNextSection().setEntireBlockReservation(train);
+ }else{
+ phase = BlockBrakePhase.STOPPING;
+ }
+ goIntoSwitch = true;
+ }else{
+ newSpeed.approach(acceleration, deceleration, driveSpeed);
+ }
+ break;
+ case STOPPING:
+ train.setStatusMessage("Stopping" + newSpeed.getSpeedPerTick());
+ if(newSpeed.isZero()){
+ phase = BlockBrakePhase.WAITING;
+ goIntoSwitch = true;
+ }
+ newSpeed.minus(deceleration, 0);
+ break;
+ case WAITING:
+ BlockSectionSafetyResult safetyResult = getNextSectionSafety(train);
+ train.setStatusMessage("Waiting \n" + train.getHeadSection() + "\n"
+ + train.getHeadSection().next(train) + " safety: " + safetyResult);
+ if(safetyResult.safe() && isMinWaitTimerFinished()){
+ train.getNextSection().setEntireBlockReservation(train);
+ resetMinWaitTimer();
+ phase = BlockBrakePhase.DRIVING;
+ goIntoSwitch = true;
+ }
+ break;
+ case DRIVING:
+ train.setStatusMessage("Driving");
+ newSpeed.approach(acceleration, deceleration, driveSpeed);
+ break;
+ }
+ }
+
+ return calculateTrainMovement(train, section, newSpeed);
+ }
+
+ private boolean isMinWaitTimerFinished(){
+ if(minWaitTicks <= 0) return true;
+ return minWaitTicksState++ >= minWaitTicks;
+ }
+
+ private void resetMinWaitTimer(){
+ minWaitTicksState = 0;
+ }
+
+ @Override
+ public void trainExitedAtStart(@Nullable Train train, @Nullable Section section) {
+
+ }
+
+ @Override
+ public void trainExitedAtEnd(@Nullable Train train, @Nullable Section section){
+ this.phase = BlockBrakePhase.IDLE;
+ }
+
+ @Override
+ public String getName() {
+ return "BlockBrake";
+ }
+
+ @Override
+ public boolean canBlock() {
+ return true;
+ }
+
+ @Override
+ public boolean canSpawnOn() {
+ return canSpawn;
+ }
+
+ @Override
+ public Frame getSpawnFrame() {
+ return stopFrame;
+ }
+
+ @Override
+ protected void setParentTrackOnFrames(Track parentTrack) {
+ stopFrame.setTrack(parentTrack);
+ }
+}
+
+enum BlockBrakePhase{
+ IDLE,
+ DRIVING_UNTIL_STOP,
+ STOPPING,
+ WAITING,
+ DRIVING
+}
\ No newline at end of file
diff --git a/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/drive/BrakeAndDriveTrackBehaviour.java b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/drive/BrakeAndDriveTrackBehaviour.java
new file mode 100644
index 00000000..8d1e2838
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/drive/BrakeAndDriveTrackBehaviour.java
@@ -0,0 +1,81 @@
+package com.jverbruggen.jrides.animator.coaster.trackbehaviour.drive;
+
+import com.jverbruggen.jrides.animator.coaster.TrainHandle;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.BaseTrackBehaviour;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.result.CartMovementFactory;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.result.TrainMovement;
+import com.jverbruggen.jrides.models.properties.frame.Frame;
+import com.jverbruggen.jrides.models.properties.Speed;
+import com.jverbruggen.jrides.models.ride.coaster.track.Track;
+import com.jverbruggen.jrides.models.ride.coaster.train.Train;
+import com.jverbruggen.jrides.models.ride.section.Section;
+
+import javax.annotation.Nullable;
+
+public class BrakeAndDriveTrackBehaviour extends BaseTrackBehaviour {
+ private final boolean isIgnoreDirection;
+ private final double deceleration;
+ private final double acceleration;
+ private final double driveSpeed;
+
+ public BrakeAndDriveTrackBehaviour(CartMovementFactory cartMovementFactory, boolean isIgnoreDirection, double driveSpeed, double deceleration, double acceleration) {
+ super(cartMovementFactory);
+ this.isIgnoreDirection = isIgnoreDirection;
+ this.deceleration = deceleration;
+ this.acceleration = acceleration;
+ this.driveSpeed = driveSpeed;
+ }
+
+ @Override
+ public TrainMovement move(Speed currentSpeed, TrainHandle trainHandle, Section section) {
+ Speed newSpeed = currentSpeed.clone();
+ Train train = trainHandle.getTrain();
+
+ if(isIgnoreDirection){
+ if(newSpeed.isPositive()){
+ newSpeed.approach(acceleration, deceleration, driveSpeed);
+ }else{
+ newSpeed.approach(acceleration, deceleration, -driveSpeed);
+ }
+ }else{
+ newSpeed.approach(acceleration, deceleration, driveSpeed);
+ }
+
+ return calculateTrainMovement(train, section, newSpeed);
+ }
+
+ @Override
+ public void trainExitedAtStart(@Nullable Train train, @Nullable Section section) {
+
+ }
+
+ @Override
+ public void trainExitedAtEnd(@Nullable Train train, @Nullable Section section){
+
+ }
+
+ @Override
+ public String getName() {
+ return "BrakeAndDrive";
+ }
+
+ @Override
+ public boolean canBlock() {
+ return false;
+ }
+
+ @Override
+ public boolean canSpawnOn() {
+ return false;
+ }
+
+ @Override
+ public Frame getSpawnFrame() {
+ return null;
+ }
+
+ @Override
+ protected void setParentTrackOnFrames(Track parentTrack) {
+
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/drive/DriveAndReleaseTrackBehaviour.java b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/drive/DriveAndReleaseTrackBehaviour.java
new file mode 100644
index 00000000..ca497525
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/drive/DriveAndReleaseTrackBehaviour.java
@@ -0,0 +1,137 @@
+package com.jverbruggen.jrides.animator.coaster.trackbehaviour.drive;
+
+import com.jverbruggen.jrides.animator.coaster.TrainHandle;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.BaseTrackBehaviour;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.FreeMovementTrackBehaviour;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.result.CartMovementFactory;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.result.TrainMovement;
+import com.jverbruggen.jrides.models.properties.Speed;
+import com.jverbruggen.jrides.models.properties.frame.Frame;
+import com.jverbruggen.jrides.models.ride.coaster.track.Track;
+import com.jverbruggen.jrides.models.ride.coaster.train.Train;
+import com.jverbruggen.jrides.models.ride.section.Section;
+
+import javax.annotation.Nullable;
+
+enum DriveAndReleasePhase{
+ IDLE,
+ DRIVING,
+ STOPPING,
+ WAITING,
+ RELEASE,
+}
+
+public class DriveAndReleaseTrackBehaviour extends BaseTrackBehaviour {
+ private final double deceleration;
+ private final double acceleration;
+ private final double driveSpeed;
+ private DriveAndReleasePhase phase;
+ private final Frame stopFrame;
+ private final int minWaitTicks;
+ private int minWaitTicksState;
+ private final double gravityConstant;
+ private final double dragConstant;
+
+ public DriveAndReleaseTrackBehaviour(CartMovementFactory cartMovementFactory, double driveSpeed, double deceleration, double acceleration, Frame stopFrame, int minWaitTicks, double gravityConstant, double dragConstant) {
+ super(cartMovementFactory);
+ this.deceleration = deceleration;
+ this.acceleration = acceleration;
+ this.driveSpeed = driveSpeed;
+ this.stopFrame = stopFrame;
+ this.minWaitTicks = minWaitTicks;
+ this.gravityConstant = gravityConstant;
+ this.dragConstant = dragConstant;
+ this.minWaitTicksState = 0;
+ this.phase = DriveAndReleasePhase.IDLE;
+ }
+
+ @Override
+ public TrainMovement move(Speed currentSpeed, TrainHandle trainHandle, Section section) {
+ Speed newSpeed = currentSpeed.clone();
+ Train train = trainHandle.getTrain();
+
+ boolean goIntoSwitch = true;
+ while(goIntoSwitch){
+ goIntoSwitch = false;
+ switch (phase){
+ case IDLE -> {
+ minWaitTicksState = 0;
+ phase = DriveAndReleasePhase.DRIVING;
+ goIntoSwitch = true;
+ }
+ case DRIVING -> {
+ if(shouldStop(train)){
+ phase = DriveAndReleasePhase.STOPPING;
+ goIntoSwitch = true;
+ }else{
+ newSpeed.approach(acceleration, deceleration, driveSpeed);
+ }
+ }
+ case STOPPING -> {
+ newSpeed.approach(acceleration, deceleration, 0);
+ if(newSpeed.isZero()){
+ phase = DriveAndReleasePhase.WAITING;
+ goIntoSwitch = true;
+ }
+ }
+ case WAITING -> {
+ if(++minWaitTicksState >= minWaitTicks){
+ phase = DriveAndReleasePhase.RELEASE;
+ goIntoSwitch = true;
+ }
+ }
+ case RELEASE -> newSpeed = FreeMovementTrackBehaviour.calculateGravityActedSpeed(
+ trainHandle, section, currentSpeed, gravityConstant, dragConstant
+ );
+ }
+ }
+
+ return calculateTrainMovement(train, section, newSpeed);
+ }
+
+ private boolean shouldStop(Train train){
+ if (driveSpeed >= 0)
+ return train.getHeadSection().hasPassed(stopFrame, train.getHeadOfTrainFrame());
+ return train.getHeadSection().hasPassedInverse(stopFrame, train.getHeadOfTrainFrame());
+ }
+
+ private void trainExited(){
+ this.phase = DriveAndReleasePhase.IDLE;
+ minWaitTicksState = 0;
+ }
+
+ @Override
+ public void trainExitedAtStart(@Nullable Train train, @Nullable Section section) {
+ trainExited();
+ }
+
+ @Override
+ public void trainExitedAtEnd(@Nullable Train train, @Nullable Section section){
+ trainExited();
+ }
+
+ @Override
+ public String getName() {
+ return "DriveAndRelease";
+ }
+
+ @Override
+ public boolean canBlock() {
+ return false;
+ }
+
+ @Override
+ public boolean canSpawnOn() {
+ return false;
+ }
+
+ @Override
+ public Frame getSpawnFrame() {
+ return null;
+ }
+
+ @Override
+ protected void setParentTrackOnFrames(Track parentTrack) {
+
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/drive/DriveStopDriveTrackBehaviour.java b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/drive/DriveStopDriveTrackBehaviour.java
new file mode 100644
index 00000000..33ba43cf
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/drive/DriveStopDriveTrackBehaviour.java
@@ -0,0 +1,134 @@
+package com.jverbruggen.jrides.animator.coaster.trackbehaviour.drive;
+
+import com.jverbruggen.jrides.animator.coaster.TrainHandle;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.BaseTrackBehaviour;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.result.CartMovementFactory;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.result.TrainMovement;
+import com.jverbruggen.jrides.models.properties.frame.Frame;
+import com.jverbruggen.jrides.models.properties.Speed;
+import com.jverbruggen.jrides.models.ride.coaster.track.Track;
+import com.jverbruggen.jrides.models.ride.coaster.train.Train;
+import com.jverbruggen.jrides.models.ride.section.Section;
+
+import javax.annotation.Nullable;
+
+
+enum DriveStopDrivePhase {
+ IDLE,
+ DRIVING_IN,
+ STOPPING,
+ WAITING,
+ DRIVING_OUT
+}
+
+public class DriveStopDriveTrackBehaviour extends BaseTrackBehaviour {
+ private DriveStopDrivePhase phase;
+ private final int minWaitTicks;
+ private int minWaitTicksState;
+
+ private final Frame stopFrame;
+ private final double deceleration;
+ private final double acceleration;
+ private final double driveSpeedIn;
+ private final double driveSpeedOut;
+
+ public DriveStopDriveTrackBehaviour(CartMovementFactory cartMovementFactory, int minWaitTicks, Frame stopFrame, double deceleration, double acceleration, double driveSpeedIn, double driveSpeedOut) {
+ super(cartMovementFactory);
+
+ this.minWaitTicks = minWaitTicks;
+ this.stopFrame = stopFrame;
+ this.deceleration = deceleration;
+ this.acceleration = acceleration;
+ this.driveSpeedIn = driveSpeedIn;
+ this.driveSpeedOut = driveSpeedOut;
+ trainExitedAtEnd(null, null);
+ }
+
+ @Override
+ public TrainMovement move(Speed currentSpeed, TrainHandle trainHandle, Section section) {
+ Speed newSpeed = currentSpeed.clone();
+ Train train = trainHandle.getTrain();
+
+ boolean goIntoSwitch = true;
+ while(goIntoSwitch){
+ goIntoSwitch = false;
+ switch (phase){
+ case IDLE -> {
+ minWaitTicksState = 0;
+ phase = DriveStopDrivePhase.DRIVING_IN;
+ goIntoSwitch = true;
+ }
+ case DRIVING_IN -> {
+ if(shouldStop(train)){
+ phase = DriveStopDrivePhase.STOPPING;
+ goIntoSwitch = true;
+ }else{
+ newSpeed.approach(acceleration, deceleration, driveSpeedIn);
+ }
+ }
+ case STOPPING -> {
+ newSpeed.approach(acceleration, deceleration, 0);
+ if(newSpeed.isZero()){
+ phase = DriveStopDrivePhase.WAITING;
+ goIntoSwitch = true;
+ }
+ }
+ case WAITING -> {
+ if(++minWaitTicksState >= minWaitTicks){
+ phase = DriveStopDrivePhase.DRIVING_OUT;
+ goIntoSwitch = true;
+ }
+ }
+ case DRIVING_OUT -> newSpeed.approach(acceleration, deceleration, driveSpeedOut);
+ }
+ }
+
+ return calculateTrainMovement(train, section, newSpeed);
+ }
+
+ private boolean shouldStop(Train train){
+ if (driveSpeedIn >= 0)
+ return train.getHeadSection().hasPassed(stopFrame, train.getHeadOfTrainFrame());
+ return train.getHeadSection().hasPassedInverse(stopFrame, train.getHeadOfTrainFrame());
+ }
+
+ @Override
+ public void trainExitedAtStart(@Nullable Train train, @Nullable Section section) {
+ trainExited();
+ }
+
+ @Override
+ public void trainExitedAtEnd(@Nullable Train train, @Nullable Section section) {
+ trainExited();
+ }
+
+ private void trainExited(){
+ this.phase = DriveStopDrivePhase.IDLE;
+ this.minWaitTicksState = this.minWaitTicks;
+ }
+
+ @Override
+ public String getName() {
+ return "DriveStopDrive";
+ }
+
+ @Override
+ public boolean canBlock() {
+ return false;
+ }
+
+ @Override
+ public boolean canSpawnOn() {
+ return false;
+ }
+
+ @Override
+ public Frame getSpawnFrame() {
+ return null;
+ }
+
+ @Override
+ protected void setParentTrackOnFrames(Track parentTrack) {
+
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/drive/ProximityDriveTrackBehaviour.java b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/drive/ProximityDriveTrackBehaviour.java
new file mode 100644
index 00000000..488fb94f
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/drive/ProximityDriveTrackBehaviour.java
@@ -0,0 +1,218 @@
+package com.jverbruggen.jrides.animator.coaster.trackbehaviour.drive;
+
+import com.jverbruggen.jrides.animator.coaster.TrainHandle;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.BaseTrackBehaviour;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.ProximityUtils;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.result.CartMovementFactory;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.result.TrainMovement;
+import com.jverbruggen.jrides.models.properties.Speed;
+import com.jverbruggen.jrides.models.properties.frame.Frame;
+import com.jverbruggen.jrides.models.ride.coaster.track.Track;
+import com.jverbruggen.jrides.models.ride.coaster.train.Train;
+import com.jverbruggen.jrides.models.ride.section.Section;
+import com.jverbruggen.jrides.models.ride.section.SectionSafetyProvider;
+import com.jverbruggen.jrides.models.ride.section.result.BlockSectionSafetyResult;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+
+public class ProximityDriveTrackBehaviour extends BaseTrackBehaviour implements SectionSafetyProvider {
+ private final boolean canSpawn;
+ private final double deceleration;
+ private final double acceleration;
+ private final double driveSpeed;
+ private final double minTrainDistance;
+ private final Frame stopFrame;
+ private final HashMap trainPhases;
+ private final List reservations;
+
+ public ProximityDriveTrackBehaviour(CartMovementFactory cartMovementFactory, boolean canSpawn, double driveSpeed, double deceleration, double acceleration, double minTrainDistance, Frame stopFrame) {
+ super(cartMovementFactory);
+ this.canSpawn = canSpawn;
+ this.deceleration = deceleration;
+ this.acceleration = acceleration;
+ this.driveSpeed = driveSpeed;
+ this.minTrainDistance = minTrainDistance;
+ this.stopFrame = stopFrame;
+ this.trainPhases = new LinkedHashMap<>();
+ this.reservations = new ArrayList<>();
+ }
+
+ @Override
+ public TrainMovement move(Speed currentSpeed, TrainHandle trainHandle, Section section) {
+ Speed newSpeed = currentSpeed.clone();
+ Train train = trainHandle.getTrain();
+ if(!trainPhases.containsKey(train)){
+ throw new RuntimeException("New occupation not handled correctly");
+ }
+
+ boolean goIntoSwitch = true;
+ ProximityDrivePhase phase = trainPhases.get(train);
+ while(goIntoSwitch){
+ goIntoSwitch = false;
+
+ switch (phase) {
+ case DRIVING_UNTIL_STOP -> {
+ train.setStatusMessage("Driving until stop");
+ if (train.getHeadSection().hasPassed(stopFrame, train.getHeadOfTrainFrame())) {
+ if (getNextSectionSafety(train).safe()) {
+ phase = ProximityDrivePhase.DRIVING_TO_NEXT;
+ train.getNextSection().setEntireBlockReservation(train);
+ } else {
+ phase = ProximityDrivePhase.STOPPING;
+ }
+ goIntoSwitch = true;
+ } else {
+ boolean tooCloseToOther = this.isTooCloseToOtherTrains(train);
+
+ if(tooCloseToOther){
+ newSpeed.approach(acceleration, deceleration, 0);
+ }else{
+ newSpeed.approach(acceleration, deceleration, driveSpeed);
+ }
+ }
+ }
+ case STOPPING -> {
+ train.setStatusMessage("Stopping" + newSpeed.getSpeedPerTick());
+ if (newSpeed.isZero()) {
+ phase = ProximityDrivePhase.WAITING;
+ goIntoSwitch = true;
+ }
+ newSpeed.minus(deceleration, 0);
+ }
+ case WAITING -> {
+ train.setStatusMessage("Waiting \n" + train.getHeadSection() + "\n"
+ + train.getHeadSection().next(train));
+ if (getNextSectionSafety(train).safe()) {
+ train.getNextSection().setEntireBlockReservation(train);
+ phase = ProximityDrivePhase.DRIVING_TO_NEXT;
+ goIntoSwitch = true;
+ }
+ }
+ case DRIVING_TO_NEXT -> {
+ train.setStatusMessage("Driving");
+ newSpeed.approach(acceleration, deceleration, driveSpeed);
+ }
+ }
+ }
+
+
+ return calculateTrainMovement(train, section, newSpeed);
+ }
+
+ private boolean isTooCloseToOtherTrains(Train train){
+ return ProximityUtils.isTooCloseToOtherTrains(train, trainPhases.keySet().stream().toList(), minTrainDistance);
+ }
+
+ @Override
+ public void trainExitedAtStart(@Nullable Train train, @Nullable Section section) {
+ trainExited(train);
+ }
+
+ @Override
+ public void trainExitedAtEnd(@Nullable Train train, @Nullable Section section){
+ trainExited(train);
+ }
+
+ private void trainExited(@Nullable Train train){
+ if(train == null) return;
+ trainPhases.remove(train);
+ reservations.remove(train);
+ }
+
+ @Override
+ public String getName() {
+ return "ProximityDrive";
+ }
+
+ @Override
+ public boolean canBlock() {
+ return true;
+ }
+
+ @Override
+ public boolean canSpawnOn() {
+ return canSpawn;
+ }
+
+ @Override
+ public Frame getSpawnFrame() {
+ return stopFrame;
+ }
+
+ @Override
+ protected void setParentTrackOnFrames(Track parentTrack) {
+ stopFrame.setTrack(parentTrack);
+ }
+
+ @Override
+ public boolean canHandleBlockSectionSafety() {
+ return true;
+ }
+
+ @Override
+ public BlockSectionSafetyResult getEnteringSafety(Train train, Section nextSection) {
+// BlockSectionSafetyResult nextSectionSafety = nextSection.getBlockSectionSafety(train);
+// if()
+ return new BlockSectionSafetyResult(true, train, "");
+ }
+
+ @Override
+ public boolean canHandleOccupation(@Nonnull Train train) {
+ if(reservations.contains(train)) return true;
+ if(trainPhases.containsKey(train)) return true;
+
+ return !ProximityUtils.isTooCloseToOtherTrains(train, trainPhases.keySet().stream().toList(), minTrainDistance);
+ }
+
+ @Override
+ public void handleNewReservation(@Nonnull Train train) {
+ reservations.add(train);
+ }
+
+ @Override
+ public void handleClearReservation(@Nonnull Train train) {
+ reservations.remove(train);
+ }
+
+ @Override
+ public Train getReservation() {
+ return null;
+ }
+
+ @Override
+ public void handleNewOccupation(@Nonnull Train train) {
+ trainPhases.put(train, ProximityDrivePhase.DRIVING_UNTIL_STOP);
+ }
+
+ @Override
+ public void handleClearOccupation(@Nonnull Train train) {
+
+ }
+
+ @Override
+ public boolean isReservedBy(@Nonnull Train train) {
+ return isOccupiedBy(train);
+ }
+
+ @Override
+ public boolean isOccupied() {
+ return !trainPhases.isEmpty();
+ }
+
+ @Override
+ public boolean isOccupiedBy(@Nonnull Train train) {
+ return trainPhases.containsKey(train);
+ }
+}
+
+enum ProximityDrivePhase{
+ DRIVING_UNTIL_STOP,
+ STOPPING,
+ WAITING,
+ DRIVING_TO_NEXT
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/drive/TrimBrakeTrackBehaviour.java b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/drive/TrimBrakeTrackBehaviour.java
new file mode 100644
index 00000000..8ee0c5fa
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/drive/TrimBrakeTrackBehaviour.java
@@ -0,0 +1,71 @@
+package com.jverbruggen.jrides.animator.coaster.trackbehaviour.drive;
+
+import com.jverbruggen.jrides.animator.coaster.TrainHandle;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.BaseTrackBehaviour;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.FreeMovementTrackBehaviour;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.result.CartMovementFactory;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.result.TrainMovement;
+import com.jverbruggen.jrides.models.properties.Speed;
+import com.jverbruggen.jrides.models.properties.frame.Frame;
+import com.jverbruggen.jrides.models.ride.coaster.track.Track;
+import com.jverbruggen.jrides.models.ride.coaster.train.Train;
+import com.jverbruggen.jrides.models.ride.section.Section;
+
+import javax.annotation.Nullable;
+
+public class TrimBrakeTrackBehaviour extends BaseTrackBehaviour {
+ private final double gravityConstant;
+ private final double dragConstantWithTrim;
+
+ public TrimBrakeTrackBehaviour(CartMovementFactory cartMovementFactory, double gravityConstant, double dragConstantWithTrim) {
+ super(cartMovementFactory);
+ this.gravityConstant = gravityConstant;
+ this.dragConstantWithTrim = dragConstantWithTrim;
+ }
+
+ @Override
+ public TrainMovement move(Speed currentSpeed, TrainHandle trainHandle, Section section) {
+ Train train = trainHandle.getTrain();
+
+ Speed newSpeed = FreeMovementTrackBehaviour.calculateGravityActedSpeed(
+ trainHandle, section, currentSpeed, gravityConstant, dragConstantWithTrim
+ );
+
+ return calculateTrainMovement(train, section, newSpeed);
+ }
+
+ @Override
+ public void trainExitedAtStart(@Nullable Train train, @Nullable Section section) {
+
+ }
+
+ @Override
+ public void trainExitedAtEnd(@Nullable Train train, @Nullable Section section){
+
+ }
+
+ @Override
+ public String getName() {
+ return "TrimBrake";
+ }
+
+ @Override
+ public boolean canBlock() {
+ return false;
+ }
+
+ @Override
+ public boolean canSpawnOn() {
+ return false;
+ }
+
+ @Override
+ public Frame getSpawnFrame() {
+ return null;
+ }
+
+ @Override
+ protected void setParentTrackOnFrames(Track parentTrack) {
+
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/factory/TrackBehaviourFactory.java b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/factory/TrackBehaviourFactory.java
new file mode 100644
index 00000000..ea89b2b4
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/factory/TrackBehaviourFactory.java
@@ -0,0 +1,306 @@
+package com.jverbruggen.jrides.animator.coaster.trackbehaviour.factory;
+
+import com.jverbruggen.jrides.JRidesPlugin;
+import com.jverbruggen.jrides.animator.coaster.CoasterHandle;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.FreeMovementTrackBehaviour;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.LaunchTrackBehaviour;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.station.StationTrackBehaviour;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.TrackBehaviour;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.drive.*;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.result.CartMovementFactory;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.transfer.TrainDisplacerTransferTrackBehaviour;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.point.SwitchBehaviour;
+import com.jverbruggen.jrides.config.coaster.CoasterConfig;
+import com.jverbruggen.jrides.config.coaster.objects.section.base.PointSectionConfig;
+import com.jverbruggen.jrides.config.coaster.objects.section.base.RangedSectionConfig;
+import com.jverbruggen.jrides.config.coaster.objects.section.point.SwitchSectionSpecConfig;
+import com.jverbruggen.jrides.config.coaster.objects.section.ranged.*;
+import com.jverbruggen.jrides.config.coaster.objects.section.ranged.transfer.TransferSectionPositionSpecConfig;
+import com.jverbruggen.jrides.config.coaster.objects.section.ranged.transfer.TransferSectionSpecConfig;
+import com.jverbruggen.jrides.config.gates.GateOwnerConfigSpec;
+import com.jverbruggen.jrides.control.DispatchLock;
+import com.jverbruggen.jrides.control.DispatchLockCollection;
+import com.jverbruggen.jrides.control.SimpleDispatchLock;
+import com.jverbruggen.jrides.control.trigger.*;
+import com.jverbruggen.jrides.effect.EffectTriggerFactory;
+import com.jverbruggen.jrides.effect.handle.train.TrainEffectTriggerHandle;
+import com.jverbruggen.jrides.items.ItemStackFactory;
+import com.jverbruggen.jrides.language.LanguageFile;
+import com.jverbruggen.jrides.language.LanguageFileField;
+import com.jverbruggen.jrides.models.entity.TrainModelItem;
+import com.jverbruggen.jrides.models.entity.VirtualEntity;
+import com.jverbruggen.jrides.models.math.Quaternion;
+import com.jverbruggen.jrides.models.math.Vector3;
+import com.jverbruggen.jrides.models.properties.frame.Frame;
+import com.jverbruggen.jrides.models.properties.frame.FrameRange;
+import com.jverbruggen.jrides.models.properties.frame.SimpleFrame;
+import com.jverbruggen.jrides.models.ride.CoasterStationHandle;
+import com.jverbruggen.jrides.models.ride.RideType;
+import com.jverbruggen.jrides.models.ride.coaster.trackswitch.SwitchPosition;
+import com.jverbruggen.jrides.models.ride.coaster.transfer.Transfer;
+import com.jverbruggen.jrides.models.ride.coaster.transfer.TransferPosition;
+import com.jverbruggen.jrides.models.ride.gate.Gate;
+import com.jverbruggen.jrides.serviceprovider.ServiceProvider;
+import com.jverbruggen.jrides.state.viewport.ViewportManager;
+import org.bukkit.Material;
+import org.bukkit.World;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class TrackBehaviourFactory {
+ private final CartMovementFactory cartMovementFactory;
+ private final EffectTriggerFactory effectTriggerFactory;
+ private final LanguageFile languageFile;
+ private final ViewportManager viewportManager;
+
+ public TrackBehaviourFactory() {
+ this.cartMovementFactory = ServiceProvider.getSingleton(CartMovementFactory.class);
+ this.effectTriggerFactory = ServiceProvider.getSingleton(EffectTriggerFactory.class);
+ this.languageFile = ServiceProvider.getSingleton(LanguageFile.class);
+ this.viewportManager = ServiceProvider.getSingleton(ViewportManager.class);
+ }
+
+ public TrackBehaviour getTrackBehaviour(double gravityConstant, double dragConstant){
+ return new FreeMovementTrackBehaviour(cartMovementFactory, gravityConstant, dragConstant);
+ }
+
+ public TrackBehaviour getBlockBrakeBehaviour(RangedSectionConfig rangedSectionConfig, int totalFrames){
+ BlockSectionSpecConfig blockSectionSpecConfig = rangedSectionConfig.getBlockSectionSpec();
+ double engagePercentage = blockSectionSpecConfig.getEngage();
+ Frame lowerRange = new SimpleFrame(rangedSectionConfig.getLowerRange());
+ Frame upperRange = new SimpleFrame(rangedSectionConfig.getUpperRange());
+ boolean canSpawn = blockSectionSpecConfig.canSpawn();
+ double driveSpeed = blockSectionSpecConfig.getDriveSpeed();
+ double acceleration = blockSectionSpecConfig.getAcceleration();
+ double deceleration = blockSectionSpecConfig.getDeceleration();
+ int minWaitTicks = blockSectionSpecConfig.getMinWaitTicks();
+
+ Frame blockBrakeEngageFrame = new FrameRange(lowerRange, upperRange, totalFrames).getInBetween(engagePercentage);
+
+ return new BlockBrakeTrackBehaviour(cartMovementFactory, blockBrakeEngageFrame, canSpawn, driveSpeed, deceleration, acceleration, minWaitTicks);
+ }
+
+ public TrackBehaviour getLaunchBehaviour(CoasterHandle coasterHandle, Frame engageFrame, boolean canSpawn, double driveSpeed, double acceleration, double deceleration, boolean isForwardsLaunch, int waitTicks, double launchAcceleration, double launchSpeed, double launchSpeedBackward, List launchEffectStrings){
+ String rideIdentifier = coasterHandle.getRide().getIdentifier();
+ List launchEffectTriggers = effectTriggerFactory.getFramelessEffectTriggers(RideType.COASTER, rideIdentifier, launchEffectStrings);
+
+ return new LaunchTrackBehaviour(cartMovementFactory, canSpawn, driveSpeed, deceleration, acceleration, isForwardsLaunch, waitTicks, engageFrame, launchAcceleration, launchSpeed, launchSpeedBackward, launchEffectTriggers);
+ }
+
+ public TrackBehaviour getStationBehaviour(Frame blockBrakeEngageFrame, CoasterHandle coasterHandle, RangedSectionConfig rangedSectionConfig, GateOwnerConfigSpec gateSpec){
+ String rideIdentifier = coasterHandle.getRide().getIdentifier();
+ String shortStationName = rangedSectionConfig.getIdentifier();
+ String stationName = rideIdentifier + "_station_" + shortStationName;
+ World world = JRidesPlugin.getWorld();
+
+ DispatchLockCollection dispatchLockCollection = new DispatchLockCollection("Main locks");
+
+ DispatchLock trainInStationDispatchLock = new SimpleDispatchLock(dispatchLockCollection,
+ languageFile.get(LanguageFileField.NOTIFICATION_RIDE_NO_TRAIN_PRESENT), true);
+ DispatchLock blockSectionOccupiedDispatchLock = new SimpleDispatchLock(dispatchLockCollection,
+ languageFile.get(LanguageFileField.NOTIFICATION_RIDE_NEXT_BLOCK_OCCUPIED), true);
+ DispatchLock minimumWaitTimeDispatchLock = new SimpleDispatchLock(dispatchLockCollection,
+ languageFile.get(LanguageFileField.NOTIFICATION_RIDE_WAITING_TIME), true);
+ DispatchLock restraintLock = new SimpleDispatchLock(dispatchLockCollection,
+ languageFile.get(LanguageFileField.NOTIFICATION_RIDE_RESTRAINTS_NOT_CLOSED), true);
+ DispatchLockCollection gatesGenericLock = new DispatchLockCollection(
+ languageFile.get(LanguageFileField.NOTIFICATION_RIDE_GATES_NOT_CLOSED), dispatchLockCollection);
+
+ List gates = gateSpec != null
+ ? gateSpec.createGates(stationName, world, gatesGenericLock)
+ : new ArrayList<>();
+
+ TriggerContext triggerContext = new TriggerContext(
+ dispatchLockCollection,
+ trainInStationDispatchLock,
+ new SimpleDispatchTrigger(dispatchLockCollection),
+ new GateTrigger(gatesGenericLock),
+ new RestraintTrigger(restraintLock));
+
+ CoasterStationConfig coasterStationConfig = rangedSectionConfig.getStationSectionSpec();
+ double driveSpeed = coasterStationConfig.getDriveSpeed();
+
+ CoasterStationHandle stationHandle = coasterStationConfig.createStationHandle(
+ stationName, shortStationName, triggerContext, coasterHandle,
+ gates, minimumWaitTimeDispatchLock);
+
+ return new StationTrackBehaviour(coasterHandle, cartMovementFactory, blockBrakeEngageFrame, coasterStationConfig.canSpawn(), triggerContext,
+ stationHandle, trainInStationDispatchLock, blockSectionOccupiedDispatchLock, restraintLock, driveSpeed,
+ coasterStationConfig.isForwardsDispatch(), coasterStationConfig.getPassThroughCount());
+ }
+
+ private TrackBehaviour getSwitchBehaviour(SwitchSectionSpecConfig switchSectionSpecConfig) {
+ List destinations = switchSectionSpecConfig.getDestinations()
+ .stream()
+ .map(SwitchPosition::new)
+ .collect(Collectors.toList());
+ SwitchPosition origin = new SwitchPosition(switchSectionSpecConfig.getOrigin());
+
+ return new SwitchBehaviour(cartMovementFactory, destinations, origin);
+ }
+
+ public TrackBehaviour getTrackBehaviourFor(CoasterHandle coasterHandle, CoasterConfig coasterConfig, RangedSectionConfig rangedSectionConfig, int totalFrames){
+ String type = rangedSectionConfig.getType();
+ String identifier = rangedSectionConfig.getIdentifier();
+
+ if(type.equalsIgnoreCase("track")){
+ double gravityConstant = coasterConfig.getGravityConstant();
+ double dragConstant = coasterConfig.getDragConstant();
+ return getTrackBehaviour(gravityConstant, dragConstant);
+ }else if(type.equalsIgnoreCase("blocksection")){
+ return getBlockBrakeBehaviour(rangedSectionConfig, totalFrames);
+ }else if(type.equalsIgnoreCase("station")){
+ CoasterStationConfig stationSectionSpecConfig = rangedSectionConfig.getStationSectionSpec();
+ GateOwnerConfigSpec gateSpec = coasterConfig.getGates().getGateOwnerSpec(identifier).orElse(null);
+
+ double engagePercentage = stationSectionSpecConfig.getEngage();
+ Frame lowerRange = new SimpleFrame(rangedSectionConfig.getLowerRange());
+ Frame upperRange = new SimpleFrame(rangedSectionConfig.getUpperRange());
+
+ Frame blockBrakeEngageFrame = new FrameRange(lowerRange, upperRange, totalFrames).getInBetween(engagePercentage);
+ return getStationBehaviour(blockBrakeEngageFrame, coasterHandle, rangedSectionConfig, gateSpec);
+ }else if(type.equalsIgnoreCase("brake")){
+ BrakeSectionSpecConfig brakeSectionSpecConfig = rangedSectionConfig.getBrakeSectionSpec();
+ double driveSpeed = brakeSectionSpecConfig.getDriveSpeed();
+ double deceleration = brakeSectionSpecConfig.getDeceleration();
+ return new BrakeAndDriveTrackBehaviour(cartMovementFactory, false, driveSpeed, deceleration, deceleration);
+ }else if(type.equalsIgnoreCase("trim")){
+ TrimBrakeSectionSpecConfig trimBrakeSectionSpecConfig = rangedSectionConfig.getTrimBrakeSectionSpecConfig();
+ double dragConstantWithTrim = trimBrakeSectionSpecConfig.getTrimResistanceConstant() * coasterConfig.getDragConstant();
+ return new TrimBrakeTrackBehaviour(cartMovementFactory, coasterConfig.getGravityConstant(), dragConstantWithTrim);
+ }else if(type.equalsIgnoreCase("drive")){
+ DriveSectionSpecConfig driveSectionSpecConfig = rangedSectionConfig.getDriveSectionSpec();
+ boolean ignoreDirection = driveSectionSpecConfig.isIgnoreDirection();
+ double driveSpeed = driveSectionSpecConfig.getDriveSpeed();
+ double acceleration = driveSectionSpecConfig.getAcceleration();
+ double deceleration = driveSectionSpecConfig.getDeceleration();
+ return new BrakeAndDriveTrackBehaviour(cartMovementFactory, ignoreDirection, driveSpeed, deceleration, acceleration);
+ }else if(type.equalsIgnoreCase("proximityDrive")){
+ ProximityDriveSectionSpecConfig driveSectionSpecConfig = rangedSectionConfig.getProximityDriveSectionSpec();
+ boolean canSpawn = driveSectionSpecConfig.canSpawn();
+ double driveSpeed = driveSectionSpecConfig.getDriveSpeed();
+ double acceleration = driveSectionSpecConfig.getAcceleration();
+ double deceleration = driveSectionSpecConfig.getDeceleration();
+ int minTrainDistance = driveSectionSpecConfig.getMinTrainDistance();
+
+ Frame lowerRange = new SimpleFrame(rangedSectionConfig.getLowerRange());
+ Frame upperRange = new SimpleFrame(rangedSectionConfig.getUpperRange());
+ Frame stopFrame = Frame.getDistanceFromUpperFrame(lowerRange, upperRange, 10);
+
+ return new ProximityDriveTrackBehaviour(cartMovementFactory, canSpawn, driveSpeed, deceleration, acceleration, minTrainDistance, stopFrame);
+ }else if(type.equalsIgnoreCase("driveAndRelease")){
+ DriveAndReleaseSectionSpecConfig driveAndReleaseSectionSpecConfig = rangedSectionConfig.getDriveAndReleaseSectionSpecConfig();
+ double driveSpeed = driveAndReleaseSectionSpecConfig.getDriveSpeed();
+ double acceleration = driveAndReleaseSectionSpecConfig.getAcceleration();
+ double deceleration = driveAndReleaseSectionSpecConfig.getDeceleration();
+
+ double engagePercentage = driveAndReleaseSectionSpecConfig.getEngage();
+ Frame lowerRange = new SimpleFrame(rangedSectionConfig.getLowerRange());
+ Frame upperRange = new SimpleFrame(rangedSectionConfig.getUpperRange());
+
+ Frame stopFrame = new FrameRange(lowerRange, upperRange, totalFrames).getInBetween(engagePercentage);
+
+ int minWaitTicks = driveAndReleaseSectionSpecConfig.getWaitTicks();
+
+ return new DriveAndReleaseTrackBehaviour(cartMovementFactory, driveSpeed, deceleration, acceleration,
+ stopFrame, minWaitTicks, coasterConfig.getGravityConstant(), coasterConfig.getDragConstant());
+ }else if(type.equalsIgnoreCase("driveStopDrive")){
+ DriveStopDriveSectionSpecConfig driveStopDriveSectionSpecConfig = rangedSectionConfig.getDriveStopDriveSectionSpecConfig();
+ double driveSpeedIn = driveStopDriveSectionSpecConfig.getDriveSpeedIn();
+ double driveSpeedOut = driveStopDriveSectionSpecConfig.getDriveSpeedOut();
+ double acceleration = driveStopDriveSectionSpecConfig.getAcceleration();
+ double deceleration = driveStopDriveSectionSpecConfig.getDeceleration();
+
+ double engagePercentage = driveStopDriveSectionSpecConfig.getEngage();
+ Frame lowerRange = new SimpleFrame(rangedSectionConfig.getLowerRange());
+ Frame upperRange = new SimpleFrame(rangedSectionConfig.getUpperRange());
+
+ Frame stopFrame = new FrameRange(lowerRange, upperRange, totalFrames).getInBetween(engagePercentage);
+
+ int minWaitTicks = driveStopDriveSectionSpecConfig.getWaitTicks();
+
+ return new DriveStopDriveTrackBehaviour(cartMovementFactory, minWaitTicks, stopFrame, deceleration, acceleration,
+ driveSpeedIn, driveSpeedOut);
+ }else if(type.equalsIgnoreCase("launch")){
+ LaunchSectionSpecConfig launchSectionSpecConfig = rangedSectionConfig.getLaunchSectionSpecConfig();
+ double engagePercentage = launchSectionSpecConfig.getEngage();
+ Frame lowerRange = new SimpleFrame(rangedSectionConfig.getLowerRange());
+ Frame upperRange = new SimpleFrame(rangedSectionConfig.getUpperRange());
+ Frame engageFrame = new FrameRange(lowerRange, upperRange, totalFrames).getInBetween(engagePercentage);
+
+ boolean canSpawn = launchSectionSpecConfig.canSpawn();
+ double driveSpeed = launchSectionSpecConfig.getDriveSpeed();
+ double acceleration = launchSectionSpecConfig.getAcceleration();
+ double deceleration = launchSectionSpecConfig.getDeceleration();
+ boolean isForwardsLaunch = launchSectionSpecConfig.isForwardsLaunch();
+ int waitTicks = launchSectionSpecConfig.getWaitTicks();
+ double launchAcceleration = launchSectionSpecConfig.getLaunchAcceleration();
+ double launchSpeed = launchSectionSpecConfig.getLaunchSpeed();
+ double launchSpeedBackward = launchSectionSpecConfig.getLaunchSpeedBackward();
+ List launchEffectsString = launchSectionSpecConfig.getLaunchEffectsConfig().getLaunchEffects();
+
+ return getLaunchBehaviour(coasterHandle, engageFrame, canSpawn, driveSpeed, acceleration, deceleration, isForwardsLaunch, waitTicks, launchAcceleration, launchSpeed, launchSpeedBackward, launchEffectsString);
+ }else if(type.equalsIgnoreCase("transfer")){
+ TransferSectionSpecConfig transferSectionSpecConfig = rangedSectionConfig.getTransferSectionSpec();
+
+ Vector3 origin = transferSectionSpecConfig.getOrigin();
+ double engagePercentage = transferSectionSpecConfig.getEngage();
+ Frame lowerRange = new SimpleFrame(rangedSectionConfig.getLowerRange());
+ Frame upperRange = new SimpleFrame(rangedSectionConfig.getUpperRange());
+ Frame engageFrame = new FrameRange(lowerRange, upperRange, totalFrames).getInBetween(engagePercentage);
+ Vector3 modelOffsetPosition = transferSectionSpecConfig.getModelOffsetPosition();
+ Vector3 modelOffsetRotation = transferSectionSpecConfig.getModelOffsetRotation();
+ double enterDriveSpeed = transferSectionSpecConfig.getEnterDriveSpeed();
+ double exitDriveSpeed = transferSectionSpecConfig.getExitDriveSpeed();
+ double acceleration = transferSectionSpecConfig.getAcceleration();
+ double deceleration = transferSectionSpecConfig.getDeceleration();
+
+ List transferPositions = new ArrayList<>();
+ for(TransferSectionPositionSpecConfig transferSectionPositionSpecConfig : transferSectionSpecConfig.getPositions()){
+ String sectionAtStartReference = transferSectionPositionSpecConfig.getSectionAtStart();
+ String sectionAtEndReference = transferSectionPositionSpecConfig.getSectionAtEnd();
+ boolean sectionAtStartForwards = transferSectionPositionSpecConfig.isSectionAtStartForwards();
+ boolean sectionAtEndForwards = transferSectionPositionSpecConfig.isSectionAtEndForwards();
+ boolean sectionAtStartConnectsToStart = transferSectionPositionSpecConfig.isSectionAtStartConnectsToStart();
+ boolean sectionAtEndConnectsToStart = transferSectionPositionSpecConfig.isSectionAtEndConnectsToStart();
+ Vector3 position = Vector3.add(origin, transferSectionPositionSpecConfig.getPosition());
+ Vector3 rotation = transferSectionPositionSpecConfig.getRotation();
+ int moveTicks = transferSectionPositionSpecConfig.getMoveTicks();
+
+ Quaternion orientation = Quaternion.fromAnglesVector(rotation);
+ transferPositions.add(new TransferPosition(position, orientation, moveTicks, sectionAtStartReference, sectionAtEndReference, sectionAtStartForwards, sectionAtEndForwards, sectionAtStartConnectsToStart, sectionAtEndConnectsToStart));
+ }
+
+ TransferPosition originTransferPosition = transferPositions.get(0);
+
+ Quaternion modelOffsetOrientation = originTransferPosition.getOrientation().clone();
+ modelOffsetOrientation.rotateYawPitchRoll(modelOffsetRotation);
+
+ VirtualEntity virtualEntity = viewportManager.spawnModelEntity(
+ Vector3.add(originTransferPosition.getLocation(), modelOffsetPosition),
+ new TrainModelItem(ItemStackFactory.getCoasterStack(Material.DIAMOND_HOE, 2, true)));
+ virtualEntity.setRotation(modelOffsetOrientation);
+
+ Transfer transfer = new Transfer(transferPositions, virtualEntity, origin, modelOffsetPosition, modelOffsetRotation);
+ coasterHandle.addTransfer(transfer);
+ coasterHandle.addUnlockable(identifier, transfer);
+
+ return new TrainDisplacerTransferTrackBehaviour(cartMovementFactory, enterDriveSpeed, deceleration, acceleration, exitDriveSpeed, engageFrame, transfer);
+ }
+
+ JRidesPlugin.getLogger().severe("Unknown section type " + type);
+ return null;
+ }
+
+ public TrackBehaviour getTrackBehaviourFor(CoasterHandle coasterHandle, CoasterConfig coasterConfig, PointSectionConfig pointSectionConfig) {
+ String type = pointSectionConfig.getType();
+
+ if(type.equalsIgnoreCase("switch")){
+ return getSwitchBehaviour(pointSectionConfig.getSwitchSectionSpecConfig());
+ }
+
+ throw new RuntimeException("Unknown point section type " + type);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/point/SwitchBehaviour.java b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/point/SwitchBehaviour.java
new file mode 100644
index 00000000..130aeb82
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/point/SwitchBehaviour.java
@@ -0,0 +1,169 @@
+package com.jverbruggen.jrides.animator.coaster.trackbehaviour.point;
+
+import com.jverbruggen.jrides.JRidesPlugin;
+import com.jverbruggen.jrides.animator.coaster.TrainHandle;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.BaseTrackBehaviour;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.result.CartMovementFactory;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.result.TrainMovement;
+import com.jverbruggen.jrides.logging.LogType;
+import com.jverbruggen.jrides.models.properties.Speed;
+import com.jverbruggen.jrides.models.properties.frame.Frame;
+import com.jverbruggen.jrides.models.ride.coaster.track.Track;
+import com.jverbruggen.jrides.models.ride.coaster.trackswitch.SwitchPosition;
+import com.jverbruggen.jrides.models.ride.coaster.train.Train;
+import com.jverbruggen.jrides.models.ride.section.Section;
+import com.jverbruggen.jrides.models.ride.section.reference.SectionReference;
+
+import javax.annotation.Nullable;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class SwitchBehaviour extends BaseTrackBehaviour {
+ private List destinations;
+ private SwitchPosition origin;
+
+ private Section selectedDestination;
+
+ private int roundRobinState;
+ private @Nullable Train lastTrain;
+
+ public SwitchBehaviour(CartMovementFactory cartMovementFactory, List destinations, SwitchPosition origin) {
+ super(cartMovementFactory);
+ this.destinations = destinations;
+ this.origin = origin;
+ this.roundRobinState = 0;
+ this.lastTrain = null;
+ }
+
+ private void updateRoundRobinState(){
+ if(++this.roundRobinState >= destinations.size())
+ this.roundRobinState = 0;
+ }
+
+ private void selectNewDestination(@Nullable Train train){
+ if(destinations.size() == 0)
+ throw new RuntimeException("Switch does not lead anywhere!");
+
+ SwitchPosition nextPosition = destinations.get(this.roundRobinState);
+ if(!nextPosition.availableFor(train)){
+ nextPosition = destinations.stream()
+ .filter(p -> p.availableFor(train))
+ .findFirst()
+ .orElse(nextPosition);
+ }
+
+ selectedDestination = nextPosition.getDestination();
+
+ JRidesPlugin.getLogger().info(LogType.SECTIONS, "Next destination for switch: " + selectedDestination);
+ updateRoundRobinState();
+ }
+
+ @Override
+ protected void setParentTrackOnFrames(Track parentTrack) {
+
+ }
+
+ @Override
+ public TrainMovement move(Speed currentSpeed, TrainHandle trainHandle, Section section) {
+ throw new RuntimeException("Should not move in point");
+ }
+
+ @Override
+ public boolean definesNextAccepting() {
+ return true;
+ }
+
+ @Override
+ public Section acceptAsNext(Train train, boolean canProcessPassed) {
+ if(canProcessPassed) trainPassed(train);
+
+ return getSectionAtEnd(train, canProcessPassed);
+ }
+
+ @Override
+ public void trainExitedAtStart(@Nullable Train train, @Nullable Section section) {
+ }
+
+ @Override
+ public void trainExitedAtEnd(@Nullable Train train, @Nullable Section section) {
+ }
+
+ @Override
+ public void trainPassed(Train train) {
+// selectNewDestination();
+ if(lastTrain == train)
+ lastTrain = null;
+ }
+
+ @Override
+ public String getName() {
+ return null;
+ }
+
+ @Override
+ public boolean canBlock() {
+ return false;
+ }
+
+ @Override
+ public boolean canSpawnOn() {
+ return false;
+ }
+
+ @Override
+ public Frame getSpawnFrame() {
+ return null;
+ }
+
+ @Override
+ public boolean definesNextSection() {
+ return true;
+ }
+
+ @Override
+ public Section getSectionAtStart(Train train, boolean process) {
+ if(process && lastTrain != train && train != null){
+ lastTrain = train;
+ newTrainEntered(train);
+ }
+ return origin.getDestination();
+ }
+
+ @Override
+ public Section getSectionAtEnd(Train train, boolean process) {
+ if(train != null){
+ if(process && lastTrain != train){
+ lastTrain = train;
+ newTrainEntered(train);
+ }
+
+ List matchingInReservation = train.getReservedSections().stream()
+ .filter(s -> destinations.stream()
+ .anyMatch(d -> d.getDestination().equals(s)))
+ .collect(Collectors.toList());
+
+ if(matchingInReservation.size() > 0){
+ JRidesPlugin.getLogger().info(LogType.SECTIONS, "Matches in reservation: " + matchingInReservation.get(0));
+ return matchingInReservation.get(0);
+ }
+ }
+
+ return selectedDestination;
+ }
+
+ @Override
+ public void populateSectionReferences(Map sectionMap) {
+ for(SwitchPosition destination : destinations){
+ destination.populateWith(sectionMap);
+ }
+
+ origin.populateWith(sectionMap);
+
+ this.selectNewDestination(null);
+ }
+
+ private void newTrainEntered(Train train){
+ selectNewDestination(train);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/result/CartMovement.java b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/result/CartMovement.java
new file mode 100644
index 00000000..ba2b8bab
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/result/CartMovement.java
@@ -0,0 +1,22 @@
+package com.jverbruggen.jrides.animator.coaster.trackbehaviour.result;
+
+import com.jverbruggen.jrides.models.math.Quaternion;
+import com.jverbruggen.jrides.models.math.Vector3;
+
+public final class CartMovement {
+ private final Vector3 location;
+ private final Quaternion orientation;
+
+ public CartMovement(Vector3 location, Quaternion orientation) {
+ this.location = location;
+ this.orientation = orientation;
+ }
+
+ public Vector3 getLocation() {
+ return location;
+ }
+
+ public Quaternion getOrientation() {
+ return orientation;
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/result/CartMovementFactory.java b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/result/CartMovementFactory.java
new file mode 100644
index 00000000..26a67cab
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/result/CartMovementFactory.java
@@ -0,0 +1,45 @@
+package com.jverbruggen.jrides.animator.coaster.trackbehaviour.result;
+
+import com.jverbruggen.jrides.animator.coaster.TrainHandle;
+import com.jverbruggen.jrides.models.math.Quaternion;
+import com.jverbruggen.jrides.models.math.Vector3;
+import com.jverbruggen.jrides.models.math.VectorQuaternionState;
+import com.jverbruggen.jrides.models.properties.frame.Frame;
+import com.jverbruggen.jrides.models.ride.coaster.train.CoasterCart;
+import com.jverbruggen.jrides.models.ride.section.Section;
+import com.jverbruggen.jrides.models.ride.section.provider.SectionProvider;
+import com.jverbruggen.jrides.serviceprovider.ServiceProvider;
+
+import java.util.HashMap;
+import java.util.List;
+
+public class CartMovementFactory {
+ private final SectionProvider sectionProvider;
+
+ public CartMovementFactory() {
+ this.sectionProvider = ServiceProvider.getSingleton(SectionProvider.class);
+ }
+
+ public HashMap createOnTrackCartMovement(TrainHandle trainHandle, List carts, int speedFrameIncrement, Section section){
+ HashMap cartMovements = new HashMap<>();
+
+ for(CoasterCart cart : carts){
+ Frame cartFrame = cart.getFrame();
+ Frame newShadedCartFrame = cartFrame.clone().add(speedFrameIncrement);
+
+ sectionProvider.addFramesWithSectionLogic(trainHandle, cartFrame, newShadedCartFrame.getValue());
+
+ Section cartSection = cartFrame.getSection();
+ Vector3 cartPositionOnTrack = cartSection.getLocationFor(cartFrame);
+ Quaternion orientation = cartSection.getOrientationFor(cartFrame).clone();
+ if(cartFrame.isInvertedFrameAddition())
+ orientation.rotateY(180);
+
+ VectorQuaternionState vectorQuaternionState = CoasterCart.calculateLocation(cartPositionOnTrack, cart.getTrackOffset(), orientation, cart.getRotationOffset());
+
+ cartMovements.put(cart, new CartMovement(vectorQuaternionState.getVector(), vectorQuaternionState.getQuaternion()));
+ }
+
+ return cartMovements;
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/result/TrainMovement.java b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/result/TrainMovement.java
new file mode 100644
index 00000000..3d20a549
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/result/TrainMovement.java
@@ -0,0 +1,54 @@
+package com.jverbruggen.jrides.animator.coaster.trackbehaviour.result;
+
+import com.jverbruggen.jrides.models.math.Vector3;
+import com.jverbruggen.jrides.models.properties.frame.Frame;
+import com.jverbruggen.jrides.models.properties.Speed;
+import com.jverbruggen.jrides.models.ride.coaster.train.CoasterCart;
+
+import javax.annotation.Nullable;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+public final class TrainMovement {
+ private final Speed newSpeed;
+ private final Frame newHeadOfTrainFrame;
+ private final Frame newMiddleOfTrainFrame;
+ private final Frame newTailOfTrainFrame;
+ private final Vector3 newTrainLocation;
+ private final HashMap cartMovements;
+
+ public TrainMovement(Speed newSpeed, Frame newHeadOfTrainFrame, Frame newMiddleOfTrainFrame, Frame newTailOfTrainFrame, Vector3 newTrainLocation, HashMap cartMovements) {
+ this.newSpeed = newSpeed;
+ this.newHeadOfTrainFrame = newHeadOfTrainFrame;
+ this.newMiddleOfTrainFrame = newMiddleOfTrainFrame;
+ this.newTailOfTrainFrame = newTailOfTrainFrame;
+ this.newTrainLocation = newTrainLocation;
+ this.cartMovements = cartMovements;
+ }
+
+ public Speed getNewSpeed() {
+ return newSpeed;
+ }
+
+ public Frame getNewHeadOfTrainFrame() {
+ return newHeadOfTrainFrame;
+ }
+
+ public Frame getNewMiddleOfTrainFrame() {
+ return newMiddleOfTrainFrame;
+ }
+
+ public Frame getNewTailOfTrainFrame() {
+ return newTailOfTrainFrame;
+ }
+
+ public Vector3 getNewTrainLocation() {
+ return newTrainLocation;
+ }
+
+ public @Nullable Set> getCartMovements() {
+ if(cartMovements == null) return null;
+ return cartMovements.entrySet();
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/station/StationPhase.java b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/station/StationPhase.java
new file mode 100644
index 00000000..61b6ade6
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/station/StationPhase.java
@@ -0,0 +1,43 @@
+package com.jverbruggen.jrides.animator.coaster.trackbehaviour.station;
+
+public enum StationPhase{
+ /**
+ * Waiting for a train to arrive.
+ */
+ IDLE,
+
+ /**
+ * Used when a train is entering the station backwards.
+ */
+ REVERSING,
+
+ /**
+ * Train drives towards the stopping point.
+ */
+ ARRIVING,
+
+ /**
+ * Decelerating action towards stopping point.
+ */
+ STOPPING,
+
+ /**
+ * Stationary. Train is in a safe and still position.
+ */
+ STATIONARY,
+
+ /**
+ * Dispatch action was given, but still waiting for it to be safe.
+ */
+ WAITING,
+
+ /**
+ * Departing from station.
+ */
+ DEPARTING,
+
+ /**
+ * Passing through skips the station behaviour and just lets the train pass with default physics.
+ */
+ PASSING_THROUGH
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/station/StationTrackBehaviour.java b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/station/StationTrackBehaviour.java
new file mode 100644
index 00000000..fa15302a
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/station/StationTrackBehaviour.java
@@ -0,0 +1,263 @@
+package com.jverbruggen.jrides.animator.coaster.trackbehaviour.station;
+
+import com.jverbruggen.jrides.JRidesPlugin;
+import com.jverbruggen.jrides.animator.coaster.CoasterHandle;
+import com.jverbruggen.jrides.animator.coaster.TrainHandle;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.BaseTrackBehaviour;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.FreeMovementTrackBehaviour;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.result.CartMovementFactory;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.result.TrainMovement;
+import com.jverbruggen.jrides.api.JRidesPlayer;
+import com.jverbruggen.jrides.control.DispatchLock;
+import com.jverbruggen.jrides.control.trigger.SimpleDispatchTrigger;
+import com.jverbruggen.jrides.control.trigger.TriggerContext;
+import com.jverbruggen.jrides.event.player.PlayerFinishedRideEvent;
+import com.jverbruggen.jrides.event.ride.RideFinishedEvent;
+import com.jverbruggen.jrides.logging.JRidesLogger;
+import com.jverbruggen.jrides.models.properties.frame.Frame;
+import com.jverbruggen.jrides.models.properties.Speed;
+import com.jverbruggen.jrides.models.ride.CoasterStationHandle;
+import com.jverbruggen.jrides.models.ride.coaster.track.Track;
+import com.jverbruggen.jrides.models.ride.coaster.train.Train;
+import com.jverbruggen.jrides.models.ride.section.Section;
+import com.jverbruggen.jrides.models.ride.section.result.BlockSectionSafetyResult;
+
+import javax.annotation.Nullable;
+import java.util.stream.Collectors;
+
+public class StationTrackBehaviour extends BaseTrackBehaviour {
+ private final double deceleration;
+ private final double acceleration;
+ private final double driveSpeed;
+
+ private final CoasterHandle coasterHandle;
+ private final JRidesLogger logger;
+ private Train handlingTrain;
+ private StationPhase phase;
+ private final Frame stopFrame;
+ private final boolean canSpawn;
+ private final TriggerContext triggerContext;
+ private final CoasterStationHandle stationHandle;
+ private final DispatchLock trainInStationDispatchLock;
+ private final DispatchLock blockSectionOccupiedDispatchLock;
+ private final DispatchLock restraintsLock;
+
+ private boolean stopping;
+ private boolean dispatching;
+
+ private final int passThroughCount;
+ private int passThroughCountState;
+ private final boolean forwardsDispatch;
+ private final byte dispatchSpeedMultiplier;
+
+ public StationTrackBehaviour(CoasterHandle coasterHandle, CartMovementFactory cartMovementFactory, Frame stopFrame, boolean canSpawn, TriggerContext triggerContext,
+ CoasterStationHandle stationHandle, DispatchLock trainInStationDispatchLock, DispatchLock blockSectionOccupiedDispatchLock,
+ DispatchLock restraintsLock, double driveSpeed, boolean forwardsDispatch, int passThroughCount) {
+ super(cartMovementFactory);
+ this.coasterHandle = coasterHandle;
+ this.logger = JRidesPlugin.getLogger();
+ this.deceleration = 0.2;
+ this.acceleration = 0.1;
+ this.driveSpeed = driveSpeed;
+ this.handlingTrain = null;
+ this.phase = StationPhase.IDLE;
+ this.stopFrame = stopFrame;
+ this.canSpawn = canSpawn;
+ this.triggerContext = triggerContext;
+ this.stationHandle = stationHandle;
+ this.dispatching = false;
+ this.stopping = false;
+ this.passThroughCount = passThroughCount;
+ this.passThroughCountState = passThroughCount;
+
+ this.forwardsDispatch = forwardsDispatch;
+ this.dispatchSpeedMultiplier = (byte) (forwardsDispatch ? 1 : -1);
+
+ this.trainInStationDispatchLock = trainInStationDispatchLock;
+ this.blockSectionOccupiedDispatchLock = blockSectionOccupiedDispatchLock;
+ this.restraintsLock = restraintsLock;
+
+ trainExitedAtEnd(null, null);
+ }
+
+ @Override
+ public TrainMovement move(Speed currentSpeed, TrainHandle trainHandle, Section section) {
+ Speed newSpeed = currentSpeed.clone();
+ Train train = trainHandle.getTrain();
+
+ if(train == null) throw new RuntimeException("Train was null in StationTrackBehaviour");
+
+ if(handlingTrain != null && !train.equals(handlingTrain)){
+ logger.warning("Train " + train.getName() + " has entered station, train is blocked");
+ return null;
+ }
+
+ boolean goIntoSwitch = true;
+ while(goIntoSwitch){
+ goIntoSwitch = false;
+ switch (phase) {
+ case IDLE -> {
+ handlingTrain = train;
+ if (shouldPassThrough()) {
+ phase = StationPhase.PASSING_THROUGH;
+ passThroughCountState++;
+ } else if (isTrainSpeedPositive(trainHandle)) {
+ phase = StationPhase.ARRIVING;
+ } else {
+ phase = StationPhase.REVERSING;
+ }
+ goIntoSwitch = true;
+ }
+ case PASSING_THROUGH -> newSpeed = FreeMovementTrackBehaviour.calculateGravityActedSpeed(
+ trainHandle, section, currentSpeed, coasterHandle.getGravityConstant(), coasterHandle.getDragConstant()
+ );
+ case REVERSING -> {
+ if (isTrainSpeedPositive(trainHandle)) {
+ phase = StationPhase.ARRIVING;
+ goIntoSwitch = true;
+ } else {
+ newSpeed.approach(acceleration, deceleration, driveSpeed);
+ }
+ }
+ case ARRIVING -> {
+ if (train.getHeadSection().hasPassed(stopFrame, train.getHeadOfTrainFrame())) {
+ phase = StationPhase.STOPPING;
+ goIntoSwitch = true;
+ } else {
+ newSpeed.approach(acceleration, deceleration, driveSpeed);
+ }
+ }
+ case STOPPING -> {
+ if (newSpeed.isZero()) {
+ if (!stopping) stationHandle.runEntryEffectTriggers(train);
+ stopping = true;
+
+ if (!stationHandle.entryEffectTriggersDone()) break;
+
+ phase = StationPhase.STATIONARY;
+ stationHandle.setStationaryTrain(train);
+
+ if (stationHandle.isExit()) {
+ PlayerFinishedRideEvent.sendFinishedRideEvent(train.getPassengers()
+ .stream()
+ .map(p -> (JRidesPlayer) p)
+ .collect(Collectors.toList()), coasterHandle.getRide());
+ RideFinishedEvent.send(coasterHandle.getRide(), train.getPassengers());
+ }
+
+ coasterHandle.getRideController().onVehicleArrive(train, stationHandle);
+ trainInStationDispatchLock.unlock();
+ restraintsLock.setLocked(true);
+ train.setRestraintForAll(false);
+
+ if (stationHandle.shouldEject())
+ train.ejectPassengers();
+
+ stopping = false;
+ goIntoSwitch = true;
+ } else
+ newSpeed.minus(deceleration, 0);
+ }
+ case STATIONARY -> {
+ BlockSectionSafetyResult safety = getNextSectionSafety(train);
+ if (safety.safe()) {
+ blockSectionOccupiedDispatchLock.unlock();
+ } else {
+ blockSectionOccupiedDispatchLock.lock();
+ blockSectionOccupiedDispatchLock.setDebugStatus(safety.reason());
+ }
+ SimpleDispatchTrigger dispatchTrigger = triggerContext.getDispatchTrigger();
+ if (dispatching || dispatchTrigger.isActive()) {
+ trainInStationDispatchLock.lock();
+ dispatchTrigger.reset();
+
+ if (!dispatching) stationHandle.runExitEffectTriggers(train);
+ dispatching = true;
+
+ if (!stationHandle.exitEffectTriggersDone()) break;
+
+ trainHandle.resetEffects();
+ passThroughCountState = 0;
+
+ phase = StationPhase.WAITING;
+ dispatching = false;
+ goIntoSwitch = true;
+ }
+ }
+ case WAITING -> {
+ Section nextSection = getNextSection(train);
+ if (nextSection != null && nextSection.getBlockSectionSafety(train).safe()) {
+ nextSection.setEntireBlockReservation(train);
+ phase = StationPhase.DEPARTING;
+ blockSectionOccupiedDispatchLock.lock();
+ coasterHandle.getRideController().onVehicleDepart(train, stationHandle);
+ stationHandle.setStationaryTrain(null);
+ train.playDispatchSound();
+ goIntoSwitch = true;
+ }
+ }
+ case DEPARTING -> newSpeed.approach(
+ acceleration,
+ acceleration,
+ driveSpeed*dispatchSpeedMultiplier);
+ }
+ }
+
+ return calculateTrainMovement(train, section, newSpeed);
+ }
+
+ private Section getNextSection(Train train){
+ if(forwardsDispatch) return train.getNextSection();
+ return train.getHeadSection().previous(train);
+ }
+
+ private boolean isTrainSpeedPositive(TrainHandle trainHandle){
+ return trainHandle.getSpeed().isPositive();
+ }
+
+ private boolean shouldPassThrough(){
+ return this.passThroughCountState < this.passThroughCount;
+ }
+
+ private void trainExited(){
+ this.phase = StationPhase.IDLE;
+ this.handlingTrain = null;
+ this.stationHandle.setStationaryTrain(null);
+ }
+
+ @Override
+ public void trainExitedAtStart(@Nullable Train train, @Nullable Section section) {
+ trainExited();
+ }
+
+ @Override
+ public void trainExitedAtEnd(@Nullable Train train, @Nullable Section section){
+ trainExited();
+ }
+
+ @Override
+ public String getName() {
+ return "Station";
+ }
+
+ @Override
+ public boolean canBlock() {
+ return true;
+ }
+
+ @Override
+ public boolean canSpawnOn() {
+ return canSpawn;
+ }
+
+ @Override
+ public Frame getSpawnFrame() {
+ return stopFrame;
+ }
+
+ @Override
+ protected void setParentTrackOnFrames(Track parentTrack) {
+ stopFrame.setTrack(parentTrack);
+ }
+}
+
diff --git a/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/transfer/TrainDisplacerTransferTrackBehaviour.java b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/transfer/TrainDisplacerTransferTrackBehaviour.java
new file mode 100644
index 00000000..a7f61ff9
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/coaster/trackbehaviour/transfer/TrainDisplacerTransferTrackBehaviour.java
@@ -0,0 +1,303 @@
+package com.jverbruggen.jrides.animator.coaster.trackbehaviour.transfer;
+
+import com.jverbruggen.jrides.JRidesPlugin;
+import com.jverbruggen.jrides.animator.coaster.TrainHandle;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.BaseTrackBehaviour;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.result.CartMovementFactory;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.result.TrainMovement;
+import com.jverbruggen.jrides.logging.LogType;
+import com.jverbruggen.jrides.models.math.Matrix4x4;
+import com.jverbruggen.jrides.models.math.Quaternion;
+import com.jverbruggen.jrides.models.math.Vector3;
+import com.jverbruggen.jrides.models.properties.frame.Frame;
+import com.jverbruggen.jrides.models.properties.Speed;
+import com.jverbruggen.jrides.models.ride.coaster.track.Track;
+import com.jverbruggen.jrides.models.ride.coaster.train.Train;
+import com.jverbruggen.jrides.models.ride.coaster.transfer.Transfer;
+import com.jverbruggen.jrides.models.ride.coaster.transfer.TransferPosition;
+import com.jverbruggen.jrides.models.ride.section.Section;
+import com.jverbruggen.jrides.models.ride.section.result.BlockSectionSafetyResult;
+import org.bukkit.Bukkit;
+
+import javax.annotation.Nullable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+public class TrainDisplacerTransferTrackBehaviour extends BaseTrackBehaviour {
+ private final double deceleration;
+ private final double acceleration;
+ private final double enterDriveSpeed;
+ private final double exitDriveSpeed;
+ private final Frame stopFrame;
+ private final Transfer transfer;
+
+ private TransferPhase phase;
+
+ public TrainDisplacerTransferTrackBehaviour(CartMovementFactory cartMovementFactory, double enterDriveSpeed, double deceleration, double acceleration, double exitDriveSpeed, Frame stopFrame, Transfer transfer) {
+ super(cartMovementFactory);
+ this.deceleration = deceleration;
+ this.acceleration = acceleration;
+ this.enterDriveSpeed = enterDriveSpeed;
+ this.exitDriveSpeed = exitDriveSpeed;
+ this.stopFrame = stopFrame;
+ this.transfer = transfer;
+ this.phase = TransferPhase.IDLE;
+ }
+
+ @Override
+ public TrainMovement move(Speed currentSpeed, TrainHandle trainHandle, Section section) {
+ Speed newSpeed = currentSpeed.clone();
+ Train train = trainHandle.getTrain();
+
+ boolean goIntoSwitch = true;
+ while(goIntoSwitch){
+ goIntoSwitch = false;
+ switch(phase){
+ case IDLE:
+ phase = TransferPhase.DRIVING_UNTIL_STOP;
+ goIntoSwitch = true;
+ break;
+ case DRIVING_UNTIL_STOP:
+ if(train.getHeadSection().hasPassed(stopFrame, train.getHeadOfTrainFrame())){
+ phase = TransferPhase.STOPPING;
+ goIntoSwitch = true;
+ }else{
+ newSpeed.approach(acceleration, deceleration, enterDriveSpeed);
+ }
+ break;
+ case STOPPING:
+ if(newSpeed.isZero()){
+ phase = TransferPhase.TRANSFERRING;
+
+ transfer.setTrain(trainHandle);
+ transfer.lockTrain();
+ transfer.setTargetPosition(1, true);
+
+ goIntoSwitch = true;
+ }
+ newSpeed.minus(deceleration, 0);
+ break;
+ case TRANSFERRING:
+ if(transfer.hasReachedRequest()){
+ phase = TransferPhase.WAITING;
+ goIntoSwitch = true;
+ }
+ break;
+ case WAITING:
+ Section currentSection = train.getHeadSection();
+ Section goToSection = getGoToSection(train);
+ if(goToSection != null && goToSection.getBlockSectionSafety(train).safe()){
+ transfer.unlockTrain();
+ transfer.releaseRequest();
+ phase = TransferPhase.DRIVING;
+ goIntoSwitch = true;
+
+ boolean positiveTowardsSectionDirection = currentSection.positiveDirectionToGoTo(goToSection, train);
+ TransferPosition currentTransferPosition = transfer.getCurrentTransferPosition();
+
+ boolean isSectionForwardsType;
+ if(positiveTowardsSectionDirection)
+ isSectionForwardsType = currentTransferPosition.isSectionAtEndForwards();
+ else
+ isSectionForwardsType = currentTransferPosition.isSectionAtStartForwards();
+
+ boolean trainWillBeForwards = isSectionForwardsType;
+
+ train.setFacingForwards(trainWillBeForwards);
+ train.setDrivingDirection(true);
+ goToSection.setEntireBlockReservation(train);
+ }
+ break;
+ case DRIVING:
+ newSpeed.approach(acceleration, deceleration, exitDriveSpeed);
+ break;
+ }
+ }
+
+ return calculateTrainMovement(train, section, newSpeed);
+ }
+
+ private Section getGoToSection(Train train){
+ Section sectionAtStart = getSectionAtStart(train, false);
+ Section sectionAtEnd = getSectionAtEnd(train, false);
+ if(sectionAtEnd != null)
+ return sectionAtEnd;
+ if(sectionAtStart != null)
+ return sectionAtStart;
+ throw new RuntimeException("No Exit section available on transfer");
+ }
+
+ @Override
+ public void trainExitedAtStart(@Nullable Train train, @Nullable Section section) {
+ throw new RuntimeException("Not supported exited train at start train displacer");
+ }
+
+ @Override
+ public void trainExitedAtEnd(@Nullable Train train, @Nullable Section section){
+ phase = TransferPhase.IDLE;
+ transfer.trainExitedTransfer();
+
+ if(section != null){
+ BlockSectionSafetyResult safetyResult = section.getBlockSectionSafety(null);
+ if(!safetyResult.safe()){
+ JRidesPlugin.getLogger().info(LogType.SECTIONS, "Transfer Exit: Not safe for next one yet: " + safetyResult);
+ return;
+ }
+ }
+
+ JRidesPlugin.getLogger().info(LogType.SECTIONS, "Transfer Exit: Safety OK");
+ transfer.resetPosition();
+ }
+
+ @Override
+ public String getName() {
+ return "Transfer";
+ }
+
+ @Override
+ public boolean canBlock() {
+ return true;
+ }
+
+ @Override
+ public boolean canSpawnOn() {
+ return false;
+ }
+
+ @Override
+ public Frame getSpawnFrame() {
+ return null;
+ }
+
+ @Override
+ protected void setParentTrackOnFrames(Track parentTrack) {
+
+ }
+
+ @Override
+ public boolean definesNextSection() {
+ return true;
+ }
+
+ @Override
+ public Vector3 getBehaviourDefinedPosition(Vector3 originalPosition) {
+ Vector3 transferLocation = transfer.getCurrentLocation();
+ Quaternion transferOrientation = transfer.getCurrentOrientation();
+
+ Vector3 offsetFromOrigin = Vector3.subtract(originalPosition, transfer.getOrigin());
+
+ Matrix4x4 rotationMatrix = new Matrix4x4();
+ rotationMatrix.translate(transferLocation);
+ rotationMatrix.rotate(transferOrientation);
+ rotationMatrix.translate(offsetFromOrigin);
+
+ return rotationMatrix.toVector3();
+ }
+
+ @Override
+ public Quaternion getBehaviourDefinedOrientation(Quaternion originalOrientation) {
+ Quaternion transferOrientation = transfer.getCurrentOrientation();
+ return Quaternion.multiply(transferOrientation, originalOrientation);
+ }
+
+ private boolean canTransferSafelyInteractWith(Train train){
+ TrainHandle trainHandle = null;
+ if(train != null)
+ trainHandle = train.getHandle();
+
+ return transfer.canSafelyInteractWith(trainHandle);
+ }
+
+ @Override
+ public Section getSectionAtStart(Train train, boolean process) {
+ if(!canTransferSafelyInteractWith(train)){
+ JRidesPlugin.getLogger().info(LogType.SECTIONS, "No safe interact at start");
+ return null;
+ }
+ return transfer.getCurrentTransferPosition().getSectionAtStart();
+ }
+
+ @Override
+ public Section getSectionAtEnd(Train train, boolean process) {
+ if(!canTransferSafelyInteractWith(train)){
+ JRidesPlugin.getLogger().info(LogType.SECTIONS, "No safe interact at end");
+ return null;
+ }
+ return transfer.getCurrentTransferPosition().getSectionAtEnd();
+ }
+
+ @Override
+ public Collection getAllNextSections(Train train) {
+ return getAllNeighbors(train);
+ }
+
+ @Override
+ public Collection getAllPreviousSections(Train train) {
+ return getAllNeighbors(train);
+ }
+
+ private Collection getAllNeighbors(Train train){
+ List sections = new ArrayList<>();
+ for(TransferPosition transferPosition : transfer.getPossiblePositions()){
+ Section start = transferPosition.getSectionAtStart();
+ Section end = transferPosition.getSectionAtEnd();
+ if(start != null) sections.add(start);
+ if(end != null) sections.add(end);
+ }
+ return sections;
+ }
+
+ @Override
+ public Section getSectionNext(Train train, boolean process) {
+ Section logicalNext = getSectionAtEnd(train, process);
+ if(logicalNext != null) {
+ JRidesPlugin.getLogger().info(LogType.SECTIONS, "Logical next: " + logicalNext.getName());
+ return logicalNext;
+ } else{
+ JRidesPlugin.getLogger().info(LogType.SECTIONS, "Logical next: null");
+ return null;
+ }
+ }
+
+ @Override
+ public Section getSectionPrevious(Train train, boolean process) {
+ Section logicalNext = getSectionAtStart(train, process);
+ if(logicalNext != null) {
+ JRidesPlugin.getLogger().info(LogType.SECTIONS, "Logical prev: " + logicalNext.getName());
+ return logicalNext;
+ }else{
+ JRidesPlugin.getLogger().info(LogType.SECTIONS, "Logical prev: null");
+ return null;
+ }
+ }
+
+ @Override
+ public boolean accepts(Train train) {
+ return canTransferSafelyInteractWith(train);
+ }
+
+ @Override
+ public boolean canHandleConnections() {
+ return true;
+ }
+
+ @Override
+ public boolean nextConnectsToStart() {
+ return transfer.getCurrentTransferPosition().isSectionAtEndConnectsToStart();
+ }
+
+ @Override
+ public boolean previousConnectsToStart() {
+ return transfer.getCurrentTransferPosition().isSectionAtStartConnectsToStart();
+ }
+}
+
+enum TransferPhase{
+ IDLE,
+ DRIVING_UNTIL_STOP,
+ STOPPING,
+ TRANSFERRING,
+ WAITING,
+ DRIVING
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/AbstractFlatRideComponent.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/AbstractFlatRideComponent.java
new file mode 100644
index 00000000..2a32a949
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/AbstractFlatRideComponent.java
@@ -0,0 +1,110 @@
+package com.jverbruggen.jrides.animator.flatride;
+
+import com.jverbruggen.jrides.animator.flatride.attachment.Attachment;
+import com.jverbruggen.jrides.animator.flatride.rotor.FlatRideModel;
+import com.jverbruggen.jrides.models.math.Matrix4x4;
+import com.jverbruggen.jrides.models.math.Quaternion;
+import com.jverbruggen.jrides.models.math.Vector3;
+import com.jverbruggen.jrides.models.ride.flatride.PlayerControl;
+
+import javax.annotation.Nullable;
+import java.util.List;
+
+public abstract class AbstractFlatRideComponent implements FlatRideComponent {
+ private final String identifier;
+ private final String groupIdentifier;
+ private final boolean root;
+ private @Nullable Attachment attachedTo;
+ private final List flatRideModels;
+
+ public AbstractFlatRideComponent(String identifier, String groupIdentifier, boolean root, List flatRideModels) {
+ this.identifier = identifier;
+ this.groupIdentifier = groupIdentifier;
+ this.root = root;
+ this.attachedTo = null;
+ this.flatRideModels = flatRideModels;
+ }
+
+ @Override
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ @Override
+ public String getGroupIdentifier() {
+ return groupIdentifier;
+ }
+
+ @Override
+ public boolean isRoot() {
+ return root;
+ }
+
+ @Override
+ public @Nullable Attachment getAttachedTo() {
+ return attachedTo;
+ }
+
+ @Override
+ public void setAttachedTo(@Nullable Attachment attachment) {
+ attachedTo = attachment;
+ }
+
+ @Override
+ public Quaternion getRotation() {
+ Attachment attachedTo = getAttachedTo();
+ if(attachedTo == null) throw new RuntimeException("Component " + identifier + " not attached to anything");
+
+ return attachedTo.getRotation();
+ }
+
+ @Override
+ public Vector3 getPosition() {
+ Attachment attachedTo = getAttachedTo();
+ if(attachedTo == null) throw new RuntimeException("Component " + identifier + " not attached to anything");
+
+ return attachedTo.getPosition();
+ }
+
+ @Override
+ public Matrix4x4 getPositionMatrix(){
+ Attachment attachedTo = getAttachedTo();
+ if(attachedTo == null) throw new RuntimeException("Component " + identifier + " not attached to anything");
+
+ return attachedTo.getCachedMatrix();
+ }
+
+ @Override
+ public void tick() {
+ updateFlatRideModels();
+ }
+
+ @Override
+ public void attach(FlatRideComponent child, Quaternion offsetRotation, Vector3 offsetPosition) {
+ throw new RuntimeException("Cannot attach to this component");
+ }
+
+ @Nullable
+ @Override
+ public PlayerControl getPlayerControl() {
+ Attachment attachedTo = getAttachedTo();
+ if(attachedTo == null) return null;
+ if(attachedTo.getParent() == null) return null;
+
+ FlatRideComponent parent = attachedTo.getParent();
+ if(parent == null) throw new RuntimeException("Expected flat ride component " + identifier + " to have parent");
+
+ return parent.getPlayerControl();
+ }
+
+ protected void updateFlatRideModels(){
+ for(FlatRideModel flatRideModel : flatRideModels){
+ flatRideModel.updateLocation(getPosition(), getRotation());
+ }
+ }
+
+ @Override
+ public boolean equalsToIdentifier(String identifier) {
+ return identifier.equals(this.identifier) || identifier.equals(this.groupIdentifier);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/AbstractInterconnectedFlatRideComponent.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/AbstractInterconnectedFlatRideComponent.java
new file mode 100644
index 00000000..221d8c89
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/AbstractInterconnectedFlatRideComponent.java
@@ -0,0 +1,61 @@
+package com.jverbruggen.jrides.animator.flatride;
+
+import com.jverbruggen.jrides.animator.flatride.attachment.Attachment;
+import com.jverbruggen.jrides.animator.flatride.attachment.RelativeAttachment;
+import com.jverbruggen.jrides.animator.flatride.rotor.FlatRideModel;
+import com.jverbruggen.jrides.config.flatride.structure.attachment.joint.RelativeAttachmentJointConfig;
+import com.jverbruggen.jrides.models.math.Quaternion;
+import com.jverbruggen.jrides.models.math.Vector3;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class AbstractInterconnectedFlatRideComponent extends AbstractFlatRideComponent {
+ private final List children;
+ private final RelativeAttachmentJointConfig joint;
+
+ public AbstractInterconnectedFlatRideComponent(String identifier, String groupIdentifier, boolean root, RelativeAttachmentJointConfig joint, List flatRideModels) {
+ super(identifier, groupIdentifier, root, flatRideModels);
+ this.joint = joint;
+ this.children = new ArrayList<>();
+ }
+
+ @Override
+ public void attach(FlatRideComponent child, Quaternion offsetRotation, Vector3 offsetPosition){
+ Attachment attachment = new RelativeAttachment(this, child, offsetRotation, offsetPosition);
+
+ child.setAttachedTo(attachment);
+ children.add(attachment);
+ }
+
+ @Override
+ public void tick() {
+ for(Attachment attachment : getChildren()){
+ attachment.update();
+ attachment.getChild().tick();
+ }
+
+ updateFlatRideModels();
+ }
+
+ @Override
+ public Quaternion getRotation() {
+ Attachment attachedTo = getAttachedTo();
+ if(attachedTo == null) throw new RuntimeException("Interconnected component " + getIdentifier() + " not attached to anything");
+ Quaternion rotation = attachedTo.getRotation();
+
+ if(joint != null && joint.anyFixed()){
+ double pitch = joint.isFixedX() ? -rotation.getPitch() + joint.getFixX() : 0;
+ double yaw = joint.isFixedY() ? -rotation.getYaw() + joint.getFixY() : 0;
+ double roll = joint.isFixedZ() ? -rotation.getRoll() + joint.getFixZ() : 0;
+ rotation.rotateYawPitchRoll(pitch, yaw, roll);
+ }
+
+ return rotation;
+ }
+
+
+ public List getChildren() {
+ return children;
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/AbstractPlayerControl.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/AbstractPlayerControl.java
new file mode 100644
index 00000000..e581e348
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/AbstractPlayerControl.java
@@ -0,0 +1,53 @@
+package com.jverbruggen.jrides.animator.flatride;
+
+import com.jverbruggen.jrides.animator.flatride.rotor.controltype.ControlType;
+import com.jverbruggen.jrides.api.JRidesPlayer;
+import com.jverbruggen.jrides.models.ride.flatride.PlayerControl;
+import org.bukkit.ChatColor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class AbstractPlayerControl implements PlayerControl {
+ private List controlling;
+ private final ControlType controlType;
+
+
+ public AbstractPlayerControl(ControlType controlType) {
+ this.controlType = controlType;
+ this.controlling = null;
+ }
+
+ @Override
+ public void addControlling(JRidesPlayer player) {
+ if(controlling == null) controlling = new ArrayList<>();
+ controlling.add(player);
+ }
+
+ @Override
+ public void removeControlling(JRidesPlayer player) {
+ if(controlling == null) return;
+ controlling.remove(player);
+ if(controlling.size() == 0) controlling = null;
+ }
+
+ @Override
+ public void sendStartNotification() {
+ if(controlling == null) return;
+
+ String title = controlType.getControlMessageTitle();
+ String subTitle = controlType.getControlMessageSubtitle();
+
+ controlling.forEach(
+ p -> p.sendTitle(title, subTitle, 60));
+ }
+
+ public ControlType getControlType() {
+ return controlType;
+ }
+
+ @Override
+ public void sendStopNotification() {
+
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/ActuatorMode.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/ActuatorMode.java
new file mode 100644
index 00000000..02308f1d
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/ActuatorMode.java
@@ -0,0 +1,6 @@
+package com.jverbruggen.jrides.animator.flatride;
+
+public interface ActuatorMode {
+ double getLowerBound();
+ double getUpperBound();
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/BlenderExportPositionRecord.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/BlenderExportPositionRecord.java
new file mode 100644
index 00000000..1ee95726
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/BlenderExportPositionRecord.java
@@ -0,0 +1,110 @@
+package com.jverbruggen.jrides.animator.flatride;
+
+import com.jverbruggen.jrides.models.math.Quaternion;
+import com.jverbruggen.jrides.models.math.Vector3;
+import com.jverbruggen.jrides.models.math.VectorQuaternionState;
+
+public class BlenderExportPositionRecord {
+ private final String object;
+ private final int frame;
+ private final float posx;
+ private final float posy;
+ private final float posz;
+ private final float scalex;
+ private final float scaley;
+ private final float scalez;
+ private final float rw;
+ private final float rx;
+ private final float ry;
+ private final float rz;
+
+ public BlenderExportPositionRecord(String object, int frame, float posx, float posy, float posz, float scalex, float scaley, float scalez, float rw, float rx, float ry, float rz) {
+ this.object = object;
+ this.frame = frame;
+ this.posx = posx;
+ this.posy = posy;
+ this.posz = posz;
+ this.scalex = scalex;
+ this.scaley = scaley;
+ this.scalez = scalez;
+ this.rw = rw;
+ this.rx = rx;
+ this.ry = ry;
+ this.rz = rz;
+ }
+
+ public String getObject() {
+ return object;
+ }
+
+ public int getFrame() {
+ return frame;
+ }
+
+ public float getPosx() {
+ return posx;
+ }
+
+ public float getPosy() {
+ return posy;
+ }
+
+ public float getPosz() {
+ return posz;
+ }
+
+ public float getRw() {
+ return rw;
+ }
+
+ public float getRx() {
+ return rx;
+ }
+
+ public float getRy() {
+ return ry;
+ }
+
+ public float getRz() {
+ return rz;
+ }
+
+ public Vector3 toMinecraftVector(){
+ return new Vector3(
+ this.getPosx(),
+ this.getPosz(), // Minecraft Y = Blender Z
+ -this.getPosy());
+ }
+
+ public Quaternion toMinecraftQuaternion(){
+ return new Quaternion(
+ this.getRx(),
+ this.getRz(), // Minecraft Y = Blender Z
+ -this.getRy(),
+ this.getRw());
+ }
+
+ public VectorQuaternionState toVectorQuaternionState(){
+ return new VectorQuaternionState(
+ toMinecraftVector(),
+ toMinecraftQuaternion()
+ );
+ }
+
+ public static BlenderExportPositionRecord createFromCSVAttributes(String[] attributes){
+ return new BlenderExportPositionRecord(
+ attributes[0],
+ Integer.parseInt(attributes[1]),
+ Float.parseFloat(attributes[2]),
+ Float.parseFloat(attributes[3]),
+ Float.parseFloat(attributes[4]),
+ Float.parseFloat(attributes[5]),
+ Float.parseFloat(attributes[6]),
+ Float.parseFloat(attributes[7]),
+ Float.parseFloat(attributes[8]),
+ Float.parseFloat(attributes[9]),
+ Float.parseFloat(attributes[10]),
+ Float.parseFloat(attributes[11])
+ );
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/FlatRideComponent.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/FlatRideComponent.java
new file mode 100644
index 00000000..ca91290a
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/FlatRideComponent.java
@@ -0,0 +1,223 @@
+package com.jverbruggen.jrides.animator.flatride;
+
+import com.jverbruggen.jrides.animator.flatride.attachment.Attachment;
+import com.jverbruggen.jrides.animator.flatride.basic.StaticStructureComponent;
+import com.jverbruggen.jrides.animator.flatride.linearactuator.LinearActuator;
+import com.jverbruggen.jrides.animator.flatride.linearactuator.mode.LinearActuatorMode;
+import com.jverbruggen.jrides.animator.flatride.rotor.FlatRideModel;
+import com.jverbruggen.jrides.animator.flatride.rotor.Rotor;
+import com.jverbruggen.jrides.animator.flatride.rotor.axis.RotorAxis;
+import com.jverbruggen.jrides.animator.flatride.rotor.axis.RotorAxisFactory;
+import com.jverbruggen.jrides.animator.flatride.rotor.mode.RotorActuatorMode;
+import com.jverbruggen.jrides.animator.flatride.seat.FlatRideSeat;
+import com.jverbruggen.jrides.animator.flatride.seat.SeatComponent;
+import com.jverbruggen.jrides.config.coaster.objects.cart.ModelConfig;
+import com.jverbruggen.jrides.config.flatride.structure.actuator.LimbConfig;
+import com.jverbruggen.jrides.config.flatride.structure.actuator.LinearActuatorConfig;
+import com.jverbruggen.jrides.config.flatride.structure.actuator.RotorPlayerControlConfig;
+import com.jverbruggen.jrides.config.flatride.structure.attachment.joint.RelativeAttachmentJointConfig;
+import com.jverbruggen.jrides.models.entity.VirtualEntity;
+import com.jverbruggen.jrides.models.math.*;
+import com.jverbruggen.jrides.models.ride.flatride.PlayerControl;
+import com.jverbruggen.jrides.serviceprovider.ServiceProvider;
+import com.jverbruggen.jrides.state.viewport.ViewportManager;
+
+import javax.annotation.Nullable;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.function.BiFunction;
+import java.util.stream.Collectors;
+
+public interface FlatRideComponent {
+ String getIdentifier();
+ String getGroupIdentifier();
+ boolean isRoot();
+ Attachment getAttachedTo();
+ void setAttachedTo(Attachment attachment);
+ void attach(FlatRideComponent child, Quaternion offsetRotation, Vector3 offsetPosition);
+ Quaternion getRotation();
+ Vector3 getPosition();
+ Matrix4x4 getPositionMatrix();
+ void tick();
+ boolean equalsToIdentifier(String identifier);
+ @Nullable PlayerControl getPlayerControl();
+
+ static List findAllMatching(List components, String needle){
+ return components.stream()
+ .filter(c -> c.equalsToIdentifier(needle))
+ .collect(Collectors.toList());
+ }
+
+ private static List createDistributedComponent(String identifier, Quaternion offsetRotation, int amount, BiFunction creationFunction){
+ if(amount == 1){
+ return List.of(creationFunction.apply(offsetRotation.clone(), identifier));
+ }
+
+ List rotors = new ArrayList<>();
+ Quaternion workingQuaternion = offsetRotation.clone();
+
+ for(int i = 0; i < amount; i++){
+ rotors.add(creationFunction.apply(workingQuaternion.clone(), identifier + "_" + (i+1)));
+
+ workingQuaternion.rotateY(360f/amount);
+ }
+ return rotors;
+ }
+
+ static List createDistributedSeats(FlatRideHandle rideHandle, String identifier, FlatRideComponent attachedTo, Quaternion offsetRotation, Vector3 offsetPosition, int seatYawOffset, List flatRideModelsConfig, int amount){
+ return createDistributedComponent(
+ identifier,
+ offsetRotation,
+ amount,
+ (seatQuaternion, seatIdentifier) -> createSeat(
+ rideHandle, seatIdentifier, identifier, attachedTo, seatQuaternion, offsetPosition, seatYawOffset, flatRideModelsConfig));
+ }
+
+ static List createDistributedAttachedRotors(String identifier, FlatRideComponent attachedTo, Quaternion offsetRotation, Vector3 offsetPosition, FlatRideComponentSpeed flatRideComponentSpeed, RotorActuatorMode rotorActuatorMode, RotorPlayerControlConfig controlConfig, RelativeAttachmentJointConfig jointConfig, String rotorAxisSpec, List flatRideModelsConfig, int amount){
+ return createDistributedComponent(
+ identifier,
+ offsetRotation,
+ amount,
+ (rotorQuaternion, rotorIdentifier) -> FlatRideComponent.createAttachedRotor(
+ rotorIdentifier, identifier, attachedTo, rotorQuaternion, offsetPosition,
+ flatRideComponentSpeed.clone(), controlConfig, jointConfig, RotorAxisFactory.createAxisFromString(rotorAxisSpec),
+ rotorActuatorMode, flatRideModelsConfig));
+ }
+
+ static List createDistributedLinearActuators(FlatRideComponent attachedTo, Quaternion offsetRotation, Vector3 offsetPosition, LinearActuatorConfig linearActuatorConfig, int amount) {
+ return createDistributedComponent(
+ linearActuatorConfig.getIdentifier(),
+ offsetRotation,
+ amount,
+ (linearActuatorQuaternion, linearActuatorIdentifier) -> FlatRideComponent.createLinearActuator(
+ linearActuatorIdentifier, linearActuatorConfig.getIdentifier(), attachedTo,
+ linearActuatorQuaternion, offsetPosition, linearActuatorConfig.getFlatRideComponentSpeed().clone(),
+ linearActuatorConfig.getLinearActuatorTypeConfig().createActuatorMode(),
+ linearActuatorConfig.getFlatRideModels()));
+ }
+
+ static List createLimb(FlatRideComponent attachedTo, Quaternion offsetRotation, Vector3 offsetPosition, LimbConfig limbConfig, VectorQuaternionState initialPose) {
+ return createDistributedComponent(
+ limbConfig.getIdentifier(),
+ offsetRotation,
+ 1,
+ (limbQuaternion, limbIdentifier) -> FlatRideComponent.createLimb(
+ limbIdentifier, limbConfig.getIdentifier(), attachedTo,
+ limbQuaternion, offsetPosition, limbConfig.getFlatRideModels(), initialPose));
+ }
+
+ static Rotor createAttachedRotor(String identifier, String groupIdentifier, FlatRideComponent attachedTo, Quaternion offsetRotation, Vector3 offsetPosition, FlatRideComponentSpeed flatRideComponentSpeed, RotorPlayerControlConfig controlConfig, RelativeAttachmentJointConfig jointConfig, RotorAxis rotorAxis, RotorActuatorMode actuatorMode, List flatRideModelsConfig){
+ ViewportManager viewportManager = ServiceProvider.getSingleton(ViewportManager.class);
+
+ Vector3 spawnPosition = MatrixMath.rotateTranslate(
+ attachedTo.getPosition(),
+ attachedTo.getRotation(),
+ offsetPosition,
+ offsetRotation).toVector3();
+
+ List flatRideModels = flatRideModelsConfig.stream()
+ .map(config -> config.toFlatRideModel(spawnPosition, viewportManager))
+ .collect(Collectors.toList());
+
+ Rotor rotor = new Rotor(identifier, groupIdentifier, false, jointConfig, flatRideModels, flatRideComponentSpeed, rotorAxis, actuatorMode);
+ rotor.createPlayerControl(controlConfig);
+ attachedTo.attach(rotor, offsetRotation, offsetPosition);
+
+ return rotor;
+ }
+
+ static LinearActuator createLinearActuator(String identifier, String groupIdentifier, FlatRideComponent attachedTo, Quaternion offsetRotation, Vector3 offsetPosition, FlatRideComponentSpeed flatRideComponentSpeed, LinearActuatorMode actuatorMode, List flatRideModelsConfig){
+ ViewportManager viewportManager = ServiceProvider.getSingleton(ViewportManager.class);
+
+ Vector3 spawnPosition = MatrixMath.rotateTranslate(
+ attachedTo.getPosition(),
+ attachedTo.getRotation(),
+ offsetPosition,
+ offsetRotation).toVector3();
+
+ List flatRideModels = flatRideModelsConfig.stream()
+ .map(config -> config.toFlatRideModel(spawnPosition, viewportManager))
+ .collect(Collectors.toList());
+
+ LinearActuator linearActuator = new LinearActuator(identifier, groupIdentifier, false, null, flatRideModels, flatRideComponentSpeed, actuatorMode);
+ attachedTo.attach(linearActuator, offsetRotation, offsetPosition);
+
+ return linearActuator;
+ }
+
+ static Limb createLimb(String identifier, String groupIdentifier, FlatRideComponent attachedTo, Quaternion offsetRotation, Vector3 offsetPosition, List flatRideModelsConfig, VectorQuaternionState initialPose){
+ ViewportManager viewportManager = ServiceProvider.getSingleton(ViewportManager.class);
+
+ Vector3 spawnPosition = MatrixMath.rotateTranslate(
+ attachedTo.getPosition(),
+ attachedTo.getRotation(),
+ offsetPosition,
+ offsetRotation).toVector3();
+
+ List flatRideModels = flatRideModelsConfig.stream()
+ .map(config -> config.toFlatRideModel(spawnPosition, viewportManager))
+ .collect(Collectors.toList());
+
+ Limb limb = new Limb(identifier, groupIdentifier, false, null, flatRideModels, initialPose);
+ attachedTo.attach(limb, offsetRotation, offsetPosition);
+
+ return limb;
+ }
+
+
+ static SeatComponent createSeat(FlatRideHandle flatRideHandle, String identifier, String groupIdentifier, FlatRideComponent attachedTo, Quaternion offsetRotation, Vector3 offsetPosition, int seatYawOffset, List flatRideModelsConfig){
+ ViewportManager viewportManager = ServiceProvider.getSingleton(ViewportManager.class);
+
+ Vector3 spawnPosition = MatrixMath.rotateTranslate(
+ attachedTo.getPosition(),
+ attachedTo.getRotation(),
+ offsetPosition,
+ offsetRotation).toVector3();
+
+ VirtualEntity seatEntity = viewportManager.spawnSeatEntity(spawnPosition, 0, null);
+ FlatRideSeat seat = new FlatRideSeat(flatRideHandle, null, seatEntity, Vector3PlusYaw.zero());
+
+ List flatRideModels = flatRideModelsConfig.stream()
+ .map(config -> {
+ FlatRideModel flatRideModel = config.toFlatRideModel(spawnPosition, viewportManager);
+ flatRideModel.getEntity().setHostSeat(seat);
+ return flatRideModel;
+ })
+ .collect(Collectors.toList());
+
+
+ Quaternion seatRotation = Quaternion.fromYawPitchRoll(0, seatYawOffset, 0);
+ SeatComponent component = new SeatComponent(identifier, groupIdentifier, false, flatRideModels, seat, seatRotation, flatRideHandle.getVehicle());
+ seat.setParentSeatHost(component);
+ flatRideHandle.addSeatComponent(component);
+
+ attachedTo.attach(component, offsetRotation, offsetPosition);
+
+ PlayerControl playerControl = attachedTo.getPlayerControl();
+ if(playerControl != null){
+ seat.setPlayerControl(playerControl);
+ }
+
+ return component;
+ }
+
+ static StaticStructureComponent createStaticStructure(String identifier, String groupIdentifier, FlatRideComponent attachedTo, Quaternion offsetRotation, Vector3 offsetPosition, RelativeAttachmentJointConfig joint, List flatRideModelsConfig){
+ ViewportManager viewportManager = ServiceProvider.getSingleton(ViewportManager.class);
+
+ Vector3 spawnPosition = MatrixMath.rotateTranslate(
+ attachedTo.getPosition(),
+ attachedTo.getRotation(),
+ offsetPosition,
+ offsetRotation).toVector3();
+
+ List flatRideModels = flatRideModelsConfig.stream()
+ .map(config -> config.toFlatRideModel(spawnPosition, viewportManager))
+ .collect(Collectors.toList());
+
+ StaticStructureComponent component = new StaticStructureComponent(identifier, groupIdentifier, false, joint, flatRideModels);
+ attachedTo.attach(component, offsetRotation, offsetPosition);
+
+ return component;
+ }
+
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/FlatRideComponentSpeed.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/FlatRideComponentSpeed.java
new file mode 100644
index 00000000..98c6ce4d
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/FlatRideComponentSpeed.java
@@ -0,0 +1,66 @@
+package com.jverbruggen.jrides.animator.flatride;
+
+public class FlatRideComponentSpeed {
+ private double speed;
+ private double minSpeed;
+ private double maxSpeed;
+
+ public FlatRideComponentSpeed(double speed, double minSpeed, double maxSpeed) {
+ if(minSpeed > maxSpeed) throw new RuntimeException("Min speed has to be lower than max speed");
+ else if(speed > maxSpeed) throw new RuntimeException("Speed has to be lower than max speed");
+ else if(speed < minSpeed) throw new RuntimeException("Speed has to be higher than min speed");
+
+ this.speed = speed;
+ this.minSpeed = minSpeed;
+ this.maxSpeed = maxSpeed;
+ }
+
+ public FlatRideComponentSpeed(double speed){
+ this.speed = 0;
+ this.minSpeed = 0;
+ this.maxSpeed = speed;
+ }
+
+ /**
+ * Discouraged. This is an abrupt speed change.
+ * Only use when absolutely necessary.
+ */
+ public void setHard(double speed){
+ this.speed = speed;
+ }
+
+ public void accelerate(double acceleration){
+ this.speed += acceleration;
+ if(this.speed > this.maxSpeed) this.speed = this.maxSpeed;
+ else if(this.speed < this.minSpeed) this.speed = this.minSpeed;
+ }
+
+ public void accelerateTowards(double acceleration, double towards){
+ if(this.speed > towards){
+ this.speed -= acceleration;
+ if(this.speed < towards) this.speed = towards;
+ }else if(this.speed < towards){
+ this.speed += acceleration;
+ if(this.speed > towards) this.speed = towards;
+ }
+
+ if(this.speed > this.maxSpeed) this.speed = this.maxSpeed;
+ else if(this.speed < this.minSpeed) this.speed = this.minSpeed;
+ }
+
+ public double getSpeed() {
+ return speed;
+ }
+
+ public double getMinSpeed() {
+ return minSpeed;
+ }
+
+ public double getMaxSpeed() {
+ return maxSpeed;
+ }
+
+ public FlatRideComponentSpeed clone(){
+ return new FlatRideComponentSpeed(this.speed, this.minSpeed, this.maxSpeed);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/FlatRideHandle.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/FlatRideHandle.java
new file mode 100644
index 00000000..1cbb1e70
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/FlatRideHandle.java
@@ -0,0 +1,198 @@
+package com.jverbruggen.jrides.animator.flatride;
+
+import com.jverbruggen.jrides.animator.AbstractRideHandle;
+import com.jverbruggen.jrides.animator.flatride.seat.SeatComponent;
+import com.jverbruggen.jrides.animator.flatride.station.FlatRideStationHandle;
+import com.jverbruggen.jrides.animator.flatride.timing.TimingSequence;
+import com.jverbruggen.jrides.api.JRidesPlayer;
+import com.jverbruggen.jrides.config.coaster.objects.SoundsConfig;
+import com.jverbruggen.jrides.config.ride.RideCounterMapConfigs;
+import com.jverbruggen.jrides.control.controller.RideController;
+import com.jverbruggen.jrides.control.trigger.DispatchTrigger;
+import com.jverbruggen.jrides.control.trigger.SimpleDispatchTrigger;
+import com.jverbruggen.jrides.control.trigger.TriggerContext;
+import com.jverbruggen.jrides.event.player.PlayerFinishedRideEvent;
+import com.jverbruggen.jrides.event.ride.RideFinishedEvent;
+import com.jverbruggen.jrides.models.entity.Player;
+import com.jverbruggen.jrides.models.properties.PlayerLocation;
+import com.jverbruggen.jrides.models.ride.Ride;
+import com.jverbruggen.jrides.models.ride.StationHandle;
+import com.jverbruggen.jrides.models.ride.coaster.train.Vehicle;
+import com.jverbruggen.jrides.models.ride.count.RideCounterRecord;
+import com.jverbruggen.jrides.models.ride.gate.Gate;
+import org.bukkit.World;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import javax.annotation.Nonnull;
+
+public class FlatRideHandle extends AbstractRideHandle {
+ private TimingSequence timingSequence;
+ private final FlatRideStationHandle stationHandle;
+ private final SimpleDispatchTrigger dispatchTrigger;
+ private final List seatComponents;
+
+ private FlatRideState flatRideState;
+
+ public FlatRideHandle(World world, Ride ride, boolean loaded, FlatRideStationHandle stationHandle, SoundsConfig sounds, PlayerLocation customEjectLocation, RideCounterMapConfigs rideCounterMapConfigs) {
+ super(world, ride, null, loaded, sounds, customEjectLocation, rideCounterMapConfigs);
+ this.stationHandle = stationHandle;
+ this.timingSequence = null;
+ this.dispatchTrigger = stationHandle.getTriggerContext().getDispatchTrigger();
+ this.flatRideState = FlatRideState.IDLE;
+ this.seatComponents = new ArrayList<>();
+
+ stationHandle.setFlatRideHandle(this);
+ stationHandle.getTriggerContext().getRestraintTrigger().getLock().addEventListener(c -> this.onRestraintLockUpdateEventListener(c.isUnlocked()));
+ stationHandle.getEntryGates().forEach(Gate::open);
+ }
+
+ @Override
+ public void tick() {
+ if(!isLoaded()) return;
+
+ RideController rideController = getRideController();
+ if(rideController.isActive())
+ rideController.getControlMode().tick();
+
+ switch(this.flatRideState){
+ case IDLE -> {
+ vehicleTick();
+
+ boolean dispatchActive = dispatchTrigger.isActive();
+ if(dispatchActive){
+ boolean dispatched = checkForDispatch(dispatchActive);
+ if(dispatched){
+ stationHandle.runExitEffectTriggers(null);
+ this.flatRideState = FlatRideState.STARTING;
+ }
+ }
+ }
+ case STARTING -> {
+ if(stationHandle.exitEffectTriggersDone()){
+ this.flatRideState = FlatRideState.RUNNING;
+ }
+ }
+ case RUNNING -> {
+ boolean finished = vehicleTick();
+
+ if(finished) {
+ stationHandle.runEntryEffectTriggers(null);
+ this.flatRideState = FlatRideState.STOPPING;
+ }
+ }
+ case STOPPING -> {
+ if(stationHandle.entryEffectTriggersDone()){
+ onRideFinish();
+ this.flatRideState = FlatRideState.IDLE;
+ }
+ }
+ }
+ }
+
+ private boolean vehicleTick(){
+ boolean finished = this.timingSequence.tick();
+ this.stationHandle.getVehicle().tick();
+
+ return finished;
+ }
+
+ private boolean checkForDispatch(boolean dispatchActive){
+ if(dispatchActive && this.timingSequence.isIdle()){
+ onRideStart();
+
+ Vehicle vehicle = getVehicle();
+ getRideController().onVehicleDepart(vehicle, stationHandle);
+ vehicle.playDispatchSound();
+ return true;
+ }else return false;
+ }
+
+ private void onRideStart(){
+ dispatchTrigger.reset();
+ this.timingSequence.restart();
+ stationHandle.getTriggerContext().getVehiclePresentLock().setLocked(true);
+ stationHandle.getEntryGates().forEach(Gate::close);
+ }
+
+ private void onRideFinish(){
+ PlayerFinishedRideEvent.sendFinishedRideEvent(getPassengers()
+ .stream()
+ .map(p -> (JRidesPlayer)p)
+ .collect(Collectors.toList()), getRide());
+ RideFinishedEvent.send(getRide(), getPassengers());
+
+ stationHandle.getTriggerContext().getVehiclePresentLock().setLocked(false);
+ stationHandle.getTriggerContext().getRestraintTrigger().getLock().setLocked(true);
+ stationHandle.getVehicle().ejectPassengers();
+ stationHandle.getEntryGates().forEach(Gate::open);
+ }
+
+ private void onRestraintLockUpdateEventListener(boolean unlocked){
+ seatComponents.forEach(c -> c.setRestraint(unlocked));
+ }
+
+ public void setTimingSequence(TimingSequence timingSequence) {
+ this.timingSequence = timingSequence;
+ }
+
+ public void addRootComponent(FlatRideComponent component){
+ stationHandle.getVehicle().addRootComponent(component);
+ }
+
+ public List getRootComponents() {
+ return stationHandle.getVehicle().getRootComponents();
+ }
+
+ @Override
+ public DispatchTrigger getDispatchTrigger() {
+ return getFirstTriggerContext().getDispatchTrigger();
+ }
+
+ @Override
+ public TriggerContext getTriggerContext(@Nonnull String contextOwner) {
+ return getFirstTriggerContext();
+ }
+
+ @Override
+ public TriggerContext getFirstTriggerContext() {
+ return stationHandle.getTriggerContext();
+ }
+
+ @Override
+ public PlayerLocation getEjectLocation() {
+ return stationHandle.getEjectLocation();
+ }
+
+ @Override
+ public List getStationHandles() {
+ return List.of(stationHandle);
+ }
+
+ @Override
+ public List getTopRideCounters() {
+ return null;
+ }
+
+ @Override
+ public List getPassengers() {
+ return stationHandle.getVehicle().getPassengers();
+ }
+
+ public Vehicle getVehicle(){
+ return stationHandle.getVehicle();
+ }
+
+ public void addSeatComponent(SeatComponent seatComponent){
+ this.seatComponents.add(seatComponent);
+ }
+}
+
+enum FlatRideState{
+ IDLE,
+ STARTING,
+ RUNNING,
+ STOPPING
+}
\ No newline at end of file
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/Limb.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/Limb.java
new file mode 100644
index 00000000..fdb55a45
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/Limb.java
@@ -0,0 +1,55 @@
+package com.jverbruggen.jrides.animator.flatride;
+
+import com.jverbruggen.jrides.animator.flatride.interfaces.Component6DOFPosition;
+import com.jverbruggen.jrides.animator.flatride.rotor.FlatRideModel;
+import com.jverbruggen.jrides.config.flatride.structure.attachment.joint.RelativeAttachmentJointConfig;
+import com.jverbruggen.jrides.models.math.Quaternion;
+import com.jverbruggen.jrides.models.math.Vector3;
+import com.jverbruggen.jrides.models.math.VectorQuaternionState;
+import com.jverbruggen.jrides.serviceprovider.ServiceProvider;
+import com.jverbruggen.jrides.state.ride.flatride.Animation;
+import com.jverbruggen.jrides.state.ride.flatride.AnimationHandle;
+import com.jverbruggen.jrides.state.ride.flatride.AnimationLoader;
+
+import java.util.List;
+
+public class Limb extends AbstractInterconnectedFlatRideComponent implements Component6DOFPosition {
+ private Vector3 position;
+ private Quaternion rotation;
+
+ public Limb(String identifier, String groupIdentifier, boolean root, RelativeAttachmentJointConfig joint, List flatRideModels, VectorQuaternionState initialPose) {
+ super(identifier, groupIdentifier, root, joint, flatRideModels);
+ position = initialPose.getVector();
+ rotation = initialPose.getQuaternion();
+ }
+
+ @Override
+ public Vector3 getPosition() {
+ return Vector3.add(super.getPosition(), position);
+ }
+
+ @Override
+ public Quaternion getRotation() {
+ return Quaternion.multiply(super.getRotation(), rotation);
+ }
+
+ @Override
+ public void setPositionRotation(Vector3 position, Quaternion rotation) {
+ this.position = position;
+ this.rotation = rotation;
+ }
+
+ public static VectorQuaternionState getInitialPoseFromAnimation(String preloadAnim, String limbIdentifier, FlatRideHandle rideHandle){
+ VectorQuaternionState vectorQuaternionState;
+ if(preloadAnim != null){
+ AnimationLoader animationLoader = ServiceProvider.getSingleton(AnimationLoader.class);
+ AnimationHandle animationHandle = animationLoader.loadFlatRideAnimation(preloadAnim, rideHandle);
+ Animation animation = animationHandle.getAnimation(limbIdentifier);
+ vectorQuaternionState = animation.getInitialPose();
+ }else{
+ vectorQuaternionState = VectorQuaternionState.zero();
+ }
+
+ return vectorQuaternionState;
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/attachment/Attachment.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/attachment/Attachment.java
new file mode 100644
index 00000000..ae06df11
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/attachment/Attachment.java
@@ -0,0 +1,17 @@
+package com.jverbruggen.jrides.animator.flatride.attachment;
+
+import com.jverbruggen.jrides.animator.flatride.FlatRideComponent;
+import com.jverbruggen.jrides.models.math.Matrix4x4;
+import com.jverbruggen.jrides.models.math.Quaternion;
+import com.jverbruggen.jrides.models.math.Vector3;
+
+import javax.annotation.Nullable;
+
+public interface Attachment {
+ Vector3 getPosition();
+ Quaternion getRotation();
+ Matrix4x4 getCachedMatrix();
+ FlatRideComponent getChild();
+ @Nullable FlatRideComponent getParent();
+ void update();
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/attachment/FixedAttachment.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/attachment/FixedAttachment.java
new file mode 100644
index 00000000..e83b5b0d
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/attachment/FixedAttachment.java
@@ -0,0 +1,41 @@
+package com.jverbruggen.jrides.animator.flatride.attachment;
+
+import com.jverbruggen.jrides.animator.flatride.FlatRideComponent;
+import com.jverbruggen.jrides.models.math.Matrix4x4;
+import com.jverbruggen.jrides.models.math.Quaternion;
+import com.jverbruggen.jrides.models.math.Vector3;
+
+public record FixedAttachment(FlatRideComponent child, Vector3 position, Quaternion rotation) implements Attachment {
+ @Override
+ public Vector3 getPosition() {
+ return position;
+ }
+
+ @Override
+ public Quaternion getRotation() {
+ return rotation;
+ }
+
+ @Override
+ public Matrix4x4 getCachedMatrix() {
+ Matrix4x4 matrix = new Matrix4x4();
+ matrix.translate(getPosition());
+ matrix.rotate(getRotation());
+ return matrix;
+ }
+
+ @Override
+ public FlatRideComponent getChild() {
+ return child;
+ }
+
+ @Override
+ public FlatRideComponent getParent() {
+ return null;
+ }
+
+ @Override
+ public void update() {
+
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/attachment/RelativeAttachment.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/attachment/RelativeAttachment.java
new file mode 100644
index 00000000..5c61483b
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/attachment/RelativeAttachment.java
@@ -0,0 +1,59 @@
+package com.jverbruggen.jrides.animator.flatride.attachment;
+
+import com.jverbruggen.jrides.animator.flatride.FlatRideComponent;
+import com.jverbruggen.jrides.models.math.Matrix4x4;
+import com.jverbruggen.jrides.models.math.MatrixMath;
+import com.jverbruggen.jrides.models.math.Quaternion;
+import com.jverbruggen.jrides.models.math.Vector3;
+
+public class RelativeAttachment implements Attachment {
+ private FlatRideComponent parent;
+ private FlatRideComponent child;
+ private Quaternion offsetRotation;
+ private Vector3 offsetPosition;
+ private Matrix4x4 cacheMatrix;
+
+ public RelativeAttachment(FlatRideComponent parent, FlatRideComponent child, Quaternion offsetRotation, Vector3 offsetPosition) {
+ this.parent = parent;
+ this.child = child;
+ this.offsetRotation = offsetRotation;
+ this.offsetPosition = offsetPosition;
+ this.cacheMatrix = null;
+
+ update();
+ }
+
+ @Override
+ public Vector3 getPosition() {
+ return cacheMatrix.toVector3();
+ }
+
+ @Override
+ public Quaternion getRotation() {
+ return cacheMatrix.getRotation();
+ }
+
+ @Override
+ public Matrix4x4 getCachedMatrix() {
+ return cacheMatrix.clone();
+ }
+
+ @Override
+ public FlatRideComponent getChild() {
+ return child;
+ }
+
+ @Override
+ public FlatRideComponent getParent() {
+ return parent;
+ }
+
+ @Override
+ public void update() {
+ cacheMatrix = MatrixMath.rotateTranslate(
+ parent.getPosition(),
+ parent.getRotation(),
+ this.offsetPosition,
+ this.offsetRotation);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/basic/StaticStructureComponent.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/basic/StaticStructureComponent.java
new file mode 100644
index 00000000..2606ee2f
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/basic/StaticStructureComponent.java
@@ -0,0 +1,13 @@
+package com.jverbruggen.jrides.animator.flatride.basic;
+
+import com.jverbruggen.jrides.animator.flatride.AbstractInterconnectedFlatRideComponent;
+import com.jverbruggen.jrides.animator.flatride.rotor.FlatRideModel;
+import com.jverbruggen.jrides.config.flatride.structure.attachment.joint.RelativeAttachmentJointConfig;
+
+import java.util.List;
+
+public class StaticStructureComponent extends AbstractInterconnectedFlatRideComponent {
+ public StaticStructureComponent(String identifier, String groupIdentifier, boolean root, RelativeAttachmentJointConfig joint, List flatRideModels) {
+ super(identifier, groupIdentifier, root, joint, flatRideModels);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/factory/FlatRideFactory.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/factory/FlatRideFactory.java
new file mode 100644
index 00000000..b6145f85
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/factory/FlatRideFactory.java
@@ -0,0 +1,109 @@
+package com.jverbruggen.jrides.animator.flatride.factory;
+
+import com.jverbruggen.jrides.animator.RideHandle;
+import com.jverbruggen.jrides.animator.flatride.FlatRideComponent;
+import com.jverbruggen.jrides.animator.flatride.FlatRideHandle;
+import com.jverbruggen.jrides.animator.flatride.station.FlatRideStationHandle;
+import com.jverbruggen.jrides.animator.flatride.timing.TimingSequence;
+import com.jverbruggen.jrides.config.flatride.FlatRideConfig;
+import com.jverbruggen.jrides.config.flatride.structure.StructureConfig;
+import com.jverbruggen.jrides.config.flatride.structure.StructureConfigItem;
+import com.jverbruggen.jrides.config.gates.GateOwnerConfigSpec;
+import com.jverbruggen.jrides.config.ride.RideState;
+import com.jverbruggen.jrides.control.DispatchLock;
+import com.jverbruggen.jrides.control.DispatchLockCollection;
+import com.jverbruggen.jrides.control.SimpleDispatchLock;
+import com.jverbruggen.jrides.control.controller.RideController;
+import com.jverbruggen.jrides.control.controller.RideControllerFactory;
+import com.jverbruggen.jrides.control.trigger.*;
+import com.jverbruggen.jrides.control.uiinterface.menu.RideControlMenuFactory;
+import com.jverbruggen.jrides.language.LanguageFile;
+import com.jverbruggen.jrides.language.LanguageFileField;
+import com.jverbruggen.jrides.models.menu.Menu;
+import com.jverbruggen.jrides.models.properties.PlayerLocation;
+import com.jverbruggen.jrides.models.ride.flatride.FlatRide;
+import com.jverbruggen.jrides.models.ride.gate.Gate;
+import com.jverbruggen.jrides.serviceprovider.ServiceProvider;
+import org.bukkit.World;
+import org.bukkit.inventory.ItemStack;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+public class FlatRideFactory {
+ private final RideControllerFactory rideControllerFactory;
+ private final RideControlMenuFactory rideControlMenuFactory;
+ private final LanguageFile languageFile;
+
+ public FlatRideFactory() {
+ rideControllerFactory = ServiceProvider.getSingleton(RideControllerFactory.class);
+ rideControlMenuFactory = ServiceProvider.getSingleton(RideControlMenuFactory.class);
+ languageFile = ServiceProvider.getSingleton(LanguageFile.class);
+ }
+
+ public RideHandle createFromConfig(String rideIdentifier, World world, RideState rideState, FlatRideConfig flatRideConfig){
+ String displayName = flatRideConfig.getDisplayName();
+ List displayDescription = flatRideConfig.getDisplayDescription();
+ ItemStack displayItem = flatRideConfig.getDisplayItem().createItemStack();
+ PlayerLocation warpLocation = flatRideConfig.getWarpLocation();
+ boolean canExitDuringRide = flatRideConfig.canExitDuringRide();
+ String shortStationName = "station";
+
+ DispatchLockCollection dispatchLockCollection = new DispatchLockCollection("Main locks");
+
+ DispatchLock vehicleInStation = new SimpleDispatchLock(dispatchLockCollection,
+ languageFile.get(LanguageFileField.NOTIFICATION_RIDE_NO_TRAIN_PRESENT), false);
+ DispatchLock minimumWaitTimeDispatchLock = new SimpleDispatchLock(dispatchLockCollection,
+ languageFile.get(LanguageFileField.NOTIFICATION_RIDE_WAITING_TIME), true);
+ DispatchLock restraintLock = new SimpleDispatchLock(dispatchLockCollection,
+ languageFile.get(LanguageFileField.NOTIFICATION_RIDE_RESTRAINTS_NOT_CLOSED), true);
+ DispatchLockCollection gatesGenericLock = new DispatchLockCollection(
+ languageFile.get(LanguageFileField.NOTIFICATION_RIDE_GATES_NOT_CLOSED), dispatchLockCollection);
+
+ TriggerContext triggerContext = new TriggerContext(
+ dispatchLockCollection,
+ vehicleInStation,
+ new SimpleDispatchTrigger(dispatchLockCollection),
+ new GateTrigger(gatesGenericLock),
+ new RestraintTrigger(restraintLock));
+
+ Optional optionalGateOwner = flatRideConfig.getGates().getGateOwnerSpec(shortStationName);
+ List gates = optionalGateOwner.isPresent()
+ ? optionalGateOwner.get().createGates(shortStationName, world, gatesGenericLock)
+ : new ArrayList<>();
+
+
+ FlatRideStationHandle stationHandle = flatRideConfig.getStationConfig().createFlatRideStationHandle(
+ rideIdentifier,
+ displayName + "_" + shortStationName, shortStationName, triggerContext, gates, minimumWaitTimeDispatchLock
+ );
+
+ FlatRide flatRide = new FlatRide(rideIdentifier, displayName, displayDescription, displayItem,
+ warpLocation, canExitDuringRide);
+ FlatRideHandle flatRideHandle = new FlatRideHandle(world, flatRide, true, stationHandle, flatRideConfig.getSoundsConfig(), flatRideConfig.getCustomEjectLocation(), flatRideConfig.getRideCounterMapConfigs());
+
+ flatRideConfig.getInteractionEntities().spawnEntities(flatRideHandle);
+
+ List components = new ArrayList<>();
+
+ StructureConfig structureConfig = flatRideConfig.getStructureConfig();
+ for(StructureConfigItem item : structureConfig.getItems()){
+ item.createAndAddTo(components, flatRideHandle);
+ }
+
+ components.stream()
+ .filter(FlatRideComponent::isRoot)
+ .forEach(flatRideHandle::addRootComponent);
+
+ TimingSequence timingSequence = flatRideConfig.getTimingConfig().createTimingSequence(flatRideHandle, components);
+ flatRideHandle.setTimingSequence(timingSequence);
+
+ RideController rideController = rideControllerFactory.createFlatRideController(flatRideHandle);
+ Menu rideControlMenu = rideControlMenuFactory.getRideControlMenu(rideController, null);
+ flatRideHandle.setRideController(rideController, rideControlMenu);
+
+ flatRideHandle.setState(rideState);
+ return flatRideHandle;
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/interfaces/Component6DOFPosition.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/interfaces/Component6DOFPosition.java
new file mode 100644
index 00000000..7712054e
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/interfaces/Component6DOFPosition.java
@@ -0,0 +1,8 @@
+package com.jverbruggen.jrides.animator.flatride.interfaces;
+
+import com.jverbruggen.jrides.models.math.Quaternion;
+import com.jverbruggen.jrides.models.math.Vector3;
+
+public interface Component6DOFPosition {
+ void setPositionRotation(Vector3 position, Quaternion rotation);
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/interfaces/HasPosition.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/interfaces/HasPosition.java
new file mode 100644
index 00000000..a1c4d737
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/interfaces/HasPosition.java
@@ -0,0 +1,17 @@
+package com.jverbruggen.jrides.animator.flatride.interfaces;
+
+import com.jverbruggen.jrides.animator.flatride.FlatRideComponentSpeed;
+
+public interface HasPosition extends HasSpeed {
+ void setInstructionPosition(double position);
+
+ double getInstructionPosition();
+
+ double getLowerOperatingRange();
+ double getUpperOperatingRange();
+
+ void setLowerOperatingRange(double lower);
+ void setUpperOperatingRange(double upper);
+
+ void goTowards(double targetPosition, double fromPosition, double acceleration, FlatRideComponentSpeed componentSpeed);
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/interfaces/HasSpeed.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/interfaces/HasSpeed.java
new file mode 100644
index 00000000..b5af6319
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/interfaces/HasSpeed.java
@@ -0,0 +1,8 @@
+package com.jverbruggen.jrides.animator.flatride.interfaces;
+
+import com.jverbruggen.jrides.animator.flatride.FlatRideComponent;
+import com.jverbruggen.jrides.animator.flatride.FlatRideComponentSpeed;
+
+public interface HasSpeed extends FlatRideComponent {
+ FlatRideComponentSpeed getFlatRideComponentSpeed();
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/interfaces/PlayerControllable.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/interfaces/PlayerControllable.java
new file mode 100644
index 00000000..4d828840
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/interfaces/PlayerControllable.java
@@ -0,0 +1,8 @@
+package com.jverbruggen.jrides.animator.flatride.interfaces;
+
+import com.jverbruggen.jrides.animator.flatride.FlatRideComponent;
+
+public interface PlayerControllable extends FlatRideComponent {
+ boolean allowsControl();
+ void setAllowControl(boolean allow);
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/linearactuator/LinearActuator.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/linearactuator/LinearActuator.java
new file mode 100644
index 00000000..217c97db
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/linearactuator/LinearActuator.java
@@ -0,0 +1,83 @@
+package com.jverbruggen.jrides.animator.flatride.linearactuator;
+
+import com.jverbruggen.jrides.animator.flatride.AbstractInterconnectedFlatRideComponent;
+import com.jverbruggen.jrides.animator.flatride.FlatRideComponentSpeed;
+import com.jverbruggen.jrides.animator.flatride.attachment.Attachment;
+import com.jverbruggen.jrides.animator.flatride.interfaces.HasPosition;
+import com.jverbruggen.jrides.animator.flatride.linearactuator.mode.LinearActuatorMode;
+import com.jverbruggen.jrides.animator.flatride.rotor.FlatRideModel;
+import com.jverbruggen.jrides.config.flatride.structure.attachment.joint.RelativeAttachmentJointConfig;
+import com.jverbruggen.jrides.models.math.Vector3;
+
+import java.util.List;
+
+public class LinearActuator extends AbstractInterconnectedFlatRideComponent implements HasPosition {
+ private final FlatRideComponentSpeed flatRideComponentSpeed;
+ private final Vector3 actuatorState;
+ private final LinearActuatorMode actuatorMode;
+
+ public LinearActuator(String identifier, String groupIdentifier, boolean root, RelativeAttachmentJointConfig joint, List flatRideModels, FlatRideComponentSpeed flatRideComponentSpeed, LinearActuatorMode actuatorMode) {
+ super(identifier, groupIdentifier, root, joint, flatRideModels);
+ this.flatRideComponentSpeed = flatRideComponentSpeed;
+
+ this.actuatorState = new Vector3(0,0,0);
+ this.actuatorMode = actuatorMode;
+ }
+
+ @Override
+ public Vector3 getPosition() {
+ return Vector3.add(super.getPosition(), actuatorState);
+ }
+
+ @Override
+ public void tick() {
+ actuatorMode.tick(flatRideComponentSpeed, actuatorState);
+
+ for(Attachment attachment : getChildren()){
+ attachment.update();
+ attachment.getChild().tick();
+ }
+
+ updateFlatRideModels();
+ }
+
+ @Override
+ public FlatRideComponentSpeed getFlatRideComponentSpeed() {
+ return flatRideComponentSpeed;
+ }
+
+ @Override
+ public void setInstructionPosition(double position) {
+ actuatorMode.setPosition(actuatorState, position);
+ }
+
+ @Override
+ public double getInstructionPosition() {
+ return actuatorMode.getPosition(actuatorState);
+ }
+
+ @Override
+ public double getLowerOperatingRange() {
+ return actuatorMode.getLowerBound();
+ }
+
+ @Override
+ public double getUpperOperatingRange() {
+ return actuatorMode.getUpperBound();
+ }
+
+ @Override
+ public void setLowerOperatingRange(double lower) {
+ throw new RuntimeException("Cannot set operating range for linear actuator");
+ }
+
+ @Override
+ public void setUpperOperatingRange(double upper) {
+ throw new RuntimeException("Cannot set operating range for linear actuator");
+ }
+
+ @Override
+ public void goTowards(double targetPosition, double fromPosition, double acceleration, FlatRideComponentSpeed componentSpeed) {
+ componentSpeed.accelerate(acceleration);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/linearactuator/mode/ContinuousMode.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/linearactuator/mode/ContinuousMode.java
new file mode 100644
index 00000000..ae45841c
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/linearactuator/mode/ContinuousMode.java
@@ -0,0 +1,48 @@
+package com.jverbruggen.jrides.animator.flatride.linearactuator.mode;
+
+import com.jverbruggen.jrides.animator.flatride.FlatRideComponentSpeed;
+import com.jverbruggen.jrides.models.math.Vector3;
+
+public class ContinuousMode implements LinearActuatorMode {
+ private final Double lowerBound;
+ private final Double upperBound;
+
+ public ContinuousMode(Double lowerBound, Double upperBound) {
+ this.lowerBound = lowerBound;
+ this.upperBound = upperBound;
+ }
+
+ public void tick(FlatRideComponentSpeed flatRideComponentSpeed, Vector3 actuatorState){
+ double currentSpeed = flatRideComponentSpeed.getSpeed();
+ actuatorState.y += currentSpeed;
+
+ // TODO: implement braking
+ if(upperBound != null && currentSpeed >= 0 && actuatorState.y > upperBound){
+ actuatorState.y = upperBound;
+ flatRideComponentSpeed.setHard(0);
+ }else if(lowerBound != null && currentSpeed < 0 && actuatorState.y < lowerBound){
+ actuatorState.y = lowerBound;
+ flatRideComponentSpeed.setHard(0);
+ }
+ }
+
+ @Override
+ public double getPosition(Vector3 actuatorState) {
+ return actuatorState.y;
+ }
+
+ @Override
+ public void setPosition(Vector3 actuatorState, double position) {
+ actuatorState.y = position;
+ }
+
+ @Override
+ public double getLowerBound() {
+ return lowerBound;
+ }
+
+ @Override
+ public double getUpperBound() {
+ return upperBound;
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/linearactuator/mode/LinearActuatorMode.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/linearactuator/mode/LinearActuatorMode.java
new file mode 100644
index 00000000..380b33f3
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/linearactuator/mode/LinearActuatorMode.java
@@ -0,0 +1,11 @@
+package com.jverbruggen.jrides.animator.flatride.linearactuator.mode;
+
+import com.jverbruggen.jrides.animator.flatride.ActuatorMode;
+import com.jverbruggen.jrides.animator.flatride.FlatRideComponentSpeed;
+import com.jverbruggen.jrides.models.math.Vector3;
+
+public interface LinearActuatorMode extends ActuatorMode {
+ void tick(FlatRideComponentSpeed flatRideComponentSpeed, Vector3 actuatorState);
+ double getPosition(Vector3 actuatorState);
+ void setPosition(Vector3 actuatorState, double position);
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/linearactuator/mode/LinearActuatorModeEnum.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/linearactuator/mode/LinearActuatorModeEnum.java
new file mode 100644
index 00000000..f4a49d42
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/linearactuator/mode/LinearActuatorModeEnum.java
@@ -0,0 +1,14 @@
+package com.jverbruggen.jrides.animator.flatride.linearactuator.mode;
+
+public enum LinearActuatorModeEnum {
+ CONTINUOUS,
+ SINE;
+
+ public static LinearActuatorModeEnum from(String s) {
+ return switch (s) {
+ case "continuous" -> CONTINUOUS;
+ case "sine" -> SINE;
+ default -> throw new IllegalStateException("Unexpected value: " + s);
+ };
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/linearactuator/mode/SineMode.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/linearactuator/mode/SineMode.java
new file mode 100644
index 00000000..51752ce9
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/linearactuator/mode/SineMode.java
@@ -0,0 +1,57 @@
+package com.jverbruggen.jrides.animator.flatride.linearactuator.mode;
+
+import com.jverbruggen.jrides.animator.flatride.FlatRideComponentSpeed;
+import com.jverbruggen.jrides.models.math.Vector3;
+
+public class SineMode implements LinearActuatorMode {
+ private static final float PI = 3.1415926535f;
+ private static final float PI2 = PI*2;
+
+ private final float size;
+ private final short phase;
+ private double sineState;
+
+ public SineMode(float size, short phase) {
+ this.size = size;
+ this.phase = phase;
+
+ resetToInitialPhase();
+ }
+
+ public void tick(FlatRideComponentSpeed flatRideComponentSpeed, Vector3 actuatorState){
+ increaseSineState(flatRideComponentSpeed, actuatorState);
+ }
+
+ @Override
+ public double getPosition(Vector3 actuatorState) {
+ return sineState;
+ }
+
+ @Override
+ public void setPosition(Vector3 actuatorState, double position) {
+ this.updateActuatorState(actuatorState, position);
+ }
+
+ @Override
+ public double getLowerBound() {
+ return 0;
+ }
+
+ @Override
+ public double getUpperBound() {
+ return PI2;
+ }
+
+ private void resetToInitialPhase(){
+ this.sineState = phase/180f*PI;
+ }
+
+ private void increaseSineState(FlatRideComponentSpeed flatRideComponentSpeed, Vector3 actuatorState){
+ sineState = (sineState + flatRideComponentSpeed.getSpeed()/180*PI) % PI2;
+ updateActuatorState(actuatorState, this.sineState);
+ }
+
+ private void updateActuatorState(Vector3 actuatorState, double sineState){
+ actuatorState.y = Math.sin(sineState)*size;
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/FlatRideModel.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/FlatRideModel.java
new file mode 100644
index 00000000..a195752a
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/FlatRideModel.java
@@ -0,0 +1,29 @@
+package com.jverbruggen.jrides.animator.flatride.rotor;
+
+import com.jverbruggen.jrides.models.entity.VirtualEntity;
+import com.jverbruggen.jrides.models.math.Matrix4x4;
+import com.jverbruggen.jrides.models.math.MatrixMath;
+import com.jverbruggen.jrides.models.math.Quaternion;
+import com.jverbruggen.jrides.models.math.Vector3;
+
+public class FlatRideModel {
+ private final VirtualEntity entity;
+ private final Vector3 offset;
+ private final Quaternion rotationOffset;
+
+ public FlatRideModel(VirtualEntity entity, Vector3 offset, Quaternion rotationOffset) {
+ this.entity = entity;
+ this.offset = offset;
+ this.rotationOffset = rotationOffset;
+ }
+
+ public void updateLocation(Vector3 parentLocation, Quaternion parentRotation){
+ Matrix4x4 matrix = MatrixMath.rotateTranslate(parentLocation, parentRotation, offset, rotationOffset);
+ entity.setLocation(matrix.toVector3());
+ entity.setRotation(matrix.getRotation());
+ }
+
+ public VirtualEntity getEntity() {
+ return entity;
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/Rotor.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/Rotor.java
new file mode 100644
index 00000000..571a86f1
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/Rotor.java
@@ -0,0 +1,188 @@
+package com.jverbruggen.jrides.animator.flatride.rotor;
+
+import com.jverbruggen.jrides.animator.flatride.AbstractInterconnectedFlatRideComponent;
+import com.jverbruggen.jrides.animator.flatride.FlatRideComponentSpeed;
+import com.jverbruggen.jrides.animator.flatride.attachment.Attachment;
+import com.jverbruggen.jrides.animator.flatride.interfaces.HasPosition;
+import com.jverbruggen.jrides.animator.flatride.interfaces.PlayerControllable;
+import com.jverbruggen.jrides.animator.flatride.rotor.axis.RotorAxis;
+import com.jverbruggen.jrides.animator.flatride.rotor.mode.RotorActuatorMode;
+import com.jverbruggen.jrides.config.flatride.structure.actuator.RotorPlayerControlConfig;
+import com.jverbruggen.jrides.config.flatride.structure.attachment.joint.RelativeAttachmentJointConfig;
+import com.jverbruggen.jrides.models.math.Quaternion;
+import com.jverbruggen.jrides.models.math.SpeedUtil;
+import com.jverbruggen.jrides.models.ride.flatride.PlayerControl;
+
+import javax.annotation.Nullable;
+import java.util.List;
+
+public class Rotor extends AbstractInterconnectedFlatRideComponent implements PlayerControllable, HasPosition {
+ private final FlatRideComponentSpeed flatRideComponentSpeed;
+ private final RotorAxis rotorAxis;
+ private RotorPlayerControl playerControl;
+ private boolean allowsControlState;
+ private double lowerOperatingRange;
+ private double upperOperatingRange;
+ private final RotorActuatorMode actuatorMode;
+
+ public Rotor(String identifier, String groupIdentifier, boolean root, RelativeAttachmentJointConfig joint, List flatRideModels, FlatRideComponentSpeed flatRideComponentSpeed, RotorAxis rotorAxis, RotorActuatorMode actuatorMode) {
+ super(identifier, groupIdentifier, root, joint, flatRideModels);
+ this.rotorAxis = rotorAxis;
+ this.actuatorMode = actuatorMode;
+ this.playerControl = null;
+ this.flatRideComponentSpeed = flatRideComponentSpeed;
+ this.allowsControlState = false;
+ this.lowerOperatingRange = 0;
+ this.upperOperatingRange = 360;
+ }
+
+ @Override
+ public Quaternion getRotation() {
+ Attachment attachedTo = getAttachedTo();
+ if(attachedTo == null) throw new RuntimeException("Rotor " + getIdentifier() + " not attached to anything");
+
+ return Quaternion.multiply(attachedTo.getRotation(), rotorAxis.getQuaternion());
+ }
+
+ public FlatRideComponentSpeed getFlatRideComponentSpeed() {
+ return flatRideComponentSpeed;
+ }
+
+ @Override
+ public void tick() {
+ if(allowsControl()){
+ playerControl.apply();
+ }
+
+ actuatorMode.tick(flatRideComponentSpeed, rotorAxis);
+
+ for(Attachment attachment : getChildren()){
+ attachment.update();
+ attachment.getChild().tick();
+ }
+
+ updateFlatRideModels();
+ }
+
+ @Override
+ public boolean allowsControl() {
+ return this.allowsControlState;
+ }
+
+ @Override
+ public void setAllowControl(boolean allow) {
+ if(this.allowsControlState == allow) return;
+
+ if(allow){
+ playerControl.reset();
+ playerControl.sendStartNotification();
+ }
+ this.allowsControlState = allow;
+ }
+
+ @Nullable
+ @Override
+ public PlayerControl getPlayerControl() {
+ if(playerControl != null)
+ return playerControl;
+
+ return super.getPlayerControl();
+ }
+
+ public void createPlayerControl(RotorPlayerControlConfig controlConfig){
+ if(controlConfig == null) return;
+
+ playerControl = controlConfig.createPlayerControl();
+ playerControl.setRotor(this);
+ }
+
+ public double getRotorRotation(){
+ return rotorAxis.getRotation();
+ }
+
+ public void setRotorRotation(double toValue){
+ rotorAxis.setRotation(toValue);
+ }
+
+ @Override
+ public void setInstructionPosition(double position) {
+ setRotorRotation(position);
+ }
+
+ @Override
+ public double getInstructionPosition() {
+ return getRotorRotation();
+ }
+
+ @Override
+ public double getLowerOperatingRange() {
+ return lowerOperatingRange;
+ }
+
+ @Override
+ public double getUpperOperatingRange() {
+ return upperOperatingRange;
+ }
+
+ @Override
+ public void setLowerOperatingRange(double lower) {
+ lowerOperatingRange = lower;
+ }
+
+ @Override
+ public void setUpperOperatingRange(double upper) {
+ upperOperatingRange = upper;
+ }
+
+ @Override
+ public void goTowards(double targetPosition, double fromPosition, double acceleration, FlatRideComponentSpeed componentSpeed) {
+ double currentSpeed = componentSpeed.getSpeed();
+ double currentPosition = this.getInstructionPosition();
+ double absAcceleration = Math.abs(acceleration);
+ double maxSpeed = componentSpeed.getMaxSpeed();
+ double minSpeed = componentSpeed.getMinSpeed();
+
+ boolean positiveAcceleration = acceleration >= 0;
+ boolean goingForwards = currentSpeed > 0 || (currentSpeed == 0 && positiveAcceleration);
+
+ double breakPosition = SpeedUtil.positionStartBraking(
+ currentSpeed,
+ goingForwards ? -absAcceleration : absAcceleration,
+ targetPosition,
+ 0);
+
+// JRidesPlugin.getLogger().debug("s: " + currentSpeed + "(" + goingForwards + ") a: " + acceleration);
+// JRidesPlugin.getLogger().debug("f: " + fromPositionAcc + " c: " + hasPosition.getInstructionPosition() + " t: " + targetPositionAcc + " b: " + breakPosition);
+
+ double margin = 0.1;
+
+ boolean shouldBreak = SpeedUtil.hasPassed(fromPosition, this.getInstructionPosition(), breakPosition,
+ positiveAcceleration, margin);
+ boolean shouldHardBreak = SpeedUtil.hasPassed(fromPosition, this.getInstructionPosition(), targetPosition,
+ goingForwards, absAcceleration);
+
+// JRidesPlugin.getLogger().debug("break: " + shouldBreak + " hard: " + shouldHardBreak + "\n----");
+
+ if(shouldHardBreak){
+ componentSpeed.setHard(0);
+ if(Math.abs(targetPosition - this.getInstructionPosition()) < margin)
+ this.setInstructionPosition(targetPosition);
+ }else if(shouldBreak){
+ componentSpeed.accelerateTowards(absAcceleration, 0);
+ this.checkBump(currentPosition, componentSpeed, fromPosition, targetPosition, positiveAcceleration);
+ }else{
+ double targetSpeed = positiveAcceleration ? maxSpeed : minSpeed;
+
+ componentSpeed.accelerateTowards(absAcceleration, targetSpeed);
+ this.checkBump(currentPosition, componentSpeed, fromPosition, targetPosition, positiveAcceleration);
+ }
+ }
+
+ private void checkBump(double currentPosition, FlatRideComponentSpeed componentSpeed, double fromPosition, double targetPosition, boolean positiveSpeed){
+ double newPosition = currentPosition + componentSpeed.getSpeed();
+ if(SpeedUtil.hasPassed(fromPosition, newPosition, targetPosition, positiveSpeed, 0d)){
+ componentSpeed.setHard(0);
+ this.setInstructionPosition(targetPosition);
+ }
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/RotorPlayerControl.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/RotorPlayerControl.java
new file mode 100644
index 00000000..33e6833f
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/RotorPlayerControl.java
@@ -0,0 +1,7 @@
+package com.jverbruggen.jrides.animator.flatride.rotor;
+
+import com.jverbruggen.jrides.models.ride.flatride.PlayerControl;
+
+public interface RotorPlayerControl extends PlayerControl {
+ void setRotor(Rotor rotor);
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/RotorSpeedPlayerControl.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/RotorSpeedPlayerControl.java
new file mode 100644
index 00000000..8655e784
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/RotorSpeedPlayerControl.java
@@ -0,0 +1,64 @@
+package com.jverbruggen.jrides.animator.flatride.rotor;
+
+import com.jverbruggen.jrides.animator.flatride.AbstractPlayerControl;
+import com.jverbruggen.jrides.animator.flatride.rotor.controltype.ControlType;
+import com.jverbruggen.jrides.models.ride.seat.InstructionType;
+
+public class RotorSpeedPlayerControl extends AbstractPlayerControl implements RotorPlayerControl {
+ private Rotor rotor;
+ private final double lowerSpeed;
+ private final double upperSpeed;
+ private final double accelerate;
+
+ private double currentSpeed;
+ private double pendingAcceleration;
+
+ public RotorSpeedPlayerControl(double lowerSpeed, double upperSpeed, double accelerate, ControlType controlType) {
+ super(controlType);
+ this.rotor = null;
+ this.lowerSpeed = lowerSpeed;
+ this.upperSpeed = upperSpeed;
+ this.accelerate = accelerate;
+ this.currentSpeed = 0f;
+ this.pendingAcceleration = 0f;
+ }
+
+ public void setRotor(Rotor rotor) {
+ this.rotor = rotor;
+ this.currentSpeed = this.rotor.getFlatRideComponentSpeed().getSpeed();
+ }
+
+ @Override
+ public void processInstructionAsync(InstructionType instruction) {
+ if(!rotor.allowsControl()) return;
+
+ pendingAcceleration = getControlType().processInstruction(instruction, accelerate);
+ }
+
+ @Override
+ public void apply() {
+ double acceleration = this.pendingAcceleration; // Synchronization?
+
+ currentSpeed = rotor.getFlatRideComponentSpeed().getSpeed();
+ double oldSpeed = currentSpeed;
+ currentSpeed += acceleration;
+ if(currentSpeed > upperSpeed){
+ currentSpeed = upperSpeed;
+ acceleration = upperSpeed - oldSpeed;
+ }
+ else if(currentSpeed < lowerSpeed){
+ currentSpeed = lowerSpeed;
+ acceleration = lowerSpeed - oldSpeed;
+ }
+
+ rotor.getFlatRideComponentSpeed().accelerate(acceleration);
+ this.pendingAcceleration = 0;
+ }
+
+ @Override
+ public void reset() {
+ this.pendingAcceleration = 0;
+ this.currentSpeed = rotor.getFlatRideComponentSpeed().getSpeed();
+ }
+
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/RotorTargetPositionPlayerControl.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/RotorTargetPositionPlayerControl.java
new file mode 100644
index 00000000..e846a5bd
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/RotorTargetPositionPlayerControl.java
@@ -0,0 +1,57 @@
+package com.jverbruggen.jrides.animator.flatride.rotor;
+
+import com.jverbruggen.jrides.animator.flatride.AbstractPlayerControl;
+import com.jverbruggen.jrides.animator.flatride.rotor.controltype.ControlType;
+import com.jverbruggen.jrides.animator.flatride.timing.instruction.towards.TowardsPositionInstruction;
+import com.jverbruggen.jrides.models.ride.seat.InstructionType;
+
+public class RotorTargetPositionPlayerControl extends AbstractPlayerControl implements RotorPlayerControl {
+ private Rotor rotor;
+ private final double lowerPosition;
+ private final double upperPosition;
+ private final double acceleration;
+ private final double margin;
+
+ private double pendingAcceleration;
+
+ public RotorTargetPositionPlayerControl(double lowerPosition, double upperPosition, double acceleration, ControlType controlType) {
+ super(controlType);
+ this.rotor = null;
+ this.lowerPosition = lowerPosition;
+ this.upperPosition = upperPosition;
+ this.acceleration = acceleration;
+ this.margin = 2*this.acceleration;
+ this.pendingAcceleration = 0f;
+ }
+
+ public void setRotor(Rotor rotor) {
+ this.rotor = rotor;
+ rotor.setLowerOperatingRange(lowerPosition);
+ rotor.setUpperOperatingRange(upperPosition);
+ }
+
+ @Override
+ public void processInstructionAsync(InstructionType instruction) {
+ if(!rotor.allowsControl()) return;
+
+ pendingAcceleration = getControlType().processInstruction(instruction, acceleration);
+ }
+
+ @Override
+ public void apply() {
+ TowardsPositionInstruction.run(
+ rotor,
+ this.pendingAcceleration,
+ this.lowerPosition,
+ this.upperPosition,
+ this.margin,
+ rotor.getFlatRideComponentSpeed().getMaxSpeed(),
+ rotor.getFlatRideComponentSpeed().getMinSpeed());
+ }
+
+ @Override
+ public void reset() {
+ this.pendingAcceleration = 0;
+ }
+
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/axis/RotorAxis.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/axis/RotorAxis.java
new file mode 100644
index 00000000..c526108d
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/axis/RotorAxis.java
@@ -0,0 +1,10 @@
+package com.jverbruggen.jrides.animator.flatride.rotor.axis;
+
+import com.jverbruggen.jrides.models.math.Quaternion;
+
+public interface RotorAxis {
+ void setRotation(double toValue);
+ void addRotation(double addValue);
+ double getRotation();
+ Quaternion getQuaternion();
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/axis/RotorAxisFactory.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/axis/RotorAxisFactory.java
new file mode 100644
index 00000000..5cc2652b
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/axis/RotorAxisFactory.java
@@ -0,0 +1,25 @@
+package com.jverbruggen.jrides.animator.flatride.rotor.axis;
+
+public class RotorAxisFactory {
+ public static RotorAxis createAxisX(){
+ return new RotorAxisX();
+ }
+
+ public static RotorAxis createAxisY(){
+ return new RotorAxisY();
+ }
+
+ public static RotorAxis createAxisZ(){
+ return new RotorAxisZ();
+ }
+
+ public static RotorAxis createAxisFromString(String rotorAxis){
+ if(rotorAxis.equalsIgnoreCase("x"))
+ return createAxisX();
+ else if(rotorAxis.equalsIgnoreCase("y"))
+ return createAxisY();
+ else if(rotorAxis.equalsIgnoreCase("z"))
+ return createAxisZ();
+ else throw new RuntimeException("Unknown axis " + rotorAxis);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/axis/RotorAxisX.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/axis/RotorAxisX.java
new file mode 100644
index 00000000..002d39e2
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/axis/RotorAxisX.java
@@ -0,0 +1,15 @@
+package com.jverbruggen.jrides.animator.flatride.rotor.axis;
+
+import com.jverbruggen.jrides.models.math.Quaternion;
+
+public class RotorAxisX extends RotorAxisY {
+ @Override
+ public void addRotation(double addValue) {
+ add(addValue);
+ }
+
+ @Override
+ public Quaternion getQuaternion() {
+ return Quaternion.fromYawPitchRoll(getRotation(), 0, 0);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/axis/RotorAxisY.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/axis/RotorAxisY.java
new file mode 100644
index 00000000..f4b9775a
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/axis/RotorAxisY.java
@@ -0,0 +1,39 @@
+package com.jverbruggen.jrides.animator.flatride.rotor.axis;
+
+import com.jverbruggen.jrides.models.math.MathUtil;
+import com.jverbruggen.jrides.models.math.Quaternion;
+
+public class RotorAxisY implements RotorAxis {
+ private double value;
+
+ public RotorAxisY() {
+ this.value = 0;
+ }
+
+ protected void add(double value){
+ this.value = MathUtil.floorMod(this.value + value, 360d);
+ }
+
+ @Override
+ public void setRotation(double toValue){
+ double fromRotation = getRotation();
+ if(fromRotation == toValue) return;
+
+ addRotation(toValue - fromRotation);
+ }
+
+ @Override
+ public void addRotation(double addValue) {
+ add(addValue);
+ }
+
+ @Override
+ public double getRotation() {
+ return this.value;
+ }
+
+ @Override
+ public Quaternion getQuaternion() {
+ return Quaternion.fromYawPitchRoll(0, this.value, 0);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/axis/RotorAxisZ.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/axis/RotorAxisZ.java
new file mode 100644
index 00000000..2f95591c
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/axis/RotorAxisZ.java
@@ -0,0 +1,15 @@
+package com.jverbruggen.jrides.animator.flatride.rotor.axis;
+
+import com.jverbruggen.jrides.models.math.Quaternion;
+
+public class RotorAxisZ extends RotorAxisY {
+ @Override
+ public void addRotation(double addValue) {
+ add(addValue);
+ }
+
+ @Override
+ public Quaternion getQuaternion() {
+ return Quaternion.fromYawPitchRoll(0, 0, getRotation());
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/controltype/ADControl.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/controltype/ADControl.java
new file mode 100644
index 00000000..a0f7f618
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/controltype/ADControl.java
@@ -0,0 +1,26 @@
+package com.jverbruggen.jrides.animator.flatride.rotor.controltype;
+
+import com.jverbruggen.jrides.models.ride.seat.InstructionType;
+import org.bukkit.ChatColor;
+
+public class ADControl implements ControlType {
+ @Override
+ public double processInstruction(InstructionType instruction, double data) {
+ if(instruction == InstructionType.A){
+ return -data;
+ }else if(instruction == InstructionType.D){
+ return data;
+ }
+ else return 0;
+ }
+
+ @Override
+ public String getControlMessageTitle() {
+ return ChatColor.RED + "Take Control!";
+ }
+
+ @Override
+ public String getControlMessageSubtitle() {
+ return ChatColor.GOLD + "Press A or D";
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/controltype/ControlType.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/controltype/ControlType.java
new file mode 100644
index 00000000..a016bfa5
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/controltype/ControlType.java
@@ -0,0 +1,9 @@
+package com.jverbruggen.jrides.animator.flatride.rotor.controltype;
+
+import com.jverbruggen.jrides.models.ride.seat.InstructionType;
+
+public interface ControlType {
+ double processInstruction(InstructionType instruction, double data);
+ String getControlMessageTitle();
+ String getControlMessageSubtitle();
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/controltype/SpaceBarControl.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/controltype/SpaceBarControl.java
new file mode 100644
index 00000000..8528ea7b
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/controltype/SpaceBarControl.java
@@ -0,0 +1,24 @@
+package com.jverbruggen.jrides.animator.flatride.rotor.controltype;
+
+import com.jverbruggen.jrides.models.ride.seat.InstructionType;
+import org.bukkit.ChatColor;
+
+public class SpaceBarControl implements ControlType {
+ @Override
+ public double processInstruction(InstructionType instruction, double data) {
+ if(instruction == InstructionType.SPACE){
+ return data;
+ }
+ else return -data;
+ }
+
+ @Override
+ public String getControlMessageTitle() {
+ return ChatColor.RED + "Take Control!";
+ }
+
+ @Override
+ public String getControlMessageSubtitle() {
+ return ChatColor.GOLD + "Press Space";
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/controltype/WSControl.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/controltype/WSControl.java
new file mode 100644
index 00000000..1aca9dad
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/controltype/WSControl.java
@@ -0,0 +1,26 @@
+package com.jverbruggen.jrides.animator.flatride.rotor.controltype;
+
+import com.jverbruggen.jrides.models.ride.seat.InstructionType;
+import org.bukkit.ChatColor;
+
+public class WSControl implements ControlType {
+ @Override
+ public double processInstruction(InstructionType instruction, double data) {
+ if(instruction == InstructionType.W){
+ return data;
+ }else if(instruction == InstructionType.S){
+ return -data;
+ }
+ else return 0;
+ }
+
+ @Override
+ public String getControlMessageTitle() {
+ return ChatColor.RED + "Take Control!";
+ }
+
+ @Override
+ public String getControlMessageSubtitle() {
+ return ChatColor.GOLD + "Press W or S";
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/mode/ContinuousMode.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/mode/ContinuousMode.java
new file mode 100644
index 00000000..3fee4e36
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/mode/ContinuousMode.java
@@ -0,0 +1,39 @@
+package com.jverbruggen.jrides.animator.flatride.rotor.mode;
+
+import com.jverbruggen.jrides.animator.flatride.FlatRideComponentSpeed;
+import com.jverbruggen.jrides.animator.flatride.rotor.axis.RotorAxis;
+
+public class ContinuousMode implements RotorActuatorMode {
+ private final Double lowerBound;
+ private final Double upperBound;
+
+ public ContinuousMode(Double lowerBound, Double upperBound) {
+ this.lowerBound = lowerBound;
+ this.upperBound = upperBound;
+ }
+
+ public void tick(FlatRideComponentSpeed flatRideComponentSpeed, RotorAxis rotorAxis){
+ rotorAxis.addRotation(flatRideComponentSpeed.getSpeed());
+ }
+
+ @Override
+ public double getRotation(RotorAxis rotorAxis) {
+ return rotorAxis.getRotation();
+ }
+
+ @Override
+ public void setRotation(RotorAxis rotorAxis, double position) {
+ rotorAxis.setRotation(position);
+ }
+
+ @Override
+ public double getLowerBound() {
+ return lowerBound;
+ }
+
+ @Override
+ public double getUpperBound() {
+ return upperBound;
+ }
+
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/mode/RotorActuatorMode.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/mode/RotorActuatorMode.java
new file mode 100644
index 00000000..787b3ac2
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/mode/RotorActuatorMode.java
@@ -0,0 +1,11 @@
+package com.jverbruggen.jrides.animator.flatride.rotor.mode;
+
+import com.jverbruggen.jrides.animator.flatride.ActuatorMode;
+import com.jverbruggen.jrides.animator.flatride.FlatRideComponentSpeed;
+import com.jverbruggen.jrides.animator.flatride.rotor.axis.RotorAxis;
+
+public interface RotorActuatorMode extends ActuatorMode {
+ void tick(FlatRideComponentSpeed flatRideComponentSpeed, RotorAxis rotorAxis);
+ double getRotation(RotorAxis rotorAxis);
+ void setRotation(RotorAxis rotorAxis, double position);
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/mode/RotorModeEnum.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/mode/RotorModeEnum.java
new file mode 100644
index 00000000..b3a8debd
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/mode/RotorModeEnum.java
@@ -0,0 +1,14 @@
+package com.jverbruggen.jrides.animator.flatride.rotor.mode;
+
+public enum RotorModeEnum {
+ CONTINUOUS,
+ SINE;
+
+ public static RotorModeEnum from(String s) {
+ return switch (s) {
+ case "continuous" -> CONTINUOUS;
+ case "sine" -> SINE;
+ default -> throw new IllegalStateException("Unexpected value: " + s);
+ };
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/mode/SineMode.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/mode/SineMode.java
new file mode 100644
index 00000000..a6cfb7e1
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/rotor/mode/SineMode.java
@@ -0,0 +1,59 @@
+package com.jverbruggen.jrides.animator.flatride.rotor.mode;
+
+import com.jverbruggen.jrides.animator.flatride.FlatRideComponentSpeed;
+import com.jverbruggen.jrides.animator.flatride.rotor.axis.RotorAxis;
+import org.bukkit.Bukkit;
+
+public class SineMode implements RotorActuatorMode {
+ private static final float PI = 3.1415926535f;
+ private static final float PI2 = PI*2;
+
+ private final float size;
+ private final short phase;
+ private double sineState;
+
+ public SineMode(float size, short phase) {
+ this.size = size;
+ this.phase = phase;
+
+ resetToInitialPhase();
+ }
+
+ @Override
+ public void tick(FlatRideComponentSpeed flatRideComponentSpeed, RotorAxis rotorAxis) {
+ increaseSineState(flatRideComponentSpeed, rotorAxis);
+ }
+
+ @Override
+ public double getLowerBound() {
+ return 0;
+ }
+
+ @Override
+ public double getUpperBound() {
+ return PI2;
+ }
+
+ private void resetToInitialPhase(){
+ this.sineState = phase/180f*PI;
+ }
+
+ private void increaseSineState(FlatRideComponentSpeed flatRideComponentSpeed, RotorAxis rotorAxis){
+ sineState = (sineState + flatRideComponentSpeed.getSpeed()/180*PI) % PI2;
+ updateRotorAxis(rotorAxis, this.sineState);
+ }
+
+ private void updateRotorAxis(RotorAxis rotorAxis, double sineState){
+ rotorAxis.setRotation(Math.sin(sineState)*size);
+ }
+
+ @Override
+ public double getRotation(RotorAxis rotorAxis) {
+ return sineState;
+ }
+
+ @Override
+ public void setRotation(RotorAxis rotorAxis, double position) {
+ this.updateRotorAxis(rotorAxis, position);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/seat/FlatRideSeat.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/seat/FlatRideSeat.java
new file mode 100644
index 00000000..2a2510ba
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/seat/FlatRideSeat.java
@@ -0,0 +1,55 @@
+package com.jverbruggen.jrides.animator.flatride.seat;
+
+import com.jverbruggen.jrides.animator.flatride.FlatRideHandle;
+import com.jverbruggen.jrides.models.entity.Player;
+import com.jverbruggen.jrides.models.entity.VirtualEntity;
+import com.jverbruggen.jrides.models.math.Vector3;
+import com.jverbruggen.jrides.models.math.Vector3PlusYaw;
+import com.jverbruggen.jrides.models.ride.flatride.PlayerControl;
+import com.jverbruggen.jrides.models.ride.seat.AbstractSeat;
+import com.jverbruggen.jrides.models.ride.seat.InstructionType;
+import com.jverbruggen.jrides.models.ride.seat.SeatHost;
+
+public class FlatRideSeat extends AbstractSeat {
+ private PlayerControl playerControl;
+
+ public FlatRideSeat(FlatRideHandle parentRideHandle, SeatHost seatHost, VirtualEntity virtualEntity, Vector3PlusYaw offset) {
+ super(parentRideHandle, seatHost, virtualEntity, offset);
+ this.playerControl = null;
+
+ virtualEntity.setHostSeat(this);
+ setRestraint(parentRideHandle.getFirstTriggerContext().getRestraintTrigger().getLock().isUnlocked());
+ }
+
+ public void setPlayerControl(PlayerControl playerControl) {
+ this.playerControl = playerControl;
+ }
+
+ @Override
+ public boolean supportsPlayerControl() {
+ return playerControl != null;
+ }
+
+ @Override
+ public void sendPlayerControlInstruction(InstructionType instruction) {
+ if(playerControl == null) return;
+
+ this.playerControl.processInstructionAsync(instruction);
+ }
+
+ @Override
+ protected void onPassengerEnter(Player passenger) {
+ super.onPassengerEnter(passenger);
+
+ if(playerControl != null)
+ playerControl.addControlling(passenger);
+ }
+
+ @Override
+ protected void onPassengerExit(Player passenger) {
+ super.onPassengerExit(passenger);
+
+ if(playerControl != null)
+ playerControl.removeControlling(passenger);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/seat/SeatComponent.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/seat/SeatComponent.java
new file mode 100644
index 00000000..1b89ff35
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/seat/SeatComponent.java
@@ -0,0 +1,90 @@
+package com.jverbruggen.jrides.animator.flatride.seat;
+
+import com.jverbruggen.jrides.animator.RideHandle;
+import com.jverbruggen.jrides.animator.flatride.AbstractFlatRideComponent;
+import com.jverbruggen.jrides.animator.flatride.rotor.FlatRideModel;
+import com.jverbruggen.jrides.models.entity.Player;
+import com.jverbruggen.jrides.models.math.Quaternion;
+import com.jverbruggen.jrides.models.properties.PlayerLocation;
+import com.jverbruggen.jrides.models.ride.coaster.train.Vehicle;
+import com.jverbruggen.jrides.models.ride.factory.SeatFactory;
+import com.jverbruggen.jrides.models.ride.seat.Seat;
+import com.jverbruggen.jrides.models.ride.seat.SeatHost;
+
+import java.util.List;
+
+public class SeatComponent extends AbstractFlatRideComponent implements SeatHost {
+ private final Seat seat;
+ private final Quaternion rotationOffset;
+ private final Vehicle parentVehicle;
+
+ public SeatComponent(String identifier, String groupIdentifier, boolean root, List flatRideModels, Seat seat, Quaternion rotationOffset, Vehicle parentVehicle) {
+ super(identifier, groupIdentifier, root, flatRideModels);
+ this.seat = seat;
+ this.rotationOffset = rotationOffset;
+ this.parentVehicle = parentVehicle;
+ }
+
+ @Override
+ public void tick() {
+ super.tick();
+
+ SeatFactory.moveFlatRideSeat(this.seat, getPositionMatrix(), getRotation());
+ }
+
+ @Override
+ public Quaternion getRotation() {
+ return Quaternion.multiply(super.getRotation(), rotationOffset);
+ }
+
+ @Override
+ public List getSeats() {
+ return List.of(seat);
+ }
+
+ @Override
+ public List getPassengers() {
+ return List.of(seat.getPassenger());
+ }
+
+ @Override
+ public void ejectPassengers() {
+ if(seat.hasPassenger())
+ seat.setPassenger(null);
+ }
+
+ @Override
+ public void despawn() {
+
+ }
+
+ @Override
+ public void setRestraint(boolean locked) {
+ seat.setRestraint(locked);
+ }
+
+ @Override
+ public boolean getRestraintState() {
+ return seat.restraintsActive();
+ }
+
+ @Override
+ public PlayerLocation getEjectLocation() {
+ return seat.getParentRideHandle().getEjectLocation();
+ }
+
+ @Override
+ public RideHandle getRideHandle() {
+ return seat.getParentRideHandle();
+ }
+
+ @Override
+ public void onPlayerEnter(Player player) {
+ parentVehicle.onPlayerEnter(player);
+ }
+
+ @Override
+ public void onPlayerExit(Player player) {
+ parentVehicle.onPlayerExit(player);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/station/FlatRideStationHandle.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/station/FlatRideStationHandle.java
new file mode 100644
index 00000000..029bb537
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/station/FlatRideStationHandle.java
@@ -0,0 +1,37 @@
+package com.jverbruggen.jrides.animator.flatride.station;
+
+import com.jverbruggen.jrides.animator.flatride.FlatRideHandle;
+import com.jverbruggen.jrides.control.trigger.TriggerContext;
+import com.jverbruggen.jrides.effect.handle.train.TrainEffectTriggerHandle;
+import com.jverbruggen.jrides.models.properties.MinMaxWaitingTimer;
+import com.jverbruggen.jrides.models.properties.PlayerLocation;
+import com.jverbruggen.jrides.models.ride.StationHandle;
+import com.jverbruggen.jrides.models.ride.coaster.train.Train;
+import com.jverbruggen.jrides.models.ride.coaster.train.Vehicle;
+import com.jverbruggen.jrides.models.ride.gate.Gate;
+
+import java.util.List;
+
+public class FlatRideStationHandle extends StationHandle {
+ private final FlatRideUniVehicle vehicle;
+
+ public FlatRideStationHandle(String name, String shortName, List entryGates, PlayerLocation ejectLocation, MinMaxWaitingTimer waitingTimer, TriggerContext triggerContext, List entryBlockingEffectTriggers, List exitBlockingEffectTriggers, List exitEffectTriggers) {
+ super(name, shortName, entryGates, ejectLocation, waitingTimer, triggerContext, entryBlockingEffectTriggers, exitBlockingEffectTriggers, exitEffectTriggers);
+ this.vehicle = new FlatRideUniVehicle(name + "_vehicle", false,
+ triggerContext.getRestraintTrigger().getLock(), triggerContext.getVehiclePresentLock());
+ }
+
+ @Override
+ public Vehicle getStationaryVehicle() {
+ if(vehicle.isStationary()) return vehicle;
+ return null;
+ }
+
+ public FlatRideUniVehicle getVehicle() {
+ return vehicle;
+ }
+
+ public void setFlatRideHandle(FlatRideHandle flatRideHandle) {
+ this.vehicle.setFlatRideHandle(flatRideHandle);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/station/FlatRideUniVehicle.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/station/FlatRideUniVehicle.java
new file mode 100644
index 00000000..d60f6137
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/station/FlatRideUniVehicle.java
@@ -0,0 +1,92 @@
+package com.jverbruggen.jrides.animator.flatride.station;
+
+import com.jverbruggen.jrides.animator.flatride.FlatRideComponent;
+import com.jverbruggen.jrides.animator.flatride.FlatRideHandle;
+import com.jverbruggen.jrides.control.DispatchLock;
+import com.jverbruggen.jrides.models.entity.Player;
+import com.jverbruggen.jrides.models.math.Vector3;
+import com.jverbruggen.jrides.models.properties.PlayerLocation;
+import com.jverbruggen.jrides.models.ride.coaster.train.AbstractVehicle;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class FlatRideUniVehicle extends AbstractVehicle {
+ private final List rootComponents;
+ private FlatRideHandle flatRideHandle;
+ private boolean onStation;
+ private final DispatchLock restraintLock;
+
+ public FlatRideUniVehicle(String name, boolean debugMode, DispatchLock restraintLock, DispatchLock vehiclePresentLock) {
+ super(name, debugMode);
+ this.rootComponents = new ArrayList<>();
+ this.onStation = true;
+ this.restraintLock = restraintLock;
+
+ vehiclePresentLock.addEventListener(l -> setStationary(l.isUnlocked()));
+ }
+
+ public void tick(){
+ this.rootComponents.forEach(FlatRideComponent::tick);
+ }
+
+
+ public void addRootComponent(FlatRideComponent component){
+ rootComponents.add(component);
+ }
+
+ public List getRootComponents() {
+ return rootComponents;
+ }
+
+ @Override
+ public boolean isStationary() {
+ return onStation;
+ }
+
+ public void setStationary(boolean stationary){
+ onStation = stationary;
+ }
+
+ @Override
+ public boolean getRestraintState() {
+ return restraintLock.isUnlocked();
+ }
+
+ @Override
+ public void setRestraintForAll(boolean closed) {
+ restraintLock.setLocked(!closed);
+ }
+
+ @Override
+ public void ejectPassengers() {
+ PlayerLocation ejectLocation = flatRideHandle.getEjectLocation();
+ for(Player passenger : new ArrayList<>(getPassengers())){
+ passenger.teleport(ejectLocation, true);
+ }
+ }
+
+ @Override
+ public void playRestraintOpenSound() {
+
+ }
+
+ @Override
+ public void playRestraintCloseSound() {
+
+ }
+
+ @Override
+ public void playDispatchSound() {
+
+ }
+
+ @Override
+ public Vector3 getCurrentLocation() {
+ return flatRideHandle.getRootComponents().get(0).getPosition();
+ }
+
+ public void setFlatRideHandle(FlatRideHandle flatRideHandle) {
+ this.flatRideHandle = flatRideHandle;
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/TimingSequence.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/TimingSequence.java
new file mode 100644
index 00000000..4592f916
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/TimingSequence.java
@@ -0,0 +1,55 @@
+package com.jverbruggen.jrides.animator.flatride.timing;
+
+import com.jverbruggen.jrides.animator.flatride.timing.instruction.InstructionSequenceItem;
+
+import java.util.Iterator;
+import java.util.List;
+
+public class TimingSequence {
+ private final List items;
+
+ private Iterator itemIterator;
+ private InstructionSequenceItem current;
+ private int state;
+
+ public TimingSequence(List items) {
+ this.items = items;
+ this.state = 0;
+ this.current = null;
+ }
+
+ public void restart(){
+ if(this.current != null)
+ return;
+
+ this.state = 0;
+ this.itemIterator = items.iterator();
+ loadNext();
+ }
+
+ private void loadNext(){
+ if(!itemIterator.hasNext())
+ this.current = null;
+ else
+ this.current = itemIterator.next();
+ }
+
+ public boolean tick(){
+ if(current == null) return false;
+
+ boolean finished = current.tick(state);
+ if(finished) {
+ current.cleanUp();
+ loadNext();
+ state = 0;
+ return this.current == null;
+ }else{
+ state++;
+ return false;
+ }
+ }
+
+ public boolean isIdle(){
+ return this.current == null;
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/instruction/AnimationInstruction.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/instruction/AnimationInstruction.java
new file mode 100644
index 00000000..fceb93a4
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/instruction/AnimationInstruction.java
@@ -0,0 +1,49 @@
+package com.jverbruggen.jrides.animator.flatride.timing.instruction;
+
+import com.jverbruggen.jrides.animator.flatride.BlenderExportPositionRecord;
+import com.jverbruggen.jrides.animator.flatride.FlatRideComponent;
+import com.jverbruggen.jrides.animator.flatride.interfaces.Component6DOFPosition;
+import com.jverbruggen.jrides.state.ride.flatride.Animation;
+import com.jverbruggen.jrides.state.ride.flatride.AnimationHandle;
+
+public class AnimationInstruction implements Instruction {
+ private final AnimationHandle animationHandle;
+ private int frameIndexState;
+
+ public AnimationInstruction(AnimationHandle animationHandle) {
+ this.animationHandle = animationHandle;
+ this.frameIndexState = 0;
+ }
+
+ @Override
+ public void applyTo(FlatRideComponent component) {
+ Animation animation = animationHandle.getAnimation(component.getIdentifier());
+ if(animation.getFrames().size() <= frameIndexState) return;
+
+ BlenderExportPositionRecord position = animation.getFrames().get(frameIndexState);
+
+ ((Component6DOFPosition)component).setPositionRotation(
+ position.toMinecraftVector(),
+ position.toMinecraftQuaternion());
+ }
+
+ @Override
+ public boolean canHandle(FlatRideComponent component) {
+ return component instanceof Component6DOFPosition;
+ }
+
+ @Override
+ public void tick() {
+ frameIndexState++;
+ }
+
+ @Override
+ public void reset() {
+ frameIndexState = 0;
+ }
+
+ @Override
+ public void cleanUp(FlatRideComponent component) {
+
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/instruction/ControlInstruction.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/instruction/ControlInstruction.java
new file mode 100644
index 00000000..ad20f070
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/instruction/ControlInstruction.java
@@ -0,0 +1,41 @@
+package com.jverbruggen.jrides.animator.flatride.timing.instruction;
+
+import com.jverbruggen.jrides.animator.flatride.FlatRideComponent;
+import com.jverbruggen.jrides.animator.flatride.interfaces.PlayerControllable;
+
+public class ControlInstruction implements Instruction {
+ private final boolean allowControl;
+
+ public ControlInstruction(boolean allowControl) {
+ this.allowControl = allowControl;
+ }
+
+ public void execute(PlayerControllable playerControllable){
+ playerControllable.setAllowControl(this.allowControl);
+ }
+
+ @Override
+ public void applyTo(FlatRideComponent component) {
+ execute((PlayerControllable) component);
+ }
+
+ @Override
+ public boolean canHandle(FlatRideComponent component) {
+ return component instanceof PlayerControllable;
+ }
+
+ @Override
+ public void tick() {
+
+ }
+
+ @Override
+ public void reset() {
+
+ }
+
+ @Override
+ public void cleanUp(FlatRideComponent component) {
+
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/instruction/Instruction.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/instruction/Instruction.java
new file mode 100644
index 00000000..089e3796
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/instruction/Instruction.java
@@ -0,0 +1,11 @@
+package com.jverbruggen.jrides.animator.flatride.timing.instruction;
+
+import com.jverbruggen.jrides.animator.flatride.FlatRideComponent;
+
+public interface Instruction {
+ void applyTo(FlatRideComponent component);
+ boolean canHandle(FlatRideComponent component);
+ void tick();
+ void reset();
+ void cleanUp(FlatRideComponent component);
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/instruction/InstructionBinding.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/instruction/InstructionBinding.java
new file mode 100644
index 00000000..f31e1754
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/instruction/InstructionBinding.java
@@ -0,0 +1,30 @@
+package com.jverbruggen.jrides.animator.flatride.timing.instruction;
+
+import com.jverbruggen.jrides.animator.flatride.FlatRideComponent;
+
+import java.util.List;
+
+public class InstructionBinding implements TimingAction {
+ private final Instruction instruction;
+ private final List flatRideComponents;
+
+ public InstructionBinding(Instruction instruction, List flatRideComponents) {
+ this.instruction = instruction;
+ this.flatRideComponents = flatRideComponents;
+ }
+
+ public void tick(){
+ for(FlatRideComponent flatRideComponent : flatRideComponents){
+ instruction.applyTo(flatRideComponent);
+ }
+ instruction.tick();
+ }
+
+ @Override
+ public void cleanUp() {
+ for(FlatRideComponent flatRideComponent : flatRideComponents){
+ instruction.cleanUp(flatRideComponent);
+ }
+ instruction.reset();
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/instruction/InstructionSequenceItem.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/instruction/InstructionSequenceItem.java
new file mode 100644
index 00000000..0766424d
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/instruction/InstructionSequenceItem.java
@@ -0,0 +1,29 @@
+package com.jverbruggen.jrides.animator.flatride.timing.instruction;
+
+import java.util.List;
+
+public class InstructionSequenceItem {
+ private final int durationTicks;
+ private final List actions;
+
+ public InstructionSequenceItem(int durationTicks, List actions) {
+ this.durationTicks = durationTicks;
+ this.actions = actions;
+ }
+
+ public boolean tick(int state){
+ if(state > durationTicks) return true;
+
+ for(TimingAction action : actions){
+ action.tick();
+ }
+
+ return false;
+ }
+
+ public void cleanUp(){
+ for(TimingAction action : actions){
+ action.cleanUp();
+ }
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/instruction/SpeedInstruction.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/instruction/SpeedInstruction.java
new file mode 100644
index 00000000..251dbc70
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/instruction/SpeedInstruction.java
@@ -0,0 +1,45 @@
+package com.jverbruggen.jrides.animator.flatride.timing.instruction;
+
+import com.jverbruggen.jrides.animator.flatride.FlatRideComponent;
+import com.jverbruggen.jrides.animator.flatride.FlatRideComponentSpeed;
+import com.jverbruggen.jrides.animator.flatride.interfaces.HasSpeed;
+
+public class SpeedInstruction implements Instruction {
+ private final float acceleration;
+ private final float speed;
+
+ public SpeedInstruction(float acceleration, float speed) {
+ this.acceleration = acceleration;
+ this.speed = speed;
+ }
+
+ public void execute(HasSpeed hasSpeed){
+ FlatRideComponentSpeed speedComponent = hasSpeed.getFlatRideComponentSpeed();
+ speedComponent.accelerateTowards(this.acceleration, this.speed);
+ }
+
+ @Override
+ public void applyTo(FlatRideComponent component) {
+ execute((HasSpeed) component);
+ }
+
+ @Override
+ public boolean canHandle(FlatRideComponent component) {
+ return component instanceof HasSpeed;
+ }
+
+ @Override
+ public void tick() {
+
+ }
+
+ @Override
+ public void reset() {
+
+ }
+
+ @Override
+ public void cleanUp(FlatRideComponent component) {
+
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/instruction/TimingAction.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/instruction/TimingAction.java
new file mode 100644
index 00000000..5b7f3403
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/instruction/TimingAction.java
@@ -0,0 +1,6 @@
+package com.jverbruggen.jrides.animator.flatride.timing.instruction;
+
+public interface TimingAction {
+ void tick();
+ void cleanUp();
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/instruction/towards/TowardsPositionInstruction.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/instruction/towards/TowardsPositionInstruction.java
new file mode 100644
index 00000000..e1835ba9
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/instruction/towards/TowardsPositionInstruction.java
@@ -0,0 +1,106 @@
+package com.jverbruggen.jrides.animator.flatride.timing.instruction.towards;
+
+import com.jverbruggen.jrides.animator.flatride.FlatRideComponent;
+import com.jverbruggen.jrides.animator.flatride.FlatRideComponentSpeed;
+import com.jverbruggen.jrides.animator.flatride.interfaces.HasPosition;
+import com.jverbruggen.jrides.animator.flatride.timing.instruction.Instruction;
+import com.jverbruggen.jrides.models.math.SpeedUtil;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class TowardsPositionInstruction implements Instruction {
+ private final double accelerate;
+ private final double minSpeed;
+ private final double maxSpeed;
+ private final double towardsPosition;
+ private final Map states;
+
+ public TowardsPositionInstruction(double accelerate, double minSpeed, double maxSpeed, double towardsPosition) {
+ this.accelerate = accelerate;
+ this.minSpeed = minSpeed;
+ this.maxSpeed = maxSpeed;
+ this.towardsPosition = towardsPosition;
+ this.states = new HashMap<>();
+ }
+
+ public void execute(HasPosition hasPosition){
+ if(!states.containsKey(hasPosition)){
+ TowardsPositionInstructionState state = new TowardsPositionInstructionState();
+ states.put(hasPosition, state);
+ execute(hasPosition, state);
+ }else{
+ execute(hasPosition, states.get(hasPosition));
+ }
+ }
+
+ public void execute(HasPosition hasPosition, TowardsPositionInstructionState state){
+ if (state.getOriginalState() == null) {
+ state.setOriginalState(hasPosition.getInstructionPosition());
+ state.setAcceleration(accelerate);
+
+ double lowerOperatingRange = hasPosition.getLowerOperatingRange();
+ double upperOperatingRange = hasPosition.getUpperOperatingRange();
+
+// JRidesPlugin.getLogger().debug("l: " + lowerOperatingRange + ", x: " + state.getOriginalState() + ", t: " + towardsPosition + ", p: " + positiveFrom);
+
+ if(!SpeedUtil.aboveInRange(lowerOperatingRange, state.getOriginalState(), towardsPosition, upperOperatingRange, true)){
+ state.setAcceleration(-accelerate);
+// JRidesPlugin.getLogger().debug("Flipped " + state.getAcceleration());
+ }
+ }
+
+ double acc = state.getAcceleration();
+ double lowerPosition = acc >= 0 ? state.getOriginalState() : this.towardsPosition;
+ double upperPosition = acc >= 0 ? this.towardsPosition : state.getOriginalState();
+
+// JRidesPlugin.getLogger().debug("" + lowerPosition + "," + upperPosition + "," + acc);
+ TowardsPositionInstruction.run(
+ hasPosition,
+ acc,
+ lowerPosition,
+ upperPosition,
+ 0d,
+ this.maxSpeed,
+ this.minSpeed);
+ }
+
+ @Override
+ public void applyTo(FlatRideComponent component) {
+ execute((HasPosition) component);
+ }
+
+ @Override
+ public boolean canHandle(FlatRideComponent component) {
+ return component instanceof HasPosition;
+ }
+
+ @Override
+ public void tick() {
+
+ }
+
+ @Override
+ public void reset() {
+ states.values().forEach(s -> {
+ s.setAcceleration(accelerate);
+ s.setOriginalState(null);
+ }
+ );
+ }
+
+ @Override
+ public void cleanUp(FlatRideComponent component) {
+ ((HasPosition)component).setInstructionPosition(towardsPosition);
+ }
+
+ public static void run(HasPosition hasPosition, double acceleration, double lowerPosition, double upperPosition, double margin, double maxSpeed, double minSpeed){
+ FlatRideComponentSpeed componentSpeed = hasPosition.getFlatRideComponentSpeed();
+ boolean positiveAcceleration = acceleration >= 0;
+
+ double targetPosition = positiveAcceleration ? upperPosition : lowerPosition;
+ double fromPosition = positiveAcceleration ? lowerPosition : upperPosition;
+
+ hasPosition.goTowards(targetPosition, fromPosition, acceleration, componentSpeed);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/instruction/towards/TowardsPositionInstructionState.java b/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/instruction/towards/TowardsPositionInstructionState.java
new file mode 100644
index 00000000..77acabf4
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/flatride/timing/instruction/towards/TowardsPositionInstructionState.java
@@ -0,0 +1,27 @@
+package com.jverbruggen.jrides.animator.flatride.timing.instruction.towards;
+
+public class TowardsPositionInstructionState {
+ private Double originalState;
+ private double acceleration;
+
+ public TowardsPositionInstructionState() {
+ this.originalState = null;
+ this.acceleration = 0d;
+ }
+
+ public Double getOriginalState() {
+ return originalState;
+ }
+
+ public void setOriginalState(Double originalState) {
+ this.originalState = originalState;
+ }
+
+ public double getAcceleration() {
+ return acceleration;
+ }
+
+ public void setAcceleration(double acceleration) {
+ this.acceleration = acceleration;
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/smoothanimation/SmoothAnimation.java b/src/main/java/com/jverbruggen/jrides/animator/smoothanimation/SmoothAnimation.java
new file mode 100644
index 00000000..d61509d3
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/smoothanimation/SmoothAnimation.java
@@ -0,0 +1,10 @@
+package com.jverbruggen.jrides.animator.smoothanimation;
+
+import com.jverbruggen.jrides.models.entity.Player;
+import com.jverbruggen.jrides.models.math.Quaternion;
+
+public interface SmoothAnimation {
+ boolean isEnabled(Player player);
+ void clearRotation(Player player);
+ void setRotation(Player player, Quaternion orientation);
+}
diff --git a/src/main/java/com/jverbruggen/jrides/animator/smoothanimation/SmoothAnimationSupport.java b/src/main/java/com/jverbruggen/jrides/animator/smoothanimation/SmoothAnimationSupport.java
new file mode 100644
index 00000000..2111b697
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/smoothanimation/SmoothAnimationSupport.java
@@ -0,0 +1,6 @@
+package com.jverbruggen.jrides.animator.smoothanimation;
+
+public enum SmoothAnimationSupport{
+ UNKNOWN, AVAILABLE, UNAVAILABLE
+}
+
diff --git a/src/main/java/com/jverbruggen/jrides/animator/smoothanimation/SmoothCoastersSmoothAnimation.java b/src/main/java/com/jverbruggen/jrides/animator/smoothanimation/SmoothCoastersSmoothAnimation.java
new file mode 100644
index 00000000..0c9710a4
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/animator/smoothanimation/SmoothCoastersSmoothAnimation.java
@@ -0,0 +1,32 @@
+package com.jverbruggen.jrides.animator.smoothanimation;
+
+import com.jverbruggen.jrides.models.entity.Player;
+import com.jverbruggen.jrides.models.math.Quaternion;
+import me.m56738.smoothcoasters.api.SmoothCoastersAPI;
+
+public class SmoothCoastersSmoothAnimation implements SmoothAnimation {
+ private final SmoothCoastersAPI api;
+
+ public SmoothCoastersSmoothAnimation(SmoothCoastersAPI api) {
+ this.api = api;
+ }
+
+ @Override
+ public boolean isEnabled(Player player) {
+ return api.isEnabled(player.getBukkitPlayer());
+ }
+
+ @Override
+ public void clearRotation(Player player) {
+ api.resetRotation(null, player.getBukkitPlayer());
+ }
+
+ @Override
+ public void setRotation(Player player, Quaternion orientation) {
+ float x = (float) orientation.getX();
+ float y = (float) orientation.getY();
+ float z = (float) orientation.getZ();
+ float w = (float) orientation.getW();
+ api.setRotation(null, player.getBukkitPlayer(), x, y, z, w, (byte)3);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/api/JRidesPlayer.java b/src/main/java/com/jverbruggen/jrides/api/JRidesPlayer.java
new file mode 100644
index 00000000..e86ccf21
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/api/JRidesPlayer.java
@@ -0,0 +1,13 @@
+package com.jverbruggen.jrides.api;
+
+import java.util.UUID;
+
+public interface JRidesPlayer {
+ org.bukkit.entity.Player getBukkitPlayer();
+ String getName();
+ String getIdentifier();
+ UUID getUniqueId();
+ boolean isSeated();
+
+ void sendTitle(String title, String subtitle, int stay);
+}
diff --git a/src/main/java/com/jverbruggen/jrides/api/JRidesPlayerLocation.java b/src/main/java/com/jverbruggen/jrides/api/JRidesPlayerLocation.java
new file mode 100644
index 00000000..e4c6f7a5
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/api/JRidesPlayerLocation.java
@@ -0,0 +1,9 @@
+package com.jverbruggen.jrides.api;
+
+public interface JRidesPlayerLocation {
+ double getX();
+ double getY();
+ double getZ();
+ double getYaw();
+ double getPitch();
+}
diff --git a/src/main/java/com/jverbruggen/jrides/api/JRidesRide.java b/src/main/java/com/jverbruggen/jrides/api/JRidesRide.java
new file mode 100644
index 00000000..ef131641
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/api/JRidesRide.java
@@ -0,0 +1,6 @@
+package com.jverbruggen.jrides.api;
+
+public interface JRidesRide {
+ String getIdentifier();
+ JRidesPlayerLocation getWarpLocation();
+}
diff --git a/src/main/java/com/jverbruggen/jrides/api/PlayerAPI.java b/src/main/java/com/jverbruggen/jrides/api/PlayerAPI.java
new file mode 100644
index 00000000..251f7983
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/api/PlayerAPI.java
@@ -0,0 +1,32 @@
+package com.jverbruggen.jrides.api;
+
+import com.jverbruggen.jrides.common.MenuSessionManager;
+import com.jverbruggen.jrides.models.menu.Menu;
+import com.jverbruggen.jrides.serviceprovider.ServiceProvider;
+import com.jverbruggen.jrides.state.player.PlayerManager;
+import com.jverbruggen.jrides.state.ride.menu.RideOverviewMenuFactory;
+import org.bukkit.inventory.Inventory;
+
+public class PlayerAPI {
+ private final PlayerManager playerManager;
+ private final RideOverviewMenuFactory rideOverviewMenuFactory;
+ private final MenuSessionManager menuSessionManager;
+
+ public PlayerAPI() {
+ playerManager = ServiceProvider.getSingleton(PlayerManager.class);
+ rideOverviewMenuFactory = ServiceProvider.getSingleton(RideOverviewMenuFactory.class);
+ menuSessionManager = ServiceProvider.getSingleton(MenuSessionManager.class);
+ }
+
+ public JRidesPlayer getFromBukkitPlayer(org.bukkit.entity.Player bukkitPlayer){
+ return playerManager.getPlayer(bukkitPlayer);
+ }
+
+ public void displayRideOverviewMenu(JRidesPlayer player){
+ Menu menu = rideOverviewMenuFactory.getRideOverviewMenu();
+ Inventory inventory = menu.getInventoryFor(player);
+
+ menuSessionManager.addOpenMenu(player, menu, inventory);
+ player.getBukkitPlayer().openInventory(inventory);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/api/RidesAPI.java b/src/main/java/com/jverbruggen/jrides/api/RidesAPI.java
new file mode 100644
index 00000000..285afad9
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/api/RidesAPI.java
@@ -0,0 +1,23 @@
+package com.jverbruggen.jrides.api;
+
+import com.jverbruggen.jrides.animator.RideHandle;
+import com.jverbruggen.jrides.serviceprovider.ServiceProvider;
+import com.jverbruggen.jrides.state.ride.RideManager;
+
+import java.util.List;
+
+public class RidesAPI {
+ private final RideManager rideManager;
+
+ public RidesAPI(){
+ this.rideManager = ServiceProvider.getSingleton(RideManager.class);
+ }
+
+ public List getRides(){
+ return this.rideManager.getRideHandles();
+ }
+
+ public RideHandle getRide(String rideIdentifier){
+ return this.rideManager.getRideHandle(rideIdentifier);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/command/BaseCommandExecutor.java b/src/main/java/com/jverbruggen/jrides/command/BaseCommandExecutor.java
new file mode 100644
index 00000000..9ede9ff7
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/command/BaseCommandExecutor.java
@@ -0,0 +1,120 @@
+package com.jverbruggen.jrides.command;
+
+import com.jverbruggen.jrides.command.context.CommandContext;
+import com.jverbruggen.jrides.common.permissions.Permissions;
+import com.jverbruggen.jrides.language.LanguageFile;
+import com.jverbruggen.jrides.language.LanguageFileField;
+import com.jverbruggen.jrides.models.entity.agent.MessageAgent;
+import com.jverbruggen.jrides.models.entity.MessageReceiver;
+import com.jverbruggen.jrides.models.entity.agent.MessageAgentManager;
+import com.jverbruggen.jrides.serviceprovider.ServiceProvider;
+import com.jverbruggen.jrides.state.player.PlayerManager;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+public abstract class BaseCommandExecutor implements JRidesCommandExecutor {
+ protected final LanguageFile languageFile;
+ protected final PlayerManager playerManager;
+ protected final MessageAgentManager messageAgentManager;
+ protected final Map subCommands;
+ protected final int depth;
+
+ protected BaseCommandExecutor(int depth) {
+ this.depth = depth;
+ this.languageFile = ServiceProvider.getSingleton(LanguageFile.class);
+ this.playerManager = ServiceProvider.getSingleton(PlayerManager.class);
+ this.messageAgentManager = ServiceProvider.getSingleton(MessageAgentManager.class);
+ this.subCommands = new HashMap<>();
+ }
+
+ @Override
+ public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
+ if(getPermission() != null && !commandSender.hasPermission(getPermission()) && !canEveryoneRun()){
+ languageFile.sendMessage(commandSender, LanguageFileField.ERROR_GENERAL_NO_PERMISSION_MESSAGE);
+ return true;
+ }
+
+ return onCommand(messageAgentManager.getOrCreateMessageAgent(commandSender), command, s, args, new CommandContext());
+ }
+
+ @Override
+ public boolean onCommand(MessageAgent messageAgent, Command command, String s, String[] args, CommandContext commandContext){
+ if(args.length == depth){
+ languageFile.sendMultilineMessage(messageAgent, getHelpMessageForParent());
+ return true;
+ }
+
+ commandContext.add(MessageReceiver.class, messageAgent);
+ String subCommand = args[depth];
+ return runSubCommand(messageAgent, command, s, args, subCommand, commandContext);
+ }
+
+ protected boolean runSubCommand(MessageAgent commandSender, Command command, String s, String[] args, String subCommand, CommandContext commandContext){
+ JRidesCommandExecutor firstCommand = findSubCommand(subCommand);
+ if(firstCommand != null) {
+ if(!commandSender.hasPermission(firstCommand.getPermission())){
+ languageFile.sendMessage(commandSender, LanguageFileField.ERROR_GENERAL_NO_PERMISSION_MESSAGE);
+ return true;
+ }
+
+ firstCommand.onCommand(commandSender, command, s, args, commandContext);
+ return true;
+ }
+
+ languageFile.sendMessage(commandSender, LanguageFileField.ERROR_UNKNOWN_COMMAND_MESSAGE);
+ return false;
+ }
+
+ protected T registerSubCommand(T commandExecutor){
+ subCommands.put(commandExecutor.getCommand(), commandExecutor);
+ return commandExecutor;
+ }
+
+ public List getCommandSuggestions(MessageAgent forAgent){
+ return subCommands.entrySet().stream()
+ .filter(entry -> forAgent.hasPermission(entry.getValue().getPermission()))
+ .map(Map.Entry::getKey)
+ .collect(Collectors.toList());
+ }
+
+ protected JRidesCommandExecutor findSubCommand(String command){
+ return subCommands.get(command);
+ }
+
+ @Override
+ public List onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) {
+ return onTabComplete(messageAgentManager.getOrCreateMessageAgent(commandSender), command, s, strings);
+ }
+
+ @Override
+ public List onTabComplete(MessageAgent messageAgent, Command command, String s, String[] strings) {
+ if(!messageAgent.hasPermission(getPermission())) return Collections.emptyList();
+
+ if(strings.length <= depth+1){
+ return getCommandSuggestions(messageAgent);
+ }else{
+ JRidesCommandExecutor subCommand = findSubCommand(strings[depth]);
+ if(subCommand == null) return List.of();
+ return subCommand.onTabComplete(messageAgent, command, s, strings);
+ }
+ }
+
+ @Override
+ public String getHelpMessageForSelf() {
+ return subCommands.values().stream()
+ .map(JRidesCommandExecutor::getHelpMessageForParent)
+ .collect(Collectors.joining("\n"));
+ }
+
+ @Override
+ public String getPermission() {
+ return Permissions.COMMAND_ELEVATED_BASE;
+ }
+
+ public boolean canEveryoneRun(){
+ return false;
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/command/BlockSectionCommandExecutor.java b/src/main/java/com/jverbruggen/jrides/command/BlockSectionCommandExecutor.java
new file mode 100644
index 00000000..84808421
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/command/BlockSectionCommandExecutor.java
@@ -0,0 +1,113 @@
+package com.jverbruggen.jrides.command;
+
+import com.jverbruggen.jrides.animator.coaster.CoasterHandle;
+import com.jverbruggen.jrides.animator.RideHandle;
+import com.jverbruggen.jrides.command.context.CommandContext;
+import com.jverbruggen.jrides.common.permissions.Permissions;
+import com.jverbruggen.jrides.language.FeedbackType;
+import com.jverbruggen.jrides.language.LanguageFileField;
+import com.jverbruggen.jrides.models.entity.agent.MessageAgent;
+import com.jverbruggen.jrides.models.ride.coaster.track.Track;
+import com.jverbruggen.jrides.models.ride.section.Section;
+import com.jverbruggen.jrides.serviceprovider.ServiceProvider;
+import com.jverbruggen.jrides.state.ride.RideManager;
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class BlockSectionCommandExecutor extends BaseCommandExecutor {
+ private final RideManager rideManager;
+
+ protected BlockSectionCommandExecutor() {
+ super(1);
+ this.rideManager = ServiceProvider.getSingleton(RideManager.class);
+ }
+
+ @Override
+ public String getHelpMessageForParent() {
+ return "/jrides " + getCommand() + " ";
+ }
+
+ @Override
+ public boolean onCommand(MessageAgent messageAgent, Command command, String arg, String[] args, CommandContext context) {
+ if(!messageAgent.isPlayer()){
+ languageFile.sendMessage(messageAgent, LanguageFileField.ERROR_PLAYER_COMMAND_ONLY_MESSAGE);
+ return true;
+ }
+
+ if(args.length != 2){
+ languageFile.sendMessage(messageAgent, getHelpMessageForSelf());
+ return true;
+ }
+
+ String identifier = args[1];
+ if(identifier.equalsIgnoreCase("")){
+ languageFile.sendMessage(messageAgent, getHelpMessageForSelf());
+ return true;
+ }
+
+ RideHandle rideHandle = ServiceProvider.getSingleton(RideManager.class).getRideHandle(identifier);
+ if(rideHandle == null){
+ languageFile.sendMessage(messageAgent, "Ride '" + identifier + "' not found", FeedbackType.CONFLICT);
+ return true;
+ }
+
+ if(!(rideHandle instanceof CoasterHandle)){
+ languageFile.sendMessage(messageAgent, "Ride has no track", FeedbackType.CONFLICT);
+ return true;
+ }
+
+ Track track = ((CoasterHandle)rideHandle).getTrack();
+ if(track == null){
+ languageFile.sendMessage(messageAgent, "Track was not found", FeedbackType.CONFLICT);
+ return true;
+ }
+
+ List sections = new ArrayList<>(track.getSections());
+ Collections.sort(sections);
+
+ languageFile.sendMessage(messageAgent, "-- Block section occupations --");
+ for(Section section : sections){
+ boolean occupied = section.isOccupied();
+ boolean reserved = section.getReservedBy() != null;
+ boolean safe = section.getBlockSectionSafety(null).safe();
+
+ ChatColor color = ChatColor.GREEN;
+ if(occupied) color = ChatColor.RED;
+ else if(reserved) color = ChatColor.DARK_AQUA;
+ else if(!safe) color = ChatColor.YELLOW;
+
+ languageFile.sendMessage(messageAgent, color + section.toString());
+ }
+
+
+ return true;
+ }
+
+ @Override
+ public String getHelpMessageForSelf() {
+ return getHelpMessageForParent();
+ }
+
+ @Override
+ public String getCommand() {
+ return "blocksections";
+ }
+
+ @Override
+ public String getPermission() {
+ return Permissions.COMMAND_ELEVATED_BLOCK_SECTION;
+ }
+
+ @Override
+ public List onTabComplete(MessageAgent messageAgent, Command command, String s, String[] strings) {
+ if(!messageAgent.hasPermission(getPermission())) return Collections.emptyList();
+
+ if(strings.length == depth+1)
+ return rideManager.getRideIdentifiers();
+ return null;
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/command/HelpCommandExecutor.java b/src/main/java/com/jverbruggen/jrides/command/HelpCommandExecutor.java
new file mode 100644
index 00000000..adf00f36
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/command/HelpCommandExecutor.java
@@ -0,0 +1,30 @@
+package com.jverbruggen.jrides.command;
+
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+public class HelpCommandExecutor extends BaseCommandExecutor {
+ private final MainCommandExecutor mainCommandExecutor;
+
+ public HelpCommandExecutor(MainCommandExecutor mainCommandExecutor) {
+ super(1);
+ this.mainCommandExecutor = mainCommandExecutor;
+ }
+
+ @Override
+ public String getCommand() {
+ return "help";
+ }
+
+ @Override
+ public String getHelpMessageForParent() {
+ return mainCommandExecutor.subCommands.values().stream()
+ .map(executor -> {
+ if(executor == this) return null;
+ return executor.getHelpMessageForParent();
+ })
+ .filter(Objects::nonNull)
+ .sorted()
+ .collect(Collectors.joining("\n"));
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/command/JRidesCommandExecutor.java b/src/main/java/com/jverbruggen/jrides/command/JRidesCommandExecutor.java
new file mode 100644
index 00000000..b2c965ad
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/command/JRidesCommandExecutor.java
@@ -0,0 +1,19 @@
+package com.jverbruggen.jrides.command;
+
+import com.jverbruggen.jrides.command.context.CommandContext;
+import com.jverbruggen.jrides.models.entity.agent.MessageAgent;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.TabCompleter;
+
+import java.util.List;
+
+public interface JRidesCommandExecutor extends CommandExecutor, TabCompleter {
+ String getHelpMessageForParent();
+ String getCommand();
+ String getHelpMessageForSelf();
+ boolean onCommand(MessageAgent messageAgent, Command command, String s, String[] args, CommandContext commandContext);
+ List onTabComplete(MessageAgent messageAgent, Command command, String s, String[] strings);
+ String getPermission();
+
+}
diff --git a/src/main/java/com/jverbruggen/jrides/command/MainCommandExecutor.java b/src/main/java/com/jverbruggen/jrides/command/MainCommandExecutor.java
new file mode 100644
index 00000000..dc0dc5a9
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/command/MainCommandExecutor.java
@@ -0,0 +1,39 @@
+package com.jverbruggen.jrides.command;
+
+import com.jverbruggen.jrides.JRidesPlugin;
+import com.jverbruggen.jrides.command.control.ControlCommandExecutor;
+import org.bukkit.ChatColor;
+
+public class MainCommandExecutor extends BaseCommandExecutor {
+ public MainCommandExecutor() {
+ super(0);
+ registerSubCommand(new HelpCommandExecutor(this));
+ registerSubCommand(new BlockSectionCommandExecutor());
+ registerSubCommand(new VisualizeCommandExecutor());
+ registerSubCommand(new ControlCommandExecutor());
+ registerSubCommand(new WarpCommandExecutor());
+ registerSubCommand(new RideOverviewMapCommandExecutor());
+ registerSubCommand(new RideCounterMapCommandExecutor());
+ registerSubCommand(new RidesCommandExecutor());
+ }
+
+ @Override
+ public String getCommand() {
+ return null;
+ }
+
+ @Override
+ public String getPermission() {
+ return null;
+ }
+
+ @Override
+ public String getHelpMessageForParent() {
+ return ChatColor.GOLD + "This server is running jrides - " + JRidesPlugin.getVersion();
+ }
+
+ @Override
+ public boolean canEveryoneRun() {
+ return true;
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/command/RideCounterMapCommandExecutor.java b/src/main/java/com/jverbruggen/jrides/command/RideCounterMapCommandExecutor.java
new file mode 100644
index 00000000..8f9d9e27
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/command/RideCounterMapCommandExecutor.java
@@ -0,0 +1,98 @@
+package com.jverbruggen.jrides.command;
+
+import com.jverbruggen.jrides.animator.RideHandle;
+import com.jverbruggen.jrides.command.context.CommandContext;
+import com.jverbruggen.jrides.common.permissions.Permissions;
+import com.jverbruggen.jrides.language.FeedbackType;
+import com.jverbruggen.jrides.language.LanguageFileField;
+import com.jverbruggen.jrides.models.entity.Player;
+import com.jverbruggen.jrides.models.entity.agent.MessageAgent;
+import com.jverbruggen.jrides.models.map.ridecounter.RideCounterMapFactory;
+import com.jverbruggen.jrides.serviceprovider.ServiceProvider;
+import com.jverbruggen.jrides.state.ride.RideManager;
+import org.bukkit.command.Command;
+
+import java.util.Collections;
+import java.util.List;
+
+public class RideCounterMapCommandExecutor extends BaseCommandExecutor {
+ private final RideManager rideManager;
+ private final RideCounterMapFactory rideCounterMapFactory;
+
+ protected RideCounterMapCommandExecutor() {
+ super(1);
+ this.rideManager = ServiceProvider.getSingleton(RideManager.class);
+ this.rideCounterMapFactory = ServiceProvider.getSingleton(RideCounterMapFactory.class);
+ }
+
+ @Override
+ public String getHelpMessageForParent() {
+ return "/jrides " + getCommand() + " ";
+ }
+
+ @Override
+ public boolean onCommand(MessageAgent messageAgent, Command command, String arg, String[] args, CommandContext context) {
+ if(!messageAgent.isPlayer()){
+ languageFile.sendMessage(messageAgent, LanguageFileField.ERROR_PLAYER_COMMAND_ONLY_MESSAGE);
+ return true;
+ }
+
+ if(args.length != 3){
+ languageFile.sendMessage(messageAgent, getHelpMessageForSelf());
+ return true;
+ }
+
+ String rideIdentifier = args[1];
+ if(rideIdentifier.equalsIgnoreCase("")){
+ languageFile.sendMessage(messageAgent, getHelpMessageForSelf());
+ return true;
+ }
+
+ String boardIdentifier = args[2];
+ if(boardIdentifier.equalsIgnoreCase("")){
+ languageFile.sendMessage(messageAgent, getHelpMessageForSelf());
+ return true;
+ }
+
+ RideHandle rideHandle = ServiceProvider.getSingleton(RideManager.class).getRideHandle(rideIdentifier);
+ if(rideHandle == null){
+ languageFile.sendMessage(messageAgent, "Ride '" + rideIdentifier + "' not found", FeedbackType.CONFLICT);
+ return true;
+ }
+
+ Player player = messageAgent.getPlayer(playerManager);
+ rideCounterMapFactory.giveMap(player, rideHandle, boardIdentifier);
+
+ return true;
+ }
+
+ @Override
+ public String getHelpMessageForSelf() {
+ return getHelpMessageForParent();
+ }
+
+ @Override
+ public String getCommand() {
+ return "ridecountermap";
+ }
+
+ @Override
+ public String getPermission() {
+ return Permissions.COMMAND_ELEVATED_RIDE_COUNTER_MAP;
+ }
+
+ @Override
+ public List onTabComplete(MessageAgent messageAgent, Command command, String s, String[] strings) {
+ if(!messageAgent.hasPermission(getPermission())) return Collections.emptyList();
+
+ if(strings.length == depth+1)
+ return rideManager.getRideIdentifiers();
+
+ if(strings.length == depth+2)
+ return rideCounterMapFactory.getBoardIdentifiersByRide(strings[depth+1]);
+
+ return null;
+ }
+
+
+}
diff --git a/src/main/java/com/jverbruggen/jrides/command/RideOverviewMapCommandExecutor.java b/src/main/java/com/jverbruggen/jrides/command/RideOverviewMapCommandExecutor.java
new file mode 100644
index 00000000..4132f441
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/command/RideOverviewMapCommandExecutor.java
@@ -0,0 +1,92 @@
+package com.jverbruggen.jrides.command;
+
+import com.jverbruggen.jrides.animator.coaster.CoasterHandle;
+import com.jverbruggen.jrides.animator.RideHandle;
+import com.jverbruggen.jrides.command.context.CommandContext;
+import com.jverbruggen.jrides.common.permissions.Permissions;
+import com.jverbruggen.jrides.language.FeedbackType;
+import com.jverbruggen.jrides.language.LanguageFileField;
+import com.jverbruggen.jrides.models.entity.Player;
+import com.jverbruggen.jrides.models.entity.agent.MessageAgent;
+import com.jverbruggen.jrides.models.map.rideoverview.RideOverviewMapFactory;
+import com.jverbruggen.jrides.serviceprovider.ServiceProvider;
+import com.jverbruggen.jrides.state.ride.RideManager;
+import org.bukkit.command.Command;
+
+import java.util.Collections;
+import java.util.List;
+
+public class RideOverviewMapCommandExecutor extends BaseCommandExecutor {
+ private final RideManager rideManager;
+ private final RideOverviewMapFactory rideOverviewMapFactory;
+
+ protected RideOverviewMapCommandExecutor() {
+ super(1);
+ this.rideManager = ServiceProvider.getSingleton(RideManager.class);
+ this.rideOverviewMapFactory = ServiceProvider.getSingleton(RideOverviewMapFactory.class);
+ }
+
+ @Override
+ public String getHelpMessageForParent() {
+ return "/jrides " + getCommand() + " ";
+ }
+
+ @Override
+ public boolean onCommand(MessageAgent messageAgent, Command command, String arg, String[] args, CommandContext context) {
+ if(!messageAgent.isPlayer()){
+ languageFile.sendMessage(messageAgent, LanguageFileField.ERROR_PLAYER_COMMAND_ONLY_MESSAGE);
+ return true;
+ }
+
+ if(args.length != 2){
+ languageFile.sendMessage(messageAgent, getHelpMessageForSelf());
+ return true;
+ }
+
+ String identifier = args[1];
+ if(identifier.equalsIgnoreCase("")){
+ languageFile.sendMessage(messageAgent, getHelpMessageForSelf());
+ return true;
+ }
+
+ RideHandle rideHandle = ServiceProvider.getSingleton(RideManager.class).getRideHandle(identifier);
+ if(rideHandle == null){
+ languageFile.sendMessage(messageAgent, "Ride '" + identifier + "' not found", FeedbackType.CONFLICT);
+ return true;
+ }
+
+ if(!(rideHandle instanceof CoasterHandle)){
+ languageFile.sendMessage(messageAgent, "Ride has no track", FeedbackType.CONFLICT);
+ return true;
+ }
+
+ Player player = messageAgent.getPlayer(playerManager);
+ rideOverviewMapFactory.giveMap(player, ((CoasterHandle) rideHandle));
+
+ return true;
+ }
+
+ @Override
+ public String getHelpMessageForSelf() {
+ return getHelpMessageForParent();
+ }
+
+ @Override
+ public String getCommand() {
+ return "rideoverview";
+ }
+
+ @Override
+ public String getPermission() {
+ return Permissions.COMMAND_ELEVATED_RIDE_OVERVIEW;
+ }
+
+ @Override
+ public List onTabComplete(MessageAgent messageAgent, Command command, String s, String[] strings) {
+ if(!messageAgent.hasPermission(getPermission())) return Collections.emptyList();
+
+ if(strings.length == depth+1)
+ return rideManager.getRideIdentifiers();
+ return null;
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/command/RidesCommandExecutor.java b/src/main/java/com/jverbruggen/jrides/command/RidesCommandExecutor.java
new file mode 100644
index 00000000..527f96b8
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/command/RidesCommandExecutor.java
@@ -0,0 +1,76 @@
+package com.jverbruggen.jrides.command;
+
+import com.jverbruggen.jrides.command.context.CommandContext;
+import com.jverbruggen.jrides.common.MenuSessionManager;
+import com.jverbruggen.jrides.common.permissions.Permissions;
+import com.jverbruggen.jrides.language.LanguageFileField;
+import com.jverbruggen.jrides.models.entity.Player;
+import com.jverbruggen.jrides.models.entity.agent.MessageAgent;
+import com.jverbruggen.jrides.models.menu.Menu;
+import com.jverbruggen.jrides.serviceprovider.ServiceProvider;
+import com.jverbruggen.jrides.state.ride.menu.RideOverviewMenuFactory;
+import org.bukkit.command.Command;
+import org.bukkit.inventory.Inventory;
+
+import java.util.Collections;
+import java.util.List;
+
+public class RidesCommandExecutor extends BaseCommandExecutor {
+ private final RideOverviewMenuFactory rideOverviewMenuFactory;
+ private final MenuSessionManager menuSessionManager;
+
+ protected RidesCommandExecutor() {
+ super(1);
+ this.rideOverviewMenuFactory = ServiceProvider.getSingleton(RideOverviewMenuFactory.class);
+ this.menuSessionManager = ServiceProvider.getSingleton(MenuSessionManager.class);
+ }
+
+ @Override
+ public String getHelpMessageForParent() {
+ return "/jrides " + getCommand();
+ }
+
+ @Override
+ public boolean onCommand(MessageAgent messageAgent, Command command, String arg, String[] args, CommandContext context) {
+ if(!messageAgent.isPlayer()){
+ languageFile.sendMessage(messageAgent, LanguageFileField.ERROR_PLAYER_COMMAND_ONLY_MESSAGE);
+ return true;
+ }
+
+ if(args.length != 1){
+ languageFile.sendMessage(messageAgent, getHelpMessageForSelf());
+ return true;
+ }
+
+ Player player = messageAgent.getPlayer(playerManager);
+
+ Menu menu = rideOverviewMenuFactory.getRideOverviewMenu();
+ Inventory inventory = menu.getInventoryFor(player);
+ menuSessionManager.addOpenMenu(player, menu, inventory);
+ player.getBukkitPlayer().openInventory(inventory);
+
+ return true;
+ }
+
+ @Override
+ public String getHelpMessageForSelf() {
+ return getHelpMessageForParent();
+ }
+
+ @Override
+ public String getCommand() {
+ return "rides";
+ }
+
+ @Override
+ public String getPermission() {
+ return Permissions.COMMAND_RIDES_MENU;
+ }
+
+ @Override
+ public List onTabComplete(MessageAgent messageAgent, Command command, String s, String[] strings) {
+ if(!messageAgent.hasPermission(getPermission())) return Collections.emptyList();
+
+ return null;
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/command/VisualizeCommandExecutor.java b/src/main/java/com/jverbruggen/jrides/command/VisualizeCommandExecutor.java
new file mode 100644
index 00000000..d32292f8
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/command/VisualizeCommandExecutor.java
@@ -0,0 +1,108 @@
+package com.jverbruggen.jrides.command;
+
+import com.jverbruggen.jrides.animator.coaster.CoasterHandle;
+import com.jverbruggen.jrides.animator.RideHandle;
+import com.jverbruggen.jrides.animator.coaster.tool.ParticleTrackVisualisationTool;
+import com.jverbruggen.jrides.command.context.CommandContext;
+import com.jverbruggen.jrides.common.permissions.Permissions;
+import com.jverbruggen.jrides.language.FeedbackType;
+import com.jverbruggen.jrides.language.LanguageFileField;
+import com.jverbruggen.jrides.language.LanguageFileTag;
+import com.jverbruggen.jrides.models.entity.Player;
+import com.jverbruggen.jrides.models.entity.agent.MessageAgent;
+import com.jverbruggen.jrides.serviceprovider.ServiceProvider;
+import com.jverbruggen.jrides.state.ride.RideManager;
+import org.bukkit.command.Command;
+
+import java.util.Collections;
+import java.util.List;
+
+public class VisualizeCommandExecutor extends BaseCommandExecutor {
+ private final RideManager rideManager;
+
+ protected VisualizeCommandExecutor() {
+ super(1);
+ this.rideManager = ServiceProvider.getSingleton(RideManager.class);
+ }
+
+ @Override
+ public String getHelpMessageForParent() {
+ return "/jrides visualize ";
+ }
+
+ @Override
+ public boolean onCommand(MessageAgent messageAgent, Command command, String arg, String[] args, CommandContext context) {
+ if(!messageAgent.isPlayer()){
+ languageFile.sendMessage(messageAgent, LanguageFileField.ERROR_PLAYER_COMMAND_ONLY_MESSAGE);
+ return true;
+ }
+
+ if(args.length != 2){
+ languageFile.sendMessage(messageAgent, getHelpMessageForSelf());
+ return true;
+ }
+
+ String identifier = args[1];
+ if(identifier.equalsIgnoreCase("")){
+ languageFile.sendMessage(messageAgent, getHelpMessageForSelf());
+ return true;
+ }
+
+ RideHandle rideHandle = ServiceProvider.getSingleton(RideManager.class).getRideHandle(identifier);
+ if(rideHandle == null){
+ languageFile.sendMessage(messageAgent, "Ride '" + identifier + "' not found", FeedbackType.CONFLICT);
+ return true;
+ }
+
+ if(!(rideHandle instanceof CoasterHandle coasterHandle)){
+ languageFile.sendMessage(messageAgent, "Ride cannot be visualized: not a coaster", FeedbackType.CONFLICT);
+ return true;
+ }
+
+ ParticleTrackVisualisationTool tool = coasterHandle.getVisualisationTool();
+ if(tool == null){
+ languageFile.sendMessage(messageAgent, "Could not visualize track", FeedbackType.CONFLICT);
+ return true;
+ }
+
+ String actualIdentifier = coasterHandle.getRide().getIdentifier();
+ Player player = messageAgent.getPlayer(playerManager);
+ if(tool.isViewer(player)){
+ tool.removeViewer(player);
+
+ languageFile.sendMessage(player, LanguageFileField.COMMAND_VISUALIZE_REMOVED_VIEWER,
+ b -> b.add(LanguageFileTag.rideIdentifier, actualIdentifier));
+ }else{
+ tool.addViewer(player);
+
+ languageFile.sendMessage(player, LanguageFileField.COMMAND_VISUALIZE_ADDED_VIEWER,
+ b -> b.add(LanguageFileTag.rideIdentifier, actualIdentifier));
+ }
+
+ return true;
+ }
+
+ @Override
+ public String getHelpMessageForSelf() {
+ return getHelpMessageForParent();
+ }
+
+ @Override
+ public String getCommand() {
+ return "visualize";
+ }
+
+ @Override
+ public String getPermission() {
+ return Permissions.COMMAND_ELEVATED_VISUALIZE;
+ }
+
+ @Override
+ public List onTabComplete(MessageAgent messageAgent, Command command, String s, String[] strings) {
+ if(!messageAgent.hasPermission(getPermission())) return Collections.emptyList();
+
+ if(strings.length == depth+1)
+ return rideManager.getRideIdentifiers();
+ return null;
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/command/WarpCommandExecutor.java b/src/main/java/com/jverbruggen/jrides/command/WarpCommandExecutor.java
new file mode 100644
index 00000000..c9a1cc56
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/command/WarpCommandExecutor.java
@@ -0,0 +1,87 @@
+package com.jverbruggen.jrides.command;
+
+import com.jverbruggen.jrides.animator.RideHandle;
+import com.jverbruggen.jrides.command.context.CommandContext;
+import com.jverbruggen.jrides.common.permissions.Permissions;
+import com.jverbruggen.jrides.event.player.PlayerTeleportByJRidesEvent;
+import com.jverbruggen.jrides.language.FeedbackType;
+import com.jverbruggen.jrides.language.LanguageFileField;
+import com.jverbruggen.jrides.language.LanguageFileTag;
+import com.jverbruggen.jrides.models.entity.Player;
+import com.jverbruggen.jrides.models.entity.agent.MessageAgent;
+import com.jverbruggen.jrides.serviceprovider.ServiceProvider;
+import com.jverbruggen.jrides.state.ride.RideManager;
+import org.bukkit.command.Command;
+
+import java.util.Collections;
+import java.util.List;
+
+public class WarpCommandExecutor extends BaseCommandExecutor {
+ private final RideManager rideManager;
+
+ protected WarpCommandExecutor() {
+ super(1);
+ this.rideManager = ServiceProvider.getSingleton(RideManager.class);
+ }
+
+ @Override
+ public String getHelpMessageForParent() {
+ return "/jrides warp ";
+ }
+
+ @Override
+ public boolean onCommand(MessageAgent messageAgent, Command command, String arg, String[] args, CommandContext context) {
+ if(!messageAgent.isPlayer()){
+ languageFile.sendMessage(messageAgent, LanguageFileField.ERROR_PLAYER_COMMAND_ONLY_MESSAGE);
+ return true;
+ }
+
+ if(args.length != 2){
+ languageFile.sendMessage(messageAgent, getHelpMessageForSelf());
+ return true;
+ }
+
+ String identifier = args[1];
+
+ Player player = messageAgent.getPlayer(playerManager);
+ if(!player.getBukkitPlayer().hasPermission(Permissions.COMMAND_RIDE_WARP)){
+ languageFile.sendMessage(player, LanguageFileField.ERROR_GENERAL_NO_PERMISSION_MESSAGE);
+ return false;
+ }
+
+ RideHandle rideHandle = ServiceProvider.getSingleton(RideManager.class).getRideHandle(identifier);
+ if(rideHandle == null){
+ languageFile.sendMessage(messageAgent, "Ride '" + identifier + "' not found", FeedbackType.CONFLICT);
+ return true;
+ }
+ PlayerTeleportByJRidesEvent.sendEvent(player, rideHandle.getRide().getWarpLocation(), false);
+
+ player.teleport(rideHandle.getRide().getWarpLocation());
+ languageFile.sendMessage(player, LanguageFileField.NOTIFICATION_WARPED, b -> b.add(LanguageFileTag.rideDisplayName, rideHandle.getRide().getDisplayName()));
+ return true;
+ }
+
+ @Override
+ public String getHelpMessageForSelf() {
+ return getHelpMessageForParent();
+ }
+
+ @Override
+ public String getCommand() {
+ return "warp";
+ }
+
+ @Override
+ public String getPermission() {
+ return Permissions.COMMAND_RIDE_WARP;
+ }
+
+ @Override
+ public List onTabComplete(MessageAgent messageAgent, Command command, String s, String[] strings) {
+ if(!messageAgent.hasPermission(getPermission())) return Collections.emptyList();
+
+ if(strings.length == depth+1)
+ return rideManager.getRideIdentifiers();
+ return null;
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/command/context/CommandContext.java b/src/main/java/com/jverbruggen/jrides/command/context/CommandContext.java
new file mode 100644
index 00000000..3b50aa52
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/command/context/CommandContext.java
@@ -0,0 +1,24 @@
+package com.jverbruggen.jrides.command.context;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@SuppressWarnings("rawtypes")
+public class CommandContext {
+ private final Map objects;
+
+ public CommandContext() {
+ this.objects = new HashMap<>();
+ }
+
+ public CommandContext add(Class clazz, Object object){
+ objects.put(clazz, object);
+ return this;
+ }
+
+ public T get(Class clazz){
+ Object object = objects.get(clazz);
+ if(!clazz.isInstance(object)) throw new RuntimeException("Non-matching type in command context for type " + clazz.getTypeName());
+ return clazz.cast(object);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/command/control/ControlAdminMenuCommandExecutor.java b/src/main/java/com/jverbruggen/jrides/command/control/ControlAdminMenuCommandExecutor.java
new file mode 100644
index 00000000..68621064
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/command/control/ControlAdminMenuCommandExecutor.java
@@ -0,0 +1,64 @@
+package com.jverbruggen.jrides.command.control;
+
+import com.jverbruggen.jrides.animator.RideHandle;
+import com.jverbruggen.jrides.command.BaseCommandExecutor;
+import com.jverbruggen.jrides.command.context.CommandContext;
+import com.jverbruggen.jrides.common.MenuSessionManager;
+import com.jverbruggen.jrides.common.permissions.Permissions;
+import com.jverbruggen.jrides.control.uiinterface.menu.RideControlMenuFactory;
+import com.jverbruggen.jrides.language.FeedbackType;
+import com.jverbruggen.jrides.language.LanguageFileField;
+import com.jverbruggen.jrides.models.entity.Player;
+import com.jverbruggen.jrides.models.entity.agent.MessageAgent;
+import com.jverbruggen.jrides.models.menu.Menu;
+import com.jverbruggen.jrides.serviceprovider.ServiceProvider;
+import org.bukkit.command.Command;
+import org.bukkit.inventory.Inventory;
+
+public class ControlAdminMenuCommandExecutor extends BaseCommandExecutor {
+ private final RideControlMenuFactory rideControlMenuFactory;
+ private final MenuSessionManager menuSessionManager;
+
+ protected ControlAdminMenuCommandExecutor(int depth) {
+ super(depth);
+ this.rideControlMenuFactory = ServiceProvider.getSingleton(RideControlMenuFactory.class);
+ this.menuSessionManager = ServiceProvider.getSingleton(MenuSessionManager.class);
+ }
+
+ @Override
+ public boolean onCommand(MessageAgent messageAgent, Command command, String s, String[] args, CommandContext commandContext) {
+ if(!messageAgent.isPlayer()){
+ languageFile.sendMessage(messageAgent, LanguageFileField.ERROR_PLAYER_COMMAND_ONLY_MESSAGE, FeedbackType.CONFLICT);
+ return true;
+ }
+
+ Player player = messageAgent.getPlayer(playerManager);
+
+ RideHandle rideHandle = commandContext.get(RideHandle.class);
+ Menu rideControlMenu = rideControlMenuFactory.getAdminMenu(rideHandle.getRideController());
+ if(rideControlMenu == null){
+ languageFile.sendMessage(player, LanguageFileField.ERROR_RIDE_CONTROL_MENU_NOT_FOUND, FeedbackType.CONFLICT);
+ return true;
+ }
+ Inventory inventory = rideControlMenu.getInventoryFor(player);
+
+ menuSessionManager.addOpenMenu(player, rideControlMenu, inventory);
+ player.getBukkitPlayer().openInventory(inventory);
+ return true;
+ }
+
+ @Override
+ public String getCommand() {
+ return "admin";
+ }
+
+ @Override
+ public String getPermission() {
+ return Permissions.COMMAND_ELEVATED_ADMIN_MENU;
+ }
+
+ @Override
+ public String getHelpMessageForParent() {
+ return "/jrides control admin";
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/command/control/ControlCommandExecutor.java b/src/main/java/com/jverbruggen/jrides/command/control/ControlCommandExecutor.java
new file mode 100644
index 00000000..f497ddba
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/command/control/ControlCommandExecutor.java
@@ -0,0 +1,76 @@
+package com.jverbruggen.jrides.command.control;
+
+import com.jverbruggen.jrides.animator.RideHandle;
+import com.jverbruggen.jrides.command.BaseCommandExecutor;
+import com.jverbruggen.jrides.command.context.CommandContext;
+import com.jverbruggen.jrides.common.permissions.Permissions;
+import com.jverbruggen.jrides.language.FeedbackType;
+import com.jverbruggen.jrides.models.entity.agent.MessageAgent;
+import com.jverbruggen.jrides.serviceprovider.ServiceProvider;
+import com.jverbruggen.jrides.state.ride.RideManager;
+import org.bukkit.command.Command;
+
+import java.util.Collections;
+import java.util.List;
+
+public class ControlCommandExecutor extends BaseCommandExecutor {
+ private final RideManager rideManager;
+
+ public ControlCommandExecutor() {
+ super(1);
+ rideManager = ServiceProvider.getSingleton(RideManager.class);
+
+ registerSubCommand(new ControlMenuCommandExecutor(depth+2));
+ registerSubCommand(new ControlAdminMenuCommandExecutor(depth+2));
+ registerSubCommand(new ControlDispatchCommandExecutor(depth+2));
+ }
+
+ @Override
+ public boolean onCommand(MessageAgent messageAgent, Command command, String arg, String[] args, CommandContext commandContext) {
+ if(args.length <= 2){
+ languageFile.sendMultilineMessage(messageAgent, getHelpMessageForSelf());
+ return true;
+ }
+
+ String identifier = args[1];
+ String subCommand = args[2];
+
+ RideHandle rideHandle = rideManager.getRideHandle(identifier);
+ if(rideHandle == null){
+ languageFile.sendMessage(messageAgent, "Ride '" + identifier + "' not found", FeedbackType.CONFLICT);
+ return true;
+ }
+
+ commandContext.add(RideHandle.class, rideHandle);
+
+ runSubCommand(messageAgent, command, arg, args, subCommand, commandContext);
+ return true;
+ }
+
+ @Override
+ public String getCommand() {
+ return "control";
+ }
+
+ @Override
+ public String getPermission() {
+ return Permissions.COMMAND_CONTROL;
+ }
+
+ @Override
+ public String getHelpMessageForParent() {
+ return "/jrides control";
+ }
+
+ @Override
+ public List onTabComplete(MessageAgent messageAgent, Command command, String s, String[] strings) {
+ if(!messageAgent.hasPermission(getPermission())) return Collections.emptyList();
+
+ if(strings.length == depth+1){
+ return rideManager.getRideIdentifiers();
+ }else if(strings.length == depth+2){
+ return getCommandSuggestions(messageAgent);
+ }
+ return null;
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/command/control/ControlDispatchCommandExecutor.java b/src/main/java/com/jverbruggen/jrides/command/control/ControlDispatchCommandExecutor.java
new file mode 100644
index 00000000..d3ba21aa
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/command/control/ControlDispatchCommandExecutor.java
@@ -0,0 +1,53 @@
+package com.jverbruggen.jrides.command.control;
+
+import com.jverbruggen.jrides.animator.RideHandle;
+import com.jverbruggen.jrides.command.BaseCommandExecutor;
+import com.jverbruggen.jrides.command.context.CommandContext;
+import com.jverbruggen.jrides.common.permissions.Permissions;
+import com.jverbruggen.jrides.control.controller.RideController;
+import com.jverbruggen.jrides.control.trigger.SimpleDispatchTrigger;
+import com.jverbruggen.jrides.language.FeedbackType;
+import com.jverbruggen.jrides.language.LanguageFileField;
+import com.jverbruggen.jrides.language.LanguageFileTag;
+import com.jverbruggen.jrides.models.entity.agent.MessageAgent;
+import org.bukkit.command.Command;
+
+public class ControlDispatchCommandExecutor extends BaseCommandExecutor {
+ protected ControlDispatchCommandExecutor(int depth) {
+ super(depth);
+ }
+
+ @Override
+ public boolean onCommand(MessageAgent messageAgent, Command command, String s, String[] args, CommandContext commandContext) {
+ RideHandle rideHandle = commandContext.get(RideHandle.class);
+ RideController rideController = rideHandle.getRideController();
+ if(rideController == null){
+ languageFile.sendMessage(messageAgent, LanguageFileField.ERROR_RIDE_CONTROL_MENU_NOT_FOUND, FeedbackType.CONFLICT);
+ return true;
+ }
+
+ SimpleDispatchTrigger dispatchTrigger = rideController.getTriggerContext().getDispatchTrigger();
+
+ boolean dispatched = dispatchTrigger.execute(messageAgent);
+ if(dispatched)
+ languageFile.sendMessage(messageAgent, LanguageFileField.COMMAND_RIDE_DISPATCHED_MESSAGE,
+ b -> b.add(LanguageFileTag.rideDisplayName, rideHandle.getRide().getDisplayName()));
+
+ return true;
+ }
+
+ @Override
+ public String getCommand() {
+ return "dispatch";
+ }
+
+ @Override
+ public String getPermission() {
+ return Permissions.COMMAND_CONTROL_DISPATCH;
+ }
+
+ @Override
+ public String getHelpMessageForParent() {
+ return "/jrides control dispatch";
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/command/control/ControlMenuCommandExecutor.java b/src/main/java/com/jverbruggen/jrides/command/control/ControlMenuCommandExecutor.java
new file mode 100644
index 00000000..cba0f27b
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/command/control/ControlMenuCommandExecutor.java
@@ -0,0 +1,61 @@
+package com.jverbruggen.jrides.command.control;
+
+import com.jverbruggen.jrides.animator.RideHandle;
+import com.jverbruggen.jrides.command.BaseCommandExecutor;
+import com.jverbruggen.jrides.command.context.CommandContext;
+import com.jverbruggen.jrides.common.MenuSessionManager;
+import com.jverbruggen.jrides.common.permissions.Permissions;
+import com.jverbruggen.jrides.language.FeedbackType;
+import com.jverbruggen.jrides.language.LanguageFileField;
+import com.jverbruggen.jrides.models.entity.Player;
+import com.jverbruggen.jrides.models.entity.agent.MessageAgent;
+import com.jverbruggen.jrides.models.menu.Menu;
+import com.jverbruggen.jrides.serviceprovider.ServiceProvider;
+import org.bukkit.command.Command;
+import org.bukkit.inventory.Inventory;
+
+public class ControlMenuCommandExecutor extends BaseCommandExecutor {
+ private final MenuSessionManager menuSessionManager;
+
+ protected ControlMenuCommandExecutor(int depth) {
+ super(depth);
+ this.menuSessionManager = ServiceProvider.getSingleton(MenuSessionManager.class);
+ }
+
+ @Override
+ public boolean onCommand(MessageAgent messageAgent, Command command, String s, String[] args, CommandContext commandContext) {
+ if(!messageAgent.isPlayer()){
+ languageFile.sendMessage(messageAgent, LanguageFileField.ERROR_PLAYER_COMMAND_ONLY_MESSAGE, FeedbackType.CONFLICT);
+ return true;
+ }
+
+ Player player = messageAgent.getPlayer(playerManager);
+
+ RideHandle rideHandle = commandContext.get(RideHandle.class);
+ Menu rideControlMenu = rideHandle.getRideControlMenu();
+ if(rideControlMenu == null){
+ languageFile.sendMessage(messageAgent, LanguageFileField.ERROR_RIDE_CONTROL_MENU_NOT_FOUND, FeedbackType.CONFLICT);
+ return true;
+ }
+ Inventory inventory = rideControlMenu.getInventoryFor(player);
+
+ menuSessionManager.addOpenMenu(player, rideControlMenu, inventory);
+ player.getBukkitPlayer().openInventory(inventory);
+ return true;
+ }
+
+ @Override
+ public String getCommand() {
+ return "menu";
+ }
+
+ @Override
+ public String getPermission() {
+ return Permissions.COMMAND_CONTROL_MENU;
+ }
+
+ @Override
+ public String getHelpMessageForParent() {
+ return "/jrides control menu";
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/common/MenuSessionManager.java b/src/main/java/com/jverbruggen/jrides/common/MenuSessionManager.java
new file mode 100644
index 00000000..c95e428a
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/common/MenuSessionManager.java
@@ -0,0 +1,48 @@
+package com.jverbruggen.jrides.common;
+
+import com.jverbruggen.jrides.api.JRidesPlayer;
+import com.jverbruggen.jrides.models.menu.Menu;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.Inventory;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class MenuSessionManager {
+ private final Map openMenus;
+
+ public MenuSessionManager(){
+ this.openMenus = new HashMap<>();
+ }
+
+ public void addOpenMenu(JRidesPlayer player, Menu menu, Inventory inventory){
+ menu.addSession(player, inventory);
+ openMenus.put(player, menu);
+ menu.sendUpdate();
+ }
+
+ public Menu getOpenMenu(JRidesPlayer player){
+ return openMenus.get(player);
+ }
+
+ public void removeOpenMenu(JRidesPlayer player){
+ Menu menu = openMenus.get(player);
+ if(menu == null) return;
+
+ menu.removeSession(player);
+ openMenus.remove(player);
+ }
+
+ public boolean hasOpenMenu(JRidesPlayer player){
+ return openMenus.containsKey(player);
+ }
+
+ public void closeAllOpenMenus(){
+ for(Map.Entry entry : openMenus.entrySet()){
+ JRidesPlayer player = entry.getKey();
+ Player bukkitPlayer = player.getBukkitPlayer();
+ bukkitPlayer.closeInventory();
+ removeOpenMenu(player);
+ }
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/common/Reason.java b/src/main/java/com/jverbruggen/jrides/common/Reason.java
new file mode 100644
index 00000000..6d4d83d5
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/common/Reason.java
@@ -0,0 +1,21 @@
+package com.jverbruggen.jrides.common;
+
+import com.jverbruggen.jrides.language.FeedbackType;
+import com.jverbruggen.jrides.language.LanguageFile;
+import com.jverbruggen.jrides.models.entity.agent.MessageAgent;
+import com.jverbruggen.jrides.serviceprovider.ServiceProvider;
+
+public record Reason(String description, FeedbackType feedbackType) {
+ public void sendAsMessage(MessageAgent messageAgent){
+ LanguageFile languageFile = ServiceProvider.getSingleton(LanguageFile.class);
+ languageFile.sendMessage(messageAgent, description);
+ }
+
+ public static Reason simple(String description){
+ return new Reason(description, FeedbackType.INFO);
+ }
+
+ public static Reason conflict(String description){
+ return new Reason(description, FeedbackType.CONFLICT);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/common/Result.java b/src/main/java/com/jverbruggen/jrides/common/Result.java
new file mode 100644
index 00000000..513449d5
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/common/Result.java
@@ -0,0 +1,47 @@
+package com.jverbruggen.jrides.common;
+
+import com.jverbruggen.jrides.models.entity.agent.MessageAgent;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public record Result(boolean ok, List reasons) {
+ public void sendMessageTo(MessageAgent messageAgent){
+ for(Reason reason : reasons){
+ reason.sendAsMessage(messageAgent);
+ }
+ }
+
+ public void concat(Result other){
+ reasons.addAll(other.reasons);
+ }
+
+ public static Result isOk(){
+ return new Result(true, new ArrayList<>());
+ }
+
+ public static Result isNotOk() {
+ return new Result(false, new ArrayList<>());
+ }
+
+ public static Result isNotOk(String title){
+ return isNotOk(title, List.of());
+ }
+
+ public static Result isNotOk(List reasons){
+ return isNotOk(null, reasons);
+ }
+
+ public static Result isNotOk(String title, List reasons){
+ List reasonList = new ArrayList<>();
+
+ if(title != null)
+ reasonList.add(Reason.conflict(title));
+
+ for(String reasonString : reasons){
+ reasonList.add(Reason.simple(reasonString));
+ }
+
+ return new Result(false, reasonList);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/common/Sync.java b/src/main/java/com/jverbruggen/jrides/common/Sync.java
new file mode 100644
index 00000000..3ead454d
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/common/Sync.java
@@ -0,0 +1,22 @@
+package com.jverbruggen.jrides.common;
+
+import com.jverbruggen.jrides.JRidesPlugin;
+import org.bukkit.Bukkit;
+
+public class Sync {
+ public static void runSynced(Runnable runnable){
+ Bukkit.getScheduler().runTask(JRidesPlugin.getBukkitPlugin(), runnable);
+ }
+
+ public static int runRepeated(Runnable runnable, long interval){
+ return Bukkit.getScheduler().runTaskTimer(JRidesPlugin.getBukkitPlugin(), runnable, interval, interval).getTaskId();
+ }
+
+ public static void stopTask(int taskId){
+ Bukkit.getScheduler().cancelTask(taskId);
+ }
+
+ public static void runAfter(Runnable runnable, long afterTicks) {
+ Bukkit.getScheduler().runTaskLater(JRidesPlugin.getBukkitPlugin(), runnable, afterTicks);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/common/permissions/Permissions.java b/src/main/java/com/jverbruggen/jrides/common/permissions/Permissions.java
new file mode 100644
index 00000000..3793ecf3
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/common/permissions/Permissions.java
@@ -0,0 +1,31 @@
+package com.jverbruggen.jrides.common.permissions;
+
+public class Permissions {
+ /// Default
+ public static final String RIDE_ENTER = "jrides.default.ride_enter"; // Allow entering a ride
+ public static final String RIDE_WARP = "jrides.default.warp"; // Allow warping (through menu)
+ public static final String COMMAND_RIDE_WARP = "jrides.command.default.warp"; // Allow warping (through command)
+ public static final String COMMAND_RIDES_MENU = "jrides.command.default.rides"; // Allow opening '/jrides rides' menu
+
+ /// Operator
+ public static final String CABIN_OPERATE = "jrides.operator.cabin_operate"; // Allow to operate in a ride cabin
+ public static final String COMMAND_CONTROL = "jrides.command.operator"; // Allow '/jrides control' command
+ public static final String COMMAND_CONTROL_DISPATCH = "jrides.command.operator.dispatch"; // Allow '/jrides control dispatch' command
+ public static final String COMMAND_CONTROL_MENU = "jrides.command.operator.menu"; // Allow '/jrides control menu' command
+
+ /// Elevated (admin)
+ public static final String ELEVATED_RESTRAINT_OVERRIDE = "jrides.elevated.restraint_override"; // Allow to override restraint lock
+ public static final String ELEVATED_OPERATOR_OVERRIDE = "jrides.elevated.operator_override"; // Allow to take over an operator in a cabin
+ public static final String ELEVATED_RIDE_CLOSED_ENTER_OVERRIDE = "jrides.elevated.closed_ride_enter_override"; // Allow to override closed ride entering
+ public static final String ELEVATED_RIDE_OPEN_STATE_CHANGE = "jrides.elevated.open_state_change"; // Allow to open or close a ride
+ public static final String COMMAND_ELEVATED_BASE = "jrides.command.elevated"; // Base for elevated commands (for admins)
+ public static final String COMMAND_ELEVATED_ADMIN_MENU = "jrides.command.elevated.admin_menu"; // Allow to open ride admin menu
+ public static final String COMMAND_ELEVATED_RIDE_OVERVIEW = "jrides.command.elevated.ride_overview"; // Allow for generating a ride overview map
+ public static final String COMMAND_ELEVATED_RIDE_COUNTER_MAP = "jrides.command.elevated.ride_counter_map"; // Allow for generating a ride counter map
+ public static final String COMMAND_ELEVATED_BLOCK_SECTION = "jrides.command.elevated.block_section"; // Allow for getting block section occupation message (debug)
+ public static final String COMMAND_ELEVATED_VISUALIZE = "jrides.command.elevated.visualize"; // Allow to visualize a coaster spline (debug)
+
+ /// Debug
+ public static final String ELEVATED_STATUS_INSPECTION = "jrides.elevated.status_inspection"; // Allow to inspect coaster frames (debug)
+ public static final String ELEVATED_DISPATCH_PROBLEMS_DEBUG = "jrides.elevated.dispatch_problems_debug";
+}
diff --git a/src/main/java/com/jverbruggen/jrides/common/startup/StartMessage.java b/src/main/java/com/jverbruggen/jrides/common/startup/StartMessage.java
new file mode 100644
index 00000000..87ddd764
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/common/startup/StartMessage.java
@@ -0,0 +1,36 @@
+package com.jverbruggen.jrides.common.startup;
+
+import com.jverbruggen.jrides.JRidesPlugin;
+import com.jverbruggen.jrides.serviceprovider.ServiceProvider;
+
+import java.util.List;
+import java.util.logging.Logger;
+
+public class StartMessage {
+ private static String splashLogo = """
+ _ _ _ \s
+ (_)_ __(_) __| | ___ ___\s
+ | | '__| |/ _` |/ _ \\/ __|
+ | | | | | (_| | __/\\__ \\
+ _/ |_| |_|\\__,_|\\___||___/
+ |__/ \s
+ """;
+ private static String enabled = " E N A B L E D";
+ private static String disabled = " D I S A B L E D";
+
+ public static void sendEnabledMessage(){
+ Logger logger = ServiceProvider.getSingleton(Logger.class);
+ sendSplash(logger);
+ logger.info("\u001b[32m" + enabled + " - " + JRidesPlugin.getVersion() + "\u001b[0m");
+ }
+
+ public static void sendDisabledMessage(){
+ Logger logger = ServiceProvider.getSingleton(Logger.class);
+ sendSplash(logger);
+ logger.info("\u001b[31m" + disabled + " - " + JRidesPlugin.getVersion() + "\u001b[0m");
+ }
+
+ private static void sendSplash(Logger logger){
+ List.of(splashLogo.split("\n")).forEach(line -> logger.info("\u001b[33m" + line + "\u001b[0m"));
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/config/ConfigManager.java b/src/main/java/com/jverbruggen/jrides/config/ConfigManager.java
new file mode 100644
index 00000000..523056f7
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/config/ConfigManager.java
@@ -0,0 +1,248 @@
+package com.jverbruggen.jrides.config;
+
+import com.jverbruggen.jrides.JRidesPlugin;
+import com.jverbruggen.jrides.config.coaster.CoasterConfig;
+import com.jverbruggen.jrides.config.flatride.FlatRideConfig;
+import com.jverbruggen.jrides.config.ride.RidesConfig;
+import com.jverbruggen.jrides.config.trigger.TriggerConfig;
+import com.jverbruggen.jrides.config.trigger.TriggerConfigFactory;
+import com.jverbruggen.jrides.models.ride.RideType;
+import com.jverbruggen.jrides.serviceprovider.ServiceProvider;
+import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.configuration.InvalidConfigurationException;
+import org.bukkit.configuration.file.YamlConfiguration;
+import org.bukkit.plugin.java.JavaPlugin;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+
+public class ConfigManager {
+ private final JavaPlugin plugin;
+
+ public ConfigManager(JavaPlugin plugin) {
+ this.plugin = plugin;
+ }
+
+ private File getFile(String fileName){
+ File rootFolder = plugin.getDataFolder();
+ File file = new File(rootFolder, fileName);
+ if(!file.exists()){
+ file.getParentFile().mkdirs();
+ }
+ return file;
+ }
+
+ public YamlConfiguration getYamlConfiguration(String fileName){
+ File file = getFile(fileName);
+
+ YamlConfiguration configuration = new YamlConfiguration();
+ try {
+ configuration.load(file);
+ } catch (IOException | InvalidConfigurationException e) {
+ return null;
+ }
+ return configuration;
+ }
+
+ public YamlConfiguration getOrCreateConfiguration(String fileName){
+ YamlConfiguration found = getYamlConfiguration(fileName);
+ if(found != null) return found;
+
+ found = new YamlConfiguration();
+ File file = getFile(fileName);
+ try {
+ file.createNewFile();
+ found.load(file);
+ } catch (IOException | InvalidConfigurationException e) {
+ e.printStackTrace();
+ JRidesPlugin.getLogger().severe("Could not create configuration file with name '" + fileName + "'!!");
+ }
+
+ return found;
+ }
+
+ public String getPluginName() {
+ return this.plugin.getDescription().getName();
+ }
+
+ private String prepareConfigString(String configString) {
+ int lastLine = 0;
+ int headerLine = 0;
+
+ String[] lines = configString.split("\n");
+ StringBuilder config = new StringBuilder("");
+ String[] arrayOfString1;
+ int j = (arrayOfString1 = lines).length;
+ for (int i = 0; i < j; i++) {
+ String line = arrayOfString1[i];
+ if (line.startsWith(getPluginName() + "_COMMENT")) {
+ String comment = "#" + line.trim().substring(line.indexOf(":") + 1);
+ if (comment.startsWith("# +-")) {
+ if (headerLine == 0) {
+ config.append(comment + "\n");
+ lastLine = 0;
+ headerLine = 1;
+ } else if (headerLine == 1) {
+ config.append(comment + "\n\n");
+ lastLine = 0;
+ headerLine = 0;
+ }
+ } else {
+ String normalComment;
+ if (comment.startsWith("# ' ")) {
+ normalComment =
+
+ comment.substring(0, comment.length() - 1).replaceFirst("# ' ", "# ");
+ } else {
+ normalComment = comment;
+ }
+ if (lastLine == 0) {
+ config.append(normalComment + "\n");
+ } else if (lastLine == 1) {
+ config.append("\n" + normalComment + "\n");
+ }
+ lastLine = 0;
+ }
+ } else {
+ config.append(line + "\n");
+ lastLine = 1;
+ }
+ }
+ return config.toString();
+ }
+
+ public void saveConfig(String configString, File file) {
+ String configuration = prepareConfigString(configString);
+ try {
+ BufferedWriter writer = new BufferedWriter(new FileWriter(file));
+ writer.write(configuration);
+ writer.flush();
+ writer.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void saveConfig(YamlConfiguration configuration, String fileName){
+ File file = getFile(fileName);
+ saveConfig(configuration.saveToString(), file);
+ }
+
+ public String getCoasterFolder(String rideIdentifier){
+ return "coasters/" + rideIdentifier;
+ }
+
+ public String getFlatrideFolder(String rideIdentifier){
+ return "flatrides/" + rideIdentifier;
+ }
+
+ public String getTriggerFolder(RideType rideType, String rideIdentifier){
+ return switch (rideType){
+ case COASTER -> getCoasterFolder(rideIdentifier) + "/triggers";
+ case FLATRIDE -> getFlatrideFolder(rideIdentifier) + "/triggers";
+ };
+ }
+
+ public ConfigurationSection getAllEffectsConfigSection(String rideIdentifier, String trackIdentifier){
+ String fileName = getCoasterFolder(rideIdentifier) + "/" + rideIdentifier + "." + trackIdentifier + ".trigger.yml";
+ YamlConfiguration yamlConfiguration = getYamlConfiguration(fileName);
+ if(yamlConfiguration == null){
+ JRidesPlugin.getLogger().warning("No trigger file for ride " + rideIdentifier);
+ return null;
+ }
+
+ return yamlConfiguration.getConfigurationSection("triggers");
+ }
+
+ public TriggerConfig getTriggerConfig(RideType rideType, String rideIdentifier, String effectName){
+ String fileName = getTriggerFolder(rideType, rideIdentifier) + "/" + effectName + ".yml";
+ YamlConfiguration yamlConfiguration = getYamlConfiguration(fileName);
+ if(yamlConfiguration == null){
+ JRidesPlugin.getLogger().severe("Trigger " + effectName + " not found for ride " + rideIdentifier);
+ return null;
+ }
+
+ TriggerConfigFactory triggerConfigFactory = ServiceProvider.getSingleton(TriggerConfigFactory.class);
+ return triggerConfigFactory.fromConfigurationSection(rideIdentifier, effectName, yamlConfiguration.getConfigurationSection("trigger"));
+ }
+
+ public CoasterConfig getCoasterConfig(String rideIdentifier){
+ String fileName = getCoasterFolder(rideIdentifier) + "/" + rideIdentifier + ".coaster.yml";
+ YamlConfiguration yamlConfiguration = getYamlConfiguration(fileName);
+ if(yamlConfiguration == null){
+ JRidesPlugin.getLogger().severe(rideIdentifier + ".coaster.yml config not found for " + rideIdentifier);
+ return null;
+ }
+
+ return CoasterConfig.fromConfigurationSection(yamlConfiguration.getConfigurationSection("config"));
+ }
+
+ public FlatRideConfig getFlatRideConfig(String rideIdentifier){
+ String fileName = getFlatrideFolder(rideIdentifier) + "/" + rideIdentifier + ".flatride.yml";
+ YamlConfiguration yamlConfiguration = getYamlConfiguration(fileName);
+ if(yamlConfiguration == null){
+ JRidesPlugin.getLogger().severe(rideIdentifier + ".flatride.yml config not found for " + rideIdentifier);
+ return null;
+ }
+
+ return FlatRideConfig.fromConfigurationSection(yamlConfiguration.getConfigurationSection("config"));
+ }
+
+ public RidesConfig getRideConfig(){
+ String fileName = "rides.yml";
+ YamlConfiguration yamlConfiguration = getYamlConfiguration(fileName);
+ if(yamlConfiguration == null) {
+ JRidesPlugin.getLogger().severe("rides.yml config not found");
+ return null;
+ }
+
+ return RidesConfig.fromConfigurationSection(yamlConfiguration.getConfigurationSection("config"));
+ }
+
+ public void updateConfigFile(String configFile, String yamlRootKey, Object object){
+ YamlConfiguration configuration = getOrCreateConfiguration(configFile);
+
+ configuration.set(yamlRootKey, object);
+
+ saveConfig(configuration, configFile);
+ }
+
+ public Optional getConfigFileObject(String configFile, String yamlRootKey, Class clazz){
+ YamlConfiguration configuration = getOrCreateConfiguration(configFile);
+
+ if(!configuration.contains(yamlRootKey))
+ return Optional.empty();
+
+ Object tObject = configuration.get(yamlRootKey);
+ T t;
+ try{
+ t = clazz.cast(tObject);
+ }catch(ClassCastException exception){
+ throw new RuntimeException("Config file " + configFile + " did not contain object of type " + clazz.getTypeName());
+ }
+
+ assert t != null;
+ return Optional.of(t);
+ }
+
+ public Map getLanguageFile() {
+ YamlConfiguration yamlConfiguration = getYamlConfiguration("language.yml");
+ if(yamlConfiguration == null) return null;
+
+ ConfigurationSection configurationSection = yamlConfiguration.getConfigurationSection("language");
+ Set keys = configurationSection.getKeys(false);
+ Map result = new HashMap<>();
+
+ for(String key : keys){
+ result.put(key, configurationSection.getString(key));
+ }
+
+ return result;
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/config/coaster/CoasterConfig.java b/src/main/java/com/jverbruggen/jrides/config/coaster/CoasterConfig.java
new file mode 100644
index 00000000..fd845bcf
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/config/coaster/CoasterConfig.java
@@ -0,0 +1,101 @@
+package com.jverbruggen.jrides.config.coaster;
+
+import com.jverbruggen.jrides.config.coaster.objects.*;
+import com.jverbruggen.jrides.config.coaster.objects.item.ItemStackConfig;
+import com.jverbruggen.jrides.config.gates.GatesConfig;
+import com.jverbruggen.jrides.config.ride.AbstractRideConfig;
+import com.jverbruggen.jrides.config.ride.RideCounterMapConfigs;
+import com.jverbruggen.jrides.models.properties.PlayerLocation;
+import org.bukkit.ChatColor;
+import org.bukkit.configuration.ConfigurationSection;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class CoasterConfig extends AbstractRideConfig {
+ private final TrackConfig track;
+ private final VehiclesConfig vehicles;
+ private final CartSpecConfig cartSpec;
+ private final double gravityConstant;
+ private final double dragConstant;
+ private final ControllerConfig controllerConfig;
+ private final int rideOverviewMapId;
+
+ public CoasterConfig(String manifestVersion, String identifier, String displayName, List displayDescription,
+ ItemStackConfig displayItem, PlayerLocation warpLocation, PlayerLocation customEjectLocation, TrackConfig track,
+ InteractionEntitiesConfig interactionEntities,
+ VehiclesConfig vehicles, CartSpecConfig cartSpec, GatesConfig gates, double gravityConstant, double dragConstant,
+ ControllerConfig controllerConfig, SoundsConfig soundsConfig, int rideOverviewMapId, boolean canExitDuringRide,
+ RideCounterMapConfigs rideCounterMapConfigs, boolean debugMode) {
+ super(manifestVersion, identifier, displayName, displayDescription, displayItem, warpLocation, customEjectLocation, gates, soundsConfig, canExitDuringRide, interactionEntities, rideCounterMapConfigs, debugMode);
+ this.track = track;
+ this.vehicles = vehicles;
+ this.cartSpec = cartSpec;
+ this.gravityConstant = gravityConstant;
+ this.dragConstant = dragConstant;
+ this.controllerConfig = controllerConfig;
+ this.rideOverviewMapId = rideOverviewMapId;
+ }
+
+ public TrackConfig getTrack() {
+ return track;
+ }
+
+ public VehiclesConfig getVehicles() {
+ return vehicles;
+ }
+
+ public CartSpecConfig getCartSpec() {
+ return cartSpec;
+ }
+
+ public double getGravityConstant() {
+ return gravityConstant;
+ }
+
+ public double getDragConstant() {
+ return dragConstant;
+ }
+
+ public ControllerConfig getControllerConfig() {
+ return controllerConfig;
+ }
+
+ public int getRideOverviewMapId() {
+ return rideOverviewMapId;
+ }
+
+ public static CoasterConfig fromConfigurationSection(ConfigurationSection configurationSection) {
+ String manifestVersion = getString(configurationSection, "manifestVersion");
+ String identifier = getString(configurationSection, "identifier");
+ String displayName = getString(configurationSection, "displayName");
+
+ List displayDescription = Arrays.stream(getString(configurationSection, "displayDescription", "").split("\\\\n"))
+ .map(d -> ChatColor.GRAY + d)
+ .collect(Collectors.toList());
+ if(displayDescription.size() == 1 && ChatColor.stripColor(displayDescription.get(0)).equals(""))
+ displayDescription.clear();
+
+ ItemStackConfig displayItem = ItemStackConfig.fromConfigurationSection(configurationSection.getConfigurationSection("displayItem"));
+ PlayerLocation warpLocation = PlayerLocation.fromDoubleList(configurationSection.getDoubleList("warpLocation"));
+ PlayerLocation customEjectLocation = PlayerLocation.fromDoubleList(getDoubleList(configurationSection, "customEjectLocation", null));
+ double gravityConstant = getDouble(configurationSection, "gravityConstant", 0.15);
+ double dragConstant = getDouble(configurationSection, "dragConstant", 0.9993);
+ TrackConfig track = TrackConfig.fromConfigurationSection(getConfigurationSection(configurationSection, "track"));
+ VehiclesConfig vehicles = VehiclesConfig.fromConfigurationSection(getConfigurationSection(configurationSection, "vehicles"));
+ CartSpecConfig cartSpec = CartSpecConfig.fromConfigurationSection(getConfigurationSection(configurationSection, "cartSpec"));
+ GatesConfig gates = GatesConfig.fromConfigurationSection(configurationSection.getConfigurationSection("gates"));
+ InteractionEntitiesConfig interactionEntities = InteractionEntitiesConfig.fromConfigurationSection(getConfigurationSection(configurationSection, "interactionEntities"));
+ SoundsConfig sounds = SoundsConfig.fromConfigurationSection(configurationSection.getConfigurationSection("sounds"));
+ ControllerConfig controllerConfig = ControllerConfig.fromConfigurationSection(configurationSection.getConfigurationSection("controller"));
+ int rideOverviewMapId = getInt(configurationSection, "rideOverviewMapId", -1);
+ boolean canExitDuringRide = getBoolean(configurationSection, "canExitDuringRide", false);
+ RideCounterMapConfigs rideCounterMapConfigs = RideCounterMapConfigs.fromConfigurationSection(identifier, configurationSection.getConfigurationSection("rideCounterMaps"));
+ boolean debugMode = getBoolean(configurationSection, "debugMode", false);
+
+ return new CoasterConfig(manifestVersion, identifier, displayName, displayDescription, displayItem, warpLocation, customEjectLocation, track, interactionEntities, vehicles,
+ cartSpec, gates, gravityConstant, dragConstant, controllerConfig, sounds, rideOverviewMapId,
+ canExitDuringRide, rideCounterMapConfigs, debugMode);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/config/coaster/objects/BaseConfig.java b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/BaseConfig.java
new file mode 100644
index 00000000..2b31216a
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/BaseConfig.java
@@ -0,0 +1,208 @@
+package com.jverbruggen.jrides.config.coaster.objects;
+
+import com.jverbruggen.jrides.config.utils.integersupplier.CycleIntegerSupplier;
+import com.jverbruggen.jrides.config.utils.integersupplier.RandomIntegerSupplier;
+import com.jverbruggen.jrides.config.utils.integersupplier.SimpleIntegerSupplier;
+import org.bukkit.configuration.ConfigurationSection;
+
+import javax.annotation.Nullable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Supplier;
+import java.util.stream.Collectors;
+
+public abstract class BaseConfig {
+ private static String getAvailableKeys(ConfigurationSection configurationSection){
+ if(configurationSection == null) return "";
+ return String.join(", ", configurationSection.getKeys(false));
+ }
+
+ private static void assertPresence(ConfigurationSection configurationSection, String key){
+ if(configurationSection == null || !configurationSection.contains(key)){
+ throw new RuntimeException("Missing key in config: '" + key + "', available: " + getAvailableKeys(configurationSection));
+ }
+ }
+
+ private static void assertPresence(Map config, String key){
+ if(config == null || !config.containsKey(key)){
+ throw new RuntimeException("Missing key in config: " + key);
+ }
+ }
+
+ private static boolean isPresent(ConfigurationSection configurationSection, String key){
+ if(configurationSection == null) return false;
+ return configurationSection.contains(key);
+ }
+
+ private static boolean isPresent(Map config, String key){
+ if(config == null) return false;
+ return config.containsKey(key);
+ }
+
+ protected static double getDouble(ConfigurationSection configurationSection, String key){
+ assertPresence(configurationSection, key);
+ return configurationSection.getDouble(key);
+ }
+
+ protected static Double getDoubleObj(ConfigurationSection configurationSection, String key){
+ assertPresence(configurationSection, key);
+ return configurationSection.getDouble(key);
+ }
+
+ protected static double getDouble(ConfigurationSection configurationSection, String key, double defaultValue){
+ if(!isPresent(configurationSection, key)) return defaultValue;
+ return getDouble(configurationSection, key);
+ }
+
+ protected static Double getDoubleObj(ConfigurationSection configurationSection, String key, Double defaultValue){
+ if(!isPresent(configurationSection, key)) return defaultValue;
+ return getDoubleObj(configurationSection, key);
+ }
+
+ protected static int getInt(ConfigurationSection configurationSection, String key){
+ assertPresence(configurationSection, key);
+ return configurationSection.getInt(key);
+ }
+
+ protected static int getInt(ConfigurationSection configurationSection, String key, int defaultValue){
+ if(!isPresent(configurationSection, key)) return defaultValue;
+ return getInt(configurationSection, key);
+ }
+
+ protected static Supplier getIntSupplier(ConfigurationSection configurationSection, String key){
+ assertPresence(configurationSection, key);
+ Object value = configurationSection.get(key);
+ if(value instanceof List>){
+ List ints = ((List>)value).stream().map(o -> (int)o).toList();
+ if(ints.size() != 2) throw new RuntimeException("Range can only have 2 items");
+ return new RandomIntegerSupplier(ints.get(0), ints.get(1));
+ }else if(value instanceof String sValue && sValue.startsWith("<")){
+ List ints = Arrays.stream(sValue.substring(1, sValue.length() - 1).replace(" ", "").split(","))
+ .map(Integer::parseInt)
+ .toList();
+ return new CycleIntegerSupplier(ints);
+ }
+
+ assert value instanceof Integer;
+ return new SimpleIntegerSupplier((int) value);
+ }
+
+ protected static Supplier getIntSupplier(ConfigurationSection configurationSection, String key, int defaultValue){
+ if(!isPresent(configurationSection, key)) return new SimpleIntegerSupplier(defaultValue);
+ return getIntSupplier(configurationSection, key);
+ }
+
+ protected static String getString(Map config, String key, String defaultValue){
+ if(!isPresent(config, key)) return defaultValue;
+ return (String) config.get(key);
+ }
+
+ protected static String getString(ConfigurationSection configurationSection, String key, String defaultValue){
+ if(!isPresent(configurationSection, key)) return defaultValue;
+ return configurationSection.getString(key);
+ }
+
+ protected static String getString(Map config, String key){
+ assertPresence(config, key);
+ return (String) config.get(key);
+ }
+
+ protected static String getString(ConfigurationSection configurationSection, String key){
+ assertPresence(configurationSection, key);
+ return configurationSection.getString(key);
+ }
+
+ protected static boolean getBoolean(ConfigurationSection configurationSection, String key, boolean defaultValue) {
+ if(!isPresent(configurationSection, key)) return defaultValue;
+ return configurationSection.getBoolean(key);
+ }
+
+ protected static boolean getBoolean(ConfigurationSection configurationSection, String key) {
+ assertPresence(configurationSection, key);
+ return configurationSection.getBoolean(key);
+ }
+
+ protected static @Nullable ConfigurationSection getConfigurationSection(ConfigurationSection configurationSection, String key){
+ if(!isPresent(configurationSection, key)) return null;
+ return configurationSection.getConfigurationSection(key);
+ }
+
+ protected static List getStringList(ConfigurationSection configurationSection, String key){
+ assertPresence(configurationSection, key);
+ return configurationSection.getStringList(key);
+ }
+
+ protected static List getStringList(ConfigurationSection configurationSection, String key, List defaultValue){
+ if(!isPresent(configurationSection, key)) return defaultValue;
+ return configurationSection.getStringList(key);
+ }
+
+ protected static List getDoubleList(ConfigurationSection configurationSection, String key){
+ assertPresence(configurationSection, key);
+
+ return configurationSection.getList(key)
+ .stream()
+ .map(BaseConfig::toDouble)
+ .collect(Collectors.toList());
+ }
+
+ protected static List getDoubleList(ConfigurationSection configurationSection, String key, List defaultValue){
+ if(!isPresent(configurationSection, key)) return defaultValue;
+ return getDoubleList(configurationSection, key);
+ }
+
+ protected static List> getDoubleListList(ConfigurationSection configurationSection, String key){
+ assertPresence(configurationSection, key);
+
+ return configurationSection.getList(key)
+ .stream()
+ .map(obj -> ((List>) obj).stream()
+ .map(BaseConfig::toDouble)
+ .collect(Collectors.toList()))
+ .collect(Collectors.toList());
+ }
+
+ protected static List> getDoubleListList(ConfigurationSection configurationSection, String key, List> defaultValue){
+ if(!isPresent(configurationSection, key)) return defaultValue;
+ return getDoubleListList(configurationSection, key);
+ }
+
+ protected static double toDouble(Object object){
+ if(object instanceof Double){
+ return (double) object;
+ }else if(object instanceof Integer){
+ return ((Integer)object).doubleValue();
+ }else throw new RuntimeException("Cannot convert " + object + " to double");
+ }
+
+ protected static List getIntegerList(ConfigurationSection configurationSection, String key){
+ assertPresence(configurationSection, key);
+
+ return configurationSection.getList(key)
+ .stream()
+ .map(BaseConfig::toInteger)
+ .collect(Collectors.toList());
+ }
+
+ protected static List getIntegerList(ConfigurationSection configurationSection, String key, List defaultValue){
+ if(!isPresent(configurationSection, key)) return defaultValue;
+ return getIntegerList(configurationSection, key);
+ }
+
+ protected static int toInteger(Object object){
+ if(object instanceof Integer){
+ return (Integer) object;
+ }else throw new RuntimeException("Cannot convert " + object + " to integer");
+ }
+
+ protected static List createDoubleList(double a, double b, double c){
+ List doubleList = new ArrayList<>();
+ doubleList.add(a);
+ doubleList.add(b);
+ doubleList.add(c);
+ return doubleList;
+ }
+
+}
diff --git a/src/main/java/com/jverbruggen/jrides/config/coaster/objects/CartSpecConfig.java b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/CartSpecConfig.java
new file mode 100644
index 00000000..6b33d59c
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/CartSpecConfig.java
@@ -0,0 +1,57 @@
+package com.jverbruggen.jrides.config.coaster.objects;
+
+import com.jverbruggen.jrides.config.coaster.objects.cart.CartTypeSpecConfig;
+import org.bukkit.configuration.ConfigurationSection;
+
+import javax.annotation.Nullable;
+
+public class CartSpecConfig {
+ private final CartTypeSpecConfig _default;
+ private final CartTypeSpecConfig head;
+ private final CartTypeSpecConfig tail;
+
+ public CartSpecConfig(CartTypeSpecConfig _default, CartTypeSpecConfig head, CartTypeSpecConfig tail) {
+ this._default = _default;
+ this.head = head;
+ this.tail = tail;
+ }
+
+ public CartTypeSpecConfig getDefault() {
+ return _default;
+ }
+
+ public CartTypeSpecConfig getHead() {
+ return head;
+ }
+
+ public CartTypeSpecConfig getTail() {
+ return tail;
+ }
+
+ public boolean hasHead(){
+ return head != null;
+ }
+
+ public boolean hasTail(){
+ return tail != null;
+ }
+
+ public static CartSpecConfig fromConfigurationSection(@Nullable ConfigurationSection configurationSection) {
+ if(configurationSection == null)
+ return new CartSpecConfig(CartTypeSpecConfig.fromConfigurationSection(null), null, null);
+
+ CartTypeSpecConfig _default = CartTypeSpecConfig.fromConfigurationSection(configurationSection.getConfigurationSection("default"));
+ CartTypeSpecConfig head = null;
+ CartTypeSpecConfig tail = null;
+
+ if(configurationSection.contains("head")){
+ head = CartTypeSpecConfig.fromConfigurationSection(configurationSection.getConfigurationSection("head"));
+ }
+ if(configurationSection.contains("tail")){
+ tail = CartTypeSpecConfig.fromConfigurationSection(configurationSection.getConfigurationSection("tail"));
+ }
+
+ return new CartSpecConfig(_default, head, tail);
+ }
+}
+
diff --git a/src/main/java/com/jverbruggen/jrides/config/coaster/objects/ControllerConfig.java b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/ControllerConfig.java
new file mode 100644
index 00000000..090e2341
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/ControllerConfig.java
@@ -0,0 +1,41 @@
+package com.jverbruggen.jrides.config.coaster.objects;
+
+import com.jverbruggen.jrides.config.coaster.objects.controller.DualControllerSpecConfig;
+import org.bukkit.configuration.ConfigurationSection;
+
+public class ControllerConfig extends BaseConfig {
+ public static final String CONTROLLER_DEFAULT = "default";
+ public static final String CONTROLLER_ALTERNATE = "alternate";
+ public static final String CONTROLLER_SIMULTANEOUS = "simultaneous";
+
+ private String type;
+ private DualControllerSpecConfig dualControllerSpecConfig;
+
+ public ControllerConfig(String type, DualControllerSpecConfig dualControllerSpecConfig) {
+ this.type = type;
+ this.dualControllerSpecConfig = dualControllerSpecConfig;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public DualControllerSpecConfig getAlternateControllerSpecConfig() {
+ return dualControllerSpecConfig;
+ }
+
+ public static ControllerConfig fromConfigurationSection(ConfigurationSection configurationSection) {
+ if(configurationSection == null) return null;
+
+ String type = getString(configurationSection, "type", "default");
+ DualControllerSpecConfig dualControllerSpecConfig = null;
+
+ if(type.equalsIgnoreCase(CONTROLLER_ALTERNATE))
+ dualControllerSpecConfig = DualControllerSpecConfig.fromConfigurationSection(configurationSection.getConfigurationSection("spec"));
+ else if(type.equalsIgnoreCase(CONTROLLER_SIMULTANEOUS))
+ dualControllerSpecConfig = DualControllerSpecConfig.fromConfigurationSection(configurationSection.getConfigurationSection("spec"));
+
+ return new ControllerConfig(type, dualControllerSpecConfig);
+ }
+}
+
diff --git a/src/main/java/com/jverbruggen/jrides/config/coaster/objects/InteractionEntitiesConfig.java b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/InteractionEntitiesConfig.java
new file mode 100644
index 00000000..86c8b3e9
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/InteractionEntitiesConfig.java
@@ -0,0 +1,61 @@
+package com.jverbruggen.jrides.config.coaster.objects;
+
+import com.jverbruggen.jrides.animator.RideHandle;
+import com.jverbruggen.jrides.config.coaster.objects.cart.ModelConfig;
+import com.jverbruggen.jrides.event.action.OperateRideAction;
+import com.jverbruggen.jrides.models.entity.VirtualEntity;
+import com.jverbruggen.jrides.models.math.Quaternion;
+import com.jverbruggen.jrides.models.math.Vector3;
+import com.jverbruggen.jrides.serviceprovider.ServiceProvider;
+import com.jverbruggen.jrides.state.viewport.ViewportManager;
+import org.bukkit.configuration.ConfigurationSection;
+
+import javax.annotation.Nullable;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+public class InteractionEntitiesConfig extends BaseConfig {
+ private final Map interactionEntities;
+
+ public InteractionEntitiesConfig(Map interactionEntities) {
+ this.interactionEntities = interactionEntities;
+ }
+
+ public InteractionEntitiesConfig(){
+ this.interactionEntities = new HashMap<>();
+ }
+
+ public void spawnEntities(RideHandle rideHandle){
+ ViewportManager viewportManager = ServiceProvider.getSingleton(ViewportManager.class);
+
+ for(Map.Entry entry : interactionEntities.entrySet()){
+ ModelConfig modelConfig = entry.getValue();
+ Vector3 spawnPosition = modelConfig.getPosition();
+ Quaternion spawnRotation = modelConfig.getRotation();
+ String customName = "Controller";
+ VirtualEntity virtualEntity = modelConfig.getItemConfig().spawnEntity(viewportManager, spawnPosition, spawnRotation, customName);
+
+ virtualEntity.setCustomAction(new OperateRideAction());
+ virtualEntity.setBelongsToRide(rideHandle);
+ }
+ }
+
+ public static InteractionEntitiesConfig fromConfigurationSection(@Nullable ConfigurationSection configurationSection){
+ if(configurationSection == null)
+ return new InteractionEntitiesConfig();
+
+ Set keys = configurationSection.getKeys(false);
+
+ Map entityLocations = new HashMap<>();
+
+ for(String key : keys){
+ ConfigurationSection keyConfigurationSection = configurationSection.getConfigurationSection(key);
+ ModelConfig modelConfig = ModelConfig.fromConfigurationSection(keyConfigurationSection);
+
+ entityLocations.put(key, modelConfig);
+ }
+
+ return new InteractionEntitiesConfig(entityLocations);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/config/coaster/objects/SoundsConfig.java b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/SoundsConfig.java
new file mode 100644
index 00000000..a84eca84
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/SoundsConfig.java
@@ -0,0 +1,48 @@
+package com.jverbruggen.jrides.config.coaster.objects;
+
+import org.bukkit.configuration.ConfigurationSection;
+
+public class SoundsConfig {
+ private final String onrideWind;
+ private final String restraintOpen;
+ private final String restraintClose;
+ private final String dispatch;
+
+ public SoundsConfig(String onrideWind, String restraintOpen, String restraintClose, String dispatch) {
+ this.onrideWind = onrideWind;
+ this.restraintOpen = restraintOpen;
+ this.restraintClose = restraintClose;
+ this.dispatch = dispatch;
+ }
+
+ public SoundsConfig() {
+ this(null, null, null, null);
+ }
+
+ public String getOnrideWind() {
+ return onrideWind;
+ }
+
+ public String getRestraintOpen() {
+ return restraintOpen;
+ }
+
+ public String getRestraintClose() {
+ return restraintClose;
+ }
+
+ public String getDispatch() {
+ return dispatch;
+ }
+
+ public static SoundsConfig fromConfigurationSection(ConfigurationSection configurationSection){
+ if(configurationSection == null) return new SoundsConfig();
+
+ String onrideWind = configurationSection.contains("onrideWind") ? configurationSection.getString("onrideWind") : null;
+ String restraintOpen = configurationSection.contains("restraintOpen") ? configurationSection.getString("restraintOpen") : null;
+ String restraintClose = configurationSection.contains("restraintClose") ? configurationSection.getString("restraintClose") : null;
+ String dispatch = configurationSection.contains("dispatch") ? configurationSection.getString("dispatch") : null;
+
+ return new SoundsConfig(onrideWind, restraintOpen, restraintClose, dispatch);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/config/coaster/objects/TrackConfig.java b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/TrackConfig.java
new file mode 100644
index 00000000..a43380ba
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/TrackConfig.java
@@ -0,0 +1,76 @@
+package com.jverbruggen.jrides.config.coaster.objects;
+
+import com.jverbruggen.jrides.config.coaster.objects.section.base.SectionConfig;
+import org.bukkit.configuration.ConfigurationSection;
+
+import javax.annotation.Nullable;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+public class TrackConfig {
+ private final List position;
+ private final List sections;
+ private final List parts;
+ private final boolean correctlyLoaded;
+
+ public TrackConfig(List position, List sections, List parts) {
+ this.position = position;
+ this.sections = sections;
+ this.parts = parts;
+ this.correctlyLoaded = true;
+ }
+
+ public TrackConfig(){
+ this.position = new ArrayList<>();
+ this.sections = new ArrayList<>();
+ this.parts = new ArrayList<>();
+ this.correctlyLoaded = false;
+ }
+
+ public List getPosition() {
+ return position;
+ }
+
+ public List getSections() {
+ return sections;
+ }
+
+ public List getParts() {
+ return parts;
+ }
+
+ public boolean isCorrectlyLoaded() {
+ return correctlyLoaded;
+ }
+
+ public static TrackConfig fromConfigurationSection(@Nullable ConfigurationSection configurationSection) {
+ if(configurationSection == null) return new TrackConfig();
+
+ List position = configurationSection.getFloatList("position");
+ List parts = configurationSection.getStringList("parts");
+
+ List sections = new ArrayList<>();
+ ConfigurationSection configurationSectionSections = configurationSection.getConfigurationSection("sections");
+ Set sectionsKeys = configurationSectionSections.getKeys(false);
+ for(String sectionKey : sectionsKeys){
+ ConfigurationSection sectionSpec = configurationSectionSections.getConfigurationSection(sectionKey);
+
+ String track = "spline";
+ assert sectionSpec != null;
+ if(sectionSpec.contains("track")){
+ track = sectionSpec.getString("track");
+ }
+
+ assert track != null;
+ if(track.equalsIgnoreCase("spline")){
+ sections.add(SectionConfig.fromConfigurationSection(sectionSpec, sectionKey));
+ }else if(track.equalsIgnoreCase("straight")){
+ throw new RuntimeException("Straight track not implemented yet");
+ }
+ }
+
+ return new TrackConfig(position, sections, parts);
+ }
+}
+
diff --git a/src/main/java/com/jverbruggen/jrides/config/coaster/objects/VehiclesConfig.java b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/VehiclesConfig.java
new file mode 100644
index 00000000..21c3fc2a
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/VehiclesConfig.java
@@ -0,0 +1,38 @@
+package com.jverbruggen.jrides.config.coaster.objects;
+
+import org.bukkit.configuration.ConfigurationSection;
+
+public class VehiclesConfig extends BaseConfig {
+ private final int trains;
+ private final int carts;
+ private final int cartDistance;
+
+ public VehiclesConfig(int trains, int carts, int cartDistance) {
+ this.trains = trains;
+ this.carts = carts;
+ this.cartDistance = cartDistance;
+ }
+
+ public int getCarts() {
+ return carts;
+ }
+
+ public int getTrains() {
+ return trains;
+ }
+
+ public int getCartDistance() {
+ return cartDistance;
+ }
+
+ public static VehiclesConfig fromConfigurationSection(ConfigurationSection configurationSection) {
+ int trains = getInt(configurationSection, "trains", 1);
+ int carts = getInt(configurationSection, "carts", 1);
+ int cartDistance = getInt(configurationSection, "cartDistance", 20);
+
+ if(cartDistance < 20)
+ throw new RuntimeException("Cart Distances for less than 20 frames are not supported");
+
+ return new VehiclesConfig(trains, carts, cartDistance);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/config/coaster/objects/cart/CartSeatsConfig.java b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/cart/CartSeatsConfig.java
new file mode 100644
index 00000000..6a391cf7
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/cart/CartSeatsConfig.java
@@ -0,0 +1,29 @@
+package com.jverbruggen.jrides.config.coaster.objects.cart;
+
+import com.jverbruggen.jrides.config.coaster.objects.BaseConfig;
+import com.jverbruggen.jrides.models.math.Vector3;
+import com.jverbruggen.jrides.models.math.Vector3PlusYaw;
+import org.bukkit.configuration.ConfigurationSection;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class CartSeatsConfig extends BaseConfig {
+ private List positions;
+
+ public CartSeatsConfig(List positions) {
+ this.positions = positions;
+ }
+
+ public List getPositions() {
+ return positions;
+ }
+
+ public static CartSeatsConfig fromConfigurationSection(ConfigurationSection configurationSection) {
+ List> positions = getDoubleListList(configurationSection, "positions", List.of());
+ List vectors = positions.stream()
+ .map(Vector3PlusYaw::fromDoubleList)
+ .collect(Collectors.toList());
+ return new CartSeatsConfig(vectors);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/config/coaster/objects/cart/CartTypeSpecConfig.java b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/cart/CartTypeSpecConfig.java
new file mode 100644
index 00000000..89284fff
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/cart/CartTypeSpecConfig.java
@@ -0,0 +1,30 @@
+package com.jverbruggen.jrides.config.coaster.objects.cart;
+
+import com.jverbruggen.jrides.config.coaster.objects.BaseConfig;
+import org.bukkit.configuration.ConfigurationSection;
+
+import javax.annotation.Nullable;
+
+public class CartTypeSpecConfig extends BaseConfig {
+ private final ModelConfig model;
+ private final CartSeatsConfig seats;
+
+ public CartTypeSpecConfig(ModelConfig model, CartSeatsConfig seats) {
+ this.model = model;
+ this.seats = seats;
+ }
+
+ public ModelConfig getModel() {
+ return model;
+ }
+
+ public CartSeatsConfig getSeats() {
+ return seats;
+ }
+
+ public static CartTypeSpecConfig fromConfigurationSection(@Nullable ConfigurationSection configurationSection) {
+ ModelConfig model = ModelConfig.fromConfigurationSection(getConfigurationSection(configurationSection, "model"));
+ CartSeatsConfig seats = CartSeatsConfig.fromConfigurationSection(getConfigurationSection(configurationSection, "seats"));
+ return new CartTypeSpecConfig(model, seats);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/config/coaster/objects/cart/ModelConfig.java b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/cart/ModelConfig.java
new file mode 100644
index 00000000..65203b27
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/cart/ModelConfig.java
@@ -0,0 +1,67 @@
+package com.jverbruggen.jrides.config.coaster.objects.cart;
+
+import com.jverbruggen.jrides.animator.flatride.rotor.FlatRideModel;
+import com.jverbruggen.jrides.config.coaster.objects.BaseConfig;
+import com.jverbruggen.jrides.config.coaster.objects.item.ItemConfig;
+import com.jverbruggen.jrides.models.entity.VirtualEntity;
+import com.jverbruggen.jrides.models.math.Quaternion;
+import com.jverbruggen.jrides.models.math.Vector3;
+import com.jverbruggen.jrides.state.viewport.ViewportManager;
+import org.bukkit.configuration.ConfigurationSection;
+
+import javax.annotation.Nullable;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+public class ModelConfig extends BaseConfig {
+ private final ItemConfig itemConfig;
+ private final Vector3 position;
+ private final Quaternion rotation;
+
+ public ModelConfig(ItemConfig itemConfig, Vector3 position, Quaternion rotation) {
+ this.itemConfig = itemConfig;
+ this.position = position;
+ this.rotation = rotation;
+ }
+
+ public Vector3 getPosition() {
+ return position;
+ }
+
+ public Quaternion getRotation() {
+ return rotation;
+ }
+
+ public ItemConfig getItemConfig() {
+ return itemConfig;
+ }
+
+ public FlatRideModel toFlatRideModel(Vector3 rootPosition, ViewportManager viewportManager){
+ Vector3 spawnPosition = Vector3.add(rootPosition, position);
+ VirtualEntity virtualEntity = itemConfig.spawnEntity(viewportManager, spawnPosition, new Quaternion(), null);
+
+ return new FlatRideModel(virtualEntity, position.clone(), rotation.clone());
+ }
+
+ public static ModelConfig fromConfigurationSection(@Nullable ConfigurationSection configurationSection) {
+ if(configurationSection == null) return new ModelConfig(null, Vector3.zero(), new Quaternion());
+
+ ItemConfig itemConfig = ItemConfig.fromConfigurationSection(configurationSection);
+
+ Vector3 vector = Vector3.fromDoubleList(getDoubleList(configurationSection, "position", List.of(0d,0d,0d)));
+ Quaternion rotation = Quaternion.fromDoubleList(getDoubleList(configurationSection, "rotation", List.of(0d,0d,0d)));
+
+ return new ModelConfig(itemConfig, vector, rotation);
+ }
+
+ public static List multipleFromConfigurationSection(ConfigurationSection configurationSection){
+ List modelConfigs = new ArrayList<>();
+ Set keys = configurationSection.getKeys(false);
+ for(String key : keys){
+ ModelConfig modelConfig = fromConfigurationSection(getConfigurationSection(configurationSection, key));
+ modelConfigs.add(modelConfig);
+ }
+ return modelConfigs;
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/config/coaster/objects/controller/DualControllerSpecConfig.java b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/controller/DualControllerSpecConfig.java
new file mode 100644
index 00000000..326ae94f
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/controller/DualControllerSpecConfig.java
@@ -0,0 +1,29 @@
+package com.jverbruggen.jrides.config.coaster.objects.controller;
+
+import com.jverbruggen.jrides.config.coaster.objects.BaseConfig;
+import org.bukkit.configuration.ConfigurationSection;
+
+public class DualControllerSpecConfig extends BaseConfig {
+ private String stationLeft;
+ private String stationRight;
+
+ public DualControllerSpecConfig(String stationLeft, String stationRight) {
+ this.stationLeft = stationLeft;
+ this.stationRight = stationRight;
+ }
+
+ public String getStationLeft() {
+ return stationLeft;
+ }
+
+ public String getStationRight() {
+ return stationRight;
+ }
+
+ public static DualControllerSpecConfig fromConfigurationSection(ConfigurationSection configurationSection) {
+ String stationLeft = getString(configurationSection, "stationLeft");
+ String stationRight = getString(configurationSection, "stationRight");
+
+ return new DualControllerSpecConfig(stationLeft, stationRight);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/config/coaster/objects/item/EntityConfig.java b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/item/EntityConfig.java
new file mode 100644
index 00000000..0a6f43eb
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/item/EntityConfig.java
@@ -0,0 +1,34 @@
+package com.jverbruggen.jrides.config.coaster.objects.item;
+
+import com.jverbruggen.jrides.models.entity.VirtualEntity;
+import com.jverbruggen.jrides.models.math.Quaternion;
+import com.jverbruggen.jrides.models.math.Vector3;
+import com.jverbruggen.jrides.state.viewport.ViewportManager;
+import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.entity.EntityType;
+
+import javax.annotation.Nullable;
+
+public class EntityConfig implements ItemConfig{
+ private final EntityType entityType;
+
+ public EntityConfig(EntityType entityType) {
+ this.entityType = entityType;
+ }
+
+ public EntityType getEntityType() {
+ return entityType;
+ }
+
+ @Override
+ public VirtualEntity spawnEntity(ViewportManager viewportManager, Vector3 spawnPosition, Quaternion spawnRotation, String customName) {
+ return viewportManager.spawnVirtualEntity(spawnPosition, getEntityType());
+ }
+
+ public static EntityConfig fromConfigurationSection(@Nullable ConfigurationSection configurationSection) {
+ if(configurationSection == null) return new EntityConfig(null);
+
+ EntityType entityType = EntityType.valueOf(configurationSection.getString("type"));
+ return new EntityConfig(entityType);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/config/coaster/objects/item/ItemConfig.java b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/item/ItemConfig.java
new file mode 100644
index 00000000..e4b2aab1
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/item/ItemConfig.java
@@ -0,0 +1,23 @@
+package com.jverbruggen.jrides.config.coaster.objects.item;
+
+import com.jverbruggen.jrides.models.entity.VirtualEntity;
+import com.jverbruggen.jrides.models.math.Quaternion;
+import com.jverbruggen.jrides.models.math.Vector3;
+import com.jverbruggen.jrides.state.viewport.ViewportManager;
+import org.bukkit.configuration.ConfigurationSection;
+
+import javax.annotation.Nullable;
+
+public interface ItemConfig {
+ VirtualEntity spawnEntity(ViewportManager viewportManager, Vector3 spawnPosition, Quaternion spawnRotation, String customName);
+
+ static ItemConfig fromConfigurationSection(@Nullable ConfigurationSection configurationSection){
+ if(configurationSection == null) return null;
+
+ if(configurationSection.contains("item"))
+ return ItemStackConfig.fromConfigurationSection(configurationSection.getConfigurationSection("item"));
+ else if(configurationSection.contains("entity"))
+ return EntityConfig.fromConfigurationSection(configurationSection.getConfigurationSection("entity"));
+ else throw new RuntimeException("Model config needs an item or an entity");
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/config/coaster/objects/item/ItemStackConfig.java b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/item/ItemStackConfig.java
new file mode 100644
index 00000000..32696526
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/item/ItemStackConfig.java
@@ -0,0 +1,61 @@
+package com.jverbruggen.jrides.config.coaster.objects.item;
+
+import com.jverbruggen.jrides.items.ItemStackFactory;
+import com.jverbruggen.jrides.models.entity.TrainModelItem;
+import com.jverbruggen.jrides.models.entity.VirtualEntity;
+import com.jverbruggen.jrides.models.math.Quaternion;
+import com.jverbruggen.jrides.models.math.Vector3;
+import com.jverbruggen.jrides.state.viewport.ViewportManager;
+import org.bukkit.Material;
+import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.inventory.ItemStack;
+
+import javax.annotation.Nullable;
+
+public class ItemStackConfig implements ItemConfig {
+ private final Material material;
+ private final int damage;
+ private final boolean unbreakable;
+
+ public ItemStackConfig(Material material, int damage, boolean unbreakable) {
+ this.material = material;
+ this.damage = damage;
+ this.unbreakable = unbreakable;
+ }
+
+ public ItemStackConfig() {
+ this.material = Material.STONE;
+ this.damage = 0;
+ this.unbreakable = false;
+ }
+
+ public Material getMaterial() {
+ return material;
+ }
+
+ public int getDamage() {
+ return damage;
+ }
+
+ public boolean isUnbreakable() {
+ return unbreakable;
+ }
+
+ public ItemStack createItemStack(){
+ return ItemStackFactory.getCoasterStackFromConfig(this);
+ }
+
+ @Override
+ public VirtualEntity spawnEntity(ViewportManager viewportManager, Vector3 spawnPosition, Quaternion spawnRotation, String customName) {
+ return viewportManager.spawnModelEntity(spawnPosition, spawnRotation, new TrainModelItem(createItemStack()), customName);
+ }
+
+ public static ItemStackConfig fromConfigurationSection(@Nullable ConfigurationSection configurationSection) {
+ if(configurationSection == null) return new ItemStackConfig();
+
+ Material material = Material.valueOf(configurationSection.getString("material"));
+ int damage = configurationSection.getInt("damage", 0);
+ boolean unbreakable = configurationSection.getBoolean("unbreakable", false);
+ return new ItemStackConfig(material, damage, unbreakable);
+ }
+}
diff --git a/src/main/java/com/jverbruggen/jrides/config/coaster/objects/section/base/PointSectionConfig.java b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/section/base/PointSectionConfig.java
new file mode 100644
index 00000000..feb4a47b
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/section/base/PointSectionConfig.java
@@ -0,0 +1,88 @@
+package com.jverbruggen.jrides.config.coaster.objects.section.base;
+
+import com.jverbruggen.jrides.animator.coaster.CoasterHandle;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.TrackBehaviour;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.factory.TrackBehaviourFactory;
+import com.jverbruggen.jrides.config.coaster.CoasterConfig;
+import com.jverbruggen.jrides.config.coaster.objects.section.point.SwitchSectionSpecConfig;
+import com.jverbruggen.jrides.models.properties.frame.Frame;
+import com.jverbruggen.jrides.models.properties.frame.SimpleFrame;
+import com.jverbruggen.jrides.models.ride.factory.track.TrackDescription;
+import com.jverbruggen.jrides.models.ride.section.reference.PointSectionReference;
+import com.jverbruggen.jrides.models.ride.section.reference.SectionReference;
+import org.bukkit.configuration.ConfigurationSection;
+
+import java.util.List;
+
+public class PointSectionConfig extends SectionConfig {
+ private final int point;
+ private final String trackSource;
+ private final String nextSection;
+ private final SwitchSectionSpecConfig switchSectionSpecConfig;
+
+ public PointSectionConfig(String identifier, int point, String trackSource, String type, String nextSection, SwitchSectionSpecConfig switchSectionSpecConfig) {
+ super(type, identifier);
+ this.point = point;
+ this.trackSource = trackSource;
+ this.nextSection = nextSection;
+ this.switchSectionSpecConfig = switchSectionSpecConfig;
+ }
+
+ public int getPoint() {
+ return point;
+ }
+
+ public String getNextSection() {
+ return nextSection;
+ }
+
+ public String getParentTrackIdentifier() {
+ return trackSource;
+ }
+
+ public SwitchSectionSpecConfig getSwitchSectionSpecConfig() {
+ return switchSectionSpecConfig;
+ }
+
+ public static boolean accepts(String type){
+ return switch (type) {
+ case "switch" -> true;
+ default -> false;
+ };
+ }
+
+ public static PointSectionConfig fromConfigurationSection(ConfigurationSection configurationSection, String sectionIdentifier) {
+ List> range = configurationSection.getList("at");
+ if(range == null) throw new RuntimeException("Point section " + sectionIdentifier + " requires 'at' keyword to define position of point section");
+
+ int point = (Integer)range.get(0);
+ String trackSource = "default";
+ if(range.size() == 2)
+ trackSource = (String)range.get(1);
+
+ String type = configurationSection.getString("type");
+ String nextSection = configurationSection.getString("nextSection");
+
+ SwitchSectionSpecConfig switchSectionSpecConfig = null;
+ if(configurationSection.contains("switchSpec"))
+ switchSectionSpecConfig = SwitchSectionSpecConfig.fromConfigurationSection(configurationSection.getConfigurationSection("switchSpec"));
+
+ return new PointSectionConfig(sectionIdentifier, point, trackSource, type, nextSection, switchSectionSpecConfig);
+ }
+
+ @Override
+ public SectionReference build(TrackBehaviourFactory trackBehaviourFactory, List trackDescriptions, CoasterHandle coasterHandle,
+ CoasterConfig coasterConfig) {
+ String sectionIdentifier = getIdentifier();
+ String nextSectionIdentifier = getNextSection();
+ String parentTrackIdentifier = getParentTrackIdentifier();
+
+ Frame point = new SimpleFrame(getPoint());
+
+ TrackBehaviour trackBehaviour = trackBehaviourFactory.getTrackBehaviourFor(coasterHandle, coasterConfig, this);
+ if(trackBehaviour == null) return null;
+
+ return new PointSectionReference(sectionIdentifier, point, trackBehaviour, nextSectionIdentifier, parentTrackIdentifier);
+ }
+}
+
diff --git a/src/main/java/com/jverbruggen/jrides/config/coaster/objects/section/base/RangedSectionConfig.java b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/section/base/RangedSectionConfig.java
new file mode 100644
index 00000000..f57c5e23
--- /dev/null
+++ b/src/main/java/com/jverbruggen/jrides/config/coaster/objects/section/base/RangedSectionConfig.java
@@ -0,0 +1,248 @@
+package com.jverbruggen.jrides.config.coaster.objects.section.base;
+
+import com.jverbruggen.jrides.animator.coaster.CoasterHandle;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.TrackBehaviour;
+import com.jverbruggen.jrides.animator.coaster.trackbehaviour.factory.TrackBehaviourFactory;
+import com.jverbruggen.jrides.config.coaster.CoasterConfig;
+import com.jverbruggen.jrides.config.coaster.objects.section.ranged.*;
+import com.jverbruggen.jrides.config.coaster.objects.section.ranged.transfer.TransferSectionSpecConfig;
+import com.jverbruggen.jrides.models.properties.frame.Frame;
+import com.jverbruggen.jrides.models.properties.frame.SimpleFrame;
+import com.jverbruggen.jrides.models.ride.factory.track.TrackDescription;
+import com.jverbruggen.jrides.models.ride.section.reference.RangedSectionReference;
+import com.jverbruggen.jrides.models.ride.section.reference.SectionReference;
+import org.bukkit.configuration.ConfigurationSection;
+
+import java.util.List;
+
+public class RangedSectionConfig extends SectionConfig {
+ private final int lowerRange;
+ private final int upperRange;
+ private final boolean jumpAtStart;
+ private final boolean jumpAtEnd;
+ private final boolean forwards;
+ private final String trackSource;
+ private final String nextSection;
+ private final String arrivalUnlocksSection;
+ private final List conflictSections;
+ private final BlockSectionSpecConfig blockSectionSpec;
+ private final CoasterStationConfig stationSectionSpec;
+ private final BrakeSectionSpecConfig brakeSectionSpec;
+ private final TrimBrakeSectionSpecConfig trimBrakeSectionSpecConfig;
+ private final DriveSectionSpecConfig driveSectionSpec;
+ private final ProximityDriveSectionSpecConfig proximityDriveSectionSpecConfig;
+ private final DriveAndReleaseSectionSpecConfig driveAndReleaseSectionSpecConfig;
+ private final DriveStopDriveSectionSpecConfig driveStopDriveSectionSpecConfig;
+ private final StorageSectionSpecConfig storageSectionSpec;
+ private final TransferSectionSpecConfig transferSectionSpec;
+ private final LaunchSectionSpecConfig launchSectionSpecConfig;
+
+ public RangedSectionConfig(String identifier, int lowerRange, int upperRange, boolean jumpAtStart, boolean jumpAtEnd, boolean forwards, String trackSource, String type,
+ String nextSection, String arrivalUnlocksSection, List conflictSections,
+ BlockSectionSpecConfig blockSectionSpec, CoasterStationConfig stationSectionSpec, BrakeSectionSpecConfig brakeSectionSpec,
+ TrimBrakeSectionSpecConfig trimBrakeSectionSpecConfig, DriveSectionSpecConfig driveSectionSpec, ProximityDriveSectionSpecConfig proximityDriveSectionSpecConfig, StorageSectionSpecConfig storageSectionSpec, TransferSectionSpecConfig transferSectionSpec,
+ LaunchSectionSpecConfig launchSectionSpecConfig, DriveAndReleaseSectionSpecConfig driveAndReleaseSectionSpecConfig, DriveStopDriveSectionSpecConfig driveStopDriveSectionSpecConfig) {
+ super(type, identifier);
+ this.lowerRange = lowerRange;
+ this.upperRange = upperRange;
+ this.jumpAtStart = jumpAtStart;
+ this.jumpAtEnd = jumpAtEnd;
+ this.forwards = forwards;
+ this.trackSource = trackSource;
+ this.nextSection = nextSection;
+ this.arrivalUnlocksSection = arrivalUnlocksSection;
+ this.conflictSections = conflictSections;
+ this.blockSectionSpec = blockSectionSpec;
+ this.stationSectionSpec = stationSectionSpec;
+ this.brakeSectionSpec = brakeSectionSpec;
+ this.trimBrakeSectionSpecConfig = trimBrakeSectionSpecConfig;
+ this.driveSectionSpec = driveSectionSpec;
+ this.proximityDriveSectionSpecConfig = proximityDriveSectionSpecConfig;
+ this.driveAndReleaseSectionSpecConfig = driveAndReleaseSectionSpecConfig;
+ this.storageSectionSpec = storageSectionSpec;
+ this.transferSectionSpec = transferSectionSpec;
+ this.launchSectionSpecConfig = launchSectionSpecConfig;
+ this.driveStopDriveSectionSpecConfig = driveStopDriveSectionSpecConfig;
+ }
+
+ public String getNextSection() {
+ return nextSection;
+ }
+
+ public List