Fix <item> hologram, cancel EntityTameEvent for protected NPCs

This commit is contained in:
fullwall 2023-07-19 23:53:43 +08:00
parent 9082f6ac3f
commit 5003f0c367
8 changed files with 39 additions and 17 deletions

View File

@ -301,7 +301,7 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
lib.addMavenCentral();
lib.setLogLevel(LogLevel.WARN);
// Unfortunately, transitive dependency management is not supported in this library.
lib.loadLibrary(Library.builder().groupId("ch{}ethz{}globis{}phtree").artifactId("phtree").version("2.5.0")
lib.loadLibrary(Library.builder().groupId("ch{}ethz{}globis{}phtree").artifactId("phtree").version("2.6.2")
.relocate("ch{}ethz{}globis{}phtree", "clib{}phtree").build());
lib.loadLibrary(Library.builder().groupId("net{}sf{}trove4j").artifactId("trove4j").version("3.0.3")
.relocate("gnu{}trove", "clib{}trove").build());

View File

@ -32,6 +32,7 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityPortalEvent;
import org.bukkit.event.entity.EntityTameEvent;
import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.entity.EntityTransformEvent;
import org.bukkit.event.entity.ItemDespawnEvent;
@ -361,6 +362,14 @@ public class EventListen implements Listener {
}
}
@EventHandler(ignoreCancelled = true)
public void onEntityTame(EntityTameEvent event) {
NPC npc = CitizensAPI.getNPCRegistry().getNPC(event.getEntity());
if (npc == null || !npc.isProtected())
return;
event.setCancelled(true);
}
@EventHandler
public void onEntityTarget(EntityTargetEvent event) {
NPC npc = CitizensAPI.getNPCRegistry().getNPC(event.getTarget());

View File

@ -1477,8 +1477,8 @@ public class NPCCommands {
.enablePageSwitcher('/' + args.getRawCommand() + " --page $page");
for (int i = 0; i < npcs.size(); i++) {
String id = npcs.get(i).getUniqueId().toString();
String line = StringHelper.wrap(id) + " " + npcs.get(i).getName() + " (<click:run_command:/npc tp --uuid "
+ id
String line = StringHelper.wrap(npcs.get(i).getId()) + " " + npcs.get(i).getName()
+ " (<click:run_command:/npc tp --uuid " + id
+ "><hover:show_text:Teleport to this NPC>[[tp]]</hover></click>) (<click:run_command:/npc tph --uuid "
+ id
+ "><hover:show_text:Teleport NPC to me>[[summon]]</hover></click>) (<click:run_command:/npc remove "

View File

@ -24,7 +24,6 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.permissions.PermissionAttachment;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
@ -329,14 +328,18 @@ public class CommandTrait extends Trait {
charge.run();
}
PermissionAttachment attachment = player.addAttachment(CitizensAPI.getPlugin());
if (temporaryPermissions.size() > 0) {
for (String permission : temporaryPermissions) {
attachment.setPermission(permission, true);
PermissionAttachment attachment = player.addAttachment(CitizensAPI.getPlugin());
if (attachment != null) {
for (String permission : temporaryPermissions) {
attachment.setPermission(permission, true);
}
command.run(npc, player);
attachment.remove();
return;
}
}
command.run(npc, player);
attachment.remove();
};
if (command.delay <= 0) {
runnable.run();
@ -582,7 +585,6 @@ public class CommandTrait extends Trait {
}
private static class NPCCommand {
String bungeeServer;
String command;
int cooldown;
double cost;
@ -611,8 +613,6 @@ public class CommandTrait extends Trait {
this.n = n;
this.delay = delay;
this.globalCooldown = globalCooldown;
List<String> split = Splitter.on(' ').omitEmptyStrings().trimResults().limit(2).splitToList(command);
this.bungeeServer = split.size() == 2 && split.get(0).equalsIgnoreCase("server") ? split.get(1) : null;
this.cost = cost;
this.experienceCost = experienceCost;
this.itemCost = itemCost;

View File

@ -8,6 +8,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
@ -95,6 +96,7 @@ public class HologramTrait extends Trait {
lines.clear();
}
@SuppressWarnings("deprecation")
private NPC createHologram(String line, double heightOffset) {
NPC hologramNPC = null;
if (useTextDisplay) {
@ -123,16 +125,23 @@ public class HologramTrait extends Trait {
if (itemMatcher.matches()) {
Material item = SpigotUtil.isUsing1_13API() ? Material.matchMaterial(itemMatcher.group(1), false)
: Material.matchMaterial(itemMatcher.group(1));
final NPC itemNPC = registry.createNPCUsingItem(EntityType.DROPPED_ITEM, "", new ItemStack(item, 1));
ItemStack itemStack = new ItemStack(item, 1);
final NPC itemNPC = registry.createNPCUsingItem(EntityType.DROPPED_ITEM, "", itemStack);
itemNPC.data().setPersistent(NPC.Metadata.NAMEPLATE_VISIBLE, false);
if (itemMatcher.group(2) != null) {
itemNPC.getOrAddTrait(ScoreboardTrait.class)
.setColor(Util.matchEnum(ChatColor.values(), itemMatcher.group(2).substring(1)));
if (itemMatcher.group(2).charAt(1) == '{') {
Bukkit.getUnsafe().modifyItemStack(itemStack, itemMatcher.group(2).substring(1));
itemNPC.setItemProvider(() -> itemStack);
} else {
itemNPC.getOrAddTrait(ScoreboardTrait.class)
.setColor(Util.matchEnum(ChatColor.values(), itemMatcher.group(2).substring(1)));
}
}
itemNPC.getOrAddTrait(MountTrait.class).setMountedOn(hologramNPC.getUniqueId());
itemNPC.spawn(currentLoc);
final NPC hn = hologramNPC;
itemNPC.addRunnable(() -> {
if (!itemNPC.isSpawned() || !itemNPC.getEntity().isInsideVehicle()) {
if (!itemNPC.isSpawned() || !hn.isSpawned()) {
itemNPC.destroy();
}
});

View File

@ -28,7 +28,7 @@ public class MountTrait extends Trait {
public void checkMounted() {
if (uuid == null || uuid.equals(currentMount))
return;
NPC other = CitizensAPI.getNPCRegistry().getByUniqueId(uuid);
NPC other = CitizensAPI.getNPCRegistry().getByUniqueIdGlobal(uuid);
if (other != null && other.isSpawned()) {
NMS.mount(other.getEntity(), npc.getEntity());
currentMount = uuid;

View File

@ -27,6 +27,10 @@ public class SpellcasterTrait extends Trait {
super("spellcastertrait");
}
public Spell getSpell() {
return spell;
}
@Override
public void run() {
if (!npc.isSpawned() || !(npc.getEntity() instanceof Spellcaster))

View File

@ -387,7 +387,7 @@ public class GuidedWaypointProvider implements EnumerableWaypointProvider {
@Override
public Plan buildPlan() {
return new GuidedPlan(this.<GuidedNode> getParents());
return new GuidedPlan(this.<GuidedNode> orderedPath());
}
public double distance(Waypoint dest) {