diff --git a/main/src/main/java/net/citizensnpcs/Citizens.java b/main/src/main/java/net/citizensnpcs/Citizens.java index 41e4c53ab..7170e9653 100644 --- a/main/src/main/java/net/citizensnpcs/Citizens.java +++ b/main/src/main/java/net/citizensnpcs/Citizens.java @@ -28,6 +28,7 @@ import com.comphenix.protocol.ProtocolLibrary; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import com.google.common.io.Files; import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; @@ -80,6 +81,7 @@ import net.citizensnpcs.npc.profile.ProfileFetcher; import net.citizensnpcs.npc.skin.Skin; import net.citizensnpcs.trait.ClickRedirectTrait; import net.citizensnpcs.trait.CommandTrait; +import net.citizensnpcs.trait.ScriptTrait; import net.citizensnpcs.trait.ShopTrait; import net.citizensnpcs.util.Messages; import net.citizensnpcs.util.NMS; @@ -564,6 +566,19 @@ public class Citizens extends JavaPlugin implements CitizensPlugin { } return res; })); + metrics.addCustomChart(new Metrics.AdvancedPie("script_extensions", () -> { + Map res = Maps.newHashMap(); + for (NPC npc : npcRegistry) { + ScriptTrait trait = npc.getTraitNullable(ScriptTrait.class); + if (trait != null) { + for (String file : trait.getScripts()) { + String ext = Files.getFileExtension(file); + res.put(ext, res.getOrDefault(ext, 0) + 1); + } + } + } + return res; + })); } catch (Exception e) { Messaging.logTr(Messages.METRICS_ERROR_NOTIFICATION, e.getMessage()); } diff --git a/main/src/main/java/net/citizensnpcs/commands/TemplateCommands.java b/main/src/main/java/net/citizensnpcs/commands/TemplateCommands.java index 5c60d7667..e6b766a88 100644 --- a/main/src/main/java/net/citizensnpcs/commands/TemplateCommands.java +++ b/main/src/main/java/net/citizensnpcs/commands/TemplateCommands.java @@ -3,14 +3,12 @@ package net.citizensnpcs.commands; import java.io.IOException; import java.util.List; -import javax.annotation.Nullable; - import org.bukkit.command.CommandSender; -import com.google.common.base.Function; import com.google.common.base.Splitter; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; +import com.google.common.primitives.Ints; import net.citizensnpcs.Citizens; import net.citizensnpcs.api.CitizensAPI; @@ -51,17 +49,9 @@ public class TemplateCommands { String joined = args.getJoinedStrings(2, ','); List ids = Lists.newArrayList(); for (String id : Splitter.on(',').trimResults().split(joined)) { - int parsed = Integer.parseInt(id); - ids.add(parsed); + ids.add(Ints.tryParse(id)); } - Iterable transformed = Iterables.transform(ids, new Function() { - @Override - public NPC apply(@Nullable Integer arg0) { - if (arg0 == null) - return null; - return CitizensAPI.getNPCRegistry().getById(arg0); - } - }); + Iterable transformed = Iterables.transform(ids, id -> CitizensAPI.getNPCRegistry().getById(id)); for (NPC toApply : transformed) { template.apply(toApply); appliedCount++; diff --git a/main/src/main/java/net/citizensnpcs/trait/waypoint/WanderWaypointProvider.java b/main/src/main/java/net/citizensnpcs/trait/waypoint/WanderWaypointProvider.java index 368ac8f8d..a9be1cc18 100644 --- a/main/src/main/java/net/citizensnpcs/trait/waypoint/WanderWaypointProvider.java +++ b/main/src/main/java/net/citizensnpcs/trait/waypoint/WanderWaypointProvider.java @@ -17,7 +17,7 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.metadata.FixedMetadataValue; -import com.google.common.base.Function; +import java.util.function.Function; import com.google.common.base.Supplier; import com.google.common.collect.ForwardingList; import com.google.common.collect.Lists;