Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
af9142bb05 | |||
116e816a18 | |||
e4539c3623 | |||
9ac3c11345 | |||
13cdccfc1d | |||
31b3423246 | |||
a35c07dc9c | |||
5aed252181 | |||
ef97da9177 | |||
a26cc30092 | |||
4fda4c3905 | |||
2b23e6fc56 | |||
c09063c49e | |||
b5e2565626 | |||
11d3dc7a92 | |||
1c87d803ff | |||
2076fda4d1 | |||
524130c4e0 | |||
ce5f3ef52f | |||
cae34d395b | |||
643a48392b |
10
Jenkinsfile
vendored
10
Jenkinsfile
vendored
@ -1,7 +1,7 @@
|
||||
pipeline {
|
||||
agent any
|
||||
tools {
|
||||
jdk 'JDK16'
|
||||
jdk 'JDK17'
|
||||
}
|
||||
stages {
|
||||
stage('Build') {
|
||||
@ -16,10 +16,16 @@ pipeline {
|
||||
sh 'mvn test'
|
||||
}
|
||||
}
|
||||
stage('Verify') {
|
||||
steps {
|
||||
echo 'Verifying...'
|
||||
sh 'mvn verify -Dmaven.test.skip=true'
|
||||
}
|
||||
}
|
||||
stage('Deploy') {
|
||||
steps {
|
||||
echo 'Deploying...'
|
||||
sh 'mvn verify -Dmaven.test.skip=true'
|
||||
sh 'mvn deploy -Dmaven.install.skip=true -Dmaven.test.skip=true'
|
||||
archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true
|
||||
}
|
||||
}
|
||||
|
17
README.md
17
README.md
@ -405,6 +405,23 @@ portalInfoServer=Server: %server%
|
||||
|
||||
# Changes
|
||||
|
||||
#### \[Version 0.9.4.2] EpicKnarvik97 fork
|
||||
|
||||
- Avoids a NullPointerException if Dynmap is present, but isn't properly loaded.
|
||||
- Avoids some potential NullPointerExceptions related to Dynmap integration
|
||||
- Fixes end portals hijacking BungeeCord teleportation
|
||||
- Fixes a problem where a player might not be properly teleported from an end portal Stargate in the end to the
|
||||
over-world.
|
||||
|
||||
#### \[Version 0.9.4.1] EpicKnarvik97 fork
|
||||
|
||||
- Reverts to Spigot API 1.18
|
||||
- Adds Dynmap integration
|
||||
|
||||
#### \[Version 0.9.4.0] EpicKnarvik97 fork
|
||||
|
||||
- Updates Stargate to 1.19
|
||||
|
||||
#### \[Version 0.9.3.7] EpicKnarvik97 fork
|
||||
|
||||
- Adds the Japanese language file provided by spigot user furplag
|
||||
|
96
pom.xml
96
pom.xml
@ -4,7 +4,7 @@
|
||||
|
||||
<groupId>net.knarcraft</groupId>
|
||||
<artifactId>Stargate</artifactId>
|
||||
<version>0.9.4.0</version>
|
||||
<version>0.9.4.3-SNAPSHOT</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
@ -15,49 +15,72 @@
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<java.version>16</java.version>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>knarcraft-repo</id>
|
||||
<url>https://git.knarcraft.net/api/packages/EpicKnarvik97/maven</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>vault-repo</id>
|
||||
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
|
||||
<url>https://nexus.hc.to/content/repositories/pub_releases</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>dynmap</id>
|
||||
<url>https://repo.mikeprimm.com/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>papermc</id>
|
||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>knarcraft-repo</id>
|
||||
<url>https://git.knarcraft.net/api/packages/EpicKnarvik97/maven</url>
|
||||
</repository>
|
||||
<snapshotRepository>
|
||||
<id>knarcraft-repo</id>
|
||||
<url>https://git.knarcraft.net/api/packages/EpicKnarvik97/maven</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.19-R0.1-SNAPSHOT</version>
|
||||
<version>1.19.3-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.milkbowl.vault</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>5.8.2</version>
|
||||
<version>5.9.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.seeseemelk</groupId>
|
||||
<artifactId>MockBukkit-v1.18</artifactId>
|
||||
<version>1.15.5</version>
|
||||
<version>2.85.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>22.0.0</version>
|
||||
<scope>compile</scope>
|
||||
<version>23.0.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
@ -65,20 +88,67 @@
|
||||
<version>4.13.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>us.dynmap</groupId>
|
||||
<artifactId>dynmap-api</artifactId>
|
||||
<version>3.1-beta-2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.knarcraft</groupId>
|
||||
<artifactId>knarlib</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.6.1</version>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>17</source>
|
||||
<target>17</target>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>net.knarcraft:knarlib</artifact>
|
||||
<includes>
|
||||
<include>net/knarcraft/knarlib/**</include>
|
||||
</includes>
|
||||
</filter>
|
||||
<filter>
|
||||
<excludes>
|
||||
<exclude>*.MF</exclude>
|
||||
<exclude>*.yml</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
</project>
|
@ -1,5 +1,6 @@
|
||||
package net.knarcraft.stargate;
|
||||
|
||||
import net.knarcraft.knarlib.util.UpdateChecker;
|
||||
import net.knarcraft.stargate.command.CommandStarGate;
|
||||
import net.knarcraft.stargate.command.StarGateTabCompleter;
|
||||
import net.knarcraft.stargate.config.EconomyConfig;
|
||||
@ -22,7 +23,6 @@ import net.knarcraft.stargate.portal.PortalRegistry;
|
||||
import net.knarcraft.stargate.thread.BlockChangeThread;
|
||||
import net.knarcraft.stargate.thread.ChunkUnloadThread;
|
||||
import net.knarcraft.stargate.thread.StarGateThread;
|
||||
import net.knarcraft.stargate.utility.UpdateChecker;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
@ -299,24 +299,6 @@ public class Stargate extends JavaPlugin {
|
||||
return stargateConfig.getLanguageLoader().getBackupString(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces a list of variables in a string in the order they are given
|
||||
*
|
||||
* @param input <p>The input containing the variables</p>
|
||||
* @param search <p>The variables to replace</p>
|
||||
* @param values <p>The replacement values</p>
|
||||
* @return <p>The input string with the search values replaced with the given values</p>
|
||||
*/
|
||||
public static String replaceVars(String input, String[] search, String[] values) {
|
||||
if (search.length != values.length) {
|
||||
throw new IllegalArgumentException("The number of search values and replace values do not match.");
|
||||
}
|
||||
for (int i = 0; i < search.length; i++) {
|
||||
input = replaceVars(input, search[i], values[i]);
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces a variable in a string
|
||||
*
|
||||
@ -383,7 +365,8 @@ public class Stargate extends JavaPlugin {
|
||||
this.registerCommands();
|
||||
|
||||
//Check for any available updates
|
||||
UpdateChecker.checkForUpdate();
|
||||
UpdateChecker.checkForUpdate(this, "https://api.spigotmc.org/legacy/update.php?resource=97784",
|
||||
Stargate::getPluginVersion, Stargate::setUpdateAvailable);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,6 +3,7 @@ package net.knarcraft.stargate.command;
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.ConfigOption;
|
||||
import net.knarcraft.stargate.config.ConfigTag;
|
||||
import net.knarcraft.stargate.config.DynmapManager;
|
||||
import net.knarcraft.stargate.config.OptionDataType;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||
@ -377,6 +378,10 @@ public class CommandConfig implements CommandExecutor {
|
||||
//Load or unload Vault and Economy as necessary
|
||||
Stargate.getStargateConfig().reloadEconomy();
|
||||
}
|
||||
if (ConfigTag.requiresDynmapReload(configOption)) {
|
||||
//Regenerate all Dynmap markers
|
||||
DynmapManager.addAllPortalMarkers();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static net.knarcraft.knarlib.util.TabCompletionHelper.filterMatchingStartsWith;
|
||||
|
||||
/**
|
||||
* This is the completer for stargates config sub-command (/sg config)
|
||||
*/
|
||||
@ -48,27 +50,10 @@ public class ConfigTabCompleter implements TabCompleter {
|
||||
for (ConfigOption option : ConfigOption.values()) {
|
||||
configOptionNames.add(option.getName());
|
||||
}
|
||||
return filterMatching(configOptionNames, args[0]);
|
||||
return filterMatchingStartsWith(configOptionNames, args[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find completable strings which match the text typed by the command's sender
|
||||
*
|
||||
* @param values <p>The values to filter</p>
|
||||
* @param typedText <p>The text the player has started typing</p>
|
||||
* @return <p>The given string values which start with the player's typed text</p>
|
||||
*/
|
||||
private List<String> filterMatching(List<String> values, String typedText) {
|
||||
List<String> configValues = new ArrayList<>();
|
||||
for (String value : values) {
|
||||
if (value.toLowerCase().startsWith(typedText.toLowerCase())) {
|
||||
configValues.add(value);
|
||||
}
|
||||
}
|
||||
return configValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get possible values for the selected option
|
||||
*
|
||||
@ -80,7 +65,7 @@ public class ConfigTabCompleter implements TabCompleter {
|
||||
switch (selectedOption) {
|
||||
case LANGUAGE:
|
||||
//Return available languages
|
||||
return filterMatching(languages, typedText);
|
||||
return filterMatchingStartsWith(languages, typedText);
|
||||
case GATE_FOLDER:
|
||||
case PORTAL_FOLDER:
|
||||
case DEFAULT_GATE_NETWORK:
|
||||
@ -94,12 +79,12 @@ public class ConfigTabCompleter implements TabCompleter {
|
||||
case HIGHLIGHT_SIGN_COLOR:
|
||||
case FREE_GATES_COLOR:
|
||||
//Return all colors
|
||||
return filterMatching(chatColors, typedText);
|
||||
return filterMatchingStartsWith(chatColors, typedText);
|
||||
}
|
||||
|
||||
//If the config value is a boolean, show the two boolean values
|
||||
if (selectedOption.getDataType() == OptionDataType.BOOLEAN) {
|
||||
return filterMatching(booleans, typedText);
|
||||
return filterMatchingStartsWith(booleans, typedText);
|
||||
}
|
||||
|
||||
//If the config value is an integer, display some valid numbers
|
||||
@ -145,11 +130,11 @@ public class ConfigTabCompleter implements TabCompleter {
|
||||
*/
|
||||
private List<String> getPerSignColorCompletion(String[] args) {
|
||||
if (args.length < 3) {
|
||||
return filterMatching(signTypes, args[1]);
|
||||
return filterMatchingStartsWith(signTypes, args[1]);
|
||||
} else if (args.length < 4) {
|
||||
return filterMatching(extendedColors, args[2]);
|
||||
return filterMatchingStartsWith(extendedColors, args[2]);
|
||||
} else if (args.length < 5) {
|
||||
return filterMatching(extendedColors, args[3]);
|
||||
return filterMatchingStartsWith(extendedColors, args[3]);
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
@ -178,7 +178,18 @@ public enum ConfigOption {
|
||||
/**
|
||||
* The velocity of players exiting a stargate, relative to the entry velocity
|
||||
*/
|
||||
EXIT_VELOCITY("gates.exitVelocity", "The velocity of players exiting stargates, relative to the entry velocity", 0.1D);
|
||||
EXIT_VELOCITY("gates.exitVelocity", "The velocity of players exiting stargates, relative to the entry velocity", 0.1D),
|
||||
|
||||
/**
|
||||
* Whether to enable showing Stargates in Dynmap
|
||||
*/
|
||||
ENABLE_DYNMAP("dynmap.enableDynmap", "Whether to display Stargates in Dynmap's map", true),
|
||||
|
||||
/**
|
||||
* Whether to hide Dynmap icons by default
|
||||
*/
|
||||
DYNMAP_ICONS_DEFAULT_HIDDEN("dynmap.dynmapIconsHiddenByDefault",
|
||||
"Whether to hide Stargate's Dynmap icons by default, requiring the user to enable them.", true);
|
||||
|
||||
private final String configNode;
|
||||
private final String description;
|
||||
|
@ -9,7 +9,8 @@ public enum ConfigTag {
|
||||
|
||||
COLOR(new ConfigOption[]{ConfigOption.FREE_GATES_COLOR, ConfigOption.MAIN_SIGN_COLOR,
|
||||
ConfigOption.HIGHLIGHT_SIGN_COLOR, ConfigOption.PER_SIGN_COLORS}),
|
||||
FOLDER(new ConfigOption[]{ConfigOption.GATE_FOLDER, ConfigOption.PORTAL_FOLDER});
|
||||
FOLDER(new ConfigOption[]{ConfigOption.GATE_FOLDER, ConfigOption.PORTAL_FOLDER}),
|
||||
DYNMAP(new ConfigOption[]{ConfigOption.ENABLE_DYNMAP, ConfigOption.DYNMAP_ICONS_DEFAULT_HIDDEN});
|
||||
|
||||
private final ConfigOption[] taggedOptions;
|
||||
|
||||
@ -52,6 +53,16 @@ public enum ConfigTag {
|
||||
return FOLDER.isTagged(option);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a given config option requires a re-load of all Dynmap markers
|
||||
*
|
||||
* @param configOption <p>The config option to check</p>
|
||||
* @return <p>True if changing the config option requires a reload of all dynmap markers</p>
|
||||
*/
|
||||
public static boolean requiresDynmapReload(ConfigOption configOption) {
|
||||
return DYNMAP.isTagged(configOption);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a given config option requires a portal reload to take effect
|
||||
*
|
||||
|
134
src/main/java/net/knarcraft/stargate/config/DynmapManager.java
Normal file
134
src/main/java/net/knarcraft/stargate/config/DynmapManager.java
Normal file
@ -0,0 +1,134 @@
|
||||
package net.knarcraft.stargate.config;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.dynmap.DynmapAPI;
|
||||
import org.dynmap.markers.GenericMarker;
|
||||
import org.dynmap.markers.Marker;
|
||||
import org.dynmap.markers.MarkerIcon;
|
||||
import org.dynmap.markers.MarkerSet;
|
||||
|
||||
/**
|
||||
* A manager for dealing with everything Dynmap
|
||||
*/
|
||||
public final class DynmapManager {
|
||||
|
||||
private static MarkerSet markerSet;
|
||||
private static MarkerIcon portalIcon;
|
||||
|
||||
private DynmapManager() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the dynmap manager
|
||||
*
|
||||
* @param dynmapAPI <p>A reference</p>
|
||||
*/
|
||||
public static void initialize(DynmapAPI dynmapAPI) {
|
||||
if (dynmapAPI == null || dynmapAPI.getMarkerAPI() == null) {
|
||||
markerSet = null;
|
||||
portalIcon = null;
|
||||
} else {
|
||||
markerSet = dynmapAPI.getMarkerAPI().createMarkerSet("stargate", "Stargate", null, false);
|
||||
if (markerSet != null) {
|
||||
markerSet.setHideByDefault(Stargate.getStargateConfig().hideDynmapIcons());
|
||||
}
|
||||
portalIcon = dynmapAPI.getMarkerAPI().getMarkerIcon("portal");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all portal markers for all current portals
|
||||
*/
|
||||
public static void addAllPortalMarkers() {
|
||||
if (markerSet == null || Stargate.getStargateConfig().isDynmapDisabled()) {
|
||||
//Remove any existing markers if dynmap has been disabled after startup
|
||||
if (markerSet != null) {
|
||||
markerSet.getMarkers().forEach(GenericMarker::deleteMarker);
|
||||
}
|
||||
return;
|
||||
}
|
||||
markerSet.setHideByDefault(Stargate.getStargateConfig().hideDynmapIcons());
|
||||
//Remove all existing markers for a clean start
|
||||
markerSet.getMarkers().forEach(GenericMarker::deleteMarker);
|
||||
|
||||
for (Portal portal : PortalRegistry.getAllPortals()) {
|
||||
addPortalMarker(portal);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a portal marker for the given portal
|
||||
*
|
||||
* @param portal <p>The portal to add a marker for</p>
|
||||
*/
|
||||
public static void addPortalMarker(Portal portal) {
|
||||
if (markerSet == null || Stargate.getStargateConfig().isDynmapDisabled()) {
|
||||
return;
|
||||
}
|
||||
World world = portal.getWorld();
|
||||
if (portal.getOptions().isHidden() || world == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Location location = portal.getBlockAt(portal.getGate().getLayout().getExit());
|
||||
Marker marker = markerSet.createMarker(getPortalMarkerId(portal), portal.getName(), world.getName(),
|
||||
location.getX(), location.getY(), location.getZ(), portalIcon, false);
|
||||
if (marker == null) {
|
||||
Stargate.logWarning(String.format(
|
||||
"""
|
||||
Unable to create marker for portal
|
||||
Portal marker id: %s
|
||||
Portal name: %s
|
||||
Portal world: %s
|
||||
Portal location: %s,%s,%s""",
|
||||
getPortalMarkerId(portal), portal.getName(), world.getName(), location.getX(), location.getY(),
|
||||
location.getZ()));
|
||||
return;
|
||||
}
|
||||
String networkPrompt;
|
||||
if (portal.getOptions().isBungee()) {
|
||||
networkPrompt = "Server";
|
||||
} else {
|
||||
networkPrompt = "Network";
|
||||
}
|
||||
String markerDescription = String.format("<b>Name:</b> %s<br /><b>%s:</b> %s<br /><b>Destination:</b> " +
|
||||
"%s<br /><b>Owner:</b> %s<br />", portal.getName(), networkPrompt, portal.getNetwork(),
|
||||
portal.getDestinationName(), portal.getOwner().getName());
|
||||
marker.setDescription(markerDescription);
|
||||
marker.setLabel(portal.getName(), true);
|
||||
if (portalIcon != null) {
|
||||
marker.setMarkerIcon(portalIcon);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the portal marker for the given portal
|
||||
*
|
||||
* @param portal <p>The portal to remove the marker for</p>
|
||||
*/
|
||||
public static void removePortalMarker(Portal portal) {
|
||||
if (markerSet == null || Stargate.getStargateConfig().isDynmapDisabled()) {
|
||||
return;
|
||||
}
|
||||
Marker marker = markerSet.findMarker(getPortalMarkerId(portal));
|
||||
if (marker != null) {
|
||||
marker.deleteMarker();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id used for the given portal's marker
|
||||
*
|
||||
* @param portal <p>The portal to get a marker id for</p>
|
||||
* @return <p></p>
|
||||
*/
|
||||
private static String getPortalMarkerId(Portal portal) {
|
||||
return portal.getNetwork() + "-:-" + portal.getName();
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
package net.knarcraft.stargate.config;
|
||||
|
||||
import net.knarcraft.knarlib.property.ColorConversion;
|
||||
import net.knarcraft.knarlib.util.FileHelper;
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.utility.FileHelper;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
@ -136,7 +137,8 @@ public final class LanguageLoader {
|
||||
String> currentLanguageValues) throws IOException {
|
||||
//Get language values
|
||||
BufferedReader bufferedReader = FileHelper.getBufferedReaderFromInputStream(inputStream);
|
||||
Map<String, String> internalLanguageValues = FileHelper.readKeyValuePairs(bufferedReader);
|
||||
Map<String, String> internalLanguageValues = FileHelper.readKeyValuePairs(bufferedReader, "=",
|
||||
ColorConversion.NORMAL);
|
||||
|
||||
//If currentLanguageValues is null; the chosen language has not been used before
|
||||
if (currentLanguageValues == null) {
|
||||
@ -221,7 +223,7 @@ public final class LanguageLoader {
|
||||
} else {
|
||||
bufferedReader = FileHelper.getBufferedReaderFromInputStream(inputStream);
|
||||
}
|
||||
strings = FileHelper.readKeyValuePairs(bufferedReader);
|
||||
strings = FileHelper.readKeyValuePairs(bufferedReader, "=", ColorConversion.NORMAL);
|
||||
} catch (Exception e) {
|
||||
if (Stargate.getStargateConfig().isDebuggingEnabled()) {
|
||||
Stargate.getConsoleLogger().info("[Stargate] Unable to load language " + lang);
|
||||
|
@ -1,5 +1,7 @@
|
||||
package net.knarcraft.stargate.config;
|
||||
|
||||
import net.knarcraft.knarlib.property.ColorConversion;
|
||||
import net.knarcraft.knarlib.util.FileHelper;
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.container.BlockChangeRequest;
|
||||
import net.knarcraft.stargate.listener.BungeeCordListener;
|
||||
@ -8,13 +10,13 @@ import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||
import net.knarcraft.stargate.portal.property.gate.GateHandler;
|
||||
import net.knarcraft.stargate.thread.BlockChangeThread;
|
||||
import net.knarcraft.stargate.utility.FileHelper;
|
||||
import net.knarcraft.stargate.utility.PortalFileHelper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.messaging.Messenger;
|
||||
import org.dynmap.DynmapAPI;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -101,6 +103,11 @@ public final class StargateConfig {
|
||||
|
||||
//Set up vault economy if vault has been loaded
|
||||
setupVaultEconomy();
|
||||
DynmapAPI dynmapAPI = (DynmapAPI) Bukkit.getPluginManager().getPlugin("dynmap");
|
||||
if (dynmapAPI != null) {
|
||||
DynmapManager.initialize(dynmapAPI);
|
||||
DynmapManager.addAllPortalMarkers();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -152,6 +159,24 @@ public final class StargateConfig {
|
||||
return (boolean) configOptions.get(ConfigOption.PERMISSION_DEBUG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether Dynmap integration is disabled
|
||||
*
|
||||
* @return <p>Whether Dynmap integration is disabled</p>
|
||||
*/
|
||||
public boolean isDynmapDisabled() {
|
||||
return !((boolean) configOptions.get(ConfigOption.ENABLE_DYNMAP));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether Dynmap icons should be hidden by default
|
||||
*
|
||||
* @return <p>Whether Dynmap icons should be hidden by default</p>
|
||||
*/
|
||||
public boolean hideDynmapIcons() {
|
||||
return (boolean) configOptions.get(ConfigOption.DYNMAP_ICONS_DEFAULT_HIDDEN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the object containing economy config values
|
||||
*
|
||||
@ -189,6 +214,9 @@ public final class StargateConfig {
|
||||
startStopBungeeListener(stargateGateConfig.enableBungee());
|
||||
}
|
||||
|
||||
//Reload portal markers
|
||||
DynmapManager.addAllPortalMarkers();
|
||||
|
||||
messageSender.sendErrorMessage(sender, languageLoader.getString("reloaded"));
|
||||
}
|
||||
|
||||
@ -421,7 +449,8 @@ public final class StargateConfig {
|
||||
Map<String, String> migrationFields;
|
||||
try {
|
||||
migrationFields = FileHelper.readKeyValuePairs(FileHelper.getBufferedReaderFromInputStream(
|
||||
FileHelper.getInputStreamForInternalFile("/config-migrations.txt")));
|
||||
FileHelper.getInputStreamForInternalFile("/config-migrations.txt")), "=",
|
||||
ColorConversion.NORMAL);
|
||||
} catch (IOException e) {
|
||||
Stargate.debug("Stargate::migrateConfig", "Unable to load config migration file");
|
||||
e.printStackTrace();
|
||||
|
@ -1,8 +1,8 @@
|
||||
package net.knarcraft.stargate.config;
|
||||
|
||||
import net.knarcraft.knarlib.util.ColorHelper;
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.portal.PortalSignDrawer;
|
||||
import net.knarcraft.stargate.utility.ColorHelper;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package net.knarcraft.stargate.container;
|
||||
|
||||
import net.knarcraft.stargate.utility.ColorHelper;
|
||||
import net.knarcraft.knarlib.util.ColorHelper;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.block.Sign;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.knarcraft.stargate.listener;
|
||||
|
||||
import net.knarcraft.knarlib.util.UpdateChecker;
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.MessageSender;
|
||||
import net.knarcraft.stargate.container.BlockLocation;
|
||||
@ -13,10 +14,10 @@ import net.knarcraft.stargate.utility.MaterialHelper;
|
||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||
import net.knarcraft.stargate.utility.TeleportHelper;
|
||||
import net.knarcraft.stargate.utility.UUIDMigrationHelper;
|
||||
import net.knarcraft.stargate.utility.UpdateChecker;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.type.WallSign;
|
||||
import org.bukkit.entity.AbstractHorse;
|
||||
@ -104,6 +105,11 @@ public class PlayerEventListener implements Listener {
|
||||
return;
|
||||
}
|
||||
Portal entrancePortal = PortalHandler.getByEntrance(toLocation);
|
||||
//Check an additional block away in case the portal is a bungee portal using END_PORTAL
|
||||
if (entrancePortal == null) {
|
||||
entrancePortal = PortalHandler.getByAdjacentEntrance(toLocation);
|
||||
}
|
||||
|
||||
Portal destination = entrancePortal.getPortalActivator().getDestination(player);
|
||||
|
||||
Entity playerVehicle = player.getVehicle();
|
||||
@ -163,7 +169,12 @@ public class PlayerEventListener implements Listener {
|
||||
//Check if the player moved from a portal
|
||||
Portal entrancePortal = PortalHandler.getByEntrance(toLocation);
|
||||
if (entrancePortal == null) {
|
||||
return false;
|
||||
//Check an additional block away for BungeeCord portals using END_PORTAL as its material
|
||||
entrancePortal = PortalHandler.getByAdjacentEntrance(toLocation);
|
||||
if (entrancePortal == null || !entrancePortal.getOptions().isBungee() ||
|
||||
entrancePortal.getGate().getPortalOpenBlock() != Material.END_PORTAL) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Portal destination = entrancePortal.getPortalActivator().getDestination(player);
|
||||
|
@ -6,6 +6,7 @@ import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.portal.teleporter.PlayerTeleporter;
|
||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
@ -67,14 +68,23 @@ public class PortalEventListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
Stargate.debug("PortalEventListener::onEntityPortalEnter",
|
||||
"Found player " + player + " entering END_PORTAL " + portal);
|
||||
|
||||
//Remove any old player teleportations in case weird things happen
|
||||
playersFromTheEnd.removeIf((teleportation -> teleportation.getPlayer() == player));
|
||||
//Decide if the anything stops the player from teleporting
|
||||
if (PermissionHelper.playerCannotTeleport(portal, portal.getPortalActivator().getDestination(), player, null)) {
|
||||
if (PermissionHelper.playerCannotTeleport(portal, portal.getPortalActivator().getDestination(), player, null) ||
|
||||
portal.getOptions().isBungee()) {
|
||||
//Teleport the player back to the portal they came in, just in case
|
||||
playersFromTheEnd.add(new FromTheEndTeleportation(player, portal));
|
||||
Stargate.debug("PortalEventListener::onEntityPortalEnter",
|
||||
"Sending player back to the entrance");
|
||||
} else {
|
||||
playersFromTheEnd.add(new FromTheEndTeleportation(player, portal.getPortalActivator().getDestination()));
|
||||
Stargate.debug("PortalEventListener::onEntityPortalEnter",
|
||||
"Sending player to destination");
|
||||
}
|
||||
playersFromTheEnd.add(new FromTheEndTeleportation(player, portal.getPortalActivator().getDestination()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,9 +105,18 @@ public class PortalEventListener implements Listener {
|
||||
|
||||
Portal exitPortal = teleportation.getExit();
|
||||
//Overwrite respawn location to respawn in front of the portal
|
||||
event.setRespawnLocation(new PlayerTeleporter(exitPortal, respawningPlayer).getExit());
|
||||
PlayerTeleporter teleporter = new PlayerTeleporter(exitPortal, respawningPlayer);
|
||||
Location respawnLocation = teleporter.getExit();
|
||||
event.setRespawnLocation(respawnLocation);
|
||||
//Try and force the player if for some reason the changing of respawn location isn't properly handled
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Stargate.getInstance(), () ->
|
||||
respawningPlayer.teleport(respawnLocation), 1);
|
||||
|
||||
//Properly close the portal to prevent it from staying in a locked state until it times out
|
||||
exitPortal.getPortalOpener().closePortal(false);
|
||||
|
||||
Stargate.debug("PortalEventListener::onRespawn", "Overwriting respawn for " + respawningPlayer +
|
||||
" to " + respawnLocation.getWorld() + ":" + respawnLocation);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.knarcraft.stargate.portal;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.DynmapManager;
|
||||
import net.knarcraft.stargate.container.BlockLocation;
|
||||
import net.knarcraft.stargate.utility.PortalFileHelper;
|
||||
import org.bukkit.World;
|
||||
@ -224,6 +225,7 @@ public class PortalRegistry {
|
||||
|
||||
PortalFileHelper.saveAllPortals(portal.getWorld());
|
||||
portal.setRegistered(false);
|
||||
DynmapManager.removePortalMarker(portal);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -289,6 +291,7 @@ public class PortalRegistry {
|
||||
|
||||
allPortals.add(portal);
|
||||
portal.setRegistered(true);
|
||||
DynmapManager.addPortalMarker(portal);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package net.knarcraft.stargate.portal;
|
||||
|
||||
import net.knarcraft.knarlib.property.ColorConversion;
|
||||
import net.knarcraft.knarlib.util.ColorHelper;
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.container.SignData;
|
||||
import net.knarcraft.stargate.portal.property.PortalLocation;
|
||||
@ -12,8 +14,6 @@ import org.bukkit.block.Sign;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static net.knarcraft.stargate.utility.ColorHelper.translateAllColorCodes;
|
||||
|
||||
/**
|
||||
* The portal sign drawer draws the sing of a given portal
|
||||
*/
|
||||
@ -393,4 +393,14 @@ public class PortalSignDrawer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates all normal and RGB color codes in the given input
|
||||
*
|
||||
* @param input <p>The input to translate color codes for</p>
|
||||
* @return <p>The input with color codes converted translated from & to §</p>
|
||||
*/
|
||||
private String translateAllColorCodes(String input) {
|
||||
return ColorHelper.translateColorCodes(input, ColorConversion.RGB);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ public class VehicleTeleporter extends EntityTeleporter {
|
||||
//Spawn a new vehicle
|
||||
Vehicle newVehicle = vehicleWorld.spawn(exit, teleportingVehicle.getClass());
|
||||
if (teleportingVehicle instanceof Boat boat) {
|
||||
((Boat) newVehicle).setWoodType(boat.getWoodType());
|
||||
((Boat) newVehicle).setBoatType(boat.getBoatType());
|
||||
}
|
||||
//Remove the old vehicle
|
||||
if (teleportingVehicle.eject()) {
|
||||
|
@ -1,54 +0,0 @@
|
||||
package net.knarcraft.stargate.utility;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* A helper class for dealing with colors
|
||||
*/
|
||||
public final class ColorHelper {
|
||||
|
||||
private ColorHelper() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Inverts the given color
|
||||
*
|
||||
* @param color <p>The color to invert</p>
|
||||
* @return <p>The inverted color</p>
|
||||
*/
|
||||
public static Color invert(Color color) {
|
||||
return color.setRed(255 - color.getRed()).setGreen(255 - color.getGreen()).setBlue(255 - color.getBlue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the chat color corresponding to the given color
|
||||
*
|
||||
* @param color <p>The color to convert into a chat color</p>
|
||||
* @return <p>The resulting chat color</p>
|
||||
*/
|
||||
public static ChatColor fromColor(Color color) {
|
||||
return ChatColor.of(String.format("#%02X%02X%02X", color.getRed(), color.getGreen(), color.getBlue()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates all found color codes to formatting in a string
|
||||
*
|
||||
* @param message <p>The string to search for color codes</p>
|
||||
* @return <p>The message with color codes translated</p>
|
||||
*/
|
||||
public static String translateAllColorCodes(String message) {
|
||||
message = ChatColor.translateAlternateColorCodes('&', message);
|
||||
Pattern pattern = Pattern.compile("(#[a-fA-F0-9]{6})");
|
||||
Matcher matcher = pattern.matcher(message);
|
||||
while (matcher.find()) {
|
||||
message = message.replace(matcher.group(), "" + ChatColor.of(matcher.group()));
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package net.knarcraft.stargate.utility;
|
||||
|
||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.EconomyConfig;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
@ -78,7 +79,7 @@ public final class EconomyHelper {
|
||||
*/
|
||||
public static void sendObtainMessage(String portalName, Player portalOwner, int earnings) {
|
||||
String obtainedMsg = Stargate.getString("ecoObtain");
|
||||
obtainedMsg = replaceVars(obtainedMsg, portalName, earnings);
|
||||
obtainedMsg = replacePlaceholders(obtainedMsg, portalName, earnings);
|
||||
Stargate.getMessageSender().sendSuccessMessage(portalOwner, obtainedMsg);
|
||||
}
|
||||
|
||||
@ -91,7 +92,7 @@ public final class EconomyHelper {
|
||||
*/
|
||||
public static void sendDeductMessage(String portalName, Player player, int cost) {
|
||||
String deductMsg = Stargate.getString("ecoDeduct");
|
||||
deductMsg = replaceVars(deductMsg, portalName, cost);
|
||||
deductMsg = replacePlaceholders(deductMsg, portalName, cost);
|
||||
Stargate.getMessageSender().sendSuccessMessage(player, deductMsg);
|
||||
}
|
||||
|
||||
@ -104,7 +105,7 @@ public final class EconomyHelper {
|
||||
*/
|
||||
public static void sendInsufficientFundsMessage(String portalName, Player player, int cost) {
|
||||
String inFundMsg = Stargate.getString("ecoInFunds");
|
||||
inFundMsg = replaceVars(inFundMsg, portalName, cost);
|
||||
inFundMsg = replacePlaceholders(inFundMsg, portalName, cost);
|
||||
Stargate.getMessageSender().sendErrorMessage(player, inFundMsg);
|
||||
}
|
||||
|
||||
@ -117,7 +118,7 @@ public final class EconomyHelper {
|
||||
*/
|
||||
public static void sendRefundMessage(String portalName, Player player, int cost) {
|
||||
String refundMsg = Stargate.getString("ecoRefund");
|
||||
refundMsg = replaceVars(refundMsg, portalName, -cost);
|
||||
refundMsg = replacePlaceholders(refundMsg, portalName, -cost);
|
||||
Stargate.getMessageSender().sendSuccessMessage(player, refundMsg);
|
||||
}
|
||||
|
||||
@ -239,8 +240,8 @@ public final class EconomyHelper {
|
||||
* @param cost <p>The cost for a given interaction</p>
|
||||
* @return <p>The same string with cost and portal variables replaced</p>
|
||||
*/
|
||||
private static String replaceVars(String message, String portalName, int cost) {
|
||||
return Stargate.replaceVars(message, new String[]{"%cost%", "%portal%"},
|
||||
private static String replacePlaceholders(String message, String portalName, int cost) {
|
||||
return StringFormatter.replacePlaceholders(message, new String[]{"%cost%", "%portal%"},
|
||||
new String[]{Stargate.getEconomyConfig().format(cost), portalName});
|
||||
}
|
||||
|
||||
|
@ -1,127 +0,0 @@
|
||||
package net.knarcraft.stargate.utility;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Helper class for reading files
|
||||
*/
|
||||
public final class FileHelper {
|
||||
|
||||
private FileHelper() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an input stream from a string pointing to an internal file
|
||||
*
|
||||
* <p>This is used for getting an input stream for reading a file contained within the compiled .jar file. The file
|
||||
* should be in the resources directory, and the file path should start with a forward slash ("/") character.</p>
|
||||
*
|
||||
* @param file <p>The file to read</p>
|
||||
* @return <p>An input stream for the file</p>
|
||||
*/
|
||||
public static InputStream getInputStreamForInternalFile(String file) {
|
||||
return FileHelper.class.getResourceAsStream(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a buffered reader from a string pointing to a file
|
||||
*
|
||||
* @param file <p>The file to read</p>
|
||||
* @return <p>A buffered reader reading the file</p>
|
||||
* @throws FileNotFoundException <p>If the given file does not exist</p>
|
||||
*/
|
||||
public static BufferedReader getBufferedReaderFromString(String file) throws FileNotFoundException {
|
||||
FileInputStream fileInputStream = new FileInputStream(file);
|
||||
return getBufferedReaderFromInputStream(fileInputStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a buffered reader given an input stream
|
||||
*
|
||||
* @param inputStream <p>The input stream to read</p>
|
||||
* @return <p>A buffered reader reading the input stream</p>
|
||||
*/
|
||||
public static BufferedReader getBufferedReaderFromInputStream(InputStream inputStream) {
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
||||
return new BufferedReader(inputStreamReader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a buffered writer from a string pointing to a file
|
||||
*
|
||||
* @param file <p>The file to write to</p>
|
||||
* @return <p>A buffered writer writing to the file</p>
|
||||
* @throws FileNotFoundException <p>If the file does not exist</p>
|
||||
*/
|
||||
public static BufferedWriter getBufferedWriterFromString(String file) throws FileNotFoundException {
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(file);
|
||||
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, StandardCharsets.UTF_8);
|
||||
return new BufferedWriter(outputStreamWriter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads key/value pairs from an input stream
|
||||
*
|
||||
* @param bufferedReader <p>The buffered reader to read</p>
|
||||
* @return <p>A map containing the read pairs</p>
|
||||
* @throws IOException <p>If unable to read from the stream</p>
|
||||
*/
|
||||
public static Map<String, String> readKeyValuePairs(BufferedReader bufferedReader) throws IOException {
|
||||
Map<String, String> readPairs = new HashMap<>();
|
||||
|
||||
String line = bufferedReader.readLine();
|
||||
boolean firstLine = true;
|
||||
while (line != null) {
|
||||
//Strip UTF BOM from the first line
|
||||
if (firstLine) {
|
||||
line = removeUTF8BOM(line);
|
||||
firstLine = false;
|
||||
}
|
||||
//Split at first "="
|
||||
int equalSignIndex = line.indexOf('=');
|
||||
if (equalSignIndex == -1) {
|
||||
line = bufferedReader.readLine();
|
||||
continue;
|
||||
}
|
||||
|
||||
//Read the line
|
||||
String key = line.substring(0, equalSignIndex);
|
||||
String value = ChatColor.translateAlternateColorCodes('&', line.substring(equalSignIndex + 1));
|
||||
readPairs.put(key, value);
|
||||
|
||||
line = bufferedReader.readLine();
|
||||
}
|
||||
bufferedReader.close();
|
||||
|
||||
return readPairs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the UTF-8 Byte Order Mark if present
|
||||
*
|
||||
* @param string <p>The string to remove the BOM from</p>
|
||||
* @return <p>A string guaranteed without a BOM</p>
|
||||
*/
|
||||
private static String removeUTF8BOM(String string) {
|
||||
String UTF8_BOM = "\uFEFF";
|
||||
if (string.startsWith(UTF8_BOM)) {
|
||||
string = string.substring(1);
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
package net.knarcraft.stargate.utility;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* The update checker is responsible for looking for new updates
|
||||
*/
|
||||
public final class UpdateChecker {
|
||||
|
||||
private final static String APIResourceURL = "https://api.spigotmc.org/legacy/update.php?resource=97784";
|
||||
private final static String updateNotice = "A new update is available: %s (You are still on %s)";
|
||||
|
||||
private UpdateChecker() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if there's a new update available, and alerts the user if necessary
|
||||
*/
|
||||
public static void checkForUpdate() {
|
||||
BukkitScheduler scheduler = Stargate.getInstance().getServer().getScheduler();
|
||||
scheduler.runTaskAsynchronously(Stargate.getInstance(), UpdateChecker::queryAPI);
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries the spigot API to check for a newer version, and informs the user
|
||||
*/
|
||||
private static void queryAPI() {
|
||||
try {
|
||||
InputStream inputStream = new URL(APIResourceURL).openStream();
|
||||
BufferedReader reader = FileHelper.getBufferedReaderFromInputStream(inputStream);
|
||||
//There should only be one line of output
|
||||
String newVersion = reader.readLine();
|
||||
reader.close();
|
||||
|
||||
String oldVersion = Stargate.getPluginVersion();
|
||||
//If there is a newer version, notify the user
|
||||
if (isVersionHigher(oldVersion, newVersion)) {
|
||||
Stargate.getConsoleLogger().log(Level.INFO, Stargate.getBackupString("prefix") +
|
||||
getUpdateAvailableString(newVersion, oldVersion));
|
||||
Stargate.setUpdateAvailable(newVersion);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Stargate.debug("UpdateChecker", "Unable to get newest version.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the string to display to a user to alert about a new update
|
||||
*
|
||||
* @param newVersion <p>The new available plugin version</p>
|
||||
* @param oldVersion <p>The old (current) plugin version</p>
|
||||
* @return <p>The string to display</p>
|
||||
*/
|
||||
public static String getUpdateAvailableString(String newVersion, String oldVersion) {
|
||||
return String.format(updateNotice, newVersion, oldVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decides whether one version number is higher than another
|
||||
*
|
||||
* @param oldVersion <p>The old version to check</p>
|
||||
* @param newVersion <p>The new version to check</p>
|
||||
* @return <p>True if the new version is higher than the old one</p>
|
||||
*/
|
||||
public static boolean isVersionHigher(String oldVersion, String newVersion) {
|
||||
String[] oldVersionParts = oldVersion.split("\\.");
|
||||
String[] newVersionParts = newVersion.split("\\.");
|
||||
int versionLength = Math.max(oldVersionParts.length, newVersionParts.length);
|
||||
for (int i = 0; i < versionLength; i++) {
|
||||
int oldVersionNumber = oldVersionParts.length > i ? Integer.parseInt(oldVersionParts[i]) : 0;
|
||||
int newVersionNumber = newVersionParts.length > i ? Integer.parseInt(newVersionParts[i]) : 0;
|
||||
if (newVersionNumber != oldVersionNumber) {
|
||||
return newVersionNumber > oldVersionNumber;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,8 @@
|
||||
lang=language
|
||||
defaultNetwork=defaultGateNetwork
|
||||
use-mysql=
|
||||
ignoreEntrance=
|
||||
portal-save-location=folders.portalFolder
|
||||
portal-folder=folders.portalFolder
|
||||
gate-folder=folders.gateFolder
|
||||
default-gate-network=gates.defaultGateNetwork
|
||||
@ -18,11 +22,28 @@ debug=debugging.debug
|
||||
permdebug=debugging.permissionDebug
|
||||
useiconomy=economy.useEconomy
|
||||
useeconomy=economy.useEconomy
|
||||
cost-to-use=economy.useCost
|
||||
cost-to-create=economy.createCost
|
||||
createcost=economy.createCost
|
||||
destroycost=economy.destroyCost
|
||||
usecost=economy.useCost
|
||||
toowner=economy.toOwner
|
||||
cost-destination=economy.chargeFreeDestination
|
||||
chargefreedestination=economy.chargeFreeDestination
|
||||
freegatesgreen=economy.freeGatesGreen
|
||||
CheckUpdates=
|
||||
economy.freeGatesGreen=economy.freeGatesColored
|
||||
economy.freeGatesGreen=economy.freeGatesColored
|
||||
teleportMessage=
|
||||
registerMessage=
|
||||
destroyzMessage=
|
||||
noownersMessage=
|
||||
unselectMessage=
|
||||
collisinMessage=
|
||||
cantAffordToUse=
|
||||
cantAffordToNew=
|
||||
portal-open=
|
||||
portal-closed=
|
||||
cost-type=
|
||||
cost-to-activate=
|
||||
taxaccount=taxAccount
|
||||
usevault=
|
@ -40,7 +40,8 @@ gates:
|
||||
destroyedByExplosion: false
|
||||
# verifyPortals - Whether all the non-sign blocks are checked to match the gate layout when a stargate is loaded.
|
||||
verifyPortals: false
|
||||
# protectEntrance - Whether to protect gate entrance material (More resource intensive. Only enable if using destroyable open/closed material)
|
||||
# protectEntrance - Whether to protect gate entrance material (More resource intensive. Only enable if using
|
||||
# destroyable open/closed material)
|
||||
protectEntrance: false
|
||||
functionality:
|
||||
enableBungee: false
|
||||
@ -48,18 +49,21 @@ gates:
|
||||
handleVehicles: true
|
||||
# handleEmptyVehicles - Whether to allow empty vehicles through gates (chest/hopper/tnt/furnace minecarts included)
|
||||
handleEmptyVehicles: true
|
||||
# handleCreatureTransportation - Whether to allow players to transport creatures by sending vehicles (minecarts, boats) through gates
|
||||
# handleCreatureTransportation - Whether to allow players to transport creatures by sending vehicles (minecarts,
|
||||
# boats) through gates
|
||||
handleCreatureTransportation: true
|
||||
# handleNonPlayerVehicles - Whether to allow vehicles with a passenger which is not a player through gates. handleCreatureTransportation must be enabled
|
||||
# handleNonPlayerVehicles - Whether to allow vehicles with a passenger which is not a player through gates.
|
||||
# handleCreatureTransportation must be enabled
|
||||
handleNonPlayerVehicles: true
|
||||
# handleLeashedCreatures - Whether to allow creatures lead by a player to teleport with the player
|
||||
handleLeashedCreatures: true
|
||||
# enableCraftBookRemoveOnEjectFix - Whether to enable a fix that causes loss of NBT data, but allows vehicle teleportation to work when CraftBook's remove minecart/boat on eject setting is enabled
|
||||
# enableCraftBookRemoveOnEjectFix - Whether to enable a fix that causes loss of NBT data, but allows vehicle
|
||||
# teleportation to work when CraftBook's remove minecart/boat on eject setting is enabled
|
||||
enableCraftBookRemoveOnEjectFix: false
|
||||
|
||||
#############################
|
||||
# ######################## #
|
||||
# stargate economy options #
|
||||
############################
|
||||
# ######################## #
|
||||
economy:
|
||||
# useEconomy - Whether to use an economy plugin
|
||||
useEconomy: false
|
||||
@ -78,14 +82,26 @@ economy:
|
||||
# freeGatesColor - The color to use for marking free gates
|
||||
freeGatesColor: DARK_GREEN
|
||||
|
||||
#################
|
||||
# ############# #
|
||||
# Debug options #
|
||||
#################
|
||||
# ############# #
|
||||
debugging:
|
||||
# debug - Debug -- Only enable if you have issues, massive console output
|
||||
debug: false
|
||||
# permissionDebug - This will output any and all Permissions checks to console, used for permissions debugging (Requires debug: true)
|
||||
# permissionDebug - This will output any and all Permissions checks to console, used for permissions debugging
|
||||
# (Requires debug: true)
|
||||
permissionDebug: false
|
||||
advanced:
|
||||
# waitForPlayerAfterTeleportDelay - The amount of ticks to wait before adding a player as passenger of a vehicle. On slow servers, a value of 6 is required to avoid client glitches after teleporting on a vehicle.
|
||||
waitForPlayerAfterTeleportDelay: 6
|
||||
# waitForPlayerAfterTeleportDelay - The amount of ticks to wait before adding a player as passenger of a vehicle.
|
||||
# On slow servers, a value of 6 is required to avoid client glitches after teleporting on a vehicle.
|
||||
waitForPlayerAfterTeleportDelay: 6
|
||||
|
||||
# ############## #
|
||||
# Dynmap options #
|
||||
# ############## #
|
||||
dynmap:
|
||||
# enableDynmap - Whether to display Stargates in Dynmap's map
|
||||
enableDynmap: true
|
||||
# dynmapIconsHiddenByDefault - Whether to hide the set of Stargate icons by default, requiring users to
|
||||
# manually enable them with a checkbox.
|
||||
dynmapIconsHiddenByDefault: true
|
@ -1,12 +1,12 @@
|
||||
name: Stargate
|
||||
main: net.knarcraft.stargate.Stargate
|
||||
version: 0.9.4.0
|
||||
version: '${project.version}'
|
||||
description: Stargate mod for Bukkit Revived
|
||||
author: EpicKnarvik97
|
||||
authors: [ Drakia, PseudoKnight, EpicKnarvik97 ]
|
||||
website: https://git.knarcraft.net/EpicKnarvik97/Stargate
|
||||
api-version: 1.19
|
||||
softdepend: [ Vault ]
|
||||
api-version: 1.18
|
||||
softdepend: [ Vault, dynmap ]
|
||||
commands:
|
||||
stargate:
|
||||
aliases:
|
||||
|
Loading…
Reference in New Issue
Block a user