Skip to content
This repository has been archived by the owner on Nov 19, 2021. It is now read-only.

Commit

Permalink
1.0.1
Browse files Browse the repository at this point in the history
1.0.1
  • Loading branch information
耗子 authored Jul 19, 2020
1 parent 311692f commit 651dc66
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 105 deletions.
134 changes: 34 additions & 100 deletions Fz-sDatapackImporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ def saveJson(self, filePath, configObject):
def saveDefaultConfig(self):
defaultConfig = {
'global': {
'mode': 'whitelist'
'commandPrefix': '!!fdi',
'mode': 'whitelist',
'serverPath': '/server',
'worldName': 'world'
},
'commandPermissions': {
'help': 0,
Expand All @@ -30,7 +33,8 @@ def getSelfName(self):
return os.path.basename(__file__).replace(".py", "")

def getPlayerStatsData(self, uuid, classification, target):
uuidFilePath = './server/world/stats/{}.json'.format(uuid)
config = self.loadJson('./plugins/{}/config.json'.format(self.getSelfName()))
uuidFilePath = '.{}/{}/stats/{}.json'.format(config['global']['serverPath'], config['global']['worldName'], uuid)
if (os.path.isfile(uuidFilePath)):
data = self.loadJson(uuidFilePath)
if ('minecraft:{}'.format(classification) in data['stats']):
Expand All @@ -39,8 +43,9 @@ def getPlayerStatsData(self, uuid, classification, target):
return None

def refreshUUID(self):
config = self.loadJson('./plugins/{}/config.json'.format(self.getSelfName()))
for i in {'usercache', 'whitelist'}:
t = self.loadJson('./server/{}.json'.format(i))
t = self.loadJson('.{}/{}.json'.format(config['global']['serverPath'], i))
r = {}
for k in t:
r[k['name']] = k['uuid']
Expand All @@ -61,135 +66,64 @@ def loadUUID(self):
else:
return None

def syncKillCounter(self, server):
def __sync(self, server, classification, targetList, scoreboardOjbect, totalScoreName, isAct = False):
r = self.loadUUID()
if (r):
total = 0
for i in r:
data = 0
for k in {'mob_kills', 'player_kills'}:
if(self.getPlayerStatsData(r[i], 'custom', k)):
data += self.getPlayerStatsData(r[i], 'custom', k)
server.execute('scoreboard players set {} {} {}'.format(i, 'killCounter', data))
total = total + data
server.execute('scoreboard players set {} {} {}'.format('总击杀数', 'totalList', total))
for k in targetList:
if(self.getPlayerStatsData(r[i], classification, k)):
data += self.getPlayerStatsData(r[i], classification, k)
if (isAct):
server.execute('scoreboard players set {} {} {}'.format(i, 'actCounter', data % 72000))
server.execute('scoreboard players set {} {} {}'.format(i, 'activation', data // 72000))
total = total + data // 72000
else:
server.execute('scoreboard players set {} {} {}'.format(i, scoreboardOjbect, data))
total = total + data
server.execute('scoreboard players set {} {} {}'.format(totalScoreName, 'totalList', total))
return True
else:
return False

def syncKillCounter(self, server):
return self.__sync(server, 'custom', {'mob_kills', 'player_kills'}, 'killCounter', '总击杀数')

def syncDigCounter(self, server):
r = self.loadUUID()
if (r):
total = 0
for i in r:
data = 0
for k in {'diamond_axe', 'diamond_pickaxe', 'diamond_shovel', 'iron_axe', 'iron_pickaxe', 'iron_shovel', 'stone_axe', 'stone_pickaxe', 'stone_shovel'}:
if(self.getPlayerStatsData(r[i], 'used', k)):
data += self.getPlayerStatsData(r[i], 'used', k)
server.execute('scoreboard players set {} {} {}'.format(i, 'digCounter', data))
total = total + data
server.execute('scoreboard players set {} {} {}'.format('总挖掘数', 'totalList', total))
return True
else:
return False
return self.__sync(server,'used', {'diamond_axe', 'diamond_pickaxe', 'diamond_shovel', 'iron_axe', 'iron_pickaxe', 'iron_shovel', 'stone_axe', 'stone_pickaxe', 'stone_shovel'}, 'digCounter', '总挖掘数')

def syncDeathCounter(self, server):
r = self.loadUUID()
if (r):
total = 0
for i in r:
data = 0
for k in {'deaths'}:
if(self.getPlayerStatsData(r[i], 'custom', k)):
data += self.getPlayerStatsData(r[i], 'custom', k)
server.execute('scoreboard players set {} {} {}'.format(i, 'deathCounter', data))
total = total + data
server.execute('scoreboard players set {} {} {}'.format('总死亡数', 'totalList', total))
return True
else:
return False
return self.__sync(server, 'custom', {'deaths'}, 'deathCounter', '总死亡数')

def syncTradingCounter(self, server):
r = self.loadUUID()
if (r):
total = 0
for i in r:
data = 0
for k in {'traded_with_villager'}:
if(self.getPlayerStatsData(r[i], 'custom', k)):
data += self.getPlayerStatsData(r[i], 'custom', k)
server.execute('scoreboard players set {} {} {}'.format(i, 'tradingCounter', data))
total = total + data
server.execute('scoreboard players set {} {} {}'.format('总交易数', 'totalList', total))
return True
else:
return False
return self.__sync(server, 'custom', {'traded_with_villager'}, 'tradingCounter', '总交易数')

def syncFishingCounter(self, server):
r = self.loadUUID()
if (r):
total = 0
for i in r:
data = 0
for k in {'fish_caught'}:
if(self.getPlayerStatsData(r[i], 'custom', k)):
data += self.getPlayerStatsData(r[i], 'custom', k)
server.execute('scoreboard players set {} {} {}'.format(i, 'fishingCounter', data))
total = total + data
server.execute('scoreboard players set {} {} {}'.format('总钓鱼数', 'totalList', total))
return True
else:
return False
return self.__sync(server, 'custom', {'fish_caught'}, 'fishingCounter', '总钓鱼数')

def syncDamageTaken(self, server):
r = self.loadUUID()
if (r):
total = 0
for i in r:
data = 0
for k in {'damage_taken'}:
if(self.getPlayerStatsData(r[i], 'custom', k)):
data += self.getPlayerStatsData(r[i], 'custom', k)
server.execute('scoreboard players set {} {} {}'.format(i, 'damageTaken', data))
total = total + data
server.execute('scoreboard players set {} {} {}'.format('总受伤害量', 'totalList', total))
return True
else:
return False
return self.__sync(server, 'custom', {'damage_taken'}, 'damageTaken', '总受伤害量')

def syncActCounter(self, server):
r = self.loadUUID()
if (r):
total = 0
for i in r:
data = 0
for k in {'play_one_minute'}:
if(self.getPlayerStatsData(r[i], 'custom', k)):
data += self.getPlayerStatsData(r[i], 'custom', k)
server.execute('scoreboard players set {} {} {}'.format(i, 'actCounter', data % 72000))
server.execute('scoreboard players set {} {} {}'.format(i, 'activation', data // 72000))
total = total + data // 72000
server.execute('scoreboard players set {} {} {}'.format('总活跃时间', 'totalList', total))
return True
else:
return False
return self.__sync(server, 'custom', {'play_one_minute'}, None, '总活跃时间', True)

def on_info(server, info):
p = fzsDatapackImporter()
p.checkConfig()
config = p.loadJson('./plugins/{}/config.json'.format(p.getSelfName()))
args = info.content.split(' ')
arglen = len(args)
if (args[0] == '!!fdi'):
if (args[0] == config['global']['commandPrefix']):
if (arglen > 1 and args[1] in config['commandPermissions']):
if (server.get_permission_level(info) < config['commandPermissions'][args[1]]):
server.reply(info, '§aFDI §7>> §c你没有使用该命令的权限!')
return

elif (args[1] == 'help' and arglen == 2):
server.reply(info, '§a!!fdi help §7- §e获取帮助')
server.reply(info, '§a!!fdi refresh §7- §e刷新uuid缓存')
server.reply(info, '§a!!fdi process [榜单] §7- §e执行同步')
server.reply(info, '§a{} help §7- §e获取帮助'.format(config['global']['commandPrefix']))
server.reply(info, '§a{} refresh §7- §e刷新uuid缓存'.format(config['global']['commandPrefix']))
server.reply(info, '§a{} process [榜单] §7- §e执行同步'.format(config['global']['commandPrefix']))

elif (args[1] == 'refresh' and arglen == 2):
p.refreshUUID()
Expand Down Expand Up @@ -246,4 +180,4 @@ def on_info(server, info):

def on_load(server, old_module):
fzsDatapackImporter().checkConfig()
server.add_help_message('!!fdi help', '哈尔威数据包积分榜数据同步')
server.add_help_message('!!fdi help', '哈尔威数据包计分榜数据同步')
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Fz-sDatapackImporter
一个用于将stats数据同步到Fz-sDatapack记分版的 MCDR 插件
适用于未在开服时未及时安装 Fz-sDatapack 但希望能够同步数据的场景
一个用于将stats数据同步到由 [哈尔威](https://github.com/Harveykang/)制作的[Fz-sDatapack](https://github.com/Harveykang/FZ-sDataPack) 记分版的 MCDR 插件
适用于未在开服时未及时安装 [Fz-sDatapack](https://github.com/Harveykang/FZ-sDataPack) 但希望能够同步数据的场景

本插件支持 从 usercache.json 或 whitelist.json 中载入玩家 uuid

Expand All @@ -11,7 +11,10 @@
会在插件同目录下生成配置文件夹, 编辑config.json
|设置选项|描述|默认值|可选择的值|
|-----|-----|-----|-----|
|global.mode|同步数据使用的 uuid 来源|whitelist|whitelist, usercache|
|global.commandPrefix|根命令|"!!fdi"| |
|global.mode|同步数据使用的 uuid 来源|"whitelist"|"whitelist", "usercache"|
|global.serverPath|服务端与 MCDR 根目录的相对路径|"/server"| |
|global.worldName|包含 stats 的世界名称|"world"| |
|commandPermissions.help|!!fdi help 命令权限|0|0,1,2,3,4|
|commandPermissions.refresh|!!fdi refresh 命令权限|3|0,1,2,3,4|
|commandPermissions.process|!!fdi process 命令权限|3|0,1,2,3,4|
Expand All @@ -24,6 +27,7 @@
|!!fdi help| 插件帮助信息|
|!!fdi refresh| 刷新 uuid 缓存|
|!!fdi process [榜单]| 执行刷新|
*其中根命令 !!fdi 可以通过配置文件修改

### 榜单可用的值
|参数|描述|
Expand All @@ -37,5 +41,7 @@
|activation|活跃度排行|

## 下一步计划
1. 优化冗余代码
2. 将服务端路径添加到配置文件
~~1. 优化冗余代码~~
~~2. 将服务端路径添加到配置文件~~
3. 通过 Rtext 点选进行同步
4. 可以自动删除计分板数据并导入

0 comments on commit 651dc66

Please sign in to comment.