Serving a payment option for my minecraft server so I don't have to pay for it all alone
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

MinecraftUsers.class.js 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // MLQRequire: { "Plugin": "Minecraft-Payment", "Type": "Service", "Name": "MinecraftPayService" }
  2. class MinecraftUsers {
  3. constructor() {
  4. this.user = {};
  5. this.subscriptionsStates = new Map();
  6. }
  7. onview(vnode) {
  8. if (typeof (MinecraftUser) !== 'function')
  9. LoadQueue.Start(() => { });
  10. else
  11. this.loadUser();
  12. }
  13. loadUser() {
  14. var id = m.route.param('id');
  15. if (id.match(/^[0-9]+$/))
  16. id = +id;
  17. else
  18. return;
  19. if (this.user.ID !== id) {
  20. this.user = $.extend(true, new MinecraftUser(), MinecraftPayService.Users.find(o => o.ID === id)) || this.user;
  21. if (this.user.ID) {
  22. MinecraftPayAPI.GetAllSubscriptionStates({ params: { id } }).then(map => {
  23. this.subscriptionsStates = map || this.subscriptionsStates;
  24. });
  25. }
  26. m.redraw();
  27. }
  28. }
  29. UnlockServer(serverId) {
  30. if (!this.subscriptionsStates.get(serverId)) {
  31. Modal.YesNo('Delete minecraft user', __('Do you really want to unlock this server for this minecraft user?'), (c, e) => this.unlockServer(this.user.ID, serverId, c)).Show();
  32. }
  33. }
  34. unlockServer(userId, serverId, confirmed) {
  35. if (confirmed) {
  36. MinecraftPayAPI.SubscribeServer({ params: { id: userId, serverId } }).then(r => {
  37. this.subscriptionsStates.set(serverId, r.Obj);
  38. Toasts.Messaged(r.Message, Toast.Load({ Type: r.Success ? 'success' : 'danger' }));
  39. });
  40. }
  41. return undefined;
  42. }
  43. }