Mirror von
https://github.com/St3venAU/ArmorStandTools.git
synchronisiert 2024-12-29 04:50:09 +01:00
Added command to set head block
Dieser Commit ist enthalten in:
Ursprung
30fd112c3f
Commit
fea810a5d3
@ -1,11 +1,18 @@
|
|||||||
package com.gmail.St3venAU.plugins.ArmorStandTools;
|
package com.gmail.St3venAU.plugins.ArmorStandTools;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_8_R1.Material;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.ArmorStand;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
class Commands implements CommandExecutor {
|
class Commands implements CommandExecutor {
|
||||||
@ -41,6 +48,52 @@ class Commands implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(args[0].equalsIgnoreCase("head")) {
|
||||||
|
// get the entity you are looking at
|
||||||
|
if(!Utils.hasPermissionNode(p, "astools.head")) {
|
||||||
|
p.sendMessage(ChatColor.RED + Config.noHeadPerm);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
List<Entity> nearby = p.getNearbyEntities(16, 16, 16);
|
||||||
|
if (nearby.size() == 0) {
|
||||||
|
p.sendMessage(ChatColor.RED + Config.notTarget);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
double min = 0.5;
|
||||||
|
Entity closest = null;
|
||||||
|
Vector loc = p.getLocation().toVector();
|
||||||
|
for (Entity entity : nearby) {
|
||||||
|
Vector eLoc = entity.getLocation().toVector().subtract(loc).normalize();
|
||||||
|
Vector target = p.getLocation().getDirection().normalize();
|
||||||
|
double diff = eLoc.subtract(target).length();
|
||||||
|
if (diff < min) {
|
||||||
|
min = diff;
|
||||||
|
closest = entity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (closest == null || !(closest instanceof ArmorStand)) {
|
||||||
|
p.sendMessage(ChatColor.RED + Config.notTarget);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
ArmorStand as = (ArmorStand) closest;
|
||||||
|
if (!MainListener.checkPermission(p, closest.getLocation().getBlock())) {
|
||||||
|
p.sendMessage(ChatColor.RED + Config.wgNoPerm);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
ItemStack item = p.getItemInHand();
|
||||||
|
if (item == null || item.getTypeId() == 0) {
|
||||||
|
as.setHelmet(new ItemStack(0));
|
||||||
|
p.sendMessage(ChatColor.GREEN + Config.setHead);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!item.getType().isBlock()) {
|
||||||
|
p.sendMessage(ChatColor.RED + Config.notBlock);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
as.setHelmet(item);
|
||||||
|
p.sendMessage(ChatColor.GREEN + Config.setHead);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if(args[0].equalsIgnoreCase("reload")) {
|
if(args[0].equalsIgnoreCase("reload")) {
|
||||||
if(Utils.hasPermissionNode(p, "astools.reload")) {
|
if(Utils.hasPermissionNode(p, "astools.reload")) {
|
||||||
Config.reload();
|
Config.reload();
|
||||||
|
@ -34,9 +34,9 @@ class Config {
|
|||||||
asCloned, carrying, noPerm, cbCreated, size, small,
|
asCloned, carrying, noPerm, cbCreated, size, small,
|
||||||
normal, basePlate, isOn, isOff, gravity, arms, invul,
|
normal, basePlate, isOn, isOff, gravity, arms, invul,
|
||||||
equip, locked, unLocked, notConsole, giveMsg1,
|
equip, locked, unLocked, notConsole, giveMsg1,
|
||||||
giveMsg2, conReload, noRelPerm, noAirError,
|
giveMsg2, conReload, noRelPerm, noHeadPerm, notTarget, notBlock, noAirError,
|
||||||
pleaseWait, appliedHead, noHead, invalidName,
|
pleaseWait, appliedHead, noHead, invalidName,
|
||||||
wgNoPerm;
|
wgNoPerm, setHead;
|
||||||
|
|
||||||
public static void reload(Main main) {
|
public static void reload(Main main) {
|
||||||
plugin = main;
|
plugin = main;
|
||||||
@ -74,12 +74,16 @@ class Config {
|
|||||||
giveMsg2 = languageConfig.getString("giveMsg2");
|
giveMsg2 = languageConfig.getString("giveMsg2");
|
||||||
conReload = languageConfig.getString("conReload");
|
conReload = languageConfig.getString("conReload");
|
||||||
noRelPerm = languageConfig.getString("noRelPerm");
|
noRelPerm = languageConfig.getString("noRelPerm");
|
||||||
|
noHeadPerm = languageConfig.getString("noHeadPerm");
|
||||||
|
notTarget = languageConfig.getString("notTarget");
|
||||||
|
notBlock = languageConfig.getString("notBlock");
|
||||||
noAirError = languageConfig.getString("noAirError");
|
noAirError = languageConfig.getString("noAirError");
|
||||||
pleaseWait = languageConfig.getString("pleaseWait");
|
pleaseWait = languageConfig.getString("pleaseWait");
|
||||||
appliedHead = languageConfig.getString("appliedHead");
|
appliedHead = languageConfig.getString("appliedHead");
|
||||||
noHead = languageConfig.getString("noHead");
|
noHead = languageConfig.getString("noHead");
|
||||||
invalidName = languageConfig.getString("invalidName");
|
invalidName = languageConfig.getString("invalidName");
|
||||||
wgNoPerm = languageConfig.getString("wgNoPerm");
|
wgNoPerm = languageConfig.getString("wgNoPerm");
|
||||||
|
setHead = languageConfig.getString("setHead");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void reloadMainConfig() {
|
private static void reloadMainConfig() {
|
||||||
|
@ -212,8 +212,9 @@ public class MainListener implements Listener {
|
|||||||
p.sendMessage(ChatColor.GREEN + "Deletion Protection: Enabled");
|
p.sendMessage(ChatColor.GREEN + "Deletion Protection: Enabled");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default: {
|
||||||
cancel = tool == ArmorStandTool.SUMMON || tool == ArmorStandTool.SAVE || event.isCancelled();
|
cancel = tool == ArmorStandTool.SUMMON || tool == ArmorStandTool.SAVE || event.isCancelled();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
event.setCancelled(cancel);
|
event.setCancelled(cancel);
|
||||||
}
|
}
|
||||||
@ -589,7 +590,7 @@ public class MainListener implements Listener {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkPermission(Player player, Block block) {
|
public static boolean checkPermission(Player player, Block block) {
|
||||||
|
|
||||||
// Check PlotSquared
|
// Check PlotSquared
|
||||||
Location loc = block.getLocation();
|
Location loc = block.getLocation();
|
||||||
@ -623,7 +624,7 @@ public class MainListener implements Listener {
|
|||||||
return hasperm;
|
return hasperm;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean playerHasPermission(Player p, Block b, ArmorStandTool tool) {
|
public static boolean playerHasPermission(Player p, Block b, ArmorStandTool tool) {
|
||||||
if(tool != null && !p.isOp() && (!Utils.hasPermissionNode(p, "astools.use")
|
if(tool != null && !p.isOp() && (!Utils.hasPermissionNode(p, "astools.use")
|
||||||
|| (ArmorStandTool.SAVE == tool && !Utils.hasPermissionNode(p, "astools.cmdblock"))
|
|| (ArmorStandTool.SAVE == tool && !Utils.hasPermissionNode(p, "astools.cmdblock"))
|
||||||
|| (ArmorStandTool.CLONE == tool && !Utils.hasPermissionNode(p, "astools.clone")))) {
|
|| (ArmorStandTool.CLONE == tool && !Utils.hasPermissionNode(p, "astools.clone")))) {
|
||||||
|
@ -42,12 +42,16 @@ giveMsg1: 'Given armor stand tools. L-click any tool to cycle through tools.'
|
|||||||
giveMsg2: 'Run this command again to return your inventory.'
|
giveMsg2: 'Run this command again to return your inventory.'
|
||||||
conReload: 'Armor Stand Tools config reloaded'
|
conReload: 'Armor Stand Tools config reloaded'
|
||||||
noRelPerm: 'You do not have permission to reload the plugin'
|
noRelPerm: 'You do not have permission to reload the plugin'
|
||||||
|
noHeadPerm: 'You do not have permission to set a head'
|
||||||
|
notTarget: 'You are not looking at an ArmorStand'
|
||||||
noAirError: 'Error: Failed to find a near-by air block. Move and try again.'
|
noAirError: 'Error: Failed to find a near-by air block. Move and try again.'
|
||||||
pleaseWait: 'Please wait, this may take a few seconds...'
|
pleaseWait: 'Please wait, this may take a few seconds...'
|
||||||
appliedHead: 'Applied the head of player'
|
appliedHead: 'Applied the head of player'
|
||||||
noHead: 'No player head found for player'
|
noHead: 'No player head found for player'
|
||||||
invalidName: 'is not a valid minecraft username'
|
invalidName: 'is not a valid minecraft username'
|
||||||
wgNoPerm: 'You do not have permission to alter an armor stand in this region'
|
wgNoPerm: 'You do not have permission to alter an armor stand in this region'
|
||||||
|
notBlock: 'You are not holding a block'
|
||||||
|
setHead: 'Set the head block'
|
||||||
#
|
#
|
||||||
#############################
|
#############################
|
||||||
# Tool names & descriptions #
|
# Tool names & descriptions #
|
||||||
|
@ -8,4 +8,4 @@ commands:
|
|||||||
astools:
|
astools:
|
||||||
description: Give yourself all of the armor stand tools (Warning; clears your inventory).
|
description: Give yourself all of the armor stand tools (Warning; clears your inventory).
|
||||||
aliases: ast
|
aliases: ast
|
||||||
usage: Usage /astools or /astools reload
|
usage: Usage /astools or /astools reload or /astools head
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren