Mitigate spigot issue when setting wolf owner
This fixes the Summon Wolves spell in Wizards. Explanation: - Wolves keep track of their most recent owner. - When a wolf is assigned a new owner, it updates the data watcher with the new owner's UUID - During this process, the old owner's UUID is checked against the new one - If the wolf didn't have a previous owner, the old owner's UUID is the empty string. - UUID.fromString() is called on the empty string, and throws an exception.
This commit is contained in:
parent
4477a215f4
commit
bda9772ba6
@ -4,6 +4,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import com.google.common.base.Optional;
|
||||||
import mineplex.core.common.util.UtilBlock;
|
import mineplex.core.common.util.UtilBlock;
|
||||||
import mineplex.core.common.util.UtilParticle;
|
import mineplex.core.common.util.UtilParticle;
|
||||||
import mineplex.core.common.util.UtilServer;
|
import mineplex.core.common.util.UtilServer;
|
||||||
@ -16,17 +17,15 @@ import nautilus.game.arcade.game.games.wizards.Spell;
|
|||||||
import nautilus.game.arcade.game.games.wizards.spellinterfaces.SpellClick;
|
import nautilus.game.arcade.game.games.wizards.spellinterfaces.SpellClick;
|
||||||
import nautilus.game.arcade.game.games.wizards.spellinterfaces.SpellClickBlock;
|
import nautilus.game.arcade.game.games.wizards.spellinterfaces.SpellClickBlock;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_8_R3.EntityWolf;
|
||||||
import org.bukkit.DyeColor;
|
import org.bukkit.DyeColor;
|
||||||
import org.bukkit.Effect;
|
import org.bukkit.Effect;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.entity.AnimalTamer;
|
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftWolf;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.*;
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.entity.Wolf;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
|
||||||
public class SpellSummonWolves extends Spell implements SpellClick, SpellClickBlock
|
public class SpellSummonWolves extends Spell implements SpellClick, SpellClickBlock
|
||||||
@ -57,6 +56,7 @@ public class SpellSummonWolves extends Spell implements SpellClick, SpellClickBl
|
|||||||
|
|
||||||
wolf.setCollarColor(DyeColor.YELLOW);
|
wolf.setCollarColor(DyeColor.YELLOW);
|
||||||
wolf.setTamed(true);
|
wolf.setTamed(true);
|
||||||
|
setOldOwner_ReplaceMeWhenSpigotFixesThis(wolf, player);
|
||||||
wolf.setOwner(player);
|
wolf.setOwner(player);
|
||||||
wolf.setBreed(false);
|
wolf.setBreed(false);
|
||||||
wolf.setCustomName(player.getDisplayName() + "'s Wolf");
|
wolf.setCustomName(player.getDisplayName() + "'s Wolf");
|
||||||
@ -73,6 +73,24 @@ public class SpellSummonWolves extends Spell implements SpellClick, SpellClickBl
|
|||||||
charge(player);
|
charge(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Explanation:
|
||||||
|
// - Wolves keep track of their most recent owner.
|
||||||
|
// - When a wolf is assigned a new owner, it updates the data watcher
|
||||||
|
// with the new owner's UUID
|
||||||
|
// - During this process, the old owner's UUID is checked against
|
||||||
|
// the new one
|
||||||
|
// - If the wolf didn't have a previous owner, the old owner's UUID
|
||||||
|
// is the empty string.
|
||||||
|
// - UUID.fromString() is called on the empty string, and throws
|
||||||
|
// an exception.
|
||||||
|
//
|
||||||
|
// We mitigate the issue by manually setting the old owner's UUID
|
||||||
|
// to that of the player.
|
||||||
|
private void setOldOwner_ReplaceMeWhenSpigotFixesThis(Wolf wolf, Player player)
|
||||||
|
{
|
||||||
|
((CraftWolf)wolf).getHandle().getDataWatcher().watch(17, player.getUniqueId().toString(), EntityWolf.META_OWNER, Optional.absent());
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onDamage(CustomDamageEvent event)
|
public void onDamage(CustomDamageEvent event)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user