mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-11 02:49:11 +01:00
Remove guava Function usage, track script extensions
This commit is contained in:
parent
406bea7b53
commit
dd440ed653
@ -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<String, Integer> 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());
|
||||
}
|
||||
|
@ -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<Integer> 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<NPC> transformed = Iterables.transform(ids, new Function<Integer, NPC>() {
|
||||
@Override
|
||||
public NPC apply(@Nullable Integer arg0) {
|
||||
if (arg0 == null)
|
||||
return null;
|
||||
return CitizensAPI.getNPCRegistry().getById(arg0);
|
||||
}
|
||||
});
|
||||
Iterable<NPC> transformed = Iterables.transform(ids, id -> CitizensAPI.getNPCRegistry().getById(id));
|
||||
for (NPC toApply : transformed) {
|
||||
template.apply(toApply);
|
||||
appliedCount++;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user