upstream #1
					 2 changed files with 64 additions and 1 deletions
				
			
		|  | @ -336,7 +336,8 @@ public class ZNpcsPlus { | ||||||
|                         .addSubcommand("setitem", new HoloSetItemCommand(npcRegistry)) |                         .addSubcommand("setitem", new HoloSetItemCommand(npcRegistry)) | ||||||
|                         .addSubcommand("offset", new HoloOffsetCommand(npcRegistry)) |                         .addSubcommand("offset", new HoloOffsetCommand(npcRegistry)) | ||||||
|                         .addSubcommand("refreshdelay", new HoloRefreshDelayCommand(npcRegistry)) |                         .addSubcommand("refreshdelay", new HoloRefreshDelayCommand(npcRegistry)) | ||||||
|                         .addSubcommand("removeduplicate", new HoloRemoveDuplicateCommand(npcRegistry))) |                         .addSubcommand("removeduplicate", new HoloRemoveDuplicateCommand(npcRegistry)) | ||||||
|  |                         .addSubcommand("removeallduplicates", new holoRemoveAllDuplicatesCommand(npcRegistry))) | ||||||
|                 .addSubcommand("action", new MultiCommand(bootstrap.loadHelpMessage("action")) |                 .addSubcommand("action", new MultiCommand(bootstrap.loadHelpMessage("action")) | ||||||
|                         .addSubcommand("add", new ActionAddCommand(npcRegistry, actionRegistry)) |                         .addSubcommand("add", new ActionAddCommand(npcRegistry, actionRegistry)) | ||||||
|                         .addSubcommand("clear", new ActionClearCommand(npcRegistry)) |                         .addSubcommand("clear", new ActionClearCommand(npcRegistry)) | ||||||
|  |  | ||||||
|  | @ -0,0 +1,62 @@ | ||||||
|  | package lol.pyr.znpcsplus.commands.hologram; | ||||||
|  | 
 | ||||||
|  | import lol.pyr.director.adventure.command.CommandContext; | ||||||
|  | import lol.pyr.director.adventure.command.CommandHandler; | ||||||
|  | import lol.pyr.director.common.command.CommandExecutionException; | ||||||
|  | import lol.pyr.znpcsplus.hologram.HologramImpl; | ||||||
|  | import lol.pyr.znpcsplus.hologram.HologramLine; | ||||||
|  | import lol.pyr.znpcsplus.hologram.HologramText; | ||||||
|  | import lol.pyr.znpcsplus.npc.NpcEntryImpl; | ||||||
|  | import lol.pyr.znpcsplus.npc.NpcRegistryImpl; | ||||||
|  | import net.kyori.adventure.text.Component; | ||||||
|  | import net.kyori.adventure.text.format.NamedTextColor; | ||||||
|  | 
 | ||||||
|  | import java.util.ArrayList; | ||||||
|  | import java.util.Collections; | ||||||
|  | import java.util.Iterator; | ||||||
|  | import java.util.List; | ||||||
|  | 
 | ||||||
|  | public class holoRemoveAllDuplicatesCommand implements CommandHandler { | ||||||
|  |     private final NpcRegistryImpl registry; | ||||||
|  | 
 | ||||||
|  |     public holoRemoveAllDuplicatesCommand(NpcRegistryImpl registry) { | ||||||
|  |         this.registry = registry; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void run(CommandContext context) throws CommandExecutionException { | ||||||
|  |         context.setUsage(context.getLabel() + " holo removeallduplicates <id>"); | ||||||
|  | 
 | ||||||
|  |         for (NpcEntryImpl npcEntry : registry.getAll()) { | ||||||
|  |             HologramImpl hologram = npcEntry.getNpc().getHologram(); | ||||||
|  |             List<HologramLine<?>> lines = new ArrayList<>(hologram.getLines()); | ||||||
|  |             List<HologramText> textLines = new ArrayList<>(); | ||||||
|  | 
 | ||||||
|  |             Iterator<HologramLine<?>> iterator = lines.iterator(); | ||||||
|  |             while (iterator.hasNext()) { | ||||||
|  |                 HologramLine<?> line = iterator.next(); | ||||||
|  |                 if (line instanceof HologramText textLine | ||||||
|  |                         && !textLine.getValue().equals(Component.empty()) | ||||||
|  |                         && textLines.contains(textLine)) { | ||||||
|  |                     iterator.remove(); | ||||||
|  |                     continue; | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |                 if (line instanceof HologramText textLine) { | ||||||
|  |                     textLines.add(textLine); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             hologram.clearLines(); | ||||||
|  |             hologram.addLines(lines); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         context.send(Component.text("NPCs fixed!", NamedTextColor.GREEN)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public List<String> suggest(CommandContext context) throws CommandExecutionException { | ||||||
|  |         if (context.argSize() == 1) return context.suggestCollection(registry.getModifiableIds()); | ||||||
|  |         return Collections.emptyList(); | ||||||
|  |     } | ||||||
|  | } | ||||||
		Loading…
	
		Reference in a new issue