Merge 278c51d056
into 17129f68d2
This commit is contained in:
commit
9efcdbd6ab
|
@ -8,11 +8,15 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: write
|
||||
continue-on-error: true
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: dbelyaev/action-checkstyle@v0.8.4
|
||||
continue-on-error: true
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
checkstyle_version: 10.12.2
|
||||
checkstyle_config: ./config/mv_checks.xml
|
||||
level: warning
|
||||
|
|
|
@ -18,7 +18,7 @@ jobs:
|
|||
|
||||
- uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: '11'
|
||||
java-version: '17'
|
||||
distribution: 'adopt'
|
||||
cache: gradle
|
||||
|
||||
|
|
202
build.gradle
202
build.gradle
|
@ -4,13 +4,18 @@ plugins {
|
|||
id 'java-library'
|
||||
id 'maven-publish'
|
||||
id 'com.github.johnrengelman.shadow' version '7.1.2'
|
||||
id "org.jetbrains.kotlin.jvm" version "1.8.10"
|
||||
}
|
||||
|
||||
version = System.getenv('GITHUB_VERSION') ?: 'local'
|
||||
group = 'com.onarandombox.multiversecore'
|
||||
description = 'Multiverse-Core'
|
||||
|
||||
java.sourceCompatibility = JavaVersion.VERSION_11
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion.set(JavaLanguageVersion.of(17))
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
|
@ -39,37 +44,104 @@ repositories {
|
|||
maven {
|
||||
url = uri('https://repo.maven.apache.org/maven2/')
|
||||
}
|
||||
|
||||
maven {
|
||||
name = 'aikar repo'
|
||||
url = uri('https://repo.aikar.co/content/groups/aikar/')
|
||||
}
|
||||
|
||||
maven {
|
||||
name = 'glaremasters repo'
|
||||
url = 'https://repo.glaremasters.me/repository/towny/'
|
||||
}
|
||||
|
||||
maven {
|
||||
name = 'PlaceholderAPI'
|
||||
url = 'https://repo.extendedclip.com/content/repositories/placeholderapi/'
|
||||
}
|
||||
|
||||
maven {
|
||||
name = 'papermc repo'
|
||||
url = 'https://repo.papermc.io/repository/maven-public/'
|
||||
}
|
||||
}
|
||||
|
||||
configurations {
|
||||
// Add configuration for server API
|
||||
compileOnly.extendsFrom serverApi
|
||||
runtimeClasspath.extendsFrom serverApi
|
||||
|
||||
// Add configuration for external plugins
|
||||
implementation.extendsFrom externalPlugin
|
||||
|
||||
// Add configuration for dependencies that will be included in fat jar
|
||||
compileClasspath.extendsFrom shadowed
|
||||
testCompileClasspath.extendsFrom shadowed
|
||||
testRuntimeClasspath.extendsFrom shadowed
|
||||
oldTestCompileClasspath.extendsFrom shadowed
|
||||
oldTestRuntimeClasspath.extendsFrom shadowed
|
||||
|
||||
// Add configuration for old tests
|
||||
oldTestImplementation.extendsFrom implementation
|
||||
oldTestRuntime.extendsFrom runtime
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.bukkit:bukkit:1.13.2-R0.1-SNAPSHOT'
|
||||
serverApi 'org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT'
|
||||
|
||||
implementation('com.github.MilkBowl:VaultAPI:1.7') {
|
||||
// Economy
|
||||
externalPlugin('com.github.MilkBowl:VaultAPI:1.7.1') {
|
||||
exclude group: 'org.bukkit', module: 'bukkit'
|
||||
}
|
||||
|
||||
compileOnly('me.main__.util:SerializationConfig:1.7') {
|
||||
// PlaceholderAPI
|
||||
externalPlugin 'me.clip:placeholderapi:2.11.3'
|
||||
|
||||
// Command Framework
|
||||
shadowed 'co.aikar:acf-paper:0.5.1-SNAPSHOT'
|
||||
|
||||
// Config
|
||||
shadowed('me.main__.util:SerializationConfig:1.7') {
|
||||
exclude group: 'org.bukkit', module: 'bukkit'
|
||||
}
|
||||
compileOnly('com.pneumaticraft.commandhandler:CommandHandler:11') {
|
||||
exclude group: 'org.bukkit', module: 'bukkit'
|
||||
shadowed('io.github.townyadvanced.commentedconfiguration:CommentedConfiguration:1.0.1') {
|
||||
exclude group: 'org.spigotmc', module: 'spigot-api'
|
||||
}
|
||||
|
||||
// Utils
|
||||
shadowed 'io.vavr:vavr:0.10.4'
|
||||
shadowed 'org.glassfish.hk2:hk2-locator:3.0.3'
|
||||
shadowed('com.dumptruckman.minecraft:Logging:1.1.1') {
|
||||
exclude group: 'junit', module: 'junit'
|
||||
}
|
||||
compileOnly 'com.dumptruckman.minecraft:buscript:2.0-SNAPSHOT'
|
||||
compileOnly 'org.bstats:bstats-bukkit:2.2.1'
|
||||
compileOnly('com.dumptruckman.minecraft:Logging:1.1.1') {
|
||||
exclude group: 'junit', module: 'junit'
|
||||
}
|
||||
compileOnly 'de.themoep.idconverter:mappings:1.2-SNAPSHOT'
|
||||
compileOnly 'org.jetbrains:annotations:16.0.2'
|
||||
shadowed 'de.themoep.idconverter:mappings:1.2-SNAPSHOT'
|
||||
shadowed 'org.bstats:bstats-bukkit:2.2.1'
|
||||
shadowed 'net.minidev:json-smart:2.4.9'
|
||||
shadowed 'org.jetbrains:annotations:22.0.0'
|
||||
shadowed 'io.papermc:paperlib:1.0.8'
|
||||
|
||||
testImplementation 'org.spigotmc:spigot-api:1.19.3-R0.1-SNAPSHOT'
|
||||
// Tests
|
||||
testImplementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.10'
|
||||
testImplementation 'com.github.seeseemelk:MockBukkit-v1.20:3.20.2'
|
||||
testImplementation('com.googlecode.json-simple:json-simple:1.1.1') {
|
||||
exclude group: 'junit', module: 'junit'
|
||||
}
|
||||
testImplementation 'junit:junit:4.12'
|
||||
testImplementation 'org.mockito:mockito-core:3.11.2'
|
||||
testImplementation 'commons-io:commons-io:2.4'
|
||||
testImplementation 'org.jetbrains.kotlin:kotlin-test'
|
||||
testImplementation 'com.natpryce:hamkrest:1.8.0.1'
|
||||
testImplementation 'org.mockito.kotlin:mockito-kotlin:4.1.0'
|
||||
|
||||
// Old Tests
|
||||
oldTestImplementation 'org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT'
|
||||
oldTestImplementation('com.googlecode.json-simple:json-simple:1.1.1') {
|
||||
exclude group: 'junit', module: 'junit'
|
||||
}
|
||||
oldTestImplementation 'junit:junit:4.13.1'
|
||||
oldTestImplementation 'org.mockito:mockito-core:3.11.2'
|
||||
oldTestImplementation 'commons-io:commons-io:2.7'
|
||||
|
||||
// Annotation Processors
|
||||
annotationProcessor 'org.glassfish.hk2:hk2-metadata-generator:3.0.3'
|
||||
testAnnotationProcessor 'org.glassfish.hk2:hk2-metadata-generator:3.0.3'
|
||||
}
|
||||
|
||||
|
||||
|
@ -92,28 +164,52 @@ configurations {
|
|||
it.outgoing.artifacts.removeIf { it.buildDependencies.getDependencies(null).contains(jar) }
|
||||
it.outgoing.artifact(shadowJar)
|
||||
}
|
||||
}
|
||||
|
||||
testCompileOnly.extendsFrom compileOnly
|
||||
testRuntimeOnly.extendsFrom testCompileOnly
|
||||
|
||||
shadowed.extendsFrom compileOnly {
|
||||
canBeResolved = true
|
||||
sourceSets {
|
||||
oldTest {
|
||||
java {
|
||||
compileClasspath += main.output
|
||||
runtimeClasspath += main.output
|
||||
srcDir file('src/old-test/java')
|
||||
}
|
||||
resources.srcDir file('src/old-test/resources')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
maven(MavenPublication) {
|
||||
from components.java
|
||||
|
||||
pom.withXml {
|
||||
asNode().dependencies.'*'.findAll() {
|
||||
it.scope.text() == 'runtime' && project.configurations.implementation.allDependencies.find { dep ->
|
||||
dep.name == it.artifactId.text()
|
||||
}
|
||||
Node pomNode = asNode()
|
||||
|
||||
// Remove Kotlin dependency
|
||||
pomNode.dependencies.'*'.findAll() {
|
||||
it.groupId.text() == 'org.jetbrains.kotlin'
|
||||
}.each() {
|
||||
it.parent().remove(it)
|
||||
}
|
||||
|
||||
// Switch runtime deps to provided
|
||||
pomNode.dependencies.'*'.findAll() {
|
||||
it.scope.text() == 'runtime'
|
||||
}.each() {
|
||||
it.scope*.value = 'provided'
|
||||
}
|
||||
|
||||
// Add spigot api to pom
|
||||
project.configurations.serverApi.allDependencies.each { dependency ->
|
||||
pomNode.dependencies[0].appendNode("dependency").with {
|
||||
it.appendNode("groupId", dependency.group)
|
||||
it.appendNode("artifactId", dependency.name)
|
||||
it.appendNode("version", dependency.version)
|
||||
it.appendNode("scope", "provided")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -144,6 +240,19 @@ task prepareSource(type: Sync) {
|
|||
compileJava {
|
||||
source = prepareSource.outputs
|
||||
}
|
||||
tasks.withType(JavaCompile) {
|
||||
configure(options) {
|
||||
options.compilerArgs << '-Aorg.glassfish.hk2.metadata.location=META-INF/hk2-locator/Multiverse-Core'
|
||||
}
|
||||
}
|
||||
|
||||
compileKotlin {
|
||||
// We're not using Kotlin in the plugin itself, just tests!
|
||||
enabled = false
|
||||
}
|
||||
configurations.findAll { !it.name.startsWith('test') }.each {
|
||||
it.exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk8'
|
||||
}
|
||||
|
||||
processResources {
|
||||
def props = [version: "${project.version}"]
|
||||
|
@ -168,20 +277,45 @@ javadoc {
|
|||
project.configurations.api.canBeResolved = true
|
||||
|
||||
shadowJar {
|
||||
relocate 'me.main__.util', 'com.onarandombox.serializationconfig'
|
||||
relocate 'com.pneumaticraft.commandhandler', 'com.onarandombox.commandhandler'
|
||||
relocate 'buscript', 'com.onarandombox.buscript'
|
||||
relocate 'org.bstats', 'com.onarandombox.bstats'
|
||||
relocate 'com.dumptruckman.minecraft.util.Logging', 'com.onarandombox.MultiverseCore.utils.CoreLogging'
|
||||
relocate 'com.dumptruckman.minecraft.util.DebugLog', 'com.onarandombox.MultiverseCore.utils.DebugFileLogger'
|
||||
relocate 'org.codehaus.jettison', 'com.onarandombox.jettison'
|
||||
relocate 'de.themoep.idconverter', 'com.onarandombox.idconverter'
|
||||
relocate 'co.aikar', 'org.mvplugins.multiverse.external.acf'
|
||||
relocate 'com.dumptruckman.minecraft.util.Logging', 'org.mvplugins.multiverse.core.utils.CoreLogging'
|
||||
relocate 'com.dumptruckman.minecraft.util.DebugLog', 'org.mvplugins.multiverse.core.utils.DebugFileLogger'
|
||||
relocate 'de.themoep.idconverter', 'org.mvplugins.multiverse.external.idconverter'
|
||||
relocate 'io.github.townyadvanced.commentedconfiguration', 'org.mvplugins.multiverse.external.commentedconfiguration'
|
||||
relocate 'me.main__.util', 'org.mvplugins.multiverse.external.serializationconfig'
|
||||
relocate 'org.bstats', 'org.mvplugins.multiverse.external.bstats'
|
||||
relocate 'com.sun', 'org.mvplugins.multiverse.external.sun'
|
||||
relocate 'net.minidev', 'org.mvplugins.multiverse.external.minidev'
|
||||
relocate 'org.objectweb', 'org.mvplugins.multiverse.external.objectweb'
|
||||
relocate 'io.vavr', 'org.mvplugins.multiverse.external.vavr'
|
||||
relocate 'jakarta', 'org.mvplugins.multiverse.external.jakarta'
|
||||
relocate 'javassist', 'org.mvplugins.multiverse.external.javassist'
|
||||
relocate 'org.aopalliance', 'org.mvplugins.multiverse.external.aopalliance'
|
||||
relocate 'org.glassfish', 'org.mvplugins.multiverse.external.glassfish'
|
||||
relocate 'org.jvnet', 'org.mvplugins.multiverse.external.jvnet'
|
||||
relocate 'org.intellij', 'org.mvplugins.multiverse.external.intellij'
|
||||
relocate 'org.jetbrains', 'org.mvplugins.multiverse.external.jetbrains'
|
||||
relocate 'io.papermc.lib', 'org.mvplugins.multiverse.external.paperlib'
|
||||
|
||||
configurations = [project.configurations.shadowed]
|
||||
|
||||
archiveFileName = "$baseName-$version.$extension"
|
||||
classifier = ''
|
||||
|
||||
dependencies {
|
||||
exclude(dependency {
|
||||
it.moduleGroup == 'org.jetbrains.kotlin'
|
||||
})
|
||||
}
|
||||
//classifier = ''
|
||||
}
|
||||
|
||||
build.dependsOn shadowJar
|
||||
jar.enabled = false
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
|
||||
testLogging {
|
||||
exceptionFormat = 'full'
|
||||
}
|
||||
}
|
||||
|
|
|
@ -145,7 +145,10 @@
|
|||
<module name="AvoidDoubleBraceInitialization"/>
|
||||
<module name="AvoidNoArgumentSuperConstructorCall"/>
|
||||
<module name="CovariantEquals"/>
|
||||
<module name="DeclarationOrder"/>
|
||||
<module name="DeclarationOrder">
|
||||
<!-- Doesn't respect static methods at top -->
|
||||
<property name="severity" value="ignore"/>
|
||||
</module>
|
||||
<module name="DefaultComesLast"/>
|
||||
<module name="EmptyStatement"/>
|
||||
<module name="EqualsAvoidNull"/>
|
||||
|
@ -158,6 +161,8 @@
|
|||
<property name="ignoreSetter" value="true"/>
|
||||
<property name="setterCanReturnItsClass" value="true"/>
|
||||
<property name="ignoreAbstractMethods" value="true"/>
|
||||
<!-- Not smart enough -->
|
||||
<property name="severity" value="ignore"/>
|
||||
</module>
|
||||
<module name="IllegalCatch"/>
|
||||
<module name="IllegalThrows"/>
|
||||
|
@ -192,7 +197,9 @@
|
|||
<module name="PackageDeclaration"/>
|
||||
<module name="ParameterAssignment"/>
|
||||
<module name="RequireThis"/>
|
||||
<module name="ReturnCount"/>
|
||||
<module name="ReturnCount">
|
||||
<property name="severity" value="info"/>
|
||||
</module>
|
||||
<module name="SimplifyBooleanExpression"/>
|
||||
<module name="SimplifyBooleanReturn"/>
|
||||
<module name="StringLiteralEquality"/>
|
||||
|
@ -215,18 +222,21 @@
|
|||
|
||||
<!-- Imports -->
|
||||
<module name="AvoidStarImport"/>
|
||||
<module name="CustomImportOrder">
|
||||
<property name="sortImportsInGroupAlphabetically" value="true"/>
|
||||
<property name="separateLineBetweenGroups" value="true"/>
|
||||
<property name="customImportOrderRules"
|
||||
value="THIRD_PARTY_PACKAGE###STANDARD_JAVA_PACKAGE###STATIC"/>
|
||||
<!-- value="SAME_PACKAGE(3)###THIRD_PARTY_PACKAGE###STANDARD_JAVA_PACKAGE###STATIC"/>-->
|
||||
<property name="tokens" value="IMPORT, STATIC_IMPORT, PACKAGE_DEF"/>
|
||||
</module>
|
||||
<module name="IllegalImport">
|
||||
<property name="illegalPkgs" value="sun"/>
|
||||
</module>
|
||||
<!-- <module name="ImportOrder"/>-->
|
||||
<module name="ImportOrder">
|
||||
<property name="option" value="bottom"/>
|
||||
<property name="ordered" value="true"/>
|
||||
<property name="separated" value="true"/>
|
||||
<property name="separatedStaticGroups" value="true"/>
|
||||
<property name="caseSensitive" value="true"/>
|
||||
<property name="sortStaticImportsAlphabetically" value="true"/>
|
||||
<property name="groups"
|
||||
value="java,javax,*,org.mvplugins"/>
|
||||
<property name="staticGroups"
|
||||
value="/^.*$/"/>
|
||||
</module>
|
||||
<module name="RedundantImport"/>
|
||||
<module name="UnusedImports"/>
|
||||
|
||||
|
@ -297,11 +307,48 @@
|
|||
<module name="BooleanExpressionComplexity"/>
|
||||
<module name="ClassDataAbstractionCoupling">
|
||||
<property name="max" value="7"/>
|
||||
<property name="excludedClasses" value="ArrayIndexOutOfBoundsException, ArrayList, Boolean, Byte, Character, Class, Collection, Deprecated, Deque, Double, DoubleStream, EnumSet, Exception, Float, FunctionalInterface, HashMap, HashSet, IllegalArgumentException, IllegalStateException, IndexOutOfBoundsException, IntStream, Integer, LinkedHashMap, LinkedHashSet, LinkedList, List, Long, LongStream, Map, NullPointerException, Object, Optional, OptionalDouble, OptionalInt, OptionalLong, Override, Queue, RuntimeException, SafeVarargs, SecurityException, Set, Short, SortedMap, SortedSet, Stream, String, StringBuffer, StringBuilder, SuppressWarnings, Throwable, TreeMap, TreeSet, UnsupportedOperationException, Void, boolean, byte, char, double, float, int, long, short, var, void"/>
|
||||
<property name="excludedClasses"
|
||||
value="ArrayIndexOutOfBoundsException, ArrayList, Boolean, Byte, Character,
|
||||
Class, Collection, Deprecated, Deque, Double, DoubleStream, EnumSet, Exception,
|
||||
Float, FunctionalInterface, HashMap, HashSet, IllegalArgumentException,
|
||||
IllegalStateException, IndexOutOfBoundsException, IntStream, Integer,
|
||||
LinkedHashMap, LinkedHashSet, LinkedList, List, Long, LongStream, Map,
|
||||
NullPointerException, Object, Optional, OptionalDouble, OptionalInt,
|
||||
OptionalLong, Override, Queue, RuntimeException, SafeVarargs, SecurityException,
|
||||
Set, Short, SortedMap, SortedSet, Stream, String, StringBuffer, StringBuilder,
|
||||
SuppressWarnings, Throwable, TreeMap, TreeSet, UnsupportedOperationException,
|
||||
Void, boolean, byte, char, double, float, int, long, short, var, void"/>
|
||||
</module>
|
||||
<module name="ClassFanOutComplexity">
|
||||
<property name="id" value="FanOutComplexityGettingTooHigh"/>
|
||||
<property name="max" value="20"/>
|
||||
<property name="excludedClasses" value="ArrayIndexOutOfBoundsException, ArrayList, Boolean, Byte, Character, Class, Collection, Deprecated, Deque, Double, DoubleStream, EnumSet, Exception, Float, FunctionalInterface, HashMap, HashSet, IllegalArgumentException, IllegalStateException, IndexOutOfBoundsException, IntStream, Integer, LinkedHashMap, LinkedHashSet, LinkedList, List, Long, LongStream, Map, NullPointerException, Object, Optional, OptionalDouble, OptionalInt, OptionalLong, Override, Queue, RuntimeException, SafeVarargs, SecurityException, Set, Short, SortedMap, SortedSet, Stream, String, StringBuffer, StringBuilder, SuppressWarnings, Throwable, TreeMap, TreeSet, UnsupportedOperationException, Void, boolean, byte, char, double, float, int, long, short, var, void"/>
|
||||
<property name="excludedClasses"
|
||||
value="ArrayIndexOutOfBoundsException, ArrayList, Boolean, Byte, Character,
|
||||
Class, Collection, Deprecated, Deque, Double, DoubleStream, EnumSet, Exception,
|
||||
Float, FunctionalInterface, HashMap, HashSet, IllegalArgumentException,
|
||||
IllegalStateException, IndexOutOfBoundsException, IntStream, Integer,
|
||||
LinkedHashMap, LinkedHashSet, LinkedList, List, Long, LongStream, Map,
|
||||
NullPointerException, Object, Optional, OptionalDouble, OptionalInt,
|
||||
OptionalLong, Override, Queue, RuntimeException, SafeVarargs, SecurityException,
|
||||
Set, Short, SortedMap, SortedSet, Stream, String, StringBuffer, StringBuilder,
|
||||
SuppressWarnings, Throwable, TreeMap, TreeSet, UnsupportedOperationException,
|
||||
Void, boolean, byte, char, double, float, int, long, short, var, void"/>
|
||||
<property name="severity" value="info"/>
|
||||
</module>
|
||||
<module name="ClassFanOutComplexity">
|
||||
<property name="id" value="FanOutComplexityProbablyTooHigh"/>
|
||||
<property name="max" value="35"/>
|
||||
<property name="excludedClasses"
|
||||
value="ArrayIndexOutOfBoundsException, ArrayList, Boolean, Byte, Character,
|
||||
Class, Collection, Deprecated, Deque, Double, DoubleStream, EnumSet, Exception,
|
||||
Float, FunctionalInterface, HashMap, HashSet, IllegalArgumentException,
|
||||
IllegalStateException, IndexOutOfBoundsException, IntStream, Integer,
|
||||
LinkedHashMap, LinkedHashSet, LinkedList, List, Long, LongStream, Map,
|
||||
NullPointerException, Object, Optional, OptionalDouble, OptionalInt,
|
||||
OptionalLong, Override, Queue, RuntimeException, SafeVarargs, SecurityException,
|
||||
Set, Short, SortedMap, SortedSet, Stream, String, StringBuffer, StringBuilder,
|
||||
SuppressWarnings, Throwable, TreeMap, TreeSet, UnsupportedOperationException,
|
||||
Void, boolean, byte, char, double, float, int, long, short, var, void"/>
|
||||
</module>
|
||||
<module name="CyclomaticComplexity">
|
||||
<property name="max" value="7"/>
|
||||
|
@ -339,9 +386,12 @@
|
|||
<module name="OuterTypeFilename"/>
|
||||
<module name="TodoComment">
|
||||
<property name="format" value="TODO"/>
|
||||
<property name="severity" value="warning"/>
|
||||
<!-- TODO change back to warning after MV5 -->
|
||||
<property name="severity" value="info"/>
|
||||
</module>
|
||||
<module name="TrailingComment">
|
||||
<property name="legalComment" value="^\sSUPPRESS CHECKSTYLE:"/>
|
||||
</module>
|
||||
<module name="TrailingComment"/>
|
||||
<module name="UncommentedMain"/>
|
||||
<module name="UpperEll"/>
|
||||
|
||||
|
@ -360,6 +410,7 @@
|
|||
RECORD_COMPONENT_DEF"/>
|
||||
</module>
|
||||
<module name="AbstractClassName">
|
||||
<property name="ignoreName" value="true"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Abstract class name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
|
@ -398,7 +449,7 @@
|
|||
value="Local variable name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="MemberName">
|
||||
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
|
||||
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$|^[A-Z][A-Z0-9_]*$"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Member name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
|
@ -412,6 +463,7 @@
|
|||
value="Method type name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="PackageName">
|
||||
<property name="severity" value="info"/>
|
||||
<property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
|
||||
<message key="name.invalidPattern"
|
||||
value="Package name ''{0}'' must match pattern ''{1}''."/>
|
||||
|
@ -455,7 +507,13 @@
|
|||
<property name="max" value="30"/>
|
||||
</module>
|
||||
<module name="LambdaBodyLength">
|
||||
<property name="id" value="LambdaGettingTooLong"/>
|
||||
<property name="max" value="10"/>
|
||||
<property name="severity" value="info"/>
|
||||
</module>
|
||||
<module name="LambdaBodyLength">
|
||||
<property name="id" value="LambdaProbablyTooLong"/>
|
||||
<property name="max" value="25"/>
|
||||
</module>
|
||||
<module name="MethodCount">
|
||||
<property name="maxTotal" value="100"/>
|
||||
|
@ -472,9 +530,30 @@
|
|||
<property name="max" value="1"/>
|
||||
</module>
|
||||
<module name="ParameterNumber">
|
||||
<property name="max" value="3"/>
|
||||
<property name="id" value="ConsiderLessMethodParameters"/>
|
||||
<property name="max" value="4"/>
|
||||
<property name="ignoreOverriddenMethods" value="true"/>
|
||||
<property name="severity" value="warning"/>
|
||||
<property name="severity" value="info"/>
|
||||
<property name="tokens" value="METHOD_DEF"/>
|
||||
</module>
|
||||
<module name="ParameterNumber">
|
||||
<property name="id" value="ProbablyTooManyMethodParameters"/>
|
||||
<property name="max" value="10"/>
|
||||
<property name="ignoreOverriddenMethods" value="true"/>
|
||||
<property name="tokens" value="METHOD_DEF"/>
|
||||
</module>
|
||||
<module name="ParameterNumber">
|
||||
<property name="id" value="ConsiderLessConstructorParameters"/>
|
||||
<property name="max" value="7"/>
|
||||
<property name="ignoreOverriddenMethods" value="true"/>
|
||||
<property name="severity" value="info"/>
|
||||
<property name="tokens" value="CTOR_DEF"/>
|
||||
</module>
|
||||
<module name="ParameterNumber">
|
||||
<property name="id" value="ProbablyTooManyConstructorParameters"/>
|
||||
<property name="max" value="12"/>
|
||||
<property name="ignoreOverriddenMethods" value="true"/>
|
||||
<property name="tokens" value="CTOR_DEF"/>
|
||||
</module>
|
||||
<module name="RecordComponentNumber">
|
||||
<property name="max" value="8"/>
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package co.aikar.commands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* Exists just so we can extend BukkitCommandIssuer since it has a package-private constructor.
|
||||
*/
|
||||
public abstract class OpenBukkitCommandIssuer extends BukkitCommandIssuer {
|
||||
|
||||
protected OpenBukkitCommandIssuer(BukkitCommandManager manager, CommandSender sender) {
|
||||
super(manager, sender);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,385 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseCoreConfig;
|
||||
import com.onarandombox.MultiverseCore.event.MVDebugModeEvent;
|
||||
import me.main__.util.SerializationConfig.NoSuchPropertyException;
|
||||
import me.main__.util.SerializationConfig.Property;
|
||||
import me.main__.util.SerializationConfig.SerializationConfig;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
/**
|
||||
* Our configuration.
|
||||
*/
|
||||
public class MultiverseCoreConfiguration extends SerializationConfig implements MultiverseCoreConfig {
|
||||
private static MultiverseCoreConfiguration instance;
|
||||
|
||||
/**
|
||||
* Sets the statically saved instance.
|
||||
* @param instance The new instance.
|
||||
*/
|
||||
public static void setInstance(MultiverseCoreConfiguration instance) {
|
||||
MultiverseCoreConfiguration.instance = instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return True if the static instance of config is set.
|
||||
*/
|
||||
public static boolean isSet() {
|
||||
return instance != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the statically saved instance.
|
||||
* @return The statically saved instance.
|
||||
*/
|
||||
public static MultiverseCoreConfiguration getInstance() {
|
||||
if (instance == null)
|
||||
throw new IllegalStateException("The instance wasn't set!");
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Property
|
||||
private volatile boolean enforceaccess;
|
||||
@Property
|
||||
private volatile boolean prefixchat;
|
||||
@Property
|
||||
private volatile String prefixchatformat;
|
||||
@Property
|
||||
private volatile boolean useasyncchat;
|
||||
@Property
|
||||
private volatile boolean teleportintercept;
|
||||
@Property
|
||||
private volatile boolean firstspawnoverride;
|
||||
@Property
|
||||
private volatile boolean displaypermerrors;
|
||||
@Property
|
||||
private volatile boolean enablebuscript;
|
||||
@Property
|
||||
private volatile int globaldebug;
|
||||
@Property
|
||||
private volatile boolean silentstart;
|
||||
@Property
|
||||
private volatile int messagecooldown;
|
||||
@Property
|
||||
private volatile double version;
|
||||
@Property
|
||||
private volatile String firstspawnworld;
|
||||
@Property
|
||||
private volatile int teleportcooldown;
|
||||
@Property
|
||||
private volatile boolean defaultportalsearch;
|
||||
@Property
|
||||
private volatile int portalsearchradius;
|
||||
@Property
|
||||
private volatile boolean autopurge;
|
||||
@Property
|
||||
private volatile boolean idonotwanttodonate;
|
||||
|
||||
public MultiverseCoreConfiguration() {
|
||||
super();
|
||||
MultiverseCoreConfiguration.setInstance(this);
|
||||
}
|
||||
|
||||
public MultiverseCoreConfiguration(Map<String, Object> values) {
|
||||
super(values);
|
||||
MultiverseCoreConfiguration.setInstance(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void setDefaults() {
|
||||
// BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck
|
||||
enforceaccess = false;
|
||||
useasyncchat = true;
|
||||
prefixchat = false;
|
||||
prefixchatformat = "[%world%]%chat%";
|
||||
teleportintercept = true;
|
||||
firstspawnoverride = true;
|
||||
displaypermerrors = true;
|
||||
enablebuscript = true;
|
||||
globaldebug = 0;
|
||||
messagecooldown = 5000;
|
||||
teleportcooldown = 1000;
|
||||
this.version = 2.9;
|
||||
silentstart = false;
|
||||
defaultportalsearch = true;
|
||||
portalsearchradius = 128;
|
||||
autopurge = true;
|
||||
idonotwanttodonate = false;
|
||||
// END CHECKSTYLE-SUPPRESSION: MagicNumberCheck
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean setConfigProperty(String property, String value) {
|
||||
try {
|
||||
return this.setProperty(property, value, true);
|
||||
} catch (NoSuchPropertyException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// And here we go:
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean getEnforceAccess() {
|
||||
return this.enforceaccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setEnforceAccess(boolean enforceAccess) {
|
||||
this.enforceaccess = enforceAccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean getPrefixChat() {
|
||||
return this.prefixchat;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setPrefixChat(boolean prefixChat) {
|
||||
this.prefixchat = prefixChat;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getPrefixChatFormat() {
|
||||
return this.prefixchatformat;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setPrefixChatFormat(String prefixChatFormat) {
|
||||
this.prefixchatformat = prefixChatFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean getTeleportIntercept() {
|
||||
return this.teleportintercept;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setTeleportIntercept(boolean teleportIntercept) {
|
||||
this.teleportintercept = teleportIntercept;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean getFirstSpawnOverride() {
|
||||
return this.firstspawnoverride;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setFirstSpawnOverride(boolean firstSpawnOverride) {
|
||||
this.firstspawnoverride = firstSpawnOverride;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean getDisplayPermErrors() {
|
||||
return this.displaypermerrors;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean getEnableBuscript() {
|
||||
return this.enablebuscript;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setEnableBuscript(boolean enableBuscript) {
|
||||
this.enablebuscript = enableBuscript;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setDisplayPermErrors(boolean displayPermErrors) {
|
||||
this.displaypermerrors = displayPermErrors;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getGlobalDebug() {
|
||||
return this.globaldebug;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setGlobalDebug(int globalDebug) {
|
||||
this.globaldebug = globalDebug;
|
||||
Logging.setDebugLevel(globalDebug);
|
||||
Bukkit.getPluginManager().callEvent(new MVDebugModeEvent(globalDebug));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getMessageCooldown() {
|
||||
return this.messagecooldown;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setMessageCooldown(int messageCooldown) {
|
||||
this.messagecooldown = messageCooldown;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public double getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setVersion(int version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getFirstSpawnWorld() {
|
||||
return this.firstspawnworld;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setFirstSpawnWorld(String firstSpawnWorld) {
|
||||
this.firstspawnworld = firstSpawnWorld;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getTeleportCooldown() {
|
||||
return this.teleportcooldown;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setTeleportCooldown(int teleportCooldown) {
|
||||
this.teleportcooldown = teleportCooldown;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUseAsyncChat(boolean useAsyncChat) {
|
||||
this.useasyncchat = useAsyncChat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getUseAsyncChat() {
|
||||
return this.useasyncchat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSilentStart(boolean silentStart) {
|
||||
Logging.setShowingConfig(!silentStart);
|
||||
this.silentstart = silentStart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getSilentStart() {
|
||||
return silentstart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUseDefaultPortalSearch(boolean useDefaultPortalSearch) {
|
||||
defaultportalsearch = useDefaultPortalSearch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsingDefaultPortalSearch() {
|
||||
return defaultportalsearch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPortalSearchRadius(int searchRadius) {
|
||||
this.portalsearchradius = searchRadius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPortalSearchRadius() {
|
||||
return portalsearchradius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAutoPurgeEnabled() {
|
||||
return autopurge;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAutoPurgeEnabled(boolean autopurge) {
|
||||
this.autopurge = autopurge;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShowingDonateMessage() {
|
||||
return !idonotwanttodonate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShowDonateMessage(boolean showDonateMessage) {
|
||||
this.idonotwanttodonate = !showDonateMessage;
|
||||
}
|
||||
}
|
|
@ -1,655 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MVWorld.NullLocation;
|
||||
import com.onarandombox.MultiverseCore.configuration.EntryFee;
|
||||
import com.onarandombox.MultiverseCore.configuration.SpawnLocation;
|
||||
import com.onarandombox.MultiverseCore.configuration.SpawnSettings;
|
||||
import com.onarandombox.MultiverseCore.configuration.WorldPropertyValidator;
|
||||
import com.onarandombox.MultiverseCore.enums.AllowedPortalType;
|
||||
import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
|
||||
import com.onarandombox.MultiverseCore.enums.EnglishChatStyle;
|
||||
import me.main__.util.SerializationConfig.IllegalPropertyValueException;
|
||||
import me.main__.util.SerializationConfig.Property;
|
||||
import me.main__.util.SerializationConfig.SerializationConfig;
|
||||
import me.main__.util.SerializationConfig.Serializor;
|
||||
import me.main__.util.SerializationConfig.Validator;
|
||||
import me.main__.util.SerializationConfig.VirtualProperty;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Difficulty;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.configuration.serialization.SerializableAs;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/*
|
||||
* This is a property class, I think we don't need that much javadoc.
|
||||
* BEGIN CHECKSTYLE-SUPPRESSION: Javadoc
|
||||
*/
|
||||
|
||||
@SerializableAs("MVWorld")
|
||||
public class WorldProperties extends SerializationConfig {
|
||||
|
||||
private static final Map<String, String> PROPERTY_ALIASES;
|
||||
|
||||
static {
|
||||
PROPERTY_ALIASES = new HashMap<String, String>();
|
||||
PROPERTY_ALIASES.put("curr", "entryfee.currency");
|
||||
PROPERTY_ALIASES.put("currency", "entryfee.currency");
|
||||
PROPERTY_ALIASES.put("price", "entryfee.amount");
|
||||
PROPERTY_ALIASES.put("scaling", "scale");
|
||||
PROPERTY_ALIASES.put("aliascolor", "color");
|
||||
PROPERTY_ALIASES.put("heal", "autoHeal");
|
||||
PROPERTY_ALIASES.put("storm", "allowWeather");
|
||||
PROPERTY_ALIASES.put("weather", "allowWeather");
|
||||
PROPERTY_ALIASES.put("spawnmemory", "keepSpawnInMemory");
|
||||
PROPERTY_ALIASES.put("memory", "keepSpawnInMemory");
|
||||
PROPERTY_ALIASES.put("mode", "gameMode");
|
||||
PROPERTY_ALIASES.put("diff", "difficulty");
|
||||
PROPERTY_ALIASES.put("spawnlocation", "spawn");
|
||||
PROPERTY_ALIASES.put("limit", "playerLimit");
|
||||
PROPERTY_ALIASES.put("animals", "spawning.animals.spawn");
|
||||
PROPERTY_ALIASES.put("monsters", "spawning.monsters.spawn");
|
||||
PROPERTY_ALIASES.put("animalsrate", "spawning.animals.spawnrate");
|
||||
PROPERTY_ALIASES.put("monstersrate", "spawning.monsters.spawnrate");
|
||||
PROPERTY_ALIASES.put("flight", "allowFlight");
|
||||
PROPERTY_ALIASES.put("fly", "allowFlight");
|
||||
PROPERTY_ALIASES.put("allowfly", "allowFlight");
|
||||
}
|
||||
|
||||
private final boolean keepSpawnFallback;
|
||||
|
||||
public WorldProperties(Map<String, Object> values) {
|
||||
super(values);
|
||||
Object keepSpawnObject = values.get("keepSpawnInMemory");
|
||||
keepSpawnFallback = keepSpawnObject == null || Boolean.parseBoolean(keepSpawnObject.toString());
|
||||
}
|
||||
|
||||
public WorldProperties() {
|
||||
super();
|
||||
keepSpawnFallback = true;
|
||||
}
|
||||
|
||||
public WorldProperties(final boolean fixSpawn, final Environment environment) {
|
||||
super();
|
||||
if (!fixSpawn) {
|
||||
this.adjustSpawn = false;
|
||||
}
|
||||
setScaling(getDefaultScale(environment));
|
||||
keepSpawnFallback = true;
|
||||
}
|
||||
|
||||
void setMVWorld(MVWorld world) {
|
||||
registerObjectUsing(world);
|
||||
registerGlobalValidator(new WorldPropertyValidator());
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializor for the color-property.
|
||||
*/
|
||||
private static final class EnumPropertySerializor<T extends Enum<T>> implements Serializor<T, String> {
|
||||
@Override
|
||||
public String serialize(T from) {
|
||||
return from.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T deserialize(String serialized, Class<T> wanted) throws IllegalPropertyValueException {
|
||||
try {
|
||||
return Enum.valueOf(wanted, serialized.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new IllegalPropertyValueException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializor for the difficulty-property.
|
||||
*/
|
||||
private static final class DifficultyPropertySerializor implements Serializor<Difficulty, String> {
|
||||
@Override
|
||||
public String serialize(Difficulty from) {
|
||||
return from.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Difficulty deserialize(String serialized, Class<Difficulty> wanted) throws IllegalPropertyValueException {
|
||||
try {
|
||||
return Difficulty.getByValue(Integer.parseInt(serialized));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
try {
|
||||
return Difficulty.valueOf(serialized.toUpperCase());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
throw new IllegalPropertyValueException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializor for the gameMode-property.
|
||||
*/
|
||||
private static final class GameModePropertySerializor implements Serializor<GameMode, String> {
|
||||
@Override
|
||||
public String serialize(GameMode from) {
|
||||
return from.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameMode deserialize(String serialized, Class<GameMode> wanted) throws IllegalPropertyValueException {
|
||||
try {
|
||||
return GameMode.getByValue(Integer.parseInt(serialized));
|
||||
} catch (NumberFormatException nfe) {
|
||||
}
|
||||
try {
|
||||
return GameMode.valueOf(serialized.toUpperCase());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
throw new IllegalPropertyValueException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializor for the time-property.
|
||||
*/
|
||||
private static final class TimePropertySerializor implements Serializor<Long, String> {
|
||||
// BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck
|
||||
private static final String TIME_REGEX = "(\\d\\d?):?(\\d\\d)(a|p)?m?";
|
||||
private static final Map<String, String> TIME_ALIASES;
|
||||
static {
|
||||
Map<String, String> staticTimes = new HashMap<String, String>();
|
||||
staticTimes.put("morning", "8:00");
|
||||
staticTimes.put("day", "12:00");
|
||||
staticTimes.put("noon", "12:00");
|
||||
staticTimes.put("midnight", "0:00");
|
||||
staticTimes.put("night", "20:00");
|
||||
|
||||
// now set TIME_ALIASES to a "frozen" map
|
||||
TIME_ALIASES = Collections.unmodifiableMap(staticTimes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize(Long from) {
|
||||
// I'm tired, so they get time in 24 hour for now.
|
||||
// Someone else can add 12 hr format if they want :P
|
||||
|
||||
int hours = (int) ((from / 1000 + 8) % 24);
|
||||
int minutes = (int) (60 * (from % 1000) / 1000);
|
||||
|
||||
return String.format("%d:%02d", hours, minutes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long deserialize(String serialized, Class<Long> wanted) throws IllegalPropertyValueException {
|
||||
if (TIME_ALIASES.containsKey(serialized.toLowerCase())) {
|
||||
serialized = TIME_ALIASES.get(serialized.toLowerCase());
|
||||
}
|
||||
// Regex that extracts a time in the following formats:
|
||||
// 11:11pm, 11:11, 23:11, 1111, 1111p, and the aliases at the top of this file.
|
||||
Pattern pattern = Pattern.compile(TIME_REGEX, Pattern.CASE_INSENSITIVE);
|
||||
Matcher matcher = pattern.matcher(serialized);
|
||||
matcher.find();
|
||||
int hour = 0;
|
||||
double minute = 0;
|
||||
int count = matcher.groupCount();
|
||||
if (count >= 2) {
|
||||
hour = Integer.parseInt(matcher.group(1));
|
||||
minute = Integer.parseInt(matcher.group(2));
|
||||
}
|
||||
// If there were 4 matches (all, hour, min, am/pm)
|
||||
if (count == 4) {
|
||||
// We want 24 hour time for calcs, but if they
|
||||
// added a p[m], turn it into a 24 hr one.
|
||||
if (matcher.group(3).equals("p")) {
|
||||
hour += 12;
|
||||
}
|
||||
}
|
||||
// Translate 24th hour to 0th hour.
|
||||
if (hour == 24) {
|
||||
hour = 0;
|
||||
}
|
||||
// Clamp the hour
|
||||
if (hour > 23 || hour < 0) {
|
||||
throw new IllegalPropertyValueException("Illegal hour!");
|
||||
}
|
||||
// Clamp the minute
|
||||
if (minute > 59 || minute < 0) {
|
||||
throw new IllegalPropertyValueException("Illegal minute!");
|
||||
}
|
||||
// 60 seconds in a minute, time needs to be in hrs * 1000, per
|
||||
// the bukkit docs.
|
||||
double totaltime = (hour + (minute / 60.0)) * 1000;
|
||||
// Somehow there's an 8 hour offset...
|
||||
totaltime -= 8000;
|
||||
if (totaltime < 0) {
|
||||
totaltime = 24000 + totaltime;
|
||||
}
|
||||
|
||||
return (long) totaltime;
|
||||
}
|
||||
// END CHECKSTYLE-SUPPRESSION: MagicNumberCheck
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// Begin properties
|
||||
@Property(description = "Sorry, 'hidden' must either be: true or false.")
|
||||
private volatile boolean hidden;
|
||||
@Property(description = "Alias must be a valid string.")
|
||||
private volatile String alias;
|
||||
@Property(serializor = EnumPropertySerializor.class, description = "Sorry, 'color' must be a valid color-name.")
|
||||
private volatile EnglishChatColor color;
|
||||
@Property(serializor = EnumPropertySerializor.class, description = "Sorry, 'style' must be a valid style-name.")
|
||||
private volatile EnglishChatStyle style;
|
||||
@Property(description = "Sorry, 'pvp' must either be: true or false.", virtualType = Boolean.class, persistVirtual = true)
|
||||
volatile VirtualProperty<Boolean> pvp; // SUPPRESS CHECKSTYLE: VisibilityModifier
|
||||
@Property(description = "Scale must be a positive double value. ex: 2.3")
|
||||
private volatile double scale;
|
||||
@Property(description = "You must set this to the NAME not alias of a world.")
|
||||
private volatile String respawnWorld;
|
||||
@Property(description = "Sorry, this must either be: true or false.")
|
||||
private volatile boolean allowWeather;
|
||||
@Property(serializor = DifficultyPropertySerializor.class, virtualType = Difficulty.class, persistVirtual = true,
|
||||
description = "Difficulty must be set as one of the following: peaceful easy normal hard")
|
||||
volatile VirtualProperty<Difficulty> difficulty; // SUPPRESS CHECKSTYLE: VisibilityModifier
|
||||
@Property(description = "Sorry, 'animals' must either be: true or false.")
|
||||
private volatile SpawnSettings spawning;
|
||||
@Property
|
||||
volatile EntryFee entryfee;
|
||||
@Property(description = "Sorry, 'hunger' must either be: true or false.")
|
||||
private volatile boolean hunger;
|
||||
@Property(description = "Sorry, 'autoheal' must either be: true or false.")
|
||||
private volatile boolean autoHeal;
|
||||
@Property(description = "Sorry, 'adjustspawn' must either be: true or false.")
|
||||
private volatile boolean adjustSpawn;
|
||||
@Property(serializor = EnumPropertySerializor.class, description = "Allow portal forming must be NONE, ALL, NETHER or END.")
|
||||
private volatile AllowedPortalType portalForm;
|
||||
@Property(serializor = GameModePropertySerializor.class, description = "GameMode must be set as one of the following: survival creative")
|
||||
private volatile GameMode gameMode;
|
||||
@Property(description = "Sorry, this must either be: true or false.", virtualType = Boolean.class, persistVirtual = true)
|
||||
volatile VirtualProperty<Boolean> keepSpawnInMemory; // SUPPRESS CHECKSTYLE: VisibilityModifier
|
||||
@Property
|
||||
volatile SpawnLocation spawnLocation; // SUPPRESS CHECKSTYLE: VisibilityModifier
|
||||
@Property(virtualType = Location.class,
|
||||
description = "There is no help available for this variable. Go bug Rigby90 about it.")
|
||||
volatile VirtualProperty<Location> spawn; // SUPPRESS CHECKSTYLE: VisibilityModifier
|
||||
@Property(description = "Set this to false ONLY if you don't want this world to load itself on server restart.")
|
||||
private volatile boolean autoLoad;
|
||||
@Property(description = "If a player dies in this world, shoudld they go to their bed?")
|
||||
private volatile boolean bedRespawn;
|
||||
@Property
|
||||
private volatile List<String> worldBlacklist;
|
||||
@Property(serializor = TimePropertySerializor.class, virtualType = Long.class,
|
||||
description = "Set the time to whatever you want! (Will NOT freeze time)")
|
||||
volatile VirtualProperty<Long> time; // SUPPRESS CHECKSTYLE: VisibilityModifier
|
||||
@Property
|
||||
volatile Environment environment; // SUPPRESS CHECKSTYLE: VisibilityModifier
|
||||
@Property
|
||||
volatile long seed; // SUPPRESS CHECKSTYLE: VisibilityModifier
|
||||
@Property
|
||||
private volatile String generator;
|
||||
@Property
|
||||
private volatile int playerLimit;
|
||||
@Property
|
||||
private volatile boolean allowFlight;
|
||||
// End of properties
|
||||
// --------------------------------------------------------------
|
||||
|
||||
void setValidator(String fieldName, Validator validator) {
|
||||
registerValidator(fieldName, validator); //To change body of overridden methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void copyValues(SerializationConfig other) {
|
||||
super.copyValues(other);
|
||||
}
|
||||
|
||||
/**
|
||||
* This prepares the MVWorld for unloading.
|
||||
*/
|
||||
public void cacheVirtualProperties() {
|
||||
try {
|
||||
this.buildVPropChanges();
|
||||
} catch (IllegalStateException e) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void setDefaults() {
|
||||
this.hidden = false;
|
||||
this.alias = new String();
|
||||
this.color = EnglishChatColor.WHITE;
|
||||
this.style = EnglishChatStyle.NORMAL;
|
||||
this.scale = 1D;
|
||||
this.respawnWorld = new String();
|
||||
this.allowWeather = true;
|
||||
this.spawning = new SpawnSettings();
|
||||
this.entryfee = new EntryFee();
|
||||
this.hunger = true;
|
||||
this.autoHeal = true;
|
||||
this.adjustSpawn = true;
|
||||
this.portalForm = AllowedPortalType.ALL;
|
||||
this.gameMode = GameMode.SURVIVAL;
|
||||
this.spawnLocation = new NullLocation();
|
||||
this.autoLoad = true;
|
||||
this.bedRespawn = true;
|
||||
this.worldBlacklist = new ArrayList<String>();
|
||||
this.generator = null;
|
||||
this.playerLimit = -1;
|
||||
this.allowFlight = true;
|
||||
}
|
||||
|
||||
private static double getDefaultScale(Environment environment) {
|
||||
if (environment == Environment.NETHER) {
|
||||
return 8.0; // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
} else if (environment == Environment.THE_END) {
|
||||
return 16.0; // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
}
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* getAliases().
|
||||
* @return The alias-map.
|
||||
* @see SerializationConfig
|
||||
*/
|
||||
protected static Map<String, String> getAliases() {
|
||||
return PROPERTY_ALIASES;
|
||||
}
|
||||
|
||||
void flushChanges() {
|
||||
this.flushPendingVPropChanges();
|
||||
}
|
||||
|
||||
public String getAlias() {
|
||||
return this.alias;
|
||||
}
|
||||
|
||||
public void setAlias(String alias) {
|
||||
this.setPropertyValueUnchecked("alias", alias);
|
||||
}
|
||||
|
||||
public Environment getEnvironment() {
|
||||
return this.environment;
|
||||
}
|
||||
|
||||
public void setEnvironment(Environment environment) {
|
||||
this.setPropertyValueUnchecked("environment", environment);
|
||||
}
|
||||
|
||||
public long getSeed() {
|
||||
return this.seed;
|
||||
}
|
||||
|
||||
public void setSeed(long seed) {
|
||||
this.setPropertyValueUnchecked("seed", seed);
|
||||
}
|
||||
|
||||
public String getGenerator() {
|
||||
return this.generator;
|
||||
}
|
||||
|
||||
public void setGenerator(String generator) {
|
||||
this.setPropertyValueUnchecked("generator", generator);
|
||||
}
|
||||
|
||||
public int getPlayerLimit() {
|
||||
return this.playerLimit;
|
||||
}
|
||||
|
||||
public void setPlayerLimit(int limit) {
|
||||
this.setPropertyValueUnchecked("playerLimit", limit);
|
||||
}
|
||||
|
||||
public boolean canAnimalsSpawn() {
|
||||
return this.spawning.getAnimalSettings().doSpawn();
|
||||
}
|
||||
|
||||
public void setAllowAnimalSpawn(boolean animals) {
|
||||
this.setPropertyValueUnchecked("spawning.animals.spawn", animals);
|
||||
}
|
||||
|
||||
public List<String> getAnimalList() {
|
||||
// These don't fire events at the moment. Should they?
|
||||
return this.spawning.getAnimalSettings().getExceptions();
|
||||
}
|
||||
|
||||
public boolean canMonstersSpawn() {
|
||||
return this.spawning.getMonsterSettings().doSpawn();
|
||||
}
|
||||
|
||||
public void setAllowMonsterSpawn(boolean monsters) {
|
||||
this.setPropertyValueUnchecked("spawning.monsters.spawn", monsters);
|
||||
}
|
||||
|
||||
public int getAnimalSpawnRate() {
|
||||
return this.spawning.getAnimalSettings().getSpawnRate();
|
||||
}
|
||||
|
||||
public int getMonsterSpawnRate() {
|
||||
return this.spawning.getMonsterSettings().getSpawnRate();
|
||||
}
|
||||
|
||||
public List<String> getMonsterList() {
|
||||
// These don't fire events at the moment. Should they?
|
||||
return this.spawning.getMonsterSettings().getExceptions();
|
||||
}
|
||||
|
||||
public boolean isPVPEnabled() {
|
||||
return this.pvp.get();
|
||||
}
|
||||
|
||||
public void setPVPMode(boolean pvp) {
|
||||
this.setPropertyValueUnchecked("pvp", pvp);
|
||||
}
|
||||
|
||||
public boolean isHidden() {
|
||||
return this.hidden;
|
||||
}
|
||||
|
||||
public void setHidden(boolean hidden) {
|
||||
this.setPropertyValueUnchecked("hidden", hidden);
|
||||
}
|
||||
|
||||
public List<String> getWorldBlacklist() {
|
||||
return this.worldBlacklist;
|
||||
}
|
||||
|
||||
public double getScaling() {
|
||||
return this.scale;
|
||||
}
|
||||
|
||||
public boolean setScaling(double scaling) {
|
||||
return this.setPropertyValueUnchecked("scale", scaling);
|
||||
}
|
||||
|
||||
public boolean setColor(String aliasColor) {
|
||||
return this.setPropertyUnchecked("color", aliasColor);
|
||||
}
|
||||
|
||||
public boolean setColor(EnglishChatColor color) {
|
||||
return this.setPropertyValueUnchecked("color", color);
|
||||
}
|
||||
|
||||
public EnglishChatColor getColor() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
public String getRespawnToWorld() {
|
||||
return this.respawnWorld;
|
||||
}
|
||||
|
||||
public boolean setRespawnToWorld(String respawnToWorld) {
|
||||
return this.setPropertyValueUnchecked("respawnWorld", respawnToWorld);
|
||||
}
|
||||
|
||||
public Material getCurrency() {
|
||||
return this.entryfee.getCurrency();
|
||||
}
|
||||
|
||||
public void setCurrency(@Nullable Material currency) {
|
||||
this.setPropertyValueUnchecked("entryfee.currency", currency);
|
||||
}
|
||||
|
||||
public double getPrice() {
|
||||
return this.entryfee.getAmount();
|
||||
}
|
||||
|
||||
public void setPrice(double price) {
|
||||
this.setPropertyValueUnchecked("entryfee.amount", price);
|
||||
}
|
||||
|
||||
public boolean setGameMode(String mode) {
|
||||
return this.setPropertyUnchecked("gameMode", mode);
|
||||
}
|
||||
|
||||
public boolean setGameMode(GameMode mode) {
|
||||
return this.setPropertyValueUnchecked("gameMode", mode);
|
||||
}
|
||||
|
||||
public GameMode getGameMode() {
|
||||
return this.gameMode;
|
||||
}
|
||||
|
||||
public void setEnableWeather(boolean weather) {
|
||||
this.setPropertyValueUnchecked("allowWeather", weather);
|
||||
}
|
||||
|
||||
public boolean isWeatherEnabled() {
|
||||
return this.allowWeather;
|
||||
}
|
||||
|
||||
public boolean isKeepingSpawnInMemory() {
|
||||
if (keepSpawnInMemory == null) {
|
||||
return keepSpawnFallback;
|
||||
}
|
||||
try {
|
||||
return this.keepSpawnInMemory.get();
|
||||
} catch (IllegalStateException e) {
|
||||
return keepSpawnFallback;
|
||||
}
|
||||
}
|
||||
|
||||
public void setKeepSpawnInMemory(boolean value) {
|
||||
this.setPropertyValueUnchecked("keepSpawnInMemory", value);
|
||||
}
|
||||
|
||||
public boolean getHunger() {
|
||||
return this.hunger;
|
||||
}
|
||||
|
||||
public void setHunger(boolean hunger) {
|
||||
this.setPropertyValueUnchecked("hunger", hunger);
|
||||
}
|
||||
|
||||
public Location getSpawnLocation() {
|
||||
return this.spawn.get();
|
||||
}
|
||||
|
||||
public void setSpawnLocation(Location l) {
|
||||
this.setPropertyValueUnchecked("spawn", l);
|
||||
}
|
||||
|
||||
public Difficulty getDifficulty() {
|
||||
return this.difficulty.get();
|
||||
}
|
||||
|
||||
@Deprecated // SUPPRESS CHECKSTYLE: Deprecated
|
||||
public boolean setDifficulty(String difficulty) {
|
||||
return this.setPropertyUnchecked("difficulty", difficulty);
|
||||
}
|
||||
|
||||
public boolean setDifficulty(Difficulty difficulty) {
|
||||
return this.setPropertyValueUnchecked("difficulty", difficulty);
|
||||
}
|
||||
|
||||
public boolean getAutoHeal() {
|
||||
return this.autoHeal;
|
||||
}
|
||||
|
||||
public void setAutoHeal(boolean heal) {
|
||||
this.setPropertyValueUnchecked("autoHeal", heal);
|
||||
}
|
||||
|
||||
public void setAdjustSpawn(boolean adjust) {
|
||||
this.setPropertyValueUnchecked("adjustSpawn", adjust);
|
||||
}
|
||||
|
||||
public boolean getAdjustSpawn() {
|
||||
return this.adjustSpawn;
|
||||
}
|
||||
|
||||
public void setAutoLoad(boolean load) {
|
||||
this.setPropertyValueUnchecked("autoLoad", load);
|
||||
}
|
||||
|
||||
public boolean getAutoLoad() {
|
||||
return this.autoLoad;
|
||||
}
|
||||
|
||||
public void setBedRespawn(boolean respawn) {
|
||||
this.setPropertyValueUnchecked("bedRespawn", respawn);
|
||||
}
|
||||
|
||||
public boolean getBedRespawn() {
|
||||
return this.bedRespawn;
|
||||
}
|
||||
|
||||
public String getAllPropertyNames() {
|
||||
ChatColor myColor = ChatColor.AQUA;
|
||||
StringBuilder result = new StringBuilder();
|
||||
Map<String, Object> serialized = this.serialize();
|
||||
for (String key : serialized.keySet()) {
|
||||
result.append(myColor).append(key).append(' ');
|
||||
myColor = (myColor == ChatColor.AQUA) ? ChatColor.GOLD : ChatColor.AQUA;
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return this.getPropertyUnchecked("time");
|
||||
}
|
||||
|
||||
public boolean setTime(String timeAsString) {
|
||||
return this.setPropertyUnchecked("time", timeAsString);
|
||||
}
|
||||
|
||||
public AllowedPortalType getAllowedPortals() {
|
||||
return portalForm;
|
||||
}
|
||||
|
||||
public void allowPortalMaking(AllowedPortalType portalType) {
|
||||
this.setPropertyValueUnchecked("portalForm", portalType);
|
||||
}
|
||||
|
||||
public EnglishChatStyle getStyle() {
|
||||
return style;
|
||||
}
|
||||
|
||||
public boolean setStyle(String style) {
|
||||
return this.setPropertyUnchecked("style", style);
|
||||
}
|
||||
|
||||
public boolean getAllowFlight() {
|
||||
return this.allowFlight;
|
||||
}
|
||||
|
||||
public void setAllowFlight(final boolean allowFlight) {
|
||||
this.setPropertyValueUnchecked("allowFlight", allowFlight);
|
||||
}
|
||||
}
|
|
@ -1,245 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import buscript.Buscript;
|
||||
import com.onarandombox.MultiverseCore.commandtools.queue.CommandQueueManager;
|
||||
import com.onarandombox.MultiverseCore.destination.DestinationFactory;
|
||||
import com.onarandombox.MultiverseCore.utils.AnchorManager;
|
||||
import com.onarandombox.MultiverseCore.utils.MVEconomist;
|
||||
import com.onarandombox.MultiverseCore.utils.MVPermissions;
|
||||
import com.onarandombox.MultiverseCore.utils.MVPlayerSession;
|
||||
import com.onarandombox.MultiverseCore.utils.SimpleBlockSafety;
|
||||
import com.onarandombox.MultiverseCore.utils.SimpleLocationManipulation;
|
||||
import com.onarandombox.MultiverseCore.utils.SimpleSafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.utils.VaultHandler;
|
||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Multiverse 2 Core API
|
||||
* <p>
|
||||
* This API contains a bunch of useful things you can get out of Multiverse in general!
|
||||
*/
|
||||
public interface Core {
|
||||
|
||||
/**
|
||||
* Returns the Vault handler used by Multiverse. The returned object will have all methods necessary for
|
||||
* interfacing with Vault.
|
||||
*
|
||||
* @return the Vault handler for Multiverse.
|
||||
* @deprecated we are now using {@link #getEconomist()} for all economy needs.
|
||||
*/
|
||||
@Deprecated
|
||||
VaultHandler getVaultHandler();
|
||||
|
||||
/**
|
||||
* Retrieves Multiverse's friendly economist. The economist can be used for dealing with economies without
|
||||
* worrying about any of the messy details.
|
||||
*
|
||||
* @return the economy manager for Multiverse.
|
||||
*/
|
||||
MVEconomist getEconomist();
|
||||
|
||||
/**
|
||||
* Reloads the Multiverse Configuration files:
|
||||
* worlds.yml and config.yml.
|
||||
*/
|
||||
void loadConfigs();
|
||||
|
||||
/**
|
||||
* Gets the Multiverse message system. This allows you to send messages
|
||||
* to users at specified intervals.
|
||||
*
|
||||
* @return The loaded {@link MultiverseMessaging}.
|
||||
*/
|
||||
MultiverseMessaging getMessaging();
|
||||
|
||||
/**
|
||||
* Gets the {@link MVPlayerSession} for the given player.
|
||||
* This will also create a player session if one does not exist
|
||||
* for a player.
|
||||
*
|
||||
* @param player The player's session to grab.
|
||||
*
|
||||
* @return The corresponding {@link MVPlayerSession}.
|
||||
*/
|
||||
MVPlayerSession getPlayerSession(Player player);
|
||||
|
||||
/**
|
||||
* Multiverse uses an advanced permissions setup, this object
|
||||
* simplifies getting/setting permissions.
|
||||
*
|
||||
* @return A non-null {@link MVPermissions}.
|
||||
*/
|
||||
MVPermissions getMVPerms();
|
||||
|
||||
/**
|
||||
* Multiverse uses {@link CommandHandler} to make adding and using commands
|
||||
* a piece of cake.
|
||||
*
|
||||
* @return A non-null {@link CommandHandler}.
|
||||
*/
|
||||
CommandHandler getCommandHandler();
|
||||
|
||||
/**
|
||||
* Manager for command that requires /mv confirm before execution.
|
||||
*
|
||||
* @return A non-null {@link CommandQueueManager}.
|
||||
* @deprecated To be moved to new command manager in 5.0.0
|
||||
*/
|
||||
@Deprecated
|
||||
CommandQueueManager getCommandQueueManager();
|
||||
|
||||
/**
|
||||
* Gets the factory class responsible for loading many different destinations
|
||||
* on demand.
|
||||
*
|
||||
* @return A valid {@link DestinationFactory}.
|
||||
*/
|
||||
DestinationFactory getDestFactory();
|
||||
|
||||
/**
|
||||
* Gets the primary class responsible for managing Multiverse Worlds.
|
||||
*
|
||||
* @return {@link MVWorldManager}.
|
||||
*/
|
||||
MVWorldManager getMVWorldManager();
|
||||
|
||||
/**
|
||||
* Saves all configs.
|
||||
*
|
||||
* @return Whether the config was successfully saved
|
||||
*/
|
||||
boolean saveMVConfigs();
|
||||
|
||||
/**
|
||||
* Gets the {@link AnchorManager}.
|
||||
*
|
||||
* @return The {@link AnchorManager}
|
||||
*/
|
||||
AnchorManager getAnchorManager();
|
||||
|
||||
/**
|
||||
* Previously used by queued commands to regenerate a world on a delay.
|
||||
* Do not use api method for any other purpose.
|
||||
*
|
||||
* @param name Name of the world to regenerate
|
||||
* @param useNewSeed If a new seed should be used
|
||||
* @param randomSeed If the new seed should be random
|
||||
* @param seed The seed of the world.
|
||||
*
|
||||
* @return True if success, false if fail.
|
||||
*
|
||||
* @deprecated Use {@link MVWorldManager#regenWorld(String, boolean, boolean, String, boolean)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
Boolean regenWorld(String name, Boolean useNewSeed, Boolean randomSeed, String seed);
|
||||
|
||||
/**
|
||||
* Used by queued commands to regenerate a world on a delay.
|
||||
* Do not use api method for any other purpose.
|
||||
*
|
||||
* @param name Name of the world to regenerate
|
||||
* @param useNewSeed If a new seed should be used
|
||||
* @param randomSeed If the new seed should be random
|
||||
* @param seed The seed of the world.
|
||||
* @param keepGameRules If GameRules should be kept on world regen.
|
||||
*
|
||||
* @return True if success, false if fail.
|
||||
*
|
||||
* @deprecated Use {@link MVWorldManager#regenWorld(String, boolean, boolean, String, boolean)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
Boolean regenWorld(String name, Boolean useNewSeed, Boolean randomSeed, String seed, Boolean keepGameRules);
|
||||
|
||||
/**
|
||||
* Decrements the number of plugins that have specifically hooked into core.
|
||||
*/
|
||||
void decrementPluginCount();
|
||||
|
||||
/**
|
||||
* Increments the number of plugins that have specifically hooked into core.
|
||||
*/
|
||||
void incrementPluginCount();
|
||||
|
||||
/**
|
||||
* Returns the number of plugins that have specifically hooked into core.
|
||||
*
|
||||
* @return The number if plugins that have hooked into core.
|
||||
*/
|
||||
int getPluginCount();
|
||||
|
||||
/**
|
||||
* Parse the Authors Array into a readable String with ',' and 'and'.
|
||||
*
|
||||
* @return The readable authors-{@link String}
|
||||
*/
|
||||
String getAuthors();
|
||||
|
||||
/**
|
||||
* Gets the {@link BlockSafety} this {@link Core} is using.
|
||||
* @return The {@link BlockSafety} this {@link Core} is using.
|
||||
* @see BlockSafety
|
||||
* @see SimpleBlockSafety
|
||||
*/
|
||||
BlockSafety getBlockSafety();
|
||||
|
||||
/**
|
||||
* Sets the {@link BlockSafety} this {@link Core} is using.
|
||||
* @param blockSafety The new {@link BlockSafety}.
|
||||
* @see BlockSafety
|
||||
* @see SimpleBlockSafety
|
||||
*/
|
||||
void setBlockSafety(BlockSafety blockSafety);
|
||||
|
||||
/**
|
||||
* Gets the {@link LocationManipulation} this {@link Core} is using.
|
||||
* @return The {@link LocationManipulation} this {@link Core} is using.
|
||||
* @see LocationManipulation
|
||||
* @see SimpleLocationManipulation
|
||||
*/
|
||||
LocationManipulation getLocationManipulation();
|
||||
|
||||
/**
|
||||
* Sets the {@link LocationManipulation} this {@link Core} is using.
|
||||
* @param locationManipulation The new {@link LocationManipulation}.
|
||||
* @see LocationManipulation
|
||||
* @see SimpleLocationManipulation
|
||||
*/
|
||||
void setLocationManipulation(LocationManipulation locationManipulation);
|
||||
|
||||
/**
|
||||
* Gets the {@link SafeTTeleporter} this {@link Core} is using.
|
||||
* @return The {@link SafeTTeleporter} this {@link Core} is using.
|
||||
* @see SafeTTeleporter
|
||||
* @see SimpleSafeTTeleporter
|
||||
*/
|
||||
SafeTTeleporter getSafeTTeleporter();
|
||||
|
||||
/**
|
||||
* Sets the {@link SafeTTeleporter} this {@link Core} is using.
|
||||
* @param safeTTeleporter The new {@link SafeTTeleporter}.
|
||||
* @see SafeTTeleporter
|
||||
* @see SimpleSafeTTeleporter
|
||||
*/
|
||||
void setSafeTTeleporter(SafeTTeleporter safeTTeleporter);
|
||||
|
||||
/**
|
||||
* Gets the {@link MultiverseCoreConfig}.
|
||||
* @return The configuration.
|
||||
*/
|
||||
MultiverseCoreConfig getMVConfig();
|
||||
|
||||
/**
|
||||
* Gets the buscript object for Multiverse. This is what handles Javascript processing.
|
||||
*
|
||||
* @return The Multiverse buscript object.
|
||||
*/
|
||||
Buscript getScriptAPI();
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
/**
|
||||
* A fancy text.
|
||||
*/
|
||||
public interface FancyText {
|
||||
/**
|
||||
* Gets the {@link String}-representation of this {@link FancyText}.
|
||||
*
|
||||
* @return The {@link String}-representation of this {@link FancyText}.
|
||||
*/
|
||||
String getFancyText();
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* A simple API to require plugins to have a log method.
|
||||
*
|
||||
* @deprecated Replaced by {@link Logging}.
|
||||
* */
|
||||
@Deprecated
|
||||
public interface LoggablePlugin {
|
||||
/**
|
||||
* Logs a message at the specified level.
|
||||
*
|
||||
* @param level The Log-{@link Level}.
|
||||
* @param msg The message to log.
|
||||
*/
|
||||
void log(Level level, String msg);
|
||||
|
||||
/**
|
||||
* Gets the server instance that this plugin is attached to.
|
||||
*
|
||||
* @return A {@link Server} instance.
|
||||
*/
|
||||
Server getServer();
|
||||
}
|
|
@ -1,141 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
/**
|
||||
* A destination API for Multiverse
|
||||
* Any plugin can add these to MV and when they are, any action that uses them (portals, MVTP, etc.) can use them!
|
||||
*/
|
||||
public interface MVDestination {
|
||||
/**
|
||||
* Returns the identifier or prefix that is required for this destination.
|
||||
* <p>
|
||||
* Portals have a prefix of "p" for example and OpenWarp (third party plugin) uses "ow". This is derived from a
|
||||
* hash and cannot have duplicate values. Read that as your plugin cannot use 'p' because it's already used.
|
||||
* Please check the wiki when adding a custom destination!
|
||||
*
|
||||
* @return The identifier or prefix that is required for this destination.
|
||||
*/
|
||||
String getIdentifier();
|
||||
|
||||
/**
|
||||
* Allows you to determine if a Destination is valid for the type it thinks it is.
|
||||
* <p>
|
||||
* An example of this would be the exact destination. A valid string would be: e:0,0,0 where an invalid one would
|
||||
* be e:1:2:3. The first string would return true the second would return false. This is simply a convenience
|
||||
* method
|
||||
* and does not even NEED to be called, but it's highly recommended if you're teleporting, but it's mainly for
|
||||
* Multiverse Internal use.
|
||||
*
|
||||
* @param plugin The plugin who the type belongs to.
|
||||
* @param destination The destination string. ex: p:MyPortal:nw
|
||||
*
|
||||
* @return True if the destination is valid, false if not.
|
||||
*/
|
||||
boolean isThisType(JavaPlugin plugin, String destination);
|
||||
|
||||
/**
|
||||
* Returns the location a specific entity will spawn at when being teleported to this Destination.
|
||||
* <p>
|
||||
* To just retrieve the location as it is stored you can just pass null, but be warned some destinations may return
|
||||
* null back to you if you do this. It is always safer to pass an actual entity. This is used so things like
|
||||
* minecarts can be teleported.
|
||||
* <p>
|
||||
* Do not forget to use {@link #getVelocity()} as destinations can use this too!
|
||||
*
|
||||
* @param entity The entity to be teleported.
|
||||
*
|
||||
* @return The location of the entity.
|
||||
*/
|
||||
Location getLocation(Entity entity);
|
||||
|
||||
/**
|
||||
* Returns the velocity vector for this destination.
|
||||
* <p>
|
||||
* Plugins wishing to fully support MVDestinations MUST implement this.
|
||||
*
|
||||
* @return A vector representing the speed/direction the player should travel when arriving
|
||||
*/
|
||||
Vector getVelocity();
|
||||
|
||||
/**
|
||||
* Sets the destination string.
|
||||
* <p>
|
||||
* This should be used when you want to tell this destination object about a change in where it should take people.
|
||||
* The destination param should be match the result from {@link #getIdentifier()}. A valid example would be that if
|
||||
* {@link #getIdentifier()} returned "ow" our destination string could be "ow:TownCenter" but could not be
|
||||
* "p:HomePortal"
|
||||
*
|
||||
* @param plugin The plugin who the type belongs to.
|
||||
* @param destination The destination string. ex: p:MyPortal:nw
|
||||
*/
|
||||
void setDestination(JavaPlugin plugin, String destination);
|
||||
|
||||
/**
|
||||
* Returns true if the destination is valid and players will be taken to it.
|
||||
* <p>
|
||||
* Even if destinations are in the correct format (p:MyPortal) MyPortal may not exist, and therefore this would
|
||||
* return false.
|
||||
*
|
||||
* @return True if the destination is valid; false if not.
|
||||
*/
|
||||
boolean isValid();
|
||||
|
||||
/**
|
||||
* Gives you a general friendly description of the type of destination.
|
||||
* <p>
|
||||
* For example, the PlayerDestination sets this to "Player". You can use this to show where a player will be taken.
|
||||
*
|
||||
* @return A friendly string description of the type of destination.
|
||||
*/
|
||||
String getType();
|
||||
|
||||
/**
|
||||
* Gives you a specific name of the destination.
|
||||
* <p>
|
||||
* For example, the PlayerDestination sets this to The Player's Name.
|
||||
*
|
||||
* @return A friendly string stating the name of the destination.
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Returns a string that can easily be saved in the config that contains all the details needed to rebuild this
|
||||
* destination.
|
||||
* <p>
|
||||
* ex: e:0,0,0:50:50
|
||||
*
|
||||
* @return The savable config string.
|
||||
*/
|
||||
String toString();
|
||||
|
||||
/**
|
||||
* Returns the permissions string required to go here.
|
||||
* <p>
|
||||
* ex: multiverse.access.world
|
||||
* <p>
|
||||
* NOTE: This is NOT the permission to use the teleport command.
|
||||
*
|
||||
* @return the permissions string required to go here.
|
||||
*/
|
||||
String getRequiredPermission();
|
||||
|
||||
/**
|
||||
* Should the Multiverse SafeTeleporter be used?
|
||||
* <p>
|
||||
* If not, MV will blindly take people to the location specified.
|
||||
*
|
||||
* @return True if the SafeTeleporter will be used, false if not.
|
||||
*/
|
||||
boolean useSafeTeleporter();
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.event.MVVersionEvent;
|
||||
|
||||
/**
|
||||
* This interface is implemented by every official Multiverse-plugin.
|
||||
*/
|
||||
public interface MVPlugin extends LoggablePlugin {
|
||||
/**
|
||||
* Adds This plugin's version information to the buffer and returns the new string.
|
||||
*
|
||||
* @param buffer The string that contains Core and all other MV plugins' versions.
|
||||
*
|
||||
* @return A modified buffer that contains this MVPlugin's version information.
|
||||
*
|
||||
* @deprecated This is now deprecated, nobody needs it any longer.
|
||||
* All version info-dumping is now done with {@link MVVersionEvent}.
|
||||
*/
|
||||
@Deprecated
|
||||
String dumpVersionInfo(String buffer);
|
||||
|
||||
/**
|
||||
* Gets the reference to MultiverseCore.
|
||||
*
|
||||
* @return A valid {@link com.onarandombox.MultiverseCore}.
|
||||
*/
|
||||
MultiverseCore getCore();
|
||||
|
||||
/**
|
||||
* Sets the reference to MultiverseCore.
|
||||
*
|
||||
* @param core A valid {@link com.onarandombox.MultiverseCore}.
|
||||
*/
|
||||
void setCore(MultiverseCore core);
|
||||
|
||||
/**
|
||||
* Allows Multiverse or a plugin to query another Multiverse plugin to see what version its protocol is. This
|
||||
* number
|
||||
* should change when something will break the code.
|
||||
*
|
||||
* @return The Integer protocol version.
|
||||
*/
|
||||
int getProtocolVersion();
|
||||
}
|
|
@ -1,358 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import com.onarandombox.MultiverseCore.utils.PurgeWorlds;
|
||||
import com.onarandombox.MultiverseCore.utils.SimpleWorldPurger;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.WorldType;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Multiverse 2 World Manager API
|
||||
* <p>
|
||||
* This API contains all of the world managing
|
||||
* functions that your heart desires!
|
||||
*/
|
||||
public interface MVWorldManager {
|
||||
/**
|
||||
* Add a new World to the Multiverse Setup.
|
||||
*
|
||||
* @param name World Name
|
||||
* @param env Environment Type
|
||||
* @param seedString The seed in the form of a string.
|
||||
* If the seed is a Long,
|
||||
* it will be interpreted as such.
|
||||
* @param type The Type of the world to be made.
|
||||
* @param generateStructures If true, this world will get NPC villages.
|
||||
* @param generator The Custom generator plugin to use.
|
||||
* @return True if the world is added, false if not.
|
||||
*/
|
||||
boolean addWorld(String name, Environment env, String seedString, WorldType type, Boolean generateStructures,
|
||||
String generator);
|
||||
|
||||
/**
|
||||
* Add a new World to the Multiverse Setup.
|
||||
*
|
||||
* @param name World Name
|
||||
* @param env Environment Type
|
||||
* @param seedString The seed in the form of a string.
|
||||
* If the seed is a Long,
|
||||
* it will be interpreted as such.
|
||||
* @param type The Type of the world to be made.
|
||||
* @param generateStructures If true, this world will get NPC villages.
|
||||
* @param generator The Custom generator plugin to use.
|
||||
* @param useSpawnAdjust If true, multiverse will search for a safe spawn. If not, It will not modify the level.dat.
|
||||
* @return True if the world is added, false if not.
|
||||
*/
|
||||
boolean addWorld(String name, Environment env, String seedString, WorldType type, Boolean generateStructures,
|
||||
String generator, boolean useSpawnAdjust);
|
||||
|
||||
/**
|
||||
* Make a copy of a world.
|
||||
*
|
||||
* @param oldName Name of world to be copied
|
||||
* @param newName Name of world to be created
|
||||
* @param generator The Custom generator plugin to use. Ignored.
|
||||
* @return True if the world is copied successfully, false if not.
|
||||
* @deprecated Use {@link #cloneWorld(String, String)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
boolean cloneWorld(String oldName, String newName, String generator);
|
||||
|
||||
/**
|
||||
* Make a copy of a world.
|
||||
*
|
||||
* @param oldName
|
||||
* Name of world to be copied
|
||||
* @param newName
|
||||
* Name of world to be created
|
||||
* @return True if the world is copied successfully, false if not.
|
||||
*/
|
||||
boolean cloneWorld(String oldName, String newName);
|
||||
|
||||
/**
|
||||
* Remove the world from the Multiverse list, from the config and deletes
|
||||
* the folder.
|
||||
*
|
||||
* @param name
|
||||
* The name of the world to remove
|
||||
* @return True if success, false if failure.
|
||||
*/
|
||||
boolean deleteWorld(String name);
|
||||
|
||||
/**
|
||||
* Remove the world from the Multiverse list, from the
|
||||
* config if wanted, and deletes the folder.
|
||||
*
|
||||
* @param name The name of the world to remove
|
||||
* @param removeConfig If true(default), we'll remove the entries from the
|
||||
* config. If false, they'll stay and the world may come back.
|
||||
* @return True if success, false if failure.
|
||||
*/
|
||||
boolean deleteWorld(String name, boolean removeConfig);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name The name of the world to remove
|
||||
* @param removeFromConfig If true(default), we'll remove the entries from the
|
||||
* config. If false, they'll stay and the world may come back.
|
||||
* @param deleteWorldFolder If true the world folder will be completely deleted. If false
|
||||
* only the contents of the world folder will be deleted
|
||||
* @return True if success, false if failure.
|
||||
*/
|
||||
boolean deleteWorld(String name, boolean removeFromConfig, boolean deleteWorldFolder);
|
||||
|
||||
/**
|
||||
* Unload a world from Multiverse.
|
||||
*
|
||||
* @param name Name of the world to unload
|
||||
* @return True if the world was unloaded, false if not.
|
||||
*/
|
||||
boolean unloadWorld(String name);
|
||||
|
||||
/**
|
||||
* Unload a world from Multiverse with option to prevent calling unloadWorld in Bukkit.
|
||||
*
|
||||
* @param name Name of the world to unload
|
||||
* @param unloadBukkit True if Bukkit world should be unloaded
|
||||
* @return True if the world was unloaded, false if not.
|
||||
*/
|
||||
boolean unloadWorld(String name, boolean unloadBukkit);
|
||||
|
||||
/**
|
||||
* Loads the world. Only use this if the world has been
|
||||
* unloaded with {@link #unloadWorld(String)}.
|
||||
*
|
||||
* @param name The name of the world to load
|
||||
* @return True if success, false if failure.
|
||||
*/
|
||||
boolean loadWorld(String name);
|
||||
|
||||
/**
|
||||
* Removes all players from the specified world.
|
||||
*
|
||||
* @param name World to remove players from.
|
||||
*/
|
||||
void removePlayersFromWorld(String name);
|
||||
|
||||
/**
|
||||
* Test if a given chunk generator is valid.
|
||||
*
|
||||
* @param generator The generator name.
|
||||
* @param generatorID The generator id.
|
||||
* @param worldName The worldName to use as the default.
|
||||
* @return A {@link ChunkGenerator} or null
|
||||
*/
|
||||
ChunkGenerator getChunkGenerator(String generator, String generatorID, String worldName);
|
||||
|
||||
/**
|
||||
* Returns a list of all the worlds Multiverse knows about.
|
||||
*
|
||||
* @return A list of {@link MultiverseWorld}.
|
||||
*/
|
||||
Collection<MultiverseWorld> getMVWorlds();
|
||||
|
||||
|
||||
/**
|
||||
* Returns a {@link MultiverseWorld} if it exists, and null if it does not.
|
||||
* This will search name AND alias.
|
||||
*
|
||||
* @param name The name or alias of the world to get.
|
||||
* @return A {@link MultiverseWorld} or null.
|
||||
*/
|
||||
MultiverseWorld getMVWorld(String name);
|
||||
|
||||
/**
|
||||
* Returns a {@link MultiverseWorld} if the world with name given exists, and null if it does not.
|
||||
* This will search optionally for alias names.
|
||||
*
|
||||
* @param name The name or optionally the alias of the world to get.
|
||||
* @param checkAliases Indicates whether to check for world alias name.
|
||||
* @return A {@link MultiverseWorld} or null.
|
||||
*/
|
||||
MultiverseWorld getMVWorld(String name, boolean checkAliases);
|
||||
|
||||
/**
|
||||
* Returns a {@link MultiverseWorld} if it exists, and null if it does not.
|
||||
*
|
||||
* @param world The Bukkit world to check.
|
||||
* @return A {@link MultiverseWorld} or null.
|
||||
*/
|
||||
MultiverseWorld getMVWorld(World world);
|
||||
|
||||
/**
|
||||
* Checks to see if the given name is a valid {@link MultiverseWorld}
|
||||
* Searches based on world name AND alias.
|
||||
*
|
||||
* @param name The name or alias of the world to check.
|
||||
* @return True if the world exists, false if not.
|
||||
*/
|
||||
boolean isMVWorld(String name);
|
||||
|
||||
/**
|
||||
* Checks to see if the given name is a valid {@link MultiverseWorld}.
|
||||
* Optionally searches by alias is specified.
|
||||
*
|
||||
* @param name The name or alias of the world to check.
|
||||
* @param checkAliases Indicates whether to check for world alias name.
|
||||
* @return True if the world exists, false if not.
|
||||
*/
|
||||
boolean isMVWorld(String name, boolean checkAliases);
|
||||
|
||||
/**
|
||||
* Checks to see if the given world is a valid {@link MultiverseWorld}.
|
||||
*
|
||||
* @param world The Bukkit world to check.
|
||||
* @return True if the world has been loaded into MV2, false if not.
|
||||
*/
|
||||
boolean isMVWorld(World world);
|
||||
|
||||
/**
|
||||
* Load the Worlds & Settings from the configuration file.
|
||||
*
|
||||
* @param forceLoad If set to true, this will perform a total
|
||||
* reset and not just load new worlds.
|
||||
*/
|
||||
void loadWorlds(boolean forceLoad);
|
||||
|
||||
/**
|
||||
* Loads the Worlds & Settings for any worlds that bukkit loaded before us.
|
||||
* <p>
|
||||
* This way people will _always_ have some worlds in the list.
|
||||
*/
|
||||
void loadDefaultWorlds();
|
||||
|
||||
/**
|
||||
* Return the World Purger.
|
||||
*
|
||||
* @return A valid {@link PurgeWorlds}.
|
||||
* @deprecated {@link PurgeWorlds} is deprecated!
|
||||
*/
|
||||
@Deprecated
|
||||
PurgeWorlds getWorldPurger();
|
||||
|
||||
/**
|
||||
* Gets the {@link WorldPurger}.
|
||||
* <p>
|
||||
* TODO: Remove {@link #getWorldPurger()} and replace it with this method.
|
||||
* @return The {@link WorldPurger} this {@link MVWorldManager} is using.
|
||||
* @see WorldPurger
|
||||
* @see SimpleWorldPurger
|
||||
*/
|
||||
WorldPurger getTheWorldPurger();
|
||||
|
||||
/**
|
||||
* Gets the world players will spawn in on first join.
|
||||
* Currently this always returns worlds.get(0) from Bukkit.
|
||||
*
|
||||
* @return A Multiverse world that players will spawn in or null if no MV world has been set.
|
||||
*/
|
||||
MultiverseWorld getSpawnWorld();
|
||||
|
||||
/**
|
||||
* Gets the list of worlds in the config, but unloaded.
|
||||
*
|
||||
* @return A List of worlds as strings.
|
||||
*/
|
||||
List<String> getUnloadedWorlds();
|
||||
|
||||
/**
|
||||
* This method populates an internal list and needs to be called after multiverse initialization.
|
||||
*/
|
||||
void getDefaultWorldGenerators();
|
||||
|
||||
/**
|
||||
* Load the config from a file.
|
||||
*
|
||||
* @param file The file to load.
|
||||
* @return A loaded configuration.
|
||||
*/
|
||||
FileConfiguration loadWorldConfig(File file);
|
||||
|
||||
/**
|
||||
* Saves the world config to disk.
|
||||
*
|
||||
* @return True if success, false if fail.
|
||||
*/
|
||||
boolean saveWorldsConfig();
|
||||
|
||||
/**
|
||||
* Remove the world from the Multiverse list and from the config.
|
||||
*
|
||||
* @param name The name of the world to remove
|
||||
* @return True if success, false if failure.
|
||||
*/
|
||||
boolean removeWorldFromConfig(String name);
|
||||
|
||||
/**
|
||||
* Sets the initial spawn world for new players.
|
||||
*
|
||||
* @param world The World new players should spawn in.
|
||||
*/
|
||||
void setFirstSpawnWorld(String world);
|
||||
|
||||
/**
|
||||
* Gets the world players should spawn in first.
|
||||
*
|
||||
* @return The {@link MultiverseWorld} new players should spawn in.
|
||||
*/
|
||||
MultiverseWorld getFirstSpawnWorld();
|
||||
|
||||
/**
|
||||
* Regenerates a world.
|
||||
*
|
||||
* @param name Name of the world to regenerate
|
||||
* @param useNewSeed If a new seed should be used
|
||||
* @param randomSeed If the new seed should be random
|
||||
* @param seed The seed of the world.
|
||||
*
|
||||
* @return True if success, false if fail.
|
||||
*/
|
||||
boolean regenWorld(String name, boolean useNewSeed, boolean randomSeed, String seed);
|
||||
|
||||
/**
|
||||
* Regenerates a world.
|
||||
*
|
||||
* @param name Name of the world to regenerate
|
||||
* @param useNewSeed If a new seed should be used
|
||||
* @param randomSeed If the new seed should be random
|
||||
* @param seed The seed of the world.
|
||||
* @param keepGameRules If GameRules should be kept on world regen.
|
||||
*
|
||||
* @return True if success, false if fail.
|
||||
*/
|
||||
boolean regenWorld(String name, boolean useNewSeed, boolean randomSeed, String seed, boolean keepGameRules);
|
||||
|
||||
boolean isKeepingSpawnInMemory(World world);
|
||||
|
||||
/**
|
||||
* Checks whether Multiverse knows about a provided unloaded world. This
|
||||
* method will check the parameter against the alias mappings.
|
||||
*
|
||||
* @param name The name of the unloaded world
|
||||
* @param includeLoaded The value to return if the world is loaded
|
||||
*
|
||||
* @return True if the world exists and is unloaded. False if the world
|
||||
* does not exist. {@code includeLoaded} if the world exists and is loaded.
|
||||
*/
|
||||
boolean hasUnloadedWorld(String name, boolean includeLoaded);
|
||||
|
||||
/**
|
||||
* Get all the possible worlds that Multiverse has detected to be importable.
|
||||
*
|
||||
* @return A collection of world names that are deemed importable.
|
||||
*/
|
||||
Collection<String> getPotentialWorlds();
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* Multiverse-messaging.
|
||||
*/
|
||||
public interface MultiverseMessaging {
|
||||
/**
|
||||
* Sets the message-cooldown.
|
||||
* @param milliseconds The new message-cooldown in milliseconds.
|
||||
*/
|
||||
void setCooldown(int milliseconds);
|
||||
|
||||
/**
|
||||
* Sends a message to the specified sender if the cooldown has passed.
|
||||
*
|
||||
* @param sender The person/console to send the message to.
|
||||
* @param message The message to send.
|
||||
* @param ignoreCooldown If true this message will always be sent. Useful for things like menus
|
||||
* @return true if the message was sent, false if not.
|
||||
*/
|
||||
boolean sendMessage(CommandSender sender, String message, boolean ignoreCooldown);
|
||||
|
||||
/**
|
||||
* Sends a group of messages to the specified sender if the cooldown has passed.
|
||||
* This method is needed, since sending many messages in quick succession would violate
|
||||
* the cooldown.
|
||||
*
|
||||
* @param sender The person/console to send the message to.
|
||||
* @param messages The messages to send.
|
||||
* @param ignoreCooldown If true these messages will always be sent. Useful for things like menus
|
||||
* @return true if the message was sent, false if not.
|
||||
*/
|
||||
boolean sendMessages(CommandSender sender, String[] messages, boolean ignoreCooldown);
|
||||
|
||||
/**
|
||||
* Sends a group of messages to the specified sender if the cooldown has passed.
|
||||
* This method is needed, since sending many messages in quick succession would violate
|
||||
* the cooldown.
|
||||
*
|
||||
* @param sender The person/console to send the message to.
|
||||
* @param messages The messages to send.
|
||||
* @param ignoreCooldown If true these messages will always be sent. Useful for things like menus
|
||||
* @return true if the message was sent, false if not.
|
||||
*/
|
||||
boolean sendMessages(CommandSender sender, Collection<String> messages, boolean ignoreCooldown);
|
||||
|
||||
/**
|
||||
* Gets the message-cooldown.
|
||||
* @return The message-cooldown.
|
||||
*/
|
||||
int getCooldown();
|
||||
}
|
|
@ -1,161 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.utils.DebugLog;
|
||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||
|
||||
/**
|
||||
* Make things easier for MV-Plugins!
|
||||
*/
|
||||
public abstract class MultiversePlugin extends JavaPlugin implements MVPlugin {
|
||||
private MultiverseCore core;
|
||||
/**
|
||||
* Prefix for standard log entrys.
|
||||
*/
|
||||
protected String logTag;
|
||||
private DebugLog debugLog;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* Note: You can't override this, use {@link #onPluginEnable()} instead!
|
||||
* @see #onPluginEnable()
|
||||
*/
|
||||
@Override
|
||||
public final void onEnable() {
|
||||
MultiverseCore theCore = (MultiverseCore) this.getServer().getPluginManager().getPlugin("Multiverse-Core");
|
||||
if (theCore == null) {
|
||||
this.getLogger().severe("Core not found! The plugin dev needs to add a dependency!");
|
||||
this.getLogger().severe("Disabling!");
|
||||
this.getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
if (theCore.getProtocolVersion() < this.getProtocolVersion()) {
|
||||
this.getLogger().severe("You need a newer version of Multiverse-Core!");
|
||||
this.getLogger().severe("Disabling!");
|
||||
this.getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
this.setCore(theCore);
|
||||
|
||||
this.getServer().getLogger().info(String.format("%s - Version %s enabled - By %s",
|
||||
this.getDescription().getName(), this.getDescription().getVersion(), getAuthors()));
|
||||
getDataFolder().mkdirs();
|
||||
File debugLogFile = new File(getDataFolder(), "debug.log");
|
||||
try {
|
||||
debugLogFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
debugLog = new DebugLog(this.getDescription().getName(), getDataFolder() + File.separator + "debug.log");
|
||||
debugLog.setTag(String.format("[%s-Debug]", this.getDescription().getName()));
|
||||
|
||||
this.onPluginEnable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the Authors Array into a readable String with ',' and 'and'.
|
||||
*
|
||||
* @return The readable authors-{@link String}
|
||||
*/
|
||||
protected String getAuthors() {
|
||||
String authors = "";
|
||||
List<String> auths = this.getDescription().getAuthors();
|
||||
if (auths.size() == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (auths.size() == 1) {
|
||||
return auths.get(0);
|
||||
}
|
||||
|
||||
for (int i = 0; i < auths.size(); i++) {
|
||||
if (i == this.getDescription().getAuthors().size() - 1) {
|
||||
authors += " and " + this.getDescription().getAuthors().get(i);
|
||||
} else {
|
||||
authors += ", " + this.getDescription().getAuthors().get(i);
|
||||
}
|
||||
}
|
||||
return authors.substring(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the plugin is enabled.
|
||||
* @see #onEnable()
|
||||
*/
|
||||
protected abstract void onPluginEnable();
|
||||
|
||||
/**
|
||||
* You can register commands here.
|
||||
* @param handler The CommandHandler.
|
||||
*/
|
||||
protected abstract void registerCommands(CommandHandler handler);
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!this.isEnabled()) {
|
||||
sender.sendMessage("This plugin is Disabled!");
|
||||
return true;
|
||||
}
|
||||
|
||||
ArrayList<String> allArgs = new ArrayList<String>(args.length + 1);
|
||||
allArgs.add(command.getName());
|
||||
allArgs.addAll(Arrays.asList(args));
|
||||
return this.getCore().getCommandHandler().locateAndRunCommand(sender, allArgs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(Level level, String msg) {
|
||||
int debugLevel = this.getCore().getMVConfig().getGlobalDebug();
|
||||
if ((level == Level.FINE && debugLevel >= 1) || (level == Level.FINER && debugLevel >= 2)
|
||||
|| (level == Level.FINEST && debugLevel >= 3)) {
|
||||
debugLog.log(level, msg);
|
||||
} else if (level != Level.FINE && level != Level.FINER && level != Level.FINEST) {
|
||||
String message = new StringBuilder(getLogTag()).append(msg).toString();
|
||||
this.getServer().getLogger().log(level, message);
|
||||
debugLog.log(level, message);
|
||||
}
|
||||
}
|
||||
|
||||
private String getLogTag() {
|
||||
if (logTag == null)
|
||||
logTag = String.format("[%s]", this.getDescription().getName());
|
||||
return logTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the debug log-tag.
|
||||
* @param tag The new tag.
|
||||
*/
|
||||
protected final void setDebugLogTag(String tag) {
|
||||
this.debugLog.setTag(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String dumpVersionInfo(String buffer) {
|
||||
throw new UnsupportedOperationException("This is gone.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public final MultiverseCore getCore() {
|
||||
if (this.core == null)
|
||||
throw new IllegalStateException("Core is null!");
|
||||
return this.core;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setCore(MultiverseCore core) {
|
||||
this.core = core;
|
||||
}
|
||||
}
|
|
@ -1,674 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import com.onarandombox.MultiverseCore.enums.AllowedPortalType;
|
||||
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Difficulty;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldType;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The API for a Multiverse Handled World.
|
||||
*/
|
||||
public interface MultiverseWorld {
|
||||
/**
|
||||
* Returns the Bukkit world object that this world describes.
|
||||
*
|
||||
* @return A {@link World}
|
||||
*/
|
||||
World getCBWorld();
|
||||
|
||||
/**
|
||||
* Gets the name of this world. The name cannot be changed.
|
||||
* <p>
|
||||
* Note for plugin developers: Usually {@link #getAlias()}
|
||||
* is what you want to use instead of this method.
|
||||
*
|
||||
* @return The name of the world as a String.
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Gets the type of this world. As of 1.2 this will be:
|
||||
* FLAT, NORMAL or VERSION_1_1
|
||||
* <p>
|
||||
* This is <b>not</b> the generator.
|
||||
*
|
||||
* @return The Type of this world.
|
||||
*/
|
||||
WorldType getWorldType();
|
||||
|
||||
/**
|
||||
* Gets the environment of this world.
|
||||
*
|
||||
* @return A {@link org.bukkit.World.Environment}.
|
||||
*/
|
||||
World.Environment getEnvironment();
|
||||
|
||||
/**
|
||||
* Sets the environment of a world.
|
||||
* <p>
|
||||
* Note: This will ONLY take effect once the world is unloaded/reloaded.
|
||||
*
|
||||
* @param environment A {@link org.bukkit.World.Environment}.
|
||||
*/
|
||||
void setEnvironment(World.Environment environment);
|
||||
|
||||
/**
|
||||
* Gets the difficulty of this world.
|
||||
*
|
||||
* @return The difficulty of this world.
|
||||
*/
|
||||
Difficulty getDifficulty();
|
||||
|
||||
/**
|
||||
* Sets the difficulty of this world and returns true if success.
|
||||
* Valid string values are either an integer of difficulty(0-3) or
|
||||
* the name that resides in the Bukkit enum, ex. {@code PEACEFUL}
|
||||
*
|
||||
* @param difficulty The difficulty to set the world to as a string.
|
||||
* @return True if success, false if the provided string
|
||||
* could not be translated to a difficulty.
|
||||
* @deprecated Use {@link #setDifficulty(Difficulty)} or, if you have to
|
||||
* pass a string, use {@link #setPropertyValue(String, String)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
boolean setDifficulty(String difficulty);
|
||||
|
||||
/**
|
||||
* Sets the difficulty of this world and returns {@code true} on success.
|
||||
* Valid string values are either an integer of difficulty(0-3) or
|
||||
* the name that resides in the Bukkit enum, ex. PEACEFUL
|
||||
*
|
||||
* @param difficulty The new difficulty.
|
||||
* @return True if success, false if the operation failed... for whatever reason.
|
||||
*/
|
||||
boolean setDifficulty(Difficulty difficulty);
|
||||
|
||||
/**
|
||||
* Gets the world seed of this world.
|
||||
*
|
||||
* @return The Long version of the seed.
|
||||
*/
|
||||
long getSeed();
|
||||
|
||||
/**
|
||||
* Sets the seed of this world.
|
||||
*
|
||||
* @param seed A Long that is the seed.
|
||||
*/
|
||||
void setSeed(long seed);
|
||||
|
||||
/**
|
||||
* Gets the generator of this world.
|
||||
*
|
||||
* @return The name of the generator.
|
||||
*/
|
||||
String getGenerator();
|
||||
|
||||
/**
|
||||
* Sets the generator of this world.
|
||||
*
|
||||
* @param generator The new generator's name.
|
||||
*/
|
||||
void setGenerator(String generator);
|
||||
|
||||
/**
|
||||
* Gets the help-message for a property.
|
||||
* @param property The name of the property.
|
||||
* @return The help-message.
|
||||
* @throws PropertyDoesNotExistException Thrown if the property was not found.
|
||||
*/
|
||||
String getPropertyHelp(String property) throws PropertyDoesNotExistException;
|
||||
|
||||
/**
|
||||
* Gets a property as {@link String}.
|
||||
*
|
||||
* @param property The name of a world property to get.
|
||||
* @return The string-representation of that property.
|
||||
* @throws PropertyDoesNotExistException Thrown if the property was not found in the world.
|
||||
*/
|
||||
String getPropertyValue(String property) throws PropertyDoesNotExistException;
|
||||
|
||||
/**
|
||||
* Sets a property to a given value.
|
||||
*
|
||||
* @param property The name of a world property to set.
|
||||
* @param value A value in string representation, it will be parsed to the correct type.
|
||||
* @return True if the value was set, false if not.
|
||||
* @throws PropertyDoesNotExistException Thrown if the property was not found in the world.
|
||||
*/
|
||||
boolean setPropertyValue(String property, String value) throws PropertyDoesNotExistException;
|
||||
|
||||
/**
|
||||
* Adds a value to the given property. The property must be a {@link com.onarandombox.MultiverseCore.enums.AddProperties}.
|
||||
*
|
||||
* @param property The name of a {@link com.onarandombox.MultiverseCore.enums.AddProperties} to add a value to.
|
||||
* @param value A value in string representation, it will be parsed to the correct type.
|
||||
* @return True if the value was added, false if not.
|
||||
* @deprecated We changed the entire world-config-system. This is not compatible any more.
|
||||
*/
|
||||
@Deprecated
|
||||
boolean addToVariable(String property, String value);
|
||||
|
||||
/**
|
||||
* Removes a value from the given property. The property must be a {@link com.onarandombox.MultiverseCore.enums.AddProperties}.
|
||||
*
|
||||
* @param property The name of a {@link com.onarandombox.MultiverseCore.enums.AddProperties} to remove a value
|
||||
* from.
|
||||
* @param value A value in string representation, it will be parsed to the correct type.
|
||||
* @return True if the value was removed, false if not.
|
||||
* @deprecated We changed the entire world-config-system. This is not compatible any more.
|
||||
*/
|
||||
@Deprecated
|
||||
boolean removeFromVariable(String property, String value);
|
||||
|
||||
/**
|
||||
* Removes all values from the given property. The property must be a {@link com.onarandombox.MultiverseCore.enums.AddProperties}.
|
||||
*
|
||||
* @param property The name of a {@link com.onarandombox.MultiverseCore.enums.AddProperties} to clear.
|
||||
* @return True if it was cleared, false if not.
|
||||
* @deprecated We changed the entire world-config-system. This is not compatible any more.
|
||||
*/
|
||||
@Deprecated
|
||||
boolean clearVariable(String property);
|
||||
|
||||
/**
|
||||
* Clears a list property (sets it to []).
|
||||
*
|
||||
* @param property The property to clear.
|
||||
* @return True if success, false if fail.
|
||||
* @deprecated We changed the entire world-config-system. This is not compatible any more.
|
||||
*/
|
||||
@Deprecated
|
||||
boolean clearList(String property);
|
||||
// end of old config stuff
|
||||
|
||||
// permission stuff
|
||||
/**
|
||||
* Gets the lowercased name of the world. This method is required, since the permissables
|
||||
* lowercase all permissions when recalculating.
|
||||
* <p>
|
||||
* Note: This also means if a user has worlds named: world and WORLD, that they can both
|
||||
* exist, and both be teleported to independently, but their permissions **cannot** be
|
||||
* uniqueified at this time. See bug report #.
|
||||
*
|
||||
* @return The lowercased name of the world.
|
||||
*/
|
||||
String getPermissibleName();
|
||||
|
||||
/**
|
||||
* Gets the permission required to enter this world.
|
||||
*
|
||||
* @return The permission required to be exempt from charges to/from this world.
|
||||
*/
|
||||
Permission getAccessPermission();
|
||||
|
||||
/**
|
||||
* Gets the permission required to be exempt when entering.
|
||||
*
|
||||
* @return The permission required to be exempt when entering.
|
||||
*/
|
||||
Permission getExemptPermission();
|
||||
// end of permission stuff
|
||||
|
||||
/**
|
||||
* Gets the alias of this world.
|
||||
* <p>
|
||||
* This alias allows users to have a world named "world" but show up in the list as "FernIsland"
|
||||
*
|
||||
* @return The alias of the world as a String.
|
||||
*/
|
||||
String getAlias();
|
||||
|
||||
/**
|
||||
* Sets the alias of the world.
|
||||
*
|
||||
* @param alias A string that is the new alias.
|
||||
*/
|
||||
void setAlias(String alias);
|
||||
|
||||
/**
|
||||
* Gets the color that this world's name/alias will display as.
|
||||
*
|
||||
* @return The color of this world.
|
||||
*/
|
||||
ChatColor getColor();
|
||||
|
||||
/**
|
||||
* Sets the color that this world's name/alias will display as.
|
||||
*
|
||||
* @param color A valid color name.
|
||||
* @return True if the color was set, false if not.
|
||||
*/
|
||||
boolean setColor(String color);
|
||||
|
||||
/**
|
||||
* Gets the style that this world's name/alias will display as.
|
||||
*
|
||||
* @return The style of this world. {@code null} for "normal" style.
|
||||
*/
|
||||
ChatColor getStyle();
|
||||
|
||||
/**
|
||||
* Sets the style that this world's name/alias will display as.
|
||||
*
|
||||
* @param style A valid style name.
|
||||
* @return True if the style was set, false if not.
|
||||
*/
|
||||
boolean setStyle(String style);
|
||||
|
||||
/**
|
||||
* Tells you if someone entered a valid color.
|
||||
*
|
||||
* @param color A string that may translate to a color.
|
||||
* @return True if it is a color, false if not.
|
||||
*
|
||||
* @deprecated This has been moved: {@link com.onarandombox.MultiverseCore.enums.EnglishChatColor#isValidAliasColor(String)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean isValidAliasColor(String color);
|
||||
|
||||
/**
|
||||
* Returns a very nicely colored string (using Alias and Color if they are set).
|
||||
*
|
||||
* @return A nicely colored string.
|
||||
*/
|
||||
String getColoredWorldString();
|
||||
|
||||
// animals&monster stuff
|
||||
/**
|
||||
* Gets whether or not animals are allowed to spawn in this world.
|
||||
*
|
||||
* @return True if ANY animal can, false if no animals can spawn.
|
||||
*/
|
||||
boolean canAnimalsSpawn();
|
||||
|
||||
/**
|
||||
* Sets whether or not animals can spawn.
|
||||
* If there are values in {@link #getAnimalList()} and this is false,
|
||||
* those animals become the exceptions, and will spawn
|
||||
*
|
||||
* @param allowAnimalSpawn True to allow spawning of monsters, false to prevent.
|
||||
*/
|
||||
void setAllowAnimalSpawn(boolean allowAnimalSpawn);
|
||||
|
||||
/**
|
||||
* Returns a list of animals. This list always negates the {@link #canAnimalsSpawn()} result.
|
||||
*
|
||||
* @return A list of animals that will spawn if {@link #canAnimalsSpawn()} is false.
|
||||
*/
|
||||
List<String> getAnimalList();
|
||||
|
||||
/**
|
||||
* Gets whether or not monsters are allowed to spawn in this world.
|
||||
*
|
||||
* @return True if ANY monster can, false if no monsters can spawn.
|
||||
*/
|
||||
boolean canMonstersSpawn();
|
||||
|
||||
/**
|
||||
* Sets whether or not monsters can spawn.
|
||||
* If there are values in {@link #getMonsterList()} and this is false,
|
||||
* those monsters become the exceptions, and will spawn
|
||||
*
|
||||
* @param allowMonsterSpawn True to allow spawning of monsters, false to prevent.
|
||||
*/
|
||||
void setAllowMonsterSpawn(boolean allowMonsterSpawn);
|
||||
|
||||
/**
|
||||
* Returns a list of monsters. This list always negates the {@link #canMonstersSpawn()} result.
|
||||
*
|
||||
* @return A list of monsters that will spawn if {@link #canMonstersSpawn()} is false.
|
||||
*/
|
||||
List<String> getMonsterList();
|
||||
// end of animal&monster stuff
|
||||
|
||||
/**
|
||||
* Gets whether or not PVP is enabled in this world in some form (fake or not).
|
||||
*
|
||||
* @return True if players can take damage from other players.
|
||||
*/
|
||||
boolean isPVPEnabled();
|
||||
|
||||
/**
|
||||
* Turn pvp on or off. This setting is used to set the world's PVP mode.
|
||||
*
|
||||
* @param pvpMode True to enable PVP damage, false to disable it.
|
||||
*/
|
||||
void setPVPMode(boolean pvpMode);
|
||||
|
||||
/**
|
||||
* Turn pvp on or off. This setting is used to set the world's PVP mode, and thus relies on fakePVP
|
||||
*
|
||||
* @return True if this world has fakepvp on
|
||||
* @deprecated This is deprecated.
|
||||
*/
|
||||
@Deprecated
|
||||
boolean getFakePVP();
|
||||
|
||||
/**
|
||||
* Gets whether or not this world will display in chat, mvw and mvl regardless if a user has the
|
||||
* access permissions to go to this world.
|
||||
*
|
||||
* @return True if the world will be hidden, false if not.
|
||||
*/
|
||||
boolean isHidden();
|
||||
|
||||
/**
|
||||
* Sets whether or not this world will display in chat, mvw and mvl regardless if a user has the
|
||||
* access permissions to go to this world.
|
||||
*
|
||||
* @param hidden Set
|
||||
*/
|
||||
void setHidden(boolean hidden);
|
||||
|
||||
/**
|
||||
* Gets whether weather is enabled in this world.
|
||||
*
|
||||
* @return True if weather events will occur, false if not.
|
||||
*/
|
||||
boolean isWeatherEnabled();
|
||||
|
||||
/**
|
||||
* Sets whether or not there will be weather events in a given world.
|
||||
* If set to false, Multiverse will disable the weather in the world immediately.
|
||||
*
|
||||
* @param enableWeather True if weather events should occur in a world, false if not.
|
||||
*/
|
||||
void setEnableWeather(boolean enableWeather);
|
||||
|
||||
/**
|
||||
* Gets whether or not CraftBukkit is keeping the chunks for this world in memory.
|
||||
*
|
||||
* @return True if CraftBukkit is keeping spawn chunks in memory.
|
||||
*/
|
||||
boolean isKeepingSpawnInMemory();
|
||||
|
||||
/**
|
||||
* If true, tells Craftbukkit to keep a worlds spawn chunks loaded in memory (default: true)
|
||||
* If not, CraftBukkit will attempt to free memory when players have not used that world.
|
||||
* This will not happen immediately.
|
||||
*
|
||||
* @param keepSpawnInMemory If true, CraftBukkit will keep the spawn chunks loaded in memory.
|
||||
*/
|
||||
void setKeepSpawnInMemory(boolean keepSpawnInMemory);
|
||||
|
||||
/**
|
||||
* Gets the spawn location of this world.
|
||||
*
|
||||
* @return The spawn location of this world.
|
||||
*/
|
||||
Location getSpawnLocation();
|
||||
|
||||
/**
|
||||
* Sets the spawn location for a world.
|
||||
*
|
||||
* @param spawnLocation The spawn location for a world.
|
||||
*/
|
||||
void setSpawnLocation(Location spawnLocation);
|
||||
|
||||
/**
|
||||
* Gets whether or not the hunger level of players will go down in a world.
|
||||
*
|
||||
* @return True if it will go down, false if it will remain steady.
|
||||
*/
|
||||
boolean getHunger();
|
||||
|
||||
/**
|
||||
* Sets whether or not the hunger level of players will go down in a world.
|
||||
*
|
||||
* @param hungerEnabled True if hunger will go down, false to keep it at
|
||||
* the level they entered a world with.
|
||||
*/
|
||||
void setHunger(boolean hungerEnabled);
|
||||
|
||||
/**
|
||||
* Gets the GameMode of this world.
|
||||
*
|
||||
* @return The GameMode of this world.
|
||||
*/
|
||||
GameMode getGameMode();
|
||||
|
||||
/**
|
||||
* Sets the game mode of this world.
|
||||
*
|
||||
* @param gameMode A valid game mode string (either
|
||||
* an int ex. 0 or a string ex. creative).
|
||||
* @return True if the game mode was successfully changed, false if not.
|
||||
* @deprecated Use {@link #setGameMode(GameMode)} instead. If you have to
|
||||
* pass a string, use {@link #setPropertyValue(String, String)}.
|
||||
*/
|
||||
@Deprecated
|
||||
boolean setGameMode(String gameMode);
|
||||
|
||||
/**
|
||||
* Sets the game mode of this world.
|
||||
*
|
||||
* @param gameMode The new {@link GameMode}.
|
||||
* @return True if the game mode was successfully changed, false if not.
|
||||
*/
|
||||
boolean setGameMode(GameMode gameMode);
|
||||
|
||||
/**
|
||||
* Gets the amount of currency it requires to enter this world.
|
||||
*
|
||||
* @return The amount it costs to enter this world.
|
||||
*/
|
||||
double getPrice();
|
||||
|
||||
/**
|
||||
* Sets the price for entry to this world.
|
||||
* You can think of this like an amount.
|
||||
* The type can be set with {@link #setCurrency(Material)}
|
||||
*
|
||||
* @param price The Amount of money/item to enter the world.
|
||||
*/
|
||||
void setPrice(double price);
|
||||
|
||||
/**
|
||||
* Gets the type of currency that will be used when users enter this world. A value of null indicates a non-item
|
||||
* based currency is used.
|
||||
*
|
||||
* @return The type of currency that will be used when users enter this world.
|
||||
*/
|
||||
@Nullable
|
||||
Material getCurrency();
|
||||
|
||||
/**
|
||||
* Sets the type of item that will be required given the price is not 0.
|
||||
* Use a value of null to specify a non-item based currency.
|
||||
*
|
||||
* @param item The Type of currency that will be used when users enter this world.
|
||||
*/
|
||||
void setCurrency(@Nullable Material item);
|
||||
|
||||
/**
|
||||
* Gets the world players will respawn in if they die in this one.
|
||||
*
|
||||
* @return A world that exists on the server.
|
||||
*/
|
||||
World getRespawnToWorld();
|
||||
|
||||
/**
|
||||
* Sets the world players will respawn in if they die in this one.
|
||||
* Returns true upon success, false upon failure.
|
||||
*
|
||||
* @param respawnWorld The name of a world that exists on the server.
|
||||
* @return True if respawnWorld existed, false if not.
|
||||
*/
|
||||
boolean setRespawnToWorld(String respawnWorld);
|
||||
|
||||
/**
|
||||
* Gets the scaling value of this world.Really only has an effect if you use
|
||||
* Multiverse-NetherPortals.
|
||||
*
|
||||
* @return This world's non-negative, non-zero scale.
|
||||
*/
|
||||
double getScaling();
|
||||
|
||||
/**
|
||||
* Sets the scale of this world. Really only has an effect if you use
|
||||
* Multiverse-NetherPortals.
|
||||
*
|
||||
* @param scaling A scaling value, cannot be negative or 0.
|
||||
* @return Whether the scale was set successfully.
|
||||
*/
|
||||
boolean setScaling(double scaling);
|
||||
|
||||
/**
|
||||
* Gets whether or not a world will auto-heal players if the difficulty is on peaceful.
|
||||
*
|
||||
* @return True if the world should heal (default), false if not.
|
||||
*/
|
||||
boolean getAutoHeal();
|
||||
|
||||
/**
|
||||
* Sets whether or not a world will auto-heal players if the difficulty is on peaceful.
|
||||
*
|
||||
* @param heal True if the world will heal.
|
||||
*/
|
||||
void setAutoHeal(boolean heal);
|
||||
|
||||
/**
|
||||
* Gets whether or not Multiverse should auto-adjust the spawn for this world.
|
||||
*
|
||||
* @return True if Multiverse should adjust the spawn, false if not.
|
||||
*/
|
||||
boolean getAdjustSpawn();
|
||||
|
||||
/**
|
||||
* Sets whether or not Multiverse should auto-adjust the spawn for this world.
|
||||
*
|
||||
* @param adjust True if multiverse should adjust the spawn, false if not.
|
||||
*/
|
||||
void setAdjustSpawn(boolean adjust);
|
||||
|
||||
/**
|
||||
* Gets whether or not Multiverse should auto-load this world.
|
||||
*
|
||||
* @return True if Multiverse should auto-load this world.
|
||||
*/
|
||||
boolean getAutoLoad();
|
||||
|
||||
/**
|
||||
* Sets whether or not Multiverse should auto-load this world.
|
||||
* <p>
|
||||
* True is default.
|
||||
*
|
||||
* @param autoLoad True if multiverse should autoload this world the spawn, false if not.
|
||||
*/
|
||||
void setAutoLoad(boolean autoLoad);
|
||||
|
||||
/**
|
||||
* Gets whether or not a player who dies in this world will respawn in their
|
||||
* bed or follow the normal respawn pattern.
|
||||
*
|
||||
* @return True if players dying in this world should respawn at their bed.
|
||||
*/
|
||||
boolean getBedRespawn();
|
||||
|
||||
/**
|
||||
* Sets whether or not a player who dies in this world will respawn in their
|
||||
* bed or follow the normal respawn pattern.
|
||||
* <p>
|
||||
* True is default.
|
||||
*
|
||||
* @param autoLoad True if players dying in this world respawn at their bed.
|
||||
*/
|
||||
void setBedRespawn(boolean autoLoad);
|
||||
|
||||
/**
|
||||
* Sets the player limit for this world after which players without an override
|
||||
* permission node will not be allowed in. A value of -1 or less signifies no limit
|
||||
*
|
||||
* @param limit The new limit
|
||||
*/
|
||||
void setPlayerLimit(int limit);
|
||||
|
||||
/**
|
||||
* Gets the player limit for this world after which players without an override
|
||||
* permission node will not be allowed in. A value of -1 or less signifies no limit
|
||||
*
|
||||
* @return The player limit
|
||||
*/
|
||||
int getPlayerLimit();
|
||||
|
||||
/**
|
||||
* Same as {@link #getTime()}, but returns a string.
|
||||
* @return The time as a short string: 12:34pm
|
||||
*/
|
||||
String getTime();
|
||||
|
||||
/**
|
||||
* Sets the current time in a world.
|
||||
* <p>
|
||||
* This method will take the following formats:
|
||||
* 11:37am
|
||||
* 4:30p
|
||||
* day(morning), night, noon, midnight
|
||||
*
|
||||
* @param timeAsString The formatted time to set the world to.
|
||||
* @return True if the time was set, false if not.
|
||||
*/
|
||||
boolean setTime(String timeAsString);
|
||||
|
||||
/**
|
||||
* Sets The types of portals that are allowed in this world.
|
||||
*
|
||||
* @param type The type of portals allowed in this world.
|
||||
*/
|
||||
void allowPortalMaking(AllowedPortalType type);
|
||||
|
||||
/**
|
||||
* Gets which type(s) of portals are allowed to be constructed in this world.
|
||||
*
|
||||
* @return The type of portals that are allowed.
|
||||
*/
|
||||
AllowedPortalType getAllowedPortals();
|
||||
|
||||
// properties that are not "getter+setter" style
|
||||
/**
|
||||
* Gets a list of all the worlds that players CANNOT travel to from this world,
|
||||
* regardless of their access permissions.
|
||||
*
|
||||
* @return A List of world names.
|
||||
*/
|
||||
List<String> getWorldBlacklist();
|
||||
|
||||
/**
|
||||
* Gets all the names of all properties that can be SET.
|
||||
*
|
||||
* @return All property names, with alternating colors.
|
||||
*/
|
||||
String getAllPropertyNames();
|
||||
|
||||
/**
|
||||
* Whether or not players are allowed to fly in this world.
|
||||
*
|
||||
* @return True if players allowed to fly in this world.
|
||||
*/
|
||||
boolean getAllowFlight();
|
||||
|
||||
/**
|
||||
* Sets whether or not players are allowed to fly in this world.
|
||||
*
|
||||
* @param allowFlight True to allow flight in this world.
|
||||
*/
|
||||
void setAllowFlight(final boolean allowFlight);
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import com.onarandombox.MultiverseCore.enums.TeleportResult;
|
||||
|
||||
/**
|
||||
* Used to safely teleport people.
|
||||
*/
|
||||
public interface SafeTTeleporter extends Teleporter {
|
||||
|
||||
/**
|
||||
* Gets the next safe location around the given location.
|
||||
* @param l A {@link Location}.
|
||||
* @return A safe {@link Location}.
|
||||
*/
|
||||
Location getSafeLocation(Location l);
|
||||
|
||||
/**
|
||||
* Gets the next safe location around the given location.
|
||||
* @param l A {@link Location}.
|
||||
* @param tolerance The tolerance.
|
||||
* @param radius The radius.
|
||||
* @return A safe {@link Location}.
|
||||
*/
|
||||
Location getSafeLocation(Location l, int tolerance, int radius);
|
||||
|
||||
/**
|
||||
* Safely teleport the entity to the MVDestination. This will perform checks to see if the place is safe, and if
|
||||
* it's not, will adjust the final destination accordingly.
|
||||
*
|
||||
* @param teleporter Person who performed the teleport command.
|
||||
* @param teleportee Entity to teleport
|
||||
* @param d Destination to teleport them to
|
||||
* @return true for success, false for failure
|
||||
*/
|
||||
TeleportResult safelyTeleport(CommandSender teleporter, Entity teleportee, MVDestination d);
|
||||
|
||||
/**
|
||||
* Safely teleport the entity to the Location. This may perform checks to
|
||||
* see if the place is safe, and if
|
||||
* it's not, will adjust the final destination accordingly.
|
||||
*
|
||||
* @param teleporter Person who issued the teleport command.
|
||||
* @param teleportee Entity to teleport.
|
||||
* @param location Location to teleport them to.
|
||||
* @param safely Should the destination be checked for safety before teleport?
|
||||
* @return true for success, false for failure.
|
||||
*/
|
||||
TeleportResult safelyTeleport(CommandSender teleporter, Entity teleportee, Location location,
|
||||
boolean safely);
|
||||
|
||||
/**
|
||||
* Returns a safe location for the entity to spawn at.
|
||||
*
|
||||
* @param e The entity to spawn
|
||||
* @param d The MVDestination to take the entity to.
|
||||
* @return A new location to spawn the entity at.
|
||||
*/
|
||||
Location getSafeLocation(Entity e, MVDestination d);
|
||||
|
||||
/**
|
||||
* Finds a portal-block next to the specified {@link Location}.
|
||||
* @param l The {@link Location}
|
||||
* @return The next portal-block's {@link Location}.
|
||||
*/
|
||||
Location findPortalBlockNextTo(Location l);
|
||||
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.enums.TeleportResult;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface Teleporter {
|
||||
TeleportResult teleport(CommandSender teleporter, Player teleportee, MVDestination destination);
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
/**
|
||||
* Used to remove animals from worlds that don't belong there.
|
||||
*/
|
||||
public interface WorldPurger {
|
||||
/**
|
||||
* Synchronizes the given worlds with their settings.
|
||||
*
|
||||
* @param worlds A list of {@link MultiverseWorld}
|
||||
*/
|
||||
void purgeWorlds(List<MultiverseWorld> worlds);
|
||||
|
||||
/**
|
||||
* Convenience method for {@link #purgeWorld(MultiverseWorld, java.util.List, boolean, boolean)} that takes the settings from the world-config.
|
||||
*
|
||||
* @param world The {@link MultiverseWorld}.
|
||||
*/
|
||||
void purgeWorld(MultiverseWorld world);
|
||||
|
||||
/**
|
||||
* Clear all animals/monsters that do not belong to a world according to the config.
|
||||
*
|
||||
* @param mvworld The {@link MultiverseWorld}.
|
||||
* @param thingsToKill A {@link List} of animals/monsters to be killed.
|
||||
* @param negateAnimals Whether the monsters in the list should be negated.
|
||||
* @param negateMonsters Whether the animals in the list should be negated.
|
||||
*/
|
||||
void purgeWorld(MultiverseWorld mvworld, List<String> thingsToKill, boolean negateAnimals,
|
||||
boolean negateMonsters);
|
||||
|
||||
/**
|
||||
* Clear all animals/monsters that do not belong to a world according to the config.
|
||||
*
|
||||
* @param mvworld The {@link MultiverseWorld}.
|
||||
* @param thingsToKill A {@link List} of animals/monsters to be killed.
|
||||
* @param negateAnimals Whether the monsters in the list should be negated.
|
||||
* @param negateMonsters Whether the animals in the list should be negated.
|
||||
* @param sender The {@link CommandSender} that initiated the action. He will/should be notified.
|
||||
*/
|
||||
void purgeWorld(MultiverseWorld mvworld, List<String> thingsToKill, boolean negateAnimals,
|
||||
boolean negateMonsters, CommandSender sender);
|
||||
|
||||
/**
|
||||
* Determines whether the specified creature should be killed.
|
||||
*
|
||||
* @param e The creature.
|
||||
* @param thingsToKill A {@link List} of animals/monsters to be killed.
|
||||
* @param negateAnimals Whether the monsters in the list should be negated.
|
||||
* @param negateMonsters Whether the animals in the list should be negated.
|
||||
* @return {@code true} if the creature should be killed, otherwise {@code false}.
|
||||
*/
|
||||
boolean shouldWeKillThisCreature(Entity e, List<String> thingsToKill, boolean negateAnimals, boolean negateMonsters);
|
||||
|
||||
/**
|
||||
* Determines whether the specified creature should be killed and automatically reads the params from a world object.
|
||||
*
|
||||
* @param w The world.
|
||||
* @param e The creature.
|
||||
* @return {@code true} if the creature should be killed, otherwise {@code false}.
|
||||
*/
|
||||
boolean shouldWeKillThisCreature(MultiverseWorld w, Entity e);
|
||||
}
|
|
@ -1,162 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Allows management of Anchor Destinations.
|
||||
*/
|
||||
public class AnchorCommand extends PaginatedCoreCommand<String> {
|
||||
|
||||
public AnchorCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Create, Delete and Manage Anchor Destinations.");
|
||||
this.setCommandUsage("/mv anchor " + ChatColor.GREEN + "{name}" + ChatColor.GOLD + " [-d]");
|
||||
this.setArgRange(0, 2);
|
||||
this.addKey("mv anchor");
|
||||
this.addKey("mv anchors");
|
||||
this.addKey("mvanchor");
|
||||
this.addKey("mvanchors");
|
||||
this.addCommandExample("/mv anchor " + ChatColor.GREEN + "awesomething");
|
||||
this.addCommandExample("/mv anchor " + ChatColor.GREEN + "otherthing");
|
||||
this.addCommandExample("/mv anchor " + ChatColor.GREEN + "awesomething " + ChatColor.RED + "-d");
|
||||
this.addCommandExample("/mv anchors ");
|
||||
this.setPermission("multiverse.core.anchor.list", "Allows a player to list all anchors.", PermissionDefault.OP);
|
||||
this.addAdditonalPermission(new Permission("multiverse.core.anchor.create",
|
||||
"Allows a player to create anchors.", PermissionDefault.OP));
|
||||
this.addAdditonalPermission(new Permission("multiverse.core.anchor.delete",
|
||||
"Allows a player to delete anchors.", PermissionDefault.OP));
|
||||
this.setItemsPerPage(8); // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
}
|
||||
|
||||
private List<String> getFancyAnchorList(Player p) {
|
||||
List<String> anchorList = new ArrayList<String>();
|
||||
ChatColor color = ChatColor.GREEN;
|
||||
for (String anchor : this.plugin.getAnchorManager().getAnchors(p)) {
|
||||
anchorList.add(color + anchor);
|
||||
color = (color == ChatColor.GREEN) ? ChatColor.GOLD : ChatColor.GREEN;
|
||||
}
|
||||
return anchorList;
|
||||
}
|
||||
|
||||
private void showList(CommandSender sender, List<String> args) {
|
||||
if (!this.plugin.getMVPerms().hasPermission(sender, "multiverse.core.anchor.list", true)) {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to list anchors!");
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + "====[ Multiverse Anchor List ]====");
|
||||
Player p = null;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
}
|
||||
|
||||
|
||||
FilterObject filterObject = this.getPageAndFilter(args);
|
||||
|
||||
List<String> availableAnchors = new ArrayList<String>(this.getFancyAnchorList(p));
|
||||
if (filterObject.getFilter().length() > 0) {
|
||||
availableAnchors = this.getFilteredItems(availableAnchors, filterObject.getFilter());
|
||||
if (availableAnchors.size() == 0) {
|
||||
sender.sendMessage(ChatColor.RED + "Sorry... " + ChatColor.WHITE
|
||||
+ "No anchors matched your filter: " + ChatColor.AQUA + filterObject.getFilter());
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (availableAnchors.size() == 0) {
|
||||
sender.sendMessage(ChatColor.RED + "Sorry... " + ChatColor.WHITE + "No anchors were defined.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
for (String c : availableAnchors) {
|
||||
sender.sendMessage(c);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int totalPages = (int) Math.ceil(availableAnchors.size() / (this.itemsPerPage + 0.0));
|
||||
|
||||
if (filterObject.getPage() > totalPages) {
|
||||
filterObject.setPage(totalPages);
|
||||
} else if (filterObject.getPage() < 1) {
|
||||
filterObject.setPage(1);
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.AQUA + " Page " + filterObject.getPage() + " of " + totalPages);
|
||||
|
||||
this.showPage(filterObject.getPage(), sender, availableAnchors);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
if (args.size() == 0) {
|
||||
this.showList(sender, args);
|
||||
return;
|
||||
}
|
||||
if (args.size() == 1 && (this.getPageAndFilter(args).getPage() != 1 || args.get(0).equals("1"))) {
|
||||
this.showList(sender, args);
|
||||
return;
|
||||
}
|
||||
if (args.size() == 2 && args.get(1).equalsIgnoreCase("-d")) {
|
||||
if (!this.plugin.getMVPerms().hasPermission(sender, "multiverse.core.anchor.delete", true)) {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to delete anchors!");
|
||||
} else {
|
||||
if (this.plugin.getAnchorManager().deleteAnchor(args.get(0))) {
|
||||
sender.sendMessage("Anchor '" + args.get(0) + "' was successfully " + ChatColor.RED + "deleted!");
|
||||
} else {
|
||||
sender.sendMessage("Anchor '" + args.get(0) + "' was " + ChatColor.RED + " NOT " + ChatColor.WHITE + "deleted!");
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("You must be a player to create Anchors.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.plugin.getMVPerms().hasPermission(sender, "multiverse.core.anchor.create", true)) {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to create anchors!");
|
||||
} else {
|
||||
Player player = (Player) sender;
|
||||
if (this.plugin.getAnchorManager().saveAnchorLocation(args.get(0), player.getLocation())) {
|
||||
sender.sendMessage("Anchor '" + args.get(0) + "' was successfully " + ChatColor.GREEN + "created!");
|
||||
} else {
|
||||
sender.sendMessage("Anchor '" + args.get(0) + "' was " + ChatColor.RED + " NOT " + ChatColor.WHITE + "created!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getFilteredItems(List<String> availableItems, String filter) {
|
||||
List<String> filtered = new ArrayList<String>();
|
||||
for (String s : availableItems) {
|
||||
if (s.matches("(?i).*" + filter + ".*")) {
|
||||
filtered.add(s);
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getItemText(String item) {
|
||||
return item;
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.InvalidDestination;
|
||||
import com.onarandombox.MultiverseCore.utils.MVPermissions;
|
||||
import com.onarandombox.MultiverseCore.utils.PlayerFinder;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
/**
|
||||
* Checks to see if a player can go to a destination.
|
||||
*/
|
||||
public class CheckCommand extends MultiverseCommand {
|
||||
|
||||
public CheckCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Help you validate your multiverse settings");
|
||||
this.setCommandUsage("/mv check " + ChatColor.GREEN + "{PLAYER} {DESTINATION}");
|
||||
this.setArgRange(2, 2);
|
||||
this.addKey("mv check");
|
||||
this.addKey("mvcheck");
|
||||
this.addCommandExample("/mv check " + ChatColor.GREEN + "fernferret " + ChatColor.LIGHT_PURPLE + "w:MyWorld");
|
||||
this.addCommandExample("/mv check " + ChatColor.GREEN + "Rigby90 " + ChatColor.LIGHT_PURPLE + "p:MyPortal");
|
||||
this.addCommandExample("/mv check " + ChatColor.GREEN + "lithium3141 " + ChatColor.LIGHT_PURPLE + "ow:WarpName");
|
||||
this.setPermission("multiverse.core.debug", "Checks to see if a player can go to a destination. Prints debug if false.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
Player p = PlayerFinder.get(args.get(0), sender);
|
||||
if (p == null) {
|
||||
sender.sendMessage("Could not find player " + ChatColor.GREEN + args.get(0));
|
||||
sender.sendMessage("Are they online?");
|
||||
return;
|
||||
}
|
||||
MVDestination dest = this.plugin.getDestFactory().getDestination(args.get(1));
|
||||
if (dest instanceof InvalidDestination) {
|
||||
sender.sendMessage(String.format("You asked if '%s' could go to %s%s%s,",
|
||||
args.get(0), ChatColor.GREEN, args.get(0), ChatColor.WHITE));
|
||||
sender.sendMessage("but I couldn't find a Destination of that name? Did you type it correctly?");
|
||||
return;
|
||||
}
|
||||
|
||||
MVPermissions perms = this.plugin.getMVPerms();
|
||||
perms.tellMeWhyICantDoThis(sender, p, dest);
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
|
||||
/**
|
||||
* Creates a clone of a world.
|
||||
*/
|
||||
public class CloneCommand extends MultiverseCommand {
|
||||
private MVWorldManager worldManager;
|
||||
|
||||
public CloneCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Clone World");
|
||||
this.setCommandUsage("/mv clone" + ChatColor.GREEN + " {TARGET} {NAME}" + ChatColor.GOLD + " -g [GENERATOR[:ID]]");
|
||||
this.setArgRange(2, 4); // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
this.addKey("mvclone");
|
||||
this.addKey("mvcl");
|
||||
this.addKey("mv cl");
|
||||
this.addKey("mv clone");
|
||||
this.addCommandExample("/mv clone " + ChatColor.GOLD + "world" + ChatColor.GREEN + " world_backup");
|
||||
this.addCommandExample("/mv clone " + ChatColor.GOLD + "skyblock_pristine" + ChatColor.GREEN + " skyblock");
|
||||
this.setPermission("multiverse.core.clone", "Clones a world.", PermissionDefault.OP);
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
String oldName = args.get(0);
|
||||
if (!this.worldManager.hasUnloadedWorld(oldName, true)) {
|
||||
// If no world was found, we can't clone.
|
||||
sender.sendMessage("Sorry, Multiverse doesn't know about world " + oldName + ", so we can't clone it!");
|
||||
sender.sendMessage("Check the " + ChatColor.GREEN + "/mv list" + ChatColor.WHITE + " command to verify it is listed.");
|
||||
return;
|
||||
}
|
||||
if (this.plugin.getMVWorldManager().cloneWorld(oldName, args.get(1))) {
|
||||
sender.sendMessage(ChatColor.GREEN + "World cloned!");
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "World could NOT be cloned!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Allows you to set Global MV Variables.
|
||||
*/
|
||||
public class ConfigCommand extends MultiverseCommand {
|
||||
public ConfigCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Configuration");
|
||||
this.setCommandUsage("/mv config " + ChatColor.GREEN + "{PROPERTY} {VALUE}");
|
||||
this.setArgRange(1, 2);
|
||||
this.addKey("mv config");
|
||||
this.addKey("mvconfig");
|
||||
this.addKey("mv conf");
|
||||
this.addKey("mvconf");
|
||||
this.addCommandExample("/mv config show");
|
||||
this.addCommandExample("/mv config " + ChatColor.GREEN + "debug" + ChatColor.AQUA + " 3");
|
||||
this.addCommandExample("/mv config " + ChatColor.GREEN + "enforceaccess" + ChatColor.AQUA + " false");
|
||||
this.setPermission("multiverse.core.config", "Allows you to set Global MV Variables.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
if (args.size() <= 1) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
Map<String, Object> serializedConfig = this.plugin.getMVConfig().serialize();
|
||||
for (Map.Entry<String, Object> entry : serializedConfig.entrySet()) {
|
||||
builder.append(ChatColor.GREEN);
|
||||
builder.append(entry.getKey());
|
||||
builder.append(ChatColor.WHITE).append(" = ").append(ChatColor.GOLD);
|
||||
builder.append(entry.getValue().toString());
|
||||
builder.append(ChatColor.WHITE).append(", ");
|
||||
}
|
||||
String message = builder.toString();
|
||||
message = message.substring(0, message.length() - 2);
|
||||
sender.sendMessage(message);
|
||||
return;
|
||||
}
|
||||
if (!this.plugin.getMVConfig().setConfigProperty(args.get(0).toLowerCase(), args.get(1))) {
|
||||
sender.sendMessage(String.format("%sSetting '%s' to '%s' failed!", ChatColor.RED, args.get(0).toLowerCase(), args.get(1)));
|
||||
return;
|
||||
}
|
||||
|
||||
// special rule
|
||||
if (args.get(0).equalsIgnoreCase("firstspawnworld")) {
|
||||
// Don't forget to set the world!
|
||||
this.plugin.getMVWorldManager().setFirstSpawnWorld(args.get(1));
|
||||
}
|
||||
|
||||
if (this.plugin.saveMVConfigs()) {
|
||||
sender.sendMessage(ChatColor.GREEN + "SUCCESS!" + ChatColor.WHITE + " Values were updated successfully!");
|
||||
this.plugin.loadConfigs();
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "FAIL!" + ChatColor.WHITE + " Check your console for details!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Confirms actions.
|
||||
*/
|
||||
public class ConfirmCommand extends MultiverseCommand {
|
||||
|
||||
public ConfirmCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
// Any command that is dangerous should require op
|
||||
this.setName("Confirms a command that could destroy life, the universe and everything.");
|
||||
this.setCommandUsage("/mv confirm");
|
||||
this.setArgRange(0, 0);
|
||||
this.addKey("mvconfirm");
|
||||
this.addKey("mv confirm");
|
||||
this.addCommandExample("/mv confirm");
|
||||
this.setPermission("multiverse.core.confirm", "If you have not been prompted to use this, it will not do anything.", PermissionDefault.OP);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
this.plugin.getCommandQueueManager().runQueuedCommand(sender);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Returns detailed information on the Players where abouts.
|
||||
*/
|
||||
public class CoordCommand extends MultiverseCommand {
|
||||
private MVWorldManager worldManager;
|
||||
|
||||
public CoordCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Coordinates");
|
||||
this.setCommandUsage("/mv coord");
|
||||
this.setArgRange(0, 0);
|
||||
this.addKey("mv coord");
|
||||
this.addKey("mvcoord");
|
||||
this.addKey("mvco");
|
||||
this.addCommandExample("/mv coord");
|
||||
this.setPermission("multiverse.core.coord", "Returns detailed information on the Players where abouts.", PermissionDefault.OP);
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
// Check if the command was sent from a Player.
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
World world = p.getWorld();
|
||||
|
||||
if (!this.worldManager.isMVWorld(world.getName())) {
|
||||
this.plugin.showNotMVWorldMessage(sender, world.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
MultiverseWorld mvworld = this.worldManager.getMVWorld(world.getName());
|
||||
|
||||
p.sendMessage(ChatColor.AQUA + "--- Location Information ---");
|
||||
p.sendMessage(ChatColor.AQUA + "World: " + ChatColor.WHITE + world.getName());
|
||||
p.sendMessage(ChatColor.AQUA + "Alias: " + mvworld.getColoredWorldString());
|
||||
p.sendMessage(ChatColor.AQUA + "World Scale: " + ChatColor.WHITE + mvworld.getScaling());
|
||||
DecimalFormat df = new DecimalFormat();
|
||||
df.setMinimumFractionDigits(0);
|
||||
df.setMaximumFractionDigits(2);
|
||||
p.sendMessage(ChatColor.AQUA + "Coordinates: " + ChatColor.WHITE + plugin.getLocationManipulation().strCoords(p.getLocation()));
|
||||
p.sendMessage(ChatColor.AQUA + "Direction: " + ChatColor.WHITE + plugin.getLocationManipulation().getDirection(p.getLocation()));
|
||||
p.sendMessage(ChatColor.AQUA + "Block: " + ChatColor.WHITE + world.getBlockAt(p.getLocation()).getType());
|
||||
} else {
|
||||
sender.sendMessage("This command needs to be used from a Player.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,131 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.WorldType;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Creates a new world and loads it.
|
||||
*/
|
||||
public class CreateCommand extends MultiverseCommand {
|
||||
private MVWorldManager worldManager;
|
||||
|
||||
public CreateCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Create World");
|
||||
this.setCommandUsage(String.format("/mv create %s{NAME} {ENV} %s-s [SEED] -g [GENERATOR[:ID]] -t [WORLDTYPE] [-n] -a [true|false]",
|
||||
ChatColor.GREEN, ChatColor.GOLD));
|
||||
this.setArgRange(2, 11); // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
this.addKey("mvcreate");
|
||||
this.addKey("mvc");
|
||||
this.addKey("mv create");
|
||||
this.setPermission("multiverse.core.create", "Creates a new world and loads it.", PermissionDefault.OP);
|
||||
this.addCommandExample("/mv create " + ChatColor.GOLD + "world" + ChatColor.GREEN + " normal");
|
||||
this.addCommandExample("/mv create " + ChatColor.GOLD + "lavaland" + ChatColor.RED + " nether");
|
||||
this.addCommandExample("/mv create " + ChatColor.GOLD + "starwars" + ChatColor.AQUA + " end");
|
||||
this.addCommandExample("/mv create " + ChatColor.GOLD + "flatroom" + ChatColor.GREEN + " normal" + ChatColor.AQUA + " -t flat");
|
||||
this.addCommandExample("/mv create " + ChatColor.GOLD + "gargamel" + ChatColor.GREEN + " normal" + ChatColor.DARK_AQUA + " -s gargamel");
|
||||
this.addCommandExample("/mv create " + ChatColor.GOLD + "moonworld" + ChatColor.GREEN + " normal" + ChatColor.DARK_AQUA + " -g BukkitFullOfMoon");
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
}
|
||||
|
||||
private String trimWorldName(String userInput) {
|
||||
// Removes relative paths.
|
||||
return userInput.replaceAll("^[./\\\\]+", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
String worldName = trimWorldName(args.get(0));
|
||||
File worldFile = new File(this.plugin.getServer().getWorldContainer(), worldName);
|
||||
String env = args.get(1);
|
||||
String seed = CommandHandler.getFlag("-s", args);
|
||||
String generator = CommandHandler.getFlag("-g", args);
|
||||
boolean allowStructures = true;
|
||||
String structureString = CommandHandler.getFlag("-a", args);
|
||||
if (structureString != null) {
|
||||
allowStructures = Boolean.parseBoolean(structureString);
|
||||
}
|
||||
String typeString = CommandHandler.getFlag("-t", args);
|
||||
boolean useSpawnAdjust = true;
|
||||
for (String s : args) {
|
||||
if (s.equalsIgnoreCase("-n")) {
|
||||
useSpawnAdjust = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure the world name doesn't contain the words 'plugins' and '.dat'
|
||||
if(worldName.contains("plugins")||worldName.contains(".dat")){
|
||||
sender.sendMessage(ChatColor.RED + "Multiverse cannot create a world that contains 'plugins' or '.dat'");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.worldManager.isMVWorld(worldName)) {
|
||||
sender.sendMessage(ChatColor.RED + "Multiverse cannot create " + ChatColor.GOLD + ChatColor.UNDERLINE
|
||||
+ "another" + ChatColor.RESET + ChatColor.RED + " world named " + worldName);
|
||||
return;
|
||||
}
|
||||
|
||||
if (worldFile.exists()) {
|
||||
sender.sendMessage(ChatColor.RED + "A Folder/World already exists with this name!");
|
||||
sender.sendMessage(ChatColor.RED + "If you are confident it is a world you can import with /mvimport");
|
||||
return;
|
||||
}
|
||||
|
||||
Environment environment = EnvironmentCommand.getEnvFromString(env);
|
||||
if (environment == null) {
|
||||
sender.sendMessage(ChatColor.RED + "That is not a valid environment.");
|
||||
EnvironmentCommand.showEnvironments(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
// If they didn't specify a type, default to NORMAL
|
||||
if (typeString == null) {
|
||||
typeString = "NORMAL";
|
||||
}
|
||||
WorldType type = EnvironmentCommand.getWorldTypeFromString(typeString);
|
||||
if (type == null) {
|
||||
sender.sendMessage(ChatColor.RED + "That is not a valid World Type.");
|
||||
EnvironmentCommand.showWorldTypes(sender);
|
||||
return;
|
||||
}
|
||||
// Determine if the generator is valid. #918
|
||||
if (generator != null) {
|
||||
List<String> genarray = new ArrayList<String>(Arrays.asList(generator.split(":")));
|
||||
if (genarray.size() < 2) {
|
||||
// If there was only one arg specified, pad with another empty one.
|
||||
genarray.add("");
|
||||
}
|
||||
if (this.worldManager.getChunkGenerator(genarray.get(0), genarray.get(1), "test") == null) {
|
||||
// We have an invalid generator.
|
||||
sender.sendMessage("Invalid generator! '" + generator + "'. " + ChatColor.RED + "Aborting world creation.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
Command.broadcastCommandMessage(sender, "Starting creation of world '" + worldName + "'...");
|
||||
|
||||
if (this.worldManager.addWorld(worldName, environment, seed, type, allowStructures, generator, useSpawnAdjust)) {
|
||||
Command.broadcastCommandMessage(sender, "Complete!");
|
||||
} else {
|
||||
Command.broadcastCommandMessage(sender, "FAILED.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Enables debug-information.
|
||||
*/
|
||||
public class DebugCommand extends MultiverseCommand {
|
||||
|
||||
public DebugCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Turn Debug on/off?");
|
||||
this.setCommandUsage("/mv debug" + ChatColor.GOLD + " [1|2|3|off|silent]");
|
||||
this.setArgRange(0, 1);
|
||||
this.addKey("mv debug");
|
||||
this.addKey("mv d");
|
||||
this.addKey("mvdebug");
|
||||
this.addCommandExample("/mv debug " + ChatColor.GOLD + "2");
|
||||
this.setPermission("multiverse.core.debug", "Spams the console a bunch.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
if (args.size() == 1) {
|
||||
if (args.get(0).equalsIgnoreCase("off")) {
|
||||
plugin.getMVConfig().setGlobalDebug(0);
|
||||
} else {
|
||||
try {
|
||||
int debugLevel = Integer.parseInt(args.get(0));
|
||||
if (debugLevel > 3 || debugLevel < 0) {
|
||||
throw new NumberFormatException();
|
||||
}
|
||||
plugin.getMVConfig().setGlobalDebug(debugLevel);
|
||||
} catch (NumberFormatException e) {
|
||||
sender.sendMessage(ChatColor.RED + "Error" + ChatColor.WHITE
|
||||
+ " setting debug level. Please use a number 0-3 " + ChatColor.AQUA + "(3 being many many messages!)");
|
||||
}
|
||||
}
|
||||
plugin.saveMVConfigs();
|
||||
}
|
||||
this.displayDebugMode(sender);
|
||||
}
|
||||
|
||||
private void displayDebugMode(CommandSender sender) {
|
||||
final int debugLevel = plugin.getMVConfig().getGlobalDebug();
|
||||
if (debugLevel == 0) {
|
||||
sender.sendMessage("Multiverse Debug mode is " + ChatColor.RED + "OFF");
|
||||
} else {
|
||||
sender.sendMessage("Multiverse Debug mode is " + ChatColor.GREEN + debugLevel);
|
||||
Logging.fine("Multiverse Debug ENABLED");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.commandtools.queue.QueuedCommand;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Deletes worlds.
|
||||
*/
|
||||
public class DeleteCommand extends MultiverseCommand {
|
||||
|
||||
public DeleteCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Delete World");
|
||||
this.setCommandUsage("/mv delete" + ChatColor.GREEN + " {WORLD}");
|
||||
this.setArgRange(1, 1);
|
||||
this.addKey("mvdelete");
|
||||
this.addKey("mv delete");
|
||||
this.addCommandExample("/mv delete " + ChatColor.GOLD + "MyWorld");
|
||||
this.setPermission("multiverse.core.delete", "Deletes a world on your server. " + ChatColor.RED + "PERMANENTLY.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
String worldName = args.get(0);
|
||||
|
||||
this.plugin.getCommandQueueManager().addToQueue(new QueuedCommand(
|
||||
sender,
|
||||
deleteRunnable(sender, worldName),
|
||||
String.format("Are you sure you want to delete world '%s'? You cannot undo this action.", worldName)
|
||||
));
|
||||
}
|
||||
|
||||
private Runnable deleteRunnable(@NotNull CommandSender sender,
|
||||
@NotNull String worldName) {
|
||||
|
||||
return () -> {
|
||||
sender.sendMessage(String.format("Deleting world '%s'...", worldName));
|
||||
if (this.plugin.getMVWorldManager().deleteWorld(worldName)) {
|
||||
sender.sendMessage(String.format("%sWorld %s was deleted!", ChatColor.GREEN, worldName));
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(String.format("%sThere was an issue deleting '%s'! Please check console for errors.",
|
||||
ChatColor.RED, worldName));
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,118 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldType;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Lists valid known environments.
|
||||
*/
|
||||
public class EnvironmentCommand extends MultiverseCommand {
|
||||
|
||||
public EnvironmentCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("List Environments");
|
||||
this.setCommandUsage("/mv env");
|
||||
this.setArgRange(0, 0);
|
||||
this.addKey("mvenv");
|
||||
this.addKey("mv env");
|
||||
this.addKey("mv type");
|
||||
this.addKey("mv environment");
|
||||
this.addKey("mv environments");
|
||||
this.addCommandExample("/mv env");
|
||||
this.setPermission("multiverse.core.list.environments", "Lists valid known environments/world types.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows all valid known environments to a {@link CommandSender}.
|
||||
*
|
||||
* @param sender The {@link CommandSender}.
|
||||
*/
|
||||
public static void showEnvironments(CommandSender sender) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "Valid Environments are:");
|
||||
sender.sendMessage(ChatColor.GREEN + "NORMAL");
|
||||
sender.sendMessage(ChatColor.RED + "NETHER");
|
||||
sender.sendMessage(ChatColor.AQUA + "END");
|
||||
}
|
||||
/**
|
||||
* Shows all valid known world types to a {@link CommandSender}.
|
||||
*
|
||||
* @param sender The {@link CommandSender}.
|
||||
*/
|
||||
public static void showWorldTypes(CommandSender sender) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "Valid World Types are:");
|
||||
sender.sendMessage(String.format("%sNORMAL%s, %sFLAT, %sLARGEBIOMES %sor %sVERSION_1_1",
|
||||
ChatColor.GREEN, ChatColor.WHITE, ChatColor.AQUA, ChatColor.RED, ChatColor.WHITE, ChatColor.GOLD));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
EnvironmentCommand.showEnvironments(sender);
|
||||
EnvironmentCommand.showWorldTypes(sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a {@link String} into a {@link WorldType}.
|
||||
*
|
||||
* @param type The WorldType as a {@link String}
|
||||
* @return The WorldType as a {@link WorldType}
|
||||
*/
|
||||
public static WorldType getWorldTypeFromString(String type) {
|
||||
// Don't reference the enum directly as there aren't that many, and we can be more forgiving to users this way
|
||||
if (type.equalsIgnoreCase("normal")) {
|
||||
type = "NORMAL";
|
||||
} else if (type.equalsIgnoreCase("flat")) {
|
||||
type = "FLAT";
|
||||
} else if (type.equalsIgnoreCase("largebiomes")) {
|
||||
type = "LARGE_BIOMES";
|
||||
} else if (type.equalsIgnoreCase("amplified")) {
|
||||
type = "AMPLIFIED";
|
||||
}
|
||||
try {
|
||||
// Now that we've converted a potentially unfriendly value
|
||||
// to a friendly one, get it from the ENUM!
|
||||
return WorldType.valueOf(type);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a {@link String} into an {@link org.bukkit.World.Environment}.
|
||||
*
|
||||
* @param env The environment as {@link String}
|
||||
* @return The environment as {@link org.bukkit.World.Environment}
|
||||
*/
|
||||
public static World.Environment getEnvFromString(String env) {
|
||||
env = env.toUpperCase();
|
||||
// Don't reference the enum directly as there aren't that many, and we can be more forgiving to users this way
|
||||
if (env.equalsIgnoreCase("HELL") || env.equalsIgnoreCase("NETHER"))
|
||||
env = "NETHER";
|
||||
|
||||
if (env.equalsIgnoreCase("END") || env.equalsIgnoreCase("THEEND") || env.equalsIgnoreCase("STARWARS"))
|
||||
env = "THE_END";
|
||||
|
||||
if (env.equalsIgnoreCase("NORMAL") || env.equalsIgnoreCase("WORLD"))
|
||||
env = "NORMAL";
|
||||
|
||||
try {
|
||||
// Now that we've converted a potentially unfriendly value
|
||||
// to a friendly one, get it from the ENUM!
|
||||
return World.Environment.valueOf(env);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,116 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Allows management of Anchor Destinations.
|
||||
*/
|
||||
public class GameruleCommand extends MultiverseCommand {
|
||||
|
||||
public GameruleCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Set a Minecraft Game Rule for a World.");
|
||||
this.setCommandUsage("/mv gamerule " + ChatColor.GREEN + "{RULE} {VALUE}" + ChatColor.GOLD + " [WORLD]");
|
||||
this.setArgRange(2, 3);
|
||||
this.addKey("mv gamerule");
|
||||
this.addKey("mv rule");
|
||||
this.addKey("mvgamerule");
|
||||
this.addKey("mvrule");
|
||||
this.addCommandExample("/mv gamerule " + ChatColor.GREEN + "doMobLoot false");
|
||||
this.addCommandExample("/mvrule " + ChatColor.GREEN + "keepInventory true " + ChatColor.RED + "world_nether");
|
||||
this.setPermission("multiverse.core.gamerule.set", "Allows a player to set a gamerule.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
// We NEED a world from the command line
|
||||
final Player p;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
} else {
|
||||
p = null;
|
||||
}
|
||||
|
||||
if (args.size() == 2 && p == null) {
|
||||
sender.sendMessage("From the command line, WORLD is required.");
|
||||
sender.sendMessage(this.getCommandDesc());
|
||||
sender.sendMessage(this.getCommandUsage());
|
||||
sender.sendMessage("Nothing changed.");
|
||||
return;
|
||||
}
|
||||
|
||||
final GameRule gameRule = GameRule.getByName(args.get(0));
|
||||
final String value = args.get(1);
|
||||
final World world;
|
||||
if (args.size() == 2) {
|
||||
world = p.getWorld();
|
||||
} else {
|
||||
world = Bukkit.getWorld(args.get(2));
|
||||
if (world == null) {
|
||||
sender.sendMessage(ChatColor.RED + "Failure!" + ChatColor.WHITE + " World " + ChatColor.AQUA + args.get(2)
|
||||
+ ChatColor.WHITE + " does not exist.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (gameRule == null) {
|
||||
sender.sendMessage(ChatColor.RED + "Failure! " + ChatColor.AQUA + args.get(0) + ChatColor.WHITE
|
||||
+ " is not a valid gamerule.");
|
||||
} else {
|
||||
if (gameRule.getType() == Boolean.class) {
|
||||
boolean booleanValue;
|
||||
if (value.equalsIgnoreCase("true")) {
|
||||
booleanValue = true;
|
||||
} else if (value.equalsIgnoreCase("false")) {
|
||||
booleanValue = false;
|
||||
} else {
|
||||
sender.sendMessage(getErrorMessage(gameRule.getName(), value) + "it can only be set to true or false.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!world.setGameRule(gameRule, booleanValue)) {
|
||||
sender.sendMessage(getErrorMessage(gameRule.getName(), value) + "something went wrong.");
|
||||
return;
|
||||
}
|
||||
} else if (gameRule.getType() == Integer.class) {
|
||||
try {
|
||||
if (!world.setGameRule(gameRule, Integer.parseInt(value))) {
|
||||
throw new NumberFormatException();
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
sender.sendMessage(getErrorMessage(gameRule.getName(), value) + "it can only be set to a positive integer.");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "Failure!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule.getName()
|
||||
+ ChatColor.WHITE + " isn't supported yet, please let us know about it.");
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule.getName()
|
||||
+ ChatColor.WHITE + " was set to " + ChatColor.GREEN + value + ChatColor.WHITE + ".");
|
||||
}
|
||||
}
|
||||
|
||||
private String getErrorMessage(String gameRule, String value) {
|
||||
return ChatColor.RED + "Failure!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule
|
||||
+ ChatColor.WHITE + " could not be set to " + ChatColor.RED + value + ChatColor.WHITE + ", ";
|
||||
}
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.display.ColorAlternator;
|
||||
import com.onarandombox.MultiverseCore.display.ContentDisplay;
|
||||
import com.onarandombox.MultiverseCore.display.settings.MapDisplaySettings;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Allows management of Anchor Destinations.
|
||||
*/
|
||||
public class GamerulesCommand extends MultiverseCommand {
|
||||
|
||||
public GamerulesCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("List the Minecraft Game Rules for a World.");
|
||||
this.setCommandUsage("/mv gamerules" + ChatColor.GOLD + " [WORLD]");
|
||||
this.setArgRange(0, 1);
|
||||
this.addKey("mv gamerules");
|
||||
this.addKey("mv rules");
|
||||
this.addKey("mvgamerules");
|
||||
this.addKey("mvrules");
|
||||
this.addCommandExample("/mv gamerules");
|
||||
this.addCommandExample("/mvrules " + ChatColor.RED + "world_nether");
|
||||
this.setPermission("multiverse.core.gamerule.list", "Allows a player to list gamerules.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
// We NEED a world from the command line
|
||||
final Player p;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
} else {
|
||||
p = null;
|
||||
}
|
||||
|
||||
if (args.size() == 0 && p == null) {
|
||||
sender.sendMessage("From the command line, WORLD is required.");
|
||||
sender.sendMessage(this.getCommandDesc());
|
||||
sender.sendMessage(this.getCommandUsage());
|
||||
sender.sendMessage("Nothing changed.");
|
||||
return;
|
||||
}
|
||||
|
||||
final World world;
|
||||
if (args.size() == 0) {
|
||||
world = p.getWorld();
|
||||
} else {
|
||||
world = Bukkit.getWorld(args.get(0));
|
||||
if (world == null) {
|
||||
sender.sendMessage(ChatColor.RED + "Failure!" + ChatColor.WHITE + " World " + ChatColor.AQUA + args.get(0)
|
||||
+ ChatColor.WHITE + " does not exist.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ContentDisplay.forContent(getGameRuleMap(world))
|
||||
.header("=== Gamerules for %s%s%s ===", ChatColor.AQUA, world.getName(), ChatColor.WHITE)
|
||||
.colorTool(ColorAlternator.with(ChatColor.GREEN, ChatColor.GOLD))
|
||||
.setting(MapDisplaySettings.OPERATOR, ": ")
|
||||
.show(sender);
|
||||
}
|
||||
|
||||
private Map<String, Object> getGameRuleMap(World world) {
|
||||
Map<String, Object> gameRuleMap = new HashMap<>();
|
||||
for (GameRule<?> rule : GameRule.values()) {
|
||||
Object value = world.getGameRuleValue(rule);
|
||||
if (value == null) {
|
||||
gameRuleMap.put(rule.getName(), "null");
|
||||
continue;
|
||||
}
|
||||
gameRuleMap.put(rule.getName(), value);
|
||||
}
|
||||
return gameRuleMap;
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Returns a list of loaded generator plugins.
|
||||
*/
|
||||
public class GeneratorCommand extends MultiverseCommand {
|
||||
|
||||
public GeneratorCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("World Information");
|
||||
this.setCommandUsage("/mv generators");
|
||||
this.setArgRange(0, 0);
|
||||
this.addKey("mv generators");
|
||||
this.addKey("mvgenerators");
|
||||
this.addKey("mv gens");
|
||||
this.addKey("mvgens");
|
||||
this.addCommandExample("/mv generators");
|
||||
this.setPermission("multiverse.core.generator", "Returns a list of Loaded Generator Plugins.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
Logging.info("PLEASE IGNORE the 'Plugin X does not contain any generators' message below!");
|
||||
Plugin[] plugins = this.plugin.getServer().getPluginManager().getPlugins();
|
||||
List<String> generators = new ArrayList<String>();
|
||||
for (Plugin p : plugins) {
|
||||
if (p.isEnabled() && p.getDefaultWorldGenerator("world", "") != null) {
|
||||
generators.add(p.getDescription().getName());
|
||||
}
|
||||
}
|
||||
sender.sendMessage(ChatColor.AQUA + "--- Loaded Generator Plugins ---");
|
||||
String loadedGens = "";
|
||||
boolean altColor = false;
|
||||
for (String s : generators) {
|
||||
loadedGens += (altColor ? ChatColor.YELLOW : ChatColor.WHITE) + s + " ";
|
||||
altColor = !altColor;
|
||||
}
|
||||
if (loadedGens.length() == 0) {
|
||||
loadedGens = ChatColor.RED + "No Generator Plugins found.";
|
||||
}
|
||||
sender.sendMessage(loadedGens);
|
||||
}
|
||||
}
|
|
@ -1,98 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.pneumaticraft.commandhandler.Command;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Displays a nice help menu.
|
||||
*/
|
||||
public class HelpCommand extends PaginatedCoreCommand<Command> {
|
||||
|
||||
public HelpCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Get Help with Multiverse");
|
||||
this.setCommandUsage("/mv " + ChatColor.GOLD + "[FILTER] [PAGE #]");
|
||||
this.setArgRange(0, 2);
|
||||
this.addKey("mv");
|
||||
this.addKey("mvh");
|
||||
this.addKey("mvhelp");
|
||||
this.addKey("mv help");
|
||||
this.addKey("mvsearch");
|
||||
this.addKey("mv search");
|
||||
this.addCommandExample("/mv help ?");
|
||||
this.setPermission("multiverse.help", "Displays a nice help menu.", PermissionDefault.TRUE);
|
||||
this.setItemsPerPage(7); // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Command> getFilteredItems(List<Command> availableItems, String filter) {
|
||||
String expression = "(?i).*" + cleanFilter(filter) + ".*";
|
||||
List<Command> filtered = new ArrayList<Command>();
|
||||
|
||||
for (Command c : availableItems) {
|
||||
if (stitchThisString(c.getKeyStrings()).matches(expression)
|
||||
|| c.getCommandName().matches(expression)
|
||||
|| c.getCommandDesc().matches(expression)
|
||||
|| c.getCommandUsage().matches(expression)
|
||||
|| c.getCommandExamples().stream().anyMatch(eg -> eg.matches(expression))) {
|
||||
filtered.add(c);
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getItemText(Command item) {
|
||||
return ChatColor.AQUA + item.getCommandUsage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
sender.sendMessage(ChatColor.AQUA + "====[ Multiverse Help ]====");
|
||||
|
||||
FilterObject filterObject = this.getPageAndFilter(args);
|
||||
|
||||
List<Command> availableCommands = new ArrayList<Command>(this.plugin.getCommandHandler().getCommands(sender));
|
||||
if (filterObject.getFilter().length() > 0) {
|
||||
availableCommands = this.getFilteredItems(availableCommands, filterObject.getFilter());
|
||||
if (availableCommands.size() == 0) {
|
||||
sender.sendMessage(ChatColor.RED + "Sorry... " + ChatColor.WHITE
|
||||
+ "No commands matched your filter: " + ChatColor.AQUA + filterObject.getFilter());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.AQUA + " Add a '" + ChatColor.DARK_PURPLE + "?" + ChatColor.AQUA + "' after a command to see more about it.");
|
||||
for (Command c : availableCommands) {
|
||||
sender.sendMessage(ChatColor.AQUA + c.getCommandUsage());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int totalPages = (int) Math.ceil(availableCommands.size() / (this.itemsPerPage + 0.0));
|
||||
|
||||
if (filterObject.getPage() > totalPages) {
|
||||
filterObject.setPage(totalPages);
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.AQUA + " Page " + filterObject.getPage() + " of " + totalPages);
|
||||
sender.sendMessage(ChatColor.AQUA + " Add a '" + ChatColor.DARK_PURPLE + "?" + ChatColor.AQUA + "' after a command to see more about it.");
|
||||
|
||||
this.showPage(filterObject.getPage(), sender, availableCommands);
|
||||
}
|
||||
}
|
|
@ -1,137 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.utils.WorldNameChecker;
|
||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Imports a new world of the specified type.
|
||||
*/
|
||||
public class ImportCommand extends MultiverseCommand {
|
||||
private MVWorldManager worldManager;
|
||||
|
||||
public ImportCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Import World");
|
||||
this.setCommandUsage("/mv import" + ChatColor.GREEN + " {NAME} {ENV}" + ChatColor.GOLD + " -g [GENERATOR[:ID]] [-n]");
|
||||
this.setArgRange(1, 5); // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
this.addKey("mvimport");
|
||||
this.addKey("mvim");
|
||||
this.addKey("mv import");
|
||||
this.addCommandExample("/mv import " + ChatColor.GOLD + "gargamel" + ChatColor.GREEN + " normal");
|
||||
this.addCommandExample("/mv import " + ChatColor.GOLD + "hell_world" + ChatColor.GREEN + " nether");
|
||||
this.addCommandExample("To import a world that uses a generator, you'll need the generator:");
|
||||
this.addCommandExample("/mv import " + ChatColor.GOLD + "CleanRoom" + ChatColor.GREEN + " normal" + ChatColor.DARK_AQUA + " CleanRoomGenerator");
|
||||
this.setPermission("multiverse.core.import", "Imports a new world of the specified type.", PermissionDefault.OP);
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
}
|
||||
|
||||
private String getPotentialWorldStrings() {
|
||||
final Collection<String> potentialWorlds = this.worldManager.getPotentialWorlds();
|
||||
StringBuilder worldList = new StringBuilder();
|
||||
ChatColor currColor = ChatColor.WHITE;
|
||||
|
||||
for (String world : potentialWorlds) {
|
||||
worldList.append(currColor).append(world).append(' ');
|
||||
currColor = currColor == ChatColor.WHITE ? ChatColor.YELLOW : ChatColor.WHITE;
|
||||
}
|
||||
|
||||
return worldList.toString();
|
||||
}
|
||||
|
||||
private String trimWorldName(String userInput) {
|
||||
// Removes relative paths.
|
||||
return userInput.replaceAll("^[./\\\\]+", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
String worldName = trimWorldName(args.get(0));
|
||||
|
||||
if (worldName.toLowerCase().equals("--list") || worldName.toLowerCase().equals("-l")) {
|
||||
String worldList = this.getPotentialWorldStrings();
|
||||
if (worldList.length() > 2) {
|
||||
sender.sendMessage(ChatColor.AQUA + "====[ These look like worlds ]====");
|
||||
sender.sendMessage(worldList);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "No potential worlds found. Sorry!");
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Since we made an exception for the list, we have to make sure they have at least 2 params:
|
||||
// Note the exception is --list, which is covered above.
|
||||
if (args.size() == 1 || worldName.length() < 1) {
|
||||
this.showHelp(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure the world name doesn't contain the words 'plugins' and '.dat'
|
||||
if(worldName.contains("plugins")||worldName.contains(".dat")){
|
||||
sender.sendMessage(ChatColor.RED + "Multiverse cannot create a world that contains 'plugins' or '.dat'");
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure we don't already know about this world.
|
||||
if (this.worldManager.isMVWorld(worldName)) {
|
||||
sender.sendMessage(ChatColor.GREEN + "Multiverse" + ChatColor.WHITE
|
||||
+ " already knows about '" + ChatColor.AQUA + worldName + ChatColor.WHITE + "'!");
|
||||
return;
|
||||
}
|
||||
|
||||
File worldFile = new File(this.plugin.getServer().getWorldContainer(), worldName);
|
||||
|
||||
String generator = CommandHandler.getFlag("-g", args);
|
||||
boolean useSpawnAdjust = true;
|
||||
for (String s : args) {
|
||||
if (s.equalsIgnoreCase("-n")) {
|
||||
useSpawnAdjust = false;
|
||||
}
|
||||
}
|
||||
|
||||
String env = args.get(1);
|
||||
Environment environment = EnvironmentCommand.getEnvFromString(env);
|
||||
if (environment == null) {
|
||||
sender.sendMessage(ChatColor.RED + "That is not a valid environment.");
|
||||
EnvironmentCommand.showEnvironments(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!worldFile.exists()) {
|
||||
sender.sendMessage(ChatColor.RED + "FAILED.");
|
||||
String worldList = this.getPotentialWorldStrings();
|
||||
sender.sendMessage("That world folder does not exist. These look like worlds to me:");
|
||||
sender.sendMessage(worldList);
|
||||
} else if (!WorldNameChecker.isValidWorldFolder(worldFile)) {
|
||||
sender.sendMessage(ChatColor.RED + "FAILED.");
|
||||
sender.sendMessage(String.format("'%s' does not appear to be a world. It is lacking a .dat file.",
|
||||
worldName));
|
||||
} else if (env == null) {
|
||||
sender.sendMessage(ChatColor.RED + "FAILED.");
|
||||
sender.sendMessage("That world environment did not exist.");
|
||||
sender.sendMessage("For a list of available world types, type: " + ChatColor.AQUA + "/mvenv");
|
||||
} else {
|
||||
Command.broadcastCommandMessage(sender, String.format("Starting import of world '%s'...", worldName));
|
||||
if (this.worldManager.addWorld(worldName, environment, null, null, null, generator, useSpawnAdjust))
|
||||
Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Complete!");
|
||||
else
|
||||
Command.broadcastCommandMessage(sender, ChatColor.RED + "Failed!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,274 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.FancyText;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.utils.FancyColorScheme;
|
||||
import com.onarandombox.MultiverseCore.utils.FancyHeader;
|
||||
import com.onarandombox.MultiverseCore.utils.FancyMessage;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
// Will use when we can compile with JDK 6
|
||||
//import com.sun.xml.internal.ws.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Returns detailed information about a world.
|
||||
*/
|
||||
public class InfoCommand extends MultiverseCommand {
|
||||
private MVWorldManager worldManager;
|
||||
|
||||
public InfoCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("World Information");
|
||||
this.setCommandUsage("/mv info" + ChatColor.GOLD + " [WORLD] [PAGE]");
|
||||
this.setArgRange(0, 2);
|
||||
this.addKey("mvinfo");
|
||||
this.addKey("mvi");
|
||||
this.addKey("mv info");
|
||||
this.addCommandExample("/mv info " + ChatColor.GOLD + "1");
|
||||
this.addCommandExample("/mv info " + ChatColor.GOLD + "3");
|
||||
this.setPermission("multiverse.core.info", "Returns detailed information on the world.", PermissionDefault.OP);
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
// Check if the command was sent from a Player.
|
||||
String worldName = "";
|
||||
int pageNum = 0;
|
||||
|
||||
if (args.size() == 0) {
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
worldName = p.getWorld().getName();
|
||||
} else {
|
||||
sender.sendMessage("You must enter a" + ChatColor.LIGHT_PURPLE + " world" + ChatColor.WHITE + " from the console!");
|
||||
return;
|
||||
}
|
||||
} else if (args.size() == 1) {
|
||||
if (this.worldManager.isMVWorld(args.get(0))) {
|
||||
// then we have a world!
|
||||
worldName = args.get(0);
|
||||
} else if (this.worldManager.getUnloadedWorlds().contains(args.get(0))) {
|
||||
sender.sendMessage("That world exists, but it is unloaded!");
|
||||
sender.sendMessage(String.format("You can load it with: %s/mv load %s", ChatColor.AQUA, args.get(0)));
|
||||
return;
|
||||
} else {
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
worldName = p.getWorld().getName();
|
||||
try {
|
||||
pageNum = Integer.parseInt(args.get(0)) - 1;
|
||||
} catch (NumberFormatException e) {
|
||||
sender.sendMessage("That world does not exist.");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("You must enter a" + ChatColor.LIGHT_PURPLE + " world" + ChatColor.WHITE + " from the console!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (args.size() == 2) {
|
||||
worldName = args.get(0);
|
||||
try {
|
||||
pageNum = Integer.parseInt(args.get(1)) - 1;
|
||||
} catch (NumberFormatException e) {
|
||||
pageNum = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.worldManager.isMVWorld(worldName)) {
|
||||
Player p = null;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
}
|
||||
showPage(pageNum, sender, this.buildEntireCommand(this.worldManager.getMVWorld(worldName), p));
|
||||
} else if (this.worldManager.getUnloadedWorlds().contains(worldName)) {
|
||||
sender.sendMessage("That world exists, but it is unloaded!");
|
||||
sender.sendMessage(String.format("You can load it with: %s/mv load %s", ChatColor.AQUA, worldName));
|
||||
} else if (this.plugin.getServer().getWorld(worldName) != null) {
|
||||
sender.sendMessage("That world exists, but Multiverse does not know about it!");
|
||||
sender.sendMessage("You can import it with" + ChatColor.AQUA + "/mv import " + ChatColor.GREEN + worldName + ChatColor.LIGHT_PURPLE + "{ENV}");
|
||||
sender.sendMessage("For available environments type " + ChatColor.GREEN + "/mv env");
|
||||
}
|
||||
}
|
||||
|
||||
private List<List<FancyText>> buildEntireCommand(MultiverseWorld world, Player p) {
|
||||
List<FancyText> message = new ArrayList<FancyText>();
|
||||
List<List<FancyText>> worldInfo = new ArrayList<List<FancyText>>();
|
||||
// Page 1
|
||||
FancyColorScheme colors = new FancyColorScheme(ChatColor.AQUA, ChatColor.AQUA, ChatColor.GOLD, ChatColor.WHITE);
|
||||
message.add(new FancyHeader("General Info", colors));
|
||||
message.add(new FancyMessage("World Name: ", world.getName(), colors));
|
||||
message.add(new FancyMessage("World UID: ", world.getCBWorld().getUID().toString(), colors));
|
||||
message.add(new FancyMessage("World Alias: ", world.getColoredWorldString(), colors));
|
||||
message.add(new FancyMessage("Game Mode: ", world.getGameMode().toString(), colors));
|
||||
message.add(new FancyMessage("Difficulty: ", world.getDifficulty().toString(), colors));
|
||||
|
||||
//message.add(new FancyMessage("Game Mode: ", StringUtils.capitalize(world.getGameMode().toString()), colors));
|
||||
Location spawn = world.getSpawnLocation();
|
||||
message.add(new FancyMessage("Spawn Location: ", plugin.getLocationManipulation().strCoords(spawn), colors));
|
||||
message.add(new FancyMessage("World Scale: ", String.valueOf(world.getScaling()), colors));
|
||||
message.add(new FancyMessage("World Seed: ", String.valueOf(world.getSeed()), colors));
|
||||
if (world.getPrice() > 0) {
|
||||
message.add(new FancyMessage("Price to enter this world: ",
|
||||
plugin.getEconomist().formatPrice(world.getPrice(), world.getCurrency()),
|
||||
colors));
|
||||
} else if (world.getPrice() < 0) {
|
||||
message.add(new FancyMessage("Reward for entering this world: ",
|
||||
plugin.getEconomist().formatPrice(-world.getPrice(), world.getCurrency()),
|
||||
colors));
|
||||
} else {
|
||||
message.add(new FancyMessage("Price to enter this world: ", ChatColor.GREEN + "FREE!", colors));
|
||||
}
|
||||
|
||||
if (world.getRespawnToWorld() != null) {
|
||||
MultiverseWorld respawn = this.worldManager.getMVWorld(world.getRespawnToWorld());
|
||||
if (respawn != null) {
|
||||
message.add(new FancyMessage("Players will respawn in: ", respawn.getColoredWorldString(), colors));
|
||||
} else {
|
||||
message.add(new FancyMessage("Players will respawn in: ", ChatColor.RED + "!!INVALID!!", colors));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
worldInfo.add(message);
|
||||
// Page 2
|
||||
message = new ArrayList<FancyText>();
|
||||
message.add(new FancyHeader("More World Settings", colors));
|
||||
message.add(new FancyMessage("World Type: ", world.getWorldType().toString(), colors));
|
||||
message.add(new FancyMessage("Generator: ", world.getGenerator(), colors));
|
||||
message.add(new FancyMessage("Structures: ", world.getCBWorld().canGenerateStructures() + "", colors));
|
||||
message.add(new FancyMessage("Weather: ", world.isWeatherEnabled() + "", colors));
|
||||
message.add(new FancyMessage("Players will get hungry: ", world.getHunger() + "", colors));
|
||||
message.add(new FancyMessage("Keep spawn in memory: ", world.isKeepingSpawnInMemory() + "", colors));
|
||||
message.add(new FancyHeader("PVP Settings", colors));
|
||||
message.add(new FancyMessage("Multiverse Setting: ", world.isPVPEnabled() + "", colors));
|
||||
message.add(new FancyMessage("Bukkit Setting: ", world.getCBWorld().getPVP() + "", colors));
|
||||
worldInfo.add(message);
|
||||
// Page 3
|
||||
message = new ArrayList<FancyText>();
|
||||
message.add(new FancyHeader("Monster Settings", colors));
|
||||
message.add(new FancyMessage("Multiverse Setting: ", world.canMonstersSpawn() + "", colors));
|
||||
message.add(new FancyMessage("Bukkit Setting: ", world.getCBWorld().getAllowMonsters() + "", colors));
|
||||
if (world.getMonsterList().size() > 0) {
|
||||
if (world.canMonstersSpawn()) {
|
||||
message.add(new FancyMessage("Monsters that" + ChatColor.RED + " CAN NOT "
|
||||
+ ChatColor.GREEN + "spawn: ", toCommaSeperated(world.getMonsterList()), colors));
|
||||
} else {
|
||||
message.add(new FancyMessage("Monsters that" + ChatColor.GREEN + " CAN SPAWN: ", toCommaSeperated(world.getMonsterList()), colors));
|
||||
}
|
||||
} else {
|
||||
message.add(new FancyMessage("Monsters that CAN spawn: ", world.canMonstersSpawn() ? "ALL" : "NONE", colors));
|
||||
}
|
||||
worldInfo.add(message);
|
||||
|
||||
// Page 4
|
||||
message = new ArrayList<FancyText>();
|
||||
message.add(new FancyHeader("Animal Settings", colors));
|
||||
message.add(new FancyMessage("Multiverse Setting: ", world.canAnimalsSpawn() + "", colors));
|
||||
message.add(new FancyMessage("Bukkit Setting: ", world.getCBWorld().getAllowAnimals() + "", colors));
|
||||
if (world.getAnimalList().size() > 0) {
|
||||
if (world.canAnimalsSpawn()) {
|
||||
message.add(new FancyMessage("Animals that" + ChatColor.RED + " CAN NOT "
|
||||
+ ChatColor.GREEN + "spawn: ", toCommaSeperated(world.getAnimalList()), colors));
|
||||
} else {
|
||||
message.add(new FancyMessage("Animals that" + ChatColor.GREEN + " CAN SPAWN: ", toCommaSeperated(world.getAnimalList()), colors));
|
||||
}
|
||||
} else {
|
||||
message.add(new FancyMessage("Animals that CAN spawn: ", world.canAnimalsSpawn() ? "ALL" : "NONE", colors));
|
||||
}
|
||||
worldInfo.add(message);
|
||||
|
||||
return worldInfo;
|
||||
}
|
||||
|
||||
private static String toCommaSeperated(List<String> list) {
|
||||
if (list == null || list.size() == 0) {
|
||||
return "";
|
||||
}
|
||||
if (list.size() == 1) {
|
||||
return list.get(0);
|
||||
}
|
||||
String result = list.get(0);
|
||||
|
||||
for (int i = 1; i < list.size() - 1; i++) {
|
||||
result += ", " + list.get(i);
|
||||
}
|
||||
result += " and " + list.get(list.size() - 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a "positive" or "negative" {@link ChatColor}.
|
||||
*
|
||||
* @param positive Whether this {@link ChatColor} should be "positive".
|
||||
* @return The {@link ChatColor}.
|
||||
*/
|
||||
protected ChatColor getChatColor(boolean positive) {
|
||||
return positive ? ChatColor.GREEN : ChatColor.RED;
|
||||
}
|
||||
|
||||
private static void showPage(int page, CommandSender sender, List<List<FancyText>> doc) {
|
||||
page = page < 0 ? 0 : page;
|
||||
page = page > doc.size() - 1 ? doc.size() - 1 : page;
|
||||
boolean altColor = false;
|
||||
boolean appendedPageNum = false;
|
||||
if (sender instanceof Player) {
|
||||
List<FancyText> list = doc.get(page);
|
||||
for (FancyText fancyT : list) {
|
||||
if (fancyT instanceof FancyMessage) {
|
||||
FancyMessage text = (FancyMessage) fancyT;
|
||||
text.setAltColor(altColor);
|
||||
altColor = !altColor;
|
||||
sender.sendMessage(text.getFancyText());
|
||||
} else if (fancyT instanceof FancyHeader) {
|
||||
FancyHeader text = (FancyHeader) fancyT;
|
||||
if (!appendedPageNum) {
|
||||
text.appendText(ChatColor.DARK_PURPLE + " [ Page " + (page + 1) + " of " + doc.size() + " ]");
|
||||
appendedPageNum = true;
|
||||
}
|
||||
sender.sendMessage(text.getFancyText());
|
||||
altColor = false;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
for (List<FancyText> list : doc) {
|
||||
for (FancyText fancyT : list) {
|
||||
if (fancyT instanceof FancyMessage) {
|
||||
FancyMessage text = (FancyMessage) fancyT;
|
||||
text.setAltColor(altColor);
|
||||
altColor = !altColor;
|
||||
sender.sendMessage(text.getFancyText());
|
||||
} else {
|
||||
FancyText text = fancyT;
|
||||
if (appendedPageNum) {
|
||||
sender.sendMessage(" ");
|
||||
} else {
|
||||
appendedPageNum = true;
|
||||
}
|
||||
sender.sendMessage(text.getFancyText());
|
||||
altColor = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,119 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.display.ColorAlternator;
|
||||
import com.onarandombox.MultiverseCore.display.ContentDisplay;
|
||||
import com.onarandombox.MultiverseCore.display.ContentFilter;
|
||||
import com.onarandombox.MultiverseCore.display.DisplayHandlers;
|
||||
import com.onarandombox.MultiverseCore.display.settings.PagedDisplaySettings;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Displays a listing of all worlds that a player can enter.
|
||||
*/
|
||||
public class ListCommand extends MultiverseCommand {
|
||||
|
||||
public ListCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("World Listing");
|
||||
this.setCommandUsage("/mv list [filter] [page]");
|
||||
this.setArgRange(0, 2);
|
||||
this.addKey("mvlist");
|
||||
this.addKey("mvl");
|
||||
this.addKey("mv list");
|
||||
this.setPermission("multiverse.core.list.worlds", "Displays a listing of all worlds that you can enter.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
ContentFilter filter = ContentFilter.DEFAULT;
|
||||
int page = 1;
|
||||
|
||||
// Either page or filter.
|
||||
if (args.size() == 1) {
|
||||
try {
|
||||
page = Integer.parseInt(args.get(0));
|
||||
} catch (NumberFormatException ignore) {
|
||||
filter = new ContentFilter(args.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
// Filter then page.
|
||||
if (args.size() == 2) {
|
||||
filter = new ContentFilter(args.get(0));
|
||||
try {
|
||||
page = Integer.parseInt(args.get(1));
|
||||
} catch (NumberFormatException ignore) {
|
||||
sender.sendMessage(ChatColor.RED + args.get(1) + " is not valid number!");
|
||||
}
|
||||
}
|
||||
|
||||
ContentDisplay.forContent(getListContents(sender))
|
||||
.header("%s====[ Multiverse World List ]====", ChatColor.GOLD)
|
||||
.displayHandler(DisplayHandlers.PAGE_LIST)
|
||||
.colorTool(ColorAlternator.with(ChatColor.AQUA, ChatColor.GOLD))
|
||||
.filter(filter)
|
||||
.setting(PagedDisplaySettings.SHOW_PAGE, page)
|
||||
.show(sender);
|
||||
}
|
||||
|
||||
private Collection<String> getListContents(@NotNull CommandSender sender) {
|
||||
Player player = (sender instanceof Player) ? (Player) sender : null;
|
||||
|
||||
List<String> worldList = this.plugin.getMVWorldManager().getMVWorlds().stream()
|
||||
.filter(world -> player == null || plugin.getMVPerms().canEnterWorld(player, world))
|
||||
.filter(world -> canSeeWorld(player, world))
|
||||
.map(world -> hiddenText(world) + world.getColoredWorldString() + " - " + parseColouredEnvironment(world.getEnvironment()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
this.plugin.getMVWorldManager().getUnloadedWorlds().stream()
|
||||
.filter(world -> plugin.getMVPerms().hasPermission(sender, "multiverse.access." + world, true))
|
||||
.map(world -> ChatColor.GRAY + world + " - UNLOADED")
|
||||
.forEach(worldList::add);
|
||||
|
||||
return worldList;
|
||||
}
|
||||
|
||||
private boolean canSeeWorld(Player player, MultiverseWorld world) {
|
||||
return !world.isHidden()
|
||||
|| player == null
|
||||
|| this.plugin.getMVPerms().hasPermission(player, "multiverse.core.modify", true);
|
||||
}
|
||||
|
||||
private String hiddenText(MultiverseWorld world) {
|
||||
return (world.isHidden()) ? String.format("%s[H] ", ChatColor.GRAY) : "";
|
||||
}
|
||||
|
||||
private String parseColouredEnvironment(World.Environment env) {
|
||||
ChatColor color = ChatColor.GOLD;
|
||||
switch (env) {
|
||||
case NETHER:
|
||||
color = ChatColor.RED;
|
||||
break;
|
||||
case NORMAL:
|
||||
color = ChatColor.GREEN;
|
||||
break;
|
||||
case THE_END:
|
||||
color = ChatColor.AQUA;
|
||||
break;
|
||||
}
|
||||
return color + env.toString();
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Loads a world into Multiverse.
|
||||
*/
|
||||
public class LoadCommand extends MultiverseCommand {
|
||||
|
||||
public LoadCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Load World");
|
||||
this.setCommandUsage("/mv load" + ChatColor.GREEN + " {WORLD}");
|
||||
this.setArgRange(1, 1);
|
||||
this.addKey("mvload");
|
||||
this.addKey("mv load");
|
||||
this.addCommandExample("/mv load " + ChatColor.GREEN + "MyUnloadedWorld");
|
||||
this.setPermission("multiverse.core.load", "Loads a world into Multiverse.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
if (this.plugin.getMVWorldManager().loadWorld(args.get(0))) {
|
||||
Command.broadcastCommandMessage(sender, "Loaded world '" + args.get(0) + "'!");
|
||||
} else {
|
||||
sender.sendMessage("Error trying to load world '" + args.get(0) + "'!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.enums.Action;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
// This will contain all the properties that support the ADD/REMOVE
|
||||
// Anything not in here will only support the SET action
|
||||
|
||||
/**
|
||||
* Used to modify various aspects of worlds.
|
||||
*/
|
||||
public class ModifyAddCommand extends MultiverseCommand {
|
||||
private MVWorldManager worldManager;
|
||||
|
||||
public ModifyAddCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Modify a World (Add a value)");
|
||||
this.setCommandUsage("/mv modify " + ChatColor.GREEN + "add {VALUE} {PROPERTY}" + ChatColor.GOLD + " [WORLD] ");
|
||||
this.setArgRange(2, 3);
|
||||
this.addKey("mvm add");
|
||||
this.addKey("mvmadd");
|
||||
this.addKey("mv modify add");
|
||||
this.addKey("mvmodify add");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "add " + ChatColor.GREEN + "sheep " + ChatColor.RED + "animals");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "add " + ChatColor.GREEN + "creeper " + ChatColor.RED + "monsters");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "add " + ChatColor.GREEN + "MyWorld " + ChatColor.RED + "worldblacklist");
|
||||
this.setPermission("multiverse.core.modify.add", "Modify various aspects of worlds. See the help wiki for how to use this command properly. "
|
||||
+ "If you do not include a world, the current world will be used.", PermissionDefault.OP);
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
// We NEED a world from the command line
|
||||
Player p = null;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
}
|
||||
|
||||
if (args.size() == 2 && p == null) {
|
||||
sender.sendMessage(ChatColor.RED + "From the console, WORLD is required.");
|
||||
sender.sendMessage(this.getCommandDesc());
|
||||
sender.sendMessage(this.getCommandUsage());
|
||||
sender.sendMessage("Nothing changed.");
|
||||
return;
|
||||
}
|
||||
|
||||
MultiverseWorld world;
|
||||
String value = args.get(0);
|
||||
String property = args.get(1);
|
||||
|
||||
if (args.size() == 2) {
|
||||
world = this.worldManager.getMVWorld(p.getWorld().getName());
|
||||
} else {
|
||||
world = this.worldManager.getMVWorld(args.get(2));
|
||||
}
|
||||
|
||||
if (world == null) {
|
||||
sender.sendMessage("That world does not exist!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ModifyCommand.validateAction(Action.Add, property)) {
|
||||
sender.sendMessage("Sorry, you can't ADD to " + property);
|
||||
sender.sendMessage("Please visit our Github Wiki for more information: https://goo.gl/OMGwzx");
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO fix this
|
||||
if (world.addToVariable(property, value)) {
|
||||
sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA
|
||||
+ value + ChatColor.WHITE + " was " + ChatColor.GREEN + "added to " + ChatColor.GREEN + property);
|
||||
if (!plugin.saveWorldConfig()) {
|
||||
sender.sendMessage(ChatColor.RED + "There was an issue saving worlds.yml! Your changes will only be temporary!");
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(value + " could not be added to " + property);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.enums.Action;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Removes all values from a world-property.
|
||||
*/
|
||||
public class ModifyClearCommand extends MultiverseCommand {
|
||||
private MVWorldManager worldManager;
|
||||
|
||||
public ModifyClearCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Modify a World (Clear a property)");
|
||||
this.setCommandUsage("/mv modify" + ChatColor.GREEN + " clear {PROPERTY}" + ChatColor.GOLD + " [WORLD]");
|
||||
this.setArgRange(1, 2);
|
||||
this.addKey("mvm clear");
|
||||
this.addKey("mvmclear");
|
||||
this.addKey("mv modify clear");
|
||||
this.addKey("mvmodify clear");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "clear " + ChatColor.RED + "animals");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "clear " + ChatColor.RED + "monsters");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "clear " + ChatColor.RED + "worldblacklist");
|
||||
this.setPermission("multiverse.core.modify.clear",
|
||||
"Removes all values from a property. This will work on properties that contain lists.", PermissionDefault.OP);
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
// We NEED a world from the command line
|
||||
Player p = null;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
}
|
||||
if (args.size() == 1 && p == null) {
|
||||
sender.sendMessage(ChatColor.RED + "From the console, WORLD is required.");
|
||||
sender.sendMessage(this.getCommandDesc());
|
||||
sender.sendMessage(this.getCommandUsage());
|
||||
sender.sendMessage("Nothing changed.");
|
||||
return;
|
||||
}
|
||||
|
||||
MultiverseWorld world;
|
||||
String property = args.get(0);
|
||||
|
||||
if (args.size() == 1) {
|
||||
world = this.worldManager.getMVWorld(p.getWorld().getName());
|
||||
} else {
|
||||
world = this.worldManager.getMVWorld(args.get(1));
|
||||
}
|
||||
|
||||
if (world == null) {
|
||||
sender.sendMessage("That world does not exist!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ModifyCommand.validateAction(Action.Clear, property)) {
|
||||
sender.sendMessage("Sorry, you can't use CLEAR with " + property);
|
||||
sender.sendMessage("Please visit our Github Wiki for more information: https://goo.gl/q1h01S");
|
||||
return;
|
||||
}
|
||||
// TODO fix this
|
||||
if (world.clearList(property)) {
|
||||
sender.sendMessage(property + " was cleared. It contains 0 values now.");
|
||||
sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA + property + ChatColor.WHITE + " was "
|
||||
+ ChatColor.GREEN + "CLEARED" + ChatColor.WHITE + ". It contains " + ChatColor.LIGHT_PURPLE + "0" + ChatColor.WHITE + " values now.");
|
||||
if (!plugin.saveWorldConfig()) {
|
||||
sender.sendMessage(ChatColor.RED + "There was an issue saving worlds.yml! Your changes will only be temporary!");
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "Error: " + ChatColor.GOLD + property
|
||||
+ ChatColor.WHITE + " was " + ChatColor.GOLD + "NOT" + ChatColor.WHITE + " cleared.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.enums.Action;
|
||||
import com.onarandombox.MultiverseCore.enums.AddProperties;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Used to modify various aspects of worlds.
|
||||
*/
|
||||
public class ModifyCommand extends MultiverseCommand {
|
||||
|
||||
public ModifyCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Modify a World");
|
||||
this.setCommandUsage("/mv modify" + ChatColor.GREEN + " {set|add|remove|clear} ...");
|
||||
this.setArgRange(2, 3);
|
||||
this.addKey("mvm");
|
||||
this.addKey("mvmodify");
|
||||
this.addKey("mv modify");
|
||||
Map<String, Boolean> children = new HashMap<String, Boolean>();
|
||||
children.put("multiverse.core.modify.add", true);
|
||||
children.put("multiverse.core.modify.modify", true);
|
||||
children.put("multiverse.core.modify.clear", true);
|
||||
children.put("multiverse.core.modify.remove", true);
|
||||
Permission modify = new Permission("multiverse.core.modify",
|
||||
"Modify various aspects of worlds. It requires add/set/clear/remove. See the examples below", PermissionDefault.OP, children);
|
||||
this.addCommandExample(ChatColor.AQUA + "/mv modify set ?");
|
||||
this.addCommandExample(ChatColor.GREEN + "/mv modify add ?");
|
||||
this.addCommandExample(ChatColor.BLUE + "/mv modify clear ?");
|
||||
this.addCommandExample(ChatColor.RED + "/mv modify remove ?");
|
||||
this.setPermission(modify);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the specified action.
|
||||
*
|
||||
* @param action The {@link Action}.
|
||||
* @param property The property.
|
||||
* @return Whether this action is valid.
|
||||
*/
|
||||
protected static boolean validateAction(Action action, String property) {
|
||||
if (action != Action.Set) {
|
||||
try {
|
||||
AddProperties.valueOf(property);
|
||||
return true;
|
||||
} catch (IllegalArgumentException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
// This is just a place holder. The real commands are in:
|
||||
// ModifyAddCommand
|
||||
// ModifyRemoveCommand
|
||||
// ModifySetCommand
|
||||
// ModifyClearCommand
|
||||
}
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.enums.Action;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Removes values from a world-property.
|
||||
*/
|
||||
public class ModifyRemoveCommand extends MultiverseCommand {
|
||||
private MVWorldManager worldManager;
|
||||
|
||||
public ModifyRemoveCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Modify a World (Remove a value)");
|
||||
this.setCommandUsage("/mv modify" + ChatColor.GREEN + " remove {PROPERTY} {VALUE}" + ChatColor.GOLD + " [WORLD]");
|
||||
this.setArgRange(2, 3);
|
||||
this.addKey("mvm remove");
|
||||
this.addKey("mvmremove");
|
||||
this.addKey("mv modify remove");
|
||||
this.addKey("mvmodify remove");
|
||||
this.addKey("mvm delete");
|
||||
this.addKey("mvmdelete");
|
||||
this.addKey("mv modify delete");
|
||||
this.addKey("mvmodify delete");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "remove " + ChatColor.GREEN + "sheep " + ChatColor.RED + "animals");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "remove " + ChatColor.GREEN + "creeper " + ChatColor.RED + "monsters");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "remove " + ChatColor.GREEN + "MyWorld " + ChatColor.RED + "worldblacklist");
|
||||
this.setPermission("multiverse.core.modify.remove", "Modify various aspects of worlds. See the help wiki for how to use this command properly. "
|
||||
+ "If you do not include a world, the current world will be used.", PermissionDefault.OP);
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
// We NEED a world from the command line
|
||||
Player p = null;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
}
|
||||
|
||||
if (args.size() == 2 && p == null) {
|
||||
sender.sendMessage(ChatColor.RED + "From the console, WORLD is required.");
|
||||
sender.sendMessage(this.getCommandDesc());
|
||||
sender.sendMessage(this.getCommandUsage());
|
||||
sender.sendMessage("Nothing changed.");
|
||||
return;
|
||||
}
|
||||
|
||||
MultiverseWorld world;
|
||||
String value = args.get(0);
|
||||
String property = args.get(1);
|
||||
|
||||
if (args.size() == 2) {
|
||||
world = this.worldManager.getMVWorld(p.getWorld().getName());
|
||||
} else {
|
||||
world = this.worldManager.getMVWorld(args.get(2));
|
||||
}
|
||||
|
||||
if (world == null) {
|
||||
sender.sendMessage("That world does not exist!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ModifyCommand.validateAction(Action.Remove, property)) {
|
||||
sender.sendMessage("Sorry, you can't REMOVE anything from" + property);
|
||||
sender.sendMessage("Please visit our Github Wiki for more information: https://goo.gl/OMGwzx");
|
||||
return;
|
||||
}
|
||||
// TODO fix this
|
||||
if (world.removeFromVariable(property, value)) {
|
||||
sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA + value + ChatColor.WHITE
|
||||
+ " was " + ChatColor.RED + "removed from " + ChatColor.GREEN + property);
|
||||
if (!plugin.saveWorldConfig()) {
|
||||
sender.sendMessage(ChatColor.RED + "There was an issue saving worlds.yml! Your changes will only be temporary!");
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "There was an error removing " + ChatColor.GRAY
|
||||
+ value + ChatColor.WHITE + " from " + ChatColor.GOLD + property);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,125 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
|
||||
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Used to set world-properties.
|
||||
*/
|
||||
public class ModifySetCommand extends MultiverseCommand {
|
||||
private MVWorldManager worldManager;
|
||||
|
||||
public ModifySetCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
this.setName("Modify a World (Set a value)");
|
||||
this.setCommandUsage("/mv modify" + ChatColor.GREEN + " set {PROPERTY} {VALUE}" + ChatColor.GOLD + " [WORLD]");
|
||||
this.setArgRange(1, 3);
|
||||
this.addKey("mvm set");
|
||||
this.addKey("mvmset");
|
||||
this.addKey("mv modify set");
|
||||
this.addKey("mvmodify set");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "mode " + ChatColor.RED + "creative");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "animals " + ChatColor.RED + "false");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "monsters " + ChatColor.RED + "false");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "alias " + ChatColor.RED + "MyWorld");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "color " + ChatColor.RED + "green");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "curr " + ChatColor.RED + "3");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "price " + ChatColor.RED + "5");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "scale " + ChatColor.RED + "1.2");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "memory " + ChatColor.RED + "true");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "diff " + ChatColor.RED + "hard");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "hunger " + ChatColor.RED + "false");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "hidden " + ChatColor.RED + "true");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "pvp " + ChatColor.RED + "false");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "heal " + ChatColor.RED + "true");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "adjustspawn " + ChatColor.RED + "false");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "spawn");
|
||||
this.setPermission("multiverse.core.modify.set", "Modify various aspects of worlds. See the help wiki for how to use this command properly. "
|
||||
+ "If you do not include a world, the current world will be used.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
// Special case for spawn:
|
||||
if (args.size() == 1) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("You must be a player to set the" + ChatColor.GREEN + " spawn");
|
||||
return;
|
||||
}
|
||||
if (args.get(0).equalsIgnoreCase("spawn")) {
|
||||
SetSpawnCommand c = new SetSpawnCommand(this.plugin);
|
||||
c.setWorldSpawn(sender);
|
||||
|
||||
} else {
|
||||
sender.sendMessage("Spawn is the only param with no" + ChatColor.GREEN + " VALUE");
|
||||
sender.sendMessage("Type " + ChatColor.GREEN + "/mv modify ?" + ChatColor.WHITE + " For help.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
// We NEED a world from the command line
|
||||
Player p = null;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
}
|
||||
|
||||
if (args.size() == 2 && p == null) {
|
||||
sender.sendMessage("From the command line, WORLD is required.");
|
||||
sender.sendMessage(this.getCommandDesc());
|
||||
sender.sendMessage(this.getCommandUsage());
|
||||
sender.sendMessage("Nothing changed.");
|
||||
return;
|
||||
}
|
||||
|
||||
MultiverseWorld world;
|
||||
String value = args.get(1);
|
||||
String property = args.get(0);
|
||||
|
||||
if (args.size() == 2) {
|
||||
world = this.worldManager.getMVWorld(p.getWorld().getName());
|
||||
} else {
|
||||
world = this.worldManager.getMVWorld(args.get(2));
|
||||
}
|
||||
|
||||
if (world == null) {
|
||||
sender.sendMessage("That world does not exist!");
|
||||
return;
|
||||
}
|
||||
|
||||
if ((property.equalsIgnoreCase("aliascolor") || property.equalsIgnoreCase("color")) && !EnglishChatColor.isValidAliasColor(value)) {
|
||||
sender.sendMessage(value + " is not a valid color. Please pick one of the following:");
|
||||
sender.sendMessage(EnglishChatColor.getAllColors());
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (world.setPropertyValue(property, value)) {
|
||||
sender.sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Property " + ChatColor.AQUA + property
|
||||
+ ChatColor.WHITE + " was set to " + ChatColor.GREEN + value);
|
||||
if (!plugin.saveWorldConfig()) {
|
||||
sender.sendMessage(ChatColor.RED + "There was an issue saving worlds.yml! Your changes will only be temporary!");
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + world.getPropertyHelp(property));
|
||||
}
|
||||
} catch (PropertyDoesNotExistException e) {
|
||||
sender.sendMessage(ChatColor.RED + "Sorry, You can't set: '" + ChatColor.GRAY + property + ChatColor.RED + "'");
|
||||
sender.sendMessage("Valid world-properties: " + world.getAllPropertyNames());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseMessaging;
|
||||
import com.pneumaticraft.commandhandler.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A generic Multiverse-command.
|
||||
*/
|
||||
public abstract class MultiverseCommand extends Command {
|
||||
|
||||
/**
|
||||
* The reference to the core.
|
||||
*/
|
||||
protected MultiverseCore plugin;
|
||||
/**
|
||||
* The reference to {@link MultiverseMessaging}.
|
||||
*/
|
||||
protected MultiverseMessaging messaging;
|
||||
|
||||
public MultiverseCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.plugin = plugin;
|
||||
this.messaging = this.plugin.getMessaging();
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract void runCommand(CommandSender sender, List<String> args);
|
||||
|
||||
}
|
|
@ -1,177 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.pneumaticraft.commandhandler.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* A generic paginated command.
|
||||
* @param <T> The type of items on the page.
|
||||
*/
|
||||
public abstract class PaginatedCommand<T> extends Command {
|
||||
private final Pattern REGEX_SPECIAL_CHARS = Pattern.compile("[.+*?\\[^\\]$(){}=!<>|:-\\\\]");
|
||||
private static final int DEFAULT_ITEMS_PER_PAGE = 9;
|
||||
/**
|
||||
* The number of items per page.
|
||||
*/
|
||||
protected int itemsPerPage = DEFAULT_ITEMS_PER_PAGE;
|
||||
|
||||
public PaginatedCommand(JavaPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the number of items per page.
|
||||
*
|
||||
* @param items The new number of items per page.
|
||||
*/
|
||||
protected void setItemsPerPage(int items) {
|
||||
itemsPerPage = items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets filtered items.
|
||||
*
|
||||
* @param availableItems All available items.
|
||||
* @param filter The filter-{@link String}.
|
||||
* @return A list of items that match the filter.
|
||||
*/
|
||||
protected abstract List<T> getFilteredItems(List<T> availableItems, String filter);
|
||||
|
||||
/**
|
||||
* Escape regex special characters from filter
|
||||
*
|
||||
* @param filter The filter-{@link String}.
|
||||
* @return String with regex characters escaped
|
||||
*/
|
||||
protected String cleanFilter(String filter) {
|
||||
return REGEX_SPECIAL_CHARS.matcher(filter).replaceAll("\\\\$0");
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a single string from a list of strings.
|
||||
*
|
||||
* @param list The {@link List} of strings.
|
||||
* @return A single {@link String}.
|
||||
*/
|
||||
protected String stitchThisString(List<String> list) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (String s : list) {
|
||||
builder.append(s);
|
||||
builder.append(' ');
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a page.
|
||||
*
|
||||
* @param page The number of the page to show.
|
||||
* @param sender The {@link CommandSender} that wants to see the page.
|
||||
* @param cmds The items that should be displayed on the page.
|
||||
*/
|
||||
protected void showPage(int page, CommandSender sender, List<T> cmds) {
|
||||
// Ensure the page is at least 1.
|
||||
page = (page <= 0) ? 1 : page;
|
||||
int start = (page - 1) * itemsPerPage;
|
||||
int end = start + itemsPerPage;
|
||||
|
||||
for (int i = start; i < end; i++) {
|
||||
// For consistancy, print some extra lines if it's a player:
|
||||
if (i < cmds.size()) {
|
||||
sender.sendMessage(this.getItemText(cmds.get(i)));
|
||||
} else if (sender instanceof Player) {
|
||||
sender.sendMessage(" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an item into a string.
|
||||
*
|
||||
* @param item The item.
|
||||
* @return A {@link String}.
|
||||
*/
|
||||
protected abstract String getItemText(T item);
|
||||
|
||||
/**
|
||||
* Constructs a {@link FilterObject} from a {@link List} of arguments.
|
||||
*
|
||||
* @param args The {@link List} of arguments.
|
||||
* @return The {@link FilterObject}.
|
||||
*/
|
||||
protected FilterObject getPageAndFilter(List<String> args) {
|
||||
int page = 1;
|
||||
|
||||
String filter = "";
|
||||
|
||||
if (args.size() == 0) {
|
||||
filter = "";
|
||||
page = 1;
|
||||
} else if (args.size() == 1) {
|
||||
try {
|
||||
page = Integer.parseInt(args.get(0));
|
||||
} catch (NumberFormatException ex) {
|
||||
filter = args.get(0);
|
||||
page = 1;
|
||||
}
|
||||
} else if (args.size() == 2) {
|
||||
filter = args.get(0);
|
||||
try {
|
||||
page = Integer.parseInt(args.get(1));
|
||||
} catch (NumberFormatException ex) {
|
||||
page = 1;
|
||||
}
|
||||
}
|
||||
return new FilterObject(page, filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* "Key-Object" containing information about the page and the filter that were requested.
|
||||
*/
|
||||
protected class FilterObject {
|
||||
private Integer page;
|
||||
private String filter;
|
||||
|
||||
public FilterObject(Integer page, String filter) {
|
||||
this.page = page;
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the page.
|
||||
* @return The page.
|
||||
*/
|
||||
public Integer getPage() {
|
||||
return this.page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the page.
|
||||
*
|
||||
* @param page The new page.
|
||||
*/
|
||||
public void setPage(int page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the filter.
|
||||
* @return The filter.
|
||||
*/
|
||||
public String getFilter() {
|
||||
return this.filter;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
|
||||
/**
|
||||
* A generic paginated Multiverse-command.
|
||||
* @param <T> The type of items on the page.
|
||||
*/
|
||||
public abstract class PaginatedCoreCommand<T> extends PaginatedCommand<T> {
|
||||
/**
|
||||
* The reference to the core.
|
||||
*/
|
||||
protected MultiverseCore plugin;
|
||||
|
||||
public PaginatedCoreCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.api.WorldPurger;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Removes a type of mob from a world.
|
||||
*/
|
||||
public class PurgeCommand extends MultiverseCommand {
|
||||
private MVWorldManager worldManager;
|
||||
|
||||
public PurgeCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Purge World of Creatures");
|
||||
this.setCommandUsage("/mv purge" + ChatColor.GOLD + " [WORLD|all] " + ChatColor.GREEN + "{all|animals|monsters|MOBNAME}");
|
||||
this.setArgRange(1, 2);
|
||||
this.addKey("mvpurge");
|
||||
this.addKey("mv purge");
|
||||
this.addCommandExample("/mv purge " + ChatColor.GREEN + "all");
|
||||
this.addCommandExample("/mv purge " + ChatColor.GOLD + "all " + ChatColor.GREEN + "all");
|
||||
this.addCommandExample("/mv purge " + ChatColor.GREEN + "monsters");
|
||||
this.addCommandExample("/mv purge " + ChatColor.GOLD + "all " + ChatColor.GREEN + "animals");
|
||||
this.addCommandExample("/mv purge " + ChatColor.GOLD + "MyWorld " + ChatColor.GREEN + "squid");
|
||||
this.addCommandExample("/mv purge " + ChatColor.GOLD + "MyWorld_nether " + ChatColor.GREEN + "ghast");
|
||||
this.setPermission("multiverse.core.purge", "Removed the specified type of mob from the specified world.", PermissionDefault.OP);
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
Player p = null;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
}
|
||||
if (args.size() == 1 && p == null) {
|
||||
sender.sendMessage("This command requires a WORLD when being run from the console!");
|
||||
sender.sendMessage(this.getCommandUsage());
|
||||
return;
|
||||
}
|
||||
String worldName = null;
|
||||
String deathName = null;
|
||||
if (args.size() == 1) {
|
||||
worldName = p.getWorld().getName();
|
||||
deathName = args.get(0);
|
||||
} else {
|
||||
worldName = args.get(0);
|
||||
deathName = args.get(1);
|
||||
}
|
||||
|
||||
if (!worldName.equalsIgnoreCase("all") && !this.worldManager.isMVWorld(worldName)) {
|
||||
this.plugin.showNotMVWorldMessage(sender, worldName);
|
||||
sender.sendMessage("It cannot be purged.");
|
||||
return;
|
||||
}
|
||||
|
||||
List<MultiverseWorld> worldsToRemoveEntitiesFrom = new ArrayList<MultiverseWorld>();
|
||||
// Handle all case any user who names a world "all" should know better...
|
||||
if (worldName.equalsIgnoreCase("all")) {
|
||||
worldsToRemoveEntitiesFrom.addAll(this.worldManager.getMVWorlds());
|
||||
} else {
|
||||
worldsToRemoveEntitiesFrom.add(this.worldManager.getMVWorld(worldName));
|
||||
}
|
||||
|
||||
WorldPurger purger = this.worldManager.getTheWorldPurger();
|
||||
ArrayList<String> thingsToKill = new ArrayList<String>();
|
||||
if (deathName.equalsIgnoreCase("all") || deathName.equalsIgnoreCase("animals") || deathName.equalsIgnoreCase("monsters")) {
|
||||
thingsToKill.add(deathName.toUpperCase());
|
||||
} else {
|
||||
Collections.addAll(thingsToKill, deathName.toUpperCase().split(","));
|
||||
}
|
||||
for (MultiverseWorld w : worldsToRemoveEntitiesFrom) {
|
||||
purger.purgeWorld(w, thingsToKill, false, false, sender);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.commandtools.queue.QueuedCommand;
|
||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Regenerates a world.
|
||||
*/
|
||||
public class RegenCommand extends MultiverseCommand {
|
||||
|
||||
public RegenCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Regenerates a World");
|
||||
this.setCommandUsage("/mv regen" + ChatColor.GREEN + " {WORLD}" + ChatColor.GOLD + " [-s [SEED]] [--keep-gamerules]");
|
||||
this.setArgRange(1, 4);
|
||||
this.addKey("mvregen");
|
||||
this.addKey("mv regen");
|
||||
this.addCommandExample("You can use the -s with no args to get a new seed:");
|
||||
this.addCommandExample("/mv regen " + ChatColor.GREEN + "MyWorld" + ChatColor.GOLD + " -s");
|
||||
this.addCommandExample("or specifiy a seed to get that one:");
|
||||
this.addCommandExample("/mv regen " + ChatColor.GREEN + "MyWorld" + ChatColor.GOLD + " -s" + ChatColor.AQUA + " gargamel");
|
||||
this.setPermission("multiverse.core.regen", "Regenerates a world on your server. The previous state will be lost "
|
||||
+ ChatColor.RED + "PERMANENTLY.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
String worldName = args.get(0);
|
||||
boolean useseed = CommandHandler.hasFlag("-s", args);
|
||||
String seedflag = CommandHandler.getFlag("-s", args);
|
||||
boolean keepGamerules = CommandHandler.hasFlag("--keep-gamerules", args);
|
||||
|
||||
boolean randomseed = seedflag == null || seedflag.isEmpty() || seedflag.equalsIgnoreCase("--keep-gamerules");
|
||||
String seed = randomseed ? "" : seedflag;
|
||||
|
||||
this.plugin.getCommandQueueManager().addToQueue(new QueuedCommand(
|
||||
sender,
|
||||
doWorldRegen(sender, worldName, useseed, randomseed, seed, keepGamerules),
|
||||
String.format("Are you sure you want to regen '%s'? You cannot undo this action.", worldName)
|
||||
));
|
||||
}
|
||||
|
||||
private Runnable doWorldRegen(@NotNull CommandSender sender,
|
||||
@NotNull String worldName,
|
||||
boolean useSeed,
|
||||
boolean randomSeed,
|
||||
@NotNull String seed,
|
||||
boolean keepGamerules) {
|
||||
|
||||
return () -> {
|
||||
if (this.plugin.getMVWorldManager().regenWorld(worldName, useSeed, randomSeed, seed, keepGamerules)) {
|
||||
sender.sendMessage(ChatColor.GREEN + "World Regenerated!");
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(ChatColor.RED + "World could NOT be regenerated!");
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.event.MVConfigReloadEvent;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Reloads worlds.yml and config.yml.
|
||||
*/
|
||||
public class ReloadCommand extends MultiverseCommand {
|
||||
|
||||
public ReloadCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Reload Configs");
|
||||
this.setCommandUsage("/mv reload");
|
||||
this.setArgRange(0, 0);
|
||||
this.addKey("mvreload");
|
||||
this.addKey("mvr");
|
||||
this.addKey("mv reload");
|
||||
this.addCommandExample("/mv reload");
|
||||
this.setPermission("multiverse.core.reload", "Reloads worlds.yml and config.yml.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
sender.sendMessage(ChatColor.GOLD + "Reloading all Multiverse Plugin configs...");
|
||||
this.plugin.loadConfigs();
|
||||
this.plugin.getAnchorManager().loadAnchors();
|
||||
this.plugin.getMVWorldManager().loadWorlds(true);
|
||||
|
||||
List<String> configsLoaded = new ArrayList<String>();
|
||||
configsLoaded.add("Multiverse-Core - config.yml");
|
||||
configsLoaded.add("Multiverse-Core - worlds.yml");
|
||||
configsLoaded.add("Multiverse-Core - anchors.yml");
|
||||
// Create the event
|
||||
MVConfigReloadEvent configReload = new MVConfigReloadEvent(configsLoaded);
|
||||
// Fire it off
|
||||
this.plugin.getServer().getPluginManager().callEvent(configReload);
|
||||
for (String s : configReload.getAllConfigsLoaded()) {
|
||||
sender.sendMessage(s);
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.GREEN + "Reload Complete!");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Unloads a world and removes it from the config.
|
||||
*/
|
||||
public class RemoveCommand extends MultiverseCommand {
|
||||
|
||||
public RemoveCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Remove World");
|
||||
this.setCommandUsage("/mv remove" + ChatColor.GREEN + " {WORLD}");
|
||||
this.setArgRange(1, 1);
|
||||
this.addKey("mvremove");
|
||||
this.addKey("mv remove");
|
||||
this.addCommandExample("/mv remove " + ChatColor.GREEN + "MyWorld");
|
||||
this.setPermission("multiverse.core.remove",
|
||||
"Unloads a world from Multiverse and removes it from worlds.yml, this does NOT DELETE the world folder.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
if (this.plugin.getMVWorldManager().removeWorldFromConfig(args.get(0))) {
|
||||
sender.sendMessage("World removed from config!");
|
||||
} else {
|
||||
sender.sendMessage("Error trying to remove world from config!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* States who is in what world.
|
||||
*/
|
||||
public class ScriptCommand extends MultiverseCommand {
|
||||
|
||||
public ScriptCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Runs a script.");
|
||||
this.setCommandUsage("/mv script" + ChatColor.GOLD + " {script} [target]");
|
||||
this.setArgRange(1, 2);
|
||||
this.addKey("mv script");
|
||||
this.addKey("mvscript");
|
||||
this.addCommandExample(String.format("/mv script %sscript.txt", ChatColor.GOLD));
|
||||
this.addCommandExample(String.format("/mv script %stest.txt %ssomeplayer", ChatColor.GOLD, ChatColor.GREEN));
|
||||
this.setPermission("multiverse.core.script", "Runs a script.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
if (plugin.getScriptAPI() == null) {
|
||||
sender.sendMessage("Buscript failed to load while the server was starting. Scripts cannot be run.");
|
||||
return;
|
||||
}
|
||||
File file = new File(plugin.getScriptAPI().getScriptFolder(), args.get(0));
|
||||
if (!file.exists()) {
|
||||
sender.sendMessage("That script file does not exist in the Multiverse-Core scripts directory!");
|
||||
return;
|
||||
}
|
||||
Player player = null;
|
||||
if (sender instanceof Player) {
|
||||
player = (Player) sender;
|
||||
}
|
||||
String target = null;
|
||||
if (args.size() == 2) {
|
||||
target = args.get(1);
|
||||
}
|
||||
plugin.getScriptAPI().executeScript(file, target, player);
|
||||
sender.sendMessage(String.format("Script '%s%s%s' finished!", ChatColor.GOLD, file.getName(), ChatColor.WHITE));
|
||||
}
|
||||
}
|
|
@ -1,148 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.BlockSafety;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
/**
|
||||
* Sets the spawn for a world.
|
||||
*/
|
||||
public class SetSpawnCommand extends MultiverseCommand {
|
||||
public SetSpawnCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Set World Spawn");
|
||||
this.setCommandUsage("/mv setspawn");
|
||||
this.setArgRange(0, 6);
|
||||
this.addKey("mvsetspawn");
|
||||
this.addKey("mvsets");
|
||||
this.addKey("mvss");
|
||||
this.addKey("mv set spawn");
|
||||
this.addKey("mv setspawn");
|
||||
this.addKey("mvset spawn");
|
||||
this.addCommandExample("/mv set spawn");
|
||||
this.setPermission("multiverse.core.spawn.set", "Sets the spawn for the current world.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatches the user's command depending on the number of parameters
|
||||
* @param sender The player who executes the command, may be console as well.
|
||||
* @param args Command line parameters
|
||||
*/
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
if (args.isEmpty()) {
|
||||
setWorldSpawn(sender);
|
||||
} else if (args.size() == 4) {
|
||||
setWorldSpawn(sender, args.get(0), args.get(1), args.get(2), args.get(3));
|
||||
} else if (args.size() == 6) {
|
||||
setWorldSpawn(sender, args.get(0), args.get(1), args.get(2), args.get(3), args.get(4), args.get(5));
|
||||
} else {
|
||||
sender.sendMessage("Use no arguments for your current location, or world/x/y/z, or world/x/y/z/yaw/pitch!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the world spawn when no parameters are given
|
||||
* @param sender The {@link CommandSender} who executes the command.
|
||||
* Everything not a {@link Player}, e.g. console, gets rejected, as we can't get coordinates from there.
|
||||
*/
|
||||
protected void setWorldSpawn(CommandSender sender) {
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
Location l = p.getLocation();
|
||||
World w = p.getWorld();
|
||||
setWorldSpawn(sender, w, l);
|
||||
} else {
|
||||
sender.sendMessage("You need to give coordinates to use this command from the console!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the world spawn when 4 parameters are given
|
||||
* @param sender The {@link CommandSender} who executes the command
|
||||
* @param world The world to set the spawn in
|
||||
* @param x X-coordinate to set the spawn to (as a {@link String} as it's from the command line, gets parsed into a double)
|
||||
* @param y Y-coordinate to set the spawn to (as a {@link String} as it's from the command line, gets parsed into a double)
|
||||
* @param z Z-coordinate to set the spawn to (as a {@link String} as it's from the command line, gets parsed into a double)
|
||||
*/
|
||||
protected void setWorldSpawn(CommandSender sender, String world, String x, String y, String z) {
|
||||
setWorldSpawn(sender, world, x, y, z, "0", "0");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the world spawn when 6 parameters are given
|
||||
* @param sender The {@link CommandSender} who executes the command
|
||||
* @param world The world to set the spawn in
|
||||
* @param x X-coordinate to set the spawn to (as a {@link String} as it's from the command line, gets parsed into a double)
|
||||
* @param y Y-coordinate to set the spawn to (as a {@link String} as it's from the command line, gets parsed into a double)
|
||||
* @param z Z-coordinate to set the spawn to (as a {@link String} as it's from the command line, gets parsed into a double)
|
||||
* @param yaw Yaw a newly spawned player should look at (as a {@link String} as it's from the command line, gets parsed into a float)
|
||||
* @param pitch Pitch a newly spawned player should look at (as a {@link String} as it's from the command line, gets parsed into a float)
|
||||
*/
|
||||
protected void setWorldSpawn(CommandSender sender, String world, String x, String y, String z, String yaw, String pitch) {
|
||||
double dx, dy, dz;
|
||||
float fpitch, fyaw;
|
||||
World bukkitWorld = Bukkit.getWorld(world);
|
||||
if (bukkitWorld == null) {
|
||||
sender.sendMessage("World " + world + " is unknown!");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
dx = Double.parseDouble(x);
|
||||
dy = Double.parseDouble(y);
|
||||
dz = Double.parseDouble(z);
|
||||
fpitch = Float.parseFloat(pitch);
|
||||
fyaw = Float.parseFloat(yaw);
|
||||
} catch (NumberFormatException ex) {
|
||||
sender.sendMessage("All coordinates must be numeric");
|
||||
return;
|
||||
}
|
||||
Location l = new Location(bukkitWorld, dx, dy, dz, fyaw, fpitch);
|
||||
setWorldSpawn(sender, bukkitWorld, l);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the actual spawn-setting-work.
|
||||
*
|
||||
* @param sender The {@link CommandSender} that's setting the spawn.
|
||||
* @param w The {@link World} to set the spawn in
|
||||
* @param l The {@link Location} to set the spawn to
|
||||
*/
|
||||
private void setWorldSpawn(CommandSender sender, World w, Location l) {
|
||||
MultiverseWorld foundWorld = this.plugin.getMVWorldManager().getMVWorld(w.getName());
|
||||
if (foundWorld != null) {
|
||||
foundWorld.setSpawnLocation(l);
|
||||
BlockSafety bs = this.plugin.getBlockSafety();
|
||||
if (!bs.playerCanSpawnHereSafely(l) && foundWorld.getAdjustSpawn()) {
|
||||
sender.sendMessage("It looks like that location would normally be unsafe. But I trust you.");
|
||||
sender.sendMessage("I'm turning off the Safe-T-Teleporter for spawns to this world.");
|
||||
sender.sendMessage("If you want this turned back on just do:");
|
||||
sender.sendMessage(ChatColor.AQUA + "/mvm set adjustspawn true " + foundWorld.getAlias());
|
||||
foundWorld.setAdjustSpawn(false);
|
||||
}
|
||||
sender.sendMessage("Spawn was set to: " + plugin.getLocationManipulation().strCoords(l));
|
||||
if (!plugin.saveWorldConfig()) {
|
||||
sender.sendMessage(ChatColor.RED + "There was an issue saving worlds.yml! Your changes will only be temporary!");
|
||||
}
|
||||
} else {
|
||||
w.setSpawnLocation(l.getBlockX(), l.getBlockY(), l.getBlockZ());
|
||||
sender.sendMessage("Multiverse does not know about this world, only X,Y and Z set. Please import it to set the spawn fully (Pitch/Yaws).");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Enables debug-information.
|
||||
*/
|
||||
public class SilentCommand extends MultiverseCommand {
|
||||
|
||||
public SilentCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Turn silent mode on/off?");
|
||||
this.setCommandUsage("/mv silent" + ChatColor.GOLD + " [true|false|on|off]");
|
||||
this.setArgRange(0, 1);
|
||||
this.addKey("mv silent");
|
||||
this.addKey("mvsilent");
|
||||
this.addCommandExample("/mv silent " + ChatColor.GOLD + "true");
|
||||
this.setPermission("multiverse.core.silent", "Reduces the amount of startup messages.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
if (args.size() == 1) {
|
||||
if (args.get(0).equalsIgnoreCase("on")) {
|
||||
args.set(0, "true");
|
||||
}
|
||||
plugin.getMVConfig().setSilentStart(Boolean.valueOf(args.get(0)));
|
||||
plugin.saveMVConfigs();
|
||||
}
|
||||
this.displaySilentMode(sender);
|
||||
}
|
||||
|
||||
private void displaySilentMode(CommandSender sender) {
|
||||
if (plugin.getMVConfig().getSilentStart()) {
|
||||
sender.sendMessage("Multiverse Silent Start mode is " + ChatColor.GREEN + "ON");
|
||||
} else {
|
||||
sender.sendMessage("Multiverse Silent Start mode is " + ChatColor.RED + "OFF");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Takes the player to the latest bed he's slept in.
|
||||
*/
|
||||
public class SleepCommand extends MultiverseCommand {
|
||||
|
||||
public SleepCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Go to Sleep");
|
||||
this.setCommandUsage("/mv sleep");
|
||||
this.setArgRange(0, 0);
|
||||
this.addKey("mv sleep");
|
||||
this.setPermission("multiverse.core.sleep", "Takes you the latest bed you've slept in (Currently BROKEN).", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
Player p = null;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
}
|
||||
|
||||
if (p == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.utils.PlayerFinder;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Teleports a player to the spawn.
|
||||
*/
|
||||
public class SpawnCommand extends MultiverseCommand {
|
||||
|
||||
public SpawnCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
Permission otherPerm = new Permission("multiverse.core.spawn.other",
|
||||
"Teleports another player to the spawn of the world they are in.", PermissionDefault.OP);
|
||||
this.setName("Spawn");
|
||||
this.setCommandUsage("/mv spawn" + ChatColor.GOLD + " [PLAYER]");
|
||||
this.setArgRange(0, 1);
|
||||
this.addKey("mvspawn");
|
||||
this.addKey("mv spawn");
|
||||
this.addKey("mvs");
|
||||
this.setPermission("multiverse.core.spawn.self", "Teleports you to the Spawn Point of the world you are in.", PermissionDefault.OP);
|
||||
this.addAdditonalPermission(otherPerm);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
Player player = null;
|
||||
if (sender instanceof Player) {
|
||||
player = (Player) sender;
|
||||
}
|
||||
// If a persons name was passed in, you must be A. the console, or B have permissions
|
||||
if (args.size() == 1) {
|
||||
if (player != null && !this.plugin.getMVPerms().hasPermission(player, "multiverse.core.spawn.other", true)) {
|
||||
sender.sendMessage("You don't have permission to teleport another player to spawn. (multiverse.core.spawn.other)");
|
||||
return;
|
||||
}
|
||||
Player target = PlayerFinder.get(args.get(0), sender);
|
||||
if (target != null) {
|
||||
target.sendMessage("Teleporting to this world's spawn...");
|
||||
spawnAccurately(target);
|
||||
|
||||
if (player != null) {
|
||||
target.sendMessage("You were teleported by: " + ChatColor.YELLOW + player.getName());
|
||||
} else {
|
||||
target.sendMessage("You were teleported by: " + ChatColor.LIGHT_PURPLE + "the console");
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(args.get(0) + " is not logged on right now!");
|
||||
}
|
||||
} else {
|
||||
if (player != null && !this.plugin.getMVPerms().hasPermission(player, "multiverse.core.spawn.self", true)) {
|
||||
sender.sendMessage("You don't have permission to teleport yourself to spawn. (multiverse.core.spawn.self)");
|
||||
return;
|
||||
}
|
||||
if (player != null) {
|
||||
player.sendMessage("Teleporting to this world's spawn...");
|
||||
spawnAccurately(player);
|
||||
} else {
|
||||
sender.sendMessage("From the console, you must provide a PLAYER.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void spawnAccurately(Player player) {
|
||||
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(player.getWorld().getName());
|
||||
Location spawnLocation;
|
||||
if (world != null) {
|
||||
spawnLocation = world.getSpawnLocation();
|
||||
} else {
|
||||
spawnLocation = player.getWorld().getSpawnLocation();
|
||||
}
|
||||
this.plugin.getSafeTTeleporter().safelyTeleport(player, player, spawnLocation, false);
|
||||
}
|
||||
}
|
|
@ -1,199 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.Teleporter;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.commandtools.queue.QueuedCommand;
|
||||
import com.onarandombox.MultiverseCore.destination.CustomTeleporterDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.DestinationFactory;
|
||||
import com.onarandombox.MultiverseCore.destination.InvalidDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.WorldDestination;
|
||||
import com.onarandombox.MultiverseCore.enums.TeleportResult;
|
||||
import com.onarandombox.MultiverseCore.event.MVTeleportEvent;
|
||||
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.utils.PlayerFinder;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Used to teleport players.
|
||||
*/
|
||||
public class TeleportCommand extends MultiverseCommand {
|
||||
private SafeTTeleporter playerTeleporter;
|
||||
|
||||
public TeleportCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
Permission menu = new Permission("multiverse.teleport.*", "Allows you to display the teleport menu.", PermissionDefault.OP);
|
||||
|
||||
this.setName("Teleport");
|
||||
this.setCommandUsage("/mv tp " + ChatColor.GOLD + "[PLAYER]" + ChatColor.GREEN + " {DESTINATION}");
|
||||
this.setArgRange(1, 2);
|
||||
this.addKey("mvtp");
|
||||
this.addKey("mv tp");
|
||||
this.playerTeleporter = this.plugin.getSafeTTeleporter();
|
||||
this.setPermission(menu);
|
||||
}
|
||||
|
||||
private static final int UNSAFE_TELEPORT_EXPIRE_DELAY = 15;
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
CommandSender teleporter = sender;
|
||||
Player teleportee = null;
|
||||
|
||||
String destinationName;
|
||||
|
||||
if (args.size() == 2) {
|
||||
teleportee = PlayerFinder.get(args.get(0), sender);
|
||||
if (teleportee == null) {
|
||||
this.messaging.sendMessage(sender, String.format("Sorry, I couldn't find player: %s%s",
|
||||
ChatColor.GOLD, args.get(0)), false);
|
||||
return;
|
||||
}
|
||||
destinationName = args.get(1);
|
||||
|
||||
} else {
|
||||
destinationName = args.get(0);
|
||||
if (!(sender instanceof Player)) {
|
||||
this.messaging.sendMessage(sender, String.format("From the console, you must specify a player to teleport"), false);
|
||||
return;
|
||||
}
|
||||
teleportee = (Player) sender;
|
||||
}
|
||||
|
||||
DestinationFactory df = this.plugin.getDestFactory();
|
||||
MVDestination d = df.getPlayerAwareDestination(teleportee, destinationName);
|
||||
|
||||
MVTeleportEvent teleportEvent = new MVTeleportEvent(d, teleportee, teleporter, true);
|
||||
this.plugin.getServer().getPluginManager().callEvent(teleportEvent);
|
||||
if (teleportEvent.isCancelled()) {
|
||||
Logging.fine("Someone else cancelled the MVTeleport Event!!!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (d != null && d instanceof InvalidDestination) {
|
||||
this.messaging.sendMessage(sender, String.format("Multiverse does not know how to take you to %s%s",
|
||||
ChatColor.RED, destinationName), false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.checkSendPermissions(teleporter, teleportee, d)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.getMVConfig().getEnforceAccess() && teleporter != null && !this.plugin.getMVPerms().canEnterDestination(teleporter, d)) {
|
||||
if (teleportee.equals(teleporter)) {
|
||||
teleporter.sendMessage("Doesn't look like you're allowed to go " + ChatColor.RED + "there...");
|
||||
} else {
|
||||
teleporter.sendMessage("Doesn't look like you're allowed to send " + ChatColor.GOLD
|
||||
+ teleportee.getName() + ChatColor.WHITE + " to " + ChatColor.RED + "there...");
|
||||
}
|
||||
return;
|
||||
} else if (teleporter != null && !this.plugin.getMVPerms().canTravelFromLocation(teleporter, d.getLocation(teleportee))) {
|
||||
if (teleportee.equals(teleporter)) {
|
||||
this.messaging.sendMessage(teleporter, String.format("DOH! Doesn't look like you can get to %s%s %sfrom where you are...",
|
||||
ChatColor.GREEN, d.toString(), ChatColor.WHITE), false);
|
||||
} else {
|
||||
this.messaging.sendMessage(teleporter, String.format("DOH! Doesn't look like %s%s %scan get to %sTHERE from where they are...",
|
||||
ChatColor.GREEN, ((Player) teleporter).getWorld().getName(), ChatColor.WHITE, ChatColor.RED), false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Special check to verify if players are tryint to teleport to the same
|
||||
// WORLDDestination as the world they're in, that they ALSO have multiverse.core.spawn.self
|
||||
|
||||
if (d instanceof WorldDestination) {
|
||||
World w = d.getLocation(teleportee).getWorld();
|
||||
if (teleportee.getWorld().equals(w)) {
|
||||
if (teleporter.equals(teleportee)) {
|
||||
if (!this.plugin.getMVPerms().hasPermission(teleporter, "multiverse.core.spawn.self", true)) {
|
||||
this.messaging.sendMessages(teleporter, new String[]{
|
||||
String.format("Sorry you don't have permission to go to the world spawn!"),
|
||||
String.format("%s (multiverse.core.spawn.self)",
|
||||
ChatColor.RED) }, false);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!this.plugin.getMVPerms().hasPermission(teleporter, "multiverse.core.spawn.other", true)) {
|
||||
this.messaging.sendMessages(teleporter, new String[]{
|
||||
String.format("Sorry you don't have permission to send %s to the world spawn!",
|
||||
teleportee.getDisplayName()),
|
||||
String.format("%s (multiverse.core.spawn.other)",
|
||||
ChatColor.RED) }, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (d.getLocation(teleportee) == null) {
|
||||
this.messaging.sendMessage(teleporter, "Sorry Boss, I tried everything, but just couldn't teleport ya there!", false);
|
||||
return;
|
||||
}
|
||||
Teleporter teleportObject = (d instanceof CustomTeleporterDestination) ?
|
||||
((CustomTeleporterDestination)d).getTeleporter() : this.playerTeleporter;
|
||||
TeleportResult result = teleportObject.teleport(teleporter, teleportee, d);
|
||||
if (result == TeleportResult.FAIL_UNSAFE) {
|
||||
Logging.fine("Could not teleport " + teleportee.getName()
|
||||
+ " to " + plugin.getLocationManipulation().strCoordsRaw(d.getLocation(teleportee)));
|
||||
|
||||
String player = "you";
|
||||
if (!teleportee.equals(teleporter)) {
|
||||
player = teleportee.getName();
|
||||
}
|
||||
|
||||
this.plugin.getCommandQueueManager().addToQueue(new QueuedCommand(
|
||||
sender,
|
||||
doUnsafeTeleport(teleporter, teleportee, d.getLocation(teleportee)),
|
||||
String.format("%sMultiverse %sdid not teleport %s%s %sto %s%s %sbecause it was unsafe. Would you like to try anyway?",
|
||||
ChatColor.GREEN, ChatColor.WHITE, ChatColor.AQUA, player, ChatColor.WHITE, ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE),
|
||||
UNSAFE_TELEPORT_EXPIRE_DELAY
|
||||
));
|
||||
}
|
||||
// else: Player was teleported successfully (or the tp event was fired I should say)
|
||||
}
|
||||
|
||||
private Runnable doUnsafeTeleport(CommandSender teleporter, Player player, Location location) {
|
||||
return () -> this.plugin.getSafeTTeleporter().safelyTeleport(teleporter, player, location, false);
|
||||
}
|
||||
|
||||
private boolean checkSendPermissions(CommandSender teleporter, Player teleportee, MVDestination destination) {
|
||||
if (teleporter.equals(teleportee)) {
|
||||
if (!this.plugin.getMVPerms().hasPermission(teleporter, "multiverse.teleport.self." + destination.getIdentifier(), true)) {
|
||||
this.messaging.sendMessages(teleporter, new String[]{
|
||||
String.format("%sYou don't have permission to teleport %syourself %sto a %s%s %sDestination",
|
||||
ChatColor.WHITE, ChatColor.AQUA, ChatColor.WHITE, ChatColor.RED, destination.getType(), ChatColor.WHITE),
|
||||
String.format("%s (multiverse.teleport.self.%s)",
|
||||
ChatColor.RED, destination.getIdentifier()) }, false);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!this.plugin.getMVPerms().hasPermission(teleporter, "multiverse.teleport.other." + destination.getIdentifier(), true)) {
|
||||
this.messaging.sendMessages(teleporter, new String[]{
|
||||
String.format("You don't have permission to teleport another player to a %s%s Destination.",
|
||||
ChatColor.GREEN, destination.getType()),
|
||||
String.format("%s(multiverse.teleport.other.%s)",
|
||||
ChatColor.RED, destination.getIdentifier()) }, false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Unloads worlds from Multiverse.
|
||||
*/
|
||||
public class UnloadCommand extends MultiverseCommand {
|
||||
|
||||
public UnloadCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Unload World");
|
||||
this.setCommandUsage("/mv unload" + ChatColor.GREEN + " {WORLD}");
|
||||
this.setArgRange(1, 1);
|
||||
this.addKey("mvunload");
|
||||
this.addKey("mv unload");
|
||||
this.setPermission("multiverse.core.unload",
|
||||
"Unloads a world from Multiverse. This does NOT remove the world folder. This does NOT remove it from the config file.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
if (this.plugin.getMVWorldManager().unloadWorld(args.get(0))) {
|
||||
Command.broadcastCommandMessage(sender, "Unloaded world '" + args.get(0) + "'!");
|
||||
} else {
|
||||
sender.sendMessage("Error trying to unload world '" + args.get(0) + "'!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,225 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.event.MVVersionEvent;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.PasteFailedException;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.PasteService;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.PasteServiceFactory;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.PasteServiceType;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.URLShortener;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.URLShortenerFactory;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.URLShortenerType;
|
||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Dumps version info to the console.
|
||||
*/
|
||||
public class VersionCommand extends MultiverseCommand {
|
||||
private static final URLShortener SHORTENER = URLShortenerFactory.getService(URLShortenerType.BITLY);
|
||||
|
||||
public VersionCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Multiverse Version");
|
||||
this.setCommandUsage("/mv version " + ChatColor.GOLD + "[-b|-h|-p] [--include-plugin-list]");
|
||||
this.setArgRange(0, 2);
|
||||
this.addKey("mv version");
|
||||
this.addKey("mvver");
|
||||
this.addKey("mvv");
|
||||
this.addKey("mvversion");
|
||||
this.setPermission(
|
||||
"multiverse.core.version",
|
||||
"Dumps version info to the console, optionally to pastebin.com with -b, to hastebin.com using -h, or to paste.gg with -p.",
|
||||
PermissionDefault.OP)
|
||||
;
|
||||
}
|
||||
|
||||
private String getLegacyString() {
|
||||
return "[Multiverse-Core] Multiverse-Core Version: " + this.plugin.getDescription().getVersion() + '\n'
|
||||
+ "[Multiverse-Core] Bukkit Version: " + this.plugin.getServer().getVersion() + '\n'
|
||||
+ "[Multiverse-Core] Loaded Worlds: " + this.plugin.getMVWorldManager().getMVWorlds() + '\n'
|
||||
+ "[Multiverse-Core] Multiverse Plugins Loaded: " + this.plugin.getPluginCount() + '\n'
|
||||
+"[Multiverse-Core] Economy being used: " + plugin.getEconomist().getEconomyName() + '\n'
|
||||
+ "[Multiverse-Core] Permissions Plugin: " + this.plugin.getMVPerms().getType() + '\n'
|
||||
+ "[Multiverse-Core] Dumping Config Values: (version " + this.plugin.getMVConfig().getVersion() + ")" + '\n'
|
||||
+ "[Multiverse-Core] enforceaccess: " + plugin.getMVConfig().getEnforceAccess() + '\n'
|
||||
+ "[Multiverse-Core] prefixchat: " + plugin.getMVConfig().getPrefixChat() + '\n'
|
||||
+ "[Multiverse-Core] prefixchatformat: " + plugin.getMVConfig().getPrefixChatFormat() + '\n'
|
||||
+ "[Multiverse-Core] useasyncchat: " + plugin.getMVConfig().getUseAsyncChat() + '\n'
|
||||
+ "[Multiverse-Core] teleportintercept: " + plugin.getMVConfig().getTeleportIntercept() + '\n'
|
||||
+ "[Multiverse-Core] firstspawnoverride: " + plugin.getMVConfig().getFirstSpawnOverride() + '\n'
|
||||
+ "[Multiverse-Core] displaypermerrors: " + plugin.getMVConfig().getDisplayPermErrors() + '\n'
|
||||
+ "[Multiverse-Core] enablebuscript: " + plugin.getMVConfig().getEnableBuscript() + '\n'
|
||||
+ "[Multiverse-Core] globaldebug: " + plugin.getMVConfig().getGlobalDebug() + '\n'
|
||||
+ "[Multiverse-Core] silentstart: " + plugin.getMVConfig().getSilentStart() + '\n'
|
||||
+ "[Multiverse-Core] messagecooldown: " + plugin.getMessaging().getCooldown() + '\n'
|
||||
+ "[Multiverse-Core] version: " + plugin.getMVConfig().getVersion() + '\n'
|
||||
+ "[Multiverse-Core] firstspawnworld: " + plugin.getMVConfig().getFirstSpawnWorld() + '\n'
|
||||
+ "[Multiverse-Core] teleportcooldown: " + plugin.getMVConfig().getTeleportCooldown() + '\n'
|
||||
+ "[Multiverse-Core] defaultportalsearch: " + plugin.getMVConfig().isUsingDefaultPortalSearch() + '\n'
|
||||
+ "[Multiverse-Core] portalsearchradius: " + plugin.getMVConfig().getPortalSearchRadius() + '\n'
|
||||
+ "[Multiverse-Core] autopurge: " + plugin.getMVConfig().isAutoPurgeEnabled() + '\n'
|
||||
+ "[Multiverse-Core] Special Code: FRN002" + '\n';
|
||||
}
|
||||
|
||||
private String getMarkdownString() {
|
||||
return "# Multiverse-Core" + '\n'
|
||||
+ "## Overview" + '\n'
|
||||
+ "| Name | Value |" + '\n'
|
||||
+ "| --- | --- |" + '\n'
|
||||
+ "| Multiverse-Core Version | `" + this.plugin.getDescription().getVersion() + "` |" + '\n'
|
||||
+ "| Bukkit Version | `" + this.plugin.getServer().getVersion() + "` |" + '\n'
|
||||
+ "| Loaded Worlds | `" + this.plugin.getMVWorldManager().getMVWorlds() + "` |" + '\n'
|
||||
+ "| Multiverse Plugins Loaded | `" + this.plugin.getPluginCount() + "` |" + '\n'
|
||||
+ "| Economy being used | `" + plugin.getEconomist().getEconomyName() + "` |" + '\n'
|
||||
+ "| Permissions Plugin | `" + this.plugin.getMVPerms().getType() + "` |" + '\n'
|
||||
+ "## Parsed Config" + '\n'
|
||||
+ "These are what Multiverse thought the in-memory values of the config were." + "\n\n"
|
||||
+ "| Config Key | Value |" + '\n'
|
||||
+ "| --- | --- |" + '\n'
|
||||
+ "| version | `" + this.plugin.getMVConfig().getVersion() + "` |" + '\n'
|
||||
+ "| messagecooldown | `" + plugin.getMessaging().getCooldown() + "` |" + '\n'
|
||||
+ "| teleportcooldown | `" + plugin.getMVConfig().getTeleportCooldown() + "` |" + '\n'
|
||||
+ "| worldnameprefix | `" + plugin.getMVConfig().getPrefixChat() + "` |" + '\n'
|
||||
+ "| worldnameprefixFormat | `" + plugin.getMVConfig().getPrefixChatFormat() + "` |" + '\n'
|
||||
+ "| enforceaccess | `" + plugin.getMVConfig().getEnforceAccess() + "` |" + '\n'
|
||||
+ "| displaypermerrors | `" + plugin.getMVConfig().getDisplayPermErrors() + "` |" + '\n'
|
||||
+ "| teleportintercept | `" + plugin.getMVConfig().getTeleportIntercept() + "` |" + '\n'
|
||||
+ "| firstspawnoverride | `" + plugin.getMVConfig().getFirstSpawnOverride() + "` |" + '\n'
|
||||
+ "| firstspawnworld | `" + plugin.getMVConfig().getFirstSpawnWorld() + "` |" + '\n'
|
||||
+ "| debug | `" + plugin.getMVConfig().getGlobalDebug() + "` |" + '\n';
|
||||
}
|
||||
|
||||
private void addVersionInfoToEvent(MVVersionEvent event) {
|
||||
// add the legacy version info
|
||||
event.appendVersionInfo(this.getLegacyString());
|
||||
|
||||
// add the legacy file, but as markdown so it's readable
|
||||
// TODO Readd this in 5.0.0
|
||||
// event.putDetailedVersionInfo("version.md", this.getMarkdownString());
|
||||
|
||||
// add config.yml
|
||||
File configFile = new File(this.plugin.getDataFolder(), "config.yml");
|
||||
event.putDetailedVersionInfo("multiverse-core/config.yml", configFile);
|
||||
|
||||
// add worlds.yml
|
||||
File worldsFile = new File(this.plugin.getDataFolder(), "worlds.yml");
|
||||
event.putDetailedVersionInfo("multiverse-core/worlds.yml", worldsFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(final CommandSender sender, final List<String> args) {
|
||||
// Check if the command was sent from a Player.
|
||||
if (sender instanceof Player) {
|
||||
sender.sendMessage("Version info dumped to console. Please check your server logs.");
|
||||
}
|
||||
|
||||
MVVersionEvent versionEvent = new MVVersionEvent();
|
||||
|
||||
this.addVersionInfoToEvent(versionEvent);
|
||||
this.plugin.getServer().getPluginManager().callEvent(versionEvent);
|
||||
|
||||
if (CommandHandler.hasFlag("--include-plugin-list", args)) {
|
||||
versionEvent.appendVersionInfo('\n' + "Plugins: " + getPluginList());
|
||||
versionEvent.putDetailedVersionInfo("plugins.txt", "Plugins: " + getPluginList());
|
||||
}
|
||||
|
||||
final String versionInfo = versionEvent.getVersionInfo();
|
||||
versionEvent.putDetailedVersionInfo("version.txt", versionInfo);
|
||||
|
||||
final Map<String, String> files = versionEvent.getDetailedVersionInfo();
|
||||
|
||||
// log to console
|
||||
String[] lines = versionInfo.split("\\r?\\n");
|
||||
for (String line : lines) {
|
||||
if (!line.isEmpty()) {
|
||||
this.plugin.getServer().getLogger().info(line);
|
||||
}
|
||||
}
|
||||
|
||||
BukkitRunnable logPoster = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (args.size() > 0) {
|
||||
String pasteUrl;
|
||||
if (CommandHandler.hasFlag("-b", args)) {
|
||||
// private post to pastebin
|
||||
pasteUrl = postToService(PasteServiceType.PASTEBIN, true, versionInfo, files);
|
||||
} else if (CommandHandler.hasFlag("-g", args)) {
|
||||
// private post to github
|
||||
pasteUrl = postToService(PasteServiceType.GITHUB, true, versionInfo, files);
|
||||
} else if (CommandHandler.hasFlag("-h", args)) {
|
||||
// private post to hastebin
|
||||
pasteUrl = postToService(PasteServiceType.HASTEBIN, true, versionInfo, files);
|
||||
} else if (CommandHandler.hasFlag("-p", args)) {
|
||||
// private post to paste.gg
|
||||
pasteUrl = postToService(PasteServiceType.PASTEGG, true, versionInfo, files);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(sender instanceof ConsoleCommandSender)) {
|
||||
sender.sendMessage("Version info dumped here: " + ChatColor.GREEN + pasteUrl);
|
||||
}
|
||||
Logging.info("Version info dumped here: %s", pasteUrl);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Run the log posting operation asynchronously, since we don't know how long it will take.
|
||||
logPoster.runTaskAsynchronously(this.plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the current contents of this.pasteBinBuffer to a web service.
|
||||
*
|
||||
* @param type Service type to send paste data to.
|
||||
* @param isPrivate Should the paste be marked as private.
|
||||
* @param pasteData Legacy string only data to post to a service.
|
||||
* @param pasteFiles Map of filenames/contents of debug info.
|
||||
* @return URL of visible paste
|
||||
*/
|
||||
private static String postToService(PasteServiceType type, boolean isPrivate, String pasteData, Map<String, String> pasteFiles) {
|
||||
PasteService ps = PasteServiceFactory.getService(type, isPrivate);
|
||||
|
||||
try {
|
||||
String result;
|
||||
if (ps.supportsMultiFile()) {
|
||||
result = ps.postData(pasteFiles);
|
||||
} else {
|
||||
result = ps.postData(pasteData);
|
||||
}
|
||||
|
||||
if (SHORTENER != null) return SHORTENER.shorten(result);
|
||||
return result;
|
||||
} catch (PasteFailedException e) {
|
||||
e.printStackTrace();
|
||||
return "Error posting to service.";
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
return "That service isn't supported yet.";
|
||||
}
|
||||
}
|
||||
|
||||
private String getPluginList() {
|
||||
return StringUtils.join(plugin.getServer().getPluginManager().getPlugins(), ", ");
|
||||
}
|
||||
}
|
|
@ -1,118 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* States who is in what world.
|
||||
*/
|
||||
public class WhoCommand extends MultiverseCommand {
|
||||
|
||||
private MVWorldManager worldManager;
|
||||
|
||||
public WhoCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Who?");
|
||||
this.setCommandUsage("/mv who" + ChatColor.GOLD + " [WORLD|--all]");
|
||||
this.setArgRange(0, 1);
|
||||
this.addKey("mv who");
|
||||
this.addKey("mvw");
|
||||
this.addKey("mvwho");
|
||||
this.addCommandExample("/mv who");
|
||||
this.addCommandExample(String.format("/mv who %s--all", ChatColor.GREEN));
|
||||
this.addCommandExample(String.format("/mv who %smyworld", ChatColor.GOLD));
|
||||
this.setPermission("multiverse.core.list.who", "States who is in what world.", PermissionDefault.OP);
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
// If this command was sent from a Player then we need to check Permissions
|
||||
Player p = null;
|
||||
// By default, show all from the console
|
||||
boolean showAll = true;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
showAll = false;
|
||||
}
|
||||
|
||||
final Collection onlinePlayers = plugin.getServer().getOnlinePlayers();
|
||||
final Collection<Player> visiblePlayers = new HashSet<Player>(onlinePlayers.size());
|
||||
for (final Object player : onlinePlayers) {
|
||||
if (player instanceof Player && (p == null || p.canSee((Player) player))) {
|
||||
visiblePlayers.add((Player) player);
|
||||
}
|
||||
}
|
||||
|
||||
if (args.size() == 1) {
|
||||
if (args.get(0).equalsIgnoreCase("--all") || args.get(0).equalsIgnoreCase("-a")) {
|
||||
showAll = true;
|
||||
} else {
|
||||
// single world mode
|
||||
MultiverseWorld world = this.worldManager.getMVWorld(args.get(0));
|
||||
if (world == null) {
|
||||
sender.sendMessage(ChatColor.RED + "That world does not exist.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.plugin.getMVPerms().canEnterWorld(p, world)) {
|
||||
sender.sendMessage(ChatColor.RED + "You aren't allowed to access to this world!");
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(String.format("%s--- Players in %s%s ---", ChatColor.AQUA,
|
||||
world.getColoredWorldString(), ChatColor.AQUA));
|
||||
sender.sendMessage(this.buildPlayerString(world, p, visiblePlayers));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// multiworld mode
|
||||
sender.sendMessage(ChatColor.AQUA + "--- Worlds and their players --- "
|
||||
+ visiblePlayers.size() + "/" + plugin.getServer().getMaxPlayers());
|
||||
boolean shownOne = false;
|
||||
for (MultiverseWorld world : this.worldManager.getMVWorlds()) {
|
||||
if (this.plugin.getMVPerms().canEnterWorld(p, world)) { // only show world if the player can access it
|
||||
if (showAll || !world.getCBWorld().getPlayers().isEmpty()) { // either show all or show if the world is not empty
|
||||
sender.sendMessage(String.format("%s%s - %s", world.getColoredWorldString(), ChatColor.WHITE, buildPlayerString(world, p, visiblePlayers)));
|
||||
shownOne = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!shownOne) {
|
||||
sender.sendMessage("No worlds found.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
private static String buildPlayerString(MultiverseWorld world, Player viewer, final Collection<Player> visiblePlayers) {
|
||||
// Retrieve the players in this world
|
||||
List<Player> players = world.getCBWorld().getPlayers();
|
||||
StringBuilder playerBuilder = new StringBuilder();
|
||||
for (Player player : players) {
|
||||
// If the viewer is the console or the viewier is allowed to see the player, show them.
|
||||
// Make sure we're also ONLY showing online players.
|
||||
// Since we already checked visible players, we'll just make sure who we're about to show is in that.
|
||||
if (visiblePlayers.contains(player))
|
||||
playerBuilder.append(player.getDisplayName()).append(", ");
|
||||
}
|
||||
String bString = playerBuilder.toString();
|
||||
return (bString.length() == 0) ? "No players found." : bString.substring(0, bString.length() - 2);
|
||||
}
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
/**
|
||||
* This package contains all Commands.
|
||||
*/
|
||||
package com.onarandombox.MultiverseCore.commands;
|
|
@ -1,89 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore.configuration;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.onarandombox.MultiverseCore.utils.MaterialConverter;
|
||||
import me.main__.util.SerializationConfig.Property;
|
||||
import me.main__.util.SerializationConfig.SerializationConfig;
|
||||
|
||||
import me.main__.util.SerializationConfig.Serializor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.serialization.SerializableAs;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Entryfee-settings.
|
||||
*/
|
||||
@SerializableAs("MVEntryFee")
|
||||
public class EntryFee extends SerializationConfig {
|
||||
@Property
|
||||
private double amount;
|
||||
@Property(serializor = EntryFeeCurrencySerializor.class)
|
||||
@Nullable
|
||||
private Material currency;
|
||||
|
||||
private final Material DISABLED_MATERIAL = Material.AIR;
|
||||
|
||||
public EntryFee() {
|
||||
super();
|
||||
}
|
||||
|
||||
public EntryFee(Map<String, Object> values) {
|
||||
super(values);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void setDefaults() {
|
||||
amount = 0D;
|
||||
currency = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the amount
|
||||
*/
|
||||
public double getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the currency
|
||||
*/
|
||||
@Nullable
|
||||
public Material getCurrency() {
|
||||
if (currency == null || currency.equals(DISABLED_MATERIAL)) {
|
||||
return null;
|
||||
}
|
||||
return currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the amount.
|
||||
* @param amount The new value.
|
||||
*/
|
||||
public void setAmount(double amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the currency.
|
||||
* @param currency The new value.
|
||||
*/
|
||||
public void setCurrency(@Nullable Material currency) {
|
||||
this.currency = currency;
|
||||
}
|
||||
|
||||
public static final class EntryFeeCurrencySerializor implements Serializor<Material, Object> {
|
||||
@Override
|
||||
public String serialize(Material material) {
|
||||
return material.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material deserialize(Object o, Class<Material> aClass) {
|
||||
return MaterialConverter.convertTypeString(o.toString());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore.configuration;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import me.main__.util.SerializationConfig.Property;
|
||||
import me.main__.util.SerializationConfig.SerializationConfig;
|
||||
|
||||
import org.bukkit.configuration.serialization.SerializableAs;
|
||||
|
||||
/**
|
||||
* Spawning-Settings.
|
||||
*/
|
||||
@SerializableAs("MVSpawnSettings")
|
||||
public class SpawnSettings extends SerializationConfig {
|
||||
@Property
|
||||
private SubSpawnSettings animals;
|
||||
@Property
|
||||
private SubSpawnSettings monsters;
|
||||
|
||||
public SpawnSettings() {
|
||||
super();
|
||||
}
|
||||
|
||||
public SpawnSettings(Map<String, Object> values) {
|
||||
super(values);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setDefaults() {
|
||||
animals = new SubSpawnSettings();
|
||||
monsters = new SubSpawnSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the animal-settings
|
||||
*/
|
||||
public SubSpawnSettings getAnimalSettings() {
|
||||
return animals;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the monster-settings
|
||||
*/
|
||||
public SubSpawnSettings getMonsterSettings() {
|
||||
return monsters;
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore.configuration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import me.main__.util.SerializationConfig.Property;
|
||||
import me.main__.util.SerializationConfig.SerializationConfig;
|
||||
|
||||
import org.bukkit.configuration.serialization.SerializableAs;
|
||||
|
||||
/**
|
||||
* SpawnSubSettings.
|
||||
*/
|
||||
@SerializableAs("MVSpawnSubSettings")
|
||||
public class SubSpawnSettings extends SerializationConfig {
|
||||
@Property
|
||||
private boolean spawn;
|
||||
@Property
|
||||
private int spawnrate;
|
||||
@Property
|
||||
private List<String> exceptions;
|
||||
|
||||
public SubSpawnSettings() {
|
||||
super();
|
||||
}
|
||||
|
||||
public SubSpawnSettings(Map<String, Object> values) {
|
||||
super(values);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setDefaults() {
|
||||
spawn = true;
|
||||
exceptions = new ArrayList<String>();
|
||||
spawnrate = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return spawn
|
||||
*/
|
||||
public boolean doSpawn() {
|
||||
return spawn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param spawn The new value.
|
||||
*/
|
||||
public void setSpawn(boolean spawn) {
|
||||
this.spawn = spawn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The exceptions
|
||||
*/
|
||||
public List<String> getExceptions() {
|
||||
return exceptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param rate The new spawn rate
|
||||
*/
|
||||
public void setSpawnRate(int rate) {
|
||||
this.spawnrate = rate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The spawn rate
|
||||
*/
|
||||
public int getSpawnRate() {
|
||||
return this.spawnrate;
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore.configuration;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MVWorld;
|
||||
import com.onarandombox.MultiverseCore.event.MVWorldPropertyChangeEvent;
|
||||
|
||||
import me.main__.util.SerializationConfig.ChangeDeniedException;
|
||||
import me.main__.util.SerializationConfig.ObjectUsingValidator;
|
||||
|
||||
/**
|
||||
* Validates world-property-changes.
|
||||
* @param <T> The type of the property that should be validated.
|
||||
*/
|
||||
public class WorldPropertyValidator<T> extends ObjectUsingValidator<T, MVWorld> {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public T validateChange(String property, T newValue, T oldValue, MVWorld object) throws ChangeDeniedException {
|
||||
MVWorldPropertyChangeEvent<T> event = new MVWorldPropertyChangeEvent<T>(object, null, property, newValue);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled())
|
||||
throw new ChangeDeniedException();
|
||||
return event.getTheNewValue();
|
||||
}
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
/**
|
||||
* This package contains the Multiverse-configuration.
|
||||
*/
|
||||
package com.onarandombox.MultiverseCore.configuration;
|
|
@ -1,148 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.destination;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An anchor-{@link MVDestination}.
|
||||
*/
|
||||
public class AnchorDestination implements MVDestination {
|
||||
private boolean isValid;
|
||||
private Location location;
|
||||
private MultiverseCore plugin;
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "a";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Vector getVelocity() {
|
||||
return new Vector(0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isThisType(JavaPlugin plugin, String destination) {
|
||||
if (!(plugin instanceof MultiverseCore)) {
|
||||
return false;
|
||||
}
|
||||
this.plugin = (MultiverseCore) plugin;
|
||||
List<String> parsed = Arrays.asList(destination.split(":"));
|
||||
// Need at least: a:name
|
||||
if (!(parsed.size() == 2)) {
|
||||
return false;
|
||||
}
|
||||
// If it's not an Anchor type
|
||||
return parsed.get(0).equalsIgnoreCase("a");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Location getLocation(Entity e) {
|
||||
return this.location;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return this.isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setDestination(JavaPlugin plugin, String destination) {
|
||||
if (!(plugin instanceof MultiverseCore)) {
|
||||
return;
|
||||
}
|
||||
this.plugin = (MultiverseCore) plugin;
|
||||
List<String> parsed = Arrays.asList(destination.split(":"));
|
||||
// Need at least: e:world:x,y,z
|
||||
// OR e:world:x,y,z:pitch:yaw
|
||||
// so basically 3 or 5
|
||||
if (!(parsed.size() == 2)) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
this.name = parsed.get(1);
|
||||
this.location = this.plugin.getAnchorManager().getAnchorLocation(parsed.get(1));
|
||||
if (this.location == null) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
if (!parsed.get(0).equalsIgnoreCase(this.getIdentifier())) {
|
||||
this.isValid = false;
|
||||
}
|
||||
this.isValid = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getType() {
|
||||
return "Anchor";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Anchor: " + this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (isValid) {
|
||||
return "a:" + this.name;
|
||||
}
|
||||
return "i:Invalid Destination";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getRequiredPermission() {
|
||||
return "multiverse.access." + this.location.getWorld().getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean useSafeTeleporter() {
|
||||
// This is an ANCHOR destination, don't safely teleport here.
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,141 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.destination;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
/**
|
||||
* A bed-{@link MVDestination}.
|
||||
*/
|
||||
public class BedDestination implements MVDestination {
|
||||
public static final String OWN_BED_STRING = "playerbed";
|
||||
private String playername = "";
|
||||
private boolean isValid;
|
||||
private Location knownBedLoc;
|
||||
private MultiverseCore plugin;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "b";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isThisType(JavaPlugin plugin, String destination) {
|
||||
String[] split = destination.split(":");
|
||||
boolean validFormat = split.length >= 1 && split.length <= 2 && split[0].equals(this.getIdentifier());
|
||||
|
||||
OfflinePlayer p = Bukkit.getOfflinePlayer(split[1]);
|
||||
boolean validPlayer = p.getName() != null && !p.getName().equals(OWN_BED_STRING);
|
||||
|
||||
if (validFormat && validPlayer) this.playername = p.getName();
|
||||
|
||||
this.isValid = destination.equals("b:" + OWN_BED_STRING) || (validFormat && validPlayer);
|
||||
|
||||
return this.isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Location getLocation(Entity entity) {
|
||||
if (entity instanceof Player) {
|
||||
if (this.playername.isEmpty())
|
||||
this.knownBedLoc = this.plugin.getBlockSafety().getSafeBedSpawn(((Player) entity).getBedSpawnLocation());
|
||||
else
|
||||
this.knownBedLoc = this.plugin.getBlockSafety().getSafeBedSpawn(Bukkit.getOfflinePlayer(this.playername).getBedSpawnLocation());
|
||||
|
||||
if (this.knownBedLoc == null) {
|
||||
((Player) entity).sendMessage("The bed was " + ChatColor.RED + "invalid or blocked" + ChatColor.RESET + ". Sorry.");
|
||||
}
|
||||
return this.knownBedLoc;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Vector getVelocity() {
|
||||
return new Vector();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setDestination(JavaPlugin plugin, String destination) {
|
||||
this.plugin = (MultiverseCore) plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return this.isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getType() {
|
||||
return "Bed";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Bed";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getRequiredPermission() {
|
||||
if (knownBedLoc != null) {
|
||||
return "multiverse.access." + knownBedLoc.getWorld().getName();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean useSafeTeleporter() {
|
||||
// Bukkit should have already checked this.
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "b:" + (playername.isEmpty() ? OWN_BED_STRING : playername);
|
||||
}
|
||||
}
|
|
@ -1,227 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.destination;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A cannon-{@link MVDestination}.
|
||||
*/
|
||||
public class CannonDestination implements MVDestination {
|
||||
private final String coordRegex = "(-?[\\d]+\\.?[\\d]*),(-?[\\d]+\\.?[\\d]*),(-?[\\d]+\\.?[\\d]*)";
|
||||
private boolean isValid;
|
||||
private Location location;
|
||||
private double speed;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Vector getVelocity() {
|
||||
double pitchRadians = Math.toRadians(location.getPitch());
|
||||
double yawRadians = Math.toRadians(location.getYaw());
|
||||
double x = Math.sin(yawRadians) * speed * -1;
|
||||
double y = Math.sin(pitchRadians) * speed * -1;
|
||||
double z = Math.cos(yawRadians) * speed;
|
||||
// Account for the angle they were pointed, and take away velocity
|
||||
x = Math.cos(pitchRadians) * x;
|
||||
z = Math.cos(pitchRadians) * z;
|
||||
return new Vector(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "ca";
|
||||
}
|
||||
|
||||
// NEED ca:world:x,y,z:pitch:yaw:speed
|
||||
// so basically 6
|
||||
private static final int SPLIT_SIZE = 6;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isThisType(JavaPlugin plugin, String destination) {
|
||||
if (!(plugin instanceof MultiverseCore)) {
|
||||
return false;
|
||||
}
|
||||
List<String> parsed = Arrays.asList(destination.split(":"));
|
||||
if (parsed.size() != SPLIT_SIZE) {
|
||||
return false;
|
||||
}
|
||||
// If it's not an Cannon type
|
||||
if (!parsed.get(0).equalsIgnoreCase("ca")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If it's not a MV world
|
||||
if (!((MultiverseCore) plugin).getMVWorldManager().isMVWorld(parsed.get(1))) {
|
||||
return false;
|
||||
}
|
||||
// Verify X,Y,Z are numbers
|
||||
if (!parsed.get(2).matches(coordRegex)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
// BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck
|
||||
Float.parseFloat(parsed.get(3));
|
||||
Float.parseFloat(parsed.get(4));
|
||||
Float.parseFloat(parsed.get(5));
|
||||
// END CHECKSTYLE-SUPPRESSION: MagicNumberCheck
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Location getLocation(Entity e) {
|
||||
return this.location;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return this.isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setDestination(JavaPlugin plugin, String destination) {
|
||||
if (!(plugin instanceof MultiverseCore)) {
|
||||
return;
|
||||
}
|
||||
List<String> parsed = Arrays.asList(destination.split(":"));
|
||||
|
||||
if (parsed.size() != SPLIT_SIZE) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
if (!parsed.get(0).equalsIgnoreCase(this.getIdentifier())) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!((MultiverseCore) plugin).getMVWorldManager().isMVWorld(parsed.get(1))) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
this.location = new Location(((MultiverseCore) plugin).getMVWorldManager().getMVWorld(parsed.get(1)).getCBWorld(), 0, 0, 0);
|
||||
|
||||
if (!parsed.get(2).matches(this.coordRegex)) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
double[] coords = new double[3];
|
||||
String[] coordString = parsed.get(2).split(",");
|
||||
for (int i = 0; i < 3; i++) {
|
||||
try {
|
||||
coords[i] = Double.parseDouble(coordString[i]);
|
||||
} catch (NumberFormatException e) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.location.setX(coords[0]);
|
||||
this.location.setY(coords[1]);
|
||||
this.location.setZ(coords[2]);
|
||||
|
||||
try {
|
||||
// BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck
|
||||
this.location.setPitch(Float.parseFloat(parsed.get(3)));
|
||||
this.location.setYaw(Float.parseFloat(parsed.get(4)));
|
||||
this.speed = Math.abs(Float.parseFloat(parsed.get(5)));
|
||||
// END CHECKSTYLE-SUPPRESSION: MagicNumberCheck
|
||||
} catch (NumberFormatException e) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
this.isValid = true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getType() {
|
||||
return "Cannon!";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Cannon (" + this.location.getX() + ", " + this.location.getY() + ", " + this.location.getZ() + ":"
|
||||
+ this.location.getPitch() + ":" + this.location.getYaw() + ":" + this.speed + ")";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this {@link CannonDestination}.
|
||||
*
|
||||
* @param location The {@link Location}.
|
||||
* @param speed The speed.
|
||||
*/
|
||||
public void setDestination(Location location, double speed) {
|
||||
if (location != null) {
|
||||
this.location = location;
|
||||
this.speed = Math.abs(speed);
|
||||
this.isValid = true;
|
||||
}
|
||||
this.isValid = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getRequiredPermission() {
|
||||
return "multiverse.access." + this.location.getWorld().getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean useSafeTeleporter() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (isValid) {
|
||||
return "ca:" + location.getWorld().getName() + ":" + location.getX() + "," + location.getY()
|
||||
+ "," + location.getZ() + ":" + location.getPitch() + ":" + location.getYaw() + ":" + this.speed;
|
||||
}
|
||||
return "i:Invalid Destination";
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore.destination;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.Teleporter;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public abstract class CustomTeleporterDestination implements MVDestination {
|
||||
@Override
|
||||
public final Location getLocation(final Entity entity) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Vector getVelocity() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean useSafeTeleporter() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract String toString();
|
||||
|
||||
public abstract Teleporter getTeleporter();
|
||||
}
|
|
@ -1,179 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.destination;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.commands.TeleportCommand;
|
||||
import com.onarandombox.MultiverseCore.utils.PermissionTools;
|
||||
import com.onarandombox.MultiverseCore.utils.PlayerFinder;
|
||||
import com.pneumaticraft.commandhandler.Command;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* A factory class that will create destinations from specific strings.
|
||||
*/
|
||||
public class DestinationFactory {
|
||||
|
||||
private static final Pattern CANNON_PATTERN = Pattern.compile("(?i)cannon-[\\d]+(\\.[\\d]+)?");
|
||||
|
||||
private MultiverseCore plugin;
|
||||
private Map<String, Class<? extends MVDestination>> destList;
|
||||
private Command teleportCommand;
|
||||
|
||||
public DestinationFactory(MultiverseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
this.destList = new HashMap<String, Class<? extends MVDestination>>();
|
||||
List<Command> cmds = this.plugin.getCommandHandler().getAllCommands();
|
||||
for (Command c : cmds) {
|
||||
if (c instanceof TeleportCommand) {
|
||||
this.teleportCommand = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a destination that has relation to sender, such as a cannon or player destination.
|
||||
*
|
||||
* @param teleportee The player that is going to be teleported.
|
||||
* @param destinationName The destination to parse.
|
||||
* @return A non-null MVDestination
|
||||
*/
|
||||
@NotNull
|
||||
public MVDestination getPlayerAwareDestination(@NotNull Player teleportee,
|
||||
@NotNull String destinationName) {
|
||||
|
||||
// Prioritise world, in the event that a world is named after a player online.
|
||||
if (Bukkit.getWorld(destinationName) != null) {
|
||||
return getDestination(destinationName);
|
||||
}
|
||||
|
||||
Player targetPlayer = PlayerFinder.get(destinationName, teleportee);
|
||||
if (targetPlayer != null) {
|
||||
return getDestination("pl:" + targetPlayer.getName());
|
||||
}
|
||||
|
||||
if (CANNON_PATTERN.matcher(destinationName).matches()) {
|
||||
return getDestination(parseCannonDest(teleportee, destinationName));
|
||||
}
|
||||
|
||||
return getDestination(destinationName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a cannon destination.
|
||||
*
|
||||
* @param teleportee The player that is going to be teleported.
|
||||
* @param destinationName The destination to parse.
|
||||
* @return A destination string.
|
||||
*/
|
||||
@NotNull
|
||||
private String parseCannonDest(@NotNull Player teleportee,
|
||||
@NotNull String destinationName) {
|
||||
|
||||
String[] cannonSpeed = destinationName.split("-");
|
||||
try {
|
||||
double speed = Double.parseDouble(cannonSpeed[1]);
|
||||
destinationName = "ca:" + teleportee.getWorld().getName() + ":" + teleportee.getLocation().getX()
|
||||
+ "," + teleportee.getLocation().getY() + "," + teleportee.getLocation().getZ() + ":"
|
||||
+ teleportee.getLocation().getPitch() + ":" + teleportee.getLocation().getYaw() + ":" + speed;
|
||||
}
|
||||
catch (Exception e) {
|
||||
destinationName = "i:invalid";
|
||||
}
|
||||
|
||||
return destinationName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a new destination from a string.
|
||||
* Returns a new InvalidDestination if the string could not be parsed.
|
||||
*
|
||||
* @param destination The destination in string format.
|
||||
*
|
||||
* @return A non-null MVDestination
|
||||
*/
|
||||
public MVDestination getDestination(String destination) {
|
||||
String idenChar = "";
|
||||
if (destination.split(":").length > 1) {
|
||||
idenChar = destination.split(":")[0];
|
||||
}
|
||||
|
||||
if (this.destList.containsKey(idenChar)) {
|
||||
Class<? extends MVDestination> myClass = this.destList.get(idenChar);
|
||||
try {
|
||||
MVDestination mydest = myClass.newInstance();
|
||||
if (!mydest.isThisType(this.plugin, destination)) {
|
||||
return new InvalidDestination();
|
||||
}
|
||||
mydest.setDestination(this.plugin, destination);
|
||||
return mydest;
|
||||
} catch (InstantiationException e) {
|
||||
} catch (IllegalAccessException e) {
|
||||
}
|
||||
}
|
||||
return new InvalidDestination();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a {@link MVDestination}.
|
||||
*
|
||||
* @param c The {@link Class} of the {@link MVDestination} to register.
|
||||
* @param identifier The {@link String}-identifier.
|
||||
* @return True if the class was successfully registered.
|
||||
*/
|
||||
public boolean registerDestinationType(Class<? extends MVDestination> c, String identifier) {
|
||||
if (this.destList.containsKey(identifier)) {
|
||||
return false;
|
||||
}
|
||||
this.destList.put(identifier, c);
|
||||
// Special case for world defaults:
|
||||
if (identifier.equals("")) {
|
||||
identifier = "w";
|
||||
}
|
||||
Permission self = this.plugin.getServer().getPluginManager().getPermission("multiverse.teleport.self." + identifier);
|
||||
Permission other = this.plugin.getServer().getPluginManager().getPermission("multiverse.teleport.other." + identifier);
|
||||
PermissionTools pt = new PermissionTools(this.plugin);
|
||||
if (self == null) {
|
||||
self = new Permission("multiverse.teleport.self." + identifier,
|
||||
"Permission to teleport yourself for the " + identifier + " destination.", PermissionDefault.OP);
|
||||
this.plugin.getServer().getPluginManager().addPermission(self);
|
||||
pt.addToParentPerms("multiverse.teleport.self." + identifier);
|
||||
}
|
||||
if (other == null) {
|
||||
other = new Permission("multiverse.teleport.other." + identifier,
|
||||
"Permission to teleport others for the " + identifier + " destination.", PermissionDefault.OP);
|
||||
this.plugin.getServer().getPluginManager().addPermission(other);
|
||||
pt.addToParentPerms("multiverse.teleport.other." + identifier);
|
||||
}
|
||||
this.teleportCommand.addAdditonalPermission(self);
|
||||
this.teleportCommand.addAdditonalPermission(other);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the {@link MVDestination} identifiers registered.
|
||||
*
|
||||
* @return A collection of destination identifiers.
|
||||
*/
|
||||
public Collection<String> getRegisteredIdentifiers() {
|
||||
return this.destList.keySet();
|
||||
}
|
||||
}
|
|
@ -1,263 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.destination;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An exact {@link MVDestination}.
|
||||
*/
|
||||
public class ExactDestination implements MVDestination {
|
||||
private final String coordRegex = "(-?[\\d]+\\.?[\\d]*|~-?[\\d]+\\.?[\\d]*|~),(-?[\\d]+\\.?[\\d]*|~-?[\\d]+\\.?[\\d]*|~),(-?[\\d]+\\.?[\\d]*|~-?[\\d]+\\.?[\\d]*|~)";
|
||||
private boolean isValid;
|
||||
private Location location;
|
||||
private boolean relativeX, relativeY, relativeZ;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "e";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Vector getVelocity() {
|
||||
return new Vector(0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isThisType(JavaPlugin plugin, String destination) {
|
||||
if (!(plugin instanceof MultiverseCore)) {
|
||||
return false;
|
||||
}
|
||||
List<String> parsed = Arrays.asList(destination.split(":"));
|
||||
// Need at least: e:world:x,y,z
|
||||
// OR e:world:x,y,z:pitch:yaw
|
||||
// so basically 3 or 5
|
||||
if (!(parsed.size() == 3 || parsed.size() == 5)) { // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
return false;
|
||||
}
|
||||
// If it's not an Exact type
|
||||
if (!parsed.get(0).equalsIgnoreCase("e")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If it's not a MV world
|
||||
if (!((MultiverseCore) plugin).getMVWorldManager().isMVWorld(parsed.get(1))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parsed.get(2).matches(coordRegex)) {
|
||||
return false;
|
||||
}
|
||||
// This is 1 now, because we've removed 2
|
||||
if (parsed.size() == 3) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
Float.parseFloat(parsed.get(3));
|
||||
Float.parseFloat(parsed.get(4)); // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Location getLocation(Entity e) {
|
||||
Location loc = this.location.clone();
|
||||
if (relativeX || relativeY || relativeZ) {
|
||||
Location eLoc = e.getLocation();
|
||||
loc.add(relativeX ? eLoc.getX() : 0, relativeY ? eLoc.getY() : 0, relativeZ ? eLoc.getZ() : 0);
|
||||
// Since the location is relative, it makes sense to use the entity's pitch and yaw unless those were
|
||||
// specified in the destination.
|
||||
if (loc.getPitch() == 0) {
|
||||
loc.setPitch(eLoc.getPitch());
|
||||
}
|
||||
if (loc.getYaw() == 0) {
|
||||
loc.setYaw(eLoc.getYaw());
|
||||
}
|
||||
}
|
||||
return loc;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return this.isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setDestination(JavaPlugin plugin, String destination) {
|
||||
if (!(plugin instanceof MultiverseCore)) {
|
||||
return;
|
||||
}
|
||||
List<String> parsed = Arrays.asList(destination.split(":"));
|
||||
// Need at least: e:world:x,y,z
|
||||
// OR e:world:x,y,z:pitch:yaw
|
||||
// so basically 3 or 5
|
||||
if (!(parsed.size() == 3 || parsed.size() == 5)) { // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!parsed.get(0).equalsIgnoreCase(this.getIdentifier())) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!((MultiverseCore) plugin).getMVWorldManager().isMVWorld(parsed.get(1))) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
this.location = new Location(((MultiverseCore) plugin).getMVWorldManager().getMVWorld(parsed.get(1)).getCBWorld(), 0, 0, 0);
|
||||
|
||||
if (!parsed.get(2).matches(this.coordRegex)) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
double[] coords = new double[3];
|
||||
String[] coordString = parsed.get(2).split(",");
|
||||
for (int i = 0; i < 3; i++) {
|
||||
String[] relSplit = coordString[i].split("~");
|
||||
boolean relative = false;
|
||||
if (relSplit.length == 0) {
|
||||
// coord is "~" form
|
||||
relative = true;
|
||||
coords[i] = 0;
|
||||
} else if (relSplit.length == 1) {
|
||||
// coord is "123" form
|
||||
try {
|
||||
coords[i] = Double.parseDouble(relSplit[0]);
|
||||
} catch (NumberFormatException e) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// coord is "~123" form
|
||||
relative = true;
|
||||
try {
|
||||
coords[i] = Double.parseDouble(relSplit[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (relative) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
relativeX = true;
|
||||
break;
|
||||
case 1:
|
||||
relativeY = true;
|
||||
break;
|
||||
case 2:
|
||||
relativeZ = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.location.setX(coords[0]);
|
||||
this.location.setY(coords[1]);
|
||||
this.location.setZ(coords[2]);
|
||||
|
||||
if (parsed.size() == 3) {
|
||||
this.isValid = true;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
this.location.setPitch(Float.parseFloat(parsed.get(3)));
|
||||
this.location.setYaw(Float.parseFloat(parsed.get(4))); // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
} catch (NumberFormatException e) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
this.isValid = true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getType() {
|
||||
return "Exact";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Exact (" + this.location.getX() + ", " + this.location.getY() + ", " + this.location.getZ()
|
||||
+ ":" + location.getPitch() + ":" + location.getYaw() + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this {@link ExactDestination}.
|
||||
*
|
||||
* @param location The {@link Location}.
|
||||
*/
|
||||
public void setDestination(Location location) {
|
||||
this.isValid = (this.location = location) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
if (isValid) {
|
||||
return "e:" + location.getWorld().getName() + ":" + location.getX() + "," + location.getY()
|
||||
+ "," + location.getZ() + ":" + location.getPitch() + ":" + location.getYaw();
|
||||
}
|
||||
return "i:Invalid Destination";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getRequiredPermission() {
|
||||
return "multiverse.access." + this.location.getWorld().getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean useSafeTeleporter() {
|
||||
// This is an EXACT destination, don't safely teleport here.
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,107 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.destination;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
/**
|
||||
* An invalid {@link MVDestination}.
|
||||
*/
|
||||
public class InvalidDestination implements MVDestination {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "i";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isThisType(JavaPlugin plugin, String destination) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Location getLocation(Entity e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setDestination(JavaPlugin plugin, String destination) {
|
||||
// Nothing needed, it's invalid.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getType() {
|
||||
return ChatColor.RED + "Invalid Destination";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return ChatColor.RED + "Invalid Destination";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "i:Invalid Destination";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getRequiredPermission() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Vector getVelocity() {
|
||||
return new Vector(0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean useSafeTeleporter() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,137 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.destination;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
/**
|
||||
* A player-{@link MVDestination}.
|
||||
*/
|
||||
public class PlayerDestination implements MVDestination {
|
||||
private String player;
|
||||
private boolean isValid;
|
||||
private JavaPlugin plugin;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "pl";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isThisType(JavaPlugin plugin, String destination) {
|
||||
String[] items = destination.split(":");
|
||||
if (items.length != 2) {
|
||||
return false;
|
||||
}
|
||||
if (!items[0].equalsIgnoreCase("pl")) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Location getLocation(Entity e) {
|
||||
Player p = plugin.getServer().getPlayerExact(this.player);
|
||||
Player plLoc = null;
|
||||
if (e instanceof Player) {
|
||||
plLoc = (Player) e;
|
||||
} else if (e.getPassenger() instanceof Player) {
|
||||
plLoc = (Player) e.getPassenger();
|
||||
}
|
||||
|
||||
if (p != null && plLoc != null) {
|
||||
return p.getLocation();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return this.isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setDestination(JavaPlugin plugin, String destination) {
|
||||
String[] items = destination.split(":");
|
||||
if (items.length != 2) {
|
||||
this.isValid = false;
|
||||
}
|
||||
if (!items[0].equalsIgnoreCase("pl")) {
|
||||
this.isValid = false;
|
||||
}
|
||||
this.isValid = true;
|
||||
this.player = items[1];
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getType() {
|
||||
return "Player";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "pl:" + this.player;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getRequiredPermission() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Vector getVelocity() {
|
||||
return new Vector(0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean useSafeTeleporter() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,173 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.destination;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.Core;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
/**
|
||||
* A world-{@link MVDestination}.
|
||||
*/
|
||||
public class WorldDestination implements MVDestination {
|
||||
private boolean isValid;
|
||||
private MultiverseWorld world;
|
||||
private float yaw = -1;
|
||||
private String direction = "";
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "w";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isThisType(JavaPlugin plugin, String destination) {
|
||||
String[] items = destination.split(":");
|
||||
if (items.length > 3) {
|
||||
return false;
|
||||
}
|
||||
if (items.length == 1 && ((MultiverseCore) plugin).getMVWorldManager().isMVWorld(items[0])) {
|
||||
// This case is: world
|
||||
return true;
|
||||
}
|
||||
if (items.length == 2 && ((MultiverseCore) plugin).getMVWorldManager().isMVWorld(items[0])) {
|
||||
// This case is: world:n
|
||||
return true;
|
||||
} else if (items[0].equalsIgnoreCase("w") && ((MultiverseCore) plugin).getMVWorldManager().isMVWorld(items[1])) {
|
||||
// This case is: w:world
|
||||
// and w:world:ne
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Location getLocation(Entity e) {
|
||||
Location spawnLoc = getAcurateSpawnLocation(e, this.world);
|
||||
if (this.yaw >= 0) {
|
||||
// Only modify the yaw if its set.
|
||||
spawnLoc.setYaw(this.yaw);
|
||||
}
|
||||
return spawnLoc;
|
||||
}
|
||||
|
||||
private static Location getAcurateSpawnLocation(Entity e, MultiverseWorld world) {
|
||||
if (world != null) {
|
||||
return world.getSpawnLocation();
|
||||
} else {
|
||||
// add 0.5 to x and z to center people
|
||||
// (spawn location is stored as int meaning that you would spawn in the corner of a block)
|
||||
return e.getWorld().getSpawnLocation().add(.5, 0, .5);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return this.isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setDestination(JavaPlugin plugin, String destination) {
|
||||
// TODO Taking a JavaPlugin here is rather useless, if we keep casting it up to MultiverseCore.
|
||||
// We should change that.
|
||||
Core core = (Core) plugin;
|
||||
String[] items = destination.split(":");
|
||||
if (items.length > 3) {
|
||||
isValid = false;
|
||||
return;
|
||||
}
|
||||
if (items.length == 1 && ((MultiverseCore) plugin).getMVWorldManager().isMVWorld(items[0])) {
|
||||
isValid = true;
|
||||
this.world = core.getMVWorldManager().getMVWorld(items[0]);
|
||||
return;
|
||||
}
|
||||
if (items.length == 2 && ((MultiverseCore) plugin).getMVWorldManager().isMVWorld(items[0])) {
|
||||
this.world = core.getMVWorldManager().getMVWorld(items[0]);
|
||||
this.yaw = core.getLocationManipulation().getYaw(items[1]);
|
||||
return;
|
||||
}
|
||||
if (items[0].equalsIgnoreCase("w") && ((MultiverseCore) plugin).getMVWorldManager().isMVWorld(items[1])) {
|
||||
this.world = ((MultiverseCore) plugin).getMVWorldManager().getMVWorld(items[1]);
|
||||
isValid = true;
|
||||
if (items.length == 3) {
|
||||
this.yaw = core.getLocationManipulation().getYaw(items[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getType() {
|
||||
return "World";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.world.getColoredWorldString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (direction.length() > 0 && yaw >= 0) {
|
||||
return this.world.getCBWorld().getName() + ":" + this.direction;
|
||||
}
|
||||
return this.world.getCBWorld().getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getRequiredPermission() {
|
||||
// TODO: Potenitally replace spaces wiht tabs for friendlier yaml.
|
||||
// this.world.getName().replace(" ","_");
|
||||
return "multiverse.access." + this.world.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Vector getVelocity() {
|
||||
return new Vector(0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean useSafeTeleporter() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore.display;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Helper class to switch between 2 {@link ChatColor}.
|
||||
*/
|
||||
public class ColorAlternator implements ColorTool {
|
||||
|
||||
/**
|
||||
* Creates a new {@link ColorAlternator} with 2 {@link ChatColor}s.
|
||||
*
|
||||
* @param colorThis The first color.
|
||||
* @param colorThat The second color.
|
||||
* @return The {@link ColorAlternator} created for you.
|
||||
*/
|
||||
public static ColorAlternator with(@NotNull ChatColor colorThis,
|
||||
@NotNull ChatColor colorThat) {
|
||||
|
||||
return new ColorAlternator(colorThis, colorThat);
|
||||
}
|
||||
|
||||
private boolean switcher;
|
||||
private final ChatColor thisColor;
|
||||
private final ChatColor thatColor;
|
||||
|
||||
/**
|
||||
* @param colorThis The first color.
|
||||
* @param colorThat The second color.
|
||||
*/
|
||||
public ColorAlternator(@NotNull ChatColor colorThis,
|
||||
@NotNull ChatColor colorThat) {
|
||||
|
||||
this.thisColor = colorThis;
|
||||
this.thatColor = colorThat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the color. Everytime this method is called, it swaps the color that it returns.
|
||||
*
|
||||
* @return The color.
|
||||
*/
|
||||
@Override
|
||||
public ChatColor get() {
|
||||
return (this.switcher ^= true) ? this.thisColor : this.thatColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The first color.
|
||||
*/
|
||||
public ChatColor getThisColor() {
|
||||
return thisColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The second color.
|
||||
*/
|
||||
public ChatColor getThatColor() {
|
||||
return thatColor;
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore.display;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
/**
|
||||
* Tools to allow customisation.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ColorTool {
|
||||
|
||||
/**
|
||||
* Gets a chat color.
|
||||
*
|
||||
* @return The color.
|
||||
*/
|
||||
ChatColor get();
|
||||
|
||||
/**
|
||||
* Default implementation of this interface. Returns a default white color.
|
||||
*/
|
||||
ColorTool DEFAULT = () -> ChatColor.WHITE;
|
||||
}
|
|
@ -1,268 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore.display;
|
||||
|
||||
import com.onarandombox.MultiverseCore.display.settings.DisplaySetting;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
/**
|
||||
* Helps to display contents such as list and maps in a nicely formatted fashion.
|
||||
*
|
||||
* @param <T> Type of content to display.
|
||||
*/
|
||||
public class ContentDisplay<T> {
|
||||
|
||||
public static final String LINE_BREAK = "%br%";
|
||||
|
||||
/**
|
||||
* Creates a ContentDisplay.Builder for the given content.
|
||||
*
|
||||
* @param content The content to be displayed.
|
||||
* @param <T> The type of the content which can be inferred.
|
||||
* @return A new Builder.
|
||||
*/
|
||||
public static <T> Builder<T> forContent(T content) {
|
||||
return new Builder<>(content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a ContentDisplay.Builder for the given collection of content.
|
||||
*
|
||||
* @param content The content to be displayed.
|
||||
* @return A new Builder.
|
||||
*/
|
||||
public static Builder<Collection<String>> forContent(Collection<String> content) {
|
||||
return new Builder<>(content).displayHandler(DisplayHandlers.LIST);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a ContentDisplay.Builder for the given map of content.
|
||||
*
|
||||
* @param content The content to be displayed.
|
||||
* @return A new Builder.
|
||||
*/
|
||||
public static Builder<Map<String, Object>> forContent(Map<String, Object> content) {
|
||||
return new Builder<>(content).displayHandler(DisplayHandlers.INLINE_MAP);
|
||||
}
|
||||
|
||||
private final T contents;
|
||||
|
||||
private String header;
|
||||
private String emptyMessage = "No matching content to display.";
|
||||
private DisplayHandler<T> displayHandler;
|
||||
private ColorTool colorTool = ColorTool.DEFAULT;
|
||||
private ContentFilter filter = ContentFilter.DEFAULT;
|
||||
private final Map<DisplaySetting<?>, Object> settingsMap = new WeakHashMap<>();
|
||||
|
||||
private ContentDisplay(T contents) {
|
||||
this.contents = contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do the actual displaying of contents to the sender.
|
||||
*
|
||||
* @param sender The CommandSender to show the display to.
|
||||
*/
|
||||
public void show(@NotNull CommandSender sender) {
|
||||
Collection<String> formattedContent;
|
||||
try {
|
||||
formattedContent = (this.contents == null) ? null : this.displayHandler.format(sender, this);
|
||||
} catch (DisplayFormatException e) {
|
||||
sender.sendMessage(String.format("%sError: %s", ChatColor.RED, e.getMessage()));
|
||||
return;
|
||||
}
|
||||
this.displayHandler.sendHeader(sender, this);
|
||||
this.displayHandler.sendSubHeader(sender, this);
|
||||
this.displayHandler.sendBody(sender, this, formattedContent);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Gets the header to display.
|
||||
*/
|
||||
public String getHeader() {
|
||||
return header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the header text.
|
||||
*/
|
||||
public void setHeader(@NotNull String header) {
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Gets the contents to display.
|
||||
*/
|
||||
public T getContents() {
|
||||
return contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Gets the message to display when no content is shown.
|
||||
*/
|
||||
@NotNull
|
||||
public String getEmptyMessage() {
|
||||
return emptyMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Gets the display handler that formats and sends content to sender.
|
||||
*/
|
||||
@NotNull
|
||||
public DisplayHandler<T> getDisplayHandler() {
|
||||
return displayHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Gets the color tool used.
|
||||
*/
|
||||
@NotNull
|
||||
public ColorTool getColorTool() {
|
||||
return colorTool;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Gets the filter used.
|
||||
*/
|
||||
@NotNull
|
||||
public ContentFilter getFilter() {
|
||||
return filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value for a given setting option.
|
||||
*
|
||||
* @param setting The setting option.
|
||||
* @param <S> The setting type.
|
||||
* @return Value set for the given setting.
|
||||
*/
|
||||
public <S> S getSetting(@NotNull DisplaySetting<S> setting) {
|
||||
return (S) settingsMap.getOrDefault(setting, setting.defaultValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets other specific settings that may be used by the {@link DisplayHandler}.
|
||||
*
|
||||
* @param setting The settings option.
|
||||
* @param value The value to set.
|
||||
* @param <S> The type of setting.
|
||||
*/
|
||||
public <S> void setSetting(@NotNull DisplaySetting<S> setting, S value) {
|
||||
this.settingsMap.put(setting, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a {@link ContentDisplay}.
|
||||
*
|
||||
* @param <T> Type of content to display.
|
||||
*/
|
||||
public static class Builder<T> {
|
||||
|
||||
private final ContentDisplay<T> display;
|
||||
|
||||
private Builder(T content) {
|
||||
this.display = new ContentDisplay<>(content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets header to be displayed.
|
||||
*
|
||||
* @param header The header text.
|
||||
* @param replacements String formatting replacements.
|
||||
* @return The builder.
|
||||
*/
|
||||
@NotNull
|
||||
public Builder<T> header(@NotNull String header, Object...replacements) {
|
||||
this.display.header = String.format(header, replacements);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the message to show when no content is available for display.
|
||||
*
|
||||
* @param emptyMessage The message text.
|
||||
* @param replacements String formatting replacements.
|
||||
* @return The builder.
|
||||
*/
|
||||
@NotNull
|
||||
public Builder<T> emptyMessage(@NotNull String emptyMessage, Object...replacements) {
|
||||
this.display.emptyMessage = String.format(emptyMessage, replacements);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the display handler that does the formatting and sending of content. <b>Required.</b>
|
||||
*
|
||||
* @param displayHandler The display handler for the given content type.
|
||||
* @return The builder.
|
||||
*/
|
||||
@NotNull
|
||||
public Builder<T> displayHandler(@NotNull DisplayHandler<T> displayHandler) {
|
||||
this.display.displayHandler = displayHandler;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color tool used to make messages more colourful.
|
||||
*
|
||||
* @param colorTool The color tool to use.
|
||||
* @return The builder.
|
||||
*/
|
||||
@NotNull
|
||||
public Builder<T> colorTool(@NotNull ColorTool colorTool) {
|
||||
this.display.colorTool = colorTool;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets content filter used to match specific content to be displayed.
|
||||
*
|
||||
* @param filter The filter to use.
|
||||
* @return The builder.
|
||||
*/
|
||||
@NotNull
|
||||
public Builder<T> filter(@NotNull ContentFilter filter) {
|
||||
this.display.filter = filter;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets other specific settings that may be used by the {@link DisplayHandler}.
|
||||
*
|
||||
* @param setting The settings option.
|
||||
* @param value The value to set.
|
||||
* @param <S> The type of setting.
|
||||
* @return The builder.
|
||||
*/
|
||||
@NotNull
|
||||
public <S> Builder<T> setting(@NotNull DisplaySetting<S> setting, S value) {
|
||||
this.display.settingsMap.put(setting, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates and build the content display.
|
||||
*
|
||||
* @return The content display.
|
||||
*/
|
||||
@NotNull
|
||||
public ContentDisplay<T> build() {
|
||||
Objects.requireNonNull(this.display.displayHandler);
|
||||
return this.display;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build and show the content to the sender.
|
||||
*
|
||||
* @param sender The CommandSender to show the display to.
|
||||
*/
|
||||
public void show(CommandSender sender) {
|
||||
this.build().show(sender);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,153 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore.display;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
/**
|
||||
* <p>Filter content and text based on regex matching.</p>
|
||||
*
|
||||
* <p>Compile regex pattern based on {@link ContentFilter#filterString}. When prefixed with 'r=',
|
||||
* use {@link ContentFilter#filterString} as the full regex pattern. Else, set to any match that
|
||||
* contains the {@link ContentFilter#filterString}.<p>
|
||||
*/
|
||||
public class ContentFilter {
|
||||
|
||||
public static final ContentFilter DEFAULT = new ContentFilter();
|
||||
private static final Pattern REGEX_SPECIAL_CHARS = Pattern.compile("[.+*?\\[^\\]$(){}=!<>|:-\\\\]");
|
||||
|
||||
private String filterString;
|
||||
private Pattern filterPattern;
|
||||
private boolean exactMatch;
|
||||
|
||||
private ContentFilter() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param filterString The text to do matching, either plaintext or regex.
|
||||
*/
|
||||
public ContentFilter(@NotNull String filterString) {
|
||||
this(filterString, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param filterString The text to do matching, else plaintext or regex.
|
||||
* @param exactMatch Should check for exact match when doing regex matching.
|
||||
*/
|
||||
public ContentFilter(@NotNull String filterString,
|
||||
boolean exactMatch) {
|
||||
|
||||
this.filterString = filterString;
|
||||
this.exactMatch = exactMatch;
|
||||
parseFilter();
|
||||
}
|
||||
|
||||
private void parseFilter() {
|
||||
if (filterString == null) {
|
||||
return;
|
||||
}
|
||||
if (filterString.startsWith("r=")) {
|
||||
convertToMatcher(filterString.substring(2));
|
||||
return;
|
||||
}
|
||||
String cleanedFilter = REGEX_SPECIAL_CHARS.matcher(filterString.toLowerCase()).replaceAll("\\\\$0");
|
||||
convertToMatcher("(?i).*" + cleanedFilter + ".*");
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile and store the regex into a {@link Pattern}.
|
||||
*
|
||||
* @param regex The regex text.
|
||||
*/
|
||||
private void convertToMatcher(@NotNull String regex) {
|
||||
try {
|
||||
this.filterPattern = Pattern.compile(regex);
|
||||
Logging.finest("Parsed regex pattern: %s", this.filterPattern.toString());
|
||||
}
|
||||
catch (PatternSyntaxException ignored) {
|
||||
Logging.warning("Error parsing regex: %s", filterString);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Do regex matching.
|
||||
*
|
||||
* @param text String to check regex on.
|
||||
* @return True of matches regex pattern, false otherwise.
|
||||
*/
|
||||
public boolean checkMatch(@Nullable Object text) {
|
||||
if (!hasFilter()) {
|
||||
return true;
|
||||
}
|
||||
if (text == null || !hasValidPattern()) {
|
||||
return false;
|
||||
}
|
||||
text = ChatColor.stripColor(String.valueOf(text));
|
||||
return (exactMatch)
|
||||
? filterPattern.matcher((CharSequence) text).matches()
|
||||
: filterPattern.matcher((CharSequence) text).find();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a filter string is present.
|
||||
*
|
||||
* @return True if there is a filter string, else false.
|
||||
*/
|
||||
public boolean hasFilter() {
|
||||
return filterString != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if regex pattern syntax is valid.
|
||||
*
|
||||
* @return True if valid, else false.
|
||||
*/
|
||||
public boolean hasValidPattern() {
|
||||
return filterPattern != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The filter string.
|
||||
*/
|
||||
@Nullable
|
||||
public String getString() {
|
||||
return filterString;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The regex pattern.
|
||||
*/
|
||||
@Nullable
|
||||
public Pattern getPattern() {
|
||||
return filterPattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return True if filter is set to do exact matching, else false.
|
||||
*/
|
||||
public boolean isExactMatch() {
|
||||
return exactMatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Nicely format the filter string to be used for showing the sender.
|
||||
*
|
||||
* @return The formatted filter string.
|
||||
*/
|
||||
public @NotNull String getFormattedString() {
|
||||
return String.format("%sFilter: '%s'", ChatColor.ITALIC, filterString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ContentFilter{" +
|
||||
"filterString='" + filterString + '\'' +
|
||||
", filterPattern=" + filterPattern +
|
||||
", exactMatch=" + exactMatch +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore.display;
|
||||
|
||||
/**
|
||||
* Thrown when an issue occur while formatting content.
|
||||
*/
|
||||
public class DisplayFormatException extends Exception {
|
||||
public DisplayFormatException() {
|
||||
}
|
||||
|
||||
public DisplayFormatException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public DisplayFormatException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public DisplayFormatException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public DisplayFormatException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore.display;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Handles the formatting and sending of all content by the {@link ContentDisplay}.
|
||||
*
|
||||
* @param <T> Type of content to display.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface DisplayHandler<T> {
|
||||
|
||||
/**
|
||||
* Formats the raw content into a {@link Collection} for displaying to the given sender.
|
||||
*
|
||||
* @param sender The {@link CommandSender} who will the content will be displayed to.
|
||||
* @param display The responsible {@link ContentDisplay}.
|
||||
* @return The formatted content.
|
||||
* @throws DisplayFormatException Issue occurred while formatting content. E.g. invalid page.
|
||||
*/
|
||||
Collection<String> format(@NotNull CommandSender sender, @NotNull ContentDisplay<T> display)
|
||||
throws DisplayFormatException;
|
||||
|
||||
/**
|
||||
* Sends the header.
|
||||
*
|
||||
* @param sender The {@link CommandSender} who will the header will be displayed to.
|
||||
* @param display The responsible {@link ContentDisplay}.
|
||||
*/
|
||||
default void sendHeader(@NotNull CommandSender sender, @NotNull ContentDisplay<T> display) {
|
||||
if (!Strings.isNullOrEmpty(display.getHeader())) {
|
||||
sender.sendMessage(display.getHeader());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends info such as filter and page.
|
||||
*
|
||||
* @param sender The {@link CommandSender} who will the sub header will be displayed to.
|
||||
* @param display The responsible {@link ContentDisplay}.
|
||||
*/
|
||||
default void sendSubHeader(@NotNull CommandSender sender, @NotNull ContentDisplay<T> display) {
|
||||
if (display.getFilter().hasFilter()) {
|
||||
sender.sendMessage(String.format("%s[ %s ]", ChatColor.GRAY, display.getFilter().getFormattedString()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the content.
|
||||
*
|
||||
* @param sender The {@link CommandSender} who will the body will be displayed to.
|
||||
* @param display The responsible {@link ContentDisplay}.
|
||||
* @param formattedContent The content after being formatted by {@link #format(CommandSender, ContentDisplay)}
|
||||
*/
|
||||
default void sendBody(@NotNull CommandSender sender, @NotNull ContentDisplay<T> display,
|
||||
Collection<String> formattedContent) {
|
||||
if (formattedContent == null || formattedContent.size() == 0) {
|
||||
sender.sendMessage(display.getEmptyMessage());
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(formattedContent.toArray(new String[0]));
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore.display;
|
||||
|
||||
import com.onarandombox.MultiverseCore.display.handlers.InlineListDisplayHandler;
|
||||
import com.onarandombox.MultiverseCore.display.handlers.InlineMapDisplayHandler;
|
||||
import com.onarandombox.MultiverseCore.display.handlers.ListDisplayHandler;
|
||||
import com.onarandombox.MultiverseCore.display.handlers.PagedListDisplayHandler;
|
||||
import com.onarandombox.MultiverseCore.display.settings.InlineDisplaySettings;
|
||||
import com.onarandombox.MultiverseCore.display.settings.PagedDisplaySettings;
|
||||
import com.onarandombox.MultiverseCore.display.settings.MapDisplaySettings;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Various implementations of {@link DisplayHandler}.
|
||||
*/
|
||||
public class DisplayHandlers {
|
||||
|
||||
/**
|
||||
* Standard list display.
|
||||
*
|
||||
* Supported settings: none.
|
||||
*/
|
||||
public static final DisplayHandler<Collection<String>> LIST = new ListDisplayHandler();
|
||||
|
||||
/**
|
||||
* List display with paging.
|
||||
*
|
||||
* Supported settings: {@link PagedDisplaySettings#SHOW_PAGE}, {@link PagedDisplaySettings#LINES_PER_PAGE},
|
||||
* {@link PagedDisplaySettings#PAGE_IN_CONSOLE}, {@link PagedDisplaySettings#DO_END_PADDING}.
|
||||
*/
|
||||
public static final DisplayHandler<Collection<String>> PAGE_LIST = new PagedListDisplayHandler();
|
||||
|
||||
/**
|
||||
* Display a list inline.
|
||||
*
|
||||
* Supported settings: {@link InlineDisplaySettings#SEPARATOR}.
|
||||
*/
|
||||
public static final DisplayHandler<Collection<String>> INLINE_LIST = new InlineListDisplayHandler();
|
||||
|
||||
/**
|
||||
* Display key value pair inline.
|
||||
*
|
||||
* Supported settings: {@link InlineDisplaySettings#SEPARATOR}, {@link MapDisplaySettings#OPERATOR}.
|
||||
*/
|
||||
public static final DisplayHandler<Map<String, Object>> INLINE_MAP = new InlineMapDisplayHandler();
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore.display.handlers;
|
||||
|
||||
import com.onarandombox.MultiverseCore.display.ContentDisplay;
|
||||
import com.onarandombox.MultiverseCore.display.DisplayFormatException;
|
||||
import com.onarandombox.MultiverseCore.display.DisplayHandler;
|
||||
import com.onarandombox.MultiverseCore.display.settings.InlineDisplaySettings;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class InlineListDisplayHandler implements DisplayHandler<Collection<String>> {
|
||||
|
||||
@Override
|
||||
public Collection<String> format(@NotNull CommandSender sender, @NotNull ContentDisplay<Collection<String>> display)
|
||||
throws DisplayFormatException {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
String separator = display.getSetting(InlineDisplaySettings.SEPARATOR);
|
||||
|
||||
for (Iterator<String> iterator = display.getContents().iterator(); iterator.hasNext(); ) {
|
||||
String content = iterator.next();
|
||||
if (!display.getFilter().checkMatch(content)) {
|
||||
continue;
|
||||
}
|
||||
builder.append(display.getColorTool().get()).append(content);
|
||||
if (iterator.hasNext()) {
|
||||
builder.append(separator);
|
||||
}
|
||||
}
|
||||
return (builder.length() == 0)
|
||||
? Collections.singletonList(display.getEmptyMessage())
|
||||
: Collections.singleton(builder.toString());
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore.display.handlers;
|
||||
|
||||
import com.onarandombox.MultiverseCore.display.ContentDisplay;
|
||||
import com.onarandombox.MultiverseCore.display.DisplayFormatException;
|
||||
import com.onarandombox.MultiverseCore.display.DisplayHandler;
|
||||
import com.onarandombox.MultiverseCore.display.settings.InlineDisplaySettings;
|
||||
import com.onarandombox.MultiverseCore.display.settings.MapDisplaySettings;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
public class InlineMapDisplayHandler implements DisplayHandler<Map<String, Object>> {
|
||||
|
||||
@Override
|
||||
public Collection<String> format(@NotNull CommandSender sender,
|
||||
@NotNull ContentDisplay<Map<String, Object>> display)
|
||||
throws DisplayFormatException {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
String separator = display.getSetting(InlineDisplaySettings.SEPARATOR);
|
||||
String operator = display.getSetting(MapDisplaySettings.OPERATOR);
|
||||
|
||||
for (Iterator<Map.Entry<String, Object>> iterator = display.getContents().entrySet().iterator(); iterator.hasNext(); ) {
|
||||
Map.Entry<String, Object> entry = iterator.next();
|
||||
if (!display.getFilter().checkMatch(entry.getKey()) && !display.getFilter().checkMatch(entry.getValue())) {
|
||||
continue;
|
||||
}
|
||||
builder.append(display.getColorTool().get())
|
||||
.append(entry.getKey())
|
||||
.append(operator)
|
||||
.append(display.getColorTool().get())
|
||||
.append(entry.getValue());
|
||||
if (iterator.hasNext()) {
|
||||
builder.append(separator);
|
||||
}
|
||||
}
|
||||
return (builder.length() == 0)
|
||||
? Collections.singletonList(display.getEmptyMessage())
|
||||
: Collections.singleton(builder.toString());
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore.display.handlers;
|
||||
|
||||
import com.onarandombox.MultiverseCore.display.ContentDisplay;
|
||||
import com.onarandombox.MultiverseCore.display.DisplayFormatException;
|
||||
import com.onarandombox.MultiverseCore.display.DisplayHandler;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ListDisplayHandler implements DisplayHandler<Collection<String>> {
|
||||
|
||||
@Override
|
||||
public Collection<String> format(@NotNull CommandSender sender, @NotNull ContentDisplay<Collection<String>> display)
|
||||
throws DisplayFormatException {
|
||||
return display.getContents().stream()
|
||||
.filter(display.getFilter()::checkMatch)
|
||||
.map(s -> (ContentDisplay.LINE_BREAK.equals(s)) ? "" : display.getColorTool().get() + s)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore.display.handlers;
|
||||
|
||||
import com.onarandombox.MultiverseCore.display.ContentDisplay;
|
||||
import com.onarandombox.MultiverseCore.display.DisplayFormatException;
|
||||
import com.onarandombox.MultiverseCore.display.settings.PagedDisplaySettings;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class PagedListDisplayHandler extends ListDisplayHandler {
|
||||
|
||||
@Override
|
||||
public Collection<String> format(@NotNull CommandSender sender, @NotNull ContentDisplay<Collection<String>> display)
|
||||
throws DisplayFormatException {
|
||||
if (dontNeedPaging(sender, display)) {
|
||||
return super.format(sender, display);
|
||||
}
|
||||
|
||||
int pages = 1;
|
||||
int currentLength = 0;
|
||||
int targetPage = display.getSetting(PagedDisplaySettings.SHOW_PAGE);
|
||||
int linesPerPage = display.getSetting(PagedDisplaySettings.LINES_PER_PAGE);
|
||||
List<String> content = new ArrayList<>(linesPerPage);
|
||||
|
||||
// Calculate the paging.
|
||||
for (String line : display.getContents()) {
|
||||
if (!display.getFilter().checkMatch(line)) {
|
||||
continue;
|
||||
}
|
||||
// When it's the next page.
|
||||
boolean isLineBreak = ContentDisplay.LINE_BREAK.equals(line);
|
||||
if (isLineBreak || ++currentLength > linesPerPage) {
|
||||
pages++;
|
||||
currentLength = 0;
|
||||
if (isLineBreak) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (pages == targetPage) {
|
||||
// Let first line be the header when no header is defined.
|
||||
if (display.getHeader() == null) {
|
||||
display.setHeader(line);
|
||||
currentLength--;
|
||||
continue;
|
||||
}
|
||||
content.add(display.getColorTool().get() + line);
|
||||
}
|
||||
}
|
||||
|
||||
// Page out of range.
|
||||
if (targetPage < 1 || targetPage > pages) {
|
||||
if (pages == 1) {
|
||||
throw new DisplayFormatException("There is only 1 page!");
|
||||
}
|
||||
throw new DisplayFormatException("Please enter a page from 1 to " + pages + ".");
|
||||
}
|
||||
|
||||
// No content
|
||||
if (content.size() == 0) {
|
||||
content.add(display.getEmptyMessage());
|
||||
}
|
||||
|
||||
// Add empty lines to make output length consistent.
|
||||
if (display.getSetting(PagedDisplaySettings.DO_END_PADDING)) {
|
||||
IntStream.range(0, linesPerPage - content.size()).forEach(i -> content.add(""));
|
||||
}
|
||||
display.setSetting(PagedDisplaySettings.TOTAL_PAGE, pages);
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendSubHeader(@NotNull CommandSender sender, @NotNull ContentDisplay<Collection<String>> display) {
|
||||
if (dontNeedPaging(sender, display)) {
|
||||
super.sendSubHeader(sender, display);
|
||||
return;
|
||||
}
|
||||
|
||||
if (display.getFilter().hasFilter()) {
|
||||
sender.sendMessage(String.format("%s[ Page %s of %s, %s ]",
|
||||
ChatColor.GRAY,
|
||||
display.getSetting(PagedDisplaySettings.SHOW_PAGE),
|
||||
display.getSetting(PagedDisplaySettings.TOTAL_PAGE),
|
||||
display.getFilter().getFormattedString())
|
||||
);
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(String.format("%s[ Page %s of %s ]",
|
||||
ChatColor.GRAY,
|
||||
display.getSetting(PagedDisplaySettings.SHOW_PAGE),
|
||||
display.getSetting(PagedDisplaySettings.TOTAL_PAGE))
|
||||
);
|
||||
}
|
||||
|
||||
private boolean dontNeedPaging(CommandSender sender, ContentDisplay<Collection<String>> display) {
|
||||
return sender instanceof ConsoleCommandSender
|
||||
&& !display.getSetting(PagedDisplaySettings.PAGE_IN_CONSOLE);
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore.display.settings;
|
||||
|
||||
import com.onarandombox.MultiverseCore.display.DisplayHandler;
|
||||
|
||||
/**
|
||||
* Represents a setting option that can be used by {@link DisplayHandler}.
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface DisplaySetting<T> {
|
||||
|
||||
/**
|
||||
* Gets the default value of this Display Setting.
|
||||
*
|
||||
* @return The default value.
|
||||
*/
|
||||
T defaultValue();
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore.display.settings;
|
||||
|
||||
import com.onarandombox.MultiverseCore.display.DisplayHandler;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
/**
|
||||
* Collection of {@link DisplaySetting} that are used by various {@link DisplayHandler}.
|
||||
*/
|
||||
public class InlineDisplaySettings {
|
||||
|
||||
/**
|
||||
* Inline separator. E.g. '1, 2, 3'
|
||||
*/
|
||||
public static final DisplaySetting<String> SEPARATOR = () -> ChatColor.WHITE + ", ";
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore.display.settings;
|
||||
|
||||
import com.onarandombox.MultiverseCore.display.DisplayHandler;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
/**
|
||||
* Collection of {@link DisplaySetting} that are used by various {@link DisplayHandler}.
|
||||
*/
|
||||
public class MapDisplaySettings {
|
||||
|
||||
/**
|
||||
* The thing between a key value pair. E.g. 'Me = Smart'
|
||||
*/
|
||||
public static final DisplaySetting<String> OPERATOR = () -> ChatColor.WHITE + " = ";
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore.display.settings;
|
||||
|
||||
public class PagedDisplaySettings {
|
||||
|
||||
/**
|
||||
* Page to display.
|
||||
*/
|
||||
public static final DisplaySetting<Integer> SHOW_PAGE = () -> 1;
|
||||
|
||||
/**
|
||||
* Total pages available to display.
|
||||
*/
|
||||
public static final DisplaySetting<Integer> TOTAL_PAGE = () -> 1;
|
||||
|
||||
/**
|
||||
* The max number of lines per page. This excludes header.
|
||||
*/
|
||||
public static final DisplaySetting<Integer> LINES_PER_PAGE = () -> 8;
|
||||
|
||||
/**
|
||||
* Should add empty lines if content lines shown is less that {@link #LINES_PER_PAGE}.
|
||||
*/
|
||||
public static final DisplaySetting<Boolean> DO_END_PADDING = () -> true;
|
||||
|
||||
/**
|
||||
* Should display with paging when it's sent to console.
|
||||
*/
|
||||
public static final DisplaySetting<Boolean> PAGE_IN_CONSOLE = () -> false;
|
||||
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.enums;
|
||||
|
||||
/**
|
||||
* A enum containing all actions that can be used to modify world-properties.
|
||||
*/
|
||||
public enum Action {
|
||||
/**
|
||||
* Setting a property.
|
||||
*/
|
||||
Set,
|
||||
/**
|
||||
* Adding something to a list-property.
|
||||
*/
|
||||
Add,
|
||||
/**
|
||||
* Removing something from a list-property.
|
||||
*/
|
||||
Remove,
|
||||
/**
|
||||
* Clearing a list-property.
|
||||
*/
|
||||
Clear
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.enums;
|
||||
|
||||
/**
|
||||
* An enum containing all list-properties.
|
||||
*/
|
||||
public enum AddProperties {
|
||||
/**
|
||||
* Worlds that people cannot go to from a world.
|
||||
*/
|
||||
worldblacklist,
|
||||
/**
|
||||
* Animal-exceptions.
|
||||
*/
|
||||
animals,
|
||||
/**
|
||||
* Monster-exceptions.
|
||||
*/
|
||||
monsters
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.enums;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
/**
|
||||
* A regular {@link ChatColor} represented by an english string.
|
||||
* @see ChatColor
|
||||
*/
|
||||
public enum EnglishChatColor {
|
||||
// BEGIN CHECKSTYLE-SUPPRESSION: JavadocVariable
|
||||
AQUA(ChatColor.AQUA),
|
||||
BLACK(ChatColor.BLACK),
|
||||
BLUE(ChatColor.BLUE),
|
||||
DARKAQUA(ChatColor.DARK_AQUA),
|
||||
DARKBLUE(ChatColor.DARK_BLUE),
|
||||
DARKGRAY(ChatColor.DARK_GRAY),
|
||||
DARKGREEN(ChatColor.DARK_GREEN),
|
||||
DARKPURPLE(ChatColor.DARK_PURPLE),
|
||||
DARKRED(ChatColor.DARK_RED),
|
||||
GOLD(ChatColor.GOLD),
|
||||
GRAY(ChatColor.GRAY),
|
||||
GREEN(ChatColor.GREEN),
|
||||
LIGHTPURPLE(ChatColor.LIGHT_PURPLE),
|
||||
RED(ChatColor.RED),
|
||||
YELLOW(ChatColor.YELLOW),
|
||||
WHITE(ChatColor.WHITE);
|
||||
// END CHECKSTYLE-SUPPRESSION: JavadocVariable
|
||||
|
||||
private final ChatColor color;
|
||||
//private final String text;
|
||||
|
||||
EnglishChatColor(ChatColor color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the text.
|
||||
* @return The text.
|
||||
*/
|
||||
public String getText() {
|
||||
return this.name();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the color.
|
||||
* @return The color as {@link ChatColor}.
|
||||
*/
|
||||
public ChatColor getColor() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a string containing all available colors.
|
||||
* @return That {@link String}.
|
||||
*/
|
||||
public static String getAllColors() {
|
||||
String buffer = "";
|
||||
for (EnglishChatColor c : EnglishChatColor.values()) {
|
||||
buffer += c.getColor() + c.getText() + " ";
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an {@link EnglishChatColor} from a {@link String}.
|
||||
* @param text The {@link String}.
|
||||
* @return The {@link EnglishChatColor}.
|
||||
*/
|
||||
public static EnglishChatColor fromString(String text) {
|
||||
if (text != null) {
|
||||
for (EnglishChatColor c : EnglishChatColor.values()) {
|
||||
if (text.equalsIgnoreCase(c.name())) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks if the given-color name is a valid color.
|
||||
* @param aliasColor A color-name.
|
||||
* @return True if the name is a valid color, false if it isn't.
|
||||
*/
|
||||
public static boolean isValidAliasColor(String aliasColor) {
|
||||
return (EnglishChatColor.fromString(aliasColor) != null);
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore.enums;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
/**
|
||||
* A regular {@link ChatColor} represented by an english string.
|
||||
* @see ChatColor
|
||||
*/
|
||||
public enum EnglishChatStyle {
|
||||
// BEGIN CHECKSTYLE-SUPPRESSION: JavadocVariable
|
||||
/** No style. */
|
||||
NORMAL(null),
|
||||
MAGIC(ChatColor.MAGIC),
|
||||
BOLD(ChatColor.BOLD),
|
||||
STRIKETHROUGH(ChatColor.STRIKETHROUGH),
|
||||
UNDERLINE(ChatColor.UNDERLINE),
|
||||
ITALIC(ChatColor.ITALIC);
|
||||
// END CHECKSTYLE-SUPPRESSION: JavadocVariable
|
||||
|
||||
private final ChatColor color;
|
||||
|
||||
EnglishChatStyle(ChatColor color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the color.
|
||||
* @return The color as {@link ChatColor}.
|
||||
*/
|
||||
public ChatColor getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an {@link EnglishChatStyle} from a {@link String}.
|
||||
* @param text The {@link String}.
|
||||
* @return The {@link EnglishChatStyle}.
|
||||
*/
|
||||
public static EnglishChatStyle fromString(String text) {
|
||||
if (text != null) {
|
||||
for (EnglishChatStyle c : EnglishChatStyle.values()) {
|
||||
if (text.equalsIgnoreCase(c.name())) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore.enums;
|
||||
|
||||
public enum RespawnType {
|
||||
BED,
|
||||
ANCHOR,
|
||||
OTHER
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.enums;
|
||||
|
||||
/**
|
||||
* An enum containing possible teleport-results.
|
||||
*/
|
||||
public enum TeleportResult {
|
||||
/**
|
||||
* Insufficient permissions.
|
||||
*/
|
||||
FAIL_PERMISSION,
|
||||
/**
|
||||
* The teleport was unsafe.
|
||||
*/
|
||||
FAIL_UNSAFE,
|
||||
/**
|
||||
* The player was to poor.
|
||||
*/
|
||||
FAIL_TOO_POOR,
|
||||
/**
|
||||
* The teleport was invalid.
|
||||
*/
|
||||
FAIL_INVALID,
|
||||
/**
|
||||
* Unknown reason.
|
||||
*/
|
||||
FAIL_OTHER,
|
||||
/**
|
||||
* The player was successfully teleported.
|
||||
*/
|
||||
SUCCESS
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
/**
|
||||
* This package contains all enums.
|
||||
*/
|
||||
package com.onarandombox.MultiverseCore.enums;
|
|
@ -1,4 +0,0 @@
|
|||
/**
|
||||
* This package contains all events.
|
||||
*/
|
||||
package com.onarandombox.MultiverseCore.event;
|
|
@ -1,4 +0,0 @@
|
|||
/**
|
||||
* This package contains all exceptions.
|
||||
*/
|
||||
package com.onarandombox.MultiverseCore.exceptions;
|
|
@ -1,35 +0,0 @@
|
|||
package com.onarandombox.MultiverseCore.listeners;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
/**
|
||||
* A wrapper for the {@link AsyncPlayerChatEvent}.
|
||||
*/
|
||||
public class AsyncChatEvent implements ChatEvent {
|
||||
private final AsyncPlayerChatEvent event;
|
||||
|
||||
public AsyncChatEvent(AsyncPlayerChatEvent event) {
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return event.isCancelled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFormat() {
|
||||
return event.getFormat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFormat(String s) {
|
||||
event.setFormat(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player getPlayer() {
|
||||
return event.getPlayer();
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue