mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-18 08:36:13 +01:00
cab333b217
Don't send requests of every player was found in the global api cache SpigotMC/Spigot@841270ff1e Correctly set the response code for the cached lookups and return the ... SpigotMC/Spigot@f170b7899c Don't try and re-set the global api cache on reload SpigotMC/Spigot@b410a00a66 Use a compile time sneaky throw hack. SpigotMC/Spigot@508462b96b Fix a missed rename in WorldGenGroundBush SpigotMC/Spigot@0614d8fae9
148 lines
6.8 KiB
Diff
148 lines
6.8 KiB
Diff
From 6b1a86ec8fd19b77d214b882ddd1793ce76fc3ca Mon Sep 17 00:00:00 2001
|
|
From: Thinkofdeath <thinkofdeath@spigotmc.org>
|
|
Date: Thu, 31 Jul 2014 17:48:20 +0100
|
|
Subject: [PATCH] Filter attribute modifiers which cause the attribute to go
|
|
out of its range
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
index ec37524..bcde85c 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
@@ -38,6 +38,8 @@ import com.google.common.collect.ImmutableMap;
|
|
|
|
// Spigot start
|
|
import static org.spigotmc.ValidateUtils.*;
|
|
+import net.minecraft.server.GenericAttributes;
|
|
+import net.minecraft.server.IAttribute;
|
|
// Spigot end
|
|
|
|
/**
|
|
@@ -256,6 +258,123 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|
NBTTagList save = null;
|
|
NBTTagList nbttaglist = tag.getList(ATTRIBUTES.NBT, 10);
|
|
|
|
+ // Spigot start
|
|
+ net.minecraft.util.gnu.trove.map.hash.TObjectDoubleHashMap<String> attributeTracker = new net.minecraft.util.gnu.trove.map.hash.TObjectDoubleHashMap<String>();
|
|
+ net.minecraft.util.gnu.trove.map.hash.TObjectDoubleHashMap<String> attributeTrackerX = new net.minecraft.util.gnu.trove.map.hash.TObjectDoubleHashMap<String>();
|
|
+ Map<String, IAttribute> attributesByName = new HashMap<String, IAttribute>();
|
|
+ attributeTracker.put( "generic.maxHealth", 20.0 );
|
|
+ attributesByName.put( "generic.maxHealth", GenericAttributes.maxHealth );
|
|
+ attributeTracker.put( "generic.followRange", 32.0 );
|
|
+ attributesByName.put( "generic.followRange", GenericAttributes.b );
|
|
+ attributeTracker.put( "generic.knockbackResistance", 0.0 );
|
|
+ attributesByName.put( "generic.knockbackResistance", GenericAttributes.c );
|
|
+ attributeTracker.put( "generic.movementSpeed", 0.7 );
|
|
+ attributesByName.put( "generic.movementSpeed", GenericAttributes.d );
|
|
+ attributeTracker.put( "generic.attackDamage", 1.0 );
|
|
+ attributesByName.put( "generic.attackDamage", GenericAttributes.e );
|
|
+ NBTTagList oldList = nbttaglist;
|
|
+ nbttaglist = new NBTTagList();
|
|
+
|
|
+ List<NBTTagCompound> op0 = new ArrayList<NBTTagCompound>();
|
|
+ List<NBTTagCompound> op1 = new ArrayList<NBTTagCompound>();
|
|
+ List<NBTTagCompound> op2 = new ArrayList<NBTTagCompound>();
|
|
+
|
|
+ for ( int i = 0; i < oldList.size(); ++i )
|
|
+ {
|
|
+ NBTTagCompound nbttagcompound = oldList.get( i );
|
|
+ if ( nbttagcompound == null ) continue;
|
|
+
|
|
+ if ( !( nbttagcompound.get( ATTRIBUTES_UUID_HIGH.NBT ) instanceof NBTTagLong ) )
|
|
+ {
|
|
+ continue;
|
|
+ }
|
|
+ if ( !( nbttagcompound.get( ATTRIBUTES_UUID_LOW.NBT ) instanceof NBTTagLong ) )
|
|
+ {
|
|
+ continue;
|
|
+ }
|
|
+ if ( !( nbttagcompound.get( ATTRIBUTES_IDENTIFIER.NBT ) instanceof NBTTagString ) || !CraftItemFactory.KNOWN_NBT_ATTRIBUTE_NAMES.contains( nbttagcompound.getString( ATTRIBUTES_IDENTIFIER.NBT ) ) )
|
|
+ {
|
|
+ continue;
|
|
+ }
|
|
+ if ( !( nbttagcompound.get( ATTRIBUTES_NAME.NBT ) instanceof NBTTagString ) || nbttagcompound.getString( ATTRIBUTES_NAME.NBT ).isEmpty() )
|
|
+ {
|
|
+ continue;
|
|
+ }
|
|
+ if ( !( nbttagcompound.get( ATTRIBUTES_VALUE.NBT ) instanceof NBTTagDouble ) )
|
|
+ {
|
|
+ continue;
|
|
+ }
|
|
+ if ( !( nbttagcompound.get( ATTRIBUTES_TYPE.NBT ) instanceof NBTTagInt ) || nbttagcompound.getInt( ATTRIBUTES_TYPE.NBT ) < 0 || nbttagcompound.getInt( ATTRIBUTES_TYPE.NBT ) > 2 )
|
|
+ {
|
|
+ continue;
|
|
+ }
|
|
+
|
|
+ switch ( nbttagcompound.getInt( ATTRIBUTES_TYPE.NBT ) )
|
|
+ {
|
|
+ case 0:
|
|
+ op0.add( nbttagcompound );
|
|
+ break;
|
|
+ case 1:
|
|
+ op1.add( nbttagcompound );
|
|
+ break;
|
|
+ case 2:
|
|
+ op2.add( nbttagcompound );
|
|
+ break;
|
|
+ }
|
|
+ }
|
|
+ for ( NBTTagCompound nbtTagCompound : op0 )
|
|
+ {
|
|
+ String name = nbtTagCompound.getString( ATTRIBUTES_IDENTIFIER.NBT );
|
|
+ if ( attributeTracker.containsKey( name ) )
|
|
+ {
|
|
+ double val = attributeTracker.get( name );
|
|
+ val += nbtTagCompound.getDouble( ATTRIBUTES_VALUE.NBT );
|
|
+ if ( val != attributesByName.get( name ).a( val ) )
|
|
+ {
|
|
+ continue;
|
|
+ }
|
|
+ attributeTracker.put( name, val );
|
|
+ }
|
|
+ nbttaglist.add( nbtTagCompound );
|
|
+ }
|
|
+ for ( String name : attributeTracker.keySet() )
|
|
+ {
|
|
+ attributeTrackerX.put( name, attributeTracker.get( name ) );
|
|
+ }
|
|
+ for ( NBTTagCompound nbtTagCompound : op1 )
|
|
+ {
|
|
+ String name = nbtTagCompound.getString( ATTRIBUTES_IDENTIFIER.NBT );
|
|
+ if ( attributeTracker.containsKey( name ) )
|
|
+ {
|
|
+ double val = attributeTracker.get( name );
|
|
+ double valX = attributeTrackerX.get( name );
|
|
+ val += valX * nbtTagCompound.getDouble( ATTRIBUTES_VALUE.NBT );
|
|
+ if ( val != attributesByName.get( name ).a( val ) )
|
|
+ {
|
|
+ continue;
|
|
+ }
|
|
+ attributeTracker.put( name, val );
|
|
+ }
|
|
+ nbttaglist.add( nbtTagCompound );
|
|
+ }
|
|
+ for ( NBTTagCompound nbtTagCompound : op2 )
|
|
+ {
|
|
+ String name = nbtTagCompound.getString( ATTRIBUTES_IDENTIFIER.NBT );
|
|
+ if ( attributeTracker.containsKey( name ) )
|
|
+ {
|
|
+ double val = attributeTracker.get( name );
|
|
+ val += val * nbtTagCompound.getDouble( ATTRIBUTES_VALUE.NBT );
|
|
+ if ( val != attributesByName.get( name ).a( val ) )
|
|
+ {
|
|
+ continue;
|
|
+ }
|
|
+ attributeTracker.put( name, val );
|
|
+ }
|
|
+ nbttaglist.add( nbtTagCompound );
|
|
+ }
|
|
+
|
|
+ // Spigot end
|
|
+
|
|
for (int i = 0; i < nbttaglist.size(); ++i) {
|
|
if (!(nbttaglist.get(i) instanceof NBTTagCompound)) {
|
|
continue;
|
|
--
|
|
1.9.1
|
|
|