Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Replace flagentity with flag/unflag
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Feb 16, 2017
1 parent 166fad5 commit 9bc21a7
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 25 deletions.
Expand Up @@ -124,10 +124,11 @@ public void onServerStart(GamePreInitializationEvent event) {
Denizen2Core.getImplementation().getScriptDataFolder().mkdirs();
// Commands: Entity
Denizen2Core.register(new EditEntityCommand());
Denizen2Core.register(new FlagEntityCommand());
Denizen2Core.register(new FlagCommand());
Denizen2Core.register(new MountCommand());
Denizen2Core.register(new SpawnCommand());
Denizen2Core.register(new TeleportCommand());
Denizen2Core.register(new UnflagCommand());
// Commands: Player
Denizen2Core.register(new ActionBarCommand());
Denizen2Core.register(new GiveCommand());
Expand Down
Expand Up @@ -17,30 +17,27 @@
import java.util.Map;
import java.util.Optional;

public class FlagEntityCommand extends AbstractCommand {
public class FlagCommand extends AbstractCommand {

// <--[command]
// @Name flagentity
// @Name flag
// @Arguments <entity> <map of flags to set>
// @Short flags an entity.
// @Updated 2016/10/26
// @Short flags an entity with some data.
// @Updated 2017/02/15
// @Group Entities
// @Minimum 2
// @Maximum 2
// @Switch remove BooleanTag whether to remove things.
// @Description
// Adds or edits flags on an entity (including players, etc.)
// Adds or edits flags on an entity (including players, etc.).
// See also the <@link command unflag>unflag command<@/link>.
// @Example
// # Mark the player as a VIP.
// - flagentity <player> vip:true
// @Example
// # Remove the flag 'VIP' from the player.
// - flagentity <player> vip:null -remove true
// - flag <player> vip:true
// -->

@Override
public String getName() {
return "flagentity";
return "flag";
}

@Override
Expand All @@ -63,8 +60,6 @@ public void execute(CommandQueue queue, CommandEntry entry) {
EntityTag entityTag = EntityTag.getFor(queue.error, entry.getArgumentObject(queue, 0));
Entity entity = entityTag.getInternal();
MapTag propertyMap = MapTag.getFor(queue.error, entry.getArgumentObject(queue, 1));
boolean remover = entry.namedArgs.containsKey("remove") &&
BooleanTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "remove")).getInternal();
MapTag basic;
Optional<FlagMap> fm = entity.get(FlagHelper.FLAGMAP);
if (fm.isPresent()) {
Expand All @@ -74,18 +69,13 @@ public void execute(CommandQueue queue, CommandEntry entry) {
basic = new MapTag();
}
for (Map.Entry<String, AbstractTagObject> dat : propertyMap.getInternal().entrySet()) {
if (remover) {
basic.getInternal().remove(dat.getKey());
}
else {
basic.getInternal().put(CoreUtilities.toLowerCase(dat.getKey()), dat.getValue());
}
basic.getInternal().put(CoreUtilities.toLowerCase(dat.getKey()), dat.getValue());
}
entity.offer(new FlagMapDataImpl(new FlagMap(basic)));
if (queue.shouldShowGood()) {
queue.outGood("Flagged the entity "
+ ColorSet.emphasis + entityTag.friendlyName() + ColorSet.good
+ " with the specified data... " + (remover ? "(Removal mode)" : "(Normal mode)"));
+ " with the specified data... (" + propertyMap + ")");
}
}
}
@@ -0,0 +1,80 @@
package com.denizenscript.denizen2sponge.commands.entity;

import com.denizenscript.denizen2core.commands.AbstractCommand;
import com.denizenscript.denizen2core.commands.CommandEntry;
import com.denizenscript.denizen2core.commands.CommandQueue;
import com.denizenscript.denizen2core.tags.AbstractTagObject;
import com.denizenscript.denizen2core.tags.objects.ListTag;
import com.denizenscript.denizen2core.tags.objects.MapTag;
import com.denizenscript.denizen2core.utilities.CoreUtilities;
import com.denizenscript.denizen2core.utilities.debugging.ColorSet;
import com.denizenscript.denizen2sponge.tags.objects.EntityTag;
import com.denizenscript.denizen2sponge.utilities.flags.FlagHelper;
import com.denizenscript.denizen2sponge.utilities.flags.FlagMap;
import com.denizenscript.denizen2sponge.utilities.flags.FlagMapDataImpl;
import org.spongepowered.api.entity.Entity;

import java.util.Optional;

public class UnflagCommand extends AbstractCommand {

// <--[command]
// @Name unflag
// @Arguments <entity> <list of flags to remove>
// @Short removes a list of flags from an entity.
// @Updated 2017/02/15
// @Group Entities
// @Minimum 2
// @Maximum 2
// @Description
// Removes flags from an entity (including players, etc.).
// See also the <@link command flag>flag command<@/link>.
// @Example
// # Mark the player as no longer VIP.
// - unflag <player> vip
// -->

@Override
public String getName() {
return "unflag";
}

@Override
public String getArguments() {
return "<entity> <list of flags to remove>";
}

@Override
public int getMinimumArguments() {
return 2;
}

@Override
public int getMaximumArguments() {
return 2;
}

@Override
public void execute(CommandQueue queue, CommandEntry entry) {
EntityTag entityTag = EntityTag.getFor(queue.error, entry.getArgumentObject(queue, 0));
Entity entity = entityTag.getInternal();
ListTag toRemove = ListTag.getFor(queue.error, entry.getArgumentObject(queue, 1));
MapTag basic;
Optional<FlagMap> fm = entity.get(FlagHelper.FLAGMAP);
if (fm.isPresent()) {
basic = fm.get().flags;
}
else {
basic = new MapTag();
}
for (AbstractTagObject dat : toRemove.getInternal()) {
basic.getInternal().remove(CoreUtilities.toLowerCase(dat.toString()));
}
entity.offer(new FlagMapDataImpl(new FlagMap(basic)));
if (queue.shouldShowGood()) {
queue.outGood("Removed from the entity "
+ ColorSet.emphasis + entityTag.friendlyName() + ColorSet.good
+ " the specified flags... (" + toRemove + ")");
}
}
}
Expand Up @@ -70,7 +70,7 @@ public ItemStack getInternal() {
return DataKeys.getValue(((ItemTag) obj).internal, key, dat.error);
});
// <--[tag]
// @Name ItemTag.without_flags[<MapTag>]
// @Name ItemTag.without_flags[<ListTag>]
// @Updated 2017/02/13
// @Group General Information
// @ReturnType ItemTag
Expand All @@ -86,9 +86,9 @@ public ItemStack getInternal() {
else {
flags = new MapTag();
}
MapTag toApply = MapTag.getFor(dat.error, dat.getNextModifier());
for (String k : toApply.getInternal().keySet()) {
flags.getInternal().remove(k);
ListTag toRemove = ListTag.getFor(dat.error, dat.getNextModifier());
for (AbstractTagObject k : toRemove.getInternal()) {
flags.getInternal().remove(k.toString());
}
ItemStack its = ((ItemTag) obj).internal.createSnapshot().createStack();
its.offer(new FlagMapDataImpl(new FlagMap(flags)));
Expand Down

0 comments on commit 9bc21a7

Please sign in to comment.