Skip to content

Commit

Permalink
Merge branch 'main' into feature/thread-friendly-command
Browse files Browse the repository at this point in the history
  • Loading branch information
szumielxd authored Jan 16, 2025
2 parents 0adc1c1 + 0275372 commit 8bbbb4b
Show file tree
Hide file tree
Showing 25 changed files with 215 additions and 72 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ body:
description: Which server version are you using? If your server version is not listed, it is not supported. Update to a supported version first.
multiple: false
options:
- '1.21.3'
- '1.21.1'
- '1.20.6'
- '1.20.4'
Expand Down
2 changes: 1 addition & 1 deletion .github/renovate.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base",
"config:recommended",
":semanticCommitsDisabled"
],
"automerge": true,
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/label-merge-conflicts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Label conflicting PRs
uses: eps1lon/[email protected].2
uses: eps1lon/[email protected].3
with:
dirtyLabel: "unresolved-merge-conflict"
repoToken: "${{ secrets.GITHUB_TOKEN }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,9 @@ public void setGenerator(final @NonNull String worldName) {
@Override
public @NonNull String serverNativePackage() {
final String name = Bukkit.getServer().getClass().getPackage().getName();
return name.substring(name.lastIndexOf('.') + 1);
String ver = name.substring(name.lastIndexOf('.') + 1);
// org.bukkit.craftbukkit is no longer suffixed by a version
return ver.equals("craftbukkit") ? "" : ver;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
Expand Down Expand Up @@ -445,7 +445,7 @@ private final class BukkitPlotBiomeProvider extends BiomeProvider {
private static final List<Biome> BIOMES;

static {
Set<Biome> disabledBiomes = EnumSet.of(Biome.CUSTOM);
Set<Biome> disabledBiomes = new HashSet<>(List.of(Biome.CUSTOM));
if (PlotSquared.platform().serverVersion()[1] <= 19) {
final Biome cherryGrove = Registry.BIOME.get(NamespacedKey.minecraft("cherry_grove"));
if (cherryGrove != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.plotsquared.core.plot.flag.implementations.ExplosionFlag;
import com.plotsquared.core.plot.flag.implementations.InvincibleFlag;
import com.plotsquared.core.plot.flag.implementations.ProjectileChangeBlockFlag;
import com.plotsquared.core.plot.flag.implementations.WeavingDeathPlace;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.PlotFlagUtil;
Expand Down Expand Up @@ -243,6 +244,29 @@ public void onEntityFall(EntityChangeBlockEvent event) {
}
}

@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onWeavingEffect(EntityChangeBlockEvent event) {
if (event.getTo() != Material.COBWEB) {
return;
}
Location location = BukkitUtil.adapt(event.getBlock().getLocation());
PlotArea area = location.getPlotArea();
if (area == null) {
return;
}
Plot plot = location.getOwnedPlot();
if (plot == null) {
if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, WeavingDeathPlace.class, false)) {
event.setCancelled(true);
}
return;
}
if (!plot.getFlag(WeavingDeathPlace.class)) {
plot.debug(event.getTo() + " could not spawn because weaving-death-place = false");
event.setCancelled(true);
}
}

@EventHandler(priority = EventPriority.HIGH)
public void onDamage(EntityDamageEvent event) {
if (event.getEntityType() != EntityType.PLAYER) {
Expand Down Expand Up @@ -401,7 +425,13 @@ public void onPeskyMobsChangeTheWorldLikeWTFEvent(EntityChangeBlockEvent event)
}

Plot plot = area.getOwnedPlot(location);
if (plot != null && !plot.getFlag(EntityChangeBlockFlag.class)) {
if (plot == null) {
if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, EntityChangeBlockFlag.class, false)) {
event.setCancelled(true);
}
return;
}
if (!plot.getFlag(EntityChangeBlockFlag.class)) {
plot.debug(e.getType() + " could not change block because entity-change-block = false");
event.setCancelled(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import com.plotsquared.core.plot.flag.types.BooleanFlag;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.PlotFlagUtil;
import io.papermc.paper.event.entity.EntityMoveEvent;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
Expand All @@ -58,6 +59,7 @@
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Slime;
import org.bukkit.event.Cancellable;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
Expand Down Expand Up @@ -104,33 +106,7 @@ public void onEntityPathfind(EntityPathfindEvent event) {
if (!Settings.Paper_Components.ENTITY_PATHING) {
return;
}
Location toLoc = BukkitUtil.adapt(event.getLoc());
Location fromLoc = BukkitUtil.adapt(event.getEntity().getLocation());
PlotArea tarea = toLoc.getPlotArea();
if (tarea == null) {
return;
}
PlotArea farea = fromLoc.getPlotArea();
if (farea == null) {
return;
}
if (tarea != farea) {
event.setCancelled(true);
return;
}
Plot tplot = toLoc.getPlot();
Plot fplot = fromLoc.getPlot();
if (tplot == null ^ fplot == null) {
event.setCancelled(true);
return;
}
if (tplot == null || tplot.getId().hashCode() == fplot.getId().hashCode()) {
return;
}
if (fplot.isMerged() && fplot.getConnectedPlots().contains(fplot)) {
return;
}
event.setCancelled(true);
handleEntityMovement(event, event.getEntity().getLocation(), event.getLoc());
}

@EventHandler
Expand All @@ -145,8 +121,23 @@ public void onEntityPathfind(SlimePathfindEvent event) {
return;
}

Location toLoc = BukkitUtil.adapt(b.getLocation());
Location fromLoc = BukkitUtil.adapt(event.getEntity().getLocation());
handleEntityMovement(event, event.getEntity().getLocation(), b.getLocation());
}

@EventHandler
public void onEntityMove(EntityMoveEvent event) {
if (!Settings.Paper_Components.ENTITY_MOVEMENT) {
return;
}
if (!event.hasExplicitlyChangedBlock()) {
return;
}
handleEntityMovement(event, event.getFrom(), event.getTo());
}

private static void handleEntityMovement(Cancellable event, org.bukkit.Location from, org.bukkit.Location target) {
Location toLoc = BukkitUtil.adapt(target);
Location fromLoc = BukkitUtil.adapt(from);
PlotArea tarea = toLoc.getPlotArea();
if (tarea == null) {
return;
Expand All @@ -155,7 +146,6 @@ public void onEntityPathfind(SlimePathfindEvent event) {
if (farea == null) {
return;
}

if (tarea != farea) {
event.setCancelled(true);
return;
Expand All @@ -166,10 +156,10 @@ public void onEntityPathfind(SlimePathfindEvent event) {
event.setCancelled(true);
return;
}
if (tplot == null || tplot.getId().hashCode() == fplot.getId().hashCode()) {
if (tplot == null || tplot.getId().equals(fplot.getId())) {
return;
}
if (fplot.isMerged() && fplot.getConnectedPlots().contains(fplot)) {
if (fplot.isMerged() && fplot.getConnectedPlots().contains(tplot)) {
return;
}
event.setCancelled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import com.plotsquared.core.plot.flag.implementations.HangingBreakFlag;
import com.plotsquared.core.plot.flag.implementations.HangingPlaceFlag;
import com.plotsquared.core.plot.flag.implementations.HostileInteractFlag;
import com.plotsquared.core.plot.flag.implementations.InteractionInteractFlag;
import com.plotsquared.core.plot.flag.implementations.ItemDropFlag;
import com.plotsquared.core.plot.flag.implementations.KeepInventoryFlag;
import com.plotsquared.core.plot.flag.implementations.LecternReadBookFlag;
Expand Down Expand Up @@ -1737,6 +1738,11 @@ public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
return;
}

if (EntityCategories.INTERACTION.contains(entityType) && flagContainer
.getFlag(InteractionInteractFlag.class).getValue()) {
return;
}

if (EntityCategories.VILLAGER.contains(entityType) && flagContainer
.getFlag(VillagerInteractFlag.class).getValue()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@ public SingleWorldListener() throws Exception {
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle").getRealMethod();
} catch (NoSuchMethodException ignored) {
try {
ReflectionUtils.RefClass classChunkStatus = getRefClass("net.minecraft.world.level.chunk.ChunkStatus");
String chunkStatus = PlotSquared.platform().serverVersion()[1] < 21
? "net.minecraft.world.level.chunk" + ".ChunkStatus"
: "net.minecraft.world.level.chunk.status.ChunkStatus";
ReflectionUtils.RefClass classChunkStatus = getRefClass(chunkStatus);
this.objChunkStatusFull = classChunkStatus.getRealClass().getField("n").get(null);
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle", classChunkStatus.getRealClass()).getRealMethod();
this.methodGetHandleChunk = classCraftChunk
.getMethod("getHandle", classChunkStatus.getRealClass())
.getRealMethod();
} catch (NoSuchMethodException ex) {
throw new RuntimeException(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,28 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
private static final SideEffectSet EDGE_LIGHTING_SIDE_EFFECT_SET;

static {
NO_SIDE_EFFECT_SET = SideEffectSet.none().with(SideEffect.LIGHTING, SideEffect.State.OFF).with(
SideEffect.NEIGHBORS,
SideEffect.State.OFF
);
EDGE_SIDE_EFFECT_SET = SideEffectSet.none().with(SideEffect.UPDATE, SideEffect.State.ON).with(
SideEffect.NEIGHBORS,
SideEffect.State.ON
);
LIGHTING_SIDE_EFFECT_SET = SideEffectSet.none().with(SideEffect.NEIGHBORS, SideEffect.State.OFF);
EDGE_LIGHTING_SIDE_EFFECT_SET = SideEffectSet.none().with(SideEffect.UPDATE, SideEffect.State.ON).with(
SideEffect.NEIGHBORS,
SideEffect.State.ON
);
NO_SIDE_EFFECT_SET = enableNetworkIfNeeded()
.with(SideEffect.LIGHTING, SideEffect.State.OFF)
.with(SideEffect.NEIGHBORS, SideEffect.State.OFF);
EDGE_SIDE_EFFECT_SET = NO_SIDE_EFFECT_SET
.with(SideEffect.UPDATE, SideEffect.State.ON)
.with(SideEffect.NEIGHBORS, SideEffect.State.ON);
LIGHTING_SIDE_EFFECT_SET = NO_SIDE_EFFECT_SET
.with(SideEffect.NEIGHBORS, SideEffect.State.OFF);
EDGE_LIGHTING_SIDE_EFFECT_SET = NO_SIDE_EFFECT_SET
.with(SideEffect.UPDATE, SideEffect.State.ON)
.with(SideEffect.NEIGHBORS, SideEffect.State.ON);
}

// make sure block changes are sent
private static SideEffectSet enableNetworkIfNeeded() {
SideEffect network;
try {
network = SideEffect.valueOf("NETWORK");
} catch (IllegalArgumentException ignored) {
return SideEffectSet.none();
}
return SideEffectSet.none().with(network, SideEffect.State.ON);
}

private org.bukkit.World bukkitWorld;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import org.bukkit.entity.Firework;
import org.bukkit.entity.Ghast;
import org.bukkit.entity.Hanging;
import org.bukkit.entity.Interaction;
import org.bukkit.entity.IronGolem;
import org.bukkit.entity.Item;
import org.bukkit.entity.LightningStrike;
Expand Down Expand Up @@ -432,14 +433,15 @@ public void setFoodLevel(final @NonNull PlotPlayer<?> player, @NonNegative final
@Override
public @NonNull Set<com.sk89q.worldedit.world.entity.EntityType> getTypesInCategory(final @NonNull String category) {
final Collection<Class<?>> allowedInterfaces = new HashSet<>();
final int[] version = PlotSquared.platform().serverVersion();
switch (category) {
case "animal" -> {
allowedInterfaces.add(IronGolem.class);
allowedInterfaces.add(Snowman.class);
allowedInterfaces.add(Animals.class);
allowedInterfaces.add(WaterMob.class);
allowedInterfaces.add(Ambient.class);
if (PlotSquared.platform().serverVersion()[1] >= 19) {
if (version[1] >= 19) {
allowedInterfaces.add(Allay.class);
}
}
Expand Down Expand Up @@ -470,6 +472,11 @@ public void setFoodLevel(final @NonNull PlotPlayer<?> player, @NonNegative final
allowedInterfaces.add(Firework.class);
}
case "player" -> allowedInterfaces.add(Player.class);
case "interaction" -> {
if ((version[1] > 19) || (version[1] == 19 && version[2] >= 4)) {
allowedInterfaces.add(Interaction.class);
}
}
default -> LOGGER.error("Unknown entity category requested: {}", category);
}
final Set<com.sk89q.worldedit.world.entity.EntityType> types = new HashSet<>();
Expand Down
7 changes: 4 additions & 3 deletions Core/src/main/java/com/plotsquared/core/PlotSquared.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,16 @@ public PlotSquared(
GlobalFlagContainer.setup();

try {
new ReflectionUtils(this.platform.serverNativePackage());
String ver = this.platform.serverNativePackage();
new ReflectionUtils(ver.isEmpty() ? null : ver);
try {
URL logurl = PlotSquared.class.getProtectionDomain().getCodeSource().getLocation();
this.jarFile = new File(
URI.create(
logurl.toURI().toString().split("\\!")[0].replaceAll("jar:file", "file"))
.getPath());
} catch (URISyntaxException | SecurityException e) {
e.printStackTrace();
LOGGER.error(e);
this.jarFile = new File(this.platform.getDirectory().getParentFile(), "PlotSquared.jar");
if (!this.jarFile.exists()) {
this.jarFile = new File(
Expand All @@ -238,7 +239,7 @@ public PlotSquared(
copyFile("skyblock.template", Settings.Paths.TEMPLATES);
showDebug();
} catch (Throwable e) {
e.printStackTrace();
LOGGER.error(e);
}
}

Expand Down
3 changes: 2 additions & 1 deletion Core/src/main/java/com/plotsquared/core/command/Music.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public class Music extends SubCommand {
.asList("music_disc_13", "music_disc_cat", "music_disc_blocks", "music_disc_chirp",
"music_disc_far", "music_disc_mall", "music_disc_mellohi", "music_disc_stal",
"music_disc_strad", "music_disc_ward", "music_disc_11", "music_disc_wait", "music_disc_otherside",
"music_disc_pigstep", "music_disc_5", "music_disc_relic"
"music_disc_pigstep", "music_disc_5", "music_disc_relic", "music_disc_creator",
"music_disc_creator_music_box", "music_disc_precipice"
);

private final InventoryUtil inventoryUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import java.io.File;
import java.io.PrintWriter;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand Down Expand Up @@ -372,6 +373,7 @@ private static void setAccessible(Field field) {
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.TYPE})
@Documented
public @interface Comment {

String[] value();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,8 @@ public static final class Paper_Components {
public static boolean PAPER_LISTENERS = true;
@Comment("Prevent entities from leaving plots")
public static boolean ENTITY_PATHING = true;
@Comment("Prevent entities from leaving plots, even by pushing or pulling")
public static boolean ENTITY_MOVEMENT = false;
@Comment(
"Cancel entity spawns when the chunk is loaded if the PlotArea's mob spawning is off")
public static boolean CANCEL_CHUNK_SPAWN = true;
Expand Down
Loading

0 comments on commit 8bbbb4b

Please sign in to comment.