1. Mattie
  2. eventscripts-mc

Commits

Mattie  committed 3667d96

Updating MagicItems for bukkit.
Added magicrod which supports "Fishing Trip" to teleport a player to you.

  • Participants
  • Parent commits d3d832f
  • Branches default

Comments (0)

Files changed (8)

File eventscripts/magicitems/magicblocks.py

View file
 # EventScripts Minecraft Example
-# Copyright 2010, Mattie Casper
+# Copyright 2011, Mattie Casper
 #
 # magicblocks.py
 #   Replace /warp, /sethome, and /home with some new commands
         self.player = player
         self.lastmove = 0
         self.jumpcount = 0
+        self.lastblock = player.location
     def move(self, mfrom, mto):
-        #esm.server.messageAll(str(self.jumpcount))
-        id = esm.getBlockId(mto.x,mto.y,mto.z)
+        id = esm.blockat(mto.blockx, mto.blocky, mto.blockz, mto.getWorld()).typeid
         if id in (esm.items.water, esm.items.ladder):
             # not jumping if there's a ladder or water involved
             self.reset()
         else:
-            if mfrom.x==mto.x and mfrom.z==mto.z and mfrom.y != mto.y:
-                if mfrom.y == mto.y - 1:
+            #esm.output("%f,%f,%f -> %f,%f,%f" %(mfrom.x, mfrom.y, mfrom.z, mto.x, mto.y, mto.z))
+            #if self.lastblock.blockx-mto.blockx !=0 or self.lastblock.blocky-mto.blocky != 0 or self.lastblock.blockz-mto.blockz != 0:
+            #    esm.output("%d,%d,%d" % (self.lastblock.blockx-mto.blockx, self.lastblock.blocky-mto.blocky, self.lastblock.blockz-mto.blockz))
+            if self.lastblock.blockx==mto.blockx and self.lastblock.blockz==mto.blockz and self.lastblock.blocky != mto.blocky:
+                if self.lastblock.blocky == mto.blocky - 1:
                     self._jumpup()
-                elif mfrom.y - 1 == mto.y:
+                elif self.lastblock.blocky - 1 == mto.blocky:
                     self._falldown()
                 else:
                     self.reset()
+            elif self.lastblock.blockx==mto.blockx and self.lastblock.blockz==mto.blockz and self.lastblock.blocky == mto.blocky:
+                pass
             else:
                 self.reset()
+        self.lastblock = mto
         return self.jumpcount
     def _jumpup(self):
         if self.lastmove == -1:
         self.hopstop_jumpcost = cfg.getInt("magicblocks-hopstop-usage-jumpcost", 2)
         self.hopstop_createcost = cfg.getInt("magicblocks-hopstop-create-redstonecost", 50)
         self.hopstop_hopcost = cfg.getInt("magicblocks-hopstop-usage-redstonecost-per-segment", 1)
+        self.hopstop_world_hopcost = cfg.getInt("magicblocks-hopstop-usage-redstonecost-across-worlds", 30)
         self.hopstop_hoplength = cfg.getInt("magicblocks-hopstop-segment-distance", 100)
         if os.path.exists(self.homesdat):
             self.homes = self.loadDict(self.homesdat)
         name = player.getName()
         loc = (0,0,0)
         if name not in self.homes:
-            sloc = esm.server.getSpawnLocation()
+            sloc = esm.world.spawnlocation
             loc = (sloc.x, sloc.y-1, sloc.z)
         else:
             loc = self.homes[name]
-        player.teleportTo(loc[0]+0.5, loc[1]+1, loc[2]+0.5, 0, 0)
+        if len(loc) > 3:
+            wo = esm.server.getWorld(loc[3])
+        else:
+            wo = esm.world
+        location = esm.location(loc[0]+0.5, loc[1]+1, loc[2]+0.5, player.location.yaw, player.location.pitch, wo)
+        player.teleportTo(location)
 
     def useBasequick(self, player):
         if self.homerun_enabled and utils.spendRedstone(player, self.homerun_cost):
             self.warpHome(player)
+        return True
 
     def useBasejump(self, player, lfrom, lto):
         if not self.homewardbound_enabled and not self.hopstop_enabled:
         if name not in self.jumpcounters:
             self.trackPlayer(player)
         jumped = self.jumpcounters[name].move(lfrom, lto)
-        if self.homewardbound_enabled and player.getItemInHand() == -1:
+        if self.homewardbound_enabled and player.iteminhand.typeid == esm.items.air:
             if jumped >= self.homebound_jumpcost-1:
                 self.jumpcounters[name].reset()
                 self.warpHome(player)
-                return True
+                return False
         if self.hopstop_enabled and jumped >= self.hopstop_jumpcost-1:
             if self.useWarpRoom(player, lto):
                 self.jumpcounters[name].reset()
+                return False
         return True
     
     def useBasecamp(self, player, block):
         if name in self.homes:
             # destroy home
             oldhome = self.homes[name]
-            bl = esm.server.getBlockAt(int(oldhome[0]), int(oldhome[1]), int(oldhome[2]))
-            esm.server.loadChunk(bl)
-            bl = esm.server.getBlockAt(int(oldhome[0]), int(oldhome[1]), int(oldhome[2]))
-            bl.setType(esm.items.cobblestone)
-            bl.update()
-        inv = player.getInventory()
-        for i in range(0, 10):
-            it = inv.getItemFromSlot(i)
-            if it is not None and it.getItemId()==esm.items.compass:
-                amount = it.getAmount() - 1
-                if amount > 0:
-                    it.setAmount(amount-1)
-                    inv.setSlot(it, i)
-                else:
-                    inv.removeItem(i)
-                inv.update()
+            if len(oldhome) > 3:
+                world = esm.server.getWorld(oldhome[3])
+            else:
+                world = esm.world
+            world.loadChunk(block.x, block.z)
+            bl = esm.blockat(int(oldhome[0]), int(oldhome[1]), int(oldhome[2]), world)
+            bl.typeid = esm.items.cobblestone
+        # surely they were still holding the compass
+        inv = player.inventory
+        inv.clear(inv.helditemslot)
         # set block to obsidian
-        def setBlockToObsidian(block):
-            block.setType(esm.items.obsidian)
-            block.update()
-        esm.queue(setBlockToObsidian, block)
-        self.homes[name] = (block.getX(), block.getY(), block.getZ())
+        block.typeid = esm.items.obsidian
+        self.homes[name] = (block.x, block.y, block.z, str(block.world.name))
         self.saveDict(self.homes, self.homesdat)
         # save block+1 as player home spot
         return False
 
     def checkWarpStructure(self, block, style=None):
         # checkWarpStructure assumes it gets the core block
-        ox, oy, oz = block.getX(), block.getY(), block.getZ()
+        wo, ox, oy, oz = block.getWorld(), block.getX(), block.getY(), block.getZ()
         for x in range(ox-1, ox+2):
             for z in range(oz-1, oz+2):
-                esm.server.loadChunk(x, oy, z)
+                wo.loadChunk(x, z)
+                #esm.world.getChunkAt(x, z)
                 if x == ox and z == oz:
                     if style is None:
                         continue
                     else:
                         # testing a working structure
-                        if esm.server.getBlockIdAt(x, oy, z) != style:
+                        if self.getWarpType(esm.blockat(x, oy, z, wo)) != style:
+                            esm.output('failed1')
                             return 0
-                        if esm.server.getBlockIdAt(x, oy+1, z) != esm.items.redstonewire:
+                        if esm.blockidat(x, oy+1, z, wo) != esm.items.redstonewire:
+                            esm.output('failed_redstone')
+                            esm.output(esm.blockidat(x, oy+1, z, wo))
                             return 0
                     continue
-                if esm.server.getBlockIdAt(x, oy, z) != esm.items.obsidian:
-                    #esm.output("not obsid %d, %d, %d -- was %d" %(x,oy,z, esm.server.getBlockIdAt(x, oy, z)))
+                if esm.blockidat(x, oy, z, wo) != esm.items.obsidian:
+                    esm.output("not obsid %d, %d, %d -- was %d" %(x,oy,z, esm.blockidat(x, oy, z, wo)))
                     return 0
         return 1
 
     def removeWarpPoint(self, block, typ):
-        esm.server.loadChunk(block)
+        wo = block.getWorld()
+        wo.loadChunk(block.getX(), block.getZ())
         # removeWarpPoint assumes it gets the core block
-        esm.output("MagicItems[HopStop]: Removing warp point" + str(typ) + " " + str((block.getX(), block.getY(), block.getZ())))
-        pt = (block.getX(), block.getY(), block.getZ())
-        self.warps[typ].remove(pt)
+        esm.output("MagicItems[HopStop]: Removing warp point" + str(typ) + " " + str((block.getX(), block.getY(), block.getZ(), wo.getName())))
+        pt = (block.getX(), block.getY(), block.getZ(), wo.getName())
+        if pt in self.warps[typ]:
+            self.warps[typ].remove(pt)
+        else:
+            pt = (block.getX(), block.getY(), block.getZ())
+            self.warps[typ].remove(pt)
         if len(self.warps[typ]) < 1:
             del self.warps[typ]
         self.saveDict(self.warps, self.warpsdat)
-        
+
+    def getContentsWarpType(self, inv):
+        typ = []
+        try:
+            if inv.getSize() > 0:
+                contents = inv.getContents()
+                i = 0
+                for item in contents:
+                    if item.getTypeId() != 0:
+                        data = item.getData()
+                        data = data.getData() if data else None
+                        typ.append((i, item.getTypeId(), data, item.getAmount(),))
+                    i+=1
+        except:
+            esm.output("[MagicItems] Warning: Couldn't read warp target contents.")
+        return tuple(typ)
+
+    def getWarpType(self, block):
+        id = block.getTypeId()
+        data = block.getData()
+        if id == esm.items.note_block:
+            st = block.getState()
+            typ = (id, data, st.getNote())
+            st.play()
+        elif id in [esm.items.chest, esm.items.dispenser, esm.items.furnace]:
+            st = block.getState()
+            items = self.getContentsWarpType(st.getInventory())
+            if len(items) < 1:
+                typ = id
+            elif id == esm.items.furnace:
+                typ = (id, items)
+            else:
+                typ = (id, data, items)
+        elif data and data != 0:
+            typ = (id, data)
+        else:
+            typ = id
+        return typ
+
     def createWarpPoint(self, block):
-        typ = block.getType()
-        pt = (block.getX(), block.getY(), block.getZ())
+        typ = self.getWarpType(block)
+        esm.output(typ)
+        wo = block.getWorld()
+        pt = (block.getX(), block.getY(), block.getZ(), wo.getName())
         if typ and typ in self.warps:
             if pt and pt not in self.warps[typ]:
                 esm.output("MagicItems[HopStop]: Appending" + str(pt) +" to " + str(typ) + " in " + str(self.warps[typ]))
                 self.warps[typ].append(pt)
-                esm.server.setBlockAt(esm.items.redstonewire,block.getX(), block.getY()+1, block.getZ())
+                esm.blockat(block.getX(), block.getY()+1, block.getZ(), wo).typeid = esm.items.redstonewire
         elif typ:
             esm.output("MagicItems[HopStop]: Adding " + str(pt) +" to " + str(typ))
             self.warps[typ] = [pt]
-            esm.server.setBlockAt(esm.items.redstonewire,block.getX(), block.getY()+1, block.getZ())
+            esm.blockat(block.getX(), block.getY()+1, block.getZ(), wo).typeid = esm.items.redstonewire
         self.saveDict(self.warps, self.warpsdat)
 
     # called on destroy block
     def useWarpBind(self, player, block):
-        if self.hopstop_enabled and player.getItemInHand() == esm.items.redstonedust:
+        esm.output(str(player.getItemInHand())+"."+ str(esm.items.redstonedust))
+        if self.hopstop_enabled and player.iteminhand.typeid == esm.items.redstonedust:
             if self.warpcooldown.get(player.getName(), 0) < time.time() - 2 and self.checkWarpStructure(block)==1 and utils.spendRedstone(player, self.hopstop_createcost):
                 self.createWarpPoint(block)
                 self.warpcooldown[player.getName()] = time.time()
     def _warpActivate(self, player, bl2):
         if self.checkWarpStructure(bl2) != 1:
             return True
-        warptype = bl2.getType()
+        warptype = self.getWarpType(bl2)
+        #esm.output(warptype)
+        #esm.output(self.warps.keys())
         if warptype in self.warps and self.warpcooldown.get(player.getName(), 0) < time.time() - 2:
-            spot = (bl2.getX(), bl2.getY(), bl2.getZ())
+            esm.output("warptype found")
+            wo = bl2.getWorld()
+            spotnew = (bl2.getX(), bl2.getY(), bl2.getZ(), wo.getName())
+            spotold = (bl2.getX(), bl2.getY(), bl2.getZ())
             #esm.output("all warps of the type: " + str(self.warps[warptype]))
             #esm.output("where we are now " + str(spot))
-            if spot in self.warps[warptype]:
-                #esm.output("where we are now2 " + str(spot))
+            spot = None
+            if spotnew in self.warps[warptype]:
+                spot = spotnew
+            elif wo.getName() == esm.world.getName() and spotold in self.warps[warptype]:
+                spot = spotold
+            if spot is not None:
                 loc = spot
                 while len(self.warps[warptype]) > 1:
-                    ind = self.warps[warptype].index(spot)
+                    ind = self.warps[warptype].index(loc)
                     try:
                         loc = self.warps[warptype][ind+1]
                     except:
                         loc = self.warps[warptype][0]
-                    bl3 = esm.server.getBlockAt(loc[0], loc[1], loc[2])
+                    if len(loc) < 4:
+                        bl3 = esm.blockat(loc[0], loc[1], loc[2])
+                    else:
+                        wo3 = esm.server.getWorld(loc[3])
+                        bl3 = esm.blockat(loc[0], loc[1], loc[2], wo3)
                     ret = self.checkWarpStructure(bl3, warptype)
                     if ret == -1:
                         # checking it will load the chunks we need
                     else:
                         break
                 esm.output("MagicItems[HopStop]: Trying to teleport %s to %s" %(player.getName(), str(loc)))
-                cost = int(esm.blocklib.distance(spot, loc)/self.hopstop_hoplength)*self.hopstop_hopcost
+                worldname1 = spot[3] if len(spot) > 3 else esm.world.getName()
+                worldname2 = loc[3] if len(loc) > 3 else esm.world.getName()
+                if worldname1 != worldname2:
+                    cost = self.hopstop_world_hopcost
+                else:
+                    cost = int(esm.blocklib.distance(spot, loc)/self.hopstop_hoplength)*self.hopstop_hopcost
                 if cost<=0 or utils.spendRedstone(player, cost):
-                    player.teleportTo(loc[0]+0.5, loc[1]+1, loc[2]+0.5, player.getLocation().rotX, player.getLocation().rotY)
+                    wo = esm.server.getWorld(worldname2)
+                    location = esm.location(loc[0]+0.5, loc[1]+1, loc[2]+0.5, player.location.yaw, player.location.pitch, wo)
+                    player.teleportTo(location)
                 else:
                     health = player.getHealth()
                     if health <= 1:
 
     # called on player move
     def useWarpRoom(self, player, lto):
-        bl = esm.server.getBlockAt(int(lto.x), int(lto.y), int(lto.z))
-        if bl.getType() == esm.items.redstonewire:
-            bl2 = esm.server.getBlockAt(bl.getX(), bl.getY()-1, bl.getZ())
+        bl = esm.blockat(int(lto.blockx), int(lto.blocky), int(lto.blockz), lto.getWorld())
+        if bl.typeid == esm.items.redstonewire:
+            bl2 = esm.blockat(bl.x, bl.y-1, bl.z, bl.getWorld())
             return self._warpActivate(player, bl2)
         return False

File eventscripts/magicitems/magichelmet.py

View file
 # EventScripts Minecraft Example
-# Copyright 2010, Mattie Casper
+# Copyright 2011, Mattie Casper
 #
 # magichelmet.py
 #   Allow underwater breathing
 class MagicHelmet():
     def __init__(self, cfg):
         self.helmetplayers = {}
-        self.cost = cfg.getInt("magichelmet-merminer-costperbreath", 2)
+        self.cooldowns = {}
+        self.seatouchenabled = cfg.getBoolean("magichelmet-seatouch-enabled", True)
+        self.seatouchcost = cfg.getInt("magichelmet-seatouch-cost", 3)
+        self.cost = cfg.getInt("magichelmet-merminer-costperbreath", 1)
         self.breath = cfg.getInt("magichelmet-merminer-breathseconds", 30)
 
+    def useSeatouch(self, player, block):
+        if self.seatouchenabled:
+            if magicitems.spendRedstone(player, self.seatouchcost):
+                bl = block.getRelative(0, 1, 0)
+                if bl.getTypeId() == items.air:
+                    bl.setTypeId(items.water)
+        return True
+
     def useWaterBreathing(self, player):
         if magicitems.isPlayerWearing(player, items.goldhelmet):
-            if self.checkAnyAirTimeLeft(player):
+            if magicitems.spendRedstone(player, self.cost):
+                player.remainingair = player.maximumair
                 return False
-            else:
-                if magicitems.spendRedstone(player, self.cost):
-                    self.helmetplayers[player.getName()] = time.time()
-                    return False
         # no helmet or no stone and you're out of luck!
         return True
 

File eventscripts/magicitems/magicitems.py

View file
 # magicitems.py
 #   Magic items to make gold and redstone more useful day-to-day
 #  
-# Version: 0.4
+# Version: 0.3
 
 import esm
 from esm import items
 import esm.blocklib as blocklib
-import PropertiesFile
+import com.eventscripts.minecraft.PropertiesFile as PropertiesFile
+from org.bukkit.event.entity import EntityDamageByEntityEvent
 
 import magichelmet
 reload(magichelmet)
-import magicpick
-reload(magicpick)
+#import magicpick
+#reload(magicpick)
 import magicshovel
 reload(magicshovel)
 import magicwatch
 reload(magicblocks)
 import magicsword
 reload(magicsword)
+import magicrod
+reload(magicrod)
 
 from utils import *
 import java.util.LinkedHashSet as LinkedHashSet
 warp = None
 cfg = None
 sword = None
+rod = None
+
 def load():
-    global cfg, helmet, pick, shovel, watch, warp, sword
+    global cfg, helmet, pick, shovel, watch, warp, sword, rod
     cfg = PropertiesFile("magicitems.properties")
     if cfg.getBoolean("magichelmet-enabled", True):
         helmet = magichelmet.MagicHelmet(cfg)
-    if cfg.getBoolean("magicpick-enabled", True):
+    if cfg.getBoolean("magicpick-enabled", False):
         pick = magicpick.MagicPick(cfg)
     if cfg.getBoolean("magicshovel-enabled", True):
         shovel = magicshovel.MagicShovel(cfg)
         warp = magicblocks.MagicBlocks(cfg)
     if cfg.getBoolean("magicsword-enabled", True):
         sword = magicsword.MagicSword(cfg)
+    if cfg.getBoolean("magicrod-enabled", True):
+        rod = magicrod.MagicRod(cfg)
+    esm.output("[MagicItems] Loaded.")
 
 # TODO: Allow disabling of individual magic items
 # List of events and how those tie into all the magic items
             return helmet.useWaterBreathing(player)
     return True
 
-def block_broken(event):
-    inhand = event.player.getItemInHand()
+def block_break(event):
+    inhand = event.player.iteminhand.typeid
     if shovel and inhand == items.goldspade:
         return shovel.useMagicShovel(event.player, event.block)
     if watch and inhand == items.watch:
-        if event.block.getType() == items.stone:
+        if event.block.typeid == items.stone:
             return watch.useDaybreak(event.player, event.block)
     if warp and inhand == items.compass:
-        if event.block.getType() == items.goldblock:
+        if event.block.typeid == items.goldblock:
             return warp.useBasecamp(event.player, event.block)
     if sword and inhand == items.goldsword:
-        if event.block.getType() == items.mobspawner:
+        if event.block.typeid == items.mobspawner:
             sword.useSwordsToPlowshares(event.player, event.block)
     return True
 
-def block_destroyed(event):
-    if warp and event.player.getItemInHand() == items.redstonedust:
+def block_damaged(event):
+    if warp and event.player.iteminhand.typeid == items.redstone:
         return warp.useWarpBind(event.player, event.block)
-    if pick and event.player.getItemInHand() == items.goldpickaxe:
+    if pick and event.player.iteminhand.typeid == items.goldpickaxe:
         return pick.useResourceScan(event.player, event.block)
     return not pick.checkProtectedBlock(event.block) if pick else True
 
-def item_use(event):
-    if warp and event.item.getItemId() == items.compass:
+
+chestitems = {}
+def player_item(event):
+    if warp and event.item.typeid == items.compass:
         return warp.useBasequick(event.player)
+    if helmet and event.item.typeid == items.goldhelmet and event.blockclicked:
+        return helmet.useSeatouch(event.player, event.blockclicked)
+    if rod and event.item.typeid == items.fishingrod and event.blockclicked:
+        return rod.useFishingTrip(event.player, event.blockclicked)
+    if event.item.typeid == items.goldchestplate and event.blockclicked:
+        bl = event.blockclicked.getRelative(0, 1, 0)
+        if bl.typeid == items.air:
+            bl.typeid = items.chest
+            bl2 = esm.server.getComplexBlock(bl)
+            name = event.player.getName()
+            j = chestitems.get(name, [])
+            if len(j) > 0:
+                for c in j:
+                    bl2.setSlot(c, c.getSlot())
+            bl2.update()
+            bl.update()
+            def removeChest(name, blx, chest):
+                esm.output(str(blx) + str(esm.items.chest))
+                if blx.getType() == esm.items.chest:
+                    chestitems[name] = filter(lambda x: x is not None, chest.getContents())
+                    chest.clearContents()
+                    blx.setType(items.air)
+                    blx.update()
+            esm.delayed(45, removeChest, (name, bl, bl2))
     return True
 
-def attack(event):
-    attacker = event.attacker
-    if sword and attacker and attacker.isPlayer() and attacker.getPlayer().getItemInHand() == items.goldsword:
-        return sword.useSunslice(event.attacker.getPlayer(), event.defender)
+def entity_damaged(event):
+    if esm.isInstance(event, EntityDamageByEntityEvent):
+        attacker = event.damager
+        if sword and attacker and esm.isPlayer(attacker) and str(event.cause) == "ENTITY_ATTACK" and attacker.iteminhand.typeid == items.goldsword:
+            return sword.useSunslice(attacker, event.entity)
+    if helmet and esm.isPlayer(event.entity):
+        if event.getCause() == event.DamageCause.DROWNING:
+            return helmet.useWaterBreathing(event.entity)
     return True
 
-def login(event):
+def player_join(event):
     if warp:
         warp.trackPlayer(event.player)
 
 def player_move(event):
     # check for jumps
     if warp:
-        warp.useBasejump(event.player, event.from, event.to)
+        if not warp.useBasejump(event.player, event.from, event.to):
+            event.from = event.player.getLocation()
+            return False
+    return True
     # disabled redcrumbs since beta
     # pants.useRedcrumbs(event.player, event.from)
 
+
+
+#def chunk_loaded(event):
+#    esm.output(event)

File eventscripts/magicitems/magicrod.py

View file
+# EventScripts Minecraft Example
+# Copyright 2011, Mattie Casper
+#
+# magicshovel.py
+#   Allows rapid mining of gravel and sand
+#
+import esm
+from utils import *
+from org.bukkit.inventory import ItemStack
+from org.bukkit.craftbukkit.entity import CraftBoat
+
+class MagicRod():
+    def __init__(self, cfg):
+        self.cost = cfg.getInt("magicrod-fishingtrip-cost-per-activation", 20)
+
+    def useFishingTrip(self, player, block):
+        if block.typeid == esm.items.torch:
+            if block.getRelative(0, 1, 0).getTypeId() == esm.items.air:
+                for j in esm.server.getOnlinePlayers():
+                    if j.getItemInHand().getTypeId() == items.rawfish:
+                        if j.isInsideVehicle():
+                            if esm.isInstance(j.getVehicle(), CraftBoat):
+                                if spendRedstone(player, 20):
+                                    j.leaveVehicle()
+                                    j.teleportTo(block.getLocation())
+                                    j.setItemInHand(ItemStack(esm.items.cookedfish, 1))
+                                else:
+                                    health = player.getHealth()
+                                    if health > 1:
+                                        player.health = health - 1
+                                break
+            block.typeid = esm.items.air
+            return False
+        return True
+
+
+

File eventscripts/magicitems/magicshovel.py

View file
 # Copyright 2011, Mattie Casper
 #
 # magicshovel.py
-#   Allows rapid mining of large gravel, sand, and dirt columns
+#   Allows rapid mining of gravel and sand
 #
 import esm
 from esm import items
 import magicitems
 import time
+from org.bukkit.inventory import ItemStack
+
 
 class MagicShovel():
     def __init__(self, cfg):
         self.length = cfg.getInt("magicshovel-undermine-activation-seconds", 10)
 
     def useMagicShovel(self, player, tblock):
-        if (tblock.getType() in (esm.items.gravel, esm.items.sand, esm.items.dirt)):
+        if (tblock.getTypeId() in (esm.items.gravel, esm.items.sand, esm.items.dirt)):
             # loop upwards and kill gravel or sand above
             block = tblock.getRelative(0, 1, 0)
-            while block.getType() == tblock.getType():
+            while block.getTypeId() == tblock.getTypeId():
                 if not self.checkAnyShovelTimeLeft(player):
                     if magicitems.spendRedstone(player, self.cost):
                         self.players[player.getName()] = time.time()
                     else:
                         return True
-                block.setType(esm.items.air)
-                block.update()
-                esm.server.dropItem(block.getX(), block.getY(), block.getZ(),tblock.getType())
+                block.setTypeId(esm.items.air)
+                esm.world.dropItemNaturally(block.getLocation(), ItemStack(tblock.getTypeId(), 1))
                 block = block.getRelative(0, 1, 0)
         return True
 

File eventscripts/magicitems/magicsword.py

View file
 from esm import items
 import esm.blocklib
 import magicitems
+from org.bukkit.inventory import ItemStack
 
 class MagicSword():
     def __init__(self, cfg):
         self.stpenabled = cfg.getBoolean(pre+"swordstoplowshares-enabled", True)
     def useSunslice(self, player, mob):
         if self.sunsliceenabled and magicitems.spendRedstone(player, self.redstonecost):
-            mob.setRotation(player.getRotation())
-            mob.setFireTicks(60)
+            mob.getHandle().fireTicks = 120
+            mobl = mob.location
+            playl = player.location
+            mob.teleportTo(esm.location(mobl.x, mobl.y, mobl.z, playl.yaw, playl.pitch, playl.getWorld()))
         return True
     def useSwordsToPlowshares(self, player, block):
         if self.stpenabled:
-            def explode(x, y, z):
-                bl = esm.server.getBlockAt(x, y, z)
+            def explode(x, y, z, world):
+                bl = esm.blockat(x, y, z, world)
                 esm.blocklib.experimental.explode(bl, 1.0)
-            esm.queue(explode, (block.getX(), block.getY(), block.getZ()))
-            esm.queue(_repairBySword, player)
-            return False
+            esm.queue(explode, (block.getX(), block.getY(), block.getZ(), block.getWorld()))
+            _repairBySword(player)
+            return True
         return True
 
 
 def _repairBySword(player):
-    inv = player.getInventory()
-    for i in range(0, 10):
-        it = inv.getItemFromSlot(i)
-        if it is not None and it.getItemId()==items.goldsword:
-            inv.removeItem(i)
-    for it in inv.getContents():
-        if it:
-            if it.getDamage() > 0:
-                esm.output(str(it.getItemId()) + " " + str(it.getDamage()))
-                sl = it.getSlot()
-                inv.removeItem(sl)
-                it.setDamage(0)
-                inv.setSlot(it, sl)
-    inv.update()
+    inv = player.inventory
+    esm.output(inv.size)
+    for i in range(0, inv.size):
+        it = inv.getItem(i)
+        esm.output(str(it.getTypeId()) + " " + str(it.getDurability()))
+        id = it.getTypeId()
+        if id != esm.items.goldsword:
+            if it.getDurability() > 0:
+                newit = ItemStack(id, 1)
+                inv.setItem(i, newit)
+                esm.output("fixing:" + str(it.getTypeId()) + " " + str(it.getDurability()))
+    boots = inv.boots
+    boots.durability = 0
+    inv.boots = boots.getTrueInternalObject()
+    helmet = inv.helmet
+    helmet.durability = 0
+    inv.helmet = helmet.getTrueInternalObject()
+    chestplate = inv.chestplate
+    chestplate.durability = 0
+    inv.chestplate = chestplate.getTrueInternalObject()
+    leggings = inv.leggings
+    leggings.durability = 0
+    inv.leggings = leggings.getTrueInternalObject()
+    inv.clear(inv.getHeldItemSlot())

File eventscripts/magicitems/magicwatch.py

View file
 # EventScripts Minecraft Example
-# Copyright 2010, Mattie Casper
+# Copyright 2011, Mattie Casper
 #
 # magicwatch.py
 #   Your watch can control time if you destroy it.
         self.daybreaktime = cfg.getInt("magicwatch-daybreak-time", 23400)
         self.daybreakradius = cfg.getDouble("magicwatch-daybreak-explosion-radius", 1.0)
     def useDaybreak(self, player, block):
-        def explode(x, y, z):
-            bl = esm.server.getBlockAt(x, y, z)
+        def explode(x, y, z, world):
+            bl = esm.blockat(x, y, z, world)
             esm.blocklib.experimental.explode(bl, self.daybreakradius)
-        esm.queue(explode, (block.getX(), block.getY(), block.getZ()))
-        esm.server.setRelativeTime(self.daybreaktime)
+        esm.queue(explode, (block.getX(), block.getY(), block.getZ(), block.getWorld()))
+        player.world.time = self.daybreaktime
         inv = player.getInventory()
-        for i in range(0, 10):
-            it = inv.getItemFromSlot(i)
-            if it is not None and it.getItemId()==items.watch:
-                amount = it.getAmount() - 1
-                if amount > 0:
-                    it.setAmount(amount-1)
-                    inv.setSlot(it, i)
-                else:
-                    inv.removeItem(i)
-                inv.update()
-                return True
+        item = inv.getItemInHand()
+        amount = item.getAmount()
+        if amount > 1:
+            item.setAmount(amount-1)
+            inv.setItem(inv.getHeldItemSlot(), item)
+        else:
+            inv.clear(inv.getHeldItemSlot())
         return True

File eventscripts/magicitems/utils.py

View file
 # EventScripts Minecraft Example
-# Copyright 2010, Mattie Casper
+# Copyright 2011, Mattie Casper
 #
 # utils.py
 #   Some tools to help with magic items
 
 import esm
 from esm import items
-import Item
+import org.bukkit.entity.Item as Item
+
+def totalItems(inv, itemid):
+    total = 0
+    # loop through all items that match the itemid and sum up
+    for entry in inv.all(itemid).entrySet():
+        total += entry.value.getAmount()
+    return total
+
+import org.bukkit.inventory.ItemStack as ItemStack
+from jarray import *
+
+def removeItemCount(inv, itemid, count):
+#    inv.removeItem(array([ItemStack(itemid, count)], ItemStack))
+    for entry in inv.all(itemid).entrySet():
+        slot = entry.key
+        item = entry.value
+        amount = item.getAmount()
+        if count > amount:
+            count -= amount
+            inv.clear(slot)
+        else:
+            newitem = ItemStack(item.getTypeId(), amount-count)
+            inv.setItem(slot, newitem)
+            return
 
 def isPlayerWearing(player, item):
-    eq = player.getInventory()
-    if eq:
-        it = eq.getItemFromId(item)
-        if it and it.getSlot() >= esm.slots.boots:
-            return True
+    eq = player.getInventory().getArmorContents()
+    for i in eq:
+        if i.getTypeId() == item:
+           return True
     return False
 
 def isRedstoneCostAvailable(player, cost, inv=None):
     if inv == None:
         inv = player.getInventory()
-    if inv and inv.hasItem(items.redstonedust, cost, 64):
+    if inv and totalItems(inv, esm.items.redstone) >= cost:
         return True
     else:
         return False
     if inv == None:
         inv = player.getInventory()
     if isRedstoneCostAvailable(player, cost, inv):
-        inv.removeItem(Item(items.redstonedust, cost))
-        inv.update()
+        removeItemCount(inv, items.redstonedust, cost)
         return True
     else:
         return False