use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class ExCommandHandler method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String alias, String[] args) {
if (cmd.getName().equalsIgnoreCase("ex")) {
List<Object> entries = new ArrayList<>();
String entry = String.join(" ", args);
boolean quiet = !Settings.showExDebug();
if (entry.length() > 3 && entry.startsWith("-q ")) {
quiet = !quiet;
entry = entry.substring("-q ".length());
}
if (entry.length() < 2) {
sender.sendMessage("/ex (-q) <denizen script command> (arguments)");
return true;
}
if (Settings.showExHelp()) {
if (Debug.showDebug) {
if (quiet) {
sender.sendMessage(ChatColor.YELLOW + "Executing Denizen script command... check the console for full debug output!");
} else {
// sender.sendMessage(ChatColor.YELLOW + "Executing Denizen script command...");
}
} else {
sender.sendMessage(ChatColor.YELLOW + "Executing Denizen script command... to see debug, use /denizen debug");
}
}
entries.add(entry);
InstantQueue queue = new InstantQueue("EXCOMMAND");
NPCTag npc = null;
if (Depends.citizens != null && Depends.citizens.getNPCSelector().getSelected(sender) != null) {
npc = new NPCTag(Depends.citizens.getNPCSelector().getSelected(sender));
}
List<ScriptEntry> scriptEntries = ScriptBuilder.buildScriptEntries(entries, null, new BukkitScriptEntryData(sender instanceof Player ? new PlayerTag((Player) sender) : null, npc));
queue.addEntries(scriptEntries);
if (!quiet && sender instanceof Player) {
final Player player = (Player) sender;
queue.debugOutput = (s) -> {
player.spigot().sendMessage(FormattedTextHelper.parse(s, net.md_5.bungee.api.ChatColor.WHITE));
};
}
queue.start();
return true;
}
return false;
}
use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class ExCommandHandler method onTabComplete.
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String cmdName, String[] rawArgs) {
if ((!cmdName.equalsIgnoreCase("ex") && !cmdName.equalsIgnoreCase("exs")) || !sender.hasPermission("denizen.ex")) {
return null;
}
String entry = String.join(" ", rawArgs);
if (entry.length() > 3 && entry.startsWith("-q ")) {
entry = entry.substring("-q ".length());
}
String[] args = ArgumentHelper.buildArgs(entry);
boolean isNewArg = rawArgs.length == 0 || rawArgs[rawArgs.length - 1].isEmpty();
boolean isCommandArg = args.length == 0 || (args.length == 1 && !isNewArg) || args[args.length - (isNewArg ? 1 : 2)].equals("-");
if (isCommandArg) {
if (isNewArg || args.length == 0) {
return new ArrayList<>(DenizenCore.commandRegistry.instances.keySet());
}
ArrayList<String> output = new ArrayList<>();
String startOfName = CoreUtilities.toLowerCase(args[args.length - 1]);
for (String command : DenizenCore.commandRegistry.instances.keySet()) {
if (command.startsWith(startOfName)) {
output.add(command);
}
}
return output;
}
if (!isNewArg) {
String lastArg = rawArgs[rawArgs.length - 1];
int argStart = 0;
for (int i = 0; i < lastArg.length(); i++) {
if (lastArg.charAt(i) == '"' || lastArg.charAt(i) == '\'') {
char quote = lastArg.charAt(i++);
while (i < lastArg.length() && lastArg.charAt(i) != quote) {
i++;
}
} else if (lastArg.charAt(i) == ' ') {
argStart = i + 1;
}
}
String arg = lastArg.substring(argStart);
if (CoreUtilities.contains(arg, '<')) {
int tagBits = 0;
int relevantTagStart = -1;
for (int i = arg.length() - 1; i >= 0; i--) {
if (arg.charAt(i) == '>') {
tagBits++;
} else if (arg.charAt(i) == '<') {
if (tagBits == 0) {
relevantTagStart = i + 1;
break;
}
tagBits--;
}
}
if (relevantTagStart != -1) {
String fullTag = CoreUtilities.toLowerCase(arg.substring(relevantTagStart));
int components = 0;
int subTags = 0;
int squareBrackets = 0;
int lastDot = 0;
int bracketStart = -1;
Collection<Class<? extends ObjectTag>> typesApplicable = null;
for (int i = 0; i < fullTag.length(); i++) {
char c = fullTag.charAt(i);
if (c == '<') {
subTags++;
} else if (c == '>') {
subTags--;
} else if (c == '[' && subTags == 0) {
squareBrackets++;
bracketStart = i;
} else if (c == ']' && subTags == 0) {
squareBrackets--;
} else if (c == '.' && subTags == 0 && squareBrackets == 0) {
Class<? extends ObjectTag> type = null;
String part = fullTag.substring(lastDot, bracketStart == -1 ? i : bracketStart);
if (components == 0) {
TagManager.TagBaseData baseType = TagManager.baseTags.get(part);
if (baseType != null) {
type = baseType.returnType;
}
} else if (typesApplicable != null) {
for (Class<? extends ObjectTag> possibleType : typesApplicable) {
ObjectFetcher.ObjectType<? extends ObjectTag> typeData = ObjectFetcher.objectsByClass.get(possibleType);
if (typeData != null && typeData.tagProcessor != null) {
ObjectTagProcessor.TagData data = typeData.tagProcessor.registeredObjectTags.get(part);
if (data != null && data.returnType != null) {
type = data.returnType;
break;
}
}
}
}
if (type != null) {
typesApplicable = ObjectFetcher.getAllApplicableSubTypesFor(type);
} else {
typesApplicable = ObjectFetcher.objectsByClass.keySet();
}
components++;
lastDot = i + 1;
bracketStart = -1;
}
}
String beforeDot = arg.substring(0, relevantTagStart) + fullTag.substring(0, lastDot);
if (components == 0 && !CoreUtilities.contains(fullTag, '[')) {
ArrayList<String> output = new ArrayList<>();
for (String tagBase : TagManager.baseTags.keySet()) {
if (tagBase.startsWith(fullTag)) {
output.add(beforeDot + tagBase);
}
}
return output;
}
String subComponent = fullTag.substring(lastDot);
if (lastDot > 0 && !CoreUtilities.contains(subComponent, '[')) {
ArrayList<String> output = new ArrayList<>();
for (Class<? extends ObjectTag> possibleType : typesApplicable) {
ObjectFetcher.ObjectType<? extends ObjectTag> typeData = ObjectFetcher.objectsByClass.get(possibleType);
if (typeData != null && typeData.tagProcessor != null) {
for (String tag : typeData.tagProcessor.registeredObjectTags.keySet()) {
if (tag.startsWith(subComponent)) {
output.add(beforeDot + tag);
}
}
}
}
return output;
}
}
}
}
AbstractCommand dcmd = DenizenCore.commandRegistry.get(args[0]);
for (int i = args.length - 2; i >= 0; i--) {
if (args[i].equals("-")) {
dcmd = DenizenCore.commandRegistry.get(args[i + 1]);
}
}
if (dcmd == null) {
return null;
}
String lowArg = CoreUtilities.toLowerCase(rawArgs[rawArgs.length - 1]);
AbstractCommand.TabCompletionsBuilder completionsBuilder = new AbstractCommand.TabCompletionsBuilder();
completionsBuilder.arg = lowArg;
for (String flat : dcmd.docFlagArgs) {
completionsBuilder.add(flat);
}
for (String prefix : dcmd.docPrefixes) {
completionsBuilder.add(prefix + ":");
}
dcmd.addCustomTabCompletions(completionsBuilder);
if (dcmd instanceof FlagCommand) {
if (sender instanceof Player) {
for (String flagName : new PlayerTag((Player) sender).getFlagTracker().listAllFlags()) {
if (!flagName.startsWith("__")) {
completionsBuilder.add(flagName);
}
}
}
if (Depends.citizens != null && Depends.citizens.getNPCSelector().getSelected(sender) != null) {
for (String flagName : new NPCTag(Depends.citizens.getNPCSelector().getSelected(sender)).getFlagTracker().listAllFlags()) {
if (!flagName.startsWith("__")) {
completionsBuilder.add(flagName);
}
}
}
}
return completionsBuilder.completions;
}
use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class PlayerHelperImpl method sendEntitySpawn.
@Override
public FakeEntity sendEntitySpawn(List<PlayerTag> players, DenizenEntityType entityType, LocationTag location, ArrayList<Mechanism> mechanisms, int customId, UUID customUUID, boolean autoTrack) {
CraftWorld world = ((CraftWorld) location.getWorld());
net.minecraft.server.v1_16_R3.Entity nmsEntity;
if (entityType.isCustom()) {
if (entityType.customEntityType == CustomEntityType.ITEM_PROJECTILE) {
org.bukkit.inventory.ItemStack itemStack = new ItemStack(Material.STONE);
for (Mechanism mechanism : mechanisms) {
if (mechanism.matches("item") && mechanism.requireObject(ItemTag.class)) {
itemStack = mechanism.valueAsType(ItemTag.class).getItemStack();
}
}
nmsEntity = new EntityItemProjectileImpl(world.getHandle(), location, CraftItemStack.asNMSCopy(itemStack));
} else if (entityType.customEntityType == CustomEntityType.FAKE_PLAYER) {
String name = null;
String skin = null;
for (Mechanism mechanism : new ArrayList<>(mechanisms)) {
if (mechanism.matches("name")) {
name = mechanism.getValue().asString();
mechanisms.remove(mechanism);
} else if (mechanism.matches("skin")) {
skin = mechanism.getValue().asString();
mechanisms.remove(mechanism);
}
if (name != null && skin != null) {
break;
}
}
nmsEntity = ((CraftFakePlayerImpl) CustomEntityHelperImpl.spawnFakePlayer(location, name, skin, false)).getHandle();
} else {
throw new IllegalArgumentException("entityType");
}
} else {
nmsEntity = world.createEntity(location, entityType.getBukkitEntityType().getEntityClass());
}
if (customUUID != null) {
nmsEntity.e(customId);
nmsEntity.a_(customUUID);
}
EntityTag entity = new EntityTag(nmsEntity.getBukkitEntity());
for (Mechanism mechanism : mechanisms) {
entity.safeAdjustDuplicate(mechanism);
}
nmsEntity.dead = false;
FakeEntity fake = new FakeEntity(players, location, entity.getBukkitEntity().getEntityId());
fake.entity = new EntityTag(entity.getBukkitEntity());
fake.entity.isFake = true;
fake.entity.isFakeValid = true;
List<TrackerData> trackers = new ArrayList<>();
fake.triggerSpawnPacket = (player) -> {
EntityPlayer nmsPlayer = ((CraftPlayer) player.getPlayerEntity()).getHandle();
PlayerConnection conn = nmsPlayer.playerConnection;
final EntityTrackerEntry tracker = new EntityTrackerEntry(world.getHandle(), nmsEntity, 1, true, conn::sendPacket, Collections.singleton(nmsPlayer));
tracker.b(nmsPlayer);
final TrackerData data = new TrackerData();
data.player = player;
data.tracker = tracker;
trackers.add(data);
if (autoTrack) {
new BukkitRunnable() {
boolean wasOnline = true;
@Override
public void run() {
if (!fake.entity.isFakeValid) {
cancel();
return;
}
if (player.isOnline()) {
if (!wasOnline) {
tracker.b(((CraftPlayer) player.getPlayerEntity()).getHandle());
wasOnline = true;
}
tracker.a();
} else if (wasOnline) {
wasOnline = false;
}
}
}.runTaskTimer(Denizen.getInstance(), 1, 1);
}
};
for (PlayerTag player : players) {
fake.triggerSpawnPacket.accept(player);
}
fake.triggerUpdatePacket = () -> {
for (TrackerData tracker : trackers) {
if (tracker.player.isOnline()) {
tracker.tracker.a();
}
}
};
fake.triggerDestroyPacket = () -> {
for (TrackerData tracker : trackers) {
if (tracker.player.isOnline()) {
tracker.tracker.a(((CraftPlayer) tracker.player.getPlayerEntity()).getHandle());
}
}
trackers.clear();
};
return fake;
}
use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class PacketHelperImpl method showSignEditor.
@Override
public boolean showSignEditor(Player player, Location location) {
if (location == null) {
LocationTag fakeSign = new LocationTag(player.getLocation());
fakeSign.setY(0);
FakeBlock.showFakeBlockTo(Collections.singletonList(new PlayerTag(player)), fakeSign, new MaterialTag(org.bukkit.Material.OAK_WALL_SIGN), new DurationTag(1), true);
BlockPos pos = new BlockPos(fakeSign.getX(), 0, fakeSign.getZ());
((DenizenNetworkManagerImpl) ((CraftPlayer) player).getHandle().connection.connection).packetListener.fakeSignExpected = pos;
send(player, new ClientboundOpenSignEditorPacket(pos));
return true;
}
BlockEntity tileEntity = ((CraftWorld) location.getWorld()).getHandle().getTileEntity(new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()), true);
if (tileEntity instanceof SignBlockEntity) {
SignBlockEntity sign = (SignBlockEntity) tileEntity;
// Prevent client crashing by sending current state of the sign
send(player, sign.getUpdatePacket());
sign.isEditable = true;
sign.setAllowedPlayerEditor(player.getUniqueId());
send(player, new ClientboundOpenSignEditorPacket(sign.getBlockPos()));
return true;
} else {
return false;
}
}
use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class PlayerHelperImpl method sendEntitySpawn.
@Override
public FakeEntity sendEntitySpawn(List<PlayerTag> players, DenizenEntityType entityType, LocationTag location, ArrayList<Mechanism> mechanisms, int customId, UUID customUUID, boolean autoTrack) {
CraftWorld world = ((CraftWorld) location.getWorld());
net.minecraft.world.entity.Entity nmsEntity;
if (entityType.isCustom()) {
if (entityType.customEntityType == CustomEntityType.ITEM_PROJECTILE) {
org.bukkit.inventory.ItemStack itemStack = new ItemStack(Material.STONE);
for (Mechanism mechanism : mechanisms) {
if (mechanism.matches("item") && mechanism.requireObject(ItemTag.class)) {
itemStack = mechanism.valueAsType(ItemTag.class).getItemStack();
}
}
nmsEntity = new EntityItemProjectileImpl(world.getHandle(), location, CraftItemStack.asNMSCopy(itemStack));
} else if (entityType.customEntityType == CustomEntityType.FAKE_PLAYER) {
String name = null;
String skin = null;
for (Mechanism mechanism : new ArrayList<>(mechanisms)) {
if (mechanism.matches("name")) {
name = mechanism.getValue().asString();
mechanisms.remove(mechanism);
} else if (mechanism.matches("skin")) {
skin = mechanism.getValue().asString();
mechanisms.remove(mechanism);
}
if (name != null && skin != null) {
break;
}
}
nmsEntity = ((CraftFakePlayerImpl) CustomEntityHelperImpl.spawnFakePlayer(location, name, skin, false)).getHandle();
} else {
throw new IllegalArgumentException("entityType");
}
} else {
nmsEntity = world.createEntity(location, entityType.getBukkitEntityType().getEntityClass());
}
if (customUUID != null) {
nmsEntity.setId(customId);
nmsEntity.setUUID(customUUID);
}
EntityTag entity = new EntityTag(nmsEntity.getBukkitEntity());
entity.isFake = true;
entity.isFakeValid = true;
for (Mechanism mechanism : mechanisms) {
entity.safeAdjustDuplicate(mechanism);
}
nmsEntity.unsetRemoved();
FakeEntity fake = new FakeEntity(players, location, entity.getBukkitEntity().getEntityId());
fake.entity = new EntityTag(entity.getBukkitEntity());
fake.entity.isFake = true;
fake.entity.isFakeValid = true;
List<TrackerData> trackers = new ArrayList<>();
fake.triggerSpawnPacket = (player) -> {
ServerPlayer nmsPlayer = ((CraftPlayer) player.getPlayerEntity()).getHandle();
ServerGamePacketListenerImpl conn = nmsPlayer.connection;
final ServerEntity tracker = new ServerEntity(world.getHandle(), nmsEntity, 1, true, conn::send, Collections.singleton(nmsPlayer.connection));
tracker.addPairing(nmsPlayer);
final TrackerData data = new TrackerData();
data.player = player;
data.tracker = tracker;
trackers.add(data);
if (autoTrack) {
new BukkitRunnable() {
boolean wasOnline = true;
@Override
public void run() {
if (!fake.entity.isFakeValid) {
cancel();
return;
}
if (player.isOnline()) {
if (!wasOnline) {
tracker.addPairing(((CraftPlayer) player.getPlayerEntity()).getHandle());
wasOnline = true;
}
tracker.sendChanges();
} else if (wasOnline) {
wasOnline = false;
}
}
}.runTaskTimer(Denizen.getInstance(), 1, 1);
}
};
for (PlayerTag player : players) {
fake.triggerSpawnPacket.accept(player);
}
fake.triggerUpdatePacket = () -> {
for (TrackerData tracker : trackers) {
if (tracker.player.isOnline()) {
tracker.tracker.sendChanges();
}
}
};
fake.triggerDestroyPacket = () -> {
for (TrackerData tracker : trackers) {
if (tracker.player.isOnline()) {
tracker.tracker.removePairing(((CraftPlayer) tracker.player.getPlayerEntity()).getHandle());
}
}
trackers.clear();
};
return fake;
}
Aggregations