-
-
Notifications
You must be signed in to change notification settings - Fork 995
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor spawn egg provider to separate classes
- Loading branch information
Showing
10 changed files
with
107 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
package net.ess3.api; | ||
|
||
import net.ess3.nms.SpawnEggProvider; | ||
|
||
public interface IEssentials extends com.earth2me.essentials.IEssentials { | ||
|
||
SpawnEggProvider getSpawnEggProvider(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
nms/1_9_R1Provider/src/net/ess3/nms/v1_9_R1/v1_9_R1SpawnEggProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package net.ess3.nms.v1_9_R1; | ||
|
||
import net.ess3.nms.SpawnEggProvider; | ||
import net.ess3.nms.v1_9_R1.nms.SpawnEgg1_9; | ||
import org.bukkit.entity.EntityType; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
public class v1_9_R1SpawnEggProvider extends SpawnEggProvider { | ||
@Override | ||
public ItemStack createEggItem(EntityType type) throws IllegalArgumentException { | ||
return new SpawnEgg1_9(type).toItemStack(); | ||
} | ||
|
||
@Override | ||
public EntityType getSpawnedType(ItemStack eggItem) throws IllegalArgumentException { | ||
return SpawnEgg1_9.fromItemStack(eggItem).getSpawnedType(); | ||
} | ||
|
||
@Override | ||
public String getHumanName() { | ||
return "CraftBukkit 1.9 NMS-based provider"; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
nms/LegacyProvider/src/net/ess3/nms/legacy/LegacySpawnEggProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package net.ess3.nms.legacy; | ||
|
||
import net.ess3.nms.SpawnEggProvider; | ||
import org.bukkit.entity.EntityType; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.material.MaterialData; | ||
import org.bukkit.material.SpawnEgg; | ||
|
||
public class LegacySpawnEggProvider extends SpawnEggProvider { | ||
@Override | ||
public ItemStack createEggItem(EntityType type) throws IllegalArgumentException { | ||
return new SpawnEgg(type).toItemStack(); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("deprecation") | ||
public EntityType getSpawnedType(ItemStack eggItem) throws IllegalArgumentException { | ||
MaterialData data = eggItem.getData(); | ||
if (data instanceof SpawnEgg) { | ||
return ((SpawnEgg) data).getSpawnedType(); | ||
} else { | ||
throw new IllegalArgumentException("Item is missing data"); | ||
} | ||
} | ||
|
||
@Override | ||
public String getHumanName() { | ||
return "legacy item data provider"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package net.ess3.nms; | ||
|
||
import net.ess3.providers.Provider; | ||
import org.bukkit.entity.EntityType; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
public abstract class SpawnEggProvider implements Provider { | ||
public abstract ItemStack createEggItem(EntityType type) throws IllegalArgumentException; | ||
public abstract EntityType getSpawnedType(ItemStack eggItem) throws IllegalArgumentException; | ||
|
||
@Override | ||
public boolean tryProvider() { | ||
try { | ||
EntityType type = EntityType.CREEPER; | ||
ItemStack is = createEggItem(type); | ||
EntityType readType = getSpawnedType(is); | ||
return type == readType; | ||
} catch (Throwable t) { | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters