增加菜单与管理员操作

This commit is contained in:
Toger 2025-05-20 13:05:00 +08:00
parent 60e0bd6ea7
commit 2dadb84258

551
reiki.py
View File

@ -6,19 +6,34 @@ import pyspigot as ps
from org.bukkit import Material, Sound, Particle
from org.bukkit.util import Vector
from org.bukkit.entity import Player
from org.bukkit.potion import PotionEffect, PotionEffectType
from org.bukkit.Bukkit import getServer
from org.bukkit.inventory import ItemStack, EquipmentSlot
from org.bukkit.enchantments import Enchantment
from org.bukkit.event.player import PlayerInteractEvent
from org.bukkit.potion import PotionEffect, PotionEffectType
from org.bukkit.event.inventory import InventoryClickEvent
from org.bukkit.event.inventory import InventoryDragEvent
from org.bukkit.event.inventory import InventoryCloseEvent
from util2.develop.gui.builder import initializeItemStack
from util2.develop.gui.builder import getGUIValue
from util2.develop.gui.manager import GUIManager
from util2.develop.gui.manager import GUIController
from util2.develop.gui.builder import isGUI
from util2.develop.gui.bugfixer import closeGuiForAll
from util2.develop.gui.bugfixer import cancelShiftClickFromPlayerInventory
from util2.develop.gui.bugfixer import denyAllInventoryDrag
from util2.plugins.head import PlayerHeadsAPI
WORLD_NAME = u"Old_World"
MIN_TODAY_PRO = 0.0 #天时最小值
MAX_TODAY_PRO = 10.0 #天时最大值
MIN_REIKI_PRO = 0.0 #地利最小值
MAX_REIKI_PRO = 10.0 #地利最大值
guiManager = GUIManager() #菜单管理
playerHeadsAPI = PlayerHeadsAPI() # 初始化Player Heads
playerPage = {} #玩家页数
class WorldManager: #世界管理
def __init__(self):
@ -59,6 +74,9 @@ class ItemsManager:
self.iceItems.append(itemId)
elif element == u"WIND":
self.windItems.append(itemId)
def getAllItems(self): #获取所有道具
items = self.itemsData.getKeys(False)
return items
def getItemstack(self, itemId=0):
if str(itemId) not in self.itemsData.getKeys(False): #若不存在该Id道具
return None
@ -123,13 +141,13 @@ class BlockManager:
self.blockData.set("{}.z".format(blockId), loc.getBlockZ())
self.blockData.set("{}.world".format(blockId), loc.getWorld().getName())
self.blockData.set("{}.name".format(blockId), u"普通灵气台")
self.blockData.set("{}.grass".format(blockId), 11)
self.blockData.set("{}.fire".format(blockId), 11)
self.blockData.set("{}.water".format(blockId), 11)
self.blockData.set("{}.earth".format(blockId), 11)
self.blockData.set("{}.thunder".format(blockId), 11)
self.blockData.set("{}.ice".format(blockId), 11)
self.blockData.set("{}.wind".format(blockId), 11)
self.blockData.set("{}.grass".format(blockId), 1)
self.blockData.set("{}.fire".format(blockId), 1)
self.blockData.set("{}.water".format(blockId), 1)
self.blockData.set("{}.earth".format(blockId), 1)
self.blockData.set("{}.thunder".format(blockId), 1)
self.blockData.set("{}.ice".format(blockId), 1)
self.blockData.set("{}.wind".format(blockId), 1)
self.blockData.set("{}.timesOfUse".format(blockId), 0) #使用过的次数
self.blockData.set("{}.timesOfMutation".format(blockId), 0) #突变召唤次数
self.blockData.save()
@ -198,6 +216,15 @@ class BlockManager:
self.blockData.set("{}.timesOfMutation".format(blockId), timesOfMutation + 1) #设置
self.blockData.save() #保存
return True
def addTableTimesOfElement(self, blockId, element=u"grass"):
if str(blockId) not in self.blockData.getKeys(False): #若不存在
return False
if element.lower() not in ["grass", "fire", "water", "earth", "thunder", "ice", "wind"]: #若元素不存在
return False
timesOfElement = self.blockData.getInt("{}.timesOf{}".format(blockId, element.lower()), 0) #获取
self.blockData.set("{}.timesOf{}".format(blockId, element.lower()), timesOfElement + 1) #设置
self.blockData.save() #保存
return True
#灵气召唤--------------------------------
def reikiCall(self, player, blockId, key=u"DANDELION", mutation=False): #灵气召唤
if str(blockId) not in self.blockData.getKeys(False): #若不存在
@ -220,6 +247,9 @@ class BlockManager:
self.element[blockId] = element #设置元素
self.itemId[blockId] = itemId #设置物品
self.players[blockId] = player #设置玩家
playerManager = PlayerManager(player)
playerManager.setGetting(True)
self.taskIds[blockId] = ps.scheduler.scheduleRepeatingTask(lambda s=self, b=blockId, m=mutation, : s.spawnParticles(b, m), 0, 1)
return True
def reikiCallEnd(self, blockId):
@ -228,19 +258,25 @@ class BlockManager:
loc = self.getTableLoc(blockId)
world = loc.getWorld()
blockManager.addTableTimesOfUse(blockId) #增加使用次数
player = self.players[blockId] #获取玩家
playerManager = PlayerManager(player) #获取玩家管理器
playerManager.addTimesOfUse()
if key == u"DANDELION": #如果是蒲公英
if mutation: #如果是突变
blockManager.addTableTimesOfMutation(blockId) #增加突变次数
world.spawnParticle(Particle.REVERSE_PORTAL, loc.add(Vector(0.5,0.9,0.5)), 100, 0.25, 0.06, 0.25, 0) #播放粒子
world.playSound(loc, Sound.ENTITY_PLAYER_LEVELUP, 0.5, 2.0) #播放声音
player = self.players[blockId] #获取玩家
message = u"§d[灵气] §e{} §a在{}§a成功召唤出 {} ".format(player.getName(), self.getTableName(blockId), itemManager.getItemDisplay(self.itemId[blockId])) #消息
playerManager = PlayerManager(player) #获取玩家管理器
playerManager.upgradeLuck()
playerManager.addTimesOfElement(self.element[blockId])
playerManager.addTimesOfMutation()
blockManager.addTableTimesOfMutation(blockId) #增加突变次数
blockManager.addTableTimesOfElement(blockId, self.element[blockId]) #增加元素次数
message = u"§d[灵气] §e{} §a在{}§a成功召唤出 {} §a".format(player.getName(), self.getTableName(blockId), itemManager.getItemDisplay(self.itemId[blockId])) #消息
getServer().broadcastMessage(message)
self.dropItem(blockId, self.itemId[blockId]) #掉落
else: #如果不是
self.dropItem(blockId, 1) #掉落
playerManager.setGetting(False) #结束获取
def spawnParticles(self, blockId, mutation=False):
if str(blockId) not in self.blockData.getKeys(False):
return False
@ -347,16 +383,21 @@ class BlockManager:
pro = (float(timesOfUse - timesOfMutation + 50) / float(timesOfUse + 100)) * 10 #计算
return pro
def getPlayerPro(self, player): #获取玩家概率
playerName = player.getName()
playerData = ps.config.loadConfig("reiki/player.yml")
timesOfUse = playerData.getInt("{}.timesOfUse".format(playerName), 0) #获取
timesOfMutation = playerData.getInt("{}.timesOfMutation".format(playerName), 0) #获取
pro = (float(timesOfUse - timesOfMutation + 50) / float(timesOfUse + 100)) * 10 #计算
luck = player.getPotionEffect(PotionEffectType.LUCK)
unluck = player.getPotionEffect(PotionEffectType.UNLUCK)
pro = 0.0
if luck is not None:
luckLevel = luck.getAmplifier() + 1 # 效果等级从 0 开始,所以加 1
luckBonus = min(luckLevel * 5, 50) # 幸运影响最多 +5
luckLevel = luck.getAmplifier() + 1
luckBonus = min(luckLevel * 2, 14)
pro += luckBonus
if unluck is not None:
unluckLevel = unluck.getAmplifier() + 1 # 效果等级从 0 开始,所以加 1
unluckPenalty = min(unluckLevel * 5, 50) # 霉运影响最多 -5
unluckLevel = unluck.getAmplifier() + 1
unluckPenalty = min(unluckLevel * 2, 14)
pro -= unluckPenalty
return pro
def getPro(self, player, blockId): #获取概率
@ -399,6 +440,365 @@ class PlayerManager:
self.player.addPotionEffect(PotionEffect(PotionEffectType.LUCK, 72000, luckLevel, True, False))
else:
self.player.addPotionEffect(PotionEffect(PotionEffectType.LUCK, 72000, 0, True, False))
def addTimesOfUse(self):
playerData = ps.config.loadConfig("reiki/player.yml")
timesOfUse = playerData.getInt("{}.timesOfUse".format(self.player.getName()), 0)
playerData.set("{}.timesOfUse".format(self.player.getName()), timesOfUse + 1)
playerData.save()
def addTimesOfMutation(self):
playerData = ps.config.loadConfig("reiki/player.yml")
timesOfMutation = playerData.getInt("{}.timesOfMutation".format(self.player.getName()), 0)
playerData.set("{}.timesOfMutation".format(self.player.getName()), timesOfMutation + 1)
playerData.save()
def addTimesOfElement(self, element=u"grass"):
if element.lower() not in ["grass", "fire", "water", "earth", "thunder", "ice", "wind"]: #若元素不存在
return False
playerData = ps.config.loadConfig("reiki/player.yml")
timesOfElement = playerData.getInt("{}.timesOf{}".format(self.player.getName(), element.lower()), 0)
playerData.set("{}.timesOf{}".format(self.player.getName(), element.lower()), timesOfElement + 1)
playerData.save()
def setGetting(self, value=True):
playerData = ps.config.loadConfig("reiki/player.yml")
playerData.set("{}.getting".format(self.player.getName()), value)
playerData.save()
class MenuReikiInfo(GUIController):# 单人房间菜单
def __init__(self, player, blockId):
super(MenuReikiInfo, self).__init__(player)
self.blockId = blockId
self.tableName = blockManager.getTableName(blockId)
self.setInfo("reiki.info", u"§0[灵气]{} 信息一览".format(self.tableName))
self.setGUIManager(guiManager)
def render(self):
player = self.getPlayer()
playerName = player.getName()
pro = blockManager.getPro(player, self.blockId)
todayPro = blockManager.getTodayPro()
playerPro = blockManager.getPlayerPro(player)
reikiPro = blockManager.getReikiTablePro(self.blockId)
playerData = ps.config.loadConfig("reiki/player.yml")
playerTimesOfUse = playerData.getInt("{}.timesOfUse".format(playerName), 0)
playerTimesOfMutation = playerData.getInt("{}.timesOfMutation".format(playerName), 0)
playerMutationPro = (float(playerTimesOfMutation) / float(playerTimesOfUse)) * 100 if playerTimesOfUse > 0 else 0
blockTimesOfUse = blockManager.blockData.getInt("{}.timesOfUse".format(self.blockId), 0)
blockTimesOfMutation = blockManager.blockData.getInt("{}.timesOfMutation".format(self.blockId), 0)
blockMutationPro = (float(blockTimesOfMutation) / float(blockTimesOfUse)) * 100 if blockTimesOfUse > 0 else 0
self.set(2, playerHeadsAPI.getPlayerHead(playerName), u"§b§l✟ §e§l召唤历史 §b§l✟",
u"§e个人总运势 §f{:.2f}% §7[{}/{}]".format(playerMutationPro, playerTimesOfMutation, playerTimesOfUse),
u"§e本台总运势 §f{:.2f}% §7[{}/{}]".format(blockMutationPro, blockTimesOfMutation, blockTimesOfUse))
self.set(4, Material.END_PORTAL_FRAME, u"§5§l☯ §d§l本台运势 §5§l☯",
u"§e当前运势 §f{:.2f}%".format(pro),
u"§f",
u"§e天时 §f{:.2f} §7[0, 10]".format(todayPro),
u"§e地利 §f{:.2f} §7[0, 10)".format(reikiPro),
u"§e人和 §f{:.2f} §7[0, 24)".format(playerPro),
u"§f",
u"§6>> §e点击查看所有灵气台信息 §6<<")
self.set(6, Material.DANDELION, u"§7§l✿ §a§l召唤物图鉴 §7§l✿",
u"§f",
u"§6>> §e点击查阅图鉴 §6<<")
self.set(19, Material.WHEAT_SEEDS, u"§7§l✿ §a§l草元素召唤次数 §7§l✿",
u"§a本台次数 §f{}§7/{}".format(blockManager.blockData.getInt("{}.timesOfgrass".format(self.blockId), 0), blockTimesOfMutation),
u"§a个人次数 §f{}§7/{}".format(playerData.getInt("{}.timesOfgrass".format(playerName), 0), playerTimesOfMutation))
self.set(20, Material.BLAZE_POWDER, u"§7§l✿ §c§l火元素召唤次数 §7§l✿",
u"§c本台次数 §f{}§7/{}".format(blockManager.blockData.getInt("{}.timesOffire".format(self.blockId), 0),blockTimesOfMutation),
u"§c个人次数 §f{}§7/{}".format(playerData.getInt("{}.timesOffire".format(playerName), 0), playerTimesOfMutation))
self.set(21, Material.HEART_OF_THE_SEA, u"§7§l✿ §3§l水元素召唤次数 §7§l✿",
u"§3本台次数 §f{}§7/{}".format(blockManager.blockData.getInt("{}.timesOfwater".format(self.blockId), 0),blockTimesOfMutation),
u"§3个人次数 §f{}§7/{}".format(playerData.getInt("{}.timesOfwater".format(playerName), 0), playerTimesOfMutation))
self.set(22, Material.COCOA_BEANS, u"§7§l✿ §6§l地元素召唤次数 §7§l✿",
u"§6本台次数 §f{}§7/{}".format(blockManager.blockData.getInt("{}.timesOfearth".format(self.blockId), 0),blockTimesOfMutation),
u"§6个人次数 §f{}§7/{}".format(playerData.getInt("{}.timesOfearth".format(playerName), 0), playerTimesOfMutation))
self.set(23, Material.NETHER_STAR, u"§7§l✿ §e§l雷元素召唤次数 §7§l✿",
u"§e本台次数 §f{}§7/{}".format(blockManager.blockData.getInt("{}.timesOfthunder".format(self.blockId), 0),blockTimesOfMutation),
u"§e个人次数 §f{}§7/{}".format(playerData.getInt("{}.timesOfthunder".format(playerName), 0), playerTimesOfMutation))
self.set(24, Material.SNOWBALL, u"§7§l✿ §b§l冰元素召唤次数 §7§l✿",
u"§b本台次数 §f{}§7/{}".format(blockManager.blockData.getInt("{}.timesOfice".format(self.blockId), 0),blockTimesOfMutation),
u"§b个人次数 §f{}§7/{}".format(playerData.getInt("{}.timesOfice".format(playerName), 0), playerTimesOfMutation))
self.set(25, Material.FEATHER, u"§7§l✿ §f§l风元素召唤次数 §7§l✿",
u"§f本台次数 §f{}§7/{}".format(blockManager.blockData.getInt("{}.timesOfwind".format(self.blockId), 0),blockTimesOfMutation),
u"§f个人次数 §f{}§7/{}".format(playerData.getInt("{}.timesOfwind".format(playerName), 0), playerTimesOfMutation))
self.spawnSeparators(0, 18, vertical=True)
self.spawnSeparators(8, 26, vertical=True)
def onClick(self, e):
e.setCancelled(True)
clickInt = e.getSlot()
player = self.getPlayer()
if clickInt == 4:
MenuReikiTable(player).openWithRender()
player.playSound(player, Sound.ITEM_BOOK_PAGE_TURN, 1.0, 1.0)
elif clickInt == 6:
MenuItems(player).openWithRender()
player.playSound(player, Sound.ITEM_BOOK_PAGE_TURN, 1.0, 1.0)
class MenuItems(GUIController):# 物品图鉴
def __init__(self, player, page=1, element=u"none"):
super(MenuItems, self).__init__(player)
self.page = page
self.element = element
self.setInfo("reiki.items", u"§0[灵气]召唤物图鉴 第{}".format(self.page))
self.setGUIManager(guiManager)
def render(self):
player = self.getPlayer()
playerName = player.getName()
if self.element.lower() == u"none":
items = list(itemManager.getAllItems())
elif self.element.lower() == u"grass":
items = list(itemManager.grassItems)
elif self.element.lower() == u"fire":
items = list(itemManager.fireItems)
elif self.element.lower() == u"water":
items = list(itemManager.waterItems)
elif self.element.lower() == u"earth":
items = list(itemManager.earthItems)
elif self.element.lower() == u"thunder":
items = list(itemManager.thunderItems)
elif self.element.lower() == u"ice":
items = list(itemManager.iceItems)
elif self.element.lower() == u"wind":
items = list(itemManager.windItems)
else:
items = list(itemManager.getAllItems())
itemsPerPage = 45 # 每页显示 45 个物品,最后一行用于控制
self.totalPages = (len(items) + itemsPerPage - 1) // itemsPerPage
startIndex = (self.page - 1) * itemsPerPage
endIndex = startIndex + itemsPerPage
currentPageItems = items[startIndex:endIndex]
for index, itemNumber in enumerate(currentPageItems):
item = itemManager.getItemstack(itemNumber)
display = itemManager.getItemDisplay(itemNumber)
if item is None:
item = Material.PAPER
self.set(index, item, display, data=itemNumber)
self.spawnSeparators(45, 53) # 填充最后一行默认黑色染色玻璃板
if self.page > 1:
self.set(45, Material.WHITE_STAINED_GLASS_PANE, u"§a上一页") # 上一页按钮
self.set(46, Material.WHEAT_SEEDS, u"§6>> §a§l查看草元素召唤物 §6<<")
self.set(47, Material.BLAZE_POWDER, u"§6>> §c§l查看火元素召唤物 §6<<")
self.set(48, Material.HEART_OF_THE_SEA, u"§6>> §3§l查看水元素召唤物 §6<<")
self.set(49, Material.COCOA_BEANS, u"§6>> §6§l查看地元素召唤物 §6<<")
self.set(50, Material.NETHER_STAR, u"§6>> §e§l查看雷元素召唤物 §6<<")
self.set(51, Material.SNOWBALL, u"§6>> §b§l查看冰元素召唤物 §6<<")
self.set(52, Material.FEATHER, u"§6>> §f§l查看风元素召唤物 §6<<")
if self.page < self.totalPages:
self.set(53, Material.WHITE_STAINED_GLASS_PANE, u"§a下一页") # 下一页按钮
# 记录玩家当前页码和筛选设置
playerPage[playerName] = {
"page": self.page,
"element": self.element
}
def onClick(self, e):
e.setCancelled(True)
clickInt = e.getSlot()
player = self.getPlayer()
playerName = player.getName()
playerPageInfo = playerPage.get(playerName, {"page": 1, "element": "none"})
currentPage = playerPageInfo["page"]
element = playerPageInfo["element"]
if clickInt == 45 and currentPage > 1:
MenuItems(player, page=currentPage - 1, element=element).openWithRender()
player.playSound(player, Sound.ITEM_BOOK_PAGE_TURN, 1.0, 1.0)
elif clickInt == 46:
MenuItems(player, page=1, element="grass").openWithRender()
player.playSound(player, Sound.ITEM_BOOK_PAGE_TURN, 1.0, 1.0)
elif clickInt == 47:
MenuItems(player, page=1, element="fire").openWithRender()
player.playSound(player, Sound.ITEM_BOOK_PAGE_TURN, 1.0, 1.0)
elif clickInt == 48:
MenuItems(player, page=1, element="water").openWithRender()
player.playSound(player, Sound.ITEM_BOOK_PAGE_TURN, 1.0, 1.0)
elif clickInt == 49:
MenuItems(player, page=1, element="earth").openWithRender()
player.playSound(player, Sound.ITEM_BOOK_PAGE_TURN, 1.0, 1.0)
elif clickInt == 50:
MenuItems(player, page=1, element="thunder").openWithRender()
player.playSound(player, Sound.ITEM_BOOK_PAGE_TURN, 1.0, 1.0)
elif clickInt == 51:
MenuItems(player, page=1, element="ice").openWithRender()
player.playSound(player, Sound.ITEM_BOOK_PAGE_TURN, 1.0, 1.0)
elif clickInt == 52:
MenuItems(player, page=1, element="wind").openWithRender()
player.playSound(player, Sound.ITEM_BOOK_PAGE_TURN, 1.0, 1.0)
elif clickInt == 53 and currentPage < self.totalPages:
MenuItems(player, page=currentPage + 1, element=element).openWithRender()
player.playSound(player, Sound.ITEM_BOOK_PAGE_TURN, 1.0, 1.0)
elif clickInt < 45:
if player.isOp():
item = e.getCurrentItem()
if item is not None:
guiValue = getGUIValue(item)
if guiValue:
itemId = guiValue
inv = player.getInventory()
if inv.firstEmpty() == -1: #如果背包满了
player.sendMessage(u"§d[灵气]§c背包已满无法获取召唤物")
player.playSound(player, Sound.ENTITY_VILLAGER_NO, 1.0, 1.0)
return
else:
player.getInventory().addItem(itemManager.getItemstack(itemId))
player.sendMessage(u"§d[灵气]§f成功获取 {}".format(itemManager.getItemDisplay(itemId)))
player.playSound(player, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0, 1.0)
class MenuReikiTable(GUIController):# 灵气台
def __init__(self, player, page=1):
super(MenuReikiTable, self).__init__(player)
self.page = page
self.setInfo("reiki.table", u"§0[灵气]灵气台 第{}".format(self.page))
self.setGUIManager(guiManager)
def render(self):
player = self.getPlayer()
playerName = player.getName()
blocks = list(blockManager.blockData.getKeys(False))
blocksLoc = {}
playerIsOP = player.isOp()
for id in blocks: #移除没有的台并记录坐标
blockLoc = blockManager.getTableLoc(id)
if blockLoc is None:
blocks.remove(id)
else:
blocksLoc[id] = blockLoc
blocksPerPage = 45 # 每页显示 45 个物品,最后一行用于控制
self.totalPages = (len(blocks) + blocksPerPage - 1) // blocksPerPage
startIndex = (self.page - 1) * blocksPerPage
endIndex = startIndex + blocksPerPage
currentPageBlocks = blocks[startIndex:endIndex]
for index, blockId in enumerate(currentPageBlocks):
blockLoc = blocksLoc[blockId]
display = blockManager.getTableName(blockId)
reikiTablePro = blockManager.getReikiTablePro(blockId)
blockX = blockLoc.getBlockX()
blockY = blockLoc.getBlockY()
blockZ = blockLoc.getBlockZ()
lores = [
u"§e坐标 §f{}, §f{}, §f{}".format(blockX, blockY, blockZ),
u"§e地利 §f{:.2f}".format(reikiTablePro)
]
if playerIsOP:
grass = blockManager.blockData.getInt("{}.grass".format(blockId), 0)
fire = blockManager.blockData.getInt("{}.fire".format(blockId), 0)
water = blockManager.blockData.getInt("{}.water".format(blockId), 0)
earth = blockManager.blockData.getInt("{}.earth".format(blockId), 0)
thunder = blockManager.blockData.getInt("{}.thunder".format(blockId), 0)
ice = blockManager.blockData.getInt("{}.ice".format(blockId), 0)
wind = blockManager.blockData.getInt("{}.wind".format(blockId), 0)
lores.append(u"§8- 以下信息仅管理员可见")
lores.append(u"§6ID §f{}".format(blockId))
lores.append(u"§6元素值 §a草{} §c火{} §3水{} §6地{} §e雷{} §b冰{} §f风{}".format(grass, fire, water, earth, thunder, ice, wind))
lores.append(u"§6")
lores.append(u"§6>> 点击传送至该灵气台 <<")
self.set(index, Material.END_PORTAL_FRAME, u"§a§l{}".format(display), *lores, data=blockId)
self.spawnSeparators(45, 53) # 填充最后一行默认黑色染色玻璃板
if self.page > 1:
self.set(45, Material.WHITE_STAINED_GLASS_PANE, u"§a上一页") # 上一页按钮
if self.page < self.totalPages:
self.set(53, Material.WHITE_STAINED_GLASS_PANE, u"§a下一页") # 下一页按钮
# 记录玩家当前页码
playerPage[playerName] = {
"page": self.page
}
def onClick(self, e):
e.setCancelled(True)
clickInt = e.getSlot()
player = self.getPlayer()
playerName = player.getName()
playerPageInfo = playerPage.get(playerName, {"page": 1})
currentPage = playerPageInfo["page"]
if clickInt == 45 and currentPage > 1:
MenuReikiTable(player, page=currentPage - 1).openWithRender()
player.playSound(player, Sound.ITEM_BOOK_PAGE_TURN, 1.0, 1.0)
elif clickInt == 53 and currentPage < self.totalPages:
MenuReikiTable(player, page=currentPage + 1).openWithRender()
player.playSound(player, Sound.ITEM_BOOK_PAGE_TURN, 1.0, 1.0)
elif clickInt < 45:
if player.isOp(): #OP传送
item = e.getCurrentItem()
if item is not None:
guiValue = getGUIValue(item)
if guiValue:
blockId = guiValue
blockLoc = blockManager.getTableLoc(blockId)
if blockLoc is None:
player.sendMessage(u"§d[灵气]§c该灵气台不存在或已被移除")
player.playSound(player, Sound.ENTITY_VILLAGER_NO, 1.0, 1.0)
return
player.teleport(blockLoc)
player.sendMessage(u"§d[灵气]§f成功前往 {}".format(blockManager.getTableName(blockId)))
player.playSound(player, Sound.ENTITY_ENDERMAN_TELEPORT, 1.0, 1.0)
def onInventoryClick(e): # 菜单点击
player = e.getWhoClicked()
worldName = player.getWorld().getName()
if worldName != WORLD_NAME:
return
inv = e.getClickedInventory()
if inv is None:
return
invHolder = inv.getHolder()
if isGUI(invHolder):
guiManager.get(e.getWhoClicked(), e.getClickedInventory().getHolder().getName()).onClick(e) # 菜单控制
return
cancelShiftClickFromPlayerInventory(e)
def onInventoryClose(e): # 菜单关闭
inv = e.getInventory()
if isGUI(inv.getHolder()):
guiManager.remove(e.getPlayer()) # 关闭菜单时清空存储的控制器
def stop(): # 程序卸载时
closeGuiForAll() # 关菜单
ps.listener.registerListener(onInventoryClick, InventoryClickEvent)
ps.listener.registerListener(onInventoryClose, InventoryCloseEvent)
ps.listener.registerListener(denyAllInventoryDrag, InventoryDragEvent)
def onPlayerInteract(event):
player = event.getPlayer()
worldName = player.getWorld().getName()
if worldName != WORLD_NAME:
return False
if event.getHand() == EquipmentSlot.OFF_HAND: #禁止副手触发
return False
clickedBlock = event.getClickedBlock()
if clickedBlock is None: #防止空指针
return False
if clickedBlock.getType() != Material.END_PORTAL_FRAME: #判断是否是灵气台
return False
blockLoc = clickedBlock.getLocation()
blockX = blockLoc.getBlockX()
blockY = blockLoc.getBlockY()
blockZ = blockLoc.getBlockZ()
blockId = None
for id in blockManager.blockData.getKeys(False):
x = blockManager.blockData.getInt("{}.x".format(id))
if blockX == x:
y = blockManager.blockData.getInt("{}.y".format(id))
if blockY == y:
z = blockManager.blockData.getInt("{}.z".format(id))
if blockZ == z:
blockId = id
break
if blockId is None:
return False
playerManager = PlayerManager(player)
item = event.getItem()
guiValue = getGUIValue(item)
if guiValue is not None:
reiki, key = guiValue.split(':')
if reiki == u"reiki":
if key == u"DANDELION":
result = playerManager.reikiCall(blockId, key)
if result:
item.setAmount(item.getAmount()-1)
return
MenuReikiInfo(player, blockId).openWithRender()
ps.listener.registerListener(onPlayerInteract, PlayerInteractEvent)
def reikiCommand(sender, label, args):
if isinstance(sender, Player):
if sender.isOp():
@ -407,9 +807,15 @@ def reikiCommand(sender, label, args):
return False
playerManager = PlayerManager(sender)
if len(args) < 1:
sender.sendMessage(u"§d[灵气]§f请输入参数")
sender.sendMessage(u"§d[灵气] §a管理员命令帮助")
sender.sendMessage(u"§d[灵气] §f/reiki add §e- 创建灵气台")
sender.sendMessage(u"§d[灵气] §f/reiki del §e- 删除灵气台")
sender.sendMessage(u"§d[灵气] §f/reiki list §e- 查看所有灵气台")
sender.sendMessage(u"§d[灵气] §f/reiki item §e- 查看所有召唤物")
sender.sendMessage(u"§d[灵气] §f/reiki set element <元素名> <值> §e- 设置灵气台元素值")
sender.sendMessage(u"§d[灵气] §f/reiki set name <名称> §e- 设置灵气台名称")
return False
elif args[0] == u"add":
elif args[0] == u"add": #目视传送门框架,创建灵气台
blockLoc = playerManager.getTargetFrameLocation()
if blockLoc is not None:
blockId = blockManager.createReikiTable(blockLoc)
@ -422,7 +828,7 @@ def reikiCommand(sender, label, args):
else:
sender.sendMessage(u"§d[灵气]§f请看着一个末地传送门框架")
return False
elif args[0] == u"del":
elif args[0] == u"del": #目视传送门框架,删除灵气台
blockLoc = playerManager.getTargetFrameLocation()
if blockLoc is not None:
blockId = blockManager.getLocTable(blockLoc)
@ -440,51 +846,12 @@ def reikiCommand(sender, label, args):
sender.sendMessage(u"§d[灵气]§f请看着一个末地传送门框架")
return False
elif args[0] == u"list":
try:
page = int(args[1]) if len(args) > 1 else 1
except ValueError:
sender.sendMessage(u"§d[灵气]§f页数参数必须是整数")
MenuReikiTable(sender).openWithRender()
return True
pageSize = 10
blockIds = list(blockManager.blockData.getKeys(False))
startIndex = (page - 1) * pageSize
endIndex = startIndex + pageSize
totalPages = (len(blockIds) + pageSize - 1) // pageSize
if startIndex >= len(blockIds):
sender.sendMessage(u"§d[灵气]§f指定的页数不存在")
elif args[0] == u"item":
MenuItems(sender).openWithRender()
return True
sender.sendMessage(u"§d[灵气]§f当前灵气台列表 (第 {} 页,共 {} 页):".format(page, totalPages))
for blockId in blockIds[startIndex:endIndex]:
blockLoc = blockManager.getTableLoc(blockId)
blockX = blockLoc.getBlockX()
blockY = blockLoc.getBlockY()
blockZ = blockLoc.getBlockZ()
blockName = blockManager.getTableName(blockId)
# 获取元素值
elements = ["grass", "fire", "water", "earth", "thunder", "ice", "wind"]
elementValues = {}
for element in elements:
value = blockManager.getTableElement(blockId, element)
if value is None:
value = 0
elementValues[element] = value
elementStr = " ".join([u"{}:{}".format(elem, val) for elem, val in elementValues.items()])
sender.sendMessage(u"§d[灵气]§fID: §e{} §f位置: §e({},{},{}) §f名称: §e{} \n§f元素值: §e{}".format(blockId, blockX, blockY, blockZ, blockName, elementStr))
return True
elif args[0] == u"getitem":
if len(args) > 1:
itemId = args[1]
if str(itemId) not in itemManager.itemsData.getKeys(False):
sender.sendMessage(u"§d[灵气]§f未找到该道具")
return False
itemstack = itemManager.getItemstack(itemId)
sender.getInventory().addItem(itemstack)
sender.sendMessage(u"§d[灵气]§f成功获取道具")
return True
elif args[0] == u"set":
elif args[0] == u"set": #目视传送门框架,设置灵气台
if len(args) > 2:
blockLoc = playerManager.getTargetFrameLocation()
if blockLoc is not None:
@ -532,61 +899,3 @@ def reikiCommand(sender, label, args):
return False
return False
ps.command.registerCommand(reikiCommand, "reiki")
def onPlayerInteract(event):
player = event.getPlayer()
worldName = player.getWorld().getName()
if worldName != WORLD_NAME:
return False
if event.getHand() == EquipmentSlot.OFF_HAND: #禁止副手触发
return False
clickedBlock = event.getClickedBlock()
if clickedBlock is None: #防止空指针
return False
if clickedBlock.getType() != Material.END_PORTAL_FRAME: #判断是否是灵气台
return False
blockLoc = clickedBlock.getLocation()
blockX = blockLoc.getBlockX()
blockY = blockLoc.getBlockY()
blockZ = blockLoc.getBlockZ()
blockId = None
for id in blockManager.blockData.getKeys(False):
x = blockManager.blockData.getInt("{}.x".format(id))
if blockX == x:
y = blockManager.blockData.getInt("{}.y".format(id))
if blockY == y:
z = blockManager.blockData.getInt("{}.z".format(id))
if blockZ == z:
blockId = id
break
if blockId is None:
return False
playerManager = PlayerManager(player)
item = event.getItem()
guiValue = getGUIValue(item)
if guiValue is not None:
reiki, key = guiValue.split(':')
if reiki == u"reiki":
if key == u"DANDELION":
result = playerManager.reikiCall(blockId, key)
if result:
item.setAmount(item.getAmount()-1)
return
name = blockManager.getTableName(blockId)
if player.isOp():
elements = ["grass", "fire", "water", "earth", "thunder", "ice", "wind"]
weights = {}
for element in elements:
value = blockManager.getTableElement(blockId, element)
if value is None:
value = 0
weights[element] = value
player.sendMessage(u"§d[灵气]§a{}元素值§a草{} §c火{} §3水{} §6土{} §e雷{} §b冰{} §f风{}".format(name,
weights["grass"], weights["fire"], weights["water"], weights["earth"],
weights["thunder"], weights["ice"], weights["wind"]))
pro = blockManager.getPro(player, blockId)
todayPro = blockManager.getTodayPro()
playerPro = blockManager.getPlayerPro(player)
reikiPro = blockManager.getReikiTablePro(blockId)
player.sendMessage(u"§d[灵气]§a{}运势§f{:.2f}%§7[天时{:.2f}|地利{:.2f}|人和{:.2f}]".format(name, pro, todayPro, reikiPro, playerPro))
ps.listener.registerListener(onPlayerInteract, PlayerInteractEvent)