Update to 1.5

Added new Staff message utility to be used going forward
New demote action in MCM listener
Added tag option to move [MCM] into hover event
Fixes #3
Fixes #5
master
Etzelia 2018-10-20 23:01:00 -05:00
parent 9f0a0bfad5
commit 33f893907d
5 changed files with 72 additions and 44 deletions

View File

@ -3,7 +3,7 @@
<groupId>xyz.etztech</groupId> <groupId>xyz.etztech</groupId>
<artifactId>MinecraftManager</artifactId> <artifactId>MinecraftManager</artifactId>
<!-- Version is used in plugin.yml --> <!-- Version is used in plugin.yml -->
<version>1.4</version> <version>1.5</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<!-- Plugin Information --> <!-- Plugin Information -->
@ -38,13 +38,11 @@
<groupId>commons-lang</groupId> <groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId> <artifactId>commons-lang</artifactId>
<version>2.6</version> <version>2.6</version>
<scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>xyz.etztech</groupId> <groupId>xyz.etztech</groupId>
<artifactId>EtzCore</artifactId> <artifactId>EtzCore</artifactId>
<version>1.0.4</version> <version>1.0.5</version>
<scope>compile</scope>
</dependency> </dependency>

View File

@ -46,8 +46,12 @@ public class MCMUtil {
} }
public static void staffMessage(String message) { public static void staffMessage(String message) {
staffMessage(message, false);
}
public static void staffMessage(String message, boolean mcm) {
log(staffLog, message); log(staffLog, message);
HoverEvent hover = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Staff Chat").create()); String tag = mcm ? "MCM " : "";
HoverEvent hover = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(tag + "Staff Chat").create());
TextComponent text = new TextComponent(message); TextComponent text = new TextComponent(message);
text.setHoverEvent(hover); text.setHoverEvent(hover);
for (Player player : Bukkit.getServer().getOnlinePlayers()) { for (Player player : Bukkit.getServer().getOnlinePlayers()) {
@ -92,6 +96,13 @@ public class MCMUtil {
} }
} }
public static void globalMessage(TextComponent message) {
log(globalLog, message.toPlainText());
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
player.spigot().sendMessage(message);
}
}
public static String getUUID(String playerName) { public static String getUUID(String playerName) {
String uuid = null; String uuid = null;
try { try {

View File

@ -5,8 +5,6 @@ import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import xyz.etztech.core.api.IMinecraftManager; import xyz.etztech.core.api.IMinecraftManager;
import xyz.etztech.core.maven.MavenLibrary;
import xyz.etztech.core.maven.MavenPlugin;
import xyz.etztech.minecraftmanager.command.*; import xyz.etztech.minecraftmanager.command.*;
import xyz.etztech.minecraftmanager.listeners.AsyncPlayerChatListener; import xyz.etztech.minecraftmanager.listeners.AsyncPlayerChatListener;
import xyz.etztech.minecraftmanager.listeners.BlockBreakListener; import xyz.etztech.minecraftmanager.listeners.BlockBreakListener;
@ -23,8 +21,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.logging.Logger; import java.util.logging.Logger;
@MavenLibrary(group = "commons-lang", artifact = "commons-lang", version = "2.6") public class MinecraftManager extends JavaPlugin implements IMinecraftManager {
public class MinecraftManager extends MavenPlugin implements IMinecraftManager {
public static MinecraftManager instance; public static MinecraftManager instance;
@ -50,8 +47,7 @@ public class MinecraftManager extends MavenPlugin implements IMinecraftManager {
@Override public void onEnable() {
public void enable() {
instance = this; instance = this;
saveDefaultConfig(); saveDefaultConfig();
@ -95,8 +91,7 @@ public class MinecraftManager extends MavenPlugin implements IMinecraftManager {
} }
} }
@Override public void onDisable() {
public void disable() {
} }

View File

@ -37,7 +37,6 @@ public class MinecraftManagerThread extends Thread {
public void run() { public void run() {
List<String> commands = Arrays.asList("application", "ticket", "accept", "deny", "global", "staff");
try { try {
ServerSocket cmdSock = new ServerSocket(this.plugin.getConfig().getInt("port"), 0, InetAddress.getByName(null)); ServerSocket cmdSock = new ServerSocket(this.plugin.getConfig().getInt("port"), 0, InetAddress.getByName(null));
while (getRunning()) { while (getRunning()) {
@ -54,7 +53,6 @@ public class MinecraftManagerThread extends Thread {
args = new ArrayList<>(Arrays.asList(buf.split(" "))); args = new ArrayList<>(Arrays.asList(buf.split(" ")));
args.remove(0); args.remove(0);
} }
if (commands.contains(base)) {
switch (base) { switch (base) {
case "application": case "application":
application(args.get(0), args.get(1)); application(args.get(0), args.get(1));
@ -74,13 +72,15 @@ public class MinecraftManagerThread extends Thread {
case "staff": case "staff":
staffChat(args); staffChat(args);
break; break;
case "demote":
demote(args.get(0));
break;
default: default:
Bukkit.getConsoleSender().sendMessage("Input not recognized, ignoring."); Bukkit.getConsoleSender().sendMessage("Input not recognized, ignoring.");
break; break;
} }
} }
} }
}
Bukkit.getConsoleSender().sendMessage("Closing MinecraftManager on Port " + this.plugin.getConfig().get("port")); Bukkit.getConsoleSender().sendMessage("Closing MinecraftManager on Port " + this.plugin.getConfig().get("port"));
cmdSock.close(); cmdSock.close();
} catch (Exception ex) { } catch (Exception ex) {
@ -93,7 +93,7 @@ public class MinecraftManagerThread extends Thread {
.color(ChatColor.GREEN) .color(ChatColor.GREEN)
.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/app info " + id)); .event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/app info " + id));
TextComponent message = new TextComponent(builder.create()); TextComponent message = new TextComponent(builder.create());
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Staff Chat").create())); message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("MCM Staff Chat").create()));
MCMUtil.staffMessage(message); MCMUtil.staffMessage(message);
} }
@ -102,7 +102,7 @@ public class MinecraftManagerThread extends Thread {
.color(ChatColor.GREEN) .color(ChatColor.GREEN)
.event(new ClickEvent(ClickEvent.Action.OPEN_URL, link)); .event(new ClickEvent(ClickEvent.Action.OPEN_URL, link));
TextComponent message = new TextComponent(builder.create()); TextComponent message = new TextComponent(builder.create());
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Staff Chat").create())); message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("MCM Staff Chat").create()));
MCMUtil.staffMessage(message); MCMUtil.staffMessage(message);
} }
@ -142,7 +142,7 @@ public class MinecraftManagerThread extends Thread {
ComponentBuilder builder = new ComponentBuilder(username + " was " + (accepted ? "accepted" : "denied") + ".") ComponentBuilder builder = new ComponentBuilder(username + " was " + (accepted ? "accepted" : "denied") + ".")
.color(ChatColor.GREEN); .color(ChatColor.GREEN);
TextComponent staffMessage = new TextComponent(builder.create()); TextComponent staffMessage = new TextComponent(builder.create());
staffMessage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Staff Chat").create())); staffMessage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("MCM Staff Chat").create()));
MCMUtil.staffMessage(staffMessage); MCMUtil.staffMessage(staffMessage);
} }
@ -159,19 +159,40 @@ public class MinecraftManagerThread extends Thread {
private void globalChat(ArrayList<String> args) { private void globalChat(ArrayList<String> args) {
String name = args.get(0); String name = args.get(0);
args.remove(0); args.remove(0);
MCMUtil.globalMessage("[MCM] " + name + " > " + StringUtils.join(args, " ")); String tag = plugin.getConfig().getBoolean("tag", true) ? "[MCM] " : "";
ComponentBuilder builder = new ComponentBuilder(tag + name + " > ")
.append(StringUtils.join(args, " "));
TextComponent message = new TextComponent(builder.create());
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("MCM Global Chat").create()));
MCMUtil.globalMessage(message);
} }
private void staffChat(ArrayList<String> args) { private void staffChat(ArrayList<String> args) {
String name = args.get(0); String name = args.get(0);
args.remove(0); args.remove(0);
ComponentBuilder builder = new ComponentBuilder("[MCM] " + name + " > ") String tag = plugin.getConfig().getBoolean("tag", true) ? "[MCM] " : "";
ComponentBuilder builder = new ComponentBuilder(tag + name + " > ")
.color(ChatColor.GOLD) .color(ChatColor.GOLD)
.append(StringUtils.join(args, " "), ComponentBuilder.FormatRetention.NONE) .append(StringUtils.join(args, " "), ComponentBuilder.FormatRetention.NONE)
.color(ChatColor.GREEN); .color(ChatColor.GREEN);
TextComponent message = new TextComponent(builder.create()); TextComponent message = new TextComponent(builder.create());
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Staff Chat").create())); message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("MCM Staff Chat").create()));
MCMUtil.staffMessage(message); MCMUtil.staffMessage(message);
} }
private void demote(String username) {
String engine = MinecraftManager.config.getString("permissions.engine");
String promote = MinecraftManager.config.getString("permissions.promote");
if ("permissionsex".equalsIgnoreCase(engine)) {
runTask("pex user <player> group set " + promote, username);
} else if ("luckperms".equalsIgnoreCase(engine)) {
runTask("lp user <player> group set " + promote, username);
}
ComponentBuilder builder = new ComponentBuilder(username + " has been demoted.")
.color(ChatColor.GREEN);
TextComponent staffMessage = new TextComponent(builder.create());
staffMessage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("MCM Staff Chat").create()));
MCMUtil.staffMessage(staffMessage);
}
} }

View File

@ -8,6 +8,9 @@ staff-chat:
prefix: prefix:
- "#" - "#"
# If true, chat is prefixed with an [MCM] tag. When false, the tag is moved to a hover event.
tag: true
# Override rules # Override rules
# A '*' before a rule will show as a sub-rule # A '*' before a rule will show as a sub-rule
rules: rules: