Add broadcasting messages when players do stuff with coordinates
This commit is contained in:
@@ -13,6 +13,8 @@ import net.md_5.bungee.api.chat.TextComponent;
|
|||||||
import nl.interestingcorner.coordinates.db.Coordinate;
|
import nl.interestingcorner.coordinates.db.Coordinate;
|
||||||
import nl.interestingcorner.coordinates.db.CoordinatesDatabaseManager;
|
import nl.interestingcorner.coordinates.db.CoordinatesDatabaseManager;
|
||||||
import nl.interestingcorner.core.MinecraftColor;
|
import nl.interestingcorner.core.MinecraftColor;
|
||||||
|
import nl.interestingcorner.core.MinecraftFormattingCode;
|
||||||
|
import nl.interestingcorner.core.chat.ChatHelper;
|
||||||
|
|
||||||
public class AddCoordinateCommandHandler implements CoordinatesCommandHandler {
|
public class AddCoordinateCommandHandler implements CoordinatesCommandHandler {
|
||||||
|
|
||||||
@@ -63,7 +65,7 @@ public class AddCoordinateCommandHandler implements CoordinatesCommandHandler {
|
|||||||
|
|
||||||
player.sendMessage(MinecraftColor.BLUE.toColorCode() + "Adding coordinate '" + name + "' at your current location...");
|
player.sendMessage(MinecraftColor.BLUE.toColorCode() + "Adding coordinate '" + name + "' at your current location...");
|
||||||
//TODO check if item doesnt already exist, coordinate with same values, create isEquals method for coordinate
|
//TODO check if item doesnt already exist, coordinate with same values, create isEquals method for coordinate
|
||||||
return CoordinatesDatabaseManager.INSTANCE
|
boolean addSuccess = CoordinatesDatabaseManager.INSTANCE
|
||||||
.addCoordinate(name, // name
|
.addCoordinate(name, // name
|
||||||
description, // description
|
description, // description
|
||||||
new Coordinate.Position(playerLocation.getBlockX(), playerLocation.getBlockY(),
|
new Coordinate.Position(playerLocation.getBlockX(), playerLocation.getBlockY(),
|
||||||
@@ -72,6 +74,30 @@ public class AddCoordinateCommandHandler implements CoordinatesCommandHandler {
|
|||||||
playerWorld.getName(), // world
|
playerWorld.getName(), // world
|
||||||
MinecraftColor.fromString(color) // color
|
MinecraftColor.fromString(color) // color
|
||||||
);
|
);
|
||||||
|
if (!addSuccess) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append(MinecraftFormattingCode.ITALIC.toString())
|
||||||
|
.append(MinecraftFormattingCode.UNDERLINE.toString())
|
||||||
|
.append(MinecraftColor.LIGHT_PURPLE.toColorCode())
|
||||||
|
.append("[IC-Coords] ")
|
||||||
|
.append(MinecraftFormattingCode.RESET.toString())
|
||||||
|
.append(MinecraftColor.WHITE.toColorCode())
|
||||||
|
.append("Player ")
|
||||||
|
.append(MinecraftColor.AQUA.toColorCode())
|
||||||
|
.append(player.getName())
|
||||||
|
.append(MinecraftColor.WHITE.toColorCode())
|
||||||
|
.append(MinecraftFormattingCode.RESET.toString())
|
||||||
|
.append(" added new coordinate ")
|
||||||
|
.append(MinecraftColor.fromString(color).toColorCode())
|
||||||
|
.append(MinecraftFormattingCode.BOLD.toString())
|
||||||
|
.append(name)
|
||||||
|
.append(MinecraftFormattingCode.RESET.toString())
|
||||||
|
.append(MinecraftColor.WHITE.toColorCode())
|
||||||
|
.append(" to the map!");
|
||||||
|
ChatHelper.broadcastMessage(sb.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import nl.interestingcorner.coordinates.db.Coordinate;
|
import nl.interestingcorner.coordinates.db.Coordinate;
|
||||||
import nl.interestingcorner.coordinates.db.CoordinatesDatabaseManager;
|
import nl.interestingcorner.coordinates.db.CoordinatesDatabaseManager;
|
||||||
import nl.interestingcorner.core.MinecraftColor;
|
import nl.interestingcorner.core.MinecraftColor;
|
||||||
|
import nl.interestingcorner.core.MinecraftFormattingCode;
|
||||||
|
import nl.interestingcorner.core.chat.ChatHelper;
|
||||||
import nl.interestingcorner.core.gui.GUI;
|
import nl.interestingcorner.core.gui.GUI;
|
||||||
import nl.interestingcorner.core.gui.GUIItemClickListener;
|
import nl.interestingcorner.core.gui.GUIItemClickListener;
|
||||||
|
|
||||||
@@ -22,6 +24,28 @@ public class RemoveItemClickListener implements GUIItemClickListener{
|
|||||||
|
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
player.sendMessage("Removed coordinate " + coordinate.name);
|
player.sendMessage("Removed coordinate " + coordinate.name);
|
||||||
}
|
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append(MinecraftFormattingCode.ITALIC.toString())
|
||||||
|
.append(MinecraftFormattingCode.UNDERLINE.toString())
|
||||||
|
.append(MinecraftColor.LIGHT_PURPLE.toColorCode())
|
||||||
|
.append("[IC-Coords] ")
|
||||||
|
.append(MinecraftFormattingCode.RESET.toString())
|
||||||
|
.append(MinecraftColor.WHITE.toColorCode())
|
||||||
|
.append("Player ")
|
||||||
|
.append(MinecraftColor.AQUA.toColorCode())
|
||||||
|
.append(player.getName())
|
||||||
|
.append(MinecraftFormattingCode.RESET.toString())
|
||||||
|
.append(MinecraftColor.RED.toColorCode())
|
||||||
|
.append(" removed ")
|
||||||
|
.append(MinecraftColor.WHITE.toColorCode())
|
||||||
|
.append("coordinate ")
|
||||||
|
.append(coordinate.color.toColorCode())
|
||||||
|
.append(MinecraftFormattingCode.BOLD.toString())
|
||||||
|
.append(coordinate.name)
|
||||||
|
.append(MinecraftFormattingCode.RESET.toString())
|
||||||
|
.append(MinecraftColor.WHITE.toColorCode())
|
||||||
|
.append(" from the map!");
|
||||||
|
ChatHelper.broadcastMessage(sb.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import nl.interestingcorner.coordinates.db.Coordinate;
|
import nl.interestingcorner.coordinates.db.Coordinate;
|
||||||
|
import nl.interestingcorner.core.MinecraftColor;
|
||||||
|
import nl.interestingcorner.core.MinecraftFormattingCode;
|
||||||
|
import nl.interestingcorner.core.chat.ChatHelper;
|
||||||
import nl.interestingcorner.core.gui.GUI;
|
import nl.interestingcorner.core.gui.GUI;
|
||||||
import nl.interestingcorner.core.gui.GUIItemClickListener;
|
import nl.interestingcorner.core.gui.GUIItemClickListener;
|
||||||
import nl.interestingcorner.core.logging.Logger;
|
import nl.interestingcorner.core.logging.Logger;
|
||||||
@@ -26,6 +29,25 @@ public class TeleportItemClickListener implements GUIItemClickListener {
|
|||||||
player.teleport(loc);
|
player.teleport(loc);
|
||||||
player.sendTitle(coordinate.name, coordinate.description, 10, 70, 20);
|
player.sendTitle(coordinate.name, coordinate.description, 10, 70, 20);
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append(MinecraftFormattingCode.ITALIC.toString())
|
||||||
|
.append(MinecraftFormattingCode.UNDERLINE.toString())
|
||||||
|
.append(MinecraftColor.LIGHT_PURPLE.toColorCode())
|
||||||
|
.append("[IC-Coords] ")
|
||||||
|
.append(MinecraftFormattingCode.RESET.toString())
|
||||||
|
.append(MinecraftColor.WHITE.toColorCode())
|
||||||
|
.append("Player ")
|
||||||
|
.append(MinecraftColor.AQUA.toColorCode())
|
||||||
|
.append(player.getName())
|
||||||
|
.append(MinecraftFormattingCode.RESET.toString())
|
||||||
|
.append(MinecraftColor.WHITE.toColorCode())
|
||||||
|
.append(" yeeted themselves to ")
|
||||||
|
.append(coordinate.color.toColorCode())
|
||||||
|
.append(MinecraftFormattingCode.BOLD.toString())
|
||||||
|
.append(coordinate.name)
|
||||||
|
.append(MinecraftFormattingCode.RESET.toString())
|
||||||
|
.append(MinecraftColor.WHITE.toColorCode());
|
||||||
|
ChatHelper.broadcastMessage(sb.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package nl.interestingcorner.core;
|
||||||
|
|
||||||
|
public enum MinecraftFormattingCode {
|
||||||
|
BOLD("§l"),
|
||||||
|
ITALIC("§o"),
|
||||||
|
UNDERLINE("§n"),
|
||||||
|
STRIKETHROUGH("§m"),
|
||||||
|
RESET("§r"),
|
||||||
|
OBFUSCATED("§k");
|
||||||
|
|
||||||
|
private final String code;
|
||||||
|
|
||||||
|
MinecraftFormattingCode(String code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package nl.interestingcorner.core.chat;
|
||||||
|
|
||||||
|
import org.bukkit.Server;
|
||||||
|
|
||||||
|
public class ChatHelper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a message to all online players on the server.
|
||||||
|
* @param message the message to send
|
||||||
|
*/
|
||||||
|
public static void sendMessageToEveryone(String message) {
|
||||||
|
Server server = org.bukkit.Bukkit.getServer();
|
||||||
|
server.getOnlinePlayers().forEach(player -> player.sendMessage(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Broadcasts a message to all players on the server, including those who are not online.
|
||||||
|
* @param message the message to send
|
||||||
|
*/
|
||||||
|
public static void broadcastMessage(String message) {
|
||||||
|
Server server = org.bukkit.Bukkit.getServer();
|
||||||
|
server.broadcastMessage(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user