SHARE
TWEET

Untitled

JavaFactory Jul 20th, 2019 115 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package de.leonhard.xcore.bungee.commands
  2.  
  3. import co.aikar.commands.annotation.CommandAlias
  4. import co.aikar.commands.annotation.CommandCompletion
  5. import co.aikar.commands.annotation.Default
  6. import co.aikar.commands.annotation.Subcommand
  7. import de.leonhard.storage.Yaml
  8. import de.leonhard.xcore.XCore
  9. import de.leonhard.xcore.bungee.Party
  10. import de.leonhard.xcore.bungee.PartyManager
  11. import de.leonhard.xcore.data.yaml.ConfigFactory
  12. import de.leonhard.xcore.data.yaml.language.LanguageManager
  13. import de.leonhard.xcore.util.EasyComponent
  14. import de.leonhard.xcore.util.UniversalCommand
  15. import net.md_5.bungee.api.ProxyServer
  16. import net.md_5.bungee.api.chat.TextComponent
  17. import net.md_5.bungee.api.connection.ProxiedPlayer
  18. import java.util.*
  19.  
  20. @CommandAlias("party|p")
  21. class PartyCommand : UniversalCommand() {
  22.  
  23.     private val cfg = Yaml(LanguageManager.getLanguage().code, XCore.PATH + "/languages")
  24.  
  25.     init { //WAS für ein KeyWord ist das?
  26.         cfg.pathPrefix = "commands.bungee.PartyCommand"
  27.     }
  28.  
  29.     private val prefix = ConfigFactory.getPartyPrefix()
  30.     private val notInParty: String = cfg.getOrSetDefault("NotInParty",
  31.             "You are in no party. Use &7/party help for &7help")
  32.     private val usage: String = cfg.getOrSetDefault("UseHelp", "Use /party help for help")
  33.     private val notLeader: String = cfg.getOrSetDefault("NotLeader", "You are not the leader of the party")
  34.  
  35.     @Default
  36.     fun onParty(p: ProxiedPlayer) {
  37.         /*
  38.         Wenn in keiner Party -> DU bist in keiner Party
  39.         Wenn in einer Party ->Help ->
  40.          */
  41.  
  42.         doHelp()
  43.     }
  44.  
  45.     @CommandAlias("pc")
  46.     @Subcommand("chat|c")
  47.     fun onChat(p: ProxiedPlayer, args: Array<String>) {
  48.         isFalse(PartyManager.isInParty(p.uniqueId), notInParty)
  49.         val party: Party = PartyManager.getPartyFromPlayer(p.uniqueId)
  50.         var msg = "§e" + p.name + "§7 » "
  51.  
  52.         args.forEach {
  53.             msg = "$msg$it "
  54.         }
  55.         val leader: ProxiedPlayer = ProxyServer.getInstance().getPlayer(party.leader)
  56.         send(leader, msg, ConfigFactory.getPartyPrefix())
  57.         party.members.forEach {
  58.             ProxyServer.getInstance().getPlayer(it).sendMessage(TextComponent(ConfigFactory.getPartyPrefix() + msg))
  59.         }
  60.     }
  61.  
  62.     @Subcommand("list|info")
  63.     fun onList(p: ProxiedPlayer) {
  64.  
  65.         isFalse(PartyManager.isInParty(p.uniqueId), notInParty)
  66.         val party: Party = PartyManager.getPartyFromPlayer(p.uniqueId)
  67.         send("§7Leader:§7 ${party.getLeaderName()}", prefix)
  68.         send("§7Size: ${party.members.size.plus(1)}", prefix)
  69.         party.members.forEach {
  70.             if (it == party.leader)
  71.                 return
  72.             send("§a§l•§7 ${ProxyServer.getInstance().getPlayer(it).name}", prefix)
  73.         }
  74.     }
  75.  
  76.     @Subcommand("create")
  77.     fun onCreate(p: ProxiedPlayer) {
  78.         val party = Party(p.uniqueId)
  79.  
  80.         send(cfg.getOrSetDefault("PartyCreated", "§7Party created §asuccessfully"))
  81.  
  82.     }
  83.  
  84.     @CommandCompletion("@players")
  85.     @Subcommand("invite")
  86.     fun onInvite(p: ProxiedPlayer, args: Array<String>) {
  87.  
  88.         checkArgsStrict(1, LanguageManager.providePlayer())
  89.  
  90.         val party: Party? = PartyManager.getPartyFromPlayer(p.uniqueId)
  91.         checkNotNull(party, notInParty)
  92.  
  93.  
  94.         val target: ProxiedPlayer = getPlayerIfOnlineBungee(args[0], LanguageManager.NotOnline(true))
  95.         isTrue(party!!.members.contains(target.uniqueId),
  96.                 cfg.getOrSetDefault("AlreadyInParty", "§cThis player is already member §cof the party"))
  97.         party.invite(target.uniqueId)
  98.  
  99.         send(cfg.getOrSetDefault("SuccessfullyInvited", "Invited §6%name §asuccessfully").replace("%name", target.name))
  100.         send(target, cfg.getOrSetDefault("InvitedByParty", "You have been invited to party the from ${p.name}"))
  101.         EasyComponent.builder("§6[§a§lJOIN§6]").onHover("Click to join").onClickRunCmd("/party join ${p.name}").send(target)
  102.     }
  103.  
  104.     @CommandCompletion("@players")
  105.     @Subcommand("join")
  106.     fun onJoin(p: ProxiedPlayer, args: Array<String>) {
  107.         checkArgsStrict(1, LanguageManager.providePlayer())
  108.         val target: ProxiedPlayer = getPlayerIfOnlineBungee(args[0], LanguageManager.NotOnline(true)) //TODO Change in pro
  109.         val uuid: UUID = target.uniqueId
  110.         isFalse(PartyManager.parties.containsKey(target.uniqueId),
  111.                 cfg.getOrSetDefault("HasNoParty", "The player &6%name is in &cnot the leader&7 of any party."))
  112.         val party: Party = PartyManager.getPartyFromPlayer(uuid)
  113.         isFalse(party.isInvited(p.uniqueId), cfg.getOrSetDefault("NotInvited",
  114.                 "You have no invitation for the party of %name").replace("%name", target.name))
  115.         party.add(p.uniqueId)
  116.         party.broadcast("§6${p.name}§7 joined the party")
  117.     }
  118.  
  119.     @Subcommand("remove")
  120.     fun onRemove(p: ProxiedPlayer, args: Array<String>) {
  121.         checkArgsStrict(1, usage)
  122.  
  123.         val party: Party? = PartyManager.getPartyFromPlayer(p.uniqueId)
  124.         checkNotNull(party, notInParty)
  125.         isFalse(party!!.isLeader(p.uniqueId), cfg.getOrSetDefault("NotLeader", "You are not the leader of the party"))
  126.         val target: ProxiedPlayer = getPlayerIfOnlineBungee(args[0], LanguageManager.NotOnline(true))
  127.         isFalse(party.isMember(target.uniqueId), cfg.getOrSetDefault("NotAnMember", "The player %name is not an member of this party"))
  128.         party.remove(target.uniqueId)
  129.         send(cfg.getOrSetDefault("Removed", "You have removed %name successfully from the party").replace("%name", target.name))
  130.     }
  131.  
  132.     @Subcommand("promote")
  133.     fun onPromote(p: ProxiedPlayer, args: Array<String>) {
  134.         val party: Party? = PartyManager.getPartyFromPlayer(p.uniqueId)
  135.         checkNotNull(party, notInParty)
  136.         checkArgsStrict(1, usage)
  137.         isFalse(party!!.isLeader(p.uniqueId), notLeader)
  138.         val target = getPlayerIfOnlineBungee(args[0], LanguageManager.NotOnline(true))
  139.         isTrue(party.isLeader(target.uniqueId), cfg.getOrSetDefault("AlreadyLeader", "&cYou are already leader of the party"))
  140.         party.promote(target.uniqueId)
  141.         PartyManager.parties.remove(p.uniqueId)
  142.         PartyManager.parties[target.uniqueId] = party
  143.         send(cfg.getOrSetDefault("SuccessfullyPromoted.1", "§aSuccessfully promoted §6%name").replace("%name", target.name))
  144.         send(cfg.getOrSetDefault("SuccessfullyPromoted.2", "§7You are no longer the leader of this party."))
  145.     }
  146.  
  147.     @Subcommand("delete")
  148.     fun onDelete(p: ProxiedPlayer) {
  149.         val party: Party? = PartyManager.getPartyFromPlayer(p.uniqueId)
  150.         checkNotNull(party, notInParty)
  151.         isFalse(party!!.isLeader(p.uniqueId), notLeader)
  152.         PartyManager.delete(p.uniqueId)
  153.     }
  154.  
  155.     @Subcommand("leave")
  156.     fun onLeave(p: ProxiedPlayer) {
  157.         val party: Party? = PartyManager.getPartyFromPlayer(p.uniqueId)
  158.         checkNotNull(party, notInParty)
  159.         isTrue(party!!.isLeader(p.uniqueId), cfg.getOrSetDefault("CantLeave",
  160.                 "&7The party leader can't leave his own party." +
  161.                         " Use &6/party delete &7to delete your party"))
  162.         party.remove(p.uniqueId)
  163.         send(cfg.getOrSetDefault("LeftTheParty", "You have §asuccessfully §7left the party"))
  164.     }
  165.  
  166.     @Subcommand("help")
  167.     fun onHelp(p: ProxiedPlayer) {
  168.         doHelp()
  169.     }
  170.  
  171.     private fun doHelp() {
  172.         send(cfg.getOrSetDefault("Usage.0", "===== §ePartySystem by ${XCore.NAME} §7====="), prefix)
  173.         send(cfg.getOrSetDefault("Usage.1", "/party <invite> <player> &7Invite a player"), prefix)
  174.         send(cfg.getOrSetDefault("Usage.2", "/party <remove> <player> &7Remove a player"), prefix)
  175.         send(cfg.getOrSetDefault("Usage.3", "/party <promote> <player> - &7Transfered party leadership"), prefix)
  176.         send(cfg.getOrSetDefault("Usage.4", "/party <leave> &7Leaves the party"), prefix)
  177.         send(cfg.getOrSetDefault("Usage.5", "/party <delete> &7 Deletes the party"), prefix)
  178.         send(cfg.getOrSetDefault("Usage.6", "/pc <Message> Chat with party members"), prefix)
  179.     }
  180.  
  181. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top