3
0
Mirror von https://github.com/St3venAU/ArmorStandTools.git synchronisiert 2024-12-26 19:42:41 +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>
<groupId>com.gmail.st3venau.plugins</groupId>
<artifactId>ArmorStandTools</artifactId>
<version>4.4.0</version>
<version>4.4.1</version>
<name>ArmorStandTools</name>
<repositories>

Datei anzeigen

@ -8,6 +8,9 @@ import com.sk89q.worldguard.protection.regions.RegionContainer;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.ArmorStand;
@ -15,6 +18,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.java.JavaPlugin;
@ -24,6 +28,7 @@ import java.util.AbstractMap;
import java.util.HashMap;
import java.util.UUID;
import java.util.logging.Level;
import java.util.regex.Pattern;
public class AST extends JavaPlugin {
@ -40,6 +45,8 @@ public class AST extends JavaPlugin {
static AST plugin;
static String nmsVersion;
static final Pattern MC_USERNAME_PATTERN = Pattern.compile("^[a-zA-Z0-9_]{1,16}$");
@Override
public void onLoad() {
if (getServer().getPluginManager().getPlugin("WorldGuard") != null) {
@ -205,8 +212,15 @@ public class AST extends JavaPlugin {
Bukkit.getScheduler().cancelTask(waitingForSkull.get(uuid).getValue());
waitingForSkull.remove(uuid);
}
p.sendTitle(" ", ChatColor.GOLD + Config.enterName, 0, 600, 0);
p.sendMessage(ChatColor.GOLD + Config.enterName2 + " &");
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.sendMessage(ChatColor.GOLD + Config.enterName2 + " &");
}
int taskID = new BukkitRunnable() {
@Override
public void run() {
@ -224,8 +238,14 @@ public class AST extends JavaPlugin {
Bukkit.getScheduler().cancelTask(waitingForName.get(uuid).getValue());
waitingForName.remove(uuid);
}
p.sendTitle(" ", ChatColor.GOLD + Config.enterSkull, 0, 600, 0);
p.sendMessage(ChatColor.GOLD + Config.enterSkull);
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.sendMessage(ChatColor.GOLD + Config.enterSkull);
}
int taskID = new BukkitRunnable() {
@Override
public void run() {
@ -287,4 +307,86 @@ public class AST extends JavaPlugin {
if(!Config.showDebugMessages) return;
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();
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")) {
p.sendMessage(ChatColor.RED + Config.noCommandPerm);
return true;

Datei anzeigen

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

Datei anzeigen

@ -49,8 +49,6 @@ import java.util.regex.Pattern;
@SuppressWarnings("CommentedOutCode")
public class MainListener implements Listener {
private final Pattern MC_USERNAME_PATTERN = Pattern.compile("^[a-zA-Z0-9_]{1,16}$");
@EventHandler
public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) {
if(!(event.getRightClicked() instanceof ArmorStand as)) return;
@ -359,75 +357,10 @@ public class MainListener implements Listener {
@EventHandler
public void onPlayerChat(final AsyncPlayerChatEvent event) {
final Player p = event.getPlayer();
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;
if(Config.useCommandForTextInput) return;
if(AST.processInput(event.getPlayer(), event.getMessage())) {
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
@ -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
/*@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {

Datei anzeigen

@ -90,6 +90,7 @@ defaultASCmdCooldownTicks: 0
bypassWorldguardForASCmdExecution: false
saveToolCreatesCommandBlock: true
logGeneratedSummonCommands: false
useCommandForTextInput: 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

Datei anzeigen

@ -110,6 +110,10 @@ inputTimeout: 'Input timeout. Please try again.'
nameSet: 'Armor stand name set'
nameRemoved: 'Armor stand name removed'
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 #
#############################