1
0
Fork 0
mirror of https://github.com/PaperMC/Paper.git synced 2025-02-16 18:31:53 +01:00

Update from upstream SpigotMC

Allow Attribute Capping. SpigotMC/Spigot@fb3a9d38dd
Fix unit tests (broken in the above) SpigotMC/Spigot@1e98f1161f
Update attribute maxes again once loaded SpigotMC/Spigot@2bf4481e15
This commit is contained in:
Zach Brown 2014-07-28 03:00:45 -05:00
parent 794f5c76dc
commit 86c0528de1
2 changed files with 232 additions and 0 deletions

View file

@ -23,6 +23,54 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
</dependencies>
<!-- This builds a completely 'ready to start' jar with all dependencies inside -->
diff --git a/src/main/java/net/minecraft/server/AttributeRanged.java b/src/main/java/net/minecraft/server/AttributeRanged.java
new file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
--- /dev/null
+++ b/src/main/java/net/minecraft/server/AttributeRanged.java
@@ -0,0 +0,0 @@
+package net.minecraft.server;
+
+public class AttributeRanged extends AttributeBase {
+
+ private final double a;
+ private final double b;
+ private String c;
+
+ public AttributeRanged(String s, double d0, double d1, double d2) {
+ super(s, d0);
+ this.a = d1;
+ this.b = d2;
+ if (d1 > d2) {
+ throw new IllegalArgumentException("Minimum value cannot be bigger than maximum value!");
+ } else if (d0 < d1) {
+ throw new IllegalArgumentException("Default value cannot be lower than minimum value!");
+ } else if (d0 > d2) {
+ throw new IllegalArgumentException("Default value cannot be bigger than maximum value!");
+ }
+ }
+
+ public AttributeRanged a(String s) {
+ this.c = s;
+ return this;
+ }
+
+ public String f() {
+ return this.c;
+ }
+
+ public double a(double d0) {
+ if (d0 < this.a) {
+ d0 = this.a;
+ }
+
+ if (d0 > this.b) {
+ d0 = this.b;
+ }
+
+ return d0;
+ }
+}
diff --git a/src/main/java/net/minecraft/server/BanEntrySerializer.java b/src/main/java/net/minecraft/server/BanEntrySerializer.java
new file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
@ -1347,6 +1395,117 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+ }
+}
diff --git a/src/main/java/net/minecraft/server/GenericAttributes.java b/src/main/java/net/minecraft/server/GenericAttributes.java
new file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
--- /dev/null
+++ b/src/main/java/net/minecraft/server/GenericAttributes.java
@@ -0,0 +0,0 @@
+package net.minecraft.server;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.UUID;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+public class GenericAttributes {
+
+ private static final Logger f = LogManager.getLogger();
+ public static final IAttribute maxHealth = (new AttributeRanged("generic.maxHealth", 20.0D, 0.0D, Double.MAX_VALUE)).a("Max Health").a(true);
+ public static final IAttribute b = (new AttributeRanged("generic.followRange", 32.0D, 0.0D, 2048.0D)).a("Follow Range");
+ public static final IAttribute c = (new AttributeRanged("generic.knockbackResistance", 0.0D, 0.0D, 1.0D)).a("Knockback Resistance");
+ public static final IAttribute d = (new AttributeRanged("generic.movementSpeed", 0.699999988079071D, 0.0D, Double.MAX_VALUE)).a("Movement Speed").a(true);
+ public static final IAttribute e = new AttributeRanged("generic.attackDamage", 2.0D, 0.0D, Double.MAX_VALUE);
+
+ public static NBTTagList a(AttributeMapBase attributemapbase) {
+ NBTTagList nbttaglist = new NBTTagList();
+ Iterator iterator = attributemapbase.a().iterator();
+
+ while (iterator.hasNext()) {
+ AttributeInstance attributeinstance = (AttributeInstance) iterator.next();
+
+ nbttaglist.add(a(attributeinstance));
+ }
+
+ return nbttaglist;
+ }
+
+ private static NBTTagCompound a(AttributeInstance attributeinstance) {
+ NBTTagCompound nbttagcompound = new NBTTagCompound();
+ IAttribute iattribute = attributeinstance.getAttribute();
+
+ nbttagcompound.setString("Name", iattribute.getName());
+ nbttagcompound.setDouble("Base", attributeinstance.b());
+ Collection collection = attributeinstance.c();
+
+ if (collection != null && !collection.isEmpty()) {
+ NBTTagList nbttaglist = new NBTTagList();
+ Iterator iterator = collection.iterator();
+
+ while (iterator.hasNext()) {
+ AttributeModifier attributemodifier = (AttributeModifier) iterator.next();
+
+ if (attributemodifier.e()) {
+ nbttaglist.add(a(attributemodifier));
+ }
+ }
+
+ nbttagcompound.set("Modifiers", nbttaglist);
+ }
+
+ return nbttagcompound;
+ }
+
+ private static NBTTagCompound a(AttributeModifier attributemodifier) {
+ NBTTagCompound nbttagcompound = new NBTTagCompound();
+
+ nbttagcompound.setString("Name", attributemodifier.b());
+ nbttagcompound.setDouble("Amount", attributemodifier.d());
+ nbttagcompound.setInt("Operation", attributemodifier.c());
+ nbttagcompound.setLong("UUIDMost", attributemodifier.a().getMostSignificantBits());
+ nbttagcompound.setLong("UUIDLeast", attributemodifier.a().getLeastSignificantBits());
+ return nbttagcompound;
+ }
+
+ public static void a(AttributeMapBase attributemapbase, NBTTagList nbttaglist) {
+ for (int i = 0; i < nbttaglist.size(); ++i) {
+ NBTTagCompound nbttagcompound = nbttaglist.get(i);
+ AttributeInstance attributeinstance = attributemapbase.a(nbttagcompound.getString("Name"));
+
+ if (attributeinstance != null) {
+ a(attributeinstance, nbttagcompound);
+ } else {
+ f.warn("Ignoring unknown attribute \'" + nbttagcompound.getString("Name") + "\'");
+ }
+ }
+ }
+
+ private static void a(AttributeInstance attributeinstance, NBTTagCompound nbttagcompound) {
+ attributeinstance.setValue(nbttagcompound.getDouble("Base"));
+ if (nbttagcompound.hasKeyOfType("Modifiers", 9)) {
+ NBTTagList nbttaglist = nbttagcompound.getList("Modifiers", 10);
+
+ for (int i = 0; i < nbttaglist.size(); ++i) {
+ AttributeModifier attributemodifier = a(nbttaglist.get(i));
+ AttributeModifier attributemodifier1 = attributeinstance.a(attributemodifier.a());
+
+ if (attributemodifier1 != null) {
+ attributeinstance.b(attributemodifier1);
+ }
+
+ attributeinstance.a(attributemodifier);
+ }
+ }
+ }
+
+ public static AttributeModifier a(NBTTagCompound nbttagcompound) {
+ UUID uuid = new UUID(nbttagcompound.getLong("UUIDMost"), nbttagcompound.getLong("UUIDLeast"));
+
+ return new AttributeModifier(uuid, nbttagcompound.getString("Name"), nbttagcompound.getDouble("Amount"), nbttagcompound.getInt("Operation"));
+ }
+}
diff --git a/src/main/java/net/minecraft/server/IntCache.java b/src/main/java/net/minecraft/server/IntCache.java
new file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000

View file

@ -0,0 +1,73 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
Date: Mon, 28 Jul 2014 16:55:51 +1000
Subject: [PATCH] Allow Attribute Capping.
Apply some sensible defaults and allow server owners to customize the maximum values of selected common attributes.
diff --git a/src/main/java/net/minecraft/server/AttributeRanged.java b/src/main/java/net/minecraft/server/AttributeRanged.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/AttributeRanged.java
+++ b/src/main/java/net/minecraft/server/AttributeRanged.java
@@ -0,0 +0,0 @@ package net.minecraft.server;
public class AttributeRanged extends AttributeBase {
private final double a;
- private final double b;
+ public double b; // Spigot
private String c;
public AttributeRanged(String s, double d0, double d1, double d2) {
diff --git a/src/main/java/net/minecraft/server/GenericAttributes.java b/src/main/java/net/minecraft/server/GenericAttributes.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/GenericAttributes.java
+++ b/src/main/java/net/minecraft/server/GenericAttributes.java
@@ -0,0 +0,0 @@ import org.apache.logging.log4j.Logger;
public class GenericAttributes {
private static final Logger f = LogManager.getLogger();
- public static final IAttribute maxHealth = (new AttributeRanged("generic.maxHealth", 20.0D, 0.0D, Double.MAX_VALUE)).a("Max Health").a(true);
+ // Spigot Start
+ public static final IAttribute maxHealth = (new AttributeRanged("generic.maxHealth", 20.0D, 0.0D, org.spigotmc.SpigotConfig.maxHealth)).a("Max Health").a(true);
public static final IAttribute b = (new AttributeRanged("generic.followRange", 32.0D, 0.0D, 2048.0D)).a("Follow Range");
public static final IAttribute c = (new AttributeRanged("generic.knockbackResistance", 0.0D, 0.0D, 1.0D)).a("Knockback Resistance");
- public static final IAttribute d = (new AttributeRanged("generic.movementSpeed", 0.699999988079071D, 0.0D, Double.MAX_VALUE)).a("Movement Speed").a(true);
- public static final IAttribute e = new AttributeRanged("generic.attackDamage", 2.0D, 0.0D, Double.MAX_VALUE);
+ public static final IAttribute d = (new AttributeRanged("generic.movementSpeed", 0.699999988079071D, 0.0D, org.spigotmc.SpigotConfig.movementSpeed)).a("Movement Speed").a(true);
+ public static final IAttribute e = new AttributeRanged("generic.attackDamage", 2.0D, 0.0D, org.spigotmc.SpigotConfig.attackDamage);
+ // Spigot End
public static NBTTagList a(AttributeMapBase attributemapbase) {
NBTTagList nbttaglist = new NBTTagList();
diff --git a/src/main/java/org/spigotmc/SpigotConfig.java b/src/main/java/org/spigotmc/SpigotConfig.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/spigotmc/SpigotConfig.java
+++ b/src/main/java/org/spigotmc/SpigotConfig.java
@@ -0,0 +0,0 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
+import net.minecraft.server.AttributeRanged;
+import net.minecraft.server.GenericAttributes;
import net.minecraft.util.gnu.trove.map.hash.TObjectIntHashMap;
import net.minecraft.server.MinecraftServer;
import org.bukkit.Bukkit;
@@ -0,0 +0,0 @@ public class SpigotConfig
{
movedTooQuicklyThreshold = getDouble( "settings.moved-too-quickly-threshold", 100.0D );
}
+
+ public static double maxHealth = 2048;
+ public static double movementSpeed = 2048;
+ public static double attackDamage = 2048;
+ private static void attributeMaxes()
+ {
+ maxHealth = getDouble( "settings.attribute.maxHealth.max", maxHealth );
+ ( (AttributeRanged) GenericAttributes.maxHealth ).b = maxHealth;
+ movementSpeed = getDouble( "settings.attribute.movementSpeed.max", movementSpeed );
+ ( (AttributeRanged) GenericAttributes.d ).b = movementSpeed;
+ attackDamage = getDouble( "settings.attribute.attackDamage.max", attackDamage );
+ ( (AttributeRanged) GenericAttributes.e ).b = attackDamage;
+ }
}
--