diff --git a/Bukkit/LanguageFiles/de.yml b/Bukkit/LanguageFiles/de.yml new file mode 100644 index 0000000..8346739 --- /dev/null +++ b/Bukkit/LanguageFiles/de.yml @@ -0,0 +1,192 @@ +# CubeRunner plugin +# Made by EgoLeX +# de.yml - Language file + +languageName: "Deutsche" + +prefixShort: "&7[&5CR&7]" +prefixLong: "&7[&5CubeRunner&7]" + +developper: "&5Erstellt durch: &7%developper%" +version: "&5Version: &7%version%" +description: "&dTippe &5/%command% help &d für eine Liste aller Kommandos." + +errorPermission: "&4Du hast die nicht die benötigten Rechte um dies zu tun" +###UNTRANSLATED### +errorCommand: "&cCommand not found. Type &8/%cmd% help &cfor help." +errorTeleport: "&cDu kannst dich nicht teleportieren während du dich im Spiel befindest. Tippe &7/cr quit &cum zu verlassen." +###UNTRANSLATED### +errorMissingArena: "&cYou need to specify a valid arena." +errorAlreadyInGame: "&cDu bist bereits in einem CubeRunner Spiel." +errorNotInGame: "&cDu befindest dich derzeit in keinem CubeRunner Spiel." + +infoTip: "&8[&7Tipp&8] &7Du kannst auch &8/%cmd% list &7und rechtsklick machen um Informationen zu bekommen." + +joinUnready: "&cDie Arena der du Beitreten wolltest exestiert anscheinend nicht" +joinActive: "&cEs läuft derzeit ein Spiel in der Arena der du Beitreten wolltest." +joinSpectator: "&dJoining als Zuschauer..." +joinPlayer: "&aDu bist erfolgreich der Arena &2%arena%&a beigetreten." +joinOthers: "&f%player% &dist der CubeRunners Arena beigetreten." +joinGuiTitle: "&2Arena Liste" +joinGuiInfo: "&eKlicke auf den Namen der Arena zu der du möchtest." +joinGuiTipStarted: "&cAktiv : &eKlicke zum Zuschauen" +joinGuiTipJoin: "&aBereit : &eKlicke zum Beitreten" + +quitPlayer: "&aDu hast die CubeRunners Arena &2%arena%&a verlassen." +quitOthers: "&f%player% &dhat die CubeRunners Arena verlassen." + +startNotReady: "&cDas Spiel ist derzeit nicht bereit zum Starten" +startMinimum: "&cEs müssen mindestens %amount% Spieler in der Arena sein um das Spiel zu starten." +startMaximum: "&cEs dürfen maximal %amount% Spieler in der Arena sein um das Spiel zu starten." +startBroadcast: "&dEin neues Spiel von &5CubeRunner &dwurde gefunden. Du kannst beitreten indem du folgendes Kommando verwendest: &5/cr join %arena%&d." +startStop: "&cDer Countdown wurde gestoppt. Nicht genügend Spieler." + +endCrushPlayer: "&dDu bist mit einem Score von &5%score%&d rausgeflogen. Spiel Vorbei!" +endCrushOthers: "&f%player% &dist mit einem Score von &5%score%&d rausgeflogen." +###UNTRANSLATED### +endHidePlayer: "&dYou have been kicked out of the game for hiding under a block." +###UNTRANSLATED### +endHideOthers: "&f%player% &dhave been kicked out of the game for hiding under a block." +endTeleport: "&dSpiel Vorbei. Teleport zurück in 5 Sekunden..." +endBest: "&6Glückwunsch an &f%player% &6welcher den neuen Highscore von &4%score% &6in der Arena &5%arena% hält." +endReward: "&dDu hast %amount%%currency% für das Überleben von %amount2% Sekunden bekommen." +###UNTRANSLATED### +endBroadcastMultiplayer: "&6Congradulation to &f%player% &6who won a multiplayer game of CubeRunner in the arena &5%arena% &6with a score of &4%score%&6!" +###UNTRANSLATED### +endBroadcastSingleplayer: "&f%player% &6finished a game of CubeRunner in the arena &5%arena% &6with a score of &4%score%&6!" + +statsGuiTitle: "&6Stats" +statsInfoAverageScore: "&bEigener Score pro Arena" +statsInfoDistanceRan: "&bTotale Distanz" +statsInfoGames: "&bgespielte Spiele" +statsInfoTotalScore: "&bTotal Score" +statsInfoKills: "&bgetötete Spieler" +statsInfoMultiplayerWon: "&bMultiplayer Spiele gewonnen" +statsInfoTimePlayed: "&dSpielzeit" +statsInfoMoney: "&dGeldgewinn" +statsChallengesTitle: "&bHerausforderungen" + +achievementBroadcast: "&f%player% &6hat die Errungenschaft &d%achievementName%&6 erhalten!" +achievementReward: "&dDu hast %amount%%currency% für die Errungenschaft bekommen." +achievementAmountGame: "&dSpiele %amount% Spiele" +achievementTotalScore: "&dTotaler Score von %amount% erreichen" +achievementKills: "&dTöte %amount% Spieler" +achievementMultiplayerWon: "&dWin %amount% multiplayer game(s)" +achievementSurvive5Minutes: "&dÜberlebe 5 Minuten" +achievementReachHeight10: "&dErreiche eine Höhe von 10" +achievementFillTheArena: "&dFülle den Arenaboden" +achievementAnswerToLife: "&dDie Antwort für das Leben, das Universum und alles andere" +achievementRageQuit: "&dDer Rage Quit" +achievementKillerBunny: "&dDer Todeshase" + +editCreateNoname: "&cDu musst einen Namen für deine Arena wählen." +editNewSuccess: "&aEine Arena namens &2%arena% &awurde erfolgreich erstellt." +editNewExists: "&cEine Arena namens &4%arena% &cexistiert bereits." +###UNTRANSLATED### +editNewLongName: "&cThe arena's name can't be more than 12 letters long." +editErrorArena: "&cEine Arena namens &4%arena% &cexistiert nicht." +editRegionWorldedit: "&cDu musst erst eine WorldEdit Region festlegen." +editRegion: "&aZone erfolgreich gesetzt für &2%arena%&a." +editStartPoint: "&aStartpunkt erfolgreich gesetzt für &2%arena%&a." +editLobby: "&aLobby erfolgreich gesetzt für &2%arena%&a." +editPlayersMissing: "&cDu musst eine Menge angeben um die Spieleranzahl zu ändern." +editPlayersError: "&cDie Anzahl der Spieler die du angeben hast ist unbekannt. &7[&8%error%&7]" +editPlayersNaN: "Keine gültige Nummer" +editPlayersMinimum1: "Minimum weniger als 1" +editPlayersMinimumMaximum: "Minimum größer als Maximum" +editPlayersMaximumMinimum: "Maximum kleiner als Minimum" +editPlayersMaximum10 : "Maximum größer als 10" +editPlayers: "&aAnzahl an Spielern erfolgreich editiert für &2%arena%&a." +editColorGuiTitle: "&4Farbtool" +editColorGuiInfo: "&eDie ausgewählten Blöcke sind\n&edie derzeit ausgewählten.\n&eKlicke auf einen Block\n&eum In zu De/-Aktivieren." +editColorError: "&cDu kannst die Farben nicht ändern während du Ingame bist." +editDelete: "&cArena entfernt." + +languageList: "Verfügbare Sprachen" +languageNotFound: "&cSprache nicht gefunden. &8/%cmd% language &cfür eine Liste aller verfügbaren Sprachen" +languageChanged: "&aSprache erfolgreich auf Englisch gesetzt" + +helpErrorPermission: "&cDu hast keinerlei Rechte für die Kategorie." +helpDescriptionAll: "&7Alle Kommandos" +helpDescriptionGeneral: "&7Generelle Spieler Kommandos" +helpDescriptionGame: "&7Kommandos für das einfach Spiel" +helpDescriptionArena: "&7Kommandos um die Arena zu erstellen" +helpDescriptionAdmin: "&7Admin Kommandos" + +signPerm0: "&cDu hast nicht" +signPerm1: "&cdie benötigten Rechte" +signPerm2: "&cum ein DaC" +signPerm3: "&cSchild zu erstellen" +signValid1: "&cNone valid" +signValid2: "&cSchild Parameter" +signValid3: "&cVersuch es erneut" + +keyWordSignJoin: "&aBeitreten" +keyWordSignQuit: "&cVerlassen" +keyWordSignStart: "&9Spiel starten" +keyWordSignStats: "&6Statistiken" +keyWordSignPlay: "&aSpielen" +###UNTRANSLATED### +keyWordSignTop: "&bBest Score" + +keyWordGuiInstructions: "&6Einleitung" +###UNTRANSLATED### +keyWordGuiPage: "&ePage %number%" + +keyWordGameStateUnset: "&7Arena Unset" +keyWordGameStatReady: "&aBereit" +keyWordGameStatStartup: "&9Anfang" +keyWordGameStatActive: "&cAktiv" + +keyWordGeneralHours: "Stunde" +keyWordGeneralMinutes: "Minute" +keyWordGeneralSeconds: "Sekunde" +keyWordGeneralDistance: "km" +keyWordGeneralBy: "von" + +keyWordHelp: "Hilfe" +keyWordHelpCategory: "Kategorie" +keyWordHelpPage: "Seite" + +keyWordInfo: "Information" +keyWordInfoAdvanced: "Erweiterte Information" +keyWordInfoMinimum: "Minimum" +keyWordInfoMaximum: "Maximum" +keyWordInfoCurrent: "Derzeitig" +keyWordInfoAmountPlayer: "Spieleranzahl" +keyWordInfoGameState: "Spielstatus" +keyWordInfoWorld: "Welt" +keyWordInfoLobby: "Lobby" +keyWordInfoStartPoint: "Startpunkt" +keyWordInfoZoneMinPoint: " Zonen Koordinaten" +keyWordInfoBestScore: "Bester Score" + +keyWordStatsTop10: "Top 10" +keyWordStatsProgression: "Entwicklung" +keyWordStatsCompleted: "Beendet" +keyWordStatsNotCompleted: "nicht beendet" +keyWordStatsReward: "Belohnung" + +keyWordScoreboardPlayers: "Spieler" +keyWordScoreboardScore: "Punkte" + +adminReload: "&aPlugin CubeRunner wurde erfolgreich reloaded." + +###UNTRANSLATED### +cmdDescriptionHelp: "&7You already know how to do that don't you? ;)" +cmdDescriptionLanguage: "&7Änder deine eigene Sprache für das CubeRunners plugin." +cmdDescriptionStats: "&7Öffnet deine CubeRunners Statistik." +cmdDescriptionList: "&7Öffnet eine Liste aller Kommandos." +cmdDescriptionInfo: "&7Zeigt jede Information über eine Arena." +cmdDescriptionJoin: "&7Betrete ein spezifisches Spiel oder öffne die GUI." +cmdDescriptionQuit: "&7Verlasse dein derzeitiges Spiel." +cmdDescriptionStart: "&7Startcountdown eingeleitet." +cmdDescriptionNew: "&7Erstellt eine neue CubeRunners Arena." +cmdDescriptionDelete: "&7Lösche eine spezifische Arena." +cmdDescriptionSetzone: "&7Setze die Abgrenzung für eine spezifische Arena mit einer Worldedit Region." +cmdDescriptionSetlobby: "&7Setz die Lobby der spezifischen Arena." +cmdDescriptionStartpoint: "&7Setze den Startpunkt der Arena." +cmdDescriptionSetcolor: "&7Setz die Blockfarbe der Arena" +cmdDescriptionSetminplayer: "&7Setze die Minimale Spieleranzahl der Arena." +cmdDescriptionSetmaxplayer: "&7Setze die Maximale Spieleranzahl der Arena." +cmdDescriptionReload: "&7Reloade die config, die Spieler Daten und die Sprachdatei." \ No newline at end of file diff --git a/Bukkit/LanguageFiles/en.yml b/Bukkit/LanguageFiles/en.yml new file mode 100644 index 0000000..29e0d49 --- /dev/null +++ b/Bukkit/LanguageFiles/en.yml @@ -0,0 +1,182 @@ +# CubeRunner plugin +# Made by PoutineQc +# en.yml - Language file + +languageName: "English" + +prefixShort: "&7[&5CR&7]" +prefixLong: "&8[&5CubeRunner&8]" + +developper: "&5Developped by: &7%developper%" +version: "&5Version: &7%version%" +description: "&dType &5/%command% help &d for the list of commands." + +errorPermission: "&4You don't have the permission to do this" +errorCommand: "&cCommand or arena not found. Type &8/%cmd% help &cfor help." +errorTeleport: "&cYou can't teleport away while you are in game. Do &7/cr quit &cto leave it." +errorMissingArena: "&cYou need to specify a valid arena." +errorAlreadyInGame: "&cYou are already in a CubeRunner game." +errorNotInGame: "&cYou are not currently in a CubeRunner game." + +infoTip: "&8[&7Tip&8] &7You may also do &8/%cmd% list &7and right click an arena to display it's information." + +joinUnready: "&cThe arena you are trying to join is not available." +joinActive: "&cThere is already an active game in the arena you are trying to join." +joinSpectator: "&dJoining as spectator..." +joinPlayer: "&aYou have successfully joined the arena &2%arena%&a." +joinOthers: "&f%player% &djoined your CubeRunner's arena." +joinGuiTitle: "&2Arena List" +joinGuiInfo: "&eClick the name of the arena you wish to go to." +joinGuiTipStarted: "&cActive : &eClick to Spectate" +joinGuiTipJoin: "&aReady : &eClick to Join" + +quitPlayer: "&aYou have left the CubeRunner's arena &2%arena%&a." +quitOthers: "&f%player% &dleft your CubeRunner's arena." + +startNotReady: "&cThe game is not ready to start at the moment" +startMinimum: "&cThere must be at least %amount% players to start the game." +startMaximum: "&cThere must be at most %amount% players to start the game." +startBroadcast: "&dA new game of &5CubeRunner &dhas been initiated. You may join with the command &5/cr join %arena%&d." +startStop: "&cThe countdown has been stopped. Not enough players in the game anymore." + +endCrushPlayer: "&dYou have been crushed with a score of &5%score%&d. Game over!" +endCrushOthers: "&f%player% &dhas been crushed with a score of &5%score%&d." +endHidePlayer: "&dYou have been kicked out of the game for hiding under a block." +endHideOthers: "&f%player% &dhave been kicked out of the game for hiding under a block." +endTeleport: "&dGame is over. Teleporting back in 5 seconds..." +endBest: "&6Congratulation to &f%player% &6who got the new best score of &4%score% &6in the arena &5%arena%" +endReward: "&dYou gain %amount%%currency% for surviving %amount2% seconds." +endBroadcastMultiplayer: "&6Congradulation to &f%player% &6who won a multiplayer game of CubeRunner in the arena &5%arena% &6with a score of &4%score%&6!" +endBroadcastSingleplayer: "&f%player% &6finished a game of CubeRunner in the arena &5%arena% &6with a score of &4%score%&6!" + +statsGuiTitle: "&6Stats" +statsInfoAverageScore: "&bAverage Score Per Game" +statsInfoDistanceRan: "&bTotal Distance Ran" +statsInfoGames: "&bGames played" +statsInfoTotalScore: "&bTotal Score" +statsInfoKills: "&bPlayers Killed" +statsInfoMultiplayerWon: "&bMultiplayer games won" +statsInfoTimePlayed: "&dTime Played" +statsInfoMoney: "&dMoney Gained" +statsChallengesTitle: "&bChallenges" + +achievementBroadcast: "&f%player% &6just completed the achievement &d%achievementName%&6!" +achievementReward: "&dYou gain %amount%%currency% for your achievement." +achievementAmountGame: "&dPlay %amount% game(s)" +achievementTotalScore: "&dReach total score of %amount%" +achievementKills: "&dKill %amount% player(s)" +achievementMultiplayerWon: "&dWin %amount% multiplayer game(s)" +achievementSurvive5Minutes: "&dSurvive 5 minutes" +achievementReachHeight10: "&dReach height 10" +achievementFillTheArena: "&dFill the arena's floor" +achievementAnswerToLife: "&dThe answer to life the universe and everything" +achievementRageQuit: "&dThe Rage Quit" +achievementKillerBunny: "&dThe Killer Bunny" + +editCreateNoname: "&cYou must choose a name for your new arena." +editNewSuccess: "&aAn arena named &2%arena% &ahas been successfully created." +editNewExists: "&cAn arena named &4%arena% &calready exists." +editNewLongName: "&cThe arena's name can't be more than 12 letters long." +editErrorArena: "&cAn arena named &4%arena% &cdoes not exists." +editRegionWorldedit: "&cYou must first choose a World Edit region." +editRegion: "&aZone successfully set for the arena &2%arena%&a." +editStartPoint: "&aStart Point successfully set for the arena &2%arena%&a." +editLobby: "&aLobby successfully set for the arena &2%arena%&a." +editPlayersMissing: "&cYou must provide a quantity to change the amount of players." +editPlayersError: "&cThe amount of player you entered is not valid. &7[&8%error%&7]" +editPlayersNaN: "Not a number" +editPlayersMinimum1: "Minimum lower than 1" +editPlayersMinimumMaximum: "Minimum higher than maximum" +editPlayersMaximumMinimum: "Maximum lower than minimum" +editPlayersMaximum10 : "Maximum higher than 10" +editPlayers: "&aAmount of player successfully edited for the arena &2%arena%&a." +editColorGuiTitle: "&4Color Picker" +editColorGuiInfo: "&eThe enchanted blocks are\nðe curently selected ones.\n&eClick a block to\n&eenable or disable it." +editColorError: "&cYou can't edit the colors while a game is active." +editDelete: "&cArena deleted." + +languageList: "Available languages" +languageNotFound: "&cLanguage not found. &8/%cmd% language &cfor a list of available languages" +languageChanged: "&aLanguage successfully set to english" + +helpErrorPermission: "&cYou do not have any permissions in this category." +helpDescriptionAll: "&7All Commands" +helpDescriptionGeneral: "&7General player commands" +helpDescriptionGame: "&7Commands to simply play the game" +helpDescriptionArena: "&7Commands to setup the arenas" +helpDescriptionAdmin: "&7Admin maintenance commands" + +signPerm0: "&cYou don't have" +signPerm1: "&cthe permissions" +signPerm2: "&cto create a DaC" +signPerm3: "&csign, &4Sorry..." +signValid1: "&cNone valid" +signValid2: "&csign parameters" +signValid3: "&cTry again" + +keyWordSignJoin: "&aJoin Arena" +keyWordSignQuit: "&cQuit Arena" +keyWordSignStart: "&9Start Game" +keyWordSignStats: "&6Stats" +keyWordSignPlay: "&aPlay" +keyWordSignTop: "&bBest Score" + +keyWordGuiInstructions: "&6Instructions" +keyWordGuiPage: "&ePage %number%" + +keyWordGameStateUnset: "&7Arena Unset" +keyWordGameStatReady: "&aReady" +keyWordGameStatStartup: "&9Startup" +keyWordGameStatActive: "&cActive" + +keyWordGeneralHours: "hours" +keyWordGeneralMinutes: "minutes" +keyWordGeneralSeconds: "seconds" +keyWordGeneralDistance: "km" +keyWordGeneralBy: "by" + +keyWordHelp: "Help" +keyWordHelpCategory: "Category" +keyWordHelpPage: "Page" + +keyWordInfo: "Information" +keyWordInfoAdvanced: "Advanced Information" +keyWordInfoMinimum: "Minimum" +keyWordInfoMaximum: "Maximum" +keyWordInfoCurrent: "Current" +keyWordInfoAmountPlayer: "amount of players" +keyWordInfoGameState: "game state" +keyWordInfoWorld: "World" +keyWordInfoLobby: "Lobby" +keyWordInfoStartPoint: "Start point" +keyWordInfoZoneMinPoint: " zone coordinate" +keyWordInfoBestScore: "Best Score" + +keyWordStatsTop10: "Top 10" +keyWordStatsProgression: "Progression" +keyWordStatsCompleted: "Completed" +keyWordStatsNotCompleted: "Not Completed" +keyWordStatsReward: "Reward" + +keyWordScoreboardPlayers: "Players" +keyWordScoreboardScore: "Score" + +adminReload: "&aPlugin CubeRunner has been successfully reloaded." + +cmdDescriptionHelp: "&7You already know how to do that don't you? ;)" +cmdDescriptionLanguage: "&7Change your own language for CubeRunner's plugin." +cmdDescriptionStats: "&7Opens your CubeRunner's stats." +cmdDescriptionList: "&7Opens a list of all the arenas." +cmdDescriptionInfo: "&7Display every information from the selected arena." +cmdDescriptionJoin: "&7Join the specified game or open a GUI to choose." +cmdDescriptionQuit: "&7Leave your current game." +cmdDescriptionStart: "&7Initiate the starting countdown." +cmdDescriptionNew: "&7Creates a new CubeRunner arena." +cmdDescriptionDelete: "&7Delete the specified arena." +cmdDescriptionSetzone: "&7Set the delimitation of the selected arena with a World Edit region." +cmdDescriptionSetlobby: "&7Set the lobby of the selected arena." +cmdDescriptionStartpoint: "&7Set the start point of the selected arena." +cmdDescriptionSetcolor: "&7Set the block colors for the arena" +cmdDescriptionSetminplayer: "&7Set the minimum amount of player for an arena." +cmdDescriptionSetmaxplayer: "&7Set the maximum amount of player for an arena." +cmdDescriptionReload: "&7Reload the config, the player data and the language files." \ No newline at end of file diff --git a/Bukkit/LanguageFiles/fr.yml b/Bukkit/LanguageFiles/fr.yml new file mode 100644 index 0000000..53801fb --- /dev/null +++ b/Bukkit/LanguageFiles/fr.yml @@ -0,0 +1,182 @@ +# CubeRunner plugin +# Made by PoutineQc +# fr.yml - Language file + +languageName: "Francais" + +prefixShort: "&7[&5CR&7]" +prefixLong: "&8[&5CubeRunner&8]" + +developper: "&5Developpé par: &7%developper%" +version: "&5Version: &7%version%" +description: "&dTape &5/%command% help &d pour la liste des commandes." + +errorPermission: "&4Tu n'a pas la permission de faire cela." +errorCommand: "&cCommande ou arène introuvable. Tape &8/%cmd% help &cpour de la liste des commandes." +errorTeleport: "&cTu ne peux pas te téléporter en cours de partie. Fais &7/cr quit &cpour quiter" +errorMissingArena: "&cIl faut spécifier une arène valide." +errorAlreadyInGame: "&cTu es déja dans une partie de CubeRunner." +errorNotInGame: "&cTu n'es pas dans une partie de CubeRunner." + +infoTip: "&8[&7Truc&8] &7Tu peux aussi faire &8/%cmd% list &7et effectuer un clic droit sur une arène pour afficher ses informations." + +joinUnready: "&cL'arène que tu essaie de joindre n'est pas disponible." +joinActive: "&cUne partie est déja en cours dans cette arène." +joinSpectator: "&dPartie rejointe en tant que spectateur." +joinPlayer: "&aTu as rejoint l'arène &2%arena%&a." +joinOthers: "&f%player% &da rejoint votre partie." +joinGuiTitle: "&2Arènes" +joinGuiInfo: "&eClick le nom de l'arène que tu souhaites joindre." +joinGuiTipStarted: "&cEn cours de partie : &eClique pour assister" +joinGuiTipJoin: "&aPrête : &eClique pour rejoindre" + +quitPlayer: "&aTu as quitté l'arène &2%arena%&a." +quitOthers: "&f%player% &da quitté votre partie." + +startNotReady: "&cLa partie n'est pas prête a commencer." +startMinimum: "&cIl doit y avoir au moins %amount% joueurs pour commencer la partie." +startMaximum: "&cIl doit y avoir au plus %amount% joueurs pour commencer la partie." +startBroadcast: "&dUne nouvelle partie de &5CubeRunner &dva commencer sous peu. Vous pouvez la rejoindre avec &5/cr join %arena%&d." +startStop: "&cLe décompte a été annulé. Il n'y a plus assez de joueurs." + +endCrushPlayer: "&dTu t'es fait écraser avec un score de &5%score%&d. Game over!" +endCrushOthers: "&f%player% &ds'est fait écraser avec un score de &5%score%&d." +endHidePlayer: "&dTu as été éjecté de la partie pour t'être caché sous un bloc." +endHideOthers: "&f%player% &da été éjecté de la partie pour s'être caché sous un bloc." +endTeleport: "&dLa partie est finie. Vous serez téléportés dans 5 secondes..." +endBest: "&6Bravo à &f%player% &6qui a fait le nouveau record de &4%score% &6dans l'arène &5%arena%" +endReward: "&dTu gagne %amount%%currency% pour avoir survécu %amount2% secondes." +endBroadcastMultiplayer: "&6Félicitation à &f%player% &6qui vient de gagner une partie multijoueur de CubeRunner dans l'arène &5%arena% &6avec un score de &4%score%&6!" +endBroadcastSingleplayer: "&f%player% &6a fini une partie de CubeRunner dans l'arène &5%arena% &6avec un score de &4%score%&6!" + +statsGuiTitle: "&6Statistiques" +statsInfoAverageScore: "&bScore moyen par partie" +statsInfoDistanceRan: "&bDistance totale courue" +statsInfoGames: "&bParties jouées" +statsInfoTotalScore: "&bScore total" +statsInfoKills: "&bJoueurs tués" +statsInfoMultiplayerWon: "&bParties multijoueurs gagnées" +statsInfoTimePlayed: "&dTemps joué" +statsInfoMoney: "&dArgent gagné" +statsChallengesTitle: "&bDéfis" + +achievementBroadcast: "&f%player% &6a complété le défi &d%achievementName%&6!" +achievementReward: "&dTu a gagné %amount%%currency% pour ton défi." +achievementAmountGame: "&dJouer %amount% partie(s)" +achievementTotalScore: "&dAtteidre le score total de %amount%" +achievementKills: "&dTuer %amount% joueur(s)" +achievementMultiplayerWon: "&dGagner %amount% partie(s) multijoueurs" +achievementSurvive5Minutes: "&dSurvivre 5 minutes" +achievementReachHeight10: "&dAtteindre la hauteur 10" +achievementFillTheArena: "&dRemplir le plancher de l'arène" +achievementAnswerToLife: "&dLa réponse à la vie, à l'univers et à l'humanité" +achievementRageQuit: "&dLe Rage Quit!" +achievementKillerBunny: "&dLe lapin tueur" + +editCreateNoname: "&cTu dois spécifier un nom pour l'arène." +editNewSuccess: "&aUne arène appelée &2%arena% &aà été créé." +editNewExists: "&cIl y a déja une arène appelée &4%arena%&c." +editNewLongName: "&cLe nom de l'arène ne peux pas être plus long que 12 caractères." +editErrorArena: "&cL'arène &4%arena% &cn'existe pas." +editRegionWorldedit: "&cTu dois sélectionner une région World Edit." +editRegion: "&aLa zone a été sélectionnée avec succès pour l'arène &2%arena%&a." +editStartPoint: "&aLe point de départ a été sélectionné avec succès pour l'arène &2%arena%&a." +editLobby: "&aLa salle d'attente a été séléctionnée avec succès pour l'arène &2%arena%&a." +editPlayersMissing: "&cTu dois nommer une quantitée pour changer le nombre de joueurs." +editPlayersError: "&cCe nombre de joueurs n'est pas valide. &7[&8%error%&7]" +editPlayersNaN: "Pas un nombre" +editPlayersMinimum1: "Minimum plus petit que 1" +editPlayersMinimumMaximum: "Minimum plus haut que le maximum" +editPlayersMaximumMinimum: "Maximum plus bas que le minimum" +editPlayersMaximum10 : "Maximum plus haut que 10" +editPlayers: "&aNombre de joueurs changé pour l'arène &2%arena%&a." +editColorGuiTitle: "&4Couleurs" +editColorGuiInfo: "&eLes blocs séléctionnés\n&esont ceux enchantés.\n&eCliquez sur un bloc\n&epour l'activer ou le désactiver." +editColorError: "&cTu ne peux pas changer les couleur alors qu'il y a une partie en cours." +editDelete: "&cArène supprimée." + +languageList: "Langues disponibles" +languageNotFound: "&cLangue non-trouvée. &8/%cmd% language &cpour une liste des langues disponibles" +languageChanged: "&aLangue changée avec succès au francais" + +helpErrorPermission: "&cTu n'as aucune permission dans cette catégorie." +helpDescriptionAll: "&7Toutes les commandes" +helpDescriptionGeneral: "&7Commandes générales pour joueurs" +helpDescriptionGame: "&7Commandes pour jouer au jeu" +helpDescriptionArena: "&7Commandes pour configurer les arènes" +helpDescriptionAdmin: "&7Commandes pour la maintenance du jeu" + +signPerm0: "&cManque perms" +signPerm1: "&cpour faire" +signPerm2: "&cdes pancartes" +signPerm3: "&cCubeRunner." +signValid1: "&cParamètres" +signValid2: "&cnon-valides" +signValid3: "&cRéessayez" + +keyWordSignJoin: "&aRejoindre" +keyWordSignQuit: "&cQuitter" +keyWordSignStart: "&9Commencer" +keyWordSignStats: "&6Statistiques" +keyWordSignPlay: "&aJouer" +keyWordSignTop: "&bMeilleur Score" + +keyWordGuiInstructions: "&6Instructions" +keyWordGuiPage: "&2Page %number%" + +keyWordGameStateUnset: "&7Arène non définie" +keyWordGameStatReady: "&aPrêt" +keyWordGameStatStartup: "&9Démarrage" +keyWordGameStatActive: "&cActif" + +keyWordGeneralHours: "heures" +keyWordGeneralMinutes: "minutes" +keyWordGeneralSeconds: "secondes" +keyWordGeneralDistance: "km" +keyWordGeneralBy: "par" + +keyWordHelp: "Aide" +keyWordHelpCategory: "Catégorie" +keyWordHelpPage: "Page" + +keyWordInfo: "Information" +keyWordInfoAdvanced: "Information Avancé" +keyWordInfoMinimum: "Minimum" +keyWordInfoMaximum: "Maximum" +keyWordInfoCurrent: "Actuel" +keyWordInfoAmountPlayer: "nombre de joueurs" +keyWordInfoGameState: "état du jeu" +keyWordInfoWorld: "Monde" +keyWordInfoLobby: "Salle d'attente" +keyWordInfoStartPoint: "Point de départ" +keyWordInfoZoneMinPoint: " coordonée de zone" +keyWordInfoBestScore: "Meilleur Score" + +keyWordStatsTop10: "Top 10" +keyWordStatsProgression: "Progression" +keyWordStatsCompleted: "Complété" +keyWordStatsNotCompleted: "Non Complété" +keyWordStatsReward: "Récompense" + +keyWordScoreboardPlayers: "Joueurs" +keyWordScoreboardScore: "Pointage" + +adminReload: "&aLe plugin CubeRunner a été relancé avec succès." + +cmdDescriptionHelp: "&7Tu sais déjà cela n'est ce pas? ;)" +cmdDescriptionLanguage: "&7Change ton language personnel pour le plugin CubeRunner." +cmdDescriptionStats: "&7Ouvre les statistiques CubeRunner." +cmdDescriptionList: "&7Ouvre la liste des arènes." +cmdDescriptionInfo: "&7Montre les informations de l'arène séléctionnée." +cmdDescriptionJoin: "&7Rejoins la partie spécifiée ou ouvre un GUI pour choisir." +cmdDescriptionQuit: "&7Quitte la partie en cours." +cmdDescriptionStart: "&7Commence le décompte de démarrage." +cmdDescriptionNew: "&7Crée une nouvelle arène CubeRunner." +cmdDescriptionDelete: "&7Supprime l'arène specifiée." +cmdDescriptionSetzone: "&7Configure la délimitation de l'arène en utilisant une région WorldEdit." +cmdDescriptionSetlobby: "&7Configure la salle d'attente de l'arène séléctionnée." +cmdDescriptionStartpoint: "&7Configure le point de départ de l'arène séléctionnée." +cmdDescriptionSetcolor: "&7Séléctionne les couleurs dans l'arène séléctionnée" +cmdDescriptionSetminplayer: "&7Configure le nombre de joueurs minimum pour l'arène séléctionée." +cmdDescriptionSetmaxplayer: "&7Configure le nombre de joueurs maximum pour l'arène séléctionée." +cmdDescriptionReload: "&7Relance le fichier de config, le player data et les fichiers de langues." \ No newline at end of file diff --git a/Bukkit_1.9/achievements.yml b/Bukkit/achievements.yml similarity index 72% rename from Bukkit_1.9/achievements.yml rename to Bukkit/achievements.yml index 97cb751..a834bbb 100644 --- a/Bukkit_1.9/achievements.yml +++ b/Bukkit/achievements.yml @@ -29,4 +29,12 @@ multiplayerGamesWon: - 2;5.0 - 20;40.0 - 75;100.0 - - 250;300.0 \ No newline at end of file + - 250;300.0 + +# Challenge Rewards +rewardSurvive5Minutes: 25.0 +rewardFillTheArenasFloor: 50.0 +rewardReachHeight10: 100.0 +rewardTheRageQuit: 15.0 +rewardTheKillerBunny: 15.0 +rewardTheAnswerToLife: 15.0 \ No newline at end of file diff --git a/Bukkit/config.yml b/Bukkit/config.yml new file mode 100644 index 0000000..5a85993 --- /dev/null +++ b/Bukkit/config.yml @@ -0,0 +1,114 @@ +############################################################ +# +------------------------------------------------------+ # +# | Notes | # +# +------------------------------------------------------+ # +############################################################ + +# CubeRunner plugin +# Made by PoutineQc +# config.yml - Config File + +# If you want to edit the challenges' rewards +# Go in the achievements.yml file in the plugin/CubeRunner folder + +############################################################ +# +------------------------------------------------------+ # +# | CubeRunner general configuration | # +# +------------------------------------------------------+ # +############################################################ + +# Currently available languages: +# "fr" - Francais +# "en" - English +# "de" - Deutsch +# You may make another YAML file with another language +# Simply put it in the LanguageFiles folder and write it's name here (without the ".yml") +# This will option will be the "CR server language".. The signs will be in this language. +# Warning: If you change this, a simple /dac reload won't do, you'll have to restart the server. +language: 'en' + +# Set to true if you have a MySQL database and fill the information below +# Warning: If you change this, a simple /dac reload won't do, you'll have to restart the server. +mysql: false +host: 127.0.0.1 +port: 3306 +user: '' +password: '' +database: 'minecraft' +tablePrefix: 'cuberunner_' + +# If you want the Plugin's "logo" ([cr] if not changed) to be displayed in front of every messages +prefixInFrontOfEveryMessages: true + +# True : The game starts automaticly as soon as there are enough players in the lobby +# False : Players have to manually start the game +autostart: true + +# The countdown from the moment a players starts the game to the beginning of the block shower. (in seconds) +# Players may still join the game during this countdown +countdownTime: 15 + +# Set to true if you want player's inventories to be cleared during a game and returned after it. +# Note : If the server crash of the plugin throws an error (which should not happend) during a game, +# the player will permenantly loose it's inventory +saveAndClearInventory: true + +# Set to true if you want players to get back to their original location after the end of the game +teleportAfterEnding: true + +# Broadcasts +# True to enable - False to disable +broadcasts: + startup: true + achievement: true + ending: + singleplayer: true + multiplayer: true + + +############################################################ +# +------------------------------------------------------+ # +# | Rewards and end game commands | # +# +------------------------------------------------------+ # +############################################################ + +# Economy Rewards +# Requires Vault and an economy plugin +economyRewards: false + +# Reward at the end of the game +# The reward will be the amount selected below times the score of the player +# Choose the reward amounts depending on the values of your server's economy +pricePerScore: 0.05 + +# if true, when completing a challenge gives a money reward +# will be false in all cases if you disable the economy rewards +achievementsRewards: true + +# Commands that the console will execute at the end of the game +# (Examples below) +# +-----------------------------------------------------------------------------------------------------+ +# | Key Words | Commands with this node are executed : | +# |-----------------------------------------------------------------------------------------------------| +# | %winner% | when the last player from a multiplayer game is eliminated where %winner% is the winner | +# | %player% | whenever a player is eliminated where %player% is the eliminated player | +# | (nothing) | at the end of a game | +# |-----------------------------------------------------------------------------------------------------| +# | %all% | Everybody playing and watching | +# | %arena% | Name of the arena the game is being played in | +# | %prefix% | CubeRunner's prefix as in all CubeRunner's messages | +# +-----------------------------------------------------------------------------------------------------+ +commands: +# - minecraft:playsound minecraft:entity.zombie.death hostile %player% +# - minecraft:give %winner% minecraft:apple 10 +# - send %all% hub +# - minecraft:tell @a %prefix% The CubeRunner's arena %arena% is now ready for a new game +# - minecraft:weather clear + +############################################################ +# +------------------------------------------------------+ # +# | Updates | # +# +------------------------------------------------------+ # +############################################################ + +checkForUpdates: true \ No newline at end of file diff --git a/Bukkit_1.8/plugin.yml b/Bukkit/plugin.yml similarity index 96% rename from Bukkit_1.8/plugin.yml rename to Bukkit/plugin.yml index 974fc7b..404263b 100644 --- a/Bukkit_1.8/plugin.yml +++ b/Bukkit/plugin.yml @@ -1,11 +1,11 @@ name: CubeRunner main : me.poutineqc.cuberunner.CubeRunner -version: 2.2.1 +version: 2.4.1 description: Blocks are falling over your head! Can you outrun them? load: postworld author: PoutineQc database: false -prefix: CubeRunner +prefix: CR commands: cuberunner: @@ -22,11 +22,15 @@ permissions: cuberunner.player.*: description: Gives access to all commands simply needed to play the game children: + cuberunner.player.help: true cuberunner.player.list: true cuberunner.player.info: true cuberunner.player.stats: true cuberunner.player.language: true cuberunner.player.play.*: true + cuberunner.player.help: + description: Allows to get command help + default: true cuberunner.player.list: description: Allows to see the list of arenas default: true diff --git a/Bukkit/src/me/poutineqc/cuberunner/AchievementManager.java b/Bukkit/src/me/poutineqc/cuberunner/AchievementManager.java new file mode 100644 index 0000000..859094d --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/AchievementManager.java @@ -0,0 +1,223 @@ +package me.poutineqc.cuberunner; + +import java.util.HashMap; +import java.util.LinkedHashMap; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import me.poutineqc.cuberunner.CRPlayer.PlayerStatsException; +import me.poutineqc.cuberunner.Language.Messages; +import me.poutineqc.cuberunner.utils.MinecraftConfiguration; +import net.milkbowl.vault.economy.Economy; + +public class AchievementManager { + + private HashMap> achievements; + private HashMap challenges; + + public AchievementManager(CubeRunner plugin) { + MinecraftConfiguration config = new MinecraftConfiguration(null, "achievements", true); + + generateAchievements(config); + generateChallenges(config); + } + + private void generateAchievements(MinecraftConfiguration config) { + achievements = new HashMap>(); + + for (Achievement achievement : Achievement.values()) { + achievements.put(achievement, new LinkedHashMap()); + + for (String line : config.get().getStringList(achievement.configName)) { + + AchievementReader reader = new AchievementReader(line); + if (!reader.ok) { + Bukkit.getLogger().warning("Could not read line [" + line + "] from achievements.yml.. Ignoring"); + continue; + } + + achievements.get(achievement).put(reader.level, reader.reward); + } + } + } + + private void generateChallenges(MinecraftConfiguration config) { + challenges = new HashMap(); + + for (Challenge challenge : Challenge.values()) + challenges.put(challenge, config.get().getDouble(challenge.configName)); + } + + public void complete(CRPlayer player, CRStats crStats, int value) { + Achievement achievement = Achievement.association.get(crStats); + if (achievement == null) + return; + + if (!achievements.get(achievement).containsKey(value)) + return; + + congradulate(player, achievement, value); + + if (CubeRunner.get().isEconomyEnabled()) { + double reward = achievements.get(achievement).get(value); + Economy economy = CubeRunner.get().getEconomy(); + economy.depositPlayer(player.getPlayer(), reward); + + Language local = player.getLanguage(); + local.sendMsg(player.getPlayer(), local.get(Messages.ACHIEVEMENT_REWARD) + .replace("%amount%", String.valueOf(reward)).replace("%currency%", economy.currencyNamePlural())); + + try { + player.addDouble(CRStats.MONEY, reward); + } catch (PlayerStatsException e) { + e.printStackTrace(); + } + } + } + + private void congradulate(CRPlayer player, Achievement achievement, int amount) { + if (CubeRunner.get().getConfiguration().broadcastAchievement) + for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { + Language local = CubeRunner.get().getLang(onlinePlayer); + local.sendMsg(onlinePlayer, local.get(Messages.ACHIEVEMENT_BROADCAST) + .replace("%player%", player.getPlayer().getDisplayName()).replace("%achievementName%", + local.get(achievement.achievementMessage).replace("%amount%", String.valueOf(amount)))); + } + } + + public void complete(CRPlayer player, CRStats crStats) { + Challenge challenge = Challenge.association.get(crStats); + if (challenge == null) + return; + + congradulate(player, challenge); + + if (CubeRunner.get().isEconomyEnabled()) { + double reward = challenges.get(challenge); + Economy economy = CubeRunner.get().getEconomy(); + economy.depositPlayer(player.getPlayer(), reward); + + Language local = player.getLanguage(); + local.sendMsg(player.getPlayer(), local.get(Messages.ACHIEVEMENT_REWARD) + .replace("%amount%", String.valueOf(reward)).replace("%currency%", economy.currencyNamePlural())); + + try { + player.addDouble(CRStats.MONEY, reward); + } catch (PlayerStatsException e) { + e.printStackTrace(); + } + } + } + + private void congradulate(CRPlayer player, Challenge challenge) { + if (CubeRunner.get().getConfiguration().broadcastAchievement) + for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { + Language local = CubeRunner.get().getLang(onlinePlayer); + local.sendMsg(onlinePlayer, + local.get(Messages.ACHIEVEMENT_BROADCAST) + .replace("%player%", player.getPlayer().getDisplayName()) + .replace("%achievementName%", local.get(challenge.message))); + } + } + + private class AchievementReader { + private boolean ok = true; + private int level; + private double reward; + + private AchievementReader(String line) { + String[] lineArgs = line.split(";"); + + try { + level = Integer.parseInt(lineArgs[0]); + reward = Double.parseDouble(lineArgs[1]); + + } catch (NumberFormatException | IndexOutOfBoundsException e) { + ok = false; + } + } + } + + public enum Achievement { + GAMES_PLAYED(CRStats.GAMES_PLAYED, "amountOfGamesPlayed", Messages.ACHIEVEMENT_GAMES, Messages.STATS_INFO_GAMES), + TOTAL_SCORE(CRStats.TOTAL_SCORE, "totalScore", Messages.ACHIEVEMENT_TOTAL_SCORE, Messages.STATS_INFO_GAMES), + KILLS(CRStats.KILLS, "amountPlayerKills", Messages.ACHIEVEMENT_KILLS, Messages.STATS_INFO_GAMES), + MULTIPLAYER_WON(CRStats.MULTIPLAYER_WON, "multiplayerGamesWon", Messages.ACHIEVEMENT_MULTIPLAYER_WON, Messages.STATS_INFO_GAMES); + + private final CRStats stats; + private final String configName; + private final Messages achievementMessage; + private final Messages statsMessage; + + private static HashMap association; + + static { + association = new HashMap(); + for (Achievement achievement : Achievement.values()) + association.put(achievement.stats, achievement); + } + + private Achievement(CRStats stats, String configName, Messages achievementMessage, Messages statsMessage) { + this.stats = stats; + this.configName = configName; + this.achievementMessage = achievementMessage; + this.statsMessage = statsMessage; + } + + public CRStats getCrStats() { + return stats; + } + + public Messages getMessage() { + return statsMessage; + } + + public Messages getAchievementMessage() { + return achievementMessage; + } + } + + public enum Challenge { + SURVIVE_5_MINUTES(CRStats.SURVIVE_5_MINUTES, "rewardSurvive5Minutes", Messages.ACHIEVEMENT_SURVIVE_5_MINUTES), + FILL_THE_ARENA(CRStats.FILL_THE_ARENA, "rewardFillTheArenasFloor", Messages.ACHIEVEMENT_FILL_THE_ARENA), + REACH_HEIGHT_10(CRStats.REACH_HEIGHT_10, "rewardReachHeight10", Messages.ACHIEVEMENT_REACH_HEIGHT_10), + THE_RAGE_QUIT(CRStats.THE_RAGE_QUIT, "rewardTheRageQuit", Messages.ACHIEVEMENT_RAGE_QUIT), + THE_KILLER_BUNNY(CRStats.THE_KILLER_BUNNY, "rewardTheKillerBunny", Messages.ACHIEVEMENT_KILLER_BUNNY), + THE_ANSWER_TO_LIFE(CRStats.THE_ANSWER_TO_LIFE, "rewardTheAnswerToLife", Messages.ACHIEVEMENT_ANSWER_TO_LIFE); + + private final CRStats stats; + private final String configName; + private final Messages message; + + private static HashMap association; + + static { + association = new HashMap(); + for (Challenge challenge : Challenge.values()) + association.put(challenge.stats, challenge); + } + + private Challenge(CRStats stats, String configName, Messages message) { + this.stats = stats; + this.configName = configName; + this.message = message; + } + + public CRStats getCrStats() { + return stats; + } + + public Messages getMessage() { + return message; + } + } + + public HashMap> getAchievements() { + return achievements; + } + + public HashMap getChallenges() { + return challenges; + } +} diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/ArenaData.java b/Bukkit/src/me/poutineqc/cuberunner/ArenaData.java similarity index 100% rename from Bukkit_1.8/src/me/poutineqc/cuberunner/ArenaData.java rename to Bukkit/src/me/poutineqc/cuberunner/ArenaData.java diff --git a/Bukkit/src/me/poutineqc/cuberunner/CRPlayer.java b/Bukkit/src/me/poutineqc/cuberunner/CRPlayer.java new file mode 100644 index 0000000..9cfba26 --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/CRPlayer.java @@ -0,0 +1,243 @@ +package me.poutineqc.cuberunner; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.entity.Player; + +import me.poutineqc.cuberunner.commands.inventories.CRInventory; +import me.poutineqc.cuberunner.utils.MinecraftConfiguration; + +public class CRPlayer { + + private UUID uuid; + private HashMap stats = new HashMap(); + private CRInventory crInventory; + + public CRPlayer(UUID uuid, String name) { + this.uuid = uuid; + + if (CubeRunner.get().getMySQL().hasConnection()) + CubeRunner.get().getMySQL().newPlayer(uuid, name); + else { + MinecraftConfiguration config = CubeRunner.get().getPlayerConfig(); + for (CRStats key : CRStats.values()) { + if (key == CRStats.NAME) + config.get().set("players." + uuid.toString() + "." + key.getNameFlatFile(), name); + else + config.get().set("players." + uuid.toString() + "." + key.getNameFlatFile(), key.getDefaultValue()); + + config.save(); + } + + CubeRunner.get().updateAll(this); + } + + for (CRStats stats : CRStats.values()) { + this.stats.put(stats, stats.getDefault()); + if (stats == CRStats.NAME) + this.stats.put(stats, name); + } + } + + public CRPlayer(String uuid, ConfigurationSection config) { + this.uuid = UUID.fromString(uuid); + + for (CRStats stats : CRStats.values()) + this.stats.put(stats, stats.getValue(config)); + + CubeRunner.get().updateAll(this); + } + + public CRPlayer(ResultSet query) { + try { + this.uuid = UUID.fromString(query.getString("UUID")); + + for (CRStats stats : CRStats.values()) + this.stats.put(stats, stats.getValue(query)); + + } catch (SQLException e) { + Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could read some informations from playerData.ylm."); + } + + CubeRunner.get().updateAll(this); + } + + private void updateInformation(CRStats key, String value) { + if (CubeRunner.get().getMySQL().hasConnection()) + CubeRunner.get().getMySQL().updatePlayer(uuid, key, value); + else { + CubeRunner.get().getPlayerConfig().get().set("players." + uuid.toString() + "." + key.getNameFlatFile(), + value); + CubeRunner.get().getPlayerConfig().save(); + } + } + + private void updateInformation(CRStats key, double value) { + if (CubeRunner.get().getMySQL().hasConnection()) + CubeRunner.get().getMySQL().updatePlayer(uuid, key, String.valueOf(value)); + else { + CubeRunner.get().getPlayerConfig().get().set("players." + uuid.toString() + "." + key.getNameFlatFile(), + value); + CubeRunner.get().getPlayerConfig().save(); + } + } + + private void updateInformation(CRStats key, int value) { + if (CubeRunner.get().getMySQL().hasConnection()) + CubeRunner.get().getMySQL().updatePlayer(uuid, key, String.valueOf(value)); + else { + CubeRunner.get().getPlayerConfig().get().set("players." + uuid.toString() + "." + key.getNameFlatFile(), + value); + CubeRunner.get().getPlayerConfig().save(); + } + } + + private void updateInformation(CRStats key, boolean value) { + if (CubeRunner.get().getMySQL().hasConnection()) + CubeRunner.get().getMySQL().updatePlayer(uuid, key, value ? "1" : "0"); + else { + CubeRunner.get().getPlayerConfig().get().set("players." + uuid.toString() + "." + key.getNameFlatFile(), + value); + CubeRunner.get().getPlayerConfig().save(); + } + } + + public void setCurrentInventory(CRInventory crInventory) { + this.crInventory = crInventory; + } + + public CRInventory getCurrentInventory() { + return crInventory; + } + + public UUID getUUID() { + return uuid; + } + + public Player getPlayer() { + return Bukkit.getOfflinePlayer(uuid).getPlayer(); + } + + public void setName(String name) { + stats.put(CRStats.NAME, name); + updateInformation(CRStats.NAME, name); + } + + public String getName() { + return (String) stats.get(CRStats.NAME); + } + + public void setLanguage(Language local) { + stats.put(CRStats.LANGUAGE, local); + updateInformation(CRStats.LANGUAGE, local.getFileName()); + } + + public Language getLanguage() { + return (Language) stats.get(CRStats.LANGUAGE); + } + + public void updateAverageScorePerGame() { + int distance = (int) stats.get(CRStats.TOTAL_SCORE); + int games = (int) stats.get(CRStats.GAMES_PLAYED); + stats.put(CRStats.AVERAGE_SCORE, (double) distance / games); + updateInformation(CRStats.AVERAGE_SCORE, distance / games); + } + + public void addInt(CRStats crStats, int amount) throws PlayerStatsException { + Object value = stats.get(crStats); + if (!(value instanceof Integer)) + throw new PlayerStatsException("Stat [" + crStats.name() + "] is not an Integer."); + + stats.put(crStats, (int) value + amount); + updateInformation(crStats, (int) value + amount); + } + + public void addDouble(CRStats crStats, double amount) throws PlayerStatsException { + Object value = stats.get(crStats); + if (!(value instanceof Double)) + throw new PlayerStatsException("Stat [" + crStats.name() + "] is not a Double."); + + stats.put(crStats, (double) value + amount); + updateInformation(crStats, (double) value + amount); + } + + public void increment(CRStats crStats, boolean save) throws PlayerStatsException { + Object value = stats.get(crStats); + if (!(value instanceof Integer)) + throw new PlayerStatsException("Stat [" + crStats.name() + "] is not an Incrementor."); + + stats.put(crStats, ((int) value) + 1); + CubeRunner.get().getAchievementManager().complete(this, crStats, ((int) value) + 1); + + if (save) + saveIncrementor(crStats); + } + + public void saveIncrementor(CRStats crStats) throws PlayerStatsException { + Object value = stats.get(crStats); + if (!(value instanceof Integer)) + throw new PlayerStatsException("Stat [" + crStats.name() + "] is not an Incrementor."); + + updateInformation(crStats, (int) value); + } + + public void doneChallenge(CRStats challenge) throws PlayerStatsException { + Object didIt = stats.get(challenge); + if (!(didIt instanceof Boolean)) + throw new PlayerStatsException("Stat [" + challenge.name() + "] is not a challenge."); + + if (!((boolean) didIt)) { + stats.put(challenge, true); + updateInformation(challenge, true); + CubeRunner.get().getAchievementManager().complete(this, challenge); + } + } + + public int getInt(CRStats crStats) throws PlayerStatsException { + Object value = stats.get(crStats); + if (!(value instanceof Integer)) + throw new PlayerStatsException("Stat [" + crStats.name() + "] is not an Integer."); + + return (int) value; + } + + public double getDouble(CRStats crStats) throws PlayerStatsException { + Object value = stats.get(crStats); + if (!(value instanceof Double) && !(value instanceof Integer)) + throw new PlayerStatsException("Stat [" + crStats.name() + "] is not a Double."); + + return (double) value; + } + + public boolean hasChallenge(CRStats challenge) throws PlayerStatsException { + Object didIt = stats.get(challenge); + if (!(didIt instanceof Boolean)) + throw new PlayerStatsException("Stat [" + challenge.name() + "] is not a challenge."); + + return (boolean) didIt; + } + + public class PlayerStatsException extends Exception { + + /** + * + */ + private static final long serialVersionUID = -4844283181470739524L; + + public PlayerStatsException(String message) { + super(message); + } + + } + + public Object get(CRStats stat) { + return stats.get(stat); + } + +} diff --git a/Bukkit/src/me/poutineqc/cuberunner/CRStats.java b/Bukkit/src/me/poutineqc/cuberunner/CRStats.java new file mode 100644 index 0000000..e2abdfb --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/CRStats.java @@ -0,0 +1,296 @@ +package me.poutineqc.cuberunner; + +import java.sql.ResultSet; +import java.sql.SQLException; + +import org.bukkit.configuration.ConfigurationSection; + +public enum CRStats { + + GAMES_PLAYED("games", "games", 0) { + @Override + public Object getValue(ResultSet query) throws SQLException { + return query.getInt(this.getNameMySQL()); + } + + @Override + public Object getValue(ConfigurationSection config) { + return config.getInt(this.getNameFlatFile(), (int) this.getDefaultValue()); + } + + @Override + public Object getDefault() { + return (int) 0; + } + }, + TOTAL_SCORE("totalScore", "totalScore", 0) { + @Override + public Object getValue(ResultSet query) throws SQLException { + return query.getInt(this.getNameMySQL()); + } + + @Override + public Object getValue(ConfigurationSection config) { + return config.getInt(this.getNameFlatFile(), (int) this.getDefaultValue()); + } + + @Override + public Object getDefault() { + return 0; + } + }, + KILLS("kills", "kills", 0) { + @Override + public Object getValue(ResultSet query) throws SQLException { + return query.getInt(this.getNameMySQL()); + } + + @Override + public Object getValue(ConfigurationSection config) { + return config.getInt(this.getNameFlatFile(), (int) this.getDefaultValue()); + } + + @Override + public Object getDefault() { + return 0; + } + }, + MULTIPLAYER_WON("multiplayerWon", "multiplayerWon", 0) { + @Override + public Object getValue(ResultSet query) throws SQLException { + return query.getInt(this.getNameMySQL()); + } + + @Override + public Object getValue(ConfigurationSection config) { + return config.getInt(this.getNameFlatFile(), (int) this.getDefaultValue()); + } + + @Override + public Object getDefault() { + return 0; + } + }, + TOTAL_DISTANCE("totalDistance", "totalDistance", 0.0) { + @Override + public Object getValue(ResultSet query) throws SQLException { + return query.getDouble(this.getNameMySQL()); + } + + @Override + public Object getValue(ConfigurationSection config) { + return config.getDouble(this.getNameFlatFile(), (double) this.getDefaultValue()); + } + + @Override + public Object getDefault() { + return 0.0; + } + }, + AVERAGE_SCORE("averageDistancePerGame", "averageDistancePerGame", 0.0) { + @Override + public Object getValue(ResultSet query) throws SQLException { + return query.getDouble(this.getNameMySQL()); + } + + @Override + public Object getValue(ConfigurationSection config) { + return config.getDouble(this.getNameFlatFile(), (double) this.getDefaultValue()); + } + + @Override + public Object getDefault() { + return 0.0; + } + }, + + TIME_PLAYED("timePlayed", "timePlayed", 0) { + @Override + public Object getValue(ResultSet query) throws SQLException { + return query.getInt(this.getNameMySQL()); + } + + @Override + public Object getValue(ConfigurationSection config) { + return config.getInt(this.getNameFlatFile(), (int) this.getDefaultValue()); + } + + @Override + public Object getDefault() { + return 0; + } + }, + MONEY("money", "money", 0.0) { + @Override + public Object getValue(ResultSet query) throws SQLException { + return query.getDouble(this.getNameMySQL()); + } + + @Override + public Object getValue(ConfigurationSection config) { + return config.getDouble(this.getNameFlatFile(), (double) this.getDefaultValue()); + } + + @Override + public Object getDefault() { + return 0.0; + } + }, + + SURVIVE_5_MINUTES("survive5Minutes", "achievement.survive5Minutes", false) { + @Override + public Object getValue(ResultSet query) throws SQLException { + return query.getBoolean(this.getNameMySQL()); + } + + @Override + public Object getValue(ConfigurationSection config) { + return config.getBoolean(this.getNameFlatFile(), (boolean) this.getDefaultValue()); + } + + @Override + public Object getDefault() { + return false; + } + }, + REACH_HEIGHT_10("reachHeight10", "achievement.reachHeight10", false) { + @Override + public Object getValue(ResultSet query) throws SQLException { + return query.getBoolean(this.getNameMySQL()); + } + + @Override + public Object getValue(ConfigurationSection config) { + return config.getBoolean(this.getNameFlatFile(), (boolean) this.getDefaultValue()); + } + + @Override + public Object getDefault() { + return false; + } + }, + FILL_THE_ARENA("fillTheArena", "achievement.fillTheArena", false) { + @Override + public Object getValue(ResultSet query) throws SQLException { + return query.getBoolean(this.getNameMySQL()); + } + + @Override + public Object getValue(ConfigurationSection config) { + return config.getBoolean(this.getNameFlatFile(), (boolean) this.getDefaultValue()); + } + + @Override + public Object getDefault() { + return false; + } + }, + THE_ANSWER_TO_LIFE("theAnswerToLife", "achievement.theAnswerToLife", false) { + @Override + public Object getValue(ResultSet query) throws SQLException { + return query.getBoolean(this.getNameMySQL()); + } + + @Override + public Object getValue(ConfigurationSection config) { + return config.getBoolean(this.getNameFlatFile(), (boolean) this.getDefaultValue()); + } + + @Override + public Object getDefault() { + return false; + } + }, + THE_RAGE_QUIT("theRageQuit", "achievement.theRageQuit", false) { + @Override + public Object getValue(ResultSet query) throws SQLException { + return query.getBoolean(this.getNameMySQL()); + } + + @Override + public Object getValue(ConfigurationSection config) { + return config.getBoolean(this.getNameFlatFile(), (boolean) this.getDefaultValue()); + } + + @Override + public Object getDefault() { + return false; + } + }, + THE_KILLER_BUNNY("theKillerBunny", "achievement.theKillerBunny", false) { + @Override + public Object getValue(ResultSet query) throws SQLException { + return query.getBoolean(this.getNameMySQL()); + } + + @Override + public Object getValue(ConfigurationSection config) { + return config.getBoolean(this.getNameFlatFile(), (boolean) this.getDefaultValue()); + } + + @Override + public Object getDefault() { + return false; + } + }, + NAME("name", "name", "default") { + @Override + public Object getValue(ResultSet query) throws SQLException { + return query.getString(this.getNameMySQL()); + } + + @Override + public Object getValue(ConfigurationSection config) { + return config.getString(this.getNameFlatFile(), (String) this.getDefaultValue()); + } + + @Override + public Object getDefault() { + return null; + } + }, + LANGUAGE("language", "language", "default") { + @Override + public Object getValue(ResultSet query) throws SQLException { + return Language.getKeyLanguage(query.getString(this.getNameMySQL())); + } + + @Override + public Object getValue(ConfigurationSection config) { + return Language.getKeyLanguage(config.getString(this.getNameFlatFile(), (String) this.getDefaultValue())); + } + + @Override + public Object getDefault() { + return Language.getKeyLanguage("default"); + } + }; + + private final String nameMySQL; + private final String nameFlatFile; + private final Object defaultValue; + + public abstract Object getValue(ResultSet query) throws SQLException; + + public abstract Object getValue(ConfigurationSection config); + + public abstract Object getDefault(); + + private CRStats(String nameMySQL, String nameFlatFile, Object defaultValue) { + this.nameMySQL = nameMySQL; + this.nameFlatFile = nameFlatFile; + this.defaultValue = defaultValue; + } + + public String getNameMySQL() { + return nameMySQL; + } + + public String getNameFlatFile() { + return nameFlatFile; + } + + public Object getDefaultValue() { + return defaultValue; + } +} diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/Configuration.java b/Bukkit/src/me/poutineqc/cuberunner/Configuration.java similarity index 58% rename from Bukkit_1.9/src/me/poutineqc/cuberunner/Configuration.java rename to Bukkit/src/me/poutineqc/cuberunner/Configuration.java index 5c10450..ce5f4a1 100644 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/Configuration.java +++ b/Bukkit/src/me/poutineqc/cuberunner/Configuration.java @@ -1,6 +1,8 @@ package me.poutineqc.cuberunner; import java.io.File; +import java.util.ArrayList; +import java.util.List; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; @@ -12,7 +14,6 @@ public class Configuration { private FileConfiguration config; private File configFile; - public String version; public String language; public boolean mysql; @@ -24,18 +25,24 @@ public class Configuration { public String tablePrefix; public boolean prefixInFrontOfEveryMessages; + public boolean autostart; public int countdownTime; + public boolean saveAndClearInventory; public boolean teleportAfterEnding; + public boolean broadcastStartup; + public boolean broadcastAchievement; + public boolean broadcastEndingSingle; + public boolean broadcastEndingMulti; + + public boolean lookForUpdates; public boolean economyRewards; public double pricePerScore; public boolean achievementsRewards; - public double rewardSurvive5Minutes; - public double rewardFillTheArenasFloor; - public double rewardReachHeight10; - public double rewardTheRageQuit; - public double rewardTheKillerBunny; - public double rewardTheAnswerToLife; + + public List winnerCommands; + public List playerCommands; + public List endingCommands; public Configuration(CubeRunner plugin) { configFile = new File(plugin.getDataFolder(), "config.yml"); @@ -49,7 +56,6 @@ public Configuration(CubeRunner plugin) { public void loadConfiguration(Plugin plugin) { config = YamlConfiguration.loadConfiguration(configFile); - version = config.getString("version"); language = config.getString("language", "en-US"); mysql = config.getBoolean("mysql", false); @@ -65,20 +71,37 @@ public void loadConfiguration(Plugin plugin) { tablePrefix = config.getString("tablePrefix", "cuberunner_"); } + lookForUpdates = config.getBoolean("checkForUpdates", true); prefixInFrontOfEveryMessages = config.getBoolean("prefixInFrontOfEveryMessages", true); countdownTime = config.getInt("countdownTime", 15); + autostart = config.getBoolean("autostart", true); + saveAndClearInventory = config.getBoolean("saveAndClearInventory", true); teleportAfterEnding = config.getBoolean("teleportAfterEnding", true); + + broadcastStartup = config.getBoolean("broadcasts.startup", true); + broadcastAchievement = config.getBoolean("broadcasts.achievement", true); + broadcastEndingSingle = config.getBoolean("broadcasts.ending.singleplayer", true); + broadcastEndingMulti = config.getBoolean("broadcasts.ending.multiplayer", true); economyRewards = config.getBoolean("economyRewards", false); pricePerScore = config.getDouble("pricePerScore", 0.05); achievementsRewards = config.getBoolean("achievementsRewards"); - rewardSurvive5Minutes = config.getDouble("rewardSurvive5Minutes", 25.0); - rewardFillTheArenasFloor = config.getDouble("rewardFillTheArenasFloor", 50.0); - rewardReachHeight10 = config.getDouble("rewardReachHeight10", 100.0); - rewardTheRageQuit = config.getDouble("rewardTheRageQuit", 15.0); - rewardTheKillerBunny = config.getDouble("rewardTheKillerBunny", 15.0); - rewardTheAnswerToLife = config.getDouble("rewardTheAnswerToLife", 15.0); + + winnerCommands = new ArrayList(); + playerCommands = new ArrayList(); + endingCommands = new ArrayList(); + for (String command : config.getStringList("commands")) { + if (command.contains("%winner%")) + winnerCommands.add(command); + else if (command.contains("%player%")) + playerCommands.add(command); + else + endingCommands.add(command); + } + } + + public enum CommandType { + WINNER, PLAYER, NOTHING } - } diff --git a/Bukkit/src/me/poutineqc/cuberunner/CubeRunner.java b/Bukkit/src/me/poutineqc/cuberunner/CubeRunner.java new file mode 100644 index 0000000..1d8ae98 --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/CubeRunner.java @@ -0,0 +1,246 @@ +package me.poutineqc.cuberunner; + +import java.io.IOException; +import java.util.UUID; +import java.util.logging.Logger; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.plugin.PluginDescriptionFile; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.RegisteredServiceProvider; +import org.bukkit.plugin.java.JavaPlugin; + +import me.poutineqc.cuberunner.CRPlayer.PlayerStatsException; +import me.poutineqc.cuberunner.commands.signs.CRSign; +import me.poutineqc.cuberunner.game.Arena; +import me.poutineqc.cuberunner.listeners.ListenerCommand; +import me.poutineqc.cuberunner.listeners.ListenerEntityChangeBlock; +import me.poutineqc.cuberunner.listeners.ListenerEntityGlide; +import me.poutineqc.cuberunner.listeners.ListenerInventoryClick; +import me.poutineqc.cuberunner.listeners.ListenerInventoryClose; +import me.poutineqc.cuberunner.listeners.ListenerPlayerDamage; +import me.poutineqc.cuberunner.listeners.ListenerPlayerDisconnect; +import me.poutineqc.cuberunner.listeners.ListenerPlayerInteract; +import me.poutineqc.cuberunner.listeners.ListenerPlayerMove; +import me.poutineqc.cuberunner.listeners.ListenerPlayerTeleport; +import me.poutineqc.cuberunner.listeners.ListenerSignBreak; +import me.poutineqc.cuberunner.listeners.ListenerSignUpdate; +import me.poutineqc.cuberunner.listeners.ListenerTabComplete; +import me.poutineqc.cuberunner.utils.MinecraftConfiguration; +import net.milkbowl.vault.economy.Economy; + +public class CubeRunner extends JavaPlugin { + + private static CubeRunner plugin; + public static final String name = "CubeRunner"; + + private Updater updater; + private Configuration config; + private MySQL mysql = new MySQL(); + private ArenaData arenaData; + private PlayerData playerData; + private AchievementManager achievementManager; + + private Economy economy; + public static String NMS_VERSION; + public static boolean oneNine; + + public void onEnable() { + plugin = this; + NMS_VERSION = getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]; + oneNine = NMS_VERSION.startsWith("v1_9"); + + config = new Configuration(this); + if (config.lookForUpdates) + updater = new Updater(this); + + if (!initialiseEconomy()) + return; + + loadLanguages(); + connectMySQL(); + arenaData = new ArenaData(this); + playerData = new PlayerData(this); + playerData.loadPlayers(plugin); + achievementManager = new AchievementManager(this); + CRSign.setVariables(this); + new Arena(this); + + getCommand("cuberunner").setExecutor(new ListenerCommand()); + getCommand("cuberunner").setTabCompleter(new ListenerTabComplete()); + + enableListeners(); + + try { + Metrics metrics; + metrics = new Metrics(this); + metrics.start(); + } catch (IOException e) { + e.printStackTrace(); + } + + Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { + @Override + public void run() { + Arena.loadExistingArenas(); + CRSign.loadAllSigns(); + } + }, 0); + + getLogger().info(getDescription().getName() + " has been enabled (v" + getDescription().getVersion() + ")"); + } + + public void onDisable() { + PluginDescriptionFile pdfFile = getDescription(); + Logger logger = getLogger(); + + if (config.lookForUpdates) + updater.stop(); + + if (mysql.hasConnection()) + mysql.close(); + else + arenaData.loadArenaData(); + + logger.info(pdfFile.getName() + " has been diabled"); + } + + public void reload() { + updater.stop(); + Language.clear(); + + config.loadConfiguration(this); + if (config.lookForUpdates) + updater = new Updater(this); + + if (!initialiseEconomy()) + return; + + loadLanguages(); + + playerData.clear(); + playerData.loadViews(); + playerData.loadPlayers(this); + achievementManager = new AchievementManager(this); + CRSign.setVariables(this); + + Arena.loadExistingArenas(); + CRSign.loadAllSigns(); + } + + public void connectMySQL() { + if (config.mysql) { + mysql = new MySQL(this, config.host, config.port, config.database, config.user, config.password, config.tablePrefix); + } else { + mysql = new MySQL(this); + } + } + + public void loadLanguages() { + new Language(this, "en"); + new Language(this, "fr"); + new Language(this, "de"); + new Language(this, config.language); + } + + public boolean initialiseEconomy() { + if (config.economyRewards) + if (!setupEconomy()) { + getLogger().warning("Vault not found."); + getLogger().warning("Add Vault to your plugins or disable monetary rewards in the config."); + getLogger().info("Disabling CubeRunner..."); + getServer().getPluginManager().disablePlugin(this); + return false; + } + return true; + } + + private boolean setupEconomy() { + economy = null; + if (getServer().getPluginManager().getPlugin("Vault") == null) { + return false; + } + RegisteredServiceProvider rsp = getServer().getServicesManager().getRegistration(Economy.class); + if (rsp == null) { + return false; + } + economy = rsp.getProvider(); + return economy != null; + } + + public boolean isEconomyEnabled() { + return economy != null; + } + + public Economy getEconomy() { + return economy; + } + + private void enableListeners() { + PluginManager pm = getServer().getPluginManager(); + + pm.registerEvents(playerData, this); + pm.registerEvents(new ListenerPlayerDamage(), this); + pm.registerEvents(new ListenerPlayerTeleport(), this); + pm.registerEvents(new ListenerPlayerDisconnect(), this); + pm.registerEvents(new ListenerSignUpdate(), this); + pm.registerEvents(new ListenerPlayerInteract(), this); + pm.registerEvents(new ListenerInventoryClose(), this); + pm.registerEvents(new ListenerPlayerMove(), this); + pm.registerEvents(new ListenerSignBreak(), this); + pm.registerEvents(new ListenerInventoryClick(), this); + pm.registerEvents(new ListenerEntityChangeBlock(), this); + + if (oneNine) + pm.registerEvents(new ListenerEntityGlide(), this); + } + + public Configuration getConfiguration() { + return config; + } + + public MySQL getMySQL() { + return mysql; + } + + public ArenaData getArenaData() { + return arenaData; + } + + public PlayerData getPlayerData() { + return playerData; + } + + public static CubeRunner get() { + return plugin; + } + + public CRPlayer getCRPlayer(Player player) { + return playerData.getCRPlayer(player); + } + + public MinecraftConfiguration getPlayerConfig() { + return playerData.getConfig(); + } + + public Language getLang(Player player) { + return getCRPlayer(player).getLanguage(); + } + + public AchievementManager getAchievementManager() { + return achievementManager; + } + + public void updateAll(CRPlayer crPlayer) { + try { + playerData.updateAll(crPlayer); + } catch (PlayerStatsException e) { + e.printStackTrace(); + } + } + + public CRPlayer getCRPlayer(UUID uuid) { + return playerData.getCRPlayer(uuid); + } +} diff --git a/Bukkit/src/me/poutineqc/cuberunner/Language.java b/Bukkit/src/me/poutineqc/cuberunner/Language.java new file mode 100644 index 0000000..5835a19 --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/Language.java @@ -0,0 +1,286 @@ +package me.poutineqc.cuberunner; + +import java.util.HashMap; +import java.util.Map.Entry; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import me.poutineqc.cuberunner.game.User; +import me.poutineqc.cuberunner.utils.MinecraftConfiguration; + +public class Language { + private static HashMap languages; + + private HashMap messages; + private String langageName; + private String fileName; + + static { + languages = new HashMap(); + } + + public Language(CubeRunner plugin, String fileName) { + this.fileName = fileName; + MinecraftConfiguration languageFile = new MinecraftConfiguration("LanguageFiles", fileName, true); + + langageName = languageFile.get().getString("languageName", null); + if (langageName == null) + return; + + messages = new HashMap(); + + for (Messages message : Messages.values()) + messages.put(message, languageFile.get().getString(message.key, message.defaultMessage)); + + languages.put(fileName, this); + } + + public String getFileName() { + return fileName; + } + + public String getLanguageName() { + return langageName; + } + + public String get(Messages message) { + return messages.get(message); + } + + public void sendMsg(Player player, String message) { + if (CubeRunner.get().getConfiguration().prefixInFrontOfEveryMessages) + player.sendMessage(ChatColor.translateAlternateColorCodes('&', get(Messages.PREFIX_SHORT) + " " + message)); + else + player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); + } + + public void sendMsg(User user, String message) { + sendMsg(user.getPlayer(), message); + } + + public static Language getKeyLanguage(String fileName) { + for (Entry local : languages.entrySet()) { + if (local.getKey().equalsIgnoreCase(fileName)) + return local.getValue(); + } + return getDefault(); + } + + public static Language getLanguage(String languageName) { + for (Entry local : languages.entrySet()) + if (local.getValue().langageName.equalsIgnoreCase(languageName)) + return local.getValue(); + + return null; + } + + public static Language getDefault() { + for (Entry local : languages.entrySet()) { + if (local.getKey().equalsIgnoreCase(CubeRunner.get().getConfiguration().language)) { + return local.getValue(); + } + } + + return languages.get("en"); + } + + public static HashMap getLanguages() { + return languages; + } + + public static void clear() { + languages.clear(); + } + + public enum Messages { + PREFIX_SHORT("prefixShort", "&7[&5CR&7]"), + PREFIX_LONG("prefixLong", "&8[&5CubeRunner&8]"), + + DEVELOPPER("developper", "&5Developped by: &7%developper%"), + VERSION("version", "&5Version: &7%version%"), + DESCRIPTION("description", "&dType &5/%command% help &d for the list of commands."), + + ERROR_PERMISSION("errorPermission", "&4You don't have the permission to do this"), + ERROR_COMMAND("errorCommand", "&cCommand not found. Type &8/%cmd% help &cfor help."), + ERROR_TELEPORT("errorTeleport", "&cYou can't teleport away while you are in game. Do &7/cr quit &cto leave it."), + ERROR_MISSING_ARENA("errorMissingArena", "&cYou need to choose an arena."), + ERROR_ALREADY_IN_GAME("errorAlreadyInGame", "&cYou are already in a CubeRunner game."), + ERROR_NOT_IN_GAME("errorNotInGame", "&cYou are not currently in a CubeRunner game."), + + INFO_TIP("infoTip", "&8[&7Tip&8] &7You may also do &8/%cmd% list &7and right click an arena to display it's information."), + + JOIN_UNREADY("joinUnready", "&cThe arena you are trying to join is not available."), + JOIN_ACTIVE("joinActive", "&cThere is already an active game in the arena you are trying to join."), + JOIN_SPECTATOR("joinSpectator", "&dJoining as spectator..."), + JOIN_PLAYER("joinPlayer", "&aYou have successfully joined the arena &2%arena%&a."), + JOIN_OTHERS("joinOthers", "&f%player% &djoined your CubeRunner's arena."), + JOIN_GUI_TITLE("joinGuiTitle", "&2Arena List"), + JOIN_GUI_INFO("joinGuiInfo", "&eClick the name of the arena you wish to go to."), + JOIN_GUI_TIP_SPECTATE("joinGuiTipStarted", "&eClick to Spectate"), + JOIN_GUI_TIP_JOIN("joinGuiTipJoin", "&aReady : &eClick to Join"), + + QUIT_PLAYER("quitPlayer", "&aYou have left the CubeRunner's arena &2%arena%&a."), + QUIT_OTHERS("quitOthers", "&f%player% &dleft your CubeRunner's arena."), + + START_NOT_READY("startNotReady", "&cThe game is not ready to start at the moment"), + START_MINIMUM("startMinimum", "&cThere must be at least %amount% players to start the game."), + START_MAXIMUM("startMaximum", "&cThere must be at most %amount% players to start the game."), + START_BROADCAST("startBroadcast", "&dA new game of &5CubeRunner &dhas been initiated. You may join with the command &5/cr join %arena%&d."), + START_STOP("startStop", "&cThe countdown has been stopped. Not enough players in the game anymore."), + + END_CRUSH_PLAYER("endCrushPlayer", "&dYou have been crushed with a score of &5%score%&d. Game over!"), + END_CRUSH_OTHERS("endCrushOthers", "&f%player% &dhas been crushed with a score of &5%score%&d."), + END_HIDE_PLAYER("endHidePlayer", "&dYou have been kicked out of the game for hiding under a block."), + END_HIDE_OTHERS("endHideOthers", "&f%player% &dhave been kicked out of the game for hiding under a block."), + END_TELEPORT("endTeleport", "&dGame is over. Teleporting back in 5 seconds..."), + END_BEST("endBest", "&6Congratulation to &f%player% &6who got the new best score of &4%score% &6in the arena &5%arena%"), + END_REWARD("endReward", "&dYou gain %amount%%currency% for surviving %amount2% seconds."), + END_BROADCAST_MULTIPLAYER("endBroadcastMultiplayer", "&6Congradulation to &f%player% &6who won a multiplayer game of CubeRunner in the arena &5%arena% &6with a score of &4%score%&6!"), + END_BROADCAST_SINGLEPLAYER("endBroadcastSingleplayer", "&f%player% &6finished a game of CubeRunner in the arena &5%arena% &6with a score of &4%score%&6!"), + + STATS_GUI_TITLE("statsGuiTitle", "&6Stats"), + STATS_INFO_AVERAGE_SCORE("statsInfoAverageScore", "&bAverage Score Per Game"), + STATS_INFO_DISTANCE_RAN("statsInfoDistanceRan", "&bTotal Distance Ran"), + STATS_INFO_GAMES("statsInfoGames", "&bGames played"), + STATS_INFO_TOTAL_SCORE("statsInfoTotalScore", "&bTotal Score"), + STATS_INFO_KILLS("statsInfoKills", "&bPlayers Killed"), + STATS_INFO_MULTIPLAYER_WON("statsInfoMultiplayerWon", "&bMultiplayer games won"), + STATS_INFO_TIME_PLAYED("statsInfoTimePlayed", "&dTime Played"), + STATS_INFO_MONEY("statsInfoMoney", "&dMoney Gained"), + STATS_CHALLENGES_TITLE("statsChallengesTitle", "&bChallenges"), + + ACHIEVEMENT_BROADCAST("achievementBroadcast", "&f%player% &6just completed the achievement &d%achievementName%&6!"), + ACHIEVEMENT_REWARD("achievementReward", "&dYou gain %amount%%currency% for your achievement."), + ACHIEVEMENT_GAMES("achievementAmountGame", "&dPlay %amount% game(s)"), + ACHIEVEMENT_TOTAL_SCORE("achievementTotalScore", "&dReach total score of %amount%"), + ACHIEVEMENT_KILLS("achievementKills", "&dKill %amount% player(s)"), + ACHIEVEMENT_MULTIPLAYER_WON("achievementMultiplayerWon", "&dWin %amount% multiplayer game(s)"), + ACHIEVEMENT_SURVIVE_5_MINUTES("achievementSurvive5Minutes", "&dSurvive 5 minutes"), + ACHIEVEMENT_REACH_HEIGHT_10("achievementReachHeight10", "&dReach height 10"), + ACHIEVEMENT_FILL_THE_ARENA("achievementFillTheArena", "&dFill the arena's floor"), + ACHIEVEMENT_ANSWER_TO_LIFE("achievementAnswerToLife", "&dThe answer to life the universe and everything"), + ACHIEVEMENT_RAGE_QUIT("achievementRageQuit", "&dThe Rage Quit"), + ACHIEVEMENT_KILLER_BUNNY("achievementKillerBunny", "&dThe Killer Bunny"), + + EDIT_CREATE_NONAME("editCreateNoname", "&cYou must choose a name for your new arena."), + EDIT_NEW_SUCCESS("editNewSuccess", "&aAn arena named &2%arena% &ahas been successfully created."), + EDIT_NEW_EXISTS("editNewExists", "&cAn arena named &4%arena% &calready exists."), + EDIT_NEW_LONG_NAME("editNewLongName", "&cTheArena's name can't be more than 12 letters long."), + EDIT_ERROR_ARENA("editErrorArena", "&cAn arena named &4%arena% &cdoes not exists."), + EDIT_REGION_WORLDEDIT("editRegionWorldedit", "&cYou must first choose a World Edit region."), + EDIT_REGION("editRegion", "&aZone successfully set for the arena &2%arena%&a."), + EDIT_STARTPOINT("editStartPoint", "&aStart Point successfully set for the arena &2%arena%&a."), + EDIT_LOBBY("editLobby", "&aLobby successfully set for the arena &2%arena%&a."), + EDIT_PLAYERS_MISSING("editPlayersMissing", "&cYou must provide a quantity to change the amount of players."), + EDIT_PLAYERS_ERROR("editPlayersError", "&cThe amount of player you entered is not valid. &7[&8%error%&7]"), + EDIT_PLAYERS_NAN("editPlayersNaN", "Not a number"), + EDIT_PLAYERS_MINIMUM_1("editPlayersMinimum1", "Minimum lower than 1"), + EDIT_PLAYERS_MINIMUM_MAXIMUM("editPlayersMinimumMaximum", "Minimum higher than maximum"), + EDIT_PLAYERS_MAXIMUM_MINIMUM("editPlayersMaximumMinimum", "Maximum lower than minimum"), + EDIT_PLAYERS_MAXIMUM_10("editPlayersMaximum10", "Maximum higher than 10"), + EDIT_PLAYERS("editPlayers", "&aAmount of player successfully edited for the arena &2%arena%&a."), + EDIT_COLOR_GUI_TITLE("editColorGuiTitle", "&4Color Picker"), + EDIT_COLOR_GUI_INFO("editColorGuiInfo", "&eThe enchanted blocks are\nðe curently selected ones.\n&eClick a block to\n&eenable or disable it."), + EDIT_COLOR_ERROR("editColorError", "&cYou can't edit the colors while a game is active."), + EDIT_DELETE("editDelete", "&cArena deleted."), + + LANGUAGE_LIST("languageList", "Available languages"), + LANGUAGE_NOT_FOUND("languageNotFound", "&cLanguage not found. &8/%cmd% language &cfor a list of available languages"), + LANGUAGE_CHANGED("languageChanged", "&aLanguage successfully set to %language%"), + + HELP_ERROR_PERMISSION("helpErrorPermission", "&cYou do not have any permissions in this category."), + HELP_DESCRIPTION_ALL("helpDescriptionAll", "&7All Commands"), + HELP_DESCRIPTION_GENERALL("helpDescriptionGeneral", "&7General player commands"), + HELP_DESCRIPTION_GAME("helpDescriptionGame", "&7Commands to simply play the game"), + HELP_DESCRIPTION_ARENA("helpDescriptionArena", "&7Commands to setup the arenas"), + HELP_DESCRIPTION_ADMIN("helpDescriptionAdmin", "&7Admin maintenance commands"), + + SIGN_PERM_0("signPerm0", "&cYou don't have"), + SIGN_PERM_1("signPerm1", "&cthe permissions"), + SIGN_PERM_2("signPerm2", "&cto create a DaC"), + SIGN_PERM_3("signPerm3", "&csign, &4Sorry..."), + SIGN_VALID_1("signValid1", "&cNone valid"), + SIGN_VALID_2("signValid2", "&csign parameters"), + SIGN_VALID_3("signValid3", "&cTry again"), + + KEYWORD_SIGN_JOIN("keyWordSignJoin", "&aJoin Arena"), + KEYWORD_SIGN_QUIT("keyWordSignQuit", "&cQuit Arena"), + KEYWORD_SIGN_START("keyWordSignStart", "&9Start Game"), + KEYWORD_SIGN_STATS("keyWordSignStats", "&6Stats"), + KEYWORD_SIGN_PLAY("keyWordSignPlay", "&aPlay"), + KEYWORD_SIGN_TOP("keyWordSignTop", "&bBest Score"), + + KEYWORD_GUI_INSTRUCTIONS("keyWordGuiInstructions", "&6Instructions"), + KEYWORD_GUI_PAGE("keyWordGuiPage", "&ePage %number%"), + + KEYWORD_GAMESTATE_UNSET("keyWordGameStateUnset", "&7Arena Unset"), + KEYWORD_GAMESTATE_READY("keyWordGameStatReady", "&aReady"), + KEYWORD_GAMESTATE_STARTUP("keyWordGameStatStartup", "&9Startup"), + KEYWORD_GAMESTATE_ACTIVE("keyWordGameStatActive", "&cActive"), + + KEYWORD_GENERAL_HOURS("keyWordGeneralHours", "hours"), + KEYWORD_GENERAL_MINUTES("keyWordGeneralMinutes", "minutes"), + KEYWORD_GENERAL_SECONDS("keyWordGeneralSeconds", "seconds"), + KEYWORD_GENERAL_DISTANCE("keyWordGeneralDistance", "km"), + KEYWORD_GENERAL_BY("keyWordGeneralBy", "by"), + + KEYWORD_HELP("keyWordHelp", "Help"), + KEYWORD_HELP_CATEGORY("keyWordHelpCategory", "Category"), + KEYWORD_HELP_PAGE("keyWordHelpPage", "Page"), + + KEYWORD_INFO("keyWordInfo", "Information"), + KEYWORD_INFO_ADVANCED("keyWordInfoAdvanced", "Advanced Information"), + KEYWORD_INFO_MINIMUM("keyWordInfoMinimum", "Minimum"), + KEYWORD_INFO_MAXIMUM("keyWordInfoMaximum", "Maximum"), + KEYWORD_INFO_CURRENT("keyWordInfoCurrent", "Current"), + KEYWORD_INFO_AMOUNT_OF_PLAYER("keyWordInfoAmountPlayer", "amount of players"), + KEYWORD_INFO_GAME_STATE("keyWordInfoGameState", "game state"), + KEYWORD_INFO_WORLD("keyWordInfoWorld", "World"), + KEYWORD_INFO_LOBBY("keyWordInfoLobby", "Lobby"), + KEYWORD_INFO_START_POINT("keyWordInfoStartPoint", "Start point"), + KEYWORD_INFO_ZONE_COORDINATE("keyWordInfoZoneMinPoint", " zone coordinate"), + KEYWORD_INFO_BEST_SCORE("keyWordInfoBestScore", "Best Score"), + + KEYWORD_STATS_TOP10("keyWordStatsTop10", "Top 10"), + KEYWORD_STATS_PROGRESSION("keyWordStatsProgression", "Progression"), + KEYWORD_STATS_COMPLETED("keyWordStatsCompleted", "Completed"), + KEYWORD_STATS_NOT_COMPLETED("keyWordStatsNotCompleted", "Not Completed"), + KEYWORD_STATS_REWARD("keyWordStatsReward", "Reward"), + + KEYWORD_SCOREBOARD_PLAYERS("keyWordScoreboardPlayers", "Players"), + KEYWORD_SCOREBOARD_SCORE("keyWordScoreboardScore", "Score"), + + ADMIN_RELOAD("adminReload", "&aPlugin CubeRunner has been successfully reloaded."), + + COMMAND_HELP("cmdDescriptionHelp", "&7You already know how to do that don't you? ;)"), + COMMAND_LANGUAGE("cmdDescriptionLanguage", "&7Change your own language for CubeRunner's plugin."), + COMMAND_STATS("cmdDescriptionStats", "&7Opens your CubeRunner's stats."), + COMMAND_LIST("cmdDescriptionList", "&7Opens a list of all the arenas."), + COMMAND_INFO("cmdDescriptionInfo", "&7Display every information from the selected arena."), + COMMAND_JOIN("cmdDescriptionJoin", "&7Join the specified game or open a GUI to choose."), + COMMAND_QUIT("cmdDescriptionQuit", "&7Leave your current game."), + COMMAND_START("cmdDescriptionStart", "&7Initiate the starting countdown."), + COMMAND_NEW("cmdDescriptionNew", "&7Creates a new CubeRunner arena."), + COMMAND_DELETE("cmdDescriptionDelete", "&7Delete the specified arena."), + COMMAND_SETZONE("cmdDescriptionSetzone", "&7Set the delimitation of the selected arena with a World Edit region."), + COMMAND_SETLOBBY("cmdDescriptionSetlobby", "&7Set the lobby of the selected arena."), + COMMAND_SETSTARTPOINT("cmdDescriptionStartpoint", "&7Set the start point of the selected arena."), + COMMAND_SETMINPLAYER("cmdDescriptionSetminplayer", "&7Set the minimum amount of player for an arena."), + COMMAND_SETMAXPLAYER("cmdDescriptionSetmaxplayer", "&7Set the maximum amount of player for an arena."), + COMMAND_SETCOLOR("cmdDescriptionSetcolor", "&7Set the block colors for the arena"), + COMMAND_RELOAD("cmdDescriptionReload", "&7Reload the config, the player data and the language files."); + + private String key; + private String defaultMessage; + + private Messages(String key, String defaultMessage) { + this.key = key; + this.defaultMessage = defaultMessage; + } + + public String key() { + return key; + } + } +} diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/Metrics.java b/Bukkit/src/me/poutineqc/cuberunner/Metrics.java similarity index 99% rename from Bukkit_1.8/src/me/poutineqc/cuberunner/Metrics.java rename to Bukkit/src/me/poutineqc/cuberunner/Metrics.java index 910c42a..3aceb13 100644 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/Metrics.java +++ b/Bukkit/src/me/poutineqc/cuberunner/Metrics.java @@ -272,7 +272,7 @@ private int getOnlinePlayers() { private void postPlugin(final boolean isPing) throws IOException { // Server software specific section PluginDescriptionFile description = plugin.getDescription(); - String pluginName = "CubeRunner"; + String pluginName = CubeRunner.name; boolean onlineMode = Bukkit.getServer().getOnlineMode(); String pluginVersion = description.getVersion(); String serverVersion = Bukkit.getVersion(); diff --git a/Bukkit/src/me/poutineqc/cuberunner/MySQL.java b/Bukkit/src/me/poutineqc/cuberunner/MySQL.java new file mode 100644 index 0000000..b43057f --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/MySQL.java @@ -0,0 +1,157 @@ +package me.poutineqc.cuberunner; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.UUID; + +public class MySQL { + + private CubeRunner plugin; + private String prefix; + + private String host; + private int port; + private String database; + private String user; + private String password; + + private Connection connection; + + public MySQL(CubeRunner plugin) { + this.plugin = plugin; + connection = null; + } + + public MySQL(CubeRunner plugin, String host, int port, String database, String user, String password, + String prefix) { + this.plugin = plugin; + this.prefix = prefix; + + this.host = host; + this.port = port; + this.database = database; + this.user = user; + this.password = password; + + connect(); + + if (hasConnection()) + initializeDatabases(); + } + + private void initializeDatabases() { + update("CREATE TABLE IF NOT EXISTS " + prefix + "SIGNS (" + + "uuid varchar(64), type varchar(32)," + + "locationWorld varchar(32), locationX INT DEFAULT 0, locationY INT DEFAULT 0, locationZ INT DEFAULT 0);"); + update("ALTER TABLE " + prefix + "SIGNS CONVERT TO CHARACTER SET utf8;"); + + update("CREATE TABLE IF NOT EXISTS " + prefix + "ARENAS (name varchar(32),world varchar(32)," + + "minAmountPlayer INT DEFAULT 1, maxAmountPlayer INT DEFAULT 8, highestScore INT DEFAULT 0," + + "colorIndice LONG, highestPlayer varchar(32) DEFAULT 'null'," + + "minPointX INT DEFAULT 0,minPointY INT DEFAULT 0,minPointZ INT DEFAULT 0," + + "maxPointX INT DEFAULT 0, maxPointY INT DEFAULT 0,maxPointZ INT DEFAULT 0," + + "lobbyX DOUBLE DEFAULT 0,lobbyY DOUBLE DEFAULT 0,lobbyZ DOUBLE DEFAULT 0," + + "lobbyPitch FLOAT DEFAULT 0,lobbyYaw FLOAT DEFAULT 0," + + "startPointX DOUBLE DEFAULT 0,startPointY DOUBLE DEFAULT 0,startPointZ DOUBLE DEFAULT 0," + + "startPointPitch FLOAT DEFAULT 0,startPointYaw FLOAT DEFAULT 0);"); + update("ALTER TABLE " + prefix + "ARENAS CONVERT TO CHARACTER SET utf8;"); + + update("CREATE TABLE IF NOT EXISTS " + prefix + + "PLAYERS (UUID varchar(64), name varchar(64), language varchar(32), timePlayed INT DEFAULT 0," + + "money DOUBLE DEFAULT 0, averageDistancePerGame DOUBLE DEFAULT 0, totalDistance DOUBLE DEFAULT 0," + + "games INT DEFAULT 0, totalScore INT DEFAULT 0, kills INT DEFAULT 0, multiplayerWon INT DEFAULT 0," + + "survive5Minutes BOOLEAN DEFAULT FALSE, reachHeight10 BOOLEAN DEFAULT FALSE," + + "fillTheArena BOOLEAN DEFAULT FALSE, theAnswerToLife BOOLEAN DEFAULT FALSE," + + "theRageQuit BOOLEAN DEFAULT FALSE, theKillerBunny BOOLEAN DEFAULT FALSE);"); + update("ALTER TABLE " + prefix + "PLAYERS CONVERT TO CHARACTER SET utf8;"); + } + + public MySQL() { + connection = null; + } + + public void updateInfo(CubeRunner plugin) { + Configuration config = plugin.getConfiguration(); + this.plugin = plugin; + this.host = config.host; + this.port = config.port; + this.database = config.database; + this.user = config.user; + this.password = config.password; + + connect(); + } + + public void connect() { + try { + connection = DriverManager.getConnection( + "jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true", user, password); + plugin.getLogger().info("[MySQL] The connection to MySQL is made!"); + } catch (SQLException e) { + plugin.getLogger().info("[MySQL] The connection to MySQL couldn't be made! reason: " + e.getMessage()); + } + } + + public void close() { + try { + if (connection != null) { + connection.close(); + plugin.getLogger().info("[MySQL] The connection to MySQL is ended successfully!"); + } + } catch (SQLException e) { + plugin.getLogger().info("[MySQL] The connection couldn't be closed! reason: " + e.getMessage()); + } + } + + public void update(String qry) { + try { + PreparedStatement st = connection.prepareStatement(qry); + st.execute(); + st.close(); + } catch (SQLException e) { + connect(); + System.err.println(qry); + System.err.println(e); + } + } + + public void newPlayer(UUID uuid, String name) { + String qry = String.format("INSERT INTO %1$sPLAYERS (UUID, name) VALUES ('%2$s','%3$s');", prefix, uuid.toString(), name); + update(qry); + } + + public void updatePlayer(UUID uuid, CRStats key, String value) { + String qry = String.format("UPDATE %1$sPLAYERS SET %2$s='%3$s' WHERE UUID='%4$s';", prefix, + key.getNameMySQL(), value, uuid.toString()); + update(qry); + } + + public boolean hasConnection() { + return connection != null; + } + + public ResultSet query(String qry) { + ResultSet rs = null; + try { + PreparedStatement st = connection.prepareStatement(qry); + rs = st.executeQuery(); + } catch (SQLException e) { + connect(); + System.err.println(qry); + System.err.println(e); + } + return rs; + } + + public ResultSet queryAll() { + String qry = String.format("SELECT * FROM %1$sPLAYERS", prefix); + return query(qry); + } + + public ResultSet queryView(String viewName) { + return query("SELECT * FROM " + prefix + viewName + ";"); + } +} diff --git a/Bukkit/src/me/poutineqc/cuberunner/PlayerData.java b/Bukkit/src/me/poutineqc/cuberunner/PlayerData.java new file mode 100644 index 0000000..9610f81 --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/PlayerData.java @@ -0,0 +1,164 @@ +package me.poutineqc.cuberunner; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +import me.poutineqc.cuberunner.CRPlayer.PlayerStatsException; +import me.poutineqc.cuberunner.utils.MinecraftConfiguration; + +public final class PlayerData implements Listener { + + private MinecraftConfiguration playerData; + private HashMap players; + private HashMap views; + + public PlayerData(CubeRunner plugin) { + players = new HashMap(); + loadViews(); + } + + public void loadViews() { + views = new HashMap(); + + try { + views.put(CRStats.AVERAGE_SCORE, new View(CRStats.AVERAGE_SCORE)); + views.put(CRStats.GAMES_PLAYED, new View(CRStats.GAMES_PLAYED)); + views.put(CRStats.MULTIPLAYER_WON, new View(CRStats.MULTIPLAYER_WON)); + views.put(CRStats.TOTAL_SCORE, new View(CRStats.TOTAL_SCORE)); + views.put(CRStats.TOTAL_DISTANCE, new View(CRStats.TOTAL_DISTANCE)); + views.put(CRStats.KILLS, new View(CRStats.KILLS)); + } catch (PlayerStatsException e) { + e.printStackTrace(); + } + } + + public void loadPlayers(CubeRunner plugin) { + loadExistingPlayers(plugin); + + for (Player player : Bukkit.getOnlinePlayers()) + loadPlayer(player); + } + + private void loadExistingPlayers(CubeRunner plugin) { + if (plugin.getMySQL().hasConnection()) { + ResultSet query = plugin.getMySQL().queryAll(); + + try { + while (query.next()) { + CRPlayer player = new CRPlayer(query); + players.put(player.getUUID(), player); + } + } catch (SQLException e) { + e.printStackTrace(); + } + + } else { + playerData = new MinecraftConfiguration(null, "playerData", false); + if (playerData.get().contains("players")) + for (String uuid : playerData.get().getConfigurationSection("players").getKeys(false)) { + CRPlayer player = new CRPlayer(uuid, playerData.get().getConfigurationSection("players." + uuid)); + players.put(player.getUUID(), player); + } + } + } + + private void loadPlayer(Player player) { + UUID uuid = player.getUniqueId(); + CRPlayer crPlayer = players.get(uuid); + + if (crPlayer == null) + players.put(uuid, new CRPlayer(uuid, player.getName())); + + else if (!crPlayer.getName().equalsIgnoreCase(player.getName())) + crPlayer.setName(player.getName()); + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + loadPlayer(event.getPlayer()); + } + + public CRPlayer getCRPlayer(Player player) { + return players.get(player.getUniqueId()); + } + + public MinecraftConfiguration getConfig() { + return playerData; + } + + public class View { + CRStats stats; + List list = new ArrayList<>(10); + + public View(CRStats stats) throws PlayerStatsException { + this.stats = stats; + + for (Entry player : players.entrySet()) + update(player.getValue()); + } + + public void update(CRPlayer crPlayer) throws PlayerStatsException { + if (list.contains(crPlayer)) + list.remove(crPlayer); + + boolean over = false; + int originalSize = list.size(); + list.add(crPlayer); + + for (int i = originalSize; i > 0 && !over; i--) { + Object value = list.get(i).get(stats); + if (value instanceof Integer) { + if ((int) value > list.get(i - 1).getInt(stats)) { + CRPlayer temp = list.get(i); + list.set(i, list.get(i - 1)); + list.set(i - 1, temp); + } else + over = true; + + } else if (value instanceof Double) { + if ((double) value > list.get(i - 1).getDouble(stats)) { + CRPlayer temp = list.get(i); + list.set(i, list.get(i - 1)); + list.set(i - 1, temp); + } else + over = true; + } + } + + if (originalSize == 10) + list.remove(originalSize); + } + + public List getList() { + return list; + } + } + + public void updateAll(CRPlayer crPlayer) throws PlayerStatsException { + for (Entry set : views.entrySet()) + set.getValue().update(crPlayer); + } + + public HashMap getViews() { + return views; + } + + public CRPlayer getCRPlayer(UUID uuid) { + return players.get(uuid); + } + + public void clear() { + players = new HashMap(); + } +} diff --git a/Bukkit/src/me/poutineqc/cuberunner/Updater.java b/Bukkit/src/me/poutineqc/cuberunner/Updater.java new file mode 100644 index 0000000..e2f71a8 --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/Updater.java @@ -0,0 +1,99 @@ +package me.poutineqc.cuberunner; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.logging.Logger; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +import me.poutineqc.cuberunner.commands.CRCommand; +import me.poutineqc.cuberunner.utils.Permissions; + +public final class Updater implements Listener { + + private static final String spigotPage = "https://www.spigotmc.org/resources/cuberunner.19715/"; + private static final String versionPage = "http://www.poutineqc.ca/pluginVersion.txt"; + + private final CubeRunner plugin; + private final int id; + + private boolean lastVersion; + private String latestVersion; + + public Updater(final CubeRunner plugin) { + this.plugin = plugin; + + id = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { + public void run() { + checkForLastVersion(plugin); + if (!lastVersion) { + notifyConsole(plugin); + } + } + }, 0, 72000L); + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + if (Permissions.hasPermission(CRCommand.RELOAD.getPermission(), event.getPlayer(), false) && !lastVersion) + notifyPlayer(event.getPlayer()); + } + + private void checkForLastVersion(CubeRunner plugin) { + boolean next = false; + + try { + lastVersion = getInfoFromServer(); + } catch (IOException e) { + plugin.getLogger().warning("Could not find the latest version available."); + } + + lastVersion = (next) ? latestVersion.equalsIgnoreCase(plugin.getDescription().getVersion()) : true; + } + + private boolean getInfoFromServer() throws IOException { + boolean next = false; + + URL url = new URL(versionPage); + BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); + + while ((latestVersion = in.readLine()) != null && !next) { + if (latestVersion.equalsIgnoreCase(CubeRunner.name)) + next = true; + } + + in.close(); + return next; + } + + private void notifyConsole(CubeRunner plugin) { + Logger logger = plugin.getLogger(); + logger.info("----------------------------"); + logger.info("CubeRunner Updater"); + logger.info(""); + logger.info("An update for CubeRunner has been found!"); + logger.info("CubeRunner " + latestVersion); + logger.info("You are running " + plugin.getDescription().getVersion()); + logger.info(""); + logger.info("Download at https://www.spigotmc.org/resources/cuberunner.19715/"); + logger.info("----------------------------"); + } + + private void notifyPlayer(Player player) { + Language local = plugin.getCRPlayer(player).getLanguage(); + local.sendMsg(player, + String.format("&5A new CubeRunner version is available &d(v%1$s)&5.%n&5Get it now : &d%2$s", + latestVersion, spigotPage)); + } + + public void stop() { + Bukkit.getScheduler().cancelTask(id); + } + +} diff --git a/Bukkit/src/me/poutineqc/cuberunner/commands/CRCommand.java b/Bukkit/src/me/poutineqc/cuberunner/commands/CRCommand.java new file mode 100644 index 0000000..bd12721 --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/commands/CRCommand.java @@ -0,0 +1,586 @@ +package me.poutineqc.cuberunner.commands; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map.Entry; + +import org.apache.commons.lang3.StringUtils; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import me.poutineqc.cuberunner.CubeRunner; +import me.poutineqc.cuberunner.Language; +import me.poutineqc.cuberunner.Language.Messages; +import me.poutineqc.cuberunner.commands.inventories.CRInventoryColor; +import me.poutineqc.cuberunner.commands.inventories.CRInventoryJoin; +import me.poutineqc.cuberunner.commands.inventories.CRInventoryStats; +import me.poutineqc.cuberunner.game.Arena; +import me.poutineqc.cuberunner.game.GameState; +import me.poutineqc.cuberunner.game.Arena.LeavingReason; +import me.poutineqc.cuberunner.utils.Permissions; +import me.poutineqc.cuberunner.utils.Utils; + +public enum CRCommand { + + HELP("help", Messages.COMMAND_HELP, "cuberunner.player.help", "/%command% help [category] [page]", + CRCommandType.GENERAL) { + @Override + public void execute(CubeRunner plugin, Player player, String[] args, Object... extra) { + Language local = CubeRunner.get().getLang(player); + String cmdValue = extra.length > 0 ? ((extra[0] instanceof String) ? (String) extra[0] : "cr") : "cr"; + String header = Utils.color("&8&m" + StringUtils.repeat(" ", 15) + "&r&8| &5CubeRunner &d" + + local.get(Messages.KEYWORD_HELP) + "&8&m|" + StringUtils.repeat(" ", 35)); + + if (args.length == 1) { + player.sendMessage(ChatColor.translateAlternateColorCodes('&', header)); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', + "&5/" + cmdValue + " help general &8- " + local.get(Messages.HELP_DESCRIPTION_GENERALL))); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', + "&5/" + cmdValue + " help game &8- " + local.get(Messages.HELP_DESCRIPTION_GAME))); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', + "&5/" + cmdValue + " help arena &8- " + local.get(Messages.HELP_DESCRIPTION_ARENA))); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', + "&5/" + cmdValue + " help admin &8- " + local.get(Messages.HELP_DESCRIPTION_ADMIN))); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', + "&5/" + cmdValue + " help all &8- " + local.get(Messages.HELP_DESCRIPTION_ALL))); + player.sendMessage("\n"); + return; + } + + int pageNumber = 1; + CRCommandType commandType = null; + List requestedCommands; + + try { + pageNumber = Integer.parseInt(args[1]); + if (pageNumber < 1) + pageNumber = 1; + + requestedCommands = CRCommand.getRequiredCommands(player, commandType); + if (pageNumber > Math.ceil((double) requestedCommands.size() / 3)) + pageNumber = (int) Math.ceil((double) requestedCommands.size() / 3); + + } catch (NumberFormatException e) { + switch (args[1].toLowerCase()) { + case "game": + commandType = CRCommandType.GAME; + break; + case "arena": + commandType = CRCommandType.ARENA; + break; + case "admin": + commandType = CRCommandType.ADMIN; + break; + case "general": + commandType = CRCommandType.GENERAL; + break; + } + + requestedCommands = CRCommand.getRequiredCommands(player, commandType); + + if (args.length > 2) { + try { + pageNumber = Integer.parseInt(args[2]); + if (pageNumber < 1) + pageNumber = 1; + + if (pageNumber > Math.ceil((double) requestedCommands.size() / 3)) + pageNumber = (int) Math.ceil((double) requestedCommands.size() / 3); + + } catch (NumberFormatException ex) { + } + } + } + + if (requestedCommands.size() == 0) + pageNumber = 0; + + player.sendMessage(ChatColor.translateAlternateColorCodes('&', header)); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', + "&5" + local.get(Messages.KEYWORD_HELP_CATEGORY) + ": &7" + + (commandType == null ? "ALL" : commandType.toString()) + ", &5" + + local.get(Messages.KEYWORD_HELP_PAGE) + ": &7" + String.valueOf(pageNumber) + "&8/&7" + + (int) (Math.ceil((double) requestedCommands.size() / 3)))); + + if (pageNumber == 0) { + local.sendMsg(player, local.get(Messages.HELP_ERROR_PERMISSION)); + return; + } + + for (int i = 3 * (pageNumber - 1); i < requestedCommands.size() && i < (3 * (pageNumber - 1)) + 3; i++) { + player.sendMessage(ChatColor.translateAlternateColorCodes('&', + "&5" + requestedCommands.get(i).getUsage().replace("%command%", cmdValue))); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', + " &8- &7" + local.get(requestedCommands.get(i).getDescription()))); + } + player.sendMessage("\n"); + } + + @Override + public void complete(List tabCompletion, String[] args) { + if (args.length == 2) + for (CRCommandType category : CRCommandType.values()) + if (category.name().toLowerCase().startsWith(args[1].toLowerCase())) + tabCompletion.add(category.name().toLowerCase()); + } + }, + LANGUAGE("lang", Messages.COMMAND_LANGUAGE, "cuberunner.player.language", "/%command% language ", + CRCommandType.GENERAL) { + @Override + public void execute(CubeRunner plugin, Player player, String[] args, Object... extra) { + Language local = CubeRunner.get().getLang(player); + if (args.length == 1) { + local.sendMsg(player, local.get(Messages.LANGUAGE_LIST)); + for (Entry language : Language.getLanguages().entrySet()) + player.sendMessage("- " + language.getValue().getLanguageName()); + + return; + } + + Language language = Language.getLanguage(args[1]); + if (language == null) { + String cmdValue = extra.length > 0 ? ((extra[0] instanceof String) ? (String) extra[0] : "cr") : "cr"; + local.sendMsg(player, local.get(Messages.LANGUAGE_NOT_FOUND).replace("%cmd%", cmdValue)); + return; + } + + CubeRunner.get().getCRPlayer(player).setLanguage(language); + + language.sendMsg(player, language.get(Messages.LANGUAGE_CHANGED)); + } + + @Override + public void complete(List tabCompletion, String[] args) { + if (args.length == 2) + for (Entry lang : Language.getLanguages().entrySet()) + if (lang.getValue().getLanguageName().toLowerCase().startsWith(args[1].toLowerCase())) + tabCompletion.add(lang.getValue().getLanguageName()); + } + }, + STATS("stats", Messages.COMMAND_STATS, "cuberunner.player.stats", "/%command% stats", CRCommandType.GENERAL) { + @Override + public void execute(CubeRunner plugin, Player player, String[] args, Object... extra) { + new CRInventoryStats(plugin.getCRPlayer(player)); + } + + @Override + public void complete(List tabCompletion, String[] args) { + return; + } + }, + + LIST("list", Messages.COMMAND_LIST, "cuberunner.player.list", "/%command% list", CRCommandType.GAME) { + @Override + public void execute(CubeRunner plugin, Player player, String[] args, Object... extra) { + JOIN.execute(plugin, player, new String[0]); + } + + @Override + public void complete(List tabCompletion, String[] args) { + return; + } + }, + INFO("info", Messages.COMMAND_INFO, "cuberunner.player.info", "/%command% info ", CRCommandType.GAME) { + @Override + public void execute(CubeRunner plugin, Player player, String[] args, Object... extra) { + Language local = CubeRunner.get().getLang(player); + + Arena arena = args.length > 1 ? Arena.getArena(args[1]) : null; + if (arena == null) { + local.sendMsg(player, local.get(Messages.ERROR_MISSING_ARENA)); + return; + } + + String cmdValue = extra.length > 0 ? ((extra[0] instanceof String) ? (String) extra[0] : "cr") : "cr"; + + if (args.length == 1) { + local.sendMsg(player, local.get(Messages.ERROR_MISSING_ARENA)); + local.sendMsg(player, local.get(Messages.INFO_TIP).replace("%cmd%", cmdValue)); + return; + } + + arena = Arena.getArena(args[1]); + if (arena == null) { + local.sendMsg(player, local.get(Messages.ERROR_MISSING_ARENA).replace("%arena%", args[1])); + local.sendMsg(player, local.get(Messages.INFO_TIP).replace("%cmd%", cmdValue)); + return; + } + + arena.displayInformation(player); + + } + + @Override + public void complete(List tabCompletion, String[] args) { + if (args.length == 2) + for (Arena arena : Arena.getArenas()) + if (arena.getName().startsWith(args[1].toLowerCase())) + tabCompletion.add(arena.getName()); + } + }, + JOIN("join", Messages.COMMAND_JOIN, "cuberunner.player.play.join", "/%command% join [arena]", CRCommandType.GAME) { + @Override + public void execute(CubeRunner plugin, Player player, String[] args, Object... extra) { + Language local = CubeRunner.get().getLang(player); + + Arena arena = Arena.getArenaFromPlayer(player); + if (arena != null) { + local.sendMsg(player, local.get(Messages.ERROR_ALREADY_IN_GAME)); + return; + } + + arena = args.length > 1 ? Arena.getArena(args[1]) : null; + if (arena == null) { + new CRInventoryJoin(CubeRunner.get().getCRPlayer(player), 1); + return; + } + + boolean teleport = extra.length > 0 ? ((extra[0] instanceof Boolean) ? (boolean) extra[0] : true) : false; + arena.addPlayer(player, teleport); + + } + + @Override + public void complete(List tabCompletion, String[] args) { + if (args.length == 2) + for (Arena arena : Arena.getArenas()) + if (arena.getName().toLowerCase().startsWith(args[1].toLowerCase())) + tabCompletion.add(arena.getName()); + } + }, + QUIT("quit", Messages.COMMAND_QUIT, "cuberunner.player.play.quit", "/%command% quit", CRCommandType.GAME) { + @Override + public void execute(CubeRunner plugin, Player player, String[] args, Object... extra) { + Language local = CubeRunner.get().getLang(player); + + Arena arena = Arena.getArenaFromPlayer(player); + if (arena == null) { + local.sendMsg(player, local.get(Messages.ERROR_NOT_IN_GAME)); + return; + } + + arena.removePlayer(player, LeavingReason.COMMAND); + } + + @Override + public void complete(List tabCompletion, String[] args) { + return; + } + }, + START("start", Messages.COMMAND_START, "cuberunner.player.play.start", "/%command% start", CRCommandType.GAME) { + @Override + public void execute(CubeRunner plugin, Player player, String[] args, Object... extra) { + Language local = CubeRunner.get().getLang(player); + + Arena arena = Arena.getArenaFromPlayer(player); + if (arena == null) { + local.sendMsg(player, local.get(Messages.ERROR_NOT_IN_GAME)); + return; + } + + if (arena.getGameState() != GameState.READY) { + local.sendMsg(player, local.get(Messages.START_NOT_READY)); + return; + } + + arena.initiateGame(player); + } + + @Override + public void complete(List tabCompletion, String[] args) { + return; + } + }, + + NEW("new", Messages.COMMAND_NEW, "cuberunner.admin.edit.new", "/%command% new ", CRCommandType.ARENA) { + @Override + public void execute(CubeRunner plugin, Player player, String[] args, Object... extra) { + Language local = CubeRunner.get().getLang(player); + + if (args.length <= 1) { + local.sendMsg(player, local.get(Messages.EDIT_CREATE_NONAME)); + return; + } + + if (Arena.getArena(args[1]) != null) { + local.sendMsg(player, local.get(Messages.EDIT_NEW_EXISTS).replace("%arena%", args[1])); + return; + } + + if (args[1].length() > 12) { + local.sendMsg(player, local.get(Messages.EDIT_NEW_LONG_NAME)); + return; + } + + new Arena(args[1], player); + local.sendMsg(player, local.get(Messages.EDIT_NEW_SUCCESS).replace("%arena%", args[1])); + } + + @Override + public void complete(List tabCompletion, String[] args) { + return; + } + }, + DELETE("delete", Messages.COMMAND_DELETE, "cuberunner.admin.edit.delete", "/%command% delete ", + CRCommandType.ARENA) { + @Override + public void execute(CubeRunner plugin, Player player, String[] args, Object... extra) { + Language local = CubeRunner.get().getLang(player); + + Arena arena = args.length > 1 ? Arena.getArena(args[1]) : null; + if (arena == null) { + local.sendMsg(player, local.get(Messages.ERROR_MISSING_ARENA)); + return; + } + + arena.delete(player); + } + + @Override + public void complete(List tabCompletion, String[] args) { + if (args.length == 2) + for (Arena arena : Arena.getArenas()) + if (arena.getName().toLowerCase().startsWith(args[1].toLowerCase())) + tabCompletion.add(arena.getName()); + } + }, + SETZONE("setzone", Messages.COMMAND_SETZONE, "cuberunner.admin.edit.zone", "/%command% setzone ", + CRCommandType.ARENA) { + @Override + public void execute(CubeRunner plugin, Player player, String[] args, Object... extra) { + Language local = CubeRunner.get().getLang(player); + + Arena arena = args.length > 1 ? Arena.getArena(args[1]) : null; + if (arena == null) { + local.sendMsg(player, local.get(Messages.ERROR_MISSING_ARENA)); + return; + } + + arena.setArena(player); + } + + @Override + public void complete(List tabCompletion, String[] args) { + if (args.length == 2) + for (Arena arena : Arena.getArenas()) + if (arena.getName().toLowerCase().startsWith(args[1].toLowerCase())) + tabCompletion.add(arena.getName()); + } + }, + SETLOBBY("setlobby", Messages.COMMAND_SETLOBBY, "cuberunner.admin.edit.lobby", "/%command% setlobby ", + CRCommandType.ARENA) { + @Override + public void execute(CubeRunner plugin, Player player, String[] args, Object... extra) { + Language local = CubeRunner.get().getLang(player); + + Arena arena = args.length > 1 ? Arena.getArena(args[1]) : null; + if (arena == null) { + local.sendMsg(player, local.get(Messages.ERROR_MISSING_ARENA)); + return; + } + + arena.setLobby(player); + } + + @Override + public void complete(List tabCompletion, String[] args) { + if (args.length == 2) + for (Arena arena : Arena.getArenas()) + if (arena.getName().toLowerCase().startsWith(args[1].toLowerCase())) + tabCompletion.add(arena.getName()); + } + }, + SETSTARTPOINT("setstartpoint", Messages.COMMAND_SETSTARTPOINT, "cuberunner.admin.edit.startpoint", + "/%command% setstartpoint ", CRCommandType.ARENA) { + @Override + public void execute(CubeRunner plugin, Player player, String[] args, Object... extra) { + Language local = CubeRunner.get().getLang(player); + + Arena arena = args.length > 1 ? Arena.getArena(args[1]) : null; + if (arena == null) { + local.sendMsg(player, local.get(Messages.ERROR_MISSING_ARENA)); + return; + } + + arena.setStartPoint(player); + } + + @Override + public void complete(List tabCompletion, String[] args) { + if (args.length == 2) + for (Arena arena : Arena.getArenas()) + if (arena.getName().toLowerCase().startsWith(args[1].toLowerCase())) + tabCompletion.add(arena.getName()); + } + }, + SETMINPLAYER("setminplayer", Messages.COMMAND_SETMINPLAYER, "cuberunner.admin.edit.amountplayer.minplayer", + "/%command% setminplayer ", CRCommandType.ARENA) { + @Override + public void execute(CubeRunner plugin, Player player, String[] args, Object... extra) { + Language local = CubeRunner.get().getLang(player); + + Arena arena = args.length > 1 ? Arena.getArena(args[1]) : null; + if (arena == null) { + local.sendMsg(player, local.get(Messages.ERROR_MISSING_ARENA)); + return; + } + + if (args.length < 3) { + local.sendMsg(player, local.get(Messages.EDIT_PLAYERS_MISSING)); + } + + try { + arena.setMinPlayer(Integer.parseInt(args[2]), player); + } catch (NumberFormatException e) { + local.sendMsg(player, local.get(Messages.EDIT_PLAYERS_ERROR).replace("%error%", + local.get(Messages.EDIT_PLAYERS_NAN))); + return; + } + + } + + @Override + public void complete(List tabCompletion, String[] args) { + if (args.length == 2) + for (Arena arena : Arena.getArenas()) + if (arena.getName().toLowerCase().startsWith(args[1].toLowerCase())) + tabCompletion.add(arena.getName()); + } + }, + SETMAXPLAYER("setmaxplayer", Messages.COMMAND_SETMAXPLAYER, "cuberunner.admin.edit.amountplayer.maxplayer", + "/%command% setmaxplayer ", CRCommandType.ARENA) { + @Override + public void execute(CubeRunner plugin, Player player, String[] args, Object... extra) { + Language local = CubeRunner.get().getLang(player); + + Arena arena = args.length > 1 ? Arena.getArena(args[1]) : null; + if (arena == null) { + local.sendMsg(player, local.get(Messages.ERROR_MISSING_ARENA)); + return; + } + + if (args.length < 3) { + local.sendMsg(player, local.get(Messages.EDIT_PLAYERS_MISSING)); + } + + try { + arena.setMaxPlayer(Integer.parseInt(args[2]), player); + } catch (NumberFormatException e) { + local.sendMsg(player, local.get(Messages.EDIT_PLAYERS_ERROR).replace("%error%", + local.get(Messages.EDIT_PLAYERS_NAN))); + return; + } + + } + + @Override + public void complete(List tabCompletion, String[] args) { + if (args.length == 2) + for (Arena arena : Arena.getArenas()) + if (arena.getName().toLowerCase().startsWith(args[1].toLowerCase())) + tabCompletion.add(arena.getName()); + + } + }, + SETCOLOR("setcolor", Messages.COMMAND_SETCOLOR, "cuberunner.admin.edit.color", "/%command% setcolor ", + CRCommandType.ARENA) { + @Override + public void execute(CubeRunner plugin, Player player, String[] args, Object... extra) { + Language local = CubeRunner.get().getLang(player); + + Arena arena = args.length > 1 ? Arena.getArena(args[1]) : null; + if (arena == null) { + local.sendMsg(player, local.get(Messages.ERROR_MISSING_ARENA)); + return; + } + + if (arena.getGameState() == GameState.ACTIVE || arena.getGameState() == GameState.ENDING) { + local.sendMsg(player, local.get(Messages.EDIT_COLOR_ERROR)); + return; + } + + new CRInventoryColor(plugin.getCRPlayer(player), arena); + } + + @Override + public void complete(List tabCompletion, String[] args) { + if (args.length == 2) + for (Arena arena : Arena.getArenas()) + if (arena.getName().toLowerCase().startsWith(args[1].toLowerCase())) + tabCompletion.add(arena.getName()); + } + }, + + RELOAD("reload", Messages.COMMAND_RELOAD, "cuberunner.admin.reload", "/%command% reload", CRCommandType.ADMIN) { + @Override + public void execute(CubeRunner plugin, Player player, String[] args, Object... extra) { + CubeRunner.get().reload(); + + Language local = CubeRunner.get().getLang(player); + local.sendMsg(player, local.get(Messages.ADMIN_RELOAD)); + } + + @Override + public void complete(List tabCompletion, String[] args) { + return; + } + }; + + private final String commandName; + private final Messages description; + private final String permission; + private final String usage; + private final CRCommandType type; + + public abstract void execute(CubeRunner plugin, Player player, String[] args, Object... extra); + + public abstract void complete(List tabCompletion, String[] args); + + private CRCommand(String commandName, Messages description, String permission, String usage, CRCommandType type) { + this.commandName = commandName; + this.description = description; + this.permission = permission; + this.usage = usage; + this.type = type; + } + + public String getCommandName() { + return commandName; + } + + public Messages getDescription() { + return description; + } + + public String getPermission() { + return permission; + } + + public String getUsage() { + return usage; + } + + public static CRCommand getCommand(String argument) { + for (CRCommand command : CRCommand.values()) { + if (command.commandName.equalsIgnoreCase(argument)) + return command; + } + return null; + } + + public static List getRequiredCommands(Player player, CRCommandType commandType) { + List requestedCommands = new ArrayList(); + + for (CRCommand command : CRCommand.values()) + if (command.type == commandType || commandType == null) + if (Permissions.hasPermission(command.permission, player, false)) + requestedCommands.add(command); + + return requestedCommands; + } + + public enum CRCommandType { + GENERAL, GAME, ARENA, ADMIN; + } + +} diff --git a/Bukkit/src/me/poutineqc/cuberunner/commands/InventoryItem.java b/Bukkit/src/me/poutineqc/cuberunner/commands/InventoryItem.java new file mode 100644 index 0000000..3f7aeac --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/commands/InventoryItem.java @@ -0,0 +1,66 @@ +package me.poutineqc.cuberunner.commands; + +import org.bukkit.Material; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import me.poutineqc.cuberunner.utils.ItemBannerManager; +import me.poutineqc.cuberunner.utils.ItemHeadManager; +import me.poutineqc.cuberunner.utils.ItemStackManager; + +public class InventoryItem { + private int position; + private ItemStackManager item; + + public InventoryItem(ItemStackManager item, int position) { + this.item = item; + this.position = position; + } + + public InventoryItem(ItemStackManager item) { + this.item = item; + } + + public InventoryItem(ItemStack itemStack) { + switch (itemStack.getType()) { + case SKULL_ITEM: + this.item = new ItemHeadManager(itemStack); + break; + case BANNER: + this.item = new ItemBannerManager(itemStack); + break; + default: + this.item = new ItemStackManager(itemStack); + } + } + + public InventoryItem(Material material) { + switch (material) { + case SKULL_ITEM: + this.item = new ItemHeadManager(); + break; + case BANNER: + this.item = new ItemBannerManager(); + break; + default: + this.item = new ItemStackManager(material); + } + } + + public InventoryItem(Material material, int position) { + this(material); + this.position = position; + } + + public ItemStackManager getItem() { + return item; + } + + public void setPosition(int position) { + this.position = position; + } + + public void addToInventory(Inventory inventory) { + inventory.setItem(position, item.getItem()); + } +} \ No newline at end of file diff --git a/Bukkit/src/me/poutineqc/cuberunner/commands/inventories/CRInventory.java b/Bukkit/src/me/poutineqc/cuberunner/commands/inventories/CRInventory.java new file mode 100644 index 0000000..a8f3f0d --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/commands/inventories/CRInventory.java @@ -0,0 +1,49 @@ +package me.poutineqc.cuberunner.commands.inventories; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import me.poutineqc.cuberunner.CRPlayer; +import me.poutineqc.cuberunner.CRPlayer.PlayerStatsException; +import me.poutineqc.cuberunner.Language.Messages; + +public abstract class CRInventory { + protected Inventory inventory; + protected CRPlayer crPlayer; + protected int amountOfRows; + protected String title; + + public CRInventory(CRPlayer crPlayer) { + this.crPlayer = crPlayer; + } + + public abstract void fillInventory() throws PlayerStatsException; + + public abstract void update(ItemStack itemStack, InventoryAction action); + + public static boolean areEqualOnColorStrip(String itemA, String itemB) { + return ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', itemA)) + .equalsIgnoreCase(ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', itemB))); + } + + protected void createInventory() { + inventory = Bukkit.createInventory(crPlayer.getPlayer(), amountOfRows * 9, getFullTitle()); + } + + protected String getFullTitle() { + return ChatColor.translateAlternateColorCodes('&', crPlayer.getLanguage().get(Messages.PREFIX_LONG) + " " + title); + } + + protected void openInventory() { + crPlayer.getPlayer().openInventory(inventory); + crPlayer.setCurrentInventory(this); + } + + protected void closeInventory() { + crPlayer.getPlayer().closeInventory(); + crPlayer.setCurrentInventory(null); + } +} diff --git a/Bukkit/src/me/poutineqc/cuberunner/commands/inventories/CRInventoryChallenge.java b/Bukkit/src/me/poutineqc/cuberunner/commands/inventories/CRInventoryChallenge.java new file mode 100644 index 0000000..776d940 --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/commands/inventories/CRInventoryChallenge.java @@ -0,0 +1,180 @@ +package me.poutineqc.cuberunner.commands.inventories; + +import java.text.DecimalFormat; +import java.text.NumberFormat; +import java.util.Map.Entry; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.inventory.ItemStack; + +import me.poutineqc.cuberunner.CRPlayer; +import me.poutineqc.cuberunner.CRStats; +import me.poutineqc.cuberunner.CRPlayer.PlayerStatsException; +import me.poutineqc.cuberunner.CubeRunner; +import me.poutineqc.cuberunner.Language; +import me.poutineqc.cuberunner.AchievementManager.Challenge; +import me.poutineqc.cuberunner.Language.Messages; +import me.poutineqc.cuberunner.commands.InventoryItem; +import me.poutineqc.cuberunner.utils.ItemStackManager; +import me.poutineqc.cuberunner.utils.Utils; + +public class CRInventoryChallenge extends CRInventory { + + public CRInventoryChallenge(CRPlayer crPlayer) { + super(crPlayer); + + Language local = crPlayer.getLanguage(); + this.title = local.get(Messages.STATS_CHALLENGES_TITLE); + this.amountOfRows = 3; + createInventory(); + + try { + fillInventory(); + } catch (PlayerStatsException e) { + e.printStackTrace(); + } + } + + @Override + public void fillInventory() throws PlayerStatsException { + Language local = crPlayer.getLanguage(); + InventoryItem icon; + int location; + + /*************************************************** + * Glass Spacer + ***************************************************/ + + icon = new InventoryItem(new ItemStackManager(Material.STAINED_GLASS_PANE)); + icon.getItem().setData((short) 10); + icon.getItem().setDisplayName(ChatColor.RED + ""); + + for (int i = 0; i < inventory.getSize(); i++) + switch (i) { + case 9: + case 10: + case 11: + case 12: + case 13: + case 14: + case 15: + case 16: + case 17: + icon.setPosition(i); + icon.addToInventory(inventory); + } + + /*************************************************** + * Stats + ***************************************************/ + + NumberFormat format2 = new DecimalFormat("#0.00"); + NumberFormat format3 = new DecimalFormat("#0.000"); + + icon = new InventoryItem(new ItemStackManager(Material.PAPER), 4); + icon.getItem().setDisplayName( + ChatColor.translateAlternateColorCodes('&', local.get(Messages.STATS_GUI_TITLE) + " : CubeRunner")); + + icon.getItem().addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); + icon.getItem().addToLore(local.get(Messages.STATS_INFO_AVERAGE_SCORE) + " : &e" + + format2.format(crPlayer.getDouble(CRStats.AVERAGE_SCORE))); + icon.getItem() + .addToLore(local.get(Messages.STATS_INFO_DISTANCE_RAN) + " : &e" + + format3.format(crPlayer.getDouble(CRStats.TOTAL_DISTANCE) / 1000) + " " + ChatColor.GREEN + + local.get(Messages.KEYWORD_GENERAL_DISTANCE)); + icon.getItem().addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); + icon.getItem().addToLore( + local.get(Messages.STATS_INFO_GAMES) + " : &e" + String.valueOf(crPlayer.getInt(CRStats.GAMES_PLAYED))); + icon.getItem().addToLore(local.get(Messages.STATS_INFO_TOTAL_SCORE) + " : &e" + + String.valueOf(crPlayer.getInt(CRStats.TOTAL_SCORE))); + icon.getItem().addToLore( + local.get(Messages.STATS_INFO_KILLS) + " : &e" + String.valueOf(crPlayer.getInt(CRStats.KILLS))); + icon.getItem().addToLore(local.get(Messages.STATS_INFO_MULTIPLAYER_WON) + " : &e" + + String.valueOf(crPlayer.getInt(CRStats.MULTIPLAYER_WON))); + icon.getItem().addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); + icon.getItem().addToLore(ChatColor.LIGHT_PURPLE + Utils.strip(local.get(Messages.STATS_INFO_TIME_PLAYED)) + ": " + + getTimePLayed(local, crPlayer.getInt(CRStats.TIME_PLAYED))); + if (CubeRunner.get().isEconomyEnabled()) + icon.getItem() + .addToLore(ChatColor.LIGHT_PURPLE + Utils.strip(local.get(Messages.STATS_INFO_MONEY)) + ": &e" + + format2.format(crPlayer.getDouble(CRStats.MONEY)) + ChatColor.GREEN + + CubeRunner.get().getEconomy().currencyNamePlural()); + + icon.addToInventory(inventory); + + /*************************************************** + * Challenges + ***************************************************/ + + location = 19; + for (Entry challenge : CubeRunner.get().getAchievementManager().getChallenges().entrySet()) { + if (location == 22) + location++; + + icon = new InventoryItem(new ItemStackManager(Material.INK_SACK)); + boolean done = crPlayer.hasChallenge(challenge.getKey().getCrStats()); + icon.getItem().setData(done ? (short) 10 : (short) 8); + icon.getItem().setDisplayName( + (done ? (ChatColor.GREEN + "") : (ChatColor.RED + "")) + Utils.strip(local.get(challenge.getKey().getMessage()))); + icon.getItem().addToLore(ChatColor.YELLOW + "----------------------------"); + icon.getItem() + .addToLore(ChatColor.AQUA + Utils.strip(local.get(Messages.KEYWORD_STATS_PROGRESSION)) + ": " + + (done ? (ChatColor.GREEN + Utils.strip(local.get(Messages.KEYWORD_STATS_COMPLETED))) + : (ChatColor.RED + Utils.strip(local.get(Messages.KEYWORD_STATS_NOT_COMPLETED))))); + if (!done && CubeRunner.get().isEconomyEnabled() && CubeRunner.get().getConfiguration().achievementsRewards) + icon.getItem().addToLore(ChatColor.AQUA + + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', + local.get(Messages.KEYWORD_STATS_REWARD) + ": ")) + + ChatColor.YELLOW + String.valueOf(challenge.getValue()) + + CubeRunner.get().getEconomy().currencyNamePlural()); + + icon.setPosition(location++); + icon.addToInventory(inventory); + } + + /*************************************************** + * Arrow + ***************************************************/ + + icon = new InventoryItem(new ItemStackManager(Material.ARROW)); + + icon.getItem().setDisplayName(local.get(Messages.STATS_GUI_TITLE)); + + icon.setPosition(8); + icon.addToInventory(inventory); + + /*************************************************** + * Display + ***************************************************/ + + openInventory(); + + } + + private String getTimePLayed(Language local, int timePlayed) { + long hours = 0; + + timePlayed /= 60000; + while (timePlayed > 60) { + timePlayed -= 60; + hours++; + } + + return ChatColor.YELLOW + String.valueOf(hours) + ChatColor.GREEN + " " + + Utils.strip(local.get(Messages.KEYWORD_GENERAL_HOURS)) + ChatColor.YELLOW + " " + + String.valueOf(timePlayed) + ChatColor.GREEN + " " + + Utils.strip(local.get(Messages.KEYWORD_GENERAL_MINUTES)); + } + + @Override + public void update(ItemStack itemStack, InventoryAction action) { + Language local = crPlayer.getLanguage(); + + if (Utils.isEqualOnColorStrip(itemStack.getItemMeta().getDisplayName(), local.get(Messages.STATS_GUI_TITLE))) { + new CRInventoryStats(crPlayer); + } + } + +} diff --git a/Bukkit/src/me/poutineqc/cuberunner/commands/inventories/CRInventoryColor.java b/Bukkit/src/me/poutineqc/cuberunner/commands/inventories/CRInventoryColor.java new file mode 100644 index 0000000..ea9f82b --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/commands/inventories/CRInventoryColor.java @@ -0,0 +1,122 @@ +package me.poutineqc.cuberunner.commands.inventories; + +import java.util.List; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.inventory.ItemStack; + +import me.poutineqc.cuberunner.CRPlayer; +import me.poutineqc.cuberunner.Language; +import me.poutineqc.cuberunner.Language.Messages; +import me.poutineqc.cuberunner.commands.InventoryItem; +import me.poutineqc.cuberunner.game.Arena; +import me.poutineqc.cuberunner.game.GameState; +import me.poutineqc.cuberunner.utils.ItemStackManager; + +public class CRInventoryColor extends CRInventory { + + private Arena arena; + + public CRInventoryColor(CRPlayer crPlayer, Arena arena) { + super(crPlayer); + + this.arena = arena; + Language local = crPlayer.getLanguage(); + this.title = local.get(Messages.EDIT_COLOR_GUI_TITLE); + this.amountOfRows = 6; + createInventory(); + + fillInventory(); + } + + @Override + public void fillInventory() { + Language local = crPlayer.getLanguage(); + InventoryItem icon; + + /*************************************************** + * Instructions + ***************************************************/ + + icon = new InventoryItem(new ItemStackManager(Material.BOOKSHELF), 4); + icon.getItem().setDisplayName(local.get(Messages.KEYWORD_GUI_INSTRUCTIONS)); + for (String loreLine : local.get(Messages.EDIT_COLOR_GUI_INFO).split("\n")) + icon.getItem().addToLore(loreLine); + icon.addToInventory(inventory); + + /*************************************************** + * Glass Spacer + ***************************************************/ + + icon = new InventoryItem(new ItemStackManager(Material.STAINED_GLASS_PANE)); + icon.getItem().setData((short) 10); + icon.getItem().setDisplayName(ChatColor.RED + ""); + + for (int i = 0; i < inventory.getSize(); i++) + switch (i) { + case 9: + case 10: + case 11: + case 12: + case 13: + case 14: + case 15: + case 16: + case 17: + case 18: + case 27: + case 36: + case 45: + icon.setPosition(i); + icon.addToInventory(inventory); + } + + /*************************************************** + * Blocks + ***************************************************/ + + List colorManager = arena.getColorManager().getAllBlocks(); + for (int i = 0; i < 32; i++) { + icon = new InventoryItem(colorManager.get(i)); + icon.setPosition((int) ((Math.floor(i / 8.0) * 9) + 19 + (i % 8))); + icon.addToInventory(inventory); + } + + /*************************************************** + * Display + ***************************************************/ + + openInventory(); + } + + @Override + public void update(ItemStack itemStack, InventoryAction action) { + if (itemStack.getType() != Material.STAINED_CLAY && itemStack.getType() != Material.WOOL) + return; + + if (arena.getGameState() == GameState.ACTIVE || arena.getGameState() == GameState.ENDING) { + crPlayer.getPlayer().closeInventory(); + crPlayer.setCurrentInventory(null); + crPlayer.getLanguage().sendMsg(crPlayer.getPlayer(), crPlayer.getLanguage().get(Messages.EDIT_COLOR_ERROR)); + return; + } + + int valueOfItem = itemStack.getDurability(); + if (itemStack.getType() == Material.STAINED_CLAY) + valueOfItem += 16; + + if (itemStack.getItemMeta().hasEnchants()) { + arena.getColorManager() + .setColorIndice(arena.getColorManager().getColorIndice() - (int) Math.pow(2, valueOfItem)); + } else { + arena.getColorManager() + .setColorIndice(arena.getColorManager().getColorIndice() + (int) Math.pow(2, valueOfItem)); + } + + arena.resetArena(itemStack); + new CRInventoryColor(crPlayer, arena); + } + +} diff --git a/Bukkit/src/me/poutineqc/cuberunner/commands/inventories/CRInventoryJoin.java b/Bukkit/src/me/poutineqc/cuberunner/commands/inventories/CRInventoryJoin.java new file mode 100644 index 0000000..03e5199 --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/commands/inventories/CRInventoryJoin.java @@ -0,0 +1,185 @@ +package me.poutineqc.cuberunner.commands.inventories; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.inventory.ItemStack; + +import me.poutineqc.cuberunner.CRPlayer; +import me.poutineqc.cuberunner.Language; +import me.poutineqc.cuberunner.Language.Messages; +import me.poutineqc.cuberunner.commands.InventoryItem; +import me.poutineqc.cuberunner.game.Arena; +import me.poutineqc.cuberunner.game.GameState; +import me.poutineqc.cuberunner.utils.ItemBannerManager; +import me.poutineqc.cuberunner.utils.ItemBannerManager.CustomPattern; +import me.poutineqc.cuberunner.utils.ItemStackManager; +import me.poutineqc.cuberunner.utils.Utils; + +public class CRInventoryJoin extends CRInventory { + + private int page; + + public CRInventoryJoin(CRPlayer crPlayer, int page) { + super(crPlayer); + + Language local = crPlayer.getLanguage(); + this.title = local.get(Messages.JOIN_GUI_TITLE); + this.page = page; + this.amountOfRows = 6; + createInventory(); + + fillInventory(); + } + + @Override + public void fillInventory() { + + List arenas = new ArrayList(); + for (Arena arena : Arena.getArenas()) + arenas.add(arena.getName()); + java.util.Collections.sort(arenas); + + Language local = crPlayer.getLanguage(); + InventoryItem icon; + + /*************************************************** + * Instructions + ***************************************************/ + + icon = new InventoryItem(new ItemStackManager(Material.BOOKSHELF), 4); + icon.getItem().setDisplayName(local.get(Messages.KEYWORD_GUI_INSTRUCTIONS)); + for (String loreLine : local.get(Messages.JOIN_GUI_INFO).split("\n")) + icon.getItem().addToLore(loreLine); + icon.addToInventory(inventory); + + /*************************************************** + * Glass Spacer + ***************************************************/ + + icon = new InventoryItem(new ItemStackManager(Material.STAINED_GLASS_PANE)); + icon.getItem().setData((short) 10); + icon.getItem().setDisplayName(ChatColor.RED + ""); + + for (int i = 0; i < inventory.getSize(); i++) + switch (i) { + case 9: + case 10: + case 11: + case 12: + case 13: + case 14: + case 15: + case 16: + case 17: + icon.setPosition(i); + icon.addToInventory(inventory); + } + + /*************************************************** + * arenas + ***************************************************/ + + icon = new InventoryItem(new ItemStackManager(Material.INK_SACK)); + int slot = 18; + + for (int i = ((page - 1) * 27); arenas.size() > i && slot < 45; i++) { + Arena arena = Arena.getArena(arenas.get(i)); + icon.getItem().clearLore(); + + if (arena.getGameState() == GameState.UNREADY) { + icon.getItem().setData((short) 8); + icon.getItem().setDisplayName(ChatColor.GOLD + arenas.get(i)); + icon.getItem().addToLore(local.get(Messages.KEYWORD_GAMESTATE_UNSET)); + + } else if (arena.getGameState() == GameState.ACTIVE || arena.getGameState() == GameState.ENDING) { + icon.getItem().setData((short) 12); + icon.getItem().setDisplayName(ChatColor.GOLD + arenas.get(i)); + icon.getItem().addToLore(local.get(Messages.KEYWORD_GAMESTATE_ACTIVE)); + + } else { + icon.getItem().setData((short) 10); + icon.getItem().setDisplayName(ChatColor.GOLD + arenas.get(i)); + icon.getItem().addToLore(local.get(Messages.KEYWORD_GAMESTATE_READY)); + icon.getItem().addToLore(ChatColor.YELLOW + local.get(Messages.KEYWORD_SCOREBOARD_PLAYERS) + " : " + + String.valueOf(arena.getAmountOfPlayerInGame()) + "/" + arena.getMaxPlayer()); + } + + icon.setPosition(slot++); + icon.addToInventory(inventory); + } + + /*************************************************** + * NextPage + ***************************************************/ + + if (arenas.size() - ((page - 1) * 27) > 27) { + icon = new InventoryItem(new ItemBannerManager(CustomPattern.ARROW_RIGHT), 50); + icon.getItem() + .setDisplayName(local.get(Messages.KEYWORD_GUI_PAGE).replace("%number%", String.valueOf(page + 1))); + icon.addToInventory(inventory); + } + + /*************************************************** + * Current + ***************************************************/ + + icon = new InventoryItem(new ItemBannerManager(CustomPattern.ARROW_ACTUAL), 49); + icon.getItem().setDisplayName(local.get(Messages.KEYWORD_GUI_PAGE).replace("%number%", String.valueOf(page))); + icon.addToInventory(inventory); + + /*************************************************** + * Previous Page + ***************************************************/ + + if (page > 1) { + icon = new InventoryItem(new ItemBannerManager(CustomPattern.ARROW_LEFT), 48); + icon.getItem() + .setDisplayName(local.get(Messages.KEYWORD_GUI_PAGE).replace("%number%", String.valueOf(page - 1))); + icon.addToInventory(inventory); + } + + /*********************************************** + * Final Procedure + */ + + openInventory(); + + } + + @Override + public void update(ItemStack itemStack, InventoryAction action) { + + Language local = crPlayer.getLanguage(); + String itemName = itemStack.getItemMeta().getDisplayName(); + + if (Utils.isEqualOnColorStrip(itemName, + local.get(Messages.KEYWORD_GUI_PAGE).replace("%number%", String.valueOf(page + 1)))) { + new CRInventoryJoin(crPlayer, page + 1); + return; + } + + if (Utils.isEqualOnColorStrip(itemName, + local.get(Messages.KEYWORD_GUI_PAGE).replace("%number%", String.valueOf(page - 1)))) { + new CRInventoryJoin(crPlayer, page - 1); + return; + } + + Arena arena = Arena.getArena(ChatColor.stripColor(itemName)); + if (arena == null) + return; + + if (action == InventoryAction.PICKUP_HALF) { + arena.displayInformation(crPlayer.getPlayer()); + } else { + arena.addPlayer(crPlayer.getPlayer(), true); + } + + crPlayer.getPlayer().closeInventory(); + + } + +} diff --git a/Bukkit/src/me/poutineqc/cuberunner/commands/inventories/CRInventoryStats.java b/Bukkit/src/me/poutineqc/cuberunner/commands/inventories/CRInventoryStats.java new file mode 100644 index 0000000..832089d --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/commands/inventories/CRInventoryStats.java @@ -0,0 +1,306 @@ +package me.poutineqc.cuberunner.commands.inventories; + +import java.text.DecimalFormat; +import java.text.NumberFormat; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map.Entry; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.inventory.ItemStack; + +import me.poutineqc.cuberunner.AchievementManager.Achievement; +import me.poutineqc.cuberunner.CRPlayer; +import me.poutineqc.cuberunner.CRPlayer.PlayerStatsException; +import me.poutineqc.cuberunner.CRStats; +import me.poutineqc.cuberunner.CubeRunner; +import me.poutineqc.cuberunner.Language; +import me.poutineqc.cuberunner.Language.Messages; +import me.poutineqc.cuberunner.commands.InventoryItem; +import me.poutineqc.cuberunner.utils.ItemStackManager; +import me.poutineqc.cuberunner.utils.Utils; + +public class CRInventoryStats extends CRInventory { + + public CRInventoryStats(CRPlayer crPlayer) { + super(crPlayer); + + Language local = crPlayer.getLanguage(); + this.title = local.get(Messages.STATS_GUI_TITLE); + this.amountOfRows = 6; + createInventory(); + + try { + fillInventory(); + } catch (PlayerStatsException e) { + e.printStackTrace(); + } + } + + @Override + public void fillInventory() throws PlayerStatsException { + + Language local = crPlayer.getLanguage(); + int location; + InventoryItem icon; + + /*************************************************** + * Glass Spacer + ***************************************************/ + + icon = new InventoryItem(new ItemStackManager(Material.STAINED_GLASS_PANE)); + icon.getItem().setData((short) 10); + icon.getItem().setDisplayName(ChatColor.RED + ""); + + for (int i = 0; i < inventory.getSize(); i++) + switch (i) { + case 1: + case 10: + case 11: + case 12: + case 13: + case 14: + case 15: + case 16: + case 17: + case 19: + case 28: + case 37: + case 46: + icon.setPosition(i); + icon.addToInventory(inventory); + } + + /*************************************************** + * Stats + ***************************************************/ + + NumberFormat format2 = new DecimalFormat("#0.00"); + NumberFormat format3 = new DecimalFormat("#0.000"); + + icon = new InventoryItem(new ItemStackManager(Material.PAPER), 2); + icon.getItem().setDisplayName( + ChatColor.translateAlternateColorCodes('&', local.get(Messages.STATS_GUI_TITLE) + " : CubeRunner")); + + icon.getItem().addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); + icon.getItem().addToLore(local.get(Messages.STATS_INFO_AVERAGE_SCORE) + " : &e" + + format2.format(crPlayer.getDouble(CRStats.AVERAGE_SCORE))); + icon.getItem() + .addToLore(local.get(Messages.STATS_INFO_DISTANCE_RAN) + " : &e" + + format3.format(crPlayer.getDouble(CRStats.TOTAL_DISTANCE) / 1000) + " " + ChatColor.GREEN + + local.get(Messages.KEYWORD_GENERAL_DISTANCE)); + icon.getItem().addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); + icon.getItem().addToLore( + local.get(Messages.STATS_INFO_GAMES) + " : &e" + String.valueOf(crPlayer.getInt(CRStats.GAMES_PLAYED))); + icon.getItem().addToLore(local.get(Messages.STATS_INFO_TOTAL_SCORE) + " : &e" + + String.valueOf(crPlayer.getInt(CRStats.TOTAL_SCORE))); + icon.getItem().addToLore( + local.get(Messages.STATS_INFO_KILLS) + " : &e" + String.valueOf(crPlayer.getInt(CRStats.KILLS))); + icon.getItem().addToLore(local.get(Messages.STATS_INFO_MULTIPLAYER_WON) + " : &e" + + String.valueOf(crPlayer.getInt(CRStats.MULTIPLAYER_WON))); + icon.getItem().addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); + icon.getItem().addToLore(ChatColor.LIGHT_PURPLE + Utils.strip(local.get(Messages.STATS_INFO_TIME_PLAYED)) + ": " + + getTimePLayed(local, crPlayer.getInt(CRStats.TIME_PLAYED))); + if (CubeRunner.get().isEconomyEnabled()) + icon.getItem() + .addToLore(ChatColor.LIGHT_PURPLE + Utils.strip(local.get(Messages.STATS_INFO_MONEY)) + ": &e" + + format2.format(crPlayer.getDouble(CRStats.MONEY)) + ChatColor.GREEN + + CubeRunner.get().getEconomy().currencyNamePlural()); + + icon.addToInventory(inventory); + + /*************************************************** + * Top Ratio + ***************************************************/ + + int position = 0; + for (Top10 top : Top10.values()) { + icon = new InventoryItem(new ItemStackManager(Material.EMPTY_MAP)); + icon.getItem().setDisplayName(top.getName(local)); + icon.getItem().addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); + + List view = CubeRunner.get().getPlayerData().getViews().get(top.getCrStats()).getList(); + for (int i = 0; i < 10 && i < view.size(); i++) + icon.getItem().addToLore(ChatColor.LIGHT_PURPLE + view.get(i).getName() + " : " + ChatColor.YELLOW + + top.getAmount(view.get(i))); + + icon.setPosition(position); + icon.addToInventory(inventory); + position += 9; + } + + /*************************************************** + * Achievements games + ***************************************************/ + int generalLocation = 20; + HashMap> entries = CubeRunner.get().getAchievementManager() + .getAchievements(); + for (Achievement achievement : Achievement.values()) { + + location = generalLocation; + + for (Entry goal : entries.get(achievement).entrySet()) { + + boolean done = goal.getKey() <= crPlayer.getInt(achievement.getCrStats()); + + icon = new InventoryItem(new ItemStackManager(Material.WOOL)); + icon.getItem().setData(done ? (short) 5 : (short) 8); + icon.getItem().setDisplayName((done ? ChatColor.GREEN : ChatColor.RED) + Utils.strip(local + .get(achievement.getAchievementMessage()).replace("%amount%", String.valueOf(goal.getKey())))); + icon.getItem().addToLore(ChatColor.YELLOW + "----------------------------"); + icon.getItem() + .addToLore(ChatColor.AQUA + Utils.strip(local.get(Messages.KEYWORD_STATS_PROGRESSION) + ": ") + + (done ? (ChatColor.GREEN + Utils.strip(local.get(Messages.KEYWORD_STATS_COMPLETED))) + : ChatColor.YELLOW + String.valueOf(crPlayer.getInt(achievement.getCrStats())) + "/" + + String.valueOf(goal.getKey()))); + + if (!done && CubeRunner.get().isEconomyEnabled() + && CubeRunner.get().getConfiguration().achievementsRewards) + icon.getItem() + .addToLore(ChatColor.AQUA + Utils.strip(local.get(Messages.KEYWORD_STATS_REWARD)) + ": " + + ChatColor.YELLOW + String.valueOf(goal.getValue()) + + CubeRunner.get().getEconomy().currencyNamePlural()); + + icon.setPosition(location++); + icon.addToInventory(inventory); + + } + + generalLocation += 9; + } + + /*************************************************** + * Arrow + ***************************************************/ + + icon = new InventoryItem(new ItemStackManager(Material.ARROW)); + + icon.getItem().setDisplayName(local.get(Messages.STATS_CHALLENGES_TITLE)); + + icon.setPosition(8); + icon.addToInventory(inventory); + + /*************************************************** + * Display + ***************************************************/ + + openInventory(); + + } + + private String getTimePLayed(Language local, int timePlayed) { + long hours = 0; + + timePlayed /= 60000; + while (timePlayed > 60) { + timePlayed -= 60; + hours++; + } + + return ChatColor.YELLOW + String.valueOf(hours) + ChatColor.GREEN + " " + + Utils.strip(local.get(Messages.KEYWORD_GENERAL_HOURS)) + ChatColor.YELLOW + " " + + String.valueOf(timePlayed) + ChatColor.GREEN + " " + + Utils.strip(local.get(Messages.KEYWORD_GENERAL_MINUTES)); + } + + @Override + public void update(ItemStack itemStack, InventoryAction action) { + Language local = crPlayer.getLanguage(); + + if (Utils.isEqualOnColorStrip(itemStack.getItemMeta().getDisplayName(), + local.get(Messages.STATS_CHALLENGES_TITLE))) { + new CRInventoryChallenge(crPlayer); + } + } + + private enum Top10 { + AVERAGE_SCORE(CRStats.AVERAGE_SCORE, Messages.STATS_INFO_AVERAGE_SCORE) { + @Override + public String getAmount(CRPlayer player) { + try { + return ChatColor.YELLOW + new DecimalFormat("#0.00").format(player.getDouble(getCrStats())); + } catch (PlayerStatsException e) { + e.printStackTrace(); + return ""; + } + } + }, + TOTAL_DISTANCE(CRStats.TOTAL_DISTANCE, Messages.STATS_INFO_DISTANCE_RAN) { + @Override + public String getAmount(CRPlayer player) { + try { + return ChatColor.YELLOW + new DecimalFormat("#0.000").format(player.getDouble(getCrStats()) / 1000) + " " + + ChatColor.GREEN + player.getLanguage().get(Messages.KEYWORD_GENERAL_DISTANCE); + } catch (PlayerStatsException e) { + e.printStackTrace(); + return ""; + } + } + }, + GAMES(CRStats.GAMES_PLAYED, Messages.STATS_INFO_GAMES) { + @Override + public String getAmount(CRPlayer player) { + try { + return String.format("%1$d", player.getInt(getCrStats())); + } catch (PlayerStatsException e) { + e.printStackTrace(); + return ""; + } + } + }, + TOTAL_SCORE(CRStats.TOTAL_SCORE, Messages.STATS_INFO_TOTAL_SCORE) { + @Override + public String getAmount(CRPlayer player) { + try { + return String.format("%1$d", player.getInt(getCrStats())); + } catch (PlayerStatsException e) { + e.printStackTrace(); + return ""; + } + } + }, + KILLS(CRStats.KILLS, Messages.STATS_INFO_KILLS) { + @Override + public String getAmount(CRPlayer player) { + try { + return String.format("%1$d", player.getInt(getCrStats())); + } catch (PlayerStatsException e) { + e.printStackTrace(); + return ""; + } + } + }, + MULTIPLAYER_WON(CRStats.MULTIPLAYER_WON, Messages.STATS_INFO_MULTIPLAYER_WON) { + @Override + public String getAmount(CRPlayer player) { + try { + return String.format("%1$d", player.getInt(getCrStats())); + } catch (PlayerStatsException e) { + e.printStackTrace(); + return ""; + } + } + }; + + private CRStats crStats; + private Messages message; + + private Top10(CRStats crStats, Messages message) { + this.message = message; + this.crStats = crStats; + } + + public abstract String getAmount(CRPlayer player); + + public String getName(Language local) { + return ChatColor.GOLD + local.get(Messages.KEYWORD_STATS_TOP10) + " : " + local.get(message); + } + + public CRStats getCrStats() { + return crStats; + } + } +} diff --git a/Bukkit/src/me/poutineqc/cuberunner/commands/signs/CRSign.java b/Bukkit/src/me/poutineqc/cuberunner/commands/signs/CRSign.java new file mode 100644 index 0000000..8bf8485 --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/commands/signs/CRSign.java @@ -0,0 +1,261 @@ +package me.poutineqc.cuberunner.commands.signs; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.block.BlockState; +import org.bukkit.block.Sign; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.entity.Player; + +import me.poutineqc.cuberunner.Configuration; +import me.poutineqc.cuberunner.CubeRunner; +import me.poutineqc.cuberunner.Language; +import me.poutineqc.cuberunner.MySQL; +import me.poutineqc.cuberunner.PlayerData; +import me.poutineqc.cuberunner.game.Arena; +import me.poutineqc.cuberunner.utils.MinecraftConfiguration; + +public abstract class CRSign { + + protected static CubeRunner plugin; + protected static Configuration config; + private static MySQL mysql; + protected static PlayerData playerData; + + private static MinecraftConfiguration signData; + + protected static List signs = new ArrayList(); + + private UUID uuid; + protected Location location; + + public static void setVariables(CubeRunner plugin) { + CRSign.plugin = plugin; + CRSign.config = plugin.getConfiguration(); + CRSign.mysql = plugin.getMySQL(); + CRSign.playerData = plugin.getPlayerData(); + + signData = new MinecraftConfiguration(null, "signData", false); + } + + public static void loadAllSigns() { + signs.clear(); + + if (mysql.hasConnection()) { + ResultSet query = mysql.query("SELECT * FROM " + config.tablePrefix + "SIGNS;"); + try { + while (query.next()) { + UUID uuid = UUID.fromString(query.getString("uuid")); + Location location = new Location(Bukkit.getWorld(query.getString("locationWorld")), + query.getInt("locationX"), query.getInt("locationY"), query.getInt("locationZ")); + + try { + switch (SignType.valueOf(query.getString("type"))) { + case JOIN: + new CRSignJoin(uuid, location); + break; + case PLAY: + new CRSignPlay(uuid, location); + break; + case QUIT: + new CRSignQuit(uuid, location); + break; + case START: + new CRSignStart(uuid, location); + break; + case STATS: + new CRSignStats(uuid, location); + break; + case TOP: + new CRSignTop(uuid, location); + break; + + } + } catch (IllegalArgumentException e) { + CRSign.removeSign(uuid, location); + } + } + } catch (SQLException e) { + e.printStackTrace(); + } + } else { + if (!signData.get().contains("signs")) + return; + + for (String uuid : signData.get().getConfigurationSection("signs").getKeys(false)) { + ConfigurationSection cs = signData.get().getConfigurationSection("signs." + uuid); + Location location = new Location(Bukkit.getWorld(cs.getString("location.world")), + cs.getInt("location.X", 0), cs.getInt("location.Y", 0), cs.getInt("location.Z")); + + try { + switch (SignType.valueOf(cs.getString("type", UUID.randomUUID().toString()))) { + case JOIN: + new CRSignJoin(UUID.fromString(uuid), location); + break; + case PLAY: + new CRSignPlay(UUID.fromString(uuid), location); + break; + case QUIT: + new CRSignQuit(UUID.fromString(uuid), location); + break; + case START: + new CRSignStart(UUID.fromString(uuid), location); + break; + case STATS: + new CRSignStats(UUID.fromString(uuid), location); + break; + case TOP: + new CRSignTop(UUID.fromString(uuid), location); + break; + } + } catch (IllegalArgumentException e) { + CRSign.removeSign(UUID.fromString(uuid), location); + } + } + } + + updateSigns(); + } + + public CRSign(UUID uuid, Location location, SignType type) { + this.uuid = uuid; + this.location = location; + } + + public CRSign(Location location, SignType type) { + this.uuid = UUID.randomUUID(); + this.location = location; + + if (mysql.hasConnection()) { + mysql.update("INSERT INTO " + config.tablePrefix + + "SIGNS (uuid, type ,locationWorld, locationX, locationY, locationZ) " + "VALUES ('" + uuid + "','" + + type.name() + "','" + location.getWorld().getName() + "','" + location.getBlockX() + "','" + + location.getBlockY() + "','" + location.getBlockZ() + "');"); + + } else { + signData.get().set("signs." + uuid.toString() + ".type", type.name()); + signData.get().set("signs." + uuid.toString() + ".location.world", location.getWorld().getName()); + signData.get().set("signs." + uuid.toString() + ".location.X", location.getBlockX()); + signData.get().set("signs." + uuid.toString() + ".location.Y", location.getBlockY()); + signData.get().set("signs." + uuid.toString() + ".location.Z", location.getBlockZ()); + signData.save(); + } + } + + private static void removeSign(UUID uuid, Location location) { + if (location.getBlock().getState() instanceof Sign) { + Sign sign = (Sign) location.getBlock().getState(); + sign.setLine(0, " "); + sign.setLine(1, " "); + sign.setLine(2, " "); + sign.setLine(3, " "); + sign.getLocation().getChunk().load(); + sign.update(); + } + + if (mysql.hasConnection()) { + mysql.update("DELETE FROM " + config.tablePrefix + "SIGNS WHERE uuid='" + uuid.toString() + "';"); + } else { + signData.get().set("signs." + uuid.toString(), null); + signData.save(); + } + } + + public void removeSign() { + removeSign(uuid, location); + signs.remove(this); + } + + public abstract void onInteract(Player player); + + protected abstract boolean updateSign(Language local, Sign sign); + + public static void updateSigns() { + List errors = new ArrayList(); + + for (CRSign dacsign : signs) { + + BlockState block = dacsign.location.getBlock().getState(); + if (!(block instanceof Sign)) { + errors.add(dacsign); + continue; + } + + if (!dacsign.updateSign(Language.getDefault(), (Sign) block)) + errors.add(dacsign); + } + + for (CRSign toRemove : errors) + toRemove.removeSign(); + } + + public static void updateSigns(Arena arena) { + if (arena == null) + return; + + List errors = new ArrayList(); + + for (CRSign dacsign : signs) { + if (!(dacsign instanceof CRSignDisplay)) + continue; + + CRSignDisplay displaySign = (CRSignDisplay) dacsign; + if (displaySign.arena != arena) + continue; + + BlockState block = dacsign.location.getBlock().getState(); + if (!(block instanceof Sign)) { + errors.add(dacsign); + continue; + } + + displaySign.updateDisplay(Language.getDefault(), (Sign) block); + } + + for (CRSign toRemove : errors) + toRemove.removeSign(); + } + + public static void arenaDelete(Arena arena) { + if (arena == null) + return; + + List errors = new ArrayList(); + + for (CRSign dacsign : signs) { + if (!(dacsign instanceof CRSignDisplay)) + continue; + + CRSignDisplay displaySign = (CRSignDisplay) dacsign; + if (displaySign.arena != arena) + continue; + + if (!arena.getName().equalsIgnoreCase(((Sign) dacsign.location.getBlock().getState()).getLine(2))) + continue; + + errors.add(dacsign); + } + + for (CRSign toRemove : errors) + toRemove.removeSign(); + } + + public static CRSign getCrSign(Location location) { + for (CRSign dacsign : signs) { + if (dacsign.location.equals(location)) + return dacsign; + } + + return null; + } + + public enum SignType { + JOIN, PLAY, START, QUIT, STATS, TOP; + } +} diff --git a/Bukkit/src/me/poutineqc/cuberunner/commands/signs/CRSignDisplay.java b/Bukkit/src/me/poutineqc/cuberunner/commands/signs/CRSignDisplay.java new file mode 100644 index 0000000..d5d47d5 --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/commands/signs/CRSignDisplay.java @@ -0,0 +1,25 @@ +package me.poutineqc.cuberunner.commands.signs; + +import java.util.UUID; + +import org.bukkit.Location; +import org.bukkit.block.Sign; + +import me.poutineqc.cuberunner.Language; +import me.poutineqc.cuberunner.game.Arena; + +public abstract class CRSignDisplay extends CRSign { + + protected Arena arena; + + public CRSignDisplay(Location location, SignType type) { + super(location, type); + } + + public CRSignDisplay(UUID uuid, Location location, SignType type) { + super(uuid, location, type); + } + + protected abstract void updateDisplay(Language local, Sign sign); + +} diff --git a/Bukkit/src/me/poutineqc/cuberunner/commands/signs/CRSignJoin.java b/Bukkit/src/me/poutineqc/cuberunner/commands/signs/CRSignJoin.java new file mode 100644 index 0000000..a1eeffb --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/commands/signs/CRSignJoin.java @@ -0,0 +1,97 @@ +package me.poutineqc.cuberunner.commands.signs; + +import java.util.UUID; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.block.BlockState; +import org.bukkit.block.Sign; +import org.bukkit.entity.Player; +import org.bukkit.event.block.SignChangeEvent; + +import me.poutineqc.cuberunner.Language; +import me.poutineqc.cuberunner.Language.Messages; +import me.poutineqc.cuberunner.commands.CRCommand; +import me.poutineqc.cuberunner.game.Arena; +import me.poutineqc.cuberunner.utils.Permissions; + +public class CRSignJoin extends CRSignPlayers { + + public CRSignJoin(SignChangeEvent event, Arena arena) { + super(event.getBlock().getLocation(), SignType.JOIN); + this.arena = arena; + + Language local = Language.getDefault(); + + event.setLine(0, ChatColor.translateAlternateColorCodes('&', local.get(Messages.PREFIX_LONG))); + event.setLine(1, ChatColor.translateAlternateColorCodes('&', local.get(Messages.KEYWORD_SIGN_JOIN))); + switch (arena.getGameState()) { + case ACTIVE: + case ENDING: + event.setLine(3, ChatColor.translateAlternateColorCodes('&', local.get(Messages.KEYWORD_GAMESTATE_ACTIVE))); + break; + case READY: + case STARTUP: + event.setLine(3, + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.get(Messages.KEYWORD_SCOREBOARD_PLAYERS))) + + " : " + String.valueOf(arena.getAmountOfPlayerInGame()) + "/" + + String.valueOf(arena.getMaxPlayer())); + break; + case UNREADY: + event.setLine(3, ChatColor.translateAlternateColorCodes('&', local.get(Messages.KEYWORD_GAMESTATE_UNSET))); + break; + } + + signs.add(this); + updateSigns(arena); + + } + + public CRSignJoin(UUID uuid, Location location) { + super(uuid, location, SignType.JOIN); + + boolean delete = false; + BlockState block = null; + try { + block = location.getBlock().getState(); + if (!(block instanceof Sign)) { + delete = true; + } else { + Sign sign = (Sign) block; + arena = Arena.getArena(sign.getLine(2)); + if (arena == null) + delete = true; + } + } catch (NullPointerException e) { + delete = true; + } + + if (delete) { + removeSign(); + return; + } + + signs.add(this); + updateSigns(arena); + } + + @Override + protected boolean updateSign(Language local, Sign sign) { + sign.setLine(0, ChatColor.translateAlternateColorCodes('&', local.get(Messages.PREFIX_LONG))); + sign.setLine(1, ChatColor.translateAlternateColorCodes('&', local.get(Messages.KEYWORD_SIGN_JOIN))); + sign.update(); + + if (arena == null) + return false; + + updateDisplay(local, sign); + return true; + } + + @Override + public void onInteract(Player player) { + if (Permissions.hasPermission(CRCommand.JOIN.getPermission(), player, true)) + CRCommand.JOIN.execute(plugin, player, new String[]{"join", arena.getName()}, true); + } + +} diff --git a/Bukkit/src/me/poutineqc/cuberunner/commands/signs/CRSignPlay.java b/Bukkit/src/me/poutineqc/cuberunner/commands/signs/CRSignPlay.java new file mode 100644 index 0000000..52b9efc --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/commands/signs/CRSignPlay.java @@ -0,0 +1,100 @@ +package me.poutineqc.cuberunner.commands.signs; + +import java.util.UUID; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.block.BlockState; +import org.bukkit.block.Sign; +import org.bukkit.entity.Player; +import org.bukkit.event.block.SignChangeEvent; + +import me.poutineqc.cuberunner.Language; +import me.poutineqc.cuberunner.Language.Messages; +import me.poutineqc.cuberunner.commands.CRCommand; +import me.poutineqc.cuberunner.game.Arena; +import me.poutineqc.cuberunner.utils.Permissions; + +public class CRSignPlay extends CRSignPlayers { + + public CRSignPlay(SignChangeEvent event, Arena arena) { + super(event.getBlock().getLocation(), SignType.PLAY); + this.arena = arena; + + Language local = Language.getDefault(); + + event.setLine(0, ChatColor.translateAlternateColorCodes('&', local.get(Messages.PREFIX_LONG))); + event.setLine(1, ChatColor.translateAlternateColorCodes('&', local.get(Messages.KEYWORD_SIGN_PLAY))); + switch (arena.getGameState()) { + case ACTIVE: + case ENDING: + event.setLine(3, ChatColor.translateAlternateColorCodes('&', local.get(Messages.KEYWORD_GAMESTATE_ACTIVE))); + break; + case READY: + case STARTUP: + event.setLine(3, + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.get(Messages.KEYWORD_SCOREBOARD_PLAYERS))) + + " : " + String.valueOf(arena.getAmountOfPlayerInGame()) + "/" + + String.valueOf(arena.getMaxPlayer())); + break; + case UNREADY: + event.setLine(3, ChatColor.translateAlternateColorCodes('&', local.get(Messages.KEYWORD_GAMESTATE_UNSET))); + break; + } + + signs.add(this); + updateSigns(arena); + + } + + public CRSignPlay(UUID uuid, Location location) { + super(uuid, location, SignType.PLAY); + + boolean delete = false; + BlockState block = null; + try { + block = location.getBlock().getState(); + if (!(block instanceof Sign)) { + delete = true; + } else { + Sign sign = (Sign) block; + arena = Arena.getArena(sign.getLine(2)); + if (arena == null) { + delete = true; + } else if (arena.getWorld() != location.getWorld()) { + delete = true; + } + } + } catch (NullPointerException e) { + delete = true; + } + + if (delete) { + removeSign(); + return; + } + + signs.add(this); + updateSigns(arena); + } + + @Override + protected boolean updateSign(Language local, Sign sign) { + sign.setLine(0, ChatColor.translateAlternateColorCodes('&', local.get(Messages.PREFIX_LONG))); + sign.setLine(1, ChatColor.translateAlternateColorCodes('&', local.get(Messages.KEYWORD_SIGN_PLAY))); + sign.update(); + + if (arena == null) + return false; + + updateDisplay(local, sign); + return true; + } + + @Override + public void onInteract(Player player) { + if (Permissions.hasPermission(CRCommand.JOIN.getPermission(), player, true)) + CRCommand.JOIN.execute(plugin, player, new String[] { "join", arena.getName() }, false); + } + +} diff --git a/Bukkit/src/me/poutineqc/cuberunner/commands/signs/CRSignPlayers.java b/Bukkit/src/me/poutineqc/cuberunner/commands/signs/CRSignPlayers.java new file mode 100644 index 0000000..b4ff40c --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/commands/signs/CRSignPlayers.java @@ -0,0 +1,44 @@ +package me.poutineqc.cuberunner.commands.signs; + +import java.util.UUID; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.block.Sign; + +import me.poutineqc.cuberunner.Language; +import me.poutineqc.cuberunner.Language.Messages; + +public abstract class CRSignPlayers extends CRSignDisplay { + + public CRSignPlayers(Location location, SignType type) { + super(location, type); + } + + public CRSignPlayers(UUID uuid, Location location, SignType type) { + super(uuid, location, type); + } + + @Override + protected void updateDisplay(Language local, Sign sign) { + switch (arena.getGameState()) { + case ACTIVE: + case ENDING: + sign.setLine(3, ChatColor.translateAlternateColorCodes('&', local.get(Messages.KEYWORD_GAMESTATE_ACTIVE))); + break; + case READY: + case STARTUP: + sign.setLine(3, + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.get(Messages.KEYWORD_SCOREBOARD_PLAYERS))) + + " : " + String.valueOf(arena.getAmountOfPlayerInGame()) + "/" + + String.valueOf(arena.getMaxPlayer())); + break; + case UNREADY: + sign.setLine(3, ChatColor.translateAlternateColorCodes('&', local.get(Messages.KEYWORD_GAMESTATE_UNSET))); + break; + } + + sign.update(); + } + +} diff --git a/Bukkit/src/me/poutineqc/cuberunner/commands/signs/CRSignQuit.java b/Bukkit/src/me/poutineqc/cuberunner/commands/signs/CRSignQuit.java new file mode 100644 index 0000000..1ab02cd --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/commands/signs/CRSignQuit.java @@ -0,0 +1,68 @@ +package me.poutineqc.cuberunner.commands.signs; + +import java.util.UUID; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.block.BlockState; +import org.bukkit.block.Sign; +import org.bukkit.entity.Player; +import org.bukkit.event.block.SignChangeEvent; + +import me.poutineqc.cuberunner.Language; +import me.poutineqc.cuberunner.Language.Messages; +import me.poutineqc.cuberunner.commands.CRCommand; +import me.poutineqc.cuberunner.utils.Permissions; + +public class CRSignQuit extends CRSign { + + public CRSignQuit(SignChangeEvent event) { + super(event.getBlock().getLocation(), SignType.QUIT); + + Language local = Language.getDefault(); + event.setLine(0, ""); + event.setLine(1, ChatColor.translateAlternateColorCodes('&', local.get(Messages.PREFIX_LONG))); + event.setLine(2, ChatColor.translateAlternateColorCodes('&', local.get(Messages.KEYWORD_SIGN_QUIT))); + event.setLine(3, ""); + + signs.add(this); + + } + + public CRSignQuit(UUID uuid, Location location) { + super(uuid, location, SignType.QUIT); + + boolean delete = false; + BlockState block = null; + try { + block = location.getBlock().getState(); + if (!(block instanceof Sign)) + delete = true; + } catch (NullPointerException e) { + delete = true; + } + + if (delete) { + removeSign(); + return; + } + + signs.add(this); + } + + @Override + protected boolean updateSign(Language local, Sign sign) { + sign.setLine(1, ChatColor.translateAlternateColorCodes('&', local.get(Messages.PREFIX_LONG))); + sign.setLine(2, ChatColor.translateAlternateColorCodes('&', local.get(Messages.KEYWORD_SIGN_QUIT))); + sign.update(); + + return true; + } + + @Override + public void onInteract(Player player) { + if (Permissions.hasPermission(CRCommand.QUIT.getPermission(), player, true)) + CRCommand.QUIT.execute(plugin, player, new String[0]); + } + +} \ No newline at end of file diff --git a/Bukkit/src/me/poutineqc/cuberunner/commands/signs/CRSignStart.java b/Bukkit/src/me/poutineqc/cuberunner/commands/signs/CRSignStart.java new file mode 100644 index 0000000..380fb68 --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/commands/signs/CRSignStart.java @@ -0,0 +1,68 @@ +package me.poutineqc.cuberunner.commands.signs; + +import java.util.UUID; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.block.BlockState; +import org.bukkit.block.Sign; +import org.bukkit.entity.Player; +import org.bukkit.event.block.SignChangeEvent; + +import me.poutineqc.cuberunner.Language; +import me.poutineqc.cuberunner.Language.Messages; +import me.poutineqc.cuberunner.commands.CRCommand; +import me.poutineqc.cuberunner.utils.Permissions; + +public class CRSignStart extends CRSign { + + public CRSignStart(SignChangeEvent event) { + super(event.getBlock().getLocation(), SignType.START); + + Language local = Language.getDefault(); + event.setLine(0, ""); + event.setLine(1, ChatColor.translateAlternateColorCodes('&', local.get(Messages.PREFIX_LONG))); + event.setLine(2, ChatColor.translateAlternateColorCodes('&', local.get(Messages.KEYWORD_SIGN_START))); + event.setLine(3, ""); + + signs.add(this); + + } + + public CRSignStart(UUID uuid, Location location) { + super(uuid, location, SignType.START); + + boolean delete = false; + BlockState block = null; + try { + block = location.getBlock().getState(); + if (!(block instanceof Sign)) + delete = true; + } catch (NullPointerException e) { + delete = true; + } + + if (delete) { + removeSign(); + return; + } + + signs.add(this); + } + + @Override + protected boolean updateSign(Language local, Sign sign) { + sign.setLine(1, ChatColor.translateAlternateColorCodes('&', local.get(Messages.PREFIX_LONG))); + sign.setLine(2, ChatColor.translateAlternateColorCodes('&', local.get(Messages.KEYWORD_SIGN_START))); + sign.update(); + + return true; + } + + @Override + public void onInteract(Player player) { + if (Permissions.hasPermission(CRCommand.START.getPermission(), player, true)) + CRCommand.START.execute(plugin, player, new String[0]); + } + +} diff --git a/Bukkit/src/me/poutineqc/cuberunner/commands/signs/CRSignStats.java b/Bukkit/src/me/poutineqc/cuberunner/commands/signs/CRSignStats.java new file mode 100644 index 0000000..5ae53f4 --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/commands/signs/CRSignStats.java @@ -0,0 +1,68 @@ +package me.poutineqc.cuberunner.commands.signs; + +import java.util.UUID; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.block.BlockState; +import org.bukkit.block.Sign; +import org.bukkit.entity.Player; +import org.bukkit.event.block.SignChangeEvent; + +import me.poutineqc.cuberunner.Language; +import me.poutineqc.cuberunner.Language.Messages; +import me.poutineqc.cuberunner.commands.CRCommand; +import me.poutineqc.cuberunner.utils.Permissions; + +public class CRSignStats extends CRSign { + + public CRSignStats(SignChangeEvent event) { + super(event.getBlock().getLocation(), SignType.STATS); + + Language local = Language.getDefault(); + event.setLine(0, ""); + event.setLine(1, ChatColor.translateAlternateColorCodes('&', local.get(Messages.PREFIX_LONG))); + event.setLine(2, ChatColor.translateAlternateColorCodes('&', local.get(Messages.KEYWORD_SIGN_STATS))); + event.setLine(3, ""); + + signs.add(this); + + } + + public CRSignStats(UUID uuid, Location location) { + super(uuid, location, SignType.STATS); + + boolean delete = false; + BlockState block = null; + try { + block = location.getBlock().getState(); + if (!(block instanceof Sign)) + delete = true; + } catch (NullPointerException e) { + delete = true; + } + + if (delete) { + removeSign(); + return; + } + + signs.add(this); + } + + @Override + protected boolean updateSign(Language local, Sign sign) { + sign.setLine(1, ChatColor.translateAlternateColorCodes('&', local.get(Messages.PREFIX_LONG))); + sign.setLine(2, ChatColor.translateAlternateColorCodes('&', local.get(Messages.KEYWORD_SIGN_STATS))); + sign.update(); + + return true; + } + + @Override + public void onInteract(Player player) { + if (Permissions.hasPermission(CRCommand.STATS.getPermission(), player, true)) + CRCommand.STATS.execute(plugin, player, new String[0]); + } + +} \ No newline at end of file diff --git a/Bukkit/src/me/poutineqc/cuberunner/commands/signs/CRSignTop.java b/Bukkit/src/me/poutineqc/cuberunner/commands/signs/CRSignTop.java new file mode 100644 index 0000000..d0e8288 --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/commands/signs/CRSignTop.java @@ -0,0 +1,85 @@ +package me.poutineqc.cuberunner.commands.signs; + +import java.util.UUID; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.block.BlockState; +import org.bukkit.block.Sign; +import org.bukkit.entity.Player; +import org.bukkit.event.block.SignChangeEvent; + +import me.poutineqc.cuberunner.CubeRunner; +import me.poutineqc.cuberunner.Language; +import me.poutineqc.cuberunner.Language.Messages; +import me.poutineqc.cuberunner.game.Arena; + +public class CRSignTop extends CRSignDisplay { + + public CRSignTop(SignChangeEvent event, Arena arena) { + super(event.getBlock().getLocation(), SignType.TOP); + this.arena = arena; + + Language local = Language.getDefault(); + event.setLine(0, ChatColor.translateAlternateColorCodes('&', local.get(Messages.PREFIX_LONG))); + event.setLine(1, ChatColor.translateAlternateColorCodes('&', local.get(Messages.KEYWORD_SIGN_TOP))); + event.setLine(3, arena.getHighestPlayer()); + + signs.add(this); + + } + + public CRSignTop(UUID uuid, Location location) { + super(uuid, location, SignType.TOP); + + boolean delete = false; + BlockState block = null; + try { + block = location.getBlock().getState(); + if (!(block instanceof Sign)) + delete = true; + else { + Sign sign = (Sign) block; + arena = Arena.getArena(sign.getLine(2)); + if (arena == null) + delete = true; + } + } catch (NullPointerException e) { + delete = true; + } + + if (delete) { + removeSign(); + return; + } + + signs.add(this); + } + + @Override + protected boolean updateSign(Language local, Sign sign) { + sign.setLine(0, ChatColor.translateAlternateColorCodes('&', local.get(Messages.PREFIX_LONG))); + sign.setLine(1, ChatColor.translateAlternateColorCodes('&', local.get(Messages.KEYWORD_SIGN_TOP))); + sign.update(); + + if (arena == null) + return false; + + updateDisplay(local, sign); + return true; + } + + @Override + protected void updateDisplay(Language local, Sign sign) { + sign.setLine(3, arena.getHighestPlayer()); + sign.update(); + } + + @Override + public void onInteract(Player player) { + Language local = CubeRunner.get().getLang(player); + local.sendMsg(player, local.get(Messages.KEYWORD_SIGN_TOP) + ChatColor.WHITE + " : " + String.valueOf(arena.getHighestPlayerScore()) + + " " + local.get(Messages.KEYWORD_GENERAL_BY) + " " + ChatColor.DARK_AQUA + arena.getHighestPlayer()); + } + +} \ No newline at end of file diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/games/Arena.java b/Bukkit/src/me/poutineqc/cuberunner/game/Arena.java similarity index 50% rename from Bukkit_1.8/src/me/poutineqc/cuberunner/games/Arena.java rename to Bukkit/src/me/poutineqc/cuberunner/game/Arena.java index b58fa8b..595a511 100644 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/games/Arena.java +++ b/Bukkit/src/me/poutineqc/cuberunner/game/Arena.java @@ -1,7 +1,9 @@ -package me.poutineqc.cuberunner.games; +package me.poutineqc.cuberunner.game; import java.sql.ResultSet; import java.sql.SQLException; +import java.text.DecimalFormat; +import java.text.NumberFormat; import java.util.ArrayList; import java.util.List; @@ -14,47 +16,38 @@ import org.bukkit.Sound; import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; -import org.bukkit.entity.FallingSand; import org.bukkit.entity.Player; +import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; +import org.bukkit.scoreboard.DisplaySlot; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Scoreboard; import org.bukkit.util.Vector; +import com.google.gson.JsonObject; import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.selections.Selection; import me.poutineqc.cuberunner.ArenaData; -import me.poutineqc.cuberunner.Configuration; +import me.poutineqc.cuberunner.CRPlayer.PlayerStatsException; +import me.poutineqc.cuberunner.CRStats; import me.poutineqc.cuberunner.CubeRunner; import me.poutineqc.cuberunner.Language; +import me.poutineqc.cuberunner.Language.Messages; import me.poutineqc.cuberunner.MySQL; -import me.poutineqc.cuberunner.Permissions; -import me.poutineqc.cuberunner.PlayerData; -import me.poutineqc.cuberunner.achievements.AchievementType; -import me.poutineqc.cuberunner.achievements.Achievements; -import me.poutineqc.cuberunner.achievements.TopManager; -import me.poutineqc.cuberunner.tools.ColorManager; -import me.poutineqc.cuberunner.tools.ItemStackManager; -import net.milkbowl.vault.economy.Economy; -import net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer; -import net.minecraft.server.v1_8_R3.PacketPlayOutTitle; -import net.minecraft.server.v1_8_R3.PacketPlayOutTitle.EnumTitleAction; -import net.minecraft.server.v1_8_R3.PlayerConnection; - -@SuppressWarnings("deprecation") +import me.poutineqc.cuberunner.commands.signs.CRSign; +import me.poutineqc.cuberunner.utils.ItemStackManager; +import me.poutineqc.cuberunner.utils.Permissions; +import me.poutineqc.cuberunner.utils.Utils; + public class Arena { private static CubeRunner plugin; - private static Configuration config; private static MySQL mysql; - private static PlayerData playerData; private static ArenaData arenaData; - private static Achievements achievements; - private static TopManager topManager; private static List arenas = new ArrayList(); - private static Economy economy; private String name; private World world; @@ -68,10 +61,12 @@ public class Arena { private int minAmountPlayer; private int maxAmountPlayer; private ColorManager colorManager; + private Objective objective; + private Scoreboard scoreboard; private List users = new ArrayList(); private GameState gameState = GameState.UNREADY; - private int originalAmountPlayer; + private boolean multiplayerGame = false; private boolean filled; /******************************************* @@ -81,12 +76,7 @@ public class Arena { public Arena(CubeRunner plugin) { Arena.plugin = plugin; Arena.mysql = plugin.getMySQL(); - Arena.config = plugin.getConfiguration(); Arena.arenaData = plugin.getArenaData(); - Arena.playerData = plugin.getPlayerData(); - Arena.achievements = plugin.getAchievements(); - Arena.topManager = plugin.getTopManager(); - Arena.economy = CubeRunner.getEconomy(); } public static void loadExistingArenas() { @@ -95,7 +85,7 @@ public static void loadExistingArenas() { if (mysql.hasConnection()) { try { - ResultSet arenas = mysql.query("SELECT * FROM " + config.tablePrefix + "ARENAS;"); + ResultSet arenas = mysql.query("SELECT * FROM " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS;"); while (arenas.next()) { String name = arenas.getString("name"); Long colorIndice = arenas.getLong("colorIndice"); @@ -169,7 +159,7 @@ public static void loadExistingArenas() { } } - public Arena(String name, World world, Location minPoint, Location maxPoint, Location lobby, Location startPoint, + private Arena(String name, World world, Location minPoint, Location maxPoint, Location lobby, Location startPoint, int minAmountPlayer, int maxAmountPlayer, int highestScore, String highestPlayer, Long colorIndice) { this.name = name; this.world = world; @@ -185,22 +175,45 @@ public Arena(String name, World world, Location minPoint, Location maxPoint, Loc setNullIfDefault(); arenas.add(this); + + resetScoreboard(); + } + + private void resetScoreboard() { + Language local = Language.getDefault(); + scoreboard = Bukkit.getScoreboardManager().getNewScoreboard(); + objective = scoreboard.registerNewObjective(name, "dummy"); + objective.setDisplaySlot(DisplaySlot.SIDEBAR); + objective.setDisplayName(ChatColor.LIGHT_PURPLE + name + ChatColor.WHITE + " : " + ChatColor.GREEN + + local.get(Messages.KEYWORD_SCOREBOARD_PLAYERS)); + objective.getScore(ChatColor.GREEN + "-------------------").setScore(1); + objective.getScore(ChatColor.GREEN + local.get(Messages.KEYWORD_INFO_BEST_SCORE) + " = " + + ChatColor.LIGHT_PURPLE + String.valueOf(highestScore)).setScore(highestScore); + objective.getScore(ChatColor.GREEN + local.get(Messages.KEYWORD_INFO_MINIMUM) + " " + + local.get(Messages.KEYWORD_SCOREBOARD_PLAYERS) + " = " + ChatColor.LIGHT_PURPLE + + String.valueOf(minAmountPlayer)).setScore(2); + objective.getScore(ChatColor.GREEN + local.get(Messages.KEYWORD_INFO_MAXIMUM) + " " + + local.get(Messages.KEYWORD_SCOREBOARD_PLAYERS) + " = " + ChatColor.LIGHT_PURPLE + + String.valueOf(maxAmountPlayer)).setScore(3); + } public Arena(String name, Player player) { this.name = name; - world = player.getWorld(); + this.world = player.getWorld(); arenas.add(this); - colorManager = new ColorManager((long) 1, plugin, this); + this.colorManager = new ColorManager((long) 1, plugin, this); this.highestPlayer = "null"; this.highestScore = 0; this.minAmountPlayer = 1; this.maxAmountPlayer = 8; + resetScoreboard(); + if (mysql.hasConnection()) { - mysql.update("INSERT INTO " + config.tablePrefix + "ARENAS (name, world) " + "VALUES ('" + name + "','" + mysql.update("INSERT INTO " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS (name, world) " + "VALUES ('" + name + "','" + world.getName() + "');"); - mysql.update("UPDATE " + config.tablePrefix + "ARENAS SET colorIndice=" + (long) 1 + " WHERE name='" + name + mysql.update("UPDATE " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS SET colorIndice=" + (long) 1 + " WHERE name='" + name + "';"); } else { arenaData.getData().set("arenas." + name + ".world", world.getName()); @@ -227,12 +240,12 @@ private void setNullIfDefault() { } public void delete(Player player) { - Language local = playerData.getLanguageOfPlayer(player); - local.sendMsg(player, local.arenaDeleted); + Language local = CubeRunner.get().getCRPlayer(player).getLanguage(); + local.sendMsg(player, local.get(Messages.EDIT_DELETE)); arenas.remove(this); if (mysql.hasConnection()) { - mysql.update("DELETE FROM " + config.tablePrefix + "ARENAS WHERE name='" + name + "';"); + mysql.update("DELETE FROM " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS WHERE name='" + name + "';"); } else { arenaData.getData().set("arenas." + name, null); arenaData.saveArenaData(); @@ -244,11 +257,11 @@ public void delete(Player player) { *********************************************/ public void setArena(Player player) { - Language local = playerData.getLanguageOfPlayer(player); + Language local = CubeRunner.get().getCRPlayer(player).getLanguage(); Selection s = getWorldEdit().getSelection(player); if (s == null) { - local.sendMsg(player, local.missingWorldEditRegion); + local.sendMsg(player, local.get(Messages.EDIT_REGION_WORLDEDIT)); return; } @@ -256,10 +269,10 @@ public void setArena(Player player) { world = s.getWorld(); minPoint = s.getMinimumPoint(); maxPoint = s.getMaximumPoint(); - local.sendMsg(player, local.arenaSetArena.replace("%arena%", name)); + local.sendMsg(player, local.get(Messages.EDIT_REGION).replace("%arena%", name)); if (mysql.hasConnection()) { - mysql.update("UPDATE " + config.tablePrefix + "ARENAS SET world=" + world.getName() + ",minPointX=" + mysql.update("UPDATE " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS SET world='" + world.getName() + "',minPointX=" + minPoint.getBlockX() + ",minPointY=" + minPoint.getBlockY() + ",minPointZ=" + minPoint.getBlockZ() + ",maxPointX=" + maxPoint.getBlockX() + ",maxPointY=" + maxPoint.getBlockY() + ",maxPointZ=" + maxPoint.getBlockZ() + " WHERE name='" + name + "';"); @@ -279,16 +292,16 @@ public void setArena(Player player) { } public void setLobby(Player player) { - Language local = playerData.getLanguageOfPlayer(player); + Language local = CubeRunner.get().getCRPlayer(player).getLanguage(); gameState = GameState.UNREADY; world = player.getWorld(); lobby = player.getLocation(); lobby.add(new Vector(0, 0.5, 0)); - local.sendMsg(player, local.arenaSetLobby.replace("%arena%", name)); + local.sendMsg(player, local.get(Messages.EDIT_LOBBY).replace("%arena%", name)); if (mysql.hasConnection()) { - mysql.update("UPDATE " + config.tablePrefix + "ARENAS SET world=" + world.getName() + ",lobbyX=" + mysql.update("UPDATE " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS SET world='" + world.getName() + "',lobbyX=" + lobby.getX() + ",lobbyY=" + lobby.getY() + ",lobbyZ=" + lobby.getZ() + ",lobbyPitch=" + lobby.getPitch() + ",lobbyYaw=" + lobby.getYaw() + " WHERE name='" + name + "';"); } else { @@ -306,16 +319,16 @@ public void setLobby(Player player) { } public void setStartPoint(Player player) { - Language local = playerData.getLanguageOfPlayer(player); + Language local = CubeRunner.get().getCRPlayer(player).getLanguage(); gameState = GameState.UNREADY; world = player.getWorld(); startPoint = player.getLocation(); startPoint.add(new Vector(0, 0.5, 0)); - local.sendMsg(player, local.arenaSetStartPoint.replace("%arena%", name)); + local.sendMsg(player, local.get(Messages.EDIT_STARTPOINT).replace("%arena%", name)); if (mysql.hasConnection()) { - mysql.update("UPDATE " + config.tablePrefix + "ARENAS SET world=" + world.getName() + ",startPointX=" + mysql.update("UPDATE " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS SET world='" + world.getName() + "',startPointX=" + startPoint.getX() + ",startPointY=" + startPoint.getY() + ",startPointZ=" + startPoint.getZ() + ",startPointPitch=" + startPoint.getPitch() + ",startPointYaw=" + startPoint.getYaw() + " WHERE name='" + name + "';"); @@ -342,51 +355,67 @@ private WorldEditPlugin getWorldEdit() { } public void setMinPlayer(int amount, Player player) { - Language local = playerData.getLanguageOfPlayer(player); + Language local = CubeRunner.get().getCRPlayer(player).getLanguage(); if (amount < 1) { local.sendMsg(player, - local.arenaAmountPlayerInvalidArgument.replace("%error%", local.arenaAmountPlayerMinEqualZero)); + local.get(Messages.EDIT_PLAYERS_ERROR).replace("%error%", local.get(Messages.EDIT_PLAYERS_ERROR))); return; } if (amount > maxAmountPlayer) { - local.sendMsg(player, - local.arenaAmountPlayerInvalidArgument.replace("%error%", local.arenaAmountPlayerMinBiggerMax)); + local.sendMsg(player, local.get(Messages.EDIT_PLAYERS_ERROR).replace("%error%", + local.get(Messages.EDIT_PLAYERS_MINIMUM_MAXIMUM))); return; } if (mysql.hasConnection()) { - mysql.update("UPDATE " + config.tablePrefix + "ARENAS SET minAmountPlayer=" + amount + " WHERE name='" + mysql.update("UPDATE " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS SET minAmountPlayer=" + amount + " WHERE name='" + name + "';"); } else { arenaData.getData().set("arenas." + name + ".minAmountPlayer", amount); arenaData.saveArenaData(); } + scoreboard.resetScores(ChatColor.GREEN + local.get(Messages.KEYWORD_INFO_MINIMUM) + " = " + + ChatColor.LIGHT_PURPLE + String.valueOf(minAmountPlayer)); minAmountPlayer = amount; - local.sendMsg(player, local.arenaAmountPlayerSuccess.replace("%arena%", name)); + objective.getScore(ChatColor.GREEN + local.get(Messages.KEYWORD_INFO_MINIMUM) + " = " + ChatColor.LIGHT_PURPLE + + String.valueOf(minAmountPlayer)).setScore(3); + + local.sendMsg(player, local.get(Messages.COMMAND_SETMINPLAYER).replace("%arena%", name)); } public void setMaxPlayer(int amount, Player player) { - Language local = playerData.getLanguageOfPlayer(player); + Language local = CubeRunner.get().getCRPlayer(player).getLanguage(); + + if (amount > 12) { + local.sendMsg(player, local.get(Messages.EDIT_PLAYERS_ERROR).replace("%error%", + local.get(Messages.EDIT_PLAYERS_MAXIMUM_10))); + return; + } if (amount < minAmountPlayer) { - local.sendMsg(player, - local.arenaAmountPlayerInvalidArgument.replace("%error%", local.arenaAmountPlayerMaxBiggerMin)); + local.sendMsg(player, local.get(Messages.EDIT_PLAYERS_ERROR).replace("%error%", + local.get(Messages.EDIT_PLAYERS_MAXIMUM_MINIMUM))); return; } if (mysql.hasConnection()) { - mysql.update("UPDATE " + config.tablePrefix + "ARENAS SET maxAmountPlayer=" + amount + " WHERE name='" + mysql.update("UPDATE " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS SET maxAmountPlayer=" + amount + " WHERE name='" + name + "';"); } else { arenaData.getData().set("arenas." + name + ".maxAmountPlayer", amount); arenaData.saveArenaData(); } + scoreboard.resetScores(ChatColor.GREEN + local.get(Messages.KEYWORD_INFO_MAXIMUM) + " = " + + ChatColor.LIGHT_PURPLE + String.valueOf(maxAmountPlayer)); maxAmountPlayer = amount; - local.sendMsg(player, local.arenaAmountPlayerSuccess.replace("%arena%", name)); + objective.getScore(ChatColor.GREEN + local.get(Messages.KEYWORD_INFO_MAXIMUM) + " = " + ChatColor.LIGHT_PURPLE + + String.valueOf(maxAmountPlayer)).setScore(3); + + local.sendMsg(player, local.get(Messages.COMMAND_SETMAXPLAYER).replace("%arena%", name)); } private boolean isReady() { @@ -398,80 +427,90 @@ private boolean isReady() { *********************************************/ public void displayInformation(Player player) { - Language local = playerData.getLanguageOfPlayer(player); + Language local = CubeRunner.get().getCRPlayer(player).getLanguage(); String stringGameState; switch (gameState) { case ACTIVE: - stringGameState = local.keyWordActive; + stringGameState = local.get(Messages.KEYWORD_GAMESTATE_ACTIVE); break; case READY: - stringGameState = local.keyWordReady; + stringGameState = local.get(Messages.KEYWORD_GAMESTATE_READY); break; case STARTUP: - stringGameState = local.keyWordStartup; + stringGameState = local.get(Messages.KEYWORD_GAMESTATE_STARTUP); break; case ENDING: case UNREADY: default: - stringGameState = local.keyWordUnset; + stringGameState = local.get(Messages.KEYWORD_GAMESTATE_UNSET); } player.sendMessage( ChatColor.translateAlternateColorCodes('&', "&8&m" + StringUtils.repeat(" ", 13) + "&r &5CubeRunner &d" - + local.keyWordInformation + " &5: &d" + name + " &8&m" + StringUtils.repeat(" ", 13))); - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5" + local.keyWordCurrent + " " + local.keyWordGameState + ": &7" + stringGameState)); - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5" + local.keyWordCurrent + " " + local.keyWordAmountPlayer + ": &7" + users.size())); - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5" + local.keyWordMinimum + " " + local.keyWordAmountPlayer + ": &7" + minAmountPlayer)); - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5" + local.keyWordMaximum + " " + local.keyWordAmountPlayer + ": &7" + maxAmountPlayer)); - player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&5" + local.keyWordBestScore + ": &7" - + highestScore + " &5" + local.keyWordBy + " &7" + highestPlayer)); + + local.get(Messages.KEYWORD_INFO) + " &5: &d" + name + " &8&m" + StringUtils.repeat(" ", 13))); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&5" + local.get(Messages.KEYWORD_INFO_CURRENT) + + " " + local.get(Messages.KEYWORD_INFO_GAME_STATE) + ": &7" + stringGameState)); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&5" + local.get(Messages.KEYWORD_INFO_CURRENT) + + " " + local.get(Messages.KEYWORD_INFO_AMOUNT_OF_PLAYER) + ": &7" + users.size())); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&5" + local.get(Messages.KEYWORD_INFO_MINIMUM) + + " " + local.get(Messages.KEYWORD_INFO_AMOUNT_OF_PLAYER) + ": &7" + minAmountPlayer)); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&5" + local.get(Messages.KEYWORD_INFO_MAXIMUM) + + " " + local.get(Messages.KEYWORD_INFO_AMOUNT_OF_PLAYER) + ": &7" + maxAmountPlayer)); + player.sendMessage( + ChatColor.translateAlternateColorCodes('&', "&5" + local.get(Messages.KEYWORD_INFO_BEST_SCORE) + ": &7" + + highestScore + " &5" + local.get(Messages.KEYWORD_GENERAL_BY) + " &7" + highestPlayer)); player.sendMessage("\n"); if (!Permissions.hasPermission(Permissions.advancedInfo, player, false)) return; player.sendMessage( - ChatColor.translateAlternateColorCodes('&', "&8&m" + StringUtils.repeat(" ", 5) + "&r &5CubeRunner &d" - + local.keyWordAdvanced + " &5: &d" + name + " &8&m" + StringUtils.repeat(" ", 5))); - player.sendMessage( - ChatColor.translateAlternateColorCodes('&', "&5" + local.keyWordWorld + ": &7" + world.getName())); + ChatColor.translateAlternateColorCodes('&', + "&8&m" + StringUtils.repeat(" ", 5) + "&r &5CubeRunner &d" + + local.get(Messages.KEYWORD_INFO_ADVANCED) + " &5: &d" + name + " &8&m" + + StringUtils.repeat(" ", 5))); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', + "&5" + local.get(Messages.KEYWORD_INFO_WORLD) + ": &7" + world.getName())); if (lobby == null) { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&5" + local.keyWordLobby + ": &7null")); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', + "&5" + local.get(Messages.KEYWORD_INFO_LOBBY) + ": &7null")); } else { player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5" + local.keyWordLobby + ": &7{" + ((int) (lobby.getX() * 100)) / (double) 100 + ", " + "&5" + local.get(Messages.KEYWORD_INFO_LOBBY) + ": &7{" + + ((int) (lobby.getX() * 100)) / (double) 100 + ", " + ((int) (lobby.getY() * 100)) / (double) 100 + ", " + ((int) (lobby.getZ() * 100)) / (double) 100 + "}")); } if (startPoint == null) { - player.sendMessage( - ChatColor.translateAlternateColorCodes('&', "&5" + local.keyWordStartPoint + ": &7null")); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', + "&5" + local.get(Messages.KEYWORD_INFO_START_POINT) + ": &7null")); } else { player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5" + local.keyWordStartPoint + ": &7{" + ((int) (startPoint.getX() * 100)) / (double) 100 + ", " + "&5" + local.get(Messages.KEYWORD_INFO_START_POINT) + ": &7{" + + ((int) (startPoint.getX() * 100)) / (double) 100 + ", " + ((int) (startPoint.getY() * 100)) / (double) 100 + ", " + ((int) (startPoint.getZ() * 100)) / (double) 100 + "}")); } if (minPoint == null) { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5" + local.keyWordMinimum + local.keyWordZone + ": &7null")); + player.sendMessage( + ChatColor.translateAlternateColorCodes('&', "&5" + local.get(Messages.KEYWORD_INFO_MINIMUM) + + local.get(Messages.KEYWORD_INFO_ZONE_COORDINATE) + ": &7null")); } else { player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5" + local.keyWordMinimum + local.keyWordZone + ": &7{" + minPoint.getBlockX() + ", " - + minPoint.getBlockY() + ", " + minPoint.getBlockZ() + "}")); + "&5" + local.get(Messages.KEYWORD_INFO_MINIMUM) + local.get(Messages.KEYWORD_INFO_ZONE_COORDINATE) + + ": &7{" + minPoint.getBlockX() + ", " + minPoint.getBlockY() + ", " + minPoint.getBlockZ() + + "}")); } if (maxPoint == null) { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5" + local.keyWordMaximum + local.keyWordZone + ": &7null")); + player.sendMessage( + ChatColor.translateAlternateColorCodes('&', "&5" + local.get(Messages.KEYWORD_INFO_MAXIMUM) + + local.get(Messages.KEYWORD_INFO_ZONE_COORDINATE) + ": &7null")); } else { player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5" + local.keyWordMaximum + local.keyWordZone + ": &7{" + maxPoint.getBlockX() + ", " - + maxPoint.getBlockY() + ", " + maxPoint.getBlockZ() + "}")); + "&5" + local.get(Messages.KEYWORD_INFO_MAXIMUM) + local.get(Messages.KEYWORD_INFO_ZONE_COORDINATE) + + ": &7{" + maxPoint.getBlockX() + ", " + maxPoint.getBlockY() + ", " + maxPoint.getBlockZ() + + "}")); } player.sendMessage("\n"); } @@ -481,104 +520,118 @@ public void displayInformation(Player player) { *********************************************/ public void addPlayer(Player player, boolean teleport) { - Language local = playerData.getLanguageOfPlayer(player); - playerData.addOnFileIfNotExist(player); + Language local = CubeRunner.get().getCRPlayer(player).getLanguage(); if (getArenaFromPlayer(player) != null) { - local.sendMsg(player, local.playerAlreadyInGame); + local.sendMsg(player, local.get(Messages.ERROR_ALREADY_IN_GAME)); return; } if (gameState == GameState.UNREADY || gameState == GameState.ENDING) { - local.sendMsg(player, local.playerJoinUnready); + local.sendMsg(player, local.get(Messages.JOIN_UNREADY)); return; } - User user = addUser(player, gameState == GameState.ACTIVE); + player.setScoreboard(scoreboard); - if (teleport) { - player.teleport(lobby); - user.maxStats(); + User user = null; + if (teleport || gameState != GameState.ACTIVE) { + user = new User(CubeRunner.get().getConfiguration(), CubeRunner.get().getCRPlayer(player), this, gameState == GameState.ACTIVE, + teleport); + users.add(user); + CRSign.updateSigns(this); } if (gameState == GameState.ACTIVE) { - local.sendMsg(player, local.playerJoinActive); + local.sendMsg(player, local.get(Messages.JOIN_ACTIVE)); - if (teleport) - local.sendMsg(player, local.playerJoinSpectator); + if (user != null) + local.sendMsg(player, local.get(Messages.JOIN_SPECTATOR)); return; + } else { + objective.getScore(user.getName()).setScore(0); } - if (gameState == GameState.STARTUP) { + if (gameState == GameState.STARTUP) player.teleport(startPoint); - user.maxStats(); - } - local.sendMsg(player, local.playerJoinSuccess.replace("%arena%", name)); + local.sendMsg(player, local.get(Messages.JOIN_PLAYER).replace("%arena%", name)); for (User u : users) { - Player p = u.getPlayer(); - if (p == player) - return; + if (u == user) + continue; - Language localAlt = playerData.getLanguageOfPlayer(p); - localAlt.sendMsg(p, localAlt.playerJoinOthers.replace("%player%", player.getDisplayName())); + Language localAlt = u.getCRPlayer().getLanguage(); + localAlt.sendMsg(u, localAlt.get(Messages.JOIN_OTHERS).replace("%player%", player.getDisplayName())); } - } - private User addUser(Player player, boolean eliminated) { - User user = new User(config, player, gameState == GameState.ACTIVE); - users.add(user); - user.maxStats(); - user.setEliminated(eliminated); - return user; + if (gameState == GameState.READY && CubeRunner.get().getConfiguration().autostart && getAmountOfPlayerInGame() >= minAmountPlayer) + initiateGame(null); } - public void removePlayer(Player player, boolean disconnect) { - Language local = playerData.getLanguageOfPlayer(player); + public void removePlayer(Player player, LeavingReason reason) { + Language local = CubeRunner.get().getCRPlayer(player).getLanguage(); User user = getUser(player); + if (user == null) + return; - user.quit(); + if (!user.isEliminated()) { + local.sendMsg(user, local.get(Messages.QUIT_PLAYER).replace("%arena%", name)); + for (User u : users) { + if (u == user) + continue; - local.sendMsg(player, local.playerQuitSuccess.replace("%arena%", name)); - for (User u : users) { - Player p = u.getPlayer(); - if (p == player) - continue; + Language l = u.getCRPlayer().getLanguage(); + l.sendMsg(u, l.get(Messages.QUIT_OTHERS).replace("%player%", user.getDisplayName())); + } + + if (gameState == GameState.ACTIVE) + eliminateUser(user, reason); + } - Language l = playerData.getLanguageOfPlayer(p); - l.sendMsg(p, l.playerQuitOthers.replace("%player%", player.getDisplayName())); + if (gameState == GameState.STARTUP) { + user.getPlayer().teleport(lobby); } - if (getGameState() == GameState.ACTIVE) - eliminateUser(user, disconnect); + if (gameState == GameState.STARTUP || gameState == GameState.READY) + objective.getScoreboard().resetScores(user.getName()); - if (getGameState() == GameState.STARTUP) - player.teleport(lobby); + user.ireturnStats(); + users.remove(user); + CRSign.updateSigns(this); - user.returnStats(); - removeUser(player); + if (gameState == GameState.STARTUP) + if (getAmountOfPlayerInGame() < minAmountPlayer) { + gameState = GameState.READY; + for (User u : users) + u.getPlayer().teleport(lobby); + } } public void initiateGame(Player player) { - Language local = playerData.getLanguageOfPlayer(player); + Language local = player == null ? null : CubeRunner.get().getCRPlayer(player).getLanguage(); if (users.size() < minAmountPlayer) { - local.sendMsg(player, local.gameStartLessMin.replace("%amount%", String.valueOf(minAmountPlayer))); + if (local != null) + local.sendMsg(player, + local.get(Messages.START_MINIMUM).replace("%amount%", String.valueOf(minAmountPlayer))); + return; } if (users.size() > maxAmountPlayer) { - local.sendMsg(player, local.gameStartLessMax.replace("%amount%", String.valueOf(maxAmountPlayer))); + if (local != null) + local.sendMsg(player, + local.get(Messages.START_MAXIMUM).replace("%amount%", String.valueOf(maxAmountPlayer))); + return; } - if (users.size() < maxAmountPlayer) + if (CubeRunner.get().getConfiguration().broadcastStartup) for (Player p : Bukkit.getServer().getOnlinePlayers()) { - Language localTemp = playerData.getLanguageOfPlayer(p); - p.sendMessage(ChatColor.translateAlternateColorCodes('&', - localTemp.prefixShort + localTemp.gameCountdownStarted.replace("%arena%", name))); + Language localTemp = CubeRunner.get().getLang(p); + localTemp.sendMsg(p, localTemp.get(Messages.START_BROADCAST).replace("%arena%", name)); } resetArena(); @@ -586,10 +639,10 @@ public void initiateGame(Player player) { for (User user : users) { user.getPlayer().teleport(startPoint); - user.maxStats(); + user.imaxStats(); } - countdown(this, config.countdownTime * 20); + countdown(this, CubeRunner.get().getConfiguration().countdownTime * 20); } private void countdown(final Arena arena, final int cooldownTimer) { @@ -618,24 +671,25 @@ public void run() { case 1: for (User user : arena.users) { if (cooldownTimer % 20.0 == 0) { - user.getPlayer().playSound(user.getPlayer().getLocation(), Sound.CLICK, 1, 1); - Language local = playerData.getLanguageOfPlayer(user.getPlayer()); + Sound sound = CubeRunner.oneNine ? Sound.valueOf("UI_BUTTON_CLICK") + : Sound.valueOf("CLICK"); - PacketPlayOutTitle countNumberTitle = new PacketPlayOutTitle(EnumTitleAction.TITLE, - ChatSerializer.a("{\"text\":\"" + cooldownTimer / 20 - + "\",\"color\":\"gold\",\"bold\":true}"), - 1, 20, 5); - PacketPlayOutTitle countNumberSubtitle = new PacketPlayOutTitle( - EnumTitleAction.SUBTITLE, ChatSerializer.a("{\"text\":\"" + local.keyWordSeconds - + "\",\"color\":\"dark_gray\",\"italic\":true}"), - 1, 20, 5); + user.getPlayer().playSound(user.getPlayer().getLocation(), sound, 1, 1); - PlayerConnection connection = ((CraftPlayer) user.getPlayer()) - .getHandle().playerConnection; - connection.sendPacket(countNumberTitle); - connection.sendPacket(countNumberSubtitle); + Language local = CubeRunner.get().getCRPlayer(user.getPlayer()).getLanguage(); + JsonObject title = new JsonObject(); + title.addProperty("text", String.valueOf((int) cooldownTimer / 20)); + title.addProperty("bold", true); + title.addProperty("color", "gold"); + + JsonObject subtitle = new JsonObject(); + subtitle.addProperty("text", local.get(Messages.KEYWORD_GENERAL_SECONDS)); + subtitle.addProperty("italic", true); + subtitle.addProperty("color", "gray"); + + Utils.sendTitle(user.getPlayer(), title.toString(), subtitle.toString(), 5, 10, 5); } } break; @@ -654,8 +708,8 @@ public void run() { Player p = user.getPlayer(); p.setLevel(0); p.setExp(0); - Language local = playerData.getLanguageOfPlayer(p); - local.sendMsg(user.getPlayer(), local.gameCountdownStopped); + Language local = user.getCRPlayer().getLanguage(); + local.sendMsg(user.getPlayer(), local.get(Messages.START_STOP)); } } } @@ -664,8 +718,23 @@ public void run() { } protected void startGame() { + Language local = Language.getDefault(); gameState = GameState.ACTIVE; - originalAmountPlayer = getAmountInGame(this); + CRSign.updateSigns(this); + multiplayerGame = getAmountOfPlayerInGame() > 1; + + objective.setDisplayName(ChatColor.AQUA + name + ChatColor.WHITE + " : " + ChatColor.GREEN + + local.get(Messages.KEYWORD_SCOREBOARD_SCORE)); + objective.getScoreboard().resetScores(ChatColor.GREEN + "-------------------"); + objective.getScoreboard() + .resetScores(ChatColor.GREEN + local.get(Messages.KEYWORD_INFO_MINIMUM) + " " + + local.get(Messages.KEYWORD_SCOREBOARD_PLAYERS) + " = " + ChatColor.LIGHT_PURPLE + + String.valueOf(minAmountPlayer)); + objective.getScoreboard() + .resetScores(ChatColor.GREEN + local.get(Messages.KEYWORD_INFO_MAXIMUM) + " " + + local.get(Messages.KEYWORD_SCOREBOARD_PLAYERS) + " = " + ChatColor.LIGHT_PURPLE + + String.valueOf(maxAmountPlayer)); + blockShower(1, this); for (User user : users) { @@ -678,6 +747,7 @@ protected void startGame() { } + @SuppressWarnings("deprecation") private void resetArena() { for (int x = minPoint.getBlockX(); x <= maxPoint.getBlockX(); x++) for (int y = maxPoint.getBlockY(); y >= minPoint.getBlockY(); y--) @@ -697,6 +767,7 @@ private void resetArena() { } } + @SuppressWarnings("deprecation") public void resetArena(ItemStack item) { for (int x = minPoint.getBlockX(); x <= maxPoint.getBlockX(); x++) for (int y = maxPoint.getBlockY(); y >= minPoint.getBlockY(); y--) @@ -719,7 +790,7 @@ private static void blockShower(final long number, final Arena arena) { Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { public void run() { - if (getAmountInGame(arena) == 0) + if (arena.getAmountOfPlayerInGame() == 0) return; if (!arena.filled) @@ -727,70 +798,108 @@ public void run() { arena.filled = true; for (User u : arena.users) if (!u.isEliminated()) - achievements.checkAchievement(AchievementType.FILL_THE_ARENA, u.getPlayer()); + try { + u.getCRPlayer().doneChallenge(CRStats.FILL_THE_ARENA); + } catch (PlayerStatsException e) { + e.printStackTrace(); + } } if (number == 6000) for (User u : arena.users) if (!u.isEliminated()) - achievements.checkAchievement(AchievementType.SURVIVE_5_MINUTES, u.getPlayer()); + try { + u.getCRPlayer().doneChallenge(CRStats.SURVIVE_5_MINUTES); + } catch (PlayerStatsException e) { + e.printStackTrace(); + } for (User user : arena.users) { - if (user.isEliminated()) continue; + + if (user.getLastTreeSecondsDistance() < 1 && user.getScore() >= 2) + arena.eliminateUser(user, LeavingReason.HIDING); Player player = user.getPlayer(); Location l; if (arena.maxPoint.getBlockY() > player.getLocation().getBlockY() + 10) - l = new Location(player.getWorld(), player.getLocation().getBlockX(), - player.getLocation().getBlockY() + 10, player.getLocation().getBlockZ()); + l = new Location(player.getWorld(), player.getLocation().getX(), + player.getLocation().getY() + 10, player.getLocation().getZ()); else - l = new Location(player.getWorld(), player.getLocation().getBlockX(), - arena.maxPoint.getBlockY(), player.getLocation().getBlockZ()); + l = new Location(player.getWorld(), player.getLocation().getX(), arena.maxPoint.getY(), + player.getLocation().getZ()); + + NumberFormat formater = new DecimalFormat("#.#####"); + double xOffset = Double + .parseDouble(formater.format(l.getX() > 0 ? l.getX() % 1 : 1 + (l.getX() % 1))); + double zOffset = Double + .parseDouble(formater.format(l.getZ() > 0 ? l.getZ() % 1 : 1 + (l.getZ() % 1))); + + if (xOffset <= 0.7 && xOffset >= 0.3) + l.setX(Math.floor(l.getX()) + 0.5D); + + if (zOffset <= 0.7 && zOffset >= 0.3) + l.setZ(Math.floor(l.getZ()) + 0.5D); player.setSaturation(20); if (number % 20 == 0) { player.setLevel((int) number / 20); + player.setSaturation(20); user.addToScore(); + arena.objective.getScore(user.getName()).setScore(user.getScore()); - int totalScore = 0; - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT totalScore FROM " + config.tablePrefix - + "PLAYERS WHERE UUID='" + user.getUUID() + "';"); - try { - if (query.next()) - totalScore = query.getInt("totalScore"); - } catch (SQLException e) { - e.printStackTrace(); - } - - mysql.update("UPDATE " + config.tablePrefix + "PLAYERS SET totalScore='" + ++totalScore - + "' WHERE UUID='" + user.getUUID() + "';"); - } else { - totalScore = playerData.getData().getInt("players." + user.getUUID() + ".totalScore", 0); - playerData.getData().set("players." + user.getUUID() + ".totalScore", ++totalScore); - playerData.savePlayerData(); + try { + user.getCRPlayer().increment(CRStats.TOTAL_SCORE, false); + } catch (PlayerStatsException e) { + e.printStackTrace(); } - - achievements.checkAchievement(AchievementType.TOTAL_SCORE, player); } - ItemStackManager fallingBlock = arena.colorManager.getRandomAvailableBlock(); - - FallingSand clay = (FallingSand) player.getWorld().spawnFallingBlock(l, fallingBlock.getMaterial(), - (byte) fallingBlock.getData()); - - clay.setDropItem(false); - clay.setHurtEntities(true); - clay.setCustomName(user.getUUID()); - clay.setCustomNameVisible(false); - - if (number % 2 == 0) { - clay.setVelocity( - new Vector((1 - (Math.random() * 2)) / 10.0, 0, (1 - (Math.random() * 2)) / 10.0)); + ItemStackManager itemStack = arena.colorManager.getRandomAvailableBlock(); + + try { + + Object craftWorld = Class + .forName("org.bukkit.craftbukkit." + CubeRunner.NMS_VERSION + ".CraftWorld") + .cast(player.getWorld()); + Object world = craftWorld.getClass().getMethod("getHandle").invoke(craftWorld); + + @SuppressWarnings("deprecation") + Object entityBlock = Utils.getNMSClass("Block").getMethod("getById", int.class).invoke(null, + itemStack.getMaterial().getId()); + Object iBlockData = entityBlock.getClass().getMethod("fromLegacyData", int.class) + .invoke(entityBlock, (int) itemStack.getDurability()); + Object entityFallingBlock = Utils.getNMSClass("EntityFallingBlock") + .getConstructor(Utils.getNMSClass("World"), double.class, double.class, double.class, + Utils.getNMSClass("IBlockData")) + .newInstance(world, l.getX(), l.getY(), l.getZ(), iBlockData); + + entityFallingBlock.getClass().getField("ticksLived").set(entityFallingBlock, (int) 1); + entityFallingBlock.getClass().getSuperclass().getMethod("setCustomName", String.class) + .invoke(entityFallingBlock, user.getUUID().toString()); + entityFallingBlock.getClass().getSuperclass().getMethod("setCustomNameVisible", boolean.class) + .invoke(entityFallingBlock, false); + + entityFallingBlock.getClass().getMethod("a", boolean.class).invoke(entityFallingBlock, true); + entityFallingBlock.getClass().getField("dropItem").set(entityFallingBlock, false); + + world.getClass().getMethod("addEntity", Utils.getNMSClass("Entity"), SpawnReason.class) + .invoke(world, entityFallingBlock, SpawnReason.CUSTOM); + + if (number % 2 == 0) { + entityFallingBlock.getClass().getSuperclass().getField("motX").set(entityFallingBlock, + (1 - (Math.random() * 2)) / 10.0); + entityFallingBlock.getClass().getSuperclass().getField("motY").set(entityFallingBlock, 0); + entityFallingBlock.getClass().getSuperclass().getField("motZ").set(entityFallingBlock, + (1 - (Math.random() * 2)) / 10.0); + entityFallingBlock.getClass().getSuperclass().getField("velocityChanged") + .set(entityFallingBlock, true); + } + } catch (Exception e) { + e.printStackTrace(); } } @@ -809,121 +918,150 @@ private boolean isArenaFull() { return true; } - protected void eliminateUser(User user, boolean disconnection) { + public void eliminateUser(User user, LeavingReason reason) { user.getPlayer().teleport(lobby); user.setEliminated(true); - if (!disconnection) { - Language local = playerData.getLanguageOfPlayer(user.getPlayer()); - local.sendMsg(user, local.gameCrushedPlayer.replace("%score%", String.valueOf(user.getScore()))); + if (reason == LeavingReason.CRUSHED) { + Language local = user.getCRPlayer().getLanguage(); + local.sendMsg(user, + local.get(Messages.END_CRUSH_PLAYER).replace("%score%", String.valueOf(user.getScore()))); for (User u : users) { if (u == user) continue; - Language l = playerData.getLanguageOfPlayer(u.getPlayer()); - l.sendMsg(u, l.gameCrushedOthers.replace("%player%", user.getDisplayName()).replace("%score%", - String.valueOf(user.getScore()))); + Language l = u.getCRPlayer().getLanguage(); + l.sendMsg(u, l.get(Messages.END_CRUSH_OTHERS).replace("%player%", user.getDisplayName()) + .replace("%score%", String.valueOf(user.getScore()))); } } - int games = 0; - int timePlayed = 0; - double totalDistance = 0; - int totalScore = 0; - double money = 0; - - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT games, timePlayed, totalDistance, totalScore, money FROM " - + config.tablePrefix + "PLAYERS WHERE UUID='" + user.getUUID() + "';"); + if (reason == LeavingReason.HIDING) { + Language local = user.getCRPlayer().getLanguage(); + local.sendMsg(user, local.get(Messages.END_HIDE_PLAYER)); + for (User u : users) { + if (u == user) + continue; - try { - if (query.next()) { - games = query.getInt("games"); - timePlayed = query.getInt("timePlayed"); - totalDistance = query.getDouble("totalDistance"); - totalScore = query.getInt("totalScore"); - money = query.getDouble("money"); - } - } catch (SQLException e) { - e.printStackTrace(); + Language l = u.getCRPlayer().getLanguage(); + l.sendMsg(u, l.get(Messages.END_HIDE_OTHERS).replace("%player%", user.getDisplayName())); } - } else { - games = playerData.getData().getInt("players." + user.getUUID() + ".games", 0); - timePlayed = playerData.getData().getInt("players." + user.getUUID() + ".timePlayed", 0); - totalDistance = playerData.getData().getDouble("players." + user.getUUID() + ".totalDistance", 0); - totalScore = playerData.getData().getInt("players." + user.getUUID() + ".totalScore", 0); - money = playerData.getData().getDouble("players." + user.getUUID() + ".money", 0); } - games++; - timePlayed += user.getGameLenght(); - totalDistance += user.getDistanceRan(); - double ratio = (double) totalScore / games; + try { + user.getCRPlayer().increment(CRStats.GAMES_PLAYED, true); + user.getCRPlayer().addInt(CRStats.TIME_PLAYED, user.getGameLenght()); + user.getCRPlayer().addDouble(CRStats.TOTAL_DISTANCE, user.getDistanceRan()); + user.getCRPlayer().saveIncrementor(CRStats.TOTAL_SCORE); + } catch (PlayerStatsException e) { + e.printStackTrace(); + } + user.getCRPlayer().updateAverageScorePerGame(); - if (CubeRunner.isEconomyEnabled()) { + if (CubeRunner.get().isEconomyEnabled()) { Player player = user.getPlayer(); - double amount = (config.pricePerScore * user.getScore()); - economy.depositPlayer(player, amount); - Language l = playerData.getLanguageOfPlayer(player); + double amount = (CubeRunner.get().getConfiguration().pricePerScore * user.getScore()); + CubeRunner.get().getEconomy().depositPlayer(player, amount); + try { + user.getCRPlayer().addDouble(CRStats.MONEY, amount); + } catch (PlayerStatsException e) { + e.printStackTrace(); + } + + Language l = user.getCRPlayer().getLanguage(); l.sendMsg(player, - l.achievementMoneyGame.replace("%amount2%", String.valueOf(user.getScore())) + l.get(Messages.END_REWARD).replace("%amount2%", String.valueOf(user.getScore())) .replace("%amount%", String.valueOf((int) (amount * 100) / 100.0)) - .replace("%currency%", economy.currencyNamePlural())); - money += amount; + .replace("%currency%", CubeRunner.get().getEconomy().currencyNamePlural())); } - if (mysql.hasConnection()) { - mysql.update("UPDATE " + config.tablePrefix + "PLAYERS SET money='" + money + "', timePlayed='" + timePlayed - + "', games='" + games + "', totalDistance='" + totalDistance + "', averageDistancePerGame='" - + ratio + "' WHERE UUID='" + user.getUUID() + "';"); - } else { - playerData.getData().set("players." + user.getUUID() + ".timePlayed", timePlayed); - playerData.getData().set("players." + user.getUUID() + ".games", games); - playerData.getData().set("players." + user.getUUID() + ".totalDistance", totalDistance); - playerData.getData().set("players." + user.getUUID() + ".averageDistancePerGame", ratio); - playerData.getData().set("players." + user.getUUID() + ".money", money); - playerData.savePlayerData(); - } - - achievements.checkAchievement(AchievementType.AMOUNT_GAMES, user.getPlayer()); - if (user.getScore() == 42) - achievements.checkAchievement(AchievementType.DIE_SECONDS_42, user.getPlayer()); + try { + user.getCRPlayer().doneChallenge(CRStats.THE_ANSWER_TO_LIFE); + } catch (PlayerStatsException e) { + e.printStackTrace(); + } - if (getAmountInGame(this) == 0) + if (getAmountOfPlayerInGame() == 0) endingSequence(); - if (!mysql.hasConnection()) - topManager.updateAll(); + commandReward(user, getAmountOfPlayerInGame() == 0); + + try { + CubeRunner.get().getPlayerData().updateAll(user.getCRPlayer()); + } catch (PlayerStatsException e) { + e.printStackTrace(); + } + } + + private void commandReward(User user, boolean lastPlayer) { + for (String command : CubeRunner.get().getConfiguration().playerCommands) + if (command.contains("%all%")) + for (User u : users) + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), + command.replace("%all%", u.getName()).replace("%player%", user.getName()) + .replace("%arena%", name) + .replace("%prefix%", u.getCRPlayer().getLanguage().get(Messages.PREFIX_SHORT))); + else + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), + command.replace("%player%", user.getName()).replace("%arena%", name).replace("%prefix%", + user.getCRPlayer().getLanguage().get(Messages.PREFIX_SHORT))); + + if (lastPlayer) { + if (multiplayerGame) + for (String command : CubeRunner.get().getConfiguration().winnerCommands) + if (command.contains("%all%")) + for (User u : users) + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), + command.replace("%all%", u.getName()).replace("%winner%", user.getName()) + .replace("%arena%", name).replace("%prefix%", + u.getCRPlayer().getLanguage().get(Messages.PREFIX_SHORT))); + else + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), + command.replace("%winner%", user.getName()).replace("%arena%", name).replace("%prefix%", + user.getCRPlayer().getLanguage().get(Messages.PREFIX_SHORT))); + + for (String command : CubeRunner.get().getConfiguration().endingCommands) + if (command.contains("%all%")) + for (User u : users) + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), + command.replace("%all%", u.getName()).replace("%arena%", name).replace("%prefix%", + u.getCRPlayer().getLanguage().get(Messages.PREFIX_SHORT))); + else + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.replace("%arena%", name) + .replace("%prefix%", user.getCRPlayer().getLanguage().get(Messages.PREFIX_SHORT))); + + if (multiplayerGame) { + if (CubeRunner.get().getConfiguration().broadcastEndingMulti) + for (Player player : Bukkit.getOnlinePlayers()) { + Language local = CubeRunner.get().getLang(player); + local.sendMsg(player, + local.get(Messages.END_BROADCAST_MULTIPLAYER).replace("%player%", user.getDisplayName()) + .replace("%arena%", name).replace("%score%", String.valueOf(user.getScore()))); + } + } else if (CubeRunner.get().getConfiguration().broadcastEndingSingle) + for (Player player : Bukkit.getOnlinePlayers()) { + Language local = CubeRunner.get().getLang(player); + local.sendMsg(player, + local.get(Messages.END_BROADCAST_SINGLEPLAYER).replace("%player%", user.getDisplayName()) + .replace("%arena%", name).replace("%score%", String.valueOf(user.getScore()))); + } + } } private void endingSequence() { gameState = GameState.ENDING; + CRSign.updateSigns(this); User user = getHighestScore(); - if (originalAmountPlayer > 1) { - int multiWins = 0; - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT multiplayerWon FROM " + config.tablePrefix - + "PLAYERS WHERE UUID='" + user.getUUID() + "';"); - try { - if (query.next()) - multiWins = query.getInt("multiplayerWon"); - - mysql.update("UPDATE " + config.tablePrefix + "PLAYERS SET multiplayerWon='" + ++multiWins - + "' WHERE UUID='" + user.getUUID() + "';"); - } catch (SQLException e) { - e.printStackTrace(); - } - } else { - multiWins = playerData.getData().getInt("players." + user.getUUID() + ".multiplayerWon", 0); - playerData.getData().set("players." + user.getUUID() + ".multiplayerWon", ++multiWins); - playerData.savePlayerData(); + if (multiplayerGame) { + try { + user.getCRPlayer().increment(CRStats.MULTIPLAYER_WON, true); + } catch (PlayerStatsException e) { + e.printStackTrace(); } - - achievements.checkAchievement(AchievementType.MULTIPLAYER_GAMES_WON, user.getPlayer()); } if (user.getScore() > highestScore) { @@ -931,13 +1069,13 @@ private void endingSequence() { highestPlayer = user.getPlayer().getName(); for (Player player : Bukkit.getServer().getOnlinePlayers()) { - Language local = playerData.getLanguageOfPlayer(player); - local.sendMsg(player, local.endingBest.replace("%player%", user.getDisplayName()) + Language local = CubeRunner.get().getCRPlayer(player).getLanguage(); + local.sendMsg(player, local.get(Messages.END_BEST).replace("%player%", user.getDisplayName()) .replace("%score%", String.valueOf(user.getScore())).replace("%arena%", name)); } if (mysql.hasConnection()) { - mysql.update("UPDATE " + config.tablePrefix + "ARENAS SET highestScore='" + user.getScore() + mysql.update("UPDATE " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS SET highestScore='" + user.getScore() + "', highestPlayer='" + user.getPlayer().getName() + "' WHERE name='" + name + "';"); } else { arenaData.getData().set("arenas." + name + ".highestScore.score", highestScore); @@ -946,10 +1084,12 @@ private void endingSequence() { } } - if (config.teleportAfterEnding) { + resetScoreboard(); + + if (CubeRunner.get().getConfiguration().teleportAfterEnding) { for (User u : users) { - Language local = playerData.getLanguageOfPlayer(u.getPlayer()); - local.sendMsg(u, local.endingTeleport); + Language local = u.getCRPlayer().getLanguage(); + local.sendMsg(u, local.get(Messages.END_TELEPORT)); } Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @@ -959,10 +1099,9 @@ public void run() { }, 100L); } else kickUsers(true); - } - private User getHighestScore() { + public User getHighestScore() { User user = new User(0); for (User u : users) if (user.getScore() <= u.getScore()) @@ -970,49 +1109,21 @@ private User getHighestScore() { return user; } - private static int getAmountInGame(Arena arena) { - int i = 0; - for (User user : arena.users) - if (!user.isEliminated()) - i++; - - return i; - } - private void kickUsers(boolean wait) { for (User user : users) { - user.quit(); - user.returnStats(); + user.allowTeleport(); + user.ireturnStats(); } users.clear(); + final Arena a = this; Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { public void run() { gameState = GameState.READY; + CRSign.updateSigns(a); } - }, wait ? 5L : 0L); - } - - public void removeUser(Player player) { - for (User user : users) { - if (user.getUUID().equalsIgnoreCase(player.getUniqueId().toString())) { - users.remove(user); - - if (getGameState() == GameState.STARTUP) - checkIfStillActive(); - - return; - } - } - } - - private void checkIfStillActive() { - if (getAmountInGame(this) < minAmountPlayer) { - gameState = GameState.READY; - for (User user : users) - user.getPlayer().teleport(lobby); - } + }, wait ? 20L : 0L); } public boolean isInsideArena(Location location) { @@ -1035,7 +1146,7 @@ public boolean isInsideArena(Location location) { return true; } - public boolean isOutsideArena(Location location) { + private boolean isOutsideArena(Location location) { if (minPoint == null) return false; if (maxPoint == null) @@ -1086,14 +1197,6 @@ public static Arena getArenaFromPlayer(Player player) { return null; } - public static Arena getArenaFromUser(User user) { - for (Arena arena : arenas) - for (User u : arena.users) - if (user == u) - return arena; - return null; - } - public User getUser(Player player) { for (User user : users) if (user.getPlayer() == player) @@ -1101,7 +1204,7 @@ public User getUser(Player player) { return null; } - protected int getAmountOfPlayerInGame() { + public int getAmountOfPlayerInGame() { int i = 0; for (User user : users) if (!user.isEliminated()) @@ -1118,19 +1221,12 @@ public Location getStartPoint() { return startPoint; } - public List getUsers() { - return users; - } - - protected String getHighestPlayer() { + public String getHighestPlayer() { return highestPlayer; } - public Player getPlayerFromUUID(String dammagerUUID) { - for (User user : users) - if (user.getUUID().equalsIgnoreCase(dammagerUUID)) - return user.getPlayer(); - return null; + public int getHighestPlayerScore() { + return highestScore; } public Location getMinPoint() { @@ -1141,8 +1237,16 @@ public ColorManager getColorManager() { return colorManager; } - public Location getMaxPoint() { - return maxPoint; + public enum LeavingReason { + DISCONNECT, HIDING, CRUSHED, COMMAND + } + + public World getWorld() { + return world; + } + + public int getMaxPlayer() { + return maxAmountPlayer; } } diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/tools/ColorManager.java b/Bukkit/src/me/poutineqc/cuberunner/game/ColorManager.java similarity index 85% rename from Bukkit_1.8/src/me/poutineqc/cuberunner/tools/ColorManager.java rename to Bukkit/src/me/poutineqc/cuberunner/game/ColorManager.java index fc534fa..d23251a 100644 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/tools/ColorManager.java +++ b/Bukkit/src/me/poutineqc/cuberunner/game/ColorManager.java @@ -1,4 +1,4 @@ -package me.poutineqc.cuberunner.tools; +package me.poutineqc.cuberunner.game; import java.util.ArrayList; import java.util.List; @@ -7,10 +7,9 @@ import org.bukkit.enchantments.Enchantment; import me.poutineqc.cuberunner.ArenaData; -import me.poutineqc.cuberunner.Configuration; import me.poutineqc.cuberunner.CubeRunner; import me.poutineqc.cuberunner.MySQL; -import me.poutineqc.cuberunner.games.Arena; +import me.poutineqc.cuberunner.utils.ItemStackManager; public class ColorManager { @@ -18,7 +17,6 @@ public class ColorManager { private List allBlocks; private List onlyChoosenBlocks; private MySQL mysql; - private Configuration config; private Arena arena; private ArenaData arenaData; @@ -26,7 +24,6 @@ public ColorManager(Long colorIndice, CubeRunner plugin, Arena arena) { this.colorIndice = colorIndice; this.mysql = plugin.getMySQL(); this.arenaData = plugin.getArenaData(); - this.config = plugin.getConfiguration(); this.arena = arena; updateLists(); } @@ -34,10 +31,10 @@ public ColorManager(Long colorIndice, CubeRunner plugin, Arena arena) { public void setColorIndice(long colorIndice) { this.colorIndice = colorIndice; updateLists(); - + if (mysql.hasConnection()) { - mysql.update("UPDATE " + config.tablePrefix + "ARENAS SET colorIndice=" + colorIndice + " WHERE name='" - + arena.getName() + "';"); + mysql.update("UPDATE " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS SET colorIndice=" + + colorIndice + " WHERE name='" + arena.getName() + "';"); } else { arenaData.getData().set("arenas." + arena.getName() + ".colorIndice", colorIndice); arenaData.saveArenaData(); @@ -48,7 +45,7 @@ public void updateLists() { allBlocks = new ArrayList(); onlyChoosenBlocks = new ArrayList(); long tempColorIndice = colorIndice; - + for (int i = 31; i >= 0; i--) { ItemStackManager icon; if (i >= 16) @@ -67,7 +64,7 @@ public void updateLists() { allBlocks.add(0, icon); } - + if (onlyChoosenBlocks.size() == 0) onlyChoosenBlocks = allBlocks; } @@ -75,11 +72,11 @@ public void updateLists() { public ItemStackManager getRandomAvailableBlock() { return onlyChoosenBlocks.get((int) Math.floor(Math.random() * onlyChoosenBlocks.size())); } - + public List getAllBlocks() { return allBlocks; } - + public List getOnlyChoosenBlocks() { return onlyChoosenBlocks; } @@ -87,5 +84,5 @@ public List getOnlyChoosenBlocks() { public long getColorIndice() { return colorIndice; } - + } diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/games/GameState.java b/Bukkit/src/me/poutineqc/cuberunner/game/GameState.java similarity index 63% rename from Bukkit_1.8/src/me/poutineqc/cuberunner/games/GameState.java rename to Bukkit/src/me/poutineqc/cuberunner/game/GameState.java index 22f23b1..9ef92d9 100644 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/games/GameState.java +++ b/Bukkit/src/me/poutineqc/cuberunner/game/GameState.java @@ -1,4 +1,4 @@ -package me.poutineqc.cuberunner.games; +package me.poutineqc.cuberunner.game; public enum GameState { READY, STARTUP, ACTIVE, ENDING, UNREADY diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/tools/OriginalPlayerStats.java b/Bukkit/src/me/poutineqc/cuberunner/game/OriginalPlayerStats.java similarity index 56% rename from Bukkit_1.9/src/me/poutineqc/cuberunner/tools/OriginalPlayerStats.java rename to Bukkit/src/me/poutineqc/cuberunner/game/OriginalPlayerStats.java index a8e18f9..47823d6 100644 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/tools/OriginalPlayerStats.java +++ b/Bukkit/src/me/poutineqc/cuberunner/game/OriginalPlayerStats.java @@ -1,11 +1,13 @@ -package me.poutineqc.cuberunner.tools; +package me.poutineqc.cuberunner.game; import java.util.Collection; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; +import org.bukkit.util.Vector; import me.poutineqc.cuberunner.Configuration; @@ -21,23 +23,27 @@ public class OriginalPlayerStats { private float saturation; private Collection effects; private Location location; + private boolean flying; + private boolean allowFlight; + + private ItemStack[] inventoryItems; public OriginalPlayerStats(Configuration config, Player player) { this.config = config; - this.level = player.getLevel(); - this.experience = player.getExp(); - this.gameMode = player.getGameMode(); - this.health = player.getHealth(); - this.foodLevel = player.getFoodLevel(); - this.saturation = player.getSaturation(); - this.effects = player.getActivePotionEffects(); this.location = player.getLocation(); } - public void returnStats(Player player) { - if (config.teleportAfterEnding) - player.teleport(location); + public void ireturnStats(Player player) { + for (PotionEffect effect : player.getActivePotionEffects()) + player.removePotionEffect(effect.getType()); + player.setAllowFlight(allowFlight); + if (flying) { + player.setAllowFlight(true); + player.setFlying(flying); + } + player.setFallDistance(0); + player.setVelocity(new Vector()); player.setLevel(level); player.setExp(experience); player.setGameMode(gameMode); @@ -45,9 +51,22 @@ public void returnStats(Player player) { player.setFoodLevel(foodLevel); player.setSaturation(saturation); player.addPotionEffects(effects); + + if (config.saveAndClearInventory) { + player.getInventory().setContents(inventoryItems); + player.updateInventory(); + } + + if (config.teleportAfterEnding) + player.teleport(location); + } - public void maxStats(Player player) { + public void imaxStats(Player player) { + player.setFallDistance(0); + player.setVelocity(new Vector()); + player.setFlying(false); + player.setAllowFlight(false); player.setLevel(0); player.setExp(0); player.setGameMode(GameMode.ADVENTURE); @@ -56,6 +75,23 @@ public void maxStats(Player player) { player.setSaturation(20); for (PotionEffect effect : player.getActivePotionEffects()) player.removePotionEffect(effect.getType()); + + if (config.saveAndClearInventory) { + player.getInventory().clear();; + player.updateInventory(); + } + } + public void ifillOtherStats(Player player) { + this.flying = player.isFlying(); + this.allowFlight = player.getAllowFlight(); + this.level = player.getLevel(); + this.experience = player.getExp(); + this.gameMode = player.getGameMode(); + this.health = player.getHealth(); + this.foodLevel = player.getFoodLevel(); + this.saturation = player.getSaturation(); + this.effects = player.getActivePotionEffects(); + this.inventoryItems = player.getInventory().getContents().clone(); } -} +} \ No newline at end of file diff --git a/Bukkit/src/me/poutineqc/cuberunner/game/User.java b/Bukkit/src/me/poutineqc/cuberunner/game/User.java new file mode 100644 index 0000000..1cef017 --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/game/User.java @@ -0,0 +1,144 @@ +package me.poutineqc.cuberunner.game; + +import java.util.HashMap; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +import me.poutineqc.cuberunner.CRPlayer; +import me.poutineqc.cuberunner.Configuration; + +public class User { + + private CRPlayer player; + private String displayName; + private OriginalPlayerStats originalStats; + + private boolean allowTeleport = false; + private boolean eliminated = false; + private long startTime; + private int score = 0; + private int jump = 0; + private boolean jumping = false; + private double distanceRan = 0; + + private HashMap totalDistance = new HashMap(); + + public User(Configuration config, CRPlayer player, Arena arena, boolean eliminated, boolean tpAuto) { + this.player = player; + displayName = player.getPlayer().getDisplayName(); + this.eliminated = eliminated; + + originalStats = new OriginalPlayerStats(config, player.getPlayer()); + + if (tpAuto) + player.getPlayer().teleport(arena.getLobby()); + + originalStats.ifillOtherStats(player.getPlayer()); + imaxStats(); + } + + public User(int time) { + this.score = time; + } + + protected void setStartTime() { + startTime = System.currentTimeMillis(); + } + + public Player getPlayer() { + return player.getPlayer(); + } + + public CRPlayer getCRPlayer() { + return player; + } + + protected void addToScore() { + score++; + } + + protected int getScore() { + return score; + } + + public String getDisplayName() { + return displayName; + } + + protected UUID getUUID() { + return player.getUUID(); + } + + protected int getGameLenght() { + return (int) (System.currentTimeMillis() - startTime); + } + + protected void ireturnStats() { + player.getPlayer().setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard()); + allowTeleport = true; + originalStats.ireturnStats(player.getPlayer()); + } + + protected void imaxStats() { + originalStats.imaxStats(player.getPlayer()); + } + + public boolean isEliminated() { + return eliminated; + } + + public void setEliminated(boolean eliminated) { + this.eliminated = eliminated; + } + + public void allowTeleport() { + allowTeleport = true; + } + + public boolean hasAllowTeleport() { + return allowTeleport; + } + + public void jump() { + jump++; + } + + public int getJump() { + return jump; + } + + public void setJumping(boolean jumping) { + this.jumping = jumping; + } + + public boolean isJumping() { + return jumping; + } + + public void addToDistanceRan(Vector vector) { + distanceRan += vector.length(); + totalDistance.put(System.currentTimeMillis(), + Math.sqrt(Math.pow(vector.getX(), 2) + Math.pow(vector.getZ(), 2))); + } + + public double getDistanceRan() { + return distanceRan; + } + + public String getName() { + return player.getName(); + } + + public double getLastTreeSecondsDistance() { + long currentTime = System.currentTimeMillis(); + double distanceDone = 0; + + for (long i = currentTime - 2000; i <= currentTime; i++) + distanceDone += totalDistance.getOrDefault(i, 0.0); + + return distanceDone; + } +} diff --git a/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerCommand.java b/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerCommand.java new file mode 100644 index 0000000..5291fef --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerCommand.java @@ -0,0 +1,63 @@ +package me.poutineqc.cuberunner.listeners; + +import org.apache.commons.lang3.StringUtils; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import me.poutineqc.cuberunner.CubeRunner; +import me.poutineqc.cuberunner.Language; +import me.poutineqc.cuberunner.Language.Messages; +import me.poutineqc.cuberunner.commands.CRCommand; +import me.poutineqc.cuberunner.utils.Permissions; +import me.poutineqc.cuberunner.utils.Utils; + +public class ListenerCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String cmdValue, String[] args) { + + if (!(sender instanceof Player)) { + sender.sendMessage("Only players can use CubeRunner's commands"); + return true; + } + + CubeRunner plugin = CubeRunner.get(); + Player player = (Player) sender; + Language local = CubeRunner.get().getLang(player); + + if (args.length == 0) { + player.sendMessage(Utils.color("&8&m" + StringUtils.repeat(" ", 15) + "&r&8| &5CubeRunner " + "&8&m|" + StringUtils.repeat(" ", 40))); + player.sendMessage(Utils + .color(local.get(Messages.DEVELOPPER).replace("%developper%", plugin.getDescription().getAuthors().toString()))); + player.sendMessage(Utils.color(local.get(Messages.VERSION).replace("%version%", plugin.getDescription().getVersion()))); + player.sendMessage(Utils.color(local.get(Messages.DESCRIPTION).replace("%command%", cmdValue))); + player.sendMessage("\n"); + return true; + } + + CRCommand crCommand = CRCommand.getCommand(args[0]); + if (crCommand == null) { + local.sendMsg(player, local.get(Messages.ERROR_COMMAND).replace("%cmd%", cmdValue)); + return true; + } + + if (!Permissions.hasPermission(crCommand.getPermission(), player, true)) + return true; + + switch (crCommand) { + case HELP: + case LANGUAGE: + case INFO: + crCommand.execute(plugin, player, args, cmdValue); + break; + case JOIN: + crCommand.execute(plugin, player, args, "false"); + break; + default: + crCommand.execute(plugin, player, args); + } + return true; + } +} diff --git a/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerEntityChangeBlock.java b/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerEntityChangeBlock.java new file mode 100644 index 0000000..6b63fd4 --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerEntityChangeBlock.java @@ -0,0 +1,24 @@ +package me.poutineqc.cuberunner.listeners; + +import org.bukkit.Material; +import org.bukkit.entity.FallingBlock; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityChangeBlockEvent; + +public class ListenerEntityChangeBlock implements Listener { + + @EventHandler(priority = EventPriority.HIGHEST) + public void onEntityChangeBlock(EntityChangeBlockEvent event) { + if ((event.getEntity() instanceof FallingBlock)) { + FallingBlock fallingBlock = (FallingBlock) event.getEntity(); + if ((fallingBlock.getMaterial() == Material.WOOL) && (event.getBlock().getType() == Material.AIR)) { + if (fallingBlock.getCustomName() + .matches("[a-f0-9]{8}-[a-f0-9]{4}-4[0-9]{3}-[89ab][a-f0-9]{3}-[0-9a-f]{12}")) + event.setCancelled(false); + } + } + } + +} diff --git a/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerEntityGlide.java b/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerEntityGlide.java new file mode 100644 index 0000000..eb8b6be --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerEntityGlide.java @@ -0,0 +1,29 @@ +package me.poutineqc.cuberunner.listeners; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityToggleGlideEvent; + +import me.poutineqc.cuberunner.game.Arena; + +public class ListenerEntityGlide implements Listener { + + @EventHandler + public void onEntityToggleGlide(EntityToggleGlideEvent event) { + if (!event.isGliding()) + return; + + if (!(event.getEntity() instanceof Player)) + return; + + Player player = (Player) event.getEntity(); + Arena arena = Arena.getArenaFromPlayer(player); + if (arena == null) + return; + + event.setCancelled(true); + + } + +} diff --git a/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerInventoryClick.java b/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerInventoryClick.java new file mode 100644 index 0000000..0530552 --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerInventoryClick.java @@ -0,0 +1,35 @@ +package me.poutineqc.cuberunner.listeners; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.ItemStack; + +import me.poutineqc.cuberunner.CRPlayer; +import me.poutineqc.cuberunner.CubeRunner; +import me.poutineqc.cuberunner.commands.inventories.CRInventory; + +public class ListenerInventoryClick implements Listener { + + @EventHandler + public void onInventoryClick(InventoryClickEvent event) { + if (event.getAction() == InventoryAction.NOTHING || event.getAction() == InventoryAction.UNKNOWN) + return; + + if (!(event.getWhoClicked() instanceof Player)) + return; + + ItemStack item = event.getCurrentItem(); + CRPlayer player = CubeRunner.get().getCRPlayer((Player) event.getWhoClicked()); + + CRInventory inv = player.getCurrentInventory(); + if (inv == null) + return; + + event.setCancelled(true); + inv.update(item, event.getAction()); + } + +} diff --git a/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerInventoryClose.java b/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerInventoryClose.java new file mode 100644 index 0000000..e362eb9 --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerInventoryClose.java @@ -0,0 +1,24 @@ +package me.poutineqc.cuberunner.listeners; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryCloseEvent; + +import me.poutineqc.cuberunner.CRPlayer; +import me.poutineqc.cuberunner.CubeRunner; + +public class ListenerInventoryClose implements Listener { + + @EventHandler + public void onInventoryClose(InventoryCloseEvent event) { + if (!(event.getPlayer() instanceof Player)) + return; + + CRPlayer player = CubeRunner.get().getCRPlayer((Player) event.getPlayer()); + player.setCurrentInventory(null); + + + } + +} diff --git a/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerPlayerDamage.java b/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerPlayerDamage.java new file mode 100644 index 0000000..0aa36b3 --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerPlayerDamage.java @@ -0,0 +1,84 @@ +package me.poutineqc.cuberunner.listeners; + +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; + +import me.poutineqc.cuberunner.CRStats; +import me.poutineqc.cuberunner.CubeRunner; +import me.poutineqc.cuberunner.CRPlayer.PlayerStatsException; +import me.poutineqc.cuberunner.game.Arena; +import me.poutineqc.cuberunner.game.GameState; +import me.poutineqc.cuberunner.game.User; +import me.poutineqc.cuberunner.game.Arena.LeavingReason; + +public class ListenerPlayerDamage implements Listener { + + @EventHandler + public void onPlayerDamageByEntity(EntityDamageByEntityEvent event) throws PlayerStatsException { + + if (!(event.getEntity() instanceof Player)) + return; + + Player player = (Player) event.getEntity(); + Arena arena = Arena.getArenaFromPlayer(player); + + if (arena == null) + return; + + if (event.getCause() != DamageCause.FALLING_BLOCK) { + event.setCancelled(true); + return; + } + + if (arena.getGameState() != GameState.ACTIVE) { + event.setCancelled(true); + return; + } + + User user = arena.getUser(player); + if (user.isEliminated()) { + event.setCancelled(true); + return; + } + + event.setDamage(0); + arena.eliminateUser(arena.getUser(player), LeavingReason.CRUSHED); + + String dammagerUUID = event.getDamager().getCustomName(); + if (!dammagerUUID.equalsIgnoreCase(player.getUniqueId().toString())) + CubeRunner.get().getCRPlayer(Bukkit.getPlayer(UUID.fromString(dammagerUUID))).increment(CRStats.KILLS, + true); + } + + @EventHandler + public void onPlayerDamage(EntityDamageEvent event) { + + if (!(event.getEntity() instanceof Player)) + return; + + Player player = (Player) event.getEntity(); + Arena arena = Arena.getArenaFromPlayer(player); + + if (arena == null) + return; + + if (event.getCause() != DamageCause.FALLING_BLOCK) { + event.setCancelled(true); + return; + } + + User user = arena.getUser(player); + if (user.isEliminated()) { + event.setCancelled(true); + return; + } + } + +} diff --git a/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerPlayerDisconnect.java b/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerPlayerDisconnect.java new file mode 100644 index 0000000..80c88e0 --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerPlayerDisconnect.java @@ -0,0 +1,31 @@ +package me.poutineqc.cuberunner.listeners; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerQuitEvent; + +import me.poutineqc.cuberunner.CRStats; +import me.poutineqc.cuberunner.CRPlayer.PlayerStatsException; +import me.poutineqc.cuberunner.game.Arena; +import me.poutineqc.cuberunner.game.GameState; +import me.poutineqc.cuberunner.game.Arena.LeavingReason; + +public class ListenerPlayerDisconnect implements Listener { + + @EventHandler + public void onPlayerDisconnect(PlayerQuitEvent event) throws PlayerStatsException { + + Player player = event.getPlayer(); + Arena arena = Arena.getArenaFromPlayer(player); + + if (arena == null) + return; + + if (arena.getGameState() == GameState.STARTUP) + arena.getUser(player).getCRPlayer().doneChallenge(CRStats.THE_RAGE_QUIT); + + arena.removePlayer(player, LeavingReason.DISCONNECT); + + } +} diff --git a/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerPlayerInteract.java b/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerPlayerInteract.java new file mode 100644 index 0000000..05c3a37 --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerPlayerInteract.java @@ -0,0 +1,29 @@ +package me.poutineqc.cuberunner.listeners; + +import org.bukkit.block.Sign; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +import me.poutineqc.cuberunner.commands.signs.CRSign; + +public class ListenerPlayerInteract implements Listener { + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + if (!event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) + return; + + if (!(event.getClickedBlock().getState() instanceof Sign)) + return; + + Sign s = (Sign) event.getClickedBlock().getState(); + CRSign crSign = CRSign.getCrSign(s.getLocation()); + if (crSign == null) + return; + + event.setCancelled(true); + crSign.onInteract(event.getPlayer()); + } +} diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/achievements/PlayerMovement.java b/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerPlayerMove.java similarity index 59% rename from Bukkit_1.8/src/me/poutineqc/cuberunner/achievements/PlayerMovement.java rename to Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerPlayerMove.java index d28c715..16d3bac 100644 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/achievements/PlayerMovement.java +++ b/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerPlayerMove.java @@ -1,25 +1,20 @@ -package me.poutineqc.cuberunner.achievements; +package me.poutineqc.cuberunner.listeners; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerMoveEvent; -import me.poutineqc.cuberunner.CubeRunner; -import me.poutineqc.cuberunner.games.Arena; -import me.poutineqc.cuberunner.games.GameState; -import me.poutineqc.cuberunner.games.User; +import me.poutineqc.cuberunner.CRStats; +import me.poutineqc.cuberunner.CRPlayer.PlayerStatsException; +import me.poutineqc.cuberunner.game.Arena; +import me.poutineqc.cuberunner.game.GameState; +import me.poutineqc.cuberunner.game.User; -public class PlayerMovement implements Listener { - - private Achievements achievements; - - public PlayerMovement(CubeRunner plugin) { - this.achievements = plugin.getAchievements(); - } +public class ListenerPlayerMove implements Listener { @EventHandler - public void onPlayerMove(PlayerMoveEvent event) { + public void onPlayerMove(PlayerMoveEvent event) throws PlayerStatsException { Player player = event.getPlayer(); Arena arena = Arena.getArenaFromPlayer(player); @@ -41,13 +36,13 @@ public void onPlayerMove(PlayerMoveEvent event) { if (arena.getGameState() != GameState.ACTIVE) return; - user.addToDistanceRan(event.getFrom().distance(event.getTo())); + user.addToDistanceRan(event.getTo().toVector().subtract(event.getFrom().toVector())); double toLocation = event.getTo().getY(); double fromLocation = event.getFrom().getY(); if (toLocation > arena.getMinPoint().getY() + 10) - achievements.checkAchievement(AchievementType.REACH_HEIGHT_10, player); + user.getCRPlayer().doneChallenge(CRStats.REACH_HEIGHT_10); if (user.isJumping()) { if (toLocation < fromLocation) @@ -58,7 +53,7 @@ public void onPlayerMove(PlayerMoveEvent event) { user.jump(); if (user.getJump() == 50) - achievements.checkAchievement(AchievementType.JUMP_50_TIMES, player); + user.getCRPlayer().doneChallenge(CRStats.THE_KILLER_BUNNY); } } } diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/games/PlayerTeleport.java b/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerPlayerTeleport.java similarity index 70% rename from Bukkit_1.9/src/me/poutineqc/cuberunner/games/PlayerTeleport.java rename to Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerPlayerTeleport.java index e087b56..903138c 100644 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/games/PlayerTeleport.java +++ b/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerPlayerTeleport.java @@ -1,4 +1,4 @@ -package me.poutineqc.cuberunner.games; +package me.poutineqc.cuberunner.listeners; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -8,15 +8,11 @@ import me.poutineqc.cuberunner.CubeRunner; import me.poutineqc.cuberunner.Language; -import me.poutineqc.cuberunner.PlayerData; +import me.poutineqc.cuberunner.Language.Messages; +import me.poutineqc.cuberunner.game.Arena; +import me.poutineqc.cuberunner.game.User; -public class PlayerTeleport implements Listener { - - private PlayerData playerData; - - public PlayerTeleport(CubeRunner plugin) { - this.playerData = plugin.getPlayerData(); - } +public class ListenerPlayerTeleport implements Listener { @EventHandler public void onPlayerTeleport(PlayerTeleportEvent event) { @@ -31,11 +27,11 @@ public void onPlayerTeleport(PlayerTeleportEvent event) { return; User user = arena.getUser(player); - if (user.hasLeft()) + if (user.hasAllowTeleport()) return; - Language local = playerData.getLanguageOfPlayer(player); - local.sendMsg(player, local.errorTeleport); + Language local = CubeRunner.get().getLang(player); + local.sendMsg(player, local.get(Messages.ERROR_TELEPORT)); event.setCancelled(true); diff --git a/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerSignBreak.java b/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerSignBreak.java new file mode 100644 index 0000000..d2acb9f --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerSignBreak.java @@ -0,0 +1,27 @@ +package me.poutineqc.cuberunner.listeners; + +import org.bukkit.block.Sign; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; + +import me.poutineqc.cuberunner.commands.signs.CRSign; + +public class ListenerSignBreak implements Listener { + + @EventHandler(priority = EventPriority.HIGHEST) + public void onBlockBreak(BlockBreakEvent event) { + if (!(event.getBlock().getState() instanceof Sign)) + return; + + if (event.isCancelled()) + return; + + Sign sign = (Sign) event.getBlock().getState(); + CRSign dacSign = CRSign.getCrSign(sign.getLocation()); + if (dacSign != null) + dacSign.removeSign(); + } + +} \ No newline at end of file diff --git a/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerSignUpdate.java b/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerSignUpdate.java new file mode 100644 index 0000000..9662c47 --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerSignUpdate.java @@ -0,0 +1,106 @@ +package me.poutineqc.cuberunner.listeners; + +import org.bukkit.ChatColor; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.SignChangeEvent; + +import me.poutineqc.cuberunner.CubeRunner; +import me.poutineqc.cuberunner.Language; +import me.poutineqc.cuberunner.Language.Messages; +import me.poutineqc.cuberunner.commands.signs.CRSignJoin; +import me.poutineqc.cuberunner.commands.signs.CRSignPlay; +import me.poutineqc.cuberunner.commands.signs.CRSignQuit; +import me.poutineqc.cuberunner.commands.signs.CRSignStart; +import me.poutineqc.cuberunner.commands.signs.CRSignStats; +import me.poutineqc.cuberunner.commands.signs.CRSignTop; +import me.poutineqc.cuberunner.game.Arena; +import me.poutineqc.cuberunner.utils.Permissions; + +public class ListenerSignUpdate implements Listener { + + @EventHandler + public void onSignPlace(SignChangeEvent event) { + + Language local = CubeRunner.get().getLang(event.getPlayer()); + + if (isPrefixInLine(event.getLine(0))) { + if (!Permissions.hasPermission(Permissions.createSign, event.getPlayer(), false)) { + setNoPermissionsSign(event, local); + return; + } + + if (event.getLine(1).equalsIgnoreCase("join")) { + Arena arena = Arena.getArena(event.getLine(2)); + if (arena != null) { + new CRSignJoin(event, arena); + } else { + setNoValidSign(event, local); + } + } else if (event.getLine(1).equalsIgnoreCase("play")) { + Arena arena = Arena.getArena(event.getLine(2)); + if (arena != null) { + if (arena.getWorld() == null) { + setNoValidSign(event, local); + } else if (arena.getWorld() != event.getBlock().getWorld()) { + setNoValidSign(event, local); + } else { + new CRSignPlay(event, arena); + } + } else { + setNoValidSign(event, local); + } + } else if (event.getLine(1).equalsIgnoreCase("quit")) { + new CRSignQuit(event); + + } else if (event.getLine(1).equalsIgnoreCase("top")) { + Arena arena = Arena.getArena(event.getLine(2)); + if (arena != null) { + new CRSignTop(event, arena); + } else { + setNoValidSign(event, local); + } + } else if (event.getLine(1).equalsIgnoreCase("start")) { + new CRSignStart(event); + + } else if (event.getLine(1).equalsIgnoreCase("stats")) { + new CRSignStats(event); + + } else { + setNoValidSign(event, local); + } + } else if (isPrefixInLine(event.getLine(1)) || isPrefixInLine(event.getLine(2)) + || isPrefixInLine(event.getLine(3))) { + + if (Permissions.hasPermission(Permissions.createSign, event.getPlayer(), false)) + setNoValidSign(event, local); + else + setNoPermissionsSign(event, local); + } + } + + private void setNoPermissionsSign(SignChangeEvent e, Language local) { + e.setLine(0, ChatColor.translateAlternateColorCodes('&', local.get(Messages.SIGN_PERM_0))); + e.setLine(1, ChatColor.translateAlternateColorCodes('&', local.get(Messages.SIGN_PERM_1))); + e.setLine(2, ChatColor.translateAlternateColorCodes('&', local.get(Messages.SIGN_PERM_2))); + e.setLine(3, ChatColor.translateAlternateColorCodes('&', local.get(Messages.SIGN_PERM_3))); + } + + private void setNoValidSign(SignChangeEvent e, Language local) { + e.setLine(0, ChatColor.translateAlternateColorCodes('&', local.get(Messages.PREFIX_LONG))); + e.setLine(1, ChatColor.translateAlternateColorCodes('&', local.get(Messages.SIGN_VALID_1))); + e.setLine(2, ChatColor.translateAlternateColorCodes('&', local.get(Messages.SIGN_VALID_2))); + e.setLine(3, ChatColor.translateAlternateColorCodes('&', local.get(Messages.SIGN_VALID_3))); + } + + private boolean isPrefixInLine(String line) { + Language local = Language.getDefault(); + String stipedLine = ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', line)).toLowerCase(); + return stipedLine.contains("[cr]") + || stipedLine.contains(ChatColor + .stripColor(ChatColor.translateAlternateColorCodes('&', local.get(Messages.PREFIX_LONG).toLowerCase().trim()))) + || stipedLine.contains(ChatColor.stripColor( + ChatColor.translateAlternateColorCodes('&', local.get(Messages.PREFIX_SHORT).toLowerCase().trim()))); + } + +} diff --git a/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerTabComplete.java b/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerTabComplete.java new file mode 100644 index 0000000..c44f48b --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/listeners/ListenerTabComplete.java @@ -0,0 +1,39 @@ +package me.poutineqc.cuberunner.listeners; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +import me.poutineqc.cuberunner.commands.CRCommand; + +public class ListenerTabComplete implements TabCompleter { + + @Override + public List onTabComplete(CommandSender sender, Command cmd, String cmdLabel, String[] args) { + List tabCompletion = new ArrayList(); + + if (!(sender instanceof Player)) + return tabCompletion; + + Player player = (Player) sender; + + if (args.length == 1) { + for (CRCommand command : CRCommand.getRequiredCommands(player, null)) + if (command.getCommandName().startsWith(args[0].toLowerCase())) + tabCompletion.add(command.getCommandName()); + + return tabCompletion; + } + + CRCommand command = CRCommand.getCommand(args[0].toLowerCase()); + if (command == null) + return tabCompletion; + + command.complete(tabCompletion, args); + return tabCompletion; + } +} diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/tools/CaseInsensitiveMap.java b/Bukkit/src/me/poutineqc/cuberunner/utils/CaseInsensitiveMap.java similarity index 92% rename from Bukkit_1.8/src/me/poutineqc/cuberunner/tools/CaseInsensitiveMap.java rename to Bukkit/src/me/poutineqc/cuberunner/utils/CaseInsensitiveMap.java index dfdeaaf..09af86d 100644 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/tools/CaseInsensitiveMap.java +++ b/Bukkit/src/me/poutineqc/cuberunner/utils/CaseInsensitiveMap.java @@ -1,4 +1,4 @@ -package me.poutineqc.cuberunner.tools; +package me.poutineqc.cuberunner.utils; import java.util.HashMap; diff --git a/Bukkit/src/me/poutineqc/cuberunner/utils/ItemBannerManager.java b/Bukkit/src/me/poutineqc/cuberunner/utils/ItemBannerManager.java new file mode 100644 index 0000000..b18351b --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/utils/ItemBannerManager.java @@ -0,0 +1,252 @@ +package me.poutineqc.cuberunner.utils; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.DyeColor; +import org.bukkit.Material; +import org.bukkit.block.banner.Pattern; +import org.bukkit.block.banner.PatternType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.BannerMeta; + +public class ItemBannerManager extends ItemStackManager { + private DyeColor baseColor; + private List patterns = new ArrayList(); + + public enum CustomPattern { + ARROW_RIGHT, ARROW_LEFT, ARROW_ACTUAL, ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, SYMBOL_PLUS, SYMBOL_MINUS, DOT; + + public static CustomPattern getPattern(int number) { + switch (number) { + case 0: + return CustomPattern.ZERO; + case 1: + return CustomPattern.ONE; + case 2: + return CustomPattern.TWO; + case 3: + return CustomPattern.THREE; + case 4: + return CustomPattern.FOUR; + case 5: + return CustomPattern.FIVE; + case 6: + return CustomPattern.SIX; + case 7: + return CustomPattern.SEVEN; + case 8: + return CustomPattern.EIGHT; + case 9: + return CustomPattern.NINE; + default: + return null; + } + } + } + + public ItemBannerManager() { + super(Material.BANNER); + } + + public ItemBannerManager(ItemStack itemStack) { + super(itemStack); + + BannerMeta meta = (BannerMeta) itemStack.getItemMeta(); + baseColor = meta.getBaseColor(); + patterns = meta.getPatterns(); + } + + public ItemBannerManager(CustomPattern pattern) { + this(pattern, DyeColor.BLACK); + } + + public ItemBannerManager(CustomPattern pattern, DyeColor dyeColor) { + super(Material.BANNER); + durability = 0; + setPattern(pattern, dyeColor); + } + + @Override + public ItemStack getItem() { + ItemStack itemStack = super.getItem(); + BannerMeta meta = (BannerMeta) itemStack.getItemMeta(); + meta.setBaseColor(baseColor); + meta.setPatterns(patterns); + + itemStack.setItemMeta(meta); + return itemStack; + } + + @Override + public boolean isSame(ItemStack itemStack) { + if (!super.isSame(itemStack)) + return false; + + BannerMeta meta = (BannerMeta) itemStack.getItemMeta(); + if (meta.getBaseColor() != baseColor) + return false; + + if (meta.getPatterns().size() != patterns.size()) + return false; + + for (int i = 0; i < patterns.size(); i++) { + if (patterns.get(i).getColor() != meta.getPatterns().get(i).getColor() + || patterns.get(i).getPattern() != meta.getPatterns().get(i).getPattern()) + return false; + } + + return true; + } + + public void add(Pattern pattern) { + patterns.add(pattern); + } + + public void setPatterns(List patterns) { + this.patterns = patterns; + } + + public void clearPatterns() { + patterns.clear(); + } + + public List getPatterns() { + return patterns; + } + + private void setPattern(CustomPattern pattern, DyeColor dyeColor) { + patterns.clear(); + switch (pattern) { + case ARROW_LEFT: + baseColor = dyeColor; + patterns.add(new Pattern(DyeColor.WHITE, PatternType.RHOMBUS_MIDDLE)); + patterns.add(new Pattern(dyeColor, PatternType.HALF_VERTICAL_MIRROR)); + break; + case ARROW_RIGHT: + baseColor = dyeColor; + patterns.add(new Pattern(DyeColor.WHITE, PatternType.RHOMBUS_MIDDLE)); + patterns.add(new Pattern(dyeColor, PatternType.HALF_VERTICAL)); + break; + case ARROW_ACTUAL: + baseColor = dyeColor; + patterns.add(new Pattern(DyeColor.WHITE, PatternType.CIRCLE_MIDDLE)); + break; + case SYMBOL_MINUS: + baseColor = DyeColor.WHITE; + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_MIDDLE)); + patterns.add(new Pattern(DyeColor.WHITE, PatternType.BORDER)); + break; + case SYMBOL_PLUS: + baseColor = DyeColor.WHITE; + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_CENTER)); + patterns.add(new Pattern(DyeColor.WHITE, PatternType.BORDER)); + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_MIDDLE)); + break; + case DOT: + baseColor = DyeColor.WHITE; + patterns.add(new Pattern(dyeColor, PatternType.TRIANGLE_BOTTOM)); + patterns.add(new Pattern(DyeColor.WHITE, PatternType.BORDER)); + patterns.add(new Pattern(DyeColor.WHITE, PatternType.STRIPE_DOWNLEFT)); + patterns.add(new Pattern(DyeColor.WHITE, PatternType.STRIPE_DOWNRIGHT)); + patterns.add(new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT)); + patterns.add(new Pattern(DyeColor.WHITE, PatternType.STRIPE_RIGHT)); + patterns.add(new Pattern(DyeColor.WHITE, PatternType.CREEPER)); + break; + case ZERO: + baseColor = DyeColor.WHITE; + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_BOTTOM)); + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_TOP)); + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_RIGHT)); + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_LEFT)); + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_DOWNLEFT)); + patterns.add(new Pattern(DyeColor.WHITE, PatternType.BORDER)); + break; + case ONE: + baseColor = DyeColor.WHITE; + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_TOP)); + patterns.add(new Pattern(DyeColor.WHITE, PatternType.STRIPE_RIGHT)); + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_CENTER)); + patterns.add(new Pattern(DyeColor.WHITE, PatternType.CURLY_BORDER)); + patterns.add(new Pattern(DyeColor.WHITE, PatternType.BORDER)); + break; + case TWO: + baseColor = DyeColor.WHITE; + patterns.add(new Pattern(dyeColor, PatternType.TRIANGLE_TOP)); + patterns.add(new Pattern(dyeColor, PatternType.TRIANGLE_BOTTOM)); + patterns.add(new Pattern(dyeColor, PatternType.SQUARE_TOP_LEFT)); + patterns.add(new Pattern(dyeColor, PatternType.SQUARE_BOTTOM_RIGHT)); + patterns.add(new Pattern(DyeColor.WHITE, PatternType.RHOMBUS_MIDDLE)); + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_DOWNLEFT)); + patterns.add(new Pattern(DyeColor.WHITE, PatternType.BORDER)); + break; + case THREE: + baseColor = DyeColor.WHITE; + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_MIDDLE)); + patterns.add(new Pattern(DyeColor.WHITE, PatternType.STRIPE_LEFT)); + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_BOTTOM)); + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_RIGHT)); + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_TOP)); + patterns.add(new Pattern(DyeColor.WHITE, PatternType.BORDER)); + break; + case FOUR: + baseColor = dyeColor; + patterns.add(new Pattern(DyeColor.WHITE, PatternType.HALF_HORIZONTAL)); + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_LEFT)); + patterns.add(new Pattern(DyeColor.WHITE, PatternType.STRIPE_BOTTOM)); + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_RIGHT)); + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_MIDDLE)); + patterns.add(new Pattern(DyeColor.WHITE, PatternType.BORDER)); + break; + case FIVE: + baseColor = dyeColor; + patterns.add(new Pattern(DyeColor.WHITE, PatternType.HALF_VERTICAL_MIRROR)); + patterns.add(new Pattern(DyeColor.WHITE, PatternType.HALF_HORIZONTAL_MIRROR)); + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_BOTTOM)); + patterns.add(new Pattern(DyeColor.WHITE, PatternType.DIAGONAL_RIGHT_MIRROR)); + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_DOWNRIGHT)); + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_TOP)); + patterns.add(new Pattern(DyeColor.WHITE, PatternType.BORDER)); + break; + case SIX: + baseColor = DyeColor.WHITE; + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_RIGHT)); + patterns.add(new Pattern(DyeColor.WHITE, PatternType.HALF_HORIZONTAL)); + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_BOTTOM)); + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_MIDDLE)); + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_LEFT)); + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_TOP)); + patterns.add(new Pattern(DyeColor.WHITE, PatternType.BORDER)); + break; + case SEVEN: + baseColor = DyeColor.WHITE; + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_TOP)); + patterns.add(new Pattern(DyeColor.WHITE, PatternType.SQUARE_BOTTOM_LEFT)); + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_DOWNLEFT)); + patterns.add(new Pattern(DyeColor.WHITE, PatternType.BORDER)); + break; + case EIGHT: + baseColor = DyeColor.WHITE; + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_TOP)); + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_BOTTOM)); + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_MIDDLE)); + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_LEFT)); + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_RIGHT)); + patterns.add(new Pattern(DyeColor.WHITE, PatternType.BORDER)); + break; + case NINE: + baseColor = DyeColor.WHITE; + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_LEFT)); + patterns.add(new Pattern(DyeColor.WHITE, PatternType.HALF_HORIZONTAL_MIRROR)); + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_MIDDLE)); + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_TOP)); + patterns.add(new Pattern(dyeColor, PatternType.STRIPE_RIGHT)); + patterns.add(new Pattern(DyeColor.WHITE, PatternType.BORDER)); + break; + } + } + + public DyeColor getBaseColor() { + return baseColor; + } +} \ No newline at end of file diff --git a/Bukkit/src/me/poutineqc/cuberunner/utils/ItemHeadManager.java b/Bukkit/src/me/poutineqc/cuberunner/utils/ItemHeadManager.java new file mode 100644 index 0000000..7dbbcf7 --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/utils/ItemHeadManager.java @@ -0,0 +1,67 @@ +package me.poutineqc.cuberunner.utils; + +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.SkullMeta; + +public class ItemHeadManager extends ItemStackManager { + + private String playerName; + + public ItemHeadManager(String playerName) { + super(Material.SKULL_ITEM); + this.durability = 3; + this.playerName = playerName; + } + + public ItemHeadManager(ItemStack itemStack) { + super(itemStack); + + SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); + this.playerName = meta.hasOwner() ? meta.getOwner() : null; + } + + public ItemHeadManager() { + super(Material.SKULL_ITEM); + this.durability = 3; + } + + @Override + public ItemStack getItem() { + ItemStack itemStack = super.getItem(); + SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); + if (playerName != null) + meta.setOwner(playerName); + + itemStack.setItemMeta(meta); + return itemStack; + } + + @Override + public boolean isSame(ItemStack itemStack) { + if (!super.isSame(itemStack)) + return false; + + if (durability != 3) + return true; + + SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); + if (meta.hasOwner()) { + if (playerName == null) + return false; + else if (!meta.getOwner().equalsIgnoreCase(playerName)) + return false; + } else if (playerName != null) + return false; + + return true; + } + + public void setPlayerName(String playerName) { + this.playerName = playerName; + } + + public String getPlayerName() { + return playerName; + } +} \ No newline at end of file diff --git a/Bukkit/src/me/poutineqc/cuberunner/utils/ItemStackManager.java b/Bukkit/src/me/poutineqc/cuberunner/utils/ItemStackManager.java new file mode 100644 index 0000000..3f52268 --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/utils/ItemStackManager.java @@ -0,0 +1,150 @@ +package me.poutineqc.cuberunner.utils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +public class ItemStackManager { + + protected Material material; + protected int amount = 1; + protected short durability = 0; + + protected String name; + protected List lore = new ArrayList(); + protected Map enchantments = new HashMap(); + + public ItemStackManager(Material material) { + this.material = material; + } + + public ItemStackManager(ItemStack itemStack) { + this.material = itemStack.getType(); + this.amount = itemStack.getAmount(); + this.durability = itemStack.getDurability(); + + ItemMeta meta = itemStack.getItemMeta(); + this.name = meta.hasDisplayName() ? meta.getDisplayName() : null; + this.enchantments = meta.hasEnchants() ? meta.getEnchants() : new HashMap(); + this.lore = meta.hasLore() ? meta.getLore() : null; + } + + public ItemStack getItem() { + ItemStack itemStack = new ItemStack(material, amount, durability); + + ItemMeta meta = itemStack.getItemMeta(); + meta.setDisplayName(name); + meta.setLore(lore); + for (Entry enchantment : enchantments.entrySet()) + meta.addEnchant(enchantment.getKey(), enchantment.getValue(), true); + + itemStack.setItemMeta(meta); + return itemStack; + } + + public boolean isSame(ItemStack itemStack) { + if (material != itemStack.getType()) + return false; + + if (durability != itemStack.getDurability()) + return false; + + if (itemStack.getItemMeta().hasDisplayName()) { + if (name == null) + return false; + + if (!Utils.isEqualOnColorStrip(itemStack.getItemMeta().getDisplayName(), name)) + return false; + + } else if (name != null) + return false; + + if (itemStack.getItemMeta().hasEnchants()) { + for (Entry enchantment : itemStack.getItemMeta().getEnchants().entrySet()) + if (!hasEnchantement(enchantment.getKey(), enchantment.getValue())) + return false; + } else if (enchantments.size() > 0) + return false; + + return true; + } + + public void setData(short durability) { + this.durability = durability; + } + + public void setDisplayName(String displayName) { + this.name = ChatColor.translateAlternateColorCodes('&', displayName); + } + + public void addToLore(String loreLine) { + lore.add(ChatColor.translateAlternateColorCodes('&', loreLine)); + } + + public void setLore(List lore) { + this.lore = lore; + } + + public void clearLore() { + lore = new ArrayList(); + } + + public void addEnchantement(Enchantment enchantment, int level) { + enchantments.put(enchantment, level); + } + + public void setEnchantements(Map enchantments) { + this.enchantments = enchantments; + } + + public void clearEnchantements() { + enchantments.clear(); + } + + public int getMaxStackSize() { + return material.getMaxStackSize(); + } + + public Material getMaterial() { + return material; + } + + public short getDurability() { + return durability; + } + + public boolean hasEnchantement(Enchantment enchantement) { + for (Entry entry : enchantments.entrySet()) + if (entry.getKey() == enchantement) + return true; + + return false; + } + + public boolean hasEnchantement(Enchantment enchantement, int value) { + for (Entry entry : enchantments.entrySet()) + if (entry.getKey() == enchantement) + if (entry.getValue() == value) + return true; + else + return false; + + return false; + } + + public String getDisplayName() { + return name; + } + + public List getLore() { + return lore; + } +} diff --git a/Bukkit/src/me/poutineqc/cuberunner/utils/MinecraftConfiguration.java b/Bukkit/src/me/poutineqc/cuberunner/utils/MinecraftConfiguration.java new file mode 100644 index 0000000..a7edc40 --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/utils/MinecraftConfiguration.java @@ -0,0 +1,93 @@ +package me.poutineqc.cuberunner.utils; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; + +import me.poutineqc.cuberunner.CubeRunner; + +public class MinecraftConfiguration { + + File folder; + File file; + FileConfiguration config; + + public MinecraftConfiguration(String folderPath, String fileName, boolean buildIn) { + getFile(folderPath, fileName, buildIn); + + if (!file.exists()) { + + return; + } + + this.config = YamlConfiguration.loadConfiguration(file); + } + + public void getFile(String folderPath, String fileName, boolean buildIn) { + folder = CubeRunner.get().getDataFolder(); + if (folderPath != null) + getFolder(folderPath); + + file = new File(folder, fileName + ".yml"); + + if (!file.exists()) { + if (!buildIn) { + try { + file.createNewFile(); + return; + } catch (IOException e) { + Bukkit.getServer().getLogger().severe("Could not create playerData.ylm."); + Bukkit.getServer().getLogger().severe("Review your minecraft server's permissions to write and edit files in it's plugin directory"); + Bukkit.getServer().getLogger().severe("Disabling CubeRunner..."); + CubeRunner.get().getPluginLoader().disablePlugin(CubeRunner.get()); + } + } else { + folderPath = (folderPath == null) ? "" : (folderPath + "/"); + InputStream local = CubeRunner.get().getResource(folderPath + fileName + ".yml"); + if (local != null) { + CubeRunner.get().saveResource(folderPath + fileName + ".yml", false); + } else { + CubeRunner.get().getLogger().severe("Could not find " + fileName + ".yml"); + CubeRunner.get().getLogger().severe("Contact the developper as fast as possible, this should not happend."); + Bukkit.getServer().getLogger().severe("Disabling CubeRunner..."); + CubeRunner.get().getPluginLoader().disablePlugin(CubeRunner.get()); + } + } + } + } + + private void getFolder(String folderPath) { + String[] folderNames = folderPath.split("/"); + for (String names : folderNames) { + folder = new File(folder, names); + if (!folder.exists()) + folder.mkdir(); + } + } + + public boolean hasFile() { + return file != null; + } + + public void save() { + try { + config.save(file); + } catch (IOException e) { + Bukkit.getServer().getLogger().severe( + ChatColor.RED + "Could not save " + ((file == null) ? "the file." : file.getName() + ".yml.")); + } + } + + public File getFile() { + return file; + } + + public FileConfiguration get() { + return config; + } +} diff --git a/Bukkit/src/me/poutineqc/cuberunner/utils/Permissions.java b/Bukkit/src/me/poutineqc/cuberunner/utils/Permissions.java new file mode 100644 index 0000000..19db6f1 --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/utils/Permissions.java @@ -0,0 +1,25 @@ +package me.poutineqc.cuberunner.utils; + +import org.bukkit.entity.Player; + +import me.poutineqc.cuberunner.CubeRunner; +import me.poutineqc.cuberunner.Language; +import me.poutineqc.cuberunner.Language.Messages; + +public class Permissions { + public static final String createSign = "cuberunner.admin.edit.sign"; + public static final String advancedInfo = "cuberunner.admin.info"; + + public static boolean hasPermission(String permission, Player player, boolean warning) { + if (player.hasPermission(permission)) + return true; + + if (warning) { + Language local = CubeRunner.get().getCRPlayer(player).getLanguage(); + local.sendMsg(player, local.get(Messages.ERROR_PERMISSION)); + } + + return false; + } + +} diff --git a/Bukkit/src/me/poutineqc/cuberunner/utils/Utils.java b/Bukkit/src/me/poutineqc/cuberunner/utils/Utils.java new file mode 100644 index 0000000..57f2aa2 --- /dev/null +++ b/Bukkit/src/me/poutineqc/cuberunner/utils/Utils.java @@ -0,0 +1,73 @@ +package me.poutineqc.cuberunner.utils; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import me.poutineqc.cuberunner.CubeRunner; + +public class Utils { + + public static Class getNMSClass(String nmsClassString) throws ClassNotFoundException { + if (!CubeRunner.NMS_VERSION.equals("v1_8_R1")) { + if (nmsClassString.equals("ChatSerializer")) + nmsClassString = "IChatBaseComponent$ChatSerializer"; + + if (nmsClassString.equals("EnumTitleAction")) + nmsClassString = "PacketPlayOutTitle$EnumTitleAction"; + } + + return Class.forName("net.minecraft.server." + CubeRunner.NMS_VERSION + "." + nmsClassString); + } + + private static void sendPacket(Player p, Object packet) { + try { + Object player = p.getClass().getMethod("getHandle").invoke(p); + Object connection = player.getClass().getField("playerConnection").get(player); + connection.getClass().getMethod("sendPacket", getNMSClass("Packet")).invoke(connection, packet); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void sendTitle(Player p, String title, String subtitle, int paramInt1, int paramInt2, int paramInt3) { + try { + Object titleEnum = getNMSClass("EnumTitleAction").getEnumConstants()[0]; + Object subtitleEnum = getNMSClass("EnumTitleAction").getEnumConstants()[1]; + + Object timePacket = getNMSClass("PacketPlayOutTitle").getConstructor(int.class, int.class, int.class) + .newInstance(paramInt1, paramInt2, paramInt3); + Object titlePacket = getNMSClass("PacketPlayOutTitle") + .getConstructor(getNMSClass("EnumTitleAction"), + getNMSClass("IChatBaseComponent")) + .newInstance(titleEnum, getJsonMessage(title)); + Object subtitlePacket = getNMSClass("PacketPlayOutTitle") + .getConstructor(getNMSClass("EnumTitleAction"), + getNMSClass("IChatBaseComponent")) + .newInstance(subtitleEnum, getJsonMessage(subtitle)); + + sendPacket(p, timePacket); + sendPacket(p, titlePacket); + sendPacket(p, subtitlePacket); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static Object getJsonMessage(String json) throws Exception { + return getNMSClass("ChatSerializer").getMethod("a", String.class).invoke(null, json); + } + + public static String color(String string) { + return ChatColor.translateAlternateColorCodes('&', string); + } + + public static boolean isEqualOnColorStrip(String l2, String l1) { + return ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', l1)) + .equalsIgnoreCase(ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', l2))); + } + + public static String strip(String string) { + return ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', string)); + } + +} diff --git a/Bukkit_1.8/LanguageFiles/de-De.yml b/Bukkit_1.8/LanguageFiles/de-De.yml deleted file mode 100644 index 3d46af9..0000000 --- a/Bukkit_1.8/LanguageFiles/de-De.yml +++ /dev/null @@ -1,174 +0,0 @@ -# CubeRunner plugin -# de-De.yml - Language file -# Made by EgoLeX - -# Language Name -languageName: "German" - -# Basic Messages -prefixShort: "&7[&5CR&7] " -prefixLong: "&7[&5CubeRunner&7] " -developper: "&5Erstellt durch: &7%developper%" -version: "&5Version: &7%version%" -description: "&dTippe &5/%command% help &d für eine Liste aller Kommandos." - -# Language Messages -languageList: "Verfügbare Sprachen" -languageNotFound: "&cSprache nicht gefunden. &8/%cmd% language &cfür eine Liste aller verfügbaren Sprachen" -languageChangeSuccess: "&aSprache erfolgreich auf Englisch gesetzt" - -# Errors and tips -missingPermission: "&4Du hast die nicht die benötigten Rechte um dies zu tun" -commandError: "&cKommando nicht gefunden. Tippe &8/%cmd% help &cfür eine Hilfe." -errorTeleport: "&cDu kannst dich nicht teleportieren während du dich im Spiel befindest. Tippe &7/cr quit &cum zu verlassen." -helpNoPermission: "&cDu hast keinerlei Rechte für die Kategorie." -toolInfoMissingName: "&cDu musst eine Arena auswählen." -toolInfoTip: "&8[&7Tipp&8] &7Du kannst auch &8/%cmd% list &7und rechtsklick machen um Informationen zu bekommen." - -# Player joining and leaving -playerAlreadyInGame: "&cDu bist bereits in einem CubeRunner Spiel." -playerNotInGame: "&cDu befindest dich derzeit in keinem CubeRunner Spiel." -playerJoinUnready: "&cDie Arena der du Beitreten wolltest exestiert anscheinend nicht" -playerJoinActive: "&cEs läuft derzeit ein Spiel in der Arena der du Beitreten wolltest." -playerJoinSpectator: "&dJoining als Zuschauer..." -playerJoinSuccess: "&aDu bist erfolgreich der Arena &2%arena%&a beigetreten." -playerJoinOthers: "&f%player% &dist der CubeRunners Arena beigetreten." -playerQuitSuccess: "&aDu hast die CubeRunners Arena &2%arena%&a verlassen." -playerQuitOthers: "&f%player% &dhat die CubeRunners Arena verlassen." - -# Active game messages -gameNotReady: "&cDas Spiel ist derzeit nicht bereit zum Starten" -arenaStartLessMin: "&cEs müssen mindestens %amount% Spieler in der Arena sein um das Spiel zu starten." -arenaStartLessMax: "&cEs dürfen maximal %amount% Spieler in der Arena sein um das Spiel zu starten." -gameCountdownStarted: "&dEin neues Spiel von &5CubeRunner &dwurde gefunden. Du kannst beitreten indem du folgendes Kommando verwendest: &5/cr join %arena%&d." -gameCountdownStopped: "&cDer Countdown wurde gestoppt. Nicht genügend Spieler." -gameCrushedPlayer: "&dDu bist mit einem Score von &5%score%&d rausgeflogen. Spiel Vorbei!" -gameCrushedOthers: "&f%player% &dist mit einem Score von &5%score%&d rausgeflogen." -gameEndingTeleport: "&dSpiel Vorbei. Teleport zurück in 5 Sekunden..." -gameEndingBest: "&6Glückwunsch an &f%player% &6welcher den neuen Highscore von &4%score% &6in der Arena &5%arena% hält." - -# Editing Arena Messages -missingArenaName: "&cDu musst einen Namen für deine Arena wählen." -arenaCreated: "&aEine Arena namens &2%arena% &awurde erfolgreich erstellt." -arenaAlreadyExist: "&cEine Arena namens &4%arena% &cexistiert bereits." -arenaNotExist: "&cEine Arena namens &4%arena% &cexistiert nicht." -arenaNotFound: "&cEine Arena namens &4%arena% &cwurde nicht gefunden." -reloadSuccess: "&aPlugin CubeRunner wurde erfolgreich reloaded." -missingEditArgument: "&cDu musst auswählen was du mit der Arena machen möchtest. Tippe &8/%cmd% help arena &cfür Hilfe." -missingWorldEditRegion: "&cDu musst erst eine WorldEdit Region festlegen." -arenaSetArena: "&aZone erfolgreich gesetzt für &2%arena%&a." -arenaSetStartPoint: "&aStartpunkt erfolgreich gesetzt für &2%arena%&a." -arenaSetLobby: "&aLobby erfolgreich gesetzt für &2%arena%&a." -arenaAmountPlayerMissingArgument: "&cDu musst eine Menge angeben um die Spieleranzahl zu ändern." -arenaAmountPlayerInvalidArgument: "&cDie Anzahl der Spieler die du angeben hast ist unbekannt. &7[&8%error%&7]" -arenaAmountPlayerNotANumber: "Keine gültige Nummer" -arenaAmountPlayerMinEqualZero: "Minimum weniger als 1" -arenaAmountPlayerMinBiggerMax: "Minimum größer als Maximum" -arenaAmountPlayerMaxBiggerMin: "Maximum kleiner als Minimum" -arenaAmountPlayerSuccess: "&aAnzahl an Spielern erfolgreich editiert für &2%arena%&a." -arenaDeleted: "&cArena entfernt." - -# GUI Messages -guiInstrictions: "&6Einleitung" -guiNextPage: "&2Nächste Seite" -guiPreviousPage: "&2Vorherige Seite" -guiJoinName: "&2Arena Liste" -guiJoinInfo: "&eKlicke auf den Namen der Arena zu der du möchtest." -guiJoinStarted: "&cAktiv : &eKlicke zum Zuschauen" -guiJoinReady: "&aBereit : &eKlicke zum Beitreten" -guiStatsName: "&6Stats" -guiStatsAverageDistancePerGame: "&bEigener Score pro Arena" -guiStatsTotalDistance: "&bTotale Distanz" -guiStatsGamePlayed: "&bgespielte Spiele" -guiStatsTotalPoints: "&bTotal Score" -guiStatsKills: "&bgetötete Spieler" -guiStatsMultiplayer: "&bMultiplayer Spiele gewonnen" -guiStatsTimePlayed: "&dSpielzeit" -guiStatsMoney: "&dGeldgewinn" -guiChallengeName: "&bHerausforderungen" -guiColorName: "&4Farbtool" -guiColorInfo: "&eDie ausgewählten Blöcke sind\n&edie derzeit ausgewählten.\n&eKlicke auf einen Block\n&eum In zu De/-Aktivieren." -guiColorEditWhileActive: "&cDu kannst die Farben nicht ändern während du Ingame bist." - -# Key Words -keyWordHelp: "Hilfe" -keyWordCategory: "Kategorie" -keyWordPage: "Seite" -keyWordHours: "Stunde" -keyWordMinutes: "Minute" -keyWordSeconds: "Sekunde" -keyWordDistance: "km" -keyWordAdvanced: "Erweiterte Information" -keyWordInformation: "Information" -keyWordMinimum: "Minimum" -keyWordMaximum: "Maximum" -keyWordCurrent: "Derzeitig" -keyWordAmountPlayer: "Spieleranzahl" -keyWordGameState: "Spielstatus" -keyWordUnset: "&7Arena Unset" -keyWordReady: "&aBereit" -keyWordStartup: "&9Anfang" -keyWordActive: "&cAktiv" -keyWordWorld: "Welt" -keyWordLobby: "Lobby" -keyWordStartPoint: "Startpunkt" -keyWordZoneMinPoint: " Zonen Koordinaten" -top10: "Top 10" -keyWordBestScore: "Bester Score" -keyWordBy: "von" -keyWordProgression: "Entwicklung" -keyWordCompleted: "Beendet" -keyWordNotCompleted: "nicht beendet" -keyWordReward: "Belohnung" - -# Signs -signNoPermission0: "&cDu hast nicht" -signNoPermission1: "&cdie benötigten Rechte" -signNoPermission2: "&cum ein DaC" -signNoPermission3: "&cSchild zu erstellen" -signNotValid1: "&cNone valid" -signNotValid2: "&cSchild Parameter" -signNotValid3: "&cVersuch es erneut" -signJoin: "&aBeitreten" -signQuit: "&cVerlassen" -signStartGame: "&9Spiel starten" -signOpenStats: "&6Statistiken" -signPlay: "&aSpielen" - -# Achievements -achievementCongrats: "&f%player% &6hat die Errungenschaft &d%achievementName%&6 erhalten!" -achievementAmountGame: "&dSpiele %amount% Spiele" -achievementTotalScore: "&dTotaler Score von %amount% erreichen" -achievementKills: "&dTöte %amount% Spieler" -achievementMultiplayerWon: "&dWin %amount% multiplayer game(s)" -achievementSurvive5Minutes: "&dÃœberlebe 5 Minuten" -reachHeight10: "&dErreiche eine Höhe von 10" -fillTheArena: "&dFülle den Arenaboden" -theAnswerToLife: "&dDie Antwort für das Leben, das Universum und alles andere" -achievementTheRageQuit: "&dDer Rage Quit" -achievementTheKillerBunny: "&dDer Todeshase" -achievementMoneyReward: "&dDu hast %amount%%currency% für die Errungenschaft bekommen." -achievementMoneyGame: "&dDu hast %amount%%currency% für das Ãœberleben von %amount2% Sekunden bekommen." - -# Help Messages -helpDescriptionAll: "&7Alle Kommandos" -helpDescriptionGeneral: "&7Generelle Spieler Kommandos" -helpDescriptionGame: "&7Kommandos für das einfach Spiel" -helpDescriptionArena: "&7Kommandos um die Arena zu erstellen" -helpDescriptionAdmin: "&7Admin Kommandos" -cmd-desc-list: "&7Öffnet eine Liste aller Kommandos." -cmd-desc-info: "&7Zeigt jede Information über eine Arena." -cmd-desc-language: "&7Änder deine eigene Sprache für das CubeRunners plugin." -cmd-desc-join: "&7Betrete ein spezifisches Spiel oder öffne die GUI." -cmd-desc-quit: "&7Verlasse dein derzeitiges Spiel." -cmd-desc-start: "&7Startcountdown eingeleitet." -cmd-desc-stats: "&7Öffnet deine CubeRunners Statistik." -cmd-desc-new: "&7Erstellt eine neue CubeRunners Arena." -cmd-desc-delete: "&7Lösche eine spezifische Arena." -cmd-desc-setzone: "&7Setze die Abgrenzung für eine spezifische Arena mit einer Worldedit Region." -cmd-desc-setlobby: "&7Setz die Lobby der spezifischen Arena." -cmd-desc-setstartpoint: "&7Setze den Startpunkt der Arena." -cmd-desc-setcolor: "&7Setz die Blockfarbe der Arena" -cmd-desc-setminplayer: "&7Setze die Minimale Spieleranzahl der Arena." -cmd-desc-setmaxplayer: "&7Setze die Maximale Spieleranzahl der Arena." -cmd-desc-reload: "&7Reloade die config, die Spieler Daten und die Sprachdatei." \ No newline at end of file diff --git a/Bukkit_1.8/LanguageFiles/en-US.yml b/Bukkit_1.8/LanguageFiles/en-US.yml deleted file mode 100644 index 200bf31..0000000 --- a/Bukkit_1.8/LanguageFiles/en-US.yml +++ /dev/null @@ -1,174 +0,0 @@ -# CubeRunner plugin -# Made by PoutineQc -# en-US.yml - Language file - -# Language Name -languageName: "English" - -# Basic Messages -prefixShort: "&7[&5CR&7] " -prefixLong: "&8[&5CubeRunner&8] " -developper: "&5Developped by: &7%developper%" -version: "&5Version: &7%version%" -description: "&dType &5/%command% help &d for the list of commands." - -# Language Messages -languageList: "Available languages" -languageNotFound: "&cLanguage not found. &8/%cmd% language &cfor a list of available languages" -languageChangeSuccess: "&aLanguage successfully set to english" - -# Errors and tips -missingPermission: "&4You don't have the permission to do this" -commandError: "&cCommand or arena not found. Type &8/%cmd% help &cfor help." -errorTeleport: "&cYou can't teleport away while you are in game. Do &7/cr quit &cto leave it." -helpNoPermission: "&cYou do not have any permissions in this category." -toolInfoMissingName: "&cYou need to choose an arena." -toolInfoTip: "&8[&7Tip&8] &7You may also do &8/%cmd% list &7and right click an arena to display it's information." - -# Player joining and leaving -playerAlreadyInGame: "&cYou are already in a CubeRunner game." -playerNotInGame: "&cYou are not currently in a CubeRunner game." -playerJoinUnready: "&cThe arena you are trying to join is not available." -playerJoinActive: "&cThere is already an active game in the arena you are trying to join." -playerJoinSpectator: "&dJoining as spectator..." -playerJoinSuccess: "&aYou have successfully joined the arena &2%arena%&a." -playerJoinOthers: "&f%player% &djoined your CubeRunner's arena." -playerQuitSuccess: "&aYou have left the CubeRunner's arena &2%arena%&a." -playerQuitOthers: "&f%player% &dleft your CubeRunner's arena." - -# Active game messages -gameNotReady: "&cThe game is not ready to start at the moment" -arenaStartLessMin: "&cThere must be at least %amount% players to start the game." -arenaStartLessMax: "&cThere must be at most %amount% players to start the game." -gameCountdownStarted: "&dA new game of &5CubeRunner &dhas been initiated. You may join with the command &5/cr join %arena%&d." -gameCountdownStopped: "&cThe countdown has been stopped. Not enough players in the game anymore." -gameCrushedPlayer: "&dYou have been crushed with a score of &5%score%&d. Game over!" -gameCrushedOthers: "&f%player% &dhas been crushed with a score of &5%score%&d." -gameEndingTeleport: "&dGame is over. Teleporting back in 5 seconds..." -gameEndingBest: "&6Congratulation to &f%player% &6who got the new best score of &4%score% &6in the arena &5%arena%" - -# Editing Arena Messages -missingArenaName: "&cYou must choose a name for your new arena." -arenaCreated: "&aAn arena named &2%arena% &ahas been successfully created." -arenaAlreadyExist: "&cAn arena named &4%arena% &calready exists." -arenaNotExist: "&cAn arena named &4%arena% &cdoes not exists." -arenaNotFound: "&cAn arena named &4%arena% &cwas not found." -reloadSuccess: "&aPlugin CubeRunner has been successfully reloaded." -missingEditArgument: "&cYou must choose what to do with this arena. Type &8/%cmd% help arena &cfor help." -missingWorldEditRegion: "&cYou must first choose a World Edit region." -arenaSetArena: "&aZone successfully set for the arena &2%arena%&a." -arenaSetStartPoint: "&aStart Point successfully set for the arena &2%arena%&a." -arenaSetLobby: "&aLobby successfully set for the arena &2%arena%&a." -arenaAmountPlayerMissingArgument: "&cYou must provide a quantity to change the amount of players." -arenaAmountPlayerInvalidArgument: "&cThe amount of player you entered is not valid. &7[&8%error%&7]" -arenaAmountPlayerNotANumber: "Not a number" -arenaAmountPlayerMinEqualZero: "Minimum lower than 1" -arenaAmountPlayerMinBiggerMax: "Minimum higher than maximum" -arenaAmountPlayerMaxBiggerMin: "Maximum lower than minimum" -arenaAmountPlayerSuccess: "&aAmount of player successfully edited for the arena &2%arena%&a." -arenaDeleted: "&cArena deleted." - -# GUI Messages -guiInstrictions: "&6Instructions" -guiNextPage: "&2Next Page" -guiPreviousPage: "&2Previous Page" -guiJoinName: "&2Arena List" -guiJoinInfo: "&eClick the name of the arena you wish to go to." -guiJoinStarted: "&cActive : &eClick to Spectate" -guiJoinReady: "&aReady : &eClick to Join" -guiStatsName: "&6Stats" -guiStatsAverageDistancePerGame: "&bAverage Score Per Game" -guiStatsTotalDistance: "&bTotal Distance Ran" -guiStatsGamePlayed: "&bGames played" -guiStatsTotalPoints: "&bTotal Score" -guiStatsKills: "&bPlayers Killed" -guiStatsMultiplayer: "&bMultiplayer games won" -guiStatsTimePlayed: "&dTime Played" -guiStatsMoney: "&dMoney Gained" -guiChallengeName: "&bChallenges" -guiColorName: "&4Color Picker" -guiColorInfo: "&eThe enchanted blocks are\nðe curently selected ones.\n&eClick a block to\n&eenable or disable it." -guiColorEditWhileActive: "&cYou can't edit the colors while a game is active." - -# Key Words -keyWordHelp: "Help" -keyWordCategory: "Category" -keyWordPage: "Page" -keyWordHours: "hours" -keyWordMinutes: "minutes" -keyWordSeconds: "seconds" -keyWordDistance: "km" -keyWordAdvanced: "Advanced Information" -keyWordInformation: "Information" -keyWordMinimum: "Minimum" -keyWordMaximum: "Maximum" -keyWordCurrent: "Current" -keyWordAmountPlayer: "amount of players" -keyWordGameState: "game state" -keyWordUnset: "&7Arena Unset" -keyWordReady: "&aReady" -keyWordStartup: "&9Startup" -keyWordActive: "&cActive" -keyWordWorld: "World" -keyWordLobby: "Lobby" -keyWordStartPoint: "Start point" -keyWordZoneMinPoint: " zone coordinate" -top10: "Top 10" -keyWordBestScore: "Best Score" -keyWordBy: "by" -keyWordProgression: "Progression" -keyWordCompleted: "Completed" -keyWordNotCompleted: "Not Completed" -keyWordReward: "Reward" - -# Signs -signNoPermission0: "&cYou don't have" -signNoPermission1: "&cthe permissions" -signNoPermission2: "&cto create a DaC" -signNoPermission3: "&csign, &4Sorry..." -signNotValid1: "&cNone valid" -signNotValid2: "&csign parameters" -signNotValid3: "&cTry again" -signJoin: "&aJoin Arena" -signQuit: "&cQuit Arena" -signStartGame: "&9Start Game" -signOpenStats: "&6Stats" -signPlay: "&aPlay" - -# Achievements -achievementCongrats: "&f%player% &6just completed the achievement &d%achievementName%&6!" -achievementAmountGame: "&dPlay %amount% game(s)" -achievementTotalScore: "&dReach total score of %amount%" -achievementKills: "&dKill %amount% player(s)" -achievementMultiplayerWon: "&dWin %amount% multiplayer game(s)" -achievementSurvive5Minutes: "&dSurvive 5 minutes" -reachHeight10: "&dReach height 10" -fillTheArena: "&dFill the arena's floor" -theAnswerToLife: "&dThe answer to life the universe and everything" -achievementTheRageQuit: "&dThe Rage Quit" -achievementTheKillerBunny: "&dThe Killer Bunny" -achievementMoneyReward: "&dYou gain %amount%%currency% for your achievement." -achievementMoneyGame: "&dYou gain %amount%%currency% for surviving %amount2% seconds." - -# Help Messages -helpDescriptionAll: "&7All Commands" -helpDescriptionGeneral: "&7General player commands" -helpDescriptionGame: "&7Commands to simply play the game" -helpDescriptionArena: "&7Commands to setup the arenas" -helpDescriptionAdmin: "&7Admin maintenance commands" -cmd-desc-list: "&7Opens a list of all the arenas." -cmd-desc-info: "&7Display every information from the selected arena." -cmd-desc-language: "&7Change your own language for CubeRunner's plugin." -cmd-desc-join: "&7Join the specified game or open a GUI to choose." -cmd-desc-quit: "&7Leave your current game." -cmd-desc-start: "&7Initiate the starting countdown." -cmd-desc-stats: "&7Opens your CubeRunner's stats." -cmd-desc-new: "&7Creates a new CubeRunner arena." -cmd-desc-delete: "&7Delete the specified arena." -cmd-desc-setzone: "&7Set the delimitation of the selected arena with a World Edit region." -cmd-desc-setlobby: "&7Set the lobby of the selected arena." -cmd-desc-setstartpoint: "&7Set the start point of the selected arena." -cmd-desc-setcolor: "&7Set the block colors for the arena" -cmd-desc-setminplayer: "&7Set the minimum amount of player for an arena." -cmd-desc-setmaxplayer: "&7Set the maximum amount of player for an arena." -cmd-desc-reload: "&7Reload the config, the player data and the language files." \ No newline at end of file diff --git a/Bukkit_1.8/LanguageFiles/fr-FR.yml b/Bukkit_1.8/LanguageFiles/fr-FR.yml deleted file mode 100644 index 762f4de..0000000 --- a/Bukkit_1.8/LanguageFiles/fr-FR.yml +++ /dev/null @@ -1,174 +0,0 @@ -# CubeRunner plugin -# Made by PoutineQc -# fr-FR.yml - Language file - -# Language Name -languageName: "Francais" - -# Basic Messages -prefixShort: "&7[&5CR&7] " -prefixLong: "&8[&5CubeRunner&8] " -developper: "&5Developpé par: &7%developper%" -version: "&5Version: &7%version%" -description: "&dTape &5/%command% help &d pour la liste des commandes." - -# Language Messages -languageList: "Langues disponibles" -languageNotFound: "&cLangue non-trouvée. &8/%cmd% language &cpour une liste des langues disponibles" -languageChangeSuccess: "&aLangue changée avec succès au francais" - -# Errors and tips -missingPermission: "&4Tu n'a pas la permission de faire cela." -commandError: "&cCommande ou arène introuvable. Tape &8/%cmd% help &cpour de la liste des commandes." -errorTeleport: "&cTu ne peux pas te téléporter en cours de partie. Fais &7/cr quit &cpour quiter" -helpNoPermission: "&cTu n'as aucune permission dans cette catégorie." -toolInfoMissingName: "&cIl faut spécifier une arène." -toolInfoTip: "&8[&7Truc&8] &7Tu peux aussi faire &8/%cmd% list &7et effectuer un clic droit sur une arène pour afficher ses informations." - -# Player joining and leaving -playerAlreadyInGame: "&cTu es déja dans une partie de CubeRunner." -playerNotInGame: "&cTu n'es pas dans une partie de CubeRunner." -playerJoinUnready: "&cL'arène que tu essaie de joindre n'est pas disponible." -playerJoinActive: "&cUne partie est déja en cours dans cette arène." -playerJoinSpectator: "&dPartie rejointe en tant que spectateur." -playerJoinSuccess: "&aTu as rejoint l'arène &2%arena%&a." -playerJoinOthers: "&f%player% &da rejoint votre partie." -playerQuitSuccess: "&aTu as quitté l'arène &2%arena%&a." -playerQuitOthers: "&f%player% &da quitté votre partie." - -# Active game messages -gameNotReady: "&cLa partie n'est pas prête a commencer." -arenaStartLessMin: "&cIl doit y avoir au moins %amount% joueurs pour commencer la partie." -arenaStartLessMax: "&cIl doit y avoir au plus %amount% joueurs pour commencer la partie." -gameCountdownStarted: "&dUne nouvelle partie de &5CubeRunner &dva commencer sous peu. Vous pouvez la rejoindre avec &5/cr join %arena%&d." -gameCountdownStopped: "&cLe décompte a été annulé. Il n'y a plus assez de joueurs." -gameCrushedPlayer: "&dTu t'es fait écraser avec un score de &5%score%&d. Game over!" -gameCrushedOthers: "&f%player% &ds'est fait écraser avec un score de &5%score%&d." -gameEndingTeleport: "&dLa partie est finie. Vous serez téléportés dans 5 secondes..." -gameEndingBest: "&6Bravo à &f%player% &6qui a fait le nouveau record de &4%score% &6dans l'arène &5%arena%" - -# Editing Arena Messages -missingArenaName: "&cTu dois spécifier un nom pour l'arène." -arenaCreated: "&aUne arène appelée &2%arena% &aà été créé." -arenaAlreadyExist: "&cIl y a déja une arène appelée &4%arena%&c." -arenaNotExist: "&cL'arène &4%arena% &cn'existe pas." -arenaNotFound: "&cUne arène nommée &4%arena% &cn'a pas été trouvée." -reloadSuccess: "&aLe plugin CubeRunner a été relancé avec succès." -missingEditArgument: "&cVous devez spécifier quoi faire avec cette arène. Tape &8/%cmd% help arena &cpour de l'aide." -missingWorldEditRegion: "&cTu dois sélectionner une région World Edit." -arenaSetArena: "&aLa zone a été sélectionnée avec succès pour l'arène &2%arena%&a." -arenaSetStartPoint: "&aLe point de départ a été sélectionné avec succès pour l'arène &2%arena%&a." -arenaSetLobby: "&aLa salle d'attente a été séléctionnée avec succès pour l'arène &2%arena%&a." -arenaAmountPlayerMissingArgument: "&cTu dois nommer une quantitée pour changer le nombre de joueurs." -arenaAmountPlayerInvalidArgument: "&cCe nombre de joueurs n'est pas valide. &7[&8%error%&7]" -arenaAmountPlayerNotANumber: "Pas un nombre" -arenaAmountPlayerMinEqualZero: "Minimum plus petit que 1" -arenaAmountPlayerMinBiggerMax: "Minimum plus haut que le maximum" -arenaAmountPlayerMaxBiggerMin: "Maximum plus bas que le minimum" -arenaAmountPlayerSuccess: "&aNombre de joueurs changé pour l'arène &2%arena%&a." -arenaDeleted: "&cArène supprimée." - -# GUI Messages -guiInstrictions: "&6Instructions" -guiNextPage: "&2Prochaine page" -guiPreviousPage: "&2Page précédente" -guiJoinName: "&2Arènes" -guiJoinInfo: "&eClick le nom de l'arène que tu souhaites joindre." -guiJoinStarted: "&cEn cours de partie : &eClique pour assister" -guiJoinReady: "&aPrête : &eClique pour rejoindre" -guiStatsName: "&6Statistiques" -guiStatsAverageDistancePerGame: "&bScore moyen par partie" -guiStatsTotalDistance: "&bDistance totale courue" -guiStatsGamePlayed: "&bParties jouées" -guiStatsTotalPoints: "&bScore total" -guiStatsKills: "&bJoueurs tués" -guiStatsMultiplayer: "&bParties multijoueurs gagnées" -guiStatsTimePlayed: "&dTemps joué" -guiStatsMoney: "&dArgent gagné" -guiChallengeName: "&bDéfis" -guiColorName: "&4Couleurs" -guiColorInfo: "&eLes blocs séléctionnés\n&esont ceux enchantés.\n&eCliquez sur un bloc\n&epour l'activer ou le désactiver." -guiColorEditWhileActive: "&cTu ne peux pas changer les couleur alors qu'il y a une partie en cours." - -# Key Words -keyWordHelp: "Aide" -keyWordCategory: "Catégorie" -keyWordPage: "Page" -keyWordHours: "heures" -keyWordMinutes: "minutes" -keyWordSeconds: "secondes" -keyWordDistance: "km" -keyWordAdvanced: "Information Avancé" -keyWordInformation: "Information" -keyWordMinimum: "Minimum" -keyWordMaximum: "Maximum" -keyWordCurrent: "Actuel" -keyWordAmountPlayer: "nombre de joueurs" -keyWordGameState: "état du jeu" -keyWordUnset: "&7Arène non définie" -keyWordReady: "&aPrêt" -keyWordStartup: "&9Démarrage" -keyWordActive: "&cActif" -keyWordWorld: "Monde" -keyWordLobby: "Salle d'attente" -keyWordStartPoint: "Point de départ" -keyWordZoneMinPoint: " coordonée de zone" -top10: "Top 10" -keyWordBestScore: "Meilleur Score" -keyWordBy: "par" -keyWordProgression: "Progression" -keyWordCompleted: "Complété" -keyWordNotCompleted: "Non Complété" -keyWordReward: "Récompense" - -# Signs -signNoPermission0: "&cManque perms" -signNoPermission1: "&cpour faire" -signNoPermission2: "&cdes pancartes" -signNoPermission3: "&cCubeRunner." -signNotValid1: "&cParamètres" -signNotValid2: "&cnon-valides" -signNotValid3: "&cRéessayez" -signJoin: "&aRejoindre" -signQuit: "&cQuitter" -signStartGame: "&9Commencer" -signOpenStats: "&6Statistiques" -signPlay: "&aJouer" - -# Achievements -achievementCongrats: "&f%player% &6a complété le défi &d%achievementName%&6!" -achievementAmountGame: "&dJouer %amount% partie(s)" -achievementTotalScore: "&dAtteidre le score total de %amount%" -achievementKills: "&dTuer %amount% joueur(s)" -achievementMultiplayerWon: "&dGagner %amount% partie(s) multijoueurs" -achievementSurvive5Minutes: "&dSurvivre 5 minutes" -reachHeight10: "&dAtteindre la hauteur 10" -fillTheArena: "&dRemplir le plancher de l'arène" -theAnswerToLife: "&dLa réponse à la vie, à l'univers et à l'humanité" -achievementTheRageQuit: "&dLe Rage Quit!" -achievementTheKillerBunny: "&dLe lapin tueur" -achievementMoneyReward: "&dTu a gagné %amount%%currency% pour ton défi." -achievementMoneyGame: "&dTu gagne %amount%%currency% pour avoir survécu %amount2% secondes." - -# Help Messages -helpDescriptionAll: "&7Toutes les commandes" -helpDescriptionGeneral: "&7Commandes générales pour joueurs" -helpDescriptionGame: "&7Commandes pour jouer au jeu" -helpDescriptionArena: "&7Commandes pour configurer les arènes" -helpDescriptionAdmin: "&7Commandes pour la maintenance du jeu" -cmd-desc-list: "&7Ouvre la liste des arènes." -cmd-desc-info: "&7Montre les informations de l'arène séléctionnée." -cmd-desc-language: "&7Change ton language personnel pour le plugin CubeRunner." -cmd-desc-join: "&7Rejoins la partie spécifiée ou ouvre un GUI pour choisir." -cmd-desc-quit: "&7Quitte la partie en cours." -cmd-desc-start: "&7Commence le décompte de démarrage." -cmd-desc-stats: "&7Ouvre les statistiques CubeRunner." -cmd-desc-new: "&7Crée une nouvelle arène CubeRunner." -cmd-desc-delete: "&7Supprime l'arène specifiée." -cmd-desc-setzone: "&7Configure la délimitation de l'arène en utilisant une région WorldEdit." -cmd-desc-setlobby: "&7Configure la salle d'attente de l'arène séléctionnée." -cmd-desc-setstartpoint: "&7Configure le point de départ de l'arène séléctionnée." -cmd-desc-setcolor: "&7Séléctionne les couleurs dans l'arène séléctionnée" -cmd-desc-setminplayer: "&7Configure le nombre de joueurs minimum pour l'arène séléctionée." -cmd-desc-setmaxplayer: "&7Configure le nombre de joueurs maximum pour l'arène séléctionée." -cmd-desc-reload: "&7Relance le fichier de config, le player data et les fichiers de langues." \ No newline at end of file diff --git a/Bukkit_1.8/achievements.yml b/Bukkit_1.8/achievements.yml deleted file mode 100644 index 97cb751..0000000 --- a/Bukkit_1.8/achievements.yml +++ /dev/null @@ -1,32 +0,0 @@ -# File to edit the achievements -# Maximum of 7 achievements per categories -# Minimum of 0 if you want to disable them -# Don't worry about this file if you have set -# the economy rewards to false in the config. - -# How to use: -# - amount_to_achieve;reward amount - -amountOfGamesPlayed: - - 10;10.0 - - 50;50.0 - - 150;200.0 - - 500;1000.0 - -totalScore: - - 100;5.0 - - 1000;40.0 - - 3600;100.0 - - 15000;750.0 - -amountPlayerKills: - - 1;5.0 - - 5;10.0 - - 20;50.0 - - 100;200.0 - -multiplayerGamesWon: - - 2;5.0 - - 20;40.0 - - 75;100.0 - - 250;300.0 \ No newline at end of file diff --git a/Bukkit_1.8/commands.yml b/Bukkit_1.8/commands.yml deleted file mode 100644 index 66b03a0..0000000 --- a/Bukkit_1.8/commands.yml +++ /dev/null @@ -1,69 +0,0 @@ -commands: - general: - language: - usage: "/%command% language " - description: "cmd-desc-language" - permission: "cuberunner.player.language" - stats: - usage: "/%command% stats" - description: "cmd-desc-stats" - permission: "cuberunner.player.stats" - game: - list: - usage: "/%command% list" - description: "cmd-desc-list" - permission: "cuberunner.player.list" - info: - usage: "/%command% info " - description: "cmd-desc-info" - permission: "cuberunner.player.info" - join: - usage: "/%command% join [arena]" - description: "cmd-desc-join" - permission: "cuberunner.player.play.join" - quit: - usage: "/%command% quit" - description: "cmd-desc-quit" - permission: "cuberunner.player.play.quit" - start: - usage: "/%command% start" - description: "cmd-desc-start" - permission: "cuberunner.player.play.start" - arena: - new: - usage: "/%command% new " - description: "cmd-desc-new" - permission: "cuberunner.admin.edit.new" - delete: - usage: "/%command% delete" - description: "cmd-desc-delete" - permission: "cuberunner.admin.edit.delete" - setzone: - usage: "/%command% setzone" - description: "cmd-desc-setzone" - permission: "cuberunner.admin.edit.zone" - setlobby: - usage: "/%command% setlobby" - description: "cmd-desc-setlobby" - permission: "cuberunner.admin.edit.lobby" - setstartpoint: - usage: "/%command% setstartpoint" - description: "cmd-desc-setstartpoint" - permission: "cuberunner.admin.edit.startpoint" - setminplayer: - usage: "/%command% setminplayer " - description: "cmd-desc-setminplayer" - permission: "cuberunner.admin.edit.amountplayer.minplayer" - setmaxplayer: - usage: "/%command% setmaxplayer " - description: "cmd-desc-setmaxplayer" - permission: "cuberunner.admin.edit.amountplayer.maxplayer" - setcolor: - usage: "/%command% setcolor" - description: "cmd-desc-setcolor" - permission: "cuberunner.admin.edit.color" - admin: - reload: - usage: "/%command% reload" - description: "cmd-desc-reload" - permission: "cuberunner.admin.reload" \ No newline at end of file diff --git a/Bukkit_1.8/config.yml b/Bukkit_1.8/config.yml deleted file mode 100644 index 9bd43b5..0000000 --- a/Bukkit_1.8/config.yml +++ /dev/null @@ -1,52 +0,0 @@ -# CubeRunner plugin -# Made by PoutineQc -# config.yml - Config File -# Version: DO NOT edit this -version: '1.0' - -# Currently available languages: "fr-FR", "en-US" -# You may make another YAML file with another language -# Simply put it in the LanguageFiles folder and write it's name here (without the ".yml") -# This will option will be the " DaC server language".. The signs will be in this language. -# Warning: If you change this, a simple /dac reload won't do, you'll have to restart the server. -language: 'en-US' - -# Set to true if you have a MySQL database and fill the information below -mysql: false -host: 127.0.0.1 -port: 3306 -user: '' -password: '' -database: 'minecraft' -tablePrefix: 'cuberunner_' - -# If you want the Plugin's "logo" ([cr] if not changed) to be displayed in front of every messages -prefixInFrontOfEveryMessages: true - -# The countdown from the moment a players starts the game to the beginning of the block shower. (in seconds) -# Players may still join the game during this countdown -countdownTime: 15 - -# Set to true if you want players to get back to their original location before the teleport to the arena -teleportAfterEnding: true - -# Requires Vault and an economy plugin -economyRewards: false - -# Choose the reward amounts depending on the values of your server's economy -pricePerScore: 0.05 - -# if true, when completing a challenge gives a money reward -# will be false in all cases if you disable the economy rewards -achievementsRewards: true - -# To edit the GamePlayed challenges, Win challenges, Lost Challenge and DaCsDone challenges -# Go in the achievements.yml file in the plugin/DeACoudre folder - -# Challenge Rewards -rewardSurvive5Minutes: 25.0 -rewardFillTheArenasFloor: 50.0 -rewardReachHeight10: 100.0 -rewardTheRageQuit: 15.0 -rewardTheKillerBunny: 15.0 -rewardTheAnswerToLife: 15.0 \ No newline at end of file diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/Configuration.java b/Bukkit_1.8/src/me/poutineqc/cuberunner/Configuration.java deleted file mode 100644 index 5c10450..0000000 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/Configuration.java +++ /dev/null @@ -1,84 +0,0 @@ -package me.poutineqc.cuberunner; - -import java.io.File; - -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.plugin.Plugin; - - -public class Configuration { - - private FileConfiguration config; - private File configFile; - - public String version; - public String language; - - public boolean mysql; - public String host; - public int port; - public String user; - public String password; - public String database; - public String tablePrefix; - - public boolean prefixInFrontOfEveryMessages; - public int countdownTime; - public boolean teleportAfterEnding; - - public boolean economyRewards; - public double pricePerScore; - public boolean achievementsRewards; - public double rewardSurvive5Minutes; - public double rewardFillTheArenasFloor; - public double rewardReachHeight10; - public double rewardTheRageQuit; - public double rewardTheKillerBunny; - public double rewardTheAnswerToLife; - - public Configuration(CubeRunner plugin) { - configFile = new File(plugin.getDataFolder(), "config.yml"); - - if (!configFile.exists()) - plugin.saveDefaultConfig(); - - loadConfiguration(plugin); - } - - public void loadConfiguration(Plugin plugin) { - config = YamlConfiguration.loadConfiguration(configFile); - - version = config.getString("version"); - language = config.getString("language", "en-US"); - - mysql = config.getBoolean("mysql", false); - if (mysql) { - host = config.getString("host", "127.0.0.1"); - if (host.equalsIgnoreCase("localhost")) - host = "127.0.0.1"; - - port = config.getInt("host", 3306); - user = config.getString("user"); - password = config.getString("password"); - database = config.getString("database"); - tablePrefix = config.getString("tablePrefix", "cuberunner_"); - } - - prefixInFrontOfEveryMessages = config.getBoolean("prefixInFrontOfEveryMessages", true); - countdownTime = config.getInt("countdownTime", 15); - teleportAfterEnding = config.getBoolean("teleportAfterEnding", true); - - economyRewards = config.getBoolean("economyRewards", false); - - pricePerScore = config.getDouble("pricePerScore", 0.05); - achievementsRewards = config.getBoolean("achievementsRewards"); - rewardSurvive5Minutes = config.getDouble("rewardSurvive5Minutes", 25.0); - rewardFillTheArenasFloor = config.getDouble("rewardFillTheArenasFloor", 50.0); - rewardReachHeight10 = config.getDouble("rewardReachHeight10", 100.0); - rewardTheRageQuit = config.getDouble("rewardTheRageQuit", 15.0); - rewardTheKillerBunny = config.getDouble("rewardTheKillerBunny", 15.0); - rewardTheAnswerToLife = config.getDouble("rewardTheAnswerToLife", 15.0); - } - -} diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/CubeRunner.java b/Bukkit_1.8/src/me/poutineqc/cuberunner/CubeRunner.java deleted file mode 100644 index 8ee6f8f..0000000 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/CubeRunner.java +++ /dev/null @@ -1,251 +0,0 @@ -package me.poutineqc.cuberunner; - -import java.io.IOException; -import java.util.logging.Logger; - -import org.bukkit.Bukkit; -import org.bukkit.plugin.PluginDescriptionFile; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.RegisteredServiceProvider; -import org.bukkit.plugin.java.JavaPlugin; - -import me.poutineqc.cuberunner.achievements.AchievementGUI; -import me.poutineqc.cuberunner.achievements.Achievements; -import me.poutineqc.cuberunner.achievements.PlayerMovement; -import me.poutineqc.cuberunner.achievements.TopManager; -import me.poutineqc.cuberunner.commands.CubeRunnerCommand; -import me.poutineqc.cuberunner.commands.PlayerCommands; -import me.poutineqc.cuberunner.commands.PlayerInteract; -import me.poutineqc.cuberunner.commands.SignPlace; -import me.poutineqc.cuberunner.games.Arena; -import me.poutineqc.cuberunner.games.ColorGUI; -import me.poutineqc.cuberunner.games.PlayerDamage; -import me.poutineqc.cuberunner.games.PlayerDisconnect; -import me.poutineqc.cuberunner.games.PlayerTeleport; -import me.poutineqc.cuberunner.tools.JoinGUI; -import net.milkbowl.vault.economy.Economy; - -public class CubeRunner extends JavaPlugin { - - private Configuration config; - private MySQL mysql = new MySQL(); - private ArenaData arenaData; - private PlayerData playerData; - private TopManager topManager; - private Achievements achievements; - private AchievementGUI achievementsGui; - private JoinGUI joinGui; - private ColorGUI colorGUI; - private PlayerCommands playerCommands; - - private static Economy economy; - - public void onEnable() { - final PluginDescriptionFile pdfFile = getDescription(); - final Logger logger = getLogger(); - - config = new Configuration(this); - if (!initialiseEconomy()) - return; - new CubeRunnerCommand(this); - loadLanguages(); - connectMySQL(); - arenaData = new ArenaData(this); - playerData = new PlayerData(this); - topManager = new TopManager(this); - achievements = new Achievements(this); - achievementsGui = new AchievementGUI(this); - joinGui = new JoinGUI(this); - colorGUI = new ColorGUI(this); - new Arena(this); - new Permissions(this); - - playerCommands = new PlayerCommands(this); - enableListeners(); - getCommand("cuberunner").setExecutor(playerCommands); - - try { - Metrics metrics; - metrics = new Metrics(this); - metrics.start(); - } catch (IOException e) { - e.printStackTrace(); - } - - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() { - public void run() { - if (!playerData.isLatestVersion()) { - logger.info("----------------------------"); - logger.info("CubeRunner Updater"); - logger.info(""); - logger.info("An update for CubeRunner has been found!"); - logger.info("CubeRunner " + playerData.getLatestVersion()); - logger.info("You are running " + pdfFile.getVersion()); - logger.info(""); - logger.info("Download at https://www.spigotmc.org/resources/cuberunner.19715/"); - logger.info("----------------------------"); - } - Arena.loadExistingArenas(); - } - }, 1L); - - logger.info(pdfFile.getName() + " has been enabled (v" + pdfFile.getVersion() + ")"); - } - - public void onDisable() { - PluginDescriptionFile pdfFile = getDescription(); - Logger logger = getLogger(); - - if (mysql.hasConnection()) - mysql.close(); - - logger.info(pdfFile.getName() + " has been diabled"); - } - - public void connectMySQL() { - if (config.mysql) { - mysql = new MySQL(this, config.host, config.port, config.database, config.user, config.password); - - if (mysql.hasConnection()) - createMySQLTables(); - } else { - mysql = new MySQL(this); - } - } - - private void createMySQLTables() { - mysql.update("CREATE TABLE IF NOT EXISTS " + config.tablePrefix + "ARENAS (name varchar(32),world varchar(32)," - + "minAmountPlayer INT DEFAULT 1, maxAmountPlayer INT DEFAULT 8, highestScore INT DEFAULT 0," - + "colorIndice LONG, highestPlayer varchar(32) DEFAULT 'null'," - + "minPointX INT DEFAULT 0,minPointY INT DEFAULT 0,minPointZ INT DEFAULT 0," - + "maxPointX INT DEFAULT 0, maxPointY INT DEFAULT 0,maxPointZ INT DEFAULT 0," - + "lobbyX DOUBLE DEFAULT 0,lobbyY DOUBLE DEFAULT 0,lobbyZ DOUBLE DEFAULT 0," - + "lobbyPitch FLOAT DEFAULT 0,lobbyYaw FLOAT DEFAULT 0," - + "startPointX DOUBLE DEFAULT 0,startPointY DOUBLE DEFAULT 0,startPointZ DOUBLE DEFAULT 0," - + "startPointPitch FLOAT DEFAULT 0,startPointYaw FLOAT DEFAULT 0);"); - mysql.update("ALTER TABLE " + config.tablePrefix + "ARENAS CONVERT TO CHARACTER SET utf8;"); - mysql.update("CREATE TABLE IF NOT EXISTS " + config.tablePrefix - + "PLAYERS (UUID varchar(64), name varchar(64), language varchar(32), timePlayed INT DEFAULT 0," - + "money DOUBLE DEFAULT 0, averageDistancePerGame DOUBLE DEFAULT 0, totalDistance DOUBLE DEFAULT 0," - + "games INT DEFAULT 0, totalScore INT DEFAULT 0, kills INT DEFAULT 0, multiplayerWon INT DEFAULT 0," - + "survive5Minutes BOOLEAN DEFAULT FALSE, reachHeight10 BOOLEAN DEFAULT FALSE," - + "fillTheArena BOOLEAN DEFAULT FALSE, theAnswerToLife BOOLEAN DEFAULT FALSE," - + "theRageQuit BOOLEAN DEFAULT FALSE, theKillerBunny BOOLEAN DEFAULT FALSE);"); - mysql.update("ALTER TABLE " + config.tablePrefix + "PLAYERS CONVERT TO CHARACTER SET utf8;"); - mysql.update("CREATE OR REPLACE VIEW " + config.tablePrefix - + "AVERAGESCORE AS SELECT name, averageDistancePerGame FROM " + config.tablePrefix - + "PLAYERS ORDER BY averageDistancePerGame DESC LIMIT 10"); - mysql.update( - "CREATE OR REPLACE VIEW " + config.tablePrefix + "TOTALDISTANCE AS SELECT name, totalDistance FROM " - + config.tablePrefix + "PLAYERS ORDER BY totalDistance DESC LIMIT 10"); - mysql.update("CREATE OR REPLACE VIEW " + config.tablePrefix + "MOSTGAMES AS SELECT name, games FROM " - + config.tablePrefix + "PLAYERS ORDER BY games DESC LIMIT 10"); - mysql.update("CREATE OR REPLACE VIEW " + config.tablePrefix + "TOTALSCORE AS SELECT name, totalScore FROM " - + config.tablePrefix + "PLAYERS ORDER BY totalScore DESC LIMIT 10"); - mysql.update("CREATE OR REPLACE VIEW " + config.tablePrefix + "KILLS AS SELECT name, kills FROM " - + config.tablePrefix + "PLAYERS ORDER BY kills DESC LIMIT 10"); - mysql.update( - "CREATE OR REPLACE VIEW " + config.tablePrefix + "MULTIPLAYERWON AS SELECT name, multiplayerWon FROM " - + config.tablePrefix + "PLAYERS ORDER BY multiplayerWon DESC LIMIT 10"); - } - - public void loadLanguages() { - Language.clearLanguages(); - - // A CHANGER AVANT LA RELEASE - new Language(this); - new Language("en-US", false); - new Language("fr-FR", false); - new Language("de-De", false); - new Language(config.language, false); - } - - public boolean initialiseEconomy() { - if (config.economyRewards) - if (!setupEconomy()) { - getLogger().warning("Vault not found."); - getLogger().warning("Add Vault to your plugins or disable monetary rewards in the config."); - getLogger().info("Disabling CubeRunner..."); - getServer().getPluginManager().disablePlugin(this); - return false; - } - return true; - } - - private boolean setupEconomy() { - economy = null; - if (getServer().getPluginManager().getPlugin("Vault") == null) { - return false; - } - RegisteredServiceProvider rsp = getServer().getServicesManager().getRegistration(Economy.class); - if (rsp == null) { - return false; - } - economy = rsp.getProvider(); - return economy != null; - } - - public static boolean isEconomyEnabled() { - return economy != null; - } - - public static Economy getEconomy() { - return economy; - } - - private void enableListeners() { - PluginManager pm = getServer().getPluginManager(); - - pm.registerEvents(playerData, this); - pm.registerEvents(new PlayerDamage(this), this); - pm.registerEvents(new PlayerTeleport(this), this); - pm.registerEvents(new PlayerDisconnect(this), this); - pm.registerEvents(new SignPlace(this), this); - pm.registerEvents(new PlayerInteract(this), this); - pm.registerEvents(new PlayerMovement(this), this); - pm.registerEvents(achievementsGui, this); - pm.registerEvents(joinGui, this); - pm.registerEvents(colorGUI, this); - } - - public Configuration getConfiguration() { - return config; - } - - public MySQL getMySQL() { - return mysql; - } - - public ArenaData getArenaData() { - return arenaData; - } - - public PlayerData getPlayerData() { - return playerData; - } - - public JoinGUI getJoinGui() { - return joinGui; - } - - public AchievementGUI getAchievementsGui() { - return achievementsGui; - } - - public PlayerCommands getPlayerCommands() { - return playerCommands; - } - - public Achievements getAchievements() { - return achievements; - } - - public TopManager getTopManager() { - return topManager; - } - - public ColorGUI getColorGUI() { - return colorGUI; - } - -} diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/Language.java b/Bukkit_1.8/src/me/poutineqc/cuberunner/Language.java deleted file mode 100644 index 29dd745..0000000 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/Language.java +++ /dev/null @@ -1,384 +0,0 @@ -package me.poutineqc.cuberunner; - -import java.io.File; -import java.io.InputStream; -import java.util.HashMap; -import java.util.Map.Entry; - -import org.bukkit.ChatColor; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; - -import me.poutineqc.cuberunner.commands.CubeRunnerCommand; -import me.poutineqc.cuberunner.games.User; -import me.poutineqc.cuberunner.tools.CaseInsensitiveMap; - -public class Language { - - private static CubeRunner plugin; - private static Configuration config; - - private static File langFolder; - - private File languageFile; - private FileConfiguration languageData; - - private static HashMap languages = new HashMap<>(); - private CaseInsensitiveMap commandDescriptions; - - public String languageName; - public String prefixShort; - public String prefixLong; - public String developper; - public String version; - public String description; - - public String errorPermission; - public String errorCommand; - public String errorTeleport; - public String helpNoPermission; - public String toolInfoMissingName; - public String toolInfoTip; - - public String playerAlreadyInGame; - public String playerNotInGame; - public String playerJoinUnready; - public String playerJoinActive; - public String playerJoinSpectator; - public String playerJoinSuccess; - public String playerJoinOthers; - public String playerQuitSuccess; - public String playerQuitOthers; - - public String gameNotReady; - public String gameStartLessMin; - public String gameStartLessMax; - public String gameCountdownStarted; - public String gameCountdownStopped; - public String gameCrushedPlayer; - public String gameCrushedOthers; - - public String endingTeleport; - public String endingBest; - - public String missingArenaName; - public String arenaCreated; - public String arenaAlreadyExist; - public String arenaNotExist; - public String arenaNotFound; - public String reloadSuccess; - public String missingEditArgument; - public String missingWorldEditRegion; - public String arenaSetArena; - public String arenaSetStartPoint; - public String arenaSetLobby; - public String arenaAmountPlayerMissingArgument; - public String arenaAmountPlayerInvalidArgument; - public String arenaAmountPlayerNotANumber; - public String arenaAmountPlayerMinEqualZero; - public String arenaAmountPlayerMinBiggerMax; - public String arenaAmountPlayerMaxBiggerMin; - public String arenaAmountPlayerSuccess; - public String arenaDeleted; - - public String guiInstrictions; - public String guiNextPage; - public String guiPreviousPage; - - public String guiJoinName; - public String guiJoinInfo; - public String guiJoinStarted; - public String guiJoinReady; - public String guiStatsName; - public String guiStatsAverageDistancePerGame; - public String guiStatsTotalDistance; - public String guiStatsGamePlayed; - public String guiStatsTotalPoints; - public String guiStatsKills; - public String guiStatsMultiplayer; - public String guiStatsTimePlayed; - public String guiStatsMoney; - public String guiChallengeName; - public String guiColorName; - public String guiColorInfo; - public String guiColorEditWhileActive; - - public String keyWordHelp; - public String keyWordCategory; - public String keyWordPage; - public String keyWordHours; - public String keyWordMinutes; - public String keyWordSeconds; - public String keyWordDistance; - public String keyWordInformation; - public String keyWordAdvanced; - public String keyWordMinimum; - public String keyWordMaximum; - public String keyWordCurrent; - public String keyWordAmountPlayer; - public String keyWordGameState; - public String keyWordUnset; - public String keyWordReady; - public String keyWordStartup; - public String keyWordActive; - public String keyWordWorld; - public String keyWordLobby; - public String keyWordStartPoint; - public String keyWordZone; - public String keyWordTop10; - public String keyWordBestScore; - public String keyWordBy; - public String keyWordProgression; - public String keyWordCompleted; - public String keyWordNotCompleted; - public String keyWordReward; - - public String helpDescriptionAll; - public String helpDescriptionGeneral; - public String helpDescriptionGame; - public String helpDescriptionArena; - public String helpDescriptionAdmin; - - public String signNoPermission0; - public String signNoPermission1; - public String signNoPermission2; - public String signNoPermission3; - public String signNotValid1; - public String signNotValid2; - public String signNotValid3; - public String signStartGame; - public String signOpenStats; - public String signQuit; - public String signJoin; - public String signPlay; - - public String achievementCongrats; - public String achievementAmountGame; - public String achievementTotalScore; - public String achievementKills; - public String achievementMultiplayerWon; - public String achievementSurvive5Minutes; - public String achievementReachHeight10; - public String achievementFillTheArena; - public String achievementTheAnswerToLife; - public String achievementTheRageQuit; - public String achievementTheKillerBunny; - public String achievementMoneyReward; - public String achievementMoneyGame; - - public String languageList; - public String languageNotFound; - public String languageChangeSuccess; - - public Language(CubeRunner plugin) { - Language.plugin = plugin; - config = plugin.getConfiguration(); - - langFolder = new File(plugin.getDataFolder(), "LanguageFiles"); - if (!langFolder.exists()) - langFolder.mkdir(); - } - - public Language(String fileName, boolean forceFileOverwrite) { - languageFile = new File(langFolder.getPath(), fileName + ".yml"); - if (forceFileOverwrite) { - languageFile.delete(); - plugin.saveResource("LanguageFiles/" + fileName + ".yml", false); - } - - if (!languageFile.exists()) { - InputStream local = plugin.getResource("LanguageFiles/" + fileName + ".yml"); - if (local != null) { - plugin.saveResource("LanguageFiles/" + fileName + ".yml", false); - } else - plugin.getLogger().info("Could not find " + fileName + ".yml"); - } - - languages.put(fileName, this); - loadLanguage(); - } - - private void loadLanguage() { - languageData = YamlConfiguration.loadConfiguration(languageFile); - - languageName = languageData.getString("languageName"); - prefixShort = languageData.getString("prefixShort", "&7[&5CR&7] "); - prefixLong = languageData.getString("prefixLong", "&8[&5CubeRunner&8] "); - developper = languageData.getString("developper", "&5Developped by: &7%developper%"); - version = languageData.getString("version", "&5Version: &7%version%"); - description = languageData.getString("description", "&dType &5/%command% help &d for the list of commands."); - - errorPermission = languageData.getString("missingPermission", "&4You don't have the permission to do this"); - errorCommand = languageData.getString("commandError", "&cCommand or arena not found. Type &8/%cmd% help &cfor help."); - errorTeleport = languageData.getString("errorTeleport", "&cYou can't teleport away while you are in game. Do &7/cr quit &cto leave it."); - helpNoPermission = languageData.getString("helpNoPermission", "&cYou do not have any permissions in this category."); - toolInfoMissingName = languageData.getString("toolInfoMissingName", "&cYou need to choose an arena."); - toolInfoTip = languageData.getString("toolInfoTip", "&8[&7Tip&8] &7You may also do &8/%cmd% list &7and right click an arena to display it's information."); - - playerAlreadyInGame = languageData.getString("playerAlreadyInGame", "&cYou are already in a CubeRunner game."); - playerNotInGame = languageData.getString("playerNotInGame", "&cYou are not currently in a CubeRunner game."); - playerJoinUnready = languageData.getString("playerJoinUnready", "&cThe arena you are trying to join is not available."); - playerJoinActive = languageData.getString("playerJoinActive", "&cThere is already an active game in the arena you are trying to join."); - playerJoinSpectator = languageData.getString("playerJoinSpectator", "&dJoining as spectator..."); - playerJoinSuccess = languageData.getString("playerJoinSuccess", "&aYou have successfully joined the arena &2%arena%&a."); - playerJoinOthers = languageData.getString("playerJoinOthers", "&f%player% &djoined your CubeRunner's arena."); - playerQuitSuccess = languageData.getString("playerQuitSuccess", "&aYou have left the CubeRunner's arena &2%arena%&a."); - playerQuitOthers = languageData.getString("playerQuitOthers", "&f%player% &dleft your CubeRunner's arena."); - - gameNotReady = languageData.getString("gameNotReady", "&cThe game is not ready to start at the moment"); - gameStartLessMin = languageData.getString("arenaStartLessMin", "&cThere must be at least %amount% players to start the game."); - gameStartLessMax = languageData.getString("arenaStartLessMax", "&cThere must be at most %amount% players to start the game."); - gameCountdownStarted = languageData.getString("gameCountdownStarted", "&dA new game of &5CubeRunner &dhas been initiated. You may join with the command &5/cr join %arena%&d."); - gameCountdownStopped = languageData.getString("gameCountdownStopped", "&cThe countdown has been stopped. Not enough players in the game anymore."); - gameCrushedPlayer = languageData.getString("gameCrushedPlayer", "&dYou have been crushed with a score of &5%score%&d. Game over!"); - gameCrushedOthers = languageData.getString("gameCrushedOthers", "&f%player% &dhas been crushed with a score of &5%score%&d."); - endingTeleport = languageData.getString("gameEndingTeleport", "&dGame is over. Teleporting back in 5 seconds..."); - endingBest = languageData.getString("gameEndingBest", "&6Congratulation to &f%player% &6who got the new best score of &4%score% &6in the arena &5%arena%"); - - missingArenaName = languageData.getString("missingArenaName", "&cYou must choose a name for your new arena."); - arenaCreated = languageData.getString("arenaCreated", "&aAn arena named &2%arena% &ahas been successfully created."); - arenaAlreadyExist = languageData.getString("arenaAlreadyExist", "&cAn arena named &4%arena% &calready exists."); - arenaNotExist = languageData.getString("arenaNotExist", "&cAn arena named &4%arena% &cdoes not exists."); - arenaNotFound = languageData.getString("arenaNotFound", "&cAn arena named &4%arena% &cwas not found."); - reloadSuccess = languageData.getString("reloadSuccess", "&aPlugin CubeRunner has been successfully reloaded."); - missingEditArgument = languageData.getString("missingEditArgument", "&cYou must choose what to do with this arena. Type &8/%cmd% help arena &cfor help."); - missingWorldEditRegion = languageData.getString("missingWorldEditRegion", "&cYou must first choose a World Edit region."); - arenaSetArena = languageData.getString("arenaSetArena", "&aZone successfully set for the arena &2%arena%&a."); - arenaSetStartPoint = languageData.getString("arenaSetStartPoint", "&aStart Point successfully set for the arena &2%arena%&a."); - arenaSetLobby = languageData.getString("arenaSetLobby", "&aLobby successfully set for the arena &2%arena%&a."); - arenaAmountPlayerMissingArgument = languageData.getString("arenaAmountPlayerMissingArgument", "&cYou must provide a quantity to change the amount of players."); - arenaAmountPlayerInvalidArgument = languageData.getString("arenaAmountPlayerInvalidArgument", "&cThe amount of player you entered is not valid. &7[&8%error%&7]"); - arenaAmountPlayerNotANumber = languageData.getString("arenaAmountPlayerNotANumber", "Not a number"); - arenaAmountPlayerMinEqualZero = languageData.getString("arenaAmountPlayerMinEqualZero", "Minimum lower than 1"); - arenaAmountPlayerMinBiggerMax = languageData.getString("arenaAmountPlayerMinBiggerMax", "Minimum higher than maximum"); - arenaAmountPlayerMaxBiggerMin = languageData.getString("arenaAmountPlayerMaxBiggerMin", "Maximum lower than minimum"); - arenaAmountPlayerSuccess = languageData.getString("arenaAmountPlayerSuccess", "&aAmount of player successfully edited for the arena &2%arena%&a."); - arenaDeleted = languageData.getString("arenaDeleted", "&cArena deleted."); - - guiInstrictions = languageData.getString("guiInstrictions", "&6Instructions"); - guiNextPage = languageData.getString("guiNextPage", "&2Next Page"); - guiPreviousPage = languageData.getString("guiPreviousPage", "&2Previous Page"); - guiJoinName = languageData.getString("guiJoinName", "&2Arena List"); - guiJoinInfo = languageData.getString("guiJoinInfo", "&eClick the name of the arena you wish to go to."); - guiJoinStarted = languageData.getString("guiJoinStarted", "&cActive : &eClick to Spectate"); - guiJoinReady = languageData.getString("guiJoinReady", "&aReady : &eClick to Join"); - guiStatsName = languageData.getString("guiStatsName", "&6Stats"); - guiStatsAverageDistancePerGame = languageData.getString("guiStatsAverageDistancePerGame", "&bAverage Score Per Game"); - guiStatsTotalDistance = languageData.getString("guiStatsTotalDistance", "&bTotal Distance Ran"); - guiStatsGamePlayed = languageData.getString("guiStatsGamePlayed", "&bGames played"); - guiStatsTotalPoints = languageData.getString("guiStatsTotalPoints", "&bTotal Score"); - guiStatsKills = languageData.getString("guiStatsKills", "&bPlayers Killed"); - guiStatsMultiplayer = languageData.getString("guiStatsMultiplayer", "&bMultiplayer games won"); - guiStatsTimePlayed = languageData.getString("guiStatsTimePlayed", "&dTime Played"); - guiStatsMoney = languageData.getString("guiStatsMoney", "&dMoney Gained"); - guiChallengeName = languageData.getString("guiChallengeName", "&bChallenges"); - guiColorName = languageData.getString("guiColorName", "&4Color Picker"); - guiColorInfo = languageData.getString("guiColorInfo", "&eThe enchanted blocks are\nðe curently selected ones.\n&eClick a block to\n&eenable or disable it."); - guiColorEditWhileActive = languageData.getString("guiColorEditWhileActive", "&cYou can't edit the colors while a game is active."); - - commandDescriptions = new CaseInsensitiveMap(); - for (CubeRunnerCommand cmd : CubeRunnerCommand.getCommands()) { - commandDescriptions.put(cmd.getDescription(), - languageData.getString(cmd.getDescription(), "&cOops, an Error has occured!")); - } - - keyWordHelp = languageData.getString("keyWordHelp", "Help"); - keyWordCategory = languageData.getString("keyWordCategory", "Category"); - keyWordPage = languageData.getString("keyWordPage", "Page"); - keyWordHours = languageData.getString("keyWordHours", "hours"); - keyWordMinutes = languageData.getString("keyWordMinutes", "minutes"); - keyWordSeconds = languageData.getString("keyWordSeconds", "seconds"); - keyWordDistance = languageData.getString("keyWordDistance", "km"); - keyWordAdvanced = languageData.getString("keyWordAdvanced", "Advanced Information"); - keyWordInformation = languageData.getString("keyWordInformation", "Information"); - keyWordMinimum = languageData.getString("keyWordMinimum", "Minimum"); - keyWordMaximum = languageData.getString("keyWordMaximum", "Maximum"); - keyWordCurrent = languageData.getString("keyWordCurrent", "Current"); - keyWordAmountPlayer = languageData.getString("keyWordAmountPlayer", "amount of players"); - keyWordGameState = languageData.getString("keyWordGameState", "game state"); - keyWordUnset = languageData.getString("keyWordUnset", "&7Arena Unset"); - keyWordReady = languageData.getString("keyWordReady", "&aReady"); - keyWordStartup = languageData.getString("keyWordStartup", "&9Startup"); - keyWordActive = languageData.getString("keyWordActive", "&cActive"); - keyWordWorld = languageData.getString("keyWordWorld", "World"); - keyWordLobby = languageData.getString("keyWordLobby", "Lobby"); - keyWordStartPoint = languageData.getString("keyWordStartPoint", "Start point"); - keyWordZone = languageData.getString("keyWordZoneMinPoint", " zone coordinate"); - keyWordTop10 = languageData.getString("top10", "Top 10"); - keyWordBestScore = languageData.getString("keyWordBestScore", "Best Score"); - keyWordBy = languageData.getString("keyWordBy", "by"); - keyWordProgression = languageData.getString("keyWordProgression", "Progression"); - keyWordCompleted = languageData.getString("keyWordCompleted", "Completed"); - keyWordNotCompleted = languageData.getString("keyWordNotCompleted", "Not Completed"); - keyWordReward = languageData.getString("keyWordReward", "Reward"); - - helpDescriptionAll = languageData.getString("helpDescriptionAll", "&7All Commands"); - helpDescriptionGeneral = languageData.getString("helpDescriptionGeneral", "&7General player commands"); - helpDescriptionGame = languageData.getString("helpDescriptionGame", "&7Commands to simply play the game"); - helpDescriptionArena = languageData.getString("helpDescriptionArena", "&7Commands to setup the arenas"); - helpDescriptionAdmin = languageData.getString("helpDescriptionAdmin", "&7Admin maintenance commands"); - - signNoPermission0 = languageData.getString("signNoPermission0", "&cYou don't have"); - signNoPermission1 = languageData.getString("signNoPermission1", "&cthe permissions"); - signNoPermission2 = languageData.getString("signNoPermission2", "&cto create a DaC"); - signNoPermission3 = languageData.getString("signNoPermission3", "&csign, &4Sorry..."); - signNotValid1 = languageData.getString("signNotValid1", "&cNone valid"); - signNotValid2 = languageData.getString("signNotValid2", "&csign parameters"); - signNotValid3 = languageData.getString("signNotValid3", "&cTry again"); - signJoin = languageData.getString("signJoin", "&aJoin Arena"); - signQuit = languageData.getString("signQuit", "&cQuit Arena"); - signStartGame = languageData.getString("signStartGame", "&9Start Game"); - signOpenStats = languageData.getString("signOpenStats", "&6Stats"); - signPlay = languageData.getString("signPlay", "&aPlay"); - - achievementCongrats = languageData.getString("achievementCongrats", "&f%player% &6just completed the achievement &d%achievementName%&6!"); - achievementAmountGame = languageData.getString("achievementAmountGame", "&dPlay %amount% game(s)"); - achievementTotalScore = languageData.getString("achievementTotalScore", "&dReach total score of %amount%"); - achievementKills = languageData.getString("achievementKills", "&dKill %amount% player(s)"); - achievementMultiplayerWon = languageData.getString("achievementMultiplayerWon", "&dWin %amount% multiplayer game(s)"); - achievementSurvive5Minutes = languageData.getString("achievementSurvive5Minutes", "&dSurvive 5 minutes"); - achievementReachHeight10 = languageData.getString("reachHeight10", "&dReach height 10"); - achievementFillTheArena = languageData.getString("fillTheArena", "&dFill the arena's floor"); - achievementTheAnswerToLife = languageData.getString("theAnswerToLife", "&dThe answer to life the universe and everything"); - achievementTheRageQuit = languageData.getString("achievementTheRageQuit", "&dThe Rage Quit"); - achievementTheKillerBunny = languageData.getString("achievementTheKillerBunny", "&dThe Killer Bunny"); - achievementMoneyReward = languageData.getString("achievementMoneyReward", "&dYou gain %amount%%currency% for your achievement."); - achievementMoneyGame = languageData.getString("achievementMoneyGame", "&dYou gain %amount%%currency% for surviving %amount2% seconds."); - - languageList = languageData.getString("languageList", "Available languages"); - languageNotFound = languageData.getString("languageNotFound", "&cLanguage not found. &8/%cmd% language &cfor a list of available languages"); - languageChangeSuccess = languageData.getString("languageChangeSuccess", "&aLanguage successfully set to %language%"); - } - - public CaseInsensitiveMap getCommandsDescription() { - return commandDescriptions; - } - - public void sendMsg(Player player, String message) { - if (config.prefixInFrontOfEveryMessages) - player.sendMessage(ChatColor.translateAlternateColorCodes('&', prefixShort + message)); - else - player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); - } - - public void sendMsg(User user, String message) { - sendMsg(user.getPlayer(), message); - } - - public static HashMap getLanguages() { - return languages; - } - - public static void clearLanguages() { - languages.clear(); - } - - public static Entry getLanguage(String languageName) { - for (Entry local : languages.entrySet()) - if (local.getValue().languageName.equalsIgnoreCase(languageName)) - return local; - - return null; - } -} diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/MySQL.java b/Bukkit_1.8/src/me/poutineqc/cuberunner/MySQL.java deleted file mode 100644 index a2ed0d1..0000000 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/MySQL.java +++ /dev/null @@ -1,99 +0,0 @@ -package me.poutineqc.cuberunner; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; - -public class MySQL { - - private CubeRunner plugin; - private String host; - private int port; - private String database; - private String user; - private String password; - - private Connection connection; - - public MySQL(CubeRunner plugin) { - this.plugin = plugin; - connection = null; - } - - public MySQL(CubeRunner plugin, String host, int port, String database, String user, String password) { - this.plugin = plugin; - this.host = host; - this.port = port; - this.database = database; - this.user = user; - this.password = password; - - connect(); - } - - public MySQL() { - connection = null; - } - - public void updateInfo(CubeRunner plugin) { - Configuration config = plugin.getConfiguration(); - this.plugin = plugin; - this.host = config.host; - this.port = config.port; - this.database = config.database; - this.user = config.user; - this.password = config.password; - - connect(); - } - - public void connect() { - try { - connection = DriverManager.getConnection( - "jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true", user, password); - plugin.getLogger().info("[MySQL] The connection to MySQL is made!"); - } catch (SQLException e) { - plugin.getLogger().info("[MySQL] The connection to MySQL couldn't be made! reason: " + e.getMessage()); - } - } - - public void close() { - try { - if (connection != null) { - connection.close(); - plugin.getLogger().info("[MySQL] The connection to MySQL is ended successfully!"); - } - } catch (SQLException e) { - plugin.getLogger().info("[MySQL] The connection couldn't be closed! reason: " + e.getMessage()); - } - } - - public void update(String qry) { - try { - PreparedStatement st = connection.prepareStatement(qry); - st.execute(); - st.close(); - } catch (SQLException e) { - connect(); - System.err.println(e); - } - } - - public boolean hasConnection() { - return connection != null; - } - - public ResultSet query(String qry) { - ResultSet rs = null; - try { - PreparedStatement st = connection.prepareStatement(qry); - rs = st.executeQuery(); - } catch (SQLException e) { - connect(); - System.err.println(e); - } - return rs; - } -} diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/Permissions.java b/Bukkit_1.8/src/me/poutineqc/cuberunner/Permissions.java deleted file mode 100644 index 237b0fa..0000000 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/Permissions.java +++ /dev/null @@ -1,34 +0,0 @@ -package me.poutineqc.cuberunner; - -import org.bukkit.entity.Player; - -import me.poutineqc.cuberunner.commands.CubeRunnerCommand; - -public class Permissions { - - private static PlayerData playerData; - - public static final String createSign = "cuberunner.admin.edit.sign"; - public static final String advancedInfo = "cuberunner.admin.info"; - - public Permissions(CubeRunner plugin) { - playerData = plugin.getPlayerData(); - } - - public static boolean hasPermission(CubeRunnerCommand command, Player player, boolean warning) { - return hasPermission(command.getPermission(), player, warning); - } - - public static boolean hasPermission(String permission, Player player, boolean warning) { - if (player.hasPermission(permission)) - return true; - - if (warning) { - Language local = playerData.getLanguageOfPlayer(player); - local.sendMsg(player, local.errorPermission); - } - - return false; - } - -} diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/PlayerData.java b/Bukkit_1.8/src/me/poutineqc/cuberunner/PlayerData.java deleted file mode 100644 index 552b7f3..0000000 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/PlayerData.java +++ /dev/null @@ -1,208 +0,0 @@ -package me.poutineqc.cuberunner; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.URL; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Map.Entry; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; - -import me.poutineqc.cuberunner.commands.CubeRunnerCommand; - -public class PlayerData implements Listener { - - private Configuration config; - private MySQL mysql; - - private File playerFile; - private FileConfiguration playerData; - private boolean lastVersion; - private String latestVersion; - - public PlayerData(CubeRunner plugin) { - config = plugin.getConfiguration(); - mysql = plugin.getMySQL(); - - playerFile = new File(plugin.getDataFolder(), "playerData.yml"); - if (!playerFile.exists()) { - try { - playerFile.createNewFile(); - } catch (IOException e) { - Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not create playerData.ylm."); - } - } - - lastVersion = isLastVersion(plugin); - - loadPlayerData(); - } - - private boolean isLastVersion(CubeRunner plugin) { - boolean next = false; - URL url; - try { - url = new URL("http://www.poutineqc.ca/pluginVersion.txt"); - BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); - - while ((latestVersion = in.readLine()) != null) { - if (next) - break; - if (latestVersion.equalsIgnoreCase("CubeRunner")) - next = true; - } - - in.close(); - } catch (IOException e) { - plugin.getLogger().warning("Could not find the latest version available."); - } - - if (next) - return latestVersion.equalsIgnoreCase(plugin.getDescription().getVersion()); - - return true; - } - - public void loadPlayerData() { - playerData = YamlConfiguration.loadConfiguration(playerFile); - } - - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) { - Player player = event.getPlayer(); - addOnFileIfNotExist(player); - - if (!lastVersion && Permissions.hasPermission(CubeRunnerCommand.getCommand("reload"), player, false)) { - Language local = getLanguageOfPlayer(player); - local.sendMsg(player, - "&5A new CubeRunner version is available &d(v%version%)&5.\n".replace("%version%", latestVersion) - + "&5Get it now : &dhttps://www.spigotmc.org/resources/cuberunner.19715/"); - } - } - - public void addOnFileIfNotExist(Player player) { - String uuid = player.getUniqueId().toString(); - - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT * FROM " + config.tablePrefix + "PLAYERS WHERE UUID='" + uuid + "';"); - try { - if (!query.next()) { - mysql.update("INSERT INTO " + config.tablePrefix + "PLAYERS (UUID, name) VALUES ('" + uuid + "','" - + player.getName() + "');"); - } else { - mysql.update("UPDATE " + config.tablePrefix + "PLAYERS SET name='" + player.getName() - + "' WHERE UUID='" + uuid + "';"); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } else { - if (!playerData.contains("players." + uuid)) { - playerData.set("players." + uuid + ".name", player.getName()); - playerData.set("players." + uuid + ".language", "default"); - playerData.set("players." + uuid + ".money", 0); - playerData.set("players." + uuid + ".averageDistancePerGame", 0); - playerData.set("players." + uuid + ".totalDistance", 0); - playerData.set("players." + uuid + ".games", 0); - playerData.set("players." + uuid + ".totalScore", 0); - playerData.set("players." + uuid + ".kills", 0); - playerData.set("players." + uuid + ".multiplayerWon", 0); - playerData.set("players." + uuid + ".timePlayed", 0); - playerData.set("players." + uuid + ".achievement.survive5Minutes", false); - playerData.set("players." + uuid + ".achievement.reachHeight10", false); - playerData.set("players." + uuid + ".achievement.fillTheArena", false); - playerData.set("players." + uuid + ".achievement.theAnswerToLife", false); - playerData.set("players." + uuid + ".achievement.theRageQuit", false); - playerData.set("players." + uuid + ".achievement.theKillerBunny", false); - savePlayerData(); - } else { - playerData.set("players." + uuid + ".name", player.getName()); - savePlayerData(); - } - } - } - - public FileConfiguration getData() { - return playerData; - } - - public void savePlayerData() { - try { - playerData.save(playerFile); - } catch (IOException e) { - Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not save playerData.yml!"); - } - } - - public void newUser(Player player) { - if (mysql.hasConnection()) { - mysql.update("INSERT INTO " + config.tablePrefix + "PLAYERS (language) VALUES ('default');"); - } else { - - } - } - - public Language getLanguageOfPlayer(Player player) { - String fileName = null; - if (mysql.hasConnection()) { - try { - ResultSet query = mysql.query("SELECT language FROM " + config.tablePrefix + "PLAYERS WHERE UUID='" - + player.getUniqueId() + "';"); - - if (query.next()) { - fileName = query.getString("language"); - } - - } catch (SQLException e) { - e.printStackTrace(); - } - } else { - fileName = playerData.getString("players." + player.getUniqueId().toString() + ".language", null); - } - - if (fileName == null) - return Language.getLanguages().get(config.language); - - return getLanguage(fileName); - } - - public Language getLanguage(String fileName) { - for (Entry local : Language.getLanguages().entrySet()) - if (local.getKey().equalsIgnoreCase(fileName)) - return local.getValue(); - - if (Language.getLanguages().containsKey(config.language)) - return Language.getLanguages().get(config.language); - - return Language.getLanguages().get("en-US"); - - } - - public void setLanguage(Player player, String key) { - if (mysql.hasConnection()) { - mysql.update("UPDATE " + config.tablePrefix + "PLAYERS SET language='" + key + "' WHERE UUID='" - + player.getUniqueId().toString() + "';"); - } else { - playerData.set("players." + player.getUniqueId().toString() + ".language", key); - savePlayerData(); - } - } - - public boolean isLatestVersion() { - return lastVersion; - } - - public String getLatestVersion() { - return latestVersion; - } -} diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/achievements/AchievementGUI.java b/Bukkit_1.8/src/me/poutineqc/cuberunner/achievements/AchievementGUI.java deleted file mode 100644 index 0863f80..0000000 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/achievements/AchievementGUI.java +++ /dev/null @@ -1,929 +0,0 @@ -package me.poutineqc.cuberunner.achievements; - -import java.sql.ResultSet; -import java.sql.SQLException; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.Inventory; - -import me.poutineqc.cuberunner.Configuration; -import me.poutineqc.cuberunner.CubeRunner; -import me.poutineqc.cuberunner.Language; -import me.poutineqc.cuberunner.MySQL; -import me.poutineqc.cuberunner.PlayerData; -import me.poutineqc.cuberunner.tools.ItemStackManager; -import net.milkbowl.vault.economy.Economy; - -public class AchievementGUI implements Listener { - - private Configuration config; - private MySQL mysql; - private PlayerData playerData; - private Achievements achievements; - private Economy economy; - - public AchievementGUI(CubeRunner plugin) { - this.config = plugin.getConfiguration(); - this.mysql = plugin.getMySQL(); - this.playerData = plugin.getPlayerData(); - this.achievements = plugin.getAchievements(); - this.economy = CubeRunner.getEconomy(); - } - - @EventHandler - public void onInventotyClick(InventoryClickEvent event) { - - if (!(event.getWhoClicked() instanceof Player)) - return; - - Player player = (Player) event.getWhoClicked(); - Language local = playerData.getLanguageOfPlayer(player); - - if (!ChatColor.stripColor(event.getInventory().getName()) - .equalsIgnoreCase(ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.guiStatsName + " &0: &5CubeRunner"))) - && !ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase(ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.guiChallengeName + " &0: &5CubeRunner")))) - return; - - event.setCancelled(true); - - if (event.getAction() == InventoryAction.NOTHING || event.getAction() == InventoryAction.UNKNOWN) - return; - - String itemName = event.getCurrentItem().getItemMeta().getDisplayName(); - - if (isEqualOnColorStrip(itemName, local.guiChallengeName)) { - openChallengeInventory(player); - return; - } - - if (isEqualOnColorStrip(itemName, local.guiStatsName)) { - openAchievementInventory(player); - return; - } - - } - - private boolean isEqualOnColorStrip(String toCheck, String original) { - return ChatColor.stripColor(toCheck) - .equalsIgnoreCase(ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', original))); - } - - public void openAchievementInventory(Player player) { - - String uuid = player.getUniqueId().toString(); - Language local = playerData.getLanguageOfPlayer(player); - Inventory inv = Bukkit.createInventory(null, 54, - ChatColor.translateAlternateColorCodes('&', local.guiStatsName + " &0: &5CubeRunner")); - ItemStackManager icon; - int location; - - double averageDistancePerGame = 0; - double totalDistance = 0; - int gamesPlayed = 0; - int totalPoints = 0; - int kills = 0; - int multiplayerWon = 0; - int timePlayed = 0; - double money = 0; - - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT * FROM " + config.tablePrefix + "PLAYERS WHERE UUID='" + uuid + "';"); - try { - if (query.next()) { - averageDistancePerGame = query.getDouble("averageDistancePerGame"); - totalDistance = query.getDouble("totalDistance"); - gamesPlayed = query.getInt("games"); - totalPoints = query.getInt("totalScore"); - kills = query.getInt("kills"); - multiplayerWon = query.getInt("multiplayerWon"); - timePlayed = query.getInt("timePlayed"); - money = query.getDouble("money"); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } else { - averageDistancePerGame = playerData.getData().getDouble("players." + uuid + ".averageDistancePerGame", 0); - totalDistance = playerData.getData().getDouble("players." + uuid + ".totalDistance", 0); - gamesPlayed = playerData.getData().getInt("players." + uuid + ".games", 0); - totalPoints = playerData.getData().getInt("players." + uuid + ".totalScore", 0); - kills = playerData.getData().getInt("players." + uuid + ".kills", 0); - multiplayerWon = playerData.getData().getInt("players." + uuid + ".multiplayerWon", 0); - timePlayed = playerData.getData().getInt("players." + uuid + ".timePlayed", 0); - money = playerData.getData().getDouble("players." + uuid + ".money", 0); - } - - averageDistancePerGame = ((int) (averageDistancePerGame * 100)) / 100.0; - totalDistance = (int) totalDistance / 1000.0; - money = (int) (money * 100) / 100.0; - - /*************************************************** - * Glass Spacer - ***************************************************/ - - icon = new ItemStackManager(Material.STAINED_GLASS_PANE); - icon.setData((short) 10); - icon.setTitle(" "); - - for (int i = 0; i < inv.getSize(); i++) - switch (i) { - case 1: - case 10: - case 11: - case 12: - case 13: - case 14: - case 15: - case 16: - case 17: - case 19: - case 28: - case 37: - case 46: - icon.setPosition(i); - icon.addToInventory(inv); - } - - /*************************************************** - * Stats - ***************************************************/ - - icon = new ItemStackManager(Material.PAPER); - icon.setTitle(ChatColor.translateAlternateColorCodes('&', local.guiStatsName + " : CubeRunner")); - - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.translateAlternateColorCodes('&', - local.guiStatsAverageDistancePerGame + " : &e" + String.valueOf(averageDistancePerGame))); - icon.addToLore(ChatColor.translateAlternateColorCodes('&', local.guiStatsTotalDistance + " : &e" - + String.valueOf(totalDistance) + " " + ChatColor.GREEN + local.keyWordDistance)); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.translateAlternateColorCodes('&', - local.guiStatsGamePlayed + " : &e" + String.valueOf(gamesPlayed))); - icon.addToLore(ChatColor.translateAlternateColorCodes('&', - local.guiStatsTotalPoints + " : &e" + String.valueOf(totalPoints))); - icon.addToLore( - ChatColor.translateAlternateColorCodes('&', local.guiStatsKills + " : &e" + String.valueOf(kills))); - icon.addToLore(ChatColor.translateAlternateColorCodes('&', - local.guiStatsMultiplayer + " : &e" + String.valueOf(multiplayerWon))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.LIGHT_PURPLE - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.guiStatsTimePlayed)) + ": " - + getTimePLayed(local, timePlayed)); - if (CubeRunner.isEconomyEnabled()) - icon.addToLore(ChatColor.LIGHT_PURPLE - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.guiStatsMoney)) + ": &e" - + String.valueOf(money) + ChatColor.GREEN + economy.currencyNamePlural()); - - icon.setPosition(2); - icon.addToInventory(inv); - - /*************************************************** - * Top Ratio - ***************************************************/ - - icon = new ItemStackManager(Material.EMPTY_MAP); - icon.setTitle(ChatColor.GOLD + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', - local.keyWordTop10 + " : " + local.guiStatsAverageDistancePerGame))); - - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT * FROM " + config.tablePrefix + "AVERAGESCORE;"); - try { - while (query.next()) { - icon.addToLore(ChatColor.LIGHT_PURPLE + query.getString("name") + " : " + ChatColor.YELLOW - + getAverage(query.getDouble("averageDistancePerGame"), 100)); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } else { - for (int i = 0; i < 10 && i < TopManager.getRatio().size(); i++) { - icon.addToLore(ChatColor.LIGHT_PURPLE + TopManager.getRatio().get(i).getPlayer() + " : " - + ChatColor.YELLOW + getAverage(TopManager.getRatio().get(i).getScore(), 100)); - } - } - - icon.setPosition(0); - icon.addToInventory(inv); - - /*************************************************** - * Top Distance Ran - ***************************************************/ - - icon = new ItemStackManager(Material.EMPTY_MAP); - icon.setTitle(ChatColor.GOLD + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordTop10 + " : " + local.guiStatsTotalDistance))); - - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT * FROM " + config.tablePrefix + "TOTALDISTANCE;"); - try { - while (query.next()) { - icon.addToLore(ChatColor.LIGHT_PURPLE + query.getString("name") + " : " + ChatColor.YELLOW - + getAverage(query.getDouble("totalDistance"), 1) / 1000 + " " + ChatColor.GREEN - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordDistance))); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } else { - for (int i = 0; i < 10 && i < TopManager.getDistanceRan().size(); i++) { - icon.addToLore(ChatColor.LIGHT_PURPLE + TopManager.getDistanceRan().get(i).getPlayer() + " : " - + ChatColor.YELLOW + getAverage(TopManager.getDistanceRan().get(i).getScore(), 1) / 1000); - } - } - - icon.setPosition(9); - icon.addToInventory(inv); - - /*************************************************** - * Top games - ***************************************************/ - - icon = new ItemStackManager(Material.EMPTY_MAP); - icon.setTitle(ChatColor.GOLD + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordTop10 + " : " + local.guiStatsGamePlayed))); - - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT * FROM " + config.tablePrefix + "MOSTGAMES;"); - try { - while (query.next()) { - icon.addToLore(ChatColor.LIGHT_PURPLE + query.getString("name") + " : " + ChatColor.YELLOW - + query.getInt("games")); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } else { - for (int i = 0; i < 10 && i < TopManager.getGames().size(); i++) { - icon.addToLore(ChatColor.LIGHT_PURPLE + TopManager.getGames().get(i).getPlayer() + " : " - + ChatColor.YELLOW + TopManager.getGames().get(i).getScore()); - } - } - - icon.setPosition(18); - icon.addToInventory(inv); - - /*************************************************** - * Top Total Score - ***************************************************/ - - icon = new ItemStackManager(Material.EMPTY_MAP); - icon.setTitle(ChatColor.GOLD + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordTop10 + " : " + local.guiStatsTotalPoints))); - - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT * FROM " + config.tablePrefix + "TOTALSCORE;"); - try { - while (query.next()) { - icon.addToLore(ChatColor.LIGHT_PURPLE + query.getString("name") + " : " + ChatColor.YELLOW - + query.getInt("totalScore")); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } else { - for (int i = 0; i < 10 && i < TopManager.getTotalScore().size(); i++) { - icon.addToLore(ChatColor.LIGHT_PURPLE + TopManager.getTotalScore().get(i).getPlayer() + " : " - + ChatColor.YELLOW + TopManager.getTotalScore().get(i).getScore()); - } - } - - icon.setPosition(27); - icon.addToInventory(inv); - - /*************************************************** - * Top Kills - ***************************************************/ - - icon = new ItemStackManager(Material.EMPTY_MAP); - icon.setTitle(ChatColor.GOLD + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordTop10 + " : " + local.guiStatsKills))); - - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT * FROM " + config.tablePrefix + "KILLS;"); - try { - while (query.next()) { - icon.addToLore(ChatColor.LIGHT_PURPLE + query.getString("name") + " : " + ChatColor.YELLOW - + query.getInt("kills")); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } else { - for (int i = 0; i < 10 && i < TopManager.getKills().size(); i++) { - icon.addToLore(ChatColor.LIGHT_PURPLE + TopManager.getKills().get(i).getPlayer() + " : " - + ChatColor.YELLOW + (int) TopManager.getKills().get(i).getScore()); - } - } - - icon.setPosition(36); - icon.addToInventory(inv); - - /*************************************************** - * Top Multiplayer Won - ***************************************************/ - - icon = new ItemStackManager(Material.EMPTY_MAP); - icon.setTitle(ChatColor.GOLD + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordTop10 + " : " + local.guiStatsMultiplayer))); - - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT * FROM " + config.tablePrefix + "MULTIPLAYERWON;"); - try { - while (query.next()) { - icon.addToLore(ChatColor.LIGHT_PURPLE + query.getString("name") + " : " + ChatColor.YELLOW - + query.getInt("multiplayerWon")); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } else { - for (int i = 0; i < 10 && i < TopManager.getMultiplayerWon().size(); i++) { - icon.addToLore(ChatColor.LIGHT_PURPLE + TopManager.getMultiplayerWon().get(i).getPlayer() + " : " - + ChatColor.YELLOW + (int) TopManager.getMultiplayerWon().get(i).getScore()); - } - } - - icon.setPosition(45); - icon.addToInventory(inv); - - /*************************************************** - * Achievements games - ***************************************************/ - location = 20; - for (AchievementsObject ao : achievements.getachievements().get(0)) { - - icon = new ItemStackManager(Material.WOOL); - - if (ao.get_level() <= gamesPlayed) { - icon.setData((short) 5); - icon.setTitle(ChatColor.GREEN + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', - local.achievementAmountGame.replace("%amount%", String.valueOf(ao.get_level()))))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordProgression + ": ")) - + ChatColor.GREEN - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordCompleted))); - } else { - icon.setData((short) 8); - icon.setTitle(ChatColor.RED + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', - local.achievementAmountGame.replace("%amount%", String.valueOf(ao.get_level()))))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordProgression + ": ")) - + ChatColor.YELLOW + String.valueOf(gamesPlayed) + "/" + String.valueOf(ao.get_level())); - if (CubeRunner.isEconomyEnabled()) { - if (config.achievementsRewards) - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordReward + ": ")) - + ChatColor.YELLOW + String.valueOf(ao.get_reward()) + economy.currencyNamePlural()); - } - } - - icon.setPosition(location++); - icon.addToInventory(inv); - - } - - /*************************************************** - * Achievements totalScore - ***************************************************/ - location = 29; - for (AchievementsObject ao : achievements.getachievements().get(1)) { - - icon = new ItemStackManager(Material.WOOL); - - if (ao.get_level() <= totalPoints) { - icon.setData((short) 5); - icon.setTitle(ChatColor.GREEN + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', - local.achievementTotalScore.replace("%amount%", String.valueOf(ao.get_level()))))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordProgression + ": ")) - + ChatColor.GREEN - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordCompleted))); - } else { - icon.setData((short) 8); - icon.setTitle(ChatColor.RED + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', - local.achievementTotalScore.replace("%amount%", String.valueOf(ao.get_level()))))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordProgression + ": ")) - + ChatColor.YELLOW + String.valueOf(totalPoints) + "/" + String.valueOf(ao.get_level())); - if (CubeRunner.isEconomyEnabled()) { - if (config.achievementsRewards) - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordReward + ": ")) - + ChatColor.YELLOW + String.valueOf(ao.get_reward()) + economy.currencyNamePlural()); - } - } - - icon.setPosition(location++); - icon.addToInventory(inv); - - } - - /*************************************************** - * Achievements kills - ***************************************************/ - location = 38; - for (AchievementsObject ao : achievements.getachievements().get(2)) { - - icon = new ItemStackManager(Material.WOOL); - - if (ao.get_level() <= kills) { - icon.setData((short) 5); - icon.setTitle(ChatColor.GREEN + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', - local.achievementKills.replace("%amount%", String.valueOf(ao.get_level()))))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordProgression + ": ")) - + ChatColor.GREEN - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordCompleted))); - } else { - icon.setData((short) 8); - icon.setTitle(ChatColor.RED + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', - local.achievementKills.replace("%amount%", String.valueOf(ao.get_level()))))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordProgression + ": ")) - + ChatColor.YELLOW + String.valueOf(kills) + "/" + String.valueOf(ao.get_level())); - if (CubeRunner.isEconomyEnabled()) { - if (config.achievementsRewards) - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordReward + ": ")) - + ChatColor.YELLOW + String.valueOf(ao.get_reward()) + economy.currencyNamePlural()); - } - } - - icon.setPosition(location++); - icon.addToInventory(inv); - - } - - /*************************************************** - * Achievements Multiplayer Won - ***************************************************/ - location = 47; - for (AchievementsObject ao : achievements.getachievements().get(3)) { - - icon = new ItemStackManager(Material.WOOL); - - if (ao.get_level() <= multiplayerWon) { - icon.setData((short) 5); - icon.setTitle(ChatColor.GREEN + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', - local.achievementMultiplayerWon.replace("%amount%", String.valueOf(ao.get_level()))))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordProgression + ": ")) - + ChatColor.GREEN - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordCompleted))); - } else { - icon.setData((short) 8); - icon.setTitle(ChatColor.RED + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', - local.achievementMultiplayerWon.replace("%amount%", String.valueOf(ao.get_level()))))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordProgression + ": ")) - + ChatColor.YELLOW + String.valueOf(multiplayerWon) + "/" + String.valueOf(ao.get_level())); - if (CubeRunner.isEconomyEnabled()) { - if (config.achievementsRewards) - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordReward + ": ")) - + ChatColor.YELLOW + String.valueOf(ao.get_reward()) + economy.currencyNamePlural()); - } - } - - icon.setPosition(location++); - icon.addToInventory(inv); - - } - - /*************************************************** - * Arrow - ***************************************************/ - - icon = new ItemStackManager(Material.ARROW); - - icon.setTitle(local.guiChallengeName); - - icon.setPosition(8); - icon.addToInventory(inv); - - /*************************************************** - * Display - ***************************************************/ - - player.openInventory(inv); - } - - public void openChallengeInventory(Player player) { - - String uuid = player.getUniqueId().toString(); - Language local = playerData.getLanguageOfPlayer(player); - Inventory inv = Bukkit.createInventory(null, 27, - ChatColor.translateAlternateColorCodes('&', local.guiChallengeName + " &0: &5CubeRunner")); - ItemStackManager icon; - - double averageDistancePerGame = 0; - double totalDistance = 0; - int gamesPlayed = 0; - int totalPoints = 0; - int kills = 0; - int multiplayerWon = 0; - int timePlayed = 0; - double money = 0; - boolean survive5Minutes = false; - boolean reachHeight10 = false; - boolean fillTheArena = false; - boolean theAnswerToLife = false; - boolean theRageQuit = false; - boolean theKillerBunny = false; - - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT * FROM " + config.tablePrefix + "PLAYERS WHERE UUID='" + uuid + "';"); - try { - if (query.next()) { - averageDistancePerGame = query.getDouble("averageDistancePerGame"); - totalDistance = query.getDouble("totalDistance"); - gamesPlayed = query.getInt("games"); - totalPoints = query.getInt("totalScore"); - kills = query.getInt("kills"); - multiplayerWon = query.getInt("multiplayerWon"); - timePlayed = query.getInt("timePlayed"); - money = query.getDouble("money"); - survive5Minutes = query.getBoolean("survive5Minutes"); - reachHeight10 = query.getBoolean("reachHeight10"); - fillTheArena = query.getBoolean("fillTheArena"); - theAnswerToLife = query.getBoolean("theAnswerToLife"); - theRageQuit = query.getBoolean("theRageQuit"); - theKillerBunny = query.getBoolean("theKillerBunny"); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } else { - averageDistancePerGame = playerData.getData().getDouble("players." + uuid + ".averageDistancePerGame", 0); - totalDistance = playerData.getData().getDouble("players." + uuid + ".totalDistance", 0); - gamesPlayed = playerData.getData().getInt("players." + uuid + ".games", 0); - totalPoints = playerData.getData().getInt("players." + uuid + ".totalScore", 0); - kills = playerData.getData().getInt("players." + uuid + ".kills", 0); - multiplayerWon = playerData.getData().getInt("players." + uuid + ".multiplayerWon", 0); - timePlayed = playerData.getData().getInt("players." + uuid + ".timePlayed", 0); - money = playerData.getData().getDouble("players." + uuid + ".money", 0); - survive5Minutes = playerData.getData().getBoolean("players." + uuid + ".achievement.survive5Minutes", - false); - reachHeight10 = playerData.getData().getBoolean("players." + uuid + ".achievement.reachHeight10", false); - fillTheArena = playerData.getData().getBoolean("players." + uuid + ".achievement.fillTheArena", false); - theAnswerToLife = playerData.getData().getBoolean("players." + uuid + ".achievement.theAnswerToLife", - false); - theRageQuit = playerData.getData().getBoolean("players." + uuid + ".achievement.theRageQuit", false); - theKillerBunny = playerData.getData().getBoolean("players." + uuid + ".achievement.theKillerBunny", false); - } - - averageDistancePerGame = ((int) (averageDistancePerGame * 100)) / 100.0; - totalDistance = (int) totalDistance / 1000.0; - money = (int) (money * 100) / 100.0; - - /*************************************************** - * Glass Spacer - ***************************************************/ - - icon = new ItemStackManager(Material.STAINED_GLASS_PANE); - icon.setData((short) 10); - icon.setTitle(" "); - - for (int i = 0; i < inv.getSize(); i++) - switch (i) { - case 9: - case 10: - case 11: - case 12: - case 13: - case 14: - case 15: - case 16: - case 17: - icon.setPosition(i); - icon.addToInventory(inv); - } - - /*************************************************** - * Stats - ***************************************************/ - - icon = new ItemStackManager(Material.PAPER); - icon.setTitle(ChatColor.translateAlternateColorCodes('&', local.guiStatsName + " : CubeRunner")); - - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.translateAlternateColorCodes('&', - local.guiStatsAverageDistancePerGame + " : &e" + String.valueOf(averageDistancePerGame))); - icon.addToLore(ChatColor.translateAlternateColorCodes('&', local.guiStatsTotalDistance + " : &e" - + String.valueOf(totalDistance) + " " + ChatColor.GREEN + local.keyWordDistance)); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.translateAlternateColorCodes('&', - local.guiStatsGamePlayed + " : &e" + String.valueOf(gamesPlayed))); - icon.addToLore(ChatColor.translateAlternateColorCodes('&', - local.guiStatsTotalPoints + " : &e" + String.valueOf(totalPoints))); - icon.addToLore( - ChatColor.translateAlternateColorCodes('&', local.guiStatsKills + " : &e" + String.valueOf(kills))); - icon.addToLore(ChatColor.translateAlternateColorCodes('&', - local.guiStatsMultiplayer + " : &e" + String.valueOf(multiplayerWon))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.LIGHT_PURPLE - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.guiStatsTimePlayed)) + ": " - + getTimePLayed(local, timePlayed)); - if (CubeRunner.isEconomyEnabled()) - icon.addToLore(ChatColor.LIGHT_PURPLE - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.guiStatsMoney)) + ": &e" - + String.valueOf(money) + ChatColor.GREEN + economy.currencyNamePlural()); - - icon.setPosition(4); - icon.addToInventory(inv); - - /*************************************************** - * Challenge : survive 5 minutes - ***************************************************/ - - icon = new ItemStackManager(Material.INK_SACK); - if (survive5Minutes) { - icon.setData((short) 10); - icon.setTitle(ChatColor.GREEN + ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.achievementSurvive5Minutes))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordProgression)) + ": " - + ChatColor.GREEN - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordCompleted))); - } else { - icon.setData((short) 8); - icon.setTitle(ChatColor.RED + ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.achievementSurvive5Minutes))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordProgression)) + ": " - + ChatColor.RED - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordNotCompleted))); - if (CubeRunner.isEconomyEnabled()) { - if (config.achievementsRewards) - icon.addToLore(ChatColor.AQUA - + ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordReward + ": ")) - + ChatColor.YELLOW + String.valueOf(config.rewardSurvive5Minutes) - + economy.currencyNamePlural()); - } - } - - icon.setPosition(19); - icon.addToInventory(inv); - - /*************************************************** - * Challenge : Fill the arena - ***************************************************/ - - icon = new ItemStackManager(Material.INK_SACK); - if (fillTheArena) { - icon.setData((short) 10); - icon.setTitle(ChatColor.GREEN - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.achievementFillTheArena))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordProgression)) + ": " - + ChatColor.GREEN - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordCompleted))); - } else { - icon.setData((short) 8); - icon.setTitle(ChatColor.RED - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.achievementFillTheArena))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordProgression)) + ": " - + ChatColor.RED - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordNotCompleted))); - if (CubeRunner.isEconomyEnabled()) { - if (config.achievementsRewards) - icon.addToLore(ChatColor.AQUA - + ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordReward + ": ")) - + ChatColor.YELLOW + String.valueOf(config.rewardFillTheArenasFloor) - + economy.currencyNamePlural()); - } - } - - icon.setPosition(20); - icon.addToInventory(inv); - - /*************************************************** - * Challenge : Reach Height 10 - ***************************************************/ - - icon = new ItemStackManager(Material.INK_SACK); - if (reachHeight10) { - icon.setData((short) 10); - icon.setTitle(ChatColor.GREEN + ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.achievementReachHeight10))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordProgression)) + ": " - + ChatColor.GREEN - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordCompleted))); - } else { - icon.setData((short) 8); - icon.setTitle(ChatColor.RED + ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.achievementReachHeight10))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordProgression)) + ": " - + ChatColor.RED - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordNotCompleted))); - if (CubeRunner.isEconomyEnabled()) { - if (config.achievementsRewards) - icon.addToLore(ChatColor.AQUA - + ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordReward + ": ")) - + ChatColor.YELLOW + String.valueOf(config.rewardReachHeight10) - + economy.currencyNamePlural()); - } - } - - icon.setPosition(21); - icon.addToInventory(inv); - - /*************************************************** - * Challenge : RageQuit - ***************************************************/ - - icon = new ItemStackManager(Material.INK_SACK); - if (theRageQuit) { - icon.setData((short) 10); - icon.setTitle(ChatColor.GREEN - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.achievementTheRageQuit))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordProgression)) + ": " - + ChatColor.GREEN - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordCompleted))); - } else { - icon.setData((short) 8); - icon.setTitle(ChatColor.RED - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.achievementTheRageQuit))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordProgression)) + ": " - + ChatColor.RED - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordNotCompleted))); - if (CubeRunner.isEconomyEnabled()) { - if (config.achievementsRewards) - icon.addToLore(ChatColor.AQUA - + ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordReward + ": ")) - + ChatColor.YELLOW + String.valueOf(config.rewardTheRageQuit) - + economy.currencyNamePlural()); - } - } - - icon.setPosition(23); - icon.addToInventory(inv); - - /*************************************************** - * Challenge : Killer Bunny - ***************************************************/ - - icon = new ItemStackManager(Material.INK_SACK); - if (theKillerBunny) { - icon.setData((short) 10); - icon.setTitle(ChatColor.GREEN + ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.achievementTheKillerBunny))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordProgression)) + ": " - + ChatColor.GREEN - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordCompleted))); - } else { - icon.setData((short) 8); - icon.setTitle(ChatColor.RED + ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.achievementTheKillerBunny))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordProgression)) + ": " - + ChatColor.RED - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordNotCompleted))); - if (CubeRunner.isEconomyEnabled()) { - if (config.achievementsRewards) - icon.addToLore(ChatColor.AQUA - + ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordReward + ": ")) - + ChatColor.YELLOW + String.valueOf(config.rewardTheKillerBunny) - + economy.currencyNamePlural()); - } - } - - icon.setPosition(24); - icon.addToInventory(inv); - - /*************************************************** - * Challenge : answer to life - ***************************************************/ - - icon = new ItemStackManager(Material.INK_SACK); - if (theAnswerToLife) { - icon.setData((short) 10); - icon.setTitle(ChatColor.GREEN + ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.achievementTheAnswerToLife))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordProgression)) + ": " - + ChatColor.GREEN - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordCompleted))); - } else { - icon.setData((short) 8); - icon.setTitle(ChatColor.RED + ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.achievementTheAnswerToLife))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordProgression)) + ": " - + ChatColor.RED - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordNotCompleted))); - if (CubeRunner.isEconomyEnabled()) { - if (config.achievementsRewards) - icon.addToLore(ChatColor.AQUA - + ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordReward + ": ")) - + ChatColor.YELLOW + String.valueOf(config.rewardTheAnswerToLife) - + economy.currencyNamePlural()); - } - } - - icon.setPosition(25); - icon.addToInventory(inv); - - /*************************************************** - * Arrow - ***************************************************/ - - icon = new ItemStackManager(Material.ARROW); - - icon.setTitle(local.guiStatsName); - - icon.setPosition(8); - icon.addToInventory(inv); - - /*************************************************** - * Display - ***************************************************/ - - player.openInventory(inv); - } - - private double getAverage(double value, int degree) { - return (int) (value * degree) / (double) (degree); - } - - private String getTimePLayed(Language local, int timePlayed) { - long hours = 0; - - timePlayed /= 60000; - while (timePlayed > 60) { - timePlayed -= 60; - hours++; - } - - return ChatColor.YELLOW + String.valueOf(hours) + ChatColor.GREEN + " " - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordHours)) - + ChatColor.YELLOW + " " + String.valueOf(timePlayed) + ChatColor.GREEN + " " - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordMinutes)); - } - -} diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/achievements/AchievementType.java b/Bukkit_1.8/src/me/poutineqc/cuberunner/achievements/AchievementType.java deleted file mode 100644 index 33b9102..0000000 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/achievements/AchievementType.java +++ /dev/null @@ -1,14 +0,0 @@ -package me.poutineqc.cuberunner.achievements; - -public enum AchievementType { - AMOUNT_GAMES, - AMOUNT_KILLS, - TOTAL_SCORE, - MULTIPLAYER_GAMES_WON, - SURVIVE_5_MINUTES, - FILL_THE_ARENA, - REACH_HEIGHT_10, - DISCONNECT_IN_STARTUP, - JUMP_50_TIMES, - DIE_SECONDS_42 -} diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/achievements/Achievements.java b/Bukkit_1.8/src/me/poutineqc/cuberunner/achievements/Achievements.java deleted file mode 100644 index 5e9f917..0000000 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/achievements/Achievements.java +++ /dev/null @@ -1,338 +0,0 @@ -package me.poutineqc.cuberunner.achievements; - -import java.io.File; -import java.io.InputStream; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; - -import me.poutineqc.cuberunner.Configuration; -import me.poutineqc.cuberunner.CubeRunner; -import me.poutineqc.cuberunner.Language; -import me.poutineqc.cuberunner.MySQL; -import me.poutineqc.cuberunner.PlayerData; -import net.milkbowl.vault.economy.Economy; - -public class Achievements { - - private CubeRunner plugin; - private MySQL mysql; - private Configuration config; - private PlayerData playerData; - - private File achievementFile; - private FileConfiguration achievementData; - - private ArrayList> achievements = new ArrayList>(); - private Economy economy; - - public Achievements(CubeRunner plugin) { - this.plugin = plugin; - this.mysql = plugin.getMySQL(); - this.config = plugin.getConfiguration(); - this.playerData = plugin.getPlayerData(); - this.economy = CubeRunner.getEconomy(); - - achievementFile = new File(plugin.getDataFolder(), "achievements.yml"); - if (!achievementFile.exists()) { - InputStream local = plugin.getResource("achievements.yml"); - if (local != null) { - plugin.saveResource("achievements.yml", false); - } else - plugin.getLogger().info("Could not find achievements.yml"); - } - - setupAchievements(); - } - - public void setupAchievements() { - - achievementData = YamlConfiguration.loadConfiguration(achievementFile); - - achievements.clear(); - - String[] configNames = new String[] { "amountOfGamesPlayed", "totalScore", "amountPlayerKills", - "multiplayerGamesWon" }; - for (int i = 0; i < configNames.length; i++) { - achievements.add(new ArrayList()); - - final int MAX_ACHIEVEMENT_PER_ROW = 7; - List readData = achievementData.getStringList(configNames[i]); - - for (int j = 0; j < readData.size() && achievements.get(i).size() < MAX_ACHIEVEMENT_PER_ROW; j++) { - String[] individualData = readData.get(j).split(";"); - - if (individualData.length < 2) { - plugin.getLogger().info( - "Could not load the " + j + "'th data from the " + i + "'th achievement type. (Reading)"); - continue; - } - - try { - int level = Integer.parseInt(individualData[0]); - double reward = Double.parseDouble(individualData[1]); - achievements.get(i).add(new AchievementsObject(level, reward)); - } catch (NumberFormatException e) { - plugin.getLogger().info("Could not load the " + j + "'th data from the " + i - + "'th achievement type. (Conversion)"); - continue; - } - } - } - - } - - public void checkAchievement(AchievementType type, Player player) { - if (player == null) - return; - - AchievementsObject ao; - boolean completed; - - switch (type) { - case AMOUNT_GAMES: - ao = checkNumberAchievement(player, 0, "games"); - if (ao == null) - break; - - for (Player p : Bukkit.getServer().getOnlinePlayers()) { - Language local = playerData.getLanguageOfPlayer(p); - local.sendMsg(p, - local.achievementCongrats.replace("%player%", player.getDisplayName()).replace( - "%achievementName%", - local.achievementAmountGame.replace("%amount%", String.valueOf(ao.get_level())))); - } - - checkForMoneyReward(player, ao.get_reward()); - break; - - case TOTAL_SCORE: - ao = checkNumberAchievement(player, 1, "totalScore"); - if (ao == null) - break; - - for (Player p : Bukkit.getServer().getOnlinePlayers()) { - Language local = playerData.getLanguageOfPlayer(p); - local.sendMsg(p, - local.achievementCongrats.replace("%player%", player.getDisplayName()).replace( - "%achievementName%", - local.achievementTotalScore.replace("%amount%", String.valueOf(ao.get_level())))); - } - - checkForMoneyReward(player, ao.get_reward()); - break; - - case AMOUNT_KILLS: - ao = checkNumberAchievement(player, 2, "kills"); - if (ao == null) - break; - - for (Player p : Bukkit.getServer().getOnlinePlayers()) { - Language local = playerData.getLanguageOfPlayer(p); - local.sendMsg(p, - local.achievementCongrats.replace("%player%", player.getDisplayName()).replace( - "%achievementName%", - local.achievementKills.replace("%amount%", String.valueOf(ao.get_level())))); - } - - checkForMoneyReward(player, ao.get_reward()); - break; - - case MULTIPLAYER_GAMES_WON: - ao = checkNumberAchievement(player, 3, "multiplayerWon"); - if (ao == null) - break; - - for (Player p : Bukkit.getServer().getOnlinePlayers()) { - Language local = playerData.getLanguageOfPlayer(p); - local.sendMsg(p, - local.achievementCongrats.replace("%player%", player.getDisplayName()).replace( - "%achievementName%", - local.achievementMultiplayerWon.replace("%amount%", String.valueOf(ao.get_level())))); - } - - checkForMoneyReward(player, ao.get_reward()); - break; - - case SURVIVE_5_MINUTES: - completed = checkSingleAchievement(player, "survive5Minutes"); - if (!completed) - break; - - for (Player p : Bukkit.getServer().getOnlinePlayers()) { - Language local = playerData.getLanguageOfPlayer(p); - local.sendMsg(p, local.achievementCongrats.replace("%player%", player.getDisplayName()) - .replace("%achievementName%", local.achievementSurvive5Minutes)); - } - - checkForMoneyReward(player, config.rewardSurvive5Minutes); - break; - - case REACH_HEIGHT_10: - completed = checkSingleAchievement(player, "reachHeight10"); - if (!completed) - break; - - for (Player p : Bukkit.getServer().getOnlinePlayers()) { - Language local = playerData.getLanguageOfPlayer(p); - local.sendMsg(p, local.achievementCongrats.replace("%player%", player.getDisplayName()) - .replace("%achievementName%", local.achievementReachHeight10)); - } - - checkForMoneyReward(player, config.rewardReachHeight10); - break; - - case FILL_THE_ARENA: - completed = checkSingleAchievement(player, "fillTheArena"); - if (!completed) - break; - - for (Player p : Bukkit.getServer().getOnlinePlayers()) { - Language local = playerData.getLanguageOfPlayer(p); - local.sendMsg(p, local.achievementCongrats.replace("%player%", player.getDisplayName()) - .replace("%achievementName%", local.achievementFillTheArena)); - } - - checkForMoneyReward(player, config.rewardFillTheArenasFloor); - break; - - case DIE_SECONDS_42: - completed = checkSingleAchievement(player, "theAnswerToLife"); - if (!completed) - break; - - for (Player p : Bukkit.getServer().getOnlinePlayers()) { - Language local = playerData.getLanguageOfPlayer(p); - local.sendMsg(p, local.achievementCongrats.replace("%player%", player.getDisplayName()) - .replace("%achievementName%", local.achievementTheAnswerToLife)); - } - - checkForMoneyReward(player, config.rewardTheAnswerToLife); - break; - - case DISCONNECT_IN_STARTUP: - completed = checkSingleAchievement(player, "theRageQuit"); - if (!completed) - break; - - for (Player p : Bukkit.getServer().getOnlinePlayers()) { - Language local = playerData.getLanguageOfPlayer(p); - local.sendMsg(p, local.achievementCongrats.replace("%player%", player.getDisplayName()) - .replace("%achievementName%", local.achievementTheRageQuit)); - } - - checkForMoneyReward(player, config.rewardTheRageQuit); - break; - - case JUMP_50_TIMES: - completed = checkSingleAchievement(player, "theKillerBunny"); - if (!completed) - break; - - for (Player p : Bukkit.getServer().getOnlinePlayers()) { - Language local = playerData.getLanguageOfPlayer(p); - local.sendMsg(p, local.achievementCongrats.replace("%player%", player.getDisplayName()) - .replace("%achievementName%", local.achievementTheKillerBunny)); - } - - checkForMoneyReward(player, config.rewardTheKillerBunny); - break; - - } - } - - private AchievementsObject checkNumberAchievement(Player player, int arrayNumber, String configName) { - int amount = 0; - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT " + configName + " FROM " + config.tablePrefix - + "PLAYERS WHERE UUID='" + player.getUniqueId().toString() + "';"); - try { - if (query.next()) - amount = query.getInt(configName); - } catch (SQLException e) { - e.printStackTrace(); - } - } else { - amount = playerData.getData().getInt("players." + player.getUniqueId().toString() + "." + configName, 0); - } - - for (AchievementsObject ao : achievements.get(arrayNumber)) - if (ao.get_level() == amount) - return ao; - - return null; - } - - private boolean checkSingleAchievement(Player player, String configName) { - boolean achieved = true; - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT " + configName + " FROM " + config.tablePrefix - + "PLAYERS WHERE UUID='" + player.getUniqueId().toString() + "';"); - try { - if (query.next()) { - achieved = query.getBoolean(configName); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } else { - achieved = playerData.getData() - .getBoolean("players." + player.getUniqueId().toString() + ".achievement." + configName, false); - } - - if (mysql.hasConnection()) { - mysql.update("UPDATE " + config.tablePrefix + "PLAYERS SET " + configName + "='1' WHERE UUID='" - + player.getUniqueId().toString() + "';"); - } else { - playerData.getData().set("players." + player.getUniqueId().toString() + ".achievement." + configName, true); - playerData.savePlayerData(); - } - - return !achieved; - } - - protected ArrayList> getachievements() { - return achievements; - } - - private void checkForMoneyReward(Player player, double amount) { - - if (!CubeRunner.isEconomyEnabled()) - return; - - if (!config.achievementsRewards) - return; - - economy.depositPlayer(player, amount); - Language l = playerData.getLanguageOfPlayer(player); - l.sendMsg(player, l.achievementMoneyReward.replace("%amount%", String.valueOf(amount)) - .replace("%currency%", economy.currencyNamePlural())); - - double original = 0; - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT money FROM " + config.tablePrefix - + "PLAYERS WHERE UUID='" + player.getUniqueId().toString() + "';"); - try { - if (query.next()) - original = query.getDouble("money"); - } catch (SQLException e) { - e.printStackTrace(); - } - - mysql.update("UPDATE " + config.tablePrefix + "PLAYERS SET money='" + (original + amount) - + "' WHERE UUID='" + player.getUniqueId().toString() + "';"); - } else { - original = playerData.getData().getDouble("players." + player.getUniqueId().toString() + ".money", 0); - playerData.getData().set("players." + player.getUniqueId().toString() + ".money", (original + amount)); - playerData.savePlayerData(); - } - - } - -} diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/achievements/AchievementsObject.java b/Bukkit_1.8/src/me/poutineqc/cuberunner/achievements/AchievementsObject.java deleted file mode 100644 index 0f50a24..0000000 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/achievements/AchievementsObject.java +++ /dev/null @@ -1,19 +0,0 @@ -package me.poutineqc.cuberunner.achievements; - -public class AchievementsObject { - private int level; - private double reward; - - public AchievementsObject(int level, double reward) { - this.level = level; - this.reward = reward; - } - - public int get_level() { - return level; - } - - public double get_reward() { - return reward; - } -} diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/achievements/TopManager.java b/Bukkit_1.8/src/me/poutineqc/cuberunner/achievements/TopManager.java deleted file mode 100644 index 68804c1..0000000 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/achievements/TopManager.java +++ /dev/null @@ -1,95 +0,0 @@ -package me.poutineqc.cuberunner.achievements; - -import java.util.ArrayList; -import java.util.List; - -import me.poutineqc.cuberunner.CubeRunner; -import me.poutineqc.cuberunner.PlayerData; - -public class TopManager { - - private PlayerData playerData; - - private String player; - private double score; - - private static List ratio = new ArrayList(); - private static List distanceRan = new ArrayList(); - private static List games = new ArrayList(); - private static List totalScore = new ArrayList(); - private static List kills = new ArrayList(); - private static List multiplayerWon = new ArrayList(); - - public TopManager(CubeRunner plugin) { - this.playerData = plugin.getPlayerData(); - updateAll(); - } - - public TopManager(String name, double score) { - this.player = name; - this.score = score; - } - - public void updateAll() { - ratio = updateTop("averageDistancePerGame"); - distanceRan = updateTop("totalDistance"); - games = updateTop("games"); - totalScore = updateTop("totalScore"); - kills = updateTop("kills"); - multiplayerWon = updateTop("multiplayerWon"); - } - - private List updateTop(String lookup) { - List tempList = new ArrayList(); - if (playerData.getData().contains("players")) { - for (String uuid : playerData.getData().getConfigurationSection("players").getKeys(false)) { - String name = playerData.getData().getString("players." + uuid + ".name", "unknown"); - double score = playerData.getData().getDouble("players." + uuid + "." + lookup, 0); - tempList.add(0, new TopManager(name, score)); - - for (int i = 0; i < 10 && i < tempList.size() - 1; i++) { - if (tempList.get(i).score < tempList.get(i + 1).score) { - TopManager tempValue = tempList.get(i); - tempList.set(i, tempList.get(i + 1)); - tempList.set(i + 1, tempValue); - } - } - } - } - - return tempList; - } - - protected String getPlayer() { - return player; - } - - protected double getScore() { - return score; - } - - public static List getRatio() { - return ratio; - } - - public static List getDistanceRan() { - return distanceRan; - } - - public static List getGames() { - return games; - } - - public static List getTotalScore() { - return totalScore; - } - - public static List getKills() { - return kills; - } - - public static List getMultiplayerWon() { - return multiplayerWon; - } - -} diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/commands/CommandType.java b/Bukkit_1.8/src/me/poutineqc/cuberunner/commands/CommandType.java deleted file mode 100644 index dcd8faa..0000000 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/commands/CommandType.java +++ /dev/null @@ -1,5 +0,0 @@ -package me.poutineqc.cuberunner.commands; - -public enum CommandType { - GENERAL, GAME_COMMANDS, ARENA_COMMANDS, ADMIN_COMMANDS, ALL; -} diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/commands/CubeRunnerCommand.java b/Bukkit_1.8/src/me/poutineqc/cuberunner/commands/CubeRunnerCommand.java deleted file mode 100644 index ca21e8e..0000000 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/commands/CubeRunnerCommand.java +++ /dev/null @@ -1,127 +0,0 @@ -package me.poutineqc.cuberunner.commands; - -import java.io.File; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; - -import me.poutineqc.cuberunner.CubeRunner; -import me.poutineqc.cuberunner.Permissions; - -public class CubeRunnerCommand { - - private String commandName; - private String description; - private String permission; - private String usage; - private CommandType type; - - private static ArrayList commands; - - private static CubeRunner plugin; - private static File commandFile; - private static FileConfiguration commandData; - - public CubeRunnerCommand(String commandName, String description, String permission, String usage, CommandType type) { - this.commandName = commandName; - this.description = description; - this.permission = permission; - this.usage = usage; - this.type = type; - } - - public CubeRunnerCommand(CubeRunner plugin) { - CubeRunnerCommand.plugin = plugin; - - commandFile = new File(plugin.getDataFolder(), "commands.yml"); - loadCommands(); - } - - private static void loadCommands() { - InputStream local = plugin.getResource("commands.yml"); - if (local != null) { - plugin.saveResource("commands.yml", false); - } else - plugin.getLogger().severe("Could not find commands.yml inside the jar file."); - - commandData = YamlConfiguration.loadConfiguration(commandFile); - commands = new ArrayList(); - - readingProcess(); - - commandFile.delete(); - } - - private static void readingProcess() { - for (String commandType : commandData.getConfigurationSection("commands").getKeys(false)) { - - CommandType type; - switch (commandType) { - case "game": - type = CommandType.GAME_COMMANDS; - break; - case "arena": - type = CommandType.ARENA_COMMANDS; - break; - case "general": - type = CommandType.GENERAL; - break; - case "admin": - type = CommandType.ADMIN_COMMANDS; - break; - default: - type = CommandType.ALL; - } - - for (String commandName : commandData.getConfigurationSection("commands." + commandType).getKeys(false)) { - String description = commandData.getString("commands." + commandType + "." + commandName + ".description"); - String permission = commandData.getString("commands." + commandType + "." + commandName + ".permission"); - String usage = commandData.getString("commands." + commandType + "." + commandName + ".usage"); - commands.add(new CubeRunnerCommand(commandName, description, permission, usage, type)); - } - } - } - - public static ArrayList getCommands() { - return commands; - } - - public static List getRequiredCommands(Player player, CommandType commandType) { - List requestedCommands = new ArrayList(); - - for (CubeRunnerCommand cmd : commands) - if (cmd.type == commandType || commandType == CommandType.ALL) - if (Permissions.hasPermission(cmd, player, false)) - requestedCommands.add(cmd); - - return requestedCommands; - } - - public static CubeRunnerCommand getCommand(String argument) { - for (CubeRunnerCommand command : commands) { - if (command.commandName.equalsIgnoreCase(argument)) - return command; - } - return null; - } - - public String getCommandName() { - return commandName; - } - - public String getPermission() { - return permission; - } - - public String getDescription() { - return description; - } - - public String getUsage() { - return usage; - } -} diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/commands/PlayerCommands.java b/Bukkit_1.8/src/me/poutineqc/cuberunner/commands/PlayerCommands.java deleted file mode 100644 index f0017a6..0000000 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/commands/PlayerCommands.java +++ /dev/null @@ -1,459 +0,0 @@ -package me.poutineqc.cuberunner.commands; - -import java.util.List; -import java.util.Map.Entry; - -import org.apache.commons.lang3.StringUtils; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import me.poutineqc.cuberunner.ArenaData; -import me.poutineqc.cuberunner.Configuration; -import me.poutineqc.cuberunner.CubeRunner; -import me.poutineqc.cuberunner.Language; -import me.poutineqc.cuberunner.MySQL; -import me.poutineqc.cuberunner.Permissions; -import me.poutineqc.cuberunner.PlayerData; -import me.poutineqc.cuberunner.achievements.AchievementGUI; -import me.poutineqc.cuberunner.achievements.Achievements; -import me.poutineqc.cuberunner.games.Arena; -import me.poutineqc.cuberunner.games.ColorGUI; -import me.poutineqc.cuberunner.games.GameState; -import me.poutineqc.cuberunner.tools.JoinGUI; - -public class PlayerCommands implements CommandExecutor { - private CubeRunner plugin; - private PlayerData playerData; - private JoinGUI joinGui; - private AchievementGUI achievementsGUI; - private ColorGUI colorGUI; - private ArenaData arenaData; - private MySQL mysql; - private Configuration config; - private Achievements achievements; - - public PlayerCommands(CubeRunner plugin) { - this.plugin = plugin; - arenaData = plugin.getArenaData(); - playerData = plugin.getPlayerData(); - joinGui = plugin.getJoinGui(); - achievementsGUI = plugin.getAchievementsGui(); - this.colorGUI = plugin.getColorGUI(); - this.mysql = plugin.getMySQL(); - this.config = plugin.getConfiguration(); - this.achievements = plugin.getAchievements(); - } - - @Override - public boolean onCommand(CommandSender sender, Command cmd, String cmdValue, String[] args) { - - if (!(sender instanceof Player)) { - sender.sendMessage("Only players can use CubeRunner's commands"); - return true; - } - - Player player = (Player) sender; - Language local = playerData.getLanguageOfPlayer(player); - - if (args.length == 0) { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8&m" + StringUtils.repeat(" ", 90))); - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - local.developper.replace("%developper%", plugin.getDescription().getAuthors().toString()))); - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - local.version.replace("%version%", plugin.getDescription().getVersion()))); - local.sendMsg(player, local.description.replace("%command%", cmdValue)); - player.sendMessage("\n"); - return true; - } - - if (args[0].equalsIgnoreCase("help")) { - String header = "&8&m" + StringUtils.repeat(" ", 30) + "&r &6CubeRunner &e" + local.keyWordHelp + " &8&m" - + StringUtils.repeat(" ", 30); - - if (args.length == 1) { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', header)); - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5/" + cmdValue + " help general &8- " + local.helpDescriptionGeneral)); - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5/" + cmdValue + " help game &8- " + local.helpDescriptionGame)); - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5/" + cmdValue + " help arena &8- " + local.helpDescriptionArena)); - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5/" + cmdValue + " help admin &8- " + local.helpDescriptionAdmin)); - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5/" + cmdValue + " help all &8- " + local.helpDescriptionAll)); - player.sendMessage("\n"); - return true; - } - - int pageNumber = 1; - CommandType commandType; - List requestedCommands; - - try { - pageNumber = Integer.parseInt(args[1]); - if (pageNumber < 1) - pageNumber = 1; - - commandType = CommandType.ALL; - - requestedCommands = CubeRunnerCommand.getRequiredCommands(player, commandType); - if (pageNumber > Math.ceil((double) requestedCommands.size() / 3)) - pageNumber = (int) Math.ceil((double) requestedCommands.size() / 3); - - } catch (NumberFormatException e) { - switch (args[1].toLowerCase()) { - case "game": - commandType = CommandType.GAME_COMMANDS; - break; - case "arena": - commandType = CommandType.ARENA_COMMANDS; - break; - case "admin": - commandType = CommandType.ADMIN_COMMANDS; - break; - case "general": - commandType = CommandType.GENERAL; - break; - default: - commandType = CommandType.ALL; - } - - requestedCommands = CubeRunnerCommand.getRequiredCommands(player, commandType); - - if (args.length > 2) { - try { - pageNumber = Integer.parseInt(args[2]); - if (pageNumber < 1) - pageNumber = 1; - - if (pageNumber > Math.ceil((double) requestedCommands.size() / 3)) - pageNumber = (int) Math.ceil((double) requestedCommands.size() / 3); - - } catch (NumberFormatException ex) { - } - } - } - - if (requestedCommands.size() == 0) - pageNumber = 0; - - player.sendMessage(ChatColor.translateAlternateColorCodes('&', header)); - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5" + local.keyWordCategory + ": &7" + commandType.toString() + ", &5" + local.keyWordPage + ": &7" - + String.valueOf(pageNumber) + "&8/&7" - + (int) (Math.ceil((double) requestedCommands.size() / 3)))); - - if (pageNumber == 0) { - local.sendMsg(player, local.helpNoPermission); - return true; - } - - for (int i = 3 * (pageNumber - 1); i < requestedCommands.size() && i < (3 * (pageNumber - 1)) + 3; i++) { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5" + requestedCommands.get(i).getUsage().replace("%command%", cmdValue))); - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - " &8- &7" + local.getCommandsDescription().get(requestedCommands.get(i).getDescription()))); - } - player.sendMessage("\n"); - return true; - } - - Arena arena; - CubeRunnerCommand command = CubeRunnerCommand.getCommand(args[0]); - if (command != null) { - - if (command.getCommandName().equalsIgnoreCase("language")) { - if (!Permissions.hasPermission(command, player, true)) - return true; - - if (args.length == 1) { - local.sendMsg(player, local.languageList); - for (Entry language : Language.getLanguages().entrySet()) - player.sendMessage("- " + language.getValue().languageName); - - return true; - } - - Entry entrySet = Language.getLanguage(args[1]); - if (entrySet == null) { - local.sendMsg(player, local.languageNotFound.replace("%cmd%", cmdValue)); - return true; - } - - playerData.setLanguage(player, entrySet.getKey()); - local = playerData.getLanguageOfPlayer(player); - - local.sendMsg(player, local.languageChangeSuccess); - return true; - } - - if (command.getCommandName().equalsIgnoreCase("info")) { - if (!Permissions.hasPermission(command, player, true)) - return true; - - if (args.length == 1) { - local.sendMsg(player, local.toolInfoMissingName); - local.sendMsg(player, local.toolInfoTip.replace("%cmd%", cmdValue)); - return true; - } - - arena = Arena.getArena(args[1]); - if (arena == null) { - local.sendMsg(player, local.arenaNotFound.replace("%arena%", args[1])); - local.sendMsg(player, local.toolInfoTip.replace("%cmd%", cmdValue)); - return true; - } - - local.sendMsg(player, local.toolInfoTip.replace("%cmd%", cmdValue)); - arena.displayInformation(player); - return true; - } - - if (command.getCommandName().equalsIgnoreCase("join") || command.getCommandName().equalsIgnoreCase("play") - || command.getCommandName().equalsIgnoreCase("list")) { - if (args.length > 1) - commandJoin(command, player, args.length, args[1], true); - else - commandJoin(command, player, args.length, "", true); - } - - if (command.getCommandName().equalsIgnoreCase("quit")) - commandQuit(command, player); - - if (command.getCommandName().equalsIgnoreCase("start")) - commandStart(command, player); - - if (command.getCommandName().equalsIgnoreCase("stats")) - commandStats(command, player); - - if (command.getCommandName().equalsIgnoreCase("reload")) { - if (!Permissions.hasPermission(command, player, true)) - return true; - - if (mysql.hasConnection()) - mysql.close(); - - config.loadConfiguration(plugin); - if (config.mysql) - mysql.updateInfo(plugin); - - plugin.initialiseEconomy(); - plugin.loadLanguages(); - - if (!mysql.hasConnection()) { - playerData.loadPlayerData(); - arenaData.loadArenaData(); - } - - achievements.setupAchievements(); - new SignPlace(plugin); - new PlayerInteract(plugin); - - Arena.loadExistingArenas(); - - local = playerData.getLanguageOfPlayer(player); - local.sendMsg(player, local.reloadSuccess); - return true; - } - - if (command.getCommandName().equalsIgnoreCase("new")) { - if (!Permissions.hasPermission(command, player, true)) - return true; - - if (args.length == 1) { - local.sendMsg(player, local.missingArenaName); - return true; - } - - if (Arena.getArena(args[1]) != null) { - local.sendMsg(player, local.arenaAlreadyExist.replace("%arena%", args[1])); - return true; - } - - new Arena(args[1], player); - local.sendMsg(player, local.arenaCreated.replace("%arena%", args[1])); - return true; - } - return true; - } - - arena = Arena.getArena(args[0]); - - if (arena == null) { - local.sendMsg(player, local.errorCommand.replace("%cmd%", cmdValue)); - return true; - } - - if (args.length == 1) { - local.sendMsg(player, local.missingEditArgument.replace("%cmd%", cmdValue)); - return true; - } - - command = CubeRunnerCommand.getCommand(args[1]); - if (command == null) { - local.sendMsg(player, local.errorCommand.replace("%cmd%", cmdValue)); - return true; - } - - if (command.getCommandName().equalsIgnoreCase("delete")) { - if (!Permissions.hasPermission(command, player, true)) - return true; - - arena.delete(player); - return true; - } - - if (command.getCommandName().equalsIgnoreCase("setzone")) { - if (!Permissions.hasPermission(command, player, true)) - return true; - - arena.setArena(player); - return true; - } - - if (command.getCommandName().equalsIgnoreCase("setlobby")) { - if (!Permissions.hasPermission(command, player, true)) - return true; - - arena.setLobby(player); - return true; - } - - if (command.getCommandName().equalsIgnoreCase("setstartpoint")) { - if (!Permissions.hasPermission(command, player, true)) - return true; - - arena.setStartPoint(player); - return true; - } - - if (command.getCommandName().equalsIgnoreCase("setcolor")) { - if (!Permissions.hasPermission(command, player, true)) - return true; - - if (arena.getGameState() == GameState.ACTIVE || arena.getGameState() == GameState.ENDING) { - local.sendMsg(player, local.guiColorEditWhileActive); - return true; - } - - colorGUI.openColorGUI(player, arena); - return true; - } - - if (command.getCommandName().equalsIgnoreCase("setminplayer")) { - if (!Permissions.hasPermission(command, player, true)) - return true; - - if (args.length < 3) { - local.sendMsg(player, local.arenaAmountPlayerMissingArgument); - return true; - } - - int amount = 0; - try { - amount = Integer.parseInt(args[2]); - } catch (NumberFormatException e) { - local.sendMsg(player, - local.arenaAmountPlayerInvalidArgument.replace("%error%", local.arenaAmountPlayerNotANumber)); - return true; - } - - arena.setMinPlayer(amount, player); - return true; - } - - if (command.getCommandName().equalsIgnoreCase("setmaxplayer")) { - if (!Permissions.hasPermission(command, player, true)) - return true; - - if (args.length < 3) { - local.sendMsg(player, local.arenaAmountPlayerMissingArgument); - } - - int amount = 0; - try { - amount = Integer.parseInt(args[2]); - } catch (NumberFormatException e) { - local.sendMsg(player, - local.arenaAmountPlayerInvalidArgument.replace("%error%", local.arenaAmountPlayerNotANumber)); - return true; - } - - arena.setMaxPlayer(amount, player); - return true; - } - - local.sendMsg(player, local.errorCommand); - return true; - } - - protected void commandJoin(CubeRunnerCommand command, Player player, int argsLength, String arenaName, - boolean teleport) { - if (!Permissions.hasPermission(command, player, true)) - return; - - Language local = playerData.getLanguageOfPlayer(player); - Arena arena = Arena.getArenaFromPlayer(player); - if (arena != null) { - local.sendMsg(player, local.playerAlreadyInGame); - return; - } - - if (argsLength == 1 || command.getCommandName().equalsIgnoreCase("list")) { - joinGui.openJoinGui(player, 1); - return; - } - - arena = Arena.getArena(arenaName); - if (arena == null) { - local.sendMsg(player, local.arenaNotFound.replace("%arena%", arenaName)); - return; - } - - arena.addPlayer(player, teleport); - } - - protected void commandQuit(CubeRunnerCommand command, Player player) { - if (!Permissions.hasPermission(command, player, true)) - return; - - Language local = playerData.getLanguageOfPlayer(player); - Arena arena = Arena.getArenaFromPlayer(player); - if (arena == null) { - local.sendMsg(player, local.playerNotInGame); - return; - } - - arena.removePlayer(player, true); - } - - protected void commandStats(CubeRunnerCommand command, Player player) { - if (!Permissions.hasPermission(command, player, true)) - return; - - achievementsGUI.openAchievementInventory(player); - } - - protected void commandStart(CubeRunnerCommand command, Player player) { - if (!Permissions.hasPermission(command, player, true)) - return; - - Language local = playerData.getLanguageOfPlayer(player); - Arena arena = Arena.getArenaFromPlayer(player); - if (arena == null) { - local.sendMsg(player, local.playerNotInGame); - return; - } - - if (arena.getGameState() != GameState.READY) { - local.sendMsg(player, local.gameNotReady); - return; - } - - arena.initiateGame(player); - } -} diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/commands/PlayerInteract.java b/Bukkit_1.8/src/me/poutineqc/cuberunner/commands/PlayerInteract.java deleted file mode 100644 index 16a55b4..0000000 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/commands/PlayerInteract.java +++ /dev/null @@ -1,63 +0,0 @@ -package me.poutineqc.cuberunner.commands; - -import org.bukkit.ChatColor; -import org.bukkit.block.Sign; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; -import org.bukkit.event.player.PlayerInteractEvent; - -import me.poutineqc.cuberunner.CubeRunner; -import me.poutineqc.cuberunner.Language; - -public class PlayerInteract implements Listener { - - private static Language local; - private PlayerCommands playerCommands; - - public PlayerInteract(CubeRunner plugin) { - PlayerInteract.local = plugin.getPlayerData().getLanguage(""); - this.playerCommands = plugin.getPlayerCommands(); - } - - @EventHandler - public void onPlayerInteract(PlayerInteractEvent event) { - if (!event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) - return; - - if (!(event.getClickedBlock().getState() instanceof Sign)) - return; - - Sign s = (Sign) event.getClickedBlock().getState(); - - if (!ChatColor.stripColor(s.getLine(1).toLowerCase().replace(" ", "")).equalsIgnoreCase( - ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.prefixLong).replace(" ", "")))) - return; - - event.setCancelled(true); - - Player player = event.getPlayer(); - - if (ChatColor.stripColor(s.getLine(2)) - .equalsIgnoreCase(ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.signPlay)))) - playerCommands.commandJoin(CubeRunnerCommand.getCommand("join"), player, 0, s.getLine(3), false); - - if (ChatColor.stripColor(s.getLine(2)) - .equalsIgnoreCase(ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.signJoin)))) - playerCommands.commandJoin(CubeRunnerCommand.getCommand("join"), player, 0, s.getLine(3), true); - - if (ChatColor.stripColor(s.getLine(2)) - .equalsIgnoreCase(ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.signQuit)))) - playerCommands.commandQuit(CubeRunnerCommand.getCommand("quit"), player); - - if (ChatColor.stripColor(s.getLine(2)) - .equalsIgnoreCase(ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.signStartGame)))) - playerCommands.commandStart(CubeRunnerCommand.getCommand("start"), player); - - if (ChatColor.stripColor(s.getLine(2)) - .equalsIgnoreCase(ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.signOpenStats)))) - playerCommands.commandStats(CubeRunnerCommand.getCommand("stats"), player); - - } -} diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/commands/SignPlace.java b/Bukkit_1.8/src/me/poutineqc/cuberunner/commands/SignPlace.java deleted file mode 100644 index 312a9d9..0000000 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/commands/SignPlace.java +++ /dev/null @@ -1,153 +0,0 @@ -package me.poutineqc.cuberunner.commands; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.SignChangeEvent; - -import me.poutineqc.cuberunner.CubeRunner; -import me.poutineqc.cuberunner.Language; -import me.poutineqc.cuberunner.Permissions; -import me.poutineqc.cuberunner.games.Arena; - -public class SignPlace implements Listener { - - private static Language local; - - public SignPlace(CubeRunner plugin) { - SignPlace.local = plugin.getPlayerData().getLanguage(""); - } - - @EventHandler - public void onSignPlace(SignChangeEvent event) { - - Player player = event.getPlayer(); - if (ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', event.getLine(0))).toLowerCase() - .contains("[cr]")) { - - if (!Permissions.hasPermission(Permissions.createSign, player, false)) { - setNoPermissionsSign(event); - return; - } - - if (event.getLine(1).equalsIgnoreCase("play")) - if (Arena.getArena(event.getLine(2)) != null) { - event.setLine(3, event.getLine(2)); - setPlaySign(event); - return; - } - - if (event.getLine(1).equalsIgnoreCase("join")) - if (Arena.getArena(event.getLine(2)) != null) { - event.setLine(3, event.getLine(2)); - setJoinSign(event); - return; - } - - if (event.getLine(1).equalsIgnoreCase("quit")) { - setQuitSign(event); - return; - } - - if (event.getLine(1).equalsIgnoreCase("start")) { - setStartSign(event); - return; - } - - if (event.getLine(1).equalsIgnoreCase("stats")) { - setStatsSign(event); - return; - } - - setNoValidSign(event); - - } else if (ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', event.getLine(1))).toLowerCase() - .contains("[cr]")) { - - if (!Permissions.hasPermission(Permissions.createSign, player, false)) { - setNoPermissionsSign(event); - return; - } - - if (event.getLine(2).equalsIgnoreCase("play")) - if (Arena.getArena(event.getLine(3)) == null) - setPlaySign(event); - - if (event.getLine(2).equalsIgnoreCase("join")) - if (Arena.getArena(event.getLine(3)) == null) - setJoinSign(event); - - if (event.getLine(2).equalsIgnoreCase("quit")) - setQuitSign(event); - - if (event.getLine(2).equalsIgnoreCase("start")) - setStartSign(event); - - if (event.getLine(2).equalsIgnoreCase("stats")) - setStatsSign(event); - - setNoValidSign(event); - - } else if (ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', event.getLine(2))).toLowerCase() - .contains("[cr]") - || ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', event.getLine(3))).toLowerCase() - .contains("[cr]")) { - - if (!Permissions.hasPermission(Permissions.createSign, player, false)) { - setNoPermissionsSign(event); - return; - } - - setNoValidSign(event); - } - } - - private void setNoPermissionsSign(SignChangeEvent e) { - e.setLine(0, ChatColor.translateAlternateColorCodes('&', local.signNoPermission0)); - e.setLine(1, ChatColor.translateAlternateColorCodes('&', local.signNoPermission1)); - e.setLine(2, ChatColor.translateAlternateColorCodes('&', local.signNoPermission2)); - e.setLine(3, ChatColor.translateAlternateColorCodes('&', local.signNoPermission3)); - } - - private void setNoValidSign(SignChangeEvent e) { - e.setLine(0, ChatColor.translateAlternateColorCodes('&', local.prefixLong)); - e.setLine(1, ChatColor.translateAlternateColorCodes('&', local.signNotValid1)); - e.setLine(2, ChatColor.translateAlternateColorCodes('&', local.signNotValid2)); - e.setLine(3, ChatColor.translateAlternateColorCodes('&', local.signNotValid3)); - } - - private void setStartSign(SignChangeEvent e) { - e.setLine(0, ""); - e.setLine(1, ChatColor.translateAlternateColorCodes('&', local.prefixLong)); - e.setLine(2, ChatColor.translateAlternateColorCodes('&', local.signStartGame)); - e.setLine(3, ""); - } - - private void setStatsSign(SignChangeEvent e) { - e.setLine(0, ""); - e.setLine(1, ChatColor.translateAlternateColorCodes('&', local.prefixLong)); - e.setLine(2, ChatColor.translateAlternateColorCodes('&', local.signOpenStats)); - e.setLine(3, ""); - } - - private void setQuitSign(SignChangeEvent e) { - e.setLine(0, ""); - e.setLine(1, ChatColor.translateAlternateColorCodes('&', local.prefixLong)); - e.setLine(2, ChatColor.translateAlternateColorCodes('&', local.signQuit)); - e.setLine(3, ""); - } - - private void setJoinSign(SignChangeEvent e) { - e.setLine(0, ""); - e.setLine(1, ChatColor.translateAlternateColorCodes('&', local.prefixLong)); - e.setLine(2, ChatColor.translateAlternateColorCodes('&', local.signJoin)); - } - - private void setPlaySign(SignChangeEvent e) { - e.setLine(0, ""); - e.setLine(1, ChatColor.translateAlternateColorCodes('&', local.prefixLong)); - e.setLine(2, ChatColor.translateAlternateColorCodes('&', local.signPlay)); - } - -} diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/games/ColorGUI.java b/Bukkit_1.8/src/me/poutineqc/cuberunner/games/ColorGUI.java deleted file mode 100644 index 5126f25..0000000 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/games/ColorGUI.java +++ /dev/null @@ -1,148 +0,0 @@ -package me.poutineqc.cuberunner.games; - -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; - -import me.poutineqc.cuberunner.CubeRunner; -import me.poutineqc.cuberunner.Language; -import me.poutineqc.cuberunner.PlayerData; -import me.poutineqc.cuberunner.tools.ItemStackManager; - -public class ColorGUI implements Listener { - - private PlayerData playerData; - - public ColorGUI(CubeRunner plugin) { - this.playerData = plugin.getPlayerData(); - } - - @EventHandler - public void onInventoryClick(InventoryClickEvent event) { - if (!(event.getWhoClicked() instanceof Player)) - return; - - Player player = (Player) event.getWhoClicked(); - Language local = playerData.getLanguageOfPlayer(player); - - if (!ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase(ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.guiColorName + " &0: &5CubeRunner")))) - return; - - if (event.getAction() == InventoryAction.NOTHING || event.getAction() == InventoryAction.UNKNOWN) - return; - - event.setCancelled(true); - - ItemStack item = event.getCurrentItem(); - - if (item.getType() != Material.STAINED_CLAY && item.getType() != Material.WOOL) - return; - - Arena arena = Arena - .getArena(ChatColor.stripColor(event.getInventory().getItem(0).getItemMeta().getLore().get(0))); - - if (arena.getGameState() == GameState.ACTIVE || arena.getGameState() == GameState.ENDING) { - player.closeInventory(); - local.sendMsg(player, local.guiColorEditWhileActive); - return; - } - - int valueOfItem = item.getDurability(); - if (item.getType() == Material.STAINED_CLAY) - valueOfItem += 16; - - if (item.getItemMeta().hasEnchants()) - arena.getColorManager() - .setColorIndice(arena.getColorManager().getColorIndice() - (int) Math.pow(2, valueOfItem)); - else - arena.getColorManager() - .setColorIndice(arena.getColorManager().getColorIndice() + (int) Math.pow(2, valueOfItem)); - - arena.resetArena(item); - openColorGUI(player, arena); - } - - public void openColorGUI(Player player, Arena arena) { - Language local = playerData.getLanguageOfPlayer(player); - - Inventory inv = Bukkit.createInventory(null, 54, - ChatColor.translateAlternateColorCodes('&', local.guiColorName + " &0: &5CubeRunner")); - ItemStackManager icon; - /*************************************************** - * Instructions - ***************************************************/ - - icon = new ItemStackManager(Material.BOOKSHELF, 4); - icon.setTitle(local.guiInstrictions); - for (String loreLine : local.guiColorInfo.split("\n")) - icon.addToLore(loreLine); - icon.addToInventory(inv); - - /*************************************************** - * Glass Spacer - ***************************************************/ - - icon = new ItemStackManager(Material.STAINED_GLASS_PANE); - icon.setData((short) 10); - icon.setTitle(" "); - - for (int i = 0; i < inv.getSize(); i++) - switch (i) { - case 9: - case 10: - case 11: - case 12: - case 13: - case 14: - case 15: - case 16: - case 17: - case 18: - case 27: - case 36: - case 45: - icon.setPosition(i); - icon.addToInventory(inv); - } - - /*************************************************** - * Blocks - ***************************************************/ - - List colorManager = arena.getColorManager().getAllBlocks(); - for (int i = 0; i < 32; i++) { - ItemStackManager item = colorManager.get(i); - item.setPosition((int) ((Math.floor(i / 8.0) * 9) + 19 + (i % 8))); - item.addToInventory(inv); - } - - /*************************************************** - * ArenaNAme - ***************************************************/ - - icon = new ItemStackManager(Material.PAPER); - icon.setTitle("&eArena:"); - icon.addToLore("&f" + arena.getName()); - - icon.setPosition(0); - icon.addToInventory(inv); - icon.setPosition(8); - icon.addToInventory(inv); - - /*************************************************** - * Display - ***************************************************/ - - player.openInventory(inv); - } -} diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/games/PlayerDamage.java b/Bukkit_1.8/src/me/poutineqc/cuberunner/games/PlayerDamage.java deleted file mode 100644 index 11f3ac5..0000000 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/games/PlayerDamage.java +++ /dev/null @@ -1,114 +0,0 @@ -package me.poutineqc.cuberunner.games; - -import java.sql.ResultSet; -import java.sql.SQLException; - -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityDamageEvent.DamageCause; - -import me.poutineqc.cuberunner.Configuration; -import me.poutineqc.cuberunner.CubeRunner; -import me.poutineqc.cuberunner.MySQL; -import me.poutineqc.cuberunner.PlayerData; -import me.poutineqc.cuberunner.achievements.AchievementType; -import me.poutineqc.cuberunner.achievements.Achievements; - -public class PlayerDamage implements Listener { - - private MySQL mySQL; - private Configuration config; - private PlayerData playerData; - private Achievements achievements; - - public PlayerDamage(CubeRunner plugin) { - this.mySQL = plugin.getMySQL(); - this.config = plugin.getConfiguration(); - this.playerData = plugin.getPlayerData(); - this.achievements = plugin.getAchievements(); - } - - @EventHandler - public void onPlayerDamageByEntity(EntityDamageByEntityEvent event) { - - if (!(event.getEntity() instanceof Player)) - return; - - Player player = (Player) event.getEntity(); - Arena arena = Arena.getArenaFromPlayer(player); - - if (arena == null) - return; - - if (event.getCause() != DamageCause.FALLING_BLOCK) { - event.setCancelled(true); - return; - } - - if (arena.getGameState() != GameState.ACTIVE) { - event.setCancelled(true); - return; - } - - User user = arena.getUser(player); - if (user.isEliminated()) { - event.setCancelled(true); - return; - } - - event.setDamage(0); - arena.eliminateUser(arena.getUser(player), false); - - String dammagerUUID = event.getDamager().getCustomName(); - if (!dammagerUUID.equalsIgnoreCase(player.getUniqueId().toString())) { - int kills = 0; - if (mySQL.hasConnection()) { - ResultSet query = mySQL.query("SELECT kills FROM " + config.tablePrefix - + "PLAYERS WHERE UUID='" + dammagerUUID + "';"); - try { - if (query.next()) - kills = query.getInt("kills"); - } catch (SQLException e) { - e.printStackTrace(); - } - - mySQL.update("UPDATE " + config.tablePrefix + "PLAYERS SET kills='" + ++kills - + "' WHERE UUID='" + dammagerUUID + "';"); - } else { - kills = playerData.getData().getInt("players." + dammagerUUID + ".kills", 0); - playerData.getData().set("players." + dammagerUUID + ".kills", ++kills); - playerData.savePlayerData(); - } - - achievements.checkAchievement(AchievementType.AMOUNT_KILLS, arena.getPlayerFromUUID(dammagerUUID)); - } - } - - @EventHandler - public void onPlayerDamage(EntityDamageEvent event) { - - if (!(event.getEntity() instanceof Player)) - return; - - Player player = (Player) event.getEntity(); - Arena arena = Arena.getArenaFromPlayer(player); - - if (arena == null) - return; - - if (event.getCause() != DamageCause.FALLING_BLOCK) { - event.setCancelled(true); - return; - } - - User user = arena.getUser(player); - if (user.isEliminated()) { - event.setCancelled(true); - return; - } - } - -} diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/games/PlayerDisconnect.java b/Bukkit_1.8/src/me/poutineqc/cuberunner/games/PlayerDisconnect.java deleted file mode 100644 index 3ef2522..0000000 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/games/PlayerDisconnect.java +++ /dev/null @@ -1,35 +0,0 @@ -package me.poutineqc.cuberunner.games; - -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerQuitEvent; - -import me.poutineqc.cuberunner.CubeRunner; -import me.poutineqc.cuberunner.achievements.AchievementType; -import me.poutineqc.cuberunner.achievements.Achievements; - -public class PlayerDisconnect implements Listener { - - private Achievements achievements; - - public PlayerDisconnect(CubeRunner plugin) { - this.achievements = plugin.getAchievements(); - } - - @EventHandler - public void onPlayerDisconnect(PlayerQuitEvent event) { - - Player player = event.getPlayer(); - Arena arena = Arena.getArenaFromPlayer(player); - - if (arena == null) - return; - - if (arena.getGameState() == GameState.STARTUP) - achievements.checkAchievement(AchievementType.DISCONNECT_IN_STARTUP, player); - - arena.removePlayer(player, true); - - } -} diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/games/PlayerTeleport.java b/Bukkit_1.8/src/me/poutineqc/cuberunner/games/PlayerTeleport.java deleted file mode 100644 index e087b56..0000000 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/games/PlayerTeleport.java +++ /dev/null @@ -1,54 +0,0 @@ -package me.poutineqc.cuberunner.games; - -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerTeleportEvent; - -import me.poutineqc.cuberunner.CubeRunner; -import me.poutineqc.cuberunner.Language; -import me.poutineqc.cuberunner.PlayerData; - -public class PlayerTeleport implements Listener { - - private PlayerData playerData; - - public PlayerTeleport(CubeRunner plugin) { - this.playerData = plugin.getPlayerData(); - } - - @EventHandler - public void onPlayerTeleport(PlayerTeleportEvent event) { - Player player = event.getPlayer(); - Arena arena = Arena.getArenaFromPlayer(player); - - if (arena == null) - return; - - if (teleportNearPoint(event.getTo(), arena.getLobby()) - || teleportNearPoint(event.getTo(), arena.getStartPoint()) || arena.isInsideArena(event.getTo())) - return; - - User user = arena.getUser(player); - if (user.hasLeft()) - return; - - Language local = playerData.getLanguageOfPlayer(player); - local.sendMsg(player, local.errorTeleport); - - event.setCancelled(true); - - } - - private boolean teleportNearPoint(Location to, Location point) { - if (to.getWorld() != point.getWorld()) - return false; - - if (to.distance(point) > 1) - return false; - - return true; - } - -} diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/games/User.java b/Bukkit_1.8/src/me/poutineqc/cuberunner/games/User.java deleted file mode 100644 index 2a52bdc..0000000 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/games/User.java +++ /dev/null @@ -1,115 +0,0 @@ -package me.poutineqc.cuberunner.games; - -import org.bukkit.entity.Player; - -import me.poutineqc.cuberunner.Configuration; -import me.poutineqc.cuberunner.tools.OriginalPlayerStats; - -public class User { - - private Player player; - private String uuid; - private String displayName; - private OriginalPlayerStats originalStats; - - private boolean left = false; - private boolean eliminated = false; - private long startTime; - private int score = 0; - private int jump = 0; - private boolean jumping = false; - private double distanceRan = 0; - - public User(Configuration config, Player player, boolean eliminated) { - this.player = player; - uuid = player.getUniqueId().toString(); - displayName = player.getDisplayName(); - originalStats = new OriginalPlayerStats(config, player); - this.eliminated = eliminated; - } - - public User(int time) { - this.score = time; - } - - protected void setStartTime() { - startTime = System.currentTimeMillis(); - } - - public Player getPlayer() { - return player; - } - - protected void addToScore() { - score++; - } - - protected int getScore() { - return score; - } - - protected String getDisplayName() { - return displayName; - } - - protected String getUUID() { - return uuid; - } - - protected int getGameLenght() { - return (int) (System.currentTimeMillis() - startTime); - } - - protected void returnStats() { - originalStats.returnStats(getPlayer()); - } - - protected void maxStats() { - originalStats.maxStats(getPlayer()); - } - - public boolean isEliminated() { - return eliminated; - } - - public void setEliminated(boolean eliminated) { - this.eliminated = eliminated; - } - - public void returnStats(Player player) { - originalStats.returnStats(player); - - } - - public void quit() { - left = true; - } - - public boolean hasLeft() { - return left; - } - - public void jump() { - jump++; - } - - public int getJump() { - return jump; - } - - public void setJumping(boolean jumping) { - this.jumping = jumping; - } - - public boolean isJumping() { - return jumping; - } - - public void addToDistanceRan(double distance) { - distanceRan += distance; - } - - public double getDistanceRan() { - return distanceRan; - } -} diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/tools/ItemStackManager.java b/Bukkit_1.8/src/me/poutineqc/cuberunner/tools/ItemStackManager.java deleted file mode 100644 index f8fec69..0000000 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/tools/ItemStackManager.java +++ /dev/null @@ -1,85 +0,0 @@ -package me.poutineqc.cuberunner.tools; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.SkullMeta; - -public class ItemStackManager { - - private int position; - private ItemStack item; - private ItemMeta meta; - List lore = new ArrayList(); - - public ItemStackManager(Material material) { - item = new ItemStack(material); - meta = item.getItemMeta(); - } - - public ItemStackManager(Material material, int position) { - this.position = position; - item = new ItemStack(material); - meta = item.getItemMeta(); - } - - public Material getMaterial() { - return item.getType(); - } - - public short getData() { - return item.getDurability(); - } - - public void setPosition(int position) { - this.position = position; - } - - public void setData(short data) { - item.setDurability(data); - } - - public void setTitle(String displayName) { - meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', displayName)); - } - - public void addToLore(String loreLine) { - lore.add(ChatColor.translateAlternateColorCodes('&', loreLine)); - } - - public Inventory addToInventory(Inventory inv) { - meta.setLore(lore); - item.setItemMeta(meta); - inv.setItem(position, item); - return inv; - } - - public void addEnchantement(Enchantment enchantment, int level) { - meta.addEnchant(Enchantment.DURABILITY, -1, true); - } - - public ItemStack getItem() { - meta.setLore(lore); - item.setItemMeta(meta); - return item; - } - - public void setPlayerHeadName(String player) { - if (meta instanceof SkullMeta) - ((SkullMeta) meta).setOwner(player); - } - - public String getDisplayName() { - return meta.getDisplayName(); - } - - public void clearLore() { - lore.clear(); - } -} diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/tools/JoinGUI.java b/Bukkit_1.8/src/me/poutineqc/cuberunner/tools/JoinGUI.java deleted file mode 100644 index 79d10b3..0000000 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/tools/JoinGUI.java +++ /dev/null @@ -1,188 +0,0 @@ -package me.poutineqc.cuberunner.tools; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.Inventory; - -import me.poutineqc.cuberunner.CubeRunner; -import me.poutineqc.cuberunner.Language; -import me.poutineqc.cuberunner.PlayerData; -import me.poutineqc.cuberunner.games.Arena; -import me.poutineqc.cuberunner.games.GameState; - -public class JoinGUI implements Listener { - - private PlayerData playerData; - - public JoinGUI(CubeRunner plugin) { - playerData = plugin.getPlayerData(); - } - - @EventHandler - public void onPlayerInventoryClick(InventoryClickEvent event) { - - if (!(event.getWhoClicked() instanceof Player)) - return; - - Player player = (Player) event.getWhoClicked(); - Language local = playerData.getLanguageOfPlayer(player); - - if (!ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase(ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.guiJoinName + " &0: &5CubeRunner")))) - return; - - event.setCancelled(true); - - if (event.getAction() == InventoryAction.NOTHING || event.getAction() == InventoryAction.UNKNOWN) - return; - - String itemName = event.getCurrentItem().getItemMeta().getDisplayName(); - - if (isEqualOnColorStrip(itemName, ChatColor.translateAlternateColorCodes('&', local.guiNextPage)) - || isEqualOnColorStrip(itemName, ChatColor.translateAlternateColorCodes('&', local.guiPreviousPage))) { - openJoinGui(player, - Integer.parseInt(ChatColor.stripColor(event.getCurrentItem().getItemMeta().getLore().get(0)))); - return; - } - - Arena arena = Arena.getArena(ChatColor.stripColor(itemName)); - if (arena == null) - return; - - if (event.getAction() == InventoryAction.PICKUP_HALF) { - arena.displayInformation(player); - } else { - arena.addPlayer(player, true); - } - - player.closeInventory(); - } - - private boolean isEqualOnColorStrip(String toCheck, String original) { - return ChatColor.stripColor(toCheck) - .equalsIgnoreCase(ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', original))); - } - - public void openJoinGui(Player player, int page) { - - List Arenas = new ArrayList(); - for (Arena arena : Arena.getArenas()) - Arenas.add(arena.getName()); - java.util.Collections.sort(Arenas); - - for (int i = 0; i < (page - 1) * 36; i++) { - Arenas.remove(0); - } - - int size; - if (Arenas.size() > 36) - size = 54; - else { - size = (int) (Math.ceil((Arenas.size() + 18.0) / 9.0) * 9.0); - } - - Language local = playerData.getLanguageOfPlayer(player); - Inventory inv = Bukkit.createInventory(null, size, - ChatColor.translateAlternateColorCodes('&', local.guiJoinName + " &0: &5CubeRunner")); - ItemStackManager icon; - - /*************************************************** - * Instructions - ***************************************************/ - - icon = new ItemStackManager(Material.BOOKSHELF, 4); - icon.setTitle(local.guiInstrictions); - for (String loreLine : local.guiJoinInfo.split("\n")) - icon.addToLore(loreLine); - icon.addToInventory(inv); - - /*************************************************** - * Glass Spacer - ***************************************************/ - - icon = new ItemStackManager(Material.STAINED_GLASS_PANE); - icon.setData((short) 10); - icon.setTitle(" "); - - for (int i = 0; i < inv.getSize(); i++) - switch (i) { - case 9: - case 10: - case 11: - case 12: - case 13: - case 14: - case 15: - case 16: - case 17: - icon.setPosition(i); - icon.addToInventory(inv); - } - - /*************************************************** - * arenas - ***************************************************/ - - icon = new ItemStackManager(Material.INK_SACK); - int slot = 18; - - for (String arenaName : Arenas) { - Arena arena = Arena.getArena(arenaName); - icon.clearLore(); - - if (arena.getGameState() == GameState.UNREADY) { - icon.setData((short) 8); - icon.setTitle(ChatColor.GOLD + arenaName); - icon.addToLore(local.keyWordUnset); - - } else if (arena.getGameState() == GameState.ACTIVE || arena.getGameState() == GameState.ENDING) { - icon.setData((short) 12); - icon.setTitle(ChatColor.GOLD + arenaName); - icon.addToLore(local.guiJoinStarted); - - } else { - icon.setData((short) 10); - icon.setTitle(ChatColor.GOLD + arenaName); - icon.addToLore(local.guiJoinReady); - } - - icon.setPosition(slot++); - icon.addToInventory(inv); - - /*************************************************** - * NextPage - ***************************************************/ - - if (slot == 54 && Arenas.size() > 36) { - icon = new ItemStackManager(Material.ARROW, 8); - icon.setTitle(local.guiNextPage); - icon.addToLore(String.valueOf(page + 1)); - icon.addToInventory(inv); - break; - } - } - - /*************************************************** - * Previous Page - ***************************************************/ - - if (page > 1) { - icon = new ItemStackManager(Material.ARROW, 7); - icon.setTitle(local.guiPreviousPage); - icon.addToLore(String.valueOf(page - 1)); - inv = icon.addToInventory(inv); - } - - player.openInventory(inv); - } - -} diff --git a/Bukkit_1.8/src/me/poutineqc/cuberunner/tools/OriginalPlayerStats.java b/Bukkit_1.8/src/me/poutineqc/cuberunner/tools/OriginalPlayerStats.java deleted file mode 100644 index a8e18f9..0000000 --- a/Bukkit_1.8/src/me/poutineqc/cuberunner/tools/OriginalPlayerStats.java +++ /dev/null @@ -1,61 +0,0 @@ -package me.poutineqc.cuberunner.tools; - -import java.util.Collection; - -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.potion.PotionEffect; - -import me.poutineqc.cuberunner.Configuration; - -public class OriginalPlayerStats { - - private Configuration config; - - private int level; - private float experience; - private GameMode gameMode; - private double health; - private int foodLevel; - private float saturation; - private Collection effects; - private Location location; - - public OriginalPlayerStats(Configuration config, Player player) { - this.config = config; - this.level = player.getLevel(); - this.experience = player.getExp(); - this.gameMode = player.getGameMode(); - this.health = player.getHealth(); - this.foodLevel = player.getFoodLevel(); - this.saturation = player.getSaturation(); - this.effects = player.getActivePotionEffects(); - this.location = player.getLocation(); - } - - public void returnStats(Player player) { - if (config.teleportAfterEnding) - player.teleport(location); - - player.setLevel(level); - player.setExp(experience); - player.setGameMode(gameMode); - player.setHealth(health); - player.setFoodLevel(foodLevel); - player.setSaturation(saturation); - player.addPotionEffects(effects); - } - - public void maxStats(Player player) { - player.setLevel(0); - player.setExp(0); - player.setGameMode(GameMode.ADVENTURE); - player.setHealth(20); - player.setFoodLevel(20); - player.setSaturation(20); - for (PotionEffect effect : player.getActivePotionEffects()) - player.removePotionEffect(effect.getType()); - - } -} diff --git a/Bukkit_1.9/LanguageFiles/de-De.yml b/Bukkit_1.9/LanguageFiles/de-De.yml deleted file mode 100644 index 3d46af9..0000000 --- a/Bukkit_1.9/LanguageFiles/de-De.yml +++ /dev/null @@ -1,174 +0,0 @@ -# CubeRunner plugin -# de-De.yml - Language file -# Made by EgoLeX - -# Language Name -languageName: "German" - -# Basic Messages -prefixShort: "&7[&5CR&7] " -prefixLong: "&7[&5CubeRunner&7] " -developper: "&5Erstellt durch: &7%developper%" -version: "&5Version: &7%version%" -description: "&dTippe &5/%command% help &d für eine Liste aller Kommandos." - -# Language Messages -languageList: "Verfügbare Sprachen" -languageNotFound: "&cSprache nicht gefunden. &8/%cmd% language &cfür eine Liste aller verfügbaren Sprachen" -languageChangeSuccess: "&aSprache erfolgreich auf Englisch gesetzt" - -# Errors and tips -missingPermission: "&4Du hast die nicht die benötigten Rechte um dies zu tun" -commandError: "&cKommando nicht gefunden. Tippe &8/%cmd% help &cfür eine Hilfe." -errorTeleport: "&cDu kannst dich nicht teleportieren während du dich im Spiel befindest. Tippe &7/cr quit &cum zu verlassen." -helpNoPermission: "&cDu hast keinerlei Rechte für die Kategorie." -toolInfoMissingName: "&cDu musst eine Arena auswählen." -toolInfoTip: "&8[&7Tipp&8] &7Du kannst auch &8/%cmd% list &7und rechtsklick machen um Informationen zu bekommen." - -# Player joining and leaving -playerAlreadyInGame: "&cDu bist bereits in einem CubeRunner Spiel." -playerNotInGame: "&cDu befindest dich derzeit in keinem CubeRunner Spiel." -playerJoinUnready: "&cDie Arena der du Beitreten wolltest exestiert anscheinend nicht" -playerJoinActive: "&cEs läuft derzeit ein Spiel in der Arena der du Beitreten wolltest." -playerJoinSpectator: "&dJoining als Zuschauer..." -playerJoinSuccess: "&aDu bist erfolgreich der Arena &2%arena%&a beigetreten." -playerJoinOthers: "&f%player% &dist der CubeRunners Arena beigetreten." -playerQuitSuccess: "&aDu hast die CubeRunners Arena &2%arena%&a verlassen." -playerQuitOthers: "&f%player% &dhat die CubeRunners Arena verlassen." - -# Active game messages -gameNotReady: "&cDas Spiel ist derzeit nicht bereit zum Starten" -arenaStartLessMin: "&cEs müssen mindestens %amount% Spieler in der Arena sein um das Spiel zu starten." -arenaStartLessMax: "&cEs dürfen maximal %amount% Spieler in der Arena sein um das Spiel zu starten." -gameCountdownStarted: "&dEin neues Spiel von &5CubeRunner &dwurde gefunden. Du kannst beitreten indem du folgendes Kommando verwendest: &5/cr join %arena%&d." -gameCountdownStopped: "&cDer Countdown wurde gestoppt. Nicht genügend Spieler." -gameCrushedPlayer: "&dDu bist mit einem Score von &5%score%&d rausgeflogen. Spiel Vorbei!" -gameCrushedOthers: "&f%player% &dist mit einem Score von &5%score%&d rausgeflogen." -gameEndingTeleport: "&dSpiel Vorbei. Teleport zurück in 5 Sekunden..." -gameEndingBest: "&6Glückwunsch an &f%player% &6welcher den neuen Highscore von &4%score% &6in der Arena &5%arena% hält." - -# Editing Arena Messages -missingArenaName: "&cDu musst einen Namen für deine Arena wählen." -arenaCreated: "&aEine Arena namens &2%arena% &awurde erfolgreich erstellt." -arenaAlreadyExist: "&cEine Arena namens &4%arena% &cexistiert bereits." -arenaNotExist: "&cEine Arena namens &4%arena% &cexistiert nicht." -arenaNotFound: "&cEine Arena namens &4%arena% &cwurde nicht gefunden." -reloadSuccess: "&aPlugin CubeRunner wurde erfolgreich reloaded." -missingEditArgument: "&cDu musst auswählen was du mit der Arena machen möchtest. Tippe &8/%cmd% help arena &cfür Hilfe." -missingWorldEditRegion: "&cDu musst erst eine WorldEdit Region festlegen." -arenaSetArena: "&aZone erfolgreich gesetzt für &2%arena%&a." -arenaSetStartPoint: "&aStartpunkt erfolgreich gesetzt für &2%arena%&a." -arenaSetLobby: "&aLobby erfolgreich gesetzt für &2%arena%&a." -arenaAmountPlayerMissingArgument: "&cDu musst eine Menge angeben um die Spieleranzahl zu ändern." -arenaAmountPlayerInvalidArgument: "&cDie Anzahl der Spieler die du angeben hast ist unbekannt. &7[&8%error%&7]" -arenaAmountPlayerNotANumber: "Keine gültige Nummer" -arenaAmountPlayerMinEqualZero: "Minimum weniger als 1" -arenaAmountPlayerMinBiggerMax: "Minimum größer als Maximum" -arenaAmountPlayerMaxBiggerMin: "Maximum kleiner als Minimum" -arenaAmountPlayerSuccess: "&aAnzahl an Spielern erfolgreich editiert für &2%arena%&a." -arenaDeleted: "&cArena entfernt." - -# GUI Messages -guiInstrictions: "&6Einleitung" -guiNextPage: "&2Nächste Seite" -guiPreviousPage: "&2Vorherige Seite" -guiJoinName: "&2Arena Liste" -guiJoinInfo: "&eKlicke auf den Namen der Arena zu der du möchtest." -guiJoinStarted: "&cAktiv : &eKlicke zum Zuschauen" -guiJoinReady: "&aBereit : &eKlicke zum Beitreten" -guiStatsName: "&6Stats" -guiStatsAverageDistancePerGame: "&bEigener Score pro Arena" -guiStatsTotalDistance: "&bTotale Distanz" -guiStatsGamePlayed: "&bgespielte Spiele" -guiStatsTotalPoints: "&bTotal Score" -guiStatsKills: "&bgetötete Spieler" -guiStatsMultiplayer: "&bMultiplayer Spiele gewonnen" -guiStatsTimePlayed: "&dSpielzeit" -guiStatsMoney: "&dGeldgewinn" -guiChallengeName: "&bHerausforderungen" -guiColorName: "&4Farbtool" -guiColorInfo: "&eDie ausgewählten Blöcke sind\n&edie derzeit ausgewählten.\n&eKlicke auf einen Block\n&eum In zu De/-Aktivieren." -guiColorEditWhileActive: "&cDu kannst die Farben nicht ändern während du Ingame bist." - -# Key Words -keyWordHelp: "Hilfe" -keyWordCategory: "Kategorie" -keyWordPage: "Seite" -keyWordHours: "Stunde" -keyWordMinutes: "Minute" -keyWordSeconds: "Sekunde" -keyWordDistance: "km" -keyWordAdvanced: "Erweiterte Information" -keyWordInformation: "Information" -keyWordMinimum: "Minimum" -keyWordMaximum: "Maximum" -keyWordCurrent: "Derzeitig" -keyWordAmountPlayer: "Spieleranzahl" -keyWordGameState: "Spielstatus" -keyWordUnset: "&7Arena Unset" -keyWordReady: "&aBereit" -keyWordStartup: "&9Anfang" -keyWordActive: "&cAktiv" -keyWordWorld: "Welt" -keyWordLobby: "Lobby" -keyWordStartPoint: "Startpunkt" -keyWordZoneMinPoint: " Zonen Koordinaten" -top10: "Top 10" -keyWordBestScore: "Bester Score" -keyWordBy: "von" -keyWordProgression: "Entwicklung" -keyWordCompleted: "Beendet" -keyWordNotCompleted: "nicht beendet" -keyWordReward: "Belohnung" - -# Signs -signNoPermission0: "&cDu hast nicht" -signNoPermission1: "&cdie benötigten Rechte" -signNoPermission2: "&cum ein DaC" -signNoPermission3: "&cSchild zu erstellen" -signNotValid1: "&cNone valid" -signNotValid2: "&cSchild Parameter" -signNotValid3: "&cVersuch es erneut" -signJoin: "&aBeitreten" -signQuit: "&cVerlassen" -signStartGame: "&9Spiel starten" -signOpenStats: "&6Statistiken" -signPlay: "&aSpielen" - -# Achievements -achievementCongrats: "&f%player% &6hat die Errungenschaft &d%achievementName%&6 erhalten!" -achievementAmountGame: "&dSpiele %amount% Spiele" -achievementTotalScore: "&dTotaler Score von %amount% erreichen" -achievementKills: "&dTöte %amount% Spieler" -achievementMultiplayerWon: "&dWin %amount% multiplayer game(s)" -achievementSurvive5Minutes: "&dÃœberlebe 5 Minuten" -reachHeight10: "&dErreiche eine Höhe von 10" -fillTheArena: "&dFülle den Arenaboden" -theAnswerToLife: "&dDie Antwort für das Leben, das Universum und alles andere" -achievementTheRageQuit: "&dDer Rage Quit" -achievementTheKillerBunny: "&dDer Todeshase" -achievementMoneyReward: "&dDu hast %amount%%currency% für die Errungenschaft bekommen." -achievementMoneyGame: "&dDu hast %amount%%currency% für das Ãœberleben von %amount2% Sekunden bekommen." - -# Help Messages -helpDescriptionAll: "&7Alle Kommandos" -helpDescriptionGeneral: "&7Generelle Spieler Kommandos" -helpDescriptionGame: "&7Kommandos für das einfach Spiel" -helpDescriptionArena: "&7Kommandos um die Arena zu erstellen" -helpDescriptionAdmin: "&7Admin Kommandos" -cmd-desc-list: "&7Öffnet eine Liste aller Kommandos." -cmd-desc-info: "&7Zeigt jede Information über eine Arena." -cmd-desc-language: "&7Änder deine eigene Sprache für das CubeRunners plugin." -cmd-desc-join: "&7Betrete ein spezifisches Spiel oder öffne die GUI." -cmd-desc-quit: "&7Verlasse dein derzeitiges Spiel." -cmd-desc-start: "&7Startcountdown eingeleitet." -cmd-desc-stats: "&7Öffnet deine CubeRunners Statistik." -cmd-desc-new: "&7Erstellt eine neue CubeRunners Arena." -cmd-desc-delete: "&7Lösche eine spezifische Arena." -cmd-desc-setzone: "&7Setze die Abgrenzung für eine spezifische Arena mit einer Worldedit Region." -cmd-desc-setlobby: "&7Setz die Lobby der spezifischen Arena." -cmd-desc-setstartpoint: "&7Setze den Startpunkt der Arena." -cmd-desc-setcolor: "&7Setz die Blockfarbe der Arena" -cmd-desc-setminplayer: "&7Setze die Minimale Spieleranzahl der Arena." -cmd-desc-setmaxplayer: "&7Setze die Maximale Spieleranzahl der Arena." -cmd-desc-reload: "&7Reloade die config, die Spieler Daten und die Sprachdatei." \ No newline at end of file diff --git a/Bukkit_1.9/LanguageFiles/en-US.yml b/Bukkit_1.9/LanguageFiles/en-US.yml deleted file mode 100644 index 200bf31..0000000 --- a/Bukkit_1.9/LanguageFiles/en-US.yml +++ /dev/null @@ -1,174 +0,0 @@ -# CubeRunner plugin -# Made by PoutineQc -# en-US.yml - Language file - -# Language Name -languageName: "English" - -# Basic Messages -prefixShort: "&7[&5CR&7] " -prefixLong: "&8[&5CubeRunner&8] " -developper: "&5Developped by: &7%developper%" -version: "&5Version: &7%version%" -description: "&dType &5/%command% help &d for the list of commands." - -# Language Messages -languageList: "Available languages" -languageNotFound: "&cLanguage not found. &8/%cmd% language &cfor a list of available languages" -languageChangeSuccess: "&aLanguage successfully set to english" - -# Errors and tips -missingPermission: "&4You don't have the permission to do this" -commandError: "&cCommand or arena not found. Type &8/%cmd% help &cfor help." -errorTeleport: "&cYou can't teleport away while you are in game. Do &7/cr quit &cto leave it." -helpNoPermission: "&cYou do not have any permissions in this category." -toolInfoMissingName: "&cYou need to choose an arena." -toolInfoTip: "&8[&7Tip&8] &7You may also do &8/%cmd% list &7and right click an arena to display it's information." - -# Player joining and leaving -playerAlreadyInGame: "&cYou are already in a CubeRunner game." -playerNotInGame: "&cYou are not currently in a CubeRunner game." -playerJoinUnready: "&cThe arena you are trying to join is not available." -playerJoinActive: "&cThere is already an active game in the arena you are trying to join." -playerJoinSpectator: "&dJoining as spectator..." -playerJoinSuccess: "&aYou have successfully joined the arena &2%arena%&a." -playerJoinOthers: "&f%player% &djoined your CubeRunner's arena." -playerQuitSuccess: "&aYou have left the CubeRunner's arena &2%arena%&a." -playerQuitOthers: "&f%player% &dleft your CubeRunner's arena." - -# Active game messages -gameNotReady: "&cThe game is not ready to start at the moment" -arenaStartLessMin: "&cThere must be at least %amount% players to start the game." -arenaStartLessMax: "&cThere must be at most %amount% players to start the game." -gameCountdownStarted: "&dA new game of &5CubeRunner &dhas been initiated. You may join with the command &5/cr join %arena%&d." -gameCountdownStopped: "&cThe countdown has been stopped. Not enough players in the game anymore." -gameCrushedPlayer: "&dYou have been crushed with a score of &5%score%&d. Game over!" -gameCrushedOthers: "&f%player% &dhas been crushed with a score of &5%score%&d." -gameEndingTeleport: "&dGame is over. Teleporting back in 5 seconds..." -gameEndingBest: "&6Congratulation to &f%player% &6who got the new best score of &4%score% &6in the arena &5%arena%" - -# Editing Arena Messages -missingArenaName: "&cYou must choose a name for your new arena." -arenaCreated: "&aAn arena named &2%arena% &ahas been successfully created." -arenaAlreadyExist: "&cAn arena named &4%arena% &calready exists." -arenaNotExist: "&cAn arena named &4%arena% &cdoes not exists." -arenaNotFound: "&cAn arena named &4%arena% &cwas not found." -reloadSuccess: "&aPlugin CubeRunner has been successfully reloaded." -missingEditArgument: "&cYou must choose what to do with this arena. Type &8/%cmd% help arena &cfor help." -missingWorldEditRegion: "&cYou must first choose a World Edit region." -arenaSetArena: "&aZone successfully set for the arena &2%arena%&a." -arenaSetStartPoint: "&aStart Point successfully set for the arena &2%arena%&a." -arenaSetLobby: "&aLobby successfully set for the arena &2%arena%&a." -arenaAmountPlayerMissingArgument: "&cYou must provide a quantity to change the amount of players." -arenaAmountPlayerInvalidArgument: "&cThe amount of player you entered is not valid. &7[&8%error%&7]" -arenaAmountPlayerNotANumber: "Not a number" -arenaAmountPlayerMinEqualZero: "Minimum lower than 1" -arenaAmountPlayerMinBiggerMax: "Minimum higher than maximum" -arenaAmountPlayerMaxBiggerMin: "Maximum lower than minimum" -arenaAmountPlayerSuccess: "&aAmount of player successfully edited for the arena &2%arena%&a." -arenaDeleted: "&cArena deleted." - -# GUI Messages -guiInstrictions: "&6Instructions" -guiNextPage: "&2Next Page" -guiPreviousPage: "&2Previous Page" -guiJoinName: "&2Arena List" -guiJoinInfo: "&eClick the name of the arena you wish to go to." -guiJoinStarted: "&cActive : &eClick to Spectate" -guiJoinReady: "&aReady : &eClick to Join" -guiStatsName: "&6Stats" -guiStatsAverageDistancePerGame: "&bAverage Score Per Game" -guiStatsTotalDistance: "&bTotal Distance Ran" -guiStatsGamePlayed: "&bGames played" -guiStatsTotalPoints: "&bTotal Score" -guiStatsKills: "&bPlayers Killed" -guiStatsMultiplayer: "&bMultiplayer games won" -guiStatsTimePlayed: "&dTime Played" -guiStatsMoney: "&dMoney Gained" -guiChallengeName: "&bChallenges" -guiColorName: "&4Color Picker" -guiColorInfo: "&eThe enchanted blocks are\nðe curently selected ones.\n&eClick a block to\n&eenable or disable it." -guiColorEditWhileActive: "&cYou can't edit the colors while a game is active." - -# Key Words -keyWordHelp: "Help" -keyWordCategory: "Category" -keyWordPage: "Page" -keyWordHours: "hours" -keyWordMinutes: "minutes" -keyWordSeconds: "seconds" -keyWordDistance: "km" -keyWordAdvanced: "Advanced Information" -keyWordInformation: "Information" -keyWordMinimum: "Minimum" -keyWordMaximum: "Maximum" -keyWordCurrent: "Current" -keyWordAmountPlayer: "amount of players" -keyWordGameState: "game state" -keyWordUnset: "&7Arena Unset" -keyWordReady: "&aReady" -keyWordStartup: "&9Startup" -keyWordActive: "&cActive" -keyWordWorld: "World" -keyWordLobby: "Lobby" -keyWordStartPoint: "Start point" -keyWordZoneMinPoint: " zone coordinate" -top10: "Top 10" -keyWordBestScore: "Best Score" -keyWordBy: "by" -keyWordProgression: "Progression" -keyWordCompleted: "Completed" -keyWordNotCompleted: "Not Completed" -keyWordReward: "Reward" - -# Signs -signNoPermission0: "&cYou don't have" -signNoPermission1: "&cthe permissions" -signNoPermission2: "&cto create a DaC" -signNoPermission3: "&csign, &4Sorry..." -signNotValid1: "&cNone valid" -signNotValid2: "&csign parameters" -signNotValid3: "&cTry again" -signJoin: "&aJoin Arena" -signQuit: "&cQuit Arena" -signStartGame: "&9Start Game" -signOpenStats: "&6Stats" -signPlay: "&aPlay" - -# Achievements -achievementCongrats: "&f%player% &6just completed the achievement &d%achievementName%&6!" -achievementAmountGame: "&dPlay %amount% game(s)" -achievementTotalScore: "&dReach total score of %amount%" -achievementKills: "&dKill %amount% player(s)" -achievementMultiplayerWon: "&dWin %amount% multiplayer game(s)" -achievementSurvive5Minutes: "&dSurvive 5 minutes" -reachHeight10: "&dReach height 10" -fillTheArena: "&dFill the arena's floor" -theAnswerToLife: "&dThe answer to life the universe and everything" -achievementTheRageQuit: "&dThe Rage Quit" -achievementTheKillerBunny: "&dThe Killer Bunny" -achievementMoneyReward: "&dYou gain %amount%%currency% for your achievement." -achievementMoneyGame: "&dYou gain %amount%%currency% for surviving %amount2% seconds." - -# Help Messages -helpDescriptionAll: "&7All Commands" -helpDescriptionGeneral: "&7General player commands" -helpDescriptionGame: "&7Commands to simply play the game" -helpDescriptionArena: "&7Commands to setup the arenas" -helpDescriptionAdmin: "&7Admin maintenance commands" -cmd-desc-list: "&7Opens a list of all the arenas." -cmd-desc-info: "&7Display every information from the selected arena." -cmd-desc-language: "&7Change your own language for CubeRunner's plugin." -cmd-desc-join: "&7Join the specified game or open a GUI to choose." -cmd-desc-quit: "&7Leave your current game." -cmd-desc-start: "&7Initiate the starting countdown." -cmd-desc-stats: "&7Opens your CubeRunner's stats." -cmd-desc-new: "&7Creates a new CubeRunner arena." -cmd-desc-delete: "&7Delete the specified arena." -cmd-desc-setzone: "&7Set the delimitation of the selected arena with a World Edit region." -cmd-desc-setlobby: "&7Set the lobby of the selected arena." -cmd-desc-setstartpoint: "&7Set the start point of the selected arena." -cmd-desc-setcolor: "&7Set the block colors for the arena" -cmd-desc-setminplayer: "&7Set the minimum amount of player for an arena." -cmd-desc-setmaxplayer: "&7Set the maximum amount of player for an arena." -cmd-desc-reload: "&7Reload the config, the player data and the language files." \ No newline at end of file diff --git a/Bukkit_1.9/LanguageFiles/fr-FR.yml b/Bukkit_1.9/LanguageFiles/fr-FR.yml deleted file mode 100644 index 762f4de..0000000 --- a/Bukkit_1.9/LanguageFiles/fr-FR.yml +++ /dev/null @@ -1,174 +0,0 @@ -# CubeRunner plugin -# Made by PoutineQc -# fr-FR.yml - Language file - -# Language Name -languageName: "Francais" - -# Basic Messages -prefixShort: "&7[&5CR&7] " -prefixLong: "&8[&5CubeRunner&8] " -developper: "&5Developpé par: &7%developper%" -version: "&5Version: &7%version%" -description: "&dTape &5/%command% help &d pour la liste des commandes." - -# Language Messages -languageList: "Langues disponibles" -languageNotFound: "&cLangue non-trouvée. &8/%cmd% language &cpour une liste des langues disponibles" -languageChangeSuccess: "&aLangue changée avec succès au francais" - -# Errors and tips -missingPermission: "&4Tu n'a pas la permission de faire cela." -commandError: "&cCommande ou arène introuvable. Tape &8/%cmd% help &cpour de la liste des commandes." -errorTeleport: "&cTu ne peux pas te téléporter en cours de partie. Fais &7/cr quit &cpour quiter" -helpNoPermission: "&cTu n'as aucune permission dans cette catégorie." -toolInfoMissingName: "&cIl faut spécifier une arène." -toolInfoTip: "&8[&7Truc&8] &7Tu peux aussi faire &8/%cmd% list &7et effectuer un clic droit sur une arène pour afficher ses informations." - -# Player joining and leaving -playerAlreadyInGame: "&cTu es déja dans une partie de CubeRunner." -playerNotInGame: "&cTu n'es pas dans une partie de CubeRunner." -playerJoinUnready: "&cL'arène que tu essaie de joindre n'est pas disponible." -playerJoinActive: "&cUne partie est déja en cours dans cette arène." -playerJoinSpectator: "&dPartie rejointe en tant que spectateur." -playerJoinSuccess: "&aTu as rejoint l'arène &2%arena%&a." -playerJoinOthers: "&f%player% &da rejoint votre partie." -playerQuitSuccess: "&aTu as quitté l'arène &2%arena%&a." -playerQuitOthers: "&f%player% &da quitté votre partie." - -# Active game messages -gameNotReady: "&cLa partie n'est pas prête a commencer." -arenaStartLessMin: "&cIl doit y avoir au moins %amount% joueurs pour commencer la partie." -arenaStartLessMax: "&cIl doit y avoir au plus %amount% joueurs pour commencer la partie." -gameCountdownStarted: "&dUne nouvelle partie de &5CubeRunner &dva commencer sous peu. Vous pouvez la rejoindre avec &5/cr join %arena%&d." -gameCountdownStopped: "&cLe décompte a été annulé. Il n'y a plus assez de joueurs." -gameCrushedPlayer: "&dTu t'es fait écraser avec un score de &5%score%&d. Game over!" -gameCrushedOthers: "&f%player% &ds'est fait écraser avec un score de &5%score%&d." -gameEndingTeleport: "&dLa partie est finie. Vous serez téléportés dans 5 secondes..." -gameEndingBest: "&6Bravo à &f%player% &6qui a fait le nouveau record de &4%score% &6dans l'arène &5%arena%" - -# Editing Arena Messages -missingArenaName: "&cTu dois spécifier un nom pour l'arène." -arenaCreated: "&aUne arène appelée &2%arena% &aà été créé." -arenaAlreadyExist: "&cIl y a déja une arène appelée &4%arena%&c." -arenaNotExist: "&cL'arène &4%arena% &cn'existe pas." -arenaNotFound: "&cUne arène nommée &4%arena% &cn'a pas été trouvée." -reloadSuccess: "&aLe plugin CubeRunner a été relancé avec succès." -missingEditArgument: "&cVous devez spécifier quoi faire avec cette arène. Tape &8/%cmd% help arena &cpour de l'aide." -missingWorldEditRegion: "&cTu dois sélectionner une région World Edit." -arenaSetArena: "&aLa zone a été sélectionnée avec succès pour l'arène &2%arena%&a." -arenaSetStartPoint: "&aLe point de départ a été sélectionné avec succès pour l'arène &2%arena%&a." -arenaSetLobby: "&aLa salle d'attente a été séléctionnée avec succès pour l'arène &2%arena%&a." -arenaAmountPlayerMissingArgument: "&cTu dois nommer une quantitée pour changer le nombre de joueurs." -arenaAmountPlayerInvalidArgument: "&cCe nombre de joueurs n'est pas valide. &7[&8%error%&7]" -arenaAmountPlayerNotANumber: "Pas un nombre" -arenaAmountPlayerMinEqualZero: "Minimum plus petit que 1" -arenaAmountPlayerMinBiggerMax: "Minimum plus haut que le maximum" -arenaAmountPlayerMaxBiggerMin: "Maximum plus bas que le minimum" -arenaAmountPlayerSuccess: "&aNombre de joueurs changé pour l'arène &2%arena%&a." -arenaDeleted: "&cArène supprimée." - -# GUI Messages -guiInstrictions: "&6Instructions" -guiNextPage: "&2Prochaine page" -guiPreviousPage: "&2Page précédente" -guiJoinName: "&2Arènes" -guiJoinInfo: "&eClick le nom de l'arène que tu souhaites joindre." -guiJoinStarted: "&cEn cours de partie : &eClique pour assister" -guiJoinReady: "&aPrête : &eClique pour rejoindre" -guiStatsName: "&6Statistiques" -guiStatsAverageDistancePerGame: "&bScore moyen par partie" -guiStatsTotalDistance: "&bDistance totale courue" -guiStatsGamePlayed: "&bParties jouées" -guiStatsTotalPoints: "&bScore total" -guiStatsKills: "&bJoueurs tués" -guiStatsMultiplayer: "&bParties multijoueurs gagnées" -guiStatsTimePlayed: "&dTemps joué" -guiStatsMoney: "&dArgent gagné" -guiChallengeName: "&bDéfis" -guiColorName: "&4Couleurs" -guiColorInfo: "&eLes blocs séléctionnés\n&esont ceux enchantés.\n&eCliquez sur un bloc\n&epour l'activer ou le désactiver." -guiColorEditWhileActive: "&cTu ne peux pas changer les couleur alors qu'il y a une partie en cours." - -# Key Words -keyWordHelp: "Aide" -keyWordCategory: "Catégorie" -keyWordPage: "Page" -keyWordHours: "heures" -keyWordMinutes: "minutes" -keyWordSeconds: "secondes" -keyWordDistance: "km" -keyWordAdvanced: "Information Avancé" -keyWordInformation: "Information" -keyWordMinimum: "Minimum" -keyWordMaximum: "Maximum" -keyWordCurrent: "Actuel" -keyWordAmountPlayer: "nombre de joueurs" -keyWordGameState: "état du jeu" -keyWordUnset: "&7Arène non définie" -keyWordReady: "&aPrêt" -keyWordStartup: "&9Démarrage" -keyWordActive: "&cActif" -keyWordWorld: "Monde" -keyWordLobby: "Salle d'attente" -keyWordStartPoint: "Point de départ" -keyWordZoneMinPoint: " coordonée de zone" -top10: "Top 10" -keyWordBestScore: "Meilleur Score" -keyWordBy: "par" -keyWordProgression: "Progression" -keyWordCompleted: "Complété" -keyWordNotCompleted: "Non Complété" -keyWordReward: "Récompense" - -# Signs -signNoPermission0: "&cManque perms" -signNoPermission1: "&cpour faire" -signNoPermission2: "&cdes pancartes" -signNoPermission3: "&cCubeRunner." -signNotValid1: "&cParamètres" -signNotValid2: "&cnon-valides" -signNotValid3: "&cRéessayez" -signJoin: "&aRejoindre" -signQuit: "&cQuitter" -signStartGame: "&9Commencer" -signOpenStats: "&6Statistiques" -signPlay: "&aJouer" - -# Achievements -achievementCongrats: "&f%player% &6a complété le défi &d%achievementName%&6!" -achievementAmountGame: "&dJouer %amount% partie(s)" -achievementTotalScore: "&dAtteidre le score total de %amount%" -achievementKills: "&dTuer %amount% joueur(s)" -achievementMultiplayerWon: "&dGagner %amount% partie(s) multijoueurs" -achievementSurvive5Minutes: "&dSurvivre 5 minutes" -reachHeight10: "&dAtteindre la hauteur 10" -fillTheArena: "&dRemplir le plancher de l'arène" -theAnswerToLife: "&dLa réponse à la vie, à l'univers et à l'humanité" -achievementTheRageQuit: "&dLe Rage Quit!" -achievementTheKillerBunny: "&dLe lapin tueur" -achievementMoneyReward: "&dTu a gagné %amount%%currency% pour ton défi." -achievementMoneyGame: "&dTu gagne %amount%%currency% pour avoir survécu %amount2% secondes." - -# Help Messages -helpDescriptionAll: "&7Toutes les commandes" -helpDescriptionGeneral: "&7Commandes générales pour joueurs" -helpDescriptionGame: "&7Commandes pour jouer au jeu" -helpDescriptionArena: "&7Commandes pour configurer les arènes" -helpDescriptionAdmin: "&7Commandes pour la maintenance du jeu" -cmd-desc-list: "&7Ouvre la liste des arènes." -cmd-desc-info: "&7Montre les informations de l'arène séléctionnée." -cmd-desc-language: "&7Change ton language personnel pour le plugin CubeRunner." -cmd-desc-join: "&7Rejoins la partie spécifiée ou ouvre un GUI pour choisir." -cmd-desc-quit: "&7Quitte la partie en cours." -cmd-desc-start: "&7Commence le décompte de démarrage." -cmd-desc-stats: "&7Ouvre les statistiques CubeRunner." -cmd-desc-new: "&7Crée une nouvelle arène CubeRunner." -cmd-desc-delete: "&7Supprime l'arène specifiée." -cmd-desc-setzone: "&7Configure la délimitation de l'arène en utilisant une région WorldEdit." -cmd-desc-setlobby: "&7Configure la salle d'attente de l'arène séléctionnée." -cmd-desc-setstartpoint: "&7Configure le point de départ de l'arène séléctionnée." -cmd-desc-setcolor: "&7Séléctionne les couleurs dans l'arène séléctionnée" -cmd-desc-setminplayer: "&7Configure le nombre de joueurs minimum pour l'arène séléctionée." -cmd-desc-setmaxplayer: "&7Configure le nombre de joueurs maximum pour l'arène séléctionée." -cmd-desc-reload: "&7Relance le fichier de config, le player data et les fichiers de langues." \ No newline at end of file diff --git a/Bukkit_1.9/commands.yml b/Bukkit_1.9/commands.yml deleted file mode 100644 index 66b03a0..0000000 --- a/Bukkit_1.9/commands.yml +++ /dev/null @@ -1,69 +0,0 @@ -commands: - general: - language: - usage: "/%command% language " - description: "cmd-desc-language" - permission: "cuberunner.player.language" - stats: - usage: "/%command% stats" - description: "cmd-desc-stats" - permission: "cuberunner.player.stats" - game: - list: - usage: "/%command% list" - description: "cmd-desc-list" - permission: "cuberunner.player.list" - info: - usage: "/%command% info " - description: "cmd-desc-info" - permission: "cuberunner.player.info" - join: - usage: "/%command% join [arena]" - description: "cmd-desc-join" - permission: "cuberunner.player.play.join" - quit: - usage: "/%command% quit" - description: "cmd-desc-quit" - permission: "cuberunner.player.play.quit" - start: - usage: "/%command% start" - description: "cmd-desc-start" - permission: "cuberunner.player.play.start" - arena: - new: - usage: "/%command% new " - description: "cmd-desc-new" - permission: "cuberunner.admin.edit.new" - delete: - usage: "/%command% delete" - description: "cmd-desc-delete" - permission: "cuberunner.admin.edit.delete" - setzone: - usage: "/%command% setzone" - description: "cmd-desc-setzone" - permission: "cuberunner.admin.edit.zone" - setlobby: - usage: "/%command% setlobby" - description: "cmd-desc-setlobby" - permission: "cuberunner.admin.edit.lobby" - setstartpoint: - usage: "/%command% setstartpoint" - description: "cmd-desc-setstartpoint" - permission: "cuberunner.admin.edit.startpoint" - setminplayer: - usage: "/%command% setminplayer " - description: "cmd-desc-setminplayer" - permission: "cuberunner.admin.edit.amountplayer.minplayer" - setmaxplayer: - usage: "/%command% setmaxplayer " - description: "cmd-desc-setmaxplayer" - permission: "cuberunner.admin.edit.amountplayer.maxplayer" - setcolor: - usage: "/%command% setcolor" - description: "cmd-desc-setcolor" - permission: "cuberunner.admin.edit.color" - admin: - reload: - usage: "/%command% reload" - description: "cmd-desc-reload" - permission: "cuberunner.admin.reload" \ No newline at end of file diff --git a/Bukkit_1.9/config.yml b/Bukkit_1.9/config.yml deleted file mode 100644 index 9bd43b5..0000000 --- a/Bukkit_1.9/config.yml +++ /dev/null @@ -1,52 +0,0 @@ -# CubeRunner plugin -# Made by PoutineQc -# config.yml - Config File -# Version: DO NOT edit this -version: '1.0' - -# Currently available languages: "fr-FR", "en-US" -# You may make another YAML file with another language -# Simply put it in the LanguageFiles folder and write it's name here (without the ".yml") -# This will option will be the " DaC server language".. The signs will be in this language. -# Warning: If you change this, a simple /dac reload won't do, you'll have to restart the server. -language: 'en-US' - -# Set to true if you have a MySQL database and fill the information below -mysql: false -host: 127.0.0.1 -port: 3306 -user: '' -password: '' -database: 'minecraft' -tablePrefix: 'cuberunner_' - -# If you want the Plugin's "logo" ([cr] if not changed) to be displayed in front of every messages -prefixInFrontOfEveryMessages: true - -# The countdown from the moment a players starts the game to the beginning of the block shower. (in seconds) -# Players may still join the game during this countdown -countdownTime: 15 - -# Set to true if you want players to get back to their original location before the teleport to the arena -teleportAfterEnding: true - -# Requires Vault and an economy plugin -economyRewards: false - -# Choose the reward amounts depending on the values of your server's economy -pricePerScore: 0.05 - -# if true, when completing a challenge gives a money reward -# will be false in all cases if you disable the economy rewards -achievementsRewards: true - -# To edit the GamePlayed challenges, Win challenges, Lost Challenge and DaCsDone challenges -# Go in the achievements.yml file in the plugin/DeACoudre folder - -# Challenge Rewards -rewardSurvive5Minutes: 25.0 -rewardFillTheArenasFloor: 50.0 -rewardReachHeight10: 100.0 -rewardTheRageQuit: 15.0 -rewardTheKillerBunny: 15.0 -rewardTheAnswerToLife: 15.0 \ No newline at end of file diff --git a/Bukkit_1.9/plugin.yml b/Bukkit_1.9/plugin.yml deleted file mode 100644 index 974fc7b..0000000 --- a/Bukkit_1.9/plugin.yml +++ /dev/null @@ -1,111 +0,0 @@ -name: CubeRunner -main : me.poutineqc.cuberunner.CubeRunner -version: 2.2.1 -description: Blocks are falling over your head! Can you outrun them? -load: postworld -author: PoutineQc -database: false -prefix: CubeRunner - -commands: - cuberunner: - description: CubeRunner commands - aliases: [cr, cuber, crunner] - usage: / - -permissions: - cuberunner.*: - description: Gives access to all CubeRunner's commands - children: - cuberunner.player.*: true - cuberunner.admin.*: true - cuberunner.player.*: - description: Gives access to all commands simply needed to play the game - children: - cuberunner.player.list: true - cuberunner.player.info: true - cuberunner.player.stats: true - cuberunner.player.language: true - cuberunner.player.play.*: true - cuberunner.player.list: - description: Allows to see the list of arenas - default: true - cuberunner.player.info: - description: Allows to see arenas' infos - default: true - cuberunner.player.stats: - description: Allows a player to see his stats - default: true - cuberunner.player.language: - description: Allows to change your personal language - default: true - cuberunner.player.play.*: - description: Gives all the access to play a game normally - children: - cuberunner.player.play.join: true - cuberunner.player.play.quit: true - cuberunner.player.play.start: true - cuberunner.player.play.join: - description: Allows to join a game - default: true - cuberunner.player.play.quit: - description: Allows to quit a game - default: true - cuberunner.player.play.start: - description: Allows to start a game - default: true - cuberunner.admin.*: - description: Gives access to all commands needed to setup arenas and other admin stuff. - children: - cuberunner.admin.reload: true - cuberunner.admin.info: true - cuberunner.admin.edit.*: true - cuberunner.admin.reload: - description: Allows to reload the plugin's config - default: op - cuberunner.admin.info: - description: Allows to see advanced arenas' infos - default: op - cuberunner.admin.edit.*: - description: Gives access to all commands needed to setup arenas and other admin stuff. - children: - cuberunner.admin.edit.new: true - cuberunner.admin.edit.delete: true - cuberunner.admin.edit.zone: true - cuberunner.admin.edit.lobby: true - cuberunner.admin.edit.startpoint: true - cuberunner.admin.edit.sign: true - cuberunner.admin.edit.color: true - cuberunner.admin.edit.amountplayer.*: true - cuberunner.admin.edit.new: - description: Allows to create a new arena - default: op - cuberunner.admin.edit.delete: - description: Allows to delete an arena - default: op - cuberunner.admin.edit.zone: - description: Allows to select the zone of an arena - default: op - cuberunner.admin.edit.lobby: - description: Allows to edit the lobby position of an arena - default: op - cuberunner.admin.edit.startpoint: - description: Allows to edit the startpoint of an arena - default: op - cuberunner.admin.edit.sign: - description: Allows to setup CubeRunner's signs - default: op - cuberunner.admin.edit.color: - description: Allows to set the block colors for the arena - default: op - cuberunner.admin.edit.amountplayer.*: - description: Gives access to the two commands that edit the min and max amount of players per arena. - children: - cuberunner.admin.edit.amountplayer.minplayer: true - cuberunner.admin.edit.amountplayer.maxplayer: true - cuberunner.admin.edit.amountplayer.minplayer: - description: Allows to edit the minimum amount of player for an arena - default: op - cuberunner.admin.edit.amountplayer.minplayer: - description: Allows to edit the maximum amount of player for an arena - default: op \ No newline at end of file diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/ArenaData.java b/Bukkit_1.9/src/me/poutineqc/cuberunner/ArenaData.java deleted file mode 100644 index 58b41f5..0000000 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/ArenaData.java +++ /dev/null @@ -1,47 +0,0 @@ -package me.poutineqc.cuberunner; - -import java.io.File; -import java.io.IOException; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; - -public class ArenaData { - - private File arenaFile; - private FileConfiguration arenaData; - - public ArenaData(CubeRunner plugin) { - arenaFile = new File(plugin.getDataFolder(), "arenaData.yml"); - if (!arenaFile.exists()) { - try { - arenaFile.createNewFile(); - } catch (IOException e) { - Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not create arenaData.ylm."); - } - } - loadArenaData(); - } - - public void loadArenaData() { - arenaData = YamlConfiguration.loadConfiguration(arenaFile); - } - - public FileConfiguration getData() { - return arenaData; - } - - public void saveArenaData() { - try { - arenaData.save(arenaFile); - } catch (IOException e) { - Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not save arenaData.yml!"); - } - } - - public void reloadArenaData() { - arenaData = YamlConfiguration.loadConfiguration(arenaFile); - } -} diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/CubeRunner.java b/Bukkit_1.9/src/me/poutineqc/cuberunner/CubeRunner.java deleted file mode 100644 index 8ee6f8f..0000000 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/CubeRunner.java +++ /dev/null @@ -1,251 +0,0 @@ -package me.poutineqc.cuberunner; - -import java.io.IOException; -import java.util.logging.Logger; - -import org.bukkit.Bukkit; -import org.bukkit.plugin.PluginDescriptionFile; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.RegisteredServiceProvider; -import org.bukkit.plugin.java.JavaPlugin; - -import me.poutineqc.cuberunner.achievements.AchievementGUI; -import me.poutineqc.cuberunner.achievements.Achievements; -import me.poutineqc.cuberunner.achievements.PlayerMovement; -import me.poutineqc.cuberunner.achievements.TopManager; -import me.poutineqc.cuberunner.commands.CubeRunnerCommand; -import me.poutineqc.cuberunner.commands.PlayerCommands; -import me.poutineqc.cuberunner.commands.PlayerInteract; -import me.poutineqc.cuberunner.commands.SignPlace; -import me.poutineqc.cuberunner.games.Arena; -import me.poutineqc.cuberunner.games.ColorGUI; -import me.poutineqc.cuberunner.games.PlayerDamage; -import me.poutineqc.cuberunner.games.PlayerDisconnect; -import me.poutineqc.cuberunner.games.PlayerTeleport; -import me.poutineqc.cuberunner.tools.JoinGUI; -import net.milkbowl.vault.economy.Economy; - -public class CubeRunner extends JavaPlugin { - - private Configuration config; - private MySQL mysql = new MySQL(); - private ArenaData arenaData; - private PlayerData playerData; - private TopManager topManager; - private Achievements achievements; - private AchievementGUI achievementsGui; - private JoinGUI joinGui; - private ColorGUI colorGUI; - private PlayerCommands playerCommands; - - private static Economy economy; - - public void onEnable() { - final PluginDescriptionFile pdfFile = getDescription(); - final Logger logger = getLogger(); - - config = new Configuration(this); - if (!initialiseEconomy()) - return; - new CubeRunnerCommand(this); - loadLanguages(); - connectMySQL(); - arenaData = new ArenaData(this); - playerData = new PlayerData(this); - topManager = new TopManager(this); - achievements = new Achievements(this); - achievementsGui = new AchievementGUI(this); - joinGui = new JoinGUI(this); - colorGUI = new ColorGUI(this); - new Arena(this); - new Permissions(this); - - playerCommands = new PlayerCommands(this); - enableListeners(); - getCommand("cuberunner").setExecutor(playerCommands); - - try { - Metrics metrics; - metrics = new Metrics(this); - metrics.start(); - } catch (IOException e) { - e.printStackTrace(); - } - - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() { - public void run() { - if (!playerData.isLatestVersion()) { - logger.info("----------------------------"); - logger.info("CubeRunner Updater"); - logger.info(""); - logger.info("An update for CubeRunner has been found!"); - logger.info("CubeRunner " + playerData.getLatestVersion()); - logger.info("You are running " + pdfFile.getVersion()); - logger.info(""); - logger.info("Download at https://www.spigotmc.org/resources/cuberunner.19715/"); - logger.info("----------------------------"); - } - Arena.loadExistingArenas(); - } - }, 1L); - - logger.info(pdfFile.getName() + " has been enabled (v" + pdfFile.getVersion() + ")"); - } - - public void onDisable() { - PluginDescriptionFile pdfFile = getDescription(); - Logger logger = getLogger(); - - if (mysql.hasConnection()) - mysql.close(); - - logger.info(pdfFile.getName() + " has been diabled"); - } - - public void connectMySQL() { - if (config.mysql) { - mysql = new MySQL(this, config.host, config.port, config.database, config.user, config.password); - - if (mysql.hasConnection()) - createMySQLTables(); - } else { - mysql = new MySQL(this); - } - } - - private void createMySQLTables() { - mysql.update("CREATE TABLE IF NOT EXISTS " + config.tablePrefix + "ARENAS (name varchar(32),world varchar(32)," - + "minAmountPlayer INT DEFAULT 1, maxAmountPlayer INT DEFAULT 8, highestScore INT DEFAULT 0," - + "colorIndice LONG, highestPlayer varchar(32) DEFAULT 'null'," - + "minPointX INT DEFAULT 0,minPointY INT DEFAULT 0,minPointZ INT DEFAULT 0," - + "maxPointX INT DEFAULT 0, maxPointY INT DEFAULT 0,maxPointZ INT DEFAULT 0," - + "lobbyX DOUBLE DEFAULT 0,lobbyY DOUBLE DEFAULT 0,lobbyZ DOUBLE DEFAULT 0," - + "lobbyPitch FLOAT DEFAULT 0,lobbyYaw FLOAT DEFAULT 0," - + "startPointX DOUBLE DEFAULT 0,startPointY DOUBLE DEFAULT 0,startPointZ DOUBLE DEFAULT 0," - + "startPointPitch FLOAT DEFAULT 0,startPointYaw FLOAT DEFAULT 0);"); - mysql.update("ALTER TABLE " + config.tablePrefix + "ARENAS CONVERT TO CHARACTER SET utf8;"); - mysql.update("CREATE TABLE IF NOT EXISTS " + config.tablePrefix - + "PLAYERS (UUID varchar(64), name varchar(64), language varchar(32), timePlayed INT DEFAULT 0," - + "money DOUBLE DEFAULT 0, averageDistancePerGame DOUBLE DEFAULT 0, totalDistance DOUBLE DEFAULT 0," - + "games INT DEFAULT 0, totalScore INT DEFAULT 0, kills INT DEFAULT 0, multiplayerWon INT DEFAULT 0," - + "survive5Minutes BOOLEAN DEFAULT FALSE, reachHeight10 BOOLEAN DEFAULT FALSE," - + "fillTheArena BOOLEAN DEFAULT FALSE, theAnswerToLife BOOLEAN DEFAULT FALSE," - + "theRageQuit BOOLEAN DEFAULT FALSE, theKillerBunny BOOLEAN DEFAULT FALSE);"); - mysql.update("ALTER TABLE " + config.tablePrefix + "PLAYERS CONVERT TO CHARACTER SET utf8;"); - mysql.update("CREATE OR REPLACE VIEW " + config.tablePrefix - + "AVERAGESCORE AS SELECT name, averageDistancePerGame FROM " + config.tablePrefix - + "PLAYERS ORDER BY averageDistancePerGame DESC LIMIT 10"); - mysql.update( - "CREATE OR REPLACE VIEW " + config.tablePrefix + "TOTALDISTANCE AS SELECT name, totalDistance FROM " - + config.tablePrefix + "PLAYERS ORDER BY totalDistance DESC LIMIT 10"); - mysql.update("CREATE OR REPLACE VIEW " + config.tablePrefix + "MOSTGAMES AS SELECT name, games FROM " - + config.tablePrefix + "PLAYERS ORDER BY games DESC LIMIT 10"); - mysql.update("CREATE OR REPLACE VIEW " + config.tablePrefix + "TOTALSCORE AS SELECT name, totalScore FROM " - + config.tablePrefix + "PLAYERS ORDER BY totalScore DESC LIMIT 10"); - mysql.update("CREATE OR REPLACE VIEW " + config.tablePrefix + "KILLS AS SELECT name, kills FROM " - + config.tablePrefix + "PLAYERS ORDER BY kills DESC LIMIT 10"); - mysql.update( - "CREATE OR REPLACE VIEW " + config.tablePrefix + "MULTIPLAYERWON AS SELECT name, multiplayerWon FROM " - + config.tablePrefix + "PLAYERS ORDER BY multiplayerWon DESC LIMIT 10"); - } - - public void loadLanguages() { - Language.clearLanguages(); - - // A CHANGER AVANT LA RELEASE - new Language(this); - new Language("en-US", false); - new Language("fr-FR", false); - new Language("de-De", false); - new Language(config.language, false); - } - - public boolean initialiseEconomy() { - if (config.economyRewards) - if (!setupEconomy()) { - getLogger().warning("Vault not found."); - getLogger().warning("Add Vault to your plugins or disable monetary rewards in the config."); - getLogger().info("Disabling CubeRunner..."); - getServer().getPluginManager().disablePlugin(this); - return false; - } - return true; - } - - private boolean setupEconomy() { - economy = null; - if (getServer().getPluginManager().getPlugin("Vault") == null) { - return false; - } - RegisteredServiceProvider rsp = getServer().getServicesManager().getRegistration(Economy.class); - if (rsp == null) { - return false; - } - economy = rsp.getProvider(); - return economy != null; - } - - public static boolean isEconomyEnabled() { - return economy != null; - } - - public static Economy getEconomy() { - return economy; - } - - private void enableListeners() { - PluginManager pm = getServer().getPluginManager(); - - pm.registerEvents(playerData, this); - pm.registerEvents(new PlayerDamage(this), this); - pm.registerEvents(new PlayerTeleport(this), this); - pm.registerEvents(new PlayerDisconnect(this), this); - pm.registerEvents(new SignPlace(this), this); - pm.registerEvents(new PlayerInteract(this), this); - pm.registerEvents(new PlayerMovement(this), this); - pm.registerEvents(achievementsGui, this); - pm.registerEvents(joinGui, this); - pm.registerEvents(colorGUI, this); - } - - public Configuration getConfiguration() { - return config; - } - - public MySQL getMySQL() { - return mysql; - } - - public ArenaData getArenaData() { - return arenaData; - } - - public PlayerData getPlayerData() { - return playerData; - } - - public JoinGUI getJoinGui() { - return joinGui; - } - - public AchievementGUI getAchievementsGui() { - return achievementsGui; - } - - public PlayerCommands getPlayerCommands() { - return playerCommands; - } - - public Achievements getAchievements() { - return achievements; - } - - public TopManager getTopManager() { - return topManager; - } - - public ColorGUI getColorGUI() { - return colorGUI; - } - -} diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/Language.java b/Bukkit_1.9/src/me/poutineqc/cuberunner/Language.java deleted file mode 100644 index 29dd745..0000000 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/Language.java +++ /dev/null @@ -1,384 +0,0 @@ -package me.poutineqc.cuberunner; - -import java.io.File; -import java.io.InputStream; -import java.util.HashMap; -import java.util.Map.Entry; - -import org.bukkit.ChatColor; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; - -import me.poutineqc.cuberunner.commands.CubeRunnerCommand; -import me.poutineqc.cuberunner.games.User; -import me.poutineqc.cuberunner.tools.CaseInsensitiveMap; - -public class Language { - - private static CubeRunner plugin; - private static Configuration config; - - private static File langFolder; - - private File languageFile; - private FileConfiguration languageData; - - private static HashMap languages = new HashMap<>(); - private CaseInsensitiveMap commandDescriptions; - - public String languageName; - public String prefixShort; - public String prefixLong; - public String developper; - public String version; - public String description; - - public String errorPermission; - public String errorCommand; - public String errorTeleport; - public String helpNoPermission; - public String toolInfoMissingName; - public String toolInfoTip; - - public String playerAlreadyInGame; - public String playerNotInGame; - public String playerJoinUnready; - public String playerJoinActive; - public String playerJoinSpectator; - public String playerJoinSuccess; - public String playerJoinOthers; - public String playerQuitSuccess; - public String playerQuitOthers; - - public String gameNotReady; - public String gameStartLessMin; - public String gameStartLessMax; - public String gameCountdownStarted; - public String gameCountdownStopped; - public String gameCrushedPlayer; - public String gameCrushedOthers; - - public String endingTeleport; - public String endingBest; - - public String missingArenaName; - public String arenaCreated; - public String arenaAlreadyExist; - public String arenaNotExist; - public String arenaNotFound; - public String reloadSuccess; - public String missingEditArgument; - public String missingWorldEditRegion; - public String arenaSetArena; - public String arenaSetStartPoint; - public String arenaSetLobby; - public String arenaAmountPlayerMissingArgument; - public String arenaAmountPlayerInvalidArgument; - public String arenaAmountPlayerNotANumber; - public String arenaAmountPlayerMinEqualZero; - public String arenaAmountPlayerMinBiggerMax; - public String arenaAmountPlayerMaxBiggerMin; - public String arenaAmountPlayerSuccess; - public String arenaDeleted; - - public String guiInstrictions; - public String guiNextPage; - public String guiPreviousPage; - - public String guiJoinName; - public String guiJoinInfo; - public String guiJoinStarted; - public String guiJoinReady; - public String guiStatsName; - public String guiStatsAverageDistancePerGame; - public String guiStatsTotalDistance; - public String guiStatsGamePlayed; - public String guiStatsTotalPoints; - public String guiStatsKills; - public String guiStatsMultiplayer; - public String guiStatsTimePlayed; - public String guiStatsMoney; - public String guiChallengeName; - public String guiColorName; - public String guiColorInfo; - public String guiColorEditWhileActive; - - public String keyWordHelp; - public String keyWordCategory; - public String keyWordPage; - public String keyWordHours; - public String keyWordMinutes; - public String keyWordSeconds; - public String keyWordDistance; - public String keyWordInformation; - public String keyWordAdvanced; - public String keyWordMinimum; - public String keyWordMaximum; - public String keyWordCurrent; - public String keyWordAmountPlayer; - public String keyWordGameState; - public String keyWordUnset; - public String keyWordReady; - public String keyWordStartup; - public String keyWordActive; - public String keyWordWorld; - public String keyWordLobby; - public String keyWordStartPoint; - public String keyWordZone; - public String keyWordTop10; - public String keyWordBestScore; - public String keyWordBy; - public String keyWordProgression; - public String keyWordCompleted; - public String keyWordNotCompleted; - public String keyWordReward; - - public String helpDescriptionAll; - public String helpDescriptionGeneral; - public String helpDescriptionGame; - public String helpDescriptionArena; - public String helpDescriptionAdmin; - - public String signNoPermission0; - public String signNoPermission1; - public String signNoPermission2; - public String signNoPermission3; - public String signNotValid1; - public String signNotValid2; - public String signNotValid3; - public String signStartGame; - public String signOpenStats; - public String signQuit; - public String signJoin; - public String signPlay; - - public String achievementCongrats; - public String achievementAmountGame; - public String achievementTotalScore; - public String achievementKills; - public String achievementMultiplayerWon; - public String achievementSurvive5Minutes; - public String achievementReachHeight10; - public String achievementFillTheArena; - public String achievementTheAnswerToLife; - public String achievementTheRageQuit; - public String achievementTheKillerBunny; - public String achievementMoneyReward; - public String achievementMoneyGame; - - public String languageList; - public String languageNotFound; - public String languageChangeSuccess; - - public Language(CubeRunner plugin) { - Language.plugin = plugin; - config = plugin.getConfiguration(); - - langFolder = new File(plugin.getDataFolder(), "LanguageFiles"); - if (!langFolder.exists()) - langFolder.mkdir(); - } - - public Language(String fileName, boolean forceFileOverwrite) { - languageFile = new File(langFolder.getPath(), fileName + ".yml"); - if (forceFileOverwrite) { - languageFile.delete(); - plugin.saveResource("LanguageFiles/" + fileName + ".yml", false); - } - - if (!languageFile.exists()) { - InputStream local = plugin.getResource("LanguageFiles/" + fileName + ".yml"); - if (local != null) { - plugin.saveResource("LanguageFiles/" + fileName + ".yml", false); - } else - plugin.getLogger().info("Could not find " + fileName + ".yml"); - } - - languages.put(fileName, this); - loadLanguage(); - } - - private void loadLanguage() { - languageData = YamlConfiguration.loadConfiguration(languageFile); - - languageName = languageData.getString("languageName"); - prefixShort = languageData.getString("prefixShort", "&7[&5CR&7] "); - prefixLong = languageData.getString("prefixLong", "&8[&5CubeRunner&8] "); - developper = languageData.getString("developper", "&5Developped by: &7%developper%"); - version = languageData.getString("version", "&5Version: &7%version%"); - description = languageData.getString("description", "&dType &5/%command% help &d for the list of commands."); - - errorPermission = languageData.getString("missingPermission", "&4You don't have the permission to do this"); - errorCommand = languageData.getString("commandError", "&cCommand or arena not found. Type &8/%cmd% help &cfor help."); - errorTeleport = languageData.getString("errorTeleport", "&cYou can't teleport away while you are in game. Do &7/cr quit &cto leave it."); - helpNoPermission = languageData.getString("helpNoPermission", "&cYou do not have any permissions in this category."); - toolInfoMissingName = languageData.getString("toolInfoMissingName", "&cYou need to choose an arena."); - toolInfoTip = languageData.getString("toolInfoTip", "&8[&7Tip&8] &7You may also do &8/%cmd% list &7and right click an arena to display it's information."); - - playerAlreadyInGame = languageData.getString("playerAlreadyInGame", "&cYou are already in a CubeRunner game."); - playerNotInGame = languageData.getString("playerNotInGame", "&cYou are not currently in a CubeRunner game."); - playerJoinUnready = languageData.getString("playerJoinUnready", "&cThe arena you are trying to join is not available."); - playerJoinActive = languageData.getString("playerJoinActive", "&cThere is already an active game in the arena you are trying to join."); - playerJoinSpectator = languageData.getString("playerJoinSpectator", "&dJoining as spectator..."); - playerJoinSuccess = languageData.getString("playerJoinSuccess", "&aYou have successfully joined the arena &2%arena%&a."); - playerJoinOthers = languageData.getString("playerJoinOthers", "&f%player% &djoined your CubeRunner's arena."); - playerQuitSuccess = languageData.getString("playerQuitSuccess", "&aYou have left the CubeRunner's arena &2%arena%&a."); - playerQuitOthers = languageData.getString("playerQuitOthers", "&f%player% &dleft your CubeRunner's arena."); - - gameNotReady = languageData.getString("gameNotReady", "&cThe game is not ready to start at the moment"); - gameStartLessMin = languageData.getString("arenaStartLessMin", "&cThere must be at least %amount% players to start the game."); - gameStartLessMax = languageData.getString("arenaStartLessMax", "&cThere must be at most %amount% players to start the game."); - gameCountdownStarted = languageData.getString("gameCountdownStarted", "&dA new game of &5CubeRunner &dhas been initiated. You may join with the command &5/cr join %arena%&d."); - gameCountdownStopped = languageData.getString("gameCountdownStopped", "&cThe countdown has been stopped. Not enough players in the game anymore."); - gameCrushedPlayer = languageData.getString("gameCrushedPlayer", "&dYou have been crushed with a score of &5%score%&d. Game over!"); - gameCrushedOthers = languageData.getString("gameCrushedOthers", "&f%player% &dhas been crushed with a score of &5%score%&d."); - endingTeleport = languageData.getString("gameEndingTeleport", "&dGame is over. Teleporting back in 5 seconds..."); - endingBest = languageData.getString("gameEndingBest", "&6Congratulation to &f%player% &6who got the new best score of &4%score% &6in the arena &5%arena%"); - - missingArenaName = languageData.getString("missingArenaName", "&cYou must choose a name for your new arena."); - arenaCreated = languageData.getString("arenaCreated", "&aAn arena named &2%arena% &ahas been successfully created."); - arenaAlreadyExist = languageData.getString("arenaAlreadyExist", "&cAn arena named &4%arena% &calready exists."); - arenaNotExist = languageData.getString("arenaNotExist", "&cAn arena named &4%arena% &cdoes not exists."); - arenaNotFound = languageData.getString("arenaNotFound", "&cAn arena named &4%arena% &cwas not found."); - reloadSuccess = languageData.getString("reloadSuccess", "&aPlugin CubeRunner has been successfully reloaded."); - missingEditArgument = languageData.getString("missingEditArgument", "&cYou must choose what to do with this arena. Type &8/%cmd% help arena &cfor help."); - missingWorldEditRegion = languageData.getString("missingWorldEditRegion", "&cYou must first choose a World Edit region."); - arenaSetArena = languageData.getString("arenaSetArena", "&aZone successfully set for the arena &2%arena%&a."); - arenaSetStartPoint = languageData.getString("arenaSetStartPoint", "&aStart Point successfully set for the arena &2%arena%&a."); - arenaSetLobby = languageData.getString("arenaSetLobby", "&aLobby successfully set for the arena &2%arena%&a."); - arenaAmountPlayerMissingArgument = languageData.getString("arenaAmountPlayerMissingArgument", "&cYou must provide a quantity to change the amount of players."); - arenaAmountPlayerInvalidArgument = languageData.getString("arenaAmountPlayerInvalidArgument", "&cThe amount of player you entered is not valid. &7[&8%error%&7]"); - arenaAmountPlayerNotANumber = languageData.getString("arenaAmountPlayerNotANumber", "Not a number"); - arenaAmountPlayerMinEqualZero = languageData.getString("arenaAmountPlayerMinEqualZero", "Minimum lower than 1"); - arenaAmountPlayerMinBiggerMax = languageData.getString("arenaAmountPlayerMinBiggerMax", "Minimum higher than maximum"); - arenaAmountPlayerMaxBiggerMin = languageData.getString("arenaAmountPlayerMaxBiggerMin", "Maximum lower than minimum"); - arenaAmountPlayerSuccess = languageData.getString("arenaAmountPlayerSuccess", "&aAmount of player successfully edited for the arena &2%arena%&a."); - arenaDeleted = languageData.getString("arenaDeleted", "&cArena deleted."); - - guiInstrictions = languageData.getString("guiInstrictions", "&6Instructions"); - guiNextPage = languageData.getString("guiNextPage", "&2Next Page"); - guiPreviousPage = languageData.getString("guiPreviousPage", "&2Previous Page"); - guiJoinName = languageData.getString("guiJoinName", "&2Arena List"); - guiJoinInfo = languageData.getString("guiJoinInfo", "&eClick the name of the arena you wish to go to."); - guiJoinStarted = languageData.getString("guiJoinStarted", "&cActive : &eClick to Spectate"); - guiJoinReady = languageData.getString("guiJoinReady", "&aReady : &eClick to Join"); - guiStatsName = languageData.getString("guiStatsName", "&6Stats"); - guiStatsAverageDistancePerGame = languageData.getString("guiStatsAverageDistancePerGame", "&bAverage Score Per Game"); - guiStatsTotalDistance = languageData.getString("guiStatsTotalDistance", "&bTotal Distance Ran"); - guiStatsGamePlayed = languageData.getString("guiStatsGamePlayed", "&bGames played"); - guiStatsTotalPoints = languageData.getString("guiStatsTotalPoints", "&bTotal Score"); - guiStatsKills = languageData.getString("guiStatsKills", "&bPlayers Killed"); - guiStatsMultiplayer = languageData.getString("guiStatsMultiplayer", "&bMultiplayer games won"); - guiStatsTimePlayed = languageData.getString("guiStatsTimePlayed", "&dTime Played"); - guiStatsMoney = languageData.getString("guiStatsMoney", "&dMoney Gained"); - guiChallengeName = languageData.getString("guiChallengeName", "&bChallenges"); - guiColorName = languageData.getString("guiColorName", "&4Color Picker"); - guiColorInfo = languageData.getString("guiColorInfo", "&eThe enchanted blocks are\nðe curently selected ones.\n&eClick a block to\n&eenable or disable it."); - guiColorEditWhileActive = languageData.getString("guiColorEditWhileActive", "&cYou can't edit the colors while a game is active."); - - commandDescriptions = new CaseInsensitiveMap(); - for (CubeRunnerCommand cmd : CubeRunnerCommand.getCommands()) { - commandDescriptions.put(cmd.getDescription(), - languageData.getString(cmd.getDescription(), "&cOops, an Error has occured!")); - } - - keyWordHelp = languageData.getString("keyWordHelp", "Help"); - keyWordCategory = languageData.getString("keyWordCategory", "Category"); - keyWordPage = languageData.getString("keyWordPage", "Page"); - keyWordHours = languageData.getString("keyWordHours", "hours"); - keyWordMinutes = languageData.getString("keyWordMinutes", "minutes"); - keyWordSeconds = languageData.getString("keyWordSeconds", "seconds"); - keyWordDistance = languageData.getString("keyWordDistance", "km"); - keyWordAdvanced = languageData.getString("keyWordAdvanced", "Advanced Information"); - keyWordInformation = languageData.getString("keyWordInformation", "Information"); - keyWordMinimum = languageData.getString("keyWordMinimum", "Minimum"); - keyWordMaximum = languageData.getString("keyWordMaximum", "Maximum"); - keyWordCurrent = languageData.getString("keyWordCurrent", "Current"); - keyWordAmountPlayer = languageData.getString("keyWordAmountPlayer", "amount of players"); - keyWordGameState = languageData.getString("keyWordGameState", "game state"); - keyWordUnset = languageData.getString("keyWordUnset", "&7Arena Unset"); - keyWordReady = languageData.getString("keyWordReady", "&aReady"); - keyWordStartup = languageData.getString("keyWordStartup", "&9Startup"); - keyWordActive = languageData.getString("keyWordActive", "&cActive"); - keyWordWorld = languageData.getString("keyWordWorld", "World"); - keyWordLobby = languageData.getString("keyWordLobby", "Lobby"); - keyWordStartPoint = languageData.getString("keyWordStartPoint", "Start point"); - keyWordZone = languageData.getString("keyWordZoneMinPoint", " zone coordinate"); - keyWordTop10 = languageData.getString("top10", "Top 10"); - keyWordBestScore = languageData.getString("keyWordBestScore", "Best Score"); - keyWordBy = languageData.getString("keyWordBy", "by"); - keyWordProgression = languageData.getString("keyWordProgression", "Progression"); - keyWordCompleted = languageData.getString("keyWordCompleted", "Completed"); - keyWordNotCompleted = languageData.getString("keyWordNotCompleted", "Not Completed"); - keyWordReward = languageData.getString("keyWordReward", "Reward"); - - helpDescriptionAll = languageData.getString("helpDescriptionAll", "&7All Commands"); - helpDescriptionGeneral = languageData.getString("helpDescriptionGeneral", "&7General player commands"); - helpDescriptionGame = languageData.getString("helpDescriptionGame", "&7Commands to simply play the game"); - helpDescriptionArena = languageData.getString("helpDescriptionArena", "&7Commands to setup the arenas"); - helpDescriptionAdmin = languageData.getString("helpDescriptionAdmin", "&7Admin maintenance commands"); - - signNoPermission0 = languageData.getString("signNoPermission0", "&cYou don't have"); - signNoPermission1 = languageData.getString("signNoPermission1", "&cthe permissions"); - signNoPermission2 = languageData.getString("signNoPermission2", "&cto create a DaC"); - signNoPermission3 = languageData.getString("signNoPermission3", "&csign, &4Sorry..."); - signNotValid1 = languageData.getString("signNotValid1", "&cNone valid"); - signNotValid2 = languageData.getString("signNotValid2", "&csign parameters"); - signNotValid3 = languageData.getString("signNotValid3", "&cTry again"); - signJoin = languageData.getString("signJoin", "&aJoin Arena"); - signQuit = languageData.getString("signQuit", "&cQuit Arena"); - signStartGame = languageData.getString("signStartGame", "&9Start Game"); - signOpenStats = languageData.getString("signOpenStats", "&6Stats"); - signPlay = languageData.getString("signPlay", "&aPlay"); - - achievementCongrats = languageData.getString("achievementCongrats", "&f%player% &6just completed the achievement &d%achievementName%&6!"); - achievementAmountGame = languageData.getString("achievementAmountGame", "&dPlay %amount% game(s)"); - achievementTotalScore = languageData.getString("achievementTotalScore", "&dReach total score of %amount%"); - achievementKills = languageData.getString("achievementKills", "&dKill %amount% player(s)"); - achievementMultiplayerWon = languageData.getString("achievementMultiplayerWon", "&dWin %amount% multiplayer game(s)"); - achievementSurvive5Minutes = languageData.getString("achievementSurvive5Minutes", "&dSurvive 5 minutes"); - achievementReachHeight10 = languageData.getString("reachHeight10", "&dReach height 10"); - achievementFillTheArena = languageData.getString("fillTheArena", "&dFill the arena's floor"); - achievementTheAnswerToLife = languageData.getString("theAnswerToLife", "&dThe answer to life the universe and everything"); - achievementTheRageQuit = languageData.getString("achievementTheRageQuit", "&dThe Rage Quit"); - achievementTheKillerBunny = languageData.getString("achievementTheKillerBunny", "&dThe Killer Bunny"); - achievementMoneyReward = languageData.getString("achievementMoneyReward", "&dYou gain %amount%%currency% for your achievement."); - achievementMoneyGame = languageData.getString("achievementMoneyGame", "&dYou gain %amount%%currency% for surviving %amount2% seconds."); - - languageList = languageData.getString("languageList", "Available languages"); - languageNotFound = languageData.getString("languageNotFound", "&cLanguage not found. &8/%cmd% language &cfor a list of available languages"); - languageChangeSuccess = languageData.getString("languageChangeSuccess", "&aLanguage successfully set to %language%"); - } - - public CaseInsensitiveMap getCommandsDescription() { - return commandDescriptions; - } - - public void sendMsg(Player player, String message) { - if (config.prefixInFrontOfEveryMessages) - player.sendMessage(ChatColor.translateAlternateColorCodes('&', prefixShort + message)); - else - player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); - } - - public void sendMsg(User user, String message) { - sendMsg(user.getPlayer(), message); - } - - public static HashMap getLanguages() { - return languages; - } - - public static void clearLanguages() { - languages.clear(); - } - - public static Entry getLanguage(String languageName) { - for (Entry local : languages.entrySet()) - if (local.getValue().languageName.equalsIgnoreCase(languageName)) - return local; - - return null; - } -} diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/Metrics.java b/Bukkit_1.9/src/me/poutineqc/cuberunner/Metrics.java deleted file mode 100644 index 910c42a..0000000 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/Metrics.java +++ /dev/null @@ -1,703 +0,0 @@ -package me.poutineqc.cuberunner; - -import org.bukkit.Bukkit; -import org.bukkit.Server; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginDescriptionFile; -import org.bukkit.scheduler.BukkitTask; - -import java.io.BufferedReader; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; -import java.lang.reflect.Method; -import java.net.Proxy; -import java.net.URL; -import java.net.URLConnection; -import java.net.URLEncoder; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.Set; -import java.util.UUID; -import java.util.logging.Level; -import java.util.zip.GZIPOutputStream; - -public class Metrics { - - /** - * The current revision number - */ - private final static int REVISION = 7; - - /** - * The base url of the metrics domain - */ - private static final String BASE_URL = "http://report.mcstats.org"; - - /** - * The url used to report a server's status - */ - private static final String REPORT_URL = "/plugin/%s"; - - /** - * Interval of time to ping (in minutes) - */ - private static final int PING_INTERVAL = 15; - - /** - * The plugin this metrics submits for - */ - private final Plugin plugin; - - /** - * All of the custom graphs to submit to metrics - */ - private final Set graphs = Collections.synchronizedSet(new HashSet()); - - /** - * The plugin configuration file - */ - private final YamlConfiguration configuration; - - /** - * The plugin configuration file - */ - private final File configurationFile; - - /** - * Unique server id - */ - private final String guid; - - /** - * Debug mode - */ - private final boolean debug; - - /** - * Lock for synchronization - */ - private final Object optOutLock = new Object(); - - /** - * The scheduled task - */ - private volatile BukkitTask task = null; - - public Metrics(final Plugin plugin) throws IOException { - if (plugin == null) { - throw new IllegalArgumentException("Plugin cannot be null"); - } - - this.plugin = plugin; - - // load the config - configurationFile = getConfigFile(); - configuration = YamlConfiguration.loadConfiguration(configurationFile); - - // add some defaults - configuration.addDefault("opt-out", false); - configuration.addDefault("guid", UUID.randomUUID().toString()); - configuration.addDefault("debug", false); - - // Do we need to create the file? - if (configuration.get("guid", null) == null) { - configuration.options().header("http://mcstats.org").copyDefaults(true); - configuration.save(configurationFile); - } - - // Load the guid then - guid = configuration.getString("guid"); - debug = configuration.getBoolean("debug", false); - } - - /** - * Construct and create a Graph that can be used to separate specific plotters to their own graphs on the metrics - * website. Plotters can be added to the graph object returned. - * - * @param name The name of the graph - * @return Graph object created. Will never return NULL under normal circumstances unless bad parameters are given - */ - public Graph createGraph(final String name) { - if (name == null) { - throw new IllegalArgumentException("Graph name cannot be null"); - } - - // Construct the graph object - final Graph graph = new Graph(name); - - // Now we can add our graph - graphs.add(graph); - - // and return back - return graph; - } - - /** - * Add a Graph object to BukkitMetrics that represents data for the plugin that should be sent to the backend - * - * @param graph The name of the graph - */ - public void addGraph(final Graph graph) { - if (graph == null) { - throw new IllegalArgumentException("Graph cannot be null"); - } - - graphs.add(graph); - } - - /** - * Start measuring statistics. This will immediately create an async repeating task as the plugin and send the - * initial data to the metrics backend, and then after that it will post in increments of PING_INTERVAL * 1200 - * ticks. - * - * @return True if statistics measuring is running, otherwise false. - */ - public boolean start() { - synchronized (optOutLock) { - // Is metrics already running? - if (task != null) { - return true; - } - - // Begin hitting the server with glorious data - task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() { - - private boolean firstPost = true; - - public void run() { - try { - // We use the inverse of firstPost because if it is the first time we are posting, - // it is not a interval ping, so it evaluates to FALSE - // Each time thereafter it will evaluate to TRUE, i.e PING! - postPlugin(!firstPost); - - // After the first post we set firstPost to false - // Each post thereafter will be a ping - firstPost = false; - } catch (IOException e) { - if (debug) { - Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage()); - } - } - } - }, 0, PING_INTERVAL * 1200); - - return true; - } - } - - /** - * Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task. - * - * @throws java.io.IOException - */ - public void enable() throws IOException { - // This has to be synchronized or it can collide with the check in the task. - synchronized (optOutLock) { - // Check if the server owner has already set opt-out, if not, set it. - // Enable Task, if it is not running - if (task == null) { - start(); - } - } - } - - /** - * Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task. - * - * @throws java.io.IOException - */ - public void disable() throws IOException { - // This has to be synchronized or it can collide with the check in the task. - synchronized (optOutLock) { - // Disable Task, if it is running - if (task != null) { - task.cancel(); - task = null; - } - } - } - - /** - * Gets the File object of the config file that should be used to store data such as the GUID and opt-out status - * - * @return the File object for the config file - */ - public File getConfigFile() { - // I believe the easiest way to get the base folder (e.g craftbukkit set via -P) for plugins to use - // is to abuse the plugin object we already have - // plugin.getDataFolder() => base/plugins/PluginA/ - // pluginsFolder => base/plugins/ - // The base is not necessarily relative to the startup directory. - File pluginsFolder = plugin.getDataFolder().getParentFile(); - - // return => base/plugins/PluginMetrics/config.yml - return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml"); - } - - /** - * Gets the online player (backwards compatibility) - * - * @return online player amount - */ - private int getOnlinePlayers() { - try { - Method onlinePlayerMethod = Server.class.getMethod("getOnlinePlayers"); - if(onlinePlayerMethod.getReturnType().equals(Collection.class)) { - return ((Collection)onlinePlayerMethod.invoke(Bukkit.getServer())).size(); - } else { - return ((Player[])onlinePlayerMethod.invoke(Bukkit.getServer())).length; - } - } catch (Exception ex) { - if (debug) { - Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); - } - } - - return 0; - } - - /** - * Generic method that posts a plugin to the metrics website - */ - private void postPlugin(final boolean isPing) throws IOException { - // Server software specific section - PluginDescriptionFile description = plugin.getDescription(); - String pluginName = "CubeRunner"; - boolean onlineMode = Bukkit.getServer().getOnlineMode(); - String pluginVersion = description.getVersion(); - String serverVersion = Bukkit.getVersion(); - int playersOnline = this.getOnlinePlayers(); - - // END server software specific section -- all code below does not use any code outside of this class / Java - - // Construct the post data - StringBuilder json = new StringBuilder(1024); - json.append('{'); - - // The plugin's description file containg all of the plugin data such as name, version, author, etc - appendJSONPair(json, "guid", guid); - appendJSONPair(json, "plugin_version", pluginVersion); - appendJSONPair(json, "server_version", serverVersion); - appendJSONPair(json, "players_online", Integer.toString(playersOnline)); - - // New data as of R6 - String osname = System.getProperty("os.name"); - String osarch = System.getProperty("os.arch"); - String osversion = System.getProperty("os.version"); - String java_version = System.getProperty("java.version"); - int coreCount = Runtime.getRuntime().availableProcessors(); - - // normalize os arch .. amd64 -> x86_64 - if (osarch.equals("amd64")) { - osarch = "x86_64"; - } - - appendJSONPair(json, "osname", osname); - appendJSONPair(json, "osarch", osarch); - appendJSONPair(json, "osversion", osversion); - appendJSONPair(json, "cores", Integer.toString(coreCount)); - appendJSONPair(json, "auth_mode", onlineMode ? "1" : "0"); - appendJSONPair(json, "java_version", java_version); - - // If we're pinging, append it - if (isPing) { - appendJSONPair(json, "ping", "1"); - } - - if (graphs.size() > 0) { - synchronized (graphs) { - json.append(','); - json.append('"'); - json.append("graphs"); - json.append('"'); - json.append(':'); - json.append('{'); - - boolean firstGraph = true; - - final Iterator iter = graphs.iterator(); - - while (iter.hasNext()) { - Graph graph = iter.next(); - - StringBuilder graphJson = new StringBuilder(); - graphJson.append('{'); - - for (Plotter plotter : graph.getPlotters()) { - appendJSONPair(graphJson, plotter.getColumnName(), Integer.toString(plotter.getValue())); - } - - graphJson.append('}'); - - if (!firstGraph) { - json.append(','); - } - - json.append(escapeJSON(graph.getName())); - json.append(':'); - json.append(graphJson); - - firstGraph = false; - } - - json.append('}'); - } - } - - // close json - json.append('}'); - - // Create the url - URL url = new URL(BASE_URL + String.format(REPORT_URL, urlEncode(pluginName))); - - // Connect to the website - URLConnection connection; - - // Mineshafter creates a socks proxy, so we can safely bypass it - // It does not reroute POST requests so we need to go around it - if (isMineshafterPresent()) { - connection = url.openConnection(Proxy.NO_PROXY); - } else { - connection = url.openConnection(); - } - - - byte[] uncompressed = json.toString().getBytes(); - byte[] compressed = gzip(json.toString()); - - // Headers - connection.addRequestProperty("User-Agent", "MCStats/" + REVISION); - connection.addRequestProperty("Content-Type", "application/json"); - connection.addRequestProperty("Content-Encoding", "gzip"); - connection.addRequestProperty("Content-Length", Integer.toString(compressed.length)); - connection.addRequestProperty("Accept", "application/json"); - connection.addRequestProperty("Connection", "close"); - - connection.setDoOutput(true); - - if (debug) { - System.out.println("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length + " compressed=" + compressed.length); - } - - // Write the data - OutputStream os = connection.getOutputStream(); - os.write(compressed); - os.flush(); - - // Now read the response - final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); - String response = reader.readLine(); - - // close resources - os.close(); - reader.close(); - - if (response == null || response.startsWith("ERR") || response.startsWith("7")) { - if (response == null) { - response = "null"; - } else if (response.startsWith("7")) { - response = response.substring(response.startsWith("7,") ? 2 : 1); - } - - throw new IOException(response); - } else { - // Is this the first update this hour? - if (response.equals("1") || response.contains("This is your first update this hour")) { - synchronized (graphs) { - final Iterator iter = graphs.iterator(); - - while (iter.hasNext()) { - final Graph graph = iter.next(); - - for (Plotter plotter : graph.getPlotters()) { - plotter.reset(); - } - } - } - } - } - } - - /** - * GZip compress a string of bytes - * - * @param input - * @return - */ - public static byte[] gzip(String input) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - GZIPOutputStream gzos = null; - - try { - gzos = new GZIPOutputStream(baos); - gzos.write(input.getBytes("UTF-8")); - } catch (IOException e) { - e.printStackTrace(); - } finally { - if (gzos != null) try { - gzos.close(); - } catch (IOException ignore) { - } - } - - return baos.toByteArray(); - } - - /** - * Check if mineshafter is present. If it is, we need to bypass it to send POST requests - * - * @return true if mineshafter is installed on the server - */ - private boolean isMineshafterPresent() { - try { - Class.forName("mineshafter.MineServer"); - return true; - } catch (Exception e) { - return false; - } - } - - /** - * Appends a json encoded key/value pair to the given string builder. - * - * @param json - * @param key - * @param value - * @throws UnsupportedEncodingException - */ - private static void appendJSONPair(StringBuilder json, String key, String value) throws UnsupportedEncodingException { - boolean isValueNumeric = false; - - try { - if (value.equals("0") || !value.endsWith("0")) { - Double.parseDouble(value); - isValueNumeric = true; - } - } catch (NumberFormatException e) { - isValueNumeric = false; - } - - if (json.charAt(json.length() - 1) != '{') { - json.append(','); - } - - json.append(escapeJSON(key)); - json.append(':'); - - if (isValueNumeric) { - json.append(value); - } else { - json.append(escapeJSON(value)); - } - } - - /** - * Escape a string to create a valid JSON string - * - * @param text - * @return - */ - private static String escapeJSON(String text) { - StringBuilder builder = new StringBuilder(); - - builder.append('"'); - for (int index = 0; index < text.length(); index++) { - char chr = text.charAt(index); - - switch (chr) { - case '"': - case '\\': - builder.append('\\'); - builder.append(chr); - break; - case '\b': - builder.append("\\b"); - break; - case '\t': - builder.append("\\t"); - break; - case '\n': - builder.append("\\n"); - break; - case '\r': - builder.append("\\r"); - break; - default: - if (chr < ' ') { - String t = "000" + Integer.toHexString(chr); - builder.append("\\u" + t.substring(t.length() - 4)); - } else { - builder.append(chr); - } - break; - } - } - builder.append('"'); - - return builder.toString(); - } - - /** - * Encode text as UTF-8 - * - * @param text the text to encode - * @return the encoded text, as UTF-8 - */ - private static String urlEncode(final String text) throws UnsupportedEncodingException { - return URLEncoder.encode(text, "UTF-8"); - } - - /** - * Represents a custom graph on the website - */ - public static class Graph { - - /** - * The graph's name, alphanumeric and spaces only :) If it does not comply to the above when submitted, it is - * rejected - */ - private final String name; - - /** - * The set of plotters that are contained within this graph - */ - private final Set plotters = new LinkedHashSet(); - - private Graph(final String name) { - this.name = name; - } - - /** - * Gets the graph's name - * - * @return the Graph's name - */ - public String getName() { - return name; - } - - /** - * Add a plotter to the graph, which will be used to plot entries - * - * @param plotter the plotter to add to the graph - */ - public void addPlotter(final Plotter plotter) { - plotters.add(plotter); - } - - /** - * Remove a plotter from the graph - * - * @param plotter the plotter to remove from the graph - */ - public void removePlotter(final Plotter plotter) { - plotters.remove(plotter); - } - - /** - * Gets an unmodifiable set of the plotter objects in the graph - * - * @return an unmodifiable {@link java.util.Set} of the plotter objects - */ - public Set getPlotters() { - return Collections.unmodifiableSet(plotters); - } - - @Override - public int hashCode() { - return name.hashCode(); - } - - @Override - public boolean equals(final Object object) { - if (!(object instanceof Graph)) { - return false; - } - - final Graph graph = (Graph) object; - return graph.name.equals(name); - } - - /** - * Called when the server owner decides to opt-out of BukkitMetrics while the server is running. - */ - protected void onOptOut() { - } - } - - /** - * Interface used to collect custom data for a plugin - */ - public static abstract class Plotter { - - /** - * The plot's name - */ - private final String name; - - /** - * Construct a plotter with the default plot name - */ - public Plotter() { - this("Default"); - } - - /** - * Construct a plotter with a specific plot name - * - * @param name the name of the plotter to use, which will show up on the website - */ - public Plotter(final String name) { - this.name = name; - } - - /** - * Get the current value for the plotted point. Since this function defers to an external function it may or may - * not return immediately thus cannot be guaranteed to be thread friendly or safe. This function can be called - * from any thread so care should be taken when accessing resources that need to be synchronized. - * - * @return the current value for the point to be plotted. - */ - public abstract int getValue(); - - /** - * Get the column name for the plotted point - * - * @return the plotted point's column name - */ - public String getColumnName() { - return name; - } - - /** - * Called after the website graphs have been updated - */ - public void reset() { - } - - @Override - public int hashCode() { - return getColumnName().hashCode(); - } - - @Override - public boolean equals(final Object object) { - if (!(object instanceof Plotter)) { - return false; - } - - final Plotter plotter = (Plotter) object; - return plotter.name.equals(name) && plotter.getValue() == getValue(); - } - } -} \ No newline at end of file diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/MySQL.java b/Bukkit_1.9/src/me/poutineqc/cuberunner/MySQL.java deleted file mode 100644 index a2ed0d1..0000000 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/MySQL.java +++ /dev/null @@ -1,99 +0,0 @@ -package me.poutineqc.cuberunner; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; - -public class MySQL { - - private CubeRunner plugin; - private String host; - private int port; - private String database; - private String user; - private String password; - - private Connection connection; - - public MySQL(CubeRunner plugin) { - this.plugin = plugin; - connection = null; - } - - public MySQL(CubeRunner plugin, String host, int port, String database, String user, String password) { - this.plugin = plugin; - this.host = host; - this.port = port; - this.database = database; - this.user = user; - this.password = password; - - connect(); - } - - public MySQL() { - connection = null; - } - - public void updateInfo(CubeRunner plugin) { - Configuration config = plugin.getConfiguration(); - this.plugin = plugin; - this.host = config.host; - this.port = config.port; - this.database = config.database; - this.user = config.user; - this.password = config.password; - - connect(); - } - - public void connect() { - try { - connection = DriverManager.getConnection( - "jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true", user, password); - plugin.getLogger().info("[MySQL] The connection to MySQL is made!"); - } catch (SQLException e) { - plugin.getLogger().info("[MySQL] The connection to MySQL couldn't be made! reason: " + e.getMessage()); - } - } - - public void close() { - try { - if (connection != null) { - connection.close(); - plugin.getLogger().info("[MySQL] The connection to MySQL is ended successfully!"); - } - } catch (SQLException e) { - plugin.getLogger().info("[MySQL] The connection couldn't be closed! reason: " + e.getMessage()); - } - } - - public void update(String qry) { - try { - PreparedStatement st = connection.prepareStatement(qry); - st.execute(); - st.close(); - } catch (SQLException e) { - connect(); - System.err.println(e); - } - } - - public boolean hasConnection() { - return connection != null; - } - - public ResultSet query(String qry) { - ResultSet rs = null; - try { - PreparedStatement st = connection.prepareStatement(qry); - rs = st.executeQuery(); - } catch (SQLException e) { - connect(); - System.err.println(e); - } - return rs; - } -} diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/Permissions.java b/Bukkit_1.9/src/me/poutineqc/cuberunner/Permissions.java deleted file mode 100644 index 237b0fa..0000000 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/Permissions.java +++ /dev/null @@ -1,34 +0,0 @@ -package me.poutineqc.cuberunner; - -import org.bukkit.entity.Player; - -import me.poutineqc.cuberunner.commands.CubeRunnerCommand; - -public class Permissions { - - private static PlayerData playerData; - - public static final String createSign = "cuberunner.admin.edit.sign"; - public static final String advancedInfo = "cuberunner.admin.info"; - - public Permissions(CubeRunner plugin) { - playerData = plugin.getPlayerData(); - } - - public static boolean hasPermission(CubeRunnerCommand command, Player player, boolean warning) { - return hasPermission(command.getPermission(), player, warning); - } - - public static boolean hasPermission(String permission, Player player, boolean warning) { - if (player.hasPermission(permission)) - return true; - - if (warning) { - Language local = playerData.getLanguageOfPlayer(player); - local.sendMsg(player, local.errorPermission); - } - - return false; - } - -} diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/PlayerData.java b/Bukkit_1.9/src/me/poutineqc/cuberunner/PlayerData.java deleted file mode 100644 index 552b7f3..0000000 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/PlayerData.java +++ /dev/null @@ -1,208 +0,0 @@ -package me.poutineqc.cuberunner; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.URL; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Map.Entry; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; - -import me.poutineqc.cuberunner.commands.CubeRunnerCommand; - -public class PlayerData implements Listener { - - private Configuration config; - private MySQL mysql; - - private File playerFile; - private FileConfiguration playerData; - private boolean lastVersion; - private String latestVersion; - - public PlayerData(CubeRunner plugin) { - config = plugin.getConfiguration(); - mysql = plugin.getMySQL(); - - playerFile = new File(plugin.getDataFolder(), "playerData.yml"); - if (!playerFile.exists()) { - try { - playerFile.createNewFile(); - } catch (IOException e) { - Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not create playerData.ylm."); - } - } - - lastVersion = isLastVersion(plugin); - - loadPlayerData(); - } - - private boolean isLastVersion(CubeRunner plugin) { - boolean next = false; - URL url; - try { - url = new URL("http://www.poutineqc.ca/pluginVersion.txt"); - BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); - - while ((latestVersion = in.readLine()) != null) { - if (next) - break; - if (latestVersion.equalsIgnoreCase("CubeRunner")) - next = true; - } - - in.close(); - } catch (IOException e) { - plugin.getLogger().warning("Could not find the latest version available."); - } - - if (next) - return latestVersion.equalsIgnoreCase(plugin.getDescription().getVersion()); - - return true; - } - - public void loadPlayerData() { - playerData = YamlConfiguration.loadConfiguration(playerFile); - } - - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) { - Player player = event.getPlayer(); - addOnFileIfNotExist(player); - - if (!lastVersion && Permissions.hasPermission(CubeRunnerCommand.getCommand("reload"), player, false)) { - Language local = getLanguageOfPlayer(player); - local.sendMsg(player, - "&5A new CubeRunner version is available &d(v%version%)&5.\n".replace("%version%", latestVersion) - + "&5Get it now : &dhttps://www.spigotmc.org/resources/cuberunner.19715/"); - } - } - - public void addOnFileIfNotExist(Player player) { - String uuid = player.getUniqueId().toString(); - - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT * FROM " + config.tablePrefix + "PLAYERS WHERE UUID='" + uuid + "';"); - try { - if (!query.next()) { - mysql.update("INSERT INTO " + config.tablePrefix + "PLAYERS (UUID, name) VALUES ('" + uuid + "','" - + player.getName() + "');"); - } else { - mysql.update("UPDATE " + config.tablePrefix + "PLAYERS SET name='" + player.getName() - + "' WHERE UUID='" + uuid + "';"); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } else { - if (!playerData.contains("players." + uuid)) { - playerData.set("players." + uuid + ".name", player.getName()); - playerData.set("players." + uuid + ".language", "default"); - playerData.set("players." + uuid + ".money", 0); - playerData.set("players." + uuid + ".averageDistancePerGame", 0); - playerData.set("players." + uuid + ".totalDistance", 0); - playerData.set("players." + uuid + ".games", 0); - playerData.set("players." + uuid + ".totalScore", 0); - playerData.set("players." + uuid + ".kills", 0); - playerData.set("players." + uuid + ".multiplayerWon", 0); - playerData.set("players." + uuid + ".timePlayed", 0); - playerData.set("players." + uuid + ".achievement.survive5Minutes", false); - playerData.set("players." + uuid + ".achievement.reachHeight10", false); - playerData.set("players." + uuid + ".achievement.fillTheArena", false); - playerData.set("players." + uuid + ".achievement.theAnswerToLife", false); - playerData.set("players." + uuid + ".achievement.theRageQuit", false); - playerData.set("players." + uuid + ".achievement.theKillerBunny", false); - savePlayerData(); - } else { - playerData.set("players." + uuid + ".name", player.getName()); - savePlayerData(); - } - } - } - - public FileConfiguration getData() { - return playerData; - } - - public void savePlayerData() { - try { - playerData.save(playerFile); - } catch (IOException e) { - Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not save playerData.yml!"); - } - } - - public void newUser(Player player) { - if (mysql.hasConnection()) { - mysql.update("INSERT INTO " + config.tablePrefix + "PLAYERS (language) VALUES ('default');"); - } else { - - } - } - - public Language getLanguageOfPlayer(Player player) { - String fileName = null; - if (mysql.hasConnection()) { - try { - ResultSet query = mysql.query("SELECT language FROM " + config.tablePrefix + "PLAYERS WHERE UUID='" - + player.getUniqueId() + "';"); - - if (query.next()) { - fileName = query.getString("language"); - } - - } catch (SQLException e) { - e.printStackTrace(); - } - } else { - fileName = playerData.getString("players." + player.getUniqueId().toString() + ".language", null); - } - - if (fileName == null) - return Language.getLanguages().get(config.language); - - return getLanguage(fileName); - } - - public Language getLanguage(String fileName) { - for (Entry local : Language.getLanguages().entrySet()) - if (local.getKey().equalsIgnoreCase(fileName)) - return local.getValue(); - - if (Language.getLanguages().containsKey(config.language)) - return Language.getLanguages().get(config.language); - - return Language.getLanguages().get("en-US"); - - } - - public void setLanguage(Player player, String key) { - if (mysql.hasConnection()) { - mysql.update("UPDATE " + config.tablePrefix + "PLAYERS SET language='" + key + "' WHERE UUID='" - + player.getUniqueId().toString() + "';"); - } else { - playerData.set("players." + player.getUniqueId().toString() + ".language", key); - savePlayerData(); - } - } - - public boolean isLatestVersion() { - return lastVersion; - } - - public String getLatestVersion() { - return latestVersion; - } -} diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/achievements/AchievementGUI.java b/Bukkit_1.9/src/me/poutineqc/cuberunner/achievements/AchievementGUI.java deleted file mode 100644 index 0863f80..0000000 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/achievements/AchievementGUI.java +++ /dev/null @@ -1,929 +0,0 @@ -package me.poutineqc.cuberunner.achievements; - -import java.sql.ResultSet; -import java.sql.SQLException; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.Inventory; - -import me.poutineqc.cuberunner.Configuration; -import me.poutineqc.cuberunner.CubeRunner; -import me.poutineqc.cuberunner.Language; -import me.poutineqc.cuberunner.MySQL; -import me.poutineqc.cuberunner.PlayerData; -import me.poutineqc.cuberunner.tools.ItemStackManager; -import net.milkbowl.vault.economy.Economy; - -public class AchievementGUI implements Listener { - - private Configuration config; - private MySQL mysql; - private PlayerData playerData; - private Achievements achievements; - private Economy economy; - - public AchievementGUI(CubeRunner plugin) { - this.config = plugin.getConfiguration(); - this.mysql = plugin.getMySQL(); - this.playerData = plugin.getPlayerData(); - this.achievements = plugin.getAchievements(); - this.economy = CubeRunner.getEconomy(); - } - - @EventHandler - public void onInventotyClick(InventoryClickEvent event) { - - if (!(event.getWhoClicked() instanceof Player)) - return; - - Player player = (Player) event.getWhoClicked(); - Language local = playerData.getLanguageOfPlayer(player); - - if (!ChatColor.stripColor(event.getInventory().getName()) - .equalsIgnoreCase(ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.guiStatsName + " &0: &5CubeRunner"))) - && !ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase(ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.guiChallengeName + " &0: &5CubeRunner")))) - return; - - event.setCancelled(true); - - if (event.getAction() == InventoryAction.NOTHING || event.getAction() == InventoryAction.UNKNOWN) - return; - - String itemName = event.getCurrentItem().getItemMeta().getDisplayName(); - - if (isEqualOnColorStrip(itemName, local.guiChallengeName)) { - openChallengeInventory(player); - return; - } - - if (isEqualOnColorStrip(itemName, local.guiStatsName)) { - openAchievementInventory(player); - return; - } - - } - - private boolean isEqualOnColorStrip(String toCheck, String original) { - return ChatColor.stripColor(toCheck) - .equalsIgnoreCase(ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', original))); - } - - public void openAchievementInventory(Player player) { - - String uuid = player.getUniqueId().toString(); - Language local = playerData.getLanguageOfPlayer(player); - Inventory inv = Bukkit.createInventory(null, 54, - ChatColor.translateAlternateColorCodes('&', local.guiStatsName + " &0: &5CubeRunner")); - ItemStackManager icon; - int location; - - double averageDistancePerGame = 0; - double totalDistance = 0; - int gamesPlayed = 0; - int totalPoints = 0; - int kills = 0; - int multiplayerWon = 0; - int timePlayed = 0; - double money = 0; - - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT * FROM " + config.tablePrefix + "PLAYERS WHERE UUID='" + uuid + "';"); - try { - if (query.next()) { - averageDistancePerGame = query.getDouble("averageDistancePerGame"); - totalDistance = query.getDouble("totalDistance"); - gamesPlayed = query.getInt("games"); - totalPoints = query.getInt("totalScore"); - kills = query.getInt("kills"); - multiplayerWon = query.getInt("multiplayerWon"); - timePlayed = query.getInt("timePlayed"); - money = query.getDouble("money"); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } else { - averageDistancePerGame = playerData.getData().getDouble("players." + uuid + ".averageDistancePerGame", 0); - totalDistance = playerData.getData().getDouble("players." + uuid + ".totalDistance", 0); - gamesPlayed = playerData.getData().getInt("players." + uuid + ".games", 0); - totalPoints = playerData.getData().getInt("players." + uuid + ".totalScore", 0); - kills = playerData.getData().getInt("players." + uuid + ".kills", 0); - multiplayerWon = playerData.getData().getInt("players." + uuid + ".multiplayerWon", 0); - timePlayed = playerData.getData().getInt("players." + uuid + ".timePlayed", 0); - money = playerData.getData().getDouble("players." + uuid + ".money", 0); - } - - averageDistancePerGame = ((int) (averageDistancePerGame * 100)) / 100.0; - totalDistance = (int) totalDistance / 1000.0; - money = (int) (money * 100) / 100.0; - - /*************************************************** - * Glass Spacer - ***************************************************/ - - icon = new ItemStackManager(Material.STAINED_GLASS_PANE); - icon.setData((short) 10); - icon.setTitle(" "); - - for (int i = 0; i < inv.getSize(); i++) - switch (i) { - case 1: - case 10: - case 11: - case 12: - case 13: - case 14: - case 15: - case 16: - case 17: - case 19: - case 28: - case 37: - case 46: - icon.setPosition(i); - icon.addToInventory(inv); - } - - /*************************************************** - * Stats - ***************************************************/ - - icon = new ItemStackManager(Material.PAPER); - icon.setTitle(ChatColor.translateAlternateColorCodes('&', local.guiStatsName + " : CubeRunner")); - - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.translateAlternateColorCodes('&', - local.guiStatsAverageDistancePerGame + " : &e" + String.valueOf(averageDistancePerGame))); - icon.addToLore(ChatColor.translateAlternateColorCodes('&', local.guiStatsTotalDistance + " : &e" - + String.valueOf(totalDistance) + " " + ChatColor.GREEN + local.keyWordDistance)); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.translateAlternateColorCodes('&', - local.guiStatsGamePlayed + " : &e" + String.valueOf(gamesPlayed))); - icon.addToLore(ChatColor.translateAlternateColorCodes('&', - local.guiStatsTotalPoints + " : &e" + String.valueOf(totalPoints))); - icon.addToLore( - ChatColor.translateAlternateColorCodes('&', local.guiStatsKills + " : &e" + String.valueOf(kills))); - icon.addToLore(ChatColor.translateAlternateColorCodes('&', - local.guiStatsMultiplayer + " : &e" + String.valueOf(multiplayerWon))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.LIGHT_PURPLE - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.guiStatsTimePlayed)) + ": " - + getTimePLayed(local, timePlayed)); - if (CubeRunner.isEconomyEnabled()) - icon.addToLore(ChatColor.LIGHT_PURPLE - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.guiStatsMoney)) + ": &e" - + String.valueOf(money) + ChatColor.GREEN + economy.currencyNamePlural()); - - icon.setPosition(2); - icon.addToInventory(inv); - - /*************************************************** - * Top Ratio - ***************************************************/ - - icon = new ItemStackManager(Material.EMPTY_MAP); - icon.setTitle(ChatColor.GOLD + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', - local.keyWordTop10 + " : " + local.guiStatsAverageDistancePerGame))); - - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT * FROM " + config.tablePrefix + "AVERAGESCORE;"); - try { - while (query.next()) { - icon.addToLore(ChatColor.LIGHT_PURPLE + query.getString("name") + " : " + ChatColor.YELLOW - + getAverage(query.getDouble("averageDistancePerGame"), 100)); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } else { - for (int i = 0; i < 10 && i < TopManager.getRatio().size(); i++) { - icon.addToLore(ChatColor.LIGHT_PURPLE + TopManager.getRatio().get(i).getPlayer() + " : " - + ChatColor.YELLOW + getAverage(TopManager.getRatio().get(i).getScore(), 100)); - } - } - - icon.setPosition(0); - icon.addToInventory(inv); - - /*************************************************** - * Top Distance Ran - ***************************************************/ - - icon = new ItemStackManager(Material.EMPTY_MAP); - icon.setTitle(ChatColor.GOLD + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordTop10 + " : " + local.guiStatsTotalDistance))); - - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT * FROM " + config.tablePrefix + "TOTALDISTANCE;"); - try { - while (query.next()) { - icon.addToLore(ChatColor.LIGHT_PURPLE + query.getString("name") + " : " + ChatColor.YELLOW - + getAverage(query.getDouble("totalDistance"), 1) / 1000 + " " + ChatColor.GREEN - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordDistance))); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } else { - for (int i = 0; i < 10 && i < TopManager.getDistanceRan().size(); i++) { - icon.addToLore(ChatColor.LIGHT_PURPLE + TopManager.getDistanceRan().get(i).getPlayer() + " : " - + ChatColor.YELLOW + getAverage(TopManager.getDistanceRan().get(i).getScore(), 1) / 1000); - } - } - - icon.setPosition(9); - icon.addToInventory(inv); - - /*************************************************** - * Top games - ***************************************************/ - - icon = new ItemStackManager(Material.EMPTY_MAP); - icon.setTitle(ChatColor.GOLD + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordTop10 + " : " + local.guiStatsGamePlayed))); - - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT * FROM " + config.tablePrefix + "MOSTGAMES;"); - try { - while (query.next()) { - icon.addToLore(ChatColor.LIGHT_PURPLE + query.getString("name") + " : " + ChatColor.YELLOW - + query.getInt("games")); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } else { - for (int i = 0; i < 10 && i < TopManager.getGames().size(); i++) { - icon.addToLore(ChatColor.LIGHT_PURPLE + TopManager.getGames().get(i).getPlayer() + " : " - + ChatColor.YELLOW + TopManager.getGames().get(i).getScore()); - } - } - - icon.setPosition(18); - icon.addToInventory(inv); - - /*************************************************** - * Top Total Score - ***************************************************/ - - icon = new ItemStackManager(Material.EMPTY_MAP); - icon.setTitle(ChatColor.GOLD + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordTop10 + " : " + local.guiStatsTotalPoints))); - - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT * FROM " + config.tablePrefix + "TOTALSCORE;"); - try { - while (query.next()) { - icon.addToLore(ChatColor.LIGHT_PURPLE + query.getString("name") + " : " + ChatColor.YELLOW - + query.getInt("totalScore")); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } else { - for (int i = 0; i < 10 && i < TopManager.getTotalScore().size(); i++) { - icon.addToLore(ChatColor.LIGHT_PURPLE + TopManager.getTotalScore().get(i).getPlayer() + " : " - + ChatColor.YELLOW + TopManager.getTotalScore().get(i).getScore()); - } - } - - icon.setPosition(27); - icon.addToInventory(inv); - - /*************************************************** - * Top Kills - ***************************************************/ - - icon = new ItemStackManager(Material.EMPTY_MAP); - icon.setTitle(ChatColor.GOLD + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordTop10 + " : " + local.guiStatsKills))); - - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT * FROM " + config.tablePrefix + "KILLS;"); - try { - while (query.next()) { - icon.addToLore(ChatColor.LIGHT_PURPLE + query.getString("name") + " : " + ChatColor.YELLOW - + query.getInt("kills")); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } else { - for (int i = 0; i < 10 && i < TopManager.getKills().size(); i++) { - icon.addToLore(ChatColor.LIGHT_PURPLE + TopManager.getKills().get(i).getPlayer() + " : " - + ChatColor.YELLOW + (int) TopManager.getKills().get(i).getScore()); - } - } - - icon.setPosition(36); - icon.addToInventory(inv); - - /*************************************************** - * Top Multiplayer Won - ***************************************************/ - - icon = new ItemStackManager(Material.EMPTY_MAP); - icon.setTitle(ChatColor.GOLD + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordTop10 + " : " + local.guiStatsMultiplayer))); - - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT * FROM " + config.tablePrefix + "MULTIPLAYERWON;"); - try { - while (query.next()) { - icon.addToLore(ChatColor.LIGHT_PURPLE + query.getString("name") + " : " + ChatColor.YELLOW - + query.getInt("multiplayerWon")); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } else { - for (int i = 0; i < 10 && i < TopManager.getMultiplayerWon().size(); i++) { - icon.addToLore(ChatColor.LIGHT_PURPLE + TopManager.getMultiplayerWon().get(i).getPlayer() + " : " - + ChatColor.YELLOW + (int) TopManager.getMultiplayerWon().get(i).getScore()); - } - } - - icon.setPosition(45); - icon.addToInventory(inv); - - /*************************************************** - * Achievements games - ***************************************************/ - location = 20; - for (AchievementsObject ao : achievements.getachievements().get(0)) { - - icon = new ItemStackManager(Material.WOOL); - - if (ao.get_level() <= gamesPlayed) { - icon.setData((short) 5); - icon.setTitle(ChatColor.GREEN + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', - local.achievementAmountGame.replace("%amount%", String.valueOf(ao.get_level()))))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordProgression + ": ")) - + ChatColor.GREEN - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordCompleted))); - } else { - icon.setData((short) 8); - icon.setTitle(ChatColor.RED + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', - local.achievementAmountGame.replace("%amount%", String.valueOf(ao.get_level()))))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordProgression + ": ")) - + ChatColor.YELLOW + String.valueOf(gamesPlayed) + "/" + String.valueOf(ao.get_level())); - if (CubeRunner.isEconomyEnabled()) { - if (config.achievementsRewards) - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordReward + ": ")) - + ChatColor.YELLOW + String.valueOf(ao.get_reward()) + economy.currencyNamePlural()); - } - } - - icon.setPosition(location++); - icon.addToInventory(inv); - - } - - /*************************************************** - * Achievements totalScore - ***************************************************/ - location = 29; - for (AchievementsObject ao : achievements.getachievements().get(1)) { - - icon = new ItemStackManager(Material.WOOL); - - if (ao.get_level() <= totalPoints) { - icon.setData((short) 5); - icon.setTitle(ChatColor.GREEN + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', - local.achievementTotalScore.replace("%amount%", String.valueOf(ao.get_level()))))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordProgression + ": ")) - + ChatColor.GREEN - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordCompleted))); - } else { - icon.setData((short) 8); - icon.setTitle(ChatColor.RED + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', - local.achievementTotalScore.replace("%amount%", String.valueOf(ao.get_level()))))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordProgression + ": ")) - + ChatColor.YELLOW + String.valueOf(totalPoints) + "/" + String.valueOf(ao.get_level())); - if (CubeRunner.isEconomyEnabled()) { - if (config.achievementsRewards) - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordReward + ": ")) - + ChatColor.YELLOW + String.valueOf(ao.get_reward()) + economy.currencyNamePlural()); - } - } - - icon.setPosition(location++); - icon.addToInventory(inv); - - } - - /*************************************************** - * Achievements kills - ***************************************************/ - location = 38; - for (AchievementsObject ao : achievements.getachievements().get(2)) { - - icon = new ItemStackManager(Material.WOOL); - - if (ao.get_level() <= kills) { - icon.setData((short) 5); - icon.setTitle(ChatColor.GREEN + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', - local.achievementKills.replace("%amount%", String.valueOf(ao.get_level()))))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordProgression + ": ")) - + ChatColor.GREEN - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordCompleted))); - } else { - icon.setData((short) 8); - icon.setTitle(ChatColor.RED + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', - local.achievementKills.replace("%amount%", String.valueOf(ao.get_level()))))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordProgression + ": ")) - + ChatColor.YELLOW + String.valueOf(kills) + "/" + String.valueOf(ao.get_level())); - if (CubeRunner.isEconomyEnabled()) { - if (config.achievementsRewards) - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordReward + ": ")) - + ChatColor.YELLOW + String.valueOf(ao.get_reward()) + economy.currencyNamePlural()); - } - } - - icon.setPosition(location++); - icon.addToInventory(inv); - - } - - /*************************************************** - * Achievements Multiplayer Won - ***************************************************/ - location = 47; - for (AchievementsObject ao : achievements.getachievements().get(3)) { - - icon = new ItemStackManager(Material.WOOL); - - if (ao.get_level() <= multiplayerWon) { - icon.setData((short) 5); - icon.setTitle(ChatColor.GREEN + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', - local.achievementMultiplayerWon.replace("%amount%", String.valueOf(ao.get_level()))))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordProgression + ": ")) - + ChatColor.GREEN - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordCompleted))); - } else { - icon.setData((short) 8); - icon.setTitle(ChatColor.RED + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', - local.achievementMultiplayerWon.replace("%amount%", String.valueOf(ao.get_level()))))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordProgression + ": ")) - + ChatColor.YELLOW + String.valueOf(multiplayerWon) + "/" + String.valueOf(ao.get_level())); - if (CubeRunner.isEconomyEnabled()) { - if (config.achievementsRewards) - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor( - ChatColor.translateAlternateColorCodes('&', local.keyWordReward + ": ")) - + ChatColor.YELLOW + String.valueOf(ao.get_reward()) + economy.currencyNamePlural()); - } - } - - icon.setPosition(location++); - icon.addToInventory(inv); - - } - - /*************************************************** - * Arrow - ***************************************************/ - - icon = new ItemStackManager(Material.ARROW); - - icon.setTitle(local.guiChallengeName); - - icon.setPosition(8); - icon.addToInventory(inv); - - /*************************************************** - * Display - ***************************************************/ - - player.openInventory(inv); - } - - public void openChallengeInventory(Player player) { - - String uuid = player.getUniqueId().toString(); - Language local = playerData.getLanguageOfPlayer(player); - Inventory inv = Bukkit.createInventory(null, 27, - ChatColor.translateAlternateColorCodes('&', local.guiChallengeName + " &0: &5CubeRunner")); - ItemStackManager icon; - - double averageDistancePerGame = 0; - double totalDistance = 0; - int gamesPlayed = 0; - int totalPoints = 0; - int kills = 0; - int multiplayerWon = 0; - int timePlayed = 0; - double money = 0; - boolean survive5Minutes = false; - boolean reachHeight10 = false; - boolean fillTheArena = false; - boolean theAnswerToLife = false; - boolean theRageQuit = false; - boolean theKillerBunny = false; - - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT * FROM " + config.tablePrefix + "PLAYERS WHERE UUID='" + uuid + "';"); - try { - if (query.next()) { - averageDistancePerGame = query.getDouble("averageDistancePerGame"); - totalDistance = query.getDouble("totalDistance"); - gamesPlayed = query.getInt("games"); - totalPoints = query.getInt("totalScore"); - kills = query.getInt("kills"); - multiplayerWon = query.getInt("multiplayerWon"); - timePlayed = query.getInt("timePlayed"); - money = query.getDouble("money"); - survive5Minutes = query.getBoolean("survive5Minutes"); - reachHeight10 = query.getBoolean("reachHeight10"); - fillTheArena = query.getBoolean("fillTheArena"); - theAnswerToLife = query.getBoolean("theAnswerToLife"); - theRageQuit = query.getBoolean("theRageQuit"); - theKillerBunny = query.getBoolean("theKillerBunny"); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } else { - averageDistancePerGame = playerData.getData().getDouble("players." + uuid + ".averageDistancePerGame", 0); - totalDistance = playerData.getData().getDouble("players." + uuid + ".totalDistance", 0); - gamesPlayed = playerData.getData().getInt("players." + uuid + ".games", 0); - totalPoints = playerData.getData().getInt("players." + uuid + ".totalScore", 0); - kills = playerData.getData().getInt("players." + uuid + ".kills", 0); - multiplayerWon = playerData.getData().getInt("players." + uuid + ".multiplayerWon", 0); - timePlayed = playerData.getData().getInt("players." + uuid + ".timePlayed", 0); - money = playerData.getData().getDouble("players." + uuid + ".money", 0); - survive5Minutes = playerData.getData().getBoolean("players." + uuid + ".achievement.survive5Minutes", - false); - reachHeight10 = playerData.getData().getBoolean("players." + uuid + ".achievement.reachHeight10", false); - fillTheArena = playerData.getData().getBoolean("players." + uuid + ".achievement.fillTheArena", false); - theAnswerToLife = playerData.getData().getBoolean("players." + uuid + ".achievement.theAnswerToLife", - false); - theRageQuit = playerData.getData().getBoolean("players." + uuid + ".achievement.theRageQuit", false); - theKillerBunny = playerData.getData().getBoolean("players." + uuid + ".achievement.theKillerBunny", false); - } - - averageDistancePerGame = ((int) (averageDistancePerGame * 100)) / 100.0; - totalDistance = (int) totalDistance / 1000.0; - money = (int) (money * 100) / 100.0; - - /*************************************************** - * Glass Spacer - ***************************************************/ - - icon = new ItemStackManager(Material.STAINED_GLASS_PANE); - icon.setData((short) 10); - icon.setTitle(" "); - - for (int i = 0; i < inv.getSize(); i++) - switch (i) { - case 9: - case 10: - case 11: - case 12: - case 13: - case 14: - case 15: - case 16: - case 17: - icon.setPosition(i); - icon.addToInventory(inv); - } - - /*************************************************** - * Stats - ***************************************************/ - - icon = new ItemStackManager(Material.PAPER); - icon.setTitle(ChatColor.translateAlternateColorCodes('&', local.guiStatsName + " : CubeRunner")); - - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.translateAlternateColorCodes('&', - local.guiStatsAverageDistancePerGame + " : &e" + String.valueOf(averageDistancePerGame))); - icon.addToLore(ChatColor.translateAlternateColorCodes('&', local.guiStatsTotalDistance + " : &e" - + String.valueOf(totalDistance) + " " + ChatColor.GREEN + local.keyWordDistance)); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.translateAlternateColorCodes('&', - local.guiStatsGamePlayed + " : &e" + String.valueOf(gamesPlayed))); - icon.addToLore(ChatColor.translateAlternateColorCodes('&', - local.guiStatsTotalPoints + " : &e" + String.valueOf(totalPoints))); - icon.addToLore( - ChatColor.translateAlternateColorCodes('&', local.guiStatsKills + " : &e" + String.valueOf(kills))); - icon.addToLore(ChatColor.translateAlternateColorCodes('&', - local.guiStatsMultiplayer + " : &e" + String.valueOf(multiplayerWon))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.LIGHT_PURPLE - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.guiStatsTimePlayed)) + ": " - + getTimePLayed(local, timePlayed)); - if (CubeRunner.isEconomyEnabled()) - icon.addToLore(ChatColor.LIGHT_PURPLE - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.guiStatsMoney)) + ": &e" - + String.valueOf(money) + ChatColor.GREEN + economy.currencyNamePlural()); - - icon.setPosition(4); - icon.addToInventory(inv); - - /*************************************************** - * Challenge : survive 5 minutes - ***************************************************/ - - icon = new ItemStackManager(Material.INK_SACK); - if (survive5Minutes) { - icon.setData((short) 10); - icon.setTitle(ChatColor.GREEN + ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.achievementSurvive5Minutes))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordProgression)) + ": " - + ChatColor.GREEN - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordCompleted))); - } else { - icon.setData((short) 8); - icon.setTitle(ChatColor.RED + ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.achievementSurvive5Minutes))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordProgression)) + ": " - + ChatColor.RED - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordNotCompleted))); - if (CubeRunner.isEconomyEnabled()) { - if (config.achievementsRewards) - icon.addToLore(ChatColor.AQUA - + ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordReward + ": ")) - + ChatColor.YELLOW + String.valueOf(config.rewardSurvive5Minutes) - + economy.currencyNamePlural()); - } - } - - icon.setPosition(19); - icon.addToInventory(inv); - - /*************************************************** - * Challenge : Fill the arena - ***************************************************/ - - icon = new ItemStackManager(Material.INK_SACK); - if (fillTheArena) { - icon.setData((short) 10); - icon.setTitle(ChatColor.GREEN - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.achievementFillTheArena))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordProgression)) + ": " - + ChatColor.GREEN - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordCompleted))); - } else { - icon.setData((short) 8); - icon.setTitle(ChatColor.RED - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.achievementFillTheArena))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordProgression)) + ": " - + ChatColor.RED - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordNotCompleted))); - if (CubeRunner.isEconomyEnabled()) { - if (config.achievementsRewards) - icon.addToLore(ChatColor.AQUA - + ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordReward + ": ")) - + ChatColor.YELLOW + String.valueOf(config.rewardFillTheArenasFloor) - + economy.currencyNamePlural()); - } - } - - icon.setPosition(20); - icon.addToInventory(inv); - - /*************************************************** - * Challenge : Reach Height 10 - ***************************************************/ - - icon = new ItemStackManager(Material.INK_SACK); - if (reachHeight10) { - icon.setData((short) 10); - icon.setTitle(ChatColor.GREEN + ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.achievementReachHeight10))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordProgression)) + ": " - + ChatColor.GREEN - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordCompleted))); - } else { - icon.setData((short) 8); - icon.setTitle(ChatColor.RED + ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.achievementReachHeight10))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordProgression)) + ": " - + ChatColor.RED - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordNotCompleted))); - if (CubeRunner.isEconomyEnabled()) { - if (config.achievementsRewards) - icon.addToLore(ChatColor.AQUA - + ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordReward + ": ")) - + ChatColor.YELLOW + String.valueOf(config.rewardReachHeight10) - + economy.currencyNamePlural()); - } - } - - icon.setPosition(21); - icon.addToInventory(inv); - - /*************************************************** - * Challenge : RageQuit - ***************************************************/ - - icon = new ItemStackManager(Material.INK_SACK); - if (theRageQuit) { - icon.setData((short) 10); - icon.setTitle(ChatColor.GREEN - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.achievementTheRageQuit))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordProgression)) + ": " - + ChatColor.GREEN - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordCompleted))); - } else { - icon.setData((short) 8); - icon.setTitle(ChatColor.RED - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.achievementTheRageQuit))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordProgression)) + ": " - + ChatColor.RED - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordNotCompleted))); - if (CubeRunner.isEconomyEnabled()) { - if (config.achievementsRewards) - icon.addToLore(ChatColor.AQUA - + ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordReward + ": ")) - + ChatColor.YELLOW + String.valueOf(config.rewardTheRageQuit) - + economy.currencyNamePlural()); - } - } - - icon.setPosition(23); - icon.addToInventory(inv); - - /*************************************************** - * Challenge : Killer Bunny - ***************************************************/ - - icon = new ItemStackManager(Material.INK_SACK); - if (theKillerBunny) { - icon.setData((short) 10); - icon.setTitle(ChatColor.GREEN + ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.achievementTheKillerBunny))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordProgression)) + ": " - + ChatColor.GREEN - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordCompleted))); - } else { - icon.setData((short) 8); - icon.setTitle(ChatColor.RED + ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.achievementTheKillerBunny))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordProgression)) + ": " - + ChatColor.RED - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordNotCompleted))); - if (CubeRunner.isEconomyEnabled()) { - if (config.achievementsRewards) - icon.addToLore(ChatColor.AQUA - + ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordReward + ": ")) - + ChatColor.YELLOW + String.valueOf(config.rewardTheKillerBunny) - + economy.currencyNamePlural()); - } - } - - icon.setPosition(24); - icon.addToInventory(inv); - - /*************************************************** - * Challenge : answer to life - ***************************************************/ - - icon = new ItemStackManager(Material.INK_SACK); - if (theAnswerToLife) { - icon.setData((short) 10); - icon.setTitle(ChatColor.GREEN + ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.achievementTheAnswerToLife))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordProgression)) + ": " - + ChatColor.GREEN - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordCompleted))); - } else { - icon.setData((short) 8); - icon.setTitle(ChatColor.RED + ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.achievementTheAnswerToLife))); - icon.addToLore(ChatColor.STRIKETHROUGH + "" + ChatColor.YELLOW + "----------------------------"); - icon.addToLore(ChatColor.AQUA - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordProgression)) + ": " - + ChatColor.RED - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordNotCompleted))); - if (CubeRunner.isEconomyEnabled()) { - if (config.achievementsRewards) - icon.addToLore(ChatColor.AQUA - + ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordReward + ": ")) - + ChatColor.YELLOW + String.valueOf(config.rewardTheAnswerToLife) - + economy.currencyNamePlural()); - } - } - - icon.setPosition(25); - icon.addToInventory(inv); - - /*************************************************** - * Arrow - ***************************************************/ - - icon = new ItemStackManager(Material.ARROW); - - icon.setTitle(local.guiStatsName); - - icon.setPosition(8); - icon.addToInventory(inv); - - /*************************************************** - * Display - ***************************************************/ - - player.openInventory(inv); - } - - private double getAverage(double value, int degree) { - return (int) (value * degree) / (double) (degree); - } - - private String getTimePLayed(Language local, int timePlayed) { - long hours = 0; - - timePlayed /= 60000; - while (timePlayed > 60) { - timePlayed -= 60; - hours++; - } - - return ChatColor.YELLOW + String.valueOf(hours) + ChatColor.GREEN + " " - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordHours)) - + ChatColor.YELLOW + " " + String.valueOf(timePlayed) + ChatColor.GREEN + " " - + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.keyWordMinutes)); - } - -} diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/achievements/AchievementType.java b/Bukkit_1.9/src/me/poutineqc/cuberunner/achievements/AchievementType.java deleted file mode 100644 index 33b9102..0000000 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/achievements/AchievementType.java +++ /dev/null @@ -1,14 +0,0 @@ -package me.poutineqc.cuberunner.achievements; - -public enum AchievementType { - AMOUNT_GAMES, - AMOUNT_KILLS, - TOTAL_SCORE, - MULTIPLAYER_GAMES_WON, - SURVIVE_5_MINUTES, - FILL_THE_ARENA, - REACH_HEIGHT_10, - DISCONNECT_IN_STARTUP, - JUMP_50_TIMES, - DIE_SECONDS_42 -} diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/achievements/Achievements.java b/Bukkit_1.9/src/me/poutineqc/cuberunner/achievements/Achievements.java deleted file mode 100644 index 5e9f917..0000000 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/achievements/Achievements.java +++ /dev/null @@ -1,338 +0,0 @@ -package me.poutineqc.cuberunner.achievements; - -import java.io.File; -import java.io.InputStream; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; - -import me.poutineqc.cuberunner.Configuration; -import me.poutineqc.cuberunner.CubeRunner; -import me.poutineqc.cuberunner.Language; -import me.poutineqc.cuberunner.MySQL; -import me.poutineqc.cuberunner.PlayerData; -import net.milkbowl.vault.economy.Economy; - -public class Achievements { - - private CubeRunner plugin; - private MySQL mysql; - private Configuration config; - private PlayerData playerData; - - private File achievementFile; - private FileConfiguration achievementData; - - private ArrayList> achievements = new ArrayList>(); - private Economy economy; - - public Achievements(CubeRunner plugin) { - this.plugin = plugin; - this.mysql = plugin.getMySQL(); - this.config = plugin.getConfiguration(); - this.playerData = plugin.getPlayerData(); - this.economy = CubeRunner.getEconomy(); - - achievementFile = new File(plugin.getDataFolder(), "achievements.yml"); - if (!achievementFile.exists()) { - InputStream local = plugin.getResource("achievements.yml"); - if (local != null) { - plugin.saveResource("achievements.yml", false); - } else - plugin.getLogger().info("Could not find achievements.yml"); - } - - setupAchievements(); - } - - public void setupAchievements() { - - achievementData = YamlConfiguration.loadConfiguration(achievementFile); - - achievements.clear(); - - String[] configNames = new String[] { "amountOfGamesPlayed", "totalScore", "amountPlayerKills", - "multiplayerGamesWon" }; - for (int i = 0; i < configNames.length; i++) { - achievements.add(new ArrayList()); - - final int MAX_ACHIEVEMENT_PER_ROW = 7; - List readData = achievementData.getStringList(configNames[i]); - - for (int j = 0; j < readData.size() && achievements.get(i).size() < MAX_ACHIEVEMENT_PER_ROW; j++) { - String[] individualData = readData.get(j).split(";"); - - if (individualData.length < 2) { - plugin.getLogger().info( - "Could not load the " + j + "'th data from the " + i + "'th achievement type. (Reading)"); - continue; - } - - try { - int level = Integer.parseInt(individualData[0]); - double reward = Double.parseDouble(individualData[1]); - achievements.get(i).add(new AchievementsObject(level, reward)); - } catch (NumberFormatException e) { - plugin.getLogger().info("Could not load the " + j + "'th data from the " + i - + "'th achievement type. (Conversion)"); - continue; - } - } - } - - } - - public void checkAchievement(AchievementType type, Player player) { - if (player == null) - return; - - AchievementsObject ao; - boolean completed; - - switch (type) { - case AMOUNT_GAMES: - ao = checkNumberAchievement(player, 0, "games"); - if (ao == null) - break; - - for (Player p : Bukkit.getServer().getOnlinePlayers()) { - Language local = playerData.getLanguageOfPlayer(p); - local.sendMsg(p, - local.achievementCongrats.replace("%player%", player.getDisplayName()).replace( - "%achievementName%", - local.achievementAmountGame.replace("%amount%", String.valueOf(ao.get_level())))); - } - - checkForMoneyReward(player, ao.get_reward()); - break; - - case TOTAL_SCORE: - ao = checkNumberAchievement(player, 1, "totalScore"); - if (ao == null) - break; - - for (Player p : Bukkit.getServer().getOnlinePlayers()) { - Language local = playerData.getLanguageOfPlayer(p); - local.sendMsg(p, - local.achievementCongrats.replace("%player%", player.getDisplayName()).replace( - "%achievementName%", - local.achievementTotalScore.replace("%amount%", String.valueOf(ao.get_level())))); - } - - checkForMoneyReward(player, ao.get_reward()); - break; - - case AMOUNT_KILLS: - ao = checkNumberAchievement(player, 2, "kills"); - if (ao == null) - break; - - for (Player p : Bukkit.getServer().getOnlinePlayers()) { - Language local = playerData.getLanguageOfPlayer(p); - local.sendMsg(p, - local.achievementCongrats.replace("%player%", player.getDisplayName()).replace( - "%achievementName%", - local.achievementKills.replace("%amount%", String.valueOf(ao.get_level())))); - } - - checkForMoneyReward(player, ao.get_reward()); - break; - - case MULTIPLAYER_GAMES_WON: - ao = checkNumberAchievement(player, 3, "multiplayerWon"); - if (ao == null) - break; - - for (Player p : Bukkit.getServer().getOnlinePlayers()) { - Language local = playerData.getLanguageOfPlayer(p); - local.sendMsg(p, - local.achievementCongrats.replace("%player%", player.getDisplayName()).replace( - "%achievementName%", - local.achievementMultiplayerWon.replace("%amount%", String.valueOf(ao.get_level())))); - } - - checkForMoneyReward(player, ao.get_reward()); - break; - - case SURVIVE_5_MINUTES: - completed = checkSingleAchievement(player, "survive5Minutes"); - if (!completed) - break; - - for (Player p : Bukkit.getServer().getOnlinePlayers()) { - Language local = playerData.getLanguageOfPlayer(p); - local.sendMsg(p, local.achievementCongrats.replace("%player%", player.getDisplayName()) - .replace("%achievementName%", local.achievementSurvive5Minutes)); - } - - checkForMoneyReward(player, config.rewardSurvive5Minutes); - break; - - case REACH_HEIGHT_10: - completed = checkSingleAchievement(player, "reachHeight10"); - if (!completed) - break; - - for (Player p : Bukkit.getServer().getOnlinePlayers()) { - Language local = playerData.getLanguageOfPlayer(p); - local.sendMsg(p, local.achievementCongrats.replace("%player%", player.getDisplayName()) - .replace("%achievementName%", local.achievementReachHeight10)); - } - - checkForMoneyReward(player, config.rewardReachHeight10); - break; - - case FILL_THE_ARENA: - completed = checkSingleAchievement(player, "fillTheArena"); - if (!completed) - break; - - for (Player p : Bukkit.getServer().getOnlinePlayers()) { - Language local = playerData.getLanguageOfPlayer(p); - local.sendMsg(p, local.achievementCongrats.replace("%player%", player.getDisplayName()) - .replace("%achievementName%", local.achievementFillTheArena)); - } - - checkForMoneyReward(player, config.rewardFillTheArenasFloor); - break; - - case DIE_SECONDS_42: - completed = checkSingleAchievement(player, "theAnswerToLife"); - if (!completed) - break; - - for (Player p : Bukkit.getServer().getOnlinePlayers()) { - Language local = playerData.getLanguageOfPlayer(p); - local.sendMsg(p, local.achievementCongrats.replace("%player%", player.getDisplayName()) - .replace("%achievementName%", local.achievementTheAnswerToLife)); - } - - checkForMoneyReward(player, config.rewardTheAnswerToLife); - break; - - case DISCONNECT_IN_STARTUP: - completed = checkSingleAchievement(player, "theRageQuit"); - if (!completed) - break; - - for (Player p : Bukkit.getServer().getOnlinePlayers()) { - Language local = playerData.getLanguageOfPlayer(p); - local.sendMsg(p, local.achievementCongrats.replace("%player%", player.getDisplayName()) - .replace("%achievementName%", local.achievementTheRageQuit)); - } - - checkForMoneyReward(player, config.rewardTheRageQuit); - break; - - case JUMP_50_TIMES: - completed = checkSingleAchievement(player, "theKillerBunny"); - if (!completed) - break; - - for (Player p : Bukkit.getServer().getOnlinePlayers()) { - Language local = playerData.getLanguageOfPlayer(p); - local.sendMsg(p, local.achievementCongrats.replace("%player%", player.getDisplayName()) - .replace("%achievementName%", local.achievementTheKillerBunny)); - } - - checkForMoneyReward(player, config.rewardTheKillerBunny); - break; - - } - } - - private AchievementsObject checkNumberAchievement(Player player, int arrayNumber, String configName) { - int amount = 0; - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT " + configName + " FROM " + config.tablePrefix - + "PLAYERS WHERE UUID='" + player.getUniqueId().toString() + "';"); - try { - if (query.next()) - amount = query.getInt(configName); - } catch (SQLException e) { - e.printStackTrace(); - } - } else { - amount = playerData.getData().getInt("players." + player.getUniqueId().toString() + "." + configName, 0); - } - - for (AchievementsObject ao : achievements.get(arrayNumber)) - if (ao.get_level() == amount) - return ao; - - return null; - } - - private boolean checkSingleAchievement(Player player, String configName) { - boolean achieved = true; - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT " + configName + " FROM " + config.tablePrefix - + "PLAYERS WHERE UUID='" + player.getUniqueId().toString() + "';"); - try { - if (query.next()) { - achieved = query.getBoolean(configName); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } else { - achieved = playerData.getData() - .getBoolean("players." + player.getUniqueId().toString() + ".achievement." + configName, false); - } - - if (mysql.hasConnection()) { - mysql.update("UPDATE " + config.tablePrefix + "PLAYERS SET " + configName + "='1' WHERE UUID='" - + player.getUniqueId().toString() + "';"); - } else { - playerData.getData().set("players." + player.getUniqueId().toString() + ".achievement." + configName, true); - playerData.savePlayerData(); - } - - return !achieved; - } - - protected ArrayList> getachievements() { - return achievements; - } - - private void checkForMoneyReward(Player player, double amount) { - - if (!CubeRunner.isEconomyEnabled()) - return; - - if (!config.achievementsRewards) - return; - - economy.depositPlayer(player, amount); - Language l = playerData.getLanguageOfPlayer(player); - l.sendMsg(player, l.achievementMoneyReward.replace("%amount%", String.valueOf(amount)) - .replace("%currency%", economy.currencyNamePlural())); - - double original = 0; - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT money FROM " + config.tablePrefix - + "PLAYERS WHERE UUID='" + player.getUniqueId().toString() + "';"); - try { - if (query.next()) - original = query.getDouble("money"); - } catch (SQLException e) { - e.printStackTrace(); - } - - mysql.update("UPDATE " + config.tablePrefix + "PLAYERS SET money='" + (original + amount) - + "' WHERE UUID='" + player.getUniqueId().toString() + "';"); - } else { - original = playerData.getData().getDouble("players." + player.getUniqueId().toString() + ".money", 0); - playerData.getData().set("players." + player.getUniqueId().toString() + ".money", (original + amount)); - playerData.savePlayerData(); - } - - } - -} diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/achievements/AchievementsObject.java b/Bukkit_1.9/src/me/poutineqc/cuberunner/achievements/AchievementsObject.java deleted file mode 100644 index 0f50a24..0000000 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/achievements/AchievementsObject.java +++ /dev/null @@ -1,19 +0,0 @@ -package me.poutineqc.cuberunner.achievements; - -public class AchievementsObject { - private int level; - private double reward; - - public AchievementsObject(int level, double reward) { - this.level = level; - this.reward = reward; - } - - public int get_level() { - return level; - } - - public double get_reward() { - return reward; - } -} diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/achievements/PlayerMovement.java b/Bukkit_1.9/src/me/poutineqc/cuberunner/achievements/PlayerMovement.java deleted file mode 100644 index d28c715..0000000 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/achievements/PlayerMovement.java +++ /dev/null @@ -1,66 +0,0 @@ -package me.poutineqc.cuberunner.achievements; - -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerMoveEvent; - -import me.poutineqc.cuberunner.CubeRunner; -import me.poutineqc.cuberunner.games.Arena; -import me.poutineqc.cuberunner.games.GameState; -import me.poutineqc.cuberunner.games.User; - -public class PlayerMovement implements Listener { - - private Achievements achievements; - - public PlayerMovement(CubeRunner plugin) { - this.achievements = plugin.getAchievements(); - } - - @EventHandler - public void onPlayerMove(PlayerMoveEvent event) { - Player player = event.getPlayer(); - Arena arena = Arena.getArenaFromPlayer(player); - - if (arena == null) - return; - - User user = arena.getUser(player); - if (user.isEliminated()) - return; - - if (arena.getGameState() != GameState.ACTIVE && arena.getGameState() != GameState.STARTUP) - return; - - if (!arena.isInsideArena(event.getTo())) { - event.setCancelled(true); - return; - } - - if (arena.getGameState() != GameState.ACTIVE) - return; - - user.addToDistanceRan(event.getFrom().distance(event.getTo())); - - double toLocation = event.getTo().getY(); - double fromLocation = event.getFrom().getY(); - - if (toLocation > arena.getMinPoint().getY() + 10) - achievements.checkAchievement(AchievementType.REACH_HEIGHT_10, player); - - if (user.isJumping()) { - if (toLocation < fromLocation) - user.setJumping(false); - } else { - if (toLocation > fromLocation) { - user.setJumping(true); - user.jump(); - - if (user.getJump() == 50) - achievements.checkAchievement(AchievementType.JUMP_50_TIMES, player); - } - } - } - -} diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/achievements/TopManager.java b/Bukkit_1.9/src/me/poutineqc/cuberunner/achievements/TopManager.java deleted file mode 100644 index 68804c1..0000000 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/achievements/TopManager.java +++ /dev/null @@ -1,95 +0,0 @@ -package me.poutineqc.cuberunner.achievements; - -import java.util.ArrayList; -import java.util.List; - -import me.poutineqc.cuberunner.CubeRunner; -import me.poutineqc.cuberunner.PlayerData; - -public class TopManager { - - private PlayerData playerData; - - private String player; - private double score; - - private static List ratio = new ArrayList(); - private static List distanceRan = new ArrayList(); - private static List games = new ArrayList(); - private static List totalScore = new ArrayList(); - private static List kills = new ArrayList(); - private static List multiplayerWon = new ArrayList(); - - public TopManager(CubeRunner plugin) { - this.playerData = plugin.getPlayerData(); - updateAll(); - } - - public TopManager(String name, double score) { - this.player = name; - this.score = score; - } - - public void updateAll() { - ratio = updateTop("averageDistancePerGame"); - distanceRan = updateTop("totalDistance"); - games = updateTop("games"); - totalScore = updateTop("totalScore"); - kills = updateTop("kills"); - multiplayerWon = updateTop("multiplayerWon"); - } - - private List updateTop(String lookup) { - List tempList = new ArrayList(); - if (playerData.getData().contains("players")) { - for (String uuid : playerData.getData().getConfigurationSection("players").getKeys(false)) { - String name = playerData.getData().getString("players." + uuid + ".name", "unknown"); - double score = playerData.getData().getDouble("players." + uuid + "." + lookup, 0); - tempList.add(0, new TopManager(name, score)); - - for (int i = 0; i < 10 && i < tempList.size() - 1; i++) { - if (tempList.get(i).score < tempList.get(i + 1).score) { - TopManager tempValue = tempList.get(i); - tempList.set(i, tempList.get(i + 1)); - tempList.set(i + 1, tempValue); - } - } - } - } - - return tempList; - } - - protected String getPlayer() { - return player; - } - - protected double getScore() { - return score; - } - - public static List getRatio() { - return ratio; - } - - public static List getDistanceRan() { - return distanceRan; - } - - public static List getGames() { - return games; - } - - public static List getTotalScore() { - return totalScore; - } - - public static List getKills() { - return kills; - } - - public static List getMultiplayerWon() { - return multiplayerWon; - } - -} diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/commands/CommandType.java b/Bukkit_1.9/src/me/poutineqc/cuberunner/commands/CommandType.java deleted file mode 100644 index dcd8faa..0000000 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/commands/CommandType.java +++ /dev/null @@ -1,5 +0,0 @@ -package me.poutineqc.cuberunner.commands; - -public enum CommandType { - GENERAL, GAME_COMMANDS, ARENA_COMMANDS, ADMIN_COMMANDS, ALL; -} diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/commands/CubeRunnerCommand.java b/Bukkit_1.9/src/me/poutineqc/cuberunner/commands/CubeRunnerCommand.java deleted file mode 100644 index ca21e8e..0000000 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/commands/CubeRunnerCommand.java +++ /dev/null @@ -1,127 +0,0 @@ -package me.poutineqc.cuberunner.commands; - -import java.io.File; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; - -import me.poutineqc.cuberunner.CubeRunner; -import me.poutineqc.cuberunner.Permissions; - -public class CubeRunnerCommand { - - private String commandName; - private String description; - private String permission; - private String usage; - private CommandType type; - - private static ArrayList commands; - - private static CubeRunner plugin; - private static File commandFile; - private static FileConfiguration commandData; - - public CubeRunnerCommand(String commandName, String description, String permission, String usage, CommandType type) { - this.commandName = commandName; - this.description = description; - this.permission = permission; - this.usage = usage; - this.type = type; - } - - public CubeRunnerCommand(CubeRunner plugin) { - CubeRunnerCommand.plugin = plugin; - - commandFile = new File(plugin.getDataFolder(), "commands.yml"); - loadCommands(); - } - - private static void loadCommands() { - InputStream local = plugin.getResource("commands.yml"); - if (local != null) { - plugin.saveResource("commands.yml", false); - } else - plugin.getLogger().severe("Could not find commands.yml inside the jar file."); - - commandData = YamlConfiguration.loadConfiguration(commandFile); - commands = new ArrayList(); - - readingProcess(); - - commandFile.delete(); - } - - private static void readingProcess() { - for (String commandType : commandData.getConfigurationSection("commands").getKeys(false)) { - - CommandType type; - switch (commandType) { - case "game": - type = CommandType.GAME_COMMANDS; - break; - case "arena": - type = CommandType.ARENA_COMMANDS; - break; - case "general": - type = CommandType.GENERAL; - break; - case "admin": - type = CommandType.ADMIN_COMMANDS; - break; - default: - type = CommandType.ALL; - } - - for (String commandName : commandData.getConfigurationSection("commands." + commandType).getKeys(false)) { - String description = commandData.getString("commands." + commandType + "." + commandName + ".description"); - String permission = commandData.getString("commands." + commandType + "." + commandName + ".permission"); - String usage = commandData.getString("commands." + commandType + "." + commandName + ".usage"); - commands.add(new CubeRunnerCommand(commandName, description, permission, usage, type)); - } - } - } - - public static ArrayList getCommands() { - return commands; - } - - public static List getRequiredCommands(Player player, CommandType commandType) { - List requestedCommands = new ArrayList(); - - for (CubeRunnerCommand cmd : commands) - if (cmd.type == commandType || commandType == CommandType.ALL) - if (Permissions.hasPermission(cmd, player, false)) - requestedCommands.add(cmd); - - return requestedCommands; - } - - public static CubeRunnerCommand getCommand(String argument) { - for (CubeRunnerCommand command : commands) { - if (command.commandName.equalsIgnoreCase(argument)) - return command; - } - return null; - } - - public String getCommandName() { - return commandName; - } - - public String getPermission() { - return permission; - } - - public String getDescription() { - return description; - } - - public String getUsage() { - return usage; - } -} diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/commands/PlayerCommands.java b/Bukkit_1.9/src/me/poutineqc/cuberunner/commands/PlayerCommands.java deleted file mode 100644 index f0017a6..0000000 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/commands/PlayerCommands.java +++ /dev/null @@ -1,459 +0,0 @@ -package me.poutineqc.cuberunner.commands; - -import java.util.List; -import java.util.Map.Entry; - -import org.apache.commons.lang3.StringUtils; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import me.poutineqc.cuberunner.ArenaData; -import me.poutineqc.cuberunner.Configuration; -import me.poutineqc.cuberunner.CubeRunner; -import me.poutineqc.cuberunner.Language; -import me.poutineqc.cuberunner.MySQL; -import me.poutineqc.cuberunner.Permissions; -import me.poutineqc.cuberunner.PlayerData; -import me.poutineqc.cuberunner.achievements.AchievementGUI; -import me.poutineqc.cuberunner.achievements.Achievements; -import me.poutineqc.cuberunner.games.Arena; -import me.poutineqc.cuberunner.games.ColorGUI; -import me.poutineqc.cuberunner.games.GameState; -import me.poutineqc.cuberunner.tools.JoinGUI; - -public class PlayerCommands implements CommandExecutor { - private CubeRunner plugin; - private PlayerData playerData; - private JoinGUI joinGui; - private AchievementGUI achievementsGUI; - private ColorGUI colorGUI; - private ArenaData arenaData; - private MySQL mysql; - private Configuration config; - private Achievements achievements; - - public PlayerCommands(CubeRunner plugin) { - this.plugin = plugin; - arenaData = plugin.getArenaData(); - playerData = plugin.getPlayerData(); - joinGui = plugin.getJoinGui(); - achievementsGUI = plugin.getAchievementsGui(); - this.colorGUI = plugin.getColorGUI(); - this.mysql = plugin.getMySQL(); - this.config = plugin.getConfiguration(); - this.achievements = plugin.getAchievements(); - } - - @Override - public boolean onCommand(CommandSender sender, Command cmd, String cmdValue, String[] args) { - - if (!(sender instanceof Player)) { - sender.sendMessage("Only players can use CubeRunner's commands"); - return true; - } - - Player player = (Player) sender; - Language local = playerData.getLanguageOfPlayer(player); - - if (args.length == 0) { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8&m" + StringUtils.repeat(" ", 90))); - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - local.developper.replace("%developper%", plugin.getDescription().getAuthors().toString()))); - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - local.version.replace("%version%", plugin.getDescription().getVersion()))); - local.sendMsg(player, local.description.replace("%command%", cmdValue)); - player.sendMessage("\n"); - return true; - } - - if (args[0].equalsIgnoreCase("help")) { - String header = "&8&m" + StringUtils.repeat(" ", 30) + "&r &6CubeRunner &e" + local.keyWordHelp + " &8&m" - + StringUtils.repeat(" ", 30); - - if (args.length == 1) { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', header)); - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5/" + cmdValue + " help general &8- " + local.helpDescriptionGeneral)); - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5/" + cmdValue + " help game &8- " + local.helpDescriptionGame)); - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5/" + cmdValue + " help arena &8- " + local.helpDescriptionArena)); - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5/" + cmdValue + " help admin &8- " + local.helpDescriptionAdmin)); - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5/" + cmdValue + " help all &8- " + local.helpDescriptionAll)); - player.sendMessage("\n"); - return true; - } - - int pageNumber = 1; - CommandType commandType; - List requestedCommands; - - try { - pageNumber = Integer.parseInt(args[1]); - if (pageNumber < 1) - pageNumber = 1; - - commandType = CommandType.ALL; - - requestedCommands = CubeRunnerCommand.getRequiredCommands(player, commandType); - if (pageNumber > Math.ceil((double) requestedCommands.size() / 3)) - pageNumber = (int) Math.ceil((double) requestedCommands.size() / 3); - - } catch (NumberFormatException e) { - switch (args[1].toLowerCase()) { - case "game": - commandType = CommandType.GAME_COMMANDS; - break; - case "arena": - commandType = CommandType.ARENA_COMMANDS; - break; - case "admin": - commandType = CommandType.ADMIN_COMMANDS; - break; - case "general": - commandType = CommandType.GENERAL; - break; - default: - commandType = CommandType.ALL; - } - - requestedCommands = CubeRunnerCommand.getRequiredCommands(player, commandType); - - if (args.length > 2) { - try { - pageNumber = Integer.parseInt(args[2]); - if (pageNumber < 1) - pageNumber = 1; - - if (pageNumber > Math.ceil((double) requestedCommands.size() / 3)) - pageNumber = (int) Math.ceil((double) requestedCommands.size() / 3); - - } catch (NumberFormatException ex) { - } - } - } - - if (requestedCommands.size() == 0) - pageNumber = 0; - - player.sendMessage(ChatColor.translateAlternateColorCodes('&', header)); - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5" + local.keyWordCategory + ": &7" + commandType.toString() + ", &5" + local.keyWordPage + ": &7" - + String.valueOf(pageNumber) + "&8/&7" - + (int) (Math.ceil((double) requestedCommands.size() / 3)))); - - if (pageNumber == 0) { - local.sendMsg(player, local.helpNoPermission); - return true; - } - - for (int i = 3 * (pageNumber - 1); i < requestedCommands.size() && i < (3 * (pageNumber - 1)) + 3; i++) { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5" + requestedCommands.get(i).getUsage().replace("%command%", cmdValue))); - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - " &8- &7" + local.getCommandsDescription().get(requestedCommands.get(i).getDescription()))); - } - player.sendMessage("\n"); - return true; - } - - Arena arena; - CubeRunnerCommand command = CubeRunnerCommand.getCommand(args[0]); - if (command != null) { - - if (command.getCommandName().equalsIgnoreCase("language")) { - if (!Permissions.hasPermission(command, player, true)) - return true; - - if (args.length == 1) { - local.sendMsg(player, local.languageList); - for (Entry language : Language.getLanguages().entrySet()) - player.sendMessage("- " + language.getValue().languageName); - - return true; - } - - Entry entrySet = Language.getLanguage(args[1]); - if (entrySet == null) { - local.sendMsg(player, local.languageNotFound.replace("%cmd%", cmdValue)); - return true; - } - - playerData.setLanguage(player, entrySet.getKey()); - local = playerData.getLanguageOfPlayer(player); - - local.sendMsg(player, local.languageChangeSuccess); - return true; - } - - if (command.getCommandName().equalsIgnoreCase("info")) { - if (!Permissions.hasPermission(command, player, true)) - return true; - - if (args.length == 1) { - local.sendMsg(player, local.toolInfoMissingName); - local.sendMsg(player, local.toolInfoTip.replace("%cmd%", cmdValue)); - return true; - } - - arena = Arena.getArena(args[1]); - if (arena == null) { - local.sendMsg(player, local.arenaNotFound.replace("%arena%", args[1])); - local.sendMsg(player, local.toolInfoTip.replace("%cmd%", cmdValue)); - return true; - } - - local.sendMsg(player, local.toolInfoTip.replace("%cmd%", cmdValue)); - arena.displayInformation(player); - return true; - } - - if (command.getCommandName().equalsIgnoreCase("join") || command.getCommandName().equalsIgnoreCase("play") - || command.getCommandName().equalsIgnoreCase("list")) { - if (args.length > 1) - commandJoin(command, player, args.length, args[1], true); - else - commandJoin(command, player, args.length, "", true); - } - - if (command.getCommandName().equalsIgnoreCase("quit")) - commandQuit(command, player); - - if (command.getCommandName().equalsIgnoreCase("start")) - commandStart(command, player); - - if (command.getCommandName().equalsIgnoreCase("stats")) - commandStats(command, player); - - if (command.getCommandName().equalsIgnoreCase("reload")) { - if (!Permissions.hasPermission(command, player, true)) - return true; - - if (mysql.hasConnection()) - mysql.close(); - - config.loadConfiguration(plugin); - if (config.mysql) - mysql.updateInfo(plugin); - - plugin.initialiseEconomy(); - plugin.loadLanguages(); - - if (!mysql.hasConnection()) { - playerData.loadPlayerData(); - arenaData.loadArenaData(); - } - - achievements.setupAchievements(); - new SignPlace(plugin); - new PlayerInteract(plugin); - - Arena.loadExistingArenas(); - - local = playerData.getLanguageOfPlayer(player); - local.sendMsg(player, local.reloadSuccess); - return true; - } - - if (command.getCommandName().equalsIgnoreCase("new")) { - if (!Permissions.hasPermission(command, player, true)) - return true; - - if (args.length == 1) { - local.sendMsg(player, local.missingArenaName); - return true; - } - - if (Arena.getArena(args[1]) != null) { - local.sendMsg(player, local.arenaAlreadyExist.replace("%arena%", args[1])); - return true; - } - - new Arena(args[1], player); - local.sendMsg(player, local.arenaCreated.replace("%arena%", args[1])); - return true; - } - return true; - } - - arena = Arena.getArena(args[0]); - - if (arena == null) { - local.sendMsg(player, local.errorCommand.replace("%cmd%", cmdValue)); - return true; - } - - if (args.length == 1) { - local.sendMsg(player, local.missingEditArgument.replace("%cmd%", cmdValue)); - return true; - } - - command = CubeRunnerCommand.getCommand(args[1]); - if (command == null) { - local.sendMsg(player, local.errorCommand.replace("%cmd%", cmdValue)); - return true; - } - - if (command.getCommandName().equalsIgnoreCase("delete")) { - if (!Permissions.hasPermission(command, player, true)) - return true; - - arena.delete(player); - return true; - } - - if (command.getCommandName().equalsIgnoreCase("setzone")) { - if (!Permissions.hasPermission(command, player, true)) - return true; - - arena.setArena(player); - return true; - } - - if (command.getCommandName().equalsIgnoreCase("setlobby")) { - if (!Permissions.hasPermission(command, player, true)) - return true; - - arena.setLobby(player); - return true; - } - - if (command.getCommandName().equalsIgnoreCase("setstartpoint")) { - if (!Permissions.hasPermission(command, player, true)) - return true; - - arena.setStartPoint(player); - return true; - } - - if (command.getCommandName().equalsIgnoreCase("setcolor")) { - if (!Permissions.hasPermission(command, player, true)) - return true; - - if (arena.getGameState() == GameState.ACTIVE || arena.getGameState() == GameState.ENDING) { - local.sendMsg(player, local.guiColorEditWhileActive); - return true; - } - - colorGUI.openColorGUI(player, arena); - return true; - } - - if (command.getCommandName().equalsIgnoreCase("setminplayer")) { - if (!Permissions.hasPermission(command, player, true)) - return true; - - if (args.length < 3) { - local.sendMsg(player, local.arenaAmountPlayerMissingArgument); - return true; - } - - int amount = 0; - try { - amount = Integer.parseInt(args[2]); - } catch (NumberFormatException e) { - local.sendMsg(player, - local.arenaAmountPlayerInvalidArgument.replace("%error%", local.arenaAmountPlayerNotANumber)); - return true; - } - - arena.setMinPlayer(amount, player); - return true; - } - - if (command.getCommandName().equalsIgnoreCase("setmaxplayer")) { - if (!Permissions.hasPermission(command, player, true)) - return true; - - if (args.length < 3) { - local.sendMsg(player, local.arenaAmountPlayerMissingArgument); - } - - int amount = 0; - try { - amount = Integer.parseInt(args[2]); - } catch (NumberFormatException e) { - local.sendMsg(player, - local.arenaAmountPlayerInvalidArgument.replace("%error%", local.arenaAmountPlayerNotANumber)); - return true; - } - - arena.setMaxPlayer(amount, player); - return true; - } - - local.sendMsg(player, local.errorCommand); - return true; - } - - protected void commandJoin(CubeRunnerCommand command, Player player, int argsLength, String arenaName, - boolean teleport) { - if (!Permissions.hasPermission(command, player, true)) - return; - - Language local = playerData.getLanguageOfPlayer(player); - Arena arena = Arena.getArenaFromPlayer(player); - if (arena != null) { - local.sendMsg(player, local.playerAlreadyInGame); - return; - } - - if (argsLength == 1 || command.getCommandName().equalsIgnoreCase("list")) { - joinGui.openJoinGui(player, 1); - return; - } - - arena = Arena.getArena(arenaName); - if (arena == null) { - local.sendMsg(player, local.arenaNotFound.replace("%arena%", arenaName)); - return; - } - - arena.addPlayer(player, teleport); - } - - protected void commandQuit(CubeRunnerCommand command, Player player) { - if (!Permissions.hasPermission(command, player, true)) - return; - - Language local = playerData.getLanguageOfPlayer(player); - Arena arena = Arena.getArenaFromPlayer(player); - if (arena == null) { - local.sendMsg(player, local.playerNotInGame); - return; - } - - arena.removePlayer(player, true); - } - - protected void commandStats(CubeRunnerCommand command, Player player) { - if (!Permissions.hasPermission(command, player, true)) - return; - - achievementsGUI.openAchievementInventory(player); - } - - protected void commandStart(CubeRunnerCommand command, Player player) { - if (!Permissions.hasPermission(command, player, true)) - return; - - Language local = playerData.getLanguageOfPlayer(player); - Arena arena = Arena.getArenaFromPlayer(player); - if (arena == null) { - local.sendMsg(player, local.playerNotInGame); - return; - } - - if (arena.getGameState() != GameState.READY) { - local.sendMsg(player, local.gameNotReady); - return; - } - - arena.initiateGame(player); - } -} diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/commands/PlayerInteract.java b/Bukkit_1.9/src/me/poutineqc/cuberunner/commands/PlayerInteract.java deleted file mode 100644 index 16a55b4..0000000 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/commands/PlayerInteract.java +++ /dev/null @@ -1,63 +0,0 @@ -package me.poutineqc.cuberunner.commands; - -import org.bukkit.ChatColor; -import org.bukkit.block.Sign; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; -import org.bukkit.event.player.PlayerInteractEvent; - -import me.poutineqc.cuberunner.CubeRunner; -import me.poutineqc.cuberunner.Language; - -public class PlayerInteract implements Listener { - - private static Language local; - private PlayerCommands playerCommands; - - public PlayerInteract(CubeRunner plugin) { - PlayerInteract.local = plugin.getPlayerData().getLanguage(""); - this.playerCommands = plugin.getPlayerCommands(); - } - - @EventHandler - public void onPlayerInteract(PlayerInteractEvent event) { - if (!event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) - return; - - if (!(event.getClickedBlock().getState() instanceof Sign)) - return; - - Sign s = (Sign) event.getClickedBlock().getState(); - - if (!ChatColor.stripColor(s.getLine(1).toLowerCase().replace(" ", "")).equalsIgnoreCase( - ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.prefixLong).replace(" ", "")))) - return; - - event.setCancelled(true); - - Player player = event.getPlayer(); - - if (ChatColor.stripColor(s.getLine(2)) - .equalsIgnoreCase(ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.signPlay)))) - playerCommands.commandJoin(CubeRunnerCommand.getCommand("join"), player, 0, s.getLine(3), false); - - if (ChatColor.stripColor(s.getLine(2)) - .equalsIgnoreCase(ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.signJoin)))) - playerCommands.commandJoin(CubeRunnerCommand.getCommand("join"), player, 0, s.getLine(3), true); - - if (ChatColor.stripColor(s.getLine(2)) - .equalsIgnoreCase(ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.signQuit)))) - playerCommands.commandQuit(CubeRunnerCommand.getCommand("quit"), player); - - if (ChatColor.stripColor(s.getLine(2)) - .equalsIgnoreCase(ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.signStartGame)))) - playerCommands.commandStart(CubeRunnerCommand.getCommand("start"), player); - - if (ChatColor.stripColor(s.getLine(2)) - .equalsIgnoreCase(ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', local.signOpenStats)))) - playerCommands.commandStats(CubeRunnerCommand.getCommand("stats"), player); - - } -} diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/commands/SignPlace.java b/Bukkit_1.9/src/me/poutineqc/cuberunner/commands/SignPlace.java deleted file mode 100644 index 312a9d9..0000000 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/commands/SignPlace.java +++ /dev/null @@ -1,153 +0,0 @@ -package me.poutineqc.cuberunner.commands; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.SignChangeEvent; - -import me.poutineqc.cuberunner.CubeRunner; -import me.poutineqc.cuberunner.Language; -import me.poutineqc.cuberunner.Permissions; -import me.poutineqc.cuberunner.games.Arena; - -public class SignPlace implements Listener { - - private static Language local; - - public SignPlace(CubeRunner plugin) { - SignPlace.local = plugin.getPlayerData().getLanguage(""); - } - - @EventHandler - public void onSignPlace(SignChangeEvent event) { - - Player player = event.getPlayer(); - if (ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', event.getLine(0))).toLowerCase() - .contains("[cr]")) { - - if (!Permissions.hasPermission(Permissions.createSign, player, false)) { - setNoPermissionsSign(event); - return; - } - - if (event.getLine(1).equalsIgnoreCase("play")) - if (Arena.getArena(event.getLine(2)) != null) { - event.setLine(3, event.getLine(2)); - setPlaySign(event); - return; - } - - if (event.getLine(1).equalsIgnoreCase("join")) - if (Arena.getArena(event.getLine(2)) != null) { - event.setLine(3, event.getLine(2)); - setJoinSign(event); - return; - } - - if (event.getLine(1).equalsIgnoreCase("quit")) { - setQuitSign(event); - return; - } - - if (event.getLine(1).equalsIgnoreCase("start")) { - setStartSign(event); - return; - } - - if (event.getLine(1).equalsIgnoreCase("stats")) { - setStatsSign(event); - return; - } - - setNoValidSign(event); - - } else if (ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', event.getLine(1))).toLowerCase() - .contains("[cr]")) { - - if (!Permissions.hasPermission(Permissions.createSign, player, false)) { - setNoPermissionsSign(event); - return; - } - - if (event.getLine(2).equalsIgnoreCase("play")) - if (Arena.getArena(event.getLine(3)) == null) - setPlaySign(event); - - if (event.getLine(2).equalsIgnoreCase("join")) - if (Arena.getArena(event.getLine(3)) == null) - setJoinSign(event); - - if (event.getLine(2).equalsIgnoreCase("quit")) - setQuitSign(event); - - if (event.getLine(2).equalsIgnoreCase("start")) - setStartSign(event); - - if (event.getLine(2).equalsIgnoreCase("stats")) - setStatsSign(event); - - setNoValidSign(event); - - } else if (ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', event.getLine(2))).toLowerCase() - .contains("[cr]") - || ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', event.getLine(3))).toLowerCase() - .contains("[cr]")) { - - if (!Permissions.hasPermission(Permissions.createSign, player, false)) { - setNoPermissionsSign(event); - return; - } - - setNoValidSign(event); - } - } - - private void setNoPermissionsSign(SignChangeEvent e) { - e.setLine(0, ChatColor.translateAlternateColorCodes('&', local.signNoPermission0)); - e.setLine(1, ChatColor.translateAlternateColorCodes('&', local.signNoPermission1)); - e.setLine(2, ChatColor.translateAlternateColorCodes('&', local.signNoPermission2)); - e.setLine(3, ChatColor.translateAlternateColorCodes('&', local.signNoPermission3)); - } - - private void setNoValidSign(SignChangeEvent e) { - e.setLine(0, ChatColor.translateAlternateColorCodes('&', local.prefixLong)); - e.setLine(1, ChatColor.translateAlternateColorCodes('&', local.signNotValid1)); - e.setLine(2, ChatColor.translateAlternateColorCodes('&', local.signNotValid2)); - e.setLine(3, ChatColor.translateAlternateColorCodes('&', local.signNotValid3)); - } - - private void setStartSign(SignChangeEvent e) { - e.setLine(0, ""); - e.setLine(1, ChatColor.translateAlternateColorCodes('&', local.prefixLong)); - e.setLine(2, ChatColor.translateAlternateColorCodes('&', local.signStartGame)); - e.setLine(3, ""); - } - - private void setStatsSign(SignChangeEvent e) { - e.setLine(0, ""); - e.setLine(1, ChatColor.translateAlternateColorCodes('&', local.prefixLong)); - e.setLine(2, ChatColor.translateAlternateColorCodes('&', local.signOpenStats)); - e.setLine(3, ""); - } - - private void setQuitSign(SignChangeEvent e) { - e.setLine(0, ""); - e.setLine(1, ChatColor.translateAlternateColorCodes('&', local.prefixLong)); - e.setLine(2, ChatColor.translateAlternateColorCodes('&', local.signQuit)); - e.setLine(3, ""); - } - - private void setJoinSign(SignChangeEvent e) { - e.setLine(0, ""); - e.setLine(1, ChatColor.translateAlternateColorCodes('&', local.prefixLong)); - e.setLine(2, ChatColor.translateAlternateColorCodes('&', local.signJoin)); - } - - private void setPlaySign(SignChangeEvent e) { - e.setLine(0, ""); - e.setLine(1, ChatColor.translateAlternateColorCodes('&', local.prefixLong)); - e.setLine(2, ChatColor.translateAlternateColorCodes('&', local.signPlay)); - } - -} diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/games/Arena.java b/Bukkit_1.9/src/me/poutineqc/cuberunner/games/Arena.java deleted file mode 100644 index cab7d70..0000000 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/games/Arena.java +++ /dev/null @@ -1,1148 +0,0 @@ -package me.poutineqc.cuberunner.games; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.lang3.StringUtils; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer; -import org.bukkit.entity.FallingSand; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.Plugin; -import org.bukkit.util.Vector; - -import com.sk89q.worldedit.bukkit.WorldEditPlugin; -import com.sk89q.worldedit.bukkit.selections.Selection; - -import me.poutineqc.cuberunner.ArenaData; -import me.poutineqc.cuberunner.Configuration; -import me.poutineqc.cuberunner.CubeRunner; -import me.poutineqc.cuberunner.Language; -import me.poutineqc.cuberunner.MySQL; -import me.poutineqc.cuberunner.Permissions; -import me.poutineqc.cuberunner.PlayerData; -import me.poutineqc.cuberunner.achievements.AchievementType; -import me.poutineqc.cuberunner.achievements.Achievements; -import me.poutineqc.cuberunner.achievements.TopManager; -import me.poutineqc.cuberunner.tools.ColorManager; -import me.poutineqc.cuberunner.tools.ItemStackManager; -import net.milkbowl.vault.economy.Economy; -import net.minecraft.server.v1_9_R1.IChatBaseComponent.ChatSerializer; -import net.minecraft.server.v1_9_R1.PacketPlayOutTitle; -import net.minecraft.server.v1_9_R1.PacketPlayOutTitle.EnumTitleAction; -import net.minecraft.server.v1_9_R1.PlayerConnection; - -@SuppressWarnings("deprecation") -public class Arena { - - private static CubeRunner plugin; - private static Configuration config; - private static MySQL mysql; - private static PlayerData playerData; - private static ArenaData arenaData; - private static Achievements achievements; - private static TopManager topManager; - - private static List arenas = new ArrayList(); - private static Economy economy; - - private String name; - private World world; - private Location minPoint; - private Location maxPoint; - private Location lobby; - private Location startPoint; - - private int highestScore; - private String highestPlayer; - private int minAmountPlayer; - private int maxAmountPlayer; - private ColorManager colorManager; - - private List users = new ArrayList(); - private GameState gameState = GameState.UNREADY; - private int originalAmountPlayer; - private boolean filled; - - /******************************************* - * Constructors and else - *********************************************/ - - public Arena(CubeRunner plugin) { - Arena.plugin = plugin; - Arena.mysql = plugin.getMySQL(); - Arena.config = plugin.getConfiguration(); - Arena.arenaData = plugin.getArenaData(); - Arena.playerData = plugin.getPlayerData(); - Arena.achievements = plugin.getAchievements(); - Arena.topManager = plugin.getTopManager(); - Arena.economy = CubeRunner.getEconomy(); - } - - public static void loadExistingArenas() { - Arena.mysql = plugin.getMySQL(); - arenas = new ArrayList(); - - if (mysql.hasConnection()) { - try { - ResultSet arenas = mysql.query("SELECT * FROM " + config.tablePrefix + "ARENAS;"); - while (arenas.next()) { - String name = arenas.getString("name"); - Long colorIndice = arenas.getLong("colorIndice"); - World world = Bukkit.getServer().getWorld(arenas.getString("world")); - Location minPoint = new Location(world, arenas.getInt("minPointX"), arenas.getInt("minPointY"), - arenas.getInt("minPointZ")); - Location maxPoint = new Location(world, arenas.getInt("maxPointX"), arenas.getInt("maxPointY"), - arenas.getInt("maxPointZ")); - - Location lobby = new Location(world, arenas.getDouble("lobbyX"), arenas.getDouble("lobbyY"), - arenas.getDouble("lobbyZ")); - lobby.setPitch(arenas.getFloat("lobbyPitch")); - lobby.setYaw(arenas.getFloat("lobbyYaw")); - - Location startPoint = new Location(world, arenas.getDouble("startPointX"), - arenas.getDouble("startPointY"), arenas.getDouble("startPointZ")); - startPoint.setPitch(arenas.getFloat("startPointPitch")); - startPoint.setYaw(arenas.getFloat("startPointYaw")); - - int minAmountPlayer = arenas.getInt("minAmountPlayer"); - int maxAmountPlayer = arenas.getInt("maxAmountPlayer"); - int highestScore = arenas.getInt("highestScore"); - String highestPlayer = arenas.getString("highestPlayer"); - new Arena(name, world, minPoint, maxPoint, lobby, startPoint, minAmountPlayer, maxAmountPlayer, - highestScore, highestPlayer, colorIndice); - } - } catch (SQLException e) { - plugin.getLogger().info("[MySQL] Error while loading arenas."); - } - - } else { - if (!arenaData.getData().contains("arenas")) - return; - - for (String arenaName : arenaData.getData().getConfigurationSection("arenas").getKeys(false)) { - World world = Bukkit.getServer() - .getWorld(arenaData.getData().getString("arenas." + arenaName + ".world")); - Long colorIndice = arenaData.getData().getLong("arenas." + arenaName + ".colorIndice", 1); - Location minPoint = new Location(world, - arenaData.getData().getInt("arenas." + arenaName + ".minPoint.X", 0), - arenaData.getData().getInt("arenas." + arenaName + ".minPoint.Y", 0), - arenaData.getData().getInt("arenas." + arenaName + ".minPoint.Z", 0)); - Location maxPoint = new Location(world, - arenaData.getData().getInt("arenas." + arenaName + ".maxPoint.X", 0), - arenaData.getData().getInt("arenas." + arenaName + ".maxPoint.Y", 0), - arenaData.getData().getInt("arenas." + arenaName + ".maxPoint.Z", 0)); - - Location lobby = new Location(world, - arenaData.getData().getDouble("arenas." + arenaName + ".lobby.X", 0), - arenaData.getData().getDouble("arenas." + arenaName + ".lobby.Y", 0), - arenaData.getData().getDouble("arenas." + arenaName + ".lobby.Z", 0)); - lobby.setPitch((float) arenaData.getData().getDouble("arenas." + arenaName + ".lobby.Pitch", 0)); - lobby.setYaw((float) arenaData.getData().getDouble("arenas." + arenaName + ".lobby.Yaw", 0)); - - Location startPoint = new Location(world, - arenaData.getData().getDouble("arenas." + arenaName + ".startPoint.X", 0), - arenaData.getData().getDouble("arenas." + arenaName + ".startPoint.Y", 0), - arenaData.getData().getDouble("arenas." + arenaName + ".startPoint.Z", 0)); - startPoint.setPitch( - (float) arenaData.getData().getDouble("arenas." + arenaName + ".startPoint.Pitch", 0)); - startPoint.setYaw((float) arenaData.getData().getDouble("arenas." + arenaName + ".startPoint.Yaw", 0)); - - int minAmountPlayer = arenaData.getData().getInt("arenas." + arenaName + ".minAmountPlayer", 1); - int maxAmountPlayer = arenaData.getData().getInt("arenas." + arenaName + ".maxAmountPlayer", 8); - int highestScore = arenaData.getData().getInt("arenas." + arenaName + ".highestScore.score", 0); - String highestPlayer = arenaData.getData().getString("arenas." + arenaName + ".highestScore.player", - "null"); - new Arena(arenaName, world, minPoint, maxPoint, lobby, startPoint, minAmountPlayer, maxAmountPlayer, - highestScore, highestPlayer, colorIndice); - } - } - } - - public Arena(String name, World world, Location minPoint, Location maxPoint, Location lobby, Location startPoint, - int minAmountPlayer, int maxAmountPlayer, int highestScore, String highestPlayer, Long colorIndice) { - this.name = name; - this.world = world; - this.minPoint = minPoint; - this.maxPoint = maxPoint; - this.lobby = lobby; - this.startPoint = startPoint; - this.minAmountPlayer = minAmountPlayer; - this.maxAmountPlayer = maxAmountPlayer; - this.highestScore = highestScore; - this.highestPlayer = highestPlayer; - this.colorManager = new ColorManager(colorIndice, plugin, this); - - setNullIfDefault(); - arenas.add(this); - } - - public Arena(String name, Player player) { - this.name = name; - world = player.getWorld(); - arenas.add(this); - colorManager = new ColorManager((long) 1, plugin, this); - this.highestPlayer = "null"; - this.highestScore = 0; - this.minAmountPlayer = 1; - this.maxAmountPlayer = 8; - - if (mysql.hasConnection()) { - mysql.update("INSERT INTO " + config.tablePrefix + "ARENAS (name, world) " + "VALUES ('" + name + "','" - + world.getName() + "');"); - mysql.update("UPDATE " + config.tablePrefix + "ARENAS SET colorIndice=" + (long) 1 + " WHERE name='" + name - + "';"); - } else { - arenaData.getData().set("arenas." + name + ".world", world.getName()); - arenaData.getData().set("arenas." + name + ".colorIndice", (long) 1); - arenaData.saveArenaData(); - } - } - - private void setNullIfDefault() { - if ((0 == minPoint.getX()) && (0 == minPoint.getY()) && (0 == minPoint.getZ())) - minPoint = null; - - if ((0 == maxPoint.getX()) && (0 == maxPoint.getY()) && (0 == maxPoint.getZ())) - maxPoint = null; - - if ((0 == lobby.getX()) && (0 == lobby.getY()) && (0 == lobby.getZ())) - lobby = null; - - if ((0 == startPoint.getX()) && (0 == startPoint.getY()) && (0 == startPoint.getZ())) - startPoint = null; - - if (isReady()) - gameState = GameState.READY; - } - - public void delete(Player player) { - Language local = playerData.getLanguageOfPlayer(player); - local.sendMsg(player, local.arenaDeleted); - arenas.remove(this); - - if (mysql.hasConnection()) { - mysql.update("DELETE FROM " + config.tablePrefix + "ARENAS WHERE name='" + name + "';"); - } else { - arenaData.getData().set("arenas." + name, null); - arenaData.saveArenaData(); - } - } - - /******************************************* - * Arena Setup - *********************************************/ - - public void setArena(Player player) { - Language local = playerData.getLanguageOfPlayer(player); - - Selection s = getWorldEdit().getSelection(player); - if (s == null) { - local.sendMsg(player, local.missingWorldEditRegion); - return; - } - - gameState = GameState.UNREADY; - world = s.getWorld(); - minPoint = s.getMinimumPoint(); - maxPoint = s.getMaximumPoint(); - local.sendMsg(player, local.arenaSetArena.replace("%arena%", name)); - - if (mysql.hasConnection()) { - mysql.update("UPDATE " + config.tablePrefix + "ARENAS SET world=" + world.getName() + ",minPointX=" - + minPoint.getBlockX() + ",minPointY=" + minPoint.getBlockY() + ",minPointZ=" + minPoint.getBlockZ() - + ",maxPointX=" + maxPoint.getBlockX() + ",maxPointY=" + maxPoint.getBlockY() + ",maxPointZ=" - + maxPoint.getBlockZ() + " WHERE name='" + name + "';"); - } else { - arenaData.getData().set("arenas." + name + ".world", world.getName()); - arenaData.getData().set("arenas." + name + ".minPoint.X", minPoint.getBlockX()); - arenaData.getData().set("arenas." + name + ".minPoint.Y", minPoint.getBlockY()); - arenaData.getData().set("arenas." + name + ".minPoint.Z", minPoint.getBlockZ()); - arenaData.getData().set("arenas." + name + ".maxPoint.X", maxPoint.getBlockX()); - arenaData.getData().set("arenas." + name + ".maxPoint.Y", maxPoint.getBlockY()); - arenaData.getData().set("arenas." + name + ".maxPoint.Z", maxPoint.getBlockZ()); - arenaData.saveArenaData(); - } - - if (isReady()) - gameState = GameState.READY; - } - - public void setLobby(Player player) { - Language local = playerData.getLanguageOfPlayer(player); - - gameState = GameState.UNREADY; - world = player.getWorld(); - lobby = player.getLocation(); - lobby.add(new Vector(0, 0.5, 0)); - local.sendMsg(player, local.arenaSetLobby.replace("%arena%", name)); - - if (mysql.hasConnection()) { - mysql.update("UPDATE " + config.tablePrefix + "ARENAS SET world=" + world.getName() + ",lobbyX=" - + lobby.getX() + ",lobbyY=" + lobby.getY() + ",lobbyZ=" + lobby.getZ() + ",lobbyPitch=" - + lobby.getPitch() + ",lobbyYaw=" + lobby.getYaw() + " WHERE name='" + name + "';"); - } else { - arenaData.getData().set("arenas." + name + ".world", world.getName()); - arenaData.getData().set("arenas." + name + ".lobby.X", lobby.getX()); - arenaData.getData().set("arenas." + name + ".lobby.Y", lobby.getY()); - arenaData.getData().set("arenas." + name + ".lobby.Z", lobby.getZ()); - arenaData.getData().set("arenas." + name + ".lobby.Pitch", lobby.getPitch()); - arenaData.getData().set("arenas." + name + ".lobby.Yaw", lobby.getYaw()); - arenaData.saveArenaData(); - } - - if (isReady()) - gameState = GameState.READY; - } - - public void setStartPoint(Player player) { - Language local = playerData.getLanguageOfPlayer(player); - - gameState = GameState.UNREADY; - world = player.getWorld(); - startPoint = player.getLocation(); - startPoint.add(new Vector(0, 0.5, 0)); - local.sendMsg(player, local.arenaSetStartPoint.replace("%arena%", name)); - - if (mysql.hasConnection()) { - mysql.update("UPDATE " + config.tablePrefix + "ARENAS SET world=" + world.getName() + ",startPointX=" - + startPoint.getX() + ",startPointY=" + startPoint.getY() + ",startPointZ=" + startPoint.getZ() - + ",startPointPitch=" + startPoint.getPitch() + ",startPointYaw=" + startPoint.getYaw() - + " WHERE name='" + name + "';"); - } else { - arenaData.getData().set("arenas." + name + ".world", world.getName()); - arenaData.getData().set("arenas." + name + ".startPoint.X", startPoint.getX()); - arenaData.getData().set("arenas." + name + ".startPoint.Y", startPoint.getY()); - arenaData.getData().set("arenas." + name + ".startPoint.Z", startPoint.getZ()); - arenaData.getData().set("arenas." + name + ".startPoint.Pitch", startPoint.getPitch()); - arenaData.getData().set("arenas." + name + ".startPoint.Yaw", startPoint.getYaw()); - arenaData.saveArenaData(); - } - - if (isReady()) - gameState = GameState.READY; - } - - private WorldEditPlugin getWorldEdit() { - Plugin p = Bukkit.getPluginManager().getPlugin("WorldEdit"); - if (p instanceof WorldEditPlugin) - return (WorldEditPlugin) p; - else - return null; - } - - public void setMinPlayer(int amount, Player player) { - Language local = playerData.getLanguageOfPlayer(player); - - if (amount < 1) { - local.sendMsg(player, - local.arenaAmountPlayerInvalidArgument.replace("%error%", local.arenaAmountPlayerMinEqualZero)); - return; - } - - if (amount > maxAmountPlayer) { - local.sendMsg(player, - local.arenaAmountPlayerInvalidArgument.replace("%error%", local.arenaAmountPlayerMinBiggerMax)); - return; - } - - if (mysql.hasConnection()) { - mysql.update("UPDATE " + config.tablePrefix + "ARENAS SET minAmountPlayer=" + amount + " WHERE name='" - + name + "';"); - } else { - arenaData.getData().set("arenas." + name + ".minAmountPlayer", amount); - arenaData.saveArenaData(); - } - - minAmountPlayer = amount; - local.sendMsg(player, local.arenaAmountPlayerSuccess.replace("%arena%", name)); - } - - public void setMaxPlayer(int amount, Player player) { - Language local = playerData.getLanguageOfPlayer(player); - - if (amount < minAmountPlayer) { - local.sendMsg(player, - local.arenaAmountPlayerInvalidArgument.replace("%error%", local.arenaAmountPlayerMaxBiggerMin)); - return; - } - - if (mysql.hasConnection()) { - mysql.update("UPDATE " + config.tablePrefix + "ARENAS SET maxAmountPlayer=" + amount + " WHERE name='" - + name + "';"); - } else { - arenaData.getData().set("arenas." + name + ".maxAmountPlayer", amount); - arenaData.saveArenaData(); - } - - maxAmountPlayer = amount; - local.sendMsg(player, local.arenaAmountPlayerSuccess.replace("%arena%", name)); - } - - private boolean isReady() { - return isOutsideArena(lobby) && isInsideArena(startPoint); - } - - /******************************************* - * Tools - *********************************************/ - - public void displayInformation(Player player) { - Language local = playerData.getLanguageOfPlayer(player); - - String stringGameState; - switch (gameState) { - case ACTIVE: - stringGameState = local.keyWordActive; - break; - case READY: - stringGameState = local.keyWordReady; - break; - case STARTUP: - stringGameState = local.keyWordStartup; - break; - case ENDING: - case UNREADY: - default: - stringGameState = local.keyWordUnset; - } - - player.sendMessage( - ChatColor.translateAlternateColorCodes('&', "&8&m" + StringUtils.repeat(" ", 13) + "&r &5CubeRunner &d" - + local.keyWordInformation + " &5: &d" + name + " &8&m" + StringUtils.repeat(" ", 13))); - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5" + local.keyWordCurrent + " " + local.keyWordGameState + ": &7" + stringGameState)); - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5" + local.keyWordCurrent + " " + local.keyWordAmountPlayer + ": &7" + users.size())); - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5" + local.keyWordMinimum + " " + local.keyWordAmountPlayer + ": &7" + minAmountPlayer)); - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5" + local.keyWordMaximum + " " + local.keyWordAmountPlayer + ": &7" + maxAmountPlayer)); - player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&5" + local.keyWordBestScore + ": &7" - + highestScore + " &5" + local.keyWordBy + " &7" + highestPlayer)); - player.sendMessage("\n"); - - if (!Permissions.hasPermission(Permissions.advancedInfo, player, false)) - return; - - player.sendMessage( - ChatColor.translateAlternateColorCodes('&', "&8&m" + StringUtils.repeat(" ", 5) + "&r &5CubeRunner &d" - + local.keyWordAdvanced + " &5: &d" + name + " &8&m" + StringUtils.repeat(" ", 5))); - player.sendMessage( - ChatColor.translateAlternateColorCodes('&', "&5" + local.keyWordWorld + ": &7" + world.getName())); - if (lobby == null) { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&5" + local.keyWordLobby + ": &7null")); - } else { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5" + local.keyWordLobby + ": &7{" + ((int) (lobby.getX() * 100)) / (double) 100 + ", " - + ((int) (lobby.getY() * 100)) / (double) 100 + ", " - + ((int) (lobby.getZ() * 100)) / (double) 100 + "}")); - } - if (startPoint == null) { - player.sendMessage( - ChatColor.translateAlternateColorCodes('&', "&5" + local.keyWordStartPoint + ": &7null")); - } else { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5" + local.keyWordStartPoint + ": &7{" + ((int) (startPoint.getX() * 100)) / (double) 100 + ", " - + ((int) (startPoint.getY() * 100)) / (double) 100 + ", " - + ((int) (startPoint.getZ() * 100)) / (double) 100 + "}")); - } - if (minPoint == null) { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5" + local.keyWordMinimum + local.keyWordZone + ": &7null")); - } else { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5" + local.keyWordMinimum + local.keyWordZone + ": &7{" + minPoint.getBlockX() + ", " - + minPoint.getBlockY() + ", " + minPoint.getBlockZ() + "}")); - } - if (maxPoint == null) { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5" + local.keyWordMaximum + local.keyWordZone + ": &7null")); - } else { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', - "&5" + local.keyWordMaximum + local.keyWordZone + ": &7{" + maxPoint.getBlockX() + ", " - + maxPoint.getBlockY() + ", " + maxPoint.getBlockZ() + "}")); - } - player.sendMessage("\n"); - } - - /******************************************* - * Big Game commands - *********************************************/ - - public void addPlayer(Player player, boolean teleport) { - Language local = playerData.getLanguageOfPlayer(player); - playerData.addOnFileIfNotExist(player); - - if (getArenaFromPlayer(player) != null) { - local.sendMsg(player, local.playerAlreadyInGame); - return; - } - - if (gameState == GameState.UNREADY || gameState == GameState.ENDING) { - local.sendMsg(player, local.playerJoinUnready); - return; - } - - User user = addUser(player, gameState == GameState.ACTIVE); - - if (teleport) { - player.teleport(lobby); - user.maxStats(); - } - - if (gameState == GameState.ACTIVE) { - local.sendMsg(player, local.playerJoinActive); - - if (teleport) - local.sendMsg(player, local.playerJoinSpectator); - - return; - } - - if (gameState == GameState.STARTUP) { - player.teleport(startPoint); - user.maxStats(); - } - - local.sendMsg(player, local.playerJoinSuccess.replace("%arena%", name)); - for (User u : users) { - Player p = u.getPlayer(); - if (p == player) - return; - - Language localAlt = playerData.getLanguageOfPlayer(p); - localAlt.sendMsg(p, localAlt.playerJoinOthers.replace("%player%", player.getDisplayName())); - } - } - - private User addUser(Player player, boolean eliminated) { - User user = new User(config, player, gameState == GameState.ACTIVE); - users.add(user); - user.maxStats(); - user.setEliminated(eliminated); - return user; - } - - public void removePlayer(Player player, boolean disconnect) { - Language local = playerData.getLanguageOfPlayer(player); - - User user = getUser(player); - - user.quit(); - - local.sendMsg(player, local.playerQuitSuccess.replace("%arena%", name)); - for (User u : users) { - Player p = u.getPlayer(); - if (p == player) - continue; - - Language l = playerData.getLanguageOfPlayer(p); - l.sendMsg(p, l.playerQuitOthers.replace("%player%", player.getDisplayName())); - } - - if (getGameState() == GameState.ACTIVE) - eliminateUser(user, disconnect); - - if (getGameState() == GameState.STARTUP) - player.teleport(lobby); - - user.returnStats(); - removeUser(player); - } - - public void initiateGame(Player player) { - Language local = playerData.getLanguageOfPlayer(player); - - if (users.size() < minAmountPlayer) { - local.sendMsg(player, local.gameStartLessMin.replace("%amount%", String.valueOf(minAmountPlayer))); - return; - } - - if (users.size() > maxAmountPlayer) { - local.sendMsg(player, local.gameStartLessMax.replace("%amount%", String.valueOf(maxAmountPlayer))); - return; - } - - if (users.size() < maxAmountPlayer) - for (Player p : Bukkit.getServer().getOnlinePlayers()) { - Language localTemp = playerData.getLanguageOfPlayer(p); - p.sendMessage(ChatColor.translateAlternateColorCodes('&', - localTemp.prefixShort + localTemp.gameCountdownStarted.replace("%arena%", name))); - } - - resetArena(); - gameState = GameState.STARTUP; - - for (User user : users) { - user.getPlayer().teleport(startPoint); - user.maxStats(); - } - - countdown(this, config.countdownTime * 20); - } - - private void countdown(final Arena arena, final int cooldownTimer) { - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { - public void run() { - - int level = (int) Math.floor(cooldownTimer / 20); - - for (User user : arena.users) { - if (cooldownTimer != 0) - user.getPlayer().setLevel(level + 1); - else - user.getPlayer().setLevel(0); - - user.getPlayer().setExp((float) ((cooldownTimer % 20) / 20.0)); - } - - if (gameState == GameState.STARTUP) { - switch (cooldownTimer / 20) { - case 30: - case 10: - case 5: - case 4: - case 3: - case 2: - case 1: - for (User user : arena.users) { - if (cooldownTimer % 20.0 == 0) { - user.getPlayer().playSound(user.getPlayer().getLocation(), Sound.UI_BUTTON_CLICK, 1, 1); - - Language local = playerData.getLanguageOfPlayer(user.getPlayer()); - - PacketPlayOutTitle countNumberTitle = new PacketPlayOutTitle(EnumTitleAction.TITLE, - ChatSerializer.a("{\"text\":\"" + cooldownTimer / 20 - + "\",\"color\":\"gold\",\"bold\":true}"), - 1, 20, 5); - PacketPlayOutTitle countNumberSubtitle = new PacketPlayOutTitle( - EnumTitleAction.SUBTITLE, ChatSerializer.a("{\"text\":\"" + local.keyWordSeconds - + "\",\"color\":\"dark_gray\",\"italic\":true}"), - 1, 20, 5); - - PlayerConnection connection = ((CraftPlayer) user.getPlayer()) - .getHandle().playerConnection; - connection.sendPacket(countNumberTitle); - connection.sendPacket(countNumberSubtitle); - - } - } - break; - case 0: - if (cooldownTimer % 20.0 == 0) { - - arena.startGame(); - return; - } - } - - arena.countdown(arena, cooldownTimer - 1); - - } else { - for (User user : arena.users) { - Player p = user.getPlayer(); - p.setLevel(0); - p.setExp(0); - Language local = playerData.getLanguageOfPlayer(p); - local.sendMsg(user.getPlayer(), local.gameCountdownStopped); - } - } - } - }, 1L); - - } - - protected void startGame() { - gameState = GameState.ACTIVE; - originalAmountPlayer = getAmountInGame(this); - blockShower(1, this); - - for (User user : users) { - Player player = user.getPlayer(); - player.setGameMode(GameMode.ADVENTURE); - player.setFlying(false); - - user.setStartTime(); - } - - } - - private void resetArena() { - for (int x = minPoint.getBlockX(); x <= maxPoint.getBlockX(); x++) - for (int y = maxPoint.getBlockY(); y >= minPoint.getBlockY(); y--) - nextBlock: for (int z = minPoint.getBlockZ(); z <= maxPoint.getBlockZ(); z++) { - Location location = new Location(world, x, y, z); - Block block = location.getBlock(); - if (block.getType() != Material.STAINED_CLAY && block.getType() != Material.WOOL) - continue; - - for (ItemStackManager item : colorManager.getOnlyChoosenBlocks()) - if (item.getMaterial() == block.getType()) - if (item.getItem().getDurability() == block.getData()) { - block.setType(Material.AIR); - continue nextBlock; - } - - } - } - - public void resetArena(ItemStack item) { - for (int x = minPoint.getBlockX(); x <= maxPoint.getBlockX(); x++) - for (int y = maxPoint.getBlockY(); y >= minPoint.getBlockY(); y--) - nextBlock: for (int z = minPoint.getBlockZ(); z <= maxPoint.getBlockZ(); z++) { - Location location = new Location(world, x, y, z); - Block block = location.getBlock(); - if (block.getType() != Material.STAINED_CLAY && block.getType() != Material.WOOL) - continue; - - if (item.getType() == block.getType()) - if (item.getDurability() == block.getData()) { - block.setType(Material.AIR); - continue nextBlock; - } - - } - } - - private static void blockShower(final long number, final Arena arena) { - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { - public void run() { - - if (getAmountInGame(arena) == 0) - return; - - if (!arena.filled) - if (arena.isArenaFull()) { - arena.filled = true; - for (User u : arena.users) - if (!u.isEliminated()) - achievements.checkAchievement(AchievementType.FILL_THE_ARENA, u.getPlayer()); - } - - if (number == 6000) - for (User u : arena.users) - if (!u.isEliminated()) - achievements.checkAchievement(AchievementType.SURVIVE_5_MINUTES, u.getPlayer()); - - for (User user : arena.users) { - - if (user.isEliminated()) - continue; - - Player player = user.getPlayer(); - - Location l; - if (arena.maxPoint.getBlockY() > player.getLocation().getBlockY() + 10) - l = new Location(player.getWorld(), player.getLocation().getBlockX(), - player.getLocation().getBlockY() + 10, player.getLocation().getBlockZ()); - else - l = new Location(player.getWorld(), player.getLocation().getBlockX(), - arena.maxPoint.getBlockY(), player.getLocation().getBlockZ()); - - player.setSaturation(20); - if (number % 20 == 0) { - player.setLevel((int) number / 20); - user.addToScore(); - - int totalScore = 0; - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT totalScore FROM " + config.tablePrefix - + "PLAYERS WHERE UUID='" + user.getUUID() + "';"); - try { - if (query.next()) - totalScore = query.getInt("totalScore"); - } catch (SQLException e) { - e.printStackTrace(); - } - - mysql.update("UPDATE " + config.tablePrefix + "PLAYERS SET totalScore='" + ++totalScore - + "' WHERE UUID='" + user.getUUID() + "';"); - } else { - totalScore = playerData.getData().getInt("players." + user.getUUID() + ".totalScore", 0); - playerData.getData().set("players." + user.getUUID() + ".totalScore", ++totalScore); - playerData.savePlayerData(); - } - - achievements.checkAchievement(AchievementType.TOTAL_SCORE, player); - } - - ItemStackManager fallingBlock = arena.colorManager.getRandomAvailableBlock(); - - FallingSand clay = (FallingSand) player.getWorld().spawnFallingBlock(l, fallingBlock.getMaterial(), - (byte) fallingBlock.getData()); - - clay.setDropItem(false); - clay.setHurtEntities(true); - clay.setCustomName(user.getUUID()); - clay.setCustomNameVisible(false); - - if (number % 2 == 0) { - clay.setVelocity( - new Vector((1 - (Math.random() * 2)) / 10.0, 0, (1 - (Math.random() * 2)) / 10.0)); - - } - } - - Arena.blockShower(number + 1, arena); - - } - }, 1L); - } - - private boolean isArenaFull() { - for (int i = minPoint.getBlockX(); i < maxPoint.getBlockX(); i++) - for (int j = minPoint.getBlockZ(); j < maxPoint.getBlockZ(); j++) - if (new Location(world, i, minPoint.getBlockY(), j).getBlock().getType() == Material.AIR) - return false; - - return true; - } - - protected void eliminateUser(User user, boolean disconnection) { - - user.getPlayer().teleport(lobby); - user.setEliminated(true); - - if (!disconnection) { - Language local = playerData.getLanguageOfPlayer(user.getPlayer()); - local.sendMsg(user, local.gameCrushedPlayer.replace("%score%", String.valueOf(user.getScore()))); - for (User u : users) { - if (u == user) - continue; - - Language l = playerData.getLanguageOfPlayer(u.getPlayer()); - l.sendMsg(u, l.gameCrushedOthers.replace("%player%", user.getDisplayName()).replace("%score%", - String.valueOf(user.getScore()))); - } - } - - int games = 0; - int timePlayed = 0; - double totalDistance = 0; - int totalScore = 0; - double money = 0; - - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT games, timePlayed, totalDistance, totalScore, money FROM " - + config.tablePrefix + "PLAYERS WHERE UUID='" + user.getUUID() + "';"); - - try { - if (query.next()) { - games = query.getInt("games"); - timePlayed = query.getInt("timePlayed"); - totalDistance = query.getDouble("totalDistance"); - totalScore = query.getInt("totalScore"); - money = query.getDouble("money"); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } else { - games = playerData.getData().getInt("players." + user.getUUID() + ".games", 0); - timePlayed = playerData.getData().getInt("players." + user.getUUID() + ".timePlayed", 0); - totalDistance = playerData.getData().getDouble("players." + user.getUUID() + ".totalDistance", 0); - totalScore = playerData.getData().getInt("players." + user.getUUID() + ".totalScore", 0); - money = playerData.getData().getDouble("players." + user.getUUID() + ".money", 0); - } - - games++; - timePlayed += user.getGameLenght(); - totalDistance += user.getDistanceRan(); - double ratio = (double) totalScore / games; - - if (CubeRunner.isEconomyEnabled()) { - Player player = user.getPlayer(); - double amount = (config.pricePerScore * user.getScore()); - economy.depositPlayer(player, amount); - Language l = playerData.getLanguageOfPlayer(player); - l.sendMsg(player, - l.achievementMoneyGame.replace("%amount2%", String.valueOf(user.getScore())) - .replace("%amount%", String.valueOf((int) (amount * 100) / 100.0)) - .replace("%currency%", economy.currencyNamePlural())); - money += amount; - } - - if (mysql.hasConnection()) { - mysql.update("UPDATE " + config.tablePrefix + "PLAYERS SET money='" + money + "', timePlayed='" + timePlayed - + "', games='" + games + "', totalDistance='" + totalDistance + "', averageDistancePerGame='" - + ratio + "' WHERE UUID='" + user.getUUID() + "';"); - } else { - playerData.getData().set("players." + user.getUUID() + ".timePlayed", timePlayed); - playerData.getData().set("players." + user.getUUID() + ".games", games); - playerData.getData().set("players." + user.getUUID() + ".totalDistance", totalDistance); - playerData.getData().set("players." + user.getUUID() + ".averageDistancePerGame", ratio); - playerData.getData().set("players." + user.getUUID() + ".money", money); - playerData.savePlayerData(); - } - - achievements.checkAchievement(AchievementType.AMOUNT_GAMES, user.getPlayer()); - - if (user.getScore() == 42) - achievements.checkAchievement(AchievementType.DIE_SECONDS_42, user.getPlayer()); - - if (getAmountInGame(this) == 0) - endingSequence(); - - if (!mysql.hasConnection()) - topManager.updateAll(); - } - - private void endingSequence() { - gameState = GameState.ENDING; - - User user = getHighestScore(); - - if (originalAmountPlayer > 1) { - int multiWins = 0; - if (mysql.hasConnection()) { - ResultSet query = mysql.query("SELECT multiplayerWon FROM " + config.tablePrefix - + "PLAYERS WHERE UUID='" + user.getUUID() + "';"); - try { - if (query.next()) - multiWins = query.getInt("multiplayerWon"); - - mysql.update("UPDATE " + config.tablePrefix + "PLAYERS SET multiplayerWon='" + ++multiWins - + "' WHERE UUID='" + user.getUUID() + "';"); - } catch (SQLException e) { - e.printStackTrace(); - } - } else { - multiWins = playerData.getData().getInt("players." + user.getUUID() + ".multiplayerWon", 0); - playerData.getData().set("players." + user.getUUID() + ".multiplayerWon", ++multiWins); - playerData.savePlayerData(); - } - - achievements.checkAchievement(AchievementType.MULTIPLAYER_GAMES_WON, user.getPlayer()); - } - - if (user.getScore() > highestScore) { - highestScore = user.getScore(); - highestPlayer = user.getPlayer().getName(); - - for (Player player : Bukkit.getServer().getOnlinePlayers()) { - Language local = playerData.getLanguageOfPlayer(player); - local.sendMsg(player, local.endingBest.replace("%player%", user.getDisplayName()) - .replace("%score%", String.valueOf(user.getScore())).replace("%arena%", name)); - } - - if (mysql.hasConnection()) { - mysql.update("UPDATE " + config.tablePrefix + "ARENAS SET highestScore='" + user.getScore() - + "', highestPlayer='" + user.getPlayer().getName() + "' WHERE name='" + name + "';"); - } else { - arenaData.getData().set("arenas." + name + ".highestScore.score", highestScore); - arenaData.getData().set("arenas." + name + ".highestScore.player", user.getPlayer().getName()); - arenaData.saveArenaData(); - } - } - - if (config.teleportAfterEnding) { - for (User u : users) { - Language local = playerData.getLanguageOfPlayer(u.getPlayer()); - local.sendMsg(u, local.endingTeleport); - } - - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { - public void run() { - kickUsers(false); - } - }, 100L); - } else - kickUsers(true); - - } - - private User getHighestScore() { - User user = new User(0); - for (User u : users) - if (user.getScore() <= u.getScore()) - user = u; - return user; - } - - private static int getAmountInGame(Arena arena) { - int i = 0; - for (User user : arena.users) - if (!user.isEliminated()) - i++; - - return i; - } - - private void kickUsers(boolean wait) { - for (User user : users) { - user.quit(); - user.returnStats(); - } - - users.clear(); - - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { - public void run() { - gameState = GameState.READY; - } - }, wait ? 5L : 0L); - } - - public void removeUser(Player player) { - for (User user : users) { - if (user.getUUID().equalsIgnoreCase(player.getUniqueId().toString())) { - users.remove(user); - - if (getGameState() == GameState.STARTUP) - checkIfStillActive(); - - return; - } - } - } - - private void checkIfStillActive() { - if (getAmountInGame(this) < minAmountPlayer) { - gameState = GameState.READY; - for (User user : users) - user.getPlayer().teleport(lobby); - } - } - - public boolean isInsideArena(Location location) { - if (minPoint == null) - return false; - if (maxPoint == null) - return false; - if (location == null) - return false; - - if (location.getBlockX() < minPoint.getBlockX() || location.getBlockX() > maxPoint.getBlockX()) - return false; - - if (location.getBlockY() < minPoint.getBlockY() || location.getBlockY() > maxPoint.getBlockY()) - return false; - - if (location.getBlockZ() < minPoint.getBlockZ() || location.getBlockZ() > maxPoint.getBlockZ()) - return false; - - return true; - } - - public boolean isOutsideArena(Location location) { - if (minPoint == null) - return false; - if (maxPoint == null) - return false; - if (location == null) - return false; - - if (location.getBlockX() < minPoint.getBlockX() || location.getBlockX() > maxPoint.getBlockX()) - return true; - - if (location.getBlockY() < minPoint.getBlockY() || location.getBlockY() > maxPoint.getBlockY()) - return true; - - if (location.getBlockZ() < minPoint.getBlockZ() || location.getBlockZ() > maxPoint.getBlockZ()) - return true; - - return false; - } - - /******************************************* - * Getters and setters - *********************************************/ - - public static List getArenas() { - return arenas; - } - - public String getName() { - return name; - } - - public GameState getGameState() { - return gameState; - } - - public static Arena getArena(String name) { - for (Arena arena : arenas) - if (arena.name.toLowerCase().equalsIgnoreCase(name.toLowerCase())) - return arena; - return null; - } - - public static Arena getArenaFromPlayer(Player player) { - for (Arena arena : arenas) - for (User user : arena.users) - if (user.getPlayer() == player) - return arena; - return null; - } - - public static Arena getArenaFromUser(User user) { - for (Arena arena : arenas) - for (User u : arena.users) - if (user == u) - return arena; - return null; - } - - public User getUser(Player player) { - for (User user : users) - if (user.getPlayer() == player) - return user; - return null; - } - - protected int getAmountOfPlayerInGame() { - int i = 0; - for (User user : users) - if (!user.isEliminated()) - i++; - - return i; - } - - public Location getLobby() { - return lobby; - } - - public Location getStartPoint() { - return startPoint; - } - - public List getUsers() { - return users; - } - - protected String getHighestPlayer() { - return highestPlayer; - } - - public Player getPlayerFromUUID(String dammagerUUID) { - for (User user : users) - if (user.getUUID().equalsIgnoreCase(dammagerUUID)) - return user.getPlayer(); - return null; - } - - public Location getMinPoint() { - return minPoint; - } - - public ColorManager getColorManager() { - return colorManager; - } - - public Location getMaxPoint() { - return maxPoint; - } - -} diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/games/ColorGUI.java b/Bukkit_1.9/src/me/poutineqc/cuberunner/games/ColorGUI.java deleted file mode 100644 index 5126f25..0000000 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/games/ColorGUI.java +++ /dev/null @@ -1,148 +0,0 @@ -package me.poutineqc.cuberunner.games; - -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; - -import me.poutineqc.cuberunner.CubeRunner; -import me.poutineqc.cuberunner.Language; -import me.poutineqc.cuberunner.PlayerData; -import me.poutineqc.cuberunner.tools.ItemStackManager; - -public class ColorGUI implements Listener { - - private PlayerData playerData; - - public ColorGUI(CubeRunner plugin) { - this.playerData = plugin.getPlayerData(); - } - - @EventHandler - public void onInventoryClick(InventoryClickEvent event) { - if (!(event.getWhoClicked() instanceof Player)) - return; - - Player player = (Player) event.getWhoClicked(); - Language local = playerData.getLanguageOfPlayer(player); - - if (!ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase(ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.guiColorName + " &0: &5CubeRunner")))) - return; - - if (event.getAction() == InventoryAction.NOTHING || event.getAction() == InventoryAction.UNKNOWN) - return; - - event.setCancelled(true); - - ItemStack item = event.getCurrentItem(); - - if (item.getType() != Material.STAINED_CLAY && item.getType() != Material.WOOL) - return; - - Arena arena = Arena - .getArena(ChatColor.stripColor(event.getInventory().getItem(0).getItemMeta().getLore().get(0))); - - if (arena.getGameState() == GameState.ACTIVE || arena.getGameState() == GameState.ENDING) { - player.closeInventory(); - local.sendMsg(player, local.guiColorEditWhileActive); - return; - } - - int valueOfItem = item.getDurability(); - if (item.getType() == Material.STAINED_CLAY) - valueOfItem += 16; - - if (item.getItemMeta().hasEnchants()) - arena.getColorManager() - .setColorIndice(arena.getColorManager().getColorIndice() - (int) Math.pow(2, valueOfItem)); - else - arena.getColorManager() - .setColorIndice(arena.getColorManager().getColorIndice() + (int) Math.pow(2, valueOfItem)); - - arena.resetArena(item); - openColorGUI(player, arena); - } - - public void openColorGUI(Player player, Arena arena) { - Language local = playerData.getLanguageOfPlayer(player); - - Inventory inv = Bukkit.createInventory(null, 54, - ChatColor.translateAlternateColorCodes('&', local.guiColorName + " &0: &5CubeRunner")); - ItemStackManager icon; - /*************************************************** - * Instructions - ***************************************************/ - - icon = new ItemStackManager(Material.BOOKSHELF, 4); - icon.setTitle(local.guiInstrictions); - for (String loreLine : local.guiColorInfo.split("\n")) - icon.addToLore(loreLine); - icon.addToInventory(inv); - - /*************************************************** - * Glass Spacer - ***************************************************/ - - icon = new ItemStackManager(Material.STAINED_GLASS_PANE); - icon.setData((short) 10); - icon.setTitle(" "); - - for (int i = 0; i < inv.getSize(); i++) - switch (i) { - case 9: - case 10: - case 11: - case 12: - case 13: - case 14: - case 15: - case 16: - case 17: - case 18: - case 27: - case 36: - case 45: - icon.setPosition(i); - icon.addToInventory(inv); - } - - /*************************************************** - * Blocks - ***************************************************/ - - List colorManager = arena.getColorManager().getAllBlocks(); - for (int i = 0; i < 32; i++) { - ItemStackManager item = colorManager.get(i); - item.setPosition((int) ((Math.floor(i / 8.0) * 9) + 19 + (i % 8))); - item.addToInventory(inv); - } - - /*************************************************** - * ArenaNAme - ***************************************************/ - - icon = new ItemStackManager(Material.PAPER); - icon.setTitle("&eArena:"); - icon.addToLore("&f" + arena.getName()); - - icon.setPosition(0); - icon.addToInventory(inv); - icon.setPosition(8); - icon.addToInventory(inv); - - /*************************************************** - * Display - ***************************************************/ - - player.openInventory(inv); - } -} diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/games/GameState.java b/Bukkit_1.9/src/me/poutineqc/cuberunner/games/GameState.java deleted file mode 100644 index 22f23b1..0000000 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/games/GameState.java +++ /dev/null @@ -1,5 +0,0 @@ -package me.poutineqc.cuberunner.games; - -public enum GameState { - READY, STARTUP, ACTIVE, ENDING, UNREADY -} diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/games/PlayerDamage.java b/Bukkit_1.9/src/me/poutineqc/cuberunner/games/PlayerDamage.java deleted file mode 100644 index 11f3ac5..0000000 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/games/PlayerDamage.java +++ /dev/null @@ -1,114 +0,0 @@ -package me.poutineqc.cuberunner.games; - -import java.sql.ResultSet; -import java.sql.SQLException; - -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityDamageEvent.DamageCause; - -import me.poutineqc.cuberunner.Configuration; -import me.poutineqc.cuberunner.CubeRunner; -import me.poutineqc.cuberunner.MySQL; -import me.poutineqc.cuberunner.PlayerData; -import me.poutineqc.cuberunner.achievements.AchievementType; -import me.poutineqc.cuberunner.achievements.Achievements; - -public class PlayerDamage implements Listener { - - private MySQL mySQL; - private Configuration config; - private PlayerData playerData; - private Achievements achievements; - - public PlayerDamage(CubeRunner plugin) { - this.mySQL = plugin.getMySQL(); - this.config = plugin.getConfiguration(); - this.playerData = plugin.getPlayerData(); - this.achievements = plugin.getAchievements(); - } - - @EventHandler - public void onPlayerDamageByEntity(EntityDamageByEntityEvent event) { - - if (!(event.getEntity() instanceof Player)) - return; - - Player player = (Player) event.getEntity(); - Arena arena = Arena.getArenaFromPlayer(player); - - if (arena == null) - return; - - if (event.getCause() != DamageCause.FALLING_BLOCK) { - event.setCancelled(true); - return; - } - - if (arena.getGameState() != GameState.ACTIVE) { - event.setCancelled(true); - return; - } - - User user = arena.getUser(player); - if (user.isEliminated()) { - event.setCancelled(true); - return; - } - - event.setDamage(0); - arena.eliminateUser(arena.getUser(player), false); - - String dammagerUUID = event.getDamager().getCustomName(); - if (!dammagerUUID.equalsIgnoreCase(player.getUniqueId().toString())) { - int kills = 0; - if (mySQL.hasConnection()) { - ResultSet query = mySQL.query("SELECT kills FROM " + config.tablePrefix - + "PLAYERS WHERE UUID='" + dammagerUUID + "';"); - try { - if (query.next()) - kills = query.getInt("kills"); - } catch (SQLException e) { - e.printStackTrace(); - } - - mySQL.update("UPDATE " + config.tablePrefix + "PLAYERS SET kills='" + ++kills - + "' WHERE UUID='" + dammagerUUID + "';"); - } else { - kills = playerData.getData().getInt("players." + dammagerUUID + ".kills", 0); - playerData.getData().set("players." + dammagerUUID + ".kills", ++kills); - playerData.savePlayerData(); - } - - achievements.checkAchievement(AchievementType.AMOUNT_KILLS, arena.getPlayerFromUUID(dammagerUUID)); - } - } - - @EventHandler - public void onPlayerDamage(EntityDamageEvent event) { - - if (!(event.getEntity() instanceof Player)) - return; - - Player player = (Player) event.getEntity(); - Arena arena = Arena.getArenaFromPlayer(player); - - if (arena == null) - return; - - if (event.getCause() != DamageCause.FALLING_BLOCK) { - event.setCancelled(true); - return; - } - - User user = arena.getUser(player); - if (user.isEliminated()) { - event.setCancelled(true); - return; - } - } - -} diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/games/PlayerDisconnect.java b/Bukkit_1.9/src/me/poutineqc/cuberunner/games/PlayerDisconnect.java deleted file mode 100644 index 3ef2522..0000000 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/games/PlayerDisconnect.java +++ /dev/null @@ -1,35 +0,0 @@ -package me.poutineqc.cuberunner.games; - -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerQuitEvent; - -import me.poutineqc.cuberunner.CubeRunner; -import me.poutineqc.cuberunner.achievements.AchievementType; -import me.poutineqc.cuberunner.achievements.Achievements; - -public class PlayerDisconnect implements Listener { - - private Achievements achievements; - - public PlayerDisconnect(CubeRunner plugin) { - this.achievements = plugin.getAchievements(); - } - - @EventHandler - public void onPlayerDisconnect(PlayerQuitEvent event) { - - Player player = event.getPlayer(); - Arena arena = Arena.getArenaFromPlayer(player); - - if (arena == null) - return; - - if (arena.getGameState() == GameState.STARTUP) - achievements.checkAchievement(AchievementType.DISCONNECT_IN_STARTUP, player); - - arena.removePlayer(player, true); - - } -} diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/games/User.java b/Bukkit_1.9/src/me/poutineqc/cuberunner/games/User.java deleted file mode 100644 index 2a52bdc..0000000 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/games/User.java +++ /dev/null @@ -1,115 +0,0 @@ -package me.poutineqc.cuberunner.games; - -import org.bukkit.entity.Player; - -import me.poutineqc.cuberunner.Configuration; -import me.poutineqc.cuberunner.tools.OriginalPlayerStats; - -public class User { - - private Player player; - private String uuid; - private String displayName; - private OriginalPlayerStats originalStats; - - private boolean left = false; - private boolean eliminated = false; - private long startTime; - private int score = 0; - private int jump = 0; - private boolean jumping = false; - private double distanceRan = 0; - - public User(Configuration config, Player player, boolean eliminated) { - this.player = player; - uuid = player.getUniqueId().toString(); - displayName = player.getDisplayName(); - originalStats = new OriginalPlayerStats(config, player); - this.eliminated = eliminated; - } - - public User(int time) { - this.score = time; - } - - protected void setStartTime() { - startTime = System.currentTimeMillis(); - } - - public Player getPlayer() { - return player; - } - - protected void addToScore() { - score++; - } - - protected int getScore() { - return score; - } - - protected String getDisplayName() { - return displayName; - } - - protected String getUUID() { - return uuid; - } - - protected int getGameLenght() { - return (int) (System.currentTimeMillis() - startTime); - } - - protected void returnStats() { - originalStats.returnStats(getPlayer()); - } - - protected void maxStats() { - originalStats.maxStats(getPlayer()); - } - - public boolean isEliminated() { - return eliminated; - } - - public void setEliminated(boolean eliminated) { - this.eliminated = eliminated; - } - - public void returnStats(Player player) { - originalStats.returnStats(player); - - } - - public void quit() { - left = true; - } - - public boolean hasLeft() { - return left; - } - - public void jump() { - jump++; - } - - public int getJump() { - return jump; - } - - public void setJumping(boolean jumping) { - this.jumping = jumping; - } - - public boolean isJumping() { - return jumping; - } - - public void addToDistanceRan(double distance) { - distanceRan += distance; - } - - public double getDistanceRan() { - return distanceRan; - } -} diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/tools/CaseInsensitiveMap.java b/Bukkit_1.9/src/me/poutineqc/cuberunner/tools/CaseInsensitiveMap.java deleted file mode 100644 index dfdeaaf..0000000 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/tools/CaseInsensitiveMap.java +++ /dev/null @@ -1,21 +0,0 @@ -package me.poutineqc.cuberunner.tools; - -import java.util.HashMap; - -public class CaseInsensitiveMap extends HashMap { - - /** - * - */ - private static final long serialVersionUID = -1010024940042453390L; - - @Override - public String put(String key, String value) { - return super.put(key.toLowerCase(), value); - } - - // not @Override because that would require the key parameter to be of type Object - public String get(String key) { - return super.get(key.toLowerCase()); - } -} \ No newline at end of file diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/tools/ColorManager.java b/Bukkit_1.9/src/me/poutineqc/cuberunner/tools/ColorManager.java deleted file mode 100644 index fc534fa..0000000 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/tools/ColorManager.java +++ /dev/null @@ -1,91 +0,0 @@ -package me.poutineqc.cuberunner.tools; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; - -import me.poutineqc.cuberunner.ArenaData; -import me.poutineqc.cuberunner.Configuration; -import me.poutineqc.cuberunner.CubeRunner; -import me.poutineqc.cuberunner.MySQL; -import me.poutineqc.cuberunner.games.Arena; - -public class ColorManager { - - private long colorIndice; - private List allBlocks; - private List onlyChoosenBlocks; - private MySQL mysql; - private Configuration config; - private Arena arena; - private ArenaData arenaData; - - public ColorManager(Long colorIndice, CubeRunner plugin, Arena arena) { - this.colorIndice = colorIndice; - this.mysql = plugin.getMySQL(); - this.arenaData = plugin.getArenaData(); - this.config = plugin.getConfiguration(); - this.arena = arena; - updateLists(); - } - - public void setColorIndice(long colorIndice) { - this.colorIndice = colorIndice; - updateLists(); - - if (mysql.hasConnection()) { - mysql.update("UPDATE " + config.tablePrefix + "ARENAS SET colorIndice=" + colorIndice + " WHERE name='" - + arena.getName() + "';"); - } else { - arenaData.getData().set("arenas." + arena.getName() + ".colorIndice", colorIndice); - arenaData.saveArenaData(); - } - } - - public void updateLists() { - allBlocks = new ArrayList(); - onlyChoosenBlocks = new ArrayList(); - long tempColorIndice = colorIndice; - - for (int i = 31; i >= 0; i--) { - ItemStackManager icon; - if (i >= 16) - icon = new ItemStackManager(Material.STAINED_CLAY); - else - icon = new ItemStackManager(Material.WOOL); - - icon.setData((short) (i % 16)); - - int value = (int) Math.pow(2, i); - if (value <= tempColorIndice) { - icon.addEnchantement(Enchantment.DURABILITY, 1); - tempColorIndice -= value; - onlyChoosenBlocks.add(0, icon); - } - - allBlocks.add(0, icon); - } - - if (onlyChoosenBlocks.size() == 0) - onlyChoosenBlocks = allBlocks; - } - - public ItemStackManager getRandomAvailableBlock() { - return onlyChoosenBlocks.get((int) Math.floor(Math.random() * onlyChoosenBlocks.size())); - } - - public List getAllBlocks() { - return allBlocks; - } - - public List getOnlyChoosenBlocks() { - return onlyChoosenBlocks; - } - - public long getColorIndice() { - return colorIndice; - } - -} diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/tools/ItemStackManager.java b/Bukkit_1.9/src/me/poutineqc/cuberunner/tools/ItemStackManager.java deleted file mode 100644 index f8fec69..0000000 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/tools/ItemStackManager.java +++ /dev/null @@ -1,85 +0,0 @@ -package me.poutineqc.cuberunner.tools; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.SkullMeta; - -public class ItemStackManager { - - private int position; - private ItemStack item; - private ItemMeta meta; - List lore = new ArrayList(); - - public ItemStackManager(Material material) { - item = new ItemStack(material); - meta = item.getItemMeta(); - } - - public ItemStackManager(Material material, int position) { - this.position = position; - item = new ItemStack(material); - meta = item.getItemMeta(); - } - - public Material getMaterial() { - return item.getType(); - } - - public short getData() { - return item.getDurability(); - } - - public void setPosition(int position) { - this.position = position; - } - - public void setData(short data) { - item.setDurability(data); - } - - public void setTitle(String displayName) { - meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', displayName)); - } - - public void addToLore(String loreLine) { - lore.add(ChatColor.translateAlternateColorCodes('&', loreLine)); - } - - public Inventory addToInventory(Inventory inv) { - meta.setLore(lore); - item.setItemMeta(meta); - inv.setItem(position, item); - return inv; - } - - public void addEnchantement(Enchantment enchantment, int level) { - meta.addEnchant(Enchantment.DURABILITY, -1, true); - } - - public ItemStack getItem() { - meta.setLore(lore); - item.setItemMeta(meta); - return item; - } - - public void setPlayerHeadName(String player) { - if (meta instanceof SkullMeta) - ((SkullMeta) meta).setOwner(player); - } - - public String getDisplayName() { - return meta.getDisplayName(); - } - - public void clearLore() { - lore.clear(); - } -} diff --git a/Bukkit_1.9/src/me/poutineqc/cuberunner/tools/JoinGUI.java b/Bukkit_1.9/src/me/poutineqc/cuberunner/tools/JoinGUI.java deleted file mode 100644 index 79d10b3..0000000 --- a/Bukkit_1.9/src/me/poutineqc/cuberunner/tools/JoinGUI.java +++ /dev/null @@ -1,188 +0,0 @@ -package me.poutineqc.cuberunner.tools; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.Inventory; - -import me.poutineqc.cuberunner.CubeRunner; -import me.poutineqc.cuberunner.Language; -import me.poutineqc.cuberunner.PlayerData; -import me.poutineqc.cuberunner.games.Arena; -import me.poutineqc.cuberunner.games.GameState; - -public class JoinGUI implements Listener { - - private PlayerData playerData; - - public JoinGUI(CubeRunner plugin) { - playerData = plugin.getPlayerData(); - } - - @EventHandler - public void onPlayerInventoryClick(InventoryClickEvent event) { - - if (!(event.getWhoClicked() instanceof Player)) - return; - - Player player = (Player) event.getWhoClicked(); - Language local = playerData.getLanguageOfPlayer(player); - - if (!ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase(ChatColor - .stripColor(ChatColor.translateAlternateColorCodes('&', local.guiJoinName + " &0: &5CubeRunner")))) - return; - - event.setCancelled(true); - - if (event.getAction() == InventoryAction.NOTHING || event.getAction() == InventoryAction.UNKNOWN) - return; - - String itemName = event.getCurrentItem().getItemMeta().getDisplayName(); - - if (isEqualOnColorStrip(itemName, ChatColor.translateAlternateColorCodes('&', local.guiNextPage)) - || isEqualOnColorStrip(itemName, ChatColor.translateAlternateColorCodes('&', local.guiPreviousPage))) { - openJoinGui(player, - Integer.parseInt(ChatColor.stripColor(event.getCurrentItem().getItemMeta().getLore().get(0)))); - return; - } - - Arena arena = Arena.getArena(ChatColor.stripColor(itemName)); - if (arena == null) - return; - - if (event.getAction() == InventoryAction.PICKUP_HALF) { - arena.displayInformation(player); - } else { - arena.addPlayer(player, true); - } - - player.closeInventory(); - } - - private boolean isEqualOnColorStrip(String toCheck, String original) { - return ChatColor.stripColor(toCheck) - .equalsIgnoreCase(ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', original))); - } - - public void openJoinGui(Player player, int page) { - - List Arenas = new ArrayList(); - for (Arena arena : Arena.getArenas()) - Arenas.add(arena.getName()); - java.util.Collections.sort(Arenas); - - for (int i = 0; i < (page - 1) * 36; i++) { - Arenas.remove(0); - } - - int size; - if (Arenas.size() > 36) - size = 54; - else { - size = (int) (Math.ceil((Arenas.size() + 18.0) / 9.0) * 9.0); - } - - Language local = playerData.getLanguageOfPlayer(player); - Inventory inv = Bukkit.createInventory(null, size, - ChatColor.translateAlternateColorCodes('&', local.guiJoinName + " &0: &5CubeRunner")); - ItemStackManager icon; - - /*************************************************** - * Instructions - ***************************************************/ - - icon = new ItemStackManager(Material.BOOKSHELF, 4); - icon.setTitle(local.guiInstrictions); - for (String loreLine : local.guiJoinInfo.split("\n")) - icon.addToLore(loreLine); - icon.addToInventory(inv); - - /*************************************************** - * Glass Spacer - ***************************************************/ - - icon = new ItemStackManager(Material.STAINED_GLASS_PANE); - icon.setData((short) 10); - icon.setTitle(" "); - - for (int i = 0; i < inv.getSize(); i++) - switch (i) { - case 9: - case 10: - case 11: - case 12: - case 13: - case 14: - case 15: - case 16: - case 17: - icon.setPosition(i); - icon.addToInventory(inv); - } - - /*************************************************** - * arenas - ***************************************************/ - - icon = new ItemStackManager(Material.INK_SACK); - int slot = 18; - - for (String arenaName : Arenas) { - Arena arena = Arena.getArena(arenaName); - icon.clearLore(); - - if (arena.getGameState() == GameState.UNREADY) { - icon.setData((short) 8); - icon.setTitle(ChatColor.GOLD + arenaName); - icon.addToLore(local.keyWordUnset); - - } else if (arena.getGameState() == GameState.ACTIVE || arena.getGameState() == GameState.ENDING) { - icon.setData((short) 12); - icon.setTitle(ChatColor.GOLD + arenaName); - icon.addToLore(local.guiJoinStarted); - - } else { - icon.setData((short) 10); - icon.setTitle(ChatColor.GOLD + arenaName); - icon.addToLore(local.guiJoinReady); - } - - icon.setPosition(slot++); - icon.addToInventory(inv); - - /*************************************************** - * NextPage - ***************************************************/ - - if (slot == 54 && Arenas.size() > 36) { - icon = new ItemStackManager(Material.ARROW, 8); - icon.setTitle(local.guiNextPage); - icon.addToLore(String.valueOf(page + 1)); - icon.addToInventory(inv); - break; - } - } - - /*************************************************** - * Previous Page - ***************************************************/ - - if (page > 1) { - icon = new ItemStackManager(Material.ARROW, 7); - icon.setTitle(local.guiPreviousPage); - icon.addToLore(String.valueOf(page - 1)); - inv = icon.addToInventory(inv); - } - - player.openInventory(inv); - } - -}