Hi, I am very new to plugin coding. I am coding using Python and not Java. I am still a beginner in Python, and this is my first plugin. Currently I am working on a plugin where it strikes a piece of land, and replaces the block with a block of lava, and then shoots out fire. I do not know if this will work though. Here is my code: __plugin_name__ = "FireBall" __plugin_version__ = "1.0"
# boilerplate start import org.bukkit as bukkit server = bukkit.Bukkit.getServer()
@hook.command ("fireball") def FireBallCommand(sender, args): name = sender.getName() if name == "CONSOLE": msg(sender,"I'm not quite sure where you are looking at, so i'm afraid that won't work") else: # get block the player is looking at blocks = sender.getLastTwoTargetBlocks(None,20) # 20 is the maximum range block = blocks[-1] if blocks else None if block is not None: block.getWorld().FireballEffect(block.getLocation()) block.setType(bukkit.Material.LAVA) block.getWorld().MOBSPAWNER_FLAMESEffect(block.getLocation()) return True
The thing that really gets me confused is this part: block.getWorld().FireballEffect(block.getLocation()) block.setType(bukkit.Material.LAVA) block.getWorld().MOBSPAWNER_FLAMESEffect(block.getLocation())
I am not sure what to write to get objects, positions, etc.. I am getting what I can from this page http://jd.bukkit.org/rb/doxygen/files.html
Please help me, and if you could explain the part above that would be great.
Thank You!
@PureDarkness, It's quite likely that Bukkit has a python based plugin loader or something along those lines. Python is extremely flexible and can easily be run from pretty much any established language without any hassle whatsoever. That said, this kind of thing is usually not very efficient, and while there are some situations where it is necessary, I generally like to avoid it where I can.
Anyway, while I find python to be much easier than Java, that's not to say that Java is overly difficult once you've gotten a grasp of coding and stuff. Without getting too far into evaluating the languages, I think I would like to make it clear that if your goal is to learn Python then Minecraft is not the place, and if your goal is to mod Minecraft then Python is probably not the language.
Slightly more on topic, I know my way around Python a litle bit, but just as a regular Java programmer wouldn't know how to do much with Forge, I don't know how to do a thing with Bukkit, and unfortunately I don't really plan on learning (for the reasons above).
Anyway, looking past my inexperience with Bukkit... Basically, you retrieve the block that was hit (aka that the player had the crosshairs on, within a distance of 20 blocks). This block comes all wrapped up nicely with a location, a type, and so on.
First, block.getLocation tells you where the block is in the world (x,y,z). Using this location, you call the FireEffect code, telling it to operate at the location of the block. Next, you change the block to lava (block.setType). Finally, you spawn some mobspawner flames in the world at the location of the block.
As for actually learning what objects have which fields and properties and so on? No idea. Documentation? Tutorials? Look at other people's code? Sorry I can't be of more help :'(
Rollback Post to RevisionRollBack
I believe in the Invisible Pink Unicorn, bless her Invisible Pinkness.
__plugin_name__ = "FireBall"
__plugin_version__ = "1.0"
# boilerplate start
import org.bukkit as bukkit
server = bukkit.Bukkit.getServer()
from java.util.logging import Level
log = server.getLogger()
CHAT_PREFIX = "[%s] "%__plugin_name__
def info(*text):
log.log(Level.INFO,CHAT_PREFIX+" ".join(map(unicode,text)))
def severe(*text):
log.log(Level.SEVERE,CHAT_PREFIX+" ".join(map(unicode,text)))
def msg(recipient,*text):
recipient.sendMessage(CHAT_PREFIX+" ".join(map(unicode,text)))
# boilerplate end
@hook.enable
def onEnable():
info("%s v%s enabled"%(__plugin_name__,__plugin_version__))
@hook.disable
def onDisable():
info("%s disabled"%__plugin_name__)
@hook.command ("fireball")
def FireBallCommand(sender, args):
name = sender.getName()
if name == "CONSOLE":
msg(sender,"I'm not quite sure where you are looking at, so i'm afraid that won't work")
else:
# get block the player is looking at
blocks = sender.getLastTwoTargetBlocks(None,20) # 20 is the maximum range
block = blocks[-1] if blocks else None
if block is not None:
block.getWorld().FireballEffect(block.getLocation())
block.setType(bukkit.Material.LAVA)
block.getWorld().MOBSPAWNER_FLAMESEffect(block.getLocation())
return True
The thing that really gets me confused is this part:
block.getWorld().FireballEffect(block.getLocation())
block.setType(bukkit.Material.LAVA)
block.getWorld().MOBSPAWNER_FLAMESEffect(block.getLocation())
I am not sure what to write to get objects, positions, etc.. I am getting what I can from this page http://jd.bukkit.org/rb/doxygen/files.html
Please help me, and if you could explain the part above that would be great.
Thank You!
P.S. Sorry I could not get the formatting to work
Anyway, while I find python to be much easier than Java, that's not to say that Java is overly difficult once you've gotten a grasp of coding and stuff. Without getting too far into evaluating the languages, I think I would like to make it clear that if your goal is to learn Python then Minecraft is not the place, and if your goal is to mod Minecraft then Python is probably not the language.
Slightly more on topic, I know my way around Python a litle bit, but just as a regular Java programmer wouldn't know how to do much with Forge, I don't know how to do a thing with Bukkit, and unfortunately I don't really plan on learning (for the reasons above).
Anyway, looking past my inexperience with Bukkit... Basically, you retrieve the block that was hit (aka that the player had the crosshairs on, within a distance of 20 blocks). This block comes all wrapped up nicely with a location, a type, and so on.
First, block.getLocation tells you where the block is in the world (x,y,z). Using this location, you call the FireEffect code, telling it to operate at the location of the block. Next, you change the block to lava (block.setType). Finally, you spawn some mobspawner flames in the world at the location of the block.
As for actually learning what objects have which fields and properties and so on? No idea. Documentation? Tutorials? Look at other people's code? Sorry I can't be of more help :'(
I believe in the Invisible Pink Unicorn, bless her Invisible Pinkness.