plugin should now work without cubesidestatistics (if the server doesnt have the plugin)
This commit is contained in:
		
					parent
					
						
							
								0865e344f9
							
						
					
				
			
			
				commit
				
					
						bf13f7e2b9
					
				
			
		
					 4 changed files with 125 additions and 89 deletions
				
			
		|  | @ -240,10 +240,13 @@ public class MinecleanerArena { | |||
|                     if(!currentMinecleanerGame.gameover) { | ||||
|                         ingameTime++; | ||||
|                     } | ||||
|                     if(plugin.getManager().getSettingsValue("additionaldisplay", currentPlayer) != 0 | ||||
|                             || plugin.getManager().getSettingsValue("timer", currentPlayer) != 0) { | ||||
|                         updateIngameInfoTexts(); | ||||
|                     if(plugin.isStatisticsEnabled()) { | ||||
|                         if(plugin.getManager().getSettingsValue("additionaldisplay", currentPlayer) != 0 | ||||
|                                 || plugin.getManager().getSettingsValue("timer", currentPlayer) != 0) { | ||||
|                             updateIngameInfoTexts(); | ||||
|                         } | ||||
|                     } | ||||
| 
 | ||||
|                 } else { | ||||
|                     cancel(); | ||||
|                 } | ||||
|  | @ -382,8 +385,14 @@ public class MinecleanerArena { | |||
| 
 | ||||
|     public void updateIngameInfoTexts() { | ||||
|         String timer = ""; | ||||
|         if(plugin.getManager().getSettingsValue("timer", currentPlayer) != 0) { | ||||
|             timer = ChatColor.GOLD + " Zeit: " + MinecleanerStringUtil.timeToString((ingameTime/20)*1000, true)  + " "; | ||||
|         if(plugin.isStatisticsEnabled()) { | ||||
|             if(plugin.getManager().getSettingsValue("timer", currentPlayer) != 0) { | ||||
|                 timer = ChatColor.GOLD + " Zeit: " + MinecleanerStringUtil.timeToString((ingameTime/20)*1000, true)  + " "; | ||||
|             } | ||||
|             if(plugin.getManager().getSettingsValue("additionaldisplay", currentPlayer) != 0 && plugin.isStatisticsEnabled()) { | ||||
|                 String componentActionBar = ChatColor.GREEN + "Flaggen gesetzt: " + flagsPlaced + ChatColor.RED + "  Minen insgesamt: " + BoardSize.mineCounter[widthIndex]; | ||||
|                 currentPlayer.sendActionBar(Component.text(componentActionBar + " " + timer)); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         if (textDisplay != null) { | ||||
|  | @ -398,10 +407,7 @@ public class MinecleanerArena { | |||
|             textDisplay.text(Component.text(component + newLine + timer + filler)); | ||||
|         } | ||||
| 
 | ||||
|         if(plugin.getManager().getSettingsValue("additionaldisplay", currentPlayer) != 0) { | ||||
|             String componentActionBar = ChatColor.GREEN + "Flaggen gesetzt: " + flagsPlaced + ChatColor.RED + "  Minen insgesamt: " + BoardSize.mineCounter[widthIndex]; | ||||
|             currentPlayer.sendActionBar(Component.text(componentActionBar + " " + timer)); | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     public void removeTextDisplay() { | ||||
|  |  | |||
|  | @ -67,52 +67,63 @@ public class MinecleanerManager { | |||
| 
 | ||||
|         // Settings | ||||
| 
 | ||||
|         if(plugin.isStatisticsEnabled()) { | ||||
|             minecleanerSettingTimerKey = plugin.getCubesideStatistics().getSettingKey("minecleaner.settings.timer"); | ||||
|             minecleanerSettingTimerKey.setDefault(0); | ||||
|             minecleanerSettingTimerKey.setDisplayName("Timer"); | ||||
| 
 | ||||
|         minecleanerSettingTimerKey = plugin.getCubesideStatistics().getSettingKey("minecleaner.settings.timer"); | ||||
|         minecleanerSettingTimerKey.setDefault(0); | ||||
|         minecleanerSettingTimerKey.setDisplayName("Timer"); | ||||
|             minecleanerAdditionalDisplaySettingKey = plugin.getCubesideStatistics().getSettingKey("minecleaner.settings.additionaldisplay"); | ||||
|             minecleanerAdditionalDisplaySettingKey.setDefault(0); | ||||
|             minecleanerAdditionalDisplaySettingKey.setDisplayName("Zusätzliche Anzeige in der Action Bar"); | ||||
| 
 | ||||
|         minecleanerAdditionalDisplaySettingKey = plugin.getCubesideStatistics().getSettingKey("minecleaner.settings.additionaldisplay"); | ||||
|         minecleanerAdditionalDisplaySettingKey.setDefault(0); | ||||
|         minecleanerAdditionalDisplaySettingKey.setDisplayName("Zusätzliche Anzeige in der Action Bar"); | ||||
| 
 | ||||
|         this.settingsInventory = plugin.getServer().createInventory(null, InventoryType.CHEST, | ||||
|                 plugin.getDisplayedPluginName() + " Einstellungen"); | ||||
|             this.settingsInventory = plugin.getServer().createInventory(null, InventoryType.CHEST, | ||||
|                     plugin.getDisplayedPluginName() + " Einstellungen"); | ||||
| 
 | ||||
| 
 | ||||
|         // Statistics | ||||
|             // Statistics | ||||
| 
 | ||||
|         statisticsWonGamesTotal = plugin.getCubesideStatistics().getStatisticKey("minecleaner.wonGamestotal"); | ||||
|         statisticsWonGamesTotal.setIsMonthlyStats(true); | ||||
|         statisticsWonGamesTotal.setDisplayName("Runden gewonnen"); | ||||
|          | ||||
|         statisticsPointsAcquired = plugin.getCubesideStatistics().getStatisticKey("minecleaner.pointstotal"); | ||||
|         statisticsPointsAcquired.setIsMonthlyStats(true); | ||||
|         statisticsPointsAcquired.setDisplayName("Punkte erspielt"); | ||||
|             statisticsWonGamesTotal = plugin.getCubesideStatistics().getStatisticKey("minecleaner.wonGamestotal"); | ||||
|             statisticsWonGamesTotal.setIsMonthlyStats(true); | ||||
|             statisticsWonGamesTotal.setDisplayName("Runden gewonnen"); | ||||
| 
 | ||||
|         statisticsGames = new HashMap<>(); | ||||
|         statisticsTimeRecord = new HashMap<>(); | ||||
|         statisticsTotalGamesPlayed = new HashMap<>(); | ||||
|             statisticsPointsAcquired = plugin.getCubesideStatistics().getStatisticKey("minecleaner.pointstotal"); | ||||
|             statisticsPointsAcquired.setIsMonthlyStats(true); | ||||
|             statisticsPointsAcquired.setDisplayName("Punkte erspielt"); | ||||
| 
 | ||||
|         for(Entry<Integer, String> e : this.sizes.entrySet()) { | ||||
|             String sizeDisplay = e.getValue(); | ||||
|             StatisticKey s = plugin.getCubesideStatistics().getStatisticKey("minecleaner.wongames.boardsize." + e.getKey()); | ||||
|             s.setIsMonthlyStats(true); | ||||
|             s.setDisplayName("Runden gewonnen auf Spielfeldgröße " + sizeDisplay); | ||||
|             statisticsGames.put(e.getKey(), s); | ||||
|             statisticsGames = new HashMap<>(); | ||||
|             statisticsTimeRecord = new HashMap<>(); | ||||
|             statisticsTotalGamesPlayed = new HashMap<>(); | ||||
| 
 | ||||
|             s = plugin.getCubesideStatistics().getStatisticKey("minecleaner.gamestotal.boardsize." + e.getKey()); | ||||
|             s.setIsMonthlyStats(true); | ||||
|             s.setDisplayName("Runden gespielt auf Spielfeldgröße " + sizeDisplay ); | ||||
|             statisticsTotalGamesPlayed.put(e.getKey(), s); | ||||
|             for(Entry<Integer, String> e : this.sizes.entrySet()) { | ||||
|                 String sizeDisplay = e.getValue(); | ||||
|                 StatisticKey s = plugin.getCubesideStatistics().getStatisticKey("minecleaner.wongames.boardsize." + e.getKey()); | ||||
|                 s.setIsMonthlyStats(true); | ||||
|                 s.setDisplayName("Runden gewonnen auf Spielfeldgröße " + sizeDisplay); | ||||
|                 statisticsGames.put(e.getKey(), s); | ||||
| 
 | ||||
|             s = plugin.getCubesideStatistics().getStatisticKey("minecleaner.timerecord." + e.getKey()); | ||||
|             s.setIsMonthlyStats(true); | ||||
|             s.setDisplayName("Bestzeit bei Größe " + sizeDisplay); | ||||
|             statisticsTimeRecord.put(e.getKey(), s); | ||||
|                 s = plugin.getCubesideStatistics().getStatisticKey("minecleaner.gamestotal.boardsize." + e.getKey()); | ||||
|                 s.setIsMonthlyStats(true); | ||||
|                 s.setDisplayName("Runden gespielt auf Spielfeldgröße " + sizeDisplay ); | ||||
|                 statisticsTotalGamesPlayed.put(e.getKey(), s); | ||||
| 
 | ||||
|                 s = plugin.getCubesideStatistics().getStatisticKey("minecleaner.timerecord." + e.getKey()); | ||||
|                 s.setIsMonthlyStats(true); | ||||
|                 s.setDisplayName("Bestzeit bei Größe " + sizeDisplay); | ||||
|                 statisticsTimeRecord.put(e.getKey(), s); | ||||
|                 } | ||||
|             } else { | ||||
|             this.statisticsWonGamesTotal = null; | ||||
|             this.statisticsPointsAcquired = null; | ||||
|             this.statisticsGames = null; | ||||
|             this.statisticsTimeRecord = null; | ||||
|             this.statisticsTotalGamesPlayed = null; | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|     } | ||||
|      | ||||
| 
 | ||||
| 
 | ||||
|     public void joinArena(Player player, MinecleanerArena arena) { | ||||
|         if (!player.hasPermission(MinecleanerPlugin.PERMISSION_PLAY)) { | ||||
|             return; | ||||
|  | @ -144,16 +155,19 @@ public class MinecleanerManager { | |||
| 
 | ||||
|     public void handleGameover(Player player, MinecleanerArena arena, boolean isSuccessfullyCleared) { | ||||
|         World world = player.getWorld(); | ||||
|         PlayerStatistics ps = plugin.getCubesideStatistics().getStatistics(player.getUniqueId()); | ||||
|         StatisticKey sg; | ||||
|         sg = statisticsTotalGamesPlayed.get(arena.getWidthIndex()); | ||||
|         PlayerStatistics ps = null; | ||||
|         StatisticKey sg = null; | ||||
|         if(plugin.isStatisticsEnabled()) { | ||||
|             ps = plugin.getCubesideStatistics().getStatistics(player.getUniqueId()); | ||||
|             sg = statisticsTotalGamesPlayed.get(arena.getWidthIndex()); | ||||
|         } | ||||
| 
 | ||||
|         if(!isSuccessfullyCleared) { | ||||
|             world.playSound(player.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 0.5f, 0.5f); | ||||
|             player.sendMessage(ChatColor.YELLOW + "Game Over! Du konntest das " + plugin.getDisplayedPluginName() + "-Feld nicht erfolgreich lösen!"); | ||||
|             arena.showMines(); | ||||
|              | ||||
|             if(sg != null) { | ||||
|             if(sg != null && plugin.isStatisticsEnabled()) { | ||||
|                 ps.increaseScore(sg, 1); | ||||
|             } | ||||
| 
 | ||||
|  | @ -170,48 +184,52 @@ public class MinecleanerManager { | |||
|          | ||||
|         world.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 0.5f, 0.5f); | ||||
| 
 | ||||
|         if(sg != null) { | ||||
|         if(sg != null && plugin.isStatisticsEnabled()) { | ||||
|             ps.increaseScore(sg, 1); | ||||
|         } | ||||
| 
 | ||||
|         ps.increaseScore(statisticsWonGamesTotal, 1); | ||||
|         if(plugin.isStatisticsEnabled()) { | ||||
|             ps.increaseScore(statisticsWonGamesTotal, 1); | ||||
| 
 | ||||
|         sg = statisticsGames.get(arena.getWidthIndex()); | ||||
|         if(sg != null) { | ||||
|             ps.increaseScore(sg, 1); | ||||
|         } | ||||
|         sg = statisticsTimeRecord.get(arena.getWidthIndex()); | ||||
|         if(sg != null) { | ||||
|             ps.minScore(sg, millis, isUpdated -> { | ||||
|                 if(isUpdated != null && isUpdated) { | ||||
|                     player.sendMessage(ChatColor.GOLD + "Herzlichen Glückwunsch! Du hast eine neue Bestzeit erreicht! " + ChatColor.RED + MinecleanerStringUtil.timeToString(millis, false) ); | ||||
|                 } else { | ||||
|                     player.sendMessage(ChatColor.YELLOW + "Glückwunsch, du konntest das " + plugin.getDisplayedPluginName() + "-Feld in " + ChatColor.RED + MinecleanerStringUtil.timeToString(millis, false) + ChatColor.YELLOW + " erfolgreich lösen!"); | ||||
|             sg = statisticsGames.get(arena.getWidthIndex()); | ||||
|             if(sg != null) { | ||||
|                 ps.increaseScore(sg, 1); | ||||
|             } | ||||
|             sg = statisticsTimeRecord.get(arena.getWidthIndex()); | ||||
|             if(sg != null) { | ||||
|                 ps.minScore(sg, millis, isUpdated -> { | ||||
|                     if(isUpdated != null && isUpdated) { | ||||
|                         player.sendMessage(ChatColor.GOLD + "Herzlichen Glückwunsch! Du hast eine neue Bestzeit erreicht! " + ChatColor.RED + MinecleanerStringUtil.timeToString(millis, false) ); | ||||
|                     } else { | ||||
|                         player.sendMessage(ChatColor.YELLOW + "Glückwunsch, du konntest das " + plugin.getDisplayedPluginName() + "-Feld in " + ChatColor.RED + MinecleanerStringUtil.timeToString(millis, false) + ChatColor.YELLOW + " erfolgreich lösen!"); | ||||
|                     } | ||||
|                 }); | ||||
|             } | ||||
| 
 | ||||
|             int wIndex = arena.getWidthIndex(); | ||||
|             switch (wIndex) { | ||||
|                 case 0: { | ||||
|                     ps.increaseScore(statisticsPointsAcquired, plugin.getConfig().getInt("winpoints.size.small")); | ||||
|                     break; | ||||
|                 } | ||||
|                 case 1: { | ||||
|                     ps.increaseScore(statisticsPointsAcquired, plugin.getConfig().getInt("winpoints.size.medium")); | ||||
|                     break; | ||||
|                 } | ||||
|                 case 2: { | ||||
|                     ps.increaseScore(statisticsPointsAcquired, plugin.getConfig().getInt("winpoints.size.large")); | ||||
|                     break; | ||||
|                 } | ||||
|                 case 3: { | ||||
|                     ps.increaseScore(statisticsPointsAcquired, plugin.getConfig().getInt("winpoints.size.expert")); | ||||
|                 } | ||||
|                 default: { | ||||
|                     ps.increaseScore(statisticsPointsAcquired, 0); | ||||
|                     break; | ||||
|                 } | ||||
|             }); | ||||
|         } | ||||
| 
 | ||||
|         int wIndex = arena.getWidthIndex(); | ||||
|         switch (wIndex) { | ||||
|             case 0: { | ||||
|                 ps.increaseScore(statisticsPointsAcquired, plugin.getConfig().getInt("winpoints.size.small")); | ||||
|                 break; | ||||
|             } | ||||
|             case 1: { | ||||
|                 ps.increaseScore(statisticsPointsAcquired, plugin.getConfig().getInt("winpoints.size.medium")); | ||||
|                 break; | ||||
|             } | ||||
|             case 2: { | ||||
|                 ps.increaseScore(statisticsPointsAcquired, plugin.getConfig().getInt("winpoints.size.large")); | ||||
|                 break; | ||||
|             } | ||||
|             case 3: { | ||||
|                 ps.increaseScore(statisticsPointsAcquired, plugin.getConfig().getInt("winpoints.size.expert")); | ||||
|             } | ||||
|             default: { | ||||
|                 ps.increaseScore(statisticsPointsAcquired, 0); | ||||
|                 break; | ||||
|             } | ||||
|         } else { | ||||
|             player.sendMessage(ChatColor.YELLOW + "Glückwunsch, du konntest das " + plugin.getDisplayedPluginName() + "-Feld in " + ChatColor.RED + MinecleanerStringUtil.timeToString(millis, false) + ChatColor.YELLOW + " erfolgreich lösen!"); | ||||
|         } | ||||
| 
 | ||||
|         Bukkit.getScheduler().runTaskLater(plugin, () -> { | ||||
|  |  | |||
|  | @ -12,6 +12,8 @@ import de.lunarakai.minecleaner.commands.InfoCommand; | |||
| import de.lunarakai.minecleaner.commands.ListCommand; | ||||
| import de.lunarakai.minecleaner.commands.StatsCommand; | ||||
| 
 | ||||
| import java.util.logging.Level; | ||||
| 
 | ||||
| public final class MinecleanerPlugin extends JavaPlugin { | ||||
|     public static final String PERMISSION_PLAY = "minecleaner.play"; | ||||
|     public static final String PERMISSION_ADMIN = "minecleaner.admin"; | ||||
|  | @ -29,7 +31,11 @@ public final class MinecleanerPlugin extends JavaPlugin { | |||
| 
 | ||||
|     public void onLateEnable() { | ||||
|         playerUUIDCache = (PlayerUUIDCache) getServer().getPluginManager().getPlugin("PlayerUUIDCache"); | ||||
|         cubesideStatistics = getServer().getServicesManager().load(CubesideStatisticsAPI.class); | ||||
|         if(getServer().getPluginManager().getPlugin("CubesideStatistics") != null) { | ||||
|             cubesideStatistics = getServer().getServicesManager().load(CubesideStatisticsAPI.class); | ||||
|         } else { | ||||
|             this.getLogger().log(Level.WARNING, "Cubeside Statistics not found. No Statistics will be available"); | ||||
|         } | ||||
| 
 | ||||
|         arenaList = new ArenaList(this); | ||||
|         arenaList.load(); | ||||
|  | @ -41,10 +47,13 @@ public final class MinecleanerPlugin extends JavaPlugin { | |||
|         minecleanerCommand.addCommandMapping(new CreateCommand(this), "create"); | ||||
|         minecleanerCommand.addCommandMapping(new DeleteCommand(this), "delete"); | ||||
|         minecleanerCommand.addCommandMapping(new ListCommand(this), "list"); | ||||
|         minecleanerCommand.addCommandMapping(new StatsCommand(this), "stats"); | ||||
|         minecleanerCommand.addCommandMapping(new DeletePlayerScoreCommand(this), "deleteplayerscores"); | ||||
|         minecleanerCommand.addCommandMapping(new InfoCommand(this), "info"); | ||||
|         minecleanerCommand.addCommandMapping(new SettingsCommand(this), "settings"); | ||||
| 
 | ||||
|         if(isStatisticsEnabled()) { | ||||
|             minecleanerCommand.addCommandMapping(new SettingsCommand(this), "settings"); | ||||
|             minecleanerCommand.addCommandMapping(new StatsCommand(this), "stats"); | ||||
|             minecleanerCommand.addCommandMapping(new DeletePlayerScoreCommand(this), "deleteplayerscores"); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|  | @ -62,6 +71,9 @@ public final class MinecleanerPlugin extends JavaPlugin { | |||
|         return minecleanerManager; | ||||
|     } | ||||
| 
 | ||||
|     public boolean isStatisticsEnabled() { | ||||
|         return cubesideStatistics != null; | ||||
|     } | ||||
|     public CubesideStatisticsAPI getCubesideStatistics() { | ||||
|         return cubesideStatistics; | ||||
|     } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue