mirror of
https://github.com/nkomarn/harbor.git
synced 2024-12-18 22:37:36 +01:00
🚀 Quick hotfixes! More stuff coming soon!
This commit is contained in:
parent
cea0522f06
commit
49bcd9da88
@ -31,6 +31,11 @@
|
|||||||
<attribute name="m2e-apt" value="true"/>
|
<attribute name="m2e-apt" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
|
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
|
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="optional" value="true"/>
|
<attribute name="optional" value="true"/>
|
||||||
|
11
.gitignore
vendored
11
.gitignore
vendored
@ -1,4 +1,7 @@
|
|||||||
/bin/
|
.vscode/
|
||||||
spigot
|
.settings/
|
||||||
.vscode
|
.idea/
|
||||||
target
|
target/
|
||||||
|
jars/
|
||||||
|
.classpath
|
||||||
|
.idea/
|
2
.project
2
.project
@ -17,7 +17,7 @@
|
|||||||
</buildCommand>
|
</buildCommand>
|
||||||
</buildSpec>
|
</buildSpec>
|
||||||
<natures>
|
<natures>
|
||||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
|
||||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||||
</natures>
|
</natures>
|
||||||
</projectDescription>
|
</projectDescription>
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
eclipse.preferences.version=1
|
|
||||||
encoding//src/main/java=UTF-8
|
|
||||||
encoding/<project>=UTF-8
|
|
||||||
encoding/src=UTF-8
|
|
@ -1,2 +0,0 @@
|
|||||||
eclipse.preferences.version=1
|
|
||||||
org.eclipse.jdt.apt.aptEnabled=false
|
|
@ -1,7 +0,0 @@
|
|||||||
eclipse.preferences.version=1
|
|
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
|
||||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
|
||||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
|
||||||
org.eclipse.jdt.core.compiler.processAnnotations=disabled
|
|
||||||
org.eclipse.jdt.core.compiler.release=disabled
|
|
||||||
org.eclipse.jdt.core.compiler.source=1.8
|
|
@ -1,4 +0,0 @@
|
|||||||
activeProfiles=
|
|
||||||
eclipse.preferences.version=1
|
|
||||||
resolveWorkspaceProjects=true
|
|
||||||
version=1
|
|
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2018 Mykyta
|
Copyright (c) 2019 Mykyta
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
[discord-invite]: https://discord.gg/UACRzwe
|
# 🌱 The Seed - Spigot Plugin Template
|
||||||
# Harbor [![Discord](https://discordapp.com/api/guilds/285623631042707457/widget.png)][discord-invite] [![License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/nkomarn/Harbor/blob/master/LICENSE)
|
A Spigot template that I use to develop plugins for The Seed MC!
|
||||||
Harbor is a plugin that redefines sleep within your Spigot server!
|
https://theseedmc.com
|
||||||
https://www.spigotmc.org/resources/harbor-a-sleep-enhancement-plugin.60088/
|
|
||||||
|
### test
|
2
build.sh
Normal file
2
build.sh
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
mvn package
|
||||||
|
yes | cp -rf target/*-*.jar ../Spigot/1.13.2/plugins
|
16
plugin.yml
16
plugin.yml
@ -1,16 +0,0 @@
|
|||||||
name: Harbor
|
|
||||||
version: 1.5
|
|
||||||
main: mykyta.Harbor.Harbor
|
|
||||||
description: Ahoy, matey! Harbor is a Spigot plugin that redefines how sleep works in your server, making it easier for all the online players to get in bed quick and skip through the night!
|
|
||||||
author: Mykyta (TechToolbox)
|
|
||||||
website: https://mykyta.tk
|
|
||||||
api-version: 1.14
|
|
||||||
|
|
||||||
commands:
|
|
||||||
harbor:
|
|
||||||
description: List information and control Harbor.
|
|
||||||
usage: /<command>
|
|
||||||
sleeping:
|
|
||||||
description: Show a list of the sleeping players in your world.
|
|
||||||
usage: /<command>
|
|
||||||
|
|
297
pom.xml
297
pom.xml
@ -1,157 +1,146 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>mykyta.Harbor</groupId>
|
<groupId>xyz.nkomarn</groupId>
|
||||||
<artifactId>Harbor</artifactId>
|
<artifactId>Harbor</artifactId>
|
||||||
<version>1.5</version>
|
<version>1.5.1</version>
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<spigot>${project.basedir}/spigot</spigot>
|
|
||||||
</properties>
|
|
||||||
<dependencies>
|
|
||||||
<!-- GSON -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.google.code.gson</groupId>
|
|
||||||
<artifactId>gson</artifactId>
|
|
||||||
<version>2.8.5</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Spigot versions -->
|
<properties>
|
||||||
<dependency>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<groupId>spigotmc.org</groupId>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<artifactId>spigot-1.14.1</artifactId>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
<scope>system</scope>
|
<jars>${project.basedir}/jars</jars>
|
||||||
<systemPath>${spigot}/1.14.1.jar</systemPath>
|
</properties>
|
||||||
<version>1.14.1</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>spigotmc.org</groupId>
|
|
||||||
<artifactId>spigot-1.14</artifactId>
|
|
||||||
<scope>system</scope>
|
|
||||||
<systemPath>${spigot}/1.14.jar</systemPath>
|
|
||||||
<version>1.14</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>spigotmc.org</groupId>
|
|
||||||
<artifactId>spigot-1.13.2</artifactId>
|
|
||||||
<scope>system</scope>
|
|
||||||
<systemPath>${spigot}/1.13.2.jar</systemPath>
|
|
||||||
<version>1.13.2</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>spigotmc.org</groupId>
|
|
||||||
<artifactId>spigot-1.13</artifactId>
|
|
||||||
<scope>system</scope>
|
|
||||||
<systemPath>${spigot}/1.13.jar</systemPath>
|
|
||||||
<version>1.13</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>spigotmc.org</groupId>
|
|
||||||
<artifactId>spigot-1.12.2</artifactId>
|
|
||||||
<scope>system</scope>
|
|
||||||
<systemPath>${spigot}/1.12.2.jar</systemPath>
|
|
||||||
<version>1.12.2</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>spigotmc.org</groupId>
|
|
||||||
<artifactId>spigot-1.11.2</artifactId>
|
|
||||||
<scope>system</scope>
|
|
||||||
<systemPath>${spigot}/1.11.2.jar</systemPath>
|
|
||||||
<version>1.11.2</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>spigotmc.org</groupId>
|
|
||||||
<artifactId>spigot-1.10.2</artifactId>
|
|
||||||
<scope>system</scope>
|
|
||||||
<systemPath>${spigot}/1.10.2.jar</systemPath>
|
|
||||||
<version>1.10.2</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>spigotmc.org</groupId>
|
|
||||||
<artifactId>spigot-1.9.4</artifactId>
|
|
||||||
<scope>system</scope>
|
|
||||||
<systemPath>${spigot}/1.9.4.jar</systemPath>
|
|
||||||
<version>1.9.4</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>spigotmc.org</groupId>
|
|
||||||
<artifactId>spigot-1.9.2</artifactId>
|
|
||||||
<scope>system</scope>
|
|
||||||
<systemPath>${spigot}/1.9.2.jar</systemPath>
|
|
||||||
<version>1.9.2</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>spigotmc.org</groupId>
|
|
||||||
<artifactId>spigot-1.8.8</artifactId>
|
|
||||||
<scope>system</scope>
|
|
||||||
<systemPath>${spigot}/1.8.8.jar</systemPath>
|
|
||||||
<version>1.8.8</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>spigotmc.org</groupId>
|
|
||||||
<artifactId>spigot-1.8.3</artifactId>
|
|
||||||
<scope>system</scope>
|
|
||||||
<systemPath>${spigot}/1.8.3.jar</systemPath>
|
|
||||||
<version>1.8.3</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>spigotmc.org</groupId>
|
|
||||||
<artifactId>spigot-1.8</artifactId>
|
|
||||||
<scope>system</scope>
|
|
||||||
<systemPath>${spigot}/1.8.jar</systemPath>
|
|
||||||
<version>1.8</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>spigotmc.org</groupId>
|
|
||||||
<artifactId>spigot-1.7.2</artifactId>
|
|
||||||
<scope>system</scope>
|
|
||||||
<systemPath>${spigot}/1.7.2.jar</systemPath>
|
|
||||||
<version>1.7.2</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- BossBarAPI for 1.7 -->
|
<repositories>
|
||||||
<dependency>
|
|
||||||
<groupId>inventivetalent.org</groupId>
|
</repositories>
|
||||||
<artifactId>bossbarapi-2.4.1</artifactId>
|
|
||||||
<scope>system</scope>
|
<dependencies>
|
||||||
<systemPath>${spigot}/BossBarAPI.jar</systemPath>
|
<dependency>
|
||||||
<version>2.4.1</version>
|
<groupId>spigotmc.org</groupId>
|
||||||
</dependency>
|
<artifactId>spigot-1.14.1</artifactId>
|
||||||
</dependencies>
|
<scope>system</scope>
|
||||||
<build>
|
<systemPath>${jars}/1.14.1.jar</systemPath>
|
||||||
<directory>/home/nkomarn/Documents/Spigot Servers/1.14.2/plugins/</directory>
|
<version>1.14.1</version>
|
||||||
<sourceDirectory>${basedir}/src/</sourceDirectory>
|
</dependency>
|
||||||
<resources>
|
<dependency>
|
||||||
<resource>
|
<groupId>spigotmc.org</groupId>
|
||||||
<targetPath>.</targetPath>
|
<artifactId>spigot-1.14</artifactId>
|
||||||
<filtering>true</filtering>
|
<scope>system</scope>
|
||||||
<directory>${basedir}</directory>
|
<systemPath>${jars}/1.14.jar</systemPath>
|
||||||
<includes>
|
<version>1.14</version>
|
||||||
<include>*.yml</include>
|
</dependency>
|
||||||
</includes>
|
<dependency>
|
||||||
</resource>
|
<groupId>spigotmc.org</groupId>
|
||||||
</resources>
|
<artifactId>spigot-1.13.2</artifactId>
|
||||||
<plugins>
|
<scope>system</scope>
|
||||||
<plugin>
|
<systemPath>${jars}/1.13.2.jar</systemPath>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<version>1.13.2</version>
|
||||||
<artifactId>maven-resources-plugin</artifactId>
|
</dependency>
|
||||||
<version>3.0.2</version>
|
<dependency>
|
||||||
</plugin>
|
<groupId>spigotmc.org</groupId>
|
||||||
<plugin>
|
<artifactId>spigot-1.13</artifactId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<scope>system</scope>
|
||||||
<version>3.5</version>
|
<systemPath>${jars}/1.13.jar</systemPath>
|
||||||
<configuration>
|
<version>1.13</version>
|
||||||
<source>1.8</source>
|
</dependency>
|
||||||
<target>1.8</target>
|
<dependency>
|
||||||
</configuration>
|
<groupId>spigotmc.org</groupId>
|
||||||
</plugin>
|
<artifactId>spigot-1.12.2</artifactId>
|
||||||
<plugin>
|
<scope>system</scope>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<systemPath>${jars}/1.12.2.jar</systemPath>
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
<version>1.12.2</version>
|
||||||
<version>3.0.1</version>
|
</dependency>
|
||||||
</plugin>
|
<dependency>
|
||||||
</plugins>
|
<groupId>spigotmc.org</groupId>
|
||||||
</build>
|
<artifactId>spigot-1.11.2</artifactId>
|
||||||
|
<scope>system</scope>
|
||||||
|
<systemPath>${jars}/1.11.2.jar</systemPath>
|
||||||
|
<version>1.11.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>spigotmc.org</groupId>
|
||||||
|
<artifactId>spigot-1.10.2</artifactId>
|
||||||
|
<scope>system</scope>
|
||||||
|
<systemPath>${jars}/1.10.2.jar</systemPath>
|
||||||
|
<version>1.10.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>spigotmc.org</groupId>
|
||||||
|
<artifactId>spigot-1.9.4</artifactId>
|
||||||
|
<scope>system</scope>
|
||||||
|
<systemPath>${jars}/1.9.4.jar</systemPath>
|
||||||
|
<version>1.9.4</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>spigotmc.org</groupId>
|
||||||
|
<artifactId>spigot-1.9.2</artifactId>
|
||||||
|
<scope>system</scope>
|
||||||
|
<systemPath>${jars}/1.9.2.jar</systemPath>
|
||||||
|
<version>1.9.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>spigotmc.org</groupId>
|
||||||
|
<artifactId>spigot-1.8.8</artifactId>
|
||||||
|
<scope>system</scope>
|
||||||
|
<systemPath>${jars}/1.8.8.jar</systemPath>
|
||||||
|
<version>1.8.8</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>spigotmc.org</groupId>
|
||||||
|
<artifactId>spigot-1.8.3</artifactId>
|
||||||
|
<scope>system</scope>
|
||||||
|
<systemPath>${jars}/1.8.3.jar</systemPath>
|
||||||
|
<version>1.8.3</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>spigotmc.org</groupId>
|
||||||
|
<artifactId>spigot-1.8</artifactId>
|
||||||
|
<scope>system</scope>
|
||||||
|
<systemPath>${jars}/1.8.jar</systemPath>
|
||||||
|
<version>1.8</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>spigotmc.org</groupId>
|
||||||
|
<artifactId>spigot-1.7.2</artifactId>
|
||||||
|
<scope>system</scope>
|
||||||
|
<systemPath>${jars}/1.7.2.jar</systemPath>
|
||||||
|
<version>1.7.2</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<directory>target</directory>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<includes>
|
||||||
|
<include>plugin.yml</include>
|
||||||
|
<include>config.yml</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
<pluginManagement>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-clean-plugin</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<version>3.0.2</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>3.0.2</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
|
</build>
|
||||||
</project>
|
</project>
|
@ -1,58 +0,0 @@
|
|||||||
package mykyta.Harbor.Commands;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import mykyta.Harbor.Config;
|
|
||||||
import mykyta.Harbor.Harbor;
|
|
||||||
import mykyta.Harbor.Updater;
|
|
||||||
import mykyta.Harbor.Util;
|
|
||||||
|
|
||||||
public class Command implements CommandExecutor {
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, org.bukkit.command.Command command, String label, String[] args) {
|
|
||||||
Config config = new Config();
|
|
||||||
Util util = new Util();
|
|
||||||
|
|
||||||
if (args.length < 1) {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix") + "&7Version " + util.version + " by TechToolbox."));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Permission check
|
|
||||||
if (!sender.hasPermission("harbor.admin")) {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix") + config.getString("messages.miscellaneous.permission")));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Command arguments
|
|
||||||
if (args[0].equalsIgnoreCase("reload")) {
|
|
||||||
try {
|
|
||||||
Harbor h = Config.harbor;
|
|
||||||
h.reloadConfig();
|
|
||||||
Bukkit.getPluginManager().disablePlugin(h);
|
|
||||||
Bukkit.getPluginManager().enablePlugin(h);
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix") + config.getString("messages.miscellaneous.reloaded")));
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix") + config.getString("messages.miscellaneous.reloaderror")));
|
|
||||||
if (Util.debug) e.printStackTrace();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (args[0].equalsIgnoreCase("update")) {
|
|
||||||
Updater u = new Updater();
|
|
||||||
int result = u.upgrade();
|
|
||||||
if (result == 0) sender.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix") + "&7Harbor was successfully updated to version " + Updater.latest + " and will be enabled after a server restart/reload."));
|
|
||||||
else if (result == 1) sender.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix") + "&7An error occured while updating Harbor to version " + Updater.latest + ". Check the server console for more details."));
|
|
||||||
else if (result == 2) sender.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix") + "&7This server is already running the latest version of Harbor. Great work!"));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unrecognized message if nothing else worked
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix") + config.getString("messages.miscellaneous.unrecognized")));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
package mykyta.Harbor.Commands;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.SkullMeta;
|
|
||||||
|
|
||||||
import mykyta.Harbor.Config;
|
|
||||||
import mykyta.Harbor.Util;
|
|
||||||
import mykyta.Harbor.GUI.GUIHolder;
|
|
||||||
import mykyta.Harbor.GUI.GUIType;
|
|
||||||
|
|
||||||
public class Sleeping implements CommandExecutor {
|
|
||||||
|
|
||||||
private Inventory gui;
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
||||||
if (sender instanceof Player) {
|
|
||||||
Player p = (Player) sender;
|
|
||||||
World w = p.getWorld();
|
|
||||||
Config config = new Config();
|
|
||||||
ArrayList<Player> sleeping = Util.sleeping.get(w);
|
|
||||||
int slots = Math.min(54, ((sleeping.size() - 1) / 9 + 1) * 9);
|
|
||||||
gui = Bukkit.createInventory(new GUIHolder(GUIType.SLEEPING), slots, config.getString("gui.sleeping"));
|
|
||||||
|
|
||||||
if (sleeping.size() > 0) sleeping.forEach(pl -> {
|
|
||||||
ItemStack item = new ItemStack(Material.PLAYER_HEAD, 1);
|
|
||||||
SkullMeta meta = (SkullMeta) item.getItemMeta();
|
|
||||||
meta.setDisplayName(ChatColor.GRAY + pl.getName());
|
|
||||||
meta.setOwner(pl.getName());
|
|
||||||
item.setItemMeta(meta);
|
|
||||||
gui.setItem(sleeping.indexOf(pl), item);
|
|
||||||
});
|
|
||||||
|
|
||||||
p.openInventory(gui);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Config config = new Config();
|
|
||||||
if (args.length < 1) {
|
|
||||||
ArrayList<String> list = new ArrayList<String>();
|
|
||||||
Bukkit.getServer().getWorlds().forEach(w -> {list.add("&o" + w.getName());});
|
|
||||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix") + "Specify a world name. Possible worlds are " + String.join("&r, ", list) + "&r."));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
World w = Bukkit.getServer().getWorld(args[0]);
|
|
||||||
if (w == null) Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix") + "The specified world doesn't exist."));
|
|
||||||
else {
|
|
||||||
ArrayList<String> list = new ArrayList<String>();
|
|
||||||
Util.sleeping.get(Bukkit.getServer().getWorld(args[0])).forEach(p -> {list.add("&o" + p.getName());});
|
|
||||||
if (list.size() > 0 && list.size() != 1) Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix") + "In &o" + args[0] + "&r, the currently sleeping players are " + String.join("&r, ", list) + "&r."));
|
|
||||||
else if (list.size() == 1) Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix") + "In &o" + args[0] + "&r, " + list.get(0) + "&r is the only player sleeping."));
|
|
||||||
else Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix") + "There aren't any currently sleeping players in &o" + args[0] + "&r."));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,67 +0,0 @@
|
|||||||
package mykyta.Harbor.Events;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerBedEnterEvent;
|
|
||||||
import org.bukkit.event.player.PlayerBedEnterEvent.BedEnterResult;
|
|
||||||
|
|
||||||
import mykyta.Harbor.Config;
|
|
||||||
import mykyta.Harbor.Util;
|
|
||||||
|
|
||||||
public class BedEnter implements Listener {
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
|
||||||
public void onPlayerBedEnter(PlayerBedEnterEvent event) {
|
|
||||||
Util util = new Util();
|
|
||||||
Config config = new Config();
|
|
||||||
|
|
||||||
// Block bed entry if enabled
|
|
||||||
if (config.getBoolean("features.block")) {
|
|
||||||
if (config.getString("messages.chat.blocked").length() > 0) event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.chat.blocked")));
|
|
||||||
util.sendActionbar(event.getPlayer(), config.getString("messages.actionbar.blocked"));
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1.13.2 API change bypass
|
|
||||||
boolean success = false;
|
|
||||||
try {
|
|
||||||
if (event.getBedEnterResult() == BedEnterResult.OK) success = true;
|
|
||||||
}
|
|
||||||
catch (NoSuchMethodError e) {
|
|
||||||
success = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (success) {
|
|
||||||
Player p = event.getPlayer();
|
|
||||||
World w = p.getWorld();
|
|
||||||
ArrayList<Player> excluded = util.getExcluded(w);
|
|
||||||
|
|
||||||
if (!excluded.contains(p)) {
|
|
||||||
util.add(w, p);
|
|
||||||
|
|
||||||
// Chat messages
|
|
||||||
if (config.getBoolean("messages.chat.chat") && (config.getString("messages.chat.sleeping").length() != 0)) {
|
|
||||||
Bukkit.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.chat.sleeping")
|
|
||||||
.replace("[sleeping]", String.valueOf(util.getSleeping(w))))
|
|
||||||
.replace("[online]", String.valueOf(util.getOnline(w)))
|
|
||||||
.replace("[player]", p.getName())
|
|
||||||
.replace("[needed]", String.valueOf(util.getNeeded(w))));
|
|
||||||
}
|
|
||||||
if (config.getBoolean("messages.title.title")) {
|
|
||||||
util.sendTitle(p, config.getString("messages.title.sleeping.top"), config.getString("messages.title.sleeping.bottom"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip night if possible
|
|
||||||
if (!Util.skipping) util.skip(w);
|
|
||||||
}
|
|
||||||
else if (config.getString("messages.chat.bypass").length() != 0) p.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.chat.bypass")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
package mykyta.Harbor.Events;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerBedLeaveEvent;
|
|
||||||
|
|
||||||
import mykyta.Harbor.Config;
|
|
||||||
import mykyta.Harbor.Util;
|
|
||||||
|
|
||||||
public class BedLeave implements Listener {
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
|
||||||
public void onPlayerBedLeave(PlayerBedLeaveEvent event) {
|
|
||||||
Util util = new Util();
|
|
||||||
Config config = new Config();
|
|
||||||
Player p = event.getPlayer();
|
|
||||||
World w = p.getWorld();
|
|
||||||
|
|
||||||
ArrayList<Player> excluded = util.getExcluded(w);
|
|
||||||
|
|
||||||
// Decrement the sleeping count if player isn't excluded
|
|
||||||
if (!excluded.contains(p)) {
|
|
||||||
util.remove(w, p);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send a chat message when player gets out of bed (if it's not day)
|
|
||||||
if (config.getBoolean("messages.chat.chat") && (config.getString("messages.chat.left").length() != 0) && !(w.getTime() > 0 && w.getTime() < 12300) && !excluded.contains(p)) {
|
|
||||||
Bukkit.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.chat.left")
|
|
||||||
.replace("[sleeping]", String.valueOf(util.getSleeping(w))))
|
|
||||||
.replace("[online]", String.valueOf(util.getOnline(w)))
|
|
||||||
.replace("[player]", event.getPlayer().getName())
|
|
||||||
.replace("[needed]", String.valueOf(util.getNeeded(w))));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package mykyta.Harbor.Events;
|
|
||||||
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import mykyta.Harbor.Util;
|
|
||||||
|
|
||||||
public class ChatEvent implements Listener {
|
|
||||||
Util util = new Util();
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onChat(AsyncPlayerChatEvent event) {
|
|
||||||
util.updateActivity(event.getPlayer());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package mykyta.Harbor.Events;
|
|
||||||
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
|
||||||
import mykyta.Harbor.Util;
|
|
||||||
|
|
||||||
public class CommandEvent implements Listener {
|
|
||||||
Util util = new Util();
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onCommand(PlayerCommandPreprocessEvent event) {
|
|
||||||
util.updateActivity(event.getPlayer());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
package mykyta.Harbor.Events;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
||||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
|
||||||
import mykyta.Harbor.GUI.GUIType;
|
|
||||||
import mykyta.Harbor.Util;
|
|
||||||
import mykyta.Harbor.GUI.GUIHolder;
|
|
||||||
|
|
||||||
public class GUIEvent implements Listener {
|
|
||||||
Util util = new Util();
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onClick(InventoryClickEvent event) {
|
|
||||||
util.updateActivity((Player) event.getWhoClicked());
|
|
||||||
if (event.getInventory().getHolder() != null && event.getInventory().getHolder() instanceof GUIHolder) {
|
|
||||||
GUIType t = ((GUIHolder) event.getInventory().getHolder()).getType();
|
|
||||||
if (t.equals(GUIType.SLEEPING)) event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onDrag(InventoryDragEvent event) {
|
|
||||||
util.updateActivity((Player) event.getWhoClicked());
|
|
||||||
if (event.getInventory().getHolder() != null && event.getInventory().getHolder() instanceof GUIHolder) {
|
|
||||||
GUIType t = ((GUIHolder) event.getInventory().getHolder()).getType();
|
|
||||||
if (t.equals(GUIType.SLEEPING)) event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
package mykyta.Harbor.Events;
|
|
||||||
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
|
||||||
import mykyta.Harbor.Util;
|
|
||||||
|
|
||||||
public class Move implements Listener {
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerMovement(PlayerMoveEvent event) {
|
|
||||||
Util util = new Util();
|
|
||||||
util.updateActivity(event.getPlayer());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
package mykyta.Harbor.Events;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
|
|
||||||
import mykyta.Harbor.Config;
|
|
||||||
import mykyta.Harbor.Updater;
|
|
||||||
import mykyta.Harbor.Util;
|
|
||||||
|
|
||||||
public class PlayerJoin implements Listener {
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
|
||||||
Updater updater = new Updater();
|
|
||||||
Config config = new Config();
|
|
||||||
Util util = new Util();
|
|
||||||
|
|
||||||
String json = "[{\"text\":\"[prefix]§7Hey there, Harbor [version] was released! \"},{\"text\":\"§7§oClick §7§ome §7§oto §7§oupdate!\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/harbor update\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"§a§l↑ §7Update Harbor.\"}}]";
|
|
||||||
if (event.getPlayer().isOp() && updater.check() && config.getBoolean("features.notifier")) util.sendJSONMessage(event.getPlayer(), json.replace("[version]", updater.getLatest()).replace("[prefix]", config.getString("messages.miscellaneous.prefix")).replace("&", "§"));
|
|
||||||
if (!config.getVersion().equals(util.version)) event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix") + "&7The configuration is &nout of date!&7 This server is currently using configuration &oversion " + config.getVersion() + "&7, but the latest configuration is &oversion " + util.version + "&7. Make sure you update the configuration to ensure correct functionality of the plugin."));
|
|
||||||
Util.activity.put(event.getPlayer(), System.currentTimeMillis());
|
|
||||||
if (event.getPlayer().isOp() && Util.unreleased) event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix") + "&cThis Harbor version is a prerelease. Not everything is guaranteed to work correctly, but the plugin should at least be stable. "
|
|
||||||
+ "If you encounter an issue, please create an issue on GitHub: &c&ohttps://github.com/nkomarn/Harbor/issues&c."));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
package mykyta.Harbor.Events;
|
|
||||||
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import mykyta.Harbor.Util;
|
|
||||||
|
|
||||||
public class PlayerLeave implements Listener {
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
|
||||||
Util util = new Util();
|
|
||||||
Player p = event.getPlayer();
|
|
||||||
World w = p.getWorld();
|
|
||||||
|
|
||||||
new java.util.Timer().schedule(
|
|
||||||
new java.util.TimerTask() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (w.getPlayers().size() > 0 && Math.max(0, util.getNeeded(w) - util.getExcluded(w).size()) == 0 && !Util.skipping) util.skip(w);
|
|
||||||
Util.activity.remove(p);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
1000
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
package mykyta.Harbor.Events;
|
|
||||||
|
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
|
||||||
|
|
||||||
import mykyta.Harbor.Config;
|
|
||||||
|
|
||||||
public class Spawn implements Listener {
|
|
||||||
@EventHandler
|
|
||||||
public void onSpawn(CreatureSpawnEvent event) {
|
|
||||||
Config config = new Config();
|
|
||||||
try {
|
|
||||||
if (event.getEntityType().equals(EntityType.PHANTOM) && !config.getBoolean("features.phantoms")) event.setCancelled(true);
|
|
||||||
}
|
|
||||||
catch (NoSuchFieldError e) {
|
|
||||||
// Do nothing, Phantom only exists in 1.13+
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,63 +0,0 @@
|
|||||||
package mykyta.Harbor;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import mykyta.Harbor.Commands.Command;
|
|
||||||
import mykyta.Harbor.Commands.Sleeping;
|
|
||||||
import mykyta.Harbor.Events.BedEnter;
|
|
||||||
import mykyta.Harbor.Events.BedLeave;
|
|
||||||
import mykyta.Harbor.Events.ChatEvent;
|
|
||||||
import mykyta.Harbor.Events.CommandEvent;
|
|
||||||
import mykyta.Harbor.Events.GUIEvent;
|
|
||||||
import mykyta.Harbor.Events.Move;
|
|
||||||
import mykyta.Harbor.Events.PlayerJoin;
|
|
||||||
import mykyta.Harbor.Events.PlayerLeave;
|
|
||||||
import mykyta.Harbor.Events.Spawn;
|
|
||||||
|
|
||||||
public class Harbor extends JavaPlugin {
|
|
||||||
public void onEnable() {
|
|
||||||
Config config = new Config();
|
|
||||||
Util util = new Util();
|
|
||||||
config.setInstance(this);
|
|
||||||
saveDefaultConfig();
|
|
||||||
this.getCommand("harbor").setExecutor(new Command());
|
|
||||||
this.getCommand("sleeping").setExecutor(new Sleeping());
|
|
||||||
Bukkit.getPluginManager().registerEvents(new BedEnter(), this);
|
|
||||||
Bukkit.getPluginManager().registerEvents(new BedLeave(), this);
|
|
||||||
Bukkit.getPluginManager().registerEvents(new Move(), this);
|
|
||||||
Bukkit.getPluginManager().registerEvents(new Spawn(), this);
|
|
||||||
Bukkit.getPluginManager().registerEvents(new GUIEvent(), this);
|
|
||||||
Bukkit.getPluginManager().registerEvents(new PlayerJoin(), this);
|
|
||||||
Bukkit.getPluginManager().registerEvents(new PlayerLeave(), this);
|
|
||||||
Bukkit.getPluginManager().registerEvents(new CommandEvent(), this);
|
|
||||||
Bukkit.getPluginManager().registerEvents(new ChatEvent(), this);
|
|
||||||
util.setupNMS();
|
|
||||||
|
|
||||||
Bukkit.getServer().getWorlds().forEach(w -> {
|
|
||||||
ArrayList<Player> sleeping = new ArrayList<Player>();
|
|
||||||
Util.sleeping.put(w, sleeping);
|
|
||||||
w.getPlayers().forEach(p -> {
|
|
||||||
p.setPlayerListName(p.getName());
|
|
||||||
Util.activity.put(p, System.currentTimeMillis());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
if (Util.enabled) Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Task(), 0L, config.getInteger("values.clock") * 20);
|
|
||||||
if (this.getConfig().getBoolean("debug")) Util.debug = true;
|
|
||||||
if (Util.enabled && this.getConfig().getBoolean("features.notifier")) {
|
|
||||||
if (Util.debug) Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("messages.miscellaneous.prefix")) + "Checking for new updates...");
|
|
||||||
Updater updater = new Updater();
|
|
||||||
updater.check();
|
|
||||||
}
|
|
||||||
if (Util.unreleased) Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("messages.miscellaneous.prefix") + "&cThis Harbor version is a prerelease. Not everything is guaranteed to work correctly, but the plugin should at least be stable. "
|
|
||||||
+ "If you encounter an issue, please create an issue on GitHub: &c&ohttps://github.com/nkomarn/Harbor/issues&c."));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onDisable() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
package mykyta.Harbor.NMS;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public interface NMS {
|
|
||||||
public void sendActionbar(Player player, String message);
|
|
||||||
public void sendJSONMessage(Player player, String json);
|
|
||||||
public void sendTitle(Player player, String top, String bottom);
|
|
||||||
public void enterBed(Player player);
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
package mykyta.Harbor.NMS;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import net.minecraft.server.v1_8_R1.ChatSerializer;
|
|
||||||
import net.minecraft.server.v1_8_R1.EnumTitleAction;
|
|
||||||
import net.minecraft.server.v1_8_R1.IChatBaseComponent;
|
|
||||||
import net.minecraft.server.v1_8_R1.PacketPlayOutChat;
|
|
||||||
import net.minecraft.server.v1_8_R1.PacketPlayOutTitle;
|
|
||||||
|
|
||||||
public class NMS_1_8_R1 implements NMS {
|
|
||||||
@Override
|
|
||||||
public void sendActionbar(Player player, String message) {
|
|
||||||
IChatBaseComponent titleComponent = ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
|
|
||||||
PacketPlayOutChat titlePacket = new PacketPlayOutChat(titleComponent, (byte)2);
|
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(titlePacket);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendJSONMessage(Player player, String json) {
|
|
||||||
IChatBaseComponent component = ChatSerializer.a(json);
|
|
||||||
PacketPlayOutChat packet = new PacketPlayOutChat(component);
|
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendTitle(Player player, String top, String bottom) {
|
|
||||||
IChatBaseComponent titleTop = ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
|
|
||||||
IChatBaseComponent titleBottom = ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
|
|
||||||
PacketPlayOutTitle title = new PacketPlayOutTitle(EnumTitleAction.TITLE, titleTop);
|
|
||||||
PacketPlayOutTitle subtitle = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, titleBottom);
|
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
|
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void enterBed(Player player) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
package mykyta.Harbor;
|
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
|
|
||||||
public class Task implements Runnable {
|
|
||||||
|
|
||||||
Util util = new Util();
|
|
||||||
Config config = new Config();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
Bukkit.getServer().getWorlds().forEach(w -> {
|
|
||||||
if (w.getTime() >= 12516 && w.getTime() <= 12535 && config.getBoolean("messages.title.title")) w.getPlayers().forEach(p -> {
|
|
||||||
util.sendTitle(p, config.getString("messages.title.evening.top"), config.getString("messages.title.evening.bottom"));
|
|
||||||
});
|
|
||||||
if (util.getSleeping(w) > 0 && util.getNeeded(w) == 0 && !Util.skipping) {
|
|
||||||
util.skip(w);
|
|
||||||
}
|
|
||||||
if (util.getSleeping(w) > 0 && util.getSleeping(w) < util.getNeeded(w)) {w.getPlayers().forEach(p -> {util.sendActionbar(p, config.getString("messages.actionbar.sleeping"), w);});}
|
|
||||||
else if (util.getSleeping(w) == util.getNeeded(w) && util.getSleeping(w) > 0) {w.getPlayers().forEach(p -> {util.sendActionbar(p, config.getString("messages.actionbar.everyone"), w);});}
|
|
||||||
|
|
||||||
if (config.getBoolean("features.afk")) w.getPlayers().forEach(p -> {
|
|
||||||
if (TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis() - Util.activity.get(p)) >= config.getInteger("values.timeout")) {
|
|
||||||
if (Util.sleeping.get(w).contains(p)) {
|
|
||||||
Util.activity.put(p, System.currentTimeMillis());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!Util.afk.contains(p)) {
|
|
||||||
Util.afk.add(p);
|
|
||||||
p.setPlayerListName(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.afkprefix") + p.getName()));
|
|
||||||
if (config.getString("messages.chat.afk").length() > 0) Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.chat.afk")
|
|
||||||
.replace("[player]", p.getName())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
catch (Exception e) {if (Util.debug) e.printStackTrace();}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,104 +0,0 @@
|
|||||||
package mykyta.Harbor;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
|
||||||
|
|
||||||
public class Updater {
|
|
||||||
public static String latest = "";
|
|
||||||
public static ArrayList<String> releases = new ArrayList<String>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks for an update using the Spiget API
|
|
||||||
* @see https://spiget.org/
|
|
||||||
*/
|
|
||||||
public boolean check() {
|
|
||||||
ConsoleCommandSender c = Bukkit.getServer().getConsoleSender();
|
|
||||||
Util util = new Util();
|
|
||||||
Config config = new Config();
|
|
||||||
|
|
||||||
try {
|
|
||||||
URL url = new URL("https://api.spiget.org/v2/resources/60088/versions");
|
|
||||||
URLConnection request = url.openConnection();
|
|
||||||
request.addRequestProperty("User-Agent", "Harbor");
|
|
||||||
request.connect();
|
|
||||||
|
|
||||||
JsonParser parser = new JsonParser();
|
|
||||||
JsonElement element = parser.parse(new InputStreamReader((InputStream) request.getContent()));
|
|
||||||
JsonArray versions = element.getAsJsonArray();
|
|
||||||
|
|
||||||
versions.forEach(v -> {
|
|
||||||
JsonObject n = v.getAsJsonObject();
|
|
||||||
releases.add(n.get("name").getAsString());
|
|
||||||
});
|
|
||||||
|
|
||||||
latest = releases.get(releases.size() - 1);
|
|
||||||
|
|
||||||
if (util.version.equals(latest)) {
|
|
||||||
if (Util.debug) c.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix")) + "Currently running the latest version of Harbor.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (!releases.contains(util.version)) {
|
|
||||||
if (config.getBoolean("features.notifier")) c.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix")) + "Running an unreleased version of Harbor.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
latest = releases.get(releases.size() - 1);
|
|
||||||
if (config.getBoolean("features.notifier")) c.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix")) + "Currently running an outdated version of Harbor. The latest available release is version " + latest + ".");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
if (Util.debug) c.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix")) + "Failed to check for updated releases of Harbor.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replace the current Harbor version with the latest available release
|
|
||||||
*/
|
|
||||||
public int upgrade() {
|
|
||||||
ConsoleCommandSender c = Bukkit.getServer().getConsoleSender();
|
|
||||||
Config config = new Config();
|
|
||||||
Util util = new Util();
|
|
||||||
|
|
||||||
if (util.version.equals(latest) || !releases.contains(util.version)) return 2;
|
|
||||||
|
|
||||||
c.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix")) + "Downloading Harbor version " + latest + ".");
|
|
||||||
try {
|
|
||||||
String jar = new File(Updater.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getName();
|
|
||||||
new File("update").mkdir();
|
|
||||||
URL url = new URL("http://aqua.api.spiget.org/v2/resources/60088/download");
|
|
||||||
File f = new File("plugins" + File.separator + "update" + File.separator + jar);
|
|
||||||
FileUtils.copyURLToFile(url, f);
|
|
||||||
c.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix")) + "Harbor " + latest + " has been downloaded successfully and will be enabled after a server restart/reload.");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
c.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix")) + "Failed to update Harbor to version " + latest + ".");
|
|
||||||
if (Util.debug) e.printStackTrace();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the latest version number
|
|
||||||
*/
|
|
||||||
public String getLatest() {
|
|
||||||
return latest;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,244 +0,0 @@
|
|||||||
package mykyta.Harbor;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.GameMode;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import mykyta.Harbor.NMS.NMS;
|
|
||||||
import mykyta.Harbor.NMS.NMS_1_10_R1;
|
|
||||||
import mykyta.Harbor.NMS.NMS_1_11_R1;
|
|
||||||
import mykyta.Harbor.NMS.NMS_1_12_R1;
|
|
||||||
import mykyta.Harbor.NMS.NMS_1_13_R1;
|
|
||||||
import mykyta.Harbor.NMS.NMS_1_13_R2;
|
|
||||||
import mykyta.Harbor.NMS.NMS_1_14_R1;
|
|
||||||
import mykyta.Harbor.NMS.NMS_1_8_R1;
|
|
||||||
import mykyta.Harbor.NMS.NMS_1_8_R2;
|
|
||||||
import mykyta.Harbor.NMS.NMS_1_8_R3;
|
|
||||||
import mykyta.Harbor.NMS.NMS_1_9_R1;
|
|
||||||
import mykyta.Harbor.NMS.NMS_1_9_R2;
|
|
||||||
|
|
||||||
public class Util {
|
|
||||||
public static HashMap<World, ArrayList<Player>> sleeping = new HashMap<World, ArrayList<Player>>();
|
|
||||||
public static HashMap<Player, Long> activity = new HashMap<Player, Long>();
|
|
||||||
public static ArrayList<Player> afk = new ArrayList<Player>();
|
|
||||||
|
|
||||||
public final String version = "1.5";
|
|
||||||
public static boolean enabled = true;
|
|
||||||
public static boolean debug = false;
|
|
||||||
public static boolean unreleased = true;
|
|
||||||
public static boolean skipping = false;
|
|
||||||
private static NMS nms;
|
|
||||||
Config config = new Config();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Select the correct NMS classes for the server version
|
|
||||||
*/
|
|
||||||
public void setupNMS() {
|
|
||||||
String version = "";
|
|
||||||
try {version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];}
|
|
||||||
catch (ArrayIndexOutOfBoundsException e) {
|
|
||||||
Bukkit.getServer().getConsoleSender().sendMessage(config.getString("messages.miscellaneous.prefix") + "Could not get server version. The plugin may not function correctly as a result.");
|
|
||||||
if (debug) System.err.println(e);
|
|
||||||
Bukkit.getPluginManager().disablePlugin(Config.harbor);
|
|
||||||
enabled = false;
|
|
||||||
}
|
|
||||||
if (debug) Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix") + config.getString("messages.miscellaneous.running").replace("[version]", version)));
|
|
||||||
if (version.equals("v1_8_R1")) {nms = new NMS_1_8_R1();}
|
|
||||||
else if (version.equals("v1_8_R2")) {nms = new NMS_1_8_R2();}
|
|
||||||
else if (version.equals("v1_8_R3")) {nms = new NMS_1_8_R3();}
|
|
||||||
else if (version.equals("v1_9_R1")) {nms = new NMS_1_9_R1();}
|
|
||||||
else if (version.equals("v1_9_R2")) {nms = new NMS_1_9_R2();}
|
|
||||||
else if (version.equals("v1_10_R1")) {nms = new NMS_1_10_R1();}
|
|
||||||
else if (version.equals("v1_11_R1")) {nms = new NMS_1_11_R1();}
|
|
||||||
else if (version.equals("v1_12_R1")) {nms = new NMS_1_12_R1();}
|
|
||||||
else if (version.equals("v1_13_R1")) {nms = new NMS_1_13_R1();}
|
|
||||||
else if (version.equals("v1_13_R2")) {nms = new NMS_1_13_R2();}
|
|
||||||
else if (version.equals("v1_14_R1")) {nms = new NMS_1_14_R1();}
|
|
||||||
else {
|
|
||||||
Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix") + "This version of Harbor is incompatible with your server version. As such, Harbor will be disabled."));
|
|
||||||
Bukkit.getPluginManager().disablePlugin(Config.harbor);
|
|
||||||
enabled = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Increment the sleeping count for a world
|
|
||||||
* @param world World to increment count in
|
|
||||||
*/
|
|
||||||
public void add(World world, Player player) {
|
|
||||||
ArrayList<Player> list = Util.sleeping.get(world);
|
|
||||||
list.add(player);
|
|
||||||
Util.sleeping.put(world, list);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Decrement the sleeping count for a world
|
|
||||||
* @param world World to increment count in
|
|
||||||
*/
|
|
||||||
public void remove(World world, Player player) {
|
|
||||||
ArrayList<Player> list = Util.sleeping.get(world);
|
|
||||||
list.remove(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch the sleeping count for a world
|
|
||||||
* @param world World to fetch count for
|
|
||||||
*/
|
|
||||||
public int getSleeping(World w) {
|
|
||||||
try {return Math.max(0, Util.sleeping.get(w).size());}
|
|
||||||
catch (NullPointerException e) {return 0;}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch the amount of players needed to skip night
|
|
||||||
* @param world World to fetch count for
|
|
||||||
*/
|
|
||||||
public int getNeeded(World w) {
|
|
||||||
try {return Math.max(0, (int) Math.ceil((w.getPlayers().size() - getExcluded(w).size()) * (config.getDouble("values.percent") / 100) - this.getSleeping(w)));}
|
|
||||||
//try {return Math.max(0, (int) Math.ceil((w.getPlayers().size()) * (config.getDouble("values.percent") / 100) - this.getSleeping(w)));}
|
|
||||||
catch (NullPointerException e) {return 0;}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get players in a world (returns zero if negative)
|
|
||||||
* @param world World to check player count for
|
|
||||||
*/
|
|
||||||
public int getOnline(World w) {
|
|
||||||
try {return Math.max(0, w.getPlayers().size() - getExcluded(w).size());}
|
|
||||||
catch (NullPointerException e) {return 0;}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch the excluded players in a world
|
|
||||||
* @param world World to fetch count for
|
|
||||||
*/
|
|
||||||
public ArrayList<Player> getExcluded(World w) {
|
|
||||||
ArrayList<Player> excluded = new ArrayList<Player>();
|
|
||||||
w.getPlayers().forEach(p -> {
|
|
||||||
if (this.isExcluded(p)) excluded.add(p);
|
|
||||||
});
|
|
||||||
return excluded;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether or not a player should be excluded from the sleep count
|
|
||||||
* @param player Target player
|
|
||||||
*/
|
|
||||||
public boolean isExcluded(Player p) {
|
|
||||||
boolean state = false;
|
|
||||||
if (config.getBoolean("features.ignore")) if (p.getGameMode() == GameMode.SURVIVAL) state = false; else state = true;
|
|
||||||
if (config.getBoolean("features.bypass")) if (p.hasPermission("harbor.bypass")) state = true; else state = false;
|
|
||||||
if (afk.contains(p)) state = true;
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends an actionbar message to the given player
|
|
||||||
* @param player Player to show actionbar to
|
|
||||||
* @param message Actionbar message with color codes
|
|
||||||
*/
|
|
||||||
public void sendActionbar(Player player, String message) {
|
|
||||||
if (config.getBoolean("messages.actionbar.actionbar")) nms.sendActionbar(player, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends actionbar with world information
|
|
||||||
* @see sendActionbar(Player player, String message)
|
|
||||||
* @param player Player to show actionbar to
|
|
||||||
* @param message Actionbar message with color codes
|
|
||||||
* @param world World to fetch information for
|
|
||||||
*/
|
|
||||||
public void sendActionbar(Player p, String message, World w) {
|
|
||||||
if (config.getBoolean("messages.actionbar.actionbar")) nms.sendActionbar(p, message
|
|
||||||
.replace("[sleeping]", String.valueOf(this.getSleeping(w)))
|
|
||||||
.replace("[online]", String.valueOf(this.getOnline(w)))
|
|
||||||
.replace("[needed]", String.valueOf(this.getNeeded(w))));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends a custom JSON message to selected player
|
|
||||||
* @param player Player to send message to
|
|
||||||
* @param JSON Message in JSON format
|
|
||||||
*/
|
|
||||||
public void sendJSONMessage(Player player, String JSON) {
|
|
||||||
nms.sendJSONMessage(player, JSON);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends a title to selected player
|
|
||||||
* @param player Player to send message to
|
|
||||||
* @param JSON Message in JSON format
|
|
||||||
*/
|
|
||||||
public void sendTitle(Player player, String top, String bottom) {
|
|
||||||
nms.sendTitle(player, top, bottom);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Puts selected player in a sleeping state
|
|
||||||
* @param player Player to send message to
|
|
||||||
* @param JSON Message in JSON format
|
|
||||||
*/
|
|
||||||
public void enterBed(Player player) {
|
|
||||||
nms.enterBed(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Skips the night in the specified world (if possible)
|
|
||||||
* @param World to return value for
|
|
||||||
*/
|
|
||||||
public void skip(World w) {
|
|
||||||
if (config.getBoolean("features.skip") && Math.max(0, this.getNeeded(w) - this.getExcluded(w).size()) == 0) {
|
|
||||||
skipping = true;
|
|
||||||
|
|
||||||
new java.util.Timer().schedule (
|
|
||||||
new java.util.TimerTask() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
w.setTime(1000L);
|
|
||||||
|
|
||||||
// Set weather to clear
|
|
||||||
if (config.getBoolean("features.weather")) {
|
|
||||||
w.setStorm(false);
|
|
||||||
w.setThundering(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Display messages
|
|
||||||
if (config.getBoolean("messages.chat.chat") && (config.getString("messages.chat.skipped").length() != 0)) {
|
|
||||||
List<String> msgs = config.getList("messages.chat.skipped");
|
|
||||||
Random r = new Random();
|
|
||||||
int n = r.nextInt(msgs.size());
|
|
||||||
Bukkit.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', msgs.get(n)));
|
|
||||||
}
|
|
||||||
if (config.getBoolean("messages.title.title")) {
|
|
||||||
w.getPlayers().forEach(p -> {
|
|
||||||
sendTitle(p, config.getString("messages.title.morning.top"), config.getString("messages.title.morning.bottom"));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
skipping = false;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
1000 * config.getInteger("values.delay")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the current player activity (AFK system)
|
|
||||||
* @param p Player to update activity for
|
|
||||||
*/
|
|
||||||
public void updateActivity(Player p) {
|
|
||||||
if (afk.contains(p)) {
|
|
||||||
afk.remove(p);
|
|
||||||
p.setPlayerListName(ChatColor.translateAlternateColorCodes('&', p.getName()));
|
|
||||||
if (config.getString("messages.chat.unafk").length() > 0) Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.chat.unafk").replace("[player]", p.getName())));
|
|
||||||
}
|
|
||||||
activity.put(p, System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
}
|
|
70
src/main/java/xyz/nkomarn/Harbor/Harbor.java
Normal file
70
src/main/java/xyz/nkomarn/Harbor/Harbor.java
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
package xyz.nkomarn.Harbor;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import xyz.nkomarn.Harbor.command.HarborCommand;
|
||||||
|
import xyz.nkomarn.Harbor.command.SleepingCommand;
|
||||||
|
import xyz.nkomarn.Harbor.event.GUIEvent;
|
||||||
|
import xyz.nkomarn.Harbor.event.PlayerEvent;
|
||||||
|
import xyz.nkomarn.Harbor.event.SpawnEvent;
|
||||||
|
import xyz.nkomarn.Harbor.nms.NMSUtils;
|
||||||
|
import xyz.nkomarn.Harbor.task.Timer;
|
||||||
|
import xyz.nkomarn.Harbor.util.Config;
|
||||||
|
import xyz.nkomarn.Harbor.util.Counters;
|
||||||
|
import xyz.nkomarn.Harbor.util.Updater;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
public class Harbor extends JavaPlugin {
|
||||||
|
public static Harbor instance;
|
||||||
|
public static String version = "1.5.1";
|
||||||
|
public static boolean debug = false;
|
||||||
|
public static boolean enabled = false;
|
||||||
|
public static boolean prerelease = false;
|
||||||
|
|
||||||
|
private Config config = new Config();
|
||||||
|
private NMSUtils nms = new NMSUtils();
|
||||||
|
|
||||||
|
public void onEnable() {
|
||||||
|
saveDefaultConfig();
|
||||||
|
instance = this;
|
||||||
|
nms.setNMS();
|
||||||
|
|
||||||
|
final PluginManager pm = Bukkit.getPluginManager();
|
||||||
|
Stream.of(
|
||||||
|
new PlayerEvent(), new SpawnEvent(), new GUIEvent()
|
||||||
|
).forEach(l -> pm.registerEvents(l, this));
|
||||||
|
getCommand("harbor").setExecutor(new HarborCommand());
|
||||||
|
getCommand("sleeping").setExecutor(new SleepingCommand());
|
||||||
|
|
||||||
|
Bukkit.getServer().getWorlds().forEach(w -> {
|
||||||
|
ArrayList<Player> s = new ArrayList<>();
|
||||||
|
Counters.sleeping.put(w, s);
|
||||||
|
w.getPlayers().forEach(p -> {
|
||||||
|
p.setPlayerListName(p.getName());
|
||||||
|
Counters.activity.put(p, System.currentTimeMillis());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
if (enabled) Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Timer(), 0L, config.getInteger("values.clock") * 20);
|
||||||
|
if (getConfig().getBoolean("debug")) debug = true;
|
||||||
|
if (enabled && this.getConfig().getBoolean("features.notifier")) {
|
||||||
|
if (debug) Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||||
|
getConfig().getString("messages.miscellaneous.prefix")) + "Checking for new updates...");
|
||||||
|
if (!prerelease) {
|
||||||
|
Updater updater = new Updater();
|
||||||
|
updater.check();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (prerelease) Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("messages.miscellaneous.prefix") + "&cThis Harbor version is a prerelease. Not everything is guaranteed to work correctly, but the plugin should at least be stable. "
|
||||||
|
+ "If you encounter an issue, please create an issue on GitHub: &c&ohttps://github.com/nkomarn/Harbor/issues&c. You can download newer builds when they're available at &c&ohttps://harbor.nkomarn.xyz&c."));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onDisable() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
58
src/main/java/xyz/nkomarn/Harbor/command/HarborCommand.java
Normal file
58
src/main/java/xyz/nkomarn/Harbor/command/HarborCommand.java
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
package xyz.nkomarn.Harbor.command;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import xyz.nkomarn.Harbor.Harbor;
|
||||||
|
import xyz.nkomarn.Harbor.util.Config;
|
||||||
|
import xyz.nkomarn.Harbor.util.Updater;
|
||||||
|
|
||||||
|
public class HarborCommand implements CommandExecutor {
|
||||||
|
private Config c = new Config();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender s, Command x, String l, String[] a) {
|
||||||
|
if (a.length < 1) {
|
||||||
|
s.sendMessage(ChatColor.translateAlternateColorCodes('&', c
|
||||||
|
.getString("messages.miscellaneous.prefix") + "&7Version " + Harbor.version
|
||||||
|
+ " by TechToolbox (@nkomarn)."));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!s.hasPermission("harbor.admin")) {
|
||||||
|
s.sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||||
|
c.getString("messages.miscellaneous.prefix")
|
||||||
|
+ c.getString("messages.miscellaneous.permission")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (a[0].equalsIgnoreCase("reload")) {
|
||||||
|
try {
|
||||||
|
Harbor h = Harbor.instance;
|
||||||
|
h.reloadConfig();
|
||||||
|
Bukkit.getPluginManager().disablePlugin(h);
|
||||||
|
Bukkit.getPluginManager().enablePlugin(h);
|
||||||
|
s.sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||||
|
c.getString("messages.miscellaneous.prefix")
|
||||||
|
+ c.getString("messages.miscellaneous.reloaded")));
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
s.sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||||
|
c.getString("messages.miscellaneous.prefix")
|
||||||
|
+ c.getString("messages.miscellaneous.reloaderror")));
|
||||||
|
if (Harbor.debug) e.printStackTrace();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (a[0].equalsIgnoreCase("update")) {
|
||||||
|
Updater u = new Updater();
|
||||||
|
int result = u.upgrade();
|
||||||
|
if (result == 0) s.sendMessage(ChatColor.translateAlternateColorCodes('&', c.getString("messages.miscellaneous.prefix") + "&7Harbor was successfully updated to version " + Updater.latest + " and will be enabled after a server restart/reload."));
|
||||||
|
else if (result == 1) s.sendMessage(ChatColor.translateAlternateColorCodes('&', c.getString("messages.miscellaneous.prefix") + "&7An error occured while updating Harbor to version " + Updater.latest + ". Check the server console for more details."));
|
||||||
|
else if (result == 2) s.sendMessage(ChatColor.translateAlternateColorCodes('&', c.getString("messages.miscellaneous.prefix") + "&7This server is already running the latest version of Harbor. Great work!"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
s.sendMessage(ChatColor.translateAlternateColorCodes('&', c.getString("messages.miscellaneous.prefix") + c.getString("messages.miscellaneous.unrecognized")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
package xyz.nkomarn.Harbor.command;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import xyz.nkomarn.Harbor.gui.SleepingGUI;
|
||||||
|
import xyz.nkomarn.Harbor.util.Config;
|
||||||
|
import xyz.nkomarn.Harbor.util.Counters;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class SleepingCommand implements CommandExecutor {
|
||||||
|
private Config c = new Config();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender s, Command x, String l, String[] a) {
|
||||||
|
if (s instanceof Player) {
|
||||||
|
Player p = (Player) s;
|
||||||
|
new SleepingGUI(p, 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (a.length < 1) {
|
||||||
|
ArrayList<String> list = new ArrayList<>();
|
||||||
|
Bukkit.getServer().getWorlds().forEach(w -> {list.add("&o" + w.getName());});
|
||||||
|
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||||
|
c.getString("messages.miscellaneous.prefix")
|
||||||
|
+ "Specify a world name. Possible worlds are " + String.join("&r, ", list) + "&r."));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
World w = Bukkit.getServer().getWorld(a[0]);
|
||||||
|
if (w == null) Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', c.getString("messages.miscellaneous.prefix") + "The specified world doesn't exist."));
|
||||||
|
else {
|
||||||
|
ArrayList<String> list = new ArrayList<String>();
|
||||||
|
Counters.sleeping.get(Bukkit.getServer().getWorld(a[0])).forEach(p -> {list.add("&o" + p.getName());});
|
||||||
|
if (list.size() > 0 && list.size() != 1) Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', c.getString("messages.miscellaneous.prefix") + "In &o" + a[0] + "&r, the currently sleeping players are " + String.join("&r, ", list) + "&r."));
|
||||||
|
else if (list.size() == 1) Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', c.getString("messages.miscellaneous.prefix") + "In &o" + a[0] + "&r, " + list.get(0) + "&r is the only player sleeping."));
|
||||||
|
else Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', c.getString("messages.miscellaneous.prefix") + "There aren't any currently sleeping players in &o" + a[0] + "&r."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
37
src/main/java/xyz/nkomarn/Harbor/event/GUIEvent.java
Normal file
37
src/main/java/xyz/nkomarn/Harbor/event/GUIEvent.java
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package xyz.nkomarn.Harbor.event;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import xyz.nkomarn.Harbor.gui.GUIHolder;
|
||||||
|
import xyz.nkomarn.Harbor.gui.GUIType;
|
||||||
|
import xyz.nkomarn.Harbor.gui.SleepingGUI;
|
||||||
|
import xyz.nkomarn.Harbor.util.Counters;
|
||||||
|
|
||||||
|
public class GUIEvent implements Listener {
|
||||||
|
private Counters n = new Counters();
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onClick(InventoryClickEvent e) {
|
||||||
|
n.updateActivity((Player) e.getWhoClicked());
|
||||||
|
Inventory i = e.getInventory();
|
||||||
|
if (i.getHolder() != null && i.getHolder() instanceof GUIHolder) {
|
||||||
|
GUIType t = ((GUIHolder) i.getHolder()).getType();
|
||||||
|
final Player p = (Player) e.getWhoClicked();
|
||||||
|
e.setCancelled(true);
|
||||||
|
|
||||||
|
if (t.equals(GUIType.SLEEPING)) {
|
||||||
|
int page = ((GUIHolder) i.getHolder()).getPage();
|
||||||
|
if (e.getSlot() == 39) {
|
||||||
|
if (page <= 1) {e.getWhoClicked().closeInventory();}
|
||||||
|
else new SleepingGUI(p, Math.max(1, --page));
|
||||||
|
}
|
||||||
|
else if (e.getSlot() == 41) {
|
||||||
|
new SleepingGUI(p, Math.max(1, ++page));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
107
src/main/java/xyz/nkomarn/Harbor/event/PlayerEvent.java
Normal file
107
src/main/java/xyz/nkomarn/Harbor/event/PlayerEvent.java
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
package xyz.nkomarn.Harbor.event;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.*;
|
||||||
|
import xyz.nkomarn.Harbor.Harbor;
|
||||||
|
import xyz.nkomarn.Harbor.nms.NMSUtils;
|
||||||
|
import xyz.nkomarn.Harbor.util.Config;
|
||||||
|
import xyz.nkomarn.Harbor.util.Counters;
|
||||||
|
import xyz.nkomarn.Harbor.util.Updater;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class PlayerEvent implements Listener {
|
||||||
|
private Config config = new Config();
|
||||||
|
private NMSUtils nms = new NMSUtils();
|
||||||
|
private Counters counters = new Counters();
|
||||||
|
private Updater updater = new Updater();
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onJoin(PlayerJoinEvent e) {
|
||||||
|
Player p = e.getPlayer();
|
||||||
|
String json = "[{\"text\":\"[prefix]§7Hey there, Harbor [version] was released! \"},{\"text\":\"§7§oClick §7§ome §7§oto §7§oupdate!\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/harbor update\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"§a§l↑ §7Update Harbor.\"}}]";
|
||||||
|
if (p.isOp() && updater.check() && config.getBoolean("features.notifier")) nms.sendJSONMessage(p, json.replace("[version]", updater.getLatest()).replace("[prefix]", config.getString("messages.miscellaneous.prefix")).replace("&", "§"));
|
||||||
|
Counters.activity.put(p, System.currentTimeMillis());
|
||||||
|
if (p.isOp() && Harbor.prerelease) p.sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||||
|
config.getString("messages.miscellaneous.prefix") + "&cThis Harbor version is a prerelease. Not everything is guaranteed to work correctly, but the plugin should at least be stable. "
|
||||||
|
+ "If you encounter an issue, please create an issue on GitHub: &c&ohttps://github.com/nkomarn/Harbor/issues&c."));
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
|
public void onBedEnter(PlayerBedEnterEvent e) {
|
||||||
|
if (config.getBoolean("features.block")) {
|
||||||
|
if (config.getString("messages.chat.blocked").length() > 0) e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||||
|
config.getString("messages.chat.blocked")));
|
||||||
|
nms.sendActionbar(e.getPlayer(), config.getString("messages.actionbar.blocked"));
|
||||||
|
e.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean success = false;
|
||||||
|
try {if (e.getBedEnterResult() == PlayerBedEnterEvent.BedEnterResult.OK) success = true;}
|
||||||
|
catch (NoSuchMethodError nme) {success = true;}
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
Player p = e.getPlayer();
|
||||||
|
World w = p.getWorld();
|
||||||
|
ArrayList<Player> ex = counters.getExcluded(w);
|
||||||
|
|
||||||
|
if (!ex.contains(p)) {
|
||||||
|
counters.add(w, p);
|
||||||
|
if (config.getBoolean("messages.chat.chat") && (config.getString("messages.chat.sleeping").length() != 0)) {
|
||||||
|
Bukkit.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&',
|
||||||
|
config.getString("messages.chat.sleeping")
|
||||||
|
.replace("[sleeping]", String.valueOf(counters.getSleeping(w))))
|
||||||
|
.replace("[online]", String.valueOf(counters.getOnline(w)))
|
||||||
|
.replace("[player]", p.getName())
|
||||||
|
.replace("[needed]", String.valueOf(counters.getNeeded(w))));
|
||||||
|
}
|
||||||
|
if (config.getBoolean("messages.title.title")) {
|
||||||
|
nms.sendTitle(p, config.getString("messages.title.sleeping.top"),
|
||||||
|
config.getString("messages.title.sleeping.bottom"));
|
||||||
|
}
|
||||||
|
counters.skip(w);
|
||||||
|
}
|
||||||
|
else if (config.getString("messages.chat.bypass").length() != 0)
|
||||||
|
p.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.chat.bypass")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
|
public void onBedLeave(PlayerBedLeaveEvent e) {
|
||||||
|
Player p = e.getPlayer();
|
||||||
|
World w = p.getWorld();
|
||||||
|
|
||||||
|
ArrayList<Player> ex = counters.getExcluded(w);
|
||||||
|
if (!ex.contains(p)) counters.remove(w, p);
|
||||||
|
if (config.getBoolean("messages.chat.chat") && (config.getString("messages.chat.left").length() != 0)
|
||||||
|
&& !(w.getTime() > 0 && w.getTime() < 12300) && !ex.contains(p)) {
|
||||||
|
Bukkit.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.chat.left")
|
||||||
|
.replace("[sleeping]", String.valueOf(counters.getSleeping(w))))
|
||||||
|
.replace("[online]", String.valueOf(counters.getOnline(w)))
|
||||||
|
.replace("[player]", p.getName())
|
||||||
|
.replace("[needed]", String.valueOf(counters.getNeeded(w))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onChat(AsyncPlayerChatEvent e) {
|
||||||
|
counters.updateActivity(e.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onCommand(PlayerCommandPreprocessEvent e) {
|
||||||
|
counters.updateActivity(e.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onMove(PlayerMoveEvent e) {
|
||||||
|
counters.updateActivity(e.getPlayer());
|
||||||
|
}
|
||||||
|
}
|
21
src/main/java/xyz/nkomarn/Harbor/event/SpawnEvent.java
Normal file
21
src/main/java/xyz/nkomarn/Harbor/event/SpawnEvent.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package xyz.nkomarn.Harbor.event;
|
||||||
|
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||||
|
import xyz.nkomarn.Harbor.util.Config;
|
||||||
|
|
||||||
|
public class SpawnEvent implements Listener {
|
||||||
|
private Config c = new Config();
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onSpawn(EntitySpawnEvent e) {
|
||||||
|
Config config = new Config();
|
||||||
|
try {if (e.getEntityType().equals(EntityType.PHANTOM)
|
||||||
|
&& !config.getBoolean("features.phantoms")) e.setCancelled(true);}
|
||||||
|
catch (NoSuchFieldError nsf) {
|
||||||
|
// Do nothing, Phantom only exists in 1.13+
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package mykyta.Harbor.GUI;
|
package xyz.nkomarn.Harbor.gui;
|
||||||
|
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
@ -6,17 +6,23 @@ import org.bukkit.inventory.InventoryHolder;
|
|||||||
public class GUIHolder implements InventoryHolder {
|
public class GUIHolder implements InventoryHolder {
|
||||||
private Inventory inv;
|
private Inventory inv;
|
||||||
private GUIType type;
|
private GUIType type;
|
||||||
|
private int page;
|
||||||
|
|
||||||
public GUIHolder(GUIType type) {
|
public GUIHolder(GUIType type, int page) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
this.page = page;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Inventory getInventory() {
|
public Inventory getInventory() {
|
||||||
return inv; // Required by InventoryHolder
|
return inv;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GUIType getType() {
|
public GUIType getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getPage() {
|
||||||
|
return this.page;
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package mykyta.Harbor.GUI;
|
package xyz.nkomarn.Harbor.gui;
|
||||||
|
|
||||||
public enum GUIType {
|
public enum GUIType {
|
||||||
SLEEPING
|
SLEEPING
|
62
src/main/java/xyz/nkomarn/Harbor/gui/SleepingGUI.java
Normal file
62
src/main/java/xyz/nkomarn/Harbor/gui/SleepingGUI.java
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
package xyz.nkomarn.Harbor.gui;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.inventory.meta.SkullMeta;
|
||||||
|
import xyz.nkomarn.Harbor.gui.GUIHolder;
|
||||||
|
import xyz.nkomarn.Harbor.gui.GUIType;
|
||||||
|
import xyz.nkomarn.Harbor.util.Config;
|
||||||
|
import xyz.nkomarn.Harbor.util.Counters;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class SleepingGUI {
|
||||||
|
|
||||||
|
private Inventory i;
|
||||||
|
Config c = new Config();
|
||||||
|
|
||||||
|
public SleepingGUI(Player p, int page) {
|
||||||
|
ArrayList<Player> s = Counters.sleeping.get(p.getWorld());
|
||||||
|
i = Bukkit.createInventory(new GUIHolder(GUIType.SLEEPING, page),
|
||||||
|
45, c.getString("gui.sleeping").replace("[page]", String.valueOf(page)));
|
||||||
|
|
||||||
|
ItemStack glass = new ItemStack(Material.WHITE_STAINED_GLASS_PANE, 1);
|
||||||
|
ItemMeta glassMeta = glass.getItemMeta();
|
||||||
|
glassMeta.setDisplayName(" ");
|
||||||
|
glass.setItemMeta(glassMeta);
|
||||||
|
int[] slots = {36, 37, 38, 40, 42, 43, 44};
|
||||||
|
for (int x = 0; x < slots.length; x++) {i.setItem(slots[x], glass);}
|
||||||
|
|
||||||
|
ItemStack bb = new ItemStack(Material.OAK_BUTTON, 1);
|
||||||
|
ItemMeta bbm = bb.getItemMeta();
|
||||||
|
bbm.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&6&lPrevious"));
|
||||||
|
bb.setItemMeta(bbm);
|
||||||
|
i.setItem(39, bb);
|
||||||
|
|
||||||
|
ItemStack nb = new ItemStack(Material.OAK_BUTTON, 1);
|
||||||
|
ItemMeta nbm = nb.getItemMeta();
|
||||||
|
nbm.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&6&lNext"));
|
||||||
|
nb.setItemMeta(nbm);
|
||||||
|
i.setItem(41, nb);
|
||||||
|
|
||||||
|
int f = (((page - 1) * 35) + (page + 1) - 1) - 1;
|
||||||
|
int l = Math.min(s.size(), (f + 36));
|
||||||
|
|
||||||
|
int t = 0;
|
||||||
|
for (int c = f; c < l; c++) {
|
||||||
|
ItemStack item = new ItemStack(Material.PLAYER_HEAD, 1);
|
||||||
|
SkullMeta sm = (SkullMeta) item.getItemMeta();
|
||||||
|
sm.setDisplayName(ChatColor.GRAY + s.get(c).getName());
|
||||||
|
sm.setOwningPlayer(p);
|
||||||
|
item.setItemMeta(sm);
|
||||||
|
i.setItem(s.indexOf(s.get(c)), item);
|
||||||
|
t++;
|
||||||
|
}
|
||||||
|
p.openInventory(i);
|
||||||
|
}
|
||||||
|
}
|
9
src/main/java/xyz/nkomarn/Harbor/nms/NMS.java
Normal file
9
src/main/java/xyz/nkomarn/Harbor/nms/NMS.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package xyz.nkomarn.Harbor.nms;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public interface NMS {
|
||||||
|
void sendActionbar(Player p, String m);
|
||||||
|
void sendJSONMessage(Player p, String j);
|
||||||
|
void sendTitle(Player p, String t, String n);
|
||||||
|
}
|
61
src/main/java/xyz/nkomarn/Harbor/nms/NMSUtils.java
Normal file
61
src/main/java/xyz/nkomarn/Harbor/nms/NMSUtils.java
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
package xyz.nkomarn.Harbor.nms;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import xyz.nkomarn.Harbor.Harbor;
|
||||||
|
import xyz.nkomarn.Harbor.nms.NMS;
|
||||||
|
import xyz.nkomarn.Harbor.util.Config;
|
||||||
|
import xyz.nkomarn.Harbor.util.Counters;
|
||||||
|
|
||||||
|
public class NMSUtils {
|
||||||
|
|
||||||
|
static Counters n = new Counters();
|
||||||
|
static Config c = new Config();
|
||||||
|
static NMS nms;
|
||||||
|
|
||||||
|
public void setNMS() {
|
||||||
|
String v = "";
|
||||||
|
try {v = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];}
|
||||||
|
catch (ArrayIndexOutOfBoundsException e) {
|
||||||
|
Bukkit.getServer().getConsoleSender().sendMessage(c.getString("messages.miscellaneous.prefix") + "Could not get server version. The plugin may not function correctly as a result.");
|
||||||
|
if (Harbor.debug) e.printStackTrace();
|
||||||
|
Bukkit.getPluginManager().disablePlugin(Harbor.instance);
|
||||||
|
Harbor.enabled = false;
|
||||||
|
}
|
||||||
|
if (Harbor.debug) Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', c.getString("messages.miscellaneous.prefix") + c.getString("messages.miscellaneous.running").replace("[version]", v)));
|
||||||
|
if (v.equals("v1_8_R1")) {nms = new NMS_1_8_R1();}
|
||||||
|
else if (v.equals("v1_8_R2")) {nms = new NMS_1_8_R2();}
|
||||||
|
else if (v.equals("v1_8_R3")) {nms = new NMS_1_8_R3();}
|
||||||
|
else if (v.equals("v1_9_R1")) {nms = new NMS_1_9_R1();}
|
||||||
|
else if (v.equals("v1_9_R2")) {nms = new NMS_1_9_R2();}
|
||||||
|
else if (v.equals("v1_10_R1")) {nms = new NMS_1_10_R1();}
|
||||||
|
else if (v.equals("v1_11_R1")) {nms = new NMS_1_11_R1();}
|
||||||
|
else if (v.equals("v1_12_R1")) {nms = new NMS_1_12_R1();}
|
||||||
|
else if (v.equals("v1_13_R1")) {nms = new NMS_1_13_R1();}
|
||||||
|
else if (v.equals("v1_13_R2")) {nms = new NMS_1_13_R2();}
|
||||||
|
else if (v.equals("v1_14_R1")) {nms = new NMS_1_14_R1();}
|
||||||
|
else {
|
||||||
|
Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', c.getString("messages.miscellaneous.prefix") + "This version of Harbor is incompatible with your server version. As such, Harbor will be disabled."));
|
||||||
|
Bukkit.getPluginManager().disablePlugin(Harbor.instance);
|
||||||
|
Harbor.enabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendActionbar(Player player, String message) {
|
||||||
|
if (c.getBoolean("messages.actionbar.actionbar")) nms.sendActionbar(player, message);
|
||||||
|
}
|
||||||
|
public void sendActionbar(Player p, String message, World w) {
|
||||||
|
if (c.getBoolean("messages.actionbar.actionbar")) nms.sendActionbar(p, message
|
||||||
|
.replace("[sleeping]", String.valueOf(n.getSleeping(w)))
|
||||||
|
.replace("[online]", String.valueOf(n.getOnline(w)))
|
||||||
|
.replace("[needed]", String.valueOf(n.getNeeded(w))));
|
||||||
|
}
|
||||||
|
public void sendJSONMessage(Player p, String j) {
|
||||||
|
nms.sendJSONMessage(p, j);
|
||||||
|
}
|
||||||
|
public void sendTitle(Player p, String t, String b) {
|
||||||
|
nms.sendTitle(p, t, b);
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package mykyta.Harbor.NMS;
|
package xyz.nkomarn.Harbor.nms;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
|
||||||
@ -10,22 +10,19 @@ import net.minecraft.server.v1_10_R1.PacketPlayOutTitle;
|
|||||||
import net.minecraft.server.v1_10_R1.IChatBaseComponent.ChatSerializer;
|
import net.minecraft.server.v1_10_R1.IChatBaseComponent.ChatSerializer;
|
||||||
import net.minecraft.server.v1_10_R1.PacketPlayOutTitle.EnumTitleAction;
|
import net.minecraft.server.v1_10_R1.PacketPlayOutTitle.EnumTitleAction;
|
||||||
|
|
||||||
public class NMS_1_10_R1 implements NMS {
|
class NMS_1_10_R1 implements NMS {
|
||||||
@Override
|
|
||||||
public void sendActionbar(Player player, String message) {
|
public void sendActionbar(Player player, String message) {
|
||||||
IChatBaseComponent titleComponent = ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
|
IChatBaseComponent titleComponent = ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
|
||||||
PacketPlayOutChat titlePacket = new PacketPlayOutChat(titleComponent, (byte)2);
|
PacketPlayOutChat titlePacket = new PacketPlayOutChat(titleComponent, (byte)2);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(titlePacket);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(titlePacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendJSONMessage(Player player, String json) {
|
public void sendJSONMessage(Player player, String json) {
|
||||||
IChatBaseComponent component = ChatSerializer.a(json);
|
IChatBaseComponent component = ChatSerializer.a(json);
|
||||||
PacketPlayOutChat packet = new PacketPlayOutChat(component);
|
PacketPlayOutChat packet = new PacketPlayOutChat(component);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendTitle(Player player, String top, String bottom) {
|
public void sendTitle(Player player, String top, String bottom) {
|
||||||
IChatBaseComponent titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
|
IChatBaseComponent titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
|
||||||
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
|
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
|
||||||
@ -34,9 +31,4 @@ public class NMS_1_10_R1 implements NMS {
|
|||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void enterBed(Player player) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package mykyta.Harbor.NMS;
|
package xyz.nkomarn.Harbor.nms;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
|
||||||
@ -10,22 +10,19 @@ import net.minecraft.server.v1_11_R1.PacketPlayOutTitle;
|
|||||||
import net.minecraft.server.v1_11_R1.IChatBaseComponent.ChatSerializer;
|
import net.minecraft.server.v1_11_R1.IChatBaseComponent.ChatSerializer;
|
||||||
import net.minecraft.server.v1_11_R1.PacketPlayOutTitle.EnumTitleAction;
|
import net.minecraft.server.v1_11_R1.PacketPlayOutTitle.EnumTitleAction;
|
||||||
|
|
||||||
public class NMS_1_11_R1 implements NMS {
|
class NMS_1_11_R1 implements NMS {
|
||||||
@Override
|
|
||||||
public void sendActionbar(Player player, String message) {
|
public void sendActionbar(Player player, String message) {
|
||||||
IChatBaseComponent titleComponent = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
|
IChatBaseComponent titleComponent = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
|
||||||
PacketPlayOutTitle titlePacket = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.ACTIONBAR, titleComponent);
|
PacketPlayOutTitle titlePacket = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.ACTIONBAR, titleComponent);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(titlePacket);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(titlePacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendJSONMessage(Player player, String json) {
|
public void sendJSONMessage(Player player, String json) {
|
||||||
IChatBaseComponent component = ChatSerializer.a(json);
|
IChatBaseComponent component = ChatSerializer.a(json);
|
||||||
PacketPlayOutChat packet = new PacketPlayOutChat(component);
|
PacketPlayOutChat packet = new PacketPlayOutChat(component);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendTitle(Player player, String top, String bottom) {
|
public void sendTitle(Player player, String top, String bottom) {
|
||||||
IChatBaseComponent titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
|
IChatBaseComponent titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
|
||||||
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
|
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
|
||||||
@ -34,9 +31,4 @@ public class NMS_1_11_R1 implements NMS {
|
|||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void enterBed(Player player) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package mykyta.Harbor.NMS;
|
package xyz.nkomarn.Harbor.nms;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
|
||||||
@ -10,22 +10,19 @@ import net.minecraft.server.v1_12_R1.PacketPlayOutTitle;
|
|||||||
import net.minecraft.server.v1_12_R1.IChatBaseComponent.ChatSerializer;
|
import net.minecraft.server.v1_12_R1.IChatBaseComponent.ChatSerializer;
|
||||||
import net.minecraft.server.v1_12_R1.PacketPlayOutTitle.EnumTitleAction;
|
import net.minecraft.server.v1_12_R1.PacketPlayOutTitle.EnumTitleAction;
|
||||||
|
|
||||||
public class NMS_1_12_R1 implements NMS {
|
class NMS_1_12_R1 implements NMS {
|
||||||
@Override
|
|
||||||
public void sendActionbar(Player player, String message) {
|
public void sendActionbar(Player player, String message) {
|
||||||
IChatBaseComponent titleComponent = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
|
IChatBaseComponent titleComponent = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
|
||||||
PacketPlayOutTitle titlePacket = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.ACTIONBAR, titleComponent);
|
PacketPlayOutTitle titlePacket = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.ACTIONBAR, titleComponent);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(titlePacket);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(titlePacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendJSONMessage(Player player, String json) {
|
public void sendJSONMessage(Player player, String json) {
|
||||||
IChatBaseComponent component = ChatSerializer.a(json);
|
IChatBaseComponent component = ChatSerializer.a(json);
|
||||||
PacketPlayOutChat packet = new PacketPlayOutChat(component);
|
PacketPlayOutChat packet = new PacketPlayOutChat(component);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendTitle(Player player, String top, String bottom) {
|
public void sendTitle(Player player, String top, String bottom) {
|
||||||
IChatBaseComponent titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
|
IChatBaseComponent titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
|
||||||
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
|
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
|
||||||
@ -34,9 +31,4 @@ public class NMS_1_12_R1 implements NMS {
|
|||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void enterBed(Player player) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package mykyta.Harbor.NMS;
|
package xyz.nkomarn.Harbor.nms;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.craftbukkit.v1_13_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_13_R1.entity.CraftPlayer;
|
||||||
@ -10,22 +10,19 @@ import net.minecraft.server.v1_13_R1.PacketPlayOutTitle;
|
|||||||
import net.minecraft.server.v1_13_R1.IChatBaseComponent.ChatSerializer;
|
import net.minecraft.server.v1_13_R1.IChatBaseComponent.ChatSerializer;
|
||||||
import net.minecraft.server.v1_13_R1.PacketPlayOutTitle.EnumTitleAction;
|
import net.minecraft.server.v1_13_R1.PacketPlayOutTitle.EnumTitleAction;
|
||||||
|
|
||||||
public class NMS_1_13_R1 implements NMS {
|
class NMS_1_13_R1 implements NMS {
|
||||||
@Override
|
|
||||||
public void sendActionbar(Player player, String message) {
|
public void sendActionbar(Player player, String message) {
|
||||||
IChatBaseComponent titleComponent = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
|
IChatBaseComponent titleComponent = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
|
||||||
PacketPlayOutTitle titlePacket = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.ACTIONBAR, titleComponent);
|
PacketPlayOutTitle titlePacket = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.ACTIONBAR, titleComponent);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(titlePacket);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(titlePacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendJSONMessage(Player player, String json) {
|
public void sendJSONMessage(Player player, String json) {
|
||||||
IChatBaseComponent component = ChatSerializer.a(json);
|
IChatBaseComponent component = ChatSerializer.a(json);
|
||||||
PacketPlayOutChat packet = new PacketPlayOutChat(component);
|
PacketPlayOutChat packet = new PacketPlayOutChat(component);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendTitle(Player player, String top, String bottom) {
|
public void sendTitle(Player player, String top, String bottom) {
|
||||||
IChatBaseComponent titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
|
IChatBaseComponent titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
|
||||||
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
|
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
|
||||||
@ -34,9 +31,4 @@ public class NMS_1_13_R1 implements NMS {
|
|||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void enterBed(Player player) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package mykyta.Harbor.NMS;
|
package xyz.nkomarn.Harbor.nms;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer;
|
||||||
@ -11,22 +11,19 @@ import net.minecraft.server.v1_13_R2.PacketPlayOutTitle;
|
|||||||
import net.minecraft.server.v1_13_R2.IChatBaseComponent.ChatSerializer;
|
import net.minecraft.server.v1_13_R2.IChatBaseComponent.ChatSerializer;
|
||||||
import net.minecraft.server.v1_13_R2.PacketPlayOutTitle.EnumTitleAction;
|
import net.minecraft.server.v1_13_R2.PacketPlayOutTitle.EnumTitleAction;
|
||||||
|
|
||||||
public class NMS_1_13_R2 implements NMS {
|
class NMS_1_13_R2 implements NMS {
|
||||||
@Override
|
|
||||||
public void sendActionbar(Player player, String message) {
|
public void sendActionbar(Player player, String message) {
|
||||||
IChatBaseComponent titleComponent = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
|
IChatBaseComponent titleComponent = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
|
||||||
PacketPlayOutTitle titlePacket = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.ACTIONBAR, titleComponent);
|
PacketPlayOutTitle titlePacket = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.ACTIONBAR, titleComponent);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(titlePacket);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(titlePacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendJSONMessage(Player player, String json) {
|
public void sendJSONMessage(Player player, String json) {
|
||||||
IChatBaseComponent component = ChatSerializer.a(json);
|
IChatBaseComponent component = ChatSerializer.a(json);
|
||||||
PacketPlayOutChat packet = new PacketPlayOutChat(component);
|
PacketPlayOutChat packet = new PacketPlayOutChat(component);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendTitle(Player player, String top, String bottom) {
|
public void sendTitle(Player player, String top, String bottom) {
|
||||||
IChatBaseComponent titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
|
IChatBaseComponent titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
|
||||||
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
|
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
|
||||||
@ -35,11 +32,4 @@ public class NMS_1_13_R2 implements NMS {
|
|||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void enterBed(Player player) {
|
|
||||||
PacketPlayOutBed sleep = new PacketPlayOutBed();
|
|
||||||
((CraftPlayer)player).getHandle().a(true, true, false);
|
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(sleep);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package mykyta.Harbor.NMS;
|
package xyz.nkomarn.Harbor.nms;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer;
|
||||||
@ -10,22 +10,19 @@ import net.minecraft.server.v1_14_R1.PacketPlayOutChat;
|
|||||||
import net.minecraft.server.v1_14_R1.PacketPlayOutTitle;
|
import net.minecraft.server.v1_14_R1.PacketPlayOutTitle;
|
||||||
import net.minecraft.server.v1_14_R1.PacketPlayOutTitle.EnumTitleAction;
|
import net.minecraft.server.v1_14_R1.PacketPlayOutTitle.EnumTitleAction;
|
||||||
|
|
||||||
public class NMS_1_14_R1 implements NMS {
|
class NMS_1_14_R1 implements NMS {
|
||||||
@Override
|
|
||||||
public void sendActionbar(Player player, String message) {
|
public void sendActionbar(Player player, String message) {
|
||||||
IChatBaseComponent titleComponent = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
|
IChatBaseComponent titleComponent = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
|
||||||
PacketPlayOutTitle titlePacket = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.ACTIONBAR, titleComponent);
|
PacketPlayOutTitle titlePacket = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.ACTIONBAR, titleComponent);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(titlePacket);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(titlePacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendJSONMessage(Player player, String json) {
|
public void sendJSONMessage(Player player, String json) {
|
||||||
IChatBaseComponent component = ChatSerializer.a(json);
|
IChatBaseComponent component = ChatSerializer.a(json);
|
||||||
PacketPlayOutChat packet = new PacketPlayOutChat(component);
|
PacketPlayOutChat packet = new PacketPlayOutChat(component);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendTitle(Player player, String top, String bottom) {
|
public void sendTitle(Player player, String top, String bottom) {
|
||||||
IChatBaseComponent titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
|
IChatBaseComponent titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
|
||||||
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
|
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
|
||||||
@ -34,9 +31,4 @@ public class NMS_1_14_R1 implements NMS {
|
|||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void enterBed(Player player) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
35
src/main/java/xyz/nkomarn/Harbor/nms/NMS_1_8_R1.java
Normal file
35
src/main/java/xyz/nkomarn/Harbor/nms/NMS_1_8_R1.java
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package xyz.nkomarn.Harbor.nms;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_8_R1.ChatSerializer;
|
||||||
|
import net.minecraft.server.v1_8_R1.EnumTitleAction;
|
||||||
|
import net.minecraft.server.v1_8_R1.IChatBaseComponent;
|
||||||
|
import net.minecraft.server.v1_8_R1.PacketPlayOutChat;
|
||||||
|
import net.minecraft.server.v1_8_R1.PacketPlayOutTitle;
|
||||||
|
import xyz.nkomarn.Harbor.nms.NMS;
|
||||||
|
|
||||||
|
class NMS_1_8_R1 implements NMS {
|
||||||
|
public void sendActionbar(Player p, String m) {
|
||||||
|
IChatBaseComponent tc = ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', m) + "\"}");
|
||||||
|
PacketPlayOutChat tp = new PacketPlayOutChat(tc, (byte) 2);
|
||||||
|
((CraftPlayer) p).getHandle().playerConnection.sendPacket(tp);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendJSONMessage(Player p, String j) {
|
||||||
|
IChatBaseComponent c = ChatSerializer.a(j);
|
||||||
|
PacketPlayOutChat packet = new PacketPlayOutChat(c);
|
||||||
|
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendTitle(Player p, String t, String b) {
|
||||||
|
IChatBaseComponent tt = ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', t) + "\"}");
|
||||||
|
IChatBaseComponent tm = ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', b) + "\"}");
|
||||||
|
PacketPlayOutTitle x = new PacketPlayOutTitle(EnumTitleAction.TITLE, tt);
|
||||||
|
PacketPlayOutTitle y = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, tm);
|
||||||
|
((CraftPlayer) p).getHandle().playerConnection.sendPacket(x);
|
||||||
|
((CraftPlayer) p).getHandle().playerConnection.sendPacket(y);
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package mykyta.Harbor.NMS;
|
package xyz.nkomarn.Harbor.nms;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
|
||||||
@ -9,23 +9,21 @@ import net.minecraft.server.v1_8_R2.IChatBaseComponent.ChatSerializer;
|
|||||||
import net.minecraft.server.v1_8_R2.PacketPlayOutChat;
|
import net.minecraft.server.v1_8_R2.PacketPlayOutChat;
|
||||||
import net.minecraft.server.v1_8_R2.PacketPlayOutTitle;
|
import net.minecraft.server.v1_8_R2.PacketPlayOutTitle;
|
||||||
import net.minecraft.server.v1_8_R2.PacketPlayOutTitle.EnumTitleAction;
|
import net.minecraft.server.v1_8_R2.PacketPlayOutTitle.EnumTitleAction;
|
||||||
|
import xyz.nkomarn.Harbor.nms.NMS;
|
||||||
|
|
||||||
public class NMS_1_8_R2 implements NMS {
|
class NMS_1_8_R2 implements NMS {
|
||||||
@Override
|
|
||||||
public void sendActionbar(Player player, String message) {
|
public void sendActionbar(Player player, String message) {
|
||||||
IChatBaseComponent titleComponent = ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
|
IChatBaseComponent titleComponent = ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
|
||||||
PacketPlayOutChat titlePacket = new PacketPlayOutChat(titleComponent, (byte)2);
|
PacketPlayOutChat titlePacket = new PacketPlayOutChat(titleComponent, (byte) 2);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(titlePacket);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(titlePacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendJSONMessage(Player player, String json) {
|
public void sendJSONMessage(Player player, String json) {
|
||||||
IChatBaseComponent component = ChatSerializer.a(json);
|
IChatBaseComponent component = ChatSerializer.a(json);
|
||||||
PacketPlayOutChat packet = new PacketPlayOutChat(component);
|
PacketPlayOutChat packet = new PacketPlayOutChat(component);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendTitle(Player player, String top, String bottom) {
|
public void sendTitle(Player player, String top, String bottom) {
|
||||||
IChatBaseComponent titleTop = ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
|
IChatBaseComponent titleTop = ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
|
||||||
IChatBaseComponent titleBottom = ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
|
IChatBaseComponent titleBottom = ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
|
||||||
@ -34,9 +32,4 @@ public class NMS_1_8_R2 implements NMS {
|
|||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void enterBed(Player player) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package mykyta.Harbor.NMS;
|
package xyz.nkomarn.Harbor.nms;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||||
@ -9,23 +9,21 @@ import net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer;
|
|||||||
import net.minecraft.server.v1_8_R3.PacketPlayOutChat;
|
import net.minecraft.server.v1_8_R3.PacketPlayOutChat;
|
||||||
import net.minecraft.server.v1_8_R3.PacketPlayOutTitle;
|
import net.minecraft.server.v1_8_R3.PacketPlayOutTitle;
|
||||||
import net.minecraft.server.v1_8_R3.PacketPlayOutTitle.EnumTitleAction;
|
import net.minecraft.server.v1_8_R3.PacketPlayOutTitle.EnumTitleAction;
|
||||||
|
import xyz.nkomarn.Harbor.nms.NMS;
|
||||||
|
|
||||||
public class NMS_1_8_R3 implements NMS {
|
class NMS_1_8_R3 implements NMS {
|
||||||
@Override
|
|
||||||
public void sendActionbar(Player player, String message) {
|
public void sendActionbar(Player player, String message) {
|
||||||
IChatBaseComponent titleComponent = ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
|
IChatBaseComponent titleComponent = ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
|
||||||
PacketPlayOutChat titlePacket = new PacketPlayOutChat(titleComponent, (byte)2);
|
PacketPlayOutChat titlePacket = new PacketPlayOutChat(titleComponent, (byte)2);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(titlePacket);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(titlePacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendJSONMessage(Player player, String json) {
|
public void sendJSONMessage(Player player, String json) {
|
||||||
IChatBaseComponent component = ChatSerializer.a(json);
|
IChatBaseComponent component = ChatSerializer.a(json);
|
||||||
PacketPlayOutChat packet = new PacketPlayOutChat(component);
|
PacketPlayOutChat packet = new PacketPlayOutChat(component);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendTitle(Player player, String top, String bottom) {
|
public void sendTitle(Player player, String top, String bottom) {
|
||||||
IChatBaseComponent titleTop = ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
|
IChatBaseComponent titleTop = ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
|
||||||
IChatBaseComponent titleBottom = ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
|
IChatBaseComponent titleBottom = ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
|
||||||
@ -34,9 +32,4 @@ public class NMS_1_8_R3 implements NMS {
|
|||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void enterBed(Player player) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package mykyta.Harbor.NMS;
|
package xyz.nkomarn.Harbor.nms;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
|
||||||
@ -9,23 +9,21 @@ import net.minecraft.server.v1_9_R1.PacketPlayOutChat;
|
|||||||
import net.minecraft.server.v1_9_R1.PacketPlayOutTitle;
|
import net.minecraft.server.v1_9_R1.PacketPlayOutTitle;
|
||||||
import net.minecraft.server.v1_9_R1.IChatBaseComponent.ChatSerializer;
|
import net.minecraft.server.v1_9_R1.IChatBaseComponent.ChatSerializer;
|
||||||
import net.minecraft.server.v1_9_R1.PacketPlayOutTitle.EnumTitleAction;
|
import net.minecraft.server.v1_9_R1.PacketPlayOutTitle.EnumTitleAction;
|
||||||
|
import xyz.nkomarn.Harbor.nms.NMS;
|
||||||
|
|
||||||
public class NMS_1_9_R1 implements NMS {
|
class NMS_1_9_R1 implements NMS {
|
||||||
@Override
|
|
||||||
public void sendActionbar(Player player, String message) {
|
public void sendActionbar(Player player, String message) {
|
||||||
IChatBaseComponent titleComponent = ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
|
IChatBaseComponent titleComponent = ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
|
||||||
PacketPlayOutChat titlePacket = new PacketPlayOutChat(titleComponent, (byte)2);
|
PacketPlayOutChat titlePacket = new PacketPlayOutChat(titleComponent, (byte)2);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(titlePacket);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(titlePacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendJSONMessage(Player player, String json) {
|
public void sendJSONMessage(Player player, String json) {
|
||||||
IChatBaseComponent component = ChatSerializer.a(json);
|
IChatBaseComponent component = ChatSerializer.a(json);
|
||||||
PacketPlayOutChat packet = new PacketPlayOutChat(component);
|
PacketPlayOutChat packet = new PacketPlayOutChat(component);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendTitle(Player player, String top, String bottom) {
|
public void sendTitle(Player player, String top, String bottom) {
|
||||||
IChatBaseComponent titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
|
IChatBaseComponent titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
|
||||||
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
|
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
|
||||||
@ -34,9 +32,4 @@ public class NMS_1_9_R1 implements NMS {
|
|||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void enterBed(Player player) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package mykyta.Harbor.NMS;
|
package xyz.nkomarn.Harbor.nms;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer;
|
||||||
@ -9,23 +9,21 @@ import net.minecraft.server.v1_9_R2.PacketPlayOutChat;
|
|||||||
import net.minecraft.server.v1_9_R2.PacketPlayOutTitle;
|
import net.minecraft.server.v1_9_R2.PacketPlayOutTitle;
|
||||||
import net.minecraft.server.v1_9_R2.IChatBaseComponent.ChatSerializer;
|
import net.minecraft.server.v1_9_R2.IChatBaseComponent.ChatSerializer;
|
||||||
import net.minecraft.server.v1_9_R2.PacketPlayOutTitle.EnumTitleAction;
|
import net.minecraft.server.v1_9_R2.PacketPlayOutTitle.EnumTitleAction;
|
||||||
|
import xyz.nkomarn.Harbor.nms.NMS;
|
||||||
|
|
||||||
public class NMS_1_9_R2 implements NMS {
|
class NMS_1_9_R2 implements NMS {
|
||||||
@Override
|
|
||||||
public void sendActionbar(Player player, String message) {
|
public void sendActionbar(Player player, String message) {
|
||||||
IChatBaseComponent titleComponent = ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
|
IChatBaseComponent titleComponent = ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
|
||||||
PacketPlayOutChat titlePacket = new PacketPlayOutChat(titleComponent, (byte)2);
|
PacketPlayOutChat titlePacket = new PacketPlayOutChat(titleComponent, (byte)2);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(titlePacket);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(titlePacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendJSONMessage(Player player, String json) {
|
public void sendJSONMessage(Player player, String json) {
|
||||||
IChatBaseComponent component = ChatSerializer.a(json);
|
IChatBaseComponent component = ChatSerializer.a(json);
|
||||||
PacketPlayOutChat packet = new PacketPlayOutChat(component);
|
PacketPlayOutChat packet = new PacketPlayOutChat(component);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendTitle(Player player, String top, String bottom) {
|
public void sendTitle(Player player, String top, String bottom) {
|
||||||
IChatBaseComponent titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
|
IChatBaseComponent titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
|
||||||
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
|
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
|
||||||
@ -34,9 +32,4 @@ public class NMS_1_9_R2 implements NMS {
|
|||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void enterBed(Player player) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
51
src/main/java/xyz/nkomarn/Harbor/task/Timer.java
Normal file
51
src/main/java/xyz/nkomarn/Harbor/task/Timer.java
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package xyz.nkomarn.Harbor.task;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import xyz.nkomarn.Harbor.Harbor;
|
||||||
|
import xyz.nkomarn.Harbor.nms.NMSUtils;
|
||||||
|
import xyz.nkomarn.Harbor.util.Config;
|
||||||
|
import xyz.nkomarn.Harbor.util.Counters;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class Timer implements Runnable {
|
||||||
|
Config c = new Config();
|
||||||
|
Counters n = new Counters();
|
||||||
|
NMSUtils nms = new NMSUtils();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
Bukkit.getServer().getWorlds().forEach(w -> {
|
||||||
|
if (w.getTime() >= 12516 && w.getTime() <= 12535 && c.getBoolean("messages.title.title"))
|
||||||
|
w.getPlayers().forEach(p -> nms.sendTitle(p, c.getString("messages.title.evening.top"), c.getString("messages.title.evening.bottom")));
|
||||||
|
if (n.getSleeping(w) > 0 && n.getNeeded(w) == 0) n.skip(w);
|
||||||
|
|
||||||
|
if (n.getSleeping(w) > 0 && n.getSleeping(w) < n.getNeeded(w))
|
||||||
|
w.getPlayers().forEach(p -> nms.sendActionbar(p, c.getString("messages.actionbar.sleeping"), w));
|
||||||
|
else if (n.getSleeping(w) == n.getNeeded(w) && n.getSleeping(w) > 0)
|
||||||
|
w.getPlayers().forEach(p -> nms.sendActionbar(p, c.getString("messages.actionbar.everyone"), w));
|
||||||
|
|
||||||
|
if (c.getBoolean("features.afk")) w.getPlayers().forEach(p -> {
|
||||||
|
if (TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis() - Counters.activity.get(p)) >= c.getInteger("values.timeout")) {
|
||||||
|
if (Counters.sleeping.get(w).contains(p)) {
|
||||||
|
Counters.activity.put(p, System.currentTimeMillis());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!Counters.afk.contains(p)) {
|
||||||
|
Counters.afk.add(p);
|
||||||
|
p.setPlayerListName(ChatColor.translateAlternateColorCodes('&', c.getString("messages.miscellaneous.afkprefix")
|
||||||
|
+ p.getDisplayName()));
|
||||||
|
if (c.getString("messages.chat.afk").length() > 0)
|
||||||
|
Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', c.getString("messages.chat.afk")
|
||||||
|
.replace("[player]", p.getName())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (Harbor.debug) e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package mykyta.Harbor;
|
package xyz.nkomarn.Harbor.util;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -6,36 +6,19 @@ import java.util.List;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
|
import xyz.nkomarn.Harbor.Harbor;
|
||||||
|
|
||||||
public class Config {
|
public class Config {
|
||||||
private String error = "An error occured while trying to read the configuration. Harbor may not function correctly as a result.";
|
|
||||||
public static Harbor harbor;
|
|
||||||
private ConsoleCommandSender c = Bukkit.getServer().getConsoleSender();
|
private ConsoleCommandSender c = Bukkit.getServer().getConsoleSender();
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets main class instance for accessing configuration
|
|
||||||
* @param instance Instance of the main class
|
|
||||||
*/
|
|
||||||
public void setInstance(Harbor instance) {
|
|
||||||
harbor = instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Report an error in reading the configuration
|
* Report an error in reading the configuration
|
||||||
* @param e Exception generated from reading configuration
|
* @param e Exception generated from reading configuration
|
||||||
*/
|
*/
|
||||||
private void error(Exception e) {
|
private void error(Exception e) {
|
||||||
c.sendMessage(ChatColor.translateAlternateColorCodes('&', this.getString("messages.miscellaneous.prefix") + error));
|
c.sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||||
if (Util.debug) e.printStackTrace();
|
"An error occurred while trying to read the configuration. Harbor may not function correctly as a result."));
|
||||||
}
|
if (Harbor.debug) e.printStackTrace();
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetches a boolean from the configuration
|
|
||||||
* @param location Configuration location of the boolean
|
|
||||||
*/
|
|
||||||
public String getVersion() {
|
|
||||||
try {return this.getString("version");}
|
|
||||||
catch (Exception e) {error(e); return "";}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -43,7 +26,7 @@ public class Config {
|
|||||||
* @param location Configuration location of the boolean
|
* @param location Configuration location of the boolean
|
||||||
*/
|
*/
|
||||||
public boolean getBoolean(String location) {
|
public boolean getBoolean(String location) {
|
||||||
try {return harbor.getConfig().getBoolean(location);}
|
try {return Harbor.instance.getConfig().getBoolean(location);}
|
||||||
catch (Exception e) {error(e); return false;}
|
catch (Exception e) {error(e); return false;}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +35,7 @@ public class Config {
|
|||||||
* @param location Configuration location of the string
|
* @param location Configuration location of the string
|
||||||
*/
|
*/
|
||||||
public String getString(String location) {
|
public String getString(String location) {
|
||||||
try {return harbor.getConfig().getString(location);}
|
try {return Harbor.instance.getConfig().getString(location);}
|
||||||
catch (Exception e) {error(e); return "";}
|
catch (Exception e) {error(e); return "";}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +44,7 @@ public class Config {
|
|||||||
* @param location Configuration location of the integer
|
* @param location Configuration location of the integer
|
||||||
*/
|
*/
|
||||||
public int getInteger(String location) {
|
public int getInteger(String location) {
|
||||||
try {return harbor.getConfig().getInt(location);}
|
try {return Harbor.instance.getConfig().getInt(location);}
|
||||||
catch (Exception e) {error(e); return 0;}
|
catch (Exception e) {error(e); return 0;}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +53,7 @@ public class Config {
|
|||||||
* @param location Configuration location of the double
|
* @param location Configuration location of the double
|
||||||
*/
|
*/
|
||||||
public double getDouble(String location) {
|
public double getDouble(String location) {
|
||||||
try {return Double.parseDouble(harbor.getConfig().getString(location));}
|
try {return Double.parseDouble(Harbor.instance.getConfig().getString(location));}
|
||||||
catch (Exception e) {error(e); return 0.0;}
|
catch (Exception e) {error(e); return 0.0;}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +62,7 @@ public class Config {
|
|||||||
* @param location Configuration location of the double
|
* @param location Configuration location of the double
|
||||||
*/
|
*/
|
||||||
public List<String> getList(String location) {
|
public List<String> getList(String location) {
|
||||||
try {return harbor.getConfig().getStringList(location);}
|
try {return Harbor.instance.getConfig().getStringList(location);}
|
||||||
catch (Exception e) {error(e); return new ArrayList<String>();}
|
catch (Exception e) {error(e); return new ArrayList<String>();}
|
||||||
}
|
}
|
||||||
}
|
}
|
107
src/main/java/xyz/nkomarn/Harbor/util/Counters.java
Normal file
107
src/main/java/xyz/nkomarn/Harbor/util/Counters.java
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
package xyz.nkomarn.Harbor.util;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import xyz.nkomarn.Harbor.Harbor;
|
||||||
|
import xyz.nkomarn.Harbor.nms.NMSUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class Counters {
|
||||||
|
public static HashMap<World, ArrayList<Player>> sleeping = new HashMap<>();
|
||||||
|
public static HashMap<Player, Long> activity = new HashMap<>();
|
||||||
|
public static ArrayList<Player> afk = new ArrayList<>();
|
||||||
|
|
||||||
|
private Config c = new Config();
|
||||||
|
private NMSUtils nms = new NMSUtils();
|
||||||
|
|
||||||
|
public void add(World w, Player p) {
|
||||||
|
ArrayList<Player> a = sleeping.get(w);
|
||||||
|
a.add(p);
|
||||||
|
sleeping.put(w, a);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(World w, Player p) {
|
||||||
|
ArrayList<Player> a = sleeping.get(w);
|
||||||
|
a.remove(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSleeping(World w) {
|
||||||
|
try {return Math.max(0, sleeping.get(w).size());}
|
||||||
|
catch (NullPointerException e) {
|
||||||
|
if (Harbor.debug) e.printStackTrace();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNeeded(World w) {
|
||||||
|
try {return Math.max(0, (int) Math.ceil((w.getPlayers().size() - getExcluded(w).size()) * (c.getDouble("values.percent") / 100) - getSleeping(w)));}
|
||||||
|
catch (NullPointerException e) {
|
||||||
|
if (Harbor.debug) e.printStackTrace();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getOnline(World w) {
|
||||||
|
try {return Math.max(0, w.getPlayers().size() - getExcluded(w).size());}
|
||||||
|
catch (NullPointerException e) {return 0;}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Player> getExcluded(World w) {
|
||||||
|
ArrayList<Player> a = new ArrayList<>();
|
||||||
|
w.getPlayers().forEach(p -> {
|
||||||
|
if (isExcluded(p)) a.add(p);
|
||||||
|
});
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isExcluded(Player p) {
|
||||||
|
boolean s = false;
|
||||||
|
if (c.getBoolean("features.ignore")) if (p.getGameMode() == GameMode.SURVIVAL) s = false; else s = true;
|
||||||
|
if (c.getBoolean("features.bypass")) if (p.hasPermission("harbor.bypass")) s = true; else s = false;
|
||||||
|
if (afk.contains(p)) s = true;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void skip(World w) {
|
||||||
|
if (c.getBoolean("features.skip") && Math.max(0, this.getNeeded(w) - this.getExcluded(w).size()) == 0) {
|
||||||
|
w.setTime(1000L);
|
||||||
|
|
||||||
|
// Set weather to clear TODO ASYNC NO BAD DON'T ASYNC CAUSE 1.14 API CHANGE BAD
|
||||||
|
if (c.getBoolean("features.weather")) {
|
||||||
|
w.setStorm(false);
|
||||||
|
w.setThundering(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display messages
|
||||||
|
if (c.getBoolean("messages.chat.chat") && (c.getString("messages.chat.skipped").length() != 0)) {
|
||||||
|
List<String> m = c.getList("messages.chat.skipped");
|
||||||
|
Random r = new Random();
|
||||||
|
int n = r.nextInt(m.size());
|
||||||
|
Bukkit.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', m.get(n)));
|
||||||
|
}
|
||||||
|
if (c.getBoolean("messages.title.title")) {
|
||||||
|
w.getPlayers().forEach(p -> {
|
||||||
|
nms.sendTitle(p, c.getString("messages.title.morning.top"), c.getString("messages.title.morning.bottom"));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateActivity(Player p) {
|
||||||
|
if (afk.contains(p)) {
|
||||||
|
afk.remove(p);
|
||||||
|
p.setPlayerListName(ChatColor.translateAlternateColorCodes('&', p.getDisplayName()));
|
||||||
|
if (c.getString("messages.chat.unafk").length() > 0)
|
||||||
|
Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&',
|
||||||
|
c.getString("messages.chat.unafk").replace("[player]", p.getName())));
|
||||||
|
}
|
||||||
|
activity.put(p, System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
}
|
86
src/main/java/xyz/nkomarn/Harbor/util/Updater.java
Normal file
86
src/main/java/xyz/nkomarn/Harbor/util/Updater.java
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
package xyz.nkomarn.Harbor.util;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
|
import xyz.nkomarn.Harbor.Harbor;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
|
||||||
|
public class Updater {
|
||||||
|
public static String latest = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks for an update using the Spigot API
|
||||||
|
*/
|
||||||
|
public boolean check() {
|
||||||
|
ConsoleCommandSender c = Bukkit.getServer().getConsoleSender();
|
||||||
|
Config config = new Config();
|
||||||
|
|
||||||
|
try {
|
||||||
|
URL url = new URL("https://api.spigotmc.org/legacy/update.php?resource=60088");
|
||||||
|
URLConnection request = url.openConnection();
|
||||||
|
request.addRequestProperty("User-Agent", "Harbor");
|
||||||
|
request.connect();
|
||||||
|
|
||||||
|
StringWriter writer = new StringWriter();
|
||||||
|
IOUtils.copy((InputStream) request.getContent(), writer, "UTF-8");
|
||||||
|
latest = writer.toString();
|
||||||
|
|
||||||
|
if (Harbor.version.equals(latest)) {
|
||||||
|
if (Harbor.debug) c.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix")) + "Currently running the latest version of Harbor.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (config.getBoolean("features.notifier")) c.sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||||
|
config.getString("messages.miscellaneous.prefix")) + "Currently running an outdated version of Harbor. The latest available release is version " + latest + ".");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
if (Harbor.debug) c.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix")) + "Failed to check for updated releases of Harbor.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace the current Harbor version with the latest available release
|
||||||
|
*/
|
||||||
|
public int upgrade() {
|
||||||
|
ConsoleCommandSender c = Bukkit.getServer().getConsoleSender();
|
||||||
|
Config config = new Config();
|
||||||
|
|
||||||
|
if (Harbor.version.equals(latest)) return 2;
|
||||||
|
|
||||||
|
c.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix")) + "Downloading Harbor version " + latest + ".");
|
||||||
|
try {
|
||||||
|
String jar = new File(Updater.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getName();
|
||||||
|
new File("update").mkdir();
|
||||||
|
URL url = new URL("http://aqua.api.spiget.org/v2/resources/60088/download");
|
||||||
|
File f = new File("plugins" + File.separator + "update" + File.separator + jar);
|
||||||
|
FileUtils.copyURLToFile(url, f);
|
||||||
|
c.sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||||
|
config.getString("messages.miscellaneous.prefix")) + "Harbor " + latest + " has been downloaded successfully and will be enabled after a server restart/reload.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
c.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix")) + "Failed to update Harbor to version " + latest + ".");
|
||||||
|
if (Harbor.debug) e.printStackTrace();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the latest version number
|
||||||
|
*/
|
||||||
|
public String getLatest() {
|
||||||
|
return latest;
|
||||||
|
}
|
||||||
|
}
|
@ -5,7 +5,7 @@
|
|||||||
# \/ /_/ \__,_|_| |_.__/ \___/|_|
|
# \/ /_/ \__,_|_| |_.__/ \___/|_|
|
||||||
#
|
#
|
||||||
# An open-source project by Mykyta (TechToolbox)
|
# An open-source project by Mykyta (TechToolbox)
|
||||||
# https://mykyta.tk/
|
# https://harbor.nkomarn.xyz
|
||||||
#
|
#
|
||||||
# Ahoy, matey! You've arrived at the configuration file, where things get a bit scary.
|
# Ahoy, matey! You've arrived at the configuration file, where things get a bit scary.
|
||||||
# Every single thing within this plugin is customizable (at least I tried to make it that way),
|
# Every single thing within this plugin is customizable (at least I tried to make it that way),
|
||||||
@ -21,15 +21,13 @@ values:
|
|||||||
percent: 35
|
percent: 35
|
||||||
# Time that it takes to be considered AFK (in minutes)
|
# Time that it takes to be considered AFK (in minutes)
|
||||||
timeout: 15
|
timeout: 15
|
||||||
# Time to wait before skipping the night (in seconds)
|
|
||||||
delay: 3
|
|
||||||
|
|
||||||
features:
|
features:
|
||||||
# Toggle night skipping feature. Configure amount of players needed to skip above (percent)
|
# Toggle night skipping feature. Configure amount of players needed to skip above (percent)
|
||||||
skip: true
|
skip: true
|
||||||
# Clear weather when skipping night
|
# Clear weather when skipping night
|
||||||
weather: true
|
weather: true
|
||||||
# Toggle the spawning of phantoms
|
# Toggle the spawning of phantoms (false = no phantom spawning)
|
||||||
phantoms: false
|
phantoms: false
|
||||||
# Toggle exclusion of operators/players with permission "harbor.bypass" from sleep count
|
# Toggle exclusion of operators/players with permission "harbor.bypass" from sleep count
|
||||||
bypass: true
|
bypass: true
|
||||||
@ -58,7 +56,7 @@ messages:
|
|||||||
# Shown when a player tries to sleep and sleeping is blocked
|
# Shown when a player tries to sleep and sleeping is blocked
|
||||||
blocked: "&cSleeping is disabled."
|
blocked: "&cSleeping is disabled."
|
||||||
# Sent to player when they sleep with "harbor.bypass" permission
|
# Sent to player when they sleep with "harbor.bypass" permission
|
||||||
bypass: "&eYou're excluded from the needed count. However, you have been added to the sleep count."
|
bypass: "&eYou've been excluded from the sleep count."
|
||||||
# Shown when a player goes AFK
|
# Shown when a player goes AFK
|
||||||
afk: "&7[player] has gone AFK."
|
afk: "&7[player] has gone AFK."
|
||||||
# Shown when a player comes back after being AFK
|
# Shown when a player comes back after being AFK
|
||||||
@ -103,8 +101,8 @@ messages:
|
|||||||
|
|
||||||
gui:
|
gui:
|
||||||
# Title for menu that shows when a player executes /sleeping
|
# Title for menu that shows when a player executes /sleeping
|
||||||
sleeping: "Sleeping Players"
|
sleeping: "Sleeping Players | Page [page]"
|
||||||
|
|
||||||
# Spooky controls (don't change)
|
# Spooky controls (don't change)
|
||||||
version: 1.5
|
version: 1.5.1
|
||||||
debug: false
|
debug: false
|
15
src/main/resources/plugin.yml
Normal file
15
src/main/resources/plugin.yml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
name: ${name}
|
||||||
|
description: Harbor is a Spigot plugin that redefines how sleep works in your server, making it easier for all the online players to get in bed quickly and skip through the night!
|
||||||
|
main: xyz.nkomarn.${name}.${name}
|
||||||
|
version: ${version}
|
||||||
|
author: TechToolbox (@nkomarn)
|
||||||
|
website: https://nkomarn.xyz
|
||||||
|
api-version: 1.13
|
||||||
|
|
||||||
|
commands:
|
||||||
|
harbor:
|
||||||
|
description: "Base command for Harbor!"
|
||||||
|
usage: "/harbor {subcommand}"
|
||||||
|
sleeping:
|
||||||
|
description: "Display a list of the currently sleeping players."
|
||||||
|
usage: "/sleeping"
|
Loading…
Reference in New Issue
Block a user