mirror of
https://github.com/AtlasMediaGroup/Scissors.git
synced 2024-11-01 12:37:10 +00:00
190 lines
12 KiB
Diff
190 lines
12 KiB
Diff
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||
|
From: Telesphoreo <me@telesphoreo.me>
|
||
|
Date: Sun, 10 Dec 2023 13:40:21 -0600
|
||
|
Subject: [PATCH] ResourceLocation validation
|
||
|
|
||
|
|
||
|
diff --git a/src/main/java/com/destroystokyo/paper/loottable/PaperContainerEntityLootableInventory.java b/src/main/java/com/destroystokyo/paper/loottable/PaperContainerEntityLootableInventory.java
|
||
|
index 15173e715fa36546820d930a46e0f0c493d07cfc..356cc6f468975faa676db87db8fc0fa2df32f020 100644
|
||
|
--- a/src/main/java/com/destroystokyo/paper/loottable/PaperContainerEntityLootableInventory.java
|
||
|
+++ b/src/main/java/com/destroystokyo/paper/loottable/PaperContainerEntityLootableInventory.java
|
||
|
@@ -17,7 +17,7 @@ public class PaperContainerEntityLootableInventory implements PaperLootableEntit
|
||
|
|
||
|
@Override
|
||
|
public org.bukkit.loot.LootTable getLootTable() {
|
||
|
- return entity.getLootTable() != null && !entity.getLootTable().getPath().isEmpty() ? Bukkit.getLootTable(CraftNamespacedKey.fromMinecraft(entity.getLootTable())) : null;
|
||
|
+ return entity.getLootTable() != null && !entity.getLootTable().getPath().isEmpty() && entity.getLootTable().toString().length() < 256 ? Bukkit.getLootTable(CraftNamespacedKey.fromMinecraft(entity.getLootTable())) : null; // Scissors - Validate length of loot tables before even trying
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
diff --git a/src/main/java/com/destroystokyo/paper/loottable/PaperTileEntityLootableInventory.java b/src/main/java/com/destroystokyo/paper/loottable/PaperTileEntityLootableInventory.java
|
||
|
index 2ee4ee14ab3345486dad6b24fd9a4fcc6c746b99..c5ac6cda91a81d3075f5c763e30dc009b6be7936 100644
|
||
|
--- a/src/main/java/com/destroystokyo/paper/loottable/PaperTileEntityLootableInventory.java
|
||
|
+++ b/src/main/java/com/destroystokyo/paper/loottable/PaperTileEntityLootableInventory.java
|
||
|
@@ -15,7 +15,7 @@ public class PaperTileEntityLootableInventory implements PaperLootableBlockInven
|
||
|
|
||
|
@Override
|
||
|
public org.bukkit.loot.LootTable getLootTable() {
|
||
|
- return tileEntityLootable.lootTable != null && !tileEntityLootable.lootTable.getPath().isEmpty() ? Bukkit.getLootTable(CraftNamespacedKey.fromMinecraft(tileEntityLootable.lootTable)) : null;
|
||
|
+ return tileEntityLootable.lootTable != null && !tileEntityLootable.lootTable.getPath().isEmpty() && tileEntityLootable.lootTable.toString().length() < 256 ? Bukkit.getLootTable(CraftNamespacedKey.fromMinecraft(tileEntityLootable.lootTable)) : null; // Scissors - Validate length of loot tables before even trying
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
diff --git a/src/main/java/net/minecraft/world/entity/AreaEffectCloud.java b/src/main/java/net/minecraft/world/entity/AreaEffectCloud.java
|
||
|
index 1f55185814125c691288294d18bf1580461c8066..259d65f8e21f9cf99585d416eafdc967dddccf57 100644
|
||
|
--- a/src/main/java/net/minecraft/world/entity/AreaEffectCloud.java
|
||
|
+++ b/src/main/java/net/minecraft/world/entity/AreaEffectCloud.java
|
||
|
@@ -409,7 +409,7 @@ public class AreaEffectCloud extends Entity implements TraceableEntity {
|
||
|
try {
|
||
|
this.setParticle(ParticleArgument.readParticle(new StringReader(nbt.getString("Particle")), (HolderLookup) BuiltInRegistries.PARTICLE_TYPE.asLookup()));
|
||
|
} catch (CommandSyntaxException commandsyntaxexception) {
|
||
|
- AreaEffectCloud.LOGGER.warn("Couldn't load custom particle {}", nbt.getString("Particle"), commandsyntaxexception);
|
||
|
+ // Scissors - Don't log custom particle errors
|
||
|
}
|
||
|
}
|
||
|
|
||
|
diff --git a/src/main/java/net/minecraft/world/entity/EntityType.java b/src/main/java/net/minecraft/world/entity/EntityType.java
|
||
|
index 940b8d0b89d7e55c938aefbe80ee71b0db3dacb8..297a214a7833fd67640c94352671483bc4fc8dd5 100644
|
||
|
--- a/src/main/java/net/minecraft/world/entity/EntityType.java
|
||
|
+++ b/src/main/java/net/minecraft/world/entity/EntityType.java
|
||
|
@@ -593,7 +593,7 @@ public class EntityType<T extends Entity> implements FeatureElement, EntityTypeT
|
||
|
}), (entity) -> {
|
||
|
entity.load(nbt);
|
||
|
}, () -> {
|
||
|
- EntityType.LOGGER.warn("Skipping Entity with id {}", nbt.getString("id"));
|
||
|
+ // Scissors - Don't log invalid entities
|
||
|
});
|
||
|
}
|
||
|
|
||
|
@@ -612,7 +612,7 @@ public class EntityType<T extends Entity> implements FeatureElement, EntityTypeT
|
||
|
}
|
||
|
|
||
|
public static Optional<EntityType<?>> by(CompoundTag nbt) {
|
||
|
- return BuiltInRegistries.ENTITY_TYPE.getOptional(new ResourceLocation(nbt.getString("id")));
|
||
|
+ return BuiltInRegistries.ENTITY_TYPE.getOptional(ResourceLocation.tryParse(nbt.getString("id"))); // Scissors
|
||
|
}
|
||
|
|
||
|
@Nullable
|
||
|
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
|
||
|
index e0cf7771488ab0065708d68b4e8550b865af0ed4..0dbfa66c41ba8242b6389296d175d7d738aac3ca 100644
|
||
|
--- a/src/main/java/net/minecraft/world/entity/Mob.java
|
||
|
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
|
||
|
@@ -620,7 +620,7 @@ public abstract class Mob extends LivingEntity implements Targeting {
|
||
|
|
||
|
this.setLeftHanded(nbt.getBoolean("LeftHanded"));
|
||
|
if (nbt.contains("DeathLootTable", 8)) {
|
||
|
- this.lootTable = new ResourceLocation(nbt.getString("DeathLootTable"));
|
||
|
+ this.lootTable = ResourceLocation.tryParse(nbt.getString("DeathLootTable")); // Scissors
|
||
|
this.lootTableSeed = nbt.getLong("DeathLootTableSeed");
|
||
|
}
|
||
|
|
||
|
diff --git a/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java
|
||
|
index a18aadbf7ae83713e1f2b21553185d8000bc7699..f5ad7ddf13cbb6452c2927aef9b54eae3335b4c6 100644
|
||
|
--- a/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java
|
||
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java
|
||
|
@@ -289,7 +289,12 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit
|
||
|
while (iterator.hasNext()) {
|
||
|
String s = (String) iterator.next();
|
||
|
|
||
|
- this.recipesUsed.put(new ResourceLocation(s), nbttagcompound1.getInt(s));
|
||
|
+ // Scissors start
|
||
|
+ final ResourceLocation rl = ResourceLocation.tryParse(s);
|
||
|
+ if (rl != null) {
|
||
|
+ this.recipesUsed.put(rl, nbttagcompound1.getInt(s));
|
||
|
+ }
|
||
|
+ // Scissors end
|
||
|
}
|
||
|
|
||
|
// Paper start - cook speed API
|
||
|
diff --git a/src/main/java/net/minecraft/world/level/block/entity/BrushableBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/BrushableBlockEntity.java
|
||
|
index b5b1831631e233a96b6fd55972a8862b0f420da8..a086f12c09a5e38f63c8de118fcb5a6a30e40b52 100644
|
||
|
--- a/src/main/java/net/minecraft/world/level/block/entity/BrushableBlockEntity.java
|
||
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/BrushableBlockEntity.java
|
||
|
@@ -199,7 +199,7 @@ public class BrushableBlockEntity extends BlockEntity {
|
||
|
|
||
|
private boolean tryLoadLootTable(CompoundTag nbt) {
|
||
|
if (nbt.contains("LootTable", 8)) {
|
||
|
- this.lootTable = new ResourceLocation(nbt.getString("LootTable"));
|
||
|
+ this.lootTable = ResourceLocation.tryParse(nbt.getString("LootTable")); // Scissors
|
||
|
this.lootTableSeed = nbt.getLong("LootTableSeed");
|
||
|
return true;
|
||
|
} else {
|
||
|
diff --git a/src/main/java/net/minecraft/world/level/block/entity/RandomizableContainerBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/RandomizableContainerBlockEntity.java
|
||
|
index 64875525df244db838560f5fefb7b1b07b0f1f51..fd490db7431404b0324e5ade474ec95d694aa489 100644
|
||
|
--- a/src/main/java/net/minecraft/world/level/block/entity/RandomizableContainerBlockEntity.java
|
||
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/RandomizableContainerBlockEntity.java
|
||
|
@@ -50,7 +50,7 @@ public abstract class RandomizableContainerBlockEntity extends BaseContainerBloc
|
||
|
// Copied from super with changes, always check the original method
|
||
|
this.lootableData.loadNbt(nbt); // Paper
|
||
|
if (nbt.contains("LootTable", 8)) {
|
||
|
- this.setLootTable(new ResourceLocation(nbt.getString("LootTable")));
|
||
|
+ this.setLootTable(ResourceLocation.tryParse((nbt.getString("LootTable")))); // Scissors - Validate loot tables
|
||
|
try { org.bukkit.craftbukkit.util.CraftNamespacedKey.fromMinecraft(this.lootTable); } catch (IllegalArgumentException ex) { this.lootTable = null; } // Paper - validate
|
||
|
this.setLootTableSeed(nbt.getLong("LootTableSeed"));
|
||
|
return false; // Paper - always load the items, table may still remain
|
||
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftLootable.java b/src/main/java/org/bukkit/craftbukkit/block/CraftLootable.java
|
||
|
index f6942cb3ef1f9ef03708d4bc932ea9aeb1c13894..8b32864bafb3c1948993688be8f639dd6492057e 100644
|
||
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftLootable.java
|
||
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftLootable.java
|
||
|
@@ -34,8 +34,14 @@ public abstract class CraftLootable<T extends RandomizableContainerBlockEntity>
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
- ResourceLocation key = this.getSnapshot().lootTable;
|
||
|
- return Bukkit.getLootTable(CraftNamespacedKey.fromMinecraft(key));
|
||
|
+ // Scissors start - Return a null loot table if the specified loot table is not valid
|
||
|
+ try {
|
||
|
+ ResourceLocation key = this.getSnapshot().lootTable;
|
||
|
+ return Bukkit.getLootTable(CraftNamespacedKey.fromMinecraft(key));
|
||
|
+ } catch (Exception ex) {
|
||
|
+ return null;
|
||
|
+ }
|
||
|
+ // Scissors end
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartContainer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartContainer.java
|
||
|
index 313ee5c8737b2e57f9b5db6512c1871766b2ccd4..a115a13ec911884a804800fc13f0347be1a30932 100644
|
||
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartContainer.java
|
||
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartContainer.java
|
||
|
@@ -33,8 +33,15 @@ public abstract class CraftMinecartContainer extends CraftMinecart implements Lo
|
||
|
return null; // return empty loot table?
|
||
|
}
|
||
|
|
||
|
- NamespacedKey key = CraftNamespacedKey.fromMinecraft(nmsTable);
|
||
|
- return Bukkit.getLootTable(key);
|
||
|
+ // Scissors start - Return a null loot table if the specified loot table is not valid
|
||
|
+ try
|
||
|
+ {
|
||
|
+ NamespacedKey key = CraftNamespacedKey.fromMinecraft(nmsTable);
|
||
|
+ return Bukkit.getLootTable(key);
|
||
|
+ } catch (Exception exception) {
|
||
|
+ return null;
|
||
|
+ }
|
||
|
+ // Scissors end
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java
|
||
|
index 5f6a1fb323782816f706ccf7df922cb203238302..21b4594379a5e904ad60f9c9512ace94e7ed5f68 100644
|
||
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java
|
||
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java
|
||
|
@@ -80,8 +80,15 @@ public abstract class CraftMob extends CraftLivingEntity implements Mob {
|
||
|
|
||
|
@Override
|
||
|
public LootTable getLootTable() {
|
||
|
- NamespacedKey key = CraftNamespacedKey.fromMinecraft(this.getHandle().getLootTable());
|
||
|
- return Bukkit.getLootTable(key);
|
||
|
+ // Scissors start - Return a null loot table if the specified loot table is not valid
|
||
|
+ try
|
||
|
+ {
|
||
|
+ NamespacedKey key = CraftNamespacedKey.fromMinecraft(this.getHandle().getLootTable());
|
||
|
+ return Bukkit.getLootTable(key);
|
||
|
+ } catch (Exception ex) {
|
||
|
+ return null;
|
||
|
+ }
|
||
|
+ // Scissors end
|
||
|
}
|
||
|
|
||
|
@Override
|