Merge pull request #12 from stijnb1234/malfunction
Added Malfunction GUI back
This commit is contained in:
commit
044fb85668
15 changed files with 463 additions and 112 deletions
21
pom.xml
21
pom.xml
|
@ -55,6 +55,10 @@
|
||||||
<pattern>org.bstats</pattern>
|
<pattern>org.bstats</pattern>
|
||||||
<shadedPattern>nl.sbdeveloper.themeparkplus.libs.bstats</shadedPattern>
|
<shadedPattern>nl.sbdeveloper.themeparkplus.libs.bstats</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.samjakob.spigui</pattern>
|
||||||
|
<shadedPattern>nl.sbdeveloper.themeparkplus.libs.spigui</shadedPattern>
|
||||||
|
</relocation>
|
||||||
</relocations>
|
</relocations>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
|
@ -143,7 +147,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>de.tr7zw</groupId>
|
<groupId>de.tr7zw</groupId>
|
||||||
<artifactId>item-nbt-api</artifactId>
|
<artifactId>item-nbt-api</artifactId>
|
||||||
<version>2.6.0</version>
|
<version>2.7.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.MilkBowl</groupId>
|
<groupId>com.github.MilkBowl</groupId>
|
||||||
|
@ -172,5 +176,20 @@
|
||||||
<artifactId>worldguardwrapper</artifactId>
|
<artifactId>worldguardwrapper</artifactId>
|
||||||
<version>1.1.9-SNAPSHOT</version>
|
<version>1.1.9-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.samjakob</groupId>
|
||||||
|
<artifactId>SpiGUI</artifactId>
|
||||||
|
<version>v1.1</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>bukkit</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package nl.sbdeveloper.themeparkplus;
|
package nl.sbdeveloper.themeparkplus;
|
||||||
|
|
||||||
|
import com.samjakob.spigui.SpiGUI;
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
import nl.sbdeveloper.themeparkplus.commands.TPPCMD;
|
import nl.sbdeveloper.themeparkplus.commands.TPPCMD;
|
||||||
import nl.sbdeveloper.themeparkplus.commands.TPPTabComplete;
|
import nl.sbdeveloper.themeparkplus.commands.TPPTabComplete;
|
||||||
|
@ -7,6 +8,7 @@ import nl.sbdeveloper.themeparkplus.listeners.*;
|
||||||
import nl.sbdeveloper.themeparkplus.managers.DBManager;
|
import nl.sbdeveloper.themeparkplus.managers.DBManager;
|
||||||
import nl.sbdeveloper.themeparkplus.sbutils.UpdateManager;
|
import nl.sbdeveloper.themeparkplus.sbutils.UpdateManager;
|
||||||
import nl.sbdeveloper.themeparkplus.sbutils.YamlFile;
|
import nl.sbdeveloper.themeparkplus.sbutils.YamlFile;
|
||||||
|
import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
|
||||||
import nl.sbdeveloper.themeparkplus.util.License;
|
import nl.sbdeveloper.themeparkplus.util.License;
|
||||||
import org.bstats.bukkit.Metrics;
|
import org.bstats.bukkit.Metrics;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
@ -32,7 +34,11 @@ public final class ThemeParkPlus extends JavaPlugin {
|
||||||
private static Economy econ = null;
|
private static Economy econ = null;
|
||||||
private static String webhookURL;
|
private static String webhookURL;
|
||||||
|
|
||||||
private final int configVersion = 2;
|
private static SpiGUI spiGUI;
|
||||||
|
|
||||||
|
private final int configVersion = 3;
|
||||||
|
|
||||||
|
private static boolean hasTPHook = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
@ -72,47 +78,15 @@ public final class ThemeParkPlus extends JavaPlugin {
|
||||||
|
|
||||||
Bukkit.getLogger().info("[ThemeParkPlus] Checking license...");
|
Bukkit.getLogger().info("[ThemeParkPlus] Checking license...");
|
||||||
|
|
||||||
|
final String license = config.getFile().getString("License");
|
||||||
if (config.getFile().contains("License")) {
|
if (config.getFile().contains("License")) {
|
||||||
Bukkit.getLogger().info("[ThemeParkPlus] Licence code: " + config.getFile().getString("License"));
|
Bukkit.getLogger().info("[ThemeParkPlus] Licence code: " + license);
|
||||||
} else {
|
} else {
|
||||||
Bukkit.getLogger().severe("[ThemeParkPlus] Licence code unknown! Please change the config.yml!");
|
Bukkit.getLogger().severe("[ThemeParkPlus] Licence code unknown! Please change the config.yml!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
new License(this, "TP", config.getFile().getString("License"));
|
new License(this, "TP", license);
|
||||||
|
|
||||||
if (getSConfig().getFile().getBoolean("UpdateChecker.Enabled")) {
|
|
||||||
UpdateManager updateManager = new UpdateManager(this, 6, UpdateManager.CheckType.SBDPLUGINS);
|
|
||||||
|
|
||||||
updateManager.handleResponse((versionResponse, version) -> {
|
|
||||||
if (versionResponse == UpdateManager.VersionResponse.FOUND_NEW) {
|
|
||||||
Bukkit.getLogger().warning("[ThemeParkPlus] There is a new version available! Current: " + this.getDescription().getVersion() + " New: " + version.get());
|
|
||||||
if (getSConfig().getFile().getBoolean("UpdateChecker.DownloadOnUpdate")) {
|
|
||||||
Bukkit.getLogger().info("[ThemeParkPlus] Trying to download the update...");
|
|
||||||
|
|
||||||
updateManager.handleDownloadResponse((downloadResponse, fileName) -> {
|
|
||||||
if (downloadResponse == UpdateManager.DownloadResponse.DONE) {
|
|
||||||
Bukkit.getLogger().info("[ThemeParkPlus] Update downloaded! If you restart your server, it will be loaded. Filename: " + fileName);
|
|
||||||
} else if (downloadResponse == UpdateManager.DownloadResponse.ERROR) {
|
|
||||||
Bukkit.getLogger().severe("[ThemeParkPlus] Something went wrong when trying downloading the latest version.");
|
|
||||||
} else if (downloadResponse == UpdateManager.DownloadResponse.UNAVAILABLE) {
|
|
||||||
Bukkit.getLogger().warning("[ThemeParkPlus] Unable to download the latest version.");
|
|
||||||
}
|
|
||||||
}).runUpdate();
|
|
||||||
}
|
|
||||||
} else if (versionResponse == UpdateManager.VersionResponse.LATEST) {
|
|
||||||
Bukkit.getLogger().info("[ThemeParkPlus] You are running the latest version [" + this.getDescription().getVersion() + "]!");
|
|
||||||
} else if (versionResponse == UpdateManager.VersionResponse.UNAVAILABLE) {
|
|
||||||
Bukkit.getLogger().severe("[ThemeParkPlus] Unable to perform an update check.");
|
|
||||||
}
|
|
||||||
}).check();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Bukkit.getPluginManager().getPlugin("ThemePark") == null) {
|
|
||||||
Bukkit.getLogger().severe("[ThemeParkPlus] Missing ThemePark! Please install it first.");
|
|
||||||
getServer().getPluginManager().disablePlugin(this);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Bukkit.getPluginManager().getPlugin("WorldEdit") == null) {
|
if (Bukkit.getPluginManager().getPlugin("WorldEdit") == null) {
|
||||||
Bukkit.getLogger().severe("[ThemeParkPlus] Missing WorldEdit! Please install it first.");
|
Bukkit.getLogger().severe("[ThemeParkPlus] Missing WorldEdit! Please install it first.");
|
||||||
|
@ -138,13 +112,23 @@ public final class ThemeParkPlus extends JavaPlugin {
|
||||||
|
|
||||||
Bukkit.getLogger().info("[ThemeParkPlus] Loading listeners...");
|
Bukkit.getLogger().info("[ThemeParkPlus] Loading listeners...");
|
||||||
Bukkit.getPluginManager().registerEvents(new DirectionalGateListener(), this);
|
Bukkit.getPluginManager().registerEvents(new DirectionalGateListener(), this);
|
||||||
Bukkit.getPluginManager().registerEvents(new FastpassListeners(), this);
|
|
||||||
Bukkit.getPluginManager().registerEvents(new SignListeners(), this);
|
Bukkit.getPluginManager().registerEvents(new SignListeners(), this);
|
||||||
Bukkit.getPluginManager().registerEvents(new WaitingTimeListener(), this);
|
Bukkit.getPluginManager().registerEvents(new WaitingTimeListener(), this);
|
||||||
if (getSConfig().getFile().getBoolean("AntiFreerun.Enabled")) {
|
if (getSConfig().getFile().getBoolean("AntiFreerun.Enabled")) {
|
||||||
Bukkit.getPluginManager().registerEvents(new AntiFreerunListener(), this);
|
Bukkit.getPluginManager().registerEvents(new AntiFreerunListener(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Bukkit.getPluginManager().getPlugin("ThemePark") == null) {
|
||||||
|
Bukkit.getLogger().severe("[ThemeParkPlus] Missing ThemePark! Some functions will not work without it!");
|
||||||
|
} else {
|
||||||
|
Bukkit.getLogger().severe("[ThemeParkPlus] Enabling ThemePark hook...");
|
||||||
|
hasTPHook = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasTPHook) {
|
||||||
|
Bukkit.getPluginManager().registerEvents(new FastpassListeners(), this);
|
||||||
|
Bukkit.getPluginManager().registerEvents(new MalfunctionListener(), this);
|
||||||
|
|
||||||
if (getSConfig().getFile().getBoolean("DiscordWebhook.Enabled")) {
|
if (getSConfig().getFile().getBoolean("DiscordWebhook.Enabled")) {
|
||||||
String URL = getSConfig().getFile().getString("DiscordWebhook.WebhookURL");
|
String URL = getSConfig().getFile().getString("DiscordWebhook.WebhookURL");
|
||||||
if (URL != null) {
|
if (URL != null) {
|
||||||
|
@ -156,6 +140,11 @@ public final class ThemeParkPlus extends JavaPlugin {
|
||||||
Bukkit.getLogger().severe("[ThemeParkPlus] Couldn't load the webhook builder! The URL is null.");
|
Bukkit.getLogger().severe("[ThemeParkPlus] Couldn't load the webhook builder! The URL is null.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Bukkit.getLogger().info("[ThemeParkPlus] Loading GUI helper...");
|
||||||
|
spiGUI = new SpiGUI(this);
|
||||||
|
spiGUI.setEnableAutomaticPagination(false);
|
||||||
|
|
||||||
Bukkit.getLogger().info("[ThemeParkPlus] Loading data...");
|
Bukkit.getLogger().info("[ThemeParkPlus] Loading data...");
|
||||||
try {
|
try {
|
||||||
|
@ -168,14 +157,53 @@ public final class ThemeParkPlus extends JavaPlugin {
|
||||||
Bukkit.getLogger().info("[ThemeParkPlus] Loading metrics (can be disabled in the config of bStats)...");
|
Bukkit.getLogger().info("[ThemeParkPlus] Loading metrics (can be disabled in the config of bStats)...");
|
||||||
new Metrics(this, 5023);
|
new Metrics(this, 5023);
|
||||||
|
|
||||||
|
if (getSConfig().getFile().getBoolean("UpdateChecker.Enabled")) {
|
||||||
|
UpdateManager updateManager = new UpdateManager(this, 7, license);
|
||||||
|
|
||||||
|
updateManager.handleResponse((versionResponse, version) -> {
|
||||||
|
switch (versionResponse) {
|
||||||
|
case FOUND_NEW:
|
||||||
|
Bukkit.getLogger().warning("[ThemeParkPlus] There is a new version available! Current: " + this.getDescription().getVersion() + " New: " + version.get());
|
||||||
|
if (getSConfig().getFile().getBoolean("UpdateChecker.DownloadOnUpdate")) {
|
||||||
|
Bukkit.getLogger().info("[ThemeParkPlus] Trying to download the update. This could take some time...");
|
||||||
|
|
||||||
|
updateManager.handleDownloadResponse((downloadResponse, fileName) -> {
|
||||||
|
switch (downloadResponse) {
|
||||||
|
case DONE:
|
||||||
|
Bukkit.getLogger().info("[ThemeParkPlus] Update downloaded! If you restart your server, it will be loaded. Filename: " + fileName);
|
||||||
|
break;
|
||||||
|
case ERROR:
|
||||||
|
Bukkit.getLogger().severe("[ThemeParkPlus] Something went wrong when trying downloading the latest version.");
|
||||||
|
break;
|
||||||
|
case UNAVAILABLE:
|
||||||
|
Bukkit.getLogger().warning("[ThemeParkPlus] Unable to download the latest version.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}).runUpdate();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case LATEST:
|
||||||
|
Bukkit.getLogger().info("[ThemeParkPlus] You are running the latest version [" + this.getDescription().getVersion() + "]!");
|
||||||
|
break;
|
||||||
|
case THIS_NEWER:
|
||||||
|
Bukkit.getLogger().info("[ThemeParkPlus] You are running a newer version [" + this.getDescription().getVersion() + "]! This is probably fine.");
|
||||||
|
break;
|
||||||
|
case UNAVAILABLE:
|
||||||
|
Bukkit.getLogger().severe("[ThemeParkPlus] Unable to perform an update check.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}).check();
|
||||||
|
}
|
||||||
|
|
||||||
Bukkit.getLogger().info("[ThemeParkPlus] Plugin enabled!");
|
Bukkit.getLogger().info("[ThemeParkPlus] Plugin enabled!");
|
||||||
Bukkit.getLogger().info("[ThemeParkPlus] -------------------------------");
|
Bukkit.getLogger().info("[ThemeParkPlus] -------------------------------");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
Bukkit.getLogger().info("[ThemeParkPlus] Saving data to data file...");
|
Bukkit.getLogger().info("[ThemeParkPlus] Saving data...");
|
||||||
data.save();
|
data.save();
|
||||||
|
data.closeConnection();
|
||||||
|
|
||||||
Bukkit.getLogger().info("[ThemeParkPlus] Plugin disabled!");
|
Bukkit.getLogger().info("[ThemeParkPlus] Plugin disabled!");
|
||||||
instance = null;
|
instance = null;
|
||||||
|
@ -205,6 +233,14 @@ public final class ThemeParkPlus extends JavaPlugin {
|
||||||
return webhookURL;
|
return webhookURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static SpiGUI getSpiGUI() {
|
||||||
|
return spiGUI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean hasTPHook() {
|
||||||
|
return hasTPHook;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean setupEconomy() {
|
private boolean setupEconomy() {
|
||||||
if (getServer().getPluginManager().getPlugin("Vault") == null) {
|
if (getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package nl.sbdeveloper.themeparkplus.api;
|
package nl.sbdeveloper.themeparkplus.api;
|
||||||
|
|
||||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||||
import nl.iobyte.themepark.api.attraction.Attraction;
|
|
||||||
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
||||||
import nl.sbdeveloper.themeparkplus.api.objects.Gate;
|
import nl.sbdeveloper.themeparkplus.api.objects.Gate;
|
||||||
|
import nl.sbdeveloper.themeparkplus.api.objects.MalfunctionReport;
|
||||||
import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow;
|
import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow;
|
||||||
import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
|
import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
|
||||||
import nl.sbdeveloper.themeparkplus.util.XMaterial;
|
import nl.sbdeveloper.themeparkplus.util.XMaterial;
|
||||||
|
@ -18,8 +18,29 @@ import org.jetbrains.annotations.Nullable;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class PlusAPI {
|
public class PlusAPI {
|
||||||
private static HashMap<Location, Gate> gates = new HashMap<>();
|
private static final HashMap<Location, Gate> gates = new HashMap<>();
|
||||||
private static HashMap<String, WaitingRow> rows = new HashMap<>();
|
private static final HashMap<String, WaitingRow> rows = new HashMap<>();
|
||||||
|
private static final HashMap<String, MalfunctionReport> reports = new HashMap<>();
|
||||||
|
|
||||||
|
public static void addReport(MalfunctionReport report) {
|
||||||
|
reports.put(report.getRideID(), report);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeReport(String rideID) {
|
||||||
|
reports.remove(rideID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MalfunctionReport getReport(String rideID) {
|
||||||
|
return reports.get(rideID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isReported(String rideID) {
|
||||||
|
return reports.containsKey(rideID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HashMap<String, MalfunctionReport> getReports() {
|
||||||
|
return reports;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a gate
|
* Add a gate
|
||||||
|
@ -152,7 +173,7 @@ public class PlusAPI {
|
||||||
* @return The ticket as ItemStack
|
* @return The ticket as ItemStack
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static ItemStack getFastpassTicket(Attraction att) {
|
public static ItemStack getFastpassTicket(nl.iobyte.themepark.api.attraction.Attraction att) {
|
||||||
String ticketName = ConfigUtil.makecolored(ThemeParkPlus.getSConfig().getFile().getString("Fastpass.Item.DisplayName"));
|
String ticketName = ConfigUtil.makecolored(ThemeParkPlus.getSConfig().getFile().getString("Fastpass.Item.DisplayName"));
|
||||||
|
|
||||||
ItemStack ticket = XMaterial.PAPER.parseItem();
|
ItemStack ticket = XMaterial.PAPER.parseItem();
|
||||||
|
|
|
@ -1,18 +1,19 @@
|
||||||
package nl.sbdeveloper.themeparkplus.api.objects;
|
package nl.sbdeveloper.themeparkplus.api.objects;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.*;
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/** @deprecated Please don't use! It's not implemented yet. */
|
@Getter @NoArgsConstructor
|
||||||
@Getter @Setter @NoArgsConstructor @AllArgsConstructor
|
|
||||||
public class MalfunctionReport {
|
public class MalfunctionReport {
|
||||||
private String rideID;
|
@Getter private String rideID;
|
||||||
private UUID reporterUUID;
|
@Getter private UUID reporterUUID;
|
||||||
private LocalDateTime reportDate;
|
@Getter private final LocalDateTime reportDate = LocalDateTime.now();
|
||||||
private String reason;
|
@Getter @Setter private String reason = "Unknown";
|
||||||
|
|
||||||
|
public MalfunctionReport(String rideID, UUID reporterUUID) {
|
||||||
|
this.rideID = rideID;
|
||||||
|
this.reporterUUID = reporterUUID;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package nl.sbdeveloper.themeparkplus.commands;
|
package nl.sbdeveloper.themeparkplus.commands;
|
||||||
|
|
||||||
import nl.iobyte.themepark.api.API;
|
|
||||||
import nl.iobyte.themepark.api.attraction.Attraction;
|
|
||||||
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
||||||
import nl.sbdeveloper.themeparkplus.api.PlusAPI;
|
import nl.sbdeveloper.themeparkplus.api.PlusAPI;
|
||||||
import nl.sbdeveloper.themeparkplus.api.enums.WalkingDirection;
|
import nl.sbdeveloper.themeparkplus.api.enums.WalkingDirection;
|
||||||
|
@ -196,17 +194,22 @@ public class TPPCMD implements CommandExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean giveFPTicketCommand(CommandSender sender, String[] args) {
|
private boolean giveFPTicketCommand(CommandSender sender, String[] args) {
|
||||||
|
if (!ThemeParkPlus.hasTPHook()) {
|
||||||
|
sender.sendMessage(ConfigUtil.getMessage("General.RequiresThemePark"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (args.length == 2 && !(sender instanceof Player)) {
|
if (args.length == 2 && !(sender instanceof Player)) {
|
||||||
sender.sendMessage(ConfigUtil.getMessage("General.NoPlayer"));
|
sender.sendMessage(ConfigUtil.getMessage("General.NoPlayer"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!API.isAttraction(args[1])) {
|
if (!nl.iobyte.themepark.api.API.isAttraction(args[1])) {
|
||||||
sender.sendMessage(ConfigUtil.getMessage("Fastpass.UnknownRide", Collections.singletonMap("%ridename%", args[1])));
|
sender.sendMessage(ConfigUtil.getMessage("Fastpass.UnknownRide", Collections.singletonMap("%ridename%", args[1])));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Attraction att = API.getAttraction(args[1]);
|
nl.iobyte.themepark.api.attraction.Attraction att = nl.iobyte.themepark.api.API.getAttraction(args[1]);
|
||||||
|
|
||||||
Player target;
|
Player target;
|
||||||
if (args.length == 3) {
|
if (args.length == 3) {
|
||||||
|
@ -404,7 +407,7 @@ public class TPPCMD implements CommandExecutor {
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLaterAsynchronously(ThemeParkPlus.getInstance(), () -> cub.getBlocks().forEach(block -> {
|
Bukkit.getScheduler().runTaskLaterAsynchronously(ThemeParkPlus.getInstance(), () -> cub.getBlocks().forEach(block -> {
|
||||||
if (block.getType().name().contains("REDSTONE_LAMP")) Bukkit.getScheduler().runTask(ThemeParkPlus.getInstance(), () -> LGUtil.zetLampUit(block));
|
if (block.getType().name().contains("REDSTONE_LAMP")) Bukkit.getScheduler().runTask(ThemeParkPlus.getInstance(), () -> LGUtil.zetLampUit(block));
|
||||||
}), secOn * 20);
|
}), secOn * 20L);
|
||||||
if (ConfigUtil.sendConsole(sender)) sender.sendMessage(ConfigUtil.getMessage("Lamps.TurnedOnSec", Collections.singletonMap("%sec%", String.valueOf(secOn))));
|
if (ConfigUtil.sendConsole(sender)) sender.sendMessage(ConfigUtil.getMessage("Lamps.TurnedOnSec", Collections.singletonMap("%sec%", String.valueOf(secOn))));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -0,0 +1,102 @@
|
||||||
|
package nl.sbdeveloper.themeparkplus.gui;
|
||||||
|
|
||||||
|
import com.samjakob.spigui.SGMenu;
|
||||||
|
import com.samjakob.spigui.buttons.SGButton;
|
||||||
|
import com.samjakob.spigui.item.ItemBuilder;
|
||||||
|
import nl.iobyte.themepark.api.API;
|
||||||
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
|
import nl.iobyte.themepark.api.attraction.component.Status;
|
||||||
|
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
||||||
|
import nl.sbdeveloper.themeparkplus.api.PlusAPI;
|
||||||
|
import nl.sbdeveloper.themeparkplus.api.objects.MalfunctionReport;
|
||||||
|
import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
|
||||||
|
import nl.sbdeveloper.themeparkplus.util.XMaterial;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class MalfunctionGUI {
|
||||||
|
public static void open(Attraction att, Player p) {
|
||||||
|
SGMenu menu = ThemeParkPlus.getSpiGUI().create(ConfigUtil.makecolored(ThemeParkPlus.getSConfig().getFile().getString("Malfunction.GUI.Title").replace("%ridename%", att.getId())), 1);
|
||||||
|
|
||||||
|
SGButton report = new SGButton(getItem("Report", ConfigUtil.makecolored(att.getName()))).withListener((InventoryClickEvent e) -> {
|
||||||
|
if (!PlusAPI.isReported(att.getId())) {
|
||||||
|
MalfunctionReport malfunctionReport = new MalfunctionReport(att.getId(), p.getUniqueId());
|
||||||
|
PlusAPI.addReport(malfunctionReport);
|
||||||
|
att.setStatus(Status.MALFUNCTION, null); //Player must be null, otherwise we will get a loop in the listener
|
||||||
|
|
||||||
|
p.sendMessage(ConfigUtil.getMessage("Malfunction.Reported", Collections.singletonMap("%ride%", att.getName())));
|
||||||
|
} else {
|
||||||
|
p.sendMessage(ConfigUtil.getMessage("Malfunction.AlreadyReported", Collections.singletonMap("%ride%", att.getName())));
|
||||||
|
}
|
||||||
|
p.closeInventory();
|
||||||
|
});
|
||||||
|
menu.setButton(getSlot("Report"), report);
|
||||||
|
|
||||||
|
SGButton fix = new SGButton(getItem("Fix", PlusAPI.getReport(att.getId()))).withListener((InventoryClickEvent e) -> {
|
||||||
|
if (PlusAPI.isReported(att.getId())) {
|
||||||
|
|
||||||
|
PlusAPI.removeReport(att.getId());
|
||||||
|
att.setStatus(Status.CLOSED, null); //Player must be null, otherwise we will get a loop in the listener
|
||||||
|
|
||||||
|
p.sendMessage(ConfigUtil.getMessage("Malfunction.Fixed", Collections.singletonMap("%ride%", att.getName())));
|
||||||
|
} else {
|
||||||
|
p.sendMessage(ConfigUtil.getMessage("Malfunction.AlreadyFixed", Collections.singletonMap("%ride%", att.getName())));
|
||||||
|
}
|
||||||
|
p.closeInventory();
|
||||||
|
});
|
||||||
|
menu.setButton(getSlot("Fix"), fix);
|
||||||
|
|
||||||
|
SGButton cancel = new SGButton(getItem("Cancel")).withListener((InventoryClickEvent e) -> p.closeInventory());
|
||||||
|
menu.setButton(getSlot("Cancel"), cancel);
|
||||||
|
|
||||||
|
p.openInventory(menu.getInventory());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getSlot(String type) {
|
||||||
|
return ThemeParkPlus.getSConfig().getFile().getInt("Malfunction.GUI.Buttons." + type + ".Slot");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ItemStack getItem(String type, Object... data) { //data is a string or a report
|
||||||
|
String material = ThemeParkPlus.getSConfig().getFile().getString("Malfunction.GUI.Buttons." + type + ".Material");
|
||||||
|
String name = ThemeParkPlus.getSConfig().getFile().getString("Malfunction.GUI.Buttons." + type + ".Name");
|
||||||
|
List<String> lores = ThemeParkPlus.getSConfig().getFile().getStringList("Malfunction.GUI.Buttons." + type + ".Lores");
|
||||||
|
|
||||||
|
if (material == null || name == null || lores.isEmpty()) return null; //Something is wrong in the config
|
||||||
|
|
||||||
|
List<String> loresFormatted = new ArrayList<>();
|
||||||
|
switch (type) {
|
||||||
|
case "Report":
|
||||||
|
lores.forEach(lore -> loresFormatted.add(lore.replace("%ridename%", (String) data[0])));
|
||||||
|
break;
|
||||||
|
case "Fix":
|
||||||
|
String ridename = ConfigUtil.getMessage("Malfunction.ThisRide");
|
||||||
|
String reporter = "-";
|
||||||
|
String date = "-";
|
||||||
|
String reason = "-";
|
||||||
|
if (data[0] != null) {
|
||||||
|
ridename = API.getAttraction(((MalfunctionReport) data[0]).getRideID()).getName();
|
||||||
|
reporter = Bukkit.getOfflinePlayer(((MalfunctionReport) data[0]).getReporterUUID()).getName();
|
||||||
|
date = ((MalfunctionReport) data[0]).getReportDate().format(DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss"));
|
||||||
|
reason = ((MalfunctionReport) data[0]).getReason();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String lore : lores) {
|
||||||
|
loresFormatted.add(lore.replace("%ridename%", ridename).replace("%reporter%", reporter).replace("%date%", date).replace("%reason%", reason));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<XMaterial> stack = XMaterial.matchXMaterial(material);
|
||||||
|
return stack.map(xMaterial -> new ItemBuilder(xMaterial.parseItem()).name(name).lore(loresFormatted).build()).orElse(null);
|
||||||
|
}
|
||||||
|
}
|
|
@ -46,7 +46,6 @@ public class FastpassListeners implements Listener {
|
||||||
//Buy a ticket
|
//Buy a ticket
|
||||||
String attID = sign.getLine(2);
|
String attID = sign.getLine(2);
|
||||||
if (!API.isAttraction(attID)) return;
|
if (!API.isAttraction(attID)) return;
|
||||||
|
|
||||||
Attraction att = API.getAttraction(attID);
|
Attraction att = API.getAttraction(attID);
|
||||||
|
|
||||||
double price;
|
double price;
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
package nl.sbdeveloper.themeparkplus.listeners;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.api.API;
|
||||||
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
|
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
||||||
|
import nl.sbdeveloper.themeparkplus.gui.MalfunctionGUI;
|
||||||
|
import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.block.Sign;
|
||||||
|
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.EquipmentSlot;
|
||||||
|
|
||||||
|
public class MalfunctionListener implements Listener {
|
||||||
|
@EventHandler
|
||||||
|
public void onClickSign(PlayerInteractEvent e) {
|
||||||
|
if (e.getClickedBlock() == null || e.getAction() != Action.RIGHT_CLICK_BLOCK || !(e.getClickedBlock().getState() instanceof Sign) || e.getHand() != EquipmentSlot.HAND) return;
|
||||||
|
|
||||||
|
String mrLineOne = ChatColor.stripColor(ConfigUtil.makecolored(ThemeParkPlus.getSConfig().getFile().getString("Malfunction.Sign.Row1")));
|
||||||
|
String mrLineTwo = ChatColor.stripColor(ConfigUtil.makecolored(ThemeParkPlus.getSConfig().getFile().getString("Malfunction.Sign.Row2")));
|
||||||
|
|
||||||
|
Sign sign = (Sign) e.getClickedBlock().getState();
|
||||||
|
if (ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase(mrLineOne) && ChatColor.stripColor(sign.getLine(1)).equalsIgnoreCase(mrLineTwo)) {
|
||||||
|
String attID = sign.getLine(2);
|
||||||
|
if (!API.isAttraction(attID)) return;
|
||||||
|
Attraction att = API.getAttraction(attID);
|
||||||
|
|
||||||
|
MalfunctionGUI.open(att, e.getPlayer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
package nl.sbdeveloper.themeparkplus.listeners;
|
package nl.sbdeveloper.themeparkplus.listeners;
|
||||||
|
|
||||||
import nl.iobyte.themepark.api.API;
|
|
||||||
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
||||||
import nl.sbdeveloper.themeparkplus.api.PlusAPI;
|
import nl.sbdeveloper.themeparkplus.api.PlusAPI;
|
||||||
import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow;
|
import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow;
|
||||||
|
@ -36,12 +35,17 @@ public class SignListeners implements Listener {
|
||||||
//Only check themeparkplus signs!
|
//Only check themeparkplus signs!
|
||||||
if (!lines[0].equalsIgnoreCase("[ThemeParkPlus]")) return;
|
if (!lines[0].equalsIgnoreCase("[ThemeParkPlus]")) return;
|
||||||
|
|
||||||
|
if (!ThemeParkPlus.hasTPHook()) {
|
||||||
|
p.sendMessage(ConfigUtil.getMessage("General.RequiresThemePark"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!p.hasPermission("tpp.fastpass.create")) {
|
if (!p.hasPermission("tpp.fastpass.create")) {
|
||||||
p.sendMessage(ConfigUtil.getMessage("General.NoPermission"));
|
p.sendMessage(ConfigUtil.getMessage("General.NoPermission"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!API.isAttraction(lines[2])) {
|
if (!nl.iobyte.themepark.api.API.isAttraction(lines[2])) {
|
||||||
p.sendMessage(ConfigUtil.getMessage("Fastpass.UnknownRide", Collections.singletonMap("ridename", e.getLine(2))));
|
p.sendMessage(ConfigUtil.getMessage("Fastpass.UnknownRide", Collections.singletonMap("ridename", e.getLine(2))));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -52,6 +56,8 @@ public class SignListeners implements Listener {
|
||||||
String sLineTwo = ConfigUtil.makecolored(ThemeParkPlus.getSConfig().getFile().getString("Fastpass.ScannerSign.Row2"));
|
String sLineTwo = ConfigUtil.makecolored(ThemeParkPlus.getSConfig().getFile().getString("Fastpass.ScannerSign.Row2"));
|
||||||
String wrLineOne = ConfigUtil.makecolored(ThemeParkPlus.getSConfig().getFile().getString("WaitingRow.Sign.Row1"));
|
String wrLineOne = ConfigUtil.makecolored(ThemeParkPlus.getSConfig().getFile().getString("WaitingRow.Sign.Row1"));
|
||||||
String wrLineTwo = ConfigUtil.makecolored(ThemeParkPlus.getSConfig().getFile().getString("WaitingRow.Sign.Row2"));
|
String wrLineTwo = ConfigUtil.makecolored(ThemeParkPlus.getSConfig().getFile().getString("WaitingRow.Sign.Row2"));
|
||||||
|
String mrLineOne = ConfigUtil.makecolored(ThemeParkPlus.getSConfig().getFile().getString("Malfunction.Sign.Row1"));
|
||||||
|
String mrLineTwo = ConfigUtil.makecolored(ThemeParkPlus.getSConfig().getFile().getString("Malfunction.Sign.Row2"));
|
||||||
|
|
||||||
if (lines[1].equalsIgnoreCase("Machine") && !lines[2].isEmpty() && !lines[3].isEmpty()) {
|
if (lines[1].equalsIgnoreCase("Machine") && !lines[2].isEmpty() && !lines[3].isEmpty()) {
|
||||||
e.setLine(0, mLineOne);
|
e.setLine(0, mLineOne);
|
||||||
|
@ -74,10 +80,13 @@ public class SignListeners implements Listener {
|
||||||
|
|
||||||
e.setLine(0, wrLineOne);
|
e.setLine(0, wrLineOne);
|
||||||
e.setLine(1, wrLineTwo);
|
e.setLine(1, wrLineTwo);
|
||||||
e.setLine(2, ConfigUtil.makecolored(API.getAttraction(lines[2]).getName()));
|
e.setLine(2, ConfigUtil.makecolored(nl.iobyte.themepark.api.API.getAttraction(lines[2]).getName()));
|
||||||
e.setLine(3, "0 min.");
|
e.setLine(3, "0 min.");
|
||||||
|
|
||||||
p.sendMessage(ConfigUtil.getMessage("WaitingRow.SignCreated"));
|
p.sendMessage(ConfigUtil.getMessage("WaitingRow.SignCreated"));
|
||||||
|
} else if (lines[1].equalsIgnoreCase("Malfunction") && !lines[2].isEmpty()) {
|
||||||
|
e.setLine(0, mrLineOne);
|
||||||
|
e.setLine(1, mrLineTwo);
|
||||||
} else {
|
} else {
|
||||||
p.sendMessage(ConfigUtil.getMessage("General.IncorrectSign"));
|
p.sendMessage(ConfigUtil.getMessage("General.IncorrectSign"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
package nl.sbdeveloper.themeparkplus.listeners;
|
package nl.sbdeveloper.themeparkplus.listeners;
|
||||||
|
|
||||||
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
||||||
import nl.iobyte.themepark.api.attraction.component.Status;
|
import nl.iobyte.themepark.api.attraction.component.Status;
|
||||||
import nl.iobyte.themepark.api.attraction.manager.StatusManager;
|
import nl.iobyte.themepark.api.attraction.manager.StatusManager;
|
||||||
import nl.iobyte.themepark.api.events.attraction.ChangeStatusEvent;
|
import nl.iobyte.themepark.api.events.attraction.ChangeStatusEvent;
|
||||||
|
import nl.iobyte.themepark.api.events.attraction.PreChangeStatusEvent;
|
||||||
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
||||||
|
import nl.sbdeveloper.themeparkplus.api.PlusAPI;
|
||||||
|
import nl.sbdeveloper.themeparkplus.api.objects.MalfunctionReport;
|
||||||
import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
|
import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
|
||||||
import nl.sbdeveloper.themeparkplus.util.DiscordWebhook;
|
import nl.sbdeveloper.themeparkplus.util.DiscordWebhook;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
@ -16,9 +20,33 @@ import java.awt.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Status change listener for discord webhook
|
* Status change listener for malfunction menu and discord webhook
|
||||||
*/
|
*/
|
||||||
public class StatusChangeListener implements Listener {
|
public class StatusChangeListener implements Listener {
|
||||||
|
@EventHandler
|
||||||
|
public void onStatusChange(PreChangeStatusEvent e) {
|
||||||
|
Attraction att = e.getAttraction();
|
||||||
|
|
||||||
|
if (!PlusAPI.isReported(att.getId()) && e.getAfter() == Status.MALFUNCTION && e.getPlayer() != null) {
|
||||||
|
if (ThemeParkPlus.getSConfig().getFile().getBoolean("Malfunction.AllowCommandReport")) {
|
||||||
|
MalfunctionReport malfunctionReport = new MalfunctionReport(att.getId(), e.getPlayer().getUniqueId());
|
||||||
|
PlusAPI.addReport(malfunctionReport);
|
||||||
|
} else {
|
||||||
|
e.setCancelled(true);
|
||||||
|
e.getPlayer().sendMessage(ConfigUtil.getMessage("Malfunction.NoCommand"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PlusAPI.isReported(att.getId()) && e.getAfter() != Status.MALFUNCTION && e.getPlayer() != null) {
|
||||||
|
if (ThemeParkPlus.getSConfig().getFile().getBoolean("Malfunction.AllowCommandFix")) {
|
||||||
|
PlusAPI.removeReport(att.getId());
|
||||||
|
} else {
|
||||||
|
e.setCancelled(true);
|
||||||
|
e.getPlayer().sendMessage(ConfigUtil.getMessage("Malfunction.NoCommand"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onStatusChange(@NotNull ChangeStatusEvent e) {
|
public void onStatusChange(@NotNull ChangeStatusEvent e) {
|
||||||
if (e.getAfter() != Status.GLOBAL) {
|
if (e.getAfter() != Status.GLOBAL) {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import nl.sbdeveloper.themeparkplus.api.PlusAPI;
|
import nl.sbdeveloper.themeparkplus.api.PlusAPI;
|
||||||
import nl.sbdeveloper.themeparkplus.api.objects.Gate;
|
import nl.sbdeveloper.themeparkplus.api.objects.Gate;
|
||||||
|
import nl.sbdeveloper.themeparkplus.api.objects.MalfunctionReport;
|
||||||
import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow;
|
import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow;
|
||||||
import nl.sbdeveloper.themeparkplus.sbutils.LocationSerializer;
|
import nl.sbdeveloper.themeparkplus.sbutils.LocationSerializer;
|
||||||
import nl.sbdeveloper.themeparkplus.sbutils.SQLiteDB;
|
import nl.sbdeveloper.themeparkplus.sbutils.SQLiteDB;
|
||||||
|
@ -36,6 +37,10 @@ public class DBManager {
|
||||||
query = "CREATE TABLE IF NOT EXISTS rows (rideID varchar(255) NOT NULL, rowData blob NOT NULL, UNIQUE (rideID))";
|
query = "CREATE TABLE IF NOT EXISTS rows (rideID varchar(255) NOT NULL, rowData blob NOT NULL, UNIQUE (rideID))";
|
||||||
statement = con.prepareStatement(query);
|
statement = con.prepareStatement(query);
|
||||||
statement.execute();
|
statement.execute();
|
||||||
|
|
||||||
|
query = "CREATE TABLE IF NOT EXISTS malfunction_reports (rideID varchar(255) NOT NULL, reportData blob NOT NULL, UNIQUE (rideID))";
|
||||||
|
statement = con.prepareStatement(query);
|
||||||
|
statement.execute();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -74,6 +79,20 @@ public class DBManager {
|
||||||
WaitingRow row = gson.fromJson(json, WaitingRow.class);
|
WaitingRow row = gson.fromJson(json, WaitingRow.class);
|
||||||
PlusAPI.addRow(row);
|
PlusAPI.addRow(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Load reports */
|
||||||
|
query = "SELECT * FROM malfunction_reports";
|
||||||
|
statement = con.prepareStatement(query);
|
||||||
|
ResultSet reportSet = statement.executeQuery();
|
||||||
|
while (reportSet.next()) {
|
||||||
|
//Loading a gates...
|
||||||
|
byte[] blob = reportSet.getBytes("reportData");
|
||||||
|
String json = new String(blob);
|
||||||
|
|
||||||
|
Gson gson = getGson();
|
||||||
|
MalfunctionReport report = gson.fromJson(json, MalfunctionReport.class);
|
||||||
|
PlusAPI.addReport(report);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
|
@ -103,7 +122,6 @@ public class DBManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<String, WaitingRow> entry : PlusAPI.getRows().entrySet()) {
|
for (Map.Entry<String, WaitingRow> entry : PlusAPI.getRows().entrySet()) {
|
||||||
|
|
||||||
Gson gson = getGson();
|
Gson gson = getGson();
|
||||||
byte[] blob = gson.toJson(entry.getValue()).getBytes();
|
byte[] blob = gson.toJson(entry.getValue()).getBytes();
|
||||||
|
|
||||||
|
@ -125,6 +143,29 @@ public class DBManager {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (Map.Entry<String, MalfunctionReport> entry : PlusAPI.getReports().entrySet()) {
|
||||||
|
Gson gson = getGson();
|
||||||
|
byte[] blob = gson.toJson(entry.getValue()).getBytes();
|
||||||
|
|
||||||
|
try {
|
||||||
|
String query = "INSERT INTO malfunction_reports (rideID, reportData) VALUES (?, ?)";
|
||||||
|
PreparedStatement statement = con.prepareStatement(query);
|
||||||
|
statement.setString(1, entry.getKey());
|
||||||
|
statement.setBytes(2, blob);
|
||||||
|
statement.executeUpdate();
|
||||||
|
} catch (SQLException ignored) {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
String query2 = "UPDATE malfunction_reports SET reportData = ? WHERE rideID = ?";
|
||||||
|
PreparedStatement statement2 = con.prepareStatement(query2);
|
||||||
|
statement2.setBytes(1, blob);
|
||||||
|
statement2.setString(2, entry.getKey());
|
||||||
|
statement2.executeUpdate();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void closeConnection() {
|
public void closeConnection() {
|
||||||
|
|
|
@ -3,7 +3,6 @@ package nl.sbdeveloper.themeparkplus.sbutils;
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
@ -25,39 +24,54 @@ import java.util.function.BiConsumer;
|
||||||
* Update class for SBDevelopment
|
* Update class for SBDevelopment
|
||||||
* @author Stijn [SBDeveloper]
|
* @author Stijn [SBDeveloper]
|
||||||
* @since 05-03-2020
|
* @since 05-03-2020
|
||||||
* @version 1.6
|
* @version 2.0 [26-12-2020] - This class supports the v2 Update API
|
||||||
*
|
*
|
||||||
* © Stijn Bannink <stijnbannink23@gmail.com> - All rights reserved.
|
* <p>© Stijn Bannink [stijnbannink23@gmail.com] - All rights reserved.</p>
|
||||||
*/
|
*/
|
||||||
public class UpdateManager {
|
public class UpdateManager {
|
||||||
|
|
||||||
private static final String SPIGOT_API = "https://api.spigotmc.org/legacy/update.php?resource=%d";
|
private static final String SPIGOT_API = "https://api.spigotmc.org/legacy/update.php?resource=%d";
|
||||||
private static final String SPIGOT_DOWNLOAD = "http://api.spiget.org/v2/resources/%s/download";
|
private static final String SPIGOT_DOWNLOAD = "http://api.spiget.org/v2/resources/%s/download";
|
||||||
|
|
||||||
/* Port 4000 is now legacy, 4443 has a SSL cert */
|
private static final String SBDPLUGINS_API = "https://updates.sbdplugins.nl/api/v2/plugins/%d";
|
||||||
/* As of 24-05-2020, using the legacy port because of SSL errors */
|
private static final String SBDPLUGINS_DOWNLOAD = "https://updates.sbdplugins.nl/api/v2/download/%d";
|
||||||
private static final String SBDPLUGINS_API = "http://updates.sbdplugins.nl:4000/api/resources/%d";
|
|
||||||
private static final String SBDPLUGINS_DOWNLOAD = "http://updates.sbdplugins.nl:4000/api/download/%d";
|
|
||||||
|
|
||||||
private final Plugin plugin;
|
private final Plugin plugin;
|
||||||
private final Version currentVersion;
|
private final Version currentVersion;
|
||||||
private final int resourceID;
|
private final int resourceID;
|
||||||
private final CheckType type;
|
private final CheckType type;
|
||||||
|
private final String license;
|
||||||
|
|
||||||
private BiConsumer<VersionResponse, Version> versionResponse;
|
private BiConsumer<VersionResponse, Version> versionResponse;
|
||||||
private BiConsumer<DownloadResponse, String> downloadResponse;
|
private BiConsumer<DownloadResponse, String> downloadResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new UpdateManager
|
* Construct a new UpdateManager for Spigot
|
||||||
*
|
*
|
||||||
* @param plugin The javaplugin (Main class)
|
* @param plugin The javaplugin (Main class)
|
||||||
* @param resourceID The resourceID on spigot/sbdplugins
|
* @param resourceID The resourceID on spigot/sbdplugins
|
||||||
* @param type The check type
|
|
||||||
*/
|
*/
|
||||||
public UpdateManager(@NotNull Plugin plugin, int resourceID, CheckType type) {
|
public UpdateManager(@NotNull Plugin plugin, int resourceID) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.currentVersion = new Version(plugin.getDescription().getVersion());
|
this.currentVersion = new Version(plugin.getDescription().getVersion());
|
||||||
this.resourceID = resourceID;
|
this.resourceID = resourceID;
|
||||||
this.type = type;
|
this.type = CheckType.SPIGOT;
|
||||||
|
this.license = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a new UpdateManager for SBDPlugins
|
||||||
|
*
|
||||||
|
* @param plugin The javaplugin (Main class)
|
||||||
|
* @param resourceID The resourceID on spigot/sbdplugins
|
||||||
|
* @param license The license for the download
|
||||||
|
*/
|
||||||
|
public UpdateManager(@NotNull Plugin plugin, int resourceID, String license) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.currentVersion = new Version(plugin.getDescription().getVersion());
|
||||||
|
this.resourceID = resourceID;
|
||||||
|
this.type = CheckType.SBDPLUGINS;
|
||||||
|
this.license = license;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,7 +103,7 @@ public class UpdateManager {
|
||||||
|
|
||||||
in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||||||
} else if (type == CheckType.SBDPLUGINS) {
|
} else if (type == CheckType.SBDPLUGINS) {
|
||||||
HttpURLConnection con = (HttpURLConnection) new URL(String.format(SBDPLUGINS_API, this.resourceID)).openConnection();
|
HttpsURLConnection con = (HttpsURLConnection) new URL(String.format(SBDPLUGINS_API, this.resourceID)).openConnection();
|
||||||
con.setRequestMethod("GET");
|
con.setRequestMethod("GET");
|
||||||
con.setRequestProperty("User-Agent", "Mozilla/5.0");
|
con.setRequestProperty("User-Agent", "Mozilla/5.0");
|
||||||
|
|
||||||
|
@ -98,7 +112,7 @@ public class UpdateManager {
|
||||||
|
|
||||||
if (in == null) return;
|
if (in == null) return;
|
||||||
|
|
||||||
String version = null;
|
String version;
|
||||||
|
|
||||||
String inputLine;
|
String inputLine;
|
||||||
StringBuilder response = new StringBuilder();
|
StringBuilder response = new StringBuilder();
|
||||||
|
@ -113,10 +127,10 @@ public class UpdateManager {
|
||||||
JsonArray array = parser.parse(response.toString()).getAsJsonArray();
|
JsonArray array = parser.parse(response.toString()).getAsJsonArray();
|
||||||
|
|
||||||
version = array.get(0).getAsJsonObject().get("name").getAsString();
|
version = array.get(0).getAsJsonObject().get("name").getAsString();
|
||||||
} else if (type == CheckType.SBDPLUGINS) {
|
} else {
|
||||||
JsonObject object = parser.parse(response.toString()).getAsJsonObject();
|
JsonObject object = parser.parse(response.toString()).getAsJsonObject();
|
||||||
|
|
||||||
version = object.get("data").getAsJsonObject().get("version").getAsString();
|
version = object.get("version").getAsString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (version == null) return;
|
if (version == null) return;
|
||||||
|
@ -154,11 +168,12 @@ public class UpdateManager {
|
||||||
ReadableByteChannel channel;
|
ReadableByteChannel channel;
|
||||||
try {
|
try {
|
||||||
//https://stackoverflow.com/questions/921262/how-to-download-and-save-a-file-from-internet-using-java
|
//https://stackoverflow.com/questions/921262/how-to-download-and-save-a-file-from-internet-using-java
|
||||||
HttpURLConnection connection;
|
int response;
|
||||||
|
InputStream stream;
|
||||||
if (type == CheckType.SBDPLUGINS) {
|
if (type == CheckType.SBDPLUGINS) {
|
||||||
connection = (HttpURLConnection) new URL(String.format(SBDPLUGINS_DOWNLOAD, this.resourceID)).openConnection();
|
HttpURLConnection connection = (HttpURLConnection) new URL(String.format(SBDPLUGINS_DOWNLOAD, this.resourceID)).openConnection();
|
||||||
|
|
||||||
String urlParameters = "license=" + ThemeParkPlus.getSConfig().getFile().getString("License") + "&port=" + Bukkit.getPort();
|
String urlParameters = "license=" + license + "&port=" + Bukkit.getPort();
|
||||||
byte[] postData = urlParameters.getBytes(StandardCharsets.UTF_8);
|
byte[] postData = urlParameters.getBytes(StandardCharsets.UTF_8);
|
||||||
int postDataLength = postData.length;
|
int postDataLength = postData.length;
|
||||||
|
|
||||||
|
@ -172,27 +187,31 @@ public class UpdateManager {
|
||||||
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
|
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
|
||||||
wr.write(postData);
|
wr.write(postData);
|
||||||
wr.close();
|
wr.close();
|
||||||
|
|
||||||
|
response = connection.getResponseCode();
|
||||||
|
stream = connection.getInputStream();
|
||||||
} else {
|
} else {
|
||||||
connection = (HttpURLConnection) new URL(String.format(SPIGOT_DOWNLOAD, this.resourceID)).openConnection();
|
HttpsURLConnection connection = (HttpsURLConnection) new URL(String.format(SPIGOT_DOWNLOAD, this.resourceID)).openConnection();
|
||||||
connection.setRequestProperty("User-Agent", "Mozilla/5.0");
|
connection.setRequestProperty("User-Agent", "Mozilla/5.0");
|
||||||
|
|
||||||
|
response = connection.getResponseCode();
|
||||||
|
stream = connection.getInputStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connection.getResponseCode() != 200) {
|
if (response != 200) {
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
BufferedReader in = new BufferedReader(new InputStreamReader(stream));
|
||||||
|
|
||||||
String inputLine;
|
String inputLine;
|
||||||
StringBuilder response = new StringBuilder();
|
StringBuilder responsestr = new StringBuilder();
|
||||||
while ((inputLine = in.readLine()) != null) {
|
while ((inputLine = in.readLine()) != null) {
|
||||||
response.append(inputLine);
|
responsestr.append(inputLine);
|
||||||
}
|
}
|
||||||
in.close();
|
in.close();
|
||||||
|
|
||||||
Bukkit.getLogger().info(response.toString());
|
throw new RuntimeException("Download returned status #" + response, new Throwable(responsestr.toString()));
|
||||||
|
|
||||||
throw new RuntimeException("Download returned status #" + connection.getResponseCode());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
channel = Channels.newChannel(connection.getInputStream());
|
channel = Channels.newChannel(stream);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Bukkit.getScheduler().runTask(this.plugin, () -> this.downloadResponse.accept(DownloadResponse.ERROR, null));
|
Bukkit.getScheduler().runTask(this.plugin, () -> this.downloadResponse.accept(DownloadResponse.ERROR, null));
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -243,7 +262,7 @@ public class UpdateManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum CheckType {
|
private enum CheckType {
|
||||||
SPIGOT, SBDPLUGINS
|
SPIGOT, SBDPLUGINS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,13 +279,13 @@ public class UpdateManager {
|
||||||
|
|
||||||
public static class Version {
|
public static class Version {
|
||||||
|
|
||||||
private String version;
|
private final String version;
|
||||||
|
|
||||||
public final String get() {
|
public final String get() {
|
||||||
return this.version;
|
return this.version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Version(String version) {
|
private Version(String version) {
|
||||||
if(version == null)
|
if(version == null)
|
||||||
throw new IllegalArgumentException("Version can not be null");
|
throw new IllegalArgumentException("Version can not be null");
|
||||||
if(!version.matches("[0-9]+(\\.[0-9]+)*"))
|
if(!version.matches("[0-9]+(\\.[0-9]+)*"))
|
||||||
|
@ -274,7 +293,7 @@ public class UpdateManager {
|
||||||
this.version = version;
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VersionResponse check(@NotNull Version that) {
|
private VersionResponse check(@NotNull Version that) {
|
||||||
String[] thisParts = this.get().split("\\.");
|
String[] thisParts = this.get().split("\\.");
|
||||||
String[] thatParts = that.get().split("\\.");
|
String[] thatParts = that.get().split("\\.");
|
||||||
|
|
||||||
|
|
|
@ -88,12 +88,12 @@ public class License implements Listener {
|
||||||
try {
|
try {
|
||||||
response = sendGETRequestJSON(url);
|
response = sendGETRequestJSON(url);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
disable("Couldn't send the request.");
|
disable("Something went wrong while sending the request.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response == null) {
|
if (response == null) {
|
||||||
disable("Couldn't send the request.");
|
disable("Something went wrong while sending the request. Did you even fill out a license?");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,12 +175,12 @@ public class License implements Listener {
|
||||||
try {
|
try {
|
||||||
response = sendGETRequestJSON(url);
|
response = sendGETRequestJSON(url);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
disable("Couldn't send the activate request.");
|
disable("Something went wrong while sending the request.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response == null) {
|
if (response == null) {
|
||||||
disable("Couldn't send the activate request.");
|
disable("Something went wrong while sending the request. Did you even fill out a license?");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,7 +241,6 @@ public class License implements Listener {
|
||||||
con.setRequestProperty("Authorization", "Basic " + authStringEnc);
|
con.setRequestProperty("Authorization", "Basic " + authStringEnc);
|
||||||
int code = con.getResponseCode();
|
int code = con.getResponseCode();
|
||||||
if (code == 404) {
|
if (code == 404) {
|
||||||
disable("404_error");
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
License: 'TPABCD-1234-ABCD-1234SBD'
|
License: ''
|
||||||
AntiFreerun:
|
AntiFreerun:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
UpdateChecker:
|
UpdateChecker:
|
||||||
|
@ -8,8 +8,41 @@ MessageInConsole: true
|
||||||
WaitingRow:
|
WaitingRow:
|
||||||
MinutesPerPlayer: 1.5
|
MinutesPerPlayer: 1.5
|
||||||
Sign:
|
Sign:
|
||||||
Row1: "&8[&6ThemeParkPlus&8]"
|
Row1: '&8[&6ThemeParkPlus&8]'
|
||||||
Row2: "&bWaitingRow"
|
Row2: '&bWaitingRow'
|
||||||
|
Malfunction:
|
||||||
|
AllowCommandReport: true
|
||||||
|
AllowCommandFix: false
|
||||||
|
Sign:
|
||||||
|
Row1: '&8[&6ThemeParkPlus&8]'
|
||||||
|
Row2: '&bMalfunction'
|
||||||
|
GUI:
|
||||||
|
Title: '&3Report Malfunction for %ridename%'
|
||||||
|
Buttons:
|
||||||
|
Report:
|
||||||
|
Slot: 2
|
||||||
|
Material: GREEN_WOOL
|
||||||
|
Name: '&2&lReport Malfunction'
|
||||||
|
Lores:
|
||||||
|
- '&fClick here to report malfunction for %ridename%.'
|
||||||
|
- '&r'
|
||||||
|
- '&cAbuse of this function is not allowed!'
|
||||||
|
Fix:
|
||||||
|
Slot: 4
|
||||||
|
Material: STONE_PICKAXE
|
||||||
|
Name: '&e&lFix Ride'
|
||||||
|
Lores:
|
||||||
|
- '&fClick here to fix %ridename%!'
|
||||||
|
- '&r'
|
||||||
|
- '&fReporter: &7%reporter%'
|
||||||
|
- '&fDate: &7%date%'
|
||||||
|
- '&fReason: &7%reason%'
|
||||||
|
Cancel:
|
||||||
|
Slot: 6
|
||||||
|
Material: RED_WOOL
|
||||||
|
Name: '&4&lCancel Report'
|
||||||
|
Lores:
|
||||||
|
- '&fClick here to cancel.'
|
||||||
Fastpass:
|
Fastpass:
|
||||||
Item:
|
Item:
|
||||||
DisplayName: '&6Fastpass Ticket'
|
DisplayName: '&6Fastpass Ticket'
|
||||||
|
|
|
@ -3,6 +3,7 @@ General:
|
||||||
NoPlayer: '&cYou have to be a player to do this.'
|
NoPlayer: '&cYou have to be a player to do this.'
|
||||||
IncorrectAmount: '&cThis amount is incorrect.'
|
IncorrectAmount: '&cThis amount is incorrect.'
|
||||||
IncorrectSign: '&cThis sign is incorrect. Please read the wiki for more information.'
|
IncorrectSign: '&cThis sign is incorrect. Please read the wiki for more information.'
|
||||||
|
RequiresThemePark: '&cThis function requires ThemePark to work. Install it to use this function.'
|
||||||
Gates:
|
Gates:
|
||||||
WrongDir: '&cYou can''t walk through this gate in that direction.'
|
WrongDir: '&cYou can''t walk through this gate in that direction.'
|
||||||
UnknownDir: '&cThis direction is unknown. Choose between: NORTH, SOUTH, EAST, WEST'
|
UnknownDir: '&cThis direction is unknown. Choose between: NORTH, SOUTH, EAST, WEST'
|
||||||
|
@ -39,3 +40,10 @@ WaitingRow:
|
||||||
WrongLocation: '&cA waitingrow sign (from the attraction %ridename%) couldn''t be found! It will be deleted.'
|
WrongLocation: '&cA waitingrow sign (from the attraction %ridename%) couldn''t be found! It will be deleted.'
|
||||||
RedstoneTimer:
|
RedstoneTimer:
|
||||||
Started: '&aThe timer successfully started. It will go off in &f%sec1% &asecond(s), and will turn off in &f%sec2% &asecond(s) after that.'
|
Started: '&aThe timer successfully started. It will go off in &f%sec1% &asecond(s), and will turn off in &f%sec2% &asecond(s) after that.'
|
||||||
|
Malfunction:
|
||||||
|
NoCommand: '&cYou can''t report or fix a ride using the command. Please use this Malfunction Sign at the ride.'
|
||||||
|
Reported: '&aSuccessfully reported a malfunction for &f%ride%&a.'
|
||||||
|
AlreadyReported: '&cThere is already a malfunction reported for &f%ride%&c.'
|
||||||
|
Fixed: '&aThe ride &f%ride%&a is now successfully fixed.'
|
||||||
|
AlreadyFixed: '&cThe ride &f%ride%&a &chas no malfunction report, and therefore cannot be fixed.'
|
||||||
|
ThisRide: 'this ride'
|
Reference in a new issue