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
2
pom.xml
2
pom.xml
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<groupId>de.lunarakai</groupId>
|
<groupId>de.lunarakai</groupId>
|
||||||
<artifactId>Minecleaner</artifactId>
|
<artifactId>Minecleaner</artifactId>
|
||||||
<version>1.1.3</version>
|
<version>1.1.4</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>Minecleaner</name>
|
<name>Minecleaner</name>
|
||||||
|
|
|
||||||
|
|
@ -240,10 +240,13 @@ public class MinecleanerArena {
|
||||||
if(!currentMinecleanerGame.gameover) {
|
if(!currentMinecleanerGame.gameover) {
|
||||||
ingameTime++;
|
ingameTime++;
|
||||||
}
|
}
|
||||||
if(plugin.getManager().getSettingsValue("additionaldisplay", currentPlayer) != 0
|
if(plugin.isStatisticsEnabled()) {
|
||||||
|| plugin.getManager().getSettingsValue("timer", currentPlayer) != 0) {
|
if(plugin.getManager().getSettingsValue("additionaldisplay", currentPlayer) != 0
|
||||||
updateIngameInfoTexts();
|
|| plugin.getManager().getSettingsValue("timer", currentPlayer) != 0) {
|
||||||
|
updateIngameInfoTexts();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
cancel();
|
cancel();
|
||||||
}
|
}
|
||||||
|
|
@ -382,8 +385,14 @@ public class MinecleanerArena {
|
||||||
|
|
||||||
public void updateIngameInfoTexts() {
|
public void updateIngameInfoTexts() {
|
||||||
String timer = "";
|
String timer = "";
|
||||||
if(plugin.getManager().getSettingsValue("timer", currentPlayer) != 0) {
|
if(plugin.isStatisticsEnabled()) {
|
||||||
timer = ChatColor.GOLD + " Zeit: " + MinecleanerStringUtil.timeToString((ingameTime/20)*1000, true) + " ";
|
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) {
|
if (textDisplay != null) {
|
||||||
|
|
@ -398,10 +407,7 @@ public class MinecleanerArena {
|
||||||
textDisplay.text(Component.text(component + newLine + timer + filler));
|
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() {
|
public void removeTextDisplay() {
|
||||||
|
|
|
||||||
|
|
@ -67,52 +67,63 @@ public class MinecleanerManager {
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
|
|
||||||
|
if(plugin.isStatisticsEnabled()) {
|
||||||
|
minecleanerSettingTimerKey = plugin.getCubesideStatistics().getSettingKey("minecleaner.settings.timer");
|
||||||
|
minecleanerSettingTimerKey.setDefault(0);
|
||||||
|
minecleanerSettingTimerKey.setDisplayName("Timer");
|
||||||
|
|
||||||
minecleanerSettingTimerKey = plugin.getCubesideStatistics().getSettingKey("minecleaner.settings.timer");
|
minecleanerAdditionalDisplaySettingKey = plugin.getCubesideStatistics().getSettingKey("minecleaner.settings.additionaldisplay");
|
||||||
minecleanerSettingTimerKey.setDefault(0);
|
minecleanerAdditionalDisplaySettingKey.setDefault(0);
|
||||||
minecleanerSettingTimerKey.setDisplayName("Timer");
|
minecleanerAdditionalDisplaySettingKey.setDisplayName("Zusätzliche Anzeige in der Action Bar");
|
||||||
|
|
||||||
minecleanerAdditionalDisplaySettingKey = plugin.getCubesideStatistics().getSettingKey("minecleaner.settings.additionaldisplay");
|
this.settingsInventory = plugin.getServer().createInventory(null, InventoryType.CHEST,
|
||||||
minecleanerAdditionalDisplaySettingKey.setDefault(0);
|
plugin.getDisplayedPluginName() + " Einstellungen");
|
||||||
minecleanerAdditionalDisplaySettingKey.setDisplayName("Zusätzliche Anzeige in der Action Bar");
|
|
||||||
|
|
||||||
this.settingsInventory = plugin.getServer().createInventory(null, InventoryType.CHEST,
|
|
||||||
plugin.getDisplayedPluginName() + " Einstellungen");
|
|
||||||
|
|
||||||
|
|
||||||
// Statistics
|
// Statistics
|
||||||
|
|
||||||
statisticsWonGamesTotal = plugin.getCubesideStatistics().getStatisticKey("minecleaner.wonGamestotal");
|
statisticsWonGamesTotal = plugin.getCubesideStatistics().getStatisticKey("minecleaner.wonGamestotal");
|
||||||
statisticsWonGamesTotal.setIsMonthlyStats(true);
|
statisticsWonGamesTotal.setIsMonthlyStats(true);
|
||||||
statisticsWonGamesTotal.setDisplayName("Runden gewonnen");
|
statisticsWonGamesTotal.setDisplayName("Runden gewonnen");
|
||||||
|
|
||||||
statisticsPointsAcquired = plugin.getCubesideStatistics().getStatisticKey("minecleaner.pointstotal");
|
|
||||||
statisticsPointsAcquired.setIsMonthlyStats(true);
|
|
||||||
statisticsPointsAcquired.setDisplayName("Punkte erspielt");
|
|
||||||
|
|
||||||
statisticsGames = new HashMap<>();
|
statisticsPointsAcquired = plugin.getCubesideStatistics().getStatisticKey("minecleaner.pointstotal");
|
||||||
statisticsTimeRecord = new HashMap<>();
|
statisticsPointsAcquired.setIsMonthlyStats(true);
|
||||||
statisticsTotalGamesPlayed = new HashMap<>();
|
statisticsPointsAcquired.setDisplayName("Punkte erspielt");
|
||||||
|
|
||||||
for(Entry<Integer, String> e : this.sizes.entrySet()) {
|
statisticsGames = new HashMap<>();
|
||||||
String sizeDisplay = e.getValue();
|
statisticsTimeRecord = new HashMap<>();
|
||||||
StatisticKey s = plugin.getCubesideStatistics().getStatisticKey("minecleaner.wongames.boardsize." + e.getKey());
|
statisticsTotalGamesPlayed = new HashMap<>();
|
||||||
s.setIsMonthlyStats(true);
|
|
||||||
s.setDisplayName("Runden gewonnen auf Spielfeldgröße " + sizeDisplay);
|
|
||||||
statisticsGames.put(e.getKey(), s);
|
|
||||||
|
|
||||||
s = plugin.getCubesideStatistics().getStatisticKey("minecleaner.gamestotal.boardsize." + e.getKey());
|
for(Entry<Integer, String> e : this.sizes.entrySet()) {
|
||||||
s.setIsMonthlyStats(true);
|
String sizeDisplay = e.getValue();
|
||||||
s.setDisplayName("Runden gespielt auf Spielfeldgröße " + sizeDisplay );
|
StatisticKey s = plugin.getCubesideStatistics().getStatisticKey("minecleaner.wongames.boardsize." + e.getKey());
|
||||||
statisticsTotalGamesPlayed.put(e.getKey(), s);
|
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 = plugin.getCubesideStatistics().getStatisticKey("minecleaner.gamestotal.boardsize." + e.getKey());
|
||||||
s.setIsMonthlyStats(true);
|
s.setIsMonthlyStats(true);
|
||||||
s.setDisplayName("Bestzeit bei Größe " + sizeDisplay);
|
s.setDisplayName("Runden gespielt auf Spielfeldgröße " + sizeDisplay );
|
||||||
statisticsTimeRecord.put(e.getKey(), s);
|
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) {
|
public void joinArena(Player player, MinecleanerArena arena) {
|
||||||
if (!player.hasPermission(MinecleanerPlugin.PERMISSION_PLAY)) {
|
if (!player.hasPermission(MinecleanerPlugin.PERMISSION_PLAY)) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -144,16 +155,19 @@ public class MinecleanerManager {
|
||||||
|
|
||||||
public void handleGameover(Player player, MinecleanerArena arena, boolean isSuccessfullyCleared) {
|
public void handleGameover(Player player, MinecleanerArena arena, boolean isSuccessfullyCleared) {
|
||||||
World world = player.getWorld();
|
World world = player.getWorld();
|
||||||
PlayerStatistics ps = plugin.getCubesideStatistics().getStatistics(player.getUniqueId());
|
PlayerStatistics ps = null;
|
||||||
StatisticKey sg;
|
StatisticKey sg = null;
|
||||||
sg = statisticsTotalGamesPlayed.get(arena.getWidthIndex());
|
if(plugin.isStatisticsEnabled()) {
|
||||||
|
ps = plugin.getCubesideStatistics().getStatistics(player.getUniqueId());
|
||||||
|
sg = statisticsTotalGamesPlayed.get(arena.getWidthIndex());
|
||||||
|
}
|
||||||
|
|
||||||
if(!isSuccessfullyCleared) {
|
if(!isSuccessfullyCleared) {
|
||||||
world.playSound(player.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 0.5f, 0.5f);
|
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!");
|
player.sendMessage(ChatColor.YELLOW + "Game Over! Du konntest das " + plugin.getDisplayedPluginName() + "-Feld nicht erfolgreich lösen!");
|
||||||
arena.showMines();
|
arena.showMines();
|
||||||
|
|
||||||
if(sg != null) {
|
if(sg != null && plugin.isStatisticsEnabled()) {
|
||||||
ps.increaseScore(sg, 1);
|
ps.increaseScore(sg, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -170,48 +184,52 @@ public class MinecleanerManager {
|
||||||
|
|
||||||
world.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 0.5f, 0.5f);
|
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(sg, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ps.increaseScore(statisticsWonGamesTotal, 1);
|
if(plugin.isStatisticsEnabled()) {
|
||||||
|
ps.increaseScore(statisticsWonGamesTotal, 1);
|
||||||
|
|
||||||
sg = statisticsGames.get(arena.getWidthIndex());
|
sg = statisticsGames.get(arena.getWidthIndex());
|
||||||
if(sg != null) {
|
if(sg != null) {
|
||||||
ps.increaseScore(sg, 1);
|
ps.increaseScore(sg, 1);
|
||||||
}
|
}
|
||||||
sg = statisticsTimeRecord.get(arena.getWidthIndex());
|
sg = statisticsTimeRecord.get(arena.getWidthIndex());
|
||||||
if(sg != null) {
|
if(sg != null) {
|
||||||
ps.minScore(sg, millis, isUpdated -> {
|
ps.minScore(sg, millis, isUpdated -> {
|
||||||
if(isUpdated != null && isUpdated) {
|
if(isUpdated != null && isUpdated) {
|
||||||
player.sendMessage(ChatColor.GOLD + "Herzlichen Glückwunsch! Du hast eine neue Bestzeit erreicht! " + ChatColor.RED + MinecleanerStringUtil.timeToString(millis, false) );
|
player.sendMessage(ChatColor.GOLD + "Herzlichen Glückwunsch! Du hast eine neue Bestzeit erreicht! " + ChatColor.RED + MinecleanerStringUtil.timeToString(millis, false) );
|
||||||
} else {
|
} 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!");
|
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, () -> {
|
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.ListCommand;
|
||||||
import de.lunarakai.minecleaner.commands.StatsCommand;
|
import de.lunarakai.minecleaner.commands.StatsCommand;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public final class MinecleanerPlugin extends JavaPlugin {
|
public final class MinecleanerPlugin extends JavaPlugin {
|
||||||
public static final String PERMISSION_PLAY = "minecleaner.play";
|
public static final String PERMISSION_PLAY = "minecleaner.play";
|
||||||
public static final String PERMISSION_ADMIN = "minecleaner.admin";
|
public static final String PERMISSION_ADMIN = "minecleaner.admin";
|
||||||
|
|
@ -29,7 +31,11 @@ public final class MinecleanerPlugin extends JavaPlugin {
|
||||||
|
|
||||||
public void onLateEnable() {
|
public void onLateEnable() {
|
||||||
playerUUIDCache = (PlayerUUIDCache) getServer().getPluginManager().getPlugin("PlayerUUIDCache");
|
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 = new ArenaList(this);
|
||||||
arenaList.load();
|
arenaList.load();
|
||||||
|
|
@ -41,10 +47,13 @@ public final class MinecleanerPlugin extends JavaPlugin {
|
||||||
minecleanerCommand.addCommandMapping(new CreateCommand(this), "create");
|
minecleanerCommand.addCommandMapping(new CreateCommand(this), "create");
|
||||||
minecleanerCommand.addCommandMapping(new DeleteCommand(this), "delete");
|
minecleanerCommand.addCommandMapping(new DeleteCommand(this), "delete");
|
||||||
minecleanerCommand.addCommandMapping(new ListCommand(this), "list");
|
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 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
|
@Override
|
||||||
|
|
@ -62,6 +71,9 @@ public final class MinecleanerPlugin extends JavaPlugin {
|
||||||
return minecleanerManager;
|
return minecleanerManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isStatisticsEnabled() {
|
||||||
|
return cubesideStatistics != null;
|
||||||
|
}
|
||||||
public CubesideStatisticsAPI getCubesideStatistics() {
|
public CubesideStatisticsAPI getCubesideStatistics() {
|
||||||
return cubesideStatistics;
|
return cubesideStatistics;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue