ThemePark 2.0
This commit is contained in:
parent
fe3350cc4f
commit
ad9c5d4139
84 changed files with 3446 additions and 2839 deletions
31
.idea/ThemePark.iml
Normal file
31
.idea/ThemePark.iml
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module version="4">
|
||||||
|
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||||
|
<output url="file://$MODULE_DIR$/target/classes" />
|
||||||
|
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spigotmc:spigot-api:1.8.8-R0.1-SNAPSHOT" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-lang:commons-lang:2.6" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: junit:junit:4.10" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:17.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.2.4" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.avaje:ebean:2.8.1" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.persistence:persistence-api:1.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.15" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: net.md-5:bungeecord-chat:1.8-SNAPSHOT" 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" 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: org.slf4j:slf4j-api:1.7.25" level="project" />
|
||||||
|
</component>
|
||||||
|
</module>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/ThemePark.iml" filepath="$PROJECT_DIR$/.idea/ThemePark.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
95
dependency-reduced-pom.xml
Normal file
95
dependency-reduced-pom.xml
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>nl.iobyte</groupId>
|
||||||
|
<artifactId>themepark</artifactId>
|
||||||
|
<version>2.0</version>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<relocations>
|
||||||
|
<relocation>
|
||||||
|
<pattern>de.tr7zw.changeme.nbtapi</pattern>
|
||||||
|
<shadedPattern>de.tr7zw.nbtapi</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
</relocations>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>placeholderapi</id>
|
||||||
|
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>dynmap</id>
|
||||||
|
<url>http://repo.mikeprimm.com/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
<version>1.8.8-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>commons-lang</artifactId>
|
||||||
|
<groupId>commons-lang</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>json-simple</artifactId>
|
||||||
|
<groupId>com.googlecode.json-simple</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>guava</artifactId>
|
||||||
|
<groupId>com.google.guava</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>ebean</artifactId>
|
||||||
|
<groupId>org.avaje</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>snakeyaml</artifactId>
|
||||||
|
<groupId>org.yaml</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>bungeecord-chat</artifactId>
|
||||||
|
<groupId>net.md-5</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.dynmap</groupId>
|
||||||
|
<artifactId>dynmap-api</artifactId>
|
||||||
|
<version>2.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>bukkit</artifactId>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
</project>
|
45
pom.xml
45
pom.xml
|
@ -9,9 +9,9 @@
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<groupId>me.paradoxpixel</groupId>
|
<groupId>nl.iobyte</groupId>
|
||||||
<artifactId>themepark</artifactId>
|
<artifactId>themepark</artifactId>
|
||||||
<version>1.4.1</version>
|
<version>2.0</version>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
|
@ -37,5 +37,46 @@
|
||||||
<version>2.0</version>
|
<version>2.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>nl.iobyte</groupId>
|
||||||
|
<artifactId>menuapi</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.zaxxer</groupId>
|
||||||
|
<artifactId>HikariCP</artifactId>
|
||||||
|
<version>3.4.3</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>nl.iobyte</groupId>
|
||||||
|
<artifactId>workchain</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<relocations>
|
||||||
|
<relocation>
|
||||||
|
<pattern>de.tr7zw.changeme.nbtapi</pattern>
|
||||||
|
<shadedPattern>de.tr7zw.nbtapi</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
</relocations>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
</project>
|
</project>
|
|
@ -1,118 +0,0 @@
|
||||||
package me.paradoxpixel.themepark;
|
|
||||||
|
|
||||||
import me.paradoxpixel.themepark.attraction.AttractionMenu;
|
|
||||||
import me.paradoxpixel.themepark.attraction.sign.SignManager;
|
|
||||||
import me.paradoxpixel.themepark.attraction.status.StatusManager;
|
|
||||||
import me.paradoxpixel.themepark.command.MenuCommand;
|
|
||||||
import me.paradoxpixel.themepark.command.ThemeParkCommand;
|
|
||||||
import me.paradoxpixel.themepark.config.YamlConfig;
|
|
||||||
import me.paradoxpixel.themepark.database.DatabaseHandler;
|
|
||||||
import me.paradoxpixel.themepark.gui.GUIListener;
|
|
||||||
import me.paradoxpixel.themepark.listener.ClickListener;
|
|
||||||
import me.paradoxpixel.themepark.listener.ChangeListener;
|
|
||||||
import me.paradoxpixel.themepark.listener.PlayerListener;
|
|
||||||
import me.paradoxpixel.themepark.listener.SignListener;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandMap;
|
|
||||||
import org.bukkit.plugin.PluginManager;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
public class ThemeParkPlugin extends JavaPlugin {
|
|
||||||
|
|
||||||
private static ThemeParkPlugin instance;
|
|
||||||
private YamlConfig settings, attraction, message, signs, data;
|
|
||||||
private DatabaseHandler database;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEnable() {
|
|
||||||
instance = this;
|
|
||||||
loadConfig();
|
|
||||||
loadListener();
|
|
||||||
loadCommand();
|
|
||||||
loadData();
|
|
||||||
loadDatabase();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadConfig() {
|
|
||||||
settings = new YamlConfig("settings", this);
|
|
||||||
attraction = new YamlConfig("attraction", this);
|
|
||||||
message = new YamlConfig("message", this);
|
|
||||||
signs = new YamlConfig("signs", this);
|
|
||||||
data = new YamlConfig("data", this);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadData() {
|
|
||||||
StatusManager.load();
|
|
||||||
AttractionMenu.load();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadDatabase() {
|
|
||||||
database = new DatabaseHandler(settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadCommand() {
|
|
||||||
getCommand("status").setExecutor(new MenuCommand());
|
|
||||||
|
|
||||||
String command = settings.getConfig().getString("command");
|
|
||||||
if(command == null || command.isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
final Field bukkitCommandMap = Bukkit.getServer().getClass().getDeclaredField("commandMap");
|
|
||||||
|
|
||||||
bukkitCommandMap.setAccessible(true);
|
|
||||||
CommandMap commandMap = (CommandMap) bukkitCommandMap.get(Bukkit.getServer());
|
|
||||||
|
|
||||||
commandMap.register(command, new ThemeParkCommand(command));
|
|
||||||
} catch(ReflectiveOperationException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadListener() {
|
|
||||||
PluginManager pm = Bukkit.getPluginManager();
|
|
||||||
pm.registerEvents(new GUIListener(), this);
|
|
||||||
pm.registerEvents(new ClickListener(), this);
|
|
||||||
pm.registerEvents(new ChangeListener(), this);
|
|
||||||
pm.registerEvents(new SignListener(), this);
|
|
||||||
pm.registerEvents(new PlayerListener(), this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDisable() {
|
|
||||||
AttractionMenu.save();
|
|
||||||
SignManager.saveSigns();
|
|
||||||
database.disconnect();
|
|
||||||
instance = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ThemeParkPlugin getInstance() {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public YamlConfig getSettings() {
|
|
||||||
return settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public YamlConfig getAttraction() {
|
|
||||||
return attraction;
|
|
||||||
}
|
|
||||||
|
|
||||||
public YamlConfig getMessage() {
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public YamlConfig getSigns() {
|
|
||||||
return signs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public YamlConfig getData() {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DatabaseHandler getDatabaseHandler() {
|
|
||||||
return database;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,20 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.action;
|
|
||||||
|
|
||||||
import me.paradoxpixel.themepark.attraction.AttractionMenu;
|
|
||||||
import me.paradoxpixel.themepark.gui.GUIAction;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class PageAction extends GUIAction {
|
|
||||||
|
|
||||||
private int page;
|
|
||||||
|
|
||||||
public PageAction(int page) {
|
|
||||||
this.page = page;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void click(Player player) {
|
|
||||||
AttractionMenu.openMenu(player, page);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,49 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.action;
|
|
||||||
|
|
||||||
import me.paradoxpixel.themepark.api.API;
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.Attraction;
|
|
||||||
import me.paradoxpixel.themepark.attraction.AttractionMenu;
|
|
||||||
import me.paradoxpixel.themepark.attraction.status.StatusManager;
|
|
||||||
import me.paradoxpixel.themepark.gui.GUIAction;
|
|
||||||
import me.paradoxpixel.themepark.utils.Message;
|
|
||||||
import me.paradoxpixel.themepark.utils.Utils;
|
|
||||||
import org.bukkit.entity.Minecart;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class TPUtils extends GUIAction {
|
|
||||||
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
public TPUtils(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void click(Player player) {
|
|
||||||
player.closeInventory();
|
|
||||||
Attraction attraction = API.getAttraction(id);
|
|
||||||
if(attraction == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(attraction.getLocation() == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(!StatusManager.canTeleport(attraction.getStatus())) {
|
|
||||||
String message = Message.getMessage("attraction.teleport.status");
|
|
||||||
message = message.replace("{name}", attraction.getName());
|
|
||||||
message = message.replace("{status}", StatusManager.getName(attraction.getStatus()));
|
|
||||||
player.sendMessage(Utils.color(message));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(player.isInsideVehicle())
|
|
||||||
if(player.getVehicle() instanceof Minecart)
|
|
||||||
return;
|
|
||||||
|
|
||||||
player.teleport(attraction.getLocation());
|
|
||||||
String message = Message.getMessage("attraction.teleport.success");
|
|
||||||
message = message.replace("{name}", attraction.getName());
|
|
||||||
player.sendMessage(Utils.color(message));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,160 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.api;
|
|
||||||
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.Attraction;
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.Region;
|
|
||||||
import me.paradoxpixel.themepark.api.event.attraction.AddAttractionEvent;
|
|
||||||
import me.paradoxpixel.themepark.api.event.attraction.RemoveAttractionEvent;
|
|
||||||
import me.paradoxpixel.themepark.api.event.region.AddRegionEvent;
|
|
||||||
import me.paradoxpixel.themepark.api.event.region.RemoveRegionEvent;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class API {
|
|
||||||
|
|
||||||
private static LinkedHashMap<String, Region> regions = new LinkedHashMap<>();
|
|
||||||
private static LinkedHashMap<String, Attraction> attractions = new LinkedHashMap<>();
|
|
||||||
|
|
||||||
public static void addRegion(Region region) {
|
|
||||||
if(isRegion(region.getId()))
|
|
||||||
return;
|
|
||||||
|
|
||||||
region = toLower(region);
|
|
||||||
regions.put(region.getId(), region);
|
|
||||||
|
|
||||||
AddRegionEvent event = new AddRegionEvent(region);
|
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isRegion(String id) {
|
|
||||||
if(id == null || id.isEmpty())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return regions.containsKey(id.toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isRegionFull(String id) {
|
|
||||||
if(!isRegion(id))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return getRegion(id).getAttractions().size() >= 8;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Region getRegion(String id) {
|
|
||||||
if(id == null || id.isEmpty())
|
|
||||||
return null;
|
|
||||||
|
|
||||||
return regions.get(id.toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HashMap<String, Region> getRegions() {
|
|
||||||
return new LinkedHashMap<>(regions);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void removeRegion(String id) {
|
|
||||||
if(!isRegion(id))
|
|
||||||
return;
|
|
||||||
|
|
||||||
HashMap<String, Attraction> map = new HashMap<>(attractions);
|
|
||||||
for(Map.Entry<String, Attraction> entry : map.entrySet()) {
|
|
||||||
Attraction attraction = entry.getValue();
|
|
||||||
if(!attraction.getRegion_id().equalsIgnoreCase(id))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
removeAttraction(attraction.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
RemoveRegionEvent event = new RemoveRegionEvent(getRegion(id));
|
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
regions.remove(id.toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void addAttraction(Attraction attraction) {
|
|
||||||
if(!isRegion(attraction.getRegion_id()))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(isRegionFull(attraction.getRegion_id()))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(isAttraction(attraction.getId()))
|
|
||||||
return;
|
|
||||||
|
|
||||||
attraction = toLower(attraction);
|
|
||||||
getRegion(attraction.getRegion_id()).addAttraction(attraction);
|
|
||||||
attractions.put(attraction.getId(), attraction);
|
|
||||||
|
|
||||||
AddAttractionEvent event = new AddAttractionEvent(attraction);
|
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isAttraction(String id) {
|
|
||||||
if(id == null || id.isEmpty())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return attractions.containsKey(id.toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Attraction getAttraction(String id) {
|
|
||||||
if(id == null || id.isEmpty())
|
|
||||||
return null;
|
|
||||||
|
|
||||||
return attractions.get(id.toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Attraction getAttractionFromName(String name) {
|
|
||||||
if(name == null || name.isEmpty())
|
|
||||||
return null;
|
|
||||||
|
|
||||||
for(Attraction attraction : attractions.values()) {
|
|
||||||
if(!color(attraction.getName()).equals(name))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
return attraction;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HashMap<String, Attraction> getAttractions() {
|
|
||||||
return new LinkedHashMap<>(attractions);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void removeAttraction(String id) {
|
|
||||||
if(!isAttraction(id))
|
|
||||||
return;
|
|
||||||
|
|
||||||
Attraction attraction = getAttraction(id);
|
|
||||||
if(isRegion(attraction.getRegion_id()))
|
|
||||||
getRegion(attraction.getRegion_id()).removeAttraction(attraction);
|
|
||||||
|
|
||||||
attractions.remove(id.toLowerCase());
|
|
||||||
|
|
||||||
RemoveAttractionEvent event = new RemoveAttractionEvent(attraction);
|
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Region toLower(Region region) {
|
|
||||||
Region re = new Region(region.getId().toLowerCase(),
|
|
||||||
region.getName(),
|
|
||||||
region.getLore());
|
|
||||||
|
|
||||||
re.setAttractions(region.getAttractions());
|
|
||||||
return re;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Attraction toLower(Attraction attraction) {
|
|
||||||
return new Attraction(attraction.getId().toLowerCase(),
|
|
||||||
attraction.getName(),
|
|
||||||
attraction.getRegion_id().toLowerCase(),
|
|
||||||
attraction.getLocation(),
|
|
||||||
attraction.getType(),
|
|
||||||
attraction.getStatus());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String color(String string) {
|
|
||||||
return ChatColor.translateAlternateColorCodes('&', string);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,118 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.api.attraction;
|
|
||||||
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.component.Status;
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.component.Type;
|
|
||||||
import me.paradoxpixel.themepark.api.event.attraction.PreStatusChangeEvent;
|
|
||||||
import me.paradoxpixel.themepark.api.event.attraction.StatusChangeEvent;
|
|
||||||
import me.paradoxpixel.themepark.api.event.attraction.ChangeAttractionEvent;
|
|
||||||
import me.paradoxpixel.themepark.api.LocationUtils;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Attraction {
|
|
||||||
|
|
||||||
private String id, name, region_id;
|
|
||||||
private Location location;
|
|
||||||
private Type type;
|
|
||||||
private Status status;
|
|
||||||
|
|
||||||
public Attraction(String id, String name, String region_id, Location location, Type type, Status status) {
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
this.region_id = region_id;
|
|
||||||
this.location = location;
|
|
||||||
this.type = type;
|
|
||||||
this.status = type.containsStatus(status) ? status : type.getDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
if(this.name.equals(name))
|
|
||||||
return;
|
|
||||||
|
|
||||||
ChangeAttractionEvent event = new ChangeAttractionEvent(this, this.name, name, region_id, region_id, location, location, type, type);
|
|
||||||
this.name = name;
|
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRegion_id() {
|
|
||||||
return region_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRegion_id(String region_id) {
|
|
||||||
if(this.region_id.equals(region_id))
|
|
||||||
return;
|
|
||||||
|
|
||||||
ChangeAttractionEvent event = new ChangeAttractionEvent(this, name, name, this.region_id, region_id, location, location, type, type);
|
|
||||||
this.region_id = region_id;
|
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Location getLocation() {
|
|
||||||
return location;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLocation(Location location) {
|
|
||||||
if(location == this.location)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(location == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(LocationUtils.toString(location) == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(LocationUtils.toString(this.location) != null && LocationUtils.toString(location) != null)
|
|
||||||
if(LocationUtils.toString(this.location).equals(LocationUtils.toString(location)))
|
|
||||||
return;
|
|
||||||
|
|
||||||
ChangeAttractionEvent event = new ChangeAttractionEvent(this, name, name, region_id, region_id, this.location, location, type, type);
|
|
||||||
this.location = location;
|
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Type getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setType(Type type) {
|
|
||||||
ChangeAttractionEvent event = new ChangeAttractionEvent(this, name, name, region_id, region_id, location, location, this.type, type);
|
|
||||||
this.type = type;
|
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
if(!type.containsStatus(status))
|
|
||||||
setStatus(type.getDefault(), null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Status getStatus() {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatus(Status status, Player player) {
|
|
||||||
if(!type.hasStatus())
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(!type.containsStatus(status))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(this.status == status)
|
|
||||||
return;
|
|
||||||
|
|
||||||
PreStatusChangeEvent event = new PreStatusChangeEvent(this, player, this.status, status);
|
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
if(event.isCancelled())
|
|
||||||
return;
|
|
||||||
|
|
||||||
this.status = status;
|
|
||||||
StatusChangeEvent e = new StatusChangeEvent(this, player, this.status, status);
|
|
||||||
Bukkit.getPluginManager().callEvent(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,96 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.api.attraction;
|
|
||||||
|
|
||||||
import me.paradoxpixel.themepark.api.event.region.ChangeRegionEvent;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Region {
|
|
||||||
|
|
||||||
private String id, name;
|
|
||||||
private List<String> lore;
|
|
||||||
private ArrayList<Attraction> attractions;
|
|
||||||
|
|
||||||
public Region(String id, String name, List<String> lore) {
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
this.lore = lore;
|
|
||||||
this.attractions = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String string) {
|
|
||||||
if(string == null || string.equals(""))
|
|
||||||
return;
|
|
||||||
|
|
||||||
String old = name;
|
|
||||||
name = string;
|
|
||||||
|
|
||||||
ChangeRegionEvent event = new ChangeRegionEvent(this, old, string, lore, lore);
|
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getLore() {
|
|
||||||
return lore;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLore(List<String> lore) {
|
|
||||||
List<String> old = lore;
|
|
||||||
this.lore = lore;
|
|
||||||
|
|
||||||
ChangeRegionEvent event = new ChangeRegionEvent(this, name, name, old, lore);
|
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLore(int i, String string) {
|
|
||||||
if(lore.size() >= 4 || i >= 4)
|
|
||||||
return;
|
|
||||||
|
|
||||||
List<String> old = lore;
|
|
||||||
lore = new ArrayList<>();
|
|
||||||
lore.addAll(old);
|
|
||||||
|
|
||||||
if(!string.equals("NULL")) {
|
|
||||||
if (lore.size() >= i)
|
|
||||||
for (int a = 0; a <= (i - lore.size()); a++)
|
|
||||||
lore.add(" ");
|
|
||||||
|
|
||||||
lore.set(i, string);
|
|
||||||
} else {
|
|
||||||
lore.remove(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
ChangeRegionEvent event = new ChangeRegionEvent(this, name, name, old, lore);
|
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<Attraction> getAttractions() {
|
|
||||||
return attractions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAttractions(ArrayList<Attraction> attractions) {
|
|
||||||
this.attractions = attractions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addAttraction(Attraction attraction) {
|
|
||||||
if(!isAttraction(attraction))
|
|
||||||
attractions.add(attraction);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isAttraction(Attraction attraction) {
|
|
||||||
return attractions.contains(attraction);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeAttraction(Attraction attraction) {
|
|
||||||
if(isAttraction(attraction))
|
|
||||||
attractions.remove(attraction);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.api.event.attraction;
|
|
||||||
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.Attraction;
|
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
|
|
||||||
public class AddAttractionEvent extends Event {
|
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
private Attraction attraction;
|
|
||||||
|
|
||||||
public AddAttractionEvent(Attraction attraction) {
|
|
||||||
this.attraction = attraction;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Attraction getAttraction() {
|
|
||||||
return attraction;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,79 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.api.event.attraction;
|
|
||||||
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.Attraction;
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.component.Type;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
|
|
||||||
public class ChangeAttractionEvent extends Event {
|
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
private Attraction attraction;
|
|
||||||
private String bname, aname, bregion_id, aregion_id;
|
|
||||||
private Location blocation, alocation;
|
|
||||||
private Type btype, atype;
|
|
||||||
|
|
||||||
public ChangeAttractionEvent(Attraction attraction,
|
|
||||||
String bname, String aname,
|
|
||||||
String aregion_id, String bregion_id,
|
|
||||||
Location alocation, Location blocation,
|
|
||||||
Type btype, Type atype) {
|
|
||||||
this.attraction = attraction;
|
|
||||||
this.bname = bname;
|
|
||||||
this.aname = aname;
|
|
||||||
this.bregion_id = bregion_id;
|
|
||||||
this.aregion_id = aregion_id;
|
|
||||||
this.alocation = alocation;
|
|
||||||
this.blocation = blocation;
|
|
||||||
this.btype = btype;
|
|
||||||
this.atype = atype;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Attraction getAttraction() {
|
|
||||||
return attraction;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getNameBefore() {
|
|
||||||
return bname;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getNameAfter() {
|
|
||||||
return aname;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRegionIdBefore() {
|
|
||||||
return bregion_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRegionIdAfter() {
|
|
||||||
return aregion_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Location getLocationBefore() {
|
|
||||||
return blocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Location getLocationAfter() {
|
|
||||||
return alocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Type getTypeBefore() {
|
|
||||||
return btype;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Type getTypeAfter() {
|
|
||||||
return atype;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,61 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.api.event.attraction;
|
|
||||||
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.Attraction;
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.component.Status;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.Cancellable;
|
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
|
|
||||||
public class PreStatusChangeEvent extends Event implements Cancellable {
|
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
private boolean cancel;
|
|
||||||
private Attraction attraction;
|
|
||||||
private Player player;
|
|
||||||
private Status before, after;
|
|
||||||
|
|
||||||
public PreStatusChangeEvent(Attraction attraction, Player player, Status before, Status after) {
|
|
||||||
this.attraction = attraction;
|
|
||||||
this.player = player;
|
|
||||||
this.before = before;
|
|
||||||
this.after = after;
|
|
||||||
cancel = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCancelled() {
|
|
||||||
return cancel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setCancelled(boolean b) {
|
|
||||||
cancel = b;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Attraction getAttraction() {
|
|
||||||
return attraction;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Player getPlayer() {
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Status getStatusBefore() {
|
|
||||||
return before;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Status getStatusAfter() {
|
|
||||||
return after;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.api.event.attraction;
|
|
||||||
|
|
||||||
import me.paradoxpixel.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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,48 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.api.event.attraction;
|
|
||||||
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.Attraction;
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.component.Status;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
|
|
||||||
public class StatusChangeEvent extends Event {
|
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
private Attraction attraction;
|
|
||||||
private Player player;
|
|
||||||
private Status before, after;
|
|
||||||
|
|
||||||
public StatusChangeEvent(Attraction attraction, Player player, Status before, Status after) {
|
|
||||||
this.attraction = attraction;
|
|
||||||
this.player = player;
|
|
||||||
this.before = before;
|
|
||||||
this.after = after;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Attraction getAttraction() {
|
|
||||||
return attraction;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Player getPlayer() {
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Status getStatusBefore() {
|
|
||||||
return before;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Status getStatusAfter() {
|
|
||||||
return after;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.api.event.region;
|
|
||||||
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.Region;
|
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
|
|
||||||
public class AddRegionEvent extends Event {
|
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
private Region region;
|
|
||||||
|
|
||||||
public AddRegionEvent(Region region) {
|
|
||||||
this.region = region;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Region getRegion() {
|
|
||||||
return region;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,53 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.api.event.region;
|
|
||||||
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.Region;
|
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ChangeRegionEvent extends Event {
|
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
private Region region;
|
|
||||||
private String bname, aname;
|
|
||||||
private List<String> blore, alore;
|
|
||||||
|
|
||||||
public ChangeRegionEvent(Region region, String bname, String aname, List<String> blore, List<String> alore) {
|
|
||||||
this.region = region;
|
|
||||||
this.bname = bname;
|
|
||||||
this.aname = aname;
|
|
||||||
this.blore = blore;
|
|
||||||
this.alore = alore;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Region getRegion() {
|
|
||||||
return region;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getNameBefore() {
|
|
||||||
return bname;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getNameAfter() {
|
|
||||||
return aname;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getLoreBefore() {
|
|
||||||
return blore;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getLoreAfter() {
|
|
||||||
return alore;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.api.event.region;
|
|
||||||
|
|
||||||
import me.paradoxpixel.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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,359 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.attraction;
|
|
||||||
|
|
||||||
import me.paradoxpixel.themepark.ThemeParkPlugin;
|
|
||||||
import me.paradoxpixel.themepark.action.PageAction;
|
|
||||||
import me.paradoxpixel.themepark.action.TPUtils;
|
|
||||||
import me.paradoxpixel.themepark.api.API;
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.Attraction;
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.Region;
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.component.Status;
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.component.Type;
|
|
||||||
import me.paradoxpixel.themepark.attraction.status.StatusManager;
|
|
||||||
import me.paradoxpixel.themepark.config.YamlConfig;
|
|
||||||
import me.paradoxpixel.themepark.gui.GUI;
|
|
||||||
import me.paradoxpixel.themepark.gui.GUIItem;
|
|
||||||
import me.paradoxpixel.themepark.utils.ItemBuilder;
|
|
||||||
import me.paradoxpixel.themepark.api.LocationUtils;
|
|
||||||
import me.paradoxpixel.themepark.utils.Utils;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class AttractionMenu {
|
|
||||||
|
|
||||||
private static YamlConfig config = ThemeParkPlugin.getInstance().getAttraction();
|
|
||||||
private static YamlConfig settings = ThemeParkPlugin.getInstance().getSettings();
|
|
||||||
private static HashMap<Integer, GUI> pages = new HashMap<>();
|
|
||||||
private static boolean loading = false;
|
|
||||||
private static String title;
|
|
||||||
|
|
||||||
private static HashMap<String, Integer> regionPage;
|
|
||||||
private static HashMap<String, Integer> attractionIndex;
|
|
||||||
|
|
||||||
private static Material mat = Material.NAME_TAG;
|
|
||||||
private static short data = 0;
|
|
||||||
|
|
||||||
public static void load() {
|
|
||||||
loading = true;
|
|
||||||
title = settings.getConfig().getString("menu.title");
|
|
||||||
|
|
||||||
mat = Material.getMaterial(settings.getConfig().getString("region.material"));
|
|
||||||
data = Short.parseShort(settings.getConfig().getString("region.data"));
|
|
||||||
|
|
||||||
regionPage = new HashMap<>();
|
|
||||||
attractionIndex = new HashMap<>();
|
|
||||||
|
|
||||||
loadData();
|
|
||||||
loading = false;
|
|
||||||
loadItems();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void reload() {
|
|
||||||
loadItems();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void save() {
|
|
||||||
for(Region region : API.getRegions().values()) {
|
|
||||||
config.getConfig().set("region." + region.getId() + ".name", region.getName());
|
|
||||||
config.getConfig().set("region." + region.getId() + ".lore", region.getLore());
|
|
||||||
}
|
|
||||||
|
|
||||||
for(Attraction attraction : API.getAttractions().values()) {
|
|
||||||
config.getConfig().set("attraction." + attraction.getId() + ".name", attraction.getName());
|
|
||||||
config.getConfig().set("attraction." + attraction.getId() + ".region_id", attraction.getRegion_id());
|
|
||||||
config.getConfig().set("attraction." + attraction.getId() + ".type", attraction.getType().toString());
|
|
||||||
config.getConfig().set("attraction." + attraction.getId() + ".status", attraction.getStatus().toString());
|
|
||||||
config.getConfig().set("attraction." + attraction.getId() + ".location", LocationUtils.toString(attraction.getLocation()));
|
|
||||||
}
|
|
||||||
|
|
||||||
config.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void loadData() {
|
|
||||||
if(!config.getConfig().contains("region"))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(!config.getConfig().isConfigurationSection("region"))
|
|
||||||
return;
|
|
||||||
|
|
||||||
ConfigurationSection section = config.getConfig().getConfigurationSection("region");
|
|
||||||
if(section.getKeys(false).isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
HashMap<String, Region> regions = API.getRegions();
|
|
||||||
HashMap<String, Integer> size = new HashMap<>();
|
|
||||||
for(String id : section.getKeys(false)) {
|
|
||||||
String name = config.getConfig().getString("region." + id + ".name");
|
|
||||||
List<String> lore = config.getConfig().getStringList("region." + id + ".lore");
|
|
||||||
|
|
||||||
size.put(id.toLowerCase(), 0);
|
|
||||||
regions.remove(id);
|
|
||||||
if(API.isRegion(id)) {
|
|
||||||
API.getRegion(id).setName(name);
|
|
||||||
API.getRegion(id).setLore(lore);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Region region = new Region(id, name, lore);
|
|
||||||
API.addRegion(region);
|
|
||||||
if(!id.toLowerCase().equals(id)) {
|
|
||||||
config.getConfig().set("region." + id, null);
|
|
||||||
id = id.toLowerCase();
|
|
||||||
config.getConfig().set("region." + id + ".name", name);
|
|
||||||
config.getConfig().set("region." + id + ".lore", lore);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
config.save();
|
|
||||||
for(String string : regions.keySet())
|
|
||||||
API.removeRegion(string);
|
|
||||||
|
|
||||||
prepareGUI();
|
|
||||||
if(!config.getConfig().contains("attraction"))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(!config.getConfig().isConfigurationSection("attraction"))
|
|
||||||
return;
|
|
||||||
|
|
||||||
section = config.getConfig().getConfigurationSection("attraction");
|
|
||||||
if(section.getKeys(false).isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
HashMap<String, Attraction> attractions = API.getAttractions();
|
|
||||||
for(String id : section.getKeys(false)) {
|
|
||||||
String region_id = config.getConfig().getString("attraction." + id + ".region_id");
|
|
||||||
if(region_id == null || region_id.isEmpty())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if(!region_id.toLowerCase().equals(region_id)) {
|
|
||||||
region_id = region_id.toLowerCase();
|
|
||||||
config.getConfig().set("attraction." + id + ".region_id", region_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!API.isRegion(region_id))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if(size.get(region_id.toLowerCase()) >= 8)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
String name = config.getConfig().getString("attraction." + id + ".name");
|
|
||||||
Location location = LocationUtils.toLocation(config.getConfig().getString("attraction." + id + ".location"));
|
|
||||||
Type type = Type.getType(config.getConfig().getString("attraction." + id + ".type"));
|
|
||||||
Status status = Status.getStatus(config.getConfig().getString("attraction." + id + ".status"));
|
|
||||||
if(!type.containsStatus(status)) {
|
|
||||||
status = type.getDefault();
|
|
||||||
config.getConfig().set("attraction." + id + ".status", type.getDefault().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
attractions.remove(id.toLowerCase());
|
|
||||||
size.put(region_id.toLowerCase(), size.get(region_id.toLowerCase()) + 1);
|
|
||||||
if(API.isAttraction(id)) {
|
|
||||||
Attraction attraction = API.getAttraction(id);
|
|
||||||
attraction.setName(name);
|
|
||||||
attraction.setRegion_id(region_id);
|
|
||||||
attraction.setLocation(location);
|
|
||||||
attraction.setType(type);
|
|
||||||
attraction.setStatus(status, null);
|
|
||||||
MapMarker.getMarker().setAttractionMarker(attraction);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Attraction attraction = new Attraction(id, name, region_id, location, type, status);
|
|
||||||
API.addAttraction(attraction);
|
|
||||||
MapMarker.getMarker().setAttractionMarker(attraction);
|
|
||||||
if(!id.toLowerCase().equals(id)) {
|
|
||||||
config.getConfig().set("attraction." + id, null);
|
|
||||||
id = id.toLowerCase();
|
|
||||||
config.getConfig().set("attraction." + id + ".name", name);
|
|
||||||
config.getConfig().set("attraction." + id + ".location", LocationUtils.toString(location));
|
|
||||||
config.getConfig().set("attraction." + id + ".type", type.toString());
|
|
||||||
config.getConfig().set("attraction." + id + ".status", status.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
config.save();
|
|
||||||
for(String string : attractions.keySet())
|
|
||||||
API.removeAttraction(string);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void prepareGUI() {
|
|
||||||
int keySize = API.getRegions().size();
|
|
||||||
if(pages.isEmpty()) {
|
|
||||||
if(keySize <= 6) {
|
|
||||||
pages.put(1, new GUI(title, keySize * 9));
|
|
||||||
} else {
|
|
||||||
int p = keySize / 5;
|
|
||||||
for(int i = 0; i < p; i++)
|
|
||||||
pages.put(i + 1, new GUI(title, 54));
|
|
||||||
|
|
||||||
int rest = keySize % 5;
|
|
||||||
if(rest > 0)
|
|
||||||
pages.put(p + 1, new GUI(title, rest * 9 + 9));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(keySize <= 6) {
|
|
||||||
if(pages.size() > 1) {
|
|
||||||
for(int i = 1; i < pages.size(); i++)
|
|
||||||
pages.remove(i + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int z = keySize*9;
|
|
||||||
GUI gui = pages.get(1);
|
|
||||||
if(gui.getSize() != z)
|
|
||||||
gui.setSize(z);
|
|
||||||
} else {
|
|
||||||
int p = keySize / 5;
|
|
||||||
int rest = keySize % 5;
|
|
||||||
if (rest > 0)
|
|
||||||
p++;
|
|
||||||
|
|
||||||
if (pages.size() < p) {
|
|
||||||
for (int i = (pages.size() + 1); i < p; i++)
|
|
||||||
pages.put(i, new GUI(title, 54));
|
|
||||||
|
|
||||||
pages.put(p, new GUI(title, rest * 9 + 9));
|
|
||||||
} else {
|
|
||||||
if (pages.size() > p) {
|
|
||||||
for (int i = pages.size(); i > p; i--)
|
|
||||||
pages.remove(i);
|
|
||||||
} else {
|
|
||||||
if(rest != 0) {
|
|
||||||
pages.get(p).setSize(rest * 9 + 9);
|
|
||||||
} else {
|
|
||||||
pages.get(p).setSize(54);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void update(Attraction attraction) {
|
|
||||||
if(attraction == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(!API.isAttraction(attraction.getId()))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(!attractionIndex.containsKey(attraction.getId()))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(!regionPage.containsKey(attraction.getRegion_id()))
|
|
||||||
return;
|
|
||||||
|
|
||||||
ItemBuilder builder = new ItemBuilder(StatusManager.getMaterial(attraction.getStatus()), 1, StatusManager.getData(attraction.getStatus()));
|
|
||||||
builder.setName(attraction.getName());
|
|
||||||
builder.setLore(StatusManager.getName(attraction.getStatus()));
|
|
||||||
|
|
||||||
GUI gui = pages.get(regionPage.get(attraction.getRegion_id()));
|
|
||||||
gui.addItem(attractionIndex.get(attraction.getId()), new GUIItem(builder.getItem(), new TPUtils(attraction.getId()), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void loadItems() {
|
|
||||||
if(loading)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(API.getRegions().values().size() == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for(GUI gui : pages.values())
|
|
||||||
gui.clear();
|
|
||||||
|
|
||||||
int i = 1;
|
|
||||||
int j = 0;
|
|
||||||
boolean tb = pages.size() > 1;
|
|
||||||
HashMap<String, Integer> index = new HashMap<>();
|
|
||||||
for(Region region : API.getRegions().values()) {
|
|
||||||
if(tb && j >= 5) {
|
|
||||||
i++;
|
|
||||||
j = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
index.put(region.getId(), j * 9);
|
|
||||||
regionPage.put(region.getId(), i);
|
|
||||||
if(!index.containsKey(region.getId()))
|
|
||||||
index.put(region.getId(), index.size() * 9);
|
|
||||||
|
|
||||||
ItemBuilder builder = new ItemBuilder(mat, 1, data);
|
|
||||||
builder.setName(region.getName());
|
|
||||||
builder.setLore(region.getLore());
|
|
||||||
|
|
||||||
GUI gui = pages.get(i);
|
|
||||||
gui.addItem(j * 9, new GUIItem(builder.getItem(), null, true));
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
for(Attraction attraction : API.getAttractions().values()) {
|
|
||||||
if(!API.isRegion(attraction.getRegion_id())) {
|
|
||||||
API.removeAttraction(attraction.getId());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!index.containsKey(attraction.getRegion_id()))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
int in = index.get(attraction.getRegion_id());
|
|
||||||
GUI gui = pages.get(regionPage.get(attraction.getRegion_id()));
|
|
||||||
boolean b = false;
|
|
||||||
for(int a = 1; a < 9; a++) {
|
|
||||||
if(!gui.hasItem(in + a)) {
|
|
||||||
in += a;
|
|
||||||
b = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!b) {
|
|
||||||
API.removeAttraction(attraction.getId());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemBuilder builder = new ItemBuilder(StatusManager.getMaterial(attraction.getStatus()), 1, StatusManager.getData(attraction.getStatus()));
|
|
||||||
builder.setName(attraction.getName());
|
|
||||||
builder.setLore(StatusManager.getName(attraction.getStatus()));
|
|
||||||
|
|
||||||
gui.addItem(in, new GUIItem(builder.getItem(), new TPUtils(attraction.getId()), true));
|
|
||||||
attractionIndex.put(attraction.getId(), in);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(pages.size() <= 1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
i = 1;
|
|
||||||
for(GUI gui : pages.values()) {
|
|
||||||
int rows = gui.getSize() / 9;
|
|
||||||
int offset = (rows - 1) * 9;
|
|
||||||
|
|
||||||
if(i > 1) {
|
|
||||||
ItemBuilder previous = new ItemBuilder(Material.ARROW);
|
|
||||||
previous.setName(Utils.color("&6Previous"));
|
|
||||||
gui.addItem(offset + 3, new GUIItem(previous.getItem(), new PageAction(i - 1), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemBuilder middle = new ItemBuilder(Material.STAINED_GLASS_PANE, 1, (short) 1);
|
|
||||||
middle.setName(Utils.color("&6Page: "+i));
|
|
||||||
gui.addItem(offset + 4, new GUIItem(middle.getItem(), null, true));
|
|
||||||
|
|
||||||
if(i < pages.size()) {
|
|
||||||
ItemBuilder next = new ItemBuilder(Material.ARROW);
|
|
||||||
next.setName(Utils.color("&6Next"));
|
|
||||||
gui.addItem(offset + 5, new GUIItem(next.getItem(), new PageAction(i + 1), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void openMenu(Player player, int page) {
|
|
||||||
if(page < 1 || page > pages.size())
|
|
||||||
page = 1;
|
|
||||||
|
|
||||||
player.openInventory(pages.get(page).getInventory());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,152 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.attraction.sign;
|
|
||||||
|
|
||||||
import me.paradoxpixel.themepark.ThemeParkPlugin;
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.Attraction;
|
|
||||||
import me.paradoxpixel.themepark.config.YamlConfig;
|
|
||||||
import me.paradoxpixel.themepark.api.LocationUtils;
|
|
||||||
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 = LocationUtils.toLocation(string);
|
|
||||||
if(location == null) {
|
|
||||||
System.out.println("SignManager: Incorrect sign Location");
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void saveSigns() {
|
|
||||||
for(Map.Entry<Attraction, ArrayList<StatusSign>> entry : signs.entrySet()) {
|
|
||||||
List<String> array = new ArrayList<>();
|
|
||||||
for(StatusSign sign : entry.getValue())
|
|
||||||
if(LocationUtils.toString(sign.getLocation()) != null)
|
|
||||||
array.add(LocationUtils.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 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;
|
|
||||||
|
|
||||||
ArrayList<StatusSign> array = signs.get(sign.getAttraction());
|
|
||||||
for(StatusSign s : new ArrayList<>(array)) {
|
|
||||||
Location loc1 = sign.getLocation();
|
|
||||||
Location loc2 = s.getLocation();
|
|
||||||
|
|
||||||
if(loc1 == null || loc2 == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(LocationUtils.toString(loc1) == null || LocationUtils.toString(loc2) == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(!LocationUtils.toString(loc1).equals(LocationUtils.toString(loc2)))
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,43 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.attraction.sign;
|
|
||||||
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.Attraction;
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.component.Status;
|
|
||||||
import me.paradoxpixel.themepark.attraction.status.StatusManager;
|
|
||||||
import me.paradoxpixel.themepark.utils.Utils;
|
|
||||||
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(2, Utils.color(StatusManager.getName(status)));
|
|
||||||
sign.update();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,76 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.attraction.status;
|
|
||||||
|
|
||||||
import me.paradoxpixel.themepark.ThemeParkPlugin;
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.component.Status;
|
|
||||||
import me.paradoxpixel.themepark.config.YamlConfig;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class StatusManager {
|
|
||||||
|
|
||||||
private static YamlConfig config = ThemeParkPlugin.getInstance().getSettings();
|
|
||||||
private static HashMap<Status, String> names;
|
|
||||||
private static HashMap<Status, Material> materials;
|
|
||||||
private static HashMap<Status, Short> data;
|
|
||||||
private static HashMap<Status, Boolean> teleport;
|
|
||||||
|
|
||||||
public static void load() {
|
|
||||||
names = new HashMap<>();
|
|
||||||
materials = new HashMap<>();
|
|
||||||
data = new HashMap<>();
|
|
||||||
teleport = new HashMap<>();
|
|
||||||
|
|
||||||
for(Status status : Status.values()) {
|
|
||||||
if(config.getConfig().contains(status.toString() + ".name")) {
|
|
||||||
names.put(status, config.getConfig().getString(status.toString() + ".name"));
|
|
||||||
} else {
|
|
||||||
names.put(status, "UNKNOWN");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(config.getConfig().contains(status.toString() + ".material")) {
|
|
||||||
Material material = Material.getMaterial(config.getConfig().getString(status.toString() + ".material"));
|
|
||||||
if(material == null)
|
|
||||||
material = Material.STAINED_CLAY;
|
|
||||||
|
|
||||||
materials.put(status, material);
|
|
||||||
} else {
|
|
||||||
materials.put(status, Material.STAINED_CLAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(config.getConfig().contains(status.toString() + ".data")) {
|
|
||||||
String string = config.getConfig().getString(status.toString() + ".data");
|
|
||||||
if(string.isEmpty()) {
|
|
||||||
data.put(status, (short) 0);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
data.put(status, Short.parseShort(string));
|
|
||||||
} else {
|
|
||||||
data.put(status, (short) 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(config.getConfig().contains(status.toString() + ".teleport")) {
|
|
||||||
teleport.put(status, config.getConfig().getBoolean(status.toString() + ".teleport"));
|
|
||||||
} else {
|
|
||||||
teleport.put(status, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getName(Status status) {
|
|
||||||
return names.get(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Material getMaterial(Status status) {
|
|
||||||
return materials.get(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static short getData(Status status) {
|
|
||||||
return data.get(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean canTeleport(Status status) {
|
|
||||||
return teleport.get(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,352 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.command;
|
|
||||||
|
|
||||||
import me.paradoxpixel.themepark.ThemeParkPlugin;
|
|
||||||
import me.paradoxpixel.themepark.api.API;
|
|
||||||
import me.paradoxpixel.themepark.api.LocationUtils;
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.Attraction;
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.Region;
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.component.Status;
|
|
||||||
import me.paradoxpixel.themepark.attraction.AttractionMenu;
|
|
||||||
import me.paradoxpixel.themepark.attraction.MapMarker;
|
|
||||||
import me.paradoxpixel.themepark.attraction.status.StatusManager;
|
|
||||||
import me.paradoxpixel.themepark.config.YamlConfig;
|
|
||||||
import me.paradoxpixel.themepark.utils.ItemBuilder;
|
|
||||||
import me.paradoxpixel.themepark.utils.Message;
|
|
||||||
import me.paradoxpixel.themepark.utils.Utils;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.command.defaults.BukkitCommand;
|
|
||||||
import org.bukkit.entity.Minecart;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class ThemeParkCommand extends BukkitCommand {
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
private YamlConfig config = ThemeParkPlugin.getInstance().getAttraction();
|
|
||||||
|
|
||||||
public ThemeParkCommand(String name) {
|
|
||||||
super(name);
|
|
||||||
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean execute(CommandSender sender,String label, String[] args) {
|
|
||||||
if (args.length == 0 || args[0].equalsIgnoreCase("help")) {
|
|
||||||
sender.sendMessage(Utils.color("&f>==== &6ThemePark &f ====<"));
|
|
||||||
sender.sendMessage(Utils.color("&f/" + name + " help"));
|
|
||||||
sender.sendMessage(Utils.color("&f/" + name + " list"));
|
|
||||||
sender.sendMessage(Utils.color("&f/" + name + " warp [id]"));
|
|
||||||
if(sender.hasPermission("themepark.admin") || sender.hasPermission("themepark.item")) {
|
|
||||||
sender.sendMessage(Utils.color("&f/" + name + " toggleitem"));
|
|
||||||
sender.sendMessage(Utils.color("&f/" + name + " getitem"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(sender.hasPermission("themepark.admin")) {
|
|
||||||
sender.sendMessage(Utils.color("&f/" + name + " reload"));
|
|
||||||
sender.sendMessage(Utils.color("&f/" + name + " regionname [id] [name]"));
|
|
||||||
sender.sendMessage(Utils.color("&f/" + name + " regionlore [id] [index] [lore]"));
|
|
||||||
sender.sendMessage(Utils.color("&f/" + name + " setlocation [id]"));
|
|
||||||
sender.sendMessage(Utils.color("&f/" + name + " attraction [id] [status]"));
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("list")) {
|
|
||||||
sender.sendMessage(Utils.color("&f>==== &6ThemePark &f ====<"));
|
|
||||||
if (API.getAttractions().size() == 0) {
|
|
||||||
sender.sendMessage(Utils.color(Message.getMessage("attraction.notfound")));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Attraction attraction : API.getAttractions().values()) {
|
|
||||||
String message = Message.getMessage("attraction.list");
|
|
||||||
message = message.replace("{id}", attraction.getId());
|
|
||||||
message = message.replace("{name}", attraction.getName());
|
|
||||||
message = message.replace("{region}", API.getRegion(attraction.getRegion_id()).getName());
|
|
||||||
message = message.replace("{type}", attraction.getType().toString());
|
|
||||||
message = message.replace("{status}", StatusManager.getName(attraction.getStatus()));
|
|
||||||
sender.sendMessage(Utils.color(message));
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(args[0].equalsIgnoreCase("warp")) {
|
|
||||||
if(args.length < 2) {
|
|
||||||
sender.sendMessage(Utils.color( "&6Themepark&f: &4/" + name + " warp [id]"));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
String id = args[1];
|
|
||||||
if(!API.isAttraction(id)) {
|
|
||||||
String message = Message.getMessage("attraction.no");
|
|
||||||
message = message.replace("{id}", id);
|
|
||||||
sender.sendMessage(Utils.color(message));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(sender instanceof Player) {
|
|
||||||
Attraction attraction = API.getAttraction(id);
|
|
||||||
Player player = (Player) sender;
|
|
||||||
if(!StatusManager.canTeleport(attraction.getStatus())) {
|
|
||||||
String message = Message.getMessage("attraction.teleport.status");
|
|
||||||
message = message.replace("{name}", attraction.getName());
|
|
||||||
message = message.replace("{status}", StatusManager.getName(attraction.getStatus()));
|
|
||||||
player.sendMessage(Utils.color(message));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
player.teleport(attraction.getLocation());
|
|
||||||
if(player.isInsideVehicle())
|
|
||||||
if(player.getVehicle() instanceof Minecart)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
player.sendMessage(Utils.color(Message.getMessage("attraction.teleport.success").replace("{name}", attraction.getName())));
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(Utils.color(Message.getMessage("onlyplayers")));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!sender.hasPermission("themepark.admin") && !sender.hasPermission("themepark.item")) {
|
|
||||||
sender.sendMessage(Utils.color(Message.getMessage("nopermission")));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(args[0].equalsIgnoreCase("toggleitem")) {
|
|
||||||
if(!(sender instanceof Player)) {
|
|
||||||
sender.sendMessage(Utils.color(Message.getMessage("onlyplayers")));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Player player = (Player) sender;
|
|
||||||
UUID uuid = player.getUniqueId();
|
|
||||||
|
|
||||||
YamlConfig config = ThemeParkPlugin.getInstance().getData();
|
|
||||||
boolean b = config.getConfig().getBoolean(uuid.toString() + ".item");
|
|
||||||
b = !b;
|
|
||||||
|
|
||||||
config.getConfig().set(uuid.toString() + ".item", b);
|
|
||||||
config.save();
|
|
||||||
|
|
||||||
String message = Message.getMessage("menu.item.toggle");
|
|
||||||
message = message.replace("{status}", b ? Message.getMessage("menu.item.enabled") : Message.getMessage("menu.item.disabled"));
|
|
||||||
sender.sendMessage(Utils.color(message));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(args[0].equalsIgnoreCase("getitem")) {
|
|
||||||
YamlConfig settings = ThemeParkPlugin.getInstance().getSettings();
|
|
||||||
Material material = Material.getMaterial(settings.getConfig().getString("item.material"));
|
|
||||||
String name = Utils.color(settings.getConfig().getString("item.display-name"));
|
|
||||||
if(material == null || name.isEmpty())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
Player player;
|
|
||||||
if(args.length >= 2) {
|
|
||||||
String string = args[1];
|
|
||||||
if(Bukkit.getPlayerExact(string) == null) {
|
|
||||||
String message = Message.getMessage("noplayer");
|
|
||||||
message = message.replace("{name}", string);
|
|
||||||
sender.sendMessage(Utils.color(message));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
player = Bukkit.getPlayerExact(string);
|
|
||||||
} else {
|
|
||||||
if(!(sender instanceof Player)) {
|
|
||||||
sender.sendMessage(Utils.color(Message.getMessage("onlyplayers")));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
player = (Player) sender;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ItemBuilder builder = new ItemBuilder(material);
|
|
||||||
builder.setName(name);
|
|
||||||
player.getInventory().addItem(builder.getItem());
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!sender.hasPermission("themepark.admin")) {
|
|
||||||
sender.sendMessage(Utils.color(Message.getMessage("nopermission")));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(args[0].equalsIgnoreCase("reload")) {
|
|
||||||
ThemeParkPlugin.getInstance().getData().reload();
|
|
||||||
ThemeParkPlugin.getInstance().getAttraction().reload();
|
|
||||||
ThemeParkPlugin.getInstance().getSigns().reload();
|
|
||||||
ThemeParkPlugin.getInstance().getSettings().reload();
|
|
||||||
ThemeParkPlugin.getInstance().getMessage().reload();
|
|
||||||
|
|
||||||
StatusManager.load();
|
|
||||||
AttractionMenu.load();
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(),() -> {
|
|
||||||
ThemeParkPlugin.getInstance().getDatabaseHandler().load();
|
|
||||||
});
|
|
||||||
sender.sendMessage(Utils.color(Message.getMessage("reloaded")));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("regionname")) {
|
|
||||||
if (args.length < 3) {
|
|
||||||
sender.sendMessage(Utils.color("&6Themepark&f: &4/" + name + " regionname [id] [name]"));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
String id = args[1];
|
|
||||||
if(!API.isRegion(id)) {
|
|
||||||
String message = Message.getMessage("region.not");
|
|
||||||
message = message.replace("{id}", id);
|
|
||||||
sender.sendMessage(Utils.color(message));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
String name = args[2];
|
|
||||||
name = name.replaceAll("_", " ");
|
|
||||||
|
|
||||||
Region region = API.getRegion(id);
|
|
||||||
if(!region.getName().equals(name))
|
|
||||||
region.setName(name);
|
|
||||||
|
|
||||||
config.getConfig().set("region." + id + ".name", name);
|
|
||||||
config.save();
|
|
||||||
|
|
||||||
String message = Message.getMessage("region.changed.name");
|
|
||||||
message = message.replace("{id}", id);
|
|
||||||
message = message.replace("{name}", name);
|
|
||||||
sender.sendMessage(Utils.color(message));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("regionlore")) {
|
|
||||||
if (args.length < 4) {
|
|
||||||
sender.sendMessage(Utils.color("&6Themepark&f: &4/" + name + " regionlore[id] [index] [lore]"));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
String id = args[1];
|
|
||||||
if (!API.isRegion(id)) {
|
|
||||||
String message = Message.getMessage("region.not");
|
|
||||||
message = message.replace("{id}", id);
|
|
||||||
sender.sendMessage(Utils.color(message));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
String string = args[2];
|
|
||||||
if(!isInteger(string)) {
|
|
||||||
sender.sendMessage(Utils.color(Message.getMessage("nonumber").replace("{number}", string)));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int i = Integer.parseInt(string);
|
|
||||||
|
|
||||||
String lore = args[3];
|
|
||||||
lore = lore.replaceAll("_", " ");
|
|
||||||
|
|
||||||
Region region = API.getRegion(id);
|
|
||||||
if(region.getLore().size() > i && region.getLore().get(i).equals(lore))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
region.setLore(i, lore);
|
|
||||||
config.getConfig().set("region." + id + ".lore", region.getLore());
|
|
||||||
config.save();
|
|
||||||
|
|
||||||
String message = Message.getMessage("region.changed.lore");
|
|
||||||
message = message.replace("{id}", id);
|
|
||||||
message = message.replace("{index}", "" + i);
|
|
||||||
message = message.replace("{lore}", lore);
|
|
||||||
sender.sendMessage(Utils.color(message));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("setlocation")) {
|
|
||||||
if (args.length < 2 ) {
|
|
||||||
sender.sendMessage(Utils.color("&6Themepark&f: &4/" + name + " setlocation [id]"));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
String id = args[1];
|
|
||||||
if(!API.isAttraction(id)) {
|
|
||||||
String message = Message.getMessage("attraction.not");
|
|
||||||
message = message.replace("{id}", id);
|
|
||||||
sender.sendMessage(Utils.color(message));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!(sender instanceof Player)) {
|
|
||||||
sender.sendMessage(Utils.color(Message.getMessage("onlyplayers")));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Location location = ((Player) sender).getLocation();
|
|
||||||
config.getConfig().set("attraction." + id + ".location", LocationUtils.toString(location));
|
|
||||||
config.save();
|
|
||||||
|
|
||||||
Attraction attraction = API.getAttraction(id);
|
|
||||||
attraction.setLocation(location.clone());
|
|
||||||
MapMarker.getMarker().setAttractionMarker(attraction);
|
|
||||||
sender.sendMessage(Utils.color(Message.getMessage("attraction.location").replace("{name}", attraction.getName())));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("attraction")) {
|
|
||||||
if (args.length < 3 ) {
|
|
||||||
sender.sendMessage(Utils.color("&6Themepark&f: &4/" + name + " attraction [id] [status]"));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
String id = args[1];
|
|
||||||
if (!API.isAttraction(id)) {
|
|
||||||
String message = Message.getMessage("attraction.not");
|
|
||||||
message = message.replace("{id}", id);
|
|
||||||
sender.sendMessage(Utils.color(message));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Status status = Status.getStatus(args[2]);
|
|
||||||
if (status == null) {
|
|
||||||
String message = Message.getMessage("status.not");
|
|
||||||
message = message.replace("{status}", args[2]);
|
|
||||||
sender.sendMessage(Utils.color(message));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Attraction attraction = API.getAttraction(id);
|
|
||||||
if(!attraction.getType().containsStatus(status)) {
|
|
||||||
String message = Message.getMessage("attraction.nostatus");
|
|
||||||
message = message.replace("{name}", attraction.getName());
|
|
||||||
message = message.replace("{status}", status.toString());
|
|
||||||
sender.sendMessage(Utils.color(message));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(attraction.getStatus() == status)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
Player player = (sender instanceof Player) ? (Player) sender : null;
|
|
||||||
|
|
||||||
attraction.setStatus(status, player);
|
|
||||||
config.getConfig().set("attraction." + id + ".status", status.toString());
|
|
||||||
config.save();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isInteger(String s) {
|
|
||||||
int radix = 10;
|
|
||||||
Scanner sc = new Scanner(s.trim());
|
|
||||||
if(!sc.hasNextInt(radix)) return false;
|
|
||||||
sc.nextInt(radix);
|
|
||||||
return !sc.hasNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,132 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.database;
|
|
||||||
|
|
||||||
import me.paradoxpixel.themepark.ThemeParkPlugin;
|
|
||||||
import me.paradoxpixel.themepark.config.YamlConfig;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class Database {
|
|
||||||
|
|
||||||
public Database(YamlConfig config) {
|
|
||||||
if(config == null) {
|
|
||||||
enabled = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
enabled = config.getConfig().getBoolean("mysql.enabled");
|
|
||||||
String host = config.getConfig().getString("mysql.host");
|
|
||||||
int port = config.getConfig().getInt("mysql.port");
|
|
||||||
String database = config.getConfig().getString("mysql.database");
|
|
||||||
user = config.getConfig().getString("mysql.user");
|
|
||||||
password = config.getConfig().getString("mysql.password");
|
|
||||||
url = config.getConfig().getString("mysql.url");
|
|
||||||
|
|
||||||
url = url.replace("%host%", host);
|
|
||||||
url = url.replace("%port%", Integer.toString(port));
|
|
||||||
url = url.replace("%database%", database);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean enabled;
|
|
||||||
private String user, password, url;
|
|
||||||
|
|
||||||
private Connection connection;
|
|
||||||
private int TaskID;
|
|
||||||
|
|
||||||
public boolean isEnabled() {
|
|
||||||
return enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void connect() {
|
|
||||||
try {
|
|
||||||
Class.forName("com.mysql.jdbc.Driver").newInstance();
|
|
||||||
connection = DriverManager.getConnection(url, user, password);
|
|
||||||
|
|
||||||
startPool();
|
|
||||||
} catch(Exception e) {
|
|
||||||
enabled = false;
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void disconnect() {
|
|
||||||
if(connection == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
connection.close();
|
|
||||||
connection = null;
|
|
||||||
} catch(Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean connected() {
|
|
||||||
if(connection == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
try {
|
|
||||||
return !connection.isClosed();
|
|
||||||
} catch(Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startPool() {
|
|
||||||
TaskID = Bukkit.getScheduler().runTaskLater(ThemeParkPlugin.getInstance(), new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
disconnect();
|
|
||||||
TaskID = 0;
|
|
||||||
}
|
|
||||||
}, 1200L).getTaskId();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void stopPool() {
|
|
||||||
if(TaskID == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Bukkit.getScheduler().cancelTask(TaskID);
|
|
||||||
TaskID = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean execute(String query, HashMap<Integer, Object> objects) {
|
|
||||||
if(query == null || query.isEmpty())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if(!enabled)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if(!connected())
|
|
||||||
connect();
|
|
||||||
|
|
||||||
if(!connected())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
stopPool();
|
|
||||||
try {
|
|
||||||
PreparedStatement statement = connection.prepareStatement(query);
|
|
||||||
if(objects != null)
|
|
||||||
for(Map.Entry<Integer, Object> entry : objects.entrySet())
|
|
||||||
statement.setObject(entry.getKey(), entry.getValue());
|
|
||||||
|
|
||||||
boolean b = statement.execute();
|
|
||||||
statement.close();
|
|
||||||
startPool();
|
|
||||||
|
|
||||||
return b;
|
|
||||||
} catch(Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
startPool();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,101 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.database;
|
|
||||||
|
|
||||||
import me.paradoxpixel.themepark.api.API;
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.Attraction;
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.Region;
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.component.Status;
|
|
||||||
import me.paradoxpixel.themepark.attraction.status.StatusManager;
|
|
||||||
import me.paradoxpixel.themepark.config.YamlConfig;
|
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class DatabaseHandler {
|
|
||||||
|
|
||||||
private Database database;
|
|
||||||
|
|
||||||
public DatabaseHandler(YamlConfig config) {
|
|
||||||
database = new Database(config);
|
|
||||||
load();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void load() {
|
|
||||||
database.execute("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))", null);
|
|
||||||
database.execute("CREATE TABLE IF NOT EXISTS region (id VARCHAR(256) NOT NULL, name VARCHAR(256) NOT NULL, PRIMARY KEY(id))", null);
|
|
||||||
database.execute("CREATE TABLE IF NOT EXISTS status (statusId VARCHAR(256) NOT NULL, statusName VARCHAR(256) NOT NULL)", null);
|
|
||||||
|
|
||||||
database.execute("TRUNCATE TABLE attraction", null);
|
|
||||||
database.execute("TRUNCATE TABLE region", null);
|
|
||||||
database.execute("TRUNCATE TABLE status", null);
|
|
||||||
|
|
||||||
for(Attraction attraction : API.getAttractions().values())
|
|
||||||
addAttraction(attraction);
|
|
||||||
|
|
||||||
for(Region region : API.getRegions().values())
|
|
||||||
addRegion(region);
|
|
||||||
|
|
||||||
for(Status status : Status.values()) {
|
|
||||||
HashMap<Integer, Object> objects = new HashMap<>();
|
|
||||||
objects.put(1, status.toString());
|
|
||||||
objects.put(2, StatusManager.getName(status));
|
|
||||||
database.execute("INSERT INTO status (statusId,statusName) VALUES(?,?)", objects);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addAttraction(Attraction attraction) {
|
|
||||||
HashMap<Integer, Object> objects = new HashMap<>();
|
|
||||||
objects.put(1, attraction.getId());
|
|
||||||
objects.put(2, attraction.getName());
|
|
||||||
objects.put(3, attraction.getRegion_id());
|
|
||||||
objects.put(4, attraction.getType().toString());
|
|
||||||
objects.put(5, attraction.getStatus().toString());
|
|
||||||
|
|
||||||
database.execute("INSERT IGNORE INTO attraction(id, name, region_id, type, status) VALUES (?,?,?,?,?)", objects);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateAttraction(Attraction attraction) {
|
|
||||||
HashMap<Integer, Object> objects = new HashMap<>();
|
|
||||||
objects.put(1, attraction.getStatus().toString());
|
|
||||||
objects.put(2, attraction.getId());
|
|
||||||
|
|
||||||
database.execute("UPDATE attraction SET status=? WHERE id=?", objects);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeAttraction(Attraction attraction) {
|
|
||||||
HashMap<Integer, Object> objects = new HashMap<>();
|
|
||||||
objects.put(1, attraction.getId());
|
|
||||||
|
|
||||||
database.execute("DELETE FROM attraction WHERE id=?", objects);
|
|
||||||
database.execute("DELETE FROM ridecount WHERE attractionId=?", objects);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addRegion(Region region) {
|
|
||||||
HashMap<Integer, Object> objects = new HashMap<>();
|
|
||||||
objects.put(1, region.getId());
|
|
||||||
objects.put(2, region.getName());
|
|
||||||
|
|
||||||
database.execute("INSERT IGNORE INTO region(id, name) VALUES (?,?)", objects);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateRegion(Region region) {
|
|
||||||
HashMap<Integer, Object> objects = new HashMap<>();
|
|
||||||
objects.put(1, region.getName());
|
|
||||||
objects.put(2, region.getId());
|
|
||||||
|
|
||||||
database.execute("UPDATE region SET name=? WHERE id=?", objects);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeRegion(Region region) {
|
|
||||||
HashMap<Integer, Object> objects = new HashMap<>();
|
|
||||||
objects.put(1, region.getId());
|
|
||||||
|
|
||||||
database.execute("DELETE FROM region WHERE id=?", objects);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void disconnect() {
|
|
||||||
database.disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,120 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.gui;
|
|
||||||
|
|
||||||
import me.paradoxpixel.themepark.utils.Utils;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.inventory.ClickType;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class GUI extends GUIHolder {
|
|
||||||
|
|
||||||
private String title;
|
|
||||||
private int size;
|
|
||||||
private Inventory inventory;
|
|
||||||
private HashMap<Integer, GUIItem> items = new HashMap<>();
|
|
||||||
|
|
||||||
public GUI(String title, int size) {
|
|
||||||
if(size > 54)
|
|
||||||
size = 54;
|
|
||||||
|
|
||||||
this.title = title;
|
|
||||||
this.size = Utils.toSize(size, 9);
|
|
||||||
inventory = Bukkit.createInventory(this, this.size, Utils.color(title));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void update() {
|
|
||||||
ArrayList<Integer> toRemove = new ArrayList<>();
|
|
||||||
for(Map.Entry<Integer, GUIItem> entry : items.entrySet()) {
|
|
||||||
if(entry.getKey() >= getSize()) {
|
|
||||||
toRemove.add(entry.getKey());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
inventory.setItem(entry.getKey(), entry.getValue().getItem());
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i : toRemove)
|
|
||||||
items.remove(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSize(int size) {
|
|
||||||
if(size > 54)
|
|
||||||
size = 54;
|
|
||||||
|
|
||||||
this.size = Utils.toSize(size, 9);
|
|
||||||
inventory = Bukkit.createInventory(this, this.size, Utils.color(title));
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSize() {
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clear() {
|
|
||||||
inventory = Bukkit.createInventory(this, Utils.toSize(size, 9), Utils.color(title));
|
|
||||||
items.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addItems(HashMap<Integer, GUIItem> items) {
|
|
||||||
for(Map.Entry<Integer, GUIItem> entry : items.entrySet())
|
|
||||||
addItem(entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addItem(int slot, GUIItem item) {
|
|
||||||
if(slot >= getSize() || slot < 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
items.put(slot, item);
|
|
||||||
inventory.setItem(slot, item.getItem());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeItem(int slot) {
|
|
||||||
items.remove(slot);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void switchSlot(int from, int to) {
|
|
||||||
if(!items.containsKey(from))
|
|
||||||
return;
|
|
||||||
|
|
||||||
GUIItem item = items.get(from);
|
|
||||||
items.put(to, item);
|
|
||||||
items.remove(from);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasItem(int slot) {
|
|
||||||
return items.containsKey(slot);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean execute(Player player, int slot, ClickType type) {
|
|
||||||
if(player == null || slot >= getSize() || slot < 0 || type == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if(!items.containsKey(slot))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
GUIItem item = items.get(slot);
|
|
||||||
if(type == ClickType.RIGHT) {
|
|
||||||
if(item.getActionRight() != null)
|
|
||||||
item.getActionRight().click(player);
|
|
||||||
|
|
||||||
return item.hasCancelRight();
|
|
||||||
} else {
|
|
||||||
if(item.getActionLeft() != null)
|
|
||||||
item.getActionLeft().click(player);
|
|
||||||
|
|
||||||
return item.hasCancelLeft();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Inventory getInventory() {
|
|
||||||
return inventory;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.gui;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public abstract class GUIAction {
|
|
||||||
|
|
||||||
public abstract void click(Player player);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.gui;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.inventory.ClickType;
|
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
|
||||||
|
|
||||||
public abstract class GUIHolder implements InventoryHolder {
|
|
||||||
|
|
||||||
public abstract boolean execute(Player player, int slot, ClickType type);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,45 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.gui;
|
|
||||||
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
public class GUIItem {
|
|
||||||
|
|
||||||
private ItemStack item;
|
|
||||||
private GUIAction aleft, aright;
|
|
||||||
private boolean cleft, cright;
|
|
||||||
|
|
||||||
public GUIItem(ItemStack item, GUIAction action, boolean cancel) {
|
|
||||||
this.item = item;
|
|
||||||
aleft = aright = action;
|
|
||||||
cleft = cright = cancel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GUIItem(ItemStack item, GUIAction aleft, GUIAction aright, boolean cleft, boolean cright) {
|
|
||||||
this.item = item;
|
|
||||||
this.aleft = aleft;
|
|
||||||
this.aright = aright;
|
|
||||||
this.cleft = cleft;
|
|
||||||
this.cright = cright;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack getItem() {
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasCancelLeft() {
|
|
||||||
return cleft;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasCancelRight() {
|
|
||||||
return cright;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GUIAction getActionLeft() {
|
|
||||||
return aleft;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GUIAction getActionRight() {
|
|
||||||
return aright;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,41 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.gui;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.inventory.*;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
|
|
||||||
public class GUIListener implements Listener {
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
|
||||||
public void onClick(InventoryClickEvent e) {
|
|
||||||
if(e.getClickedInventory() == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Inventory inventory = e.getClickedInventory();
|
|
||||||
if(!(inventory.getHolder() instanceof GUIHolder))
|
|
||||||
return;
|
|
||||||
|
|
||||||
Player player = (Player) e.getWhoClicked();
|
|
||||||
int slot = e.getRawSlot();
|
|
||||||
ClickType type = e.getClick();
|
|
||||||
|
|
||||||
GUI gui = (GUI) inventory.getHolder();
|
|
||||||
gui.execute(player, slot, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
|
||||||
public void onMove(InventoryClickEvent e) {
|
|
||||||
if(e.getInventory() == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Inventory inventory = e.getInventory();
|
|
||||||
if(!(inventory.getHolder() instanceof GUIHolder))
|
|
||||||
return;
|
|
||||||
|
|
||||||
e.setCancelled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,101 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.listener;
|
|
||||||
|
|
||||||
import me.paradoxpixel.themepark.ThemeParkPlugin;
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.Attraction;
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.component.Status;
|
|
||||||
import me.paradoxpixel.themepark.api.event.attraction.AddAttractionEvent;
|
|
||||||
import me.paradoxpixel.themepark.api.event.attraction.RemoveAttractionEvent;
|
|
||||||
import me.paradoxpixel.themepark.api.event.attraction.StatusChangeEvent;
|
|
||||||
import me.paradoxpixel.themepark.api.event.region.AddRegionEvent;
|
|
||||||
import me.paradoxpixel.themepark.api.event.region.ChangeRegionEvent;
|
|
||||||
import me.paradoxpixel.themepark.api.event.region.RemoveRegionEvent;
|
|
||||||
import me.paradoxpixel.themepark.attraction.AttractionMenu;
|
|
||||||
import me.paradoxpixel.themepark.attraction.MapMarker;
|
|
||||||
import me.paradoxpixel.themepark.attraction.sign.SignManager;
|
|
||||||
import me.paradoxpixel.themepark.attraction.status.StatusManager;
|
|
||||||
import me.paradoxpixel.themepark.config.YamlConfig;
|
|
||||||
import me.paradoxpixel.themepark.utils.Message;
|
|
||||||
import me.paradoxpixel.themepark.utils.Utils;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
|
|
||||||
public class ChangeListener implements Listener {
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onChange(StatusChangeEvent e) {
|
|
||||||
if(e.getAttraction() == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
SignManager.update(e.getAttraction());
|
|
||||||
|
|
||||||
Attraction attraction = e.getAttraction();
|
|
||||||
AttractionMenu.update(attraction);
|
|
||||||
|
|
||||||
Status status = e.getStatusAfter();
|
|
||||||
String message = Message.getMessage("attraction.changed.status." + status.toString());
|
|
||||||
message = message.replace("{name}", attraction.getName());
|
|
||||||
message = message.replace("{status}", StatusManager.getName(status));
|
|
||||||
Bukkit.broadcastMessage(Utils.color(message));
|
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), () -> ThemeParkPlugin.getInstance().getDatabaseHandler().updateAttraction(e.getAttraction()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onChange(AddAttractionEvent e) {
|
|
||||||
if(e.getAttraction() == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
AttractionMenu.reload();
|
|
||||||
SignManager.loadSigns(e.getAttraction());
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), () -> ThemeParkPlugin.getInstance().getDatabaseHandler().addAttraction(e.getAttraction()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onChange(RemoveAttractionEvent e) {
|
|
||||||
if(e.getAttraction() == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
AttractionMenu.reload();
|
|
||||||
SignManager.remove(e.getAttraction());
|
|
||||||
MapMarker.getMarker().removeAttractionMarker(e.getAttraction());
|
|
||||||
YamlConfig config = ThemeParkPlugin.getInstance().getAttraction();
|
|
||||||
config.getConfig().set("attraction." + e.getAttraction().getId(), null);
|
|
||||||
config.save();
|
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), () -> ThemeParkPlugin.getInstance().getDatabaseHandler().removeAttraction(e.getAttraction()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onChange(AddRegionEvent e) {
|
|
||||||
if(e.getRegion() == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
AttractionMenu.reload();
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), () -> ThemeParkPlugin.getInstance().getDatabaseHandler().addRegion(e.getRegion()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onChange(ChangeRegionEvent e) {
|
|
||||||
if(e.getRegion() == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
AttractionMenu.reload();
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), () -> ThemeParkPlugin.getInstance().getDatabaseHandler().updateRegion(e.getRegion()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onChange(RemoveRegionEvent e) {
|
|
||||||
if(e.getRegion() == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
AttractionMenu.reload();
|
|
||||||
YamlConfig config = ThemeParkPlugin.getInstance().getAttraction();
|
|
||||||
config.getConfig().set("region." + e.getRegion().getId(), null);
|
|
||||||
config.save();
|
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), () -> ThemeParkPlugin.getInstance().getDatabaseHandler().removeRegion(e.getRegion()));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,45 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.listener;
|
|
||||||
|
|
||||||
import me.paradoxpixel.themepark.ThemeParkPlugin;
|
|
||||||
import me.paradoxpixel.themepark.attraction.AttractionMenu;
|
|
||||||
import me.paradoxpixel.themepark.config.YamlConfig;
|
|
||||||
import me.paradoxpixel.themepark.utils.Utils;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
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.player.PlayerInteractEvent;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
public class ClickListener implements Listener {
|
|
||||||
|
|
||||||
private YamlConfig config = ThemeParkPlugin.getInstance().getSettings();
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onInteract(PlayerInteractEvent e) {
|
|
||||||
Material material = Material.getMaterial(config.getConfig().getString("item.material"));
|
|
||||||
String name = Utils.color(config.getConfig().getString("item.display-name"));
|
|
||||||
if(e.getItem() == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ItemStack item = e.getItem();
|
|
||||||
if(item.getType() != material)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(!item.hasItemMeta())
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(!item.getItemMeta().getDisplayName().equals(name))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(e.getAction() == Action.LEFT_CLICK_AIR ||
|
|
||||||
e.getAction() == Action.LEFT_CLICK_BLOCK)
|
|
||||||
return;
|
|
||||||
|
|
||||||
e.setCancelled(true);
|
|
||||||
Player player = e.getPlayer();
|
|
||||||
AttractionMenu.openMenu(player, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,90 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.listener;
|
|
||||||
|
|
||||||
import me.paradoxpixel.themepark.ThemeParkPlugin;
|
|
||||||
import me.paradoxpixel.themepark.config.YamlConfig;
|
|
||||||
import me.paradoxpixel.themepark.database.DatabaseHandler;
|
|
||||||
import me.paradoxpixel.themepark.utils.ItemBuilder;
|
|
||||||
import me.paradoxpixel.themepark.utils.Utils;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Minecart;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener {
|
|
||||||
|
|
||||||
private YamlConfig config = ThemeParkPlugin.getInstance().getData();
|
|
||||||
private YamlConfig settings = ThemeParkPlugin.getInstance().getSettings();
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onJoin(PlayerJoinEvent e) {
|
|
||||||
doItem(e.getPlayer());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onSwitch(PlayerChangedWorldEvent e) {
|
|
||||||
doItem(e.getPlayer());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onTeleport(PlayerTeleportEvent e) {
|
|
||||||
Player player = e.getPlayer();
|
|
||||||
if(e.getCause() != PlayerTeleportEvent.TeleportCause.PLUGIN)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(!player.isInsideVehicle())
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(player.getVehicle() == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(!(player.getVehicle() instanceof Minecart))
|
|
||||||
return;
|
|
||||||
|
|
||||||
e.setCancelled(true);
|
|
||||||
player.sendMessage(Utils.color("&6ThemePark&f: &4You can't teleport while in a minecart"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void doItem(Player player) {
|
|
||||||
if(!settings.getConfig().getBoolean("item.enabled"))
|
|
||||||
return;
|
|
||||||
|
|
||||||
Material material = Material.getMaterial(settings.getConfig().getString("item.material"));
|
|
||||||
String name = Utils.color(settings.getConfig().getString("item.display-name"));
|
|
||||||
int slot = settings.getConfig().getInt("item.slot");
|
|
||||||
if(material == null || name.isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
boolean b = true;
|
|
||||||
if(config.getConfig().contains(player.getUniqueId().toString() + ".item")) {
|
|
||||||
b = config.getConfig().getBoolean(player.getUniqueId().toString() + ".item");
|
|
||||||
} else {
|
|
||||||
config.getConfig().set(player.getUniqueId().toString() + ".item", true);
|
|
||||||
config.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(b) {
|
|
||||||
if(settings.getConfig().getBoolean("inventory.clear"))
|
|
||||||
player.getInventory().clear();
|
|
||||||
|
|
||||||
List<String> worlds = settings.getConfig().getStringList("item.worlds");
|
|
||||||
if(worlds != null && !worlds.isEmpty()) {
|
|
||||||
if (worlds.contains(player.getLocation().getWorld().getName())) {
|
|
||||||
player.getInventory().setItem(slot, new ItemStack(Material.AIR));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemBuilder builder = new ItemBuilder(material);
|
|
||||||
builder.setName(name);
|
|
||||||
player.getInventory().setItem(slot, builder.getItem());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,64 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.listener;
|
|
||||||
|
|
||||||
import me.paradoxpixel.themepark.ThemeParkPlugin;
|
|
||||||
import me.paradoxpixel.themepark.api.API;
|
|
||||||
import me.paradoxpixel.themepark.api.attraction.Attraction;
|
|
||||||
import me.paradoxpixel.themepark.attraction.sign.SignManager;
|
|
||||||
import me.paradoxpixel.themepark.attraction.sign.StatusSign;
|
|
||||||
import me.paradoxpixel.themepark.attraction.status.StatusManager;
|
|
||||||
import me.paradoxpixel.themepark.config.YamlConfig;
|
|
||||||
import me.paradoxpixel.themepark.utils.Utils;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.block.Sign;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
|
||||||
import org.bukkit.event.block.SignChangeEvent;
|
|
||||||
|
|
||||||
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, Utils.color(title));
|
|
||||||
e.setLine(1, Utils.color(attraction.getName()));
|
|
||||||
e.setLine(2, Utils.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(Utils.color(title)))
|
|
||||||
return;
|
|
||||||
|
|
||||||
Attraction attraction = API.getAttractionFromName(sign.getLine(1));
|
|
||||||
Location location = e.getBlock().getLocation();
|
|
||||||
|
|
||||||
StatusSign s = new StatusSign(attraction, location);
|
|
||||||
SignManager.removeSign(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.utils;
|
|
||||||
|
|
||||||
import me.paradoxpixel.themepark.ThemeParkPlugin;
|
|
||||||
import me.paradoxpixel.themepark.config.YamlConfig;
|
|
||||||
|
|
||||||
public class Message {
|
|
||||||
|
|
||||||
private static YamlConfig config = ThemeParkPlugin.getInstance().getMessage();
|
|
||||||
|
|
||||||
public static boolean isMessage(String string) {
|
|
||||||
return config.getConfig().contains(string);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getMessage(String string) {
|
|
||||||
if(!isMessage(string))
|
|
||||||
return "";
|
|
||||||
|
|
||||||
String message = config.getConfig().getString(string);
|
|
||||||
if(isMessage("prefix"))
|
|
||||||
message = message.replace("{prefix}", config.getConfig().getString("prefix"));
|
|
||||||
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
package me.paradoxpixel.themepark.utils;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
|
|
||||||
public class Utils {
|
|
||||||
|
|
||||||
public static String color(String string) {
|
|
||||||
return ChatColor.translateAlternateColorCodes('&', string);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int toSize(int i, int size) {
|
|
||||||
return i % size == 0 ? i : i + (size - (i % size));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
139
src/main/java/nl/iobyte/themepark/ThemeParkPlugin.java
Normal file
139
src/main/java/nl/iobyte/themepark/ThemeParkPlugin.java
Normal file
|
@ -0,0 +1,139 @@
|
||||||
|
package nl.iobyte.themepark;
|
||||||
|
|
||||||
|
import nl.iobyte.menuapi.MenuAPI;
|
||||||
|
import nl.iobyte.themepark.command.MainCommand;
|
||||||
|
import nl.iobyte.themepark.command.MenuCommand;
|
||||||
|
import nl.iobyte.themepark.command.RidecountCommand;
|
||||||
|
import nl.iobyte.themepark.config.YamlConfig;
|
||||||
|
import nl.iobyte.themepark.database.DB;
|
||||||
|
import nl.iobyte.themepark.database.DBManager;
|
||||||
|
import nl.iobyte.themepark.database.MySQL;
|
||||||
|
import nl.iobyte.themepark.database.SQLite;
|
||||||
|
import nl.iobyte.themepark.listener.AttractionListener;
|
||||||
|
import nl.iobyte.themepark.listener.PlayerListener;
|
||||||
|
import nl.iobyte.themepark.listener.RegionListener;
|
||||||
|
import nl.iobyte.themepark.menu.AttractionLoader;
|
||||||
|
import nl.iobyte.workchain.thread.WorkThreader;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandMap;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
public class ThemeParkPlugin extends JavaPlugin {
|
||||||
|
|
||||||
|
private static ThemeParkPlugin instance;
|
||||||
|
private YamlConfig settings, messages, data, regions;
|
||||||
|
private WorkThreader threader;
|
||||||
|
|
||||||
|
public void onEnable() {
|
||||||
|
instance = this;
|
||||||
|
loadConfigs();
|
||||||
|
loadDatabases();
|
||||||
|
loadWorkers();
|
||||||
|
loadListeners();
|
||||||
|
loadCommands();
|
||||||
|
AttractionLoader.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadConfigs() {
|
||||||
|
settings = new YamlConfig("settings", this);
|
||||||
|
messages = new YamlConfig("messages", this);
|
||||||
|
data = new YamlConfig("data", this);
|
||||||
|
regions = new YamlConfig("regions", this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadDatabases() {
|
||||||
|
DBManager.addDatabase("data", new SQLite("data"));
|
||||||
|
|
||||||
|
FileConfiguration fc = settings.getConfig();
|
||||||
|
if(fc.getBoolean("mysql.enabled")) {
|
||||||
|
String host = fc.getString("mysql.host");
|
||||||
|
int port = fc.getInt("mysql.port");
|
||||||
|
String database = fc.getString("mysql.database");
|
||||||
|
String username = fc.getString("mysql.user");
|
||||||
|
String password = fc.getString("mysql.pass");
|
||||||
|
DBManager.addDatabase("public", new MySQL(host, port, database, username, password));
|
||||||
|
}
|
||||||
|
|
||||||
|
loadTables();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadTables() {
|
||||||
|
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))");
|
||||||
|
|
||||||
|
db = DBManager.getDatabase("public");
|
||||||
|
if(db == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
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 status (statusId VARCHAR(256) NOT NULL, statusName VARCHAR(256) NOT NULL)");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadWorkers() {
|
||||||
|
int workers = settings.getConfig().getInt("workers");
|
||||||
|
if(workers < 1)
|
||||||
|
workers = 1;
|
||||||
|
|
||||||
|
threader = new WorkThreader(workers);
|
||||||
|
threader.createWorkers();
|
||||||
|
threader.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadListeners() {
|
||||||
|
PluginManager pm = Bukkit.getPluginManager();
|
||||||
|
pm.registerEvents(new PlayerListener(), this);
|
||||||
|
pm.registerEvents(new AttractionListener(), this);
|
||||||
|
pm.registerEvents(new RegionListener(), this);
|
||||||
|
MenuAPI.register(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadCommands() {
|
||||||
|
getCommand("status").setExecutor(new MenuCommand());
|
||||||
|
getCommand("ridecount").setExecutor(new RidecountCommand());
|
||||||
|
String command = settings.getConfig().getString("command");
|
||||||
|
if(command == null || command.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
final Field bukkitCommandMap = Bukkit.getServer().getClass().getDeclaredField("commandMap");
|
||||||
|
|
||||||
|
bukkitCommandMap.setAccessible(true);
|
||||||
|
CommandMap commandMap = (CommandMap) bukkitCommandMap.get(Bukkit.getServer());
|
||||||
|
|
||||||
|
commandMap.register(command, new MainCommand(command));
|
||||||
|
} catch(ReflectiveOperationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onDisable() {
|
||||||
|
threader.stop();
|
||||||
|
DBManager.shutdown();
|
||||||
|
instance = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ThemeParkPlugin getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public YamlConfig getSettings() {
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public YamlConfig getMessages() {
|
||||||
|
return messages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public YamlConfig getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public YamlConfig getRegions() {
|
||||||
|
return regions;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
110
src/main/java/nl/iobyte/themepark/api/API.java
Normal file
110
src/main/java/nl/iobyte/themepark/api/API.java
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
package nl.iobyte.themepark.api;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
|
import nl.iobyte.themepark.api.attraction.Region;
|
||||||
|
import nl.iobyte.themepark.api.ridecount.CountManager;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
|
public class API {
|
||||||
|
|
||||||
|
private static LinkedHashMap<String, Region> regions = new LinkedHashMap<>();
|
||||||
|
private static LinkedHashMap<String, Attraction> attractions = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
public static void addRegion(Region region) {
|
||||||
|
if(isRegion(region.getId()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
regions.put(region.getId(), region);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isRegion(String id) {
|
||||||
|
if(id == null || id.isEmpty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return regions.containsKey(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Region getRegion(String id) {
|
||||||
|
if(id == null || id.isEmpty())
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return regions.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LinkedHashMap<String, Region> getRegions() {
|
||||||
|
return regions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeRegion(String id) {
|
||||||
|
Region region = getRegion(id);
|
||||||
|
if(region == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for(Attraction attraction : region.getAttractions().values())
|
||||||
|
attractions.remove(attraction.getId());
|
||||||
|
|
||||||
|
regions.remove(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addAttraction(Attraction attraction) {
|
||||||
|
if(!isRegion(attraction.getRegionId()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(isAttraction(attraction.getId()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
getRegion(attraction.getRegionId()).addAttraction(attraction);
|
||||||
|
attractions.put(attraction.getId(), attraction);
|
||||||
|
CountManager.addCounter(attraction);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isAttraction(String id) {
|
||||||
|
if(id == null || id.isEmpty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return attractions.containsKey(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Attraction getAttraction(String id) {
|
||||||
|
if(id == null || id.isEmpty())
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return attractions.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Attraction getAttractionFromName(String name) {
|
||||||
|
if(name == null || name.isEmpty())
|
||||||
|
return null;
|
||||||
|
|
||||||
|
for(Attraction attraction : attractions.values()) {
|
||||||
|
if(!color(attraction.getName()).equals(name))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
return attraction;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LinkedHashMap<String, Attraction> getAttractions() {
|
||||||
|
return attractions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeAttraction(String id) {
|
||||||
|
if(!isAttraction(id))
|
||||||
|
return;
|
||||||
|
|
||||||
|
Attraction attraction = getAttraction(id);
|
||||||
|
if(isRegion(attraction.getRegionId()))
|
||||||
|
getRegion(attraction.getRegionId()).removeAttraction(attraction);
|
||||||
|
|
||||||
|
attractions.remove(id);
|
||||||
|
CountManager.removeCounter(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String color(String string) {
|
||||||
|
return ChatColor.translateAlternateColorCodes('&', string);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
119
src/main/java/nl/iobyte/themepark/api/attraction/Attraction.java
Normal file
119
src/main/java/nl/iobyte/themepark/api/attraction/Attraction.java
Normal file
|
@ -0,0 +1,119 @@
|
||||||
|
package nl.iobyte.themepark.api.attraction;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.api.API;
|
||||||
|
import nl.iobyte.themepark.api.attraction.component.Status;
|
||||||
|
import nl.iobyte.themepark.api.attraction.component.Type;
|
||||||
|
import nl.iobyte.themepark.api.events.attraction.*;
|
||||||
|
import nl.iobyte.themepark.api.utils.LocationSerializer;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Attraction {
|
||||||
|
|
||||||
|
private String id, name, region_id;
|
||||||
|
private Location location;
|
||||||
|
private Type type;
|
||||||
|
private Status status;
|
||||||
|
|
||||||
|
public Attraction(String id, String name, String region_id, Location location, Type type, Status status) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.region_id = region_id;
|
||||||
|
this.location = location;
|
||||||
|
this.type = type;
|
||||||
|
this.status = type.containsStatus(status) ? status : type.getDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
if(this.name.equals(name))
|
||||||
|
return;
|
||||||
|
|
||||||
|
String old = this.name;
|
||||||
|
this.name = name;
|
||||||
|
ChangeNameEvent e = new ChangeNameEvent(this, old, name);
|
||||||
|
Bukkit.getPluginManager().callEvent(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRegionId() {
|
||||||
|
return region_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Region getRegion() {
|
||||||
|
return API.getRegion(region_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocation(Location location) {
|
||||||
|
if(location == this.location)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(location == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
String loc = LocationSerializer.toString(location);
|
||||||
|
if(loc == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(this.location != null)
|
||||||
|
if(loc.equals(LocationSerializer.toString(location)))
|
||||||
|
return;
|
||||||
|
|
||||||
|
Location old = this.location;
|
||||||
|
this.location = location;
|
||||||
|
ChangeLocationEvent e = new ChangeLocationEvent(this, old, location);
|
||||||
|
Bukkit.getPluginManager().callEvent(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Type getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(Type type) {
|
||||||
|
Type old = this.type;
|
||||||
|
this.type = type;
|
||||||
|
if(!type.containsStatus(status))
|
||||||
|
setStatus(type.getDefault(), null);
|
||||||
|
|
||||||
|
ChangeTypeEvent e = new ChangeTypeEvent(this, old, type);
|
||||||
|
Bukkit.getPluginManager().callEvent(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Status getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(Status status, Player player) {
|
||||||
|
if(!type.hasStatus())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(!type.containsStatus(status))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(this.status == status)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Status old = this.status;
|
||||||
|
|
||||||
|
PreChangeStatusEvent e = new PreChangeStatusEvent(this, player, old, status);
|
||||||
|
Bukkit.getPluginManager().callEvent(e);
|
||||||
|
if(e.isCancelled())
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.status = status;
|
||||||
|
ChangeStatusEvent ev = new ChangeStatusEvent(this, player, old, status);
|
||||||
|
Bukkit.getPluginManager().callEvent(ev);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
152
src/main/java/nl/iobyte/themepark/api/attraction/Region.java
Normal file
152
src/main/java/nl/iobyte/themepark/api/attraction/Region.java
Normal file
|
@ -0,0 +1,152 @@
|
||||||
|
package nl.iobyte.themepark.api.attraction;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.api.events.region.ChangeDataEvent;
|
||||||
|
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 org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Region {
|
||||||
|
|
||||||
|
private String id, name;
|
||||||
|
private Material material;
|
||||||
|
private short data;
|
||||||
|
private List<String> lore;
|
||||||
|
private LinkedHashMap<String, Attraction> attractions = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
public Region(String id, String name, List<String> lore) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.material = Material.NAME_TAG;
|
||||||
|
this.data = 0;
|
||||||
|
this.lore = lore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Region(String id, String name, List<String> lore, Material material, short data) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.material = material;
|
||||||
|
this.data = data;
|
||||||
|
this.lore = lore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String string) {
|
||||||
|
if(string == null || string.equals(""))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(string.equals(name))
|
||||||
|
return;
|
||||||
|
|
||||||
|
String old = name;
|
||||||
|
name = string;
|
||||||
|
ChangeNameEvent e = new ChangeNameEvent(this, old, string);
|
||||||
|
Bukkit.getPluginManager().callEvent(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Material getMaterial() {
|
||||||
|
return material;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaterial(Material material) {
|
||||||
|
if(material == null || material == this.material)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Material old = this.material;
|
||||||
|
this.material = material;
|
||||||
|
ChangeMaterialEvent e = new ChangeMaterialEvent(this, old, material);
|
||||||
|
Bukkit.getPluginManager().callEvent(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public short getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData(short data) {
|
||||||
|
if(this.data == data)
|
||||||
|
return;
|
||||||
|
|
||||||
|
short old = this.data;
|
||||||
|
this.data = data;
|
||||||
|
ChangeDataEvent e = new ChangeDataEvent(this, old, data);
|
||||||
|
Bukkit.getPluginManager().callEvent(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getLore() {
|
||||||
|
return lore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLore(List<String> lore) {
|
||||||
|
if(this.lore.equals(lore))
|
||||||
|
return;
|
||||||
|
|
||||||
|
List<String> old = this.lore;
|
||||||
|
this.lore = lore;
|
||||||
|
|
||||||
|
ChangeLoreEvent e = new ChangeLoreEvent(this, old, lore);
|
||||||
|
Bukkit.getPluginManager().callEvent(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLore(int i, String string) {
|
||||||
|
if(lore.size() >= 4 || i >= 4)
|
||||||
|
return;
|
||||||
|
|
||||||
|
List<String> old = lore;
|
||||||
|
lore = new ArrayList<>();
|
||||||
|
lore.addAll(old);
|
||||||
|
|
||||||
|
if(!string.equals("NULL")) {
|
||||||
|
if (lore.size() >= i)
|
||||||
|
for (int a = 0; a <= (i - lore.size()); a++)
|
||||||
|
lore.add(" ");
|
||||||
|
|
||||||
|
lore.set(i, string);
|
||||||
|
} else {
|
||||||
|
lore.remove(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
ChangeLoreEvent e = new ChangeLoreEvent(this, old, lore);
|
||||||
|
Bukkit.getPluginManager().callEvent(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinkedHashMap<String, Attraction> getAttractions() {
|
||||||
|
return attractions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAttractions(LinkedHashMap<String, Attraction> attractions) {
|
||||||
|
this.attractions = attractions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addAttraction(Attraction attraction) {
|
||||||
|
if(attraction == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(!isAttraction(attraction))
|
||||||
|
attractions.put(attraction.getId(), attraction);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAttraction(Attraction attraction) {
|
||||||
|
if(attraction == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return attractions.containsKey(attraction.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeAttraction(Attraction attraction) {
|
||||||
|
if(isAttraction(attraction))
|
||||||
|
attractions.remove(attraction.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package me.paradoxpixel.themepark.api.attraction.component;
|
package nl.iobyte.themepark.api.attraction.component;
|
||||||
|
|
||||||
public enum Status {
|
public enum Status {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package me.paradoxpixel.themepark.api.attraction.component;
|
package nl.iobyte.themepark.api.attraction.component;
|
||||||
|
|
||||||
public enum Type {
|
public enum Type {
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
package nl.iobyte.themepark.api.attraction.manager;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.api.attraction.component.Status;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class StatusManager {
|
||||||
|
|
||||||
|
private static HashMap<Status, String> names = new HashMap<>();
|
||||||
|
private static HashMap<Status, Material> materials = new HashMap<>();
|
||||||
|
private static HashMap<Status, Short> datas = new HashMap<>();
|
||||||
|
private static HashMap<Status, Boolean> teleports = new HashMap<>();
|
||||||
|
|
||||||
|
public static void addStatus(Status status, String name, Material material, short data, boolean teleport) {
|
||||||
|
if(status == null || name == null || material == null || data < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(name.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
names.put(status, name);
|
||||||
|
materials.put(status, material);
|
||||||
|
datas.put(status, data);
|
||||||
|
teleports.put(status, teleport);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getName(Status status) {
|
||||||
|
return names.get(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Material getMaterial(Status status) {
|
||||||
|
return materials.get(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static short getData(Status status) {
|
||||||
|
return datas.get(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean canTeleport(Status status) {
|
||||||
|
return teleports.get(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package nl.iobyte.themepark.api.events;
|
||||||
|
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class ChangeEvent<T> extends Event {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
private T before, after;
|
||||||
|
|
||||||
|
public ChangeEvent(T before, T after) {
|
||||||
|
this.before = before;
|
||||||
|
this.after = after;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getBefore() {
|
||||||
|
return before;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getAfter() {
|
||||||
|
return after;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package nl.iobyte.themepark.api.events.attraction;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
|
import nl.iobyte.themepark.api.events.ChangeEvent;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
public class ChangeLocationEvent extends ChangeEvent<Location> {
|
||||||
|
|
||||||
|
private Attraction attraction;
|
||||||
|
|
||||||
|
public ChangeLocationEvent(Attraction attraction, Location before, Location after) {
|
||||||
|
super(before, after);
|
||||||
|
this.attraction = attraction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Attraction getAttraction() {
|
||||||
|
return attraction;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package nl.iobyte.themepark.api.events.attraction;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
|
import nl.iobyte.themepark.api.events.ChangeEvent;
|
||||||
|
|
||||||
|
public class ChangeNameEvent extends ChangeEvent<String> {
|
||||||
|
|
||||||
|
private Attraction attraction;
|
||||||
|
|
||||||
|
public ChangeNameEvent(Attraction attraction, String before, String after) {
|
||||||
|
super(before, after);
|
||||||
|
this.attraction = attraction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Attraction getAttraction() {
|
||||||
|
return attraction;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package nl.iobyte.themepark.api.events.attraction;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
|
import nl.iobyte.themepark.api.attraction.component.Status;
|
||||||
|
import nl.iobyte.themepark.api.events.ChangeEvent;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class ChangeStatusEvent extends ChangeEvent<Status> {
|
||||||
|
|
||||||
|
private Attraction attraction;
|
||||||
|
private Player player;
|
||||||
|
|
||||||
|
public ChangeStatusEvent(Attraction attraction, Player player, Status before, Status after) {
|
||||||
|
super(before, after);
|
||||||
|
this.attraction = attraction;
|
||||||
|
this.player = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Attraction getAttraction() {
|
||||||
|
return attraction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package nl.iobyte.themepark.api.events.attraction;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
|
import nl.iobyte.themepark.api.attraction.component.Type;
|
||||||
|
import nl.iobyte.themepark.api.events.ChangeEvent;
|
||||||
|
|
||||||
|
public class ChangeTypeEvent extends ChangeEvent<Type> {
|
||||||
|
|
||||||
|
private Attraction attraction;
|
||||||
|
|
||||||
|
public ChangeTypeEvent(Attraction attraction, Type before, Type after) {
|
||||||
|
super(before, after);
|
||||||
|
this.attraction = attraction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Attraction getAttraction() {
|
||||||
|
return attraction;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package nl.iobyte.themepark.api.events.attraction;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
|
import nl.iobyte.themepark.api.attraction.component.Status;
|
||||||
|
import nl.iobyte.themepark.api.events.ChangeEvent;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
|
||||||
|
public class PreChangeStatusEvent extends ChangeEvent<Status> implements Cancellable {
|
||||||
|
|
||||||
|
private Attraction attraction;
|
||||||
|
private Player player;
|
||||||
|
private boolean cancel = false;
|
||||||
|
|
||||||
|
public PreChangeStatusEvent(Attraction attraction, Player player, Status before, Status after) {
|
||||||
|
super(before, after);
|
||||||
|
this.attraction = attraction;
|
||||||
|
this.player = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Attraction getAttraction() {
|
||||||
|
return attraction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCancelled(boolean b) {
|
||||||
|
cancel = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package nl.iobyte.themepark.api.events.region;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.api.attraction.Region;
|
||||||
|
import nl.iobyte.themepark.api.events.ChangeEvent;
|
||||||
|
|
||||||
|
public class ChangeDataEvent extends ChangeEvent<Short> {
|
||||||
|
|
||||||
|
private Region region;
|
||||||
|
|
||||||
|
public ChangeDataEvent(Region region, short before, short after) {
|
||||||
|
super(before, after);
|
||||||
|
this.region = region;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Region getRegion() {
|
||||||
|
return region;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package nl.iobyte.themepark.api.events.region;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.api.attraction.Region;
|
||||||
|
import nl.iobyte.themepark.api.events.ChangeEvent;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ChangeLoreEvent extends ChangeEvent<List<String>> {
|
||||||
|
|
||||||
|
private Region region;
|
||||||
|
|
||||||
|
public ChangeLoreEvent(Region region, List<String> before, List<String> after) {
|
||||||
|
super(before, after);
|
||||||
|
this.region = region;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Region getRegion() {
|
||||||
|
return region;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package nl.iobyte.themepark.api.events.region;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.api.attraction.Region;
|
||||||
|
import nl.iobyte.themepark.api.events.ChangeEvent;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
|
||||||
|
public class ChangeMaterialEvent extends ChangeEvent<Material> {
|
||||||
|
|
||||||
|
private Region region;
|
||||||
|
|
||||||
|
public ChangeMaterialEvent(Region region, Material before, Material after) {
|
||||||
|
super(before, after);
|
||||||
|
this.region = region;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Region getRegion() {
|
||||||
|
return region;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package nl.iobyte.themepark.api.events.region;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.api.attraction.Region;
|
||||||
|
import nl.iobyte.themepark.api.events.ChangeEvent;
|
||||||
|
|
||||||
|
public class ChangeNameEvent extends ChangeEvent<String> {
|
||||||
|
|
||||||
|
private Region region;
|
||||||
|
|
||||||
|
public ChangeNameEvent(Region region, String before, String after) {
|
||||||
|
super(before, after);
|
||||||
|
this.region = region;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Region getRegion() {
|
||||||
|
return region;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package nl.iobyte.themepark.api.events.ridecount;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
|
import nl.iobyte.themepark.api.events.ChangeEvent;
|
||||||
|
import nl.iobyte.themepark.api.ridecount.AttractionCount;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class ChangeCountEvent extends ChangeEvent<Integer> {
|
||||||
|
|
||||||
|
private Attraction attraction;
|
||||||
|
private AttractionCount counter;
|
||||||
|
private UUID uuid;
|
||||||
|
|
||||||
|
public ChangeCountEvent(Attraction attraction, AttractionCount counter, UUID uuid, int before, int after) {
|
||||||
|
super(before, after);
|
||||||
|
this.attraction = attraction;
|
||||||
|
this.counter = counter;
|
||||||
|
this.uuid = uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Attraction getAttraction() {
|
||||||
|
return attraction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AttractionCount getCounter() {
|
||||||
|
return counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getUUID() {
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package nl.iobyte.themepark.api.events.ridecount;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
|
import nl.iobyte.themepark.api.events.ChangeEvent;
|
||||||
|
import nl.iobyte.themepark.api.ridecount.AttractionCount;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class SetCountEvent extends ChangeEvent<Integer> {
|
||||||
|
|
||||||
|
private Attraction attraction;
|
||||||
|
private AttractionCount counter;
|
||||||
|
private UUID uuid;
|
||||||
|
|
||||||
|
public SetCountEvent(Attraction attraction, AttractionCount counter, UUID uuid, int before, int after) {
|
||||||
|
super(before, after);
|
||||||
|
this.attraction = attraction;
|
||||||
|
this.counter = counter;
|
||||||
|
this.uuid = uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Attraction getAttraction() {
|
||||||
|
return attraction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AttractionCount getCounter() {
|
||||||
|
return counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getUUID() {
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,92 @@
|
||||||
|
package nl.iobyte.themepark.api.ridecount;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
|
import nl.iobyte.themepark.api.events.ridecount.ChangeCountEvent;
|
||||||
|
import nl.iobyte.themepark.api.events.ridecount.SetCountEvent;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class AttractionCount {
|
||||||
|
|
||||||
|
private Attraction attraction;
|
||||||
|
private HashMap<UUID, RideCount> counts = new HashMap<>();
|
||||||
|
|
||||||
|
public AttractionCount(Attraction attraction) {
|
||||||
|
this.attraction = attraction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Attraction getAttraction() {
|
||||||
|
return attraction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addCount(RideCount rideCount) {
|
||||||
|
if(rideCount == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(!attraction.getId().equals(rideCount.getAttraction().getId()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
counts.put(rideCount.getUUID(), rideCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasCount(UUID uuid) {
|
||||||
|
if(uuid == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return counts.containsKey(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RideCount getCount(UUID uuid) {
|
||||||
|
if(!hasCount(uuid))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return counts.get(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeCount(UUID uuid) {
|
||||||
|
if(!hasCount(uuid))
|
||||||
|
return;
|
||||||
|
|
||||||
|
counts.remove(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addCount(UUID uuid, int amount) {
|
||||||
|
if(amount < 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int before = 0;
|
||||||
|
int after = amount;
|
||||||
|
RideCount count = getCount(uuid);
|
||||||
|
if(count == null) {
|
||||||
|
count = new RideCount(uuid, attraction, amount);
|
||||||
|
counts.put(uuid, count);
|
||||||
|
} else {
|
||||||
|
before = count.getCount();
|
||||||
|
after += before;
|
||||||
|
count.addCount(amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
ChangeCountEvent e = new ChangeCountEvent(attraction, this, uuid, before, after);
|
||||||
|
Bukkit.getPluginManager().callEvent(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCount(UUID uuid, int amount) {
|
||||||
|
RideCount count = getCount(uuid);
|
||||||
|
|
||||||
|
if(count == null) {
|
||||||
|
count = new RideCount(uuid, attraction, amount);
|
||||||
|
counts.put(uuid, count);
|
||||||
|
} else {
|
||||||
|
if(count.getCount() == amount)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int before = count.getCount();
|
||||||
|
count.setCount(amount);
|
||||||
|
SetCountEvent e = new SetCountEvent(attraction, this, uuid, before, amount);
|
||||||
|
Bukkit.getPluginManager().callEvent(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,73 @@
|
||||||
|
package nl.iobyte.themepark.api.ridecount;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.api.API;
|
||||||
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class CountManager {
|
||||||
|
|
||||||
|
private static HashMap<String, AttractionCount> counts = new HashMap<>();
|
||||||
|
|
||||||
|
public static void addCounter(Attraction attraction) {
|
||||||
|
if(attraction == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(counts.containsKey(attraction.getId()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(!API.isAttraction(attraction.getId()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
counts.put(attraction.getId(), new AttractionCount(attraction));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isCounter(String id) {
|
||||||
|
if(id == null || id.isEmpty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return counts.containsKey(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AttractionCount getCounter(String id) {
|
||||||
|
if(!isCounter(id))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return counts.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeCounter(String id) {
|
||||||
|
if(!isCounter(id))
|
||||||
|
return;
|
||||||
|
|
||||||
|
counts.remove(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addCount(Attraction attraction, UUID uuid, int amount) {
|
||||||
|
if(attraction == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
AttractionCount count = getCounter(attraction.getId());
|
||||||
|
if(count == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
count.addCount(uuid, amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setCount(Attraction attraction, UUID uuid, int amount) {
|
||||||
|
if(attraction == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
AttractionCount count = getCounter(attraction.getId());
|
||||||
|
if(count == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
count.setCount(uuid, amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeCount(UUID uuid) {
|
||||||
|
for(AttractionCount attractionCount : counts.values())
|
||||||
|
attractionCount.removeCount(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package nl.iobyte.themepark.api.ridecount;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class RideCount {
|
||||||
|
|
||||||
|
private UUID uuid;
|
||||||
|
private Attraction attraction;
|
||||||
|
private int count;
|
||||||
|
|
||||||
|
public RideCount(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 void addCount(int amount) {
|
||||||
|
count += amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,13 +1,14 @@
|
||||||
package me.paradoxpixel.themepark.utils;
|
package nl.iobyte.themepark.api.utils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import org.bukkit.ChatColor;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class ItemBuilder {
|
public class ItemBuilder {
|
||||||
|
|
||||||
|
@ -43,7 +44,7 @@ public class ItemBuilder {
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
meta.setDisplayName(Utils.color(name));
|
meta.setDisplayName(color(name));
|
||||||
this.item.setItemMeta(meta);
|
this.item.setItemMeta(meta);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -54,7 +55,7 @@ public class ItemBuilder {
|
||||||
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
for(String string : lore)
|
for(String string : lore)
|
||||||
lore.set(lore.indexOf(string), Utils.color(string));
|
lore.set(lore.indexOf(string), color(string));
|
||||||
|
|
||||||
meta.setLore(lore);
|
meta.setLore(lore);
|
||||||
item.setItemMeta(meta);
|
item.setItemMeta(meta);
|
||||||
|
@ -108,4 +109,8 @@ public class ItemBuilder {
|
||||||
return new ItemBuilder(item);
|
return new ItemBuilder(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String color(String string) {
|
||||||
|
return ChatColor.translateAlternateColorCodes('&', string);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,10 +1,10 @@
|
||||||
package me.paradoxpixel.themepark.api;
|
package nl.iobyte.themepark.api.utils;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
public class LocationUtils {
|
public class LocationSerializer {
|
||||||
|
|
||||||
public static String toString(Location location) {
|
public static String toString(Location location) {
|
||||||
if(location == null)
|
if(location == null)
|
||||||
|
@ -26,22 +26,16 @@ public class LocationUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Location toLocation(String string) {
|
public static Location toLocation(String string) {
|
||||||
if(string == null || string.isEmpty()) {
|
if(string == null || string.isEmpty())
|
||||||
System.out.println("LocationUtils: Incorrect String passed");
|
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
|
|
||||||
String[] args = string.split(":");
|
String[] args = string.split(":");
|
||||||
if(args.length < 4) {
|
if(args.length < 4)
|
||||||
System.out.println("LocationUtils: Not enough arguments");
|
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
|
|
||||||
World world = Bukkit.getWorld(args[0]);
|
World world = Bukkit.getWorld(args[0]);
|
||||||
if(world == null) {
|
if(world == null)
|
||||||
System.out.println("LocationUtils: No world with name: "+args[0]);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
|
|
||||||
double x = Double.parseDouble(args[1]);
|
double x = Double.parseDouble(args[1]);
|
||||||
double y = Double.parseDouble(args[2]);
|
double y = Double.parseDouble(args[2]);
|
403
src/main/java/nl/iobyte/themepark/command/MainCommand.java
Normal file
403
src/main/java/nl/iobyte/themepark/command/MainCommand.java
Normal file
|
@ -0,0 +1,403 @@
|
||||||
|
package nl.iobyte.themepark.command;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.ThemeParkPlugin;
|
||||||
|
import nl.iobyte.themepark.api.API;
|
||||||
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
|
import nl.iobyte.themepark.api.attraction.Region;
|
||||||
|
import nl.iobyte.themepark.api.attraction.component.Status;
|
||||||
|
import nl.iobyte.themepark.api.attraction.component.Type;
|
||||||
|
import nl.iobyte.themepark.api.attraction.manager.StatusManager;
|
||||||
|
import nl.iobyte.themepark.api.utils.ItemBuilder;
|
||||||
|
import nl.iobyte.themepark.api.utils.LocationSerializer;
|
||||||
|
import nl.iobyte.themepark.config.YamlConfig;
|
||||||
|
import nl.iobyte.themepark.menu.AttractionLoader;
|
||||||
|
import nl.iobyte.themepark.menu.AttractionMenu;
|
||||||
|
import nl.iobyte.themepark.util.Color;
|
||||||
|
import nl.iobyte.themepark.util.MessageUtil;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.defaults.BukkitCommand;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.entity.Minecart;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class MainCommand extends BukkitCommand {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public MainCommand(String name) {
|
||||||
|
super(name);
|
||||||
|
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean execute(CommandSender sender,String label, String[] args) {
|
||||||
|
if (args.length == 0 || args[0].equalsIgnoreCase("help")) {
|
||||||
|
sender.sendMessage(Color.color("&f&L>==== &r&6ThemePark &L&f ====<"));
|
||||||
|
sender.sendMessage(Color.color("&f/" + name + " help"));
|
||||||
|
sender.sendMessage(Color.color("&f/" + name + " list"));
|
||||||
|
sender.sendMessage(Color.color("&f/" + name + " warp <id>"));
|
||||||
|
if(sender.hasPermission("themepark.admin") || sender.hasPermission("themepark.item")) {
|
||||||
|
sender.sendMessage(Color.color("&f/" + name + " toggleitem"));
|
||||||
|
sender.sendMessage(Color.color("&f/" + name + " getitem"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sender.hasPermission("themepark.admin")) {
|
||||||
|
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 + " attraction create <region> <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 location <id>"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args[0].equalsIgnoreCase("list")) {
|
||||||
|
sender.sendMessage(Color.color("&f&L>==== &r&6ThemePark &f&L ====<"));
|
||||||
|
if (API.getAttractions().size() == 0) {
|
||||||
|
sender.sendMessage(Color.color(MessageUtil.getMessage("attraction.notfound")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Attraction attraction : API.getAttractions().values()) {
|
||||||
|
String message = MessageUtil.getMessage("attraction.list");
|
||||||
|
message = message.replace("{id}", attraction.getId());
|
||||||
|
message = message.replace("{name}", attraction.getName());
|
||||||
|
message = message.replace("{region}", attraction.getRegion().getName());
|
||||||
|
message = message.replace("{type}", attraction.getType().toString());
|
||||||
|
message = message.replace("{status}", StatusManager.getName(attraction.getStatus()));
|
||||||
|
sender.sendMessage(Color.color(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(args[0].equalsIgnoreCase("warp")) {
|
||||||
|
if(args.length < 2) {
|
||||||
|
sender.sendMessage(Color.color( MessageUtil.getMessage("prefix")+" &4/" + name + " warp <id>"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String id = args[1];
|
||||||
|
if(!API.isAttraction(id)) {
|
||||||
|
String message = MessageUtil.getMessage("attraction.not");
|
||||||
|
message = message.replace("{id}", id);
|
||||||
|
sender.sendMessage(Color.color(message));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sender instanceof Player) {
|
||||||
|
Attraction attraction = API.getAttraction(id);
|
||||||
|
Player player = (Player) sender;
|
||||||
|
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 true;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.teleport(attraction.getLocation());
|
||||||
|
if(player.isInsideVehicle())
|
||||||
|
if(player.getVehicle() instanceof Minecart)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
player.sendMessage(Color.color(MessageUtil.getMessage("attraction.teleport.success").replace("{name}", attraction.getName())));
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(Color.color(MessageUtil.getMessage("onlyplayers")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!sender.hasPermission("themepark.admin") && !sender.hasPermission("themepark.item")) {
|
||||||
|
sender.sendMessage(Color.color(MessageUtil.getMessage("nopermission")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(args[0].equalsIgnoreCase("toggleitem")) {
|
||||||
|
if(!(sender instanceof Player)) {
|
||||||
|
sender.sendMessage(Color.color(MessageUtil.getMessage("onlyplayers")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = (Player) sender;
|
||||||
|
UUID uuid = player.getUniqueId();
|
||||||
|
|
||||||
|
YamlConfig config = ThemeParkPlugin.getInstance().getData();
|
||||||
|
boolean b = config.getConfig().getBoolean(uuid.toString() + ".item");
|
||||||
|
b = !b;
|
||||||
|
|
||||||
|
config.getConfig().set(uuid.toString() + ".item", b);
|
||||||
|
config.save();
|
||||||
|
|
||||||
|
String message = MessageUtil.getMessage("menu-item.toggle");
|
||||||
|
message = message.replace("{status}", b ? MessageUtil.getMessage("menu-item.enabled") : MessageUtil.getMessage("menu-item.disabled"));
|
||||||
|
sender.sendMessage(Color.color(message));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(args[0].equalsIgnoreCase("getitem")) {
|
||||||
|
YamlConfig settings = ThemeParkPlugin.getInstance().getSettings();
|
||||||
|
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())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
Player player;
|
||||||
|
if(args.length >= 2) {
|
||||||
|
String string = args[1];
|
||||||
|
if(Bukkit.getPlayerExact(string) == null) {
|
||||||
|
String message = MessageUtil.getMessage("noplayer");
|
||||||
|
message = message.replace("{name}", string);
|
||||||
|
sender.sendMessage(Color.color(message));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
player = Bukkit.getPlayerExact(string);
|
||||||
|
} else {
|
||||||
|
if(!(sender instanceof Player)) {
|
||||||
|
sender.sendMessage(Color.color(MessageUtil.getMessage("onlyplayers")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
player = (Player) sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ItemBuilder builder = new ItemBuilder(material, 1, data);
|
||||||
|
builder.setName(name);
|
||||||
|
player.getInventory().addItem(builder.getItem());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!sender.hasPermission("themepark.admin")) {
|
||||||
|
sender.sendMessage(Color.color(MessageUtil.getMessage("nopermission")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args[0].equalsIgnoreCase("region")) {
|
||||||
|
if(args.length < 2)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (args[1].equalsIgnoreCase("create")) {
|
||||||
|
if (args.length < 4 ) {
|
||||||
|
sender.sendMessage(Color.color(MessageUtil.getMessage("prefix")+" &4/" + name + " region create <id> <name>"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String id = args[2];
|
||||||
|
if (API.isRegion(id)) {
|
||||||
|
String message = MessageUtil.getMessage("region.exists");
|
||||||
|
message = message.replace("{id}", id);
|
||||||
|
sender.sendMessage(Color.color(message));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append(args[3]);
|
||||||
|
for(int i = 4; i < args.length; i++)
|
||||||
|
builder.append(" ").append(args[i]);
|
||||||
|
|
||||||
|
String name = builder.toString();
|
||||||
|
Region region = new Region(id, name, new ArrayList<>());
|
||||||
|
API.addRegion(region);
|
||||||
|
AttractionMenu.load();
|
||||||
|
AttractionLoader.addRegion(id);
|
||||||
|
|
||||||
|
YamlConfig config = ThemeParkPlugin.getInstance().getRegions();
|
||||||
|
FileConfiguration fc = config.getConfig();
|
||||||
|
String path = "regions."+id+".";
|
||||||
|
fc.set(path+"name", name);
|
||||||
|
fc.set(path+"lore", region.getLore());
|
||||||
|
config.save();
|
||||||
|
|
||||||
|
sender.sendMessage(Color.color(MessageUtil.getMessage("region.create").replace("{name}", name)));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(args[1].equalsIgnoreCase("name")) {
|
||||||
|
if (args.length < 4 ) {
|
||||||
|
sender.sendMessage(Color.color("&f/" + name + " region name <id> <name>"));
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append(args[3]);
|
||||||
|
for(int i = 4; i < args.length; i++)
|
||||||
|
builder.append(" ").append(args[i]);
|
||||||
|
|
||||||
|
String name = builder.toString();
|
||||||
|
Region region = API.getRegion(id);
|
||||||
|
region.setName(name);
|
||||||
|
sender.sendMessage(Color.color(MessageUtil.getMessage("region.name").replace("{name}", region.getName())));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args[0].equalsIgnoreCase("attraction")) {
|
||||||
|
if(args.length < 2)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (args[1].equalsIgnoreCase("create")) {
|
||||||
|
if (args.length < 6 ) {
|
||||||
|
sender.sendMessage(Color.color(MessageUtil.getMessage("prefix")+" &4/" + name + " attraction create <region> <id> <type> <name>"));
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
id = args[3];
|
||||||
|
if (API.isAttraction(id)) {
|
||||||
|
String message = MessageUtil.getMessage("attraction.exists");
|
||||||
|
message = message.replace("{id}", id);
|
||||||
|
sender.sendMessage(Color.color(message));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Type type = Type.getType(args[4]);
|
||||||
|
if(type == null) {
|
||||||
|
String message = MessageUtil.getMessage("no-type");
|
||||||
|
message = message.replace("{type}", args[4]);
|
||||||
|
sender.sendMessage(Color.color(message));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append(args[5]);
|
||||||
|
for(int i = 6; i < args.length; i++)
|
||||||
|
builder.append(" ").append(args[i]);
|
||||||
|
|
||||||
|
String name = builder.toString();
|
||||||
|
Attraction attraction = new Attraction(args[3], name, args[2], null, type, type.getDefault());
|
||||||
|
API.addAttraction(attraction);
|
||||||
|
AttractionMenu.load();
|
||||||
|
|
||||||
|
YamlConfig config = AttractionLoader.getConfig(attraction.getRegionId());
|
||||||
|
FileConfiguration fc = config.getConfig();
|
||||||
|
String path = "attractions."+attraction.getId()+".";
|
||||||
|
fc.set(path+"name", attraction.getName());
|
||||||
|
fc.set(path+"type", type.toString());
|
||||||
|
fc.set(path+"status", attraction.getStatus().toString());
|
||||||
|
config.save();
|
||||||
|
|
||||||
|
sender.sendMessage(Color.color(MessageUtil.getMessage("attraction.create").replace("{name}", name)));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(args[1].equalsIgnoreCase("name")) {
|
||||||
|
if (args.length < 4 ) {
|
||||||
|
sender.sendMessage(Color.color("&f/" + name + " attraction name <id> <name>"));
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append(args[3]);
|
||||||
|
for(int i = 4; i < args.length; i++)
|
||||||
|
builder.append(" ").append(args[i]);
|
||||||
|
|
||||||
|
String name = builder.toString();
|
||||||
|
Attraction attraction = API.getAttraction(id);
|
||||||
|
attraction.setName(name);
|
||||||
|
sender.sendMessage(Color.color(MessageUtil.getMessage("attraction.name").replace("{name}", attraction.getName())));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args[1].equalsIgnoreCase("status")) {
|
||||||
|
if (args.length < 4 ) {
|
||||||
|
sender.sendMessage(Color.color(MessageUtil.getMessage("prefix")+" &4/" + name + " attraction status <id> <status>"));
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
Status status = Status.getStatus(args[3].toUpperCase());
|
||||||
|
if (status == null) {
|
||||||
|
String message = MessageUtil.getMessage("no-status");
|
||||||
|
message = message.replace("{status}", args[3]);
|
||||||
|
sender.sendMessage(Color.color(message));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Attraction attraction = API.getAttraction(id);
|
||||||
|
if(!attraction.getType().containsStatus(status)) {
|
||||||
|
String message = MessageUtil.getMessage("attraction.nostatus");
|
||||||
|
message = message.replace("{name}", attraction.getName());
|
||||||
|
message = message.replace("{status}", status.toString());
|
||||||
|
sender.sendMessage(Color.color(message));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(attraction.getStatus() == status)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
Player player = (sender instanceof Player) ? (Player) sender : null;
|
||||||
|
attraction.setStatus(status, player);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(args[1].equalsIgnoreCase("location")) {
|
||||||
|
if (args.length < 3 ) {
|
||||||
|
sender.sendMessage(Color.color("&f/" + name + " attraction location <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;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!(sender instanceof Player)) {
|
||||||
|
sender.sendMessage(Color.color(MessageUtil.getMessage("onlyplayers")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Attraction attraction = API.getAttraction(id);
|
||||||
|
Location location = ((Player) sender).getLocation();
|
||||||
|
attraction.setLocation(location.clone());
|
||||||
|
sender.sendMessage(Color.color(MessageUtil.getMessage("attraction.location").replace("{name}", attraction.getName())));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,7 +1,8 @@
|
||||||
package me.paradoxpixel.themepark.command;
|
package nl.iobyte.themepark.command;
|
||||||
|
|
||||||
import me.paradoxpixel.themepark.attraction.AttractionMenu;
|
import nl.iobyte.themepark.menu.AttractionMenu;
|
||||||
import me.paradoxpixel.themepark.utils.Utils;
|
import nl.iobyte.themepark.util.Color;
|
||||||
|
import nl.iobyte.themepark.util.MessageUtil;
|
||||||
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;
|
||||||
|
@ -13,13 +14,16 @@ public class MenuCommand implements CommandExecutor {
|
||||||
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("status")) {
|
if(cmd.getName().equalsIgnoreCase("status")) {
|
||||||
if(sender instanceof Player) {
|
if(sender instanceof Player) {
|
||||||
AttractionMenu.openMenu((Player) sender, 1);
|
AttractionMenu.open((Player) sender);
|
||||||
return true;
|
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(Utils.color("&6Themepark&f: &4Only players can use this command"));
|
sender.sendMessage(Color.color(MessageUtil.getMessage("onlyplayers")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
107
src/main/java/nl/iobyte/themepark/command/RidecountCommand.java
Normal file
107
src/main/java/nl/iobyte/themepark/command/RidecountCommand.java
Normal file
|
@ -0,0 +1,107 @@
|
||||||
|
package nl.iobyte.themepark.command;
|
||||||
|
|
||||||
|
import nl.iobyte.menuapi.map.WeakConcurrentHashMap;
|
||||||
|
import nl.iobyte.themepark.api.API;
|
||||||
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
|
import nl.iobyte.themepark.ridecount.RideCountAPI;
|
||||||
|
import nl.iobyte.themepark.util.Color;
|
||||||
|
import nl.iobyte.themepark.util.MessageUtil;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class RidecountCommand implements CommandExecutor {
|
||||||
|
|
||||||
|
private static WeakConcurrentHashMap<String, String> data = new WeakConcurrentHashMap<>(5 * 60 * 1000);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if(!cmd.getName().equalsIgnoreCase("ridecount"))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(args.length == 0 || args[0].equalsIgnoreCase("help")) {
|
||||||
|
sender.sendMessage(Color.color("&f&L>==== &r&6Ridecount &L&f ====<"));
|
||||||
|
sender.sendMessage(Color.color("&f/ridecount help"));
|
||||||
|
sender.sendMessage(Color.color("&f/ridecount get <player> <id>"));
|
||||||
|
sender.sendMessage(Color.color("&f/ridecount add <player> <id> <amount>"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(args[0].equalsIgnoreCase("get")) {
|
||||||
|
if(args.length < 3) {
|
||||||
|
sender.sendMessage(Color.color(MessageUtil.getMessage("prefix")+" &4/ridecount get <player> <id>"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!API.isAttraction(args[2])) {
|
||||||
|
String message = MessageUtil.getMessage("attraction.not");
|
||||||
|
message = message.replace("{id}", args[2]);
|
||||||
|
sender.sendMessage(Color.color(message));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Attraction attraction = API.getAttraction(args[2]);
|
||||||
|
RideCountAPI.getCount(args[1], attraction).thenAccept(points -> {
|
||||||
|
if(points < 0) {
|
||||||
|
sender.sendMessage(Color.color(MessageUtil.getMessage("noplayer").replace("{name}", args[1])));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String mesage = MessageUtil.getMessage("ridecount.count");
|
||||||
|
mesage = mesage.replace("{name}", attraction.getName());
|
||||||
|
mesage = mesage.replace("{count}", points.toString());
|
||||||
|
sender.sendMessage(Color.color(mesage));
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(args[0].equalsIgnoreCase("add")) {
|
||||||
|
if(args.length < 4) {
|
||||||
|
sender.sendMessage(Color.color(MessageUtil.getMessage("prefix")+" &4/ridecount add <player> <id> <amount>"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!API.isAttraction(args[2])) {
|
||||||
|
String message = MessageUtil.getMessage("attraction.not");
|
||||||
|
message = message.replace("{id}", args[2]);
|
||||||
|
sender.sendMessage(Color.color(message));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!isInteger(args[3])) {
|
||||||
|
sender.sendMessage(Color.color(MessageUtil.getMessage("nonumber").replace("{number}", args[3])));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int amount = Integer.parseInt(args[3]);
|
||||||
|
Attraction attraction = API.getAttraction(args[2]);
|
||||||
|
RideCountAPI.addCount(args[1], attraction, amount).thenAccept(result -> {
|
||||||
|
if(!result) {
|
||||||
|
sender.sendMessage(Color.color(MessageUtil.getMessage("noplayer").replace("{name}", args[1])));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String mesage = MessageUtil.getMessage("ridecount.add");
|
||||||
|
mesage = mesage.replace("{name}", API.getAttraction(args[2]).getName());
|
||||||
|
mesage = mesage.replace("{count}", Integer.toString(amount));
|
||||||
|
sender.sendMessage(Color.color(mesage));
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private boolean isInteger(String s) {
|
||||||
|
int radix = 10;
|
||||||
|
Scanner sc = new Scanner(s.trim());
|
||||||
|
if(!sc.hasNextInt(radix)) return false;
|
||||||
|
sc.nextInt(radix);
|
||||||
|
return !sc.hasNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package me.paradoxpixel.themepark.config;
|
package nl.iobyte.themepark.config;
|
||||||
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
77
src/main/java/nl/iobyte/themepark/database/DB.java
Normal file
77
src/main/java/nl/iobyte/themepark/database/DB.java
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
package nl.iobyte.themepark.database;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public abstract class DB {
|
||||||
|
|
||||||
|
public abstract Connection getConnection();
|
||||||
|
|
||||||
|
public abstract void closeConnection();
|
||||||
|
|
||||||
|
public boolean execute(String query, HashMap<Integer, Object> objects) {
|
||||||
|
if(query == null || query.isEmpty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(getConnection() == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
PreparedStatement statement = getConnection().prepareStatement(query);
|
||||||
|
statement.closeOnCompletion();
|
||||||
|
if(objects != null)
|
||||||
|
for(Map.Entry<Integer, Object> entry : objects.entrySet())
|
||||||
|
statement.setObject(entry.getKey(), entry.getValue());
|
||||||
|
|
||||||
|
return statement.execute();
|
||||||
|
} catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int executeUpdate(String query, HashMap<Integer, Object> objects) {
|
||||||
|
if (query == null || query.isEmpty())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if(getConnection() == null)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
try {
|
||||||
|
PreparedStatement statement = getConnection().prepareStatement(query);
|
||||||
|
statement.closeOnCompletion();
|
||||||
|
for (Map.Entry<Integer, Object> entry : objects.entrySet())
|
||||||
|
statement.setObject(entry.getKey(), entry.getValue());
|
||||||
|
|
||||||
|
return statement.executeUpdate();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResultSet executeQuery(String query, HashMap<Integer, Object> objects) {
|
||||||
|
if (query == null || query.isEmpty())
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if (getConnection() == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
PreparedStatement statement = getConnection().prepareStatement(query);
|
||||||
|
statement.closeOnCompletion();
|
||||||
|
if (objects != null)
|
||||||
|
for (Map.Entry<Integer, Object> entry : objects.entrySet())
|
||||||
|
statement.setObject(entry.getKey(), entry.getValue());
|
||||||
|
|
||||||
|
return statement.executeQuery();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
90
src/main/java/nl/iobyte/themepark/database/DBManager.java
Normal file
90
src/main/java/nl/iobyte/themepark/database/DBManager.java
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
package nl.iobyte.themepark.database;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class DBManager {
|
||||||
|
|
||||||
|
private static HashMap<String, DB> databases = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add DB to manager
|
||||||
|
* @param id identifier
|
||||||
|
* @param db DB Instance
|
||||||
|
*/
|
||||||
|
public static void addDatabase(String id, DB db) {
|
||||||
|
if(id == null || id.isEmpty() || db == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(databases.containsKey(id))
|
||||||
|
return;
|
||||||
|
|
||||||
|
databases.put(id, db);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Database
|
||||||
|
* @param id identifier
|
||||||
|
* @return DB Instance
|
||||||
|
*/
|
||||||
|
public static DB getDatabase(String id) {
|
||||||
|
if(id == null || id.isEmpty())
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return databases.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Database exists
|
||||||
|
* @param id identifier
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public static boolean hasDatabase(String id) {
|
||||||
|
if(id == null || id.isEmpty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return databases.containsKey(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove Database
|
||||||
|
* @param id identifier
|
||||||
|
*/
|
||||||
|
public static void removeDatabase(String id) {
|
||||||
|
DB db = getDatabase(id);
|
||||||
|
if(db == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
db.closeConnection();
|
||||||
|
databases.remove(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close all connections
|
||||||
|
*/
|
||||||
|
public static void shutdown() {
|
||||||
|
for(DB db : databases.values())
|
||||||
|
db.closeConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create tabke
|
||||||
|
* @param db DB Instance
|
||||||
|
* @param query Query
|
||||||
|
*/
|
||||||
|
public static void createTable(DB db, String query) {
|
||||||
|
if(db == null || query == null || query.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Connection connection = db.getConnection();
|
||||||
|
PreparedStatement statement = connection.prepareStatement(query);
|
||||||
|
statement.execute();
|
||||||
|
statement.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
66
src/main/java/nl/iobyte/themepark/database/MySQL.java
Normal file
66
src/main/java/nl/iobyte/themepark/database/MySQL.java
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
package nl.iobyte.themepark.database;
|
||||||
|
|
||||||
|
import com.zaxxer.hikari.HikariConfig;
|
||||||
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
|
import nl.iobyte.themepark.ThemeParkPlugin;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class MySQL extends DB {
|
||||||
|
|
||||||
|
private String dbName;
|
||||||
|
private HikariDataSource source;
|
||||||
|
private Connection con;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize a new connection
|
||||||
|
*
|
||||||
|
* @param dbName The database name
|
||||||
|
*/
|
||||||
|
public MySQL(String host, int port, String dbName, String username, String password) {
|
||||||
|
this.dbName = dbName;
|
||||||
|
HikariConfig config = new HikariConfig();
|
||||||
|
config.setPoolName(ThemeParkPlugin.getInstance().getName());
|
||||||
|
config.setUsername(username);
|
||||||
|
config.setPassword(password);
|
||||||
|
config.setDriverClassName("com.mysql.jdbc.Driver");
|
||||||
|
config.setConnectionTestQuery("SELECT 1");
|
||||||
|
config.setMaximumPoolSize(1);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
try {
|
||||||
|
con = source.getConnection();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get connection
|
||||||
|
* @return Connection Instance
|
||||||
|
*/
|
||||||
|
public Connection getConnection() {
|
||||||
|
return con;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close connection
|
||||||
|
*/
|
||||||
|
public void closeConnection() {
|
||||||
|
System.out.println("Closing the database connection for " + dbName + ".db!");
|
||||||
|
try {
|
||||||
|
con.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
source.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
84
src/main/java/nl/iobyte/themepark/database/SQLite.java
Normal file
84
src/main/java/nl/iobyte/themepark/database/SQLite.java
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
package nl.iobyte.themepark.database;
|
||||||
|
|
||||||
|
import com.zaxxer.hikari.HikariConfig;
|
||||||
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
|
import nl.iobyte.themepark.ThemeParkPlugin;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class SQLite extends DB {
|
||||||
|
|
||||||
|
private String dbName;
|
||||||
|
private HikariDataSource source;
|
||||||
|
private Connection con;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize a new connection
|
||||||
|
*
|
||||||
|
* @param dbName The database name
|
||||||
|
*/
|
||||||
|
public SQLite(String dbName) {
|
||||||
|
this.dbName = dbName;
|
||||||
|
|
||||||
|
File dbFile = new File(ThemeParkPlugin.getInstance().getDataFolder(), dbName + ".db");
|
||||||
|
if (!dbFile.exists()) {
|
||||||
|
try {
|
||||||
|
System.out.println("Generating the " + dbName + ".db!");
|
||||||
|
if (!dbFile.createNewFile()) {
|
||||||
|
System.out.println("Couldn't generate the " + dbName + ".db!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Couldn't generate the " + dbName + ".db!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HikariConfig config = new HikariConfig();
|
||||||
|
config.setPoolName(ThemeParkPlugin.getInstance().getName());
|
||||||
|
config.setUsername(null);
|
||||||
|
config.setPassword(null);
|
||||||
|
config.setDriverClassName("org.sqlite.JDBC");
|
||||||
|
config.setConnectionTestQuery("SELECT 1");
|
||||||
|
config.setMaximumPoolSize(1);
|
||||||
|
|
||||||
|
Properties prop = new Properties();
|
||||||
|
prop.setProperty("date_string_format", "yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
|
config.setJdbcUrl("jdbc:sqlite:" + dbFile.getAbsolutePath());
|
||||||
|
config.setDataSourceProperties(prop);
|
||||||
|
source = new HikariDataSource(config);
|
||||||
|
|
||||||
|
try {
|
||||||
|
con = source.getConnection();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get connection
|
||||||
|
* @return Connection Instance
|
||||||
|
*/
|
||||||
|
public Connection getConnection() {
|
||||||
|
return con;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close connection
|
||||||
|
*/
|
||||||
|
public void closeConnection() {
|
||||||
|
System.out.println("Closing the database connection for " + dbName + ".db!");
|
||||||
|
try {
|
||||||
|
con.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
source.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,118 @@
|
||||||
|
package nl.iobyte.themepark.listener;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
|
import net.md_5.bungee.api.chat.HoverEvent;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import nl.iobyte.themepark.ThemeParkPlugin;
|
||||||
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
|
import nl.iobyte.themepark.api.events.attraction.ChangeLocationEvent;
|
||||||
|
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.config.YamlConfig;
|
||||||
|
import nl.iobyte.themepark.database.DB;
|
||||||
|
import nl.iobyte.themepark.database.DBManager;
|
||||||
|
import nl.iobyte.themepark.menu.AttractionLoader;
|
||||||
|
import nl.iobyte.themepark.menu.AttractionMenu;
|
||||||
|
import nl.iobyte.themepark.util.Color;
|
||||||
|
import nl.iobyte.themepark.util.MessageUtil;
|
||||||
|
import nl.iobyte.workchain.components.Work;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class AttractionListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onChange(ChangeStatusEvent e) {
|
||||||
|
AttractionMenu.updateAttraction(e.getAttraction());
|
||||||
|
|
||||||
|
Attraction attraction = e.getAttraction();
|
||||||
|
YamlConfig config = AttractionLoader.getConfig(attraction.getRegionId());
|
||||||
|
config.getConfig().set("attractions." + attraction.getId() + ".status", e.getAfter().toString());
|
||||||
|
config.save();
|
||||||
|
|
||||||
|
Work.firstTask(() -> DBManager.getDatabase("public")).abortIfNull().lastTask(database -> {
|
||||||
|
HashMap<Integer, Object> obj = new HashMap<>();
|
||||||
|
obj.put(1, e.getAfter().toString());
|
||||||
|
obj.put(2, attraction.getId());
|
||||||
|
|
||||||
|
String query ="UPDATE attraction SET status=? WHERE id=?";
|
||||||
|
database.execute(query, obj);
|
||||||
|
}).execute();
|
||||||
|
|
||||||
|
String command = ThemeParkPlugin.getInstance().getSettings().getConfig().getString("command");
|
||||||
|
if(command == null || command.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
HashMap<String, String> change = new HashMap<>();
|
||||||
|
change.put("{name}", attraction.getName());
|
||||||
|
ClickEvent click = new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/"+command+" warp "+attraction.getId());
|
||||||
|
HoverEvent hover = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Color.color(ThemeParkPlugin.getInstance().getMessages().getConfig().getString("attraction.changed.hover"))));
|
||||||
|
if(hover.getValue()[0].toPlainText().isEmpty())
|
||||||
|
hover = null;
|
||||||
|
|
||||||
|
BaseComponent message = MessageUtil.parseTP("attraction.changed."+e.getAfter().toString(), change, click, hover);
|
||||||
|
if(message == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for(Player player : Bukkit.getOnlinePlayers())
|
||||||
|
player.spigot().sendMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onChange(ChangeTypeEvent e) {
|
||||||
|
AttractionMenu.updateAttraction(e.getAttraction());
|
||||||
|
|
||||||
|
Attraction attraction = e.getAttraction();
|
||||||
|
YamlConfig config = AttractionLoader.getConfig(attraction.getRegionId());
|
||||||
|
config.getConfig().set("attractions." + attraction.getId() + ".type", e.getAfter().toString());
|
||||||
|
config.save();
|
||||||
|
|
||||||
|
Work.firstTask(() -> DBManager.getDatabase("public")).abortIfNull().lastTask(database -> {
|
||||||
|
HashMap<Integer, Object> obj = new HashMap<>();
|
||||||
|
obj.put(1, e.getAfter().toString());
|
||||||
|
obj.put(2, attraction.getStatus().toString());
|
||||||
|
obj.put(3, attraction.getId());
|
||||||
|
|
||||||
|
String query ="UPDATE attraction SET type=?, status=? WHERE id=?";
|
||||||
|
database.execute(query, obj);
|
||||||
|
}).execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onChange(ChangeNameEvent e) {
|
||||||
|
AttractionMenu.updateAttraction(e.getAttraction());
|
||||||
|
|
||||||
|
Attraction attraction = e.getAttraction();
|
||||||
|
YamlConfig config = AttractionLoader.getConfig(attraction.getRegionId());
|
||||||
|
config.getConfig().set("attractions." + attraction.getId() + ".name", e.getAfter());
|
||||||
|
config.save();
|
||||||
|
|
||||||
|
Work.firstTask(() -> DBManager.getDatabase("public")).abortIfNull().lastTask(database -> {
|
||||||
|
HashMap<Integer, Object> obj = new HashMap<>();
|
||||||
|
obj.put(1, e.getAfter());
|
||||||
|
obj.put(2, attraction.getId());
|
||||||
|
|
||||||
|
String query ="UPDATE attraction SET name=? WHERE id=?";
|
||||||
|
database.execute(query, obj);
|
||||||
|
}).execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onChange(ChangeLocationEvent e) {
|
||||||
|
Attraction attraction = e.getAttraction();
|
||||||
|
YamlConfig config = AttractionLoader.getConfig(attraction.getRegionId());
|
||||||
|
config.getConfig().set("attractions." + attraction.getId() + ".location", LocationSerializer.toString(e.getAfter()));
|
||||||
|
config.save();
|
||||||
|
|
||||||
|
//TODO MapMarker.getMarker().setAttractionMarker(attraction);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
190
src/main/java/nl/iobyte/themepark/listener/PlayerListener.java
Normal file
190
src/main/java/nl/iobyte/themepark/listener/PlayerListener.java
Normal file
|
@ -0,0 +1,190 @@
|
||||||
|
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.events.ridecount.ChangeCountEvent;
|
||||||
|
import nl.iobyte.themepark.api.ridecount.CountManager;
|
||||||
|
import nl.iobyte.themepark.api.utils.ItemBuilder;
|
||||||
|
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.util.Color;
|
||||||
|
import nl.iobyte.themepark.util.MessageUtil;
|
||||||
|
import nl.iobyte.workchain.components.Work;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
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.player.PlayerChangedWorldEvent;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
public class PlayerListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onJoin(PlayerJoinEvent e) {
|
||||||
|
Player player = e.getPlayer();
|
||||||
|
UUID uuid = player.getUniqueId();
|
||||||
|
|
||||||
|
doItem(e.getPlayer());
|
||||||
|
loadRideCount(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onSwitch(PlayerChangedWorldEvent e) {
|
||||||
|
doItem(e.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void doItem(Player player) {
|
||||||
|
YamlConfig settings = ThemeParkPlugin.getInstance().getSettings();
|
||||||
|
YamlConfig config = ThemeParkPlugin.getInstance().getData();
|
||||||
|
|
||||||
|
CompletableFuture<ItemStack> fc = new CompletableFuture<>();
|
||||||
|
Work.firstTask(() -> {
|
||||||
|
if(!settings.getConfig().getBoolean("item.enabled"))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
boolean b = true;
|
||||||
|
if (config.getConfig().contains(player.getUniqueId().toString() + ".item")) {
|
||||||
|
b = config.getConfig().getBoolean(player.getUniqueId().toString() + ".item");
|
||||||
|
} else {
|
||||||
|
config.getConfig().set(player.getUniqueId().toString() + ".item", true);
|
||||||
|
config.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
return b;
|
||||||
|
}).abortIfNull(() -> {
|
||||||
|
fc.complete(null);
|
||||||
|
}).nextTask(b -> {
|
||||||
|
if(!b)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
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())
|
||||||
|
return null;
|
||||||
|
|
||||||
|
ItemBuilder builder = new ItemBuilder(material, 1, data);
|
||||||
|
builder.setName(name);
|
||||||
|
return builder.getItem();
|
||||||
|
}).abortIfNull(() -> {
|
||||||
|
fc.complete(null);
|
||||||
|
}).lastTask(item -> {
|
||||||
|
if(settings.getConfig().getBoolean("item.clear"))
|
||||||
|
player.getInventory().clear();
|
||||||
|
|
||||||
|
List<String> worlds = settings.getConfig().getStringList("item.worlds");
|
||||||
|
if(worlds != null && !worlds.isEmpty()) {
|
||||||
|
if (worlds.contains(player.getLocation().getWorld().getName())) {
|
||||||
|
fc.complete(new ItemStack(Material.AIR));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fc.complete(item);
|
||||||
|
}).setFullExecute(true).execute();
|
||||||
|
|
||||||
|
fc.thenAccept(item -> {
|
||||||
|
if(item == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int slot = settings.getConfig().getInt("item.slot");
|
||||||
|
player.getInventory().setItem(slot, item);
|
||||||
|
player.updateInventory();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onInteract(PlayerInteractEvent e) {
|
||||||
|
YamlConfig config = ThemeParkPlugin.getInstance().getSettings();
|
||||||
|
Material material = Material.getMaterial(config.getConfig().getString("item.material"));
|
||||||
|
String name = Color.color(config.getConfig().getString("item.display-name"));
|
||||||
|
if(e.getItem() == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ItemStack item = e.getItem();
|
||||||
|
if(item.getType() != material)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(!item.hasItemMeta())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(!item.getItemMeta().getDisplayName().equals(name))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(e.getAction() == Action.LEFT_CLICK_AIR ||
|
||||||
|
e.getAction() == Action.LEFT_CLICK_BLOCK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
e.setCancelled(true);
|
||||||
|
Player player = e.getPlayer();
|
||||||
|
AttractionMenu.open(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onQuit(PlayerQuitEvent e) {
|
||||||
|
Player player = e.getPlayer();
|
||||||
|
UUID uuid = player.getUniqueId();
|
||||||
|
|
||||||
|
CountManager.removeCount(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadRideCount(UUID uuid) {
|
||||||
|
Work.firstTask(() -> {
|
||||||
|
DB db = DBManager.getDatabase("data");
|
||||||
|
if(db == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
Connection connection = db.getConnection();
|
||||||
|
if(connection == null || connection.isClosed())
|
||||||
|
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
|
||||||
|
public void onChange(ChangeCountEvent e) {
|
||||||
|
Player player = Bukkit.getPlayer(e.getUUID());
|
||||||
|
if(player == null || !player.isOnline())
|
||||||
|
return;
|
||||||
|
|
||||||
|
Attraction attraction = e.getAttraction();
|
||||||
|
int amount = e.getAfter() - e.getBefore();
|
||||||
|
String message = MessageUtil.getMessage("ridecount.message");
|
||||||
|
message = message.replace("{name}", attraction.getName());
|
||||||
|
message = message.replace("{amount}", Integer.toString(amount));
|
||||||
|
message = message.replace("{total}", Integer.toString(e.getCounter().getCount(e.getUUID()).getCount()));
|
||||||
|
player.sendMessage(Color.color(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
package nl.iobyte.themepark.listener;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.ThemeParkPlugin;
|
||||||
|
import nl.iobyte.themepark.api.attraction.Region;
|
||||||
|
import nl.iobyte.themepark.api.events.region.ChangeDataEvent;
|
||||||
|
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.database.DBManager;
|
||||||
|
import nl.iobyte.themepark.menu.AttractionMenu;
|
||||||
|
import nl.iobyte.workchain.components.Work;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class RegionListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onChange(ChangeNameEvent e) {
|
||||||
|
AttractionMenu.updateRegion(e.getRegion());
|
||||||
|
|
||||||
|
Region region = e.getRegion();
|
||||||
|
YamlConfig config = ThemeParkPlugin.getInstance().getRegions();
|
||||||
|
config.getConfig().set("regions." + region.getId() + ".name", e.getAfter());
|
||||||
|
config.save();
|
||||||
|
|
||||||
|
Work.firstTask(() -> DBManager.getDatabase("public")).abortIfNull().lastTask(database -> {
|
||||||
|
HashMap<Integer, Object> obj = new HashMap<>();
|
||||||
|
obj.put(1, e.getAfter());
|
||||||
|
obj.put(2, region.getId());
|
||||||
|
|
||||||
|
String query ="UPDATE region SET name=? WHERE id=?";
|
||||||
|
database.execute(query, obj);
|
||||||
|
}).execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onChange(ChangeLoreEvent e) {
|
||||||
|
AttractionMenu.updateRegion(e.getRegion());
|
||||||
|
|
||||||
|
Region region = e.getRegion();
|
||||||
|
YamlConfig config = ThemeParkPlugin.getInstance().getRegions();
|
||||||
|
config.getConfig().set("regions." + region.getId() + ".lore", e.getAfter());
|
||||||
|
config.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onChange(ChangeMaterialEvent e) {
|
||||||
|
AttractionMenu.updateRegion(e.getRegion());
|
||||||
|
|
||||||
|
Region region = e.getRegion();
|
||||||
|
YamlConfig config = ThemeParkPlugin.getInstance().getRegions();
|
||||||
|
config.getConfig().set("regions." + region.getId() + ".material", e.getAfter().toString());
|
||||||
|
config.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onChange(ChangeDataEvent e) {
|
||||||
|
AttractionMenu.updateRegion(e.getRegion());
|
||||||
|
|
||||||
|
Region region = e.getRegion();
|
||||||
|
YamlConfig config = ThemeParkPlugin.getInstance().getRegions();
|
||||||
|
config.getConfig().set("regions." + region.getId() + ".data", e.getAfter());
|
||||||
|
config.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
240
src/main/java/nl/iobyte/themepark/menu/AttractionLoader.java
Normal file
240
src/main/java/nl/iobyte/themepark/menu/AttractionLoader.java
Normal file
|
@ -0,0 +1,240 @@
|
||||||
|
package nl.iobyte.themepark.menu;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.ThemeParkPlugin;
|
||||||
|
import nl.iobyte.themepark.api.API;
|
||||||
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
|
import nl.iobyte.themepark.api.attraction.Region;
|
||||||
|
import nl.iobyte.themepark.api.attraction.component.Status;
|
||||||
|
import nl.iobyte.themepark.api.attraction.component.Type;
|
||||||
|
import nl.iobyte.themepark.api.attraction.manager.StatusManager;
|
||||||
|
import nl.iobyte.themepark.api.utils.LocationSerializer;
|
||||||
|
import nl.iobyte.themepark.config.YamlConfig;
|
||||||
|
import nl.iobyte.themepark.database.DB;
|
||||||
|
import nl.iobyte.themepark.database.DBManager;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class AttractionLoader {
|
||||||
|
|
||||||
|
private static HashMap<String, YamlConfig> configs = new HashMap<>();
|
||||||
|
|
||||||
|
public static YamlConfig getConfig(String id) {
|
||||||
|
if(id == null || id.isEmpty())
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return configs.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void load() {
|
||||||
|
loadRegions();
|
||||||
|
loadAttractions();
|
||||||
|
loadStatusData();
|
||||||
|
AttractionMenu.load();
|
||||||
|
loadDatabase();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void loadRegions() {
|
||||||
|
YamlConfig config = ThemeParkPlugin.getInstance().getRegions();
|
||||||
|
FileConfiguration fc = config.getConfig();
|
||||||
|
if(!fc.contains("regions"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
ConfigurationSection section = fc.getConfigurationSection("regions");
|
||||||
|
if(section == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for(String id : section.getKeys(false)) {
|
||||||
|
if(API.isRegion(id))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
String path = "regions."+id+".";
|
||||||
|
String name = fc.getString(path+"name");
|
||||||
|
List<String> lore = fc.getStringList(path+"lore");
|
||||||
|
if(fc.contains(path+"material")) {
|
||||||
|
Material material = Material.getMaterial(fc.getString(path + "material"));
|
||||||
|
short data = Short.parseShort(fc.getString(path + "data"));
|
||||||
|
Region region = new Region(id, name, lore, material, data);
|
||||||
|
API.addRegion(region);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Region region = new Region(id, name, lore);
|
||||||
|
API.addRegion(region);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static YamlConfig addRegion(String id) {
|
||||||
|
if(!API.isRegion(id))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
File root = new File(ThemeParkPlugin.getInstance().getDataFolder(), "attractions");
|
||||||
|
if(!root.exists())
|
||||||
|
if(!root.mkdirs())
|
||||||
|
return null;
|
||||||
|
|
||||||
|
YamlConfig config = new YamlConfig("attractions/"+id, ThemeParkPlugin.getInstance());
|
||||||
|
configs.put(id, config);
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void loadAttractions() {
|
||||||
|
File root = new File(ThemeParkPlugin.getInstance().getDataFolder(), "attractions");
|
||||||
|
if(!root.exists())
|
||||||
|
if(!root.mkdirs())
|
||||||
|
return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
for(Region region : API.getRegions().values()) {
|
||||||
|
YamlConfig config = new YamlConfig("attractions/"+region.getId(), ThemeParkPlugin.getInstance());
|
||||||
|
configs.put(region.getId(), config);
|
||||||
|
FileConfiguration fc = config.getConfig();
|
||||||
|
if(fc == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(!fc.contains("attractions")) {
|
||||||
|
fc.set("attractions", new ArrayList<>());
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), config::save);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigurationSection section = fc.getConfigurationSection("attractions");
|
||||||
|
if(section == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for(String id : section.getKeys(false)) {
|
||||||
|
if(API.isAttraction(id))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
String path = "attractions."+id+".";
|
||||||
|
String name = fc.getString(path+"name");
|
||||||
|
Type type = Type.getType(fc.getString(path+"type"));
|
||||||
|
if(type == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Status status = Status.getStatus(fc.getString(path+"status"));
|
||||||
|
if(!type.containsStatus(status)) {
|
||||||
|
status = type.getDefault();
|
||||||
|
fc.set(path+"status", status.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
Location location = LocationSerializer.toLocation(fc.getString(path+".location"));
|
||||||
|
Attraction attraction = new Attraction(id, name, region.getId(), location, type, status);
|
||||||
|
API.addAttraction(attraction);
|
||||||
|
}
|
||||||
|
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), config::save);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void loadStatusData() {
|
||||||
|
YamlConfig config = ThemeParkPlugin.getInstance().getSettings();
|
||||||
|
for(Status status : Status.values()) {
|
||||||
|
String name = "UNKNOWN";
|
||||||
|
if(config.getConfig().contains(status.toString() + ".name"))
|
||||||
|
name = config.getConfig().getString(status.toString() + ".name");
|
||||||
|
|
||||||
|
Material material = Material.STAINED_CLAY;
|
||||||
|
if(config.getConfig().contains(status.toString() + ".material")) {
|
||||||
|
material = Material.getMaterial(config.getConfig().getString(status.toString() + ".material"));
|
||||||
|
if(material == null)
|
||||||
|
material = Material.STAINED_CLAY;
|
||||||
|
}
|
||||||
|
|
||||||
|
short data = 0;
|
||||||
|
if(config.getConfig().contains(status.toString() + ".data")) {
|
||||||
|
String string = config.getConfig().getString(status.toString() + ".data");
|
||||||
|
if (!string.isEmpty())
|
||||||
|
data = Short.parseShort(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean teleport = false;
|
||||||
|
if(config.getConfig().contains(status.toString() + ".teleport"))
|
||||||
|
teleport = config.getConfig().getBoolean(status.toString() + ".teleport");
|
||||||
|
|
||||||
|
StatusManager.addStatus(status, name, material, data, teleport);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void loadDatabase() {
|
||||||
|
DB db = DBManager.getDatabase("public");
|
||||||
|
if(db == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
boolean b = false;
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
for(Region region : API.getRegions().values()) {
|
||||||
|
if(b) {
|
||||||
|
builder.append(",");
|
||||||
|
} else {
|
||||||
|
b = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
db.execute("INSERT INTO region(id, name) VALUES "+builder.toString()+" ON DUPLICATE KEY UPDATE name=VALUES(name)", obj);
|
||||||
|
b = false;
|
||||||
|
builder = new StringBuilder();
|
||||||
|
for(Attraction attraction : API.getAttractions().values()) {
|
||||||
|
if(b) {
|
||||||
|
builder.append(",");
|
||||||
|
} else {
|
||||||
|
b = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.append("(?, ?, ?, ?, ?)");
|
||||||
|
}
|
||||||
|
|
||||||
|
i = 1;
|
||||||
|
obj = new HashMap<>();
|
||||||
|
for(Attraction attraction : API.getAttractions().values()) {
|
||||||
|
obj.put(i++, attraction.getId());
|
||||||
|
obj.put(i++, attraction.getName());
|
||||||
|
obj.put(i++, attraction.getRegionId());
|
||||||
|
obj.put(i++, attraction.getType().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);
|
||||||
|
b = false;
|
||||||
|
builder = new StringBuilder();
|
||||||
|
for(Status status : Status.values()) {
|
||||||
|
if(b) {
|
||||||
|
builder.append(",");
|
||||||
|
} else {
|
||||||
|
b = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.append("(?, ?)");
|
||||||
|
}
|
||||||
|
|
||||||
|
i = 1;
|
||||||
|
obj = new HashMap<>();
|
||||||
|
for(Status status : Status.values()) {
|
||||||
|
obj.put(i++, status.toString());
|
||||||
|
obj.put(i++, StatusManager.getName(status));
|
||||||
|
}
|
||||||
|
|
||||||
|
db.execute("INSERT INTO status(statusId, statusName) VALUES "+builder.toString()+" ON DUPLICATE KEY UPDATE statusName=VALUES(statusName)", obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
173
src/main/java/nl/iobyte/themepark/menu/AttractionMenu.java
Normal file
173
src/main/java/nl/iobyte/themepark/menu/AttractionMenu.java
Normal file
|
@ -0,0 +1,173 @@
|
||||||
|
package nl.iobyte.themepark.menu;
|
||||||
|
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import nl.iobyte.menuapi.components.Types;
|
||||||
|
import nl.iobyte.menuapi.item.MenuItem;
|
||||||
|
import nl.iobyte.menuapi.multi.MenuPage;
|
||||||
|
import nl.iobyte.menuapi.multi.MultiMenu;
|
||||||
|
import nl.iobyte.themepark.ThemeParkPlugin;
|
||||||
|
import nl.iobyte.themepark.api.API;
|
||||||
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
|
import nl.iobyte.themepark.api.attraction.Region;
|
||||||
|
import nl.iobyte.themepark.api.attraction.manager.StatusManager;
|
||||||
|
import nl.iobyte.themepark.api.utils.ItemBuilder;
|
||||||
|
import nl.iobyte.themepark.menu.actions.PageAction;
|
||||||
|
import nl.iobyte.themepark.menu.actions.TPAction;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class AttractionMenu {
|
||||||
|
|
||||||
|
private static MultiMenu menu;
|
||||||
|
private static HashMap<String, Integer> reg_slots = new HashMap<>();
|
||||||
|
private static HashMap<String, Integer> att_slots = new HashMap<>();
|
||||||
|
|
||||||
|
public static void load() {
|
||||||
|
LinkedHashMap<Integer, Region> regions = new LinkedHashMap<>();
|
||||||
|
LinkedHashMap<Integer, List<Attraction>> attractions = new LinkedHashMap<>();
|
||||||
|
for(Region region : API.getRegions().values()) {
|
||||||
|
if(region.getAttractions().isEmpty()) {
|
||||||
|
regions.put(regions.size(), region);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterable<List<Attraction>> iterable = Iterables.partition(region.getAttractions().values(), 8);
|
||||||
|
for(List<Attraction> list : iterable) {
|
||||||
|
regions.put(regions.size(), region);
|
||||||
|
attractions.put(attractions.size(), list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int region_size = regions.size();
|
||||||
|
loadMenu(region_size);
|
||||||
|
for(int i = 0; i < region_size; i++) {
|
||||||
|
int start_index = i * 9;
|
||||||
|
if(region_size > 6)
|
||||||
|
start_index += (i / 5) * 9;
|
||||||
|
|
||||||
|
int j = 1;
|
||||||
|
List<Attraction> list = attractions.get(i);
|
||||||
|
Region region = regions.get(i);
|
||||||
|
if(region == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
reg_slots.put(region.getId(), start_index);
|
||||||
|
menu.setItem(start_index, new MenuItem(getRegion(region), true));
|
||||||
|
if(list == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for(Attraction attraction : list) {
|
||||||
|
MenuItem item = new MenuItem(getAttraction(attraction), true);
|
||||||
|
item.addActions(Types.NORMAL.getTypesList(), new TPAction(attraction));
|
||||||
|
|
||||||
|
int slot = start_index + j;
|
||||||
|
att_slots.put(attraction.getId(), slot);
|
||||||
|
menu.setItem(slot, item);
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(region_size > 6) {
|
||||||
|
int page_size = menu.getPageSizes().size();
|
||||||
|
for (int i = 0; i < page_size; i++) {
|
||||||
|
MenuPage page = menu.getPage(i + 1);
|
||||||
|
int size = page.getSize();
|
||||||
|
if (i > 0)
|
||||||
|
page.setItem(size - 6, getPrevious(i));
|
||||||
|
|
||||||
|
if (i < (page_size - 1))
|
||||||
|
page.setItem(size - 4, getNext(i));
|
||||||
|
|
||||||
|
ItemBuilder builder = new ItemBuilder(Material.MINECART);
|
||||||
|
builder.setName("&6Page: &f"+(i + 1));
|
||||||
|
page.setItem(size - 5, new MenuItem(builder.getItem(), true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
menu.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updateRegion(Region region) {
|
||||||
|
if(region == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(!reg_slots.containsKey(region.getId()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
int slot = reg_slots.get(region.getId());
|
||||||
|
menu.setItem(slot, getRegion(region));
|
||||||
|
menu.updateItem(slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updateAttraction(Attraction attraction) {
|
||||||
|
if(attraction == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(!att_slots.containsKey(attraction.getId()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
int slot = att_slots.get(attraction.getId());
|
||||||
|
menu.setItem(slot, getAttraction(attraction));
|
||||||
|
menu.updateItem(slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void open(Player player) {
|
||||||
|
open(player, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void open(Player player, int page) {
|
||||||
|
menu.open(player, page);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void loadMenu(int regions) {
|
||||||
|
ArrayList<Integer> page_sizes = new ArrayList<>();
|
||||||
|
if(regions <= 6) {
|
||||||
|
page_sizes.add(regions * 9);
|
||||||
|
} else {
|
||||||
|
int pages = regions / 5;
|
||||||
|
for (int i = 0; i < pages; i++)
|
||||||
|
page_sizes.add(54);
|
||||||
|
|
||||||
|
pages = regions % 5;
|
||||||
|
if (pages > 0)
|
||||||
|
page_sizes.add(pages * 9 + 9);
|
||||||
|
}
|
||||||
|
|
||||||
|
menu = new MultiMenu(ThemeParkPlugin.getInstance().getSettings().getConfig().getString("menu-title"), page_sizes);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ItemStack getRegion(Region region) {
|
||||||
|
ItemBuilder builder = new ItemBuilder(region.getMaterial(), 1, region.getData());
|
||||||
|
builder.setName(region.getName()).setLore(region.getLore());
|
||||||
|
return builder.getItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ItemStack getAttraction(Attraction attraction) {
|
||||||
|
ItemBuilder builder = new ItemBuilder(StatusManager.getMaterial(attraction.getStatus()), 1, StatusManager.getData(attraction.getStatus()));
|
||||||
|
builder.setName(attraction.getName()).setLore(StatusManager.getName(attraction.getStatus()));
|
||||||
|
return builder.getItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static MenuItem getNext(int page) {
|
||||||
|
return getPage("&6&LNext \u23F5", page + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static MenuItem getPrevious(int page) {
|
||||||
|
return getPage("&6&L\u23F4 Previous", page - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static MenuItem getPage(String text, int page) {
|
||||||
|
ItemBuilder builder = new ItemBuilder(Material.ARROW);
|
||||||
|
builder.setName(text);
|
||||||
|
|
||||||
|
MenuItem item = new MenuItem(builder.getItem(), true);
|
||||||
|
item.addActions(new PageAction(page + 1));
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package nl.iobyte.themepark.menu.actions;
|
||||||
|
|
||||||
|
import nl.iobyte.menuapi.action.MenuAction;
|
||||||
|
import nl.iobyte.themepark.menu.AttractionMenu;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class PageAction extends MenuAction {
|
||||||
|
|
||||||
|
private int page;
|
||||||
|
|
||||||
|
public PageAction(int page) {
|
||||||
|
this.page = page;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Player player) {
|
||||||
|
AttractionMenu.open(player, page);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
39
src/main/java/nl/iobyte/themepark/menu/actions/TPAction.java
Normal file
39
src/main/java/nl/iobyte/themepark/menu/actions/TPAction.java
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
package nl.iobyte.themepark.menu.actions;
|
||||||
|
|
||||||
|
import nl.iobyte.menuapi.action.MenuAction;
|
||||||
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
|
import nl.iobyte.themepark.api.attraction.manager.StatusManager;
|
||||||
|
import nl.iobyte.themepark.util.Color;
|
||||||
|
import nl.iobyte.themepark.util.MessageUtil;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class TPAction extends MenuAction {
|
||||||
|
|
||||||
|
private Attraction attraction;
|
||||||
|
|
||||||
|
public TPAction(Attraction attraction) {
|
||||||
|
this.attraction = attraction;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Player player) {
|
||||||
|
Location location = attraction.getLocation();
|
||||||
|
if(location == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
326
src/main/java/nl/iobyte/themepark/ridecount/RideCountAPI.java
Normal file
326
src/main/java/nl/iobyte/themepark/ridecount/RideCountAPI.java
Normal file
|
@ -0,0 +1,326 @@
|
||||||
|
package nl.iobyte.themepark.ridecount;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import nl.iobyte.menuapi.map.WeakConcurrentHashMap;
|
||||||
|
import nl.iobyte.themepark.ThemeParkPlugin;
|
||||||
|
import nl.iobyte.themepark.api.API;
|
||||||
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
|
import nl.iobyte.themepark.api.ridecount.AttractionCount;
|
||||||
|
import nl.iobyte.themepark.api.ridecount.CountManager;
|
||||||
|
import nl.iobyte.themepark.database.DB;
|
||||||
|
import nl.iobyte.themepark.database.DBManager;
|
||||||
|
import nl.iobyte.workchain.components.Work;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
public class RideCountAPI {
|
||||||
|
|
||||||
|
private static WeakConcurrentHashMap<String, String> data = new WeakConcurrentHashMap<>(5 * 60 * 1000);
|
||||||
|
|
||||||
|
public static CompletableFuture<Integer> getCount(String name, Attraction attraction) {
|
||||||
|
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 -> {
|
||||||
|
if(uuid == null) {
|
||||||
|
fc.complete(-1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
getCount(uuid, attraction).thenAccept(fc::complete);
|
||||||
|
});
|
||||||
|
return fc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CompletableFuture<Integer> getCount(UUID uuid, Attraction attraction) {
|
||||||
|
CompletableFuture<Integer> fc = new CompletableFuture<>();
|
||||||
|
if(uuid == null || attraction == null) {
|
||||||
|
fc.complete(-1);
|
||||||
|
return fc;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!API.isAttraction(attraction.getId())) {
|
||||||
|
fc.complete(-1);
|
||||||
|
return fc;
|
||||||
|
}
|
||||||
|
|
||||||
|
AttractionCount count = CountManager.getCounter(attraction.getId());
|
||||||
|
if(count != null && count.hasCount(uuid)) {
|
||||||
|
fc.complete(count.getCount(uuid).getCount());
|
||||||
|
return fc;
|
||||||
|
}
|
||||||
|
|
||||||
|
Work.firstTask(() -> {
|
||||||
|
DB db = DBManager.getDatabase("data");
|
||||||
|
if(db == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
Connection connection = db.getConnection();
|
||||||
|
if(connection == null || connection.isClosed())
|
||||||
|
return null;
|
||||||
|
|
||||||
|
PreparedStatement statement = connection.prepareStatement("SELECT points FROM counts WHERE uuid=? AND attraction_id=?");
|
||||||
|
statement.setString(1, uuid.toString());
|
||||||
|
statement.setString(2, attraction.getId());
|
||||||
|
statement.closeOnCompletion();
|
||||||
|
return statement.executeQuery();
|
||||||
|
}).abortIfNull(() -> fc.complete(-1)).nextTask(result -> {
|
||||||
|
int i = -1;
|
||||||
|
while(result.next()) {
|
||||||
|
int points = result.getInt("points");
|
||||||
|
if(points < 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
i = points;
|
||||||
|
}
|
||||||
|
|
||||||
|
result.close();
|
||||||
|
return i;
|
||||||
|
}).lastTask(fc::complete).setFullExecute(true).execute();
|
||||||
|
return fc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CompletableFuture<Boolean> addCount(String name, Attraction attraction, int amount) {
|
||||||
|
CompletableFuture<Boolean> fc = new CompletableFuture<>();
|
||||||
|
if(name == null || name.isEmpty() || attraction == null || amount < 0) {
|
||||||
|
fc.complete(false);
|
||||||
|
return fc;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!API.isAttraction(attraction.getId())) {
|
||||||
|
fc.complete(false);
|
||||||
|
return fc;
|
||||||
|
}
|
||||||
|
|
||||||
|
getData(name).thenAccept(uuid -> {
|
||||||
|
if(uuid == null) {
|
||||||
|
fc.complete(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
addCount(uuid, attraction, amount).thenAccept(fc::complete);
|
||||||
|
});
|
||||||
|
return fc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CompletableFuture<Boolean> addCount(UUID uuid, Attraction attraction, int amount) {
|
||||||
|
CompletableFuture<Boolean> fc = new CompletableFuture<>();
|
||||||
|
if(uuid == null || attraction == null || amount < 0) {
|
||||||
|
fc.complete(false);
|
||||||
|
return fc;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!API.isAttraction(attraction.getId())) {
|
||||||
|
fc.complete(false);
|
||||||
|
return fc;
|
||||||
|
}
|
||||||
|
|
||||||
|
AttractionCount count = CountManager.getCounter(attraction.getId());
|
||||||
|
if(count != null && count.hasCount(uuid))
|
||||||
|
Bukkit.getScheduler().runTask(ThemeParkPlugin.getInstance(), () -> count.addCount(uuid, amount));
|
||||||
|
|
||||||
|
Work.firstTask(() -> {
|
||||||
|
DB db = DBManager.getDatabase("data");
|
||||||
|
if(db == 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+?");
|
||||||
|
statement.setString(1, uuid.toString());
|
||||||
|
statement.setString(2, attraction.getId());
|
||||||
|
statement.setInt(3, amount);
|
||||||
|
statement.setInt(4, amount);
|
||||||
|
statement.closeOnCompletion();
|
||||||
|
return statement.executeUpdate() > 0;
|
||||||
|
}).abortIfNull(() -> fc.complete(false)).lastTask(fc::complete).setFullExecute(true).execute();
|
||||||
|
return fc;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static CompletableFuture<UUID> getData(String name) {
|
||||||
|
CompletableFuture<UUID> fc = new CompletableFuture<>();
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), () -> {
|
||||||
|
if(data.containsKey(name)) {
|
||||||
|
fc.complete(UUID.fromString(data.get(name)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = Bukkit.getPlayerExact(name);
|
||||||
|
if(player != null) {
|
||||||
|
UUID uuid = player.getUniqueId();
|
||||||
|
data.put(name, uuid.toString());
|
||||||
|
fc.complete(uuid);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
JsonObject object = sendGETRequestJSON("https://api.mojang.com/users/profiles/minecraft/" + name);
|
||||||
|
if(object == null) {
|
||||||
|
data.put(name, null);
|
||||||
|
fc.complete(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String id = object.get("id").getAsString();
|
||||||
|
if(id == null || id.isEmpty()) {
|
||||||
|
data.put(name, null);
|
||||||
|
fc.complete(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
id = fixUUID(id);
|
||||||
|
UUID uuid = UUID.fromString(id);
|
||||||
|
data.put(name, id);
|
||||||
|
fc.complete(uuid);
|
||||||
|
} catch (Exception e) {
|
||||||
|
data.put(name, null);
|
||||||
|
fc.complete(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return fc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CompletableFuture<HashMap<UUID, Integer>> getTop(Attraction attraction, boolean week) {
|
||||||
|
CompletableFuture<HashMap<UUID, Integer>> fc = new CompletableFuture<>();
|
||||||
|
if(attraction == null) {
|
||||||
|
fc.complete(null);
|
||||||
|
return fc;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!API.isAttraction(attraction.getId())) {
|
||||||
|
fc.complete(null);
|
||||||
|
return fc;
|
||||||
|
}
|
||||||
|
|
||||||
|
Work.firstTask(() -> {
|
||||||
|
DB db = DBManager.getDatabase("data");
|
||||||
|
if(db == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
Connection connection = db.getConnection();
|
||||||
|
if(connection == null || connection.isClosed())
|
||||||
|
return null;
|
||||||
|
|
||||||
|
String timeSort = week ? "YEARWEEK(created_at, 1)=YEARWEEK(CURDATE(), 1)" : "DAYOFYEAR(created_at)=DAYOFYEAR(CURDATE())";
|
||||||
|
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 -> {
|
||||||
|
HashMap<UUID, Integer> top = new HashMap<>();
|
||||||
|
while(result.next()) {
|
||||||
|
UUID uuid = UUID.fromString(result.getString("uuid"));
|
||||||
|
int points = result.getInt("points");
|
||||||
|
if(points < 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
top.put(uuid, points);
|
||||||
|
}
|
||||||
|
|
||||||
|
result.close();
|
||||||
|
return top;
|
||||||
|
}).lastTask(fc::complete).setFullExecute(true).execute();
|
||||||
|
return fc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CompletableFuture<HashMap<UUID, Integer>> getTopTotal(Attraction attraction) {
|
||||||
|
CompletableFuture<HashMap<UUID, Integer>> fc = new CompletableFuture<>();
|
||||||
|
if(attraction == null) {
|
||||||
|
fc.complete(null);
|
||||||
|
return fc;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!API.isAttraction(attraction.getId())) {
|
||||||
|
fc.complete(null);
|
||||||
|
return fc;
|
||||||
|
}
|
||||||
|
|
||||||
|
Work.firstTask(() -> {
|
||||||
|
DB db = DBManager.getDatabase("data");
|
||||||
|
if(db == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
Connection connection = db.getConnection();
|
||||||
|
if(connection == null || connection.isClosed())
|
||||||
|
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");
|
||||||
|
statement.setString(1, attraction.getId());
|
||||||
|
statement.closeOnCompletion();
|
||||||
|
return statement.executeQuery();
|
||||||
|
}).abortIfNull(() -> fc.complete(null)).nextTask(result -> {
|
||||||
|
HashMap<UUID, Integer> top = new HashMap<>();
|
||||||
|
while(result.next()) {
|
||||||
|
UUID uuid = UUID.fromString(result.getString("uuid"));
|
||||||
|
int points = result.getInt("points");
|
||||||
|
if(points < 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
top.put(uuid, points);
|
||||||
|
}
|
||||||
|
|
||||||
|
result.close();
|
||||||
|
return top;
|
||||||
|
}).lastTask(fc::complete).setFullExecute(true).execute();
|
||||||
|
return fc;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String fixUUID(String uuid) {
|
||||||
|
if(uuid == null || uuid.isEmpty())
|
||||||
|
return null;
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder(uuid);
|
||||||
|
sb.insert(8, "-");
|
||||||
|
sb = new StringBuilder(sb.toString());
|
||||||
|
sb.insert(13, "-");
|
||||||
|
sb = new StringBuilder(sb.toString());
|
||||||
|
sb.insert(18, "-");
|
||||||
|
sb = new StringBuilder(sb.toString());
|
||||||
|
sb.insert(23, "-");
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static JsonObject sendGETRequestJSON(String uri) throws IOException {
|
||||||
|
URL url = new URL(uri);
|
||||||
|
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
||||||
|
con.setRequestMethod("GET");
|
||||||
|
con.setRequestProperty("User-Agent", "Mozilla/5.0");
|
||||||
|
int code = con.getResponseCode();
|
||||||
|
if (code == 404)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||||||
|
String inputLine;
|
||||||
|
StringBuilder response = new StringBuilder();
|
||||||
|
while ((inputLine = in.readLine()) != null)
|
||||||
|
response.append(inputLine);
|
||||||
|
|
||||||
|
in.close();
|
||||||
|
JsonParser parser = new JsonParser();
|
||||||
|
return parser.parse(response.toString()).getAsJsonObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
11
src/main/java/nl/iobyte/themepark/util/Color.java
Normal file
11
src/main/java/nl/iobyte/themepark/util/Color.java
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
package nl.iobyte.themepark.util;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
|
public class Color {
|
||||||
|
|
||||||
|
public static String color(String str) {
|
||||||
|
return ChatColor.translateAlternateColorCodes('&', str);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
82
src/main/java/nl/iobyte/themepark/util/MessageUtil.java
Normal file
82
src/main/java/nl/iobyte/themepark/util/MessageUtil.java
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
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.ClickEvent;
|
||||||
|
import net.md_5.bungee.api.chat.HoverEvent;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import nl.iobyte.themepark.ThemeParkPlugin;
|
||||||
|
import nl.iobyte.themepark.config.YamlConfig;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class MessageUtil {
|
||||||
|
|
||||||
|
private static YamlConfig config = ThemeParkPlugin.getInstance().getMessages();
|
||||||
|
|
||||||
|
public static boolean isMessage(String string) {
|
||||||
|
return config.getConfig().contains(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getMessage(String string) {
|
||||||
|
if(!isMessage(string))
|
||||||
|
return "";
|
||||||
|
|
||||||
|
String message = config.getConfig().getString(string);
|
||||||
|
if(isMessage("prefix"))
|
||||||
|
message = message.replace("{prefix}", config.getConfig().getString("prefix"));
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BaseComponent parseTP(String string, HashMap<String, String> change, ClickEvent click, HoverEvent hover) {
|
||||||
|
String message = getMessage(string);
|
||||||
|
for(Map.Entry<String, String> entrySet : change.entrySet())
|
||||||
|
message = message.replace(entrySet.getKey(), entrySet.getValue());
|
||||||
|
|
||||||
|
message = Color.color(message);
|
||||||
|
if(click != null) {
|
||||||
|
String regex = "(.*)\\[TP\\](.*?)\\[/TP\\](.*)";
|
||||||
|
Pattern p = Pattern.compile(regex);
|
||||||
|
Matcher m = p.matcher(message);
|
||||||
|
while (m.find()) {
|
||||||
|
String first = m.group(1);
|
||||||
|
String middle = m.group(2);
|
||||||
|
String last = m.group(3);
|
||||||
|
|
||||||
|
BaseComponent[] components = TextComponent.fromLegacyText(first);
|
||||||
|
BaseComponent component = components[0];
|
||||||
|
for(int i = 1; i < components.length; i++)
|
||||||
|
component.addExtra(components[i]);
|
||||||
|
|
||||||
|
components = TextComponent.fromLegacyText(middle);
|
||||||
|
BaseComponent compClick = components[0];
|
||||||
|
for(int i = 1; i < components.length; i++)
|
||||||
|
compClick.addExtra(components[i]);
|
||||||
|
|
||||||
|
compClick.setClickEvent(click);
|
||||||
|
if(hover != null)
|
||||||
|
compClick.setHoverEvent(hover);
|
||||||
|
|
||||||
|
component.addExtra(compClick);
|
||||||
|
components = TextComponent.fromLegacyText(last);
|
||||||
|
BaseComponent compLast = components[0];
|
||||||
|
for (BaseComponent baseComponent : components) component.addExtra(baseComponent);
|
||||||
|
|
||||||
|
component.addExtra(compLast);
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseComponent[] components = TextComponent.fromLegacyText(message);
|
||||||
|
BaseComponent component = components[0];
|
||||||
|
for(int i = 1; i < components.length; i++)
|
||||||
|
component.addExtra(components[i]);
|
||||||
|
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,40 +0,0 @@
|
||||||
region:
|
|
||||||
global:
|
|
||||||
name: "&5Global"
|
|
||||||
lore:
|
|
||||||
- "&5Global Locations"
|
|
||||||
fantasy:
|
|
||||||
name: "&aFantasy"
|
|
||||||
lore:
|
|
||||||
- "&aFantasy Themed rides"
|
|
||||||
multiple:
|
|
||||||
name: "&fMultiple"
|
|
||||||
lore:
|
|
||||||
- "&fYou can have"
|
|
||||||
- "&fMultiple lines"
|
|
||||||
- "&fWith Lore"
|
|
||||||
|
|
||||||
attraction:
|
|
||||||
ride1:
|
|
||||||
name: "&aRide #1"
|
|
||||||
region_id: "fantasy"
|
|
||||||
type: RIDE
|
|
||||||
status: CLOSED
|
|
||||||
location: "world:0:0:0"
|
|
||||||
show1:
|
|
||||||
name: "&aFirst Show"
|
|
||||||
region_id: "fantasy"
|
|
||||||
type: SHOW
|
|
||||||
status: INACTIVE
|
|
||||||
location: "world:0:0:0"
|
|
||||||
global1:
|
|
||||||
name: "&aFirst Global"
|
|
||||||
region_id: "global"
|
|
||||||
type: GLOBAL
|
|
||||||
location: "world:0:0:0"
|
|
||||||
random:
|
|
||||||
name: "&fRandom"
|
|
||||||
type: RIDE
|
|
||||||
status: CLOSED
|
|
||||||
region_id: multiple
|
|
||||||
location: "world:0:0:0"
|
|
|
@ -1,42 +0,0 @@
|
||||||
prefix: "&6Themepark&f:"
|
|
||||||
|
|
||||||
onlyplayers: "{prefix} &4Only players can use this command"
|
|
||||||
nopermission: "{prefix} &4You don't have permission to use this command"
|
|
||||||
noplayer: "{prefix} &4No player found with name: {name}"
|
|
||||||
nonumber: "&6Themepark&f: &4{number} &4is not a valid number"
|
|
||||||
|
|
||||||
reloaded: "{prefix} &aThe plugin has been reloaded"
|
|
||||||
|
|
||||||
menu:
|
|
||||||
item:
|
|
||||||
enabled: "&aENABLED"
|
|
||||||
disabled: "&4DISABLED"
|
|
||||||
toggle: "{prefix} &aMenu item has been {status}"
|
|
||||||
|
|
||||||
region:
|
|
||||||
not: "{prefix} &4There is no region with ID: {id}"
|
|
||||||
changed:
|
|
||||||
name: "{prefix} &aChanged the name tho: {name} &aFor region: {id}"
|
|
||||||
lore: "{prefix} &aChanged the lore with index &f{index} &ato: {lore} &afor region: &f{id}"
|
|
||||||
|
|
||||||
status:
|
|
||||||
not: "{prefix} &4There is no status named: {status}"
|
|
||||||
|
|
||||||
attraction:
|
|
||||||
notfound: "&4No attractions found"
|
|
||||||
list: "&6ID: &f{id} &6Name: &f{name} &6Region: &f{region} &6Status: &f{status}"
|
|
||||||
not: "{prefix} &4There is no attraction with ID: {id}"
|
|
||||||
nostatus: "{prefix} &4Attraction: {name} &4has no status named: {status}"
|
|
||||||
changed:
|
|
||||||
status:
|
|
||||||
CONSTRUCTION: "{prefix} &fAttraction: {name} &fis now &7Under Construction"
|
|
||||||
OPEN: "{prefix} &fAttraction: {name} &fhas been &aOpened"
|
|
||||||
CLOSED: "{prefix} &fAttraction: {name} &fhas been &4Closed"
|
|
||||||
MAINTENANCE: "{prefix} &fAttraction: {name} &fis now in &6Maintenance"
|
|
||||||
MALFUNCTION: "{prefix} &fAttraction: {name} &fhas been closed due to a &5Malfunction"
|
|
||||||
ACTIVE: "{prefix} &fShow: {name} &fis now &aActive"
|
|
||||||
INACTIVE: "{prefix} &fShow: {name} &fis now &4In Active"
|
|
||||||
location: "&6ThemePark&f: &aChanged locatation of attraction: {name} &ato your current location"
|
|
||||||
teleport:
|
|
||||||
status: "{prefix} &4It's not possible to teleport to {name} &4because it's {status}"
|
|
||||||
success: "{prefix} &ayou have been teleported to the attraction: {name}"
|
|
47
src/main/resources/messages.yml
Normal file
47
src/main/resources/messages.yml
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
prefix: "&6<hemePark&f:"
|
||||||
|
onlyplayers: "{prefix} &4Only players can use this command"
|
||||||
|
nopermission: "{prefix} &4You don't have permission to use this command"
|
||||||
|
noplayer: "{prefix} &4No player found with name: {name}"
|
||||||
|
nonumber: "&6Themepark&f: &4{number} &4is not a valid number"
|
||||||
|
|
||||||
|
menu-item:
|
||||||
|
enabled: "&aENABLED"
|
||||||
|
disabled: "&4DISABLED"
|
||||||
|
toggle: "{prefix} &aMenu item has been {status}"
|
||||||
|
|
||||||
|
no-type: "{prefix} &4There is no type named: {type}"
|
||||||
|
no-status: "{prefix} &4There is no status named: {status}"
|
||||||
|
|
||||||
|
region:
|
||||||
|
not: "{prefix} &4There is no region with ID: {id}"
|
||||||
|
create: "{prefix} &aSuccessfully created region with name: &r{name}"
|
||||||
|
exists: "{prefix} &4There already is a region with ID: {id}"
|
||||||
|
name: "{prefix} &aChanged name of region to: &r{name}"
|
||||||
|
|
||||||
|
ridecount:
|
||||||
|
count: "{prefix} &fplayer has a ridecount of: &6{count} &ffor attraction {name}"
|
||||||
|
set: "{prefix} &fChanged ridecount of player to: &6{count} &ffor attraction {name}"
|
||||||
|
add: "{prefix} &fAdded &6{count} &fto ridecount of player for attraction {name}"
|
||||||
|
message: "{prefix} &fYou have ridden the attraction {name} &6{amount}&Lx &r&ffor a total of &6{total}&Lx"
|
||||||
|
|
||||||
|
attraction:
|
||||||
|
exists: "{prefix} &4There already is a region with ID: {id}"
|
||||||
|
create: "{prefix} &aSuccessfully created attraction with name: &r{name}"
|
||||||
|
notfound: "&4No attractions found"
|
||||||
|
list: "&6ID: &f{id} &6Name: &f{name} &6Region: &f{region} &6Status: &f{status}"
|
||||||
|
not: "{prefix} &4There is no attraction with ID: {id}"
|
||||||
|
nostatus: "{prefix} &4Attraction: {name} &4has no status named: {status}"
|
||||||
|
changed:
|
||||||
|
hover: "&6Click to Warp"
|
||||||
|
CONSTRUCTION: "{prefix} &fAttraction: {name} &fis now &7Under Construction"
|
||||||
|
OPEN: "{prefix} &fAttraction: [TP]{name}[/TP] &fhas been &aOpened"
|
||||||
|
CLOSED: "{prefix} &fAttraction: {name} &fhas been &4Closed"
|
||||||
|
MAINTENANCE: "{prefix} &fAttraction: {name} &fis now in &6Maintenance"
|
||||||
|
MALFUNCTION: "{prefix} &fAttraction: {name} &fhas been closed due to a &5Malfunction"
|
||||||
|
ACTIVE: "{prefix} &fShow: {name} &fis now &aActive"
|
||||||
|
INACTIVE: "{prefix} &fShow: {name} &fis now &4In Active"
|
||||||
|
location: "{prefix} &aChanged locatation of attraction: {name} &ato your current location"
|
||||||
|
name: "{prefix} &aChanged name of attraction to: &r{name}"
|
||||||
|
teleport:
|
||||||
|
status: "{prefix} &4It's not possible to teleport to {name} &4because it's {status}"
|
||||||
|
success: "{prefix} &ayou have been teleported to the attraction: {name}"
|
|
@ -1,7 +1,9 @@
|
||||||
name: ThemePark
|
name: ThemePark
|
||||||
version: 1.4.1
|
version: 2.0
|
||||||
main: me.paradoxpixel.themepark.ThemeParkPlugin
|
main: nl.iobyte.themepark.ThemeParkPlugin
|
||||||
author: ParadoxPixel
|
author: IOByte
|
||||||
softdepend: [PlaceholderAPI,dynmap]
|
website: "https://www.iobyte.nl/"
|
||||||
|
softdepend: [dynmap,Multiverse-Core,MultiWorld]
|
||||||
commands:
|
commands:
|
||||||
status:
|
status:
|
||||||
|
ridecount:
|
12
src/main/resources/regions.yml
Normal file
12
src/main/resources/regions.yml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
regions:
|
||||||
|
region_1:
|
||||||
|
name: '&4First Region'
|
||||||
|
lore:
|
||||||
|
- '&fFirst line of Lore'
|
||||||
|
material: IRON_BLOCK
|
||||||
|
data: 0
|
||||||
|
region_2:
|
||||||
|
name: '&4Second Region'
|
||||||
|
lore:
|
||||||
|
- '&fFirst line of Lore'
|
||||||
|
- '&fSecond line of Lore'
|
|
@ -1,37 +1,27 @@
|
||||||
command: 'themepark'
|
command: 'tp'
|
||||||
|
workers: 2
|
||||||
sign:
|
menu-title: "&6StatusMenu"
|
||||||
name: "[ThemePark]"
|
|
||||||
title: "&f[&6ThemePark&f]"
|
|
||||||
|
|
||||||
menu:
|
|
||||||
title: "&6StatusMenu"
|
|
||||||
|
|
||||||
inventory:
|
|
||||||
clear: true
|
|
||||||
|
|
||||||
item:
|
item:
|
||||||
enabled: true
|
enabled: true
|
||||||
material: NETHER_STAR
|
material: 'NETHER_STAR'
|
||||||
display-name: 'Themepark'
|
data: 0
|
||||||
|
display-name: '&6Themepark'
|
||||||
slot: 4
|
slot: 4
|
||||||
|
clear: true
|
||||||
worlds:
|
worlds:
|
||||||
- world_nether
|
- world_nether
|
||||||
- world_the_end
|
- world_the_end
|
||||||
|
|
||||||
mysql:
|
mysql:
|
||||||
enabled: false
|
enabled: false
|
||||||
host: 'localhost'
|
host: "localhost"
|
||||||
port: 3306
|
port: 3306
|
||||||
database: 'database'
|
database: "themepark"
|
||||||
user: 'username'
|
user: "root"
|
||||||
password: 'password'
|
pass: ""
|
||||||
url: 'jdbc:mysql://%host%:%port%/%database%?useSSL=false'
|
url: 'jdbc:mysql://%host%:%port%/%database%?useSSL=false'
|
||||||
|
|
||||||
region:
|
|
||||||
material: NAME_TAG
|
|
||||||
data: 0
|
|
||||||
|
|
||||||
CONSTRUCTION:
|
CONSTRUCTION:
|
||||||
name: "&7Under Construction"
|
name: "&7Under Construction"
|
||||||
material: STAINED_CLAY
|
material: STAINED_CLAY
|
||||||
|
|
Reference in a new issue