better loading / importing of modules

This commit is contained in:
jomo
2014-06-09 23:52:11 +02:00
parent bc301a3cb2
commit e853681df6
3 changed files with 28 additions and 48 deletions

1
.gitignore vendored
View File

@@ -1,5 +1,6 @@
*.pyc *.pyc
*.class *.class
*sublime*
# these are player/ingame specific # these are player/ingame specific
files/chatgroups.json files/chatgroups.json

49
main.py
View File

@@ -2,50 +2,27 @@ __plugin_name__ = "RedstonerUtils"
__plugin_version__ = "3.0" __plugin_version__ = "3.0"
__plugin_mainclass__ = "foobar" __plugin_mainclass__ = "foobar"
# damn pythonloader changed the PATH
import sys import sys
print("Loading RedstonerUtils...")
# damn pythonloader changed this...
sys.path += ['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/pymodules/python2.7', '/usr/lib/pyshared/python2.7'] sys.path += ['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/pymodules/python2.7', '/usr/lib/pyshared/python2.7']
try:
import adminchat
except Exception, e:
print("[RedstonerUtils] ERROR: Failed to import adminchat: %s" % e)
try:
import lagchunks
except Exception, e:
print("[RedstonerUtils] ERROR: Failed to import lagchunks: %s" % e)
try:
import reports
except Exception, e:
print("[RedstonerUtils] ERROR: Failed to import reports: %s" % e)
try:
import chatgroups
except Exception, e:
print("[RedstonerUtils] ERROR: Failed to import chatgroups: %s" % e)
try:
import webtoken
except Exception, e:
print("[RedstonerUtils] ERROR: Failed to import webtoken: %s" % e)
try:
import saylol
except Exception, e:
print("[RedstonerUtils] ERROR: Failed to import saylol: %s" % e)
try:
import skullclick
except Exception, e:
print("[RedstonerUtils] ERROR: Failed to import skullclick: %s]" % e)
try:
import tilehelper
except Exception, e:
print("[RedstonerUtils] ERROR: Failed to import tilehelper: %s]" % e)
try: try:
from helpers import * from helpers import *
except Exception, e: except Exception, e:
print("[RedstonerUtils] ERROR: Failed to import helpers: %s" % e) print("[RedstonerUtils] ERROR: Failed to import helpers: %s" % e)
log("Loading RedstonerUtils...")
# Import all modules
modules = ["adminchat", "lagchunks", "reports", "chatgroups", "webtoken", "saylol", "skullclick", "tilehelper"]
for module in modules:
try:
__import__(module)
log("Module %s loaded." % module)
except Exception, e:
error("Failed to import module %s: '%s'" % (module, e))
import thread import thread
import org.bukkit.entity.Player as Player import org.bukkit.entity.Player as Player

View File

@@ -1,4 +1,5 @@
import org.bukkit as bukkit import org.bukkit as bukkit
import bukkit.event.block.BlockPlaceEvent as BlockPlaceEvent
from helpers import * from helpers import *
tilehelpers = [ # Front Right Back Left Down Up tilehelpers = [ # Front Right Back Left Down Up
@@ -7,6 +8,7 @@ tilehelpers = [
@hook.event("block.BlockPlaceEvent", "high") @hook.event("block.BlockPlaceEvent", "high")
def onPlaceBlock(event): def onPlaceBlock(event):
if not event.isCancelled():
player = event.getPlayer() player = event.getPlayer()
block = event.getBlockPlaced() block = event.getBlockPlaced()
for th in tilehelpers: for th in tilehelpers:
@@ -16,6 +18,6 @@ def onPlaceBlock(event):
# stack block in directions # stack block in directions
msg(player, "&ayus") msg(player, "&ayus")
event = BlockPlaceEvent(block, block.getState(), event.getBlockAgainst(), event.getItemInHand(), player, event.canBuild())
# server.getPluginManager().callEvent(event); # server.getPluginManager().callEvent(event);