Archiviert
13
0

Improve the Saddle API for Horses

Not all horses with Saddles have armor. This lets us break up the horses with saddles
and access their saddle state separately from an interface shared with Armor.
Dieser Commit ist enthalten in:
Aikar 2017-07-26 23:31:58 -04:00
Ursprung 6177f2d61e
Commit 4a35e438e9
2 geänderte Dateien mit 185 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,98 @@
From 756079e8a09b2663c5969682a4afce4db5d74672 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sat, 10 Dec 2016 16:12:48 -0500
Subject: [PATCH] Improve the Saddle API for Horses
Not all horses with Saddles have armor. This lets us break up the horses with saddles
and access their saddle state separately from an interface shared with Armor.
diff --git a/src/main/java/org/bukkit/inventory/ArmoredHorseInventory.java b/src/main/java/org/bukkit/inventory/ArmoredHorseInventory.java
new file mode 100644
index 00000000..037479de
--- /dev/null
+++ b/src/main/java/org/bukkit/inventory/ArmoredHorseInventory.java
@@ -0,0 +1,18 @@
+package org.bukkit.inventory;
+
+public interface ArmoredHorseInventory extends Inventory {
+
+ /**
+ * Gets the item in the horse's armor slot.
+ *
+ * @return the armor item
+ */
+ ItemStack getArmor();
+
+ /**
+ * Sets the item in the horse's armor slot.
+ *
+ * @param stack the new item
+ */
+ void setArmor(ItemStack stack);
+}
diff --git a/src/main/java/org/bukkit/inventory/HorseInventory.java b/src/main/java/org/bukkit/inventory/HorseInventory.java
index a71efb83..b4b95ab5 100644
--- a/src/main/java/org/bukkit/inventory/HorseInventory.java
+++ b/src/main/java/org/bukkit/inventory/HorseInventory.java
@@ -3,33 +3,4 @@ package org.bukkit.inventory;
/**
* An interface to the inventory of a Horse.
*/
-public interface HorseInventory extends Inventory {
-
- /**
- * Gets the item in the horse's saddle slot.
- *
- * @return the saddle item
- */
- ItemStack getSaddle();
-
- /**
- * Gets the item in the horse's armor slot.
- *
- * @return the armor item
- */
- ItemStack getArmor();
-
- /**
- * Sets the item in the horse's saddle slot.
- *
- * @param stack the new item
- */
- void setSaddle(ItemStack stack);
-
- /**
- * Sets the item in the horse's armor slot.
- *
- * @param stack the new item
- */
- void setArmor(ItemStack stack);
-}
+public interface HorseInventory extends ArmoredHorseInventory, SaddledHorseInventory {}
diff --git a/src/main/java/org/bukkit/inventory/SaddledHorseInventory.java b/src/main/java/org/bukkit/inventory/SaddledHorseInventory.java
new file mode 100644
index 00000000..010dc364
--- /dev/null
+++ b/src/main/java/org/bukkit/inventory/SaddledHorseInventory.java
@@ -0,0 +1,18 @@
+package org.bukkit.inventory;
+
+public interface SaddledHorseInventory {
+
+ /**
+ * Gets the item in the horse's saddle slot.
+ *
+ * @return the saddle item
+ */
+ ItemStack getSaddle();
+
+ /**
+ * Sets the item in the horse's saddle slot.
+ *
+ * @param stack the new item
+ */
+ void setSaddle(ItemStack stack);
+}
--
2.13.0

Datei anzeigen

@ -0,0 +1,87 @@
From cbcc37ea2b8c2ff4540e10299720dae5683e0364 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sat, 10 Dec 2016 16:24:06 -0500
Subject: [PATCH] Improve the Saddle API for Horses
Not all horses with Saddles have armor. This lets us break up the horses with saddles
and access their saddle state separately from an interface shared with Armor.
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractHorse.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractHorse.java
index 62c7d44c7..64d75459a 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractHorse.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractHorse.java
@@ -6,6 +6,7 @@ import net.minecraft.server.EntityHorseAbstract;
import org.apache.commons.lang.Validate;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.inventory.CraftInventory;
+import org.bukkit.craftbukkit.inventory.CraftSaddledInventory;
import org.bukkit.entity.AbstractHorse;
import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.Horse;
@@ -92,6 +93,6 @@ public abstract class CraftAbstractHorse extends CraftAnimals implements Abstrac
@Override
public Inventory getInventory() {
- return new CraftInventory(getHandle().inventoryChest);
+ return new CraftSaddledInventory(getHandle().inventoryChest);
}
}
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryHorse.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryHorse.java
index 5adbd7437..2f6852404 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryHorse.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryHorse.java
@@ -4,24 +4,16 @@ import net.minecraft.server.IInventory;
import org.bukkit.inventory.HorseInventory;
import org.bukkit.inventory.ItemStack;
-public class CraftInventoryHorse extends CraftInventory implements HorseInventory {
+public class CraftInventoryHorse extends CraftSaddledInventory implements HorseInventory {
public CraftInventoryHorse(IInventory inventory) {
super(inventory);
}
- public ItemStack getSaddle() {
- return getItem(0);
- }
-
public ItemStack getArmor() {
return getItem(1);
}
- public void setSaddle(ItemStack stack) {
- setItem(0, stack);
- }
-
public void setArmor(ItemStack stack) {
setItem(1, stack);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftSaddledInventory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftSaddledInventory.java
new file mode 100644
index 000000000..615010c40
--- /dev/null
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftSaddledInventory.java
@@ -0,0 +1,20 @@
+package org.bukkit.craftbukkit.inventory;
+
+import net.minecraft.server.IInventory;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.SaddledHorseInventory;
+
+public class CraftSaddledInventory extends CraftInventory implements SaddledHorseInventory {
+
+ public CraftSaddledInventory(IInventory inventory) {
+ super(inventory);
+ }
+
+ public ItemStack getSaddle() {
+ return getItem(0);
+ }
+
+ public void setSaddle(ItemStack stack) {
+ setItem(0, stack);
+ }
+}
--
2.13.0