Delay protocollib loading

This commit is contained in:
fullwall 2023-03-26 13:28:23 +08:00
parent 82030a6534
commit bafc6df000
7 changed files with 106 additions and 14 deletions

View File

@ -232,11 +232,7 @@
<relocation>
<pattern>net.kyori</pattern>
<shadedPattern>clib.net.kyori</shadedPattern>
</relocation>
<relocation>
<pattern>org.joml</pattern>
<shadedPattern>clib.org.joml</shadedPattern>
</relocation>
</relocation>
<relocation>
<pattern>net.byteflux.libby</pattern>
<shadedPattern>clib.net.byteflux.libby</shadedPattern>

View File

@ -25,6 +25,7 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import com.comphenix.protocol.ProtocolLibrary;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
@ -335,8 +336,11 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
.relocate("net{}kyori", "clib{}net{}kyori").build());
lib.loadLibrary(Library.builder().groupId("net{}kyori").artifactId("examination-string").version("1.3.0")
.relocate("net{}kyori", "clib{}net{}kyori").build());
lib.loadLibrary(Library.builder().groupId("org{}joml").artifactId("joml").version("1.10.5")
.relocate("org{}joml", "clib{}org{}joml").build());
try {
Class.forName("org.joml.Vector3f");
} catch (Throwable t) {
lib.loadLibrary(Library.builder().groupId("org{}joml").artifactId("joml").version("1.10.5").build());
}
}
@Override
@ -420,14 +424,11 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
CommandTrait trait = npc.getTraitNullable(CommandTrait.class);
return trait == null ? "" : trait.fillPlaceholder(sender, input);
});
Plugin papi = Bukkit.getPluginManager().getPlugin("PlaceholderAPI");
if (papi != null && papi.isEnabled()) {
new CitizensPlaceholders(selector).register();
}
Plugin plib = Bukkit.getPluginManager().getPlugin("ProtocolLib");
if (plib != null && plib.isEnabled()) {
protocolListener = new ProtocolLibListener(this);
}
setupEconomy();
@ -591,6 +592,18 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
private class CitizensLoadTask implements Runnable {
@Override
public void run() {
Plugin plib = Bukkit.getPluginManager().getPlugin("ProtocolLib");
if (plib != null && plib.isEnabled() && ProtocolLibrary.getProtocolManager() != null) {
try {
protocolListener = new ProtocolLibListener(Citizens.this);
} catch (Throwable t) {
Messaging.severe("ProtocolLib support not enabled: enable debug to see error");
if (Messaging.isDebugging()) {
t.printStackTrace();
}
}
}
saves.loadInto(npcRegistry);
shops.load();

View File

@ -133,6 +133,7 @@ public class ProtocolLibListener {
session.onPacketOverwritten();
}
});
}
private StructureModifier<Set<PlayerTeleportFlag>> getFlagsModifier(PacketContainer handle) {

View File

@ -2318,6 +2318,7 @@ public class NPCCommands {
return;
}
}
if (args.argsLength() == 2) {
if ("all".equalsIgnoreCase(action)) {
if (!sender.hasPermission("citizens.admin.remove.all") && !sender.hasPermission("citizens.admin"))

View File

@ -0,0 +1,81 @@
package net.citizensnpcs.trait.versioned;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Warden;
import com.google.common.collect.Maps;
import net.citizensnpcs.api.command.Arg;
import net.citizensnpcs.api.command.Command;
import net.citizensnpcs.api.command.CommandContext;
import net.citizensnpcs.api.command.Requirements;
import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.command.exception.CommandUsageException;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName;
import net.citizensnpcs.api.util.Messaging;
@TraitName("wardentrait")
public class WardenTrait extends Trait {
private final Map<UUID, Integer> anger = Maps.newHashMap();
public WardenTrait() {
super("wardentrait");
}
private void addAnger(Entity entity, int anger) {
this.anger.put(entity.getUniqueId(), anger);
}
@Override
public void run() {
if (npc.isSpawned() && npc.getEntity() instanceof Warden) {
Warden warden = (Warden) npc.getEntity();
for (Map.Entry<UUID, Integer> entry : anger.entrySet()) {
warden.setAnger(Bukkit.getEntity(entry.getKey()), entry.getValue());
}
}
}
@Command(
aliases = { "npc" },
usage = "warden anger [entity uuid/player name] [anger]",
desc = "Sets warden modifiers",
modifiers = { "warden" },
min = 1,
max = 4,
permission = "citizens.npc.warden")
@Requirements(selected = true, ownership = true, types = EntityType.WARDEN)
public static void Warden(CommandContext args, CommandSender sender, NPC npc,
@Arg(value = 1, completions = { "anger" }) String command, @Arg(2) String player, @Arg(3) Integer anger)
throws CommandException {
WardenTrait trait = npc.getOrAddTrait(WardenTrait.class);
String output = "";
if (command.equalsIgnoreCase("anger")) {
if (anger == null)
throw new CommandUsageException();
Entity entity = null;
try {
UUID uuid = UUID.fromString(player);
entity = Bukkit.getEntity(uuid);
} catch (IllegalArgumentException iae) {
entity = Bukkit.getOfflinePlayer(player).getPlayer();
}
if (entity != null) {
trait.addAnger(entity, anger);
}
}
if (!output.isEmpty()) {
Messaging.send(sender, output.trim());
} else {
throw new CommandUsageException();
}
}
}

View File

@ -94,16 +94,14 @@ public class WardenController extends MobEntityController {
return;
}
NMSImpl.updateMinecraftAIState(npc, this);
npc.update();
if (npc.useMinecraftAI()) {
super.customServerAiStep();
} else {
NMSImpl.updateAI(this);
}
npc.update();
}
@Override
protected SoundEvent getAmbientSound() {
return NMSImpl.getSoundEffect(npc, super.getAmbientSound(), NPC.Metadata.AMBIENT_SOUND);

View File

@ -254,6 +254,7 @@ import net.citizensnpcs.trait.versioned.SnowmanTrait;
import net.citizensnpcs.trait.versioned.SpellcasterTrait;
import net.citizensnpcs.trait.versioned.TropicalFishTrait;
import net.citizensnpcs.trait.versioned.VillagerTrait;
import net.citizensnpcs.trait.versioned.WardenTrait;
import net.citizensnpcs.util.EmptyChannel;
import net.citizensnpcs.util.EntityPacketTracker;
import net.citizensnpcs.util.Messages;
@ -901,6 +902,7 @@ public class NMSImpl implements NMSBridge {
registerTraitWithCommand(manager, SnowmanTrait.class);
registerTraitWithCommand(manager, TropicalFishTrait.class);
registerTraitWithCommand(manager, VillagerTrait.class);
registerTraitWithCommand(manager, WardenTrait.class);
}
private void loadEntityTypes() {