Skip to content

Commit

Permalink
Add /npc painting
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Apr 7, 2023
1 parent 163499f commit 4f9506c
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 14 deletions.
46 changes: 34 additions & 12 deletions main/src/main/java/net/citizensnpcs/commands/NPCCommands.java
Expand Up @@ -11,6 +11,7 @@
import java.util.UUID;
import java.util.stream.Collectors;

import org.bukkit.Art;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
Expand Down Expand Up @@ -122,6 +123,7 @@
import net.citizensnpcs.trait.MountTrait;
import net.citizensnpcs.trait.OcelotModifiers;
import net.citizensnpcs.trait.PacketNPC;
import net.citizensnpcs.trait.PaintingTrait;
import net.citizensnpcs.trait.PausePathfindingTrait;
import net.citizensnpcs.trait.Poses;
import net.citizensnpcs.trait.Powered;
Expand Down Expand Up @@ -556,6 +558,18 @@ public void command(CommandContext args, CommandSender sender, NPC npc,
}
}

@Command(
aliases = { "npc" },
usage = "configgui",
desc = "Display NPC configuration GUI",
modifiers = { "configgui" },
min = 1,
max = 1,
permission = "citizens.npc.configgui")
public void configgui(CommandContext args, Player sender, NPC npc) {
InventoryMenu.createSelfRegistered(new NPCConfigurator(npc)).present(sender);
}

@Command(
aliases = { "npc" },
usage = "controllable|control (-m(ount),-y,-n,-o(wner required))",
Expand Down Expand Up @@ -1036,18 +1050,6 @@ public void gravity(CommandContext args, CommandSender sender, NPC npc) {
Messaging.sendTr(sender, key, npc.getName());
}

@Command(
aliases = { "npc" },
usage = "gui",
desc = "Display NPC configuration GUI",
modifiers = { "gui" },
min = 1,
max = 1,
permission = "citizens.npc.gui")
public void gui(CommandContext args, Player sender, NPC npc) {
InventoryMenu.createSelfRegistered(new NPCConfigurator(npc)).present(sender);
}

@Command(
aliases = { "npc" },
usage = "hitbox --scale [scale] --width/height [value]",
Expand Down Expand Up @@ -1873,6 +1875,26 @@ public void packet(CommandContext args, CommandSender sender, NPC npc, @Flag("en
}
}

@Command(
aliases = { "npc" },
usage = "painting (--art art)",
desc = "Set painting modifiers",
modifiers = { "painting" },
min = 1,
max = 1,
permission = "citizens.npc.painting")
@Requirements(selected = true, ownership = true, types = { EntityType.PAINTING })
public void painting(CommandContext args, CommandSender sender, NPC npc, @Flag("art") Art art)
throws CommandException {
PaintingTrait trait = npc.getOrAddTrait(PaintingTrait.class);
if (art != null) {
trait.setArt(art);
Messaging.sendTr(sender, Messages.PAINTING_ART_SET, npc.getName(), Util.prettyEnum(art));
return;
}
throw new CommandUsageException();
}

@Command(
aliases = { "npc" },
usage = "passive (--set [true|false])",
Expand Down
Expand Up @@ -74,6 +74,5 @@ public ConfiguratorInfo(Material mat, Consumer<ConfiguratorEvent> con) {
InputMenus.stringSetter(() -> evt.npc.getName(), (input) -> evt.npc.setName(input)));
}
}));

}
}
2 changes: 1 addition & 1 deletion main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java
Expand Up @@ -103,7 +103,7 @@ public boolean despawn(DespawnReason reason) {
unloadEvents();
}
for (Trait trait : new ArrayList<Trait>(traits.values())) {
trait.onDespawn();
trait.onDespawn(reason);
}
Messaging.debug("Despawned", this, "DespawnReason." + reason);

Expand Down
Expand Up @@ -42,6 +42,7 @@
import net.citizensnpcs.trait.MountTrait;
import net.citizensnpcs.trait.OcelotModifiers;
import net.citizensnpcs.trait.PacketNPC;
import net.citizensnpcs.trait.PaintingTrait;
import net.citizensnpcs.trait.PausePathfindingTrait;
import net.citizensnpcs.trait.Poses;
import net.citizensnpcs.trait.Powered;
Expand Down Expand Up @@ -89,6 +90,7 @@ public CitizensTraitFactory(Citizens plugin) {
registerTrait(TraitInfo.create(HologramTrait.class));
registerTrait(TraitInfo.create(Inventory.class));
registerTrait(TraitInfo.create(LookClose.class));
registerTrait(TraitInfo.create(PaintingTrait.class));
registerTrait(TraitInfo.create(MirrorTrait.class));
registerTrait(TraitInfo.create(MountTrait.class));
registerTrait(TraitInfo.create(MobType.class).asDefaultTrait());
Expand Down
38 changes: 38 additions & 0 deletions main/src/main/java/net/citizensnpcs/trait/PaintingTrait.java
@@ -0,0 +1,38 @@
package net.citizensnpcs.trait;

import org.bukkit.Art;
import org.bukkit.entity.Painting;

import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName;

/**
* Persists {@link Painting} metadata.
*/
@TraitName("paintingtrait")
public class PaintingTrait extends Trait {
@Persist("art")
private Art art;

public PaintingTrait() {
super("paintingtrait");
}

@Override
public void run() {
if (!(npc.getEntity() instanceof Painting))
return;
Painting painting = (Painting) npc.getEntity();
if (art != null) {
painting.setArt(art);
}
}

/**
* @see Painting#setArt(Art)
*/
public void setArt(Art art) {
this.art = art;
}
}
2 changes: 2 additions & 0 deletions main/src/main/java/net/citizensnpcs/trait/ShopTrait.java
Expand Up @@ -357,6 +357,8 @@ public void onClick(NPCShop shop, CitizensInventoryClickEvent event, boolean sec
max = Math.min(max, r);
}
}
if (max == 0)
return;
}
final int repeats = max == Integer.MAX_VALUE ? 1 : max;
List<Transaction> take = apply(cost, action -> action.take(event.getWhoClicked(), repeats));
Expand Down
1 change: 1 addition & 0 deletions main/src/main/java/net/citizensnpcs/util/Messages.java
Expand Up @@ -288,6 +288,7 @@ public class Messages {
public static final String OVER_NPC_LIMIT = "citizens.limits.over-npc-limit";
public static final String OWNER_SET = "citizens.commands.npc.owner.set";
public static final String OWNER_SET_SERVER = "citizens.commands.npc.owner.set-server";
public static final String PAINTING_ART_SET = "citizens.commands.npc.painting.art-set";
public static final String PANDA_HIDDEN_GENE_SET = "citizens.commands.npc.panda.hidden-gene-set";
public static final String PANDA_MAIN_GENE_SET = "citizens.commands.npc.panda.main-gene-set";
public static final String PANDA_ROLLING = "citizens.commands.npc.panda.rolling";
Expand Down
1 change: 1 addition & 0 deletions main/src/main/resources/messages_en.properties
Expand Up @@ -221,6 +221,7 @@ citizens.commands.npc.pausepathfinding.pause-range-set=[{0}]] will now pause pat
citizens.commands.npc.pausepathfinding.pause-ticks-set=[[{0}]] will now pause pathfinding for [[{1}]] ticks at a time.
citizens.commands.npc.pausepathfinding.rightclick-set=[[{0}]] will now pause pathfinding on right click.
citizens.commands.npc.pausepathfinding.rightclick-unset=[[{0}]] will no longer pause pathfinding on right click.
citizens.commands.npc.painting.art-set=[[{0}]]''s art set to [[{1}]].
citizens.commands.npc.playerlist.added=Added [[{0}]] to the player list.
citizens.commands.npc.playerlist.removed=Removed [[{0}]] from the player list.
citizens.commands.npc.playerfilter.cleared=[[{0}]]''s filter cleared.
Expand Down

0 comments on commit 4f9506c

Please sign in to comment.