Added Verify instead of License.java
This commit is contained in:
parent
f86d574b5d
commit
559ae95fed
97 changed files with 157 additions and 656 deletions
.gitignoredependency-reduced-pom.xmlpom.xml
src/main
java/nl/iobyte/themeparkconnector
ThemeParkConnector.javaThemeParkConnectorGson.java
api
ThemeParkConnectorAPI.java
authentication
client
config
event
load
message
network
NetworkingService.java
drivers
handlers
io
objects
packet
payload
operator
packet
adapter
enums
handlers
objects
payloads
player
show
state
commands
listeners
AttractionListener.javaOperatorListener.javaPlayerListener.javaRideCountListener.javaRideOperatorListener.javaTicketListener.java
logger
sbd
resources
0
.gitignore
vendored
Normal file → Executable file
0
.gitignore
vendored
Normal file → Executable file
|
@ -3,7 +3,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>nl.iobyte</groupId>
|
||||
<artifactId>themeparkconnector</artifactId>
|
||||
<version>3.0.3</version>
|
||||
<version>3.1.0</version>
|
||||
<build>
|
||||
<defaultGoal>clean package</defaultGoal>
|
||||
<resources>
|
||||
|
@ -69,7 +69,7 @@
|
|||
<dependency>
|
||||
<groupId>nl.iobyte</groupId>
|
||||
<artifactId>themepark</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.1.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
4
pom.xml
Normal file → Executable file
4
pom.xml
Normal file → Executable file
|
@ -12,7 +12,7 @@
|
|||
|
||||
<groupId>nl.iobyte</groupId>
|
||||
<artifactId>themeparkconnector</artifactId>
|
||||
<version>3.0.3</version>
|
||||
<version>3.1.0</version>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
|
@ -46,7 +46,7 @@
|
|||
<dependency>
|
||||
<groupId>nl.iobyte</groupId>
|
||||
<artifactId>themepark</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.1.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
53
src/main/java/nl/iobyte/themeparkconnector/ThemeParkConnector.java
Normal file → Executable file
53
src/main/java/nl/iobyte/themeparkconnector/ThemeParkConnector.java
Normal file → Executable file
|
@ -6,8 +6,7 @@ import nl.iobyte.themeparkconnector.api.ThemeParkConnectorAPI;
|
|||
import nl.iobyte.themeparkconnector.api.config.enums.StorageKey;
|
||||
import nl.iobyte.themeparkconnector.commands.ThemeParkConnectorCommand;
|
||||
import nl.iobyte.themeparkconnector.listeners.*;
|
||||
import nl.iobyte.themeparkconnector.sbd.License;
|
||||
import nl.iobyte.themeparkconnector.sbd.UpdateManager;
|
||||
import nl.iobyte.themeparkconnector.sbd.Verify;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
@ -27,57 +26,13 @@ public class ThemeParkConnector extends JavaPlugin {
|
|||
Bukkit.getLogger().info(String.format("[%s] - No Vault dependency found!", getDescription().getName()));
|
||||
}
|
||||
|
||||
instance = this;
|
||||
api.enable();
|
||||
instance = this; api.enable();
|
||||
|
||||
//License stuff
|
||||
new License(this, "TPP", api.getConfigurationManager().getString(StorageKey.LICENSE));
|
||||
new Verify(this);
|
||||
|
||||
loadCommands();
|
||||
loadListeners();
|
||||
loadUpdateManager();
|
||||
}
|
||||
|
||||
private void loadUpdateManager() {
|
||||
if(!api.getConfigurationManager().getBoolean(StorageKey.UPDATE_CHECK_ENABLED))
|
||||
return;
|
||||
|
||||
UpdateManager manager = new UpdateManager(
|
||||
this,
|
||||
5,
|
||||
api.getConfigurationManager().getString(StorageKey.LICENSE)
|
||||
);
|
||||
manager.handleResponse((response, version) -> {
|
||||
switch (response) {
|
||||
case LATEST:
|
||||
getLogger().info("You're running the latest version("+version.get()+")");
|
||||
break;
|
||||
case THIS_NEWER:
|
||||
getLogger().info("You're running a newer version("+version.get()+")");
|
||||
break;
|
||||
case UNAVAILABLE:
|
||||
getLogger().info("Unable to check for updates");
|
||||
break;
|
||||
case FOUND_NEW:
|
||||
getLogger().info("Found newer version("+version.get()+")");
|
||||
if(!api.getConfigurationManager().getBoolean(StorageKey.UPDATE_DOWNLOAD_ENABLED))
|
||||
return;
|
||||
|
||||
manager.handleDownloadResponse((downloadResponse, fileName) -> {
|
||||
switch (downloadResponse) {
|
||||
case DONE:
|
||||
getLogger().info("Update downloaded! If you restart your server, it will be loaded. Filename: " + fileName);
|
||||
break;
|
||||
case ERROR:
|
||||
getLogger().severe("Something went wrong when trying downloading the latest version.");
|
||||
break;
|
||||
case UNAVAILABLE:
|
||||
getLogger().warning("Unable to download the latest version.");
|
||||
break;
|
||||
}
|
||||
}).runUpdate();
|
||||
}
|
||||
}).check();
|
||||
}
|
||||
|
||||
private boolean setupEconomy() {
|
||||
|
@ -89,7 +44,7 @@ public class ThemeParkConnector extends JavaPlugin {
|
|||
return false;
|
||||
|
||||
econ = rsp.getProvider();
|
||||
return econ != null;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void loadCommands() {
|
||||
|
|
0
src/main/java/nl/iobyte/themeparkconnector/ThemeParkConnectorGson.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/ThemeParkConnectorGson.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/ThemeParkConnectorAPI.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/ThemeParkConnectorAPI.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/authentication/AuthenticationService.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/authentication/AuthenticationService.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/authentication/objects/WeakConcurrentHashMap.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/authentication/objects/WeakConcurrentHashMap.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/client/ClientConnection.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/client/ClientConnection.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/client/Publisher.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/client/Publisher.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/client/objects/Notification.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/client/objects/Notification.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/config/ConfigurationManager.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/config/ConfigurationManager.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/config/enums/StorageKey.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/config/enums/StorageKey.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/config/enums/StorageLocation.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/config/enums/StorageLocation.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/event/EventDispatcher.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/event/EventDispatcher.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/event/objects/ChangeEvent.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/event/objects/ChangeEvent.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/event/objects/OperatorEvent.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/event/objects/OperatorEvent.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/event/operator/OperatorConnectEvent.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/event/operator/OperatorConnectEvent.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/event/operator/OperatorDisconnectEvent.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/event/operator/OperatorDisconnectEvent.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/event/operator/OperatorStateEvent.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/event/operator/OperatorStateEvent.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/event/ticket/TicketScanEvent.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/event/ticket/TicketScanEvent.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/load/DataLoadService.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/load/DataLoadService.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/load/interfaces/IDataLoader.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/load/interfaces/IDataLoader.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/load/objects/DatabaseLoader.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/load/objects/DatabaseLoader.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/load/objects/OperatorDataLoader.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/load/objects/OperatorDataLoader.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/message/MessageKey.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/message/MessageKey.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/message/Text.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/message/Text.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/NetworkingService.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/NetworkingService.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/drivers/ClientDriver.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/drivers/ClientDriver.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/drivers/SystemDriver.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/drivers/SystemDriver.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/handlers/ClientConnectivityHandler.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/handlers/ClientConnectivityHandler.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/handlers/ClientOperatorHandler.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/handlers/ClientOperatorHandler.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/io/NullProxySelector.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/io/NullProxySelector.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/io/SocketConnector.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/io/SocketConnector.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/objects/CertificateHelper.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/objects/CertificateHelper.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/objects/INetworkingEvent.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/objects/INetworkingEvent.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/objects/SocketDriver.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/objects/SocketDriver.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/packet/KickClientPacket.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/packet/KickClientPacket.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/packet/NotificationPacket.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/packet/NotificationPacket.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/packet/operator/OperatorRequestReplyPacket.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/packet/operator/OperatorRequestReplyPacket.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/packet/operator/OperatorStatePacket.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/packet/operator/OperatorStatePacket.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/packet/operator/StatusChangePacket.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/packet/operator/StatusChangePacket.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/payload/NotificationPayload.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/payload/NotificationPayload.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/payload/operator/OperatorRequestReplyPayload.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/payload/operator/OperatorRequestReplyPayload.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/payload/operator/OperatorStatePayload.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/payload/operator/OperatorStatePayload.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/payload/operator/StatusChangePayload.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/network/payload/operator/StatusChangePayload.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/operator/OperatorService.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/operator/OperatorService.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/operator/adapter/OperatorItemAdapter.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/operator/adapter/OperatorItemAdapter.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/operator/adapter/OperatorPanelAdapter.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/operator/adapter/OperatorPanelAdapter.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/operator/enums/OperatorRequestReply.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/operator/enums/OperatorRequestReply.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/operator/objects/AttractionOperator.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/operator/objects/AttractionOperator.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/operator/objects/panel/OperatorItem.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/operator/objects/panel/OperatorItem.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/operator/objects/panel/OperatorItemState.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/operator/objects/panel/OperatorItemState.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/operator/objects/panel/OperatorPanel.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/operator/objects/panel/OperatorPanel.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/packet/adapter/PacketPayloadAdapter.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/packet/adapter/PacketPayloadAdapter.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/packet/adapter/StatusAdapter.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/packet/adapter/StatusAdapter.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/packet/enums/PacketChannel.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/packet/enums/PacketChannel.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/packet/handlers/ClientConnectHandler.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/packet/handlers/ClientConnectHandler.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/packet/handlers/ClientDisconnectHandler.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/packet/handlers/ClientDisconnectHandler.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/packet/handlers/operator/ClientOperatorClickHandler.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/packet/handlers/operator/ClientOperatorClickHandler.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/packet/objects/AbstractPacket.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/packet/objects/AbstractPacket.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/packet/objects/AbstractPacketPayload.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/packet/objects/AbstractPacketPayload.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/packet/objects/PayloadHandler.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/packet/objects/PayloadHandler.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/packet/payloads/ClientConnectPayload.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/packet/payloads/ClientConnectPayload.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/packet/payloads/ClientDisconnectPayload.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/packet/payloads/ClientDisconnectPayload.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/packet/payloads/operator/ClientOperatorClickPayload.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/packet/payloads/operator/ClientOperatorClickPayload.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/player/PlayerStateService.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/player/PlayerStateService.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/show/ShowService.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/show/ShowService.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/show/objects/Ticket.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/show/objects/Ticket.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/state/StateService.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/state/StateService.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/state/objects/AbstractState.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/state/objects/AbstractState.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/state/states/ConnectedState.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/state/states/ConnectedState.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/state/states/ConnectingState.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/state/states/ConnectingState.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/state/states/IdleState.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/api/state/states/IdleState.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/commands/ThemeParkConnectorCommand.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/commands/ThemeParkConnectorCommand.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/commands/arguments/OperatorArgument.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/commands/arguments/OperatorArgument.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/commands/subcommands/ConnectCommand.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/commands/subcommands/ConnectCommand.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/commands/subcommands/DisconnectCommand.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/commands/subcommands/DisconnectCommand.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/commands/subcommands/HelpCommand.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/commands/subcommands/HelpCommand.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/commands/subcommands/NotificationCommand.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/commands/subcommands/NotificationCommand.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/commands/subcommands/StatusCommand.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/commands/subcommands/StatusCommand.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/commands/subcommands/operator/OperatorCommands.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/commands/subcommands/operator/OperatorCommands.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/commands/subcommands/operator/OperatorReloadCommand.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/commands/subcommands/operator/OperatorReloadCommand.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/commands/subcommands/operator/OperatorStateCommand.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/commands/subcommands/operator/OperatorStateCommand.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/listeners/AttractionListener.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/listeners/AttractionListener.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/listeners/OperatorListener.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/listeners/OperatorListener.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/listeners/PlayerListener.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/listeners/PlayerListener.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/listeners/RideCountListener.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/listeners/RideCountListener.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/listeners/RideOperatorListener.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/listeners/RideOperatorListener.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/listeners/TicketListener.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/listeners/TicketListener.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/logger/ThemeParkConnectorLogger.java
Normal file → Executable file
0
src/main/java/nl/iobyte/themeparkconnector/logger/ThemeParkConnectorLogger.java
Normal file → Executable file
|
@ -1,292 +0,0 @@
|
|||
package nl.iobyte.themeparkconnector.sbd;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* License class for SBDevelopment
|
||||
*
|
||||
* v1.8 - Changed on 24-01-2022
|
||||
*
|
||||
* @author Stijn [SBDeveloper]
|
||||
* @since 23-12-2019
|
||||
*/
|
||||
public class License implements Listener {
|
||||
private final JavaPlugin plugin; // The plugin instance
|
||||
private final String license; // The license code
|
||||
private final String prefix; // The correct prefix for this plugin
|
||||
private String invalidReason = null; // The reason the license is invalid, if null it's not invalid!
|
||||
private static Boolean valid = null; // If true, it's valid, if false, it's not valid, if null it's not checked!
|
||||
|
||||
/**
|
||||
* Construct a new license
|
||||
* @param plugin The plugin
|
||||
* @param prefix The wanted prefix, like TPP or AF
|
||||
* @param license The license from the config
|
||||
*/
|
||||
public License(JavaPlugin plugin, String prefix, String license) {
|
||||
this.prefix = prefix;
|
||||
this.plugin = plugin;
|
||||
this.license = license;
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||
|
||||
validateLicense();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
if (this.invalidReason == null) return;
|
||||
|
||||
Player p = e.getPlayer();
|
||||
if (p.isOp() || p.hasPermission("sbd.licensemessages")) {
|
||||
Bukkit.getScheduler().runTaskLater(this.plugin, () -> p.sendMessage(ChatColor.GOLD + "[" + ChatColor.RED + this.plugin.getName() + ChatColor.GOLD + "] " + ChatColor.RED + "The license is incorrect! Reason: " + ChatColor.GOLD + this.invalidReason), 5 * 20L /* 5 sec */);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check a license
|
||||
*
|
||||
*/
|
||||
private void validateLicense() {
|
||||
//STEP 1: Check prefix
|
||||
if (!this.license.split("-")[0].contains(this.prefix)) {
|
||||
disable("You used the wrong license for this product.");
|
||||
return;
|
||||
}
|
||||
|
||||
//STEP 2: Send license request
|
||||
String url = "https://sbdplugins.nl/wp-json/lmfwc/v2/licenses/" + this.license;
|
||||
JsonObject response;
|
||||
try {
|
||||
response = sendGETRequestJSON(url);
|
||||
} catch (IOException e) {
|
||||
disable("Couldn't send the request.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (response == null) {
|
||||
disable("Failed to request license information. Check if you entered a license in the plugin configuration.");
|
||||
return;
|
||||
}
|
||||
|
||||
JsonObject dataObject = response.get("data").getAsJsonObject();
|
||||
|
||||
//STEP 3: Check status
|
||||
switch(dataObject.get("status").getAsString()) {
|
||||
case "2":
|
||||
//Delivered -> Try to activate (double check timesActivated)
|
||||
break;
|
||||
case "3":
|
||||
//Activated!
|
||||
break;
|
||||
default:
|
||||
disable("Your license has a wrong status.");
|
||||
return;
|
||||
}
|
||||
|
||||
//STEP 4: Check times activated, and if not activated, activate.
|
||||
if (dataObject.get("timesActivated").isJsonNull() || dataObject.get("timesActivated").getAsString().equalsIgnoreCase("0")) {
|
||||
activate();
|
||||
return;
|
||||
}
|
||||
|
||||
//STEP 5: Check expire date
|
||||
if (dataObject.get("expiresAt").isJsonNull()) {
|
||||
disable("Your license has no expire date.");
|
||||
return;
|
||||
}
|
||||
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Date date;
|
||||
try {
|
||||
date = format.parse(dataObject.get("expiresAt").getAsString());
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
disable("Your license has a wrong expire date.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (date == null) {
|
||||
disable("Your license has a wrong expire date.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(date.after(new Date()))) {
|
||||
disable("Your license has expired.");
|
||||
return;
|
||||
}
|
||||
|
||||
//STEP 6: Check IP and port.
|
||||
if (!dataObject.get("ipcheck").getAsBoolean()) {
|
||||
disable("Your license has been used with another IP. Update it in our Discord.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (dataObject.get("port").isJsonNull()) {
|
||||
disable("Your license has no port.");
|
||||
return;
|
||||
}
|
||||
|
||||
String por = dataObject.get("port").getAsString();
|
||||
if (!checkPortValue(Bukkit.getServer().getPort(), por)) {
|
||||
disable("Your license has been used with another Port. Update it in our Discord.");
|
||||
return;
|
||||
}
|
||||
|
||||
valid = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the license
|
||||
*
|
||||
*/
|
||||
private void activate() {
|
||||
//STEP 1: Send license activate request
|
||||
String url = "https://sbdplugins.nl/wp-json/lmfwc/v2/licenses/activate/" + this.license + "?port=" + Bukkit.getServer().getPort();
|
||||
JsonObject response;
|
||||
try {
|
||||
response = sendGETRequestJSON(url);
|
||||
} catch (IOException e) {
|
||||
disable("Couldn't send the activate request.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (response == null) {
|
||||
disable("Failed to request license information. Check if you entered a license in the plugin configuration.");
|
||||
return;
|
||||
}
|
||||
|
||||
JsonObject dataObject = response.get("data").getAsJsonObject();
|
||||
|
||||
//STEP 2: Check status
|
||||
switch(dataObject.get("status").getAsString()) {
|
||||
case "2":
|
||||
//Delivered -> STILL NOT ACTIVATED?! -> Double check
|
||||
break;
|
||||
case "3":
|
||||
//Activated!
|
||||
break;
|
||||
default:
|
||||
disable("Your license has a wrong status.");
|
||||
return;
|
||||
}
|
||||
|
||||
//STEP 3: Check times activated, and if still not activated, disable.
|
||||
if (dataObject.get("timesActivated").isJsonNull() || dataObject.get("timesActivated").getAsString().equalsIgnoreCase("0")) {
|
||||
disable("Couldn't activate the license.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the plugin (private)
|
||||
*
|
||||
* @param reason The disabling reason
|
||||
*/
|
||||
private void disable(String reason) {
|
||||
this.invalidReason = reason;
|
||||
|
||||
Bukkit.getScheduler().runTask(this.plugin, () -> {
|
||||
valid = false;
|
||||
|
||||
Bukkit.getLogger().severe("[" + this.plugin.getName() + "] Stopping plugin because licensing system check failed.");
|
||||
Bukkit.getLogger().severe("[" + this.plugin.getName() + "] Reason: " + reason);
|
||||
Bukkit.getLogger().severe("[" + this.plugin.getName() + "] Contact the developer if you believe something is wrong on their side.");
|
||||
Bukkit.getPluginManager().disablePlugin(this.plugin);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an GET request with JSONObject response
|
||||
*
|
||||
* @param uri The URL
|
||||
*
|
||||
* @return The JSONObject
|
||||
* @throws IOException URL errors
|
||||
*/
|
||||
private 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");
|
||||
String authStringEnc = "Y2tfMGEzNWEzMWE2NzExNmM3NDg2MGEwYTJhNjUxNGVjZjM4NTBmM2JmMDpjc185NmYxZGNlYjI4MWRkZDExOTBjMzQ3ZjJjYzMwMGNjZTIzYWNhODI1";
|
||||
con.setRequestProperty("Authorization", "Basic " + authStringEnc);
|
||||
con.setConnectTimeout(5000); //Timeout after 5 sec.
|
||||
con.setReadTimeout(5000); //Timeout after 5 sec.
|
||||
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();
|
||||
|
||||
return new JsonParser().parse(response.toString()).getAsJsonObject(); //parseString is only available from 1.18, so keep deprecated function!
|
||||
}
|
||||
|
||||
private boolean checkPortValue(int input, String dataValue) {
|
||||
//STEP 1: Check wildcard
|
||||
if (dataValue.equals("*")) return true;
|
||||
|
||||
//STEP 2: Check if equals
|
||||
try {
|
||||
int dataVal = Integer.parseInt(dataValue);
|
||||
|
||||
return input == dataVal;
|
||||
} catch (NumberFormatException ignored) {}
|
||||
|
||||
//STEP 3: Check if range
|
||||
if (dataValue.contains("-")) {
|
||||
String[] dataSplit = dataValue.split("-");
|
||||
|
||||
//STEP 3.1: Check if min or max is wildcard
|
||||
if (dataSplit[0].equals("*") && !dataSplit[1].equals("*")) {
|
||||
int max = Integer.parseInt(dataSplit[1]);
|
||||
return input <= max;
|
||||
} else if (dataSplit[1].equals("*") && !dataSplit[0].equals("*")) {
|
||||
int min = Integer.parseInt(dataSplit[0]);
|
||||
return min <= input;
|
||||
} else {
|
||||
try {
|
||||
int min = Integer.parseInt(dataSplit[0]);
|
||||
int max = Integer.parseInt(dataSplit[1]);
|
||||
|
||||
return (min <= input) && (input <= max);
|
||||
} catch (NumberFormatException ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Else, invalid value
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the license is valid
|
||||
*
|
||||
* @return true = VALID, false = INVALID, null = UNCHECKED
|
||||
*/
|
||||
public static Boolean isValid() {
|
||||
return valid;
|
||||
}
|
||||
}
|
|
@ -1,308 +0,0 @@
|
|||
package nl.iobyte.themeparkconnector.sbd;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
/**
|
||||
* Update class for SBDevelopment
|
||||
* @author Stijn [SBDeveloper]
|
||||
* @since 05-03-2020
|
||||
* @version 2.0 [26-12-2020] - This class supports the v2 Update API
|
||||
*
|
||||
* <p>© Stijn Bannink [stijnbannink23@gmail.com] - All rights reserved.</p>
|
||||
*/
|
||||
public class UpdateManager {
|
||||
|
||||
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 SBDPLUGINS_API = "https://updates.sbdplugins.nl/api/v2/plugins/%d";
|
||||
private static final String SBDPLUGINS_DOWNLOAD = "https://updates.sbdplugins.nl/api/v2/download/%d";
|
||||
|
||||
private final Plugin plugin;
|
||||
private final Version currentVersion;
|
||||
private final int resourceID;
|
||||
private final CheckType type;
|
||||
private final String license;
|
||||
|
||||
private BiConsumer<VersionResponse, Version> versionResponse;
|
||||
private BiConsumer<DownloadResponse, String> downloadResponse;
|
||||
|
||||
/**
|
||||
* Construct a new UpdateManager for Spigot
|
||||
*
|
||||
* @param plugin The javaplugin (Main class)
|
||||
* @param resourceID The resourceID on spigot/sbdplugins
|
||||
*/
|
||||
public UpdateManager(Plugin plugin, int resourceID) {
|
||||
this.plugin = plugin;
|
||||
this.currentVersion = new Version(plugin.getDescription().getVersion());
|
||||
this.resourceID = resourceID;
|
||||
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(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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the response given by check();
|
||||
* @param versionResponse The response
|
||||
* @return The updatemanager
|
||||
*/
|
||||
public UpdateManager handleResponse(BiConsumer<VersionResponse, Version> versionResponse) {
|
||||
this.versionResponse = versionResponse;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UpdateManager handleDownloadResponse(BiConsumer<DownloadResponse, String> downloadResponse) {
|
||||
this.downloadResponse = downloadResponse;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for a new version
|
||||
*/
|
||||
public void check() {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||
try {
|
||||
BufferedReader in = null;
|
||||
if (type == CheckType.SPIGOT) {
|
||||
HttpsURLConnection con = (HttpsURLConnection) new URL(String.format(SPIGOT_API, this.resourceID)).openConnection();
|
||||
con.setRequestMethod("GET");
|
||||
con.setRequestProperty("User-Agent", "Mozilla/5.0");
|
||||
|
||||
in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||||
} else if (type == CheckType.SBDPLUGINS) {
|
||||
HttpsURLConnection con = (HttpsURLConnection) new URL(String.format(SBDPLUGINS_API, this.resourceID)).openConnection();
|
||||
con.setRequestMethod("GET");
|
||||
con.setRequestProperty("User-Agent", "Mozilla/5.0");
|
||||
|
||||
in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||||
}
|
||||
|
||||
if (in == null) return;
|
||||
|
||||
String version;
|
||||
|
||||
String inputLine;
|
||||
StringBuilder response = new StringBuilder();
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
response.append(inputLine);
|
||||
}
|
||||
in.close();
|
||||
|
||||
JsonParser parser = new JsonParser();
|
||||
|
||||
if (type == CheckType.SPIGOT) {
|
||||
JsonArray array = parser.parse(response.toString()).getAsJsonArray();
|
||||
|
||||
version = array.get(0).getAsJsonObject().get("name").getAsString();
|
||||
} else {
|
||||
JsonObject object = parser.parse(response.toString()).getAsJsonObject();
|
||||
|
||||
version = object.get("version").getAsString();
|
||||
}
|
||||
|
||||
if (version == null) return;
|
||||
|
||||
Version onlineVersion = new Version(version);
|
||||
|
||||
VersionResponse verRes = this.currentVersion.check(onlineVersion);
|
||||
|
||||
Bukkit.getScheduler().runTask(this.plugin, () -> this.versionResponse.accept(verRes, onlineVersion));
|
||||
} catch (IOException | NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
Bukkit.getScheduler().runTask(this.plugin, () -> this.versionResponse.accept(VersionResponse.UNAVAILABLE, null));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void runUpdate() {
|
||||
File pluginFile = getPluginFile(); // /plugins/XXX.jar
|
||||
if (pluginFile == null) {
|
||||
this.downloadResponse.accept(DownloadResponse.ERROR, null);
|
||||
Bukkit.getLogger().info("Pluginfile is null");
|
||||
return;
|
||||
}
|
||||
File updateFolder = Bukkit.getUpdateFolderFile();
|
||||
if (!updateFolder.exists()) {
|
||||
if (!updateFolder.mkdirs()) {
|
||||
this.downloadResponse.accept(DownloadResponse.ERROR, null);
|
||||
Bukkit.getLogger().info("Updatefolder doesn't exists, and can't be made");
|
||||
return;
|
||||
}
|
||||
}
|
||||
final File updateFile = new File(updateFolder, pluginFile.getName());
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||
ReadableByteChannel channel;
|
||||
try {
|
||||
//https://stackoverflow.com/questions/921262/how-to-download-and-save-a-file-from-internet-using-java
|
||||
int response;
|
||||
InputStream stream;
|
||||
if (type == CheckType.SBDPLUGINS) {
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(String.format(SBDPLUGINS_DOWNLOAD, this.resourceID)).openConnection();
|
||||
|
||||
String urlParameters = "license=" + license + "&port=" + Bukkit.getPort();
|
||||
byte[] postData = urlParameters.getBytes(StandardCharsets.UTF_8);
|
||||
int postDataLength = postData.length;
|
||||
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||
connection.setRequestProperty("charset", "utf-8");
|
||||
connection.setRequestProperty("Content-Length", Integer.toString(postDataLength));
|
||||
connection.setRequestProperty("User-Agent", "Mozilla/5.0");
|
||||
connection.setDoOutput(true);
|
||||
|
||||
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
|
||||
wr.write(postData);
|
||||
wr.close();
|
||||
|
||||
response = connection.getResponseCode();
|
||||
stream = connection.getInputStream();
|
||||
} else {
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(String.format(SPIGOT_DOWNLOAD, this.resourceID)).openConnection();
|
||||
connection.setRequestProperty("User-Agent", "Mozilla/5.0");
|
||||
|
||||
response = connection.getResponseCode();
|
||||
stream = connection.getInputStream();
|
||||
}
|
||||
|
||||
if (response != 200) {
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(stream));
|
||||
|
||||
String inputLine;
|
||||
StringBuilder responsestr = new StringBuilder();
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
responsestr.append(inputLine);
|
||||
}
|
||||
in.close();
|
||||
|
||||
throw new RuntimeException("Download returned status #" + response, new Throwable(responsestr.toString()));
|
||||
}
|
||||
|
||||
channel = Channels.newChannel(stream);
|
||||
} catch (IOException e) {
|
||||
Bukkit.getScheduler().runTask(this.plugin, () -> this.downloadResponse.accept(DownloadResponse.ERROR, null));
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
FileChannel fileChannel = null;
|
||||
try {
|
||||
FileOutputStream fosForDownloadedFile = new FileOutputStream(updateFile);
|
||||
fileChannel = fosForDownloadedFile.getChannel();
|
||||
|
||||
fileChannel.transferFrom(channel, 0, Long.MAX_VALUE);
|
||||
} catch (IOException e) {
|
||||
Bukkit.getScheduler().runTask(this.plugin, () -> this.downloadResponse.accept(DownloadResponse.ERROR, null));
|
||||
e.printStackTrace();
|
||||
return;
|
||||
} finally {
|
||||
if (channel != null) {
|
||||
try {
|
||||
channel.close();
|
||||
} catch (IOException ioe) {
|
||||
System.out.println("Error while closing response body channel");
|
||||
}
|
||||
}
|
||||
|
||||
if (fileChannel != null) {
|
||||
try {
|
||||
fileChannel.close();
|
||||
} catch (IOException ioe) {
|
||||
System.out.println("Error while closing file channel for downloaded file");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().runTask(this.plugin, () -> this.downloadResponse.accept(DownloadResponse.DONE, updateFile.getPath()));
|
||||
});
|
||||
}
|
||||
|
||||
private File getPluginFile() {
|
||||
if (!(this.plugin instanceof JavaPlugin)) { return null; }
|
||||
try {
|
||||
Method method = JavaPlugin.class.getDeclaredMethod("getFile");
|
||||
method.setAccessible(true);
|
||||
return (File) method.invoke(this.plugin);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException("Could not get plugin file", e);
|
||||
}
|
||||
}
|
||||
|
||||
private enum CheckType {
|
||||
SPIGOT, SBDPLUGINS
|
||||
}
|
||||
|
||||
public enum VersionResponse {
|
||||
LATEST, //Latest version
|
||||
FOUND_NEW, //Newer available
|
||||
THIS_NEWER, //Local version is newer?
|
||||
UNAVAILABLE //Error
|
||||
}
|
||||
|
||||
public enum DownloadResponse {
|
||||
DONE, ERROR, UNAVAILABLE
|
||||
}
|
||||
|
||||
public static class Version {
|
||||
|
||||
private final String version;
|
||||
|
||||
public final String get() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
private Version(String version) {
|
||||
if(version == null)
|
||||
throw new IllegalArgumentException("Version can not be null");
|
||||
if(!version.matches("[0-9]+(\\.[0-9]+)*"))
|
||||
throw new IllegalArgumentException("Invalid version format");
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
private VersionResponse check(Version that) {
|
||||
String[] thisParts = this.get().split("\\.");
|
||||
String[] thatParts = that.get().split("\\.");
|
||||
|
||||
int length = Math.max(thisParts.length, thatParts.length);
|
||||
for (int i = 0; i < length; i++) {
|
||||
int thisPart = i < thisParts.length ? Integer.parseInt(thisParts[i]) : 0;
|
||||
int thatPart = i < thatParts.length ? Integer.parseInt(thatParts[i]) : 0;
|
||||
if(thisPart < thatPart)
|
||||
return VersionResponse.FOUND_NEW;
|
||||
if(thisPart > thatPart)
|
||||
return VersionResponse.THIS_NEWER;
|
||||
}
|
||||
return VersionResponse.LATEST;
|
||||
}
|
||||
}
|
||||
}
|
148
src/main/java/nl/iobyte/themeparkconnector/sbd/Verify.java
Executable file
148
src/main/java/nl/iobyte/themeparkconnector/sbd/Verify.java
Executable file
|
@ -0,0 +1,148 @@
|
|||
package nl.iobyte.themeparkconnector.sbd;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* Purchase verification class
|
||||
*
|
||||
* @author Stijn [SBDeveloper]
|
||||
* @version 2.0 [17-04-2022] - Updated to Polymart
|
||||
* @since 23-12-2019
|
||||
*/
|
||||
public class Verify implements Listener {
|
||||
private static final String endpointURL = "https://api.polymart.org/v1/verifyPurchase/?inject_version=%d&resource_id=%d&user_id=%d&nonce=%d&download_agent=%d&download_time=%d&download_token=%s";
|
||||
|
||||
private final JavaPlugin plugin; // The plugin instance
|
||||
|
||||
private final int resourceID;
|
||||
private final int injector_version;
|
||||
private final int user_id;
|
||||
private final int nonce;
|
||||
private final int download_agent;
|
||||
private final int download_time;
|
||||
private final String download_token;
|
||||
|
||||
private String invalidReason = null; // The reason the license is invalid, if null it's not invalid!
|
||||
private static Boolean valid = null; // If true, it's valid, if false, it's not valid, if null it's not checked!
|
||||
|
||||
/**
|
||||
* Construct a new license
|
||||
*
|
||||
* @param plugin The plugin
|
||||
*/
|
||||
public Verify(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
this.resourceID = Integer.parseInt("%%__RESOURCE__%%");
|
||||
this.injector_version = Integer.parseInt("%%__INJECT_VER__%%");
|
||||
this.user_id = Integer.parseInt("%%__USER__%%");
|
||||
this.nonce = Integer.parseInt("%%__NONCE__%%");
|
||||
this.download_agent = Integer.parseInt("%%__AGENT__%%");
|
||||
this.download_time = Integer.parseInt("%%__TIMESTAMP__%%");
|
||||
this.download_token = "%%__VERIFY_TOKEN__%%";
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||
|
||||
validate();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
if (this.invalidReason == null) return;
|
||||
|
||||
Player p = e.getPlayer();
|
||||
if (p.isOp() || p.hasPermission("sbd.licensemessages")) {
|
||||
Bukkit.getScheduler().runTaskLater(this.plugin, () -> p.sendMessage(ChatColor.GOLD + "[" + ChatColor.RED + this.plugin.getName() + ChatColor.GOLD + "] " + ChatColor.RED + "The license is incorrect! Reason: " + ChatColor.GOLD + this.invalidReason), 5 * 20L /* 5 sec */);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the purchase
|
||||
*/
|
||||
private void validate() {
|
||||
try {
|
||||
URL url = new URL(String.format(endpointURL, this.injector_version, this.resourceID, this.user_id, this.nonce, this.download_agent, this.download_time, this.download_token));
|
||||
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
||||
con.setRequestMethod("GET");
|
||||
con.setRequestProperty("User-Agent", "SBDVerify/2.0");
|
||||
con.setConnectTimeout(5000); //Timeout after 5 sec.
|
||||
con.setReadTimeout(5000); //Timeout after 5 sec.
|
||||
int code = con.getResponseCode();
|
||||
if (code != 200) {
|
||||
disable("Could not send the validating request.");
|
||||
return;
|
||||
}
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||||
String inputLine;
|
||||
StringBuilder response = new StringBuilder();
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
response.append(inputLine);
|
||||
}
|
||||
in.close();
|
||||
|
||||
JsonObject json = new JsonParser().parse(response.toString()).getAsJsonObject();
|
||||
if (json == null) {
|
||||
disable("Could not send the validating request.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!json.has("response")) {
|
||||
disable("An invalid response was returned by the validating request.");
|
||||
return;
|
||||
}
|
||||
|
||||
JsonObject resp = json.get("response").getAsJsonObject();
|
||||
if (!resp.has("success")) {
|
||||
disable("An invalid response was returned by the validating request.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!resp.get("success").getAsBoolean()) {
|
||||
disable("The purchase of this plugin could not be verified.");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
disable("Could not send the validating request.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the plugin (private)
|
||||
*
|
||||
* @param reason The disabling reason
|
||||
*/
|
||||
private void disable(String reason) {
|
||||
this.invalidReason = reason;
|
||||
|
||||
Bukkit.getScheduler().runTask(this.plugin, () -> {
|
||||
valid = false;
|
||||
|
||||
plugin.getLogger().severe("Stopping plugin because licensing system check failed.");
|
||||
plugin.getLogger().severe("Reason: " + reason);
|
||||
plugin.getLogger().severe("Contact the developer if you believe something is wrong on their side.");
|
||||
Bukkit.getPluginManager().disablePlugin(this.plugin);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the license is valid
|
||||
*
|
||||
* @return true = VALID, false = INVALID, null = UNCHECKED
|
||||
*/
|
||||
public static Boolean isValid() {
|
||||
return valid;
|
||||
}
|
||||
}
|
0
src/main/resources/message.yml
Normal file → Executable file
0
src/main/resources/message.yml
Normal file → Executable file
0
src/main/resources/plugin.yml
Normal file → Executable file
0
src/main/resources/plugin.yml
Normal file → Executable file
4
src/main/resources/settings.yml
Normal file → Executable file
4
src/main/resources/settings.yml
Normal file → Executable file
|
@ -1,6 +1,4 @@
|
|||
version: 1.1
|
||||
|
||||
license: ''
|
||||
version: 1.2
|
||||
|
||||
update:
|
||||
check: true
|
||||
|
|
Reference in a new issue