Fixed some stuff
This commit is contained in:
parent
ad9c5d4139
commit
2bd9c305bb
37 changed files with 1511 additions and 315 deletions
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<module version="4">
|
<module type="JAVA_MODULE" version="4">
|
||||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||||
<output url="file://$MODULE_DIR$/target/classes" />
|
<output url="file://$MODULE_DIR$/target/classes" />
|
||||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||||
|
@ -25,7 +25,56 @@
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.dynmap:dynmap-api:2.0" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.dynmap:dynmap-api:2.0" level="project" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:bukkit:1.4.7-R1.0" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:bukkit:1.4.7-R1.0" level="project" />
|
||||||
<orderEntry type="library" name="Maven: nl.iobyte:menuapi:1.0" level="project" />
|
<orderEntry type="library" name="Maven: nl.iobyte:menuapi:1.0" level="project" />
|
||||||
<orderEntry type="library" name="Maven: com.zaxxer:HikariCP:3.4.3" level="project" />
|
<orderEntry type="library" name="Maven: com.zaxxer:HikariCP:3.4.5" level="project" />
|
||||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
|
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: nl.iobyte:workchain:1.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.bergerkiller.bukkit:TrainCarts:1.16.5-v1" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: io.github.qveshn:LightAPI-fork:3.4.2-SNAPSHOT" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: me.m56738:SmoothCoastersAPI:1.1" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bergerhealer.cloud.commandframework:cloud-paper:1.4.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: io.leangen.geantyref:geantyref:1.3.11" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bergerhealer.cloud.commandframework:cloud-bukkit:1.4.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bergerhealer.cloud.commandframework:cloud-brigadier:1.4.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bergerhealer.cloud.commandframework:cloud-tasks:1.4.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bergerhealer.cloud.commandframework:cloud-annotations:1.4.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bergerhealer.cloud.commandframework:cloud-core:1.4.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bergerhealer.cloud.commandframework:cloud-services:1.4.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bergerhealer.cloud.commandframework:cloud-minecraft-extras:1.4.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: net.kyori:adventure-api:4.3.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: net.kyori:examination-api:1.0.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: net.kyori:examination-string:1.0.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.checkerframework:checker-qual:3.8.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: net.kyori:adventure-text-serializer-plain:4.3.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: me.lucko:commodore:1.9" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: me.lucko:commodore-file:1.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.mojang:brigadier:1.0.17" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: net.kyori:adventure-platform-bukkit:4.0.0-SNAPSHOT" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: net.kyori:adventure-platform-api:4.0.0-SNAPSHOT" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: net.kyori:adventure-text-serializer-craftbukkit:4.0.0-SNAPSHOT" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: net.kyori:adventure-text-serializer-gson-legacy-impl:4.7.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: net.kyori:adventure-text-serializer-bungeecord:4.0.0-SNAPSHOT" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: net.kyori:adventure-text-serializer-legacy:4.7.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: net.kyori:adventure-nbt:4.7.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.jetbrains:annotations:20.1.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: net.kyori:adventure-text-serializer-gson:4.7.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: net.kyori:adventure-platform-facet:4.0.0-SNAPSHOT" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: net.kyori:adventure-platform-viaversion:4.0.0-SNAPSHOT" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.bergerkiller.bukkit:BKCommonLib:1.16.5-v1" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.bergerkiller.mountiplex:Mountiplex:2.22" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.ow2.asm:asm:7.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.objenesis:objenesis:3.1" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.javassist:javassist:3.27.0-GA" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.maven:maven-project:2.0.6" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.maven:maven-settings:2.0.6" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.maven:maven-profile:2.0.6" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.maven:maven-model:2.0.6" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.maven:maven-artifact-manager:2.0.6" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.maven:maven-repository-metadata:2.0.6" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.maven.wagon:wagon-provider-api:1.0-beta-2" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.maven:maven-plugin-registry:2.0.6" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.codehaus.plexus:plexus-utils:1.4.1" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.maven:maven-artifact:2.0.6" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.codehaus.plexus:plexus-container-default:1.0-alpha-9-stable-1" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: classworlds:classworlds:1.1-alpha-2" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
|
@ -7,7 +7,6 @@
|
||||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
<outputRelativeToContentRoot value="true" />
|
<outputRelativeToContentRoot value="true" />
|
||||||
<module name="themepark" />
|
<module name="themepark" />
|
||||||
<module name="ThemePark" />
|
|
||||||
</profile>
|
</profile>
|
||||||
</annotationProcessing>
|
</annotationProcessing>
|
||||||
</component>
|
</component>
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="JavadocGenerationManager">
|
||||||
|
<option name="OUTPUT_DIRECTORY" value="$PROJECT_DIR$/../../JavaDoc" />
|
||||||
|
</component>
|
||||||
<component name="MavenProjectsManager">
|
<component name="MavenProjectsManager">
|
||||||
<option name="originalFiles">
|
<option name="originalFiles">
|
||||||
<list>
|
<list>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>nl.iobyte</groupId>
|
<groupId>nl.iobyte</groupId>
|
||||||
<artifactId>themepark</artifactId>
|
<artifactId>themepark</artifactId>
|
||||||
<version>2.0</version>
|
<version>2.3.3</version>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
@ -29,14 +29,14 @@
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
|
||||||
<id>placeholderapi</id>
|
|
||||||
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>dynmap</id>
|
<id>dynmap</id>
|
||||||
<url>http://repo.mikeprimm.com/</url>
|
<url>http://repo.mikeprimm.com/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>MG-Dev Jenkins CI Maven Repository</id>
|
||||||
|
<url>https://ci.mg-dev.eu/plugin/repository/everything</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -87,6 +87,54 @@
|
||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.bergerkiller.bukkit</groupId>
|
||||||
|
<artifactId>TrainCarts</artifactId>
|
||||||
|
<version>1.16.5-v1</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>LightAPI-fork</artifactId>
|
||||||
|
<groupId>io.github.qveshn</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>SmoothCoastersAPI</artifactId>
|
||||||
|
<groupId>me.m56738</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>cloud-paper</artifactId>
|
||||||
|
<groupId>org.bergerhealer.cloud.commandframework</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>cloud-annotations</artifactId>
|
||||||
|
<groupId>org.bergerhealer.cloud.commandframework</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>cloud-minecraft-extras</artifactId>
|
||||||
|
<groupId>org.bergerhealer.cloud.commandframework</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>commodore</artifactId>
|
||||||
|
<groupId>me.lucko</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>adventure-platform-bukkit</artifactId>
|
||||||
|
<groupId>net.kyori</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.bergerkiller.bukkit</groupId>
|
||||||
|
<artifactId>BKCommonLib</artifactId>
|
||||||
|
<version>1.16.5-v1</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>Mountiplex</artifactId>
|
||||||
|
<groupId>com.bergerkiller.mountiplex</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
|
24
pom.xml
24
pom.xml
|
@ -11,17 +11,17 @@
|
||||||
|
|
||||||
<groupId>nl.iobyte</groupId>
|
<groupId>nl.iobyte</groupId>
|
||||||
<artifactId>themepark</artifactId>
|
<artifactId>themepark</artifactId>
|
||||||
<version>2.0</version>
|
<version>2.3.3</version>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
|
||||||
<id>placeholderapi</id>
|
|
||||||
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>dynmap</id>
|
<id>dynmap</id>
|
||||||
<url>http://repo.mikeprimm.com/</url>
|
<url>http://repo.mikeprimm.com/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>MG-Dev Jenkins CI Maven Repository</id>
|
||||||
|
<url>https://ci.mg-dev.eu/plugin/repository/everything</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -45,13 +45,25 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.zaxxer</groupId>
|
<groupId>com.zaxxer</groupId>
|
||||||
<artifactId>HikariCP</artifactId>
|
<artifactId>HikariCP</artifactId>
|
||||||
<version>3.4.3</version>
|
<version>3.4.5</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>nl.iobyte</groupId>
|
<groupId>nl.iobyte</groupId>
|
||||||
<artifactId>workchain</artifactId>
|
<artifactId>workchain</artifactId>
|
||||||
<version>1.0</version>
|
<version>1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.bergerkiller.bukkit</groupId>
|
||||||
|
<artifactId>TrainCarts</artifactId>
|
||||||
|
<version>1.16.5-v1</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.bergerkiller.bukkit</groupId>
|
||||||
|
<artifactId>BKCommonLib</artifactId>
|
||||||
|
<version>1.16.5-v1</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -12,19 +12,23 @@ import nl.iobyte.themepark.database.SQLite;
|
||||||
import nl.iobyte.themepark.listener.AttractionListener;
|
import nl.iobyte.themepark.listener.AttractionListener;
|
||||||
import nl.iobyte.themepark.listener.PlayerListener;
|
import nl.iobyte.themepark.listener.PlayerListener;
|
||||||
import nl.iobyte.themepark.listener.RegionListener;
|
import nl.iobyte.themepark.listener.RegionListener;
|
||||||
|
import nl.iobyte.themepark.listener.SignListener;
|
||||||
import nl.iobyte.themepark.menu.AttractionLoader;
|
import nl.iobyte.themepark.menu.AttractionLoader;
|
||||||
|
import nl.iobyte.themepark.sign.SignManager;
|
||||||
import nl.iobyte.workchain.thread.WorkThreader;
|
import nl.iobyte.workchain.thread.WorkThreader;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandMap;
|
import org.bukkit.command.CommandMap;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
public class ThemeParkPlugin extends JavaPlugin {
|
public class ThemeParkPlugin extends JavaPlugin {
|
||||||
|
|
||||||
private static ThemeParkPlugin instance;
|
private static ThemeParkPlugin instance;
|
||||||
private YamlConfig settings, messages, data, regions;
|
private YamlConfig settings, messages, data, regions, signs;
|
||||||
private WorkThreader threader;
|
private WorkThreader threader;
|
||||||
|
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
@ -34,6 +38,7 @@ public class ThemeParkPlugin extends JavaPlugin {
|
||||||
loadWorkers();
|
loadWorkers();
|
||||||
loadListeners();
|
loadListeners();
|
||||||
loadCommands();
|
loadCommands();
|
||||||
|
setupTrainCarts();
|
||||||
AttractionLoader.load();
|
AttractionLoader.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +47,7 @@ public class ThemeParkPlugin extends JavaPlugin {
|
||||||
messages = new YamlConfig("messages", this);
|
messages = new YamlConfig("messages", this);
|
||||||
data = new YamlConfig("data", this);
|
data = new YamlConfig("data", this);
|
||||||
regions = new YamlConfig("regions", this);
|
regions = new YamlConfig("regions", this);
|
||||||
|
signs = new YamlConfig("signs", this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadDatabases() {
|
private void loadDatabases() {
|
||||||
|
@ -49,12 +55,13 @@ public class ThemeParkPlugin extends JavaPlugin {
|
||||||
|
|
||||||
FileConfiguration fc = settings.getConfig();
|
FileConfiguration fc = settings.getConfig();
|
||||||
if(fc.getBoolean("mysql.enabled")) {
|
if(fc.getBoolean("mysql.enabled")) {
|
||||||
|
String url = fc.getString("mysql.url");
|
||||||
String host = fc.getString("mysql.host");
|
String host = fc.getString("mysql.host");
|
||||||
int port = fc.getInt("mysql.port");
|
int port = fc.getInt("mysql.port");
|
||||||
String database = fc.getString("mysql.database");
|
String database = fc.getString("mysql.database");
|
||||||
String username = fc.getString("mysql.user");
|
String username = fc.getString("mysql.user");
|
||||||
String password = fc.getString("mysql.pass");
|
String password = fc.getString("mysql.pass");
|
||||||
DBManager.addDatabase("public", new MySQL(host, port, database, username, password));
|
DBManager.addDatabase("public", new MySQL(url, host, port, database, username, password));
|
||||||
}
|
}
|
||||||
|
|
||||||
loadTables();
|
loadTables();
|
||||||
|
@ -62,7 +69,7 @@ public class ThemeParkPlugin extends JavaPlugin {
|
||||||
|
|
||||||
private void loadTables() {
|
private void loadTables() {
|
||||||
DB db = DBManager.getDatabase("data");
|
DB db = DBManager.getDatabase("data");
|
||||||
DBManager.createTable(db, "CREATE TABLE IF NOT EXISTS counts(uuid VARCHAR(255) NOT NULL, attraction_id VARCHAR(255) NOT NULL, points BIGINT(20), created_at TEXT DEFAULT CURRENT_DATE, UNIQUE(uuid, attraction_id))");
|
DBManager.createTable(db, "CREATE TABLE IF NOT EXISTS counts(uuid VARCHAR(255) NOT NULL, attraction_id VARCHAR(255) NOT NULL, points BIGINT(20), created_at TEXT DEFAULT CURRENT_DATE, UNIQUE(uuid, attraction_id, created_at))");
|
||||||
|
|
||||||
db = DBManager.getDatabase("public");
|
db = DBManager.getDatabase("public");
|
||||||
if(db == null)
|
if(db == null)
|
||||||
|
@ -70,7 +77,7 @@ public class ThemeParkPlugin extends JavaPlugin {
|
||||||
|
|
||||||
DBManager.createTable(db, "CREATE TABLE IF NOT EXISTS attraction (id VARCHAR(256) NOT NULL, name VARCHAR(256) NOT NULL, region_id VARCHAR(256) NOT NULL, type VARCHAR(256) NOT NULL, status VARCHAR(256) NOT NULL, PRIMARY KEY(id))");
|
DBManager.createTable(db, "CREATE TABLE IF NOT EXISTS attraction (id VARCHAR(256) NOT NULL, name VARCHAR(256) NOT NULL, region_id VARCHAR(256) NOT NULL, type VARCHAR(256) NOT NULL, status VARCHAR(256) NOT NULL, PRIMARY KEY(id))");
|
||||||
DBManager.createTable(db, "CREATE TABLE IF NOT EXISTS region (id VARCHAR(256) NOT NULL, name VARCHAR(256) NOT NULL, PRIMARY KEY(id))");
|
DBManager.createTable(db, "CREATE TABLE IF NOT EXISTS region (id VARCHAR(256) NOT NULL, name VARCHAR(256) NOT NULL, PRIMARY KEY(id))");
|
||||||
DBManager.createTable(db, "CREATE TABLE IF NOT EXISTS status (statusId VARCHAR(256) NOT NULL, statusName VARCHAR(256) NOT NULL)");
|
DBManager.createTable(db, "CREATE TABLE IF NOT EXISTS status (statusId VARCHAR(256) NOT NULL, statusName VARCHAR(256) NOT NULL, PRIMARY KEY(statusId))");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadWorkers() {
|
private void loadWorkers() {
|
||||||
|
@ -88,6 +95,7 @@ public class ThemeParkPlugin extends JavaPlugin {
|
||||||
pm.registerEvents(new PlayerListener(), this);
|
pm.registerEvents(new PlayerListener(), this);
|
||||||
pm.registerEvents(new AttractionListener(), this);
|
pm.registerEvents(new AttractionListener(), this);
|
||||||
pm.registerEvents(new RegionListener(), this);
|
pm.registerEvents(new RegionListener(), this);
|
||||||
|
pm.registerEvents(new SignListener(), this);
|
||||||
MenuAPI.register(this);
|
MenuAPI.register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,9 +118,24 @@ public class ThemeParkPlugin extends JavaPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupTrainCarts() {
|
||||||
|
try {
|
||||||
|
Plugin plugin = Bukkit.getPluginManager().getPlugin("Train_Carts");
|
||||||
|
if (plugin != null && plugin.isEnabled()) {
|
||||||
|
Class<?> clazz = Class.forName("com.bergerkiller.bukkit.tc.signactions.SignAction");
|
||||||
|
Class<?> sign = Class.forName("nl.iobyte.themepark.traincarts.TCRideCount");
|
||||||
|
Method method = clazz.getMethod("register", clazz);
|
||||||
|
method.invoke(clazz, sign.newInstance());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("["+getName()+"] TrainCarts not found!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
threader.stop();
|
threader.stop();
|
||||||
DBManager.shutdown();
|
DBManager.shutdown();
|
||||||
|
SignManager.saveSigns();
|
||||||
instance = null;
|
instance = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,4 +159,8 @@ public class ThemeParkPlugin extends JavaPlugin {
|
||||||
return regions;
|
return regions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public YamlConfig getSigns() {
|
||||||
|
return signs;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
package nl.iobyte.themepark.api;
|
package nl.iobyte.themepark.api;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.ThemeParkPlugin;
|
||||||
import nl.iobyte.themepark.api.attraction.Attraction;
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
import nl.iobyte.themepark.api.attraction.Region;
|
import nl.iobyte.themepark.api.attraction.Region;
|
||||||
|
import nl.iobyte.themepark.api.events.attraction.CreateAttractionEvent;
|
||||||
|
import nl.iobyte.themepark.api.events.attraction.RemoveAttractionEvent;
|
||||||
|
import nl.iobyte.themepark.api.events.region.CreateRegionEvent;
|
||||||
|
import nl.iobyte.themepark.api.events.region.RemoveRegionEvent;
|
||||||
import nl.iobyte.themepark.api.ridecount.CountManager;
|
import nl.iobyte.themepark.api.ridecount.CountManager;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
|
@ -16,6 +22,13 @@ public class API {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
regions.put(region.getId(), region);
|
regions.put(region.getId(), region);
|
||||||
|
|
||||||
|
CreateRegionEvent e = new CreateRegionEvent(region);
|
||||||
|
if(Bukkit.isPrimaryThread()) {
|
||||||
|
Bukkit.getPluginManager().callEvent(e);
|
||||||
|
} else {
|
||||||
|
Bukkit.getScheduler().runTask(ThemeParkPlugin.getInstance(), () -> Bukkit.getPluginManager().callEvent(e));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isRegion(String id) {
|
public static boolean isRegion(String id) {
|
||||||
|
@ -45,6 +58,13 @@ public class API {
|
||||||
attractions.remove(attraction.getId());
|
attractions.remove(attraction.getId());
|
||||||
|
|
||||||
regions.remove(id);
|
regions.remove(id);
|
||||||
|
|
||||||
|
RemoveRegionEvent e = new RemoveRegionEvent(region);
|
||||||
|
if(Bukkit.isPrimaryThread()) {
|
||||||
|
Bukkit.getPluginManager().callEvent(e);
|
||||||
|
} else {
|
||||||
|
Bukkit.getScheduler().runTask(ThemeParkPlugin.getInstance(), () -> Bukkit.getPluginManager().callEvent(e));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addAttraction(Attraction attraction) {
|
public static void addAttraction(Attraction attraction) {
|
||||||
|
@ -57,6 +77,13 @@ public class API {
|
||||||
getRegion(attraction.getRegionId()).addAttraction(attraction);
|
getRegion(attraction.getRegionId()).addAttraction(attraction);
|
||||||
attractions.put(attraction.getId(), attraction);
|
attractions.put(attraction.getId(), attraction);
|
||||||
CountManager.addCounter(attraction);
|
CountManager.addCounter(attraction);
|
||||||
|
|
||||||
|
CreateAttractionEvent e = new CreateAttractionEvent(attraction);
|
||||||
|
if(Bukkit.isPrimaryThread()) {
|
||||||
|
Bukkit.getPluginManager().callEvent(e);
|
||||||
|
} else {
|
||||||
|
Bukkit.getScheduler().runTask(ThemeParkPlugin.getInstance(), () -> Bukkit.getPluginManager().callEvent(e));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isAttraction(String id) {
|
public static boolean isAttraction(String id) {
|
||||||
|
@ -101,6 +128,13 @@ public class API {
|
||||||
|
|
||||||
attractions.remove(id);
|
attractions.remove(id);
|
||||||
CountManager.removeCounter(id);
|
CountManager.removeCounter(id);
|
||||||
|
|
||||||
|
RemoveAttractionEvent e = new RemoveAttractionEvent(attraction);
|
||||||
|
if(Bukkit.isPrimaryThread()) {
|
||||||
|
Bukkit.getPluginManager().callEvent(e);
|
||||||
|
} else {
|
||||||
|
Bukkit.getScheduler().runTask(ThemeParkPlugin.getInstance(), () -> Bukkit.getPluginManager().callEvent(e));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String color(String string) {
|
private static String color(String string) {
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class Attraction {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(this.location != null)
|
if(this.location != null)
|
||||||
if(loc.equals(LocationSerializer.toString(location)))
|
if(loc.equals(LocationSerializer.toString(this.location)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Location old = this.location;
|
Location old = this.location;
|
||||||
|
|
|
@ -13,7 +13,8 @@ import java.util.List;
|
||||||
|
|
||||||
public class Region {
|
public class Region {
|
||||||
|
|
||||||
private String id, name;
|
private final String id;
|
||||||
|
private String name;
|
||||||
private Material material;
|
private Material material;
|
||||||
private short data;
|
private short data;
|
||||||
private List<String> lore;
|
private List<String> lore;
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
package nl.iobyte.themepark.api.events.attraction;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class CreateAttractionEvent extends Event {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
private Attraction attraction;
|
||||||
|
|
||||||
|
public CreateAttractionEvent(Attraction attraction) {
|
||||||
|
this.attraction = attraction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Attraction getAttraction() {
|
||||||
|
return attraction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package nl.iobyte.themepark.api.events.attraction;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class RemoveAttractionEvent extends Event {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
private Attraction attraction;
|
||||||
|
|
||||||
|
public RemoveAttractionEvent(Attraction attraction) {
|
||||||
|
this.attraction = attraction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Attraction getAttraction() {
|
||||||
|
return attraction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package nl.iobyte.themepark.api.events.region;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.api.attraction.Region;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class CreateRegionEvent extends Event {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
private Region region;
|
||||||
|
|
||||||
|
public CreateRegionEvent(Region region) {
|
||||||
|
this.region = region;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Region getRegion() {
|
||||||
|
return region;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package nl.iobyte.themepark.api.events.region;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.api.attraction.Region;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class RemoveRegionEvent extends Event {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
private Region region;
|
||||||
|
|
||||||
|
public RemoveRegionEvent(Region region) {
|
||||||
|
this.region = region;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Region getRegion() {
|
||||||
|
return region;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
package nl.iobyte.themepark.api.events.ridecount;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class PreProcessCountEvent extends Event {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
private UUID uuid;
|
||||||
|
private Attraction attraction;
|
||||||
|
private int count;
|
||||||
|
|
||||||
|
public PreProcessCountEvent(UUID uuid, Attraction attraction, int count) {
|
||||||
|
this.uuid = uuid;
|
||||||
|
this.attraction = attraction;
|
||||||
|
this.count = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getUUID() {
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Attraction getAttraction() {
|
||||||
|
return attraction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCount() {
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCount(int count) {
|
||||||
|
this.count = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ package nl.iobyte.themepark.api.ridecount;
|
||||||
|
|
||||||
import nl.iobyte.themepark.api.attraction.Attraction;
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
import nl.iobyte.themepark.api.events.ridecount.ChangeCountEvent;
|
import nl.iobyte.themepark.api.events.ridecount.ChangeCountEvent;
|
||||||
|
import nl.iobyte.themepark.api.events.ridecount.PreProcessCountEvent;
|
||||||
import nl.iobyte.themepark.api.events.ridecount.SetCountEvent;
|
import nl.iobyte.themepark.api.events.ridecount.SetCountEvent;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
@ -75,6 +76,7 @@ public class AttractionCount {
|
||||||
public void setCount(UUID uuid, int amount) {
|
public void setCount(UUID uuid, int amount) {
|
||||||
RideCount count = getCount(uuid);
|
RideCount count = getCount(uuid);
|
||||||
|
|
||||||
|
int before = 0;
|
||||||
if(count == null) {
|
if(count == null) {
|
||||||
count = new RideCount(uuid, attraction, amount);
|
count = new RideCount(uuid, attraction, amount);
|
||||||
counts.put(uuid, count);
|
counts.put(uuid, count);
|
||||||
|
@ -82,11 +84,12 @@ public class AttractionCount {
|
||||||
if(count.getCount() == amount)
|
if(count.getCount() == amount)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int before = count.getCount();
|
before = count.getCount();
|
||||||
count.setCount(amount);
|
count.setCount(amount);
|
||||||
|
}
|
||||||
|
|
||||||
SetCountEvent e = new SetCountEvent(attraction, this, uuid, before, amount);
|
SetCountEvent e = new SetCountEvent(attraction, this, uuid, before, amount);
|
||||||
Bukkit.getPluginManager().callEvent(e);
|
Bukkit.getPluginManager().callEvent(e);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import nl.iobyte.themepark.api.attraction.component.Status;
|
||||||
import nl.iobyte.themepark.api.attraction.component.Type;
|
import nl.iobyte.themepark.api.attraction.component.Type;
|
||||||
import nl.iobyte.themepark.api.attraction.manager.StatusManager;
|
import nl.iobyte.themepark.api.attraction.manager.StatusManager;
|
||||||
import nl.iobyte.themepark.api.utils.ItemBuilder;
|
import nl.iobyte.themepark.api.utils.ItemBuilder;
|
||||||
import nl.iobyte.themepark.api.utils.LocationSerializer;
|
|
||||||
import nl.iobyte.themepark.config.YamlConfig;
|
import nl.iobyte.themepark.config.YamlConfig;
|
||||||
import nl.iobyte.themepark.menu.AttractionLoader;
|
import nl.iobyte.themepark.menu.AttractionLoader;
|
||||||
import nl.iobyte.themepark.menu.AttractionMenu;
|
import nl.iobyte.themepark.menu.AttractionMenu;
|
||||||
|
@ -27,7 +26,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
public class MainCommand extends BukkitCommand {
|
public class MainCommand extends BukkitCommand {
|
||||||
|
|
||||||
private String name;
|
private final String name;
|
||||||
|
|
||||||
public MainCommand(String name) {
|
public MainCommand(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
|
@ -49,10 +48,12 @@ public class MainCommand extends BukkitCommand {
|
||||||
if(sender.hasPermission("themepark.admin")) {
|
if(sender.hasPermission("themepark.admin")) {
|
||||||
sender.sendMessage(Color.color("&f/" + name + " region create <id> <name>"));
|
sender.sendMessage(Color.color("&f/" + name + " region create <id> <name>"));
|
||||||
sender.sendMessage(Color.color("&f/" + name + " region name <id> <name>"));
|
sender.sendMessage(Color.color("&f/" + name + " region name <id> <name>"));
|
||||||
sender.sendMessage(Color.color("&f/" + name + " attraction create <region> <id> <name>"));
|
sender.sendMessage(Color.color("&f/" + name + " region remove <id>"));
|
||||||
|
sender.sendMessage(Color.color("&f/" + name + " attraction create <region> <id> <RIDE/SHOW/GLOBAL> <name>"));
|
||||||
sender.sendMessage(Color.color("&f/" + name + " attraction name <id> <name>"));
|
sender.sendMessage(Color.color("&f/" + name + " attraction name <id> <name>"));
|
||||||
sender.sendMessage(Color.color("&f/" + name + " attraction status <id> <status>"));
|
sender.sendMessage(Color.color("&f/" + name + " attraction status <id> <status>"));
|
||||||
sender.sendMessage(Color.color("&f/" + name + " attraction location <id>"));
|
sender.sendMessage(Color.color("&f/" + name + " attraction location <id>"));
|
||||||
|
sender.sendMessage(Color.color("&f/" + name + " attraction remove <id>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -103,6 +104,9 @@ public class MainCommand extends BukkitCommand {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(attraction.getLocation() == null)
|
||||||
|
return true;
|
||||||
|
|
||||||
player.teleport(attraction.getLocation());
|
player.teleport(attraction.getLocation());
|
||||||
if(player.isInsideVehicle())
|
if(player.isInsideVehicle())
|
||||||
if(player.getVehicle() instanceof Minecart)
|
if(player.getVehicle() instanceof Minecart)
|
||||||
|
@ -247,6 +251,26 @@ public class MainCommand extends BukkitCommand {
|
||||||
sender.sendMessage(Color.color(MessageUtil.getMessage("region.name").replace("{name}", region.getName())));
|
sender.sendMessage(Color.color(MessageUtil.getMessage("region.name").replace("{name}", region.getName())));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(args[1].equalsIgnoreCase("remove")) {
|
||||||
|
if (args.length < 3 ) {
|
||||||
|
sender.sendMessage(Color.color("&f/" + name + " region remove <id>"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String id = args[2];
|
||||||
|
if(!API.isRegion(id)) {
|
||||||
|
String message = MessageUtil.getMessage("region.not");
|
||||||
|
message = message.replace("{id}", id);
|
||||||
|
sender.sendMessage(Color.color(message));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Region region = API.getRegion(id);
|
||||||
|
API.removeRegion(id);
|
||||||
|
sender.sendMessage(Color.color(MessageUtil.getMessage("region.remove").replace("{name}", region.getName())));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("attraction")) {
|
if (args[0].equalsIgnoreCase("attraction")) {
|
||||||
|
@ -255,7 +279,7 @@ public class MainCommand extends BukkitCommand {
|
||||||
|
|
||||||
if (args[1].equalsIgnoreCase("create")) {
|
if (args[1].equalsIgnoreCase("create")) {
|
||||||
if (args.length < 6 ) {
|
if (args.length < 6 ) {
|
||||||
sender.sendMessage(Color.color(MessageUtil.getMessage("prefix")+" &4/" + name + " attraction create <region> <id> <type> <name>"));
|
sender.sendMessage(Color.color(MessageUtil.getMessage("prefix")+" &4/" + name + " attraction create <region> <id> <RIDE/SHOW/GLOBAL> <name>"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,10 +314,14 @@ public class MainCommand extends BukkitCommand {
|
||||||
|
|
||||||
String name = builder.toString();
|
String name = builder.toString();
|
||||||
Attraction attraction = new Attraction(args[3], name, args[2], null, type, type.getDefault());
|
Attraction attraction = new Attraction(args[3], name, args[2], null, type, type.getDefault());
|
||||||
API.addAttraction(attraction);
|
|
||||||
AttractionMenu.load();
|
|
||||||
|
|
||||||
YamlConfig config = AttractionLoader.getConfig(attraction.getRegionId());
|
YamlConfig config = AttractionLoader.getConfig(attraction.getRegionId());
|
||||||
|
if(config == null) {
|
||||||
|
String prefix = MessageUtil.getMessage("prefix");
|
||||||
|
String message = prefix+ " &4There was a problem when trying to save the attraction.";
|
||||||
|
sender.sendMessage(Color.color(message));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
FileConfiguration fc = config.getConfig();
|
FileConfiguration fc = config.getConfig();
|
||||||
String path = "attractions."+attraction.getId()+".";
|
String path = "attractions."+attraction.getId()+".";
|
||||||
fc.set(path+"name", attraction.getName());
|
fc.set(path+"name", attraction.getName());
|
||||||
|
@ -301,6 +329,8 @@ public class MainCommand extends BukkitCommand {
|
||||||
fc.set(path+"status", attraction.getStatus().toString());
|
fc.set(path+"status", attraction.getStatus().toString());
|
||||||
config.save();
|
config.save();
|
||||||
|
|
||||||
|
API.addAttraction(attraction);
|
||||||
|
AttractionMenu.load();
|
||||||
sender.sendMessage(Color.color(MessageUtil.getMessage("attraction.create").replace("{name}", name)));
|
sender.sendMessage(Color.color(MessageUtil.getMessage("attraction.create").replace("{name}", name)));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -395,6 +425,26 @@ public class MainCommand extends BukkitCommand {
|
||||||
sender.sendMessage(Color.color(MessageUtil.getMessage("attraction.location").replace("{name}", attraction.getName())));
|
sender.sendMessage(Color.color(MessageUtil.getMessage("attraction.location").replace("{name}", attraction.getName())));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(args[1].equalsIgnoreCase("remove")) {
|
||||||
|
if (args.length < 3 ) {
|
||||||
|
sender.sendMessage(Color.color("&f/" + name + " attraction remove <id>"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String id = args[2];
|
||||||
|
if(!API.isAttraction(id)) {
|
||||||
|
String message = MessageUtil.getMessage("attraction.not");
|
||||||
|
message = message.replace("{id}", id);
|
||||||
|
sender.sendMessage(Color.color(message));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Attraction attraction = API.getAttraction(id);
|
||||||
|
API.removeAttraction(id);
|
||||||
|
sender.sendMessage(Color.color(MessageUtil.getMessage("attraction.remove").replace("{name}", attraction.getName())));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1,25 +1,42 @@
|
||||||
package nl.iobyte.themepark.command;
|
package nl.iobyte.themepark.command;
|
||||||
|
|
||||||
import nl.iobyte.menuapi.map.WeakConcurrentHashMap;
|
import nl.iobyte.menuapi.map.WeakConcurrentHashMap;
|
||||||
|
import nl.iobyte.themepark.ThemeParkPlugin;
|
||||||
import nl.iobyte.themepark.api.API;
|
import nl.iobyte.themepark.api.API;
|
||||||
import nl.iobyte.themepark.api.attraction.Attraction;
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
|
import nl.iobyte.themepark.api.events.ridecount.ChangeCountEvent;
|
||||||
|
import nl.iobyte.themepark.api.events.ridecount.PreProcessCountEvent;
|
||||||
|
import nl.iobyte.themepark.api.ridecount.AttractionCount;
|
||||||
|
import nl.iobyte.themepark.api.ridecount.CountManager;
|
||||||
import nl.iobyte.themepark.ridecount.RideCountAPI;
|
import nl.iobyte.themepark.ridecount.RideCountAPI;
|
||||||
import nl.iobyte.themepark.util.Color;
|
import nl.iobyte.themepark.util.Color;
|
||||||
import nl.iobyte.themepark.util.MessageUtil;
|
import nl.iobyte.themepark.util.MessageUtil;
|
||||||
|
import nl.iobyte.themepark.util.SpigotPlayerSelector;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
public class RidecountCommand implements CommandExecutor {
|
public class RidecountCommand implements CommandExecutor {
|
||||||
|
|
||||||
private static WeakConcurrentHashMap<String, String> data = new WeakConcurrentHashMap<>(5 * 60 * 1000);
|
private static final WeakConcurrentHashMap<String, String> data = new WeakConcurrentHashMap<>(5 * 60 * 1000);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
if(!cmd.getName().equalsIgnoreCase("ridecount"))
|
if(!cmd.getName().equalsIgnoreCase("ridecount"))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if(!sender.hasPermission("themepark.admin")) {
|
||||||
|
sender.sendMessage(Color.color(MessageUtil.getMessage("nopermission")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if(args.length == 0 || args[0].equalsIgnoreCase("help")) {
|
if(args.length == 0 || args[0].equalsIgnoreCase("help")) {
|
||||||
sender.sendMessage(Color.color("&f&L>==== &r&6Ridecount &L&f ====<"));
|
sender.sendMessage(Color.color("&f&L>==== &r&6Ridecount &L&f ====<"));
|
||||||
sender.sendMessage(Color.color("&f/ridecount help"));
|
sender.sendMessage(Color.color("&f/ridecount help"));
|
||||||
|
@ -76,24 +93,50 @@ public class RidecountCommand implements CommandExecutor {
|
||||||
|
|
||||||
int amount = Integer.parseInt(args[3]);
|
int amount = Integer.parseInt(args[3]);
|
||||||
Attraction attraction = API.getAttraction(args[2]);
|
Attraction attraction = API.getAttraction(args[2]);
|
||||||
RideCountAPI.addCount(args[1], attraction, amount).thenAccept(result -> {
|
|
||||||
if(!result) {
|
AtomicBoolean b = new AtomicBoolean(false);
|
||||||
sender.sendMessage(Color.color(MessageUtil.getMessage("noplayer").replace("{name}", args[1])));
|
List<UUID> ids = executeArg(sender, args[1]);
|
||||||
|
|
||||||
|
AttractionCount count = CountManager.getCounter(attraction.getId());
|
||||||
|
for(UUID uuid : ids) {
|
||||||
|
PreProcessCountEvent event = new PreProcessCountEvent(uuid, attraction, amount);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
|
||||||
|
int u_amount = event.getCount();
|
||||||
|
RideCountAPI.getCount(uuid, attraction).thenAccept(before -> RideCountAPI.addCount(uuid, attraction, u_amount).thenAccept(result -> {
|
||||||
|
if (!result)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if(count == null || !count.hasCount(uuid)) {
|
||||||
|
Bukkit.getScheduler().runTask(ThemeParkPlugin.getInstance(), () -> {
|
||||||
|
ChangeCountEvent e = new ChangeCountEvent(attraction, count, uuid, before, before + u_amount);
|
||||||
|
Bukkit.getPluginManager().callEvent(e);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(b.get())
|
||||||
|
return;
|
||||||
|
|
||||||
|
b.set(true);
|
||||||
String mesage = MessageUtil.getMessage("ridecount.add");
|
String mesage = MessageUtil.getMessage("ridecount.add");
|
||||||
mesage = mesage.replace("{name}", API.getAttraction(args[2]).getName());
|
mesage = mesage.replace("{name}", API.getAttraction(args[2]).getName());
|
||||||
mesage = mesage.replace("{count}", Integer.toString(amount));
|
mesage = mesage.replace("{count}", Integer.toString(u_amount));
|
||||||
sender.sendMessage(Color.color(mesage));
|
sender.sendMessage(Color.color(mesage));
|
||||||
});
|
}));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<UUID> executeArg(CommandSender sender, String arg) {
|
||||||
|
List<UUID> array = new ArrayList<>();
|
||||||
|
for(Player p : new SpigotPlayerSelector(arg).getPlayers(sender))
|
||||||
|
array.add(p.getUniqueId());
|
||||||
|
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isInteger(String s) {
|
private boolean isInteger(String s) {
|
||||||
int radix = 10;
|
int radix = 10;
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
package nl.iobyte.themepark.database;
|
package nl.iobyte.themepark.database;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.*;
|
||||||
import java.sql.PreparedStatement;
|
import java.util.ArrayList;
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public abstract class DB {
|
public abstract class DB {
|
||||||
|
|
||||||
public abstract Connection getConnection();
|
public abstract Connection getConnection() throws SQLException;
|
||||||
|
|
||||||
public abstract void closeConnection();
|
public abstract void closeConnection();
|
||||||
|
|
||||||
|
@ -16,62 +15,72 @@ public abstract class DB {
|
||||||
if(query == null || query.isEmpty())
|
if(query == null || query.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(getConnection() == null)
|
boolean b = false;
|
||||||
return false;
|
try(Connection conn = getConnection()) {
|
||||||
|
PreparedStatement statement = conn.prepareStatement(query);
|
||||||
try {
|
|
||||||
PreparedStatement statement = getConnection().prepareStatement(query);
|
|
||||||
statement.closeOnCompletion();
|
statement.closeOnCompletion();
|
||||||
if(objects != null)
|
if(objects != null)
|
||||||
for(Map.Entry<Integer, Object> entry : objects.entrySet())
|
for(Map.Entry<Integer, Object> entry : objects.entrySet())
|
||||||
statement.setObject(entry.getKey(), entry.getValue());
|
statement.setObject(entry.getKey(), entry.getValue());
|
||||||
|
|
||||||
return statement.execute();
|
b = statement.execute();
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int executeUpdate(String query, HashMap<Integer, Object> objects) {
|
public int executeUpdate(String query, HashMap<Integer, Object> objects) {
|
||||||
if (query == null || query.isEmpty())
|
if (query == null || query.isEmpty())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if(getConnection() == null)
|
int i = 0;
|
||||||
return 0;
|
try(Connection conn = getConnection()) {
|
||||||
|
PreparedStatement statement = conn.prepareStatement(query);
|
||||||
try {
|
|
||||||
PreparedStatement statement = getConnection().prepareStatement(query);
|
|
||||||
statement.closeOnCompletion();
|
statement.closeOnCompletion();
|
||||||
for (Map.Entry<Integer, Object> entry : objects.entrySet())
|
for (Map.Entry<Integer, Object> entry : objects.entrySet())
|
||||||
statement.setObject(entry.getKey(), entry.getValue());
|
statement.setObject(entry.getKey(), entry.getValue());
|
||||||
|
|
||||||
return statement.executeUpdate();
|
i = statement.executeUpdate();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResultSet executeQuery(String query, HashMap<Integer, Object> objects) {
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<HashMap<String, Object>> executeQuery(String query, HashMap<Integer, Object> objects) {
|
||||||
if (query == null || query.isEmpty())
|
if (query == null || query.isEmpty())
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (getConnection() == null)
|
ArrayList<HashMap<String, Object>> set = null;
|
||||||
return null;
|
try(Connection conn = getConnection()) {
|
||||||
|
PreparedStatement statement = conn.prepareStatement(query);
|
||||||
try {
|
|
||||||
PreparedStatement statement = getConnection().prepareStatement(query);
|
|
||||||
statement.closeOnCompletion();
|
statement.closeOnCompletion();
|
||||||
if (objects != null)
|
if (objects != null)
|
||||||
for (Map.Entry<Integer, Object> entry : objects.entrySet())
|
for (Map.Entry<Integer, Object> entry : objects.entrySet())
|
||||||
statement.setObject(entry.getKey(), entry.getValue());
|
statement.setObject(entry.getKey(), entry.getValue());
|
||||||
|
|
||||||
return statement.executeQuery();
|
set = new ArrayList<>();
|
||||||
|
|
||||||
|
ResultSet result = statement.executeQuery();
|
||||||
|
ResultSetMetaData metadata = result.getMetaData();
|
||||||
|
int columnCount = metadata.getColumnCount();
|
||||||
|
while(result.next()) {
|
||||||
|
HashMap<String, Object> map = new HashMap<>();
|
||||||
|
for(int i = 1; i <= columnCount; i++)
|
||||||
|
map.put(metadata.getColumnName(i), result.getObject(i));
|
||||||
|
|
||||||
|
set.add(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
result.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,14 +77,7 @@ public class DBManager {
|
||||||
if(db == null || query == null || query.isEmpty())
|
if(db == null || query == null || query.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
try {
|
db.execute(query, null);
|
||||||
Connection connection = db.getConnection();
|
|
||||||
PreparedStatement statement = connection.prepareStatement(query);
|
|
||||||
statement.execute();
|
|
||||||
statement.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -5,48 +5,35 @@ import com.zaxxer.hikari.HikariDataSource;
|
||||||
import nl.iobyte.themepark.ThemeParkPlugin;
|
import nl.iobyte.themepark.ThemeParkPlugin;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
public class MySQL extends DB {
|
public class MySQL extends DB {
|
||||||
|
|
||||||
private String dbName;
|
private String dbName;
|
||||||
private HikariDataSource source;
|
private HikariDataSource source;
|
||||||
private Connection con;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize a new connection
|
* Initialize a new connection
|
||||||
*
|
*
|
||||||
* @param dbName The database name
|
* @param dbName The database name
|
||||||
*/
|
*/
|
||||||
public MySQL(String host, int port, String dbName, String username, String password) {
|
public MySQL(String url, String host, int port, String dbName, String username, String password) {
|
||||||
this.dbName = dbName;
|
this.dbName = dbName;
|
||||||
HikariConfig config = new HikariConfig();
|
HikariConfig config = new HikariConfig();
|
||||||
config.setPoolName(ThemeParkPlugin.getInstance().getName());
|
config.setPoolName(ThemeParkPlugin.getInstance().getName());
|
||||||
config.setUsername(username);
|
config.setUsername(username);
|
||||||
config.setPassword(password);
|
config.setPassword(password);
|
||||||
config.setDriverClassName("com.mysql.jdbc.Driver");
|
config.setDriverClassName("com.mysql.jdbc.Driver");
|
||||||
config.setConnectionTestQuery("SELECT 1");
|
config.setMaximumPoolSize(10);
|
||||||
config.setMaximumPoolSize(1);
|
config.setJdbcUrl(url.replace("%host%", host).replace("%port%", String.valueOf(port)).replace("%database%", dbName));
|
||||||
|
|
||||||
Properties prop = new Properties();
|
|
||||||
prop.setProperty("date_string_format", "yyyy-MM-dd HH:mm:ss");
|
|
||||||
config.setJdbcUrl("jdbc:mysql://"+host+":"+port+"/"+dbName);
|
|
||||||
config.setDataSourceProperties(prop);
|
|
||||||
source = new HikariDataSource(config);
|
source = new HikariDataSource(config);
|
||||||
|
|
||||||
try {
|
|
||||||
con = source.getConnection();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get connection
|
* Get connection
|
||||||
* @return Connection Instance
|
* @return Connection Instance
|
||||||
*/
|
*/
|
||||||
public Connection getConnection() {
|
public Connection getConnection() throws SQLException {
|
||||||
return con;
|
return source.getConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,12 +41,6 @@ public class MySQL extends DB {
|
||||||
*/
|
*/
|
||||||
public void closeConnection() {
|
public void closeConnection() {
|
||||||
System.out.println("Closing the database connection for " + dbName + ".db!");
|
System.out.println("Closing the database connection for " + dbName + ".db!");
|
||||||
try {
|
|
||||||
con.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
source.close();
|
source.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,14 +6,16 @@ import nl.iobyte.themepark.ThemeParkPlugin;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
public class SQLite extends DB {
|
public class SQLite extends DB {
|
||||||
|
|
||||||
private String dbName;
|
private String dbName, v;
|
||||||
private HikariDataSource source;
|
private HikariDataSource source;
|
||||||
private Connection con;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize a new connection
|
* Initialize a new connection
|
||||||
|
@ -43,7 +45,7 @@ public class SQLite extends DB {
|
||||||
config.setPassword(null);
|
config.setPassword(null);
|
||||||
config.setDriverClassName("org.sqlite.JDBC");
|
config.setDriverClassName("org.sqlite.JDBC");
|
||||||
config.setConnectionTestQuery("SELECT 1");
|
config.setConnectionTestQuery("SELECT 1");
|
||||||
config.setMaximumPoolSize(1);
|
config.setMaximumPoolSize(5);
|
||||||
|
|
||||||
Properties prop = new Properties();
|
Properties prop = new Properties();
|
||||||
prop.setProperty("date_string_format", "yyyy-MM-dd HH:mm:ss");
|
prop.setProperty("date_string_format", "yyyy-MM-dd HH:mm:ss");
|
||||||
|
@ -52,19 +54,37 @@ public class SQLite extends DB {
|
||||||
config.setDataSourceProperties(prop);
|
config.setDataSourceProperties(prop);
|
||||||
source = new HikariDataSource(config);
|
source = new HikariDataSource(config);
|
||||||
|
|
||||||
try {
|
try(Connection conn = getConnection()) {
|
||||||
con = source.getConnection();
|
PreparedStatement statement = conn.prepareStatement("SELECT sqlite_version() AS version");
|
||||||
} catch (SQLException e) {
|
statement.closeOnCompletion();
|
||||||
|
|
||||||
|
ResultSet set = statement.executeQuery();
|
||||||
|
while(set.next()) {
|
||||||
|
v = set.getString("version");
|
||||||
|
}
|
||||||
|
|
||||||
|
set.close();
|
||||||
|
} catch(Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(v == null) {
|
||||||
|
System.out.println("Unable to get SQLite version.");
|
||||||
|
} else {
|
||||||
|
System.out.println("SQLite database running on version: "+v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVersion() {
|
||||||
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get connection
|
* Get connection
|
||||||
* @return Connection Instance
|
* @return Connection Instance
|
||||||
*/
|
*/
|
||||||
public Connection getConnection() {
|
public Connection getConnection() throws SQLException {
|
||||||
return con;
|
return source.getConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,12 +92,6 @@ public class SQLite extends DB {
|
||||||
*/
|
*/
|
||||||
public void closeConnection() {
|
public void closeConnection() {
|
||||||
System.out.println("Closing the database connection for " + dbName + ".db!");
|
System.out.println("Closing the database connection for " + dbName + ".db!");
|
||||||
try {
|
|
||||||
con.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
source.close();
|
source.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
54
src/main/java/nl/iobyte/themepark/dynmap/MapMarker.java
Normal file
54
src/main/java/nl/iobyte/themepark/dynmap/MapMarker.java
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
package nl.iobyte.themepark.dynmap;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
|
import nl.iobyte.themepark.util.Color;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.dynmap.DynmapAPI;
|
||||||
|
import org.dynmap.markers.MarkerAPI;
|
||||||
|
import org.dynmap.markers.MarkerSet;
|
||||||
|
|
||||||
|
public class MapMarker {
|
||||||
|
|
||||||
|
private MarkerAPI markerApi;
|
||||||
|
private MarkerSet markerSet;
|
||||||
|
|
||||||
|
private static MapMarker marker = new MapMarker();
|
||||||
|
public static MapMarker getMarker() { return marker; }
|
||||||
|
|
||||||
|
private MapMarker() {
|
||||||
|
DynmapAPI api = (DynmapAPI) Bukkit.getServer().getPluginManager().getPlugin("dynmap");
|
||||||
|
if(api == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
markerApi = api.getMarkerAPI();
|
||||||
|
markerSet = markerApi.createMarkerSet("themepark_attractions", "Attractions", api.getMarkerAPI().getMarkerIcons(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAttractionMarker(Attraction attraction) {
|
||||||
|
if(markerSet == null || attraction == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Location loc = attraction.getLocation();
|
||||||
|
if(loc == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(markerSet.findMarker(attraction.getId()) == null) {
|
||||||
|
markerSet.createMarker(attraction.getId(), ChatColor.stripColor(Color.color(attraction.getName())), loc.getWorld().getName(), loc.getX(), loc.getY(), loc.getZ(), markerApi.getMarkerIcon("minecart"), true);
|
||||||
|
} else {
|
||||||
|
markerSet.findMarker(attraction.getId()).setLocation(loc.getWorld().getName(), loc.getX(), loc.getY(), loc.getZ());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeAttractionMarker(Attraction attraction) {
|
||||||
|
if(markerSet == null || attraction == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(markerSet.findMarker(attraction.getId()) == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
markerSet.getMarkers().remove(markerSet.findMarker(attraction.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -6,16 +6,14 @@ import net.md_5.bungee.api.chat.HoverEvent;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import nl.iobyte.themepark.ThemeParkPlugin;
|
import nl.iobyte.themepark.ThemeParkPlugin;
|
||||||
import nl.iobyte.themepark.api.attraction.Attraction;
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
import nl.iobyte.themepark.api.events.attraction.ChangeLocationEvent;
|
import nl.iobyte.themepark.api.events.attraction.*;
|
||||||
import nl.iobyte.themepark.api.events.attraction.ChangeNameEvent;
|
|
||||||
import nl.iobyte.themepark.api.events.attraction.ChangeStatusEvent;
|
|
||||||
import nl.iobyte.themepark.api.events.attraction.ChangeTypeEvent;
|
|
||||||
import nl.iobyte.themepark.api.utils.LocationSerializer;
|
import nl.iobyte.themepark.api.utils.LocationSerializer;
|
||||||
import nl.iobyte.themepark.config.YamlConfig;
|
import nl.iobyte.themepark.config.YamlConfig;
|
||||||
import nl.iobyte.themepark.database.DB;
|
|
||||||
import nl.iobyte.themepark.database.DBManager;
|
import nl.iobyte.themepark.database.DBManager;
|
||||||
|
import nl.iobyte.themepark.dynmap.MapMarker;
|
||||||
import nl.iobyte.themepark.menu.AttractionLoader;
|
import nl.iobyte.themepark.menu.AttractionLoader;
|
||||||
import nl.iobyte.themepark.menu.AttractionMenu;
|
import nl.iobyte.themepark.menu.AttractionMenu;
|
||||||
|
import nl.iobyte.themepark.sign.SignManager;
|
||||||
import nl.iobyte.themepark.util.Color;
|
import nl.iobyte.themepark.util.Color;
|
||||||
import nl.iobyte.themepark.util.MessageUtil;
|
import nl.iobyte.themepark.util.MessageUtil;
|
||||||
import nl.iobyte.workchain.components.Work;
|
import nl.iobyte.workchain.components.Work;
|
||||||
|
@ -29,6 +27,36 @@ import java.util.HashMap;
|
||||||
|
|
||||||
public class AttractionListener implements Listener {
|
public class AttractionListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onCreate(CreateAttractionEvent e) {
|
||||||
|
if(AttractionLoader.loading)
|
||||||
|
return;
|
||||||
|
|
||||||
|
AttractionMenu.load();
|
||||||
|
|
||||||
|
Attraction attraction = e.getAttraction();
|
||||||
|
String config_path = "attractions." + attraction.getId();
|
||||||
|
YamlConfig yc = AttractionLoader.getConfig(attraction.getRegionId());
|
||||||
|
FileConfiguration config = yc.getConfig();
|
||||||
|
config.set(config_path+".name", attraction.getName());
|
||||||
|
config.set(config_path+".type", attraction.getType().toString());
|
||||||
|
config.set(config_path+".status", attraction.getStatus().toString());
|
||||||
|
config.set(config_path+".location", LocationSerializer.toString(attraction.getLocation()));
|
||||||
|
yc.save();
|
||||||
|
|
||||||
|
MapMarker.getMarker().setAttractionMarker(attraction);
|
||||||
|
Work.firstTask(() -> DBManager.getDatabase("public")).abortIfNull().lastTask(database -> {
|
||||||
|
HashMap<Integer, Object> obj = new HashMap<>();
|
||||||
|
obj.put(1, attraction.getId());
|
||||||
|
obj.put(2, attraction.getName());
|
||||||
|
obj.put(3, attraction.getRegionId());
|
||||||
|
obj.put(4, attraction.getType().toString());
|
||||||
|
obj.put(5, attraction.getStatus().toString());
|
||||||
|
|
||||||
|
database.execute("INSERT IGNORE INTO attraction(id, name, region_id, type, status) VALUES (?, ?, ?, ?, ?)", obj);
|
||||||
|
}).execute();
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onChange(ChangeStatusEvent e) {
|
public void onChange(ChangeStatusEvent e) {
|
||||||
AttractionMenu.updateAttraction(e.getAttraction());
|
AttractionMenu.updateAttraction(e.getAttraction());
|
||||||
|
@ -38,13 +66,12 @@ public class AttractionListener implements Listener {
|
||||||
config.getConfig().set("attractions." + attraction.getId() + ".status", e.getAfter().toString());
|
config.getConfig().set("attractions." + attraction.getId() + ".status", e.getAfter().toString());
|
||||||
config.save();
|
config.save();
|
||||||
|
|
||||||
|
SignManager.update(attraction);
|
||||||
Work.firstTask(() -> DBManager.getDatabase("public")).abortIfNull().lastTask(database -> {
|
Work.firstTask(() -> DBManager.getDatabase("public")).abortIfNull().lastTask(database -> {
|
||||||
HashMap<Integer, Object> obj = new HashMap<>();
|
HashMap<Integer, Object> obj = new HashMap<>();
|
||||||
obj.put(1, e.getAfter().toString());
|
obj.put(1, e.getAfter().toString());
|
||||||
obj.put(2, attraction.getId());
|
obj.put(2, attraction.getId());
|
||||||
|
database.execute("UPDATE attraction SET status=? WHERE id=?", obj);
|
||||||
String query ="UPDATE attraction SET status=? WHERE id=?";
|
|
||||||
database.execute(query, obj);
|
|
||||||
}).execute();
|
}).execute();
|
||||||
|
|
||||||
String command = ThemeParkPlugin.getInstance().getSettings().getConfig().getString("command");
|
String command = ThemeParkPlugin.getInstance().getSettings().getConfig().getString("command");
|
||||||
|
@ -75,14 +102,14 @@ public class AttractionListener implements Listener {
|
||||||
config.getConfig().set("attractions." + attraction.getId() + ".type", e.getAfter().toString());
|
config.getConfig().set("attractions." + attraction.getId() + ".type", e.getAfter().toString());
|
||||||
config.save();
|
config.save();
|
||||||
|
|
||||||
|
SignManager.update(attraction);
|
||||||
Work.firstTask(() -> DBManager.getDatabase("public")).abortIfNull().lastTask(database -> {
|
Work.firstTask(() -> DBManager.getDatabase("public")).abortIfNull().lastTask(database -> {
|
||||||
HashMap<Integer, Object> obj = new HashMap<>();
|
HashMap<Integer, Object> obj = new HashMap<>();
|
||||||
obj.put(1, e.getAfter().toString());
|
obj.put(1, e.getAfter().toString());
|
||||||
obj.put(2, attraction.getStatus().toString());
|
obj.put(2, attraction.getStatus().toString());
|
||||||
obj.put(3, attraction.getId());
|
obj.put(3, attraction.getId());
|
||||||
|
|
||||||
String query ="UPDATE attraction SET type=?, status=? WHERE id=?";
|
database.execute("UPDATE attraction SET type=?, status=? WHERE id=?", obj);
|
||||||
database.execute(query, obj);
|
|
||||||
}).execute();
|
}).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,13 +122,13 @@ public class AttractionListener implements Listener {
|
||||||
config.getConfig().set("attractions." + attraction.getId() + ".name", e.getAfter());
|
config.getConfig().set("attractions." + attraction.getId() + ".name", e.getAfter());
|
||||||
config.save();
|
config.save();
|
||||||
|
|
||||||
|
SignManager.update(attraction);
|
||||||
Work.firstTask(() -> DBManager.getDatabase("public")).abortIfNull().lastTask(database -> {
|
Work.firstTask(() -> DBManager.getDatabase("public")).abortIfNull().lastTask(database -> {
|
||||||
HashMap<Integer, Object> obj = new HashMap<>();
|
HashMap<Integer, Object> obj = new HashMap<>();
|
||||||
obj.put(1, e.getAfter());
|
obj.put(1, e.getAfter());
|
||||||
obj.put(2, attraction.getId());
|
obj.put(2, attraction.getId());
|
||||||
|
|
||||||
String query ="UPDATE attraction SET name=? WHERE id=?";
|
database.execute("UPDATE attraction SET name=? WHERE id=?", obj);
|
||||||
database.execute(query, obj);
|
|
||||||
}).execute();
|
}).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +139,30 @@ public class AttractionListener implements Listener {
|
||||||
config.getConfig().set("attractions." + attraction.getId() + ".location", LocationSerializer.toString(e.getAfter()));
|
config.getConfig().set("attractions." + attraction.getId() + ".location", LocationSerializer.toString(e.getAfter()));
|
||||||
config.save();
|
config.save();
|
||||||
|
|
||||||
//TODO MapMarker.getMarker().setAttractionMarker(attraction);
|
MapMarker.getMarker().setAttractionMarker(attraction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onRemove(RemoveAttractionEvent e) {
|
||||||
|
if(AttractionLoader.loading)
|
||||||
|
return;
|
||||||
|
|
||||||
|
AttractionMenu.load();
|
||||||
|
|
||||||
|
Attraction attraction = e.getAttraction();
|
||||||
|
String config_path = "attractions." + attraction.getId();
|
||||||
|
YamlConfig yc = AttractionLoader.getConfig(attraction.getRegionId());
|
||||||
|
FileConfiguration config = yc.getConfig();
|
||||||
|
config.set(config_path, null);
|
||||||
|
yc.save();
|
||||||
|
|
||||||
|
MapMarker.getMarker().removeAttractionMarker(attraction);
|
||||||
|
Work.firstTask(() -> DBManager.getDatabase("public")).abortIfNull().lastTask(database -> {
|
||||||
|
HashMap<Integer, Object> obj = new HashMap<>();
|
||||||
|
obj.put(1, attraction.getId());
|
||||||
|
|
||||||
|
database.execute("DELETE FROM attraction WHERE id=?", obj);
|
||||||
|
}).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,8 @@ import nl.iobyte.themepark.api.events.ridecount.ChangeCountEvent;
|
||||||
import nl.iobyte.themepark.api.ridecount.CountManager;
|
import nl.iobyte.themepark.api.ridecount.CountManager;
|
||||||
import nl.iobyte.themepark.api.utils.ItemBuilder;
|
import nl.iobyte.themepark.api.utils.ItemBuilder;
|
||||||
import nl.iobyte.themepark.config.YamlConfig;
|
import nl.iobyte.themepark.config.YamlConfig;
|
||||||
import nl.iobyte.themepark.database.DB;
|
|
||||||
import nl.iobyte.themepark.database.DBManager;
|
|
||||||
import nl.iobyte.themepark.menu.AttractionMenu;
|
import nl.iobyte.themepark.menu.AttractionMenu;
|
||||||
|
import nl.iobyte.themepark.ridecount.RideCountAPI;
|
||||||
import nl.iobyte.themepark.util.Color;
|
import nl.iobyte.themepark.util.Color;
|
||||||
import nl.iobyte.themepark.util.MessageUtil;
|
import nl.iobyte.themepark.util.MessageUtil;
|
||||||
import nl.iobyte.workchain.components.Work;
|
import nl.iobyte.workchain.components.Work;
|
||||||
|
@ -19,19 +18,38 @@ import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
import org.bukkit.event.player.*;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import java.sql.Connection;
|
import java.util.*;
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class PlayerListener implements Listener {
|
public class PlayerListener implements Listener {
|
||||||
|
|
||||||
|
private final boolean enabled, clear;
|
||||||
|
private final ItemStack menuItem;
|
||||||
|
private final List<String> worlds;
|
||||||
|
private final int slot;
|
||||||
|
|
||||||
|
public PlayerListener() {
|
||||||
|
YamlConfig settings = ThemeParkPlugin.getInstance().getSettings();
|
||||||
|
|
||||||
|
enabled = settings.getConfig().getBoolean("item.enabled");
|
||||||
|
clear = settings.getConfig().getBoolean("item.clear");
|
||||||
|
worlds = settings.getConfig().getStringList("item.worlds");
|
||||||
|
slot = settings.getConfig().getInt("item.slot");
|
||||||
|
|
||||||
|
Material material = Material.getMaterial(settings.getConfig().getString("item.material"));
|
||||||
|
short data = Short.parseShort(settings.getConfig().getString("item.data"));
|
||||||
|
String name = Color.color(settings.getConfig().getString("item.display-name"));
|
||||||
|
if(material != null && !name.isEmpty()) {
|
||||||
|
ItemBuilder builder = new ItemBuilder(material, 1, data);
|
||||||
|
builder.setName(name);
|
||||||
|
menuItem = builder.getItem();
|
||||||
|
} else {
|
||||||
|
menuItem = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onJoin(PlayerJoinEvent e) {
|
public void onJoin(PlayerJoinEvent e) {
|
||||||
Player player = e.getPlayer();
|
Player player = e.getPlayer();
|
||||||
|
@ -47,12 +65,11 @@ public class PlayerListener implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doItem(Player player) {
|
public void doItem(Player player) {
|
||||||
YamlConfig settings = ThemeParkPlugin.getInstance().getSettings();
|
|
||||||
YamlConfig config = ThemeParkPlugin.getInstance().getData();
|
YamlConfig config = ThemeParkPlugin.getInstance().getData();
|
||||||
|
|
||||||
CompletableFuture<ItemStack> fc = new CompletableFuture<>();
|
CompletableFuture<ItemStack> fc = new CompletableFuture<>();
|
||||||
Work.firstTask(() -> {
|
Work.firstTask(() -> {
|
||||||
if(!settings.getConfig().getBoolean("item.enabled"))
|
if(!enabled)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
boolean b = true;
|
boolean b = true;
|
||||||
|
@ -70,22 +87,13 @@ public class PlayerListener implements Listener {
|
||||||
if(!b)
|
if(!b)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
Material material = Material.getMaterial(settings.getConfig().getString("item.material"));
|
return menuItem;
|
||||||
short data = Short.parseShort(settings.getConfig().getString("item.data"));
|
|
||||||
String name = Color.color(settings.getConfig().getString("item.display-name"));
|
|
||||||
if(material == null || name.isEmpty())
|
|
||||||
return null;
|
|
||||||
|
|
||||||
ItemBuilder builder = new ItemBuilder(material, 1, data);
|
|
||||||
builder.setName(name);
|
|
||||||
return builder.getItem();
|
|
||||||
}).abortIfNull(() -> {
|
}).abortIfNull(() -> {
|
||||||
fc.complete(null);
|
fc.complete(null);
|
||||||
}).lastTask(item -> {
|
}).lastTask(item -> {
|
||||||
if(settings.getConfig().getBoolean("item.clear"))
|
if(clear)
|
||||||
player.getInventory().clear();
|
player.getInventory().clear();
|
||||||
|
|
||||||
List<String> worlds = settings.getConfig().getStringList("item.worlds");
|
|
||||||
if(worlds != null && !worlds.isEmpty()) {
|
if(worlds != null && !worlds.isEmpty()) {
|
||||||
if (worlds.contains(player.getLocation().getWorld().getName())) {
|
if (worlds.contains(player.getLocation().getWorld().getName())) {
|
||||||
fc.complete(new ItemStack(Material.AIR));
|
fc.complete(new ItemStack(Material.AIR));
|
||||||
|
@ -100,7 +108,6 @@ public class PlayerListener implements Listener {
|
||||||
if(item == null)
|
if(item == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int slot = settings.getConfig().getInt("item.slot");
|
|
||||||
player.getInventory().setItem(slot, item);
|
player.getInventory().setItem(slot, item);
|
||||||
player.updateInventory();
|
player.updateInventory();
|
||||||
});
|
});
|
||||||
|
@ -133,6 +140,28 @@ public class PlayerListener implements Listener {
|
||||||
AttractionMenu.open(player);
|
AttractionMenu.open(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onDrop(PlayerDropItemEvent e) {
|
||||||
|
if(menuItem == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Player player = e.getPlayer();
|
||||||
|
if(player.hasPermission("themepark.admin"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
ItemStack item = e.getItemDrop().getItemStack();
|
||||||
|
if(item.getType() != menuItem.getType())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(!item.hasItemMeta())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(item.getItemMeta().getDisplayName().equals(menuItem.getItemMeta().getDisplayName()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onQuit(PlayerQuitEvent e) {
|
public void onQuit(PlayerQuitEvent e) {
|
||||||
Player player = e.getPlayer();
|
Player player = e.getPlayer();
|
||||||
|
@ -143,33 +172,11 @@ public class PlayerListener implements Listener {
|
||||||
|
|
||||||
private void loadRideCount(UUID uuid) {
|
private void loadRideCount(UUID uuid) {
|
||||||
Work.firstTask(() -> {
|
Work.firstTask(() -> {
|
||||||
DB db = DBManager.getDatabase("data");
|
for(Attraction attraction : API.getAttractions().values())
|
||||||
if(db == null)
|
RideCountAPI.getCount(uuid, attraction).thenAccept(count -> Bukkit.getScheduler().runTask(ThemeParkPlugin.getInstance(), () -> CountManager.setCount(attraction, uuid, count)));
|
||||||
return null;
|
|
||||||
|
|
||||||
Connection connection = db.getConnection();
|
return true;
|
||||||
if(connection == null || connection.isClosed())
|
}).abortIfNull().lastTask(result -> {}).setFullExecute(true).execute();
|
||||||
return null;
|
|
||||||
|
|
||||||
PreparedStatement statement = connection.prepareStatement("SELECT points, attraction_id FROM counts WHERE uuid=?");
|
|
||||||
statement.setString(1, uuid.toString());
|
|
||||||
statement.closeOnCompletion();
|
|
||||||
return statement.executeQuery();
|
|
||||||
}).abortIfNull().lastTask(result -> {
|
|
||||||
while(result.next()) {
|
|
||||||
Attraction attraction = API.getAttraction(result.getString("attraction_id"));
|
|
||||||
if(attraction == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
int points = result.getInt("points");
|
|
||||||
if(points < 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
CountManager.setCount(attraction, uuid, points);
|
|
||||||
}
|
|
||||||
|
|
||||||
result.close();
|
|
||||||
}).setFullExecute(true).execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
|
|
@ -2,20 +2,47 @@ package nl.iobyte.themepark.listener;
|
||||||
|
|
||||||
import nl.iobyte.themepark.ThemeParkPlugin;
|
import nl.iobyte.themepark.ThemeParkPlugin;
|
||||||
import nl.iobyte.themepark.api.attraction.Region;
|
import nl.iobyte.themepark.api.attraction.Region;
|
||||||
import nl.iobyte.themepark.api.events.region.ChangeDataEvent;
|
import nl.iobyte.themepark.api.events.region.*;
|
||||||
import nl.iobyte.themepark.api.events.region.ChangeLoreEvent;
|
|
||||||
import nl.iobyte.themepark.api.events.region.ChangeMaterialEvent;
|
|
||||||
import nl.iobyte.themepark.api.events.region.ChangeNameEvent;
|
|
||||||
import nl.iobyte.themepark.config.YamlConfig;
|
import nl.iobyte.themepark.config.YamlConfig;
|
||||||
import nl.iobyte.themepark.database.DBManager;
|
import nl.iobyte.themepark.database.DBManager;
|
||||||
|
import nl.iobyte.themepark.menu.AttractionLoader;
|
||||||
import nl.iobyte.themepark.menu.AttractionMenu;
|
import nl.iobyte.themepark.menu.AttractionMenu;
|
||||||
import nl.iobyte.workchain.components.Work;
|
import nl.iobyte.workchain.components.Work;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class RegionListener implements Listener {
|
public class RegionListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onCreate(CreateRegionEvent e) {
|
||||||
|
if(AttractionLoader.loading)
|
||||||
|
return;
|
||||||
|
|
||||||
|
AttractionMenu.load();
|
||||||
|
|
||||||
|
Region region = e.getRegion();
|
||||||
|
String config_path = "regions." + region.getId();
|
||||||
|
YamlConfig yc = ThemeParkPlugin.getInstance().getRegions();
|
||||||
|
FileConfiguration config = yc.getConfig();
|
||||||
|
config.set(config_path+".name", region.getName());
|
||||||
|
config.set(config_path+".material", region.getMaterial().toString());
|
||||||
|
config.set(config_path+".lore", region.getLore());
|
||||||
|
config.set(config_path+".data", region.getData());
|
||||||
|
yc.save();
|
||||||
|
|
||||||
|
AttractionLoader.addRegion(region.getId());
|
||||||
|
|
||||||
|
Work.firstTask(() -> DBManager.getDatabase("public")).abortIfNull().lastTask(database -> {
|
||||||
|
HashMap<Integer, Object> obj = new HashMap<>();
|
||||||
|
obj.put(1, region.getId());
|
||||||
|
obj.put(2, region.getName());
|
||||||
|
|
||||||
|
database.execute("INSERT IGNORE INTO region(id, name) VALUES (?, ?)", obj);
|
||||||
|
}).execute();
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onChange(ChangeNameEvent e) {
|
public void onChange(ChangeNameEvent e) {
|
||||||
AttractionMenu.updateRegion(e.getRegion());
|
AttractionMenu.updateRegion(e.getRegion());
|
||||||
|
@ -30,8 +57,7 @@ public class RegionListener implements Listener {
|
||||||
obj.put(1, e.getAfter());
|
obj.put(1, e.getAfter());
|
||||||
obj.put(2, region.getId());
|
obj.put(2, region.getId());
|
||||||
|
|
||||||
String query ="UPDATE region SET name=? WHERE id=?";
|
database.execute("UPDATE region SET name=? WHERE id=?", obj);
|
||||||
database.execute(query, obj);
|
|
||||||
}).execute();
|
}).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,4 +91,26 @@ public class RegionListener implements Listener {
|
||||||
config.save();
|
config.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onRemove(RemoveRegionEvent e) {
|
||||||
|
if(AttractionLoader.loading)
|
||||||
|
return;
|
||||||
|
|
||||||
|
AttractionMenu.load();
|
||||||
|
|
||||||
|
Region region = e.getRegion();
|
||||||
|
String config_path = "regions." + region.getId();
|
||||||
|
YamlConfig yc = ThemeParkPlugin.getInstance().getRegions();
|
||||||
|
FileConfiguration config = yc.getConfig();
|
||||||
|
config.set(config_path, null);
|
||||||
|
yc.save();
|
||||||
|
|
||||||
|
Work.firstTask(() -> DBManager.getDatabase("public")).abortIfNull().lastTask(database -> {
|
||||||
|
HashMap<Integer, Object> obj = new HashMap<>();
|
||||||
|
obj.put(1, region.getId());
|
||||||
|
|
||||||
|
database.execute("DELETE FROM region WHERE id=?", obj);
|
||||||
|
}).execute();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
104
src/main/java/nl/iobyte/themepark/listener/SignListener.java
Normal file
104
src/main/java/nl/iobyte/themepark/listener/SignListener.java
Normal file
|
@ -0,0 +1,104 @@
|
||||||
|
package nl.iobyte.themepark.listener;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.ThemeParkPlugin;
|
||||||
|
import nl.iobyte.themepark.api.API;
|
||||||
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
|
import nl.iobyte.themepark.api.attraction.manager.StatusManager;
|
||||||
|
import nl.iobyte.themepark.config.YamlConfig;
|
||||||
|
import nl.iobyte.themepark.sign.SignManager;
|
||||||
|
import nl.iobyte.themepark.sign.StatusSign;
|
||||||
|
import nl.iobyte.themepark.util.Color;
|
||||||
|
import nl.iobyte.themepark.util.MessageUtil;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.Sign;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.Action;
|
||||||
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
|
import org.bukkit.event.block.SignChangeEvent;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
|
public class SignListener implements Listener {
|
||||||
|
|
||||||
|
private YamlConfig config = ThemeParkPlugin.getInstance().getSettings();
|
||||||
|
private String name = config.getConfig().getString("sign.name");
|
||||||
|
private String title = config.getConfig().getString("sign.title");
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlace(SignChangeEvent e) {
|
||||||
|
if(!e.getLine(0).equalsIgnoreCase(name))
|
||||||
|
return;
|
||||||
|
|
||||||
|
String id = e.getLine(1);
|
||||||
|
if(id == null || id.isEmpty() || !API.isAttraction(id))
|
||||||
|
return;
|
||||||
|
|
||||||
|
Attraction attraction = API.getAttraction(id);
|
||||||
|
e.setLine(0, Color.color(title));
|
||||||
|
e.setLine(1, Color.color(attraction.getName()));
|
||||||
|
e.setLine(2, Color.color(StatusManager.getName(attraction.getStatus())));
|
||||||
|
|
||||||
|
Location location = e.getBlock().getLocation();
|
||||||
|
StatusSign statusSign = new StatusSign(attraction, location);
|
||||||
|
SignManager.addSign(statusSign);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onBreak(BlockBreakEvent e) {
|
||||||
|
if(e.getBlock() == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Block block = e.getBlock();
|
||||||
|
if(!(block.getState() instanceof Sign))
|
||||||
|
return;
|
||||||
|
|
||||||
|
Sign sign = (Sign) block.getState();
|
||||||
|
if(!sign.getLine(0).equals(Color.color(title)))
|
||||||
|
return;
|
||||||
|
|
||||||
|
Attraction attraction = API.getAttractionFromName(sign.getLine(1));
|
||||||
|
Location location = e.getBlock().getLocation();
|
||||||
|
|
||||||
|
StatusSign s = new StatusSign(attraction, location);
|
||||||
|
SignManager.removeSign(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onClick(PlayerInteractEvent e) {
|
||||||
|
if(e.getAction() != Action.RIGHT_CLICK_BLOCK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Block b = e.getClickedBlock();
|
||||||
|
if(!(b.getState() instanceof Sign))
|
||||||
|
return;
|
||||||
|
|
||||||
|
Sign sign = (Sign) b.getState();
|
||||||
|
if(!sign.getLine(0).equals(Color.color(title)))
|
||||||
|
return;
|
||||||
|
|
||||||
|
Attraction attraction = API.getAttractionFromName(sign.getLine(1));
|
||||||
|
if(!SignManager.isSign(attraction, sign.getLocation()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
Location location = attraction.getLocation();
|
||||||
|
if(location == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Player player = e.getPlayer();
|
||||||
|
if(!StatusManager.canTeleport(attraction.getStatus())) {
|
||||||
|
String message = MessageUtil.getMessage("attraction.teleport.status");
|
||||||
|
message = message.replace("{name}", attraction.getName());
|
||||||
|
message = message.replace("{status}", StatusManager.getName(attraction.getStatus()));
|
||||||
|
player.sendMessage(Color.color(message));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.teleport(location);
|
||||||
|
String message = MessageUtil.getMessage("attraction.teleport.success");
|
||||||
|
message = message.replace("{name}", attraction.getName());
|
||||||
|
player.sendMessage(Color.color(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -11,6 +11,7 @@ import nl.iobyte.themepark.api.utils.LocationSerializer;
|
||||||
import nl.iobyte.themepark.config.YamlConfig;
|
import nl.iobyte.themepark.config.YamlConfig;
|
||||||
import nl.iobyte.themepark.database.DB;
|
import nl.iobyte.themepark.database.DB;
|
||||||
import nl.iobyte.themepark.database.DBManager;
|
import nl.iobyte.themepark.database.DBManager;
|
||||||
|
import nl.iobyte.themepark.sign.SignManager;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
@ -24,6 +25,7 @@ import java.util.List;
|
||||||
public class AttractionLoader {
|
public class AttractionLoader {
|
||||||
|
|
||||||
private static HashMap<String, YamlConfig> configs = new HashMap<>();
|
private static HashMap<String, YamlConfig> configs = new HashMap<>();
|
||||||
|
public static boolean loading = false;
|
||||||
|
|
||||||
public static YamlConfig getConfig(String id) {
|
public static YamlConfig getConfig(String id) {
|
||||||
if(id == null || id.isEmpty())
|
if(id == null || id.isEmpty())
|
||||||
|
@ -33,11 +35,13 @@ public class AttractionLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void load() {
|
public static void load() {
|
||||||
|
loading = true;
|
||||||
loadRegions();
|
loadRegions();
|
||||||
loadAttractions();
|
loadAttractions();
|
||||||
loadStatusData();
|
loadStatusData();
|
||||||
AttractionMenu.load();
|
AttractionMenu.load();
|
||||||
loadDatabase();
|
loadDatabase();
|
||||||
|
loading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void loadRegions() {
|
private static void loadRegions() {
|
||||||
|
@ -106,7 +110,7 @@ public class AttractionLoader {
|
||||||
|
|
||||||
ConfigurationSection section = fc.getConfigurationSection("attractions");
|
ConfigurationSection section = fc.getConfigurationSection("attractions");
|
||||||
if(section == null)
|
if(section == null)
|
||||||
return;
|
continue;
|
||||||
|
|
||||||
for(String id : section.getKeys(false)) {
|
for(String id : section.getKeys(false)) {
|
||||||
if(API.isAttraction(id))
|
if(API.isAttraction(id))
|
||||||
|
@ -134,6 +138,9 @@ public class AttractionLoader {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(Attraction attraction : API.getAttractions().values())
|
||||||
|
SignManager.loadSigns(attraction);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void loadStatusData() {
|
private static void loadStatusData() {
|
||||||
|
@ -170,42 +177,45 @@ public class AttractionLoader {
|
||||||
if(db == null)
|
if(db == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
boolean b = false;
|
int i;
|
||||||
StringBuilder builder = new StringBuilder();
|
boolean b ;
|
||||||
for(Region region : API.getRegions().values()) {
|
StringBuilder builder;
|
||||||
if(b) {
|
HashMap<Integer, Object> obj;
|
||||||
|
if(API.getRegions().size() > 0) {
|
||||||
|
i = 1;
|
||||||
|
b = false;
|
||||||
|
builder = new StringBuilder();
|
||||||
|
obj = new HashMap<>();
|
||||||
|
for (Region region : API.getRegions().values()) {
|
||||||
|
if (b) {
|
||||||
builder.append(",");
|
builder.append(",");
|
||||||
} else {
|
} else {
|
||||||
b = true;
|
b = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.append("(?,?)");
|
builder.append("(?,?)");
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int i = 1;
|
|
||||||
HashMap<Integer, Object> obj = new HashMap<>();
|
|
||||||
for(Region region : API.getRegions().values()) {
|
|
||||||
obj.put(i++, region.getId());
|
obj.put(i++, region.getId());
|
||||||
obj.put(i++, region.getName());
|
obj.put(i++, region.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
db.execute("INSERT INTO region(id, name) VALUES "+builder.toString()+" ON DUPLICATE KEY UPDATE name=VALUES(name)", obj);
|
db.execute("INSERT INTO region(id, name) VALUES " + builder.toString() + " ON DUPLICATE KEY UPDATE name=VALUES(name)", obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(API.getAttractions().size() > 0) {
|
||||||
b = false;
|
b = false;
|
||||||
|
i = 1;
|
||||||
|
obj = new HashMap<>();
|
||||||
builder = new StringBuilder();
|
builder = new StringBuilder();
|
||||||
for(Attraction attraction : API.getAttractions().values()) {
|
for (Attraction attraction : API.getAttractions().values()) {
|
||||||
if(b) {
|
if (b) {
|
||||||
builder.append(",");
|
builder.append(",");
|
||||||
} else {
|
} else {
|
||||||
b = true;
|
b = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.append("(?, ?, ?, ?, ?)");
|
builder.append("(?, ?, ?, ?, ?)");
|
||||||
}
|
|
||||||
|
|
||||||
i = 1;
|
|
||||||
obj = new HashMap<>();
|
|
||||||
for(Attraction attraction : API.getAttractions().values()) {
|
|
||||||
obj.put(i++, attraction.getId());
|
obj.put(i++, attraction.getId());
|
||||||
obj.put(i++, attraction.getName());
|
obj.put(i++, attraction.getName());
|
||||||
obj.put(i++, attraction.getRegionId());
|
obj.put(i++, attraction.getRegionId());
|
||||||
|
@ -213,9 +223,12 @@ public class AttractionLoader {
|
||||||
obj.put(i++, attraction.getStatus().toString());
|
obj.put(i++, attraction.getStatus().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
db.execute("INSERT INTO attraction(id, name, region_id, type, status) VALUES " + builder.toString() + " ON DUPLICATE KEY UPDATE name=VALUES(name), region_id=VALUES(region_id), type=VALUES(type), status=VALUES(status)", obj);
|
||||||
|
}
|
||||||
|
|
||||||
db.execute("INSERT INTO attraction(id, name, region_id, type, status) VALUES "+builder.toString()+" ON DUPLICATE KEY UPDATE name=VALUES(name), region_id=VALUES(region_id), type=VALUES(type), status=VALUES(status)", obj);
|
|
||||||
b = false;
|
b = false;
|
||||||
|
i = 1;
|
||||||
|
obj = new HashMap<>();
|
||||||
builder = new StringBuilder();
|
builder = new StringBuilder();
|
||||||
for(Status status : Status.values()) {
|
for(Status status : Status.values()) {
|
||||||
if(b) {
|
if(b) {
|
||||||
|
@ -225,11 +238,7 @@ public class AttractionLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.append("(?, ?)");
|
builder.append("(?, ?)");
|
||||||
}
|
|
||||||
|
|
||||||
i = 1;
|
|
||||||
obj = new HashMap<>();
|
|
||||||
for(Status status : Status.values()) {
|
|
||||||
obj.put(i++, status.toString());
|
obj.put(i++, status.toString());
|
||||||
obj.put(i++, StatusManager.getName(status));
|
obj.put(i++, StatusManager.getName(status));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package nl.iobyte.themepark.menu;
|
package nl.iobyte.themepark.menu;
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import nl.iobyte.menuapi.components.Types;
|
import nl.iobyte.menuapi.enums.Types;
|
||||||
import nl.iobyte.menuapi.item.MenuItem;
|
import nl.iobyte.menuapi.item.MenuItem;
|
||||||
import nl.iobyte.menuapi.multi.MenuPage;
|
import nl.iobyte.menuapi.multi.MenuPage;
|
||||||
import nl.iobyte.menuapi.multi.MultiMenu;
|
import nl.iobyte.menuapi.multi.MultiMenu;
|
||||||
|
@ -16,16 +16,14 @@ import nl.iobyte.themepark.menu.actions.TPAction;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class AttractionMenu {
|
public class AttractionMenu {
|
||||||
|
|
||||||
private static MultiMenu menu;
|
private static MultiMenu menu;
|
||||||
private static HashMap<String, Integer> reg_slots = new HashMap<>();
|
private static final HashMap<String, Integer> reg_slots = new HashMap<>();
|
||||||
private static HashMap<String, Integer> att_slots = new HashMap<>();
|
private static final HashMap<String, Integer> att_slots = new HashMap<>();
|
||||||
|
|
||||||
public static void load() {
|
public static void load() {
|
||||||
LinkedHashMap<Integer, Region> regions = new LinkedHashMap<>();
|
LinkedHashMap<Integer, Region> regions = new LinkedHashMap<>();
|
||||||
|
@ -33,9 +31,11 @@ public class AttractionMenu {
|
||||||
for(Region region : API.getRegions().values()) {
|
for(Region region : API.getRegions().values()) {
|
||||||
if(region.getAttractions().isEmpty()) {
|
if(region.getAttractions().isEmpty()) {
|
||||||
regions.put(regions.size(), region);
|
regions.put(regions.size(), region);
|
||||||
|
attractions.put(attractions.size(), new ArrayList<>());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Iterable<List<Attraction>> iterable = Iterables.partition(region.getAttractions().values(), 8);
|
Iterable<List<Attraction>> iterable = Iterables.partition(region.getAttractions().values(), 8);
|
||||||
for(List<Attraction> list : iterable) {
|
for(List<Attraction> list : iterable) {
|
||||||
regions.put(regions.size(), region);
|
regions.put(regions.size(), region);
|
||||||
|
@ -73,19 +73,21 @@ public class AttractionMenu {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(region_size > 6) {
|
if(region_size > 6) {
|
||||||
int page_size = menu.getPageSizes().size();
|
int page;
|
||||||
for (int i = 0; i < page_size; i++) {
|
MenuPage m;
|
||||||
MenuPage page = menu.getPage(i + 1);
|
int maxPage = menu.getPageSizes().size();
|
||||||
int size = page.getSize();
|
for(Map.Entry<Integer, MenuPage> entrySet : menu.getPages().entrySet()) {
|
||||||
if (i > 0)
|
page = entrySet.getKey();
|
||||||
page.setItem(size - 6, getPrevious(i));
|
m = entrySet.getValue();
|
||||||
|
if(page != 1)
|
||||||
|
menu.setItem(page, m.getSize() - 6, getPrevious(page));
|
||||||
|
|
||||||
if (i < (page_size - 1))
|
if(page != maxPage)
|
||||||
page.setItem(size - 4, getNext(i));
|
menu.setItem(page, entrySet.getValue().getSize() - 4, getNext(page));
|
||||||
|
|
||||||
ItemBuilder builder = new ItemBuilder(Material.MINECART);
|
ItemBuilder builder = new ItemBuilder(Material.MINECART);
|
||||||
builder.setName("&6Page: &f"+(i + 1));
|
builder.setName("&6Page: &f"+page);
|
||||||
page.setItem(size - 5, new MenuItem(builder.getItem(), true));
|
m.setItem(m.getSize() - 5, new MenuItem(builder.getItem(), true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +129,7 @@ public class AttractionMenu {
|
||||||
private static void loadMenu(int regions) {
|
private static void loadMenu(int regions) {
|
||||||
ArrayList<Integer> page_sizes = new ArrayList<>();
|
ArrayList<Integer> page_sizes = new ArrayList<>();
|
||||||
if(regions <= 6) {
|
if(regions <= 6) {
|
||||||
page_sizes.add(regions * 9);
|
page_sizes.add(regions > 0 ? regions * 9 : 9);
|
||||||
} else {
|
} else {
|
||||||
int pages = regions / 5;
|
int pages = regions / 5;
|
||||||
for (int i = 0; i < pages; i++)
|
for (int i = 0; i < pages; i++)
|
||||||
|
@ -166,7 +168,7 @@ public class AttractionMenu {
|
||||||
builder.setName(text);
|
builder.setName(text);
|
||||||
|
|
||||||
MenuItem item = new MenuItem(builder.getItem(), true);
|
MenuItem item = new MenuItem(builder.getItem(), true);
|
||||||
item.addActions(new PageAction(page + 1));
|
item.addActions(new PageAction(page));
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ import nl.iobyte.themepark.api.ridecount.AttractionCount;
|
||||||
import nl.iobyte.themepark.api.ridecount.CountManager;
|
import nl.iobyte.themepark.api.ridecount.CountManager;
|
||||||
import nl.iobyte.themepark.database.DB;
|
import nl.iobyte.themepark.database.DB;
|
||||||
import nl.iobyte.themepark.database.DBManager;
|
import nl.iobyte.themepark.database.DBManager;
|
||||||
|
import nl.iobyte.themepark.database.SQLite;
|
||||||
import nl.iobyte.workchain.components.Work;
|
import nl.iobyte.workchain.components.Work;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -18,28 +19,20 @@ import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.sql.Connection;
|
import java.text.SimpleDateFormat;
|
||||||
import java.sql.PreparedStatement;
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class RideCountAPI {
|
public class RideCountAPI {
|
||||||
|
|
||||||
private static WeakConcurrentHashMap<String, String> data = new WeakConcurrentHashMap<>(5 * 60 * 1000);
|
private static final WeakConcurrentHashMap<String, String> data = new WeakConcurrentHashMap<>(5 * 60 * 1000);
|
||||||
|
private static final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
|
||||||
public static CompletableFuture<Integer> getCount(String name, Attraction attraction) {
|
public static CompletableFuture<Integer> getCount(String name, Attraction attraction) {
|
||||||
CompletableFuture<Integer> fc = new CompletableFuture<>();
|
CompletableFuture<Integer> fc = new CompletableFuture<>();
|
||||||
if(name == null || name.isEmpty() || attraction == null) {
|
|
||||||
fc.complete(-1);
|
|
||||||
return fc;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!API.isAttraction(attraction.getId())) {
|
|
||||||
fc.complete(-1);
|
|
||||||
return fc;
|
|
||||||
}
|
|
||||||
|
|
||||||
getData(name).thenAccept(uuid -> {
|
getData(name).thenAccept(uuid -> {
|
||||||
if(uuid == null) {
|
if(uuid == null) {
|
||||||
fc.complete(-1);
|
fc.complete(-1);
|
||||||
|
@ -74,26 +67,24 @@ public class RideCountAPI {
|
||||||
if(db == null)
|
if(db == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
Connection connection = db.getConnection();
|
HashMap<Integer, Object> map = new HashMap<>();
|
||||||
if(connection == null || connection.isClosed())
|
map.put(1, uuid.toString());
|
||||||
return null;
|
map.put(2, attraction.getId());
|
||||||
|
map.put(3, simpleDateFormat.format(new Date()));
|
||||||
|
|
||||||
PreparedStatement statement = connection.prepareStatement("SELECT points FROM counts WHERE uuid=? AND attraction_id=?");
|
return db.executeQuery("SELECT points FROM counts WHERE uuid=? AND attraction_id=? AND created_at=?", map);
|
||||||
statement.setString(1, uuid.toString());
|
}).abortIfNull(() -> fc.complete(0)).nextTask(result -> {
|
||||||
statement.setString(2, attraction.getId());
|
int i = 0;
|
||||||
statement.closeOnCompletion();
|
for(HashMap<String, Object> map : result) {
|
||||||
return statement.executeQuery();
|
int points = (int) map.get("points");
|
||||||
}).abortIfNull(() -> fc.complete(-1)).nextTask(result -> {
|
if(points < 0) {
|
||||||
int i = -1;
|
i = 0;
|
||||||
while(result.next()) {
|
|
||||||
int points = result.getInt("points");
|
|
||||||
if(points < 0)
|
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
i = points;
|
i = points;
|
||||||
}
|
}
|
||||||
|
|
||||||
result.close();
|
|
||||||
return i;
|
return i;
|
||||||
}).lastTask(fc::complete).setFullExecute(true).execute();
|
}).lastTask(fc::complete).setFullExecute(true).execute();
|
||||||
return fc;
|
return fc;
|
||||||
|
@ -124,7 +115,7 @@ public class RideCountAPI {
|
||||||
|
|
||||||
public static CompletableFuture<Boolean> addCount(UUID uuid, Attraction attraction, int amount) {
|
public static CompletableFuture<Boolean> addCount(UUID uuid, Attraction attraction, int amount) {
|
||||||
CompletableFuture<Boolean> fc = new CompletableFuture<>();
|
CompletableFuture<Boolean> fc = new CompletableFuture<>();
|
||||||
if(uuid == null || attraction == null || amount < 0) {
|
if(uuid == null || attraction == null) {
|
||||||
fc.complete(false);
|
fc.complete(false);
|
||||||
return fc;
|
return fc;
|
||||||
}
|
}
|
||||||
|
@ -135,25 +126,45 @@ public class RideCountAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
AttractionCount count = CountManager.getCounter(attraction.getId());
|
AttractionCount count = CountManager.getCounter(attraction.getId());
|
||||||
if(count != null && count.hasCount(uuid))
|
if(count != null)
|
||||||
Bukkit.getScheduler().runTask(ThemeParkPlugin.getInstance(), () -> count.addCount(uuid, amount));
|
Bukkit.getScheduler().runTask(ThemeParkPlugin.getInstance(), () -> count.addCount(uuid, amount));
|
||||||
|
|
||||||
Work.firstTask(() -> {
|
Work.firstTask(() -> {
|
||||||
DB db = DBManager.getDatabase("data");
|
SQLite db = (SQLite) DBManager.getDatabase("data");
|
||||||
if(db == null)
|
if(db == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
Connection connection = db.getConnection();
|
|
||||||
if(connection == null || connection.isClosed())
|
|
||||||
return null;
|
|
||||||
|
|
||||||
PreparedStatement statement = connection.prepareStatement("INSERT INTO counts(uuid, attraction_id, points) VALUES (?, ?, ?) ON CONFLICT(uuid, attraction_id) DO UPDATE SET points=points+?");
|
String date = simpleDateFormat.format(new Date());
|
||||||
statement.setString(1, uuid.toString());
|
|
||||||
statement.setString(2, attraction.getId());
|
boolean b = versionCompare(db.getVersion(), "3.24.0");
|
||||||
statement.setInt(3, amount);
|
if(!b) {
|
||||||
statement.setInt(4, amount);
|
HashMap<Integer, Object> map = new HashMap<>();
|
||||||
statement.closeOnCompletion();
|
map.put(1, uuid.toString());
|
||||||
return statement.executeUpdate() > 0;
|
map.put(2, attraction.getId());
|
||||||
|
map.put(3, amount);
|
||||||
|
map.put(4, date);
|
||||||
|
try {
|
||||||
|
b = db.execute("INSERT INTO counts(uuid, attraction_id, points,created_at) VALUES (?,?,?,?)", map);
|
||||||
|
} catch (Exception e) {}
|
||||||
|
|
||||||
|
if(b)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
map.put(3, map.get(2));
|
||||||
|
map.put(2, map.get(1));
|
||||||
|
map.put(1, amount);
|
||||||
|
return db.executeUpdate("UPDATE counts SET points=? WHERE uuid=? AND attraction_id=? AND created_at=?", map) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
HashMap<Integer, Object> map = new HashMap<>();
|
||||||
|
map.put(1, uuid.toString());
|
||||||
|
map.put(2, attraction.getId());
|
||||||
|
map.put(3, amount);
|
||||||
|
map.put(4, date);
|
||||||
|
map.put(5, amount);
|
||||||
|
|
||||||
|
return db.executeUpdate("INSERT INTO counts (uuid, attraction_id, points, created_at) VALUES (?, ?, ?, ?) ON CONFLICT(uuid, attraction_id, created_at) DO UPDATE SET points=points+?", map) > 0;
|
||||||
}).abortIfNull(() -> fc.complete(false)).lastTask(fc::complete).setFullExecute(true).execute();
|
}).abortIfNull(() -> fc.complete(false)).lastTask(fc::complete).setFullExecute(true).execute();
|
||||||
return fc;
|
return fc;
|
||||||
}
|
}
|
||||||
|
@ -162,11 +173,17 @@ public class RideCountAPI {
|
||||||
CompletableFuture<UUID> fc = new CompletableFuture<>();
|
CompletableFuture<UUID> fc = new CompletableFuture<>();
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), () -> {
|
||||||
if(data.containsKey(name)) {
|
if(data.containsKey(name)) {
|
||||||
fc.complete(UUID.fromString(data.get(name)));
|
String str = data.get(name);
|
||||||
|
if(str.isEmpty()) {
|
||||||
|
fc.complete(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = Bukkit.getPlayerExact(name);
|
fc.complete(UUID.fromString(str));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = Bukkit.getPlayer(name);
|
||||||
if(player != null) {
|
if(player != null) {
|
||||||
UUID uuid = player.getUniqueId();
|
UUID uuid = player.getUniqueId();
|
||||||
data.put(name, uuid.toString());
|
data.put(name, uuid.toString());
|
||||||
|
@ -177,14 +194,14 @@ public class RideCountAPI {
|
||||||
try {
|
try {
|
||||||
JsonObject object = sendGETRequestJSON("https://api.mojang.com/users/profiles/minecraft/" + name);
|
JsonObject object = sendGETRequestJSON("https://api.mojang.com/users/profiles/minecraft/" + name);
|
||||||
if(object == null) {
|
if(object == null) {
|
||||||
data.put(name, null);
|
data.put(name, "");
|
||||||
fc.complete(null);
|
fc.complete(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String id = object.get("id").getAsString();
|
String id = object.get("id").getAsString();
|
||||||
if(id == null || id.isEmpty()) {
|
if(id == null || id.isEmpty()) {
|
||||||
data.put(name, null);
|
data.put(name, "");
|
||||||
fc.complete(null);
|
fc.complete(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -194,7 +211,7 @@ public class RideCountAPI {
|
||||||
data.put(name, id);
|
data.put(name, id);
|
||||||
fc.complete(uuid);
|
fc.complete(uuid);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
data.put(name, null);
|
data.put(name, "");
|
||||||
fc.complete(null);
|
fc.complete(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -210,6 +227,7 @@ public class RideCountAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!API.isAttraction(attraction.getId())) {
|
if(!API.isAttraction(attraction.getId())) {
|
||||||
|
System.out.println("[ThemePark] Unknown attraction with ID: "+attraction.getId());
|
||||||
fc.complete(null);
|
fc.complete(null);
|
||||||
return fc;
|
return fc;
|
||||||
}
|
}
|
||||||
|
@ -219,27 +237,22 @@ public class RideCountAPI {
|
||||||
if(db == null)
|
if(db == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
Connection connection = db.getConnection();
|
String timeSort = week ? "strftime('%W', created_at)=strftime('%W', 'now')" : "strftime('%j', created_at)=strftime('%j', 'now')";
|
||||||
if(connection == null || connection.isClosed())
|
HashMap<Integer, Object> map = new HashMap<>();
|
||||||
return null;
|
map.put(1, attraction.getId());
|
||||||
|
|
||||||
String timeSort = week ? "YEARWEEK(created_at, 1)=YEARWEEK(CURDATE(), 1)" : "DAYOFYEAR(created_at)=DAYOFYEAR(CURDATE())";
|
return db.executeQuery("SELECT uuid, SUM(points) AS count FROM counts WHERE attraction_id=? AND "+timeSort+" AND strftime('%Y', created_at)==strftime('%Y', 'now') GROUP BY uuid ORDER BY count DESC LIMIT 3", map);
|
||||||
PreparedStatement statement = connection.prepareStatement("SELECT uuid, SUM(points) AS count FROM ridecount WHERE attraction_id=? AND "+timeSort+" AND YEAR(created_at)=YEAR(CURDATE()) GROUP BY uuid ORDER BY points DESC LIMIT 3");
|
|
||||||
statement.setString(1, attraction.getId());
|
|
||||||
statement.closeOnCompletion();
|
|
||||||
return statement.executeQuery();
|
|
||||||
}).abortIfNull(() -> fc.complete(null)).nextTask(result -> {
|
}).abortIfNull(() -> fc.complete(null)).nextTask(result -> {
|
||||||
HashMap<UUID, Integer> top = new HashMap<>();
|
HashMap<UUID, Integer> top = new HashMap<>();
|
||||||
while(result.next()) {
|
for(HashMap<String, Object> map : result) {
|
||||||
UUID uuid = UUID.fromString(result.getString("uuid"));
|
UUID uuid = UUID.fromString((String) map.get("uuid"));
|
||||||
int points = result.getInt("points");
|
int points = (int) map.get("count");
|
||||||
if(points < 0)
|
if(points < 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
top.put(uuid, points);
|
top.put(uuid, points);
|
||||||
}
|
}
|
||||||
|
|
||||||
result.close();
|
|
||||||
return top;
|
return top;
|
||||||
}).lastTask(fc::complete).setFullExecute(true).execute();
|
}).lastTask(fc::complete).setFullExecute(true).execute();
|
||||||
return fc;
|
return fc;
|
||||||
|
@ -253,6 +266,7 @@ public class RideCountAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!API.isAttraction(attraction.getId())) {
|
if(!API.isAttraction(attraction.getId())) {
|
||||||
|
System.out.println("[ThemePark] Unknown attraction with ID: "+attraction.getId());
|
||||||
fc.complete(null);
|
fc.complete(null);
|
||||||
return fc;
|
return fc;
|
||||||
}
|
}
|
||||||
|
@ -262,26 +276,21 @@ public class RideCountAPI {
|
||||||
if(db == null)
|
if(db == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
Connection connection = db.getConnection();
|
HashMap<Integer, Object> map = new HashMap<>();
|
||||||
if(connection == null || connection.isClosed())
|
map.put(1, attraction.getId());
|
||||||
return null;
|
|
||||||
|
|
||||||
PreparedStatement statement = connection.prepareStatement("SELECT uuid, SUM(points) AS count FROM ridecount WHERE attraction_id=? GROUP BY uuid ORDER BY points DESC LIMIT 3");
|
return db.executeQuery("SELECT uuid, SUM(points) AS count FROM counts WHERE attraction_id=? GROUP BY uuid ORDER BY count DESC LIMIT 3", map);
|
||||||
statement.setString(1, attraction.getId());
|
|
||||||
statement.closeOnCompletion();
|
|
||||||
return statement.executeQuery();
|
|
||||||
}).abortIfNull(() -> fc.complete(null)).nextTask(result -> {
|
}).abortIfNull(() -> fc.complete(null)).nextTask(result -> {
|
||||||
HashMap<UUID, Integer> top = new HashMap<>();
|
HashMap<UUID, Integer> top = new HashMap<>();
|
||||||
while(result.next()) {
|
for(HashMap<String, Object> map : result) {
|
||||||
UUID uuid = UUID.fromString(result.getString("uuid"));
|
UUID uuid = UUID.fromString((String) map.get("uuid"));
|
||||||
int points = result.getInt("points");
|
int points = (int) map.get("count");
|
||||||
if(points < 0)
|
if(points < 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
top.put(uuid, points);
|
top.put(uuid, points);
|
||||||
}
|
}
|
||||||
|
|
||||||
result.close();
|
|
||||||
return top;
|
return top;
|
||||||
}).lastTask(fc::complete).setFullExecute(true).execute();
|
}).lastTask(fc::complete).setFullExecute(true).execute();
|
||||||
return fc;
|
return fc;
|
||||||
|
@ -323,4 +332,20 @@ public class RideCountAPI {
|
||||||
return parser.parse(response.toString()).getAsJsonObject();
|
return parser.parse(response.toString()).getAsJsonObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean versionCompare(String s1, String s2) {
|
||||||
|
String[] thisParts = s1.split("\\.");
|
||||||
|
String[] thatParts = s2.split("\\.");
|
||||||
|
|
||||||
|
int length = Math.max(thisParts.length, thatParts.length);
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
int thisPart = i < thisParts.length ? Integer.parseInt(thisParts[i]) : 0;
|
||||||
|
int thatPart = i < thatParts.length ? Integer.parseInt(thatParts[i]) : 0;
|
||||||
|
if(thisPart < thatPart)
|
||||||
|
return false;
|
||||||
|
if(thisPart > thatPart)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
180
src/main/java/nl/iobyte/themepark/sign/SignManager.java
Normal file
180
src/main/java/nl/iobyte/themepark/sign/SignManager.java
Normal file
|
@ -0,0 +1,180 @@
|
||||||
|
package nl.iobyte.themepark.sign;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.ThemeParkPlugin;
|
||||||
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
|
import nl.iobyte.themepark.api.utils.LocationSerializer;
|
||||||
|
import nl.iobyte.themepark.config.YamlConfig;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Sign;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class SignManager {
|
||||||
|
|
||||||
|
private static YamlConfig config = ThemeParkPlugin.getInstance().getSigns();
|
||||||
|
private static HashMap<Attraction, ArrayList<StatusSign>> signs = new HashMap<>();
|
||||||
|
|
||||||
|
public static void loadSigns(Attraction attraction) {
|
||||||
|
if(attraction == null) {
|
||||||
|
System.out.println("SignManager: No attraction passed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!config.getConfig().contains("signs." + attraction.getId())) {
|
||||||
|
System.out.println("SignManager: No signs for attraction with ID: "+attraction.getId());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!config.getConfig().isList("signs." + attraction.getId())) {
|
||||||
|
System.out.println("SignManager: No signs for attraction with ID: "+attraction.getId());
|
||||||
|
config.getConfig().set("signs." + attraction.getId(), null);
|
||||||
|
config.save();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<StatusSign> array = new ArrayList<>();
|
||||||
|
List<String> locations = config.getConfig().getStringList("signs." + attraction.getId());
|
||||||
|
for(String string : locations) {
|
||||||
|
Location location = LocationSerializer.toLocation(string);
|
||||||
|
if(location == null) {
|
||||||
|
System.out.println("SignManager: Invalid location for sign: "+string);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(!(location.getBlock().getState() instanceof Sign)) {
|
||||||
|
System.out.println("SignManager: Block is not a sign at: "+string);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
array.add(new StatusSign(attraction, location));
|
||||||
|
}
|
||||||
|
|
||||||
|
signs.put(attraction, array);
|
||||||
|
System.out.println("SignManager: Loaded "+array.size()+" signs for attraction: "+attraction.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void saveSigns() {
|
||||||
|
for(Map.Entry<Attraction, ArrayList<StatusSign>> entry : signs.entrySet()) {
|
||||||
|
List<String> array = new ArrayList<>();
|
||||||
|
for(StatusSign sign : entry.getValue())
|
||||||
|
if(LocationSerializer.toString(sign.getLocation()) != null)
|
||||||
|
array.add(LocationSerializer.toString(sign.getLocation()));
|
||||||
|
|
||||||
|
config.getConfig().set("signs." + entry.getKey().getId(), array);
|
||||||
|
}
|
||||||
|
|
||||||
|
config.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addSign(StatusSign sign) {
|
||||||
|
if(sign == null || sign.getLocation() == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(!(sign.getLocation().getBlock().getState() instanceof Sign))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(signs.containsKey(sign.getAttraction())) {
|
||||||
|
signs.get(sign.getAttraction()).add(sign);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<StatusSign> array = new ArrayList<>();
|
||||||
|
array.add(sign);
|
||||||
|
signs.put(sign.getAttraction(), array);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean hasSigns(Attraction attraction) {
|
||||||
|
if(attraction == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return signs.containsKey(attraction) && (signs.get(attraction).size() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isSign(Attraction attraction, Location location) {
|
||||||
|
if(attraction == null || location == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ArrayList<StatusSign> array = signs.get(attraction);
|
||||||
|
if(array == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
String loc = LocationSerializer.toString(location);
|
||||||
|
if(loc == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for(StatusSign sign : array) {
|
||||||
|
String str = LocationSerializer.toString(sign.getLocation());
|
||||||
|
if(str == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(loc.equals(str))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void update(Attraction attraction) {
|
||||||
|
if(attraction == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(!hasSigns(attraction))
|
||||||
|
return;
|
||||||
|
|
||||||
|
for(StatusSign sign : signs.get(attraction))
|
||||||
|
sign.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void remove(Attraction attraction) {
|
||||||
|
if(attraction == null || !signs.containsKey(attraction))
|
||||||
|
return;
|
||||||
|
|
||||||
|
for(StatusSign sign : signs.get(attraction))
|
||||||
|
sign.getLocation().getBlock().setType(Material.AIR);
|
||||||
|
|
||||||
|
signs.remove(attraction);
|
||||||
|
config.getConfig().set("signs." + attraction.getId(), null);
|
||||||
|
config.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeSign(StatusSign sign) {
|
||||||
|
if(sign == null || sign.getLocation() == null || sign.getAttraction() == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(!hasSigns(sign.getAttraction()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
Location loc1 = sign.getLocation();
|
||||||
|
String str1 = LocationSerializer.toString(loc1);
|
||||||
|
ArrayList<StatusSign> array = signs.get(sign.getAttraction());
|
||||||
|
for(StatusSign s : new ArrayList<>(array)) {
|
||||||
|
Location loc2 = s.getLocation();
|
||||||
|
|
||||||
|
if(loc1 == null || loc2 == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
String str2 = LocationSerializer.toString(loc2);
|
||||||
|
if(str1 == null || str2 == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(!str1.equals(str2))
|
||||||
|
return;
|
||||||
|
|
||||||
|
array.remove(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(array.isEmpty()) {
|
||||||
|
signs.remove(sign.getAttraction());
|
||||||
|
config.getConfig().set("signs." + sign.getAttraction().getId(), null);
|
||||||
|
config.save();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
signs.put(sign.getAttraction(), array);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
44
src/main/java/nl/iobyte/themepark/sign/StatusSign.java
Normal file
44
src/main/java/nl/iobyte/themepark/sign/StatusSign.java
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
package nl.iobyte.themepark.sign;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
|
import nl.iobyte.themepark.api.attraction.component.Status;
|
||||||
|
import nl.iobyte.themepark.api.attraction.manager.StatusManager;
|
||||||
|
import nl.iobyte.themepark.util.Color;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.block.Sign;
|
||||||
|
|
||||||
|
public class StatusSign {
|
||||||
|
|
||||||
|
private Attraction attraction;
|
||||||
|
private Location location;
|
||||||
|
|
||||||
|
public StatusSign(Attraction attraction, Location location) {
|
||||||
|
this.attraction = attraction;
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Attraction getAttraction() {
|
||||||
|
return attraction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update() {
|
||||||
|
Status status = attraction.getStatus();
|
||||||
|
if(!location.getChunk().isLoaded())
|
||||||
|
location.getChunk().load();
|
||||||
|
|
||||||
|
if(!(location.getBlock().getState() instanceof Sign)) {
|
||||||
|
SignManager.removeSign(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Sign sign = (Sign) location.getBlock().getState();
|
||||||
|
sign.setLine(1, Color.color(attraction.getName()));
|
||||||
|
sign.setLine(2, Color.color(StatusManager.getName(status)));
|
||||||
|
sign.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
115
src/main/java/nl/iobyte/themepark/traincarts/TCRideCount.java
Normal file
115
src/main/java/nl/iobyte/themepark/traincarts/TCRideCount.java
Normal file
|
@ -0,0 +1,115 @@
|
||||||
|
package nl.iobyte.themepark.traincarts;
|
||||||
|
|
||||||
|
import com.bergerkiller.bukkit.tc.Permission;
|
||||||
|
import com.bergerkiller.bukkit.tc.controller.MinecartMember;
|
||||||
|
import com.bergerkiller.bukkit.tc.events.SignActionEvent;
|
||||||
|
import com.bergerkiller.bukkit.tc.events.SignChangeActionEvent;
|
||||||
|
import com.bergerkiller.bukkit.tc.signactions.SignAction;
|
||||||
|
import com.bergerkiller.bukkit.tc.signactions.SignActionType;
|
||||||
|
import com.bergerkiller.bukkit.tc.utils.SignBuildOptions;
|
||||||
|
import nl.iobyte.themepark.ThemeParkPlugin;
|
||||||
|
import nl.iobyte.themepark.api.API;
|
||||||
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
|
import nl.iobyte.themepark.api.events.ridecount.ChangeCountEvent;
|
||||||
|
import nl.iobyte.themepark.api.events.ridecount.PreProcessCountEvent;
|
||||||
|
import nl.iobyte.themepark.api.ridecount.AttractionCount;
|
||||||
|
import nl.iobyte.themepark.api.ridecount.CountManager;
|
||||||
|
import nl.iobyte.themepark.ridecount.RideCountAPI;
|
||||||
|
import nl.iobyte.themepark.util.Color;
|
||||||
|
import nl.iobyte.themepark.util.MessageUtil;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
public class TCRideCount extends SignAction {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean match(final SignActionEvent info) {
|
||||||
|
return info.getLine(1).equalsIgnoreCase("ridecount") && !info.getLine(2).isEmpty() && !info.getLine(3).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(final SignActionEvent info) {
|
||||||
|
if (!info.isPowered())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (info.isTrainSign() && info.isAction(SignActionType.REDSTONE_ON, SignActionType.GROUP_ENTER) && info.hasGroup()) {
|
||||||
|
ArrayList<Player> players = new ArrayList<>();
|
||||||
|
for (final MinecartMember<?> member : info.getGroup())
|
||||||
|
players.addAll(member.getEntity().getPlayerPassengers());
|
||||||
|
|
||||||
|
count(players, info);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!info.isCartSign() || !info.isAction(SignActionType.REDSTONE_ON, SignActionType.MEMBER_ENTER) || !info.hasMember()) {
|
||||||
|
if (info.isRCSign() && info.isAction(SignActionType.REDSTONE_ON)) {
|
||||||
|
ArrayList<Player> players = new ArrayList<>();
|
||||||
|
for (final MinecartMember<?> member : info.getGroup())
|
||||||
|
players.addAll(member.getEntity().getPlayerPassengers());
|
||||||
|
|
||||||
|
count(players, info);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!info.getMember().getEntity().isEmpty()) {
|
||||||
|
ArrayList<Player> players = new ArrayList<>(info.getMember().getEntity().getPlayerPassengers());
|
||||||
|
count(players, info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean build(SignChangeActionEvent event) {
|
||||||
|
return SignBuildOptions.create()
|
||||||
|
.setName(event.isCartSign() ? "cart ridecount sign" : "train ridecount sign")
|
||||||
|
.setDescription("Add a count to a player for an attraction")
|
||||||
|
.handle(event.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void count(ArrayList<Player> players, SignActionEvent info) {
|
||||||
|
String id = info.getLine(2);
|
||||||
|
if(!API.isAttraction(id))
|
||||||
|
return;
|
||||||
|
|
||||||
|
int amount = 1;
|
||||||
|
try {
|
||||||
|
amount = Integer.parseInt(info.getLine(3));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
Attraction attraction = API.getAttraction(id);
|
||||||
|
AtomicBoolean b = new AtomicBoolean(false);
|
||||||
|
AttractionCount count = CountManager.getCounter(attraction.getId());
|
||||||
|
|
||||||
|
for(Player player : players) {
|
||||||
|
PreProcessCountEvent event = new PreProcessCountEvent(player.getUniqueId(), attraction, amount);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
|
||||||
|
int u_amount = event.getCount();
|
||||||
|
UUID finalUuid = player.getUniqueId();
|
||||||
|
RideCountAPI.getCount(finalUuid, attraction).thenAccept(before -> RideCountAPI.addCount(finalUuid, attraction, u_amount).thenAccept(result -> {
|
||||||
|
if (!result)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(count == null || !count.hasCount(finalUuid)) {
|
||||||
|
Bukkit.getScheduler().runTask(ThemeParkPlugin.getInstance(), () -> {
|
||||||
|
ChangeCountEvent e = new ChangeCountEvent(attraction, count, finalUuid, before, before + u_amount);
|
||||||
|
Bukkit.getPluginManager().callEvent(e);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if(b.get())
|
||||||
|
return;
|
||||||
|
|
||||||
|
b.set(true);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
package nl.iobyte.themepark.util;
|
package nl.iobyte.themepark.util;
|
||||||
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
import net.md_5.bungee.api.chat.HoverEvent;
|
import net.md_5.bungee.api.chat.HoverEvent;
|
||||||
|
|
125
src/main/java/nl/iobyte/themepark/util/SpigotPlayerSelector.java
Normal file
125
src/main/java/nl/iobyte/themepark/util/SpigotPlayerSelector.java
Normal file
|
@ -0,0 +1,125 @@
|
||||||
|
package nl.iobyte.themepark.util;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.command.BlockCommandSender;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use selectors in commands!
|
||||||
|
*
|
||||||
|
* @author Mindgamesnl
|
||||||
|
*
|
||||||
|
* Code from
|
||||||
|
* https://github.com/Mindgamesnl/OpenAudioMc/blob/master/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/players/objects/SpigotPlayerSelector.java
|
||||||
|
*/
|
||||||
|
public class SpigotPlayerSelector {
|
||||||
|
|
||||||
|
private final String selector;
|
||||||
|
|
||||||
|
public SpigotPlayerSelector(String selector) {
|
||||||
|
this.selector = selector;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this turns selectors like @a[r=5] into a usable list, since
|
||||||
|
* 1.13 spigot removed this feature, FOR SOME REASON.. thanks guys..
|
||||||
|
*
|
||||||
|
* @param commandSender the sender
|
||||||
|
* @return players following the selector
|
||||||
|
*/
|
||||||
|
public List<Player> getPlayers(CommandSender commandSender) {
|
||||||
|
List<Player> players = new ArrayList<>();
|
||||||
|
|
||||||
|
if (selector.startsWith("@p")) {
|
||||||
|
//get Location
|
||||||
|
Location standPoint = getLocation(commandSender);
|
||||||
|
|
||||||
|
if (getArgument("r").length() != 0) {
|
||||||
|
Player nearest = Bukkit.getOnlinePlayers().stream()
|
||||||
|
.filter(player -> player.getLocation().getWorld().getName().equals(standPoint.getWorld().getName()))
|
||||||
|
.min(Comparator.comparing(player -> player.getLocation().distance(standPoint)))
|
||||||
|
.filter(player -> Integer.parseInt(getArgument("r")) > player.getLocation().distance(standPoint))
|
||||||
|
.get();
|
||||||
|
players.add(nearest);
|
||||||
|
} else {
|
||||||
|
Bukkit.getOnlinePlayers().stream()
|
||||||
|
.filter(player -> player.getLocation().getWorld().getName().equals(standPoint.getWorld().getName()))
|
||||||
|
.min(Comparator.comparing(player -> player.getLocation().distance(standPoint)))
|
||||||
|
.ifPresent(players::add);
|
||||||
|
}
|
||||||
|
} else if (selector.startsWith("@a")) {
|
||||||
|
//everyone
|
||||||
|
Location standPoint = getLocation(commandSender);
|
||||||
|
|
||||||
|
if (getArgument("r").length() != 0) {
|
||||||
|
players.addAll(Bukkit.getOnlinePlayers().stream()
|
||||||
|
.filter(player -> player.getLocation().getWorld().getName().equals(standPoint.getWorld().getName()))
|
||||||
|
.filter(player -> Integer.parseInt(getArgument("r")) > player.getLocation().distance(standPoint))
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
} else {
|
||||||
|
players.addAll(Bukkit.getOnlinePlayers().stream()
|
||||||
|
.filter(player -> player.getLocation().getWorld().getName().equals(standPoint.getWorld().getName()))
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
} else if (selector.length() <= 16) {
|
||||||
|
//player
|
||||||
|
Player player = Bukkit.getPlayer(selector);
|
||||||
|
if (player != null) players.add(player);
|
||||||
|
} else {
|
||||||
|
commandSender.sendMessage("[ThemePark] Invalid player query. Try something like @a, @p, username or other arguments.");
|
||||||
|
}
|
||||||
|
return players;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* attempt to parse the location
|
||||||
|
*
|
||||||
|
* @param commandSender the sender
|
||||||
|
* @return the location or null
|
||||||
|
*/
|
||||||
|
private Location getLocation(CommandSender commandSender) {
|
||||||
|
Location initialLocation = new Location(Bukkit.getWorlds().get(0), 0, 0, 0);
|
||||||
|
|
||||||
|
if (commandSender instanceof Player) {
|
||||||
|
initialLocation = ((Player) commandSender).getLocation();
|
||||||
|
} else if (commandSender instanceof BlockCommandSender) {
|
||||||
|
initialLocation = ((BlockCommandSender) commandSender).getBlock().getLocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!getArgument("x").equals("") && !getArgument("y").equals("") && !getArgument("z").equals("")) {
|
||||||
|
try {
|
||||||
|
int x = Integer.parseInt(getArgument("x"));
|
||||||
|
int y = Integer.parseInt(getArgument("y"));
|
||||||
|
int z = Integer.parseInt(getArgument("z"));
|
||||||
|
return new Location(initialLocation.getWorld(), x, y, z);
|
||||||
|
} catch (Exception e) {
|
||||||
|
commandSender.sendMessage("[ThemePark] An error occurred when parsing the location as an Integer");
|
||||||
|
return initialLocation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return initialLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getArgument(String key) {
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
String[] arguments = selector.split(key + "=");
|
||||||
|
if (arguments.length == 1) return "";
|
||||||
|
for (byte type : arguments[1].getBytes()) {
|
||||||
|
char element = (char) type;
|
||||||
|
if (element == ',' || element == ']') {
|
||||||
|
return result.toString();
|
||||||
|
} else {
|
||||||
|
result.append(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -15,6 +15,7 @@ no-status: "{prefix} &4There is no status named: {status}"
|
||||||
region:
|
region:
|
||||||
not: "{prefix} &4There is no region with ID: {id}"
|
not: "{prefix} &4There is no region with ID: {id}"
|
||||||
create: "{prefix} &aSuccessfully created region with name: &r{name}"
|
create: "{prefix} &aSuccessfully created region with name: &r{name}"
|
||||||
|
remove: "{prefix} &aSuccessfully removed region with name: &r{name}"
|
||||||
exists: "{prefix} &4There already is a region with ID: {id}"
|
exists: "{prefix} &4There already is a region with ID: {id}"
|
||||||
name: "{prefix} &aChanged name of region to: &r{name}"
|
name: "{prefix} &aChanged name of region to: &r{name}"
|
||||||
|
|
||||||
|
@ -27,6 +28,7 @@ ridecount:
|
||||||
attraction:
|
attraction:
|
||||||
exists: "{prefix} &4There already is a region with ID: {id}"
|
exists: "{prefix} &4There already is a region with ID: {id}"
|
||||||
create: "{prefix} &aSuccessfully created attraction with name: &r{name}"
|
create: "{prefix} &aSuccessfully created attraction with name: &r{name}"
|
||||||
|
remove: "{prefix} &aSuccessfully removed attraction with name: &r{name}"
|
||||||
notfound: "&4No attractions found"
|
notfound: "&4No attractions found"
|
||||||
list: "&6ID: &f{id} &6Name: &f{name} &6Region: &f{region} &6Status: &f{status}"
|
list: "&6ID: &f{id} &6Name: &f{name} &6Region: &f{region} &6Status: &f{status}"
|
||||||
not: "{prefix} &4There is no attraction with ID: {id}"
|
not: "{prefix} &4There is no attraction with ID: {id}"
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
name: ThemePark
|
name: ThemePark
|
||||||
version: 2.0
|
version: 2.3.3
|
||||||
main: nl.iobyte.themepark.ThemeParkPlugin
|
main: nl.iobyte.themepark.ThemeParkPlugin
|
||||||
author: IOByte
|
author: IOByte
|
||||||
website: "https://www.iobyte.nl/"
|
website: "https://www.iobyte.nl/"
|
||||||
softdepend: [dynmap,Multiverse-Core,MultiWorld]
|
softdepend: [dynmap,Multiverse-Core,MultiWorld,Train_Carts]
|
||||||
commands:
|
commands:
|
||||||
status:
|
status:
|
||||||
ridecount:
|
ridecount:
|
|
@ -1,7 +1,11 @@
|
||||||
command: 'tp'
|
command: 'themepark'
|
||||||
workers: 2
|
workers: 2
|
||||||
menu-title: "&6StatusMenu"
|
menu-title: "&6StatusMenu"
|
||||||
|
|
||||||
|
sign:
|
||||||
|
name: "[ThemePark]"
|
||||||
|
title: "&f[&6ThemePark&f]"
|
||||||
|
|
||||||
item:
|
item:
|
||||||
enabled: true
|
enabled: true
|
||||||
material: 'NETHER_STAR'
|
material: 'NETHER_STAR'
|
||||||
|
|
Reference in a new issue