Initial commit (Forge 1291).
This commit is contained in:
@ -0,0 +1,21 @@
|
||||
--- ../src-base/minecraft/org/bukkit/event/entity/EntityDamageByBlockEvent.java
|
||||
+++ ../src-work/minecraft/org/bukkit/event/entity/EntityDamageByBlockEvent.java
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
+import com.google.common.base.Function;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
@@ -22,8 +23,8 @@
|
||||
this.damager = damager;
|
||||
}
|
||||
|
||||
- public EntityDamageByBlockEvent(final Block damager, final Entity damagee, final DamageCause cause, final Map<DamageModifier, Double> modifiers) {
|
||||
- super(damagee, cause, modifiers);
|
||||
+ public EntityDamageByBlockEvent(final Block damager, final Entity damagee, final DamageCause cause, final Map<DamageModifier, Double> modifiers, final Map<DamageModifier, ? extends Function<? super Double, Double>> modifierFunctions) {
|
||||
+ super(damagee, cause, modifiers, modifierFunctions);
|
||||
this.damager = damager;
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
--- ../src-base/minecraft/org/bukkit/event/entity/EntityDamageByEntityEvent.java
|
||||
+++ ../src-work/minecraft/org/bukkit/event/entity/EntityDamageByEntityEvent.java
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
+import com.google.common.base.Function;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
/**
|
||||
@@ -21,8 +22,8 @@
|
||||
this.damager = damager;
|
||||
}
|
||||
|
||||
- public EntityDamageByEntityEvent(final Entity damager, final Entity damagee, final DamageCause cause, final Map<DamageModifier, Double> modifiers) {
|
||||
- super(damagee, cause, modifiers);
|
||||
+ public EntityDamageByEntityEvent(final Entity damager, final Entity damagee, final DamageCause cause, final Map<DamageModifier, Double> modifiers, final Map<DamageModifier, ? extends Function<? super Double, Double>> modifierFunctions) {
|
||||
+ super(damagee, cause, modifiers, modifierFunctions);
|
||||
this.damager = damager;
|
||||
}
|
||||
|
85
patches/org/bukkit/event/entity/EntityDamageEvent.java.patch
Normal file
85
patches/org/bukkit/event/entity/EntityDamageEvent.java.patch
Normal file
@ -0,0 +1,85 @@
|
||||
--- ../src-base/minecraft/org/bukkit/event/entity/EntityDamageEvent.java
|
||||
+++ ../src-work/minecraft/org/bukkit/event/entity/EntityDamageEvent.java
|
||||
@@ -10,6 +10,8 @@
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.util.NumberConversions;
|
||||
|
||||
+import com.google.common.base.Function;
|
||||
+import com.google.common.base.Functions;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
@@ -18,7 +20,9 @@
|
||||
public class EntityDamageEvent extends EntityEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private static final DamageModifier[] MODIFIERS = DamageModifier.values();
|
||||
+ private static final Function<? super Double, Double> ZERO = Functions.constant(-0.0);
|
||||
private final Map<DamageModifier, Double> modifiers;
|
||||
+ private final Map<DamageModifier, ? extends Function<? super Double, Double>> modifierFunctions;
|
||||
private final Map<DamageModifier, Double> originals;
|
||||
private boolean cancelled;
|
||||
private final DamageCause cause;
|
||||
@@ -30,16 +34,20 @@
|
||||
|
||||
@Deprecated
|
||||
public EntityDamageEvent(final Entity damagee, final DamageCause cause, final double damage) {
|
||||
- this(damagee, cause, new EnumMap<DamageModifier, Double>(ImmutableMap.of(DamageModifier.BASE, damage)));
|
||||
+ this(damagee, cause, new EnumMap<DamageModifier, Double>(ImmutableMap.of(DamageModifier.BASE, damage)), new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, ZERO)));
|
||||
}
|
||||
|
||||
- public EntityDamageEvent(final Entity damagee, final DamageCause cause, final Map<DamageModifier, Double> modifiers) {
|
||||
+ public EntityDamageEvent(final Entity damagee, final DamageCause cause, final Map<DamageModifier, Double> modifiers, final Map<DamageModifier, ? extends Function<? super Double, Double>> modifierFunctions) {
|
||||
super(damagee);
|
||||
Validate.isTrue(modifiers.containsKey(DamageModifier.BASE), "BASE DamageModifier missing");
|
||||
Validate.isTrue(!modifiers.containsKey(null), "Cannot have null DamageModifier");
|
||||
+ Validate.noNullElements(modifiers.values(), "Cannot have null modifier values");
|
||||
+ Validate.isTrue(modifiers.keySet().equals(modifierFunctions.keySet()), "Must have a modifier function for each DamageModifier");
|
||||
+ Validate.noNullElements(modifierFunctions.values(), "Cannot have null modifier function");
|
||||
this.originals = new EnumMap<DamageModifier, Double>(modifiers);
|
||||
this.cause = cause;
|
||||
this.modifiers = modifiers;
|
||||
+ this.modifierFunctions = modifierFunctions;
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
@@ -149,11 +157,39 @@
|
||||
}
|
||||
|
||||
/**
|
||||
- * Sets the raw amount of damage caused by the event
|
||||
+ * Sets the raw amount of damage caused by the event.
|
||||
+ * <p>
|
||||
+ * For compatibility this also recalculates the modifiers and scales
|
||||
+ * them by the difference between the modifier for the previous damage
|
||||
+ * value and the new one.
|
||||
*
|
||||
* @param damage The raw amount of damage caused by the event
|
||||
*/
|
||||
public void setDamage(double damage) {
|
||||
+ // These have to happen in the same order as the server calculates them, keep the enum sorted
|
||||
+ double remaining = damage;
|
||||
+ double oldRemaining = getDamage(DamageModifier.BASE);
|
||||
+ for (DamageModifier modifier : MODIFIERS) {
|
||||
+ if (!isApplicable(modifier)) {
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+ Function<? super Double, Double> modifierFunction = modifierFunctions.get(modifier);
|
||||
+ double newVanilla = modifierFunction.apply(remaining);
|
||||
+ double oldVanilla = modifierFunction.apply(oldRemaining);
|
||||
+ double difference = oldVanilla - newVanilla;
|
||||
+
|
||||
+ // Don't allow value to cross zero, assume zero values should be negative
|
||||
+ double old = getDamage(modifier);
|
||||
+ if (old > 0) {
|
||||
+ setDamage(modifier, Math.max(0, old - difference));
|
||||
+ } else {
|
||||
+ setDamage(modifier, Math.min(0, old - difference));
|
||||
+ }
|
||||
+ remaining += newVanilla;
|
||||
+ oldRemaining += oldVanilla;
|
||||
+ }
|
||||
+
|
||||
setDamage(DamageModifier.BASE, damage);
|
||||
}
|
||||
|
66
patches/org/bukkit/event/player/PlayerLoginEvent.java.patch
Normal file
66
patches/org/bukkit/event/player/PlayerLoginEvent.java.patch
Normal file
@ -0,0 +1,66 @@
|
||||
--- ../src-base/minecraft/org/bukkit/event/player/PlayerLoginEvent.java
|
||||
+++ ../src-work/minecraft/org/bukkit/event/player/PlayerLoginEvent.java
|
||||
@@ -14,6 +14,7 @@
|
||||
private final String hostname;
|
||||
private Result result = Result.ALLOWED;
|
||||
private String message = "";
|
||||
+ private final InetAddress realAddress; // Spigot
|
||||
|
||||
/**
|
||||
* @deprecated Address should be provided in other constructor
|
||||
@@ -40,19 +41,26 @@
|
||||
* @param address The address the player used to connect, provided for
|
||||
* timing issues
|
||||
*/
|
||||
- public PlayerLoginEvent(final Player player, final String hostname, final InetAddress address) {
|
||||
+ public PlayerLoginEvent(final Player player, final String hostname, final InetAddress address, final InetAddress realAddress) { // Spigot
|
||||
super(player);
|
||||
this.hostname = hostname;
|
||||
this.address = address;
|
||||
+ // Spigot start
|
||||
+ this.realAddress = address;
|
||||
}
|
||||
|
||||
+ public PlayerLoginEvent(final Player player, final String hostname, final InetAddress address) {
|
||||
+ this(player, hostname, address, address);
|
||||
+ // Spigot end
|
||||
+ }
|
||||
+
|
||||
/**
|
||||
* @deprecated Address and hostname should be provided in other
|
||||
* constructor
|
||||
*/
|
||||
@Deprecated
|
||||
public PlayerLoginEvent(final Player player, final Result result, final String message) {
|
||||
- this(player, "", null, result, message);
|
||||
+ this(player, "", null, result, message, null); // Spigot
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,13 +73,24 @@
|
||||
* @param result The result status for this event
|
||||
* @param message The message to be displayed if result denies login
|
||||
*/
|
||||
- public PlayerLoginEvent(final Player player, String hostname, final InetAddress address, final Result result, final String message) {
|
||||
- this(player, hostname, address);
|
||||
+ public PlayerLoginEvent(final Player player, String hostname, final InetAddress address, final Result result, final String message, final InetAddress realAddress) { // Spigot
|
||||
+ this(player, hostname, address, realAddress); // Spigot
|
||||
this.result = result;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
+ // Spigot start
|
||||
/**
|
||||
+ * Gets the connection address of this player, regardless of whether it has been spoofed or not.
|
||||
+ *
|
||||
+ * @return the player's connection address
|
||||
+ */
|
||||
+ public InetAddress getRealAddress() {
|
||||
+ return realAddress;
|
||||
+ }
|
||||
+ // Spigot end
|
||||
+
|
||||
+ /**
|
||||
* Gets the current result of the login, as an enum
|
||||
*
|
||||
* @return Current Result of the login
|
@ -0,0 +1,17 @@
|
||||
--- ../src-base/minecraft/org/bukkit/event/player/PlayerTeleportEvent.java
|
||||
+++ ../src-work/minecraft/org/bukkit/event/player/PlayerTeleportEvent.java
|
||||
@@ -55,7 +55,14 @@
|
||||
* portal
|
||||
*/
|
||||
END_PORTAL,
|
||||
+ // Cauldron start - added cause for mods
|
||||
/**
|
||||
+ * Indicates the teleportation was caused by a player entering a
|
||||
+ * Mod portal
|
||||
+ */
|
||||
+ MOD,
|
||||
+ // Cauldron end
|
||||
+ /**
|
||||
* Indicates the teleportation was caused by an event not covered by
|
||||
* this enum
|
||||
*/
|
Reference in New Issue
Block a user