Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plant growth is currently handled rather poorly by Bukkit... nonetheless, here's a working property for it!
- Loading branch information
1 parent
914420d
commit 0c5cac5
Showing
8 changed files
with
161 additions
and
19 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 was deleted.
Oops, something went wrong.
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
94 changes: 94 additions & 0 deletions
94
src/main/java/net/aufdemrand/denizen/objects/properties/Item/ItemPlantgrowth.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,94 @@ | ||
package net.aufdemrand.denizen.objects.properties.Item; | ||
|
||
|
||
import net.aufdemrand.denizen.objects.Element; | ||
import net.aufdemrand.denizen.objects.dItem; | ||
import net.aufdemrand.denizen.objects.dObject; | ||
import net.aufdemrand.denizen.objects.properties.Property; | ||
import net.aufdemrand.denizen.tags.Attribute; | ||
import org.bukkit.Material; | ||
import org.bukkit.material.CocoaPlant; | ||
import org.bukkit.material.Crops; | ||
import org.bukkit.material.NetherWarts; | ||
|
||
public class ItemPlantgrowth implements Property { | ||
|
||
public static boolean describes(dObject item) { | ||
return item instanceof dItem | ||
&& ( | ||
((dItem) item).getItemStack().getData() instanceof Crops | ||
|| ((dItem) item).getItemStack().getData() instanceof NetherWarts | ||
|| ((dItem) item).getItemStack().getData() instanceof CocoaPlant | ||
|| ((dItem) item).getItemStack().getType().equals(Material.PUMPKIN_STEM) | ||
|| ((dItem) item).getItemStack().getType().equals(Material.MELON_STEM) | ||
|| ((dItem) item).getItemStack().getType().equals(Material.CARROT) | ||
|| ((dItem) item).getItemStack().getType().equals(Material.POTATO) | ||
); | ||
} | ||
|
||
public static ItemPlantgrowth getFrom(dObject _item) { | ||
if (!describes(_item)) return null; | ||
else return new ItemPlantgrowth((dItem)_item); | ||
} | ||
|
||
|
||
private ItemPlantgrowth(dItem _item) { | ||
item = _item; | ||
} | ||
|
||
dItem item; | ||
|
||
@Override | ||
public String getAttribute(Attribute attribute) { | ||
|
||
if (attribute == null) return "null"; | ||
|
||
// <--[tag] | ||
// @attribute <i@item.plant_growth> | ||
// @returns Element | ||
// @description | ||
// Returns the growth level of a plant item as one of the following: | ||
// Wheat: SEEDED, GERMINATED, VERY_SMALL, SMALL, MEDIUM, TALL, VERY_TALL, RIPE | ||
// Nether Warts: SEEDED, STAGE_ONE, STAGE_TWO, RIPE | ||
// Cocoa Plants: SMALL, MEDIUM, LARGE | ||
// Pumpkin stem, melon stem, carrot, potato: 0-7 | ||
// --> | ||
if (attribute.startsWith("plant_growth")) { | ||
if (item.getItemStack().getData() instanceof Crops) | ||
return new Element(((Crops)item.getItemStack().getData()).getState().name()) | ||
.getAttribute(attribute.fulfill(1)); | ||
else if (item.getItemStack().getData() instanceof NetherWarts) | ||
return new Element(((NetherWarts)item.getItemStack().getData()).getState().name()) | ||
.getAttribute(attribute.fulfill(1)); | ||
else if (item.getItemStack().getData() instanceof CocoaPlant) | ||
return new Element(((CocoaPlant)item.getItemStack().getData()).getSize().name()) | ||
.getAttribute(attribute.fulfill(1)); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
|
||
@Override | ||
public String getPropertyString() { | ||
String state; | ||
if (item.getItemStack().getData() instanceof Crops) | ||
state = ((Crops)item.getItemStack().getData()).getState().name(); | ||
else if (item.getItemStack().getData() instanceof NetherWarts) | ||
state = ((NetherWarts)item.getItemStack().getData()).getState().name(); | ||
else if (item.getItemStack().getData() instanceof CocoaPlant) | ||
state = ((CocoaPlant)item.getItemStack().getData()).getSize().name(); | ||
else | ||
state = String.valueOf(item.getItemStack().getData().getData()); | ||
|
||
if (!state.equalsIgnoreCase("SEEDED") && !state.equalsIgnoreCase("0")) | ||
return state; | ||
else | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getPropertyId() { | ||
return "plant_growth"; | ||
} | ||
} |
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