3
0
Mirror von https://github.com/St3venAU/ArmorStandTools.git synchronisiert 2024-12-28 04:20:08 +01:00
Dieser Commit ist enthalten in:
Steven 2021-12-04 19:34:03 +08:00
Ursprung 80c3f7b7f2
Commit 72e09bac5b
7 geänderte Dateien mit 134 neuen und 87 gelöschten Zeilen

Datei anzeigen

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.st3venau.plugins</groupId> <groupId>com.gmail.st3venau.plugins</groupId>
<artifactId>ArmorStandTools</artifactId> <artifactId>ArmorStandTools</artifactId>
<version>4.4.0</version> <version>4.4.1</version>
<name>ArmorStandTools</name> <name>ArmorStandTools</name>
<repositories> <repositories>

Datei anzeigen

@ -8,6 +8,9 @@ import com.sk89q.worldguard.protection.regions.RegionContainer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
import org.bukkit.entity.ArmorStand; import org.bukkit.entity.ArmorStand;
@ -15,6 +18,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue; import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -24,6 +28,7 @@ import java.util.AbstractMap;
import java.util.HashMap; import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.regex.Pattern;
public class AST extends JavaPlugin { public class AST extends JavaPlugin {
@ -40,6 +45,8 @@ public class AST extends JavaPlugin {
static AST plugin; static AST plugin;
static String nmsVersion; static String nmsVersion;
static final Pattern MC_USERNAME_PATTERN = Pattern.compile("^[a-zA-Z0-9_]{1,16}$");
@Override @Override
public void onLoad() { public void onLoad() {
if (getServer().getPluginManager().getPlugin("WorldGuard") != null) { if (getServer().getPluginManager().getPlugin("WorldGuard") != null) {
@ -205,8 +212,15 @@ public class AST extends JavaPlugin {
Bukkit.getScheduler().cancelTask(waitingForSkull.get(uuid).getValue()); Bukkit.getScheduler().cancelTask(waitingForSkull.get(uuid).getValue());
waitingForSkull.remove(uuid); waitingForSkull.remove(uuid);
} }
if(Config.useCommandForTextInput) {
String msg1 = ChatColor.GOLD + Config.enterNameC + ": " + ChatColor.GREEN + "/ast <Armor Stand Name>";
p.sendTitle(" ", msg1, 0, 600, 0);
p.sendMessage(msg1);
p.sendMessage(ChatColor.GOLD + Config.enterNameC2 + ": " + ChatColor.GREEN + "/ast &");
} else {
p.sendTitle(" ", ChatColor.GOLD + Config.enterName, 0, 600, 0); p.sendTitle(" ", ChatColor.GOLD + Config.enterName, 0, 600, 0);
p.sendMessage(ChatColor.GOLD + Config.enterName2 + " &"); p.sendMessage(ChatColor.GOLD + Config.enterName2 + " &");
}
int taskID = new BukkitRunnable() { int taskID = new BukkitRunnable() {
@Override @Override
public void run() { public void run() {
@ -224,8 +238,14 @@ public class AST extends JavaPlugin {
Bukkit.getScheduler().cancelTask(waitingForName.get(uuid).getValue()); Bukkit.getScheduler().cancelTask(waitingForName.get(uuid).getValue());
waitingForName.remove(uuid); waitingForName.remove(uuid);
} }
if(Config.useCommandForTextInput) {
String msg1 = ChatColor.GOLD + Config.enterSkullC + ": " + ChatColor.GREEN + "/ast <MC Username For Skull>";
p.sendTitle(" ", msg1, 0, 600, 0);
p.sendMessage(msg1);
} else {
p.sendTitle(" ", ChatColor.GOLD + Config.enterSkull, 0, 600, 0); p.sendTitle(" ", ChatColor.GOLD + Config.enterSkull, 0, 600, 0);
p.sendMessage(ChatColor.GOLD + Config.enterSkull); p.sendMessage(ChatColor.GOLD + Config.enterSkull);
}
int taskID = new BukkitRunnable() { int taskID = new BukkitRunnable() {
@Override @Override
public void run() { public void run() {
@ -287,4 +307,86 @@ public class AST extends JavaPlugin {
if(!Config.showDebugMessages) return; if(!Config.showDebugMessages) return;
Bukkit.getLogger().log(Level.INFO, "[AST DEBUG] " + msg); Bukkit.getLogger().log(Level.INFO, "[AST DEBUG] " + msg);
} }
static ArmorStand getArmorStand(UUID uuid, World w) {
if (uuid != null && w != null) {
for (org.bukkit.entity.Entity e : w.getEntities()) {
if (e instanceof ArmorStand && e.getUniqueId().equals(uuid)) {
return (ArmorStand) e;
}
}
}
return null;
}
@SuppressWarnings("deprecation")
static ItemStack getPlayerHead(String playerName) {
OfflinePlayer offlinePlayer = Bukkit.getServer().getPlayer(playerName);
if(offlinePlayer == null) {
offlinePlayer = Bukkit.getOfflinePlayer(playerName);
}
final ItemStack item = new ItemStack(Material.PLAYER_HEAD);
final SkullMeta meta = (SkullMeta) item.getItemMeta();
if(meta == null) {
Bukkit.getLogger().warning("Skull item meta was null");
return item;
}
meta.setOwningPlayer(offlinePlayer);
item.setItemMeta(meta);
return item;
}
static boolean processInput(Player p, final String in) {
final UUID plrUuid = p.getUniqueId();
final UUID uuid;
boolean name;
int taskId;
if(AST.waitingForName.containsKey(plrUuid)) {
uuid = AST.waitingForName.get(plrUuid).getKey();
taskId = AST.waitingForName.get(plrUuid).getValue();
name = true;
} else if(AST.waitingForSkull.containsKey(plrUuid)) {
uuid = AST.waitingForSkull.get(plrUuid).getKey();
taskId = AST.waitingForSkull.get(plrUuid).getValue();
name = false;
} else {
return false;
}
Bukkit.getScheduler().cancelTask(taskId);
new BukkitRunnable() {
@Override
public void run() {
final ArmorStand as = getArmorStand(uuid, p.getWorld());
if (as != null) {
String input = ChatColor.translateAlternateColorCodes('&', in);
if(input.equals("&")) input = "";
if(name) {
if (input.length() > 0) {
as.setCustomName(input);
as.setCustomNameVisible(true);
p.sendMessage(ChatColor.GREEN + Config.nameSet);
} else {
as.setCustomName("");
as.setCustomNameVisible(false);
as.setCustomNameVisible(false);
p.sendMessage(ChatColor.GREEN + Config.nameRemoved);
}
} else {
if(MC_USERNAME_PATTERN.matcher(input).matches()) {
if(as.getEquipment() != null) {
as.getEquipment().setHelmet(getPlayerHead(input));
p.sendMessage(ChatColor.GREEN + Config.skullSet);
}
} else {
p.sendMessage(ChatColor.RED + input + " " + Config.invalidName);
}
}
}
AST.waitingForName.remove(plrUuid);
AST.waitingForSkull.remove(plrUuid);
Utils.title(p, " ");
}
}.runTask(AST.plugin);
return true;
}
} }

Datei anzeigen

@ -25,6 +25,18 @@ class Commands implements CommandExecutor, TabCompleter {
} }
String cmd = command.getName().toLowerCase(); String cmd = command.getName().toLowerCase();
if(cmd.equals("astools") || cmd.equals("ast")) { if(cmd.equals("astools") || cmd.equals("ast")) {
if(Config.useCommandForTextInput && args.length > 0) {
StringBuilder sb = new StringBuilder();
boolean space = false;
for(String s : args) {
if(space) sb.append(' ');
space = true;
sb.append(s);
}
if(AST.processInput(p, sb.toString())) {
return true;
}
}
if (!Utils.hasPermissionNode(p, "astools.command")) { if (!Utils.hasPermissionNode(p, "astools.command")) {
p.sendMessage(ChatColor.RED + Config.noCommandPerm); p.sendMessage(ChatColor.RED + Config.noCommandPerm);
return true; return true;

Datei anzeigen

@ -52,6 +52,7 @@ class Config {
static boolean saveToolCreatesCommandBlock = true; static boolean saveToolCreatesCommandBlock = true;
static boolean logGeneratedSummonCommands = false; static boolean logGeneratedSummonCommands = false;
static boolean crouchRightClickOpensGUI = false; static boolean crouchRightClickOpensGUI = false;
static boolean useCommandForTextInput = false;
static final ArrayList<String> deniedCommands = new ArrayList<>(); static final ArrayList<String> deniedCommands = new ArrayList<>();
@ -72,7 +73,8 @@ class Config {
errorExecutingCmd, isNotValidNumber, removedFromAs, errorExecutingCmd, isNotValidNumber, removedFromAs,
listAssignedCmds, addACmd, removeACmd, cmdHelp, listAssignedCmds, addACmd, removeACmd, cmdHelp,
enterName, enterName2, enterSkull, inputTimeout, enterName, enterName2, enterSkull, inputTimeout,
nameSet, nameRemoved, skullSet; nameSet, nameRemoved, skullSet, enterNameC,
enterNameC2, enterSkullC;
static void reload() { static void reload() {
reloadMainConfig(); reloadMainConfig();
@ -109,6 +111,7 @@ class Config {
saveToolCreatesCommandBlock = config.getBoolean("saveToolCreatesCommandBlock", true); saveToolCreatesCommandBlock = config.getBoolean("saveToolCreatesCommandBlock", true);
logGeneratedSummonCommands = config.getBoolean("logGeneratedSummonCommands", false); logGeneratedSummonCommands = config.getBoolean("logGeneratedSummonCommands", false);
crouchRightClickOpensGUI = config.getBoolean("crouchRightClickOpensGUI", false); crouchRightClickOpensGUI = config.getBoolean("crouchRightClickOpensGUI", false);
useCommandForTextInput = config.getBoolean("useCommandForTextInput", false);
AST.activeTool.clear(); AST.activeTool.clear();
AST.selectedArmorStand.clear(); AST.selectedArmorStand.clear();
@ -255,6 +258,9 @@ class Config {
nameSet = languageConfig.getString("nameSet"); nameSet = languageConfig.getString("nameSet");
nameRemoved = languageConfig.getString("nameRemoved"); nameRemoved = languageConfig.getString("nameRemoved");
skullSet = languageConfig.getString("skullSet"); skullSet = languageConfig.getString("skullSet");
enterNameC = languageConfig.getString("enterNameC");
enterNameC2 = languageConfig.getString("enterNameC2");
enterSkullC = languageConfig.getString("enterSkullC");
} }
private static ItemStack getItemStack(String configPath) { private static ItemStack getItemStack(String configPath) {

Datei anzeigen

@ -49,8 +49,6 @@ import java.util.regex.Pattern;
@SuppressWarnings("CommentedOutCode") @SuppressWarnings("CommentedOutCode")
public class MainListener implements Listener { public class MainListener implements Listener {
private final Pattern MC_USERNAME_PATTERN = Pattern.compile("^[a-zA-Z0-9_]{1,16}$");
@EventHandler @EventHandler
public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) { public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) {
if(!(event.getRightClicked() instanceof ArmorStand as)) return; if(!(event.getRightClicked() instanceof ArmorStand as)) return;
@ -359,75 +357,10 @@ public class MainListener implements Listener {
@EventHandler @EventHandler
public void onPlayerChat(final AsyncPlayerChatEvent event) { public void onPlayerChat(final AsyncPlayerChatEvent event) {
final Player p = event.getPlayer(); if(Config.useCommandForTextInput) return;
final UUID plrUuid = p.getUniqueId(); if(AST.processInput(event.getPlayer(), event.getMessage())) {
final UUID uuid;
boolean name;
int taskId;
if(AST.waitingForName.containsKey(plrUuid)) {
uuid = AST.waitingForName.get(plrUuid).getKey();
taskId = AST.waitingForName.get(plrUuid).getValue();
name = true;
} else if(AST.waitingForSkull.containsKey(plrUuid)) {
uuid = AST.waitingForSkull.get(plrUuid).getKey();
taskId = AST.waitingForSkull.get(plrUuid).getValue();
name = false;
} else {
return;
}
event.setCancelled(true); event.setCancelled(true);
Bukkit.getScheduler().cancelTask(taskId);
new BukkitRunnable() {
@Override
public void run() {
final ArmorStand as = getArmorStand(uuid, p.getWorld());
if (as != null) {
String input = ChatColor.translateAlternateColorCodes('&', event.getMessage());
if(input.equals("&")) input = "";
if(name) {
if (input.length() > 0) {
as.setCustomName(input);
as.setCustomNameVisible(true);
p.sendMessage(ChatColor.GREEN + Config.nameSet);
} else {
as.setCustomName("");
as.setCustomNameVisible(false);
as.setCustomNameVisible(false);
p.sendMessage(ChatColor.GREEN + Config.nameRemoved);
} }
} else {
if(MC_USERNAME_PATTERN.matcher(input).matches()) {
if(as.getEquipment() != null) {
as.getEquipment().setHelmet(getPlayerHead(input));
p.sendMessage(ChatColor.GREEN + Config.skullSet);
}
} else {
p.sendMessage(ChatColor.RED + input + " " + Config.invalidName);
}
}
}
AST.waitingForName.remove(plrUuid);
AST.waitingForSkull.remove(plrUuid);
Utils.title(p, " ");
}
}.runTask(AST.plugin);
}
@SuppressWarnings("deprecation")
private ItemStack getPlayerHead(String playerName) {
OfflinePlayer offlinePlayer = Bukkit.getServer().getPlayer(playerName);
if(offlinePlayer == null) {
offlinePlayer = Bukkit.getOfflinePlayer(playerName);
}
final ItemStack item = new ItemStack(Material.PLAYER_HEAD);
final SkullMeta meta = (SkullMeta) item.getItemMeta();
if(meta == null) {
Bukkit.getLogger().warning("Skull item meta was null");
return item;
}
meta.setOwningPlayer(offlinePlayer);
item.setItemMeta(meta);
return item;
} }
@EventHandler @EventHandler
@ -443,17 +376,6 @@ public class MainListener implements Listener {
} }
} }
private ArmorStand getArmorStand(UUID uuid, World w) {
if (uuid != null && w != null) {
for (org.bukkit.entity.Entity e : w.getEntities()) {
if (e instanceof ArmorStand && e.getUniqueId().equals(uuid)) {
return (ArmorStand) e;
}
}
}
return null;
}
// Give all permissions to all players - for testing only // Give all permissions to all players - for testing only
/*@EventHandler /*@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) { public void onPlayerJoin(PlayerJoinEvent event) {

Datei anzeigen

@ -90,6 +90,7 @@ defaultASCmdCooldownTicks: 0
bypassWorldguardForASCmdExecution: false bypassWorldguardForASCmdExecution: false
saveToolCreatesCommandBlock: true saveToolCreatesCommandBlock: true
logGeneratedSummonCommands: false logGeneratedSummonCommands: false
useCommandForTextInput: false
showDebugMessages: false showDebugMessages: false
# Uncomment the section below to deny players access to commands of your choice when they have any AST tools in their inventory # Uncomment the section below to deny players access to commands of your choice when they have any AST tools in their inventory

Datei anzeigen

@ -110,6 +110,10 @@ inputTimeout: 'Input timeout. Please try again.'
nameSet: 'Armor stand name set' nameSet: 'Armor stand name set'
nameRemoved: 'Armor stand name removed' nameRemoved: 'Armor stand name removed'
skullSet: 'Armor stand skull set' skullSet: 'Armor stand skull set'
#New since v4.4.1
enterNameC: 'To set armor stand name'
enterNameC2: 'Or to remove the name'
enterSkullC: 'To set MC username for skull'
############################# #############################
# Tool names & descriptions # # Tool names & descriptions #
############################# #############################