mirror of
https://github.com/nkomarn/harbor.git
synced 2024-12-18 22:37:36 +01:00
📣 Add bed chat messages back in
This commit is contained in:
parent
58f074a4ac
commit
71dbe4e164
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,5 +1,5 @@
|
||||
/bin
|
||||
/.classpath
|
||||
.classpath
|
||||
/.project
|
||||
/.settings
|
||||
/.idea
|
||||
|
2
build.sh
2
build.sh
@ -1,2 +0,0 @@
|
||||
mvn package
|
||||
cp -rf target/*.jar ../../Documents/Spigot/1.14.4/plugins
|
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>xyz.nkomarn</groupId>
|
||||
<artifactId>Harbor</artifactId>
|
||||
<version>1.6.1</version>
|
||||
<version>1.6.2</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
@ -4,7 +4,8 @@ import com.earth2me.essentials.Essentials;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import xyz.nkomarn.Harbor.command.HarborCommand;
|
||||
import xyz.nkomarn.Harbor.listener.PlayerListener;
|
||||
import xyz.nkomarn.Harbor.listener.BedListener;
|
||||
import xyz.nkomarn.Harbor.listener.JoinListener;
|
||||
import xyz.nkomarn.Harbor.task.Checker;
|
||||
import xyz.nkomarn.Harbor.util.Config;
|
||||
import xyz.nkomarn.Harbor.util.Metrics;
|
||||
@ -12,7 +13,7 @@ import xyz.nkomarn.Harbor.util.Metrics;
|
||||
public class Harbor extends JavaPlugin {
|
||||
|
||||
public static Harbor instance;
|
||||
public static String version = "1.6.1";
|
||||
public static String version = "1.6.2";
|
||||
public static Essentials essentials;
|
||||
|
||||
public void onEnable() {
|
||||
@ -24,7 +25,8 @@ public class Harbor extends JavaPlugin {
|
||||
}
|
||||
|
||||
getCommand("harbor").setExecutor(new HarborCommand());
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new JoinListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new BedListener(), this);
|
||||
|
||||
// bStats
|
||||
new Metrics(this);
|
||||
|
26
src/main/java/xyz/nkomarn/Harbor/listener/BedListener.java
Normal file
26
src/main/java/xyz/nkomarn/Harbor/listener/BedListener.java
Normal file
@ -0,0 +1,26 @@
|
||||
package xyz.nkomarn.Harbor.listener;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerBedEnterEvent;
|
||||
import xyz.nkomarn.Harbor.util.Config;
|
||||
import xyz.nkomarn.Harbor.util.Messages;
|
||||
|
||||
public class BedListener implements Listener {
|
||||
@EventHandler
|
||||
public void onBedEnter(final PlayerBedEnterEvent event) {
|
||||
if (event.getBedEnterResult() != PlayerBedEnterEvent.BedEnterResult.OK) return;
|
||||
Messages.sendWorldChatMessage(event.getBed().getWorld(),
|
||||
Config.getString("messages.chat.sleeping")
|
||||
.replace("[player]", event.getPlayer().getName())
|
||||
.replace("[displayname]", event.getPlayer().getDisplayName()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBedLeave(final PlayerBedEnterEvent event) {
|
||||
Messages.sendWorldChatMessage(event.getBed().getWorld(),
|
||||
Config.getString("messages.chat.left")
|
||||
.replace("[player]", event.getPlayer().getName())
|
||||
.replace("[displayname]", event.getPlayer().getDisplayName()));
|
||||
}
|
||||
}
|
44
src/main/java/xyz/nkomarn/Harbor/listener/JoinListener.java
Normal file
44
src/main/java/xyz/nkomarn/Harbor/listener/JoinListener.java
Normal file
@ -0,0 +1,44 @@
|
||||
package xyz.nkomarn.Harbor.listener;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import xyz.nkomarn.Harbor.Harbor;
|
||||
import xyz.nkomarn.Harbor.util.Config;
|
||||
import xyz.nkomarn.Harbor.util.Updater;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class JoinListener implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
if (!event.getPlayer().hasPermission("harbor.admin") || !Config.getBoolean("features.notifier")) return;
|
||||
|
||||
// Check for updates
|
||||
Bukkit.getScheduler().runTaskAsynchronously(Harbor.instance, () -> {
|
||||
boolean updateAvailable = false;
|
||||
try {
|
||||
updateAvailable = Updater.check().get();
|
||||
} catch (InterruptedException | ExecutionException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
if (!updateAvailable) return;
|
||||
TextComponent updateMessage = new TextComponent(ChatColor.translateAlternateColorCodes('&',
|
||||
Config.getString("messages.miscellaneous.prefix")
|
||||
+ "&7Hey there, Harbor " + Updater.latest + " is now out!"
|
||||
+ " Click this message to upgrade automatically."));
|
||||
updateMessage.setColor(ChatColor.GRAY);
|
||||
updateMessage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
new ComponentBuilder("§a§l↑ §7Click to update Harbor now!").create()));
|
||||
updateMessage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/harbor update"));
|
||||
event.getPlayer().spigot().sendMessage(updateMessage);
|
||||
});
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package xyz.nkomarn.Harbor.listener;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import xyz.nkomarn.Harbor.Harbor;
|
||||
import xyz.nkomarn.Harbor.util.Config;
|
||||
import xyz.nkomarn.Harbor.util.Updater;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
if (!e.getPlayer().hasPermission("harbor.admin") || !Config.getBoolean("features.notifier")) return;
|
||||
|
||||
// Check for updates
|
||||
Bukkit.getScheduler().runTaskAsynchronously(Harbor.instance, () -> {
|
||||
boolean updateAvailable = false;
|
||||
try {
|
||||
updateAvailable = Updater.check().get();
|
||||
} catch (InterruptedException | ExecutionException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
if (updateAvailable) {
|
||||
TextComponent updateMessage = new TextComponent(ChatColor.translateAlternateColorCodes('&',
|
||||
Config.getString("messages.miscellaneous.prefix")
|
||||
+ "&7Hey there, Harbor " + Updater.latest + " is now out!"
|
||||
+ " Click this message to upgrade automatically."));
|
||||
updateMessage.setColor(ChatColor.GRAY);
|
||||
updateMessage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
new ComponentBuilder("§a§l↑ §7Click to update Harbor now!").create()));
|
||||
updateMessage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/harbor update"));
|
||||
e.getPlayer().spigot().sendMessage(updateMessage);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -11,7 +11,6 @@ import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class Messages {
|
||||
|
||||
public static void sendRandomChatMessage(final World world, final String messageList) {
|
||||
final List<String> messages = Config.getList(messageList);
|
||||
if (messages.size() < 1) return;
|
||||
@ -19,7 +18,7 @@ public class Messages {
|
||||
sendWorldChatMessage(world, messages.get(index));
|
||||
}
|
||||
|
||||
private static void sendWorldChatMessage(final World world, final String message) {
|
||||
public static void sendWorldChatMessage(final World world, final String message) {
|
||||
if (!Config.getBoolean("messages.chat.chat") || message.length() < 1) return;
|
||||
world.getPlayers().forEach(player -> player.sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||
prepareMessage(world, message))));
|
||||
|
Loading…
Reference in New Issue
Block a user