Add chat and nations
This commit is contained in:
parent
bcc487623b
commit
6e3f2af410
7
pom.xml
7
pom.xml
|
@ -69,14 +69,9 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.papermc.paper</groupId>
|
<groupId>io.papermc.paper</groupId>
|
||||||
<artifactId>paper-api</artifactId>
|
<artifactId>paper-api</artifactId>
|
||||||
<version>1.18.1-R0.1-SNAPSHOT</version>
|
<version>1.18.2-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-simple</artifactId>
|
|
||||||
<version>1.7.36</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.luckperms</groupId>
|
<groupId>net.luckperms</groupId>
|
||||||
<artifactId>api</artifactId>
|
<artifactId>api</artifactId>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package moe.oko.opennaw;
|
package moe.oko.opennaw;
|
||||||
|
|
||||||
import moe.oko.opennaw.command.NationCommand;
|
import moe.oko.opennaw.command.NationCommand;
|
||||||
|
import moe.oko.opennaw.util.ChatHandler;
|
||||||
import moe.oko.opennaw.util.GroupHandler;
|
import moe.oko.opennaw.util.GroupHandler;
|
||||||
import moe.oko.opennaw.util.NationHandler;
|
import moe.oko.opennaw.util.NationHandler;
|
||||||
import net.luckperms.api.LuckPerms;
|
import net.luckperms.api.LuckPerms;
|
||||||
|
@ -34,8 +35,9 @@ public final class OpenNAW extends JavaPlugin {
|
||||||
|
|
||||||
info("OpenNAW is enabled!");
|
info("OpenNAW is enabled!");
|
||||||
|
|
||||||
// Register Commands
|
// Register Commands & Events
|
||||||
this.getCommand("nation").setExecutor(new NationCommand());
|
this.getCommand("nation").setExecutor(new NationCommand());
|
||||||
|
getServer().getPluginManager().registerEvents(new ChatHandler(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,8 +2,6 @@ package moe.oko.opennaw.command;
|
||||||
|
|
||||||
import moe.oko.opennaw.OpenNAW;
|
import moe.oko.opennaw.OpenNAW;
|
||||||
import moe.oko.opennaw.util.CommandHelper;
|
import moe.oko.opennaw.util.CommandHelper;
|
||||||
import net.luckperms.api.model.group.Group;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabExecutor;
|
import org.bukkit.command.TabExecutor;
|
||||||
|
@ -22,7 +20,7 @@ public class NationCommand implements TabExecutor {
|
||||||
|
|
||||||
if (args.length < 1) { return false; }
|
if (args.length < 1) { return false; }
|
||||||
|
|
||||||
List<String> nationList = OpenNAW.getInstance().getNationHandler().getNationList();
|
var nationList = OpenNAW.getInstance().getNationHandler().getNationList();
|
||||||
|
|
||||||
switch (args[0]) {
|
switch (args[0]) {
|
||||||
case "add" -> {
|
case "add" -> {
|
||||||
|
@ -31,7 +29,7 @@ public class NationCommand implements TabExecutor {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Group group = OpenNAW.getInstance().getGroupHandler().getGroupFromString(args[2]);
|
var group = OpenNAW.getInstance().getGroupHandler().getGroupFromString(args[2]);
|
||||||
|
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
sender.sendMessage("Group " + args[2] + " does not exist");
|
sender.sendMessage("Group " + args[2] + " does not exist");
|
||||||
|
@ -42,7 +40,7 @@ public class NationCommand implements TabExecutor {
|
||||||
sender.sendMessage("Created nation " + args[1]);
|
sender.sendMessage("Created nation " + args[1]);
|
||||||
}
|
}
|
||||||
case "list" -> {
|
case "list" -> {
|
||||||
final String msg = nationList.size() == 0
|
final var msg = nationList.size() == 0
|
||||||
? "There are no nations"
|
? "There are no nations"
|
||||||
: "There are " + nationList.size() + " nations: " + nationList;
|
: "There are " + nationList.size() + " nations: " + nationList;
|
||||||
sender.sendMessage(msg);
|
sender.sendMessage(msg);
|
||||||
|
@ -52,7 +50,7 @@ public class NationCommand implements TabExecutor {
|
||||||
sender.sendMessage("Removed nation " + args[1]);
|
sender.sendMessage("Removed nation " + args[1]);
|
||||||
}
|
}
|
||||||
case "join" -> {
|
case "join" -> {
|
||||||
OfflinePlayer player = args.length < 3
|
var player = args.length < 3
|
||||||
? ((Player) sender).getPlayer()
|
? ((Player) sender).getPlayer()
|
||||||
: OpenNAW.getInstance().getServer().getOfflinePlayer(args[2]);
|
: OpenNAW.getInstance().getServer().getOfflinePlayer(args[2]);
|
||||||
|
|
||||||
|
@ -61,13 +59,13 @@ public class NationCommand implements TabExecutor {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Group group = OpenNAW.getInstance().getNationHandler().getNationGroup(args[1]);
|
var group = OpenNAW.getInstance().getNationHandler().getNationGroup(args[1]);
|
||||||
OpenNAW.getInstance().getGroupHandler().addPlayerToGroup(player, group);
|
OpenNAW.getInstance().getGroupHandler().addPlayerToGroup(player, group);
|
||||||
|
|
||||||
sender.sendMessage("Added " + player.getName() + " to nation " + args[1]);
|
sender.sendMessage("Added " + player.getName() + " to nation " + args[1]);
|
||||||
}
|
}
|
||||||
case "leave" -> {
|
case "leave" -> {
|
||||||
OfflinePlayer player = args.length < 3
|
var player = args.length < 3
|
||||||
? ((Player) sender).getPlayer()
|
? ((Player) sender).getPlayer()
|
||||||
: OpenNAW.getInstance().getServer().getOfflinePlayer(args[2]);
|
: OpenNAW.getInstance().getServer().getOfflinePlayer(args[2]);
|
||||||
OpenNAW.getInstance().getGroupHandler().removePlayerFromGroup(player);
|
OpenNAW.getInstance().getGroupHandler().removePlayerFromGroup(player);
|
||||||
|
|
19
src/main/java/moe/oko/opennaw/model/City.java
Normal file
19
src/main/java/moe/oko/opennaw/model/City.java
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
package moe.oko.opennaw.model;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
public class City {
|
||||||
|
private String name;
|
||||||
|
private String resource;
|
||||||
|
private Nation owner;
|
||||||
|
private Location point;
|
||||||
|
private short health;
|
||||||
|
|
||||||
|
public City(String name, String resource, Location location) {
|
||||||
|
this.name = name;
|
||||||
|
this.resource = resource;
|
||||||
|
this.owner = null;
|
||||||
|
this.point = location;
|
||||||
|
this.health = 500;
|
||||||
|
}
|
||||||
|
}
|
36
src/main/java/moe/oko/opennaw/util/ChatHandler.java
Normal file
36
src/main/java/moe/oko/opennaw/util/ChatHandler.java
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
package moe.oko.opennaw.util;
|
||||||
|
|
||||||
|
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||||
|
import moe.oko.opennaw.OpenNAW;
|
||||||
|
import net.kyori.adventure.audience.Audience;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
public class ChatHandler implements Listener {
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onChat(AsyncChatEvent e) {
|
||||||
|
var legacyComponentSerializer = LegacyComponentSerializer.builder().character('&').hexColors().build();
|
||||||
|
var player = e.getPlayer();
|
||||||
|
Audience audience;
|
||||||
|
|
||||||
|
var nationString = "[" + OpenNAW.getInstance().getGroupHandler().getPrefixFromPlayer(player) + "&r] ";
|
||||||
|
var prefix = legacyComponentSerializer.deserialize(nationString);
|
||||||
|
var message = e.message();
|
||||||
|
|
||||||
|
e.setCancelled(true);
|
||||||
|
|
||||||
|
audience = Audience.audience(Bukkit.getOnlinePlayers());
|
||||||
|
|
||||||
|
audience.sendMessage(prefix
|
||||||
|
.append(player.displayName().color(TextColor.fromHexString("#939597")))
|
||||||
|
.append(Component.text(": "))
|
||||||
|
.append(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -7,13 +7,10 @@ import net.luckperms.api.node.Node;
|
||||||
import net.luckperms.api.node.NodeType;
|
import net.luckperms.api.node.NodeType;
|
||||||
import net.luckperms.api.node.types.InheritanceNode;
|
import net.luckperms.api.node.types.InheritanceNode;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public record GroupHandler(LuckPerms luckPerms) {
|
public record GroupHandler(LuckPerms luckPerms) {
|
||||||
|
|
||||||
public Group getGroupFromString(String s) {
|
|
||||||
return this.luckPerms.getGroupManager().getGroup(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addPlayerToGroup(OfflinePlayer player, Group group) {
|
public void addPlayerToGroup(OfflinePlayer player, Group group) {
|
||||||
this.luckPerms.getUserManager().modifyUser(player.getUniqueId(), (User user) -> {
|
this.luckPerms.getUserManager().modifyUser(player.getUniqueId(), (User user) -> {
|
||||||
|
|
||||||
|
@ -34,4 +31,12 @@ public record GroupHandler(LuckPerms luckPerms) {
|
||||||
user.data().clear(NodeType.INHERITANCE::matches);
|
user.data().clear(NodeType.INHERITANCE::matches);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Group getGroupFromString(String s) {
|
||||||
|
return this.luckPerms.getGroupManager().getGroup(s);
|
||||||
|
}
|
||||||
|
public String getPrefixFromPlayer(Player player) {
|
||||||
|
var user = this.luckPerms.getUserManager().getUser(player.getUniqueId());
|
||||||
|
return user.getCachedData().getMetaData().getPrefix();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue