1
0
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:
Mykyta 2019-07-17 00:04:40 -07:00
parent cea0522f06
commit 49bcd9da88
No known key found for this signature in database
GPG Key ID: C147E30C19EA3570
57 changed files with 1428 additions and 1680 deletions

View File

@ -31,6 +31,11 @@
<attribute name="m2e-apt" value="true"/>
</attributes>
</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">
<attributes>
<attribute name="optional" value="true"/>

11
.gitignore vendored
View File

@ -1,4 +1,7 @@
/bin/
spigot
.vscode
target
.vscode/
.settings/
.idea/
target/
jars/
.classpath
.idea/

View File

@ -1,23 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Harbor</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Harbor</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View File

@ -1,4 +0,0 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding/<project>=UTF-8
encoding/src=UTF-8

View File

@ -1,2 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=false

View File

@ -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

View File

@ -1,4 +0,0 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2018 Mykyta
Copyright (c) 2019 Mykyta
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -1,4 +1,5 @@
[discord-invite]: https://discord.gg/UACRzwe
# 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)
Harbor is a plugin that redefines sleep within your Spigot server!
https://www.spigotmc.org/resources/harbor-a-sleep-enhancement-plugin.60088/
# 🌱 The Seed - Spigot Plugin Template
A Spigot template that I use to develop plugins for The Seed MC!
https://theseedmc.com
### test

2
build.sh Normal file
View File

@ -0,0 +1,2 @@
mvn package
yes | cp -rf target/*-*.jar ../Spigot/1.13.2/plugins

View File

@ -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>

301
pom.xml
View File

@ -1,157 +1,146 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>mykyta.Harbor</groupId>
<artifactId>Harbor</artifactId>
<version>1.5</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>
<?xml version="1.0" encoding="UTF-8" ?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xyz.nkomarn</groupId>
<artifactId>Harbor</artifactId>
<version>1.5.1</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<jars>${project.basedir}/jars</jars>
</properties>
<repositories>
<!-- Spigot versions -->
<dependency>
<groupId>spigotmc.org</groupId>
<artifactId>spigot-1.14.1</artifactId>
<scope>system</scope>
<systemPath>${spigot}/1.14.1.jar</systemPath>
<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 -->
<dependency>
<groupId>inventivetalent.org</groupId>
<artifactId>bossbarapi-2.4.1</artifactId>
<scope>system</scope>
<systemPath>${spigot}/BossBarAPI.jar</systemPath>
<version>2.4.1</version>
</dependency>
</dependencies>
<build>
<directory>/home/nkomarn/Documents/Spigot Servers/1.14.2/plugins/</directory>
<sourceDirectory>${basedir}/src/</sourceDirectory>
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>${basedir}</directory>
<includes>
<include>*.yml</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
</plugin>
</plugins>
</build>
</project>
</repositories>
<dependencies>
<dependency>
<groupId>spigotmc.org</groupId>
<artifactId>spigot-1.14.1</artifactId>
<scope>system</scope>
<systemPath>${jars}/1.14.1.jar</systemPath>
<version>1.14.1</version>
</dependency>
<dependency>
<groupId>spigotmc.org</groupId>
<artifactId>spigot-1.14</artifactId>
<scope>system</scope>
<systemPath>${jars}/1.14.jar</systemPath>
<version>1.14</version>
</dependency>
<dependency>
<groupId>spigotmc.org</groupId>
<artifactId>spigot-1.13.2</artifactId>
<scope>system</scope>
<systemPath>${jars}/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>${jars}/1.13.jar</systemPath>
<version>1.13</version>
</dependency>
<dependency>
<groupId>spigotmc.org</groupId>
<artifactId>spigot-1.12.2</artifactId>
<scope>system</scope>
<systemPath>${jars}/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>${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>

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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")));
}
}
}

View File

@ -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))));
}
}
}

View File

@ -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());
}
}

View File

@ -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());
}
}

View File

@ -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);
}
}
}

View File

@ -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());
}
}

View File

@ -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."));
}
}

View File

@ -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
);
}
}

View File

@ -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+
}
}
}

View File

@ -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() {
}
}

View File

@ -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);
}

View File

@ -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) {
}
}

View File

@ -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();}
}
}

View File

@ -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;
}
}

View File

@ -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());
}
}

View 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() {
}
}

View 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;
}
}

View File

@ -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;
}
}

View 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));
}
}
}
}
}

View 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());
}
}

View 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+
}
}
}

View File

@ -1,4 +1,4 @@
package mykyta.Harbor.GUI;
package xyz.nkomarn.Harbor.gui;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
@ -6,17 +6,23 @@ import org.bukkit.inventory.InventoryHolder;
public class GUIHolder implements InventoryHolder {
private Inventory inv;
private GUIType type;
private int page;
public GUIHolder(GUIType type) {
public GUIHolder(GUIType type, int page) {
this.type = type;
this.page = page;
}
@Override
public Inventory getInventory() {
return inv; // Required by InventoryHolder
return inv;
}
public GUIType getType() {
return type;
}
public int getPage() {
return this.page;
}
}

View File

@ -1,5 +1,5 @@
package mykyta.Harbor.GUI;
package xyz.nkomarn.Harbor.gui;
public enum GUIType {
SLEEPING
}
}

View 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);
}
}

View 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);
}

View 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);
}
}

View File

@ -1,42 +1,34 @@
package mykyta.Harbor.NMS;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_10_R1.IChatBaseComponent;
import net.minecraft.server.v1_10_R1.PacketPlayOutChat;
import net.minecraft.server.v1_10_R1.PacketPlayOutTitle;
import net.minecraft.server.v1_10_R1.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_10_R1.PacketPlayOutTitle.EnumTitleAction;
public class NMS_1_10_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 titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
PacketPlayOutTitle title = new PacketPlayOutTitle(EnumTitleAction.TITLE, titleComponentTop);
PacketPlayOutTitle subtitle = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, titleComponentBottom);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
}
@Override
public void enterBed(Player player) {
}
}
package xyz.nkomarn.Harbor.nms;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_10_R1.IChatBaseComponent;
import net.minecraft.server.v1_10_R1.PacketPlayOutChat;
import net.minecraft.server.v1_10_R1.PacketPlayOutTitle;
import net.minecraft.server.v1_10_R1.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_10_R1.PacketPlayOutTitle.EnumTitleAction;
class NMS_1_10_R1 implements NMS {
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);
}
public void sendJSONMessage(Player player, String json) {
IChatBaseComponent component = ChatSerializer.a(json);
PacketPlayOutChat packet = new PacketPlayOutChat(component);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
public void sendTitle(Player player, String top, String bottom) {
IChatBaseComponent titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
PacketPlayOutTitle title = new PacketPlayOutTitle(EnumTitleAction.TITLE, titleComponentTop);
PacketPlayOutTitle subtitle = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, titleComponentBottom);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
}
}

View File

@ -1,42 +1,34 @@
package mykyta.Harbor.NMS;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_11_R1.IChatBaseComponent;
import net.minecraft.server.v1_11_R1.PacketPlayOutChat;
import net.minecraft.server.v1_11_R1.PacketPlayOutTitle;
import net.minecraft.server.v1_11_R1.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_11_R1.PacketPlayOutTitle.EnumTitleAction;
public class NMS_1_11_R1 implements NMS {
@Override
public void sendActionbar(Player player, String message) {
IChatBaseComponent titleComponent = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
PacketPlayOutTitle titlePacket = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.ACTIONBAR, titleComponent);
((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 titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
PacketPlayOutTitle title = new PacketPlayOutTitle(EnumTitleAction.TITLE, titleComponentTop);
PacketPlayOutTitle subtitle = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, titleComponentBottom);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
}
@Override
public void enterBed(Player player) {
}
}
package xyz.nkomarn.Harbor.nms;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_11_R1.IChatBaseComponent;
import net.minecraft.server.v1_11_R1.PacketPlayOutChat;
import net.minecraft.server.v1_11_R1.PacketPlayOutTitle;
import net.minecraft.server.v1_11_R1.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_11_R1.PacketPlayOutTitle.EnumTitleAction;
class NMS_1_11_R1 implements NMS {
public void sendActionbar(Player player, String message) {
IChatBaseComponent titleComponent = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
PacketPlayOutTitle titlePacket = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.ACTIONBAR, titleComponent);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(titlePacket);
}
public void sendJSONMessage(Player player, String json) {
IChatBaseComponent component = ChatSerializer.a(json);
PacketPlayOutChat packet = new PacketPlayOutChat(component);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
public void sendTitle(Player player, String top, String bottom) {
IChatBaseComponent titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
PacketPlayOutTitle title = new PacketPlayOutTitle(EnumTitleAction.TITLE, titleComponentTop);
PacketPlayOutTitle subtitle = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, titleComponentBottom);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
}
}

View File

@ -1,42 +1,34 @@
package mykyta.Harbor.NMS;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_12_R1.IChatBaseComponent;
import net.minecraft.server.v1_12_R1.PacketPlayOutChat;
import net.minecraft.server.v1_12_R1.PacketPlayOutTitle;
import net.minecraft.server.v1_12_R1.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_12_R1.PacketPlayOutTitle.EnumTitleAction;
public class NMS_1_12_R1 implements NMS {
@Override
public void sendActionbar(Player player, String message) {
IChatBaseComponent titleComponent = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
PacketPlayOutTitle titlePacket = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.ACTIONBAR, titleComponent);
((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 titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
PacketPlayOutTitle title = new PacketPlayOutTitle(EnumTitleAction.TITLE, titleComponentTop);
PacketPlayOutTitle subtitle = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, titleComponentBottom);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
}
@Override
public void enterBed(Player player) {
}
}
package xyz.nkomarn.Harbor.nms;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_12_R1.IChatBaseComponent;
import net.minecraft.server.v1_12_R1.PacketPlayOutChat;
import net.minecraft.server.v1_12_R1.PacketPlayOutTitle;
import net.minecraft.server.v1_12_R1.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_12_R1.PacketPlayOutTitle.EnumTitleAction;
class NMS_1_12_R1 implements NMS {
public void sendActionbar(Player player, String message) {
IChatBaseComponent titleComponent = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
PacketPlayOutTitle titlePacket = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.ACTIONBAR, titleComponent);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(titlePacket);
}
public void sendJSONMessage(Player player, String json) {
IChatBaseComponent component = ChatSerializer.a(json);
PacketPlayOutChat packet = new PacketPlayOutChat(component);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
public void sendTitle(Player player, String top, String bottom) {
IChatBaseComponent titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
PacketPlayOutTitle title = new PacketPlayOutTitle(EnumTitleAction.TITLE, titleComponentTop);
PacketPlayOutTitle subtitle = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, titleComponentBottom);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
}
}

View File

@ -1,42 +1,34 @@
package mykyta.Harbor.NMS;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_13_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_13_R1.IChatBaseComponent;
import net.minecraft.server.v1_13_R1.PacketPlayOutChat;
import net.minecraft.server.v1_13_R1.PacketPlayOutTitle;
import net.minecraft.server.v1_13_R1.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_13_R1.PacketPlayOutTitle.EnumTitleAction;
public class NMS_1_13_R1 implements NMS {
@Override
public void sendActionbar(Player player, String message) {
IChatBaseComponent titleComponent = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
PacketPlayOutTitle titlePacket = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.ACTIONBAR, titleComponent);
((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 titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
PacketPlayOutTitle title = new PacketPlayOutTitle(EnumTitleAction.TITLE, titleComponentTop);
PacketPlayOutTitle subtitle = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, titleComponentBottom);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
}
@Override
public void enterBed(Player player) {
}
}
package xyz.nkomarn.Harbor.nms;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_13_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_13_R1.IChatBaseComponent;
import net.minecraft.server.v1_13_R1.PacketPlayOutChat;
import net.minecraft.server.v1_13_R1.PacketPlayOutTitle;
import net.minecraft.server.v1_13_R1.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_13_R1.PacketPlayOutTitle.EnumTitleAction;
class NMS_1_13_R1 implements NMS {
public void sendActionbar(Player player, String message) {
IChatBaseComponent titleComponent = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
PacketPlayOutTitle titlePacket = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.ACTIONBAR, titleComponent);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(titlePacket);
}
public void sendJSONMessage(Player player, String json) {
IChatBaseComponent component = ChatSerializer.a(json);
PacketPlayOutChat packet = new PacketPlayOutChat(component);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
public void sendTitle(Player player, String top, String bottom) {
IChatBaseComponent titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
PacketPlayOutTitle title = new PacketPlayOutTitle(EnumTitleAction.TITLE, titleComponentTop);
PacketPlayOutTitle subtitle = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, titleComponentBottom);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
}
}

View File

@ -1,45 +1,35 @@
package mykyta.Harbor.NMS;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_13_R2.PacketPlayOutBed;
import net.minecraft.server.v1_13_R2.IChatBaseComponent;
import net.minecraft.server.v1_13_R2.PacketPlayOutChat;
import net.minecraft.server.v1_13_R2.PacketPlayOutTitle;
import net.minecraft.server.v1_13_R2.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_13_R2.PacketPlayOutTitle.EnumTitleAction;
public class NMS_1_13_R2 implements NMS {
@Override
public void sendActionbar(Player player, String message) {
IChatBaseComponent titleComponent = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
PacketPlayOutTitle titlePacket = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.ACTIONBAR, titleComponent);
((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 titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
PacketPlayOutTitle title = new PacketPlayOutTitle(EnumTitleAction.TITLE, titleComponentTop);
PacketPlayOutTitle subtitle = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, titleComponentBottom);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
((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);
}
}
package xyz.nkomarn.Harbor.nms;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_13_R2.PacketPlayOutBed;
import net.minecraft.server.v1_13_R2.IChatBaseComponent;
import net.minecraft.server.v1_13_R2.PacketPlayOutChat;
import net.minecraft.server.v1_13_R2.PacketPlayOutTitle;
import net.minecraft.server.v1_13_R2.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_13_R2.PacketPlayOutTitle.EnumTitleAction;
class NMS_1_13_R2 implements NMS {
public void sendActionbar(Player player, String message) {
IChatBaseComponent titleComponent = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
PacketPlayOutTitle titlePacket = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.ACTIONBAR, titleComponent);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(titlePacket);
}
public void sendJSONMessage(Player player, String json) {
IChatBaseComponent component = ChatSerializer.a(json);
PacketPlayOutChat packet = new PacketPlayOutChat(component);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
public void sendTitle(Player player, String top, String bottom) {
IChatBaseComponent titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
PacketPlayOutTitle title = new PacketPlayOutTitle(EnumTitleAction.TITLE, titleComponentTop);
PacketPlayOutTitle subtitle = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, titleComponentBottom);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
}
}

View File

@ -1,42 +1,34 @@
package mykyta.Harbor.NMS;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_14_R1.IChatBaseComponent;
import net.minecraft.server.v1_14_R1.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_14_R1.PacketPlayOutChat;
import net.minecraft.server.v1_14_R1.PacketPlayOutTitle;
import net.minecraft.server.v1_14_R1.PacketPlayOutTitle.EnumTitleAction;
public class NMS_1_14_R1 implements NMS {
@Override
public void sendActionbar(Player player, String message) {
IChatBaseComponent titleComponent = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
PacketPlayOutTitle titlePacket = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.ACTIONBAR, titleComponent);
((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 titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
PacketPlayOutTitle title = new PacketPlayOutTitle(EnumTitleAction.TITLE, titleComponentTop);
PacketPlayOutTitle subtitle = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, titleComponentBottom);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
}
@Override
public void enterBed(Player player) {
}
}
package xyz.nkomarn.Harbor.nms;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_14_R1.IChatBaseComponent;
import net.minecraft.server.v1_14_R1.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_14_R1.PacketPlayOutChat;
import net.minecraft.server.v1_14_R1.PacketPlayOutTitle;
import net.minecraft.server.v1_14_R1.PacketPlayOutTitle.EnumTitleAction;
class NMS_1_14_R1 implements NMS {
public void sendActionbar(Player player, String message) {
IChatBaseComponent titleComponent = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
PacketPlayOutTitle titlePacket = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.ACTIONBAR, titleComponent);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(titlePacket);
}
public void sendJSONMessage(Player player, String json) {
IChatBaseComponent component = ChatSerializer.a(json);
PacketPlayOutChat packet = new PacketPlayOutChat(component);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
public void sendTitle(Player player, String top, String bottom) {
IChatBaseComponent titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
PacketPlayOutTitle title = new PacketPlayOutTitle(EnumTitleAction.TITLE, titleComponentTop);
PacketPlayOutTitle subtitle = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, titleComponentBottom);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
}
}

View 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);
}
}

View File

@ -1,42 +1,35 @@
package mykyta.Harbor.NMS;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_8_R2.IChatBaseComponent;
import net.minecraft.server.v1_8_R2.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_8_R2.PacketPlayOutChat;
import net.minecraft.server.v1_8_R2.PacketPlayOutTitle;
import net.minecraft.server.v1_8_R2.PacketPlayOutTitle.EnumTitleAction;
public class NMS_1_8_R2 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) {
}
}
package xyz.nkomarn.Harbor.nms;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_8_R2.IChatBaseComponent;
import net.minecraft.server.v1_8_R2.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_8_R2.PacketPlayOutChat;
import net.minecraft.server.v1_8_R2.PacketPlayOutTitle;
import net.minecraft.server.v1_8_R2.PacketPlayOutTitle.EnumTitleAction;
import xyz.nkomarn.Harbor.nms.NMS;
class NMS_1_8_R2 implements NMS {
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);
}
public void sendJSONMessage(Player player, String json) {
IChatBaseComponent component = ChatSerializer.a(json);
PacketPlayOutChat packet = new PacketPlayOutChat(component);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
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);
}
}

View File

@ -1,42 +1,35 @@
package mykyta.Harbor.NMS;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_8_R3.IChatBaseComponent;
import net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_8_R3.PacketPlayOutChat;
import net.minecraft.server.v1_8_R3.PacketPlayOutTitle;
import net.minecraft.server.v1_8_R3.PacketPlayOutTitle.EnumTitleAction;
public class NMS_1_8_R3 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) {
}
}
package xyz.nkomarn.Harbor.nms;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_8_R3.IChatBaseComponent;
import net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_8_R3.PacketPlayOutChat;
import net.minecraft.server.v1_8_R3.PacketPlayOutTitle;
import net.minecraft.server.v1_8_R3.PacketPlayOutTitle.EnumTitleAction;
import xyz.nkomarn.Harbor.nms.NMS;
class NMS_1_8_R3 implements NMS {
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);
}
public void sendJSONMessage(Player player, String json) {
IChatBaseComponent component = ChatSerializer.a(json);
PacketPlayOutChat packet = new PacketPlayOutChat(component);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
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);
}
}

View File

@ -1,42 +1,35 @@
package mykyta.Harbor.NMS;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_9_R1.IChatBaseComponent;
import net.minecraft.server.v1_9_R1.PacketPlayOutChat;
import net.minecraft.server.v1_9_R1.PacketPlayOutTitle;
import net.minecraft.server.v1_9_R1.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_9_R1.PacketPlayOutTitle.EnumTitleAction;
public class NMS_1_9_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 titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
PacketPlayOutTitle title = new PacketPlayOutTitle(EnumTitleAction.TITLE, titleComponentTop);
PacketPlayOutTitle subtitle = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, titleComponentBottom);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
}
@Override
public void enterBed(Player player) {
}
}
package xyz.nkomarn.Harbor.nms;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_9_R1.IChatBaseComponent;
import net.minecraft.server.v1_9_R1.PacketPlayOutChat;
import net.minecraft.server.v1_9_R1.PacketPlayOutTitle;
import net.minecraft.server.v1_9_R1.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_9_R1.PacketPlayOutTitle.EnumTitleAction;
import xyz.nkomarn.Harbor.nms.NMS;
class NMS_1_9_R1 implements NMS {
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);
}
public void sendJSONMessage(Player player, String json) {
IChatBaseComponent component = ChatSerializer.a(json);
PacketPlayOutChat packet = new PacketPlayOutChat(component);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
public void sendTitle(Player player, String top, String bottom) {
IChatBaseComponent titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
PacketPlayOutTitle title = new PacketPlayOutTitle(EnumTitleAction.TITLE, titleComponentTop);
PacketPlayOutTitle subtitle = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, titleComponentBottom);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
}
}

View File

@ -1,42 +1,35 @@
package mykyta.Harbor.NMS;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_9_R2.IChatBaseComponent;
import net.minecraft.server.v1_9_R2.PacketPlayOutChat;
import net.minecraft.server.v1_9_R2.PacketPlayOutTitle;
import net.minecraft.server.v1_9_R2.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_9_R2.PacketPlayOutTitle.EnumTitleAction;
public class NMS_1_9_R2 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 titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
PacketPlayOutTitle title = new PacketPlayOutTitle(EnumTitleAction.TITLE, titleComponentTop);
PacketPlayOutTitle subtitle = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, titleComponentBottom);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
}
@Override
public void enterBed(Player player) {
}
}
package xyz.nkomarn.Harbor.nms;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_9_R2.IChatBaseComponent;
import net.minecraft.server.v1_9_R2.PacketPlayOutChat;
import net.minecraft.server.v1_9_R2.PacketPlayOutTitle;
import net.minecraft.server.v1_9_R2.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_9_R2.PacketPlayOutTitle.EnumTitleAction;
import xyz.nkomarn.Harbor.nms.NMS;
class NMS_1_9_R2 implements NMS {
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);
}
public void sendJSONMessage(Player player, String json) {
IChatBaseComponent component = ChatSerializer.a(json);
PacketPlayOutChat packet = new PacketPlayOutChat(component);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
public void sendTitle(Player player, String top, String bottom) {
IChatBaseComponent titleComponentTop = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', top) + "\"}");
IChatBaseComponent titleComponentBottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bottom) + "\"}");
PacketPlayOutTitle title = new PacketPlayOutTitle(EnumTitleAction.TITLE, titleComponentTop);
PacketPlayOutTitle subtitle = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, titleComponentBottom);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(subtitle);
}
}

View 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();
}
}
}

View File

@ -1,4 +1,4 @@
package mykyta.Harbor;
package xyz.nkomarn.Harbor.util;
import java.util.ArrayList;
import java.util.List;
@ -6,36 +6,19 @@ import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.ConsoleCommandSender;
import xyz.nkomarn.Harbor.Harbor;
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();
/**
* 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
* @param e Exception generated from reading configuration
*/
private void error(Exception e) {
c.sendMessage(ChatColor.translateAlternateColorCodes('&', this.getString("messages.miscellaneous.prefix") + error));
if (Util.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 "";}
c.sendMessage(ChatColor.translateAlternateColorCodes('&',
"An error occurred while trying to read the configuration. Harbor may not function correctly as a result."));
if (Harbor.debug) e.printStackTrace();
}
/**
@ -43,7 +26,7 @@ public class Config {
* @param location Configuration location of the boolean
*/
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;}
}
@ -52,7 +35,7 @@ public class Config {
* @param location Configuration location of the string
*/
public String getString(String location) {
try {return harbor.getConfig().getString(location);}
try {return Harbor.instance.getConfig().getString(location);}
catch (Exception e) {error(e); return "";}
}
@ -61,7 +44,7 @@ public class Config {
* @param location Configuration location of the integer
*/
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;}
}
@ -70,7 +53,7 @@ public class Config {
* @param location Configuration location of the double
*/
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;}
}
@ -79,7 +62,7 @@ public class Config {
* @param location Configuration location of the double
*/
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>();}
}
}

View 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());
}
}

View 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;
}
}

View File

@ -1,110 +1,108 @@
# _
# /\ /\__ _ _ __| |__ ___ _ __
# / /_/ / _` | '__| '_ \ / _ \| '__|
# / __ / (_| | | | |_) | (_) | |
# \/ /_/ \__,_|_| |_.__/ \___/|_|
#
# An open-source project by Mykyta (TechToolbox)
# https://mykyta.tk/
#
# 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),
# so every message and plugin module can be modified here. If you would like to report a bug
# or suggest a feature, make sure to add an issue on the GitHub page for this plugin!
# GitHub URL: https://github.com/nkomarn/Harbor/issues
values:
# How often to run the clock task (used to detect sleep, AFK players, time actionbar, etc.)
# Lower this value for relatively slow servers
clock: 1
# Percent of players that need to sleep to skip night (must be between 0 to 100)
percent: 35
# Time that it takes to be considered AFK (in minutes)
timeout: 15
# Time to wait before skipping the night (in seconds)
delay: 3
features:
# Toggle night skipping feature. Configure amount of players needed to skip above (percent)
skip: true
# Clear weather when skipping night
weather: true
# Toggle the spawning of phantoms
phantoms: false
# Toggle exclusion of operators/players with permission "harbor.bypass" from sleep count
bypass: true
# Toggle exclusion of players in creative and spectator mode
ignore: true
# Prevent all players from entering a bed
block: false
# Detect AFK players and remove them from the sleep count
afk: true
# Displays a notification when a new update is released
notifier: true
messages:
chat:
# Toggle chat messages
chat: true
# "Night skipped" chat messages
skipped:
- "&eThe night has been skipped."
- "&eAhhh, finally morning."
- "&eArghh, it's so bright outside."
# Display which player went to bed
sleeping: "&e[player] is now sleeping ([sleeping]/[online], [needed] more needed to skip)."
# Display when a player left their bed
left: "&e[player] got out of bed ([sleeping]/[online], [needed] more needed to skip)."
# Shown when a player tries to sleep and sleeping is blocked
blocked: "&cSleeping is disabled."
# 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."
# Shown when a player goes AFK
afk: "&7[player] has gone AFK."
# Shown when a player comes back after being AFK
unafk: "&7[player] is no longer AFK."
actionbar:
# Enable/Disable actionbar message
actionbar: true
# Shown when some players are in bed
sleeping: "&e[sleeping] out of [online] players are sleeping ([needed] more needed to skip)."
# Shown when all players are in bed
everyone: "&eEveryone is sleeping. Sweet dreams!"
# Shown when a player tries to sleep and sleeping is blocked
blocked: "&cSleeping is disabled."
title:
# Enable/Disable title messages
title: true
morning:
top: "&6Good morning!"
bottom: "&7Ah, such wonderful weather."
evening:
top: "&cIt's getting a bit late."
bottom: "&7Might want to hit the hay..."
sleeping:
top: "&8ZZZZZZ..."
bottom: "&7Sweet dreams."
miscellaneous:
# Prefix for Harbor command/miscellaneous messages
prefix: "&8&l(&6&lHarbor&8&l)&r "
# Prefix for player list names when a player is AFK
afkprefix: "&8&l(&7AFK&8&l)&7 "
# Display server version in console
running: "&7Running on version [version]."
# Sent in console when the plugin isn't compatible with the server
incompatible: "&7Spigot [version] isn't compatible with Harbor."
# Harbor reload message
reloaded: "&7Reloaded Harbor."
reloaderror: "&7Error reloading Harbor."
# Sent when player doesn't have permissions to run command
permission: "&7Insufficient permissions."
# Sent when command argument isn't recognized
unrecognized: "&7Urecognized command."
gui:
# Title for menu that shows when a player executes /sleeping
sleeping: "Sleeping Players"
# Spooky controls (don't change)
version: 1.5
debug: false
# _
# /\ /\__ _ _ __| |__ ___ _ __
# / /_/ / _` | '__| '_ \ / _ \| '__|
# / __ / (_| | | | |_) | (_) | |
# \/ /_/ \__,_|_| |_.__/ \___/|_|
#
# An open-source project by Mykyta (TechToolbox)
# https://harbor.nkomarn.xyz
#
# 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),
# so every message and plugin module can be modified here. If you would like to report a bug
# or suggest a feature, make sure to add an issue on the GitHub page for this plugin!
# GitHub URL: https://github.com/nkomarn/Harbor/issues
values:
# How often to run the clock task (used to detect sleep, AFK players, time actionbar, etc.)
# Lower this value for relatively slow servers
clock: 1
# Percent of players that need to sleep to skip night (must be between 0 to 100)
percent: 35
# Time that it takes to be considered AFK (in minutes)
timeout: 15
features:
# Toggle night skipping feature. Configure amount of players needed to skip above (percent)
skip: true
# Clear weather when skipping night
weather: true
# Toggle the spawning of phantoms (false = no phantom spawning)
phantoms: false
# Toggle exclusion of operators/players with permission "harbor.bypass" from sleep count
bypass: true
# Toggle exclusion of players in creative and spectator mode
ignore: true
# Prevent all players from entering a bed
block: false
# Detect AFK players and remove them from the sleep count
afk: true
# Displays a notification when a new update is released
notifier: true
messages:
chat:
# Toggle chat messages
chat: true
# "Night skipped" chat messages
skipped:
- "&eThe night has been skipped."
- "&eAhhh, finally morning."
- "&eArghh, it's so bright outside."
# Display which player went to bed
sleeping: "&e[player] is now sleeping ([sleeping]/[online], [needed] more needed to skip)."
# Display when a player left their bed
left: "&e[player] got out of bed ([sleeping]/[online], [needed] more needed to skip)."
# Shown when a player tries to sleep and sleeping is blocked
blocked: "&cSleeping is disabled."
# Sent to player when they sleep with "harbor.bypass" permission
bypass: "&eYou've been excluded from the sleep count."
# Shown when a player goes AFK
afk: "&7[player] has gone AFK."
# Shown when a player comes back after being AFK
unafk: "&7[player] is no longer AFK."
actionbar:
# Enable/Disable actionbar message
actionbar: true
# Shown when some players are in bed
sleeping: "&e[sleeping] out of [online] players are sleeping ([needed] more needed to skip)."
# Shown when all players are in bed
everyone: "&eEveryone is sleeping. Sweet dreams!"
# Shown when a player tries to sleep and sleeping is blocked
blocked: "&cSleeping is disabled."
title:
# Enable/Disable title messages
title: true
morning:
top: "&6Good morning!"
bottom: "&7Ah, such wonderful weather."
evening:
top: "&cIt's getting a bit late."
bottom: "&7Might want to hit the hay..."
sleeping:
top: "&8ZZZZZZ..."
bottom: "&7Sweet dreams."
miscellaneous:
# Prefix for Harbor command/miscellaneous messages
prefix: "&8&l(&6&lHarbor&8&l)&r "
# Prefix for player list names when a player is AFK
afkprefix: "&8&l(&7AFK&8&l)&7 "
# Display server version in console
running: "&7Running on version [version]."
# Sent in console when the plugin isn't compatible with the server
incompatible: "&7Spigot [version] isn't compatible with Harbor."
# Harbor reload message
reloaded: "&7Reloaded Harbor."
reloaderror: "&7Error reloading Harbor."
# Sent when player doesn't have permissions to run command
permission: "&7Insufficient permissions."
# Sent when command argument isn't recognized
unrecognized: "&7Urecognized command."
gui:
# Title for menu that shows when a player executes /sleeping
sleeping: "Sleeping Players | Page [page]"
# Spooky controls (don't change)
version: 1.5.1
debug: false

View 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"