1
0
mirror of https://github.com/nkomarn/harbor.git synced 2024-12-18 22:37:36 +01:00

Beginning some work on 1.5!

This commit is contained in:
BuildTools 2019-03-04 19:16:28 -08:00
parent 87a7079e55
commit 6cd5580508
37 changed files with 306 additions and 612 deletions

44
.classpath Normal file
View File

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
/bin/
spigot
.vscode
target

View File

@ -10,8 +10,14 @@
<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>

View File

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

View File

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

View File

@ -0,0 +1,7 @@
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

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

View File

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="T:/Test Server/1.13.2/Spigot.jar"/>
<classpathentry kind="lib" path="T:/Test Server/1.8/Spigot.jar"/>
<classpathentry kind="lib" path="T:/Test Server/1.8.3/Spigot.jar"/>
<classpathentry kind="lib" path="T:/Test Server/1.8.8/Spigot.jar"/>
<classpathentry kind="lib" path="T:/Test Server/1.9/Spigot.jar"/>
<classpathentry kind="lib" path="T:/Test Server/1.9.2/Spigot.jar"/>
<classpathentry kind="lib" path="T:/Test Server/1.10/Spigot.jar"/>
<classpathentry kind="lib" path="T:/Test Server/1.10.2/Spigot.jar"/>
<classpathentry kind="lib" path="T:/Test Server/1.11/Spigot.jar"/>
<classpathentry kind="lib" path="T:/Test Server/1.11.1/Spigot.jar"/>
<classpathentry kind="lib" path="T:/Test Server/1.11.2/Spigot.jar"/>
<classpathentry kind="lib" path="T:/Test Server/1.12/Spigot.jar"/>
<classpathentry kind="lib" path="T:/Test Server/1.12.1/Spigot.jar"/>
<classpathentry kind="lib" path="T:/Test Server/1.12.2/Spigot.jar"/>
<classpathentry kind="lib" path="T:/Test Server/1.13/Spigot.jar"/>
<classpathentry kind="lib" path="T:/Test Server/1.13.1/Spigot.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

1
Harbor/.gitignore vendored
View File

@ -1 +0,0 @@
/bin/

View File

@ -1,11 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8

View File

@ -1,31 +0,0 @@
package techtoolbox.Harbor;
import org.bukkit.Bukkit;
public class ActionBarMessage implements Runnable {
@Override
public void run() {
<<<<<<< HEAD
for (int i = 0; Main.worlds.size() > i; i++) {
if (((Main.worlds.get(Bukkit.getServer().getWorlds().get(i))).intValue() > 0) && ((Main.worlds.get(Bukkit.getServer().getWorlds().get(i))).intValue() < (Bukkit.getServer().getWorlds().get(i)).getPlayers().size() - Main.bypassers.size())) {
Main.sendActionbar("playersInBed", Bukkit.getServer().getWorlds().get(i));
}
else if (((Main.worlds.get(Bukkit.getServer().getWorlds().get(i))).intValue() == (Bukkit.getServer().getWorlds().get(i)).getPlayers().size() - Main.bypassers.size()) && ((Bukkit.getServer().getWorlds().get(i)).getPlayers().size() - Main.bypassers.size() > 1)) {
Main.sendActionbar("everyoneSleeping", Bukkit.getServer().getWorlds().get(i));
=======
try {
for (int i = 0; Main.worlds.size() > i; i++) {
if (((Main.worlds.get(Bukkit.getServer().getWorlds().get(i))).intValue() > 0) && ((Main.worlds.get(Bukkit.getServer().getWorlds().get(i))).intValue() < (Bukkit.getServer().getWorlds().get(i)).getPlayers().size() - Main.bypassers.size())) {
Main.sendActionbar("playersInBed", Bukkit.getServer().getWorlds().get(i), null);
}
else if (((Main.worlds.get(Bukkit.getServer().getWorlds().get(i))).intValue() == (Bukkit.getServer().getWorlds().get(i)).getPlayers().size() - Main.bypassers.size()) && ((Bukkit.getServer().getWorlds().get(i)).getPlayers().size() - Main.bypassers.size() > 1)) {
Main.sendActionbar("everyoneSleeping", Bukkit.getServer().getWorlds().get(i), null);
}
>>>>>>> Update 1.4.4, I guess.
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -1,8 +0,0 @@
package techtoolbox.Harbor.Actionbar;
import org.bukkit.entity.Player;
public interface Actionbar {
public void sendActionbar(Player player, String message);
}

View File

@ -1,19 +0,0 @@
package techtoolbox.Harbor.Actionbar;
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.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_10_R1.PacketPlayOutChat;
public class Actionbar_1_10_R1 implements Actionbar {
@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);
}
}

View File

@ -1,19 +0,0 @@
package techtoolbox.Harbor.Actionbar;
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.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_11_R1.PacketPlayOutChat;
public class Actionbar_1_11_R1 implements Actionbar {
@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);
}
}

View File

@ -1,20 +0,0 @@
package techtoolbox.Harbor.Actionbar;
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.ChatMessageType;
import net.minecraft.server.v1_12_R1.IChatBaseComponent;
import net.minecraft.server.v1_12_R1.PacketPlayOutChat;
public class Actionbar_1_12_R1 implements Actionbar {
@Override
public void sendActionbar(Player player, String message) {
IChatBaseComponent titleComponent = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");
PacketPlayOutChat titlePacket = new PacketPlayOutChat(titleComponent, ChatMessageType.GAME_INFO);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(titlePacket);
}
}

View File

@ -1,18 +0,0 @@
package techtoolbox.Harbor.Actionbar;
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.PacketPlayOutTitle;
public class Actionbar_1_13_R1 implements Actionbar {
@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);
}
}

View File

@ -1,19 +0,0 @@
package techtoolbox.Harbor.Actionbar;
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.IChatBaseComponent;
import net.minecraft.server.v1_8_R1.PacketPlayOutChat;
public class Actionbar_1_8_R1 implements Actionbar {
@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);
}
}

View File

@ -1,19 +0,0 @@
package techtoolbox.Harbor.Actionbar;
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;
public class Actionbar_1_8_R2 implements Actionbar {
@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);
}
}

View File

@ -1,20 +0,0 @@
package techtoolbox.Harbor.Actionbar;
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;
public class Actionbar_1_8_R3 implements Actionbar {
@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);
}
}

View File

@ -1,20 +0,0 @@
package techtoolbox.Harbor.Actionbar;
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.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_9_R1.PacketPlayOutChat;
public class Actionbar_1_9_R1 implements Actionbar {
@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);
}
}

View File

@ -1,40 +0,0 @@
package techtoolbox.Harbor;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class Command implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, org.bukkit.command.Command cmd, String label, String[] args) {
if (args.length < 1) {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', Main.plugin.getConfig().getString("messages.miscellaneous.prefix") + "&7Version " + Main.version + " by TechToolbox."));
}
else if (args[0].equalsIgnoreCase("reload")) {
if (sender.hasPermission("harbor.admin")) {
try {
Main.bypassers.clear();
Main.plugin.reloadConfig();
Bukkit.getServer().getPluginManager().disablePlugin(Main.plugin);
Bukkit.getServer().getPluginManager().enablePlugin(Main.plugin);
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', Main.plugin.getConfig().getString("messages.miscellaneous.prefix") + Main.plugin.getConfig().getString("messages.miscellaneous.reloaded")));
}
catch (Exception e) {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', Main.plugin.getConfig().getString("messages.miscellaneous.prefix") + Main.plugin.getConfig().getString("messages.miscellaneous.reloadError")));
if (!Main.plugin.getConfig().getBoolean("features.debug")) {
e.printStackTrace();
}
}
}
else {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', Main.plugin.getConfig().getString("messages.miscellaneous.prefix") + Main.plugin.getConfig().getString("messages.miscellaneous.permission")));
}
}
else if (args[0].equalsIgnoreCase("test")) {
System.out.println(Main.worlds.size());
System.out.println(Main.bypassers.size());
}
return true;
}
}

View File

@ -1,131 +0,0 @@
package techtoolbox.Harbor.Listeners;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
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 techtoolbox.Harbor.Main;
public class BedEnterEvent implements Listener {
String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerBedEnterEvent(PlayerBedEnterEvent event) {
// Sleep blocking feature
if (Main.plugin.getConfig().getBoolean("features.blockSleep")) {
if (Main.plugin.getConfig().getString("messages.chat.blocked").length() > 0) {
event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', Main.plugin.getConfig().getString("messages.chat.blocked")));
}
Main.sendActionbar("sleepingBlocked", null, event.getPlayer());
event.setCancelled(true);
}
else {
// TEMPORARY SOLUTION FOR 1.13.2: CHECK IF BEDENTERRESULT WORKS, IF NOT THEN RUN 1.13.1 CODE
try {
if (event.getBedEnterResult() == BedEnterResult.OK) {
Main.bypassers.clear();
if (Main.plugin.getConfig().getBoolean("features.bypass")) {
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
if (player.hasPermission("harbor.bypass")) {
Main.bypassers.add(player.getName());
}
}
}
if (!Main.plugin.getConfig().getBoolean("features.bypass") || !event.getPlayer().hasPermission("harbor.bypass")) {
try {
Main.worlds.put(event.getPlayer().getWorld(), Integer.valueOf((Main.worlds.get(event.getPlayer().getWorld())).intValue() + 1));
}
catch (Exception exception) {
// Create value if it doesn't exist already
Main.worlds.put(event.getPlayer().getWorld(), 1);
}
// Chat messages
if (Main.plugin.getConfig().getBoolean("messages.chat.chat") && (Main.plugin.getConfig().getString("messages.chat.sleeping").length() != 0)) {
Bukkit.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', Main.plugin.getConfig().getString("messages.chat.sleeping")
.replace("[sleeping]", String.valueOf(Main.worlds.get(event.getPlayer().getWorld())))
.replace("[online]", String.valueOf(event.getPlayer().getWorld().getPlayers().size() - Main.bypassers.size()))
.replace("[player]", event.getPlayer().getName())
.replace("[needed]", String.valueOf(Math.max(0, Math.round(event.getPlayer().getWorld().getPlayers().size() * Float.parseFloat(Main.plugin.getConfig().getString("values.percent")) - Main.bypassers.size() - (Main.worlds.get(event.getPlayer().getWorld())).intValue()))))));
}
// Skip night feature
if (Main.plugin.getConfig().getBoolean("features.skipNight") && ((Main.worlds.get(event.getPlayer().getWorld())).intValue() >= event.getPlayer().getWorld().getPlayers().size() * Float.parseFloat(Main.plugin.getConfig().getString("values.percent")) - Main.bypassers.size()) && (event.getPlayer().getWorld().getPlayers().size() > 1)) {
Bukkit.getServer().getWorld(event.getPlayer().getWorld().getName()).setTime(1000L);
// Weather clear feature
if (Main.plugin.getConfig().getBoolean("features.clearWeather")) {
event.getPlayer().getWorld().setStorm(false);
event.getPlayer().getWorld().setThundering(false);
}
// Night skipped message
if (Main.plugin.getConfig().getBoolean("messages.chat.chat") && (Main.plugin.getConfig().getString("messages.chat.skipped").length() != 0)) {
Bukkit.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', Main.plugin.getConfig().getString("messages.chat.skipped")));
}
}
}
else if (Main.plugin.getConfig().getString("messages.chat.bypass").length() != 0) {
event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', Main.plugin.getConfig().getString("messages.chat.bypass")));
}
}
}
catch (NoSuchMethodError e){
Main.bypassers.clear();
if (Main.plugin.getConfig().getBoolean("features.bypass")) {
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
if (player.hasPermission("harbor.bypass")) {
Main.bypassers.add(player.getName());
}
}
}
if (!event.getPlayer().hasPermission("harbor.bypass")) {
try {
Main.worlds.put(event.getPlayer().getWorld(), Integer.valueOf((Main.worlds.get(event.getPlayer().getWorld())).intValue() + 1));
}
catch (Exception exception) {
// Create value if it doesn't exist already
Main.worlds.put(event.getPlayer().getWorld(), 1);
}
// Chat messages
if (Main.plugin.getConfig().getBoolean("messages.chat.chat") && (Main.plugin.getConfig().getString("messages.chat.sleeping").length() != 0)) {
Bukkit.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', Main.plugin.getConfig().getString("messages.chat.sleeping")
.replace("[sleeping]", String.valueOf(Main.worlds.get(event.getPlayer().getWorld())))
.replace("[online]", String.valueOf(event.getPlayer().getWorld().getPlayers().size() - Main.bypassers.size()))
.replace("[player]", event.getPlayer().getName())
.replace("[needed]", String.valueOf(Math.max(0, Math.round(event.getPlayer().getWorld().getPlayers().size() * Float.parseFloat(Main.plugin.getConfig().getString("values.percent")) - Main.bypassers.size() - (Main.worlds.get(event.getPlayer().getWorld())).intValue()))))));
}
// Skip night feature
if (Main.plugin.getConfig().getBoolean("features.skipNight") && ((Main.worlds.get(event.getPlayer().getWorld())).intValue() >= event.getPlayer().getWorld().getPlayers().size() * Float.parseFloat(Main.plugin.getConfig().getString("values.percent")) - Main.bypassers.size()) && (event.getPlayer().getWorld().getPlayers().size() > 1)) {
Bukkit.getServer().getWorld(event.getPlayer().getWorld().getName()).setTime(1000L);
// Weather clear feature
if (Main.plugin.getConfig().getBoolean("features.clearWeather")) {
event.getPlayer().getWorld().setStorm(false);
event.getPlayer().getWorld().setThundering(false);
}
// Night skipped message
if (Main.plugin.getConfig().getBoolean("messages.chat.chat") && (Main.plugin.getConfig().getString("messages.chat.skipped").length() != 0)) {
Bukkit.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', Main.plugin.getConfig().getString("messages.chat.skipped")));
}
}
}
else if (Main.plugin.getConfig().getString("messages.chat.bypass").length() != 0) {
event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', Main.plugin.getConfig().getString("messages.chat.bypass")));
}
}
}
}
}

View File

@ -1,29 +0,0 @@
package techtoolbox.Harbor.Listeners;
import org.bukkit.Bukkit;
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 techtoolbox.Harbor.Main;
public class BedLeaveEvent implements Listener {
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerBedLeave(PlayerBedLeaveEvent event) {
Main.bypassers.clear();
if (Main.plugin.getConfig().getBoolean("features.bypass")) {
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
if (player.hasPermission("harbor.bypass")) {
Main.bypassers.add(player.getName());
}
}
}
if (!Main.plugin.getConfig().getBoolean("features.bypass") || !event.getPlayer().hasPermission("harbor.bypass")) {
Main.worlds.put(event.getPlayer().getWorld(), Integer.valueOf((Main.worlds.get(event.getPlayer().getWorld())).intValue() - 1));
}
}
}

View File

@ -1,23 +0,0 @@
package techtoolbox.Harbor.Listeners;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import techtoolbox.Harbor.Main;
public class JoinEvent implements Listener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Main.bypassers.clear();
if (Main.plugin.getConfig().getBoolean("features.bypass")) {
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
if (player.hasPermission("harbor.bypass")) {
Main.bypassers.add(player.getName());
}
}
}
}
}

View File

@ -1,23 +0,0 @@
package techtoolbox.Harbor.Listeners;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import techtoolbox.Harbor.Main;
public class QuitEvent implements Listener{
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
Main.bypassers.clear();
if (Main.plugin.getConfig().getBoolean("features.bypass")) {
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
if (player.hasPermission("harbor.bypass")) {
Main.bypassers.add(player.getName());
}
}
}
}
}

View File

@ -1,132 +0,0 @@
package techtoolbox.Harbor;
import java.util.ArrayList;
import java.util.HashMap;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import techtoolbox.Harbor.Actionbar.Actionbar;
import techtoolbox.Harbor.Actionbar.Actionbar_1_10_R1;
import techtoolbox.Harbor.Actionbar.Actionbar_1_11_R1;
import techtoolbox.Harbor.Actionbar.Actionbar_1_12_R1;
import techtoolbox.Harbor.Actionbar.Actionbar_1_13_R1;
import techtoolbox.Harbor.Actionbar.Actionbar_1_13_R2;
import techtoolbox.Harbor.Actionbar.Actionbar_1_8_R1;
import techtoolbox.Harbor.Actionbar.Actionbar_1_8_R2;
import techtoolbox.Harbor.Actionbar.Actionbar_1_8_R3;
import techtoolbox.Harbor.Actionbar.Actionbar_1_9_R1;
import techtoolbox.Harbor.Listeners.BedEnterEvent;
import techtoolbox.Harbor.Listeners.BedLeaveEvent;
import techtoolbox.Harbor.Listeners.JoinEvent;
import techtoolbox.Harbor.Listeners.QuitEvent;
public class Main extends JavaPlugin implements Listener {
public static Main plugin;
public static String version = "1.4.4";
public static HashMap<World, Integer> worlds = new HashMap<World, Integer>();
public static ArrayList<String> bypassers = new ArrayList<String>();
public static Actionbar actionbar;
public void onEnable() {
plugin = this;
saveDefaultConfig();
getCommand("harbor").setExecutor(new Command());
Bukkit.getPluginManager().registerEvents(new JoinEvent(), this);
Bukkit.getPluginManager().registerEvents(new QuitEvent(), this);
Bukkit.getPluginManager().registerEvents(new BedEnterEvent(), this);
Bukkit.getPluginManager().registerEvents(new BedLeaveEvent(), this);
// Fill up worlds list
if (getConfig().getBoolean("features.bypass")) {
for (int i = 0; Bukkit.getServer().getWorlds().size() > i; i++) {
worlds.put(Bukkit.getServer().getWorlds().get(i), Integer.valueOf(0));
}
}
// Start actionbar message check
if (getConfig().getBoolean("messages.actionbar.actionbar")) {
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new ActionBarMessage(), 0L, getConfig().getInt("values.check") * 20);
}
// Set up actionbar NMS
if (setupActionbar()) {
Bukkit.getPluginManager().registerEvents(this, this);
} else {
String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("messages.miscellaneous.incompatible").replace("[version]", version)));
Bukkit.getPluginManager().disablePlugin(this);
}
}
public void onDisable() {
// Knock players out of bed
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
player.damage(0.000001);
}
}
public static void sendActionbar(String type, World world, Player player) {
if (type.equals("playersInBed")) {
for (Player p : world.getPlayers()) {
actionbar.sendActionbar(p, plugin.getConfig().getString("messages.actionbar.sleeping")
.replace("[sleeping]", String.valueOf(worlds.get(world)))
.replace("[online]", String.valueOf(world.getPlayers().size() - bypassers.size()))
.replace("[needed]", String.valueOf(Math.max(0, Math.round(world.getPlayers().size() * Float.parseFloat(plugin.getConfig().getString("values.percent")) - bypassers.size() - ((Integer)worlds.get(world)).intValue())))));
}
}
else if (type.equals("everyoneSleeping")) {
for (Player p : world.getPlayers()) {
actionbar.sendActionbar(p, plugin.getConfig().getString("messages.actionbar.everyone")
.replace("[sleeping]", String.valueOf(worlds.get(world)))
.replace("[online]", String.valueOf(world.getPlayers().size() - bypassers.size()))
.replace("[needed]", String.valueOf(Math.max(0, Math.round(world.getPlayers().size() * Float.parseFloat(plugin.getConfig().getString("values.percent")) - bypassers.size() - ((Integer)worlds.get(world)).intValue())))));
}
}
else if (type.equals("sleepingBlocked")) {
actionbar.sendActionbar(player, plugin.getConfig().getString("messages.actionbar.blocked"));
}
}
private boolean setupActionbar() {
String version;
try {
version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
}
catch (ArrayIndexOutOfBoundsException e) {
if (plugin.getConfig().getBoolean("features.debug")) {
e.printStackTrace();
}
return false;
}
Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("messages.miscellaneous.prefix") + plugin.getConfig().getString("messages.miscellaneous.running").replace("[version]", version)));
// Actionbar
if (version.equals("v1_8_R1")) {
actionbar = new Actionbar_1_8_R1();
}else if (version.equals("v1_8_R2")) {
actionbar = new Actionbar_1_8_R2();
}else if (version.equals("v1_8_R3")) {
actionbar = new Actionbar_1_8_R3();
}else if (version.equals("v1_9_R1")) {
actionbar = new Actionbar_1_9_R1();
}else if (version.equals("v1_10_R1")) {
actionbar = new Actionbar_1_10_R1();
}else if (version.equals("v1_11_R1")) {
actionbar = new Actionbar_1_11_R1();
}else if (version.equals("v1_12_R1")) {
actionbar = new Actionbar_1_12_R1();
}else if (version.equals("v1_13_R1")) {
actionbar = new Actionbar_1_13_R1();
} else if (version.equals("v1_13_R2")) {
actionbar = new Actionbar_1_13_R2();
}
return actionbar != null;
}
}

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!
*Currently undergoing a rewrite for version 1.5.*
https://www.spigotmc.org/resources/harbor-a-sleep-enhancement-plugin.60088/

View File

@ -66,4 +66,4 @@ messages:
permission: "&7Insufficient permissions."
# Version identifier (do not change)
version: 1.4.4
version: 1.5

View File

@ -1,9 +1,9 @@
name: Harbor
version: 1.4.4
main: techtoolbox.Harbor.Main
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: TechToolbox
website: https://techtoolbox.tk
author: Mykyta (TechToolbox)
website: https://mykyta.tk
commands:
harbor:

61
pom.xml Normal file
View File

@ -0,0 +1,61 @@
<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>
<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>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
</dependencies>
<build>
<directory>/home/nkomarn/Documents/Spigot Servers/1.13.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>

View File

@ -0,0 +1,7 @@
package mykyta.Harbor.Actionbar;
import org.bukkit.entity.Player;
public interface Actionbar {
public void sendActionbar(Player player, String message);
}

View File

@ -1,4 +1,4 @@
package techtoolbox.Harbor.Actionbar;
package mykyta.Harbor.Actionbar;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer;
@ -8,7 +8,6 @@ import net.minecraft.server.v1_13_R2.IChatBaseComponent;
import net.minecraft.server.v1_13_R2.PacketPlayOutTitle;
public class Actionbar_1_13_R2 implements Actionbar {
@Override
public void sendActionbar(Player player, String message) {
IChatBaseComponent titleComponent = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message) + "\"}");

View File

@ -0,0 +1,32 @@
package mykyta.Harbor.Events;
import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerBedEnterEvent;
import mykyta.Harbor.Harbor;
public class BedEnter implements Listener {
Harbor harbor;
public BedEnter(Harbor instance) {
harbor = instance;
}
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerBedEnterEvent(PlayerBedEnterEvent event) {
// Prevent bed entry if "blockSleep" is enabled in the config
if (harbor.getConfig().getBoolean("features.blockSleep")) {
if (harbor.getConfig().getString("messages.chat.blocked").length() > 0) {
event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', harbor.getConfig().getString("messages.chat.blocked")));
}
//Main.sendActionbar("sleepingBlocked", null, event.getPlayer())
event.setCancelled(true);
return;
}
}
}

View File

@ -0,0 +1,21 @@
package mykyta.Harbor;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import mykyta.Harbor.Events.BedEnter;
public class Harbor extends JavaPlugin {
Updater updater = new Updater();
public void onEnable() {
saveDefaultConfig();
Bukkit.getPluginManager().registerEvents(new BedEnter(this), this);
System.out.println("Checking for updates");
updater.check();
}
public void onDisable() {
}
}

View File

@ -0,0 +1,25 @@
package mykyta.Harbor;
public class Task implements Runnable {
@Override
public void run() {
}
/* @Override
public void run() {
try {
for (int i = 0; Main.worlds.size() > i; i++) {
if (((Main.worlds.get(Bukkit.getServer().getWorlds().get(i))).intValue() > 0) && ((Main.worlds.get(Bukkit.getServer().getWorlds().get(i))).intValue() < (Bukkit.getServer().getWorlds().get(i)).getPlayers().size() - Main.bypassers.size())) {
Main.sendActionbar("playersInBed", Bukkit.getServer().getWorlds().get(i));
}
else if (((Main.worlds.get(Bukkit.getServer().getWorlds().get(i))).intValue() == (Bukkit.getServer().getWorlds().get(i)).getPlayers().size() - Main.bypassers.size()) && ((Bukkit.getServer().getWorlds().get(i)).getPlayers().size() - Main.bypassers.size() > 1)) {
Main.sendActionbar("everyoneSleeping", Bukkit.getServer().getWorlds().get(i));
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}*/
}

View File

@ -0,0 +1,72 @@
package mykyta.Harbor;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
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;
public class Updater {
/**
* Checks for an update using the Spiget API
* @see https://spiget.org/
*/
public boolean check() {
try {
URL url = new URL("https://api.spiget.org/v2/resources/60088/versions");
URLConnection request = url.openConnection();
request.connect();
Util util = new Util();
ArrayList<String> releases = new ArrayList<String>();
JsonParser parser = new JsonParser();
JsonElement element = parser.parse(new InputStreamReader((InputStream) request.getContent()));
JsonArray versions = element.getAsJsonArray();
for (JsonElement version : versions) {
JsonObject id = version.getAsJsonObject();
releases.add(id.get("name").getAsString());
}
// TODO add super secret message for when the version is newer than the latest published one
if (util.version.equals(releases.get(releases.size() - 1))) {
System.out.println("Running latest version.");
return false;
}
else {
System.out.println("Running an outdated version! Latest is " + releases.get(releases.size() - 1));
return true;
}
/*
int current = Integer.parseInt(String.valueOf(util.version).replace(".", ""));
int latest = releases.get(releases.size() - 1);
System.out.println("Current version: " + current);
System.out.println("Latest release: " + latest);
if (util.version < latest) {
System.out.println("Update available! Version " + String.valueOf(latest));
return true;
}
else if (util.version < latest) {
System.out.println("Hmm... you're using some sort of time travel technology (your version is newer than the latest release). Welp, at least you don't have updates to worry about any time soon.");
return true;
}
else {
System.out.println("Using the latest version.");
return false;
} */
}
catch (IOException e) {
System.out.println("Failed to check for updates.");
return false;
}
}
}

View File

@ -0,0 +1,10 @@
package mykyta.Harbor;
import java.util.HashMap;
import org.bukkit.World;
public class Util {
public static HashMap<World, Integer> worlds = new HashMap<World, Integer>();
public String version = "1.5";
}