服务器好友系统

Ganxiaozhe
2019/07/19

未经作者授权,禁止转载

服务器原版好友系统,玩家可指定用户进行添加好友,好友添加为双向添加,发起方与接受方好友列表都会出现对方。添加后玩家可进行好友间直接传送或者权限共享之类的。

我的世界原版好友系统

如上图,玩家可随时查看自己的好友列表。发起好友申请后对方会收到相应信息,可决定同意或拒绝申请。同意后双方好友列表会自动新增双方,好友位支持无序错开。



原理

trigger技术、uid分配(玩家唯一标识)。

UID分配主要是为了指定玩家。如果你服务器已经做了uid分配,则只需把系统中计分项uid改为你的计分项即可。

该系统为了降低内存占用,全为低频循环激活,即每1s执行一次。代码中cond:意思为该行指令为条件制约。



代码

好友管理初始化:

  1. /scoreboard objectives add friPro trigger
  2. /scoreboard objectives add friLTemp dummy
  3. /scoreboard objectives add friLS1 dummy
  4. /scoreboard objectives add friLS2 dummy
  5. /scoreboard objectives add friLS3 dummy
  6. /scoreboard objectives add friLS4 dummy
  7. /scoreboard objectives add friLS5 dummy
  8. /scoreboard objectives add friLS6 dummy

UID分配 [建议高频]:

  1. scoreboard objectives add uid dummy
  2. scoreboard players add @a uid 0
  3. execute @p[score_uid_min=0,score_uid=0] ~ ~ ~ scoreboard players add UIDStats uid 1
  4. execute @p[score_uid_min=0,score_uid=0] ~ ~ ~ scoreboard players operation @s uid = UIDStats uid

好友列表补丁:

  1. /scoreboard players add @a friLS1 0
  2. /scoreboard players add @a friLS2 0
  3. /scoreboard players add @a friLS3 0
  4. /scoreboard players add @a friLS4 0
  5. /scoreboard players add @a friLS5 0
  6. /scoreboard players add @a friLS6 0
  7. /scoreboard players set @a[score_friLS1_min=0,score_friLS1=0] friLS1 -1
  8. /scoreboard players set @a[score_friLS2_min=0,score_friLS2=0] friLS2 -1
  9. /scoreboard players set @a[score_friLS3_min=0,score_friLS3=0] friLS3 -1
  10. /scoreboard players set @a[score_friLS4_min=0,score_friLS4=0] friLS4 -1
  11. /scoreboard players set @a[score_friLS5_min=0,score_friLS5=0] friLS5 -1
  12. /scoreboard players set @a[score_friLS6_min=0,score_friLS6=0] friLS6 -1

好友管理处理与好友列表输出:

  1. /scoreboard players add @a friPro 0
  2. /scoreboard players enable @a[score_friPro_min=0,score_friPro=0] friPro
  3. /scoreboard players set numTest friPro 0
  4. /execute @a[score_friPro_min=1] ~ ~ ~ scoreboard players add numTest friPro 1
  5. /scoreboard players test numTest friPro 2 *
  6. cond:/tellraw @a[score_friPro_min=1] ["\u00a76\u00a7l[好友管理] \u00a7c\u00a7l当前系统使用人数过多,请稍后再试。"]
  7. cond:/scoreboard players set @a[score_friPro_min=1] friPro 0
  8. /tellraw @a[score_friPro_min=1,score_friPro=1] ["\n\u00a7e\u00a7l=========+>> \u00a76\u00a7l☕好友列表☕ \u00a7e\u00a7l<<+========="]
  9. /tellraw @a[score_friPro_min=1,score_friPro=1,tag=!friL1] ["\u00a7c\u00a7l[好友位1] \u00a7e\u00a7l➾ \u00a77虚以代位"]
  10. /execute @a[score_friPro_min=1,score_friPro=1,tag=friL1] ~ ~ ~ scoreboard players reset @a friLTemp
  11. /execute @a[score_friPro_min=1,score_friPro=1,tag=friL1] ~ ~ ~ execute @a[rm=0] ~ ~ ~ scoreboard players operation @s friLTemp = @p[score_friPro_min=1,score_friPro=1] friLS1
  12. /execute @a[score_friLTemp_min=1] ~ ~ ~ scoreboard players operation @s friLTemp -= @s uid
  13. /tellraw @a[score_friPro_min=1,score_friPro=1,tag=friL1] ["\u00a7c\u00a7l[好友位1] \u00a7e\u00a7l➾ ",{"selector":"@a[score_friLTemp_min=0,score_friLTemp=0]"}," \u00a77[未在线则不显示其ID]"]
  14. /tellraw @a[score_friPro_min=1,score_friPro=1,tag=!friL2] ["\u00a7c\u00a7l[好友位2] \u00a7e\u00a7l➾ \u00a77虚以代位"]
  15. /execute @a[score_friPro_min=1,score_friPro=1,tag=friL2] ~ ~ ~ scoreboard players reset @a friLTemp
  16. /execute @a[score_friPro_min=1,score_friPro=1,tag=friL2] ~ ~ ~ execute @a[rm=0] ~ ~ ~ scoreboard players operation @s friLTemp = @p[score_friPro_min=1,score_friPro=1] friLS2
  17. /execute @a[score_friLTemp_min=1] ~ ~ ~ scoreboard players operation @s friLTemp -= @s uid
  18. /tellraw @a[score_friPro_min=1,score_friPro=1,tag=friL2] ["\u00a7c\u00a7l[好友位2] \u00a7e\u00a7l➾ ",{"selector":"@a[score_friLTemp_min=0,score_friLTemp=0]"}," \u00a77[未在线则不显示其ID]"]
  19. /tellraw @a[score_friPro_min=1,score_friPro=1,tag=!friL3] ["\u00a7c\u00a7l[好友位3] \u00a7e\u00a7l➾ \u00a77虚以代位"]
  20. /execute @a[score_friPro_min=1,score_friPro=1,tag=friL3] ~ ~ ~ scoreboard players reset @a friLTemp
  21. /execute @a[score_friPro_min=1,score_friPro=1,tag=friL3] ~ ~ ~ execute @a[rm=0] ~ ~ ~ scoreboard players operation @s friLTemp = @p[score_friPro_min=1,score_friPro=1] friLS3
  22. /execute @a[score_friLTemp_min=1] ~ ~ ~ scoreboard players operation @s friLTemp -= @s uid
  23. /tellraw @a[score_friPro_min=1,score_friPro=1,tag=friL3] ["\u00a7c\u00a7l[好友位3] \u00a7e\u00a7l➾ ",{"selector":"@a[score_friLTemp_min=0,score_friLTemp=0]"}," \u00a77[未在线则不显示其ID]"]
  24. /tellraw @a[score_friPro_min=1,score_friPro=1,tag=!friL4] ["\u00a7c\u00a7l[好友位4] \u00a7e\u00a7l➾ \u00a77虚以代位"]
  25. /execute @a[score_friPro_min=1,score_friPro=1,tag=friL4] ~ ~ ~ scoreboard players reset @a friLTemp
  26. /execute @a[score_friPro_min=1,score_friPro=1,tag=friL4] ~ ~ ~ execute @a[rm=0] ~ ~ ~ scoreboard players operation @s friLTemp = @p[score_friPro_min=1,score_friPro=1] friLS4
  27. /execute @a[score_friLTemp_min=1] ~ ~ ~ scoreboard players operation @s friLTemp -= @s uid
  28. /tellraw @a[score_friPro_min=1,score_friPro=1,tag=friL4] ["\u00a7c\u00a7l[好友位4] \u00a7e\u00a7l➾ ",{"selector":"@a[score_friLTemp_min=0,score_friLTemp=0]"}," \u00a77[未在线则不显示其ID]"]
  29. /tellraw @a[score_friPro_min=1,score_friPro=1,tag=!friL5] ["\u00a7c\u00a7l[好友位5] \u00a7e\u00a7l➾ \u00a77虚以代位"]
  30. /execute @a[score_friPro_min=1,score_friPro=1,tag=friL5] ~ ~ ~ scoreboard players reset @a friLTemp
  31. /execute @a[score_friPro_min=1,score_friPro=1,tag=friL5] ~ ~ ~ execute @a[rm=0] ~ ~ ~ scoreboard players operation @s friLTemp = @p[score_friPro_min=1,score_friPro=1] friLS5
  32. /execute @a[score_friLTemp_min=1] ~ ~ ~ scoreboard players operation @s friLTemp -= @s uid
  33. /tellraw @a[score_friPro_min=1,score_friPro=1,tag=friL5] ["\u00a7c\u00a7l[好友位5] \u00a7e\u00a7l➾ ",{"selector":"@a[score_friLTemp_min=0,score_friLTemp=0]"}," \u00a77[未在线则不显示其ID]"]
  34. /tellraw @a[score_friPro_min=1,score_friPro=1,tag=!friL6] ["\u00a7c\u00a7l[好友位6] \u00a7e\u00a7l➾ \u00a77虚以代位"]
  35. /execute @a[score_friPro_min=1,score_friPro=1,tag=friL6] ~ ~ ~ scoreboard players reset @a friLTemp
  36. /execute @a[score_friPro_min=1,score_friPro=1,tag=friL6] ~ ~ ~ execute @a[rm=0] ~ ~ ~ scoreboard players operation @s friLTemp = @p[score_friPro_min=1,score_friPro=1] friLS6
  37. /execute @a[score_friLTemp_min=1] ~ ~ ~ scoreboard players operation @s friLTemp -= @s uid
  38. /tellraw @a[score_friPro_min=1,score_friPro=1,tag=friL6] ["\u00a7c\u00a7l[好友位6] \u00a7e\u00a7l➾ ",{"selector":"@a[score_friLTemp_min=0,score_friLTemp=0]"}," \u00a77[未在线则不显示其ID]"]
  39. /tellraw @a[score_friPro_min=1,score_friPro=1] ["\u00a7e\u00a7l=========+>> \u00a76\u00a7l☕好友列表☕ \u00a7e\u00a7l<<+=========\n\u00a7b[◈] \u00a77该系统来自 \u00a7a\u00a7l☘Ganxiaozhe.com"]
  40. /execute @a[score_friPro_min=2,score_friPro=2] ~ ~ ~ /execute @a ~ ~ ~ tellraw @a[score_friPro_min=2,score_friPro=2] ["➤ \u00a7a玩家名字: ",{"selector":"@s","color":"white","bold":"true"}," \u00a7e玩家UID: ",{"score":{"name":"@s","objective":"uid"},"color":"white","bold":"true"}]
  41. /tellraw @a[score_friPro_min=2,score_friPro=2] ["\n\u00a76\u00a7l[好友系统] \u00a7c\u00a7l请输入\u00a7e\u00a7l/trigger friAdd set N\u00a7c\u00a7l选择要添加为好友的玩家,N为玩家列表旁的数字(UID)。\n\u00a7e好友添加后你们将互相拥有对方空岛权限。 \u00a7a[请在一分钟之内完成添加,延期自动取消]\n",{"text":" [点击此处自动补全]","color":"aqua","bold":"true","clickEvent":{"action":"suggest_command","value":"/trigger friAdd set "}}]
  42. /scoreboard players enable @a[score_friPro_min=2,score_friPro=2] friAdd
  43. /scoreboard players reset @a[score_friPro_min=1] friPro


好友添加初始化:

  1. /scoreboard objectives add friAdd trigger
  2. /scoreboard objectives add FAapply trigger
  3. /scoreboard objectives add g_FATemp dummy
  4. /scoreboard objectives add g_FAAB dummy
  5. /scoreboard objectives add g_FADone dummy
  6. /scoreboard objectives add FriNums dummy
  7. /scoreboard objectives add FA_timer dummy

添加发起与接受:

  1. testfor @a[score_friAdd_min=1,tag=g_FA_a]
  2. cond:tellraw @a[score_friAdd_min=1,tag=!friAdding] ["\u00a76\u00a7l[好友管理] \u00a7e当前添加好友占线中,请稍后再试。 当前使用玩家:",{"selector":"@a[score_friAdd_min=1,tag=friAdding]"}]
  3. cond:scoreboard players reset @a[score_friAdd_min=1,tag=!friAdding] friAdd
  4. scoreboard players tag @a[score_friAdd_min=1] add friAdding
  5. execute @a[score_friAdd_min=1] ~ ~ ~ scoreboard players reset @a g_FATemp
  6. execute @a[score_friAdd_min=1] ~ ~ ~ scoreboard players operation @a[rm=0] g_FATemp = @s friAdd
  7. execute @p[score_friAdd_min=1,tag=friAdding] ~ ~ ~ execute @a[rm=0] ~ ~ ~ scoreboard players operation @s g_FATemp -= @s uid
  8. scoreboard players test @a[tag=!friAdding] g_FATemp 0 0
  9. cond:scoreboard players tag @p[score_friAdd_min=1,tag=friAdding] add friAddY
  10. cond:scoreboard players tag @p[score_friAdd_min=1,tag=friAdding] add g_FA_a
  11. cond:scoreboard players tag @p[score_g_FATemp_min=0,score_g_FATemp=0] add g_FA_b
  12. tellraw @a[score_friAdd_min=1,tag=friAddY] ["\u00a76\u00a7l[添加好友] \u00a7e添加请求已发送至: ",{"selector":"@p[tag=g_FA_b]"}," \u00a7e请等待对方同意。"]
  13. scoreboard players enable @a[tag=g_FA_b] FAapply
  14. execute @a[score_friAdd_min=1,tag=friAddY] ~ ~ ~ tellraw @a[tag=g_FA_b] ["\u00a76\u00a7l[添加好友] ",{"selector":"@p[tag=g_FA_a]"}," \u00a7c向您发来了好友申请,输入\u00a7e\u00a7l/trigger FAapply set 1\u00a7a\u00a7l同意申请\u00a7c,输入\u00a7e\u00a7l/trigger FAapply set 2\u00a74\u00a7l拒绝申请。",{"text":" [点击此处自动补全]","color":"aqua","bold":"true","clickEvent":{"action":"suggest_command","value":"/trigger FAapply set 1"}}]
  15. tellraw @a[score_friAdd_min=1,tag=!friAddY] ["\u00a76\u00a7l[添加好友] \u00a7e未知玩家!请重新输入玩家UID。",{"text":" [点击此处自动补全]","color":"aqua","bold":"true","clickEvent":{"action":"suggest_command","value":"/trigger friAdd set "}}]
  16. scoreboard players enable @a[score_friAdd_min=1,tag=!friAddY] friAdd
  17. scoreboard players tag @a[score_friAdd_min=1,tag=!friAddY] remove friAdding
  18. scoreboard players tag @a[score_friAdd_min=1] remove friAddY
  19. scoreboard players reset @a[score_friAdd_min=1] friAdd

玩家拒绝好友申请:

  1. testfor @a[tag=g_FA_b,score_FAapply_min=2,score_FAapply=2]
  2. cond:tellraw @a[tag=g_FA_a] ["\u00a76\u00a7l[添加好友] \u00a7c玩家 ",{"selector":"@p[tag=g_FA_b]"},"\u00a74\u00a7l拒绝了\u00a7c你的好友申请。"]
  3. cond:scoreboard players tag @a[tag=g_FA_a] remove friAdding
  4. cond:scoreboard players tag @a[tag=g_FA_a] remove g_FA_a
  5. cond:scoreboard players tag @a[tag=g_FA_b] remove g_FA_b
  6. cond:scoreboard players reset @a[score_FAapply_min=2] FAapply

玩家同意好友申请:

  1. testfor @a[tag=g_FA_b,score_FAapply_min=1,score_FAapply=1]
  2. cond:scoreboard players reset @a[score_FAapply_min=1] FAapply
  3. cond:scoreboard players set @a[tag=g_FA_a] g_FAAB 1
  4. cond:scoreboard players set @a[tag=g_FA_b] g_FAAB 2
  5. cond:scoreboard players set @a g_FADone 0
  6. cond:blockdata 519 70 532 {auto:true}

好友添加处理,此命令组由上组最后一行blockdata激活,不做循环:

  1. blockdata 519 70 532 {auto:false}
  2. scoreboard players reset * FriNums
  3. scoreboard players add @a[score_g_FAAB_min=1,score_g_FAAB=1,tag=friL1] FriNums 1
  4. scoreboard players add @a[score_g_FAAB_min=1,score_g_FAAB=1,tag=friL2] FriNums 1
  5. scoreboard players add @a[score_g_FAAB_min=1,score_g_FAAB=1,tag=friL3] FriNums 1
  6. scoreboard players add @a[score_g_FAAB_min=1,score_g_FAAB=1,tag=friL4] FriNums 1
  7. scoreboard players add @a[score_g_FAAB_min=1,score_g_FAAB=1,tag=friL5] FriNums 1
  8. scoreboard players add @a[score_g_FAAB_min=1,score_g_FAAB=1,tag=friL6] FriNums 1
  9. scoreboard players add @a[score_g_FAAB_min=2,score_g_FAAB=2,tag=friL1] FriNums 1
  10. scoreboard players add @a[score_g_FAAB_min=2,score_g_FAAB=2,tag=friL2] FriNums 1
  11. scoreboard players add @a[score_g_FAAB_min=2,score_g_FAAB=2,tag=friL3] FriNums 1
  12. scoreboard players add @a[score_g_FAAB_min=2,score_g_FAAB=2,tag=friL4] FriNums 1
  13. scoreboard players add @a[score_g_FAAB_min=2,score_g_FAAB=2,tag=friL5] FriNums 1
  14. scoreboard players add @a[score_g_FAAB_min=2,score_g_FAAB=2,tag=friL6] FriNums 1
  15. testfor @a[score_FriNums_min=6]
  16. cond:scoreboard players set @a[tag=g_FA_a] g_FADone 1
  17. cond:scoreboard players set @a[tag=g_FA_b] g_FADone 1
  18. tellraw @a[score_g_FADone_min=1] ["\u00a76\u00a7l[添加好友] \u00a74\u00a7l添加好友失败!\u00a7e您或对方的好友列表满啦!"]
  19. testfor @a[score_g_FAAB_min=1,score_g_FAAB=1,score_g_FADone=0,tag=!friL1]
  20. cond:execute @a[tag=g_FA_b] ~ ~ ~ scoreboard players operation @s friLS1 = @a[tag=g_FA_a] uid
  21. cond:scoreboard players tag @a[tag=g_FA_a] add friL1
  22. cond:scoreboard players set @a[tag=g_FA_a] g_FADone 1
  23. testfor @a[score_g_FAAB_min=1,score_g_FAAB=1,score_g_FADone=0,tag=!friL2]
  24. cond:execute @a[tag=g_FA_b] ~ ~ ~ scoreboard players operation @s friLS2 = @a[tag=g_FA_a] uid
  25. cond:scoreboard players tag @a[tag=g_FA_a] add friL2
  26. cond:scoreboard players set @a[tag=g_FA_a] g_FADone 1
  27. testfor @a[score_g_FAAB_min=1,score_g_FAAB=1,score_g_FADone=0,tag=!friL3]
  28. cond:execute @a[tag=g_FA_b] ~ ~ ~ scoreboard players operation @s friLS3 = @a[tag=g_FA_a] uid
  29. cond:scoreboard players tag @a[tag=g_FA_a] add friL3
  30. cond:scoreboard players set @a[tag=g_FA_a] g_FADone 1
  31. testfor @a[score_g_FAAB_min=1,score_g_FAAB=1,score_g_FADone=0,tag=!friL4]
  32. cond:execute @a[tag=g_FA_b] ~ ~ ~ scoreboard players operation @s friLS4 = @a[tag=g_FA_a] uid
  33. cond:scoreboard players tag @a[tag=g_FA_a] add friL4
  34. cond:scoreboard players set @a[tag=g_FA_a] g_FADone 1
  35. testfor @a[score_g_FAAB_min=1,score_g_FAAB=1,score_g_FADone=0,tag=!friL5]
  36. cond:execute @a[tag=g_FA_b] ~ ~ ~ scoreboard players operation @s friLS5 = @a[tag=g_FA_a] uid
  37. cond:scoreboard players tag @a[tag=g_FA_a] add friL5
  38. cond:scoreboard players set @a[tag=g_FA_a] g_FADone 1
  39. testfor @a[score_g_FAAB_min=1,score_g_FAAB=1,score_g_FADone=0,tag=!friL6]
  40. cond:execute @a[tag=g_FA_b] ~ ~ ~ scoreboard players operation @s friLS6 = @a[tag=g_FA_a] uid
  41. cond:scoreboard players tag @a[tag=g_FA_a] add friL6
  42. cond:scoreboard players set @a[tag=g_FA_a] g_FADone 1
  43. testfor @a[score_g_FAAB_min=2,score_g_FAAB=2,score_g_FADone=0,tag=!friL1]
  44. cond:execute @a[tag=g_FA_a] ~ ~ ~ scoreboard players operation @s friLS1 = @a[tag=g_FA_b] uid
  45. cond:scoreboard players tag @a[tag=g_FA_b] add friL1
  46. cond:scoreboard players set @a[tag=g_FA_b] g_FADone 1
  47. testfor @a[score_g_FAAB_min=2,score_g_FAAB=2,score_g_FADone=0,tag=!friL2]
  48. cond:execute @a[tag=g_FA_a] ~ ~ ~ scoreboard players operation @s friLS2 = @a[tag=g_FA_b] uid
  49. cond:scoreboard players tag @a[tag=g_FA_b] add friL2
  50. cond:scoreboard players set @a[tag=g_FA_b] g_FADone 1
  51. testfor @a[score_g_FAAB_min=2,score_g_FAAB=2,score_g_FADone=0,tag=!friL3]
  52. cond:execute @a[tag=g_FA_a] ~ ~ ~ scoreboard players operation @s friLS3 = @a[tag=g_FA_b] uid
  53. cond:scoreboard players tag @a[tag=g_FA_b] add friL3
  54. cond:scoreboard players set @a[tag=g_FA_b] g_FADone 1
  55. testfor @a[score_g_FAAB_min=2,score_g_FAAB=2,score_g_FADone=0,tag=!friL4]
  56. cond:execute @a[tag=g_FA_a] ~ ~ ~ scoreboard players operation @s friLS4 = @a[tag=g_FA_b] uid
  57. cond:scoreboard players tag @a[tag=g_FA_b] add friL4
  58. cond:scoreboard players set @a[tag=g_FA_b] g_FADone 1
  59. testfor @a[score_g_FAAB_min=2,score_g_FAAB=2,score_g_FADone=0,tag=!friL5]
  60. cond:execute @a[tag=g_FA_a] ~ ~ ~ scoreboard players operation @s friLS5 = @a[tag=g_FA_b] uid
  61. cond:scoreboard players tag @a[tag=g_FA_b] add friL5
  62. cond:scoreboard players set @a[tag=g_FA_b] g_FADone 1
  63. testfor @a[score_g_FAAB_min=2,score_g_FAAB=2,score_g_FADone=0,tag=!friL6]
  64. cond:execute @a[tag=g_FA_a] ~ ~ ~ scoreboard players operation @s friLS6 = @a[tag=g_FA_b] uid
  65. cond:scoreboard players tag @a[tag=g_FA_b] add friL6
  66. cond:scoreboard players set @a[tag=g_FA_b] g_FADone 1
  67. tellraw @a[score_g_FADone_min=1] ["\u00a76\u00a7l[添加好友] \u00a7a\u00a7l添加好友成功!"]
  68. scoreboard players reset @a[score_g_FADone_min=1] g_FAAB
  69. scoreboard players tag @a[score_g_FADone_min=1] remove g_FA_a
  70. scoreboard players tag @a[score_g_FADone_min=1] remove g_FA_b
  71. scoreboard players tag @a[score_g_FADone_min=1] remove friAdding
  72. scoreboard players reset @a[score_g_FADone_min=1] g_FADone
  73. scoreboard players add @a[tag=friAdding] FA_timer 1
  74. execute @a[score_FA_timer_min=60] ~ ~ ~ scoreboard players reset * FAapply
  75. execute @a[score_FA_timer_min=60] ~ ~ ~ scoreboard players tag * remove friAdding
  76. execute @a[score_FA_timer_min=60] ~ ~ ~ scoreboard players tag * remove g_FA_a
  77. execute @a[score_FA_timer_min=60] ~ ~ ~ scoreboard players tag * remove g_FA_b
  78. tellraw @a[score_FA_timer_min=60] ["\u00a76\u00a7l[添加好友] \u00a7e添加时间过长!已自动退出系统。"]
  79. execute @a[score_FA_timer_min=60] ~ ~ ~ scoreboard players reset * FA_timer

未经作者授权,禁止转载





LOADING | 此框架正在加载中
QQ群:771363745